Radium Engine  1.5.0
HandleData.hpp
1 #pragma once
2 
3 #include <Core/Asset/AssetData.hpp>
4 #include <Core/Containers/AlignedStdVector.hpp>
5 #include <Core/RaCore.hpp>
6 #include <Core/Types.hpp>
7 #include <Core/Utils/Log.hpp>
8 
9 #include <map>
10 #include <set>
11 #include <string>
12 #include <vector>
13 
14 namespace Ra {
15 namespace Core {
16 namespace Asset {
17 
21 struct RA_CORE_API HandleComponentData {
22  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
23 
25 
27  std::string m_name;
28 
30  Core::Transform m_frame { Core::Transform::Identity() };
31 
33  std::map<std::string, Core::Transform> m_bindMatrices;
34 
36  std::map<std::string, std::vector<std::pair<uint, Scalar>>> m_weights;
37 };
38 
42 class RA_CORE_API HandleData : public AssetData
43 {
44  public:
45  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
46 
50  enum HandleType { UNKNOWN = 1 << 0, POINT_CLOUD = 1 << 1, SKELETON = 1 << 2, CAGE = 1 << 3 };
51 
52  HandleData( const std::string& name = "", const HandleType& type = UNKNOWN );
53 
54  HandleData( const HandleData& data ) = default;
55 
56  ~HandleData();
57 
60 
64  inline void setName( const std::string& name );
65 
69  inline HandleType getType() const;
70 
74  inline void setType( const HandleType& type );
75 
79  inline Core::Transform getFrame() const;
80 
84  inline void setFrame( const Core::Transform& frame );
85 
89  inline void addBindMesh( const std::string& name );
90 
94  inline const std::set<std::string>& getBindMeshes() const;
96 
100  inline uint getVertexSize() const;
101 
105  inline void setVertexSize( uint size );
106 
110  inline void setNameTable( const std::map<std::string, uint>& nameTable );
111 
115  inline void recomputeAllIndices();
116 
119 
123  inline uint getComponentDataSize() const;
124 
128  inline const Core::AlignedStdVector<HandleComponentData>& getComponentData() const;
129 
133  inline Core::AlignedStdVector<HandleComponentData>& getComponentData();
134 
138  inline const HandleComponentData& getComponent( const uint i ) const;
139 
143  inline HandleComponentData& getComponent( const uint i );
144 
148  inline void setComponents( const Core::AlignedStdVector<HandleComponentData>& components );
149 
153  inline const Core::AlignedStdVector<Core::Vector2ui>& getEdgeData() const;
154 
158  inline Core::AlignedStdVector<Core::Vector2ui>& getEdgeData();
159 
163  inline void setEdges( const Core::AlignedStdVector<Core::Vector2ui>& edgeList );
164 
168  inline const Core::AlignedStdVector<Core::VectorNui>& getFaceData() const;
169 
173  inline Core::AlignedStdVector<Core::VectorNui>& getFaceData();
174 
178  inline void setFaces( const Core::AlignedStdVector<Core::VectorNui>& faceList );
179 
183  inline void needEndNodes( bool need );
185 
188 
192  inline bool isPointCloud() const;
193 
197  inline bool isSkeleton() const;
198 
202  inline bool isCage() const;
203 
207  inline bool hasComponents() const;
208 
212  inline bool hasEdges() const;
213 
217  inline bool hasFaces() const;
218 
222  inline bool needsEndNodes() const;
223 
228  inline int getIndexOf( const std::string& name ) const;
230 
234  inline void displayInfo() const;
235 
236  private:
238  HandleType m_type;
239 
241  Core::Transform m_frame { Core::Transform::Identity() };
242 
244  bool m_endNode { false };
245 
247  uint m_vertexSize { 0 };
248 
250  std::map<std::string, uint> m_nameTable;
251 
253  std::set<std::string> m_bindMeshes;
254 
256  Core::AlignedStdVector<HandleComponentData> m_component;
257 
259  Core::AlignedStdVector<Core::Vector2ui> m_edge;
260 
262  Core::AlignedStdVector<Core::VectorNui> m_face;
263 };
264 
265 inline void HandleData::setName( const std::string& name ) {
266  m_name = name;
267 }
268 
270  return m_type;
271 }
272 
273 inline void HandleData::setType( const HandleType& type ) {
274  m_type = type;
275 }
276 
277 inline Core::Transform HandleData::getFrame() const {
278  return m_frame;
279 }
280 
281 inline void HandleData::setFrame( const Core::Transform& frame ) {
282  m_frame = frame;
283 }
284 
285 inline uint HandleData::getVertexSize() const {
286  return m_vertexSize;
287 }
288 inline void HandleData::setVertexSize( uint size ) {
289  m_vertexSize = size;
290 }
291 
292 inline void HandleData::setNameTable( const std::map<std::string, uint>& nameTable ) {
293  m_nameTable = nameTable;
294 }
295 
296 inline uint HandleData::getComponentDataSize() const {
297  return m_component.size();
298 }
299 
300 inline const Core::AlignedStdVector<HandleComponentData>& HandleData::getComponentData() const {
301  return m_component;
302 }
303 
304 inline Core::AlignedStdVector<HandleComponentData>& HandleData::getComponentData() {
305  return m_component;
306 }
307 
308 inline void
309 HandleData::setComponents( const Core::AlignedStdVector<HandleComponentData>& components ) {
310  const uint size = components.size();
311  m_component.resize( size );
312 #pragma omp parallel for
313  for ( int i = 0; i < int( size ); ++i ) {
314  m_component[i] = components[i];
315  }
316 }
317 
318 inline const HandleComponentData& HandleData::getComponent( const uint i ) const {
319  CORE_ASSERT( ( i < m_component.size() ), "Index i out of bound" );
320  return m_component[i];
321 }
322 
324  CORE_ASSERT( ( i < m_component.size() ), "Index i out of bound" );
325  return m_component[i];
326 }
327 
328 inline const Core::AlignedStdVector<Core::Vector2ui>& HandleData::getEdgeData() const {
329  return m_edge;
330 }
331 
332 inline Core::AlignedStdVector<Core::Vector2ui>& HandleData::getEdgeData() {
333  return m_edge;
334 }
335 
336 inline void HandleData::setEdges( const Core::AlignedStdVector<Core::Vector2ui>& edgeList ) {
337  const uint size = edgeList.size();
338  m_edge.resize( size );
339 #pragma omp parallel for
340  for ( int i = 0; i < int( size ); ++i ) {
341  m_edge[i] = edgeList[i];
342  }
343 }
344 
345 inline const Core::AlignedStdVector<Core::VectorNui>& HandleData::getFaceData() const {
346  return m_face;
347 }
348 
349 inline Core::AlignedStdVector<Core::VectorNui>& HandleData::getFaceData() {
350  return m_face;
351 }
352 
353 inline void HandleData::setFaces( const Core::AlignedStdVector<Core::VectorNui>& faceList ) {
354  const uint size = faceList.size();
355  m_face.resize( size );
356 #pragma omp parallel for
357  for ( int i = 0; i < int( size ); ++i ) {
358  m_face[i] = faceList[i];
359  }
360 }
361 
363  m_nameTable.clear();
364  for ( uint i = 0; i < getComponentDataSize(); ++i ) {
365  m_nameTable[m_component[i].m_name] = i;
366  }
367 }
368 
369 inline bool HandleData::isPointCloud() const {
370  return ( m_type == POINT_CLOUD );
371 }
372 
373 inline bool HandleData::isSkeleton() const {
374  return ( m_type == SKELETON );
375 }
376 
377 inline bool HandleData::isCage() const {
378  return ( m_type == CAGE );
379 }
380 
381 inline bool HandleData::hasComponents() const {
382  return !m_component.empty();
383 }
384 
385 inline bool HandleData::hasEdges() const {
386  return !m_edge.empty();
387 }
388 
389 inline bool HandleData::hasFaces() const {
390  return !m_face.empty();
391 }
392 
393 inline bool HandleData::needsEndNodes() const {
394  return m_endNode;
395 }
396 
397 inline int HandleData::getIndexOf( const std::string& name ) const {
398  auto it = m_nameTable.find( name );
399  if ( it == m_nameTable.end() ) { return -1; }
400  return it->second;
401 }
402 
403 inline void HandleData::needEndNodes( bool need ) {
404  m_endNode = need;
405 }
406 
407 inline void HandleData::addBindMesh( const std::string& name ) {
408  m_bindMeshes.insert( name );
409 }
410 
411 inline const std::set<std::string>& HandleData::getBindMeshes() const {
412  return m_bindMeshes;
413 }
414 
415 inline void HandleData::displayInfo() const {
416  using namespace Core::Utils; // log
417  std::string type;
418  switch ( m_type ) {
419  case POINT_CLOUD:
420  type = "POINT CLOUD";
421  break;
422  case SKELETON:
423  type = "SKELETON";
424  break;
425  case CAGE:
426  type = "CAGE";
427  break;
428  case UNKNOWN:
429  default:
430  type = "UNKNOWN";
431  break;
432  }
433  LOG( logINFO ) << "======== HANDLE INFO ========";
434  LOG( logINFO ) << " Name : " << m_name;
435  LOG( logINFO ) << " Type : " << type;
436  LOG( logINFO ) << " Element # : " << m_component.size();
437  LOG( logINFO ) << " Edge # : " << m_edge.size();
438  LOG( logINFO ) << " Face # : " << m_face.size();
439  LOG( logINFO ) << " Need EndNodes ? : " << ( ( m_endNode ) ? "YES" : "NO" );
440 }
441 
442 } // namespace Asset
443 } // namespace Core
444 } // namespace Ra
void setNameTable(const std::map< std::string, uint > &nameTable)
Definition: HandleData.hpp:292
uint getComponentDataSize() const
Definition: HandleData.hpp:296
const Core::AlignedStdVector< HandleComponentData > & getComponentData() const
Definition: HandleData.hpp:300
int getIndexOf(const std::string &name) const
Definition: HandleData.hpp:397
void setFrame(const Core::Transform &frame)
Definition: HandleData.hpp:281
void setEdges(const Core::AlignedStdVector< Core::Vector2ui > &edgeList)
Definition: HandleData.hpp:336
const Core::AlignedStdVector< Core::VectorNui > & getFaceData() const
Definition: HandleData.hpp:345
void setType(const HandleType &type)
Definition: HandleData.hpp:273
const std::set< std::string > & getBindMeshes() const
Definition: HandleData.hpp:411
const Core::AlignedStdVector< Core::Vector2ui > & getEdgeData() const
Definition: HandleData.hpp:328
HandleType getType() const
Definition: HandleData.hpp:269
void needEndNodes(bool need)
Definition: HandleData.hpp:403
void addBindMesh(const std::string &name)
Definition: HandleData.hpp:407
void setFaces(const Core::AlignedStdVector< Core::VectorNui > &faceList)
Definition: HandleData.hpp:353
const HandleComponentData & getComponent(const uint i) const
Definition: HandleData.hpp:318
Core::Transform getFrame() const
Definition: HandleData.hpp:277
void setComponents(const Core::AlignedStdVector< HandleComponentData > &components)
Definition: HandleData.hpp:309
void setVertexSize(uint size)
Definition: HandleData.hpp:288
void setName(const std::string &name)
Definition: HandleData.hpp:265
Definition: Cage.cpp:3
std::map< std::string, Core::Transform > m_bindMatrices
Per skinned-mesh matrix from mesh space to bone space (local).
Definition: HandleData.hpp:33
std::map< std::string, std::vector< std::pair< uint, Scalar > > > m_weights
Per skinned-mesh vertex weigths.
Definition: HandleData.hpp:36
std::string m_name
Handle name.
Definition: HandleData.hpp:27