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

Function replicateZ

source/MRMesh/MRMeshReplicate.cpp:12–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10{
11
12void replicateZ( Mesh & m, const Mesh & target )
13{
14 MR_TIMER;
15
16 const auto szM = m.topology.numValidVerts();
17 const auto szT = target.topology.numValidVerts();
18 if ( szT < szM )
19 {
20 // target mesh shall have more vertices not to have underdetermined system of equations
21 assert( false );
22 return;
23 }
24
25 Vector<MeshTriPoint, VertId> targetVertProjections;
26 targetVertProjections.resizeNoInit( target.topology.vertSize() );
27 m.getAABBTree();
28 BitSetParallelFor( target.topology.getValidVerts(), [&]( VertId v )
29 {
30 targetVertProjections[v] = findProjection( target.points[v], m ).mtp;
31 } );
32
33 Vector<int, VertId> mVertToNum = makeVectorWithSeqNums( m.topology.getValidVerts() );
34
35 std::vector< Eigen::Triplet<double> > mTriplets;
36 mTriplets.reserve( szT * 3 );
37 Eigen::VectorXd rhs( szT );
38 int n = 0;
39 for ( VertId v : target.topology.getValidVerts() )
40 {
41 for ( const auto & wv : targetVertProjections[v].getWeightedVerts( m.topology ) )
42 mTriplets.emplace_back( n, mVertToNum[wv.v], wv.weight );
43 rhs[ n++ ] = target.points[v].z;
44 }
45 assert( mTriplets.size() == szT * 3 );
46
47 using SparseMatrix = Eigen::SparseMatrix<double,Eigen::RowMajor>;
48 SparseMatrix mat( szT, szM );
49 mat.setFromTriplets( mTriplets.begin(), mTriplets.end() );
50
51 SparseMatrix A = mat.adjoint() * mat;
52 using SparseMatrixColMajor = Eigen::SparseMatrix<double,Eigen::ColMajor>;
53 Eigen::SimplicialLDLT<SparseMatrixColMajor> ldlt;
54 ldlt.compute( A );
55
56 Eigen::VectorXd sol = ldlt.solve( mat.adjoint() * rhs );
57 n = 0;
58 for ( auto v : m.topology.getValidVerts() )
59 m.points[v].z = float( sol[n++] );
60}
61
62} //namespace MR

Callers

nothing calls this directly

Calls 11

BitSetParallelForFunction · 0.85
findProjectionFunction · 0.85
makeVectorWithSeqNumsFunction · 0.85
getWeightedVertsMethod · 0.80
numValidVertsMethod · 0.45
vertSizeMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
solveMethod · 0.45

Tested by

no test coverage detected