MBSim

Project Page
coordinates_observer.h
00001 /* Copyright (C) 2004-2011 MBSim Development Team
00002  *
00003  * This library is free software; you can redistribute it and/or 
00004  * modify it under the terms of the GNU Lesser General Public 
00005  * License as published by the Free Software Foundation; either 
00006  * version 2.1 of the License, or (at your option) any later version. 
00007  *  
00008  * This library is distributed in the hope that it will be useful, 
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
00011  * Lesser General Public License for more details. 
00012  *  
00013  * You should have received a copy of the GNU Lesser General Public 
00014  * License along with this library; if not, write to the Free Software 
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
00016  *
00017  * Contact: martin.o.foerg@gmail.com
00018  */
00019 
00020 #ifndef _COORDINATES_OBSERVER_H__
00021 #define _COORDINATES_OBSERVER_H__
00022 #include "mbsim/observer.h"
00023 
00024 #ifdef HAVE_OPENMBVCPPINTERFACE
00025 #include <mbsim/utils/boost_parameters.h>
00026 #include <mbsim/utils/openmbv_utils.h>
00027 #endif
00028 
00029 namespace MBSim {
00030   class Frame;
00031 
00032   class CoordinatesObserver : public Observer {
00033     protected:
00034       Frame* frame;
00035 #ifdef HAVE_OPENMBVCPPINTERFACE
00036       boost::shared_ptr<OpenMBV::Group> openMBVPosGrp, openMBVVelGrp, openMBVAccGrp;
00037       boost::shared_ptr<OpenMBV::Arrow> openMBVPosition, openMBVVelocity, openMBVAcceleration;
00038       boost::shared_ptr<OpenMBV::Frame> openMBVFrame;
00039 #endif
00040 
00041     public:
00042       CoordinatesObserver(const std::string &name="");
00043       void setFrame(Frame *frame_) { frame = frame_; } 
00044 
00045       void init(InitStage stage);
00046       virtual void plot(double t, double dt);
00047       virtual void initializeUsingXML(xercesc::DOMElement *element);
00048 
00049 #ifdef HAVE_OPENMBVCPPINTERFACE
00050       BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVPosition, tag, (optional (scaleLength,(double),1)(scaleSize,(double),1)(referencePoint,(OpenMBV::Arrow::ReferencePoint),OpenMBV::Arrow::fromPoint)(diffuseColor,(const fmatvec::Vec3&),"[-1;1;1]")(transparency,(double),0))) { 
00051         OpenMBVArrow ombv(diffuseColor,transparency,OpenMBV::Arrow::toHead,referencePoint,scaleLength,scaleSize);
00052         openMBVPosition=ombv.createOpenMBV(); 
00053       }
00054       BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVVelocity, tag, (optional (scaleLength,(double),1)(scaleSize,(double),1)(referencePoint,(OpenMBV::Arrow::ReferencePoint),OpenMBV::Arrow::fromPoint)(diffuseColor,(const fmatvec::Vec3&),"[-1;1;1]")(transparency,(double),0))) { 
00055         OpenMBVArrow ombv(diffuseColor,transparency,OpenMBV::Arrow::toHead,referencePoint,scaleLength,scaleSize);
00056         openMBVVelocity=ombv.createOpenMBV(); 
00057       }
00058       BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVAcceleration, tag, (optional (scaleLength,(double),1)(scaleSize,(double),1)(referencePoint,(OpenMBV::Arrow::ReferencePoint),OpenMBV::Arrow::fromPoint)(diffuseColor,(const fmatvec::Vec3&),"[-1;1;1]")(transparency,(double),0))) { 
00059         OpenMBVArrow ombv(diffuseColor,transparency,OpenMBV::Arrow::toHead,referencePoint,scaleLength,scaleSize);
00060         openMBVAcceleration=ombv.createOpenMBV(); 
00061       }
00062       BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVFrame, tag, (optional (size,(double),1)(offset,(double),1)(transparency,(double),0))) { 
00063         OpenMBVFrame ombv(size,offset,"[-1;1;1]",transparency);
00064         openMBVFrame=ombv.createOpenMBV(); 
00065       }
00066 #endif
00067 
00068     private:
00069       std::string saved_frame;
00070   };
00071 
00072   class CartesianCoordinatesObserver : public CoordinatesObserver {
00073     private:
00074       fmatvec::Vec3 ex, ey, ez;
00075       fmatvec::SqrMat3 A;
00076 #ifdef HAVE_OPENMBVCPPINTERFACE
00077       boost::shared_ptr<OpenMBV::Arrow> openMBVXPosition, openMBVYPosition, openMBVZPosition, openMBVXVelocity, openMBVYVelocity, openMBVZVelocity, openMBVXAcceleration, openMBVYAcceleration, openMBVZAcceleration; 
00078 #endif
00079 
00080     public:
00081       CartesianCoordinatesObserver(const std::string &name="");
00082 
00083       void init(InitStage stage);
00084       virtual void plot(double t, double dt);
00085   };
00086 
00087   class CylinderCoordinatesObserver : public CoordinatesObserver {
00088     private:
00089       fmatvec::Vec3 ez;
00090 #ifdef HAVE_OPENMBVCPPINTERFACE
00091       boost::shared_ptr<OpenMBV::Arrow> openMBVRadialPosition, openMBVZPosition, openMBVRadialVelocity, openMBVCircularVelocity, openMBVZVelocity, openMBVRadialAcceleration, openMBVCircularAcceleration, openMBVZAcceleration; 
00092 #endif
00093 
00094     public:
00095       CylinderCoordinatesObserver(const std::string &name="");
00096 
00097       void init(InitStage stage);
00098       virtual void plot(double t, double dt);
00099   };
00100 
00101   class NaturalCoordinatesObserver : public CoordinatesObserver {
00102     private:
00103 #ifdef HAVE_OPENMBVCPPINTERFACE
00104       boost::shared_ptr<OpenMBV::Arrow> openMBVTangentialAcceleration, openMBVNormalAcceleration;
00105 #endif
00106 
00107     public:
00108       NaturalCoordinatesObserver(const std::string &name="");
00109 
00110       void init(InitStage stage);
00111       virtual void plot(double t, double dt);
00112   };  
00113 
00114 }
00115 
00116 #endif
00117