diff --git a/code/Importer/IFC/IFCGeometry.cpp b/code/Importer/IFC/IFCGeometry.cpp index ba9098b6f..d49e5cb01 100644 --- a/code/Importer/IFC/IFCGeometry.cpp +++ b/code/Importer/IFC/IFCGeometry.cpp @@ -728,7 +728,7 @@ void ProcessSweptAreaSolid(const Schema_2x3::IfcSweptAreaSolid& swept, TempMesh& } // ------------------------------------------------------------------------------------------------ -bool ProcessGeometricItem(const Schema_2x3::IfcRepresentationItem& geo, unsigned int matid, std::vector& mesh_indices, +bool ProcessGeometricItem(const Schema_2x3::IfcRepresentationItem& geo, unsigned int matid, std::set& mesh_indices, ConversionData& conv) { bool fix_orientation = false; @@ -810,7 +810,7 @@ bool ProcessGeometricItem(const Schema_2x3::IfcRepresentationItem& geo, unsigned aiMesh* const mesh = meshtmp->ToMesh(); if(mesh) { mesh->mMaterialIndex = matid; - mesh_indices.push_back(static_cast(conv.meshes.size())); + mesh_indices.insert(static_cast(conv.meshes.size())); conv.meshes.push_back(mesh); return true; } @@ -818,33 +818,31 @@ bool ProcessGeometricItem(const Schema_2x3::IfcRepresentationItem& geo, unsigned } // ------------------------------------------------------------------------------------------------ -void AssignAddedMeshes(std::vector& mesh_indices,aiNode* nd, +void AssignAddedMeshes(std::set& mesh_indices,aiNode* nd, ConversionData& /*conv*/) { if (!mesh_indices.empty()) { + std::set::const_iterator it = mesh_indices.cbegin(); + std::set::const_iterator end = mesh_indices.cend(); - // make unique - std::sort(mesh_indices.begin(),mesh_indices.end()); - std::vector::iterator it_end = std::unique(mesh_indices.begin(),mesh_indices.end()); - - nd->mNumMeshes = static_cast(std::distance(mesh_indices.begin(),it_end)); + nd->mNumMeshes = static_cast(mesh_indices.size()); nd->mMeshes = new unsigned int[nd->mNumMeshes]; - for(unsigned int i = 0; i < nd->mNumMeshes; ++i) { - nd->mMeshes[i] = mesh_indices[i]; + for(unsigned int i = 0; it != end && i < nd->mNumMeshes; ++i, ++it) { + nd->mMeshes[i] = *it; } } } // ------------------------------------------------------------------------------------------------ bool TryQueryMeshCache(const Schema_2x3::IfcRepresentationItem& item, - std::vector& mesh_indices, unsigned int mat_index, + std::set& mesh_indices, unsigned int mat_index, ConversionData& conv) { ConversionData::MeshCacheIndex idx(&item, mat_index); ConversionData::MeshCache::const_iterator it = conv.cached_meshes.find(idx); if (it != conv.cached_meshes.end()) { - std::copy((*it).second.begin(),(*it).second.end(),std::back_inserter(mesh_indices)); + std::copy((*it).second.begin(),(*it).second.end(),std::inserter(mesh_indices, mesh_indices.end())); return true; } return false; @@ -852,7 +850,7 @@ bool TryQueryMeshCache(const Schema_2x3::IfcRepresentationItem& item, // ------------------------------------------------------------------------------------------------ void PopulateMeshCache(const Schema_2x3::IfcRepresentationItem& item, - const std::vector& mesh_indices, unsigned int mat_index, + const std::set& mesh_indices, unsigned int mat_index, ConversionData& conv) { ConversionData::MeshCacheIndex idx(&item, mat_index); @@ -861,7 +859,7 @@ void PopulateMeshCache(const Schema_2x3::IfcRepresentationItem& item, // ------------------------------------------------------------------------------------------------ bool ProcessRepresentationItem(const Schema_2x3::IfcRepresentationItem& item, unsigned int matid, - std::vector& mesh_indices, + std::set& mesh_indices, ConversionData& conv) { // determine material diff --git a/code/Importer/IFC/IFCLoader.cpp b/code/Importer/IFC/IFCLoader.cpp index 9faf68cbb..a40eedc1d 100644 --- a/code/Importer/IFC/IFCLoader.cpp +++ b/code/Importer/IFC/IFCLoader.cpp @@ -435,7 +435,7 @@ bool ProcessMappedItem(const Schema_2x3::IfcMappedItem& mapped, aiNode* nd_src, msrc = m*msrc; - std::vector meshes; + std::set meshes; const size_t old_openings = conv.collect_openings ? conv.collect_openings->size() : 0; if (conv.apply_openings) { IfcMatrix4 minv = msrc; @@ -550,7 +550,7 @@ void ProcessProductRepresentation(const Schema_2x3::IfcProduct& el, aiNode* nd, // extract Color from metadata, if present unsigned int matid = ProcessMaterials( el.GetID(), std::numeric_limits::max(), conv, false); - std::vector meshes; + std::set meshes; // we want only one representation type, so bring them in a suitable order (i.e try those // that look as if we could read them quickly at first). This way of reading diff --git a/code/Importer/IFC/IFCUtil.h b/code/Importer/IFC/IFCUtil.h index 479772d89..194206d4b 100644 --- a/code/Importer/IFC/IFCUtil.h +++ b/code/Importer/IFC/IFCUtil.h @@ -205,7 +205,7 @@ struct ConversionData bool operator == (const MeshCacheIndex& o) const { return item == o.item && matindex == o.matindex; } bool operator < (const MeshCacheIndex& o) const { return item < o.item || (item == o.item && matindex < o.matindex); } }; - typedef std::map > MeshCache; + typedef std::map > MeshCache; MeshCache cached_meshes; typedef std::map MaterialCache; @@ -281,8 +281,8 @@ unsigned int ProcessMaterials(uint64_t id, unsigned int prevMatId, ConversionDat // IFCGeometry.cpp IfcMatrix3 DerivePlaneCoordinateSpace(const TempMesh& curmesh, bool& ok, IfcVector3& norOut); -bool ProcessRepresentationItem(const Schema_2x3::IfcRepresentationItem& item, unsigned int matid, std::vector& mesh_indices, ConversionData& conv); -void AssignAddedMeshes(std::vector& mesh_indices,aiNode* nd,ConversionData& /*conv*/); +bool ProcessRepresentationItem(const Schema_2x3::IfcRepresentationItem& item, unsigned int matid, std::set& mesh_indices, ConversionData& conv); +void AssignAddedMeshes(std::set& mesh_indices,aiNode* nd,ConversionData& /*conv*/); void ProcessSweptAreaSolid(const Schema_2x3::IfcSweptAreaSolid& swept, TempMesh& meshout, ConversionData& conv);