-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathGeometryData.hpp
More file actions
256 lines (192 loc) · 6.48 KB
/
Copy pathGeometryData.hpp
File metadata and controls
256 lines (192 loc) · 6.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#pragma once
#include <Core/Asset/AssetData.hpp>
#include <Core/Asset/MaterialData.hpp>
#include <Core/Containers/VectorArray.hpp>
#include <Core/Geometry/AttribArrayGeometry.hpp>
#include <Core/Geometry/IndexedGeometry.hpp>
#include <Core/Geometry/StandardAttribNames.hpp>
#include <Core/RaCore.hpp>
#include <Core/Types.hpp>
#include <Core/Utils/Attribs.hpp>
#include <Core/Utils/Index.hpp>
#include <memory>
#include <string>
#include <vector>
#include <algorithm> //std::transform
namespace Ra {
namespace Core {
namespace Asset {
class MaterialData;
/**
* The GeometryData class stores all the geometry related data of a loaded object.
*/
class RA_CORE_API GeometryData : public AssetData
{
public:
using ColorArray = Vector4Array;
public:
/**
* The type of geometry.
*/
enum GeometryType {
UNKNOWN = 1 << 0,
POINT_CLOUD = 1 << 1,
LINE_MESH = 1 << 2,
TRI_MESH = 1 << 3,
QUAD_MESH = 1 << 4,
POLY_MESH = 1 << 5,
TETRA_MESH = 1 << 6,
HEX_MESH = 1 << 7
};
GeometryData( const std::string& name = "", const GeometryType& type = UNKNOWN );
GeometryData( const GeometryData& data ) = delete;
~GeometryData();
/// \name Data access
/// \{
/// Return the name of the object.
inline void setName( const std::string& name );
/// Return the type of geometry.
inline GeometryType getType() const;
/// Set the type of geometry.
inline void setType( const GeometryType& type );
/// Return the Transform of the object.
inline Transform getFrame() const;
/// Set the Transform of the object.
inline void setFrame( const Transform& frame );
/// Return the MaterialData associated to the objet.
inline const MaterialData& getMaterial() const;
/// Set the MaterialData for the object.
inline void setMaterial( MaterialData* material );
/// Read/write access to the multiIndexedGeometry;
inline Geometry::MultiIndexedGeometry& getGeometry();
/// Read only access to the multiIndexedGeometry;
inline const Geometry::MultiIndexedGeometry& getGeometry() const;
/// \}
/// \name Status queries
/// \{
/// Return true if the object is a Point Cloud.
inline bool isPointCloud() const;
/// Return true if the object is a Line Mesh.
inline bool isLineMesh() const;
/// Return true if the object is a Triangle Mesh.
inline bool isTriMesh() const;
/// Return true if the object is a Quadrangle Mesh.
inline bool isQuadMesh() const;
/// Return true if the object is a Polygon Mesh.
/// \note Return false for Triangle and Quadrangle meshes.
inline bool isPolyMesh() const;
/// Return true if the object is a Tetrahedron Mesh.
inline bool isTetraMesh() const;
/// Return true if the object is a Hexahedron Mesh.
inline bool isHexMesh() const;
/// Return true if the object has lines.
inline bool hasEdges() const;
/// Return true if the object has faces.
inline bool hasFaces() const;
/// Return true if the object has polyhedra.
inline bool hasPolyhedra() const;
/// Return true if the object has MaterialData.
inline bool hasMaterial() const;
/// Used to track easily the number of primitives in the geometry data
inline void setPrimitiveCount( int n );
/// Return the number of primitives in the geometry data
inline int getPrimitiveCount() const;
/// \}
/// Print stast info to the Debug output.
void displayInfo() const;
protected:
/// The transformation of the object.
Transform m_frame;
/// The type of geometry for the object.
GeometryType m_type;
/// Named attributes
/// \todo switch to shared ptr ?
Core::Geometry::MultiIndexedGeometry m_geometry;
/// Simple tracking of geometric primitive number
int m_primitiveCount { -1 };
/// The MaterialData for the object.
std::shared_ptr<MaterialData> m_material;
};
inline void GeometryData::setName( const std::string& name ) {
m_name = name;
}
inline GeometryData::GeometryType GeometryData::getType() const {
return m_type;
}
inline void GeometryData::setType( const GeometryType& type ) {
m_type = type;
}
inline Transform GeometryData::getFrame() const {
return m_frame;
}
inline void GeometryData::setFrame( const Transform& frame ) {
m_frame = frame;
}
inline const MaterialData& GeometryData::getMaterial() const {
return *( m_material.get() );
}
inline void GeometryData::setMaterial( MaterialData* material ) {
m_material.reset( material );
}
inline bool GeometryData::isPointCloud() const {
return ( m_type == POINT_CLOUD );
}
inline bool GeometryData::isLineMesh() const {
return ( m_type == LINE_MESH );
}
inline bool GeometryData::isTriMesh() const {
return ( m_type == TRI_MESH );
}
inline bool GeometryData::isQuadMesh() const {
return ( m_type == QUAD_MESH );
}
inline bool GeometryData::isPolyMesh() const {
return ( m_type == POLY_MESH );
}
inline bool GeometryData::isTetraMesh() const {
return ( m_type == TETRA_MESH );
}
inline bool GeometryData::isHexMesh() const {
return ( m_type == HEX_MESH );
}
inline bool GeometryData::hasEdges() const {
return m_geometry.containsLayer( { Geometry::LineIndexLayer::staticSemanticName }, "indices" );
}
inline bool GeometryData::hasFaces() const {
std::string layerSemanticName;
switch ( m_type ) {
case TRI_MESH:
layerSemanticName = std::string( Geometry::TriangleIndexLayer::staticSemanticName );
break;
case QUAD_MESH:
layerSemanticName = std::string( Geometry::QuadIndexLayer::staticSemanticName );
break;
case POLY_MESH:
layerSemanticName = std::string( Geometry::PolyIndexLayer::staticSemanticName );
break;
default:
return false;
}
return m_geometry.containsLayer( { layerSemanticName }, "indices" );
}
inline bool GeometryData::hasPolyhedra() const {
return m_geometry.containsLayer( { Geometry::PolyIndexLayer::staticSemanticName }, "indices" );
}
inline bool GeometryData::hasMaterial() const {
return m_material != nullptr;
}
const Geometry::MultiIndexedGeometry& GeometryData::getGeometry() const {
return m_geometry;
}
Geometry::MultiIndexedGeometry& GeometryData::getGeometry() {
return m_geometry;
}
inline void GeometryData::setPrimitiveCount( int n ) {
m_primitiveCount = n;
}
inline int GeometryData::getPrimitiveCount() const {
return m_primitiveCount;
}
} // namespace Asset
} // namespace Core
} // namespace Ra