MBSim

Project Page
contour.h
1 /* Copyright (C) 2004-2009 MBSim Development Team
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  * Contact: martin.o.foerg@googlemail.com
18  * rzander@users.berlios.de
19  */
20 
21 #ifndef _CONTOUR_H_
22 #define _CONTOUR_H_
23 
24 #include "mbsim/element.h"
25 #include "mbsim/contour_pdata.h"
26 #include "mbsim/frame.h"
27 #include "mbsim/mbsim_event.h"
28 
29 #ifdef HAVE_OPENMBVCPPINTERFACE
30 namespace OpenMBV {
31  class RigidBody;
32 }
33 #endif
34 
35 namespace MBSim {
36 
37  class Object;
38  class ContourPointData;
39  class ContactKinematics;
40 
51  class Contour : public Element {
52  public:
57  Contour(const std::string &name);
58 
62  virtual ~Contour();
63 
64  /* INHERITED INTERFACE OF ELEMENT */
65  virtual std::string getType() const { return "Contour"; }
66  virtual void plot(double t, double dt = 1);
67  /***************************************************/
68 
69  /* INTERFACE FOR DERIVED CLASSES */
75  virtual void updateKinematicsForFrame(ContourPointData &cp, FrameFeature ff) = 0;
76 
82  virtual void updateJacobiansForFrame(ContourPointData &cp, int j=0) = 0;
83 
88  virtual fmatvec::Vec computeNormal(ContourPointData &cp) { updateKinematicsForFrame(cp,normal); return cp.getFrameOfReference().getOrientation().col(0); }
89 
94  virtual fmatvec::Vec computePosition(ContourPointData &cp) { updateKinematicsForFrame(cp,position); return cp.getFrameOfReference().getPosition(); }
95 
100  virtual fmatvec::Vec computeVelocity(ContourPointData &cp) { updateKinematicsForFrame(cp,velocity); return cp.getFrameOfReference().getVelocity(); }
101 
106  virtual fmatvec::Vec computeAngularVelocity(ContourPointData &cp) { updateKinematicsForFrame(cp,angularVelocity); return cp.getFrameOfReference().getAngularVelocity(); }
107 
112  virtual double computeCurvature(ContourPointData &cp) { throw MBSimError("ERROR in "+getName()+"(Contour::computeCurvature): Not implemented."); return 0; }
113 
121  virtual fmatvec::Vec computeLagrangeParameter(const fmatvec::Vec &WrPoint) {throw MBSimError("ERROR computeLagrangeParameter(const fmatvec::Vec &WrPoint): Not implemented for this contour: \"" + this->getType() + "\"."); return 0; }
122 
126  virtual void setReferencePosition(const fmatvec::Vec &WrOP) { R.setPosition(WrOP); }
127 
131  virtual void setReferenceOrientation(const fmatvec::SqrMat &AWC) { R.setOrientation(AWC); }
132 
136  virtual void setReferenceVelocity(const fmatvec::Vec &WvP) { R.setVelocity(WvP); }
137 
141  virtual void setReferenceAngularVelocity(const fmatvec::Vec &WomegaC) { R.setAngularVelocity(WomegaC); }
142 
146  virtual void setReferenceJacobianOfTranslation(const fmatvec::Mat &WJP, int j=0) { R.setJacobianOfTranslation(WJP,j); }
147 
151  virtual void setReferenceGyroscopicAccelerationOfTranslation(const fmatvec::Vec &WjP, int j=0) { R.setGyroscopicAccelerationOfTranslation(WjP,j); }
152 
156  virtual void setReferenceJacobianOfRotation(const fmatvec::Mat &WJR, int j=0) { R.setJacobianOfRotation(WJR,j); }
157 
161  virtual void setReferenceGyroscopicAccelerationOfRotation(const fmatvec::Vec &WjR, int j=0) { R.setGyroscopicAccelerationOfRotation(WjR,j); }
162 
166  virtual void setReferenceAcceleration(const fmatvec::Vec &WaP) { R.setAcceleration(WaP); }
167 
171  virtual void setReferenceAngularAcceleration(const fmatvec::Vec &WpsiC) { R.setAngularAcceleration(WpsiC); }
172 
176  virtual void init(InitStage stage);
177  /***************************************************/
178 
184  virtual ContactKinematics * findContactPairingWith(std::string type0, std::string type1) = 0;
185 
186  /* GETTER / SETTER */
187  Frame* getFrame() { return &R; }
188  const fmatvec::Vec& getReferencePosition() const { return R.getPosition(); }
189  const fmatvec::SqrMat& getReferenceOrientation() const { return R.getOrientation(); }
190  const fmatvec::Vec& getReferenceVelocity() const { return R.getVelocity(); }
191  const fmatvec::Vec& getReferenceAngularVelocity() const { return R.getAngularVelocity(); }
192  const fmatvec::Mat& getReferenceJacobianOfTranslation(int j=0) const { return R.getJacobianOfTranslation(j); }
193  const fmatvec::Mat& getReferenceJacobianOfRotation(int j=0) const { return R.getJacobianOfRotation(j); }
194  fmatvec::Mat& getReferenceJacobianOfTranslation(int j=0) { return R.getJacobianOfTranslation(j); }
195  fmatvec::Mat& getReferenceJacobianOfRotation(int j=0) { return R.getJacobianOfRotation(j); }
196  const fmatvec::Vec& getReferenceGyroscopicAccelerationOfTranslation() const { return R.getGyroscopicAccelerationOfTranslation(); }
197  const fmatvec::Vec& getReferenceGyroscopicAccelerationOfRotation() const { return R.getGyroscopicAccelerationOfRotation(); }
198  fmatvec::Vec& getReferenceGyroscopicAccelerationOfTranslation() { return R.getGyroscopicAccelerationOfTranslation(); }
199  fmatvec::Vec& getReferenceGyroscopicAccelerationOfRotation() { return R.getGyroscopicAccelerationOfRotation(); }
200 
201  int gethSize(int i=0) const { return hSize[i]; }
202  int gethInd(int i=0) const { return hInd[i]; }
203  void sethSize(int size, int i=0) { hSize[i] = size; }
204  void sethInd(int ind, int i=0) { hInd[i] = ind; }
205 
206  virtual void setPlotFeature(PlotFeature pf, PlotFeatureStatus value) { Element::setPlotFeature(pf,value); R.setPlotFeature(pf,value);}
207 // ObjectInterface* getParent() { return parent; }
208 // void setParent(ObjectInterface* parent_) { parent = parent_; }
209  /***************************************************/
210 
211  protected:
212 // /**
213 // * \brief object the contour belongs to
214 // */
215 // ObjectInterface* parent;
216 
220  int hSize[2], hInd[2];
221 
226  };
227 
234  class RigidContour : public Contour {
235  public:
240  RigidContour(const std::string &name) : Contour(name)
241 # ifdef HAVE_OPENMBVCPPINTERFACE
242  , openMBVRigidBody(0)
243 # endif
244  {}
245 
246  virtual ~RigidContour();
247 
248  /* INHERITED INTERFACE OF ELEMENT */
249  std::string getType() const { return "RigidContour"; }
250  virtual void plot(double t, double dt = 1);
251  virtual void init(InitStage stage);
252  /***************************************************/
253 
254  /* INHERITED INTERFACE OF CONTOUR */
256  virtual void updateJacobiansForFrame(ContourPointData &cp, int j=0);
257  /***************************************************/
258 
264  ContactKinematics * findContactPairingWith(std::string type0, std::string type1);
265 
266  protected:
267 #ifdef HAVE_OPENMBVCPPINTERFACE
268  OpenMBV::RigidBody *openMBVRigidBody;
269 #endif
270 
271  };
272 }
273 
274 #endif /* _CONTOUR_H_ */
275