MBSim

Project Page
contour.h
00001 /* Copyright (C) 2004-2009 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  *          rzander@users.berlios.de
00019  */
00020 
00021 #ifndef _CONTOUR_H_
00022 #define _CONTOUR_H_
00023 
00024 #include "mbsim/element.h"
00025 #include "mbsim/contour_pdata.h"
00026 #include "mbsim/frame.h"
00027 #include "mbsim/mbsim_event.h"
00028 
00029 #ifdef HAVE_OPENMBVCPPINTERFACE
00030 namespace OpenMBV {
00031   class RigidBody;
00032 }
00033 #endif
00034 
00035 namespace MBSim {
00036 
00037   class Object;
00038   class ContourPointData;
00039   class ContactKinematics;
00040 
00051   class Contour : public Element {
00052     public:
00057       Contour(const std::string &name);
00058 
00062       virtual ~Contour();
00063 
00064       /* INHERITED INTERFACE OF ELEMENT */
00065       virtual std::string getType() const { return "Contour"; }
00066       virtual void plot(double t, double dt = 1);
00067       /***************************************************/
00068 
00069       /* INTERFACE FOR DERIVED CLASSES */
00075       virtual void updateKinematicsForFrame(ContourPointData &cp, FrameFeature ff) = 0;
00076 
00082       virtual void updateJacobiansForFrame(ContourPointData &cp, int j=0) = 0;
00083 
00088       virtual fmatvec::Vec3 computeNormal(ContourPointData &cp) { updateKinematicsForFrame(cp,normal); return cp.getFrameOfReference().getOrientation().col(0); }
00089 
00094       virtual fmatvec::Vec3 computePosition(ContourPointData &cp) { updateKinematicsForFrame(cp,position); return cp.getFrameOfReference().getPosition(); }
00095 
00100       virtual fmatvec::Vec3 computeVelocity(ContourPointData &cp) { updateKinematicsForFrame(cp,velocity); return cp.getFrameOfReference().getVelocity(); }
00101 
00106       virtual fmatvec::Vec3 computeAngularVelocity(ContourPointData &cp) { updateKinematicsForFrame(cp,angularVelocity); return cp.getFrameOfReference().getAngularVelocity(); }
00107 
00112       virtual double computeCurvature(ContourPointData &cp) { throw MBSimError("ERROR in "+getName()+"(Contour::computeCurvature): Not implemented."); return 0; }
00113 
00121       virtual fmatvec::Vec2 computeLagrangeParameter(const fmatvec::Vec3 &WrPoint) {throw MBSimError("ERROR computeLagrangeParameter(const fmatvec::Vec3 &WrPoint): Not implemented for this contour: \"" + this->getType() + "\"."); return 0; }
00122 
00126       virtual void setReferencePosition(const fmatvec::Vec3 &WrOP) { R->setPosition(WrOP); }
00127 
00131       virtual void setReferenceOrientation(const fmatvec::SqrMat3 &AWC) { R->setOrientation(AWC); }
00132 
00136       virtual void setReferenceVelocity(const fmatvec::Vec3 &WvP) { R->setVelocity(WvP); }
00137 
00141       virtual void setReferenceAngularVelocity(const fmatvec::Vec3 &WomegaC) { R->setAngularVelocity(WomegaC); }
00142 
00146       virtual void setReferenceJacobianOfTranslation(const fmatvec::Mat3xV &WJP, int j=0) { R->setJacobianOfTranslation(WJP,j); }
00147 
00151       virtual void setReferenceGyroscopicAccelerationOfTranslation(const fmatvec::Vec3 &WjP, int j=0) { R->setGyroscopicAccelerationOfTranslation(WjP,j); }
00152 
00156       virtual void setReferenceJacobianOfRotation(const fmatvec::Mat3xV &WJR, int j=0) { R->setJacobianOfRotation(WJR,j); }
00157 
00161       virtual void setReferenceGyroscopicAccelerationOfRotation(const fmatvec::Vec3 &WjR, int j=0) { R->setGyroscopicAccelerationOfRotation(WjR,j); }
00162 
00166       virtual void setReferenceAcceleration(const fmatvec::Vec3 &WaP) { R->setAcceleration(WaP); }
00167 
00171       virtual void setReferenceAngularAcceleration(const fmatvec::Vec3 &WpsiC) { R->setAngularAcceleration(WpsiC); }
00172 
00176       virtual void init(InitStage stage);
00177       /***************************************************/
00178 
00184       virtual ContactKinematics * findContactPairingWith(std::string type0, std::string type1) = 0;
00185 
00186       /* GETTER / SETTER */
00187       Frame* getFrame() { return R; }
00188       Frame* getFrameOfReference() { return R; }
00189       const fmatvec::Vec3& getReferencePosition() const { return R->getPosition(); }
00190       const fmatvec::SqrMat3& getReferenceOrientation() const { return R->getOrientation(); }
00191       const fmatvec::Vec3& getReferenceVelocity() const { return R->getVelocity(); }
00192       const fmatvec::Vec3& getReferenceAngularVelocity() const { return R->getAngularVelocity(); }
00193       const fmatvec::Mat3xV& getReferenceJacobianOfTranslation(int j=0) const { return R->getJacobianOfTranslation(j); }
00194       const fmatvec::Mat3xV& getReferenceJacobianOfRotation(int j=0) const { return R->getJacobianOfRotation(j); }
00195       fmatvec::Mat3xV& getReferenceJacobianOfTranslation(int j=0) { return R->getJacobianOfTranslation(j); }
00196       fmatvec::Mat3xV& getReferenceJacobianOfRotation(int j=0) { return R->getJacobianOfRotation(j); }
00197       const fmatvec::Vec3& getReferenceGyroscopicAccelerationOfTranslation() const { return R->getGyroscopicAccelerationOfTranslation(); }
00198       const fmatvec::Vec3& getReferenceGyroscopicAccelerationOfRotation() const { return R->getGyroscopicAccelerationOfRotation(); }
00199       fmatvec::Vec3& getReferenceGyroscopicAccelerationOfTranslation() { return R->getGyroscopicAccelerationOfTranslation(); }
00200       fmatvec::Vec3& getReferenceGyroscopicAccelerationOfRotation() { return R->getGyroscopicAccelerationOfRotation(); }
00201 
00202       int gethSize(int i=0) const { return hSize[i]; }
00203       int gethInd(int i=0) const { return hInd[i]; }
00204       void sethSize(int size, int i=0) { hSize[i] = size; }
00205       void sethInd(int ind, int i=0) { hInd[i] = ind; }
00206 
00207       //virtual void setPlotFeature(PlotFeature pf, PlotFeatureStatus value) { Element::setPlotFeature(pf,value); R->setPlotFeature(pf,value);}
00208 //      ObjectInterface* getParent() { return parent; }
00209 //      void setParent(ObjectInterface* parent_) { parent = parent_; }
00210       /***************************************************/
00211 
00212       virtual Element * getByPathSearch(std::string path);
00213 
00214       void setFrameOfReference(Frame *frame) { R = frame; }
00215       void setFrameOfReference(const std::string &frame) { saved_frameOfReference = frame; }
00216 
00217       virtual void updateStateDependentVariables(double t) {}
00218       virtual void updateJacobians(double t, int j=0) {}
00219       virtual void updateStateDerivativeDependentVariables(const fmatvec::Vec &ud, double t) {}
00220 
00221       virtual void initializeUsingXML(MBXMLUtils::TiXmlElement *element);
00222       virtual MBXMLUtils::TiXmlElement* writeXMLFile(MBXMLUtils::TiXmlNode *element);
00223 
00224     protected:
00225 //      /**
00226 //       * \brief object the contour belongs to
00227 //       */
00228 //      ObjectInterface* parent;
00229 
00233       int hSize[2], hInd[2];
00234 
00238       Frame *R;
00239 
00240       std::string saved_frameOfReference;
00241   };
00242 
00249   class RigidContour : public Contour {
00250     public:
00255       RigidContour(const std::string &name) : Contour(name)
00256 # ifdef HAVE_OPENMBVCPPINTERFACE
00257                                               , openMBVRigidBody(0)
00258 # endif
00259                                               {}
00260 
00261       virtual ~RigidContour();
00262 
00263       /* INHERITED INTERFACE OF ELEMENT */
00264       std::string getType() const { return "RigidContour"; }
00265       virtual void plot(double t, double dt = 1);
00266       virtual void init(InitStage stage);
00267       /***************************************************/
00268 
00269       /* INHERITED INTERFACE OF CONTOUR */
00270       virtual void updateKinematicsForFrame(ContourPointData &cp, FrameFeature ff);
00271       virtual void updateJacobiansForFrame(ContourPointData &cp, int j=0);
00272       /***************************************************/
00273 
00279       ContactKinematics * findContactPairingWith(std::string type0, std::string type1);
00280 
00281 #ifdef HAVE_OPENMBVCPPINTERFACE
00282       OpenMBV::RigidBody * getOpenMBVRigidBody() {
00283         return openMBVRigidBody;
00284       }
00285 #endif
00286 
00287     protected:
00288 #ifdef HAVE_OPENMBVCPPINTERFACE
00289       OpenMBV::RigidBody *openMBVRigidBody;
00290 #endif
00291 
00292   };
00293 }
00294 
00295 #endif /* _CONTOUR_H_ */
00296