Simbody  3.5
Visualizer.h
Go to the documentation of this file.
00001 #ifndef SimTK_SIMBODY_VISUALIZER_H_
00002 #define SimTK_SIMBODY_VISUALIZER_H_
00003 
00004 /* -------------------------------------------------------------------------- *
00005  *                               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/home/simbody.  *
00011  *                                                                            *
00012  * Portions copyright (c) 2010-14 Stanford University and the Authors.        *
00013  * Authors: Peter Eastman, Michael Sherman                                    *
00014  * Contributors:                                                              *
00015  *                                                                            *
00016  * Licensed under the Apache License, Version 2.0 (the "License"); you may    *
00017  * not use this file except in compliance with the License. You may obtain a  *
00018  * copy of the License at http://www.apache.org/licenses/LICENSE-2.0.         *
00019  *                                                                            *
00020  * Unless required by applicable law or agreed to in writing, software        *
00021  * distributed under the License is distributed on an "AS IS" BASIS,          *
00022  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
00023  * See the License for the specific language governing permissions and        *
00024  * limitations under the License.                                             *
00025  * -------------------------------------------------------------------------- */
00026 
00031 #include "simbody/internal/common.h"
00032 
00033 #include <utility> // for std::pair
00034 
00035 namespace SimTK {
00036 
00037 class MultibodySystem;
00038 class DecorationGenerator;
00039 
00146 class SimTK_SIMBODY_EXPORT Visualizer {
00147 public:
00148 class FrameController; // defined below
00149 class InputListener;   // defined in Visualizer_InputListener.h
00150 class InputSilo;       //                 "
00151 class Reporter;        // defined in Visualizer_Reporter.h
00152 
00153 
00188 explicit Visualizer(const MultibodySystem& system);
00189 
00195 Visualizer(const MultibodySystem& system,
00196            const Array_<String>&  searchPath);
00197 
00201 Visualizer(const Visualizer& src);
00205 Visualizer& operator=(const Visualizer& src);
00208 ~Visualizer();
00209 
00217 void shutdown();
00218 
00224 Visualizer& setShutdownWhenDestructed(bool shouldShutdown);
00225 
00229 bool getShutdownWhenDestructed() const;
00230 
00234 enum Mode {
00237     PassThrough = 1,
00240     Sampling    = 2,
00242     RealTime    = 3
00243 };
00244 
00249 enum BackgroundType {
00252     GroundAndSky = 1,
00254     SolidColor   = 2
00255 };
00256 
00260 enum PredefinedMenuIds {
00262     ViewMenuId    = -1
00263 };
00264 
00282 Visualizer& setBackgroundType(BackgroundType background);
00283 
00284 
00292 const Visualizer& setBackgroundColor(const Vec3& color) const;
00293 
00302 const Visualizer& setShowShadows(bool showShadows) const;
00303 
00309 const Visualizer& setShowFrameRate(bool showFrameRate) const;
00310 
00316 const Visualizer& setShowSimTime(bool showSimTime) const;
00317 
00323 const Visualizer& setShowFrameNumber(bool showFrameNumber) const;
00324 
00336 const Visualizer& setWindowTitle(const String& title) const;
00357 Visualizer& setSystemUpDirection(const CoordinateDirection& upDirection);
00360 CoordinateDirection getSystemUpDirection() const;
00361 
00375 Visualizer& setGroundHeight(Real height);
00379 Real getGroundHeight() const;
00380 
00381 
00386 Visualizer& setMode(Mode mode);
00389 Mode getMode() const;
00390 
00399 Visualizer& setDesiredFrameRate(Real framesPerSec);
00405 Real getDesiredFrameRate() const;
00406 
00423 Visualizer& setRealTimeScale(Real simTimePerRealSecond);
00426 Real getRealTimeScale() const;
00427 
00451 Visualizer& setDesiredBufferLengthInSec(Real bufferLengthInSec);
00457 Real getDesiredBufferLengthInSec() const;
00461 Real getActualBufferLengthInSec() const;
00463 int getActualBufferLengthInFrames() const;
00464 
00472 int addInputListener(InputListener* listener);
00474 int getNumInputListeners() const;
00476 const InputListener& getInputListener(int i) const;
00478 InputListener& updInputListener(int i);
00479 
00487 int addFrameController(FrameController* controller);
00489 int getNumFrameControllers() const;
00491 const FrameController& getFrameController(int i) const;
00493 FrameController& updFrameController(int i);
00494 
00531 void report(const State& state) const;
00532 
00539 void flushFrames() const;
00540 
00545 void drawFrameNow(const State& state) const;
00576 Visualizer& addMenu(const String& title, int id, 
00577                    const Array_<std::pair<String, int> >& items);
00578 
00592 Visualizer& addSlider(const String& title, int id, Real min, Real max, Real value);
00593 
00599 int addDecoration(MobilizedBodyIndex mobodIx, const Transform& X_BD, 
00600                   const DecorativeGeometry& geometry);
00602 int getNumDecorations() const;
00604 const DecorativeGeometry& getDecoration(int i) const;
00607 DecorativeGeometry& updDecoration(int i) const;
00608 
00614 int addRubberBandLine(MobilizedBodyIndex b1, const Vec3& station1,
00615                       MobilizedBodyIndex b2, const Vec3& station2,
00616                       const DecorativeLine& line);
00618 int getNumRubberBandLines() const;
00620 const DecorativeLine& getRubberBandLine(int i) const;
00623 DecorativeLine& updRubberBandLine(int i) const;
00624 
00631 int addDecorationGenerator(DecorationGenerator* generator);
00634 int getNumDecorationGenerators() const;
00636 const DecorationGenerator& getDecorationGenerator(int i) const;
00638 DecorationGenerator& updDecorationGenerator(int i);
00674 const Visualizer& setCameraTransform(const Transform& X_GC) const;
00675 
00678 const Visualizer& zoomCameraToShowAllGeometry() const;
00679 
00684 const Visualizer& pointCameraAt(const Vec3& point, const Vec3& upDirection) const;
00685 
00687 const Visualizer& setCameraFieldOfView(Real fov) const;
00688 
00690 const Visualizer& setCameraClippingPlanes(Real nearPlane, Real farPlane) const;
00691 
00696 const Visualizer& setSliderValue(int slider, Real value) const;
00697 
00704 const Visualizer& setSliderRange(int slider, Real newMin, Real newMax) const;
00705 
00706 
00712 void dumpStats(std::ostream& o) const;
00714 void clearStats();
00719 const Array_<InputListener*>&   getInputListeners() const;
00720 const Array_<FrameController*>& getFrameControllers() const;
00721 const MultibodySystem&          getSystem() const;
00722 int getRefCount() const;
00725 class Impl;
00726 //--------------------------------------------------------------------------
00727                                 private:
00728 explicit Visualizer(Impl* impl);
00729 Impl* impl;
00730 
00731 const Impl& getImpl() const {assert(impl); return *impl;}
00732 Impl&       updImpl()       {assert(impl); return *impl;}
00733 friend class Impl;
00734 };
00735 
00741 class SimTK_SIMBODY_EXPORT Visualizer::FrameController {
00742 public:
00754     virtual void generateControls(const Visualizer&           viz, 
00755                                   const State&                state,
00756                                   Array_<DecorativeGeometry>& geometry) = 0;
00757 
00760     virtual ~FrameController() {}
00761 };
00762 
00765 typedef Visualizer VTKVisualizer;
00766 
00767 } // namespace SimTK
00768 
00769 #endif // SimTK_SIMBODY_VISUALIZER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines