Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add no visualization option #2522

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions OpenSim/Simulation/Model/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ void Mesh::extendFinalizeFromProperties() {
std::cout << "Mesh " << get_mesh_file() << " not connected to model..ignoring" << std::endl;
return; // Orphan Mesh not descendant of a model
}
const Model* ownerModel = dynamic_cast<const Model*>(rootModel);

//No visualization don't try to load meshes
if (!ownerModel->visualizationIsEnabled())
return;

// Current interface to Visualizer calls generateDecorations on every
// frame. On first time through, load file and create DecorativeMeshFile
Expand Down
17 changes: 15 additions & 2 deletions OpenSim/Simulation/Model/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,20 @@ OpenSim_OBJECT_NONTEMPLATE_DEFS(Model, ModelComponent);
ModelVisualizer that provides visualization and interaction with the %Model
as it is executing. The default is no visualization.
@see getModelVisualizer() **/
void setUseVisualizer(bool visualize) {_useVisualizer=visualize;}
void setUseVisualizer(bool visualize) {
_useVisualizer=visualize;
enableVisualization(visualize);
}
// Enable visualization overall, loading mesh files etc.
void enableVisualization(bool enable) {
// Propagate flag so that meshes are loaded (or not)
upd_ModelVisualPreferences().setVisualize(enable);
finalizeFromProperties();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want this to be a bit more efficient, you could check that the enable status is changing. If not, no reason to do anything.

}
// Return status if visualize flag (different from useVisualizer)
bool visualizationIsEnabled() const {
return get_ModelVisualPreferences().visualize();
}
/** Return the current setting of the "use visualizer" flag, which will
take effect at the next call to initSystem() on this %Model. **/
bool getUseVisualizer() const {return _useVisualizer;}
Expand Down Expand Up @@ -1064,7 +1077,7 @@ OpenSim_OBJECT_NONTEMPLATE_DEFS(Model, ModelComponent);
SimTK::Array_<SimTK::DecorativeGeometry>& appendToThis) const
override;
/**@}**/

//--------------------------------------------------------------------------

private:
Expand Down
8 changes: 7 additions & 1 deletion OpenSim/Simulation/Model/ModelVisualPreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class OSIMSIMULATION_API ModelVisualPreferences : public Object {
//==========================================================================
OpenSim_DECLARE_UNNAMED_PROPERTY(ModelDisplayHints,
"Model display preferences");

//--------------------------------------------------------------------------
// CONSTRUCTION
//--------------------------------------------------------------------------
Expand All @@ -63,10 +62,17 @@ class OSIMSIMULATION_API ModelVisualPreferences : public Object {
}
virtual ~ModelVisualPreferences() {};

bool visualize() const {
return _visualize;
}
void setVisualize(bool visualizationStatus) {
_visualize = visualizationStatus;
}
private:
void constructProperties() {
constructProperty_ModelDisplayHints(ModelDisplayHints());
}
bool _visualize;
//=============================================================================
}; // END of class ModelVisualPreferences
//=============================================================================
Expand Down
7 changes: 6 additions & 1 deletion OpenSim/Tools/Test/testVisualization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,16 @@ int main()
LoadOpenSimLibrary("osimActuators");

Model testModel("BuiltinGeometry.osim");
testModel.enableVisualization(true);
testVisModel(testModel, "vis_BuiltinGeometry.txt");
std::cout << "BuiltinGeometry Passed" << std::endl;
Model testModel2 = createModel4AppearanceTest();
testModel2.enableVisualization(true);
testVisModel(testModel2, "vis_AppearanceTest.txt");
std::cout << "Appearance test Passed" << std::endl;
// Load Model in 3.3 format that had transforms attached to Geometry
Model testModel3("double_pendulum33.osim");

testModel3.enableVisualization(true);
SimTK::Array_<DecorativeGeometry> standard;
testModel3.updDisplayHints().set_show_frames(true);
populate_doublePendulumPrimitives(standard);
Expand All @@ -138,17 +140,20 @@ int main()
// Now a model from 3.3 where both GeometrySet and individual DisplayGeometry
// have a non-trivial transform.
Model composedTransformsModel("doubletransform33.osim");
composedTransformsModel.enableVisualization(true);
composedTransformsModel.updDisplayHints().set_show_frames(true);
populate_composedTransformPrimitives(standard);
testVisModelAgainstStandard(composedTransformsModel, standard);
// Model with contacts
Model modelWithContacts("visualize_contacts.osim");
modelWithContacts.enableVisualization(true);
modelWithContacts.updDisplayHints().set_show_frames(true);
populate_contactModelPrimitives(standard);
testVisModelAgainstStandard(modelWithContacts, standard);

// Model with WrapObjects
Model modelWithWrap("test_wrapAllVis.osim");
modelWithWrap.enableVisualization(true);
modelWithWrap.updDisplayHints().set_show_frames(true);
populate_wrapModelPrimitives(standard);
modelWithWrap.updDisplayHints().set_show_frames(false);
Expand Down