Simbody  3.6
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 
190 explicit Visualizer(const MultibodySystem& system);
191 
197 Visualizer(const MultibodySystem& system,
198  const Array_<String>& searchPath);
199 
203 Visualizer(const Visualizer& src);
207 Visualizer& operator=(const Visualizer& src);
210 ~Visualizer();
211 
219 void shutdown();
220 
226 Visualizer& setShutdownWhenDestructed(bool shouldShutdown);
227 
231 bool getShutdownWhenDestructed() const;
232 
236 enum Mode {
239  PassThrough = 1,
242  Sampling = 2,
244  RealTime = 3
245 };
246 
254  GroundAndSky = 1,
256  SolidColor = 2
257 };
258 
264  ViewMenuId = -1
265 };
266 
284 Visualizer& setBackgroundType(BackgroundType background);
285 
286 
294 const Visualizer& setBackgroundColor(const Vec3& color) const;
295 
304 const Visualizer& setShowShadows(bool showShadows) const;
305 
311 const Visualizer& setShowFrameRate(bool showFrameRate) const;
312 
318 const Visualizer& setShowSimTime(bool showSimTime) const;
319 
325 const Visualizer& setShowFrameNumber(bool showFrameNumber) const;
326 
338 const Visualizer& setWindowTitle(const String& title) const;
359 Visualizer& setSystemUpDirection(const CoordinateDirection& upDirection);
362 CoordinateDirection getSystemUpDirection() const;
363 
377 Visualizer& setGroundHeight(Real height);
381 Real getGroundHeight() const;
382 
383 
388 Visualizer& setMode(Mode mode);
391 Mode getMode() const;
392 
401 Visualizer& setDesiredFrameRate(Real framesPerSec);
407 Real getDesiredFrameRate() const;
408 
425 Visualizer& setRealTimeScale(Real simTimePerRealSecond);
428 Real getRealTimeScale() const;
429 
453 Visualizer& setDesiredBufferLengthInSec(Real bufferLengthInSec);
459 Real getDesiredBufferLengthInSec() const;
463 Real getActualBufferLengthInSec() const;
465 int getActualBufferLengthInFrames() const;
466 
474 int addInputListener(InputListener* listener);
476 int getNumInputListeners() const;
478 const InputListener& getInputListener(int i) const;
480 InputListener& updInputListener(int i);
481 
489 int addFrameController(FrameController* controller);
491 int getNumFrameControllers() const;
493 const FrameController& getFrameController(int i) const;
495 FrameController& updFrameController(int i);
496 
533 void report(const State& state) const;
534 
541 void flushFrames() const;
542 
547 void drawFrameNow(const State& state) const;
578 Visualizer& addMenu(const String& title, int id,
579  const Array_<std::pair<String, int> >& items);
580 
594 Visualizer& addSlider(const String& title, int id, Real min, Real max, Real value);
595 
601 int addDecoration(MobilizedBodyIndex mobodIx, const Transform& X_BD,
602  const DecorativeGeometry& geometry);
604 int getNumDecorations() const;
606 const DecorativeGeometry& getDecoration(int i) const;
609 DecorativeGeometry& updDecoration(int i) const;
610 
616 int addRubberBandLine(MobilizedBodyIndex b1, const Vec3& station1,
617  MobilizedBodyIndex b2, const Vec3& station2,
618  const DecorativeLine& line);
620 int getNumRubberBandLines() const;
622 const DecorativeLine& getRubberBandLine(int i) const;
625 DecorativeLine& updRubberBandLine(int i) const;
626 
633 int addDecorationGenerator(DecorationGenerator* generator);
636 int getNumDecorationGenerators() const;
638 const DecorationGenerator& getDecorationGenerator(int i) const;
640 DecorationGenerator& updDecorationGenerator(int i);
678 const Visualizer& setCameraTransform(const Transform& X_GC) const;
679 
682 const Visualizer& zoomCameraToShowAllGeometry() const;
683 
688 const Visualizer& pointCameraAt(const Vec3& point, const Vec3& upDirection) const;
689 
691 const Visualizer& setCameraFieldOfView(Real fov) const;
692 
694 const Visualizer& setCameraClippingPlanes(Real nearPlane, Real farPlane) const;
695 
700 const Visualizer& setSliderValue(int slider, Real value) const;
701 
708 const Visualizer& setSliderRange(int slider, Real newMin, Real newMax) const;
709 
710 
716 void dumpStats(std::ostream& o) const;
718 void clearStats();
723 const Array_<InputListener*>& getInputListeners() const;
724 const Array_<FrameController*>& getFrameControllers() const;
725 const MultibodySystem& getSystem() const;
726 int getRefCount() const;
729 class Impl;
730 //--------------------------------------------------------------------------
731  private:
732 explicit Visualizer(Impl* impl);
733 Impl* impl;
734 
735 const Impl& getImpl() const {assert(impl); return *impl;}
736 Impl& updImpl() {assert(impl); return *impl;}
737 friend class Impl;
738 };
739 
746 public:
758  virtual void generateControls(const Visualizer& viz,
759  const State& state,
760  Array_<DecorativeGeometry>& geometry) = 0;
761 
764  virtual ~FrameController() {}
765 };
766 
770 // This class is based on the BodyWatcher class that used to be in TimsBox.cpp.
773 public:
792  BodyFollower(const MobilizedBody& mobodB,
793  const Vec3& stationPinB = Vec3(0, 0, 0),
794  const Vec3& offset = Vec3(NaN),
795  const UnitVec3& upDirection = UnitVec3());
796 
797  void generateControls(
798  const Visualizer& viz,
799  const State& state,
800  Array_< DecorativeGeometry >& geometry) override;
801 
802 private:
803  const MobilizedBody& m_mobodB;
804  const Vec3& m_stationPinB;
805  const Vec3& m_offset;
806  const UnitVec3& m_upDirection;
807 };
808 
812 
813 } // namespace SimTK
814 
815 #endif // SimTK_SIMBODY_VISUALIZER_H_
Causes the camera to point at and follow a point fixed on a body (a station).
Definition: Visualizer.h:771
This is for arrays indexed by mobilized body number within a subsystem (typically the SimbodyMatterSu...
UnitVec< Real, 1 > UnitVec3
Definition: UnitVec.h:41
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
A CoordinateDirection is a CoordinateAxis plus a direction indicating the positive or negative direct...
Definition: CoordinateAxis.h:244
Mode
These are the operating modes for the Visualizer, with PassThrough the default mode.
Definition: Visualizer.h:236
ELEM min(const VectorBase< ELEM > &v)
Definition: VectorMath.h:178
This pre-built InputListener is extremely useful for processing user input that is intended to affect...
Definition: Visualizer_InputListener.h:233
Every Simbody header and source file should include this header before any other Simbody header...
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
This object is intended to contain all state information for a SimTK::System, except topological info...
Definition: State.h:280
const Real NaN
This is the IEEE "not a number" constant for this implementation of the default-precision Real type; ...
This abstract class represents an object that will be invoked by the Visualizer just prior to renderi...
Definition: Visualizer.h:745
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:262
A DecorationGenerator is used to define geometry that may change over the course of a simulation...
Definition: DecorationGenerator.h:45
The Array_<T> container class is a plug-compatible replacement for the C++ standard template library ...
Definition: Array.h:53
This is an EventReporter that makes it easy to generate on-screen movies of any simulation.
Definition: Visualizer_Reporter.h:51
ELEM max(const VectorBase< ELEM > &v)
Definition: VectorMath.h:251
The job of the MultibodySystem class is to coordinate the activities of various subsystems which can ...
Definition: MultibodySystem.h:48
This is the client-side interface to an implementation-independent representation of "Decorations" su...
Definition: DecorativeGeometry.h:86
Visualizer VTKVisualizer
OBSOLETE: This provides limited backwards compatibility with the old VTK Visualizer that is no longer...
Definition: Visualizer.h:811
SimTK::String is a plug-compatible std::string replacement (plus some additional functionality) inten...
Definition: String.h:62
#define SimTK_SIMBODY_EXPORT
Definition: Simbody/include/simbody/internal/common.h:68
A MobilizedBody is Simbody&#39;s fundamental body-and-joint object used to parameterize a system&#39;s motion...
Definition: MobilizedBody.h:168
BackgroundType
These are the types of backgrounds the visualizer currently supports.
Definition: Visualizer.h:251
This abstract class defines methods to be called when the Visualizer reports user activity back to th...
Definition: Visualizer_InputListener.h:47
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
virtual ~FrameController()
Destructor is virtual; be sure to override it if you have something to clean up at the end...
Definition: Visualizer.h:764
A line between two points.
Definition: DecorativeGeometry.h:306
Provide simple visualization of and interaction with a Simbody simulation, with real time control of ...
Definition: Visualizer.h:147