3 #include <Core/Containers/VectorArray.hpp>
4 #include <Core/Geometry/AbstractGeometry.hpp>
5 #include <Core/Geometry/StandardAttribNames.hpp>
6 #include <Core/RaCore.hpp>
8 #include <Core/Utils/Attribs.hpp>
9 #include <Core/Utils/Color.hpp>
10 #include <Core/Utils/Observable.hpp>
28 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
30 using Point = Vector3;
31 using Normal = Vector3;
67 void clear()
override;
70 inline void setVertices( PointAttribHandle::Container&& vertices );
72 inline void setVertices(
const PointAttribHandle::Container& vertices );
75 inline const PointAttribHandle::Container& vertices()
const;
78 inline void setNormals( PointAttribHandle::Container&& normals );
80 inline void setNormals(
const PointAttribHandle::Container& normals );
83 inline const NormalAttribHandle::Container& normals()
const;
102 template <
typename T>
106 template <
typename T>
109 template <
typename T>
113 template <
typename T>
116 template <
typename T>
127 inline bool hasAttrib(
const std::string& name )
const;
134 template <
typename T>
141 template <
typename T>
149 template <
typename T>
156 template <
typename T>
160 inline void clearAttributes();
172 template <
typename... Handles>
182 inline Aabb computeAabb()
const override;
199 inline PointAttribHandle::Container& verticesWithLock();
202 inline void verticesUnlock();
206 inline NormalAttribHandle::Container& normalsWithLock();
209 inline void normalsUnlock();
213 inline void initDefaultAttribs();
218 template <
typename T>
240 m_verticesHandle = other.m_verticesHandle;
241 m_normalsHandle = other.m_normalsHandle;
245 m_vertexAttribs( std::move( other.m_vertexAttribs ) ),
246 m_verticesHandle( std::move( other.m_verticesHandle ) ),
247 m_normalsHandle( std::move( other.m_normalsHandle ) ) {}
250 if (
this != &other ) {
251 m_vertexAttribs.
clear();
253 m_verticesHandle = other.m_verticesHandle;
254 m_normalsHandle = other.m_normalsHandle;
262 if (
this != &other ) {
263 m_vertexAttribs = std::move( other.m_vertexAttribs );
264 m_verticesHandle = std::move( other.m_verticesHandle );
265 m_normalsHandle = std::move( other.m_normalsHandle );
273 m_vertexAttribs.
clear();
275 initDefaultAttribs();
282 other.m_vertexAttribs, other.m_verticesHandle, other.m_normalsHandle );
286 template <
typename... Handles>
288 Handles... attribs ) {
291 m_vertexAttribs.
copyAttributes( input.m_vertexAttribs, attribs... );
305 if ( !isAabbValid() ) {
307 for (
const auto& v :
vertices() ) {
322 m_vertexAttribs.
setAttrib<PointAttribHandle::value_type>( m_verticesHandle,
vertices );
326 inline const AttribArrayGeometry::PointAttribHandle::Container&
328 return m_vertexAttribs.
getAttrib( m_verticesHandle ).data();
338 inline const AttribArrayGeometry::NormalAttribHandle::Container&
340 return m_vertexAttribs.
getAttrib( m_normalsHandle ).data();
343 template <
typename T>
349 template <
typename T>
351 return m_vertexAttribs.
isValid( h );
354 template <
typename T>
359 template <
typename T>
373 template <
typename T>
375 return m_vertexAttribs.
getAttrib<T>( name );
378 template <
typename T>
380 return m_vertexAttribs.
getAttrib<T>( name );
384 return m_vertexAttribs.
contains( name );
387 template <
typename T>
390 return m_vertexAttribs.
addAttrib<T>( name );
393 template <
typename T>
397 auto handle = addAttrib<T>( name );
403 template <
typename T>
407 auto handle = addAttrib<T>( name );
408 getAttrib( handle ).setData( std::move( data ) );
413 template <
typename T>
420 return m_vertexAttribs;
424 return m_vertexAttribs;
428 return m_vertexAttribs.
getAttrib( m_verticesHandle ).getDataWithLock();
432 return m_vertexAttribs.
getAttrib( m_verticesHandle ).unlock();
436 return m_vertexAttribs.
getAttrib( m_normalsHandle ).getDataWithLock();
440 return m_vertexAttribs.
getAttrib( m_normalsHandle ).unlock();
443 inline void AttribArrayGeometry::initDefaultAttribs() {
444 m_verticesHandle = m_vertexAttribs.
addAttrib<PointAttribHandle::value_type>(
445 getAttribName( MeshAttrib::VERTEX_POSITION ) );
446 m_normalsHandle = m_vertexAttribs.
addAttrib<NormalAttribHandle::value_type>(
447 getAttribName( MeshAttrib::VERTEX_NORMAL ) );
451 template <
typename T>
454 auto& v0 = m_vertexAttribs.
getAttrib( h ).getDataWithLock();
455 const auto& v1 = attr->
cast<T>().data();
456 v0.insert( v0.end(), v1.cbegin(), v1.cend() );
465 #include "IndexedGeometry.hpp"
This class represents vertex + attributes per vertex. Toplogy is handled in MultiIndexedGeometry subc...
virtual void copyBaseGeometry(const AttribArrayGeometry &other)
Utils::AttribHandle< T > getAttribHandle(const std::string &name) const
bool isValid(const Utils::AttribHandle< T > &h) const
Return true if h refers to an existing attribute in *this.
NormalAttribHandle::Container & normalsWithLock()
bool copyAttributes(const AttribArrayGeometry &input, Handles... attribs)
Aabb computeAabb() const override
Compute bounding box.
Utils::Attrib< T > * getAttribPtr(const Utils::AttribHandle< T > &h)
void setNormals(PointAttribHandle::Container &&normals)
Set normals.
bool hasAttrib(const std::string &name) const
AttribArrayGeometry & operator=(const AttribArrayGeometry &other)
void normalsUnlock()
Release lock on vertices normals.
void clear() override
Erases all data, making the AttribArrayGeometry empty.
PointAttribHandle::Container & verticesWithLock()
void verticesUnlock()
Release lock on vertices positions.
void setVertices(PointAttribHandle::Container &&vertices)
Set vertices.
AttribArrayGeometry()
Create an empty geometry.
Utils::AttribBase * getAttribBase(const std::string &name)
bool copyAllAttributes(const AttribArrayGeometry &input)
const NormalAttribHandle::Container & normals() const
Access the vertices normals.
void removeAttrib(Utils::AttribHandle< T > &h)
const PointAttribHandle::Container & vertices() const
Access the vertices positions.
const Utils::Attrib< T > * getAttribPtr(const Utils::AttribHandle< T > &h) const
Utils::AttribHandle< T > addAttrib(const std::string &name)
Utils::Attrib< T > & getAttrib(const Utils::AttribHandle< T > &h)
Utils::AttribManager & vertexAttribs()
Attrib< T > & cast()
Downcast from AttribBase to Attrib<T>.
std::string getName() const
Return the attribute's name.
The AttribManager provides attributes management by handles.
void setAttrib(const AttribHandle< T > &h, const typename AttribHandle< T >::Container &data)
void copyAllAttributes(const AttribManager &m)
AttribBase * getAttribBase(const std::string &name)
AttribHandle< T > addAttrib(const std::string &name)
void copyAttributes(const AttribManager &m)
Base copy, does nothing.
bool contains(const std::string &name) const
contains Check if an attribute with the given name exists.
Attrib< T > & getAttrib(const AttribHandle< T > &h)
bool isValid(const AttribHandle< T > &h) const
Return true if h correspond to an existing attribute in *this.
void clear()
clear all attribs, invalidate handles.
void removeAttrib(AttribHandle< T > &h)
AttribHandle< T > findAttrib(const std::string &name) const
findAttrib Grab an attribute handler by name.