MBSim

Project Page
body.h
00001 /* Copyright (C) 2004-2014 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@googlemail.com
00018  */
00019 
00020 #ifndef _BODY_H_
00021 #define _BODY_H_
00022 
00023 #include <mbsim/object.h>
00024 #ifdef HAVE_OPENMBVCPPINTERFACE
00025 namespace OpenMBV {
00026   class Body;
00027 }
00028 #endif
00029 
00030 namespace MBSim {
00031 
00032   class Frame;
00033   class Contour;
00034 
00052   class Body : public Object {
00053     public:
00058       Body(const std::string &name);
00059 
00063       virtual ~Body();
00064 
00065       void setInitialGeneralizedPosition(const fmatvec::Vec &q0_) { q0 = q0_; }
00066       void setInitialGeneralizedVelocity(const fmatvec::Vec &u0_) { u0 = u0_; }
00067       void setInitialGeneralizedPosition(double q0_) { q0 = fmatvec::Vec(1,fmatvec::INIT,q0_); }
00068       void setInitialGeneralizedVelocity(double u0_) { u0 = fmatvec::Vec(1,fmatvec::INIT,u0_); }
00069 
00070       /* INHERITED INTERFACE OF OBJECTINTERFACE */
00071       void sethSize(int hSize_, int i=0);
00072       void sethInd(int hInd_, int i=0); 
00073       /*******************************************************/ 
00074 
00075       /* INHERITED INTERFACE OF ELEMENT */
00076       virtual void plot(double t, double dt = 1); 
00077       virtual void closePlot();
00078       virtual std::string getType() const { return "Body"; }
00079       virtual void setDynamicSystemSolver(DynamicSystemSolver *sys);
00080       /*******************************************************/ 
00081 
00082       /* INHERITED INTERFACE OF OBJECT */
00083       virtual void init(InitStage stage);
00084       /*******************************************************/ 
00085 
00086       /* INTERFACE FOR DERIVED CLASSES */
00087 
00093       virtual Contour* getContour(const std::string &name, bool check=true) const;
00094 
00100       virtual Frame* getFrame(const std::string &name, bool check=true) const;
00101 
00105       virtual Frame *getFrameOfReference() { return R; }
00106 
00110       virtual const Frame *getFrameOfReference() const { return R; }
00111 
00115       virtual void setFrameOfReference(Frame *frame) { R = frame; }
00116       /*******************************************************/ 
00117 
00118       /* GETTER / SETTER */
00119       const std::vector<Frame*>& getFrames() const { return frame; }
00120       const std::vector<Contour*>& getContours() const { return contour; }
00121 #ifdef HAVE_OPENMBVCPPINTERFACE
00122       boost::shared_ptr<OpenMBV::Group> getOpenMBVGrp() { return openMBVGrp; }
00123       boost::shared_ptr<OpenMBV::Body>& getOpenMBVBody() { return openMBVBody; }
00124 #endif
00125       /*******************************************************/ 
00126 
00131       int frameIndex(const Frame *frame_) const;
00132 
00137       int contourIndex(const Contour *contour_) const;
00138 
00139       virtual void initializeUsingXML(xercesc::DOMElement *element);
00140       virtual xercesc::DOMElement* writeXMLFile(xercesc::DOMNode *element);
00141 
00142       virtual Element * getChildByContainerAndName(const std::string &container, const std::string &name) const;
00143 
00144       fmatvec::Mat3xV& getPJT(int i=0) {return PJT[i];}
00145       fmatvec::Mat3xV& getPJR(int i=0) {return PJR[i];}
00146       int getuRelSize(int i=0) const {return nu[i];}
00147 
00148     protected:
00152       virtual void addFrame(Frame * frame);
00153 
00157       virtual void addContour(Contour* contour);
00158 
00162       std::vector<Frame*> frame;
00163       std::vector<Contour*> contour;
00164 
00168       Frame *R;
00169 
00173       fmatvec::Mat3xV PJT[2], PJR[2];
00174 
00175       int nu[2], nq;
00176 
00177 #ifdef HAVE_OPENMBVCPPINTERFACE
00178       boost::shared_ptr<OpenMBV::Body> openMBVBody;
00179       boost::shared_ptr<OpenMBV::Group> openMBVGrp;
00180 #endif
00181 
00182     private:
00183       std::string saved_frameOfReference;
00184   };
00185 
00186 }
00187 
00188 #endif
00189