Simbody  3.4 (development)
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-12 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 
00181 explicit Visualizer(const MultibodySystem& system);
00182 
00188 Visualizer(const MultibodySystem& system,
00189            const Array_<String>&  searchPath);
00190 
00194 Visualizer(const Visualizer& src);
00198 Visualizer& operator=(const Visualizer& src);
00201 ~Visualizer();
00202 
00210 void shutdown();
00211 
00217 Visualizer& setShutdownWhenDestructed(bool shouldShutdown);
00218 
00222 bool getShutdownWhenDestructed() const;
00223 
00227 enum Mode {
00230     PassThrough = 1,
00233     Sampling    = 2,
00235     RealTime    = 3
00236 };
00237 
00242 enum BackgroundType {
00245     GroundAndSky = 1,
00247     SolidColor   = 2
00248 };
00249 
00253 enum PredefinedMenuIds {
00255     ViewMenuId    = -1
00256 };
00257 
00275 Visualizer& setBackgroundType(BackgroundType background);
00276 
00277 
00285 const Visualizer& setBackgroundColor(const Vec3& color) const;
00286 
00295 const Visualizer& setShowShadows(bool showShadows) const;
00296 
00302 const Visualizer& setShowFrameRate(bool showFrameRate) const;
00303 
00309 const Visualizer& setShowSimTime(bool showSimTime) const;
00310 
00316 const Visualizer& setShowFrameNumber(bool showFrameNumber) const;
00317 
00329 const Visualizer& setWindowTitle(const String& title) const;
00350 Visualizer& setSystemUpDirection(const CoordinateDirection& upDirection);
00353 CoordinateDirection getSystemUpDirection() const;
00354 
00368 Visualizer& setGroundHeight(Real height);
00372 Real getGroundHeight() const;
00373 
00374 
00379 void setMode(Mode mode);
00382 Mode getMode() const;
00383 
00392 Visualizer& setDesiredFrameRate(Real framesPerSec);
00398 Real getDesiredFrameRate() const;
00399 
00416 Visualizer& setRealTimeScale(Real simTimePerRealSecond);
00419 Real getRealTimeScale() const;
00420 
00444 Visualizer& setDesiredBufferLengthInSec(Real bufferLengthInSec);
00450 Real getDesiredBufferLengthInSec() const;
00454 Real getActualBufferLengthInSec() const;
00456 int getActualBufferLengthInFrames() const;
00457 
00465 int addInputListener(InputListener* listener);
00467 int getNumInputListeners() const;
00469 const InputListener& getInputListener(int i) const;
00471 InputListener& updInputListener(int i);
00472 
00480 int addFrameController(FrameController* controller);
00482 int getNumFrameControllers() const;
00484 const FrameController& getFrameController(int i) const;
00486 FrameController& updFrameController(int i);
00487 
00524 void report(const State& state) const;
00525 
00532 void flushFrames() const;
00533 
00538 void drawFrameNow(const State& state) const;
00569 Visualizer& addMenu(const String& title, int id, 
00570                    const Array_<std::pair<String, int> >& items);
00571 
00585 Visualizer& addSlider(const String& title, int id, Real min, Real max, Real value);
00586 
00592 int addDecoration(MobilizedBodyIndex mobodIx, const Transform& X_BD, 
00593                   const DecorativeGeometry& geometry);
00595 int getNumDecorations() const;
00597 const DecorativeGeometry& getDecoration(int i) const;
00600 DecorativeGeometry& updDecoration(int i) const;
00601 
00607 int addRubberBandLine(MobilizedBodyIndex b1, const Vec3& station1,
00608                       MobilizedBodyIndex b2, const Vec3& station2,
00609                       const DecorativeLine& line);
00611 int getNumRubberBandLines() const;
00613 const DecorativeLine& getRubberBandLine(int i) const;
00616 DecorativeLine& updRubberBandLine(int i) const;
00617 
00624 int addDecorationGenerator(DecorationGenerator* generator);
00627 int getNumDecorationGenerators() const;
00629 const DecorationGenerator& getDecorationGenerator(int i) const;
00631 DecorationGenerator& updDecorationGenerator(int i);
00667 const Visualizer& setCameraTransform(const Transform& X_GC) const;
00668 
00671 const Visualizer& zoomCameraToShowAllGeometry() const;
00672 
00677 const Visualizer& pointCameraAt(const Vec3& point, const Vec3& upDirection) const;
00678 
00680 const Visualizer& setCameraFieldOfView(Real fov) const;
00681 
00683 const Visualizer& setCameraClippingPlanes(Real nearPlane, Real farPlane) const;
00684 
00689 const Visualizer& setSliderValue(int slider, Real value) const;
00690 
00697 const Visualizer& setSliderRange(int slider, Real newMin, Real newMax) const;
00698 
00699 
00705 void dumpStats(std::ostream& o) const;
00707 void clearStats();
00712 const Array_<InputListener*>&   getInputListeners() const;
00713 const Array_<FrameController*>& getFrameControllers() const;
00714 const MultibodySystem&          getSystem() const;
00715 int getRefCount() const;
00718 class Impl;
00719 //--------------------------------------------------------------------------
00720                                 private:
00721 explicit Visualizer(Impl* impl);
00722 Impl* impl;
00723 
00724 const Impl& getImpl() const {assert(impl); return *impl;}
00725 Impl&       updImpl()       {assert(impl); return *impl;}
00726 friend class Impl;
00727 };
00728 
00734 class SimTK_SIMBODY_EXPORT Visualizer::FrameController {
00735 public:
00747     virtual void generateControls(const Visualizer&           viz, 
00748                                   const State&                state,
00749                                   Array_<DecorativeGeometry>& geometry) = 0;
00750 
00753     virtual ~FrameController() {}
00754 };
00755 
00758 typedef Visualizer VTKVisualizer;
00759 
00760 } // namespace SimTK
00761 
00762 #endif // SimTK_SIMBODY_VISUALIZER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines