MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / packMesh

Function packMesh

source/MRMesh/MRMeshDecimate.cpp:783–847  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

781}
782
783static void packMesh( Mesh & mesh, const DecimateSettings & settings,
784 FaceMap * outFmap = nullptr, VertMap * outVmap = nullptr, WholeEdgeMap * outEmap = nullptr )
785{
786 MR_TIMER;
787 FaceMap fmap;
788 FaceMap *pFmap = settings.region ? &fmap : outFmap;
789 VertMap vmap;
790 VertMap *pVmap = settings.vertForms ? &vmap : outVmap;
791 WholeEdgeMap emap;
792 WholeEdgeMap *pEmap = settings.notFlippable ? &emap : outEmap;
793 mesh.pack( pFmap, pVmap, pEmap );
794
795 if ( settings.region )
796 *settings.region = settings.region->getMapping( fmap, mesh.topology.faceSize() );
797
798 if ( settings.vertForms )
799 {
800 auto & vertForms = *settings.vertForms;
801 for ( VertId oldV{ 0 }; oldV < vmap.size(); ++oldV )
802 if ( auto newV = vmap[oldV] )
803 if ( newV < oldV )
804 vertForms[newV] = vertForms[oldV];
805 vertForms.resize( mesh.topology.vertSize() );
806 }
807
808 auto packedUndirectedEdgeId = [&emap]( UndirectedEdgeId unpackedId )
809 {
810 auto packedEdgeId = emap[unpackedId];
811 return packedEdgeId ? packedEdgeId.undirected() : UndirectedEdgeId();
812 };
813
814 if ( settings.notFlippable )
815 *settings.notFlippable = settings.notFlippable->getMapping( packedUndirectedEdgeId, mesh.topology.undirectedEdgeSize() );
816
817 if ( settings.edgesToCollapse )
818 *settings.edgesToCollapse = settings.edgesToCollapse->getMapping( packedUndirectedEdgeId, mesh.topology.undirectedEdgeSize() );
819
820 if ( settings.twinMap )
821 {
822 UndirectedEdgeHashMap packedTwinMap;
823 packedTwinMap.reserve( settings.twinMap->size() );
824
825 for ( const auto& [key, value] : *settings.twinMap )
826 {
827 auto packedKey = packedUndirectedEdgeId( key );
828 auto packedValue = packedUndirectedEdgeId( value );
829 if ( packedKey && packedValue )
830 packedTwinMap[packedKey] = packedValue;
831 else
832 assert( !packedKey && !packedValue );
833 }
834
835 *settings.twinMap = std::move( packedTwinMap );
836 }
837
838 if ( settings.bdVerts )
839 *settings.bdVerts = settings.bdVerts->getMapping( vmap, mesh.topology.vertSize() );
840

Callers 2

runMethod · 0.85

Calls 9

faceSizeMethod · 0.80
undirectedMethod · 0.80
packMethod · 0.45
getMappingMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45
vertSizeMethod · 0.45
undirectedEdgeSizeMethod · 0.45
reserveMethod · 0.45

Tested by

no test coverage detected