3#include <Core/Containers/VectorArray.hpp>
4#include <Core/Geometry/TriangleMesh.hpp>
5#include <Core/Utils/ContainerIntrospectionInterface.hpp>
6#include <Core/Utils/ObjectWithSemantic.hpp>
10#include <unordered_map>
46 template <
class... SemanticNames>
64 inline size_t getSize() const override final;
76 inline const
void*
dataPtr() const override final;
79 template <class... SemanticNames>
83 IndexContainerType m_collection;
154 void clear()
override;
162 void checkConsistency()
const;
175 inline bool containsLayer(
const LayerKeyType& layerKey )
const;
198 bool containsLayer(
const LayerSemantic& semanticName )
const;
206 inline size_t countLayers(
const LayerKeyType& layerKey )
const;
229 size_t countLayers(
const LayerSemantic& semanticName )
const;
267 getFirstLayerOccurrence(
const LayerSemantic& semanticName )
const;
313 getFirstLayerOccurrenceWithLock(
const LayerSemantic& semanticName );
356 void unlockFirstLayerOccurrence(
const LayerSemantic& semanticName );
370 const bool withLock =
false,
377 [[nodiscard]]
inline auto layerKeys()
const;
388 struct RA_CORE_API KeyHash {
416 static constexpr const char* staticSemanticName =
"PointCloud";
419 template <
class... SemanticNames>
427 static constexpr const char* staticSemanticName =
"TriangleMesh";
430 template <
class... SemanticNames>
438 static constexpr const char* staticSemanticName =
"QuadMesh";
441 template <
class... SemanticNames>
450 static constexpr const char* staticSemanticName =
"PolyMesh";
453 template <
class... SemanticNames>
461 static constexpr const char* staticSemanticName =
"LineMesh";
464 template <
class... SemanticNames>
472namespace IndexLayerType {
473template <
class IndexT>
477struct getType<Vector2ui> {
482struct getType<Vector3ui> {
487struct getType<Vector4ui> {
492struct getType<VectorNui> {
497struct getType<Vector1ui> {
521 using DefaultLayerType =
typename IndexLayerType::getType<IndexType>::Type;
554class RA_CORE_API PolyMesh :
public IndexedGeometry<VectorNui>
557class RA_CORE_API LineMesh :
public IndexedGeometry<Vector2ui>
566 CORE_UNUSED( other );
567 CORE_ASSERT( semantics() == other.semantics(),
568 "Try to assign object with different semantics" );
573 CORE_UNUSED( other );
574 CORE_ASSERT( semantics() == other.semantics(),
575 "Try to assign GeometryIndexLayer of different type" );
579inline GeometryIndexLayerBase::~GeometryIndexLayerBase() {}
600 if ( shareSemantic( other ) ) {
603 m_collection.end(), othercasted.collection().begin(), othercasted.collection().end() );
611 if ( shareSemantic( other ) ) {
613 return othercasted.collection() == m_collection;
620 return m_collection.size();
625 return IndexType::RowsAtCompileTime;
630 return m_collection.size() *
sizeof( IndexType );
635 return sizeof( IndexType );
640 return m_collection.data();
645 auto copy = std::make_unique<GeometryIndexLayer<T>>( *this );
646 copy->m_collection = m_collection;
651inline MultiIndexedGeometry::~MultiIndexedGeometry() {
658 return m_indices.find( layerKey ) != m_indices.end();
669 return m_indices.count( layerKey );
680 return *( m_indices.at( layerKey ).second.get() );
705 collection().
getMap() = IndexContainerType::Matrix::LinSpaced( n, 0, n - 1 );
707template <
class... SemanticNames>
711inline TriangleIndexLayer::TriangleIndexLayer() :
713template <
class... SemanticNames>
714inline TriangleIndexLayer::TriangleIndexLayer( SemanticNames... names ) :
717inline QuadIndexLayer::QuadIndexLayer() :
718 GeometryIndexLayer( QuadIndexLayer::staticSemanticName ) {}
719template <
class... SemanticNames>
720inline QuadIndexLayer::QuadIndexLayer( SemanticNames... names ) :
721 GeometryIndexLayer( QuadIndexLayer::staticSemanticName, names... ) {}
723inline PolyIndexLayer::PolyIndexLayer() :
724 GeometryIndexLayer( PolyIndexLayer::staticSemanticName ) {}
725template <
class... SemanticNames>
726inline PolyIndexLayer::PolyIndexLayer( SemanticNames... names ) :
727 GeometryIndexLayer( PolyIndexLayer::staticSemanticName, names... ) {}
729inline LineIndexLayer::LineIndexLayer() :
730 GeometryIndexLayer( LineIndexLayer::staticSemanticName ) {}
731template <
class... SemanticNames>
732inline LineIndexLayer::LineIndexLayer( SemanticNames... names ) :
733 GeometryIndexLayer( LineIndexLayer::staticSemanticName, names... ) {}
736inline IndexedGeometry<T>::IndexedGeometry() {
737 auto layer = std::make_unique<DefaultLayerType>();
738 m_mainIndexLayerKey = { layer->semantics(),
"" };
744inline const typename IndexedGeometry<T>::IndexContainerType&
745IndexedGeometry<T>::getIndices()
const {
746 const auto& abstractLayer = getLayer( m_mainIndexLayerKey );
747 return static_cast<const IndexedGeometry<T>::DefaultLayerType&
>( abstractLayer ).collection();
751 auto& abstractLayer = getLayerWithLock( m_mainIndexLayerKey );
752 return static_cast<IndexedGeometry<T>::DefaultLayerType&
>( abstractLayer ).collection();
757 unlockLayer( m_mainIndexLayerKey );
762 auto& abstractLayer = getLayerWithLock( m_mainIndexLayerKey );
763 static_cast<IndexedGeometry<T>::DefaultLayerType&
>( abstractLayer ).collection() =
770 auto& abstractLayer = getLayerWithLock( m_mainIndexLayerKey );
771 static_cast<IndexedGeometry<T>::DefaultLayerType&
>( abstractLayer ).collection() = indices;
777 return m_mainIndexLayerKey;
This class represents vertex + attributes per vertex. Toplogy is handled in MultiIndexedGeometry subc...
Base class for index collections stored in MultiIndexedGeometry.
GeometryIndexLayerBase(SemanticNames... names)
Hidden constructor that must be called by inheriting classes to define the object semantics.
virtual bool append(const GeometryIndexLayerBase &other)=0
Append content from another layer.
virtual std::unique_ptr< GeometryIndexLayerBase > clone()=0
Create new layer with duplicated content.
virtual bool operator==(const GeometryIndexLayerBase &other) const
Compare if two layers have the same content.
GeometryIndexLayerBase(const GeometryIndexLayerBase &other)
Copy constructor.
GeometryIndexLayerBase & operator=(const GeometryIndexLayerBase &other)
Assignment operator.
A single layer MultiIndexedGeometry.
IndexContainerType & getIndicesWithLock()
void indicesUnlock()
unlock previously read write acces, notify observers of the update.
void setIndices(IndexContainerType &&indices)
AbstractGeometry with per-vertex attributes and layers of indices. Each layer represents a different ...
const GeometryIndexLayerBase & getLayer(const LayerKeyType &layerKey) const
Read-only access to a layer.
const GeometryIndexLayerBase & getLayer(const LayerSemanticCollection &semantics, const std::string &layerName) const
Read-only access to a layer.
auto layerKeys() const
Range on layer keys (read-only)
size_t countLayers(const LayerKeyType &layerKey) const
Count the number of layer matching the input parameters.
bool containsLayer(const LayerKeyType &layerKey) const
Check if at least one layer with such properties exists.
GeometryIndexLayerBase & getLayerWithLock(const LayerKeyType &layerKey)
Write access to a layer.
void clear() override
Erases all data, making the AttribArrayGeometry empty.
void unlockLayer(const LayerKeyType &layerKey)
Unlock layer with write acces, notify observers of the update.
This class defines the introspection interface a container need to implement.
Object associated with one or multiple semantic names.
std::enable_if_t<(N > 0), MatrixMap > getMap()
@ Geometry
"Geometry" render objects are those loaded using Radium::IO and generated by GeometrySystem
hepler function to manage enum as underlying types in VariableSet
bool append(const GeometryIndexLayerBase &other) final
Append content from another layer.
size_t getSize() const override final
const void * dataPtr() const override final
size_t getBufferSize() const override final
int getStride() const override final
size_t getNumberOfComponents() const override final
bool operator==(const GeometryIndexLayerBase &other) const final
std::unique_ptr< GeometryIndexLayerBase > clone() override final
Create new layer with duplicated content.
Index layer for line mesh.
Index layer for a point cloud.
PointCloudIndexLayer()
Constructor of an empty layer.
Index layer for polygonal mesh.
Index layer for quadrilateral mesh.
Index layer for triangle mesh.
Generate a range to iterate over the keys of a map.