Skip to content

Commit e103a5b

Browse files
authored
Merge pull request #1122 from opensim-org/visualize_wrap_contact
Visualize wrap objects and contact geometry
2 parents efa4196 + 43e851d commit e103a5b

18 files changed

+815
-256
lines changed

OpenSim/Simulation/Model/Appearance.h

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ class OSIMSIMULATION_API SurfaceProperties : public Object {
6060
//==========================================================================
6161
OpenSim_DECLARE_PROPERTY(representation, int,
6262
"The representation (1:Points, 2:Wire, 3:Shaded) used to display the object.");
63-
OpenSim_DECLARE_OPTIONAL_PROPERTY(texture_file, std::string,
64-
"Name of file containing texture.");
63+
OpenSim_DECLARE_OPTIONAL_PROPERTY(texture, std::string,
64+
"Name of texture e.g. metal, bone. This is a hint to the GUI/Visualizer, implementation is Visualization dependent.");
6565

6666
//--------------------------------------------------------------------------
6767
// CONSTRUCTION
@@ -74,43 +74,11 @@ class OSIMSIMULATION_API SurfaceProperties : public Object {
7474
virtual ~SurfaceProperties() {};
7575

7676
bool hasTexture() {
77-
return !getProperty_texture_file().empty();
77+
return !getProperty_texture().empty();
7878
}
7979
//========================================================================
8080
}; // END of class SurfaceProperties
8181

82-
//=============================================================================
83-
/** CurveProperties class holds the Appearance properties of Geometry
84-
displayed in the OpenSim visualizer or GUI.The attributes in this
85-
class are specific to curves or line drawings so that thickness, line-style
86-
etc. can be maintained.
87-
*/
88-
//=============================================================================
89-
class OSIMSIMULATION_API CurveProperties : public Object {
90-
OpenSim_DECLARE_CONCRETE_OBJECT(CurveProperties, Object);
91-
public:
92-
//=========================================================================
93-
// PROPERTIES
94-
//=========================================================================
95-
OpenSim_DECLARE_PROPERTY(thickness, double,
96-
"The thickness of lines used to render a curve or a drawing. ");
97-
98-
//--------------------------------------------------------------------------
99-
// CONSTRUCTION
100-
//--------------------------------------------------------------------------
101-
public:
102-
CurveProperties() {
103-
constructProperties();
104-
}
105-
virtual ~CurveProperties() {};
106-
107-
private:
108-
void constructProperties() {
109-
constructProperty_thickness(1.0);
110-
}
111-
//=========================================================================
112-
}; // END of class CurveProperties
113-
11482
//=============================================================================
11583
//=============================================================================
11684
/**
@@ -140,8 +108,6 @@ class OSIMSIMULATION_API Appearance : public Object {
140108

141109
OpenSim_DECLARE_UNNAMED_PROPERTY(SurfaceProperties,
142110
"Visuals applied to surfaces associated with this Appearance.");
143-
OpenSim_DECLARE_UNNAMED_PROPERTY(CurveProperties,
144-
"Visuals applied to curves or line drawings associated with this Appearance.");
145111

146112

147113
//--------------------------------------------------------------------------
@@ -186,8 +152,7 @@ class OSIMSIMULATION_API Appearance : public Object {
186152
constructProperty_visible(true);
187153
constructProperty_opacity(1.0);
188154
// White by default, shows as a shade of gray
189-
constructProperty_color(SimTK::Vec3(1.0));
190-
constructProperty_CurveProperties(CurveProperties());
155+
constructProperty_color(SimTK::White);
191156
constructProperty_SurfaceProperties(SurfaceProperties());
192157
}
193158
//=========================================================================

OpenSim/Simulation/Model/ContactGeometry.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ void ContactGeometry::constructProperties()
6565
{
6666
constructProperty_location(Vec3(0));
6767
constructProperty_orientation(Vec3(0));
68-
constructProperty_display_preference(1);
68+
Appearance defaultAppearance;
69+
defaultAppearance.set_color(SimTK::Cyan);
70+
defaultAppearance.set_representation(VisualRepresentation::DrawWireframe);
71+
constructProperty_Appearance(defaultAppearance);
6972

70-
Array<double> defaultColor(1.0, 3); //color default to 0, 1, 1
71-
defaultColor[0] = 0.0;
72-
constructProperty_color(defaultColor);
7373
}
7474

7575
const Vec3& ContactGeometry::getLocation() const
@@ -104,12 +104,6 @@ void ContactGeometry::setFrame(const PhysicalFrame& frame)
104104
updConnector<PhysicalFrame>("frame").connect(frame);
105105
}
106106

107-
const int ContactGeometry::getDisplayPreference()
108-
{ return get_display_preference(); }
109-
110-
void ContactGeometry::setDisplayPreference(const int dispPref)
111-
{ set_display_preference(dispPref); }
112-
113107
const PhysicalFrame& ContactGeometry::getBody() const
114108
{ return getFrame(); }
115109

OpenSim/Simulation/Model/ContactGeometry.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <OpenSim/Simulation/osimSimulationDLL.h>
2727
#include "OpenSim/Simulation/Model/ModelComponent.h"
2828
#include "OpenSim/Simulation/Model/PhysicalFrame.h"
29+
#include "Appearance.h"
2930

3031
namespace OpenSim {
3132

@@ -54,11 +55,9 @@ OpenSim_DECLARE_ABSTRACT_OBJECT(ContactGeometry, ModelComponent);
5455
"Orientation of geometry in the PhysicalFrame "
5556
"(body-fixed XYZ Euler angles).");
5657

57-
OpenSim_DECLARE_PROPERTY(display_preference, int,
58-
"0:Hide 1:Wire 3:Flat 4:Shaded");
59-
60-
OpenSim_DECLARE_LIST_PROPERTY_SIZE(color, double, 3,
61-
"Display Color to apply to the contact geometry.");
58+
// Default display properties e.g. Representation, color, texture, etc.
59+
OpenSim_DECLARE_UNNAMED_PROPERTY(Appearance,
60+
"Default appearance for this Geometry");
6261

6362
OpenSim_DECLARE_CONNECTOR(frame, PhysicalFrame,
6463
"The frame to which this geometry is attached.");
@@ -95,12 +94,7 @@ OpenSim_DECLARE_ABSTRACT_OBJECT(ContactGeometry, ModelComponent);
9594
/** Get the PhysicalFrame this geometry is attached to. */
9695
const PhysicalFrame& getFrame() const;
9796
/** %Set the PhysicalFrame this geometry is attached to. */
98-
void setFrame(const PhysicalFrame& body);
99-
100-
/** Get the display_preference of this geometry. */
101-
const int getDisplayPreference();
102-
/** %Set the display_preference of this geometry. */
103-
void setDisplayPreference(const int dispPref);
97+
void setFrame(const PhysicalFrame& frame);
10498

10599
/** Create a new SimTK::ContactGeometry based on this object. */
106100
virtual SimTK::ContactGeometry createSimTKContactGeometry() const = 0;
@@ -109,7 +103,7 @@ OpenSim_DECLARE_ABSTRACT_OBJECT(ContactGeometry, ModelComponent);
109103
* geometry relative to the PhysicalFrame `F` to which this geometry is
110104
* connected.
111105
*
112-
* If you want the transform of this geometry relative to the Body (or
106+
* If you want the transform of this geometry relative to the Frame (or
113107
* Ground) `B` in which this geometry is fixed, you can use the following
114108
* code:
115109
* @code{.cpp}

OpenSim/Simulation/Model/ContactMesh.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,32 @@ SimTK::ContactGeometry ContactMesh::createSimTKContactGeometry() const
126126
return *_geometry;
127127
}
128128

129+
//=============================================================================
130+
// VISUALIZER GEOMETRY
131+
//=============================================================================
132+
void ContactMesh::generateDecorations(bool fixed, const ModelDisplayHints& hints,
133+
const SimTK::State& s, SimTK::Array_<SimTK::DecorativeGeometry>& geometry) const
134+
{
135+
Super::generateDecorations(fixed, hints, s, geometry);
136+
137+
// There is no fixed geometry to generate here.
138+
if (fixed) { return; }
139+
140+
// B: base Frame (Body or Ground)
141+
// F: PhysicalFrame that this ContactGeometry is connected to
142+
// P: the frame defined (relative to F) by the location and orientation
143+
// properties.
144+
if (hints.get_show_contact_geometry()) {
145+
const auto& X_BF = getFrame().findTransformInBaseFrame();
146+
const auto& X_FP = getTransform();
147+
const auto X_BP = X_BF * X_FP;
148+
geometry.push_back(SimTK::DecorativeMeshFile(get_filename())
149+
.setTransform(X_BP)
150+
.setRepresentation(get_Appearance().get_representation())
151+
.setBodyId(getFrame().getMobilizedBodyIndex())
152+
.setColor(get_Appearance().get_color())
153+
.setOpacity(get_Appearance().get_opacity()));
154+
}
155+
}
156+
129157
} // end of namespace OpenSim

OpenSim/Simulation/Model/ContactMesh.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ OpenSim_DECLARE_CONCRETE_OBJECT(ContactMesh, ContactGeometry);
9393
* %Set the name of the file to load the mesh from.
9494
*/
9595
void setFilename(const std::string& filename);
96+
97+
// VISUALIZATION
98+
void generateDecorations(bool fixed, const ModelDisplayHints& hints,
99+
const SimTK::State& s,
100+
SimTK::Array_<SimTK::DecorativeGeometry>& geometry) const override;
96101
private:
97102
// INITIALIZATION
98103
void setNull();

OpenSim/Simulation/Model/ContactSphere.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ void ContactSphere::generateDecorations(bool fixed, const ModelDisplayHints& hin
9595
const auto X_BP = X_BF * X_FP;
9696
geometry.push_back(SimTK::DecorativeSphere(getRadius())
9797
.setTransform(X_BP)
98-
.setRepresentation(SimTK::DecorativeGeometry::DrawWireframe)
98+
.setRepresentation(get_Appearance().get_representation())
9999
.setBodyId(getFrame().getMobilizedBodyIndex())
100-
.setColor(SimTK::Vec3(0,1,0))
101-
.setOpacity(0.5));
100+
.setColor(get_Appearance().get_color())
101+
.setOpacity(get_Appearance().get_opacity()));
102102
}
103103

104104
} // end of namespace OpenSim

OpenSim/Simulation/Model/ContactSphere.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,16 @@ OpenSim_DECLARE_CONCRETE_OBJECT(ContactSphere, ContactGeometry);
8787
* %Set the radius of the sphere.
8888
*/
8989
void setRadius(double radius);
90+
91+
// VISUALIZATION
92+
void generateDecorations(bool fixed, const ModelDisplayHints& hints,
93+
const SimTK::State& s,
94+
SimTK::Array_<SimTK::DecorativeGeometry>& geometry) const override;
9095
private:
9196
// INITIALIZATION
9297
void setNull();
9398
void constructProperties();
9499

95-
// VISUALIZATION
96-
void generateDecorations(bool fixed, const ModelDisplayHints& hints,
97-
const SimTK::State& s,
98-
SimTK::Array_<SimTK::DecorativeGeometry>& geometry) const override;
99-
100100
//=============================================================================
101101
}; // END of class ContactSphere
102102
//=============================================================================

OpenSim/Simulation/Model/Geometry.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ void Geometry::generateDecorations(bool fixed,
8383
if (!fixed && !getInput("transform").isConnected())
8484
return;
8585

86+
if (!get_Appearance().get_visible()) return;
87+
8688
SimTK::Array_<SimTK::DecorativeGeometry> decos;
8789
implementCreateDecorativeGeometry(decos);
8890
if (decos.size() == 0) return;

OpenSim/Simulation/RegisterTypes_osimSimulation.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ OSIMSIMULATION_API void RegisterTypes_osimSimulation()
164164
Object::registerType( ConditionalPathPoint() );
165165
Object::registerType( MovingPathPoint() );
166166
Object::registerType( SurfaceProperties());
167-
Object::registerType( CurveProperties());
168167
Object::registerType( Appearance());
169168
Object::registerType( ModelVisualPreferences());
170169

OpenSim/Simulation/Wrap/WrapObject.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,10 @@ void WrapObject::constructProperties()
6262
constructProperty_translation(defaultTranslations);
6363

6464
constructProperty_quadrant("Unassigned");
65-
66-
constructProperty_display_preference(1);
67-
Array<double> defaultColor(1.0, 3); //color default to 0, 1, 1
68-
defaultColor[0] = 0.0;
69-
70-
constructProperty_color(defaultColor);
65+
Appearance defaultAppearance;
66+
defaultAppearance.set_color(SimTK::Cyan);
67+
defaultAppearance.set_representation(VisualRepresentation::DrawWireframe);
68+
constructProperty_Appearance(defaultAppearance);
7169
}
7270

7371
const PhysicalFrame& WrapObject::getFrame() const

OpenSim/Simulation/Wrap/WrapObject.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
// INCLUDE
2727
#include <OpenSim/Simulation/Model/ModelComponent.h>
28-
28+
#include <OpenSim/Simulation/Model/Appearance.h>
2929
namespace OpenSim {
3030

3131
class PathPoint;
@@ -58,11 +58,9 @@ OpenSim_DECLARE_ABSTRACT_OBJECT(WrapObject, Component);
5858
OpenSim_DECLARE_PROPERTY(translation, SimTK::Vec3,
5959
"Translation of the WrapObject.");
6060

61-
OpenSim_DECLARE_PROPERTY(display_preference, int,
62-
"Display Pref. 0:Hide 1:Wire 3:Flat 4:Shaded");
63-
64-
OpenSim_DECLARE_LIST_PROPERTY_SIZE(color, double, 3,
65-
"Display Color as RGB with each being any value on [0, 1]");
61+
// Default display properties e.g. Representation, color, texture, etc.
62+
OpenSim_DECLARE_UNNAMED_PROPERTY(Appearance,
63+
"Default appearance for this Geometry");
6664

6765
OpenSim_DECLARE_PROPERTY(quadrant, std::string,
6866
"The name of quadrant over which the wrap object is active. "

OpenSim/Tools/Test/AppearanceTest.JPG

52.7 KB
Loading
34.7 KB
Loading

0 commit comments

Comments
 (0)