Skip to content

Commit 65b568f

Browse files
authored
Merge pull request #4182 from opensim-org/contact_geometry_generate_decorations_fix
Create `SimTK::DecorativeGeometry` directly for `ContactGeometry`
2 parents 26a06b2 + 151308d commit 65b568f

File tree

6 files changed

+196
-71
lines changed

6 files changed

+196
-71
lines changed

OpenSim/Simulation/Model/ContactGeometry.cpp

Lines changed: 152 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -91,55 +91,6 @@ SimTK::ContactGeometry ContactGeometry::createSimTKContactGeometry() const
9191
return createSimTKContactGeometryImpl();
9292
}
9393

94-
//=============================================================================
95-
// VISUALIZATION
96-
//=============================================================================
97-
void ContactGeometry::generateDecorations(
98-
bool fixed,
99-
const ModelDisplayHints& hints,
100-
const SimTK::State& s,
101-
SimTK::Array_<SimTK::DecorativeGeometry>& geometry) const {
102-
Super::generateDecorations(fixed, hints, s, geometry);
103-
generateDecorationsImpl(fixed, hints, s, geometry);
104-
}
105-
106-
void ContactGeometry::generateDecorationsImpl(
107-
bool fixed,
108-
const ModelDisplayHints& hints,
109-
const SimTK::State& s,
110-
SimTK::Array_<SimTK::DecorativeGeometry>& geometry) const {
111-
// There is no fixed geometry to generate here.
112-
if (fixed) { return; }
113-
114-
// Model-wide hints indicate that contact geometry shouldn't be shown.
115-
if (!hints.get_show_contact_geometry()) { return; }
116-
117-
// The decoration has been toggled off by its `Appearance` block.
118-
if (!get_Appearance().get_visible()) { return; }
119-
120-
// Create a SimTK::DecorativeGeometry object for this ContactGeometry.
121-
SimTK::DecorativeGeometry decoration =
122-
createSimTKContactGeometry().createDecorativeGeometry();
123-
124-
// B: base Frame (Body or Ground)
125-
// F: PhysicalFrame that this ContactGeometry is connected to
126-
// P: the frame defined (relative to F) by the location and orientation
127-
// properties defined in ContactGeometry.
128-
// D: the frame defined (relative to P) by the decoration's location and
129-
// orientation properties defined by the SimTK::DecorativeGeometry object.
130-
const auto& X_BF = getFrame().findTransformInBaseFrame();
131-
const auto& X_FP = getTransform();
132-
const auto& X_PD = decoration.getTransform();
133-
const auto X_BD = X_BF.compose(X_FP).compose(X_PD);
134-
geometry.push_back(decoration
135-
.setScale(1)
136-
.setTransform(X_BD)
137-
.setRepresentation(get_Appearance().get_representation())
138-
.setBodyId(getFrame().getMobilizedBodyIndex())
139-
.setColor(get_Appearance().get_color())
140-
.setOpacity(get_Appearance().get_opacity()));
141-
}
142-
14394
//=============================================================================
14495
// OBJECT INTERFACE
14596
//=============================================================================
@@ -264,6 +215,43 @@ SimTK::ContactGeometry ContactSphere::createSimTKContactGeometryImpl() const
264215
return SimTK::ContactGeometry::Sphere(get_radius());
265216
}
266217

218+
void ContactSphere::generateDecorations(
219+
bool fixed,
220+
const ModelDisplayHints& hints,
221+
const SimTK::State& s,
222+
SimTK::Array_<SimTK::DecorativeGeometry>& geometry) const {
223+
224+
// There is no fixed geometry to generate here.
225+
if (fixed) { return; }
226+
227+
// Model-wide hints indicate that contact geometry shouldn't be shown.
228+
if (!hints.get_show_contact_geometry()) { return; }
229+
230+
// The decoration has been toggled off by its `Appearance` block.
231+
if (!get_Appearance().get_visible()) { return; }
232+
233+
// Create a SimTK::DecorativeSphere object for this ContactSphere.
234+
SimTK::DecorativeSphere decoration(get_radius());
235+
236+
// B: base Frame (Body or Ground)
237+
// F: PhysicalFrame that this ContactGeometry is connected to
238+
// P: the frame defined (relative to F) by the location and orientation
239+
// properties defined in ContactGeometry.
240+
// D: the frame defined (relative to P) by the decoration's location and
241+
// orientation properties defined by the SimTK::DecorativeGeometry object.
242+
const auto& X_BF = getFrame().findTransformInBaseFrame();
243+
const auto& X_FP = getTransform();
244+
const auto& X_PD = decoration.getTransform();
245+
const auto X_BD = X_BF.compose(X_FP).compose(X_PD);
246+
geometry.push_back(decoration
247+
.setScale(1)
248+
.setTransform(X_BD)
249+
.setRepresentation(get_Appearance().get_representation())
250+
.setBodyId(getFrame().getMobilizedBodyIndex())
251+
.setColor(get_Appearance().get_color())
252+
.setOpacity(get_Appearance().get_opacity()));
253+
}
254+
267255
//=============================================================================
268256
// CONTACT CYLINDER
269257
//=============================================================================
@@ -303,6 +291,46 @@ SimTK::ContactGeometry ContactCylinder::createSimTKContactGeometryImpl() const
303291
return SimTK::ContactGeometry::Cylinder(get_radius());
304292
}
305293

294+
void ContactCylinder::generateDecorations(
295+
bool fixed,
296+
const ModelDisplayHints& hints,
297+
const SimTK::State& s,
298+
SimTK::Array_<SimTK::DecorativeGeometry>& geometry) const {
299+
300+
// There is no fixed geometry to generate here.
301+
if (fixed) { return; }
302+
303+
// Model-wide hints indicate that contact geometry shouldn't be shown.
304+
if (!hints.get_show_contact_geometry()) { return; }
305+
306+
// The decoration has been toggled off by its `Appearance` block.
307+
if (!get_Appearance().get_visible()) { return; }
308+
309+
// Create a SimTK::DecorativeCylinder object for this ContactCylinder.
310+
SimTK::DecorativeCylinder decoration(get_radius(), get_radius()*2);
311+
// SimTK::DecorativeCylinder's axis is defined as the y-axis,
312+
// whereas SimTK::ContactGeometry::Cylinder axis is defined as the z-axis.
313+
decoration.setTransform(SimTK::Rotation(SimTK::Pi/2, SimTK::XAxis));
314+
315+
// B: base Frame (Body or Ground)
316+
// F: PhysicalFrame that this ContactGeometry is connected to
317+
// P: the frame defined (relative to F) by the location and orientation
318+
// properties defined in ContactGeometry.
319+
// D: the frame defined (relative to P) by the decoration's location and
320+
// orientation properties defined by the SimTK::DecorativeGeometry object.
321+
const auto& X_BF = getFrame().findTransformInBaseFrame();
322+
const auto& X_FP = getTransform();
323+
const auto& X_PD = decoration.getTransform();
324+
const auto X_BD = X_BF.compose(X_FP).compose(X_PD);
325+
geometry.push_back(decoration
326+
.setScale(1)
327+
.setTransform(X_BD)
328+
.setRepresentation(get_Appearance().get_representation())
329+
.setBodyId(getFrame().getMobilizedBodyIndex())
330+
.setColor(get_Appearance().get_color())
331+
.setOpacity(get_Appearance().get_opacity()));
332+
}
333+
306334
//=============================================================================
307335
// CONTACT ELLIPSOID
308336
//=============================================================================
@@ -343,6 +371,43 @@ SimTK::ContactGeometry ContactEllipsoid::createSimTKContactGeometryImpl() const
343371
return SimTK::ContactGeometry::Ellipsoid(get_radii());
344372
}
345373

374+
void ContactEllipsoid::generateDecorations(
375+
bool fixed,
376+
const ModelDisplayHints& hints,
377+
const SimTK::State& s,
378+
SimTK::Array_<SimTK::DecorativeGeometry>& geometry) const {
379+
380+
// There is no fixed geometry to generate here.
381+
if (fixed) { return; }
382+
383+
// Model-wide hints indicate that contact geometry shouldn't be shown.
384+
if (!hints.get_show_contact_geometry()) { return; }
385+
386+
// The decoration has been toggled off by its `Appearance` block.
387+
if (!get_Appearance().get_visible()) { return; }
388+
389+
// Create a SimTK::DecorativeEllipsoid object for this ContactEllipsoid.
390+
SimTK::DecorativeEllipsoid decoration(get_radii());
391+
392+
// B: base Frame (Body or Ground)
393+
// F: PhysicalFrame that this ContactGeometry is connected to
394+
// P: the frame defined (relative to F) by the location and orientation
395+
// properties defined in ContactGeometry.
396+
// D: the frame defined (relative to P) by the decoration's location and
397+
// orientation properties defined by the SimTK::DecorativeGeometry object.
398+
const auto& X_BF = getFrame().findTransformInBaseFrame();
399+
const auto& X_FP = getTransform();
400+
const auto& X_PD = decoration.getTransform();
401+
const auto X_BD = X_BF.compose(X_FP).compose(X_PD);
402+
geometry.push_back(decoration
403+
.setScale(1)
404+
.setTransform(X_BD)
405+
.setRepresentation(get_Appearance().get_representation())
406+
.setBodyId(getFrame().getMobilizedBodyIndex())
407+
.setColor(get_Appearance().get_color())
408+
.setOpacity(get_Appearance().get_opacity()));
409+
}
410+
346411
//=============================================================================
347412
// CONTACT TORUS
348413
//=============================================================================
@@ -395,3 +460,41 @@ SimTK::ContactGeometry ContactTorus::createSimTKContactGeometryImpl() const
395460
{
396461
return SimTK::ContactGeometry::Torus(get_torus_radius(), get_tube_radius());
397462
}
463+
464+
void ContactTorus::generateDecorations(
465+
bool fixed,
466+
const ModelDisplayHints& hints,
467+
const SimTK::State& s,
468+
SimTK::Array_<SimTK::DecorativeGeometry>& geometry) const {
469+
470+
// There is no fixed geometry to generate here.
471+
if (fixed) { return; }
472+
473+
// Model-wide hints indicate that contact geometry shouldn't be shown.
474+
if (!hints.get_show_contact_geometry()) { return; }
475+
476+
// The decoration has been toggled off by its `Appearance` block.
477+
if (!get_Appearance().get_visible()) { return; }
478+
479+
// Create a SimTK::DecorativeTorus object for this ContactTorus.
480+
SimTK::DecorativeGeometry decoration =
481+
createSimTKContactGeometry().createDecorativeGeometry();
482+
483+
// B: base Frame (Body or Ground)
484+
// F: PhysicalFrame that this ContactGeometry is connected to
485+
// P: the frame defined (relative to F) by the location and orientation
486+
// properties defined in ContactGeometry.
487+
// D: the frame defined (relative to P) by the decoration's location and
488+
// orientation properties defined by the SimTK::DecorativeGeometry object.
489+
const auto& X_BF = getFrame().findTransformInBaseFrame();
490+
const auto& X_FP = getTransform();
491+
const auto& X_PD = decoration.getTransform();
492+
const auto X_BD = X_BF.compose(X_FP).compose(X_PD);
493+
geometry.push_back(decoration
494+
.setScale(1)
495+
.setTransform(X_BD)
496+
.setRepresentation(get_Appearance().get_representation())
497+
.setBodyId(getFrame().getMobilizedBodyIndex())
498+
.setColor(get_Appearance().get_color())
499+
.setOpacity(get_Appearance().get_opacity()));
500+
}

OpenSim/Simulation/Model/ContactGeometry.h

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,26 +135,12 @@ OpenSim_DECLARE_ABSTRACT_OBJECT(ContactGeometry, ModelComponent);
135135
SimTK::ContactGeometry createSimTKContactGeometry() const;
136136
// @}
137137

138-
/** @name Visualization */
139-
// @{
140-
void generateDecorations(bool fixed, const ModelDisplayHints& hints,
141-
const SimTK::State& s,
142-
SimTK::Array_<SimTK::DecorativeGeometry>& geometry) const override;
143-
// @}
144-
145138
protected:
146139
// CONTACT GEOMETRY INTERFACE
147140
// Concrete implementations of ContactGeometry must implement this method to
148141
// provide an equivalent SimTK::ContactGeometry object.
149142
virtual SimTK::ContactGeometry createSimTKContactGeometryImpl() const = 0;
150143

151-
// Concrete implementations of ContactGeometry may override this method to
152-
// customize `generateDecorations()`.
153-
virtual void generateDecorationsImpl(
154-
bool fixed, const ModelDisplayHints& hints,
155-
const SimTK::State& state,
156-
SimTK::Array_<SimTK::DecorativeGeometry>& geometry) const;
157-
158144
// OBJECT INTERFACE
159145
void updateFromXMLNode(SimTK::Xml::Element& node, int versionNumber)
160146
override;
@@ -234,6 +220,13 @@ OpenSim_DECLARE_CONCRETE_OBJECT(ContactSphere, ContactGeometry);
234220
void setRadius(double radius);
235221
// @}
236222

223+
/** @name Visualization */
224+
// @{
225+
void generateDecorations(bool fixed, const ModelDisplayHints& hints,
226+
const SimTK::State& s,
227+
SimTK::Array_<SimTK::DecorativeGeometry>& geometry) const override;
228+
// @}
229+
237230
private:
238231
// CONTACT GEOMETRY INTERFACE
239232
SimTK::ContactGeometry createSimTKContactGeometryImpl() const override;
@@ -316,6 +309,13 @@ OpenSim_DECLARE_CONCRETE_OBJECT(ContactCylinder, ContactGeometry);
316309
void setRadius(double radius);
317310
// @}
318311

312+
/** @name Visualization */
313+
// @{
314+
void generateDecorations(bool fixed, const ModelDisplayHints& hints,
315+
const SimTK::State& s,
316+
SimTK::Array_<SimTK::DecorativeGeometry>& geometry) const override;
317+
// @}
318+
319319
private:
320320
// CONTACT GEOMETRY INTERFACE
321321
SimTK::ContactGeometry createSimTKContactGeometryImpl() const override;
@@ -391,6 +391,13 @@ OpenSim_DECLARE_CONCRETE_OBJECT(ContactEllipsoid, ContactGeometry);
391391
void setRadii(const SimTK::Vec3& radii);
392392
// @}
393393

394+
/** @name Visualization */
395+
// @{
396+
void generateDecorations(bool fixed, const ModelDisplayHints& hints,
397+
const SimTK::State& s,
398+
SimTK::Array_<SimTK::DecorativeGeometry>& geometry) const override;
399+
// @}
400+
394401
private:
395402
// CONTACT GEOMETRY INTERFACE
396403
SimTK::ContactGeometry createSimTKContactGeometryImpl() const override;
@@ -491,6 +498,13 @@ OpenSim_DECLARE_CONCRETE_OBJECT(ContactTorus, ContactGeometry);
491498
void setTubeRadius(double radius);
492499
// @}
493500

501+
/** @name Visualization */
502+
// @{
503+
void generateDecorations(bool fixed, const ModelDisplayHints& hints,
504+
const SimTK::State& s,
505+
SimTK::Array_<SimTK::DecorativeGeometry>& geometry) const override;
506+
// @}
507+
494508
private:
495509
// CONTACT GEOMETRY INTERFACE
496510
SimTK::ContactGeometry createSimTKContactGeometryImpl() const override;

OpenSim/Simulation/Model/ContactHalfSpace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ SimTK::ContactGeometry ContactHalfSpace::createSimTKContactGeometryImpl() const
5959
return SimTK::ContactGeometry::HalfSpace();
6060
}
6161

62-
void ContactHalfSpace::generateDecorationsImpl(bool fixed,
62+
void ContactHalfSpace::generateDecorations(bool fixed,
6363
const ModelDisplayHints& hints,
6464
const SimTK::State& s,
6565
SimTK::Array_<SimTK::DecorativeGeometry>& geometry) const

OpenSim/Simulation/Model/ContactHalfSpace.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,15 @@ OpenSim_DECLARE_CONCRETE_OBJECT(ContactHalfSpace, ContactGeometry);
8484
const PhysicalFrame& frame,
8585
const std::string& name);
8686

87-
private:
88-
// CONTACT GEOMETRY INTERFACE
89-
void generateDecorationsImpl(bool fixed, const ModelDisplayHints& hints,
87+
/** @name Visualization */
88+
// @{
89+
void generateDecorations(bool fixed, const ModelDisplayHints& hints,
9090
const SimTK::State& s,
9191
SimTK::Array_<SimTK::DecorativeGeometry>& geometry) const override;
92+
// @}
93+
94+
private:
95+
// CONTACT GEOMETRY INTERFACE
9296
SimTK::ContactGeometry createSimTKContactGeometryImpl() const override;
9397

9498
// INITIALIZATION

OpenSim/Simulation/Model/ContactMesh.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ SimTK::ContactGeometry ContactMesh::createSimTKContactGeometryImpl() const
134134
//=============================================================================
135135
// VISUALIZATION
136136
//=============================================================================
137-
void ContactMesh::generateDecorationsImpl(
137+
void ContactMesh::generateDecorations(
138138
bool fixed,
139139
const ModelDisplayHints& hints,
140140
const SimTK::State& s,

OpenSim/Simulation/Model/ContactMesh.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,20 @@ OpenSim_DECLARE_CONCRETE_OBJECT(ContactMesh, ContactGeometry);
9494
*/
9595
void setFilename(const std::string& filename);
9696

97+
/** @name Visualization */
98+
// @{
99+
void generateDecorations(bool fixed, const ModelDisplayHints& hints,
100+
const SimTK::State& s,
101+
SimTK::Array_<SimTK::DecorativeGeometry>& geometry) const override;
102+
// @}
103+
97104
private:
98105
// INITIALIZATION
99106
void setNull();
100107
void constructProperties();
101108
void extendFinalizeFromProperties() override;
102109

103110
// CONTACT GEOMETRY INTERFACE
104-
void generateDecorationsImpl(bool fixed, const ModelDisplayHints& hints,
105-
const SimTK::State& s,
106-
SimTK::Array_<SimTK::DecorativeGeometry>& geometry) const override;
107111
SimTK::ContactGeometry createSimTKContactGeometryImpl() const override;
108112

109113
// LOAD MESH

0 commit comments

Comments
 (0)