Simbody  3.7
Visualizer.h
Go to the documentation of this file.
1 #ifndef SimTK_SIMBODY_VISUALIZER_H_
2 #define SimTK_SIMBODY_VISUALIZER_H_
3 
4 /* -------------------------------------------------------------------------- *
5  * Simbody(tm) *
6  * -------------------------------------------------------------------------- *
7  * This is part of the SimTK biosimulation toolkit originating from *
8  * Simbios, the NIH National Center for Physics-Based Simulation of *
9  * Biological Structures at Stanford, funded under the NIH Roadmap for *
10  * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody. *
11  * *
12  * Portions copyright (c) 2010-14 Stanford University and the Authors. *
13  * Authors: Peter Eastman, Michael Sherman *
14  * Contributors: *
15  * *
16  * Licensed under the Apache License, Version 2.0 (the "License"); you may *
17  * not use this file except in compliance with the License. You may obtain a *
18  * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
19  * *
20  * Unless required by applicable law or agreed to in writing, software *
21  * distributed under the License is distributed on an "AS IS" BASIS, *
22  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
23  * See the License for the specific language governing permissions and *
24  * limitations under the License. *
25  * -------------------------------------------------------------------------- */
26 
32 
33 #include <utility> // for std::pair
34 
35 namespace SimTK {
36 
37 class MobilizedBody;
38 class MultibodySystem;
39 class DecorationGenerator;
40 
148 public:
149 class FrameController; // defined below
150 class BodyFollower; // declared below, defined in Visualizer.cpp
151 class InputListener; // defined in Visualizer_InputListener.h
152 class InputSilo; // "
153 class Reporter; // defined in Visualizer_Reporter.h
154 
155 
193 explicit Visualizer(const MultibodySystem& system);
194 
201  const Array_<String>& searchPath);
202 
206 Visualizer(const Visualizer& src);
214 
222 void shutdown();
223 
229 Visualizer& setShutdownWhenDestructed(bool shouldShutdown);
230 
235 
239 enum Mode {
242  PassThrough = 1,
245  Sampling = 2,
247  RealTime = 3
248 };
249 
257  GroundAndSky = 1,
259  SolidColor = 2
260 };
261 
267  ViewMenuId = -1
268 };
269 
288 
289 
297 const Visualizer& setBackgroundColor(const Vec3& color) const;
298 
307 const Visualizer& setShowShadows(bool showShadows) const;
308 
314 const Visualizer& setShowFrameRate(bool showFrameRate) const;
315 
321 const Visualizer& setShowSimTime(bool showSimTime) const;
322 
328 const Visualizer& setShowFrameNumber(bool showFrameNumber) const;
329 
341 const Visualizer& setWindowTitle(const String& title) const;
366 
385 
386 
394 Mode getMode() const;
395 
411 
428 Visualizer& setRealTimeScale(Real simTimePerRealSecond);
432 
469 
481 const InputListener& getInputListener(int i) const;
484 
499 
536 void report(const State& state) const;
537 
544 void flushFrames() const;
545 
550 void drawFrameNow(const State& state) const;
581 Visualizer& addMenu(const String& title, int id,
582  const Array_<std::pair<String, int> >& items);
583 
597 Visualizer& addSlider(const String& title, int id, Real min, Real max, Real value);
598 
604 int addDecoration(MobilizedBodyIndex mobodIx, const Transform& X_BD,
605  const DecorativeGeometry& geometry);
607 int getNumDecorations() const;
609 const DecorativeGeometry& getDecoration(int i) const;
613 
619 int addRubberBandLine(MobilizedBodyIndex b1, const Vec3& station1,
620  MobilizedBodyIndex b2, const Vec3& station2,
621  const DecorativeLine& line);
625 const DecorativeLine& getRubberBandLine(int i) const;
629 
681 const Visualizer& setCameraTransform(const Transform& X_GC) const;
682 
686 
691 const Visualizer& pointCameraAt(const Vec3& point, const Vec3& upDirection) const;
692 
695 
697 const Visualizer& setCameraClippingPlanes(Real nearPlane, Real farPlane) const;
698 
703 const Visualizer& setSliderValue(int slider, Real value) const;
704 
711 const Visualizer& setSliderRange(int slider, Real newMin, Real newMax) const;
712 
713 
719 void dumpStats(std::ostream& o) const;
721 void clearStats();
728 const MultibodySystem& getSystem() const;
729 int getRefCount() const;
732 class Impl;
733 //--------------------------------------------------------------------------
734  private:
735 explicit Visualizer(Impl* impl);
736 Impl* impl;
737 
738 const Impl& getImpl() const {assert(impl); return *impl;}
739 Impl& updImpl() {assert(impl); return *impl;}
740 friend class Impl;
741 };
742 
749 public:
761  virtual void generateControls(const Visualizer& viz,
762  const State& state,
763  Array_<DecorativeGeometry>& geometry) = 0;
764 
767  virtual ~FrameController() {}
768 };
769 
773 // This class is based on the BodyWatcher class that used to be in TimsBox.cpp.
776 public:
796  const Vec3& stationPinB = Vec3(0, 0, 0),
797  const Vec3& offset = Vec3(NaN),
798  const UnitVec3& upDirection = UnitVec3());
799 
801  const Visualizer& viz,
802  const State& state,
803  Array_< DecorativeGeometry >& geometry) override;
804 
805 private:
806  const MobilizedBody& m_mobodB;
807  const Vec3& m_stationPinB;
808  const Vec3& m_offset;
809  const UnitVec3& m_upDirection;
810 };
811 
815 
816 } // namespace SimTK
817 
818 #endif // SimTK_SIMBODY_VISUALIZER_H_
SimTK::Visualizer::setCameraFieldOfView
const Visualizer & setCameraFieldOfView(Real fov) const
Set the camera's vertical field of view, measured in radians.
SimTK::State
This object is intended to contain all state information for a SimTK::System, except topological info...
Definition: State.h:280
SimTK::Visualizer::getFrameControllers
const Array_< FrameController * > & getFrameControllers() const
SimTK::Visualizer::setGroundHeight
Visualizer & setGroundHeight(Real height)
Set the height at which the ground plane should be displayed when the GroundAndSky background type is...
SimTK::Visualizer::getSystemUpDirection
CoordinateDirection getSystemUpDirection() const
Get the value the Visualizer is using as the System "up" direction ( not to be confused with the came...
MobilizedBodyIndex
SimTK::Visualizer::addDecoration
int addDecoration(MobilizedBodyIndex mobodIx, const Transform &X_BD, const DecorativeGeometry &geometry)
Add an always-present, body-fixed piece of geometry like the one passed in, but attached to the indic...
SimTK::Visualizer::updRubberBandLine
DecorativeLine & updRubberBandLine(int i) const
Return a writable reference to the i'th rubber band line.
SimTK::Visualizer::getRealTimeScale
Real getRealTimeScale() const
Return the current time scale, which will be 1 by default.
SimTK::Visualizer::setBackgroundColor
const Visualizer & setBackgroundColor(const Vec3 &color) const
Set the background color. This will be used when the solid background mode is in effect but has no ef...
SimTK::Visualizer::setBackgroundType
Visualizer & setBackgroundType(BackgroundType background)
Change the background mode currently in effect in the GUI. By default we take the desired background ...
SimTK::Visualizer::dumpStats
void dumpStats(std::ostream &o) const
Dump statistics to the given ostream (for example, std::cout).
SimTK::Visualizer::setShowFrameRate
const Visualizer & setShowFrameRate(bool showFrameRate) const
Control whether frame rate is shown in the Visualizer. This is a const method so you can call it from...
SimTK::Visualizer::updDecoration
DecorativeGeometry & updDecoration(int i) const
Return a writable reference to the i'th decoration.
SimTK::Visualizer::clearStats
void clearStats()
Reset all statistics to zero.
SimTK::Visualizer::Visualizer
Visualizer(const MultibodySystem &system)
Construct a new Visualizer for the indicated System, and launch the visualizer display executable fro...
SimTK::Visualizer::addFrameController
int addFrameController(FrameController *controller)
Add a new frame controller to this Visualizer, methods of which will be called just prior to renderin...
SimTK::Visualizer::setSystemUpDirection
Visualizer & setSystemUpDirection(const CoordinateDirection &upDirection)
Set the coordinate direction that should be considered the System's "up" direction....
SimTK::Visualizer::getActualBufferLengthInFrames
int getActualBufferLengthInFrames() const
Get the actual length of the real time frame buffer in number of frames.
SimTK
This is a System that represents the dynamics of a particle moving along a smooth surface.
Definition: Assembler.h:37
SimTK::Visualizer::getGroundHeight
Real getGroundHeight() const
Get the value the Visualizer considers to be the height of the ground plane for this System....
SimTK::Visualizer::Visualizer
Visualizer(const Visualizer &src)
Copy constructor has reference counted, shallow copy semantics; that is, the Visualizer copy is just ...
SimTK::NaN
const Real NaN
This is the IEEE "not a number" constant for this implementation of the default-precision Real type; ...
SimTK::min
ELEM min(const VectorBase< ELEM > &v)
Definition: VectorMath.h:178
SimTK::Visualizer::getNumFrameControllers
int getNumFrameControllers() const
Return the count of frame controllers added with addFrameController().
SimTK::Visualizer::BodyFollower
Causes the camera to point at and follow a point fixed on a body (a station).
Definition: Visualizer.h:775
SimTK::UnitVec< Real, 1 >
SimTK::Visualizer::BackgroundType
BackgroundType
These are the types of backgrounds the visualizer currently supports.
Definition: Visualizer.h:254
SimTK::Visualizer::BodyFollower::generateControls
void generateControls(const Visualizer &viz, const State &state, Array_< DecorativeGeometry > &geometry) override
The Visualizer is just about to generate and render a frame corresponding to the given State.
SimTK::Visualizer::setRealTimeScale
Visualizer & setRealTimeScale(Real simTimePerRealSecond)
In RealTime mode we normally assume that one unit of simulated time should map to one second of real ...
SimTK::Visualizer::setShowSimTime
const Visualizer & setShowSimTime(bool showSimTime) const
Control whether simulation time is shown in the Visualizer. This is a const method so you can call it...
SimTK::Visualizer::getNumDecorationGenerators
int getNumDecorationGenerators() const
Return the count of decoration generators added with addDecorationGenerator().
SimTK::Visualizer::setCameraTransform
const Visualizer & setCameraTransform(const Transform &X_GC) const
Set the transform defining the position and orientation of the camera.
SimTK::Vec< 3 >
SimTK::Visualizer::setShowFrameNumber
const Visualizer & setShowFrameNumber(bool showFrameNumber) const
Control whether frame number is shown in the Visualizer. This is a const method so you can call it fr...
SimTK::Visualizer::updDecorationGenerator
DecorationGenerator & updDecorationGenerator(int i)
Return a writable reference to the i'th decoration generator.
SimTK::Visualizer::getDesiredFrameRate
Real getDesiredFrameRate() const
Get the current value of the frame rate the Visualizer has been asked to attempt; this is not necessa...
SimTK::max
ELEM max(const VectorBase< ELEM > &v)
Definition: VectorMath.h:251
SimTK::Visualizer::zoomCameraToShowAllGeometry
const Visualizer & zoomCameraToShowAllGeometry() const
Move the camera forward or backward so that all geometry in the scene is visible.
SimTK::Visualizer::setShutdownWhenDestructed
Visualizer & setShutdownWhenDestructed(bool shouldShutdown)
Set the flag that determines whether we will automatically send a Shutdown message to the visualizer ...
SimTK::Visualizer::shutdown
void shutdown()
Ask the visualizer to shut itself down immediately.
SimTK::Visualizer::setCameraClippingPlanes
const Visualizer & setCameraClippingPlanes(Real nearPlane, Real farPlane) const
Set the distance from the camera to the near and far clipping planes.
SimTK::Visualizer::report
void report(const State &state) const
Report that a new simulation frame is available for rendering.
SimTK::Visualizer::getDesiredBufferLengthInSec
Real getDesiredBufferLengthInSec() const
Get the current value of the desired buffer time length the Visualizer has been asked to use for smoo...
SimTK::Visualizer::getActualBufferLengthInSec
Real getActualBufferLengthInSec() const
Get the actual length of the real time frame buffer in seconds, which may differ from the requested t...
SimTK::Visualizer::addInputListener
int addInputListener(InputListener *listener)
Add a new input listener to this Visualizer, methods of which will be called when the GUI detects use...
SimTK::MultibodySystem
The job of the MultibodySystem class is to coordinate the activities of various subsystems which can ...
Definition: MultibodySystem.h:48
SimTK::Visualizer::addSlider
Visualizer & addSlider(const String &title, int id, Real min, Real max, Real value)
Add a new slider to the visualizer's display.
SimTK::Visualizer::getShutdownWhenDestructed
bool getShutdownWhenDestructed() const
Return the current setting of the "shutdown when destructed" flag.
SimTK::Visualizer::~Visualizer
~Visualizer()
InputListener, FrameController, and DecorationGenerator objects are destroyed here when the last refe...
SimTK::DecorativeLine
A line between two points.
Definition: DecorativeGeometry.h:306
SimTK::Visualizer::Reporter
This is an EventReporter that makes it easy to generate on-screen movies of any simulation.
Definition: Visualizer_Reporter.h:51
SimTK::Visualizer::FrameController::~FrameController
virtual ~FrameController()
Destructor is virtual; be sure to override it if you have something to clean up at the end.
Definition: Visualizer.h:767
SimTK::Visualizer::setDesiredFrameRate
Visualizer & setDesiredFrameRate(Real framesPerSec)
Set the frame rate in frames/sec (of real time) that you want the Visualizer to attempt to achieve.
SimTK::Visualizer::setShowShadows
const Visualizer & setShowShadows(bool showShadows) const
Control whether shadows are generated when the GroundAndSky background type is in effect....
SimTK::Visualizer::setSliderValue
const Visualizer & setSliderValue(int slider, Real value) const
Change the value currently shown on one of the sliders.
SimTK::DecorativeGeometry
This is the client-side interface to an implementation-independent representation of "Decorations" su...
Definition: DecorativeGeometry.h:86
SimTK::Visualizer::getRubberBandLine
const DecorativeLine & getRubberBandLine(int i) const
Return a const reference to the i'th rubber band line.
SimTK::Visualizer::getFrameController
const FrameController & getFrameController(int i) const
Return a const reference to the i'th frame controller.
SimTK::VTKVisualizer
Visualizer VTKVisualizer
OBSOLETE: This provides limited backwards compatibility with the old VTK Visualizer that is no longer...
Definition: Visualizer.h:814
SimTK::UnitVec3
UnitVec< Real, 1 > UnitVec3
Definition: UnitVec.h:41
SimTK::MobilizedBody
A MobilizedBody is Simbody's fundamental body-and-joint object used to parameterize a system's motion...
Definition: MobilizedBody.h:169
SimTK::Visualizer::addMenu
Visualizer & addMenu(const String &title, int id, const Array_< std::pair< String, int > > &items)
Add a new pull-down menu to the visualizer's display.
SimTK::Visualizer::updFrameController
FrameController & updFrameController(int i)
Return a writable reference to the i'th frame controller.
SimTK_SIMBODY_EXPORT
#define SimTK_SIMBODY_EXPORT
Definition: Simbody/include/simbody/internal/common.h:68
SimTK::Visualizer::getDecorationGenerator
const DecorationGenerator & getDecorationGenerator(int i) const
Return a const reference to the i'th decoration generator.
SimTK::Visualizer::getSystem
const MultibodySystem & getSystem() const
SimTK::Visualizer::operator=
Visualizer & operator=(const Visualizer &src)
Copy assignment has reference counted, shallow copy semantics; that is, the Visualizer copy is just a...
SimTK::Visualizer::getNumDecorations
int getNumDecorations() const
Return the count of decorations added with addDecoration().
SimTK::DecorationGenerator
A DecorationGenerator is used to define geometry that may change over the course of a simulation.
Definition: DecorationGenerator.h:45
SimTK::Visualizer::InputListener
This abstract class defines methods to be called when the Visualizer reports user activity back to th...
Definition: Visualizer_InputListener.h:47
SimTK::Array_
The Array_<T> container class is a plug-compatible replacement for the C++ standard template library ...
Definition: Array.h:53
SimTK::Real
SimTK_Real Real
This is the default compiled-in floating point type for SimTK, either float or double.
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:606
SimTK::Visualizer::drawFrameNow
void drawFrameNow(const State &state) const
This method draws a frame unconditionally without queuing or checking the frame rate.
SimTK::Visualizer::pointCameraAt
const Visualizer & pointCameraAt(const Vec3 &point, const Vec3 &upDirection) const
Rotate the camera so that it looks at a specified point.
SimTK::Visualizer::setSliderRange
const Visualizer & setSliderRange(int slider, Real newMin, Real newMax) const
Change the allowed range for one of the sliders.
SimTK::Vec3
Vec< 3 > Vec3
This is the most common 3D vector type: a column of 3 Real values stored consecutively in memory (pac...
Definition: SmallMatrix.h:129
SimTK::Visualizer::getInputListener
const InputListener & getInputListener(int i) const
Return a const reference to the i'th input listener.
SimTK::Visualizer::addDecorationGenerator
int addDecorationGenerator(DecorationGenerator *generator)
Add a DecorationGenerator that will be invoked to add dynamically generated geometry to each frame of...
SimTK::Visualizer::getDecoration
const DecorativeGeometry & getDecoration(int i) const
Return a const reference to the i'th decoration.
SimTK::Visualizer::InputSilo
This pre-built InputListener is extremely useful for processing user input that is intended to affect...
Definition: Visualizer_InputListener.h:234
SimTK::Visualizer::setWindowTitle
const Visualizer & setWindowTitle(const String &title) const
Change the title on the main visualizer window. The default title is Simbody version : exename,...
SimTK::Visualizer::BodyFollower::BodyFollower
BodyFollower(const MobilizedBody &mobodB, const Vec3 &stationPinB=Vec3(0, 0, 0), const Vec3 &offset=Vec3(NaN), const UnitVec3 &upDirection=UnitVec3())
SimTK::String
SimTK::String is a plug-compatible std::string replacement (plus some additional functionality) inten...
Definition: String.h:62
SimTK::Visualizer::Visualizer
Visualizer(const MultibodySystem &system, const Array_< String > &searchPath)
Construct a new Visualizer for a given system, with a specified search path for locating the SimbodyV...
SimTK::Visualizer::getMode
Mode getMode() const
Get the current mode being used by the Visualizer.
SimTK::Visualizer::getRefCount
int getRefCount() const
SimTK::Visualizer::addRubberBandLine
int addRubberBandLine(MobilizedBodyIndex b1, const Vec3 &station1, MobilizedBodyIndex b2, const Vec3 &station2, const DecorativeLine &line)
Add an always-present rubber band line, modeled after the DecorativeLine supplied here.
SimTK::Visualizer::getNumInputListeners
int getNumInputListeners() const
Return the count of input listeners added with addInputListener().
SimTK::Transform_< Real >
SimTK::Visualizer::Mode
Mode
These are the operating modes for the Visualizer, with PassThrough the default mode.
Definition: Visualizer.h:239
SimTK::Visualizer::PredefinedMenuIds
PredefinedMenuIds
The visualizer may predefine some menus; if you need to refer to one of those use its menu Id as defi...
Definition: Visualizer.h:265
SimTK::Visualizer::FrameController
This abstract class represents an object that will be invoked by the Visualizer just prior to renderi...
Definition: Visualizer.h:748
SimTK::Visualizer::setDesiredBufferLengthInSec
Visualizer & setDesiredBufferLengthInSec(Real bufferLengthInSec)
When running an interactive realtime simulation, you can smooth out changes in simulation run rate by...
SimTK::CoordinateDirection
A CoordinateDirection is a CoordinateAxis plus a direction indicating the positive or negative direct...
Definition: CoordinateAxis.h:244
SimTK::Visualizer::setMode
Visualizer & setMode(Mode mode)
Set the operating mode for the Visualizer.
common.h
SimTK::Visualizer::getNumRubberBandLines
int getNumRubberBandLines() const
Return the count of rubber band lines added with addRubberBandLine().
SimTK::Visualizer::getInputListeners
const Array_< InputListener * > & getInputListeners() const
SimTK::Visualizer::updInputListener
InputListener & updInputListener(int i)
Return a writable reference to the i'th input listener.
SimTK::Visualizer::FrameController::generateControls
virtual void generateControls(const Visualizer &viz, const State &state, Array_< DecorativeGeometry > &geometry)=0
The Visualizer is just about to generate and render a frame corresponding to the given State.
SimTK::Visualizer
Provide simple visualization of and interaction with a Simbody simulation, with real time control of ...
Definition: Visualizer.h:147
SimTK::Visualizer::flushFrames
void flushFrames() const
In RealTime mode there will typically be frames still in the buffer at the end of a simulation....