Simbody  3.5
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 MultibodySystem;
38 class DecorationGenerator;
39 
147 public:
148 class FrameController; // defined below
149 class InputListener; // defined in Visualizer_InputListener.h
150 class InputSilo; // "
151 class Reporter; // defined in Visualizer_Reporter.h
152 
153 
188 explicit Visualizer(const MultibodySystem& system);
189 
195 Visualizer(const MultibodySystem& system,
196  const Array_<String>& searchPath);
197 
201 Visualizer(const Visualizer& src);
205 Visualizer& operator=(const Visualizer& src);
208 ~Visualizer();
209 
217 void shutdown();
218 
224 Visualizer& setShutdownWhenDestructed(bool shouldShutdown);
225 
229 bool getShutdownWhenDestructed() const;
230 
234 enum Mode {
237  PassThrough = 1,
240  Sampling = 2,
242  RealTime = 3
243 };
244 
252  GroundAndSky = 1,
254  SolidColor = 2
255 };
256 
262  ViewMenuId = -1
263 };
264 
282 Visualizer& setBackgroundType(BackgroundType background);
283 
284 
292 const Visualizer& setBackgroundColor(const Vec3& color) const;
293 
302 const Visualizer& setShowShadows(bool showShadows) const;
303 
309 const Visualizer& setShowFrameRate(bool showFrameRate) const;
310 
316 const Visualizer& setShowSimTime(bool showSimTime) const;
317 
323 const Visualizer& setShowFrameNumber(bool showFrameNumber) const;
324 
336 const Visualizer& setWindowTitle(const String& title) const;
357 Visualizer& setSystemUpDirection(const CoordinateDirection& upDirection);
360 CoordinateDirection getSystemUpDirection() const;
361 
375 Visualizer& setGroundHeight(Real height);
379 Real getGroundHeight() const;
380 
381 
386 Visualizer& setMode(Mode mode);
389 Mode getMode() const;
390 
399 Visualizer& setDesiredFrameRate(Real framesPerSec);
405 Real getDesiredFrameRate() const;
406 
423 Visualizer& setRealTimeScale(Real simTimePerRealSecond);
426 Real getRealTimeScale() const;
427 
451 Visualizer& setDesiredBufferLengthInSec(Real bufferLengthInSec);
457 Real getDesiredBufferLengthInSec() const;
461 Real getActualBufferLengthInSec() const;
463 int getActualBufferLengthInFrames() const;
464 
472 int addInputListener(InputListener* listener);
474 int getNumInputListeners() const;
476 const InputListener& getInputListener(int i) const;
478 InputListener& updInputListener(int i);
479 
487 int addFrameController(FrameController* controller);
489 int getNumFrameControllers() const;
491 const FrameController& getFrameController(int i) const;
493 FrameController& updFrameController(int i);
494 
531 void report(const State& state) const;
532 
539 void flushFrames() const;
540 
545 void drawFrameNow(const State& state) const;
576 Visualizer& addMenu(const String& title, int id,
577  const Array_<std::pair<String, int> >& items);
578 
592 Visualizer& addSlider(const String& title, int id, Real min, Real max, Real value);
593 
599 int addDecoration(MobilizedBodyIndex mobodIx, const Transform& X_BD,
600  const DecorativeGeometry& geometry);
602 int getNumDecorations() const;
604 const DecorativeGeometry& getDecoration(int i) const;
607 DecorativeGeometry& updDecoration(int i) const;
608 
614 int addRubberBandLine(MobilizedBodyIndex b1, const Vec3& station1,
615  MobilizedBodyIndex b2, const Vec3& station2,
616  const DecorativeLine& line);
618 int getNumRubberBandLines() const;
620 const DecorativeLine& getRubberBandLine(int i) const;
623 DecorativeLine& updRubberBandLine(int i) const;
624 
631 int addDecorationGenerator(DecorationGenerator* generator);
634 int getNumDecorationGenerators() const;
636 const DecorationGenerator& getDecorationGenerator(int i) const;
638 DecorationGenerator& updDecorationGenerator(int i);
674 const Visualizer& setCameraTransform(const Transform& X_GC) const;
675 
678 const Visualizer& zoomCameraToShowAllGeometry() const;
679 
684 const Visualizer& pointCameraAt(const Vec3& point, const Vec3& upDirection) const;
685 
687 const Visualizer& setCameraFieldOfView(Real fov) const;
688 
690 const Visualizer& setCameraClippingPlanes(Real nearPlane, Real farPlane) const;
691 
696 const Visualizer& setSliderValue(int slider, Real value) const;
697 
704 const Visualizer& setSliderRange(int slider, Real newMin, Real newMax) const;
705 
706 
712 void dumpStats(std::ostream& o) const;
714 void clearStats();
719 const Array_<InputListener*>& getInputListeners() const;
720 const Array_<FrameController*>& getFrameControllers() const;
721 const MultibodySystem& getSystem() const;
722 int getRefCount() const;
725 class Impl;
726 //--------------------------------------------------------------------------
727  private:
728 explicit Visualizer(Impl* impl);
729 Impl* impl;
730 
731 const Impl& getImpl() const {assert(impl); return *impl;}
732 Impl& updImpl() {assert(impl); return *impl;}
733 friend class Impl;
734 };
735 
742 public:
754  virtual void generateControls(const Visualizer& viz,
755  const State& state,
756  Array_<DecorativeGeometry>& geometry) = 0;
757 
760  virtual ~FrameController() {}
761 };
762 
766 
767 } // namespace SimTK
768 
769 #endif // SimTK_SIMBODY_VISUALIZER_H_
This is for arrays indexed by mobilized body number within a subsystem (typically the SimbodyMatterSu...
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:234
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:593
This object is intended to contain all state information for a SimTK::System, except topological info...
Definition: State.h:276
This abstract class represents an object that will be invoked by the Visualizer just prior to renderi...
Definition: Visualizer.h:741
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:260
A DecorationGenerator is used to define geometry that may change over the course of a simulation...
Definition: DecorationGenerator.h:45
The SimTK::Array_<T> container class is a plug-compatible replacement for the C++ standard template l...
Definition: Array.h:50
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:765
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:72
BackgroundType
These are the types of backgrounds the visualizer currently supports.
Definition: Visualizer.h:249
This abstract class defines methods to be called when the Visualizer reports user activity back to th...
Definition: Visualizer_InputListener.h:47
virtual ~FrameController()
Destructor is virtual; be sure to override it if you have something to clean up at the end...
Definition: Visualizer.h:760
A line between two points.
Definition: DecorativeGeometry.h:304
Provide simple visualization of and interaction with a Simbody simulation, with real time control of ...
Definition: Visualizer.h:146