Simbody

Visualizer.h

Go to the documentation of this file.
00001 #ifndef SimTK_SIMBODY_VISUALIZER_H_
00002 #define SimTK_SIMBODY_VISUALIZER_H_
00003 
00004 /* -------------------------------------------------------------------------- *
00005  *                              SimTK Simbody(tm)                             *
00006  * -------------------------------------------------------------------------- *
00007  * This is part of the SimTK biosimulation toolkit originating from           *
00008  * Simbios, the NIH National Center for Physics-Based Simulation of           *
00009  * Biological Structures at Stanford, funded under the NIH Roadmap for        *
00010  * Medical Research, grant U54 GM072970. See https://simtk.org.               *
00011  *                                                                            *
00012  * Portions copyright (c) 2010 Stanford University and the Authors.           *
00013  * Authors: Peter Eastman, Michael Sherman                                    *
00014  * Contributors:                                                              *
00015  *                                                                            *
00016  * Permission is hereby granted, free of charge, to any person obtaining a    *
00017  * copy of this software and associated documentation files (the "Software"), *
00018  * to deal in the Software without restriction, including without limitation  *
00019  * the rights to use, copy, modify, merge, publish, distribute, sublicense,   *
00020  * and/or sell copies of the Software, and to permit persons to whom the      *
00021  * Software is furnished to do so, subject to the following conditions:       *
00022  *                                                                            *
00023  * The above copyright notice and this permission notice shall be included in *
00024  * all copies or substantial portions of the Software.                        *
00025  *                                                                            *
00026  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
00027  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *
00028  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    *
00029  * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,    *
00030  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR      *
00031  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  *
00032  * USE OR OTHER DEALINGS IN THE SOFTWARE.                                     *
00033  * -------------------------------------------------------------------------- */
00034 
00040 #include "simbody/internal/common.h"
00041 
00042 #include <utility> // for std::pair
00043 
00044 namespace SimTK {
00045 
00046 class MultibodySystem;
00047 class DecorationGenerator;
00048 
00155 class SimTK_SIMBODY_EXPORT Visualizer {
00156 public:
00157 class FrameController; // defined below
00158 class InputListener;   // defined in Visualizer_InputListener.h
00159 class InputSilo;       //                 "
00160 class Reporter;        // defined in Visualizer_Reporter.h
00161 
00162 
00171 Visualizer(const MultibodySystem& system);
00175 Visualizer(const Visualizer& src);
00179 Visualizer& operator=(const Visualizer& src);
00182 ~Visualizer();
00183 
00187 enum Mode {
00190     PassThrough = 1,
00193     Sampling    = 2,
00195     RealTime    = 3
00196 };
00197 
00202 enum BackgroundType {
00205     GroundAndSky = 1,
00207     SolidColor   = 2
00208 };
00209 
00213 enum PredefinedMenuIds {
00215     ViewMenuId    = -1
00216 };
00217 
00235 Visualizer& setBackgroundType(BackgroundType background);
00236 
00237 
00245 const Visualizer& setBackgroundColor(const Vec3& color) const;
00246 
00255 const Visualizer& setShowShadows(bool showShadows) const;
00256 
00268 const Visualizer& setWindowTitle(const String& title) const;
00289 Visualizer& setSystemUpDirection(const CoordinateDirection& upDirection);
00292 CoordinateDirection getSystemUpDirection() const;
00293 
00307 Visualizer& setGroundHeight(Real height);
00311 Real getGroundHeight() const;
00312 
00313 
00318 void setMode(Mode mode);
00321 Mode getMode() const;
00322 
00331 Visualizer& setDesiredFrameRate(Real framesPerSec);
00337 Real getDesiredFrameRate() const;
00338 
00355 Visualizer& setRealTimeScale(Real simTimePerRealSecond);
00358 Real getRealTimeScale() const;
00359 
00383 Visualizer& setDesiredBufferLengthInSec(Real bufferLengthInSec);
00389 Real getDesiredBufferLengthInSec() const;
00393 Real getActualBufferLengthInSec() const;
00395 int getActualBufferLengthInFrames() const;
00396 
00405 Visualizer& addInputListener(InputListener* listener);
00406 
00415 Visualizer& addFrameController(FrameController* controller);
00416 
00453 void report(const State& state) const;
00454 
00461 void flushFrames() const;
00462 
00467 void drawFrameNow(const State& state) const;
00498 Visualizer& addMenu(const String& title, int id, 
00499                    const Array_<std::pair<String, int> >& items);
00500 
00514 Visualizer& addSlider(const String& title, int id, Real min, Real max, Real value);
00515 
00522 Visualizer& addDecoration(MobilizedBodyIndex, const Transform& X_BD, 
00523                    const DecorativeGeometry&);
00524 
00531 Visualizer& addRubberBandLine(MobilizedBodyIndex b1, const Vec3& station1,
00532                         MobilizedBodyIndex b2, const Vec3& station2,
00533                         const DecorativeLine& line);
00534 
00541 Visualizer& addDecorationGenerator(DecorationGenerator* generator);
00577 const Visualizer& setCameraTransform(const Transform& X_GC) const;
00578 
00581 const Visualizer& zoomCameraToShowAllGeometry() const;
00582 
00587 const Visualizer& pointCameraAt(const Vec3& point, const Vec3& upDirection) const;
00588 
00590 const Visualizer& setCameraFieldOfView(Real fov) const;
00591 
00593 const Visualizer& setCameraClippingPlanes(Real nearPlane, Real farPlane) const;
00594 
00599 const Visualizer& setSliderValue(int slider, Real value) const;
00600 
00607 const Visualizer& setSliderRange(int slider, Real newMin, Real newMax) const;
00608 
00609 
00615 void dumpStats(std::ostream& o) const;
00617 void clearStats();
00622 const Array_<InputListener*>&   getInputListeners() const;
00623 const Array_<FrameController*>& getFrameControllers() const;
00624 const MultibodySystem&          getSystem() const;
00625 int getRefCount() const;
00628 class Impl;
00629 //--------------------------------------------------------------------------
00630                                 private:
00631 explicit Visualizer(Impl* impl);
00632 Impl* impl;
00633 
00634 const Impl& getImpl() const {assert(impl); return *impl;}
00635 Impl&       updImpl()       {assert(impl); return *impl;}
00636 friend class Impl;
00637 };
00638 
00644 class SimTK_SIMBODY_EXPORT Visualizer::FrameController {
00645 public:
00657     virtual void generateControls(const Visualizer&           viz, 
00658                                   const State&                state,
00659                                   Array_<DecorativeGeometry>& geometry) = 0;
00660 
00663     virtual ~FrameController() {}
00664 };
00665 
00668 typedef Visualizer VTKVisualizer;
00669 
00670 } // namespace SimTK
00671 
00672 #endif // SimTK_SIMBODY_VISUALIZER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines