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 2 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
1 change: 1 addition & 0 deletions OpenSim/Common/ModelDisplayHints.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ your component produces. The currently-supported flags are:
- show frames
- show labels
- show debug geometry
- no visualization

This class is intended to provide some minimal user control over generated
geometry in a form that is easy for a ModelComponent author to deal with, since
Expand Down
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->isVisualizationDisabled())
return;

// Current interface to Visualizer calls generateDecorations on every
// frame. On first time through, load file and create DecorativeMeshFile
Expand Down
11 changes: 10 additions & 1 deletion OpenSim/Simulation/Model/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,16 @@ OpenSim_OBJECT_NONTEMPLATE_DEFS(Model, ModelComponent);
SimTK::Array_<SimTK::DecorativeGeometry>& appendToThis) const
override;
/**@}**/

// Turn off visualization/loading of meshes for this model
// initSystem must be invoked after this call for it to take effect.
void disableVisualization() {
upd_ModelVisualPreferences().set_no_visualization(true);
}
// Return flag indicating if visualization has been turned off
bool isVisualizationDisabled() const {
return get_ModelVisualPreferences().get_no_visualization();
}

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

private:
Expand Down
4 changes: 4 additions & 0 deletions OpenSim/Simulation/Model/ModelVisualPreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class OSIMSIMULATION_API ModelVisualPreferences : public Object {
OpenSim_DECLARE_UNNAMED_PROPERTY(ModelDisplayHints,
"Model display preferences");

OpenSim_DECLARE_PROPERTY(no_visualization, bool,
"Flag to indicate whether or not to show geometry from mesh files, default to false.");

//--------------------------------------------------------------------------
// CONSTRUCTION
//--------------------------------------------------------------------------
Expand All @@ -66,6 +69,7 @@ class OSIMSIMULATION_API ModelVisualPreferences : public Object {
private:
void constructProperties() {
constructProperty_ModelDisplayHints(ModelDisplayHints());
constructProperty_no_visualization(false);
Copy link
Member

Choose a reason for hiding this comment

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

We should avoid the possibility for double negatives. I would prefer this setting to be named "visualize" or something like that.

Copy link
Member

Choose a reason for hiding this comment

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

I don't disagree.

Copy link
Member Author

Choose a reason for hiding this comment

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

I made sure the user facing convenience method name is clear, I definitely welcome better names for the property that will appear in xml and will flip the logic accordingly. I don't particularly like visualize as it is close to "visualizer" so rather overused, but I welcome other opinions.

Copy link
Member

Choose a reason for hiding this comment

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

The description is "Flag to indicate whether or not to show geometry from mesh files, default to false." so I assume analytic geometry would still visualize. If that's the case, then perhaps put "Mesh" in the name of the property, like loadMeshFiles?

Copy link
Member Author

Choose a reason for hiding this comment

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

@tkuchida I would have called it show_meshes but I wanted to get feedback on (item 3) whether we want to use this more widely to avoid calling generateDecorations altogether which would affect all geometry but may be more efficient.

Copy link
Member

@aseth1 aseth1 Jul 11, 2019

Choose a reason for hiding this comment

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

This seems somewhat confusing to me particularly in context of existing Model::get/setUseVisualizer(). I realize that this is for the API visualizer and not the GUI visualizer. If you are not using the API visualizer (and you are not in the GUI) you would expect zero overhead/errors related to visualization. If you are in the GUI or have the visualizer on, then visualize should be true. You shouldn't have to turn two flags on.

I like the idea of bypassing generateDecorations() altogether if there is no visualization.

Can we simplify the interface and only have one internal visualize flag without exposing any properties? If getUseVisualizer is true then it is true. The GUI turns it to true but otherwise it is false.

}
//=============================================================================
}; // END of class ModelVisualPreferences
Expand Down