Skip to content

Commit 4dca722

Browse files
authored
PartMapping: rename fields (#4560)
1 parent efacbd7 commit 4dca722

File tree

9 files changed

+80
-75
lines changed

9 files changed

+80
-75
lines changed

source/MRMesh/MRFixSelfIntersections.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,17 +230,17 @@ Expected<void> fix( Mesh& mesh, const Settings& settings )
230230
// Helper function to find own self-intersections on a mesh part
231231
static Expected<FaceBitSet> findSelfCollidingTrianglesBSForPart( Mesh& mesh, const FaceBitSet& part, ProgressCallback cb, bool touchIsIntersection )
232232
{
233-
FaceMap tgt2srcFaces;
233+
FaceMap tgt2srcFaceMap;
234234
PartMapping mapping;
235-
mapping.tgt2srcFaces = &tgt2srcFaces;
235+
mapping.tgt2srcFaceMap = &tgt2srcFaceMap;
236236
Mesh partMesh = mesh.cloneRegion( part, false, mapping );
237237
// Faster than searching in mesh part due to AABB tree rebuild
238238
auto res = findSelfCollidingTrianglesBS( { partMesh }, cb, nullptr, touchIsIntersection );
239239
if ( !res.has_value() )
240240
return unexpected( res.error() );
241241
FaceBitSet result( mesh.topology.lastValidFace() + 1 );
242242
for ( FaceId f : *res )
243-
result.set( tgt2srcFaces[f] );
243+
result.set( tgt2srcFaceMap[f] );
244244
return result;
245245
}
246246

source/MRMesh/MRMesh.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,14 +401,14 @@ void Mesh::addPartBy( const Mesh & from, I fbegin, I fend, size_t fcount, bool f
401401
MR_TIMER;
402402

403403
VertHashMap localVmap;
404-
if ( !map.src2tgtVerts )
405-
map.src2tgtVerts = &localVmap;
404+
if ( !map.src2tgtVertHashMap )
405+
map.src2tgtVertHashMap = &localVmap;
406406
topology.addPartBy( from.topology, fbegin, fend, fcount, flipOrientation, thisContours, fromContours, map );
407407
VertId lastPointId = topology.lastValidVert();
408408
if ( points.size() < lastPointId + 1 )
409409
points.resize( lastPointId + 1 );
410410

411-
for ( const auto & [ fromVert, thisVert ] : *map.src2tgtVerts )
411+
for ( const auto & [ fromVert, thisVert ] : *map.src2tgtVertHashMap )
412412
points[thisVert] = from.points[fromVert];
413413

414414
invalidateCaches();

source/MRMesh/MRMeshTopology.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,12 +1737,12 @@ void MeshTopology::addPartBy( const MeshTopology & from, I fbegin, I fend, size_
17371737
emap.reserve( std::min( 2 * fcount, from.undirectedEdgeSize() ) ); // if whole connected component is copied then ecount=3/2*fcount; if unconnected triangles are copied then ecount=3*fcount
17381738
VertHashMap vmap;
17391739
vmap.reserve( std::min( fcount, from.vertSize() ) ); // if whole connected component is copied then vcount=1/2*fcount; if unconnected triangles are copied then vcount=3*fcount
1740-
if ( map.tgt2srcEdges )
1741-
map.tgt2srcEdges->resize( undirectedEdgeSize() );
1742-
if ( map.tgt2srcVerts )
1743-
map.tgt2srcVerts->resize( vertSize() );
1744-
if ( map.tgt2srcFaces )
1745-
map.tgt2srcFaces->resize( faceSize() );
1740+
if ( map.tgt2srcWholeEdgeMap )
1741+
map.tgt2srcWholeEdgeMap->resize( undirectedEdgeSize() );
1742+
if ( map.tgt2srcVertMap )
1743+
map.tgt2srcVertMap->resize( vertSize() );
1744+
if ( map.tgt2srcFaceMap )
1745+
map.tgt2srcFaceMap->resize( faceSize() );
17461746

17471747
VertBitSet fromVerts = from.getValidVerts();
17481748
auto setVmap = [&] ( VertId key, VertId val )
@@ -1806,9 +1806,9 @@ void MeshTopology::addPartBy( const MeshTopology & from, I fbegin, I fend, size_
18061806
assert( inserted );
18071807
edges_.push_back( from.edges_[EdgeId{ ue }] );
18081808
edges_.push_back( from.edges_[EdgeId{ ue }.sym()] );
1809-
if ( map.tgt2srcEdges )
1809+
if ( map.tgt2srcWholeEdgeMap )
18101810
{
1811-
map.tgt2srcEdges->push_back( EdgeId{ ue } );
1811+
map.tgt2srcWholeEdgeMap->push_back( EdgeId{ ue } );
18121812
}
18131813
}
18141814
if ( auto v = from.org( e ); v.valid() )
@@ -1818,8 +1818,8 @@ void MeshTopology::addPartBy( const MeshTopology & from, I fbegin, I fend, size_
18181818
auto nv = addVertId();
18191819
[[maybe_unused]] bool inserted = vmap.insert( { v, nv } ).second;
18201820
assert( inserted );
1821-
if ( map.tgt2srcVerts )
1822-
map.tgt2srcVerts->push_back( v );
1821+
if ( map.tgt2srcVertMap )
1822+
map.tgt2srcVertMap->push_back( v );
18231823
edgePerVertex_[nv] = mapEdge( emap, e );
18241824
if ( updateValids_ )
18251825
{
@@ -1830,8 +1830,8 @@ void MeshTopology::addPartBy( const MeshTopology & from, I fbegin, I fend, size_
18301830
}
18311831
}
18321832
auto nf = addFaceId();
1833-
if ( map.tgt2srcFaces )
1834-
map.tgt2srcFaces ->push_back( f );
1833+
if ( map.tgt2srcFaceMap )
1834+
map.tgt2srcFaceMap ->push_back( f );
18351835
fmap[f] = nf;
18361836
edgePerFace_[nf] = mapEdge( emap, flipOrientation ? efrom.sym() : efrom );
18371837
if ( updateValids_ )
@@ -1936,19 +1936,19 @@ void MeshTopology::addPartBy( const MeshTopology & from, I fbegin, I fend, size_
19361936
edges_[eNx].prev = ePr;
19371937
}
19381938

1939-
if ( map.tgt2srcEdges )
1940-
assert( map.tgt2srcEdges->size() == undirectedEdgeSize() );
1941-
if ( map.tgt2srcVerts )
1942-
assert( map.tgt2srcVerts->size() == vertSize() );
1943-
if ( map.tgt2srcFaces )
1944-
assert( map.tgt2srcFaces->size() == faceSize() );
1945-
1946-
if ( map.src2tgtFaces )
1947-
*map.src2tgtFaces = std::move( fmap );
1948-
if ( map.src2tgtVerts )
1949-
*map.src2tgtVerts = std::move( vmap );
1950-
if ( map.src2tgtEdges )
1951-
*map.src2tgtEdges = std::move( emap );
1939+
if ( map.tgt2srcWholeEdgeMap )
1940+
assert( map.tgt2srcWholeEdgeMap->size() == undirectedEdgeSize() );
1941+
if ( map.tgt2srcVertMap )
1942+
assert( map.tgt2srcVertMap->size() == vertSize() );
1943+
if ( map.tgt2srcFaceMap )
1944+
assert( map.tgt2srcFaceMap->size() == faceSize() );
1945+
1946+
if ( map.src2tgtFaceHashMap )
1947+
*map.src2tgtFaceHashMap = std::move( fmap );
1948+
if ( map.src2tgtVertHashMap )
1949+
*map.src2tgtVertHashMap = std::move( vmap );
1950+
if ( map.src2tgtWholeEdgeHashMap )
1951+
*map.src2tgtWholeEdgeHashMap = std::move( emap );
19521952
}
19531953

19541954
template MRMESH_API void MeshTopology::addPartBy( const MeshTopology & from,

source/MRMesh/MRObjectMesh.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,9 @@ std::shared_ptr<MR::ObjectMesh> cloneRegion( const std::shared_ptr<ObjectMesh>&
415415
FaceMap faceMap;
416416
PartMapping partMapping;
417417
if ( !objMesh->getVertsColorMap().empty() || !objMesh->getUVCoords().empty() )
418-
partMapping.tgt2srcVerts = &vertMap;
418+
partMapping.tgt2srcVertMap = &vertMap;
419419
if ( !objMesh->getFacesColorMap().empty() || !objMesh->getTexturePerFace().empty() )
420-
partMapping.tgt2srcFaces = &faceMap;
420+
partMapping.tgt2srcFaceMap = &faceMap;
421421
std::shared_ptr<Mesh> newMesh = std::make_shared<Mesh>( objMesh->mesh()->cloneRegion( region, false, partMapping ) );
422422
std::shared_ptr<ObjectMesh> newObj = std::make_shared<ObjectMesh>();
423423
newObj->setFrontColor( objMesh->getFrontColor( true ), true );

source/MRMesh/MRPartMapping.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,40 @@
44
namespace MR
55
{
66

7+
void PartMapping::clear()
8+
{
9+
if ( src2tgtFaceHashMap )
10+
src2tgtFaceHashMap->clear();
11+
if ( src2tgtVertHashMap )
12+
src2tgtVertHashMap->clear();
13+
if ( src2tgtWholeEdgeHashMap )
14+
src2tgtWholeEdgeHashMap->clear();
15+
if ( tgt2srcFaceMap )
16+
tgt2srcFaceMap->clear();
17+
if ( tgt2srcVertMap )
18+
tgt2srcVertMap->clear();
19+
if ( tgt2srcWholeEdgeMap )
20+
tgt2srcWholeEdgeMap->clear();
21+
}
22+
723
HashToVectorMappingConverter::HashToVectorMappingConverter( const MeshTopology & srcTopology, FaceMap * outFmap, VertMap * outVmap, WholeEdgeMap * outEmap )
824
: outFmap_( outFmap ), outVmap_( outVmap ), outEmap_( outEmap )
925
{
1026
if ( outFmap )
1127
{
12-
map_.src2tgtFaces = &src2tgtFaces_;
28+
map_.src2tgtFaceHashMap = &src2tgtFaces_;
1329
outFmap->clear();
1430
outFmap->resize( (int)srcTopology.lastValidFace() + 1 );
1531
}
1632
if ( outVmap )
1733
{
18-
map_.src2tgtVerts = &src2tgtVerts_;
34+
map_.src2tgtVertHashMap = &src2tgtVerts_;
1935
outVmap->clear();
2036
outVmap->resize( (int)srcTopology.lastValidVert() + 1 );
2137
}
2238
if ( outEmap )
2339
{
24-
map_.src2tgtEdges = &src2tgtEdges_;
40+
map_.src2tgtWholeEdgeHashMap = &src2tgtEdges_;
2541
outEmap->clear();
2642
outEmap->resize( srcTopology.undirectedEdgeSize() );
2743
}

source/MRMesh/MRPartMapping.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,26 @@
55
namespace MR
66
{
77

8-
// mapping among elements of source mesh, from which a part is taken, and target (this) mesh
8+
/// mapping among elements of source mesh, from which a part is taken, and target mesh
99
struct PartMapping
1010
{
11-
// from.id -> this.id
12-
// hash maps are used to minimize memory consumption when only a small portion of source mesh is copied
13-
FaceHashMap * src2tgtFaces = nullptr;
14-
VertHashMap * src2tgtVerts = nullptr;
15-
WholeEdgeHashMap * src2tgtEdges = nullptr;
16-
// this.id -> from.id
17-
FaceMap * tgt2srcFaces = nullptr;
18-
VertMap * tgt2srcVerts = nullptr;
19-
WholeEdgeMap * tgt2srcEdges = nullptr;
11+
// source.id -> target.id
12+
// hash maps minimize memory consumption when only a small portion of source mesh is copied
13+
FaceHashMap * src2tgtFaceHashMap = nullptr;
14+
VertHashMap * src2tgtVertHashMap = nullptr;
15+
WholeEdgeHashMap * src2tgtWholeEdgeHashMap = nullptr;
16+
17+
// target.id -> source.id
18+
// dense vectors are better by speed and memory when target mesh was empty before copying
19+
FaceMap * tgt2srcFaceMap = nullptr;
20+
VertMap * tgt2srcVertMap = nullptr;
21+
WholeEdgeMap * tgt2srcWholeEdgeMap = nullptr;
22+
23+
/// clears all memeber maps
24+
MRMESH_API void clear();
2025
};
2126

22-
// the class to convert mappings from new HashMap format to old Vector format
27+
/// the class to convert mappings from new HashMap format to old Vector format
2328
class HashToVectorMappingConverter
2429
{
2530
public:

source/MRTest/MRMeshTests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ TEST(MRMesh, AddPartByMask)
9191
FaceHashMap meshIntoMesh2;
9292
FaceMap mesh2IntoMesh;
9393
PartMapping mapping;
94-
mapping.src2tgtFaces = &meshIntoMesh2;
95-
mapping.tgt2srcFaces = &mesh2IntoMesh;
94+
mapping.src2tgtFaceHashMap = &meshIntoMesh2;
95+
mapping.tgt2srcFaceMap = &mesh2IntoMesh;
9696

9797
mesh.addMeshPart( { mesh2, &faces }, mapping );
9898
for ( auto [f, f2] : meshIntoMesh2 )

source/MRVoxels/MRVoxelsConversionsByParts.cpp

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,6 @@ namespace
2121

2222
using namespace MR;
2323

24-
void clearPartMapping( PartMapping& mapping )
25-
{
26-
if ( mapping.src2tgtFaces )
27-
mapping.src2tgtFaces->clear();
28-
if ( mapping.src2tgtVerts )
29-
mapping.src2tgtVerts->clear();
30-
if ( mapping.src2tgtEdges )
31-
mapping.src2tgtEdges->clear();
32-
if ( mapping.tgt2srcFaces )
33-
mapping.tgt2srcFaces->clear();
34-
if ( mapping.tgt2srcVerts )
35-
mapping.tgt2srcVerts->clear();
36-
if ( mapping.tgt2srcEdges )
37-
mapping.tgt2srcEdges->clear();
38-
}
39-
4024
void sortEdgePaths( const Mesh& mesh, std::vector<EdgePath>& paths )
4125
{
4226
std::sort( paths.begin(), paths.end(), [&] ( const EdgePath& ep1, const EdgePath& ep2 )
@@ -124,13 +108,13 @@ mergeVolumePart( Mesh &mesh, std::vector<EdgePath> &cutContours, Volume &&volume
124108
settings.postCut( part );
125109

126110
auto mapping = settings.mapping;
127-
clearPartMapping( mapping );
111+
mapping.clear();
128112

129113
if ( leftCutContours.empty() && cutContours.empty() )
130114
{
131-
WholeEdgeHashMap src2tgtEdges;
132-
if ( !mapping.src2tgtEdges )
133-
mapping.src2tgtEdges = &src2tgtEdges;
115+
WholeEdgeHashMap src2tgtWholeEdgeHashMap;
116+
if ( !mapping.src2tgtWholeEdgeHashMap )
117+
mapping.src2tgtWholeEdgeHashMap = &src2tgtWholeEdgeHashMap;
134118

135119
mesh.addMeshPart( part, mapping );
136120

@@ -141,7 +125,7 @@ mergeVolumePart( Mesh &mesh, std::vector<EdgePath> &cutContours, Volume &&volume
141125
{
142126
for ( auto& e : contour )
143127
{
144-
const auto ue = ( *mapping.src2tgtEdges )[e];
128+
const auto ue = ( *mapping.src2tgtWholeEdgeHashMap )[e];
145129
e = e.even() ? ue : ue.sym();
146130
}
147131
}
@@ -156,9 +140,9 @@ mergeVolumePart( Mesh &mesh, std::vector<EdgePath> &cutContours, Volume &&volume
156140
if ( cutContours[i].size() != leftCutContours[i].size() )
157141
return unexpected( "Mesh cut contours mismatch" );
158142

159-
WholeEdgeHashMap src2tgtEdges;
160-
if ( !mapping.src2tgtEdges )
161-
mapping.src2tgtEdges = &src2tgtEdges;
143+
WholeEdgeHashMap src2tgtWholeEdgeHashMap;
144+
if ( !mapping.src2tgtWholeEdgeHashMap )
145+
mapping.src2tgtWholeEdgeHashMap = &src2tgtWholeEdgeHashMap;
162146

163147
mesh.addMeshPart( part, false, cutContours, leftCutContours, mapping );
164148

@@ -169,7 +153,7 @@ mergeVolumePart( Mesh &mesh, std::vector<EdgePath> &cutContours, Volume &&volume
169153
{
170154
for ( auto& e : contour )
171155
{
172-
const auto ue = ( *mapping.src2tgtEdges )[e];
156+
const auto ue = ( *mapping.src2tgtWholeEdgeHashMap )[e];
173157
e = e.even() ? ue : ue.sym();
174158
}
175159
}

source/MRVoxels/MRVoxelsConversionsByParts.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct MergeVolumePartSettings
2424
PostCutCallback postCut = nullptr;
2525
/// callback to process the destination mesh after merging, usually to map the generated mesh's faces/edges/vertices
2626
/// the second parameter is identical to the `mapping` field, except for one case:
27-
/// if the mapping is not initialized, only `src2tgtEdges` map will be provided (since it's used during processing)
27+
/// if the mapping is not initialized, only `src2tgtWholeEdgeHashMap` map will be provided (since it's used during processing)
2828
using PostMergeCallback = std::function<void( Mesh&, const PartMapping& )>;
2929
PostMergeCallback postMerge = nullptr;
3030
/// mapping with initialized maps required for the `postMerge` callback

0 commit comments

Comments
 (0)