fw4spl
core/fwData/include/fwData/Mesh.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
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 #ifndef __FWDATA_MESH_HPP__
8 #define __FWDATA_MESH_HPP__
9 
10 #include "fwData/Array.hpp"
11 #include "fwData/config.hpp"
12 #include "fwData/Exception.hpp"
13 #include "fwData/factory/new.hpp"
14 
15 #include <fwCore/macros.hpp>
16 
17 #include <boost/multi_array.hpp>
18 
19 fwCampAutoDeclareDataMacro((fwData)(Mesh), FWDATA_API);
20 
21 namespace fwData
22 {
23 
72 class FWDATA_CLASS_API Mesh : public ::fwData::Object
73 {
74 
75 public:
76 
77  fwCoreClassDefinitionsWithFactoryMacro( (Mesh)(::fwData::Object), (()), ::fwData::factory::New< Mesh >);
78 
79  fwCampMakeFriendDataMacro((fwData)(Mesh));
80 
81  typedef std::map< std::string, ::fwData::Array::sptr > ArrayMapType;
82  typedef std::uint64_t Id;
83 
84  typedef enum
85  {
86  NO_CELL = 0,
87  POINT,
88  EDGE,
89  TRIANGLE,
90  QUAD,
91  POLY,
92  TETRA
93  } CellTypesEnum;
94 
95  typedef enum
96  {
97  RGB = 3,
98  RGBA = 4
99  } ColorArrayTypes;
100 
101  typedef float PointValueType;
102  typedef std::uint8_t ColorValueType;
103  typedef float NormalValueType;
104  typedef float TexCoordValueType;
105  typedef Id CellValueType;
106  typedef Id CellDataOffsetType;
107  typedef std::uint8_t CellTypes;
108 
109  typedef boost::multi_array_ref<PointValueType, 2> PointsMultiArrayType;
110  typedef boost::multi_array_ref<CellTypes, 1> CellTypesMultiArrayType;
111  typedef boost::multi_array_ref<CellValueType, 1> CellDataMultiArrayType;
112  typedef boost::multi_array_ref<CellDataOffsetType, 1> CellDataOffsetsMultiArrayType;
113  typedef boost::multi_array_ref<ColorValueType, 2> PointColorsMultiArrayType;
114  typedef boost::multi_array_ref<ColorValueType, 2> CellColorsMultiArrayType;
115  typedef boost::multi_array_ref<NormalValueType, 2> PointNormalsMultiArrayType;
116  typedef boost::multi_array_ref<NormalValueType, 2> CellNormalsMultiArrayType;
117  typedef boost::multi_array_ref<TexCoordValueType, 2> PointTexCoordsMultiArrayType;
118  typedef boost::multi_array_ref<TexCoordValueType, 2> CellTexCoordsMultiArrayType;
119 
120  typedef boost::const_multi_array_ref<PointValueType, 2> ConstPointsMultiArrayType;
121  typedef boost::const_multi_array_ref<CellTypes, 1> ConstCellTypesMultiArrayType;
122  typedef boost::const_multi_array_ref<CellValueType, 1> ConstCellDataMultiArrayType;
123  typedef boost::const_multi_array_ref<CellDataOffsetType, 1> ConstCellDataOffsetsMultiArrayType;
124  typedef boost::const_multi_array_ref<ColorValueType, 2> ConstPointColorsMultiArrayType;
125  typedef boost::const_multi_array_ref<ColorValueType, 2> ConstCellColorsMultiArrayType;
126  typedef boost::const_multi_array_ref<NormalValueType, 2> ConstPointNormalsMultiArrayType;
127  typedef boost::const_multi_array_ref<NormalValueType, 2> ConstCellNormalsMultiArrayType;
128  typedef boost::const_multi_array_ref<TexCoordValueType, 2> ConstPointTexCoordsMultiArrayType;
129  typedef boost::const_multi_array_ref<TexCoordValueType, 2> ConstCellTexCoordsMultiArrayType;
130 
135  FWDATA_API Mesh(::fwData::Object::Key key);
136 
138  FWDATA_API virtual ~Mesh();
139 
141  FWDATA_API void shallowCopy( const Object::csptr& _source ) override;
142 
144  FWDATA_API void cachedDeepCopy(const Object::csptr& _source, DeepCopyCacheType& cache) override;
145 
160  FWDATA_API size_t allocate(size_t nbPts, size_t nbCells, size_t nbCellsData = 0);
161 
163  FWDATA_API size_t allocatePointNormals();
164 
166  FWDATA_API size_t allocatePointColors(ColorArrayTypes t);
167 
169  FWDATA_API size_t allocatePointTexCoords();
170 
172  FWDATA_API size_t allocateCellNormals();
173 
175  FWDATA_API size_t allocateCellColors(ColorArrayTypes t);
176 
178  FWDATA_API size_t allocateCellTexCoords();
179 
193  FWDATA_API bool adjustAllocatedMemory();
194 
196  FWDATA_API void setPointsArray (const ::fwData::Array::sptr& array);
198  FWDATA_API void setCellTypesArray (const ::fwData::Array::sptr& array);
200  FWDATA_API void setCellDataArray (const ::fwData::Array::sptr& array);
202  FWDATA_API void setCellDataOffsetsArray (const ::fwData::Array::sptr& array);
204  FWDATA_API void setPointColorsArray (const ::fwData::Array::sptr& array);
206  FWDATA_API void setCellColorsArray (const ::fwData::Array::sptr& array);
208  FWDATA_API void setPointNormalsArray (const ::fwData::Array::sptr& array);
210  FWDATA_API void setCellNormalsArray (const ::fwData::Array::sptr& array);
212  FWDATA_API void setPointTexCoordsArray (const ::fwData::Array::sptr& array);
214  FWDATA_API void setCellTexCoordsArray (const ::fwData::Array::sptr& array);
215 
217  FWDATA_API ::fwData::Array::sptr getPointsArray () const;
219  FWDATA_API ::fwData::Array::sptr getCellTypesArray () const;
221  FWDATA_API ::fwData::Array::sptr getCellDataArray () const;
223  FWDATA_API ::fwData::Array::sptr getCellDataOffsetsArray () const;
225  FWDATA_API ::fwData::Array::sptr getPointColorsArray () const;
227  FWDATA_API ::fwData::Array::sptr getCellColorsArray () const;
229  FWDATA_API ::fwData::Array::sptr getPointNormalsArray () const;
231  FWDATA_API ::fwData::Array::sptr getCellNormalsArray () const;
233  FWDATA_API ::fwData::Array::sptr getPointTexCoordsArray () const;
235  FWDATA_API ::fwData::Array::sptr getCellTexCoordsArray () const;
236 
241  FWDATA_API void clearPoints();
242 
247  FWDATA_API void clearCells();
248 
252  FWDATA_API void clear();
253 
255  FWDATA_API void clearPointNormals();
257  FWDATA_API void clearPointColors();
259  FWDATA_API void clearPointTexCoords();
261  FWDATA_API void clearCellNormals();
263  FWDATA_API void clearCellColors();
265  FWDATA_API void clearCellTexCoords();
266 
268  FWDATA_API void setNumberOfPoints(Id nb);
269 
271  FWDATA_API Id getNumberOfPoints() const;
272 
274  FWDATA_API void setNumberOfCells(Id nb);
275 
277  FWDATA_API Id getNumberOfCells() const;
278 
280  FWDATA_API void setCellDataSize(Id nb);
281 
283  FWDATA_API Id getCellDataSize() const;
284 
290  FWDATA_API size_t getDataSizeInBytes() const;
291 
298  FWDATA_API size_t getAllocatedSizeInBytes() const;
299 
301  FWDATA_API void addDataArray(const std::string& name, ::fwData::Array::sptr array);
302 
304  FWDATA_API ::fwData::Array::sptr getDataArray(const std::string& name) const;
305 
307  FWDATA_API void removeDataArray(const std::string& name);
308 
310  FWDATA_API std::vector<std::string> getDataArrayNames() const;
311 
312  /***
313  * @name Signals
314  * @{
315  */
316 
318  typedef ::fwCom::Signal< void () > VertexModifiedSignalType;
319 
321  FWDATA_API static const ::fwCom::Signals::SignalKeyType s_VERTEX_MODIFIED_SIG;
322 
324  typedef ::fwCom::Signal< void () > PointColorsModifiedSignalType;
325 
327  FWDATA_API static const ::fwCom::Signals::SignalKeyType s_POINT_COLORS_MODIFIED_SIG;
328 
330  typedef ::fwCom::Signal< void () > CellColorsModifiedSignalType;
331 
333  FWDATA_API static const ::fwCom::Signals::SignalKeyType s_CELL_COLORS_MODIFIED_SIG;
334 
336  typedef ::fwCom::Signal< void () > PointNormalsModifiedSignalType;
337 
339  FWDATA_API static const ::fwCom::Signals::SignalKeyType s_POINT_NORMALS_MODIFIED_SIG;
340 
342  typedef ::fwCom::Signal< void () > CellNormalsModifiedSignalType;
343 
345  FWDATA_API static const ::fwCom::Signals::SignalKeyType s_CELL_NORMALS_MODIFIED_SIG;
346 
348  typedef ::fwCom::Signal< void () > PointTexCoordsModifiedSignalType;
349 
351  FWDATA_API static const ::fwCom::Signals::SignalKeyType s_POINT_TEX_COORDS_MODIFIED_SIG;
352 
354  typedef ::fwCom::Signal< void () > CellTexCoordsModifiedSignalType;
355 
357  FWDATA_API static const ::fwCom::Signals::SignalKeyType s_CELL_TEX_COORDS_MODIFIED_SIG;
358 
363 protected:
364 
368  FWDATA_API void initArrays();
369 
372 
375 
378 
384  ::fwData::Array::sptr m_points;
385 
391  ::fwData::Array::sptr m_cellTypes;
392 
402  ::fwData::Array::sptr m_cellData;
403 
412  ::fwData::Array::sptr m_cellDataOffsets;
413 
419  ::fwData::Array::sptr m_pointColors;
420 
426  ::fwData::Array::sptr m_cellColors;
427 
433  ::fwData::Array::sptr m_pointNormals;
434 
440  ::fwData::Array::sptr m_cellNormals;
441 
447  ::fwData::Array::sptr m_pointTexCoords;
448 
454  ::fwData::Array::sptr m_cellTexCoords;
455 
457  // analysis.
458  ArrayMapType m_arrayMap;
459 };
460 
461 } // namespace fwData
462 
463 #endif // __FWDATA_MESH_HPP__
464 
::fwCom::Signal< void() > VertexModifiedSignalType
Type of signal when vertex are modified.
Id m_cellsDataSize
Number of point index defined for mesh (size of m_cellData)
::fwData::Array::sptr m_pointNormals
Mesh point array : 3-components 1-dimension uint8_t array, size = m_nbPoints.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_POINT_NORMALS_MODIFIED_SIG
Key in m_signals map of signal m_sigPointNormalsModified.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
This file defines fwCore base macros.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_CELL_COLORS_MODIFIED_SIG
Key in m_signals map of signal m_sigCellColorsModified.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_CELL_NORMALS_MODIFIED_SIG
Key in m_signals map of signal m_sigCellNormalsModified.
::fwData::Array::sptr m_cellDataOffsets
Cell data offsets array : 1-components 1-dimension uint64 array, size = m_nbCells.
::fwData::Array::sptr m_cellTexCoords
Mesh texCoord array : 2-components 1-dimension float array, size = m_nbCells.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_POINT_TEX_COORDS_MODIFIED_SIG
Key in m_signals map of signal m_sigPointTexCoorddModified.
::fwCom::Signal< void() > PointTexCoordsModifiedSignalType
Type of signal when point tex coords are modified.
Id m_nbCells
Number of cells defined for the mesh.
#define fwCoreClassDefinitionsWithFactoryMacro(_classinfo_, _parameters_, _factory_)
Generate common construction methods for classes with one factory.
::fwData::Array::sptr m_pointColors
point colors array : 3 or 4-components 1-dimension float array, size = m_nbPoints.
::fwCom::Signal< void() > CellNormalsModifiedSignalType
Type of signal when cell normals are modified.
::fwCom::Signal< void() > PointNormalsModifiedSignalType
Type of signal when point normals are modified.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_CELL_TEX_COORDS_MODIFIED_SIG
Key in m_signals map of signal m_sigCellTexCoorddModified.
Base class for each data object.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_VERTEX_MODIFIED_SIG
Key in m_signals map of signal m_sigVertexModified.
::fwCom::Signal< void() > CellColorsModifiedSignalType
Type of signal when cell colors are modified.
::fwData::Array::sptr m_pointTexCoords
Mesh texCoord array : 2-components 1-dimension float array, size = m_nbPoints.
Id m_nbPoints
Number of points defined for the mesh.
::fwData::Array::sptr m_cellData
Cell data array : 1-components 1-dimension uint64 array, size = m_cellsDataSize.
ArrayMapType m_arrayMap
Array map where you can add few additional arrays registered thanks to a key to perform/conserve some...
Contains the representation of the data objects used in the framework.
::fwData::Array::sptr m_points
Mesh point array : 3-components 1-dimension float array, size = m_nbPoints x 3.
::fwData::Array::sptr m_cellNormals
Mesh point array : 3-components 1-dimension float array, size = m_nbCells.
::fwCom::Signal< void() > PointColorsModifiedSignalType
Type of signal when point colors are modified.
Data holding a geometric structure composed of points, lines, triangles, quads or polygons...
::fwData::Array::sptr m_cellColors
Mesh point array : 3 or 4-components 1-dimension uint8_t array, size = m_nbCells. ...
::fwData::Array::sptr m_cellTypes
Cell types array : 1-components 1-dimension uint8 array, size = m_nbCells.
::fwCom::Signal< void() > CellTexCoordsModifiedSignalType
Type of signal when cell tex coords are modified.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_POINT_COLORS_MODIFIED_SIG
Key in m_signals map of signal m_sigPointColorsModified.