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>
34 virtual std::unique_ptr<GeometryIndexLayerBase>
clone() = 0;
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;
135 using LayerSemantic = Utils::ObjectWithSemantic::SemanticName;
136 using LayerKeyType = std::pair<LayerSemanticCollection, std::string>;
154 void clear()
override;
162 void checkConsistency()
const;
175 inline bool containsLayer(
const LayerKeyType& layerKey )
const;
183 inline bool containsLayer(
const LayerSemanticCollection& semantics,
184 const std::string& layerName )
const;
191 bool containsLayer(
const LayerSemanticCollection& semantics )
const;
198 bool containsLayer(
const LayerSemantic& semanticName )
const;
206 inline size_t countLayers(
const LayerKeyType& layerKey )
const;
214 inline size_t countLayers(
const LayerSemanticCollection& semantics,
215 const std::string& layerName )
const;
222 size_t countLayers(
const LayerSemanticCollection& semantics )
const;
229 size_t countLayers(
const LayerSemantic& semanticName )
const;
248 const std::string& layerName )
const;
256 std::pair<LayerKeyType, const GeometryIndexLayerBase&>
257 getFirstLayerOccurrence(
const LayerSemanticCollection& semantics )
const;
266 std::pair<LayerKeyType, const GeometryIndexLayerBase&>
267 getFirstLayerOccurrence(
const LayerSemantic& semanticName )
const;
291 const std::string& layerName );
301 std::pair<LayerKeyType, GeometryIndexLayerBase&>
302 getFirstLayerOccurrenceWithLock(
const LayerSemanticCollection& semantics );
312 std::pair<LayerKeyType, GeometryIndexLayerBase&>
313 getFirstLayerOccurrenceWithLock(
const LayerSemantic& semanticName );
324 void unlockLayer(
const LayerKeyType& layerKey );
334 inline void unlockLayer(
const LayerSemanticCollection& semantics,
335 const std::string& layerName );
347 void unlockFirstLayerOccurrence(
const LayerSemanticCollection& semantics );
356 void unlockFirstLayerOccurrence(
const LayerSemantic& semanticName );
368 std::pair<bool, GeometryIndexLayerBase&>
369 addLayer( std::unique_ptr<GeometryIndexLayerBase>&& layer,
370 const bool withLock =
false,
371 const std::string& layerName =
"" );
377 [[nodiscard]]
inline auto layerKeys()
const;
386 using EntryType = std::pair<bool, std::unique_ptr<GeometryIndexLayerBase>>;
388 struct RA_CORE_API KeyHash {
389 std::size_t operator()(
const LayerKeyType& k )
const;
397 std::unordered_map<LayerKeyType, EntryType, KeyHash> m_indices;
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>
472 namespace IndexLayerType {
473 template <
class IndexT>
477 struct getType<Vector2ui> {
482 struct getType<Vector3ui> {
487 struct getType<Vector4ui> {
492 struct getType<VectorNui> {
497 struct getType<Vector1ui> {
513 template <
typename T>
521 using DefaultLayerType =
typename IndexLayerType::getType<IndexType>::Type;
539 inline const LayerKeyType& getLayerKey()
const;
542 LayerKeyType m_mainIndexLayerKey;
545 class RA_CORE_API IndexedPointCloud :
public IndexedGeometry<Vector1ui>
554 class RA_CORE_API PolyMesh :
public IndexedGeometry<VectorNui>
557 class 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" );
579 inline GeometryIndexLayerBase::~GeometryIndexLayerBase() {}
587 template <
typename T>
592 template <
typename T>
598 template <
typename T>
600 if ( shareSemantic( other ) ) {
603 m_collection.end(), othercasted.collection().begin(), othercasted.collection().end() );
609 template <
typename T>
611 if ( shareSemantic( other ) ) {
613 return othercasted.collection() == m_collection;
618 template <
typename T>
620 return m_collection.size();
623 template <
typename T>
625 return IndexType::RowsAtCompileTime;
628 template <
typename T>
630 return m_collection.size() *
sizeof( IndexType );
633 template <
typename T>
635 return sizeof( IndexType );
638 template <
typename T>
640 return m_collection.data();
643 template <
typename T>
645 auto copy = std::make_unique<GeometryIndexLayer<T>>( *this );
646 copy->m_collection = m_collection;
651 inline MultiIndexedGeometry::~MultiIndexedGeometry() {
658 return m_indices.find( layerKey ) != m_indices.end();
663 const std::string& layerName )
const {
669 return m_indices.count( layerKey );
674 const std::string& layerName )
const {
680 return *( m_indices.at( layerKey ).second.get() );
684 const MultiIndexedGeometry::LayerSemanticCollection& semantics,
685 const std::string& layerName ) {
691 const std::string& layerName ) {
704 collection().resize( n );
705 collection().
getMap() = IndexContainerType::Matrix::LinSpaced( n, 0, n - 1 );
707 template <
class... SemanticNames>
711 inline TriangleIndexLayer::TriangleIndexLayer() :
713 template <
class... SemanticNames>
714 inline TriangleIndexLayer::TriangleIndexLayer( SemanticNames... names ) :
717 inline QuadIndexLayer::QuadIndexLayer() :
718 GeometryIndexLayer( QuadIndexLayer::staticSemanticName ) {}
719 template <
class... SemanticNames>
720 inline QuadIndexLayer::QuadIndexLayer( SemanticNames... names ) :
721 GeometryIndexLayer( QuadIndexLayer::staticSemanticName, names... ) {}
723 inline PolyIndexLayer::PolyIndexLayer() :
724 GeometryIndexLayer( PolyIndexLayer::staticSemanticName ) {}
725 template <
class... SemanticNames>
726 inline PolyIndexLayer::PolyIndexLayer( SemanticNames... names ) :
727 GeometryIndexLayer( PolyIndexLayer::staticSemanticName, names... ) {}
729 inline LineIndexLayer::LineIndexLayer() :
730 GeometryIndexLayer( LineIndexLayer::staticSemanticName ) {}
731 template <
class... SemanticNames>
732 inline LineIndexLayer::LineIndexLayer( SemanticNames... names ) :
733 GeometryIndexLayer( LineIndexLayer::staticSemanticName, names... ) {}
735 template <
typename T>
736 inline IndexedGeometry<T>::IndexedGeometry() {
737 auto layer = std::make_unique<DefaultLayerType>();
738 m_mainIndexLayerKey = { layer->semantics(),
"" };
739 addLayer( std::move( layer ) );
742 template <
typename T>
744 inline const typename IndexedGeometry<T>::IndexContainerType&
745 IndexedGeometry<T>::getIndices()
const {
746 const auto& abstractLayer = getLayer( m_mainIndexLayerKey );
747 return static_cast<const IndexedGeometry<T>::DefaultLayerType&
>( abstractLayer ).collection();
749 template <
typename T>
751 auto& abstractLayer = getLayerWithLock( m_mainIndexLayerKey );
752 return static_cast<IndexedGeometry<T>::DefaultLayerType&
>( abstractLayer ).collection();
755 template <
typename T>
757 unlockLayer( m_mainIndexLayerKey );
760 template <
typename T>
762 auto& abstractLayer = getLayerWithLock( m_mainIndexLayerKey );
763 static_cast<IndexedGeometry<T>::DefaultLayerType&
>( abstractLayer ).collection() =
764 std::move( indices );
768 template <
typename T>
770 auto& abstractLayer = getLayerWithLock( m_mainIndexLayerKey );
771 static_cast<IndexedGeometry<T>::DefaultLayerType&
>( abstractLayer ).collection() = indices;
775 template <
typename T>
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 std::unique_ptr< GeometryIndexLayerBase > clone()=0
Create new layer with duplicated content.
virtual bool append(const GeometryIndexLayerBase &other)=0
Append content from another layer.
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.
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 geometry empty.
void unlockLayer(const LayerKeyType &layerKey)
Unlock layer with write acces, notify observers of the update.
const GeometryIndexLayerBase & getLayer(const LayerSemanticCollection &semantics, const std::string &layerName) const
Read-only access to a layer.
This class defines the introspection interface a container need to implement.
Object associated with one or multiple semantic names.
std::set< SemanticName > SemanticNameCollection
Store in set to allow for logarithmic search.
void detachAll()
Detach all observers.
std::enable_if_t<(N > 0), MatrixMap > getMap()
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.