1 #include <Core/Geometry/IndexedGeometry.hpp>
8 MultiIndexedGeometry::MultiIndexedGeometry(
const MultiIndexedGeometry& other ) :
9 AttribArrayGeometry( other ) {
13 MultiIndexedGeometry::MultiIndexedGeometry( MultiIndexedGeometry&& other ) :
14 AttribArrayGeometry( std::move( other ) ), m_indices( std::move( other.m_indices ) ) {}
16 MultiIndexedGeometry::MultiIndexedGeometry(
const AttribArrayGeometry& other ) :
17 AttribArrayGeometry( other ) {}
19 MultiIndexedGeometry::MultiIndexedGeometry( AttribArrayGeometry&& other ) :
20 AttribArrayGeometry( std::move( other ) ) {}
22 MultiIndexedGeometry& MultiIndexedGeometry::operator=(
const MultiIndexedGeometry& other ) {
24 AttribArrayGeometry::operator=( other );
30 MultiIndexedGeometry& MultiIndexedGeometry::operator=( MultiIndexedGeometry&& other ) {
32 AttribArrayGeometry::operator=( std::move( other ) );
33 m_indices = std::move( other.m_indices );
38 void MultiIndexedGeometry::clear() {
40 AttribArrayGeometry::clear();
47 AttribArrayGeometry::copyBaseGeometry( other );
53 void MultiIndexedGeometry::checkConsistency()
const {
59 bool dataHasBeenCopied =
false;
60 for (
const auto& [key, value] : other.m_indices ) {
61 auto it = m_indices.find( key );
62 if ( it == m_indices.end() )
64 m_indices[key] = std::make_pair(
65 value.first, std::unique_ptr<GeometryIndexLayerBase> { value.second->clone() } );
67 dataHasBeenCopied =
true;
71 if ( it->second.second->append( *( value.second ) ) ) { dataHasBeenCopied =
true; }
74 "Inconsistency: layers with different semantics shares the same key" );
79 if ( dataHasBeenCopied ) {
89 bool MultiIndexedGeometry::containsLayer(
const LayerSemantic& semanticName )
const {
90 for (
const auto& [key, value] : m_indices ) {
91 if ( key.first.find( semanticName ) != key.first.end() )
return true;
96 bool MultiIndexedGeometry::containsLayer(
const LayerSemanticCollection& semantics )
const {
97 for (
const auto& [key, value] : m_indices ) {
98 if ( key.first == semantics )
return true;
106 size_t MultiIndexedGeometry::countLayers(
const LayerSemantic& semanticName )
const {
108 for (
const auto& [key, value] : m_indices ) {
109 if ( key.first.find( semanticName ) != key.first.end() ) ++c;
114 size_t MultiIndexedGeometry::countLayers(
const LayerSemanticCollection& semantics )
const {
116 for (
const auto& [key, value] : m_indices ) {
117 if ( key.first == semantics ) ++c;
125 std::pair<MultiIndexedGeometry::LayerKeyType, const GeometryIndexLayerBase&>
126 MultiIndexedGeometry::getFirstLayerOccurrence(
const LayerSemantic& semanticName )
const {
127 for (
const auto& [key, value] : m_indices ) {
128 if ( key.first.find( semanticName ) != key.first.end() )
129 return { key, *( value.second.get() ) };
131 throw std::out_of_range(
"Layer entry not found" );
134 std::pair<MultiIndexedGeometry::LayerKeyType, const GeometryIndexLayerBase&>
135 MultiIndexedGeometry::getFirstLayerOccurrence(
const LayerSemanticCollection& semantics )
const {
136 for (
const auto& [key, value] : m_indices ) {
137 if ( key.first == semantics )
return { key, *( value.second.get() ) };
139 throw std::out_of_range(
"Layer entry not found" );
145 std::pair<MultiIndexedGeometry::LayerKeyType, GeometryIndexLayerBase&>
146 MultiIndexedGeometry::getFirstLayerOccurrenceWithLock(
const LayerSemantic& semanticName ) {
147 for (
auto& [key, value] : m_indices ) {
148 if ( key.first.find( semanticName ) != key.first.end() ) {
149 CORE_ASSERT( !value.first,
"try to get already locked layer" );
151 return { key, *( value.second.get() ) };
154 throw std::out_of_range(
"Layer entry not found" );
157 std::pair<MultiIndexedGeometry::LayerKeyType, GeometryIndexLayerBase&>
158 MultiIndexedGeometry::getFirstLayerOccurrenceWithLock(
const LayerSemanticCollection& semantics ) {
159 for (
auto& [key, value] : m_indices ) {
160 if ( key.first == semantics ) {
161 CORE_ASSERT( !value.first,
"try to get already locked layer" );
163 return { key, *( value.second.get() ) };
166 throw std::out_of_range(
"Layer entry not found" );
170 auto& p = m_indices.at( layerKey );
171 CORE_ASSERT( !p.first,
"try to get already locked layer" );
173 return *( p.second.get() );
179 void MultiIndexedGeometry::unlockFirstLayerOccurrence(
const LayerSemantic& semanticName ) {
180 for (
auto& [key, value] : m_indices ) {
181 if ( key.first.find( semanticName ) != key.first.end() ) {
182 CORE_ASSERT( value.first,
"try to release unlocked layer" );
188 throw std::out_of_range(
"Layer entry not found" );
191 void MultiIndexedGeometry::unlockFirstLayerOccurrence(
const LayerSemanticCollection& semantics ) {
192 for (
auto& [key, value] : m_indices ) {
193 if ( key.first == semantics ) {
194 CORE_ASSERT( value.first,
"try to release unlocked layer" );
200 throw std::out_of_range(
"Layer entry not found" );
203 void MultiIndexedGeometry::unlockLayer(
const LayerKeyType& layerKey ) {
204 auto& p = m_indices.at( layerKey );
205 CORE_ASSERT( p.first,
"try to release unlocked layer" );
213 std::pair<bool, GeometryIndexLayerBase&>
214 MultiIndexedGeometry::addLayer( std::unique_ptr<GeometryIndexLayerBase>&& layer,
216 const std::string& layerName ) {
217 LayerKeyType key { layer->semantics(), layerName };
218 std::pair<LayerKeyType, EntryType> elt { key, std::make_pair(
false, std::move( layer ) ) };
219 auto [pos, inserted] = m_indices.insert( std::move( elt ) );
223 CORE_ASSERT( !pos->second.first,
"try to get already locked layer" );
224 pos->second.first =
true;
229 return { inserted, *( pos->second.second ) };
235 for (
const auto& [key, value] : other.m_indices ) {
236 m_indices[key] = std::make_pair(
237 value.first, std::unique_ptr<GeometryIndexLayerBase> { value.second->clone() } );
241 void MultiIndexedGeometry::deepClear() {
248 std::size_t MultiIndexedGeometry::KeyHash::operator()(
const LayerKeyType& k )
const {
250 std::ostringstream stream;
251 std::copy( k.first.begin(), k.first.end(), std::ostream_iterator<std::string>( stream,
"" ) );
252 std::string result = stream.str();
253 std::sort( result.begin(), result.end() );
256 return std::hash<std::string> {}( result ) ^ ( std::hash<std::string> {}( k.second ) << 1 );
263 auto nbVert = attr.
vertices().size();
264 collection().resize( nbVert );
265 collection().getMap() = IndexContainerType::Matrix::LinSpaced( nbVert, 0, nbVert - 1 );
This class represents vertex + attributes per vertex. Toplogy is handled in MultiIndexedGeometry subc...
const PointAttribHandle::Container & vertices() const
Access the vertices positions.
Base class for index collections stored in MultiIndexedGeometry.
AbstractGeometry with per-vertex attributes and layers of indices. Each layer represents a different ...