Simbody

Body.h

Go to the documentation of this file.
00001 #ifndef SimTK_SIMBODY_BODY_H_
00002 #define SimTK_SIMBODY_BODY_H_
00003 
00004 /* -------------------------------------------------------------------------- *
00005  *                      SimTK Core: SimTK Simbody(tm)                         *
00006  * -------------------------------------------------------------------------- *
00007  * This is part of the SimTK Core 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.               *
00011  *                                                                            *
00012  * Portions copyright (c) 2007-10 Stanford University and the Authors.        *
00013  * Authors: Michael Sherman                                                   *
00014  * Contributors:                                                              *
00015  *                                                                            *
00016  * Permission is hereby granted, free of charge, to any person obtaining a    *
00017  * copy of this software and associated documentation files (the "Software"), *
00018  * to deal in the Software without restriction, including without limitation  *
00019  * the rights to use, copy, modify, merge, publish, distribute, sublicense,   *
00020  * and/or sell copies of the Software, and to permit persons to whom the      *
00021  * Software is furnished to do so, subject to the following conditions:       *
00022  *                                                                            *
00023  * The above copyright notice and this permission notice shall be included in *
00024  * all copies or substantial portions of the Software.                        *
00025  *                                                                            *
00026  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
00027  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *
00028  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    *
00029  * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,    *
00030  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR      *
00031  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  *
00032  * USE OR OTHER DEALINGS IN THE SOFTWARE.                                     *
00033  * -------------------------------------------------------------------------- */
00034 
00040 #include "SimTKcommon.h"
00041 #include "simbody/internal/common.h"
00042 #include "simbody/internal/ContactSurface.h"
00043 
00044 #include <cassert>
00045 
00046 namespace SimTK {
00047 
00048 class DecorativeGeometry;
00049 
00050 //==============================================================================
00051 //                                    BODY
00052 //==============================================================================
00063 class SimTK_SIMBODY_EXPORT Body {
00064 public:
00066 Body() : rep(0) { }
00068 ~Body();
00071 Body(const Body& source);
00074 Body& operator=(const Body& source);
00075 
00080 Body(const MassProperties& massProps);
00081 
00086 Body& setDefaultRigidBodyMassProperties(const MassProperties&);
00090 const MassProperties& getDefaultRigidBodyMassProperties() const;
00091 
00095 Body& addDecoration(const Transform& X_BD, const DecorativeGeometry&);
00096 
00099 int getNumDecorations() const;
00100 
00103 const DecorativeGeometry& getDecoration(int n) const;
00104 
00107 DecorativeGeometry& updDecoration(int n);
00108 
00111 Body& addContactSurface(const Transform&          X_BS,
00112                         const ContactSurface&     shape); 
00113 
00116 int getNumContactSurfaces() const;
00119 const ContactSurface& getContactSurface(int n) const;
00122 const Transform&      getContactSurfaceTransform(int n) const;
00126 ContactSurface& updContactSurface(int n);
00130 Transform& updContactSurfaceTransform(int n);
00131 
00132 // These are the built-in Body types.
00133 class Ground;     // infinitely massive
00134 class Massless;   // just a reference frame
00135 class Particle;   // point mass only; com=0; no inertia
00136 class Linear;     // point masses along a line; scalar inertia
00137 class Rigid;      // general rigid body
00138 class Deformable; // base class for bodies with internal deformation coords
00139 
00140 bool isOwnerHandle() const;
00141 bool isEmptyHandle() const;
00142 
00143 // Internal use only
00144 class BodyRep; // local subclass
00145 explicit Body(class BodyRep* r) : rep(r) { }
00146 bool           hasRep() const {return rep!=0;}
00147 const BodyRep& getRep() const {assert(rep); return *rep;}
00148 BodyRep&       updRep() const {assert(rep); return *rep;}
00149 void           setRep(BodyRep& r) {assert(!rep); rep = &r;}
00150 
00151 protected:
00152 class BodyRep* rep;
00153 };
00154 
00155 
00156 
00157 //==============================================================================
00158 //                               BODY::RIGID
00159 //==============================================================================
00162 class SimTK_SIMBODY_EXPORT Body::Rigid : public Body {
00163 public:
00166     Rigid(); 
00169     explicit Rigid(const MassProperties&);
00170 
00171     Rigid& addDecoration(const Transform& X_BD, const DecorativeGeometry& g) {
00172         (void)Body::addDecoration(X_BD,g);
00173         return *this;
00174     }
00175     Rigid& setDefaultRigidBodyMassProperties(const MassProperties& m) {
00176         (void)Body::setDefaultRigidBodyMassProperties(m);
00177         return *this;
00178     }
00179 
00180     class RigidRep; // local subclass
00181     SimTK_PIMPL_DOWNCAST(Rigid, Body);
00182 private:
00183     RigidRep&       updRep();
00184     const RigidRep& getRep() const;
00185 };
00186 
00187 
00188 
00189 
00190 //==============================================================================
00191 //                               BODY::LINEAR
00192 //==============================================================================
00196 class SimTK_SIMBODY_EXPORT Body::Linear : public Body {
00197 public:
00198     Linear(); // default mass properties (1,Vec3(0),Inertia(1,1,0))
00199     explicit Linear(const MassProperties&);
00200 
00201     Linear& addDecoration(const Transform& X_BD, const DecorativeGeometry& g) {
00202         (void)Body::addDecoration(X_BD,g);
00203         return *this;
00204     }
00205     Linear& setDefaultRigidBodyMassProperties(const MassProperties& m) {
00206         (void)Body::setDefaultRigidBodyMassProperties(m);
00207         return *this;
00208     }
00209 
00210     class LinearRep; // local subclass
00211     SimTK_PIMPL_DOWNCAST(Linear, Body);
00212 private:
00213     LinearRep&       updRep();
00214     const LinearRep& getRep() const;
00215 };
00216 
00217 
00218 
00219 //==============================================================================
00220 //                              BODY::PARTICLE
00221 //==============================================================================
00225 class SimTK_SIMBODY_EXPORT Body::Particle : public Body {
00226 public:
00227     Particle(); // default mass properties (1,Vec3(0),Inertia(0))
00228     explicit Particle(const Real& mass);
00229 
00230     Particle& addDecoration(const Transform& X_BD, const DecorativeGeometry& g) {
00231         (void)Body::addDecoration(X_BD,g);
00232         return *this;
00233     }
00234     Particle& setDefaultRigidBodyMassProperties(const MassProperties& m) {
00235         (void)Body::setDefaultRigidBodyMassProperties(m);
00236         return *this;
00237     }
00238 
00239     class ParticleRep; // local subclass
00240     SimTK_PIMPL_DOWNCAST(Particle, Body);
00241 private:
00242     ParticleRep&       updRep();
00243     const ParticleRep& getRep() const;
00244 };
00245 
00246 
00247 
00248 //==============================================================================
00249 //                              BODY::MASSLESS
00250 //==============================================================================
00253 class SimTK_SIMBODY_EXPORT Body::Massless : public Body {
00254 public:
00255     Massless();
00256 
00257     Massless& addDecoration(const Transform& X_BD, const DecorativeGeometry& g) {
00258         (void)Body::addDecoration(X_BD,g);
00259         return *this;
00260     }
00261 
00262     class MasslessRep; // local subclass
00263     SimTK_PIMPL_DOWNCAST(Massless, Body);
00264 private:
00265     MasslessRep&       updRep();
00266     const MasslessRep& getRep() const;
00267 };
00268 
00269 
00270 
00271 //==============================================================================
00272 //                              BODY::GROUND
00273 //==============================================================================
00276 class SimTK_SIMBODY_EXPORT Body::Ground : public Body {
00277 public:
00278     Ground();
00279 
00280     Ground& addDecoration(const Transform& X_BD, const DecorativeGeometry& g) {
00281         (void)Body::addDecoration(X_BD,g);
00282         return *this;
00283     }
00284 
00285     class GroundRep; // local subclass
00286     SimTK_PIMPL_DOWNCAST(Ground, Body);
00287 private:
00288     GroundRep&       updRep();
00289     const GroundRep& getRep() const;
00290 };
00291 
00292 } // namespace SimTK
00293 
00294 #endif // SimTK_SIMBODY_BODY_H_
00295 
00296 
00297 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines