fw4spl
MeshGetter.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2016.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "fwDataTools/helper/MeshGetter.hpp"
8 
9 #include <fwMath/MeshFunctions.hpp>
10 
11 #include <boost/assign/list_of.hpp>
12 
13 using namespace boost::assign;
14 
15 namespace fwDataTools
16 {
17 
18 namespace helper
19 {
20 
21 #define POINT_REALLOC_STEP 1000
22 #define CELL_REALLOC_STEP 1000
23 #define CELLDATA_REALLOC_STEP 1000
24 
25 MeshGetter::MeshGetter( ::fwData::Mesh::csptr mesh ) : m_mesh (mesh)
26 {
27  typedef::fwDataTools::helper::ArrayGetter ArrayGetter;
28  SLM_ASSERT("Mesh ptr is null.", mesh);
29 
30  SLM_ASSERT("Mesh ptr is null.", m_mesh);
31  m_helperPoints = ArrayGetter::uptr( new ArrayGetter(m_mesh->getPointsArray()));
32  m_helperCellTypes = ArrayGetter::uptr( new ArrayGetter(m_mesh->getCellTypesArray()));
33  m_helperCellData = ArrayGetter::uptr( new ArrayGetter(m_mesh->getCellDataArray()));
34  m_helperCellDataOffsets = ArrayGetter::uptr( new ArrayGetter(m_mesh->getCellDataOffsetsArray()));
35 
36  ::fwData::Array::sptr pointColors = m_mesh->getPointColorsArray();
37  ::fwData::Array::sptr cellColors = m_mesh->getCellColorsArray();
38  ::fwData::Array::sptr pointNormals = m_mesh->getPointNormalsArray();
39  ::fwData::Array::sptr cellNormals = m_mesh->getCellNormalsArray();
40  ::fwData::Array::sptr pointTexCoords = m_mesh->getPointTexCoordsArray();
41  ::fwData::Array::sptr cellTexCoords = m_mesh->getCellTexCoordsArray();
42 
43  if(pointColors)
44  {
45  m_helperPointColors = ArrayGetter::uptr( new ArrayGetter(pointColors));
46  }
47  if(cellColors)
48  {
49  m_helperCellColors = ArrayGetter::uptr( new ArrayGetter(cellColors));
50  }
51  if(pointNormals)
52  {
53  m_helperPointNormals = ArrayGetter::uptr( new ArrayGetter(pointNormals));
54  }
55  if(cellNormals)
56  {
57  m_helperCellNormals = ArrayGetter::uptr( new ArrayGetter(cellNormals));
58  }
59  if(pointTexCoords)
60  {
61  m_helperPointTexCoords = ArrayGetter::uptr( new ArrayGetter(pointTexCoords));
62  }
63  if(cellTexCoords)
64  {
65  m_helperCellTexCoords = ArrayGetter::uptr( new ArrayGetter(cellTexCoords));
66  }
67 }
68 
69 //-----------------------------------------------------------------------------
70 
71 MeshGetter::~MeshGetter()
72 {
73 }
74 
75 //------------------------------------------------------------------------------
76 
77 ::fwData::Mesh::ConstPointsMultiArrayType MeshGetter::getPoints() const
78 {
79  return ::fwData::Mesh::ConstPointsMultiArrayType(
80  static_cast< const ::fwData::Mesh::PointsMultiArrayType::element* >(m_helperPoints->getBuffer()),
81  ::boost::extents[m_mesh->getNumberOfPoints()][3]
82  );
83 }
84 
85 //------------------------------------------------------------------------------
86 
87 ::fwData::Mesh::ConstCellTypesMultiArrayType MeshGetter::getCellTypes() const
88 {
89  return ::fwData::Mesh::ConstCellTypesMultiArrayType(
90  static_cast< const ::fwData::Mesh::CellTypesMultiArrayType::element*> (m_helperCellTypes->getBuffer()),
91  boost::extents[m_mesh->getNumberOfCells()]
92  );
93 }
94 
95 //------------------------------------------------------------------------------
96 
97 ::fwData::Mesh::ConstCellDataMultiArrayType MeshGetter::getCellData() const
98 {
99  return ::fwData::Mesh::ConstCellDataMultiArrayType(
100  static_cast< const ::fwData::Mesh::CellDataMultiArrayType::element* >(m_helperCellData->getBuffer()),
101  ::boost::extents[m_mesh->getCellDataSize()]
102  );
103 }
104 
105 //------------------------------------------------------------------------------
106 
107 ::fwData::Mesh::ConstCellDataOffsetsMultiArrayType MeshGetter::getCellDataOffsets() const
108 {
109  return ::fwData::Mesh::ConstCellDataOffsetsMultiArrayType(
110  static_cast< const ::fwData::Mesh::CellDataOffsetsMultiArrayType::element*>(m_helperCellDataOffsets->getBuffer()),
111  ::boost::extents[m_mesh->getNumberOfCells()]
112  );
113 }
114 
115 //------------------------------------------------------------------------------
116 
117 ::fwData::Mesh::ConstPointColorsMultiArrayType MeshGetter::getPointColors() const
118 {
119  ::fwData::Array::sptr pointColors = m_mesh->getPointColorsArray();
120  return ::fwData::Mesh::ConstPointColorsMultiArrayType(
121  static_cast< const ::fwData::Mesh::PointColorsMultiArrayType::element*>(m_helperPointColors->getBuffer()),
122  ::boost::extents[m_mesh->getNumberOfPoints()][pointColors->getNumberOfComponents()]
123  );
124 }
125 
126 //------------------------------------------------------------------------------
127 
128 ::fwData::Mesh::ConstCellColorsMultiArrayType MeshGetter::getCellColors() const
129 {
130  ::fwData::Array::sptr cellColors = m_mesh->getCellColorsArray();
131  return ::fwData::Mesh::ConstCellColorsMultiArrayType(
132  static_cast< const ::fwData::Mesh::CellColorsMultiArrayType::element*>(m_helperCellColors->getBuffer()),
133  ::boost::extents[m_mesh->getNumberOfCells()][cellColors->getNumberOfComponents()]
134  );
135 }
136 
137 //------------------------------------------------------------------------------
138 
139 ::fwData::Mesh::ConstPointNormalsMultiArrayType MeshGetter::getPointNormals() const
140 {
141  ::fwData::Array::sptr pointNormals = m_mesh->getPointNormalsArray();
142  return ::fwData::Mesh::ConstPointNormalsMultiArrayType(
143  static_cast< const ::fwData::Mesh::PointNormalsMultiArrayType::element*>(m_helperPointNormals->getBuffer()),
144  ::boost::extents[m_mesh->getNumberOfPoints()][pointNormals->getNumberOfComponents()]
145  );
146 }
147 
148 //------------------------------------------------------------------------------
149 
150 ::fwData::Mesh::ConstCellNormalsMultiArrayType MeshGetter::getCellNormals() const
151 {
152  ::fwData::Array::sptr cellNormals = m_mesh->getCellNormalsArray();
153  return ::fwData::Mesh::ConstCellNormalsMultiArrayType(
154  static_cast< const ::fwData::Mesh::CellNormalsMultiArrayType::element*>(m_helperCellNormals->getBuffer()),
155  ::boost::extents[m_mesh->getNumberOfCells()][cellNormals->getNumberOfComponents()]
156  );
157 }
158 
159 //------------------------------------------------------------------------------
160 
161 ::fwData::Mesh::ConstPointTexCoordsMultiArrayType MeshGetter::getPointTexCoords() const
162 {
163  ::fwData::Array::sptr pointTexCoords = m_mesh->getPointTexCoordsArray();
164  return ::fwData::Mesh::ConstPointTexCoordsMultiArrayType(
165  static_cast< const ::fwData::Mesh::PointTexCoordsMultiArrayType::element*>(m_helperPointTexCoords->getBuffer()),
166  ::boost::extents[m_mesh->getNumberOfPoints()][pointTexCoords->getNumberOfComponents()]
167  );
168 }
169 
170 //------------------------------------------------------------------------------
171 
172 ::fwData::Mesh::ConstCellTexCoordsMultiArrayType MeshGetter::getCellTexCoords() const
173 {
174  ::fwData::Array::sptr cellTexCoords = m_mesh->getCellTexCoordsArray();
175  return ::fwData::Mesh::ConstCellTexCoordsMultiArrayType(
176  static_cast< const ::fwData::Mesh::CellTexCoordsMultiArrayType::element*>(m_helperCellTexCoords->getBuffer()),
177  ::boost::extents[m_mesh->getNumberOfCells()][cellTexCoords->getNumberOfComponents()]
178  );
179 }
180 
181 //------------------------------------------------------------------------------
182 
183 ::fwData::Mesh::csptr MeshGetter::getMesh() const
184 {
185  return m_mesh;
186 }
187 
188 //------------------------------------------------------------------------------
189 
190 bool MeshGetter::isClosed()
191 {
192  bool isClosed = false;
193 
194  ::fwData::Mesh::Id cellDataSize = m_mesh->getCellDataSize();
195  ::fwData::Mesh::Id nbOfCells = m_mesh->getNumberOfCells();
196 
197  auto cellDataBegin = m_helperCellData->begin< ::fwData::Mesh::CellValueType >();
198  auto cellDataEnd = cellDataBegin + cellDataSize;
199  auto cellDataOffsetsBegin = m_helperCellDataOffsets->begin< ::fwData::Mesh::CellDataOffsetType >();
200  auto cellDataOffsetsEnd = cellDataOffsetsBegin + nbOfCells;
201  auto cellTypesBegin = m_helperCellTypes->begin< ::fwData::Mesh::CellTypes >();
202 
203  isClosed = ::fwMath::isBorderlessSurface(cellDataBegin,
204  cellDataEnd, cellDataOffsetsBegin,
205  cellDataOffsetsEnd, cellTypesBegin );
206  return isClosed;
207 }
208 
209 //------------------------------------------------------------------------------
210 
211 } // namespace helper
212 
213 } // namespace fwDataTools
The namespace fwDataTools contains classes which provide helpers to manipulate fwData::Object. *.
#define SLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:308