Radium Engine  1.5.0
GeometryData.hpp
1 #pragma once
2 
3 #include <Core/Asset/AssetData.hpp>
4 #include <Core/Asset/MaterialData.hpp>
5 #include <Core/Containers/VectorArray.hpp>
6 #include <Core/Geometry/StandardAttribNames.hpp>
7 #include <Core/Geometry/TriangleMesh.hpp>
8 #include <Core/RaCore.hpp>
9 #include <Core/Types.hpp>
10 #include <Core/Utils/Attribs.hpp>
11 #include <Core/Utils/Index.hpp>
12 
13 #include <memory>
14 #include <string>
15 #include <vector>
16 
17 #include <algorithm> //std::transform
18 
19 namespace Ra {
20 namespace Core {
21 namespace Asset {
22 
23 class MaterialData;
24 
28 class RA_CORE_API GeometryData : public AssetData
29 {
30  public:
31  using ColorArray = Vector4Array;
32 
33  public:
34  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
35 
39  enum GeometryType {
40  UNKNOWN = 1 << 0,
41  POINT_CLOUD = 1 << 1,
42  LINE_MESH = 1 << 2,
43  TRI_MESH = 1 << 3,
44  QUAD_MESH = 1 << 4,
45  POLY_MESH = 1 << 5,
46  TETRA_MESH = 1 << 6,
47  HEX_MESH = 1 << 7
48  };
49 
50  GeometryData( const std::string& name = "", const GeometryType& type = UNKNOWN );
51 
52  GeometryData( const GeometryData& data ) = delete;
53 
54  ~GeometryData();
55 
58 
60  inline void setName( const std::string& name );
61 
63  inline GeometryType getType() const;
64 
66  inline void setType( const GeometryType& type );
67 
69  inline Transform getFrame() const;
70 
72  inline void setFrame( const Transform& frame );
73 
75  inline const MaterialData& getMaterial() const;
76 
78  inline void setMaterial( MaterialData* material );
79 
81  inline Geometry::MultiIndexedGeometry& getGeometry();
82 
84  inline const Geometry::MultiIndexedGeometry& getGeometry() const;
85 
87 
90 
92  inline bool isPointCloud() const;
93 
95  inline bool isLineMesh() const;
96 
98  inline bool isTriMesh() const;
99 
101  inline bool isQuadMesh() const;
102 
105  inline bool isPolyMesh() const;
106 
108  inline bool isTetraMesh() const;
109 
111  inline bool isHexMesh() const;
112 
114  inline bool hasEdges() const;
115 
117  inline bool hasFaces() const;
118 
120  inline bool hasPolyhedra() const;
121 
123  inline bool hasMaterial() const;
124 
126  inline void setPrimitiveCount( int n );
127 
129  inline int getPrimitiveCount() const;
130 
132 
134  void displayInfo() const;
135 
136  protected:
138  Transform m_frame;
139 
142 
145 
147  int m_primitiveCount { -1 };
148 
150  std::shared_ptr<MaterialData> m_material;
151 };
152 
153 inline void GeometryData::setName( const std::string& name ) {
154  m_name = name;
155 }
156 
158  return m_type;
159 }
160 
161 inline void GeometryData::setType( const GeometryType& type ) {
162  m_type = type;
163 }
164 
165 inline Transform GeometryData::getFrame() const {
166  return m_frame;
167 }
168 
169 inline void GeometryData::setFrame( const Transform& frame ) {
170  m_frame = frame;
171 }
172 
174  return *( m_material.get() );
175 }
176 
177 inline void GeometryData::setMaterial( MaterialData* material ) {
178  m_material.reset( material );
179 }
180 
181 inline bool GeometryData::isPointCloud() const {
182  return ( m_type == POINT_CLOUD );
183 }
184 
185 inline bool GeometryData::isLineMesh() const {
186  return ( m_type == LINE_MESH );
187 }
188 
189 inline bool GeometryData::isTriMesh() const {
190  return ( m_type == TRI_MESH );
191 }
192 
193 inline bool GeometryData::isQuadMesh() const {
194  return ( m_type == QUAD_MESH );
195 }
196 
197 inline bool GeometryData::isPolyMesh() const {
198  return ( m_type == POLY_MESH );
199 }
200 
201 inline bool GeometryData::isTetraMesh() const {
202  return ( m_type == TETRA_MESH );
203 }
204 
205 inline bool GeometryData::isHexMesh() const {
206  return ( m_type == HEX_MESH );
207 }
208 
209 inline bool GeometryData::hasEdges() const {
210  return m_geometry.containsLayer( { Geometry::LineIndexLayer::staticSemanticName }, "indices" );
211 }
212 
213 inline bool GeometryData::hasFaces() const {
214  std::string layerSemanticName;
215  switch ( m_type ) {
216  case TRI_MESH:
217  layerSemanticName = std::string( Geometry::TriangleIndexLayer::staticSemanticName );
218  break;
219  case QUAD_MESH:
220  layerSemanticName = std::string( Geometry::QuadIndexLayer::staticSemanticName );
221  break;
222  case POLY_MESH:
223  layerSemanticName = std::string( Geometry::PolyIndexLayer::staticSemanticName );
224  break;
225  default:
226  return false;
227  }
228  return m_geometry.containsLayer( { layerSemanticName }, "indices" );
229 }
230 
231 inline bool GeometryData::hasPolyhedra() const {
232  return m_geometry.containsLayer( { Geometry::PolyIndexLayer::staticSemanticName }, "indices" );
233 }
234 
235 inline bool GeometryData::hasMaterial() const {
236  return m_material != nullptr;
237 }
238 
240  return m_geometry;
241 }
242 
244  return m_geometry;
245 }
246 
247 inline void GeometryData::setPrimitiveCount( int n ) {
248  m_primitiveCount = n;
249 }
251  return m_primitiveCount;
252 }
253 
254 } // namespace Asset
255 } // namespace Core
256 } // namespace Ra
int getPrimitiveCount() const
Return the number of primitives in the geometry data.
bool isLineMesh() const
Return true if the object is a Line Mesh.
int m_primitiveCount
Simple tracking of geometric primitive number.
bool isTetraMesh() const
Return true if the object is a Tetrahedron Mesh.
bool isTriMesh() const
Return true if the object is a Triangle Mesh.
bool hasFaces() const
Return true if the object has faces.
Transform m_frame
The transformation of the object.
GeometryType m_type
The type of geometry for the object.
bool isQuadMesh() const
Return true if the object is a Quadrangle Mesh.
bool isHexMesh() const
Return true if the object is a Hexahedron Mesh.
const MaterialData & getMaterial() const
Return the MaterialData associated to the objet.
void setMaterial(MaterialData *material)
Set the MaterialData for the object.
void setPrimitiveCount(int n)
Used to track easily the number of primitives in the geometry data.
void setType(const GeometryType &type)
Set the type of geometry.
GeometryType getType() const
Return the type of geometry.
Geometry::MultiIndexedGeometry & getGeometry()
Read/write access to the multiIndexedGeometry;.
std::shared_ptr< MaterialData > m_material
The MaterialData for the object.
bool hasPolyhedra() const
Return true if the object has polyhedra.
Core::Geometry::MultiIndexedGeometry m_geometry
Named attributes.
void setFrame(const Transform &frame)
Set the Transform of the object.
void setName(const std::string &name)
Return the name of the object.
Transform getFrame() const
Return the Transform of the object.
bool hasMaterial() const
Return true if the object has MaterialData.
bool isPointCloud() const
Return true if the object is a Point Cloud.
bool hasEdges() const
Return true if the object has lines.
represent material data loaded by a file loader. Material data must be identified by a unique name....
AbstractGeometry with per-vertex attributes and layers of indices. Each layer represents a different ...
bool containsLayer(const LayerKeyType &layerKey) const
Check if at least one layer with such properties exists.
Definition: Cage.cpp:3