Skip to content

Commit 24ded1f

Browse files
committed
[Mapping] Rely on a link to the indexPairs to couple mechanical - topological mappings
[scenes] Update scene accordingly
1 parent 9b0d249 commit 24ded1f

File tree

3 files changed

+18
-66
lines changed

3 files changed

+18
-66
lines changed

Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/SubsetTopologicalMultiMapping.cpp

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,13 @@ void registerSubsetTopologicalMultiMapping(sofa::core::ObjectFactory* factory)
3232
core::ObjectRegistrationData("Merges multiple input topologies (points, edges, triangles, "
3333
"quads, tetrahedra, hexahedra) "
3434
"into a single output topology with index remapping. "
35-
"Optionally populates indexPairs for "
36-
"SubsetMultiMapping.")
35+
"Exposes indexPairs Data for linking to SubsetMultiMapping.")
3736
.add<SubsetTopologicalMultiMapping>());
3837
}
3938

4039
SubsetTopologicalMultiMapping::SubsetTopologicalMultiMapping()
4140
: l_inputs(initLink("input", "Input topology sources to merge")),
4241
l_output(initLink("output", "Output merged topology")),
43-
l_subsetMultiMapping(
44-
initLink("subsetMultiMapping",
45-
"Optional link to a SubsetMultiMapping to auto-populate its indexPairs")),
4642
d_flipNormals(
4743
initData(&d_flipNormals, sofa::type::vector<bool>(), "flipNormals",
4844
"Per-source boolean flags to reverse triangle and quad winding order")),
@@ -88,8 +84,6 @@ void SubsetTopologicalMultiMapping::init()
8884

8985
mapTopologies();
9086

91-
if (l_subsetMultiMapping.get()) populateSubsetMultiMappingIndexPairs();
92-
9387
d_componentState.setValue(sofa::core::objectmodel::ComponentState::Valid);
9488
}
9589

@@ -98,8 +92,6 @@ void SubsetTopologicalMultiMapping::reinit()
9892
if (d_componentState.getValue() == sofa::core::objectmodel::ComponentState::Invalid) return;
9993

10094
mapTopologies();
101-
102-
if (l_subsetMultiMapping.get()) populateSubsetMultiMappingIndexPairs();
10395
}
10496

10597
void SubsetTopologicalMultiMapping::mapTopologies()
@@ -217,24 +209,4 @@ void SubsetTopologicalMultiMapping::mapTopologies()
217209
<< " hexahedra.";
218210
}
219211

220-
void SubsetTopologicalMultiMapping::populateSubsetMultiMappingIndexPairs()
221-
{
222-
auto* targetObj = l_subsetMultiMapping.get();
223-
if (!targetObj) return;
224-
225-
auto* targetData = targetObj->findData("indexPairs");
226-
if (!targetData)
227-
{
228-
msg_error() << "Linked object '" << targetObj->getName()
229-
<< "' has no 'indexPairs' Data field. "
230-
"Ensure it is a SubsetMultiMapping.";
231-
return;
232-
}
233-
234-
targetData->copyValueFrom(&d_indexPairs);
235-
236-
msg_info() << "Set " << (d_indexPairs.getValue().size() / 2) << " indexPairs on '"
237-
<< targetObj->getName() << "'.";
238-
}
239-
240212
} // namespace sofa::component::topology::mapping

Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/SubsetTopologicalMultiMapping.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace sofa::component::topology::mapping
3636
* order can be reversed per source via flipNormals.
3737
*
3838
* This is the topological counterpart to SubsetMultiMapping.
39-
* The component can optionally auto-populate the indexPairs Data of a linked SubsetMultiMapping.
39+
* The indexPairs output can be linked to a SubsetMultiMapping in scenes.
4040
*
4141
* Merging is performed once during init(). Dynamic topology changes are not supported.
4242
*/
@@ -64,24 +64,18 @@ class SOFA_COMPONENT_TOPOLOGY_MAPPING_API SubsetTopologicalMultiMapping
6464
sofa::core::objectmodel::BaseLink::FLAG_STRONGLINK>
6565
l_output;
6666

67-
/// Optional link to a SubsetMultiMapping to auto-populate its indexPairs.
68-
SingleLink<SubsetTopologicalMultiMapping, sofa::core::objectmodel::BaseObject,
69-
sofa::core::objectmodel::BaseLink::FLAG_STOREPATH>
70-
l_subsetMultiMapping;
71-
7267
Data<sofa::type::vector<bool>>
7368
d_flipNormals; ///< Per-source flags to reverse triangle and/or quad winding order
7469
Data<sofa::type::vector<unsigned>>
75-
d_indexPairs; ///< Output: flat array of (source_index, coord_in_source) pairs for
76-
///< SubsetMultiMapping
70+
d_indexPairs; ///< Output: flat array of (source_index, coord_in_source) pairs,
71+
///< linkable to SubsetMultiMapping
7772

7873
protected:
7974
SubsetTopologicalMultiMapping();
8075
~SubsetTopologicalMultiMapping() override;
8176

8277
private:
8378
void mapTopologies();
84-
void populateSubsetMultiMappingIndexPairs();
8579

8680
/// Per-source cumulative point offsets. m_pointOffsets[i] = total points from sources 0..i-1.
8781
sofa::type::vector<Index> m_pointOffsets;

examples/Component/Topology/Mapping/SubsetTopologicalMultiMapping.scn

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
<?xml version="1.0" ?>
2-
<!-- SubsetTopologicalMultiMapping example
3-
Demonstrates merging multiple topologies into one for every supported element type.
4-
Four demos placed side by side along x:
5-
6-
x=0: Triangles - two 4x4 triangle grids merged, Source2 normals flipped
7-
x=5: Quads - two 4x4 quad grids merged, Source2 normals flipped
8-
x=10: Tetrahedra - two 3x3x3 grids converted to tetrahedra then merged
9-
x=16: Hexahedra - two 3x3x3 hexahedral grids merged
10-
-->
112
<Node name="root" dt="1e-3" gravity="0 -1 0">
123
<RequiredPlugin name="Sofa.Component.IO.Mesh"/> <!-- Needed to use components [GridMeshCreator] -->
134
<RequiredPlugin name="Sofa.Component.LinearSolver.Iterative"/> <!-- Needed to use components [CGLinearSolver] -->
@@ -28,7 +19,6 @@
2819
<EulerImplicitSolver rayleighStiffness="0.1" rayleighMass="0.1" />
2920
<CGLinearSolver iterations="25" tolerance="1e-5" threshold="1e-5"/>
3021

31-
<!-- ==================== TRIANGLES (x=0) ==================== -->
3222
<Node name="TriangleDemo">
3323
<Node name="Source1">
3424
<GridMeshCreator name="loader" filename="nofile" resolution="4 4" trianglePattern="2" />
@@ -47,15 +37,15 @@
4737
<MeshTopology name="topology" />
4838
<MechanicalObject template="Vec3" name="dofs" />
4939

50-
<SubsetTopologicalMultiMapping
40+
<SubsetTopologicalMultiMapping name="topoMapping"
5141
input="@../Source1/topology @../Source2/topology"
5242
output="@topology"
53-
subsetMultiMapping="@mapping"
5443
flipNormals="0 1" />
5544

5645
<SubsetMultiMapping template="Vec3,Vec3" name="mapping"
5746
input="@../Source1/dofs @../Source2/dofs"
58-
output="@dofs" />
47+
output="@dofs"
48+
indexPairs="@topoMapping.indexPairs" />
5949

6050
<UniformMass vertexMass="1" />
6151

@@ -66,7 +56,6 @@
6656
</Node>
6757
</Node>
6858

69-
<!-- ==================== QUADS (x=5) ==================== -->
7059
<Node name="QuadDemo">
7160
<Node name="Source1">
7261
<GridMeshCreator name="loader" filename="nofile" resolution="4 4" trianglePattern="0"
@@ -86,15 +75,15 @@
8675
<MeshTopology name="topology" />
8776
<MechanicalObject template="Vec3" name="dofs" />
8877

89-
<SubsetTopologicalMultiMapping
78+
<SubsetTopologicalMultiMapping name="topoMapping"
9079
input="@../Source1/topology @../Source2/topology"
9180
output="@topology"
92-
subsetMultiMapping="@mapping"
9381
flipNormals="0 1" />
9482

9583
<SubsetMultiMapping template="Vec3,Vec3" name="mapping"
9684
input="@../Source1/dofs @../Source2/dofs"
97-
output="@dofs" />
85+
output="@dofs"
86+
indexPairs="@topoMapping.indexPairs" />
9887

9988
<UniformMass vertexMass="1" />
10089

@@ -105,9 +94,7 @@
10594
</Node>
10695
</Node>
10796

108-
<!-- ==================== TETRAHEDRA (x=10) ==================== -->
10997
<Node name="TetraDemo">
110-
<!-- Each source uses RegularGridTopology (hexa) + Hexa2TetraTopologicalMapping to produce tetrahedra -->
11198
<Node name="Source1">
11299
<RegularGridTopology name="grid" n="3 3 3" min="10 0 0" max="12 2 2" />
113100
<MechanicalObject template="Vec3" name="dofs" />
@@ -132,14 +119,14 @@
132119
<MeshTopology name="topology" />
133120
<MechanicalObject template="Vec3" name="dofs" />
134121

135-
<SubsetTopologicalMultiMapping
122+
<SubsetTopologicalMultiMapping name="topoMapping"
136123
input="@../Source1/Tetra/topology @../Source2/Tetra/topology"
137-
output="@topology"
138-
subsetMultiMapping="@mapping" />
124+
output="@topology" />
139125

140126
<SubsetMultiMapping template="Vec3,Vec3" name="mapping"
141127
input="@../Source1/dofs @../Source2/dofs"
142-
output="@dofs" />
128+
output="@dofs"
129+
indexPairs="@topoMapping.indexPairs" />
143130

144131
<UniformMass vertexMass="1" />
145132

@@ -150,7 +137,6 @@
150137
</Node>
151138
</Node>
152139

153-
<!-- ==================== HEXAHEDRA (x=16) ==================== -->
154140
<Node name="HexaDemo">
155141
<Node name="Source1">
156142
<RegularGridTopology name="grid" n="3 3 3" min="16 0 0" max="18 2 2" />
@@ -166,14 +152,14 @@
166152
<MeshTopology name="topology" />
167153
<MechanicalObject template="Vec3" name="dofs" />
168154

169-
<SubsetTopologicalMultiMapping
155+
<SubsetTopologicalMultiMapping name="topoMapping"
170156
input="@../Source1/grid @../Source2/grid"
171-
output="@topology"
172-
subsetMultiMapping="@mapping" />
157+
output="@topology" />
173158

174159
<SubsetMultiMapping template="Vec3,Vec3" name="mapping"
175160
input="@../Source1/dofs @../Source2/dofs"
176-
output="@dofs" />
161+
output="@dofs"
162+
indexPairs="@topoMapping.indexPairs" />
177163

178164
<UniformMass vertexMass="1" />
179165

0 commit comments

Comments
 (0)