Simbody  3.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-12 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 
181 explicit Visualizer(const MultibodySystem& system);
182 
188 Visualizer(const MultibodySystem& system,
189  const Array_<String>& searchPath);
190 
194 Visualizer(const Visualizer& src);
198 Visualizer& operator=(const Visualizer& src);
201 ~Visualizer();
202 
210 void shutdown();
211 
217 Visualizer& setShutdownWhenDestructed(bool shouldShutdown);
218 
222 bool getShutdownWhenDestructed() const;
223 
227 enum Mode {
230  PassThrough = 1,
233  Sampling = 2,
235  RealTime = 3
236 };
237 
245  GroundAndSky = 1,
247  SolidColor = 2
248 };
249 
255  ViewMenuId = -1
256 };
257 
275 Visualizer& setBackgroundType(BackgroundType background);
276 
277 
285 const Visualizer& setBackgroundColor(const Vec3& color) const;
286 
295 const Visualizer& setShowShadows(bool showShadows) const;
296 
302 const Visualizer& setShowFrameRate(bool showFrameRate) const;
303 
309 const Visualizer& setShowSimTime(bool showSimTime) const;
310 
316 const Visualizer& setShowFrameNumber(bool showFrameNumber) const;
317 
329 const Visualizer& setWindowTitle(const String& title) const;
350 Visualizer& setSystemUpDirection(const CoordinateDirection& upDirection);
353 CoordinateDirection getSystemUpDirection() const;
354 
368 Visualizer& setGroundHeight(Real height);
372 Real getGroundHeight() const;
373 
374 
379 void setMode(Mode mode);
382 Mode getMode() const;
383 
392 Visualizer& setDesiredFrameRate(Real framesPerSec);
398 Real getDesiredFrameRate() const;
399 
416 Visualizer& setRealTimeScale(Real simTimePerRealSecond);
419 Real getRealTimeScale() const;
420 
444 Visualizer& setDesiredBufferLengthInSec(Real bufferLengthInSec);
450 Real getDesiredBufferLengthInSec() const;
454 Real getActualBufferLengthInSec() const;
456 int getActualBufferLengthInFrames() const;
457 
465 int addInputListener(InputListener* listener);
467 int getNumInputListeners() const;
469 const InputListener& getInputListener(int i) const;
471 InputListener& updInputListener(int i);
472 
480 int addFrameController(FrameController* controller);
482 int getNumFrameControllers() const;
484 const FrameController& getFrameController(int i) const;
486 FrameController& updFrameController(int i);
487 
524 void report(const State& state) const;
525 
532 void flushFrames() const;
533 
538 void drawFrameNow(const State& state) const;
569 Visualizer& addMenu(const String& title, int id,
570  const Array_<std::pair<String, int> >& items);
571 
585 Visualizer& addSlider(const String& title, int id, Real min, Real max, Real value);
586 
592 int addDecoration(MobilizedBodyIndex mobodIx, const Transform& X_BD,
593  const DecorativeGeometry& geometry);
595 int getNumDecorations() const;
597 const DecorativeGeometry& getDecoration(int i) const;
600 DecorativeGeometry& updDecoration(int i) const;
601 
607 int addRubberBandLine(MobilizedBodyIndex b1, const Vec3& station1,
608  MobilizedBodyIndex b2, const Vec3& station2,
609  const DecorativeLine& line);
611 int getNumRubberBandLines() const;
613 const DecorativeLine& getRubberBandLine(int i) const;
616 DecorativeLine& updRubberBandLine(int i) const;
617 
624 int addDecorationGenerator(DecorationGenerator* generator);
627 int getNumDecorationGenerators() const;
629 const DecorationGenerator& getDecorationGenerator(int i) const;
631 DecorationGenerator& updDecorationGenerator(int i);
667 const Visualizer& setCameraTransform(const Transform& X_GC) const;
668 
671 const Visualizer& zoomCameraToShowAllGeometry() const;
672 
677 const Visualizer& pointCameraAt(const Vec3& point, const Vec3& upDirection) const;
678 
680 const Visualizer& setCameraFieldOfView(Real fov) const;
681 
683 const Visualizer& setCameraClippingPlanes(Real nearPlane, Real farPlane) const;
684 
689 const Visualizer& setSliderValue(int slider, Real value) const;
690 
697 const Visualizer& setSliderRange(int slider, Real newMin, Real newMax) const;
698 
699 
705 void dumpStats(std::ostream& o) const;
707 void clearStats();
712 const Array_<InputListener*>& getInputListeners() const;
713 const Array_<FrameController*>& getFrameControllers() const;
714 const MultibodySystem& getSystem() const;
715 int getRefCount() const;
718 class Impl;
719 //--------------------------------------------------------------------------
720  private:
721 explicit Visualizer(Impl* impl);
722 Impl* impl;
723 
724 const Impl& getImpl() const {assert(impl); return *impl;}
725 Impl& updImpl() {assert(impl); return *impl;}
726 friend class Impl;
727 };
728 
735 public:
747  virtual void generateControls(const Visualizer& viz,
748  const State& state,
749  Array_<DecorativeGeometry>& geometry) = 0;
750 
753  virtual ~FrameController() {}
754 };
755 
759 
760 } // namespace SimTK
761 
762 #endif // SimTK_SIMBODY_VISUALIZER_H_
This is for arrays indexed by mobilized body number within a subsystem (typically the SimbodyMatterSu...
A CoordinateDirection is a CoordinateAxis plus a direction indicating the positive or negative direct...
Definition: CoordinateAxis.h:246
Mode
These are the operating modes for the Visualizer, with PassThrough the default mode.
Definition: Visualizer.h:227
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...
This is the handle class for the hidden State implementation.
Definition: State.h:264
This abstract class represents an object that will be invoked by the Visualizer just prior to renderi...
Definition: Visualizer.h:734
PredefinedMenuIds
The VisualizerGUI may predefine some menus; if you need to refer to one of those use its menu Id as d...
Definition: Visualizer.h:253
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:758
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 VisualizerGUI currently supports.
Definition: Visualizer.h:242
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:753
A line between two points.
Definition: DecorativeGeometry.h:254
Provide simple visualization of and interaction with a Simbody simulation, with real time control of ...
Definition: Visualizer.h:146