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 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 
00051 #include "SimTKcommon.h"
00052 #include "simbody/internal/common.h"
00053 
00054 #include <cassert>
00055 
00056 namespace SimTK {
00057 
00058 class DecorativeGeometry;
00059 
00060 class SimTK_SIMBODY_EXPORT Body {
00061 public:
00062     Body() : rep(0) { }
00063     ~Body();
00064     Body(const Body&);
00065     Body& operator=(const Body&);
00066 
00070     Body(const MassProperties&);
00071 
00072     Body& addDecoration(const Transform& X_BD, const DecorativeGeometry&);
00073 
00074     // Every type of Body should provide an initial set of rigid body mass 
00075     // properties defined at Topology stage (i.e., in the System rather than
00076     // the State). 
00077     const MassProperties& getDefaultRigidBodyMassProperties() const;
00078     Body& setDefaultRigidBodyMassProperties(const MassProperties&);
00079 
00080     // These are the built-in Body types.
00081     class Ground;     // infinitely massive
00082     class Massless;   // just a reference frame
00083     class Particle;   // point mass only; com=0; no inertia
00084     class Linear;     // point masses along a line; scalar inertia
00085     class Rigid;      // general rigid body
00086     class Deformable; // base class for bodies with internal deformation coords
00087 
00088     bool isOwnerHandle() const;
00089     bool isEmptyHandle() const;
00090 
00091     // Internal use only
00092     class BodyRep; // local subclass
00093     explicit Body(class BodyRep* r) : rep(r) { }
00094     bool                hasRep() const {return rep!=0;}
00095     const BodyRep& getRep() const {assert(rep); return *rep;}
00096     BodyRep&       updRep() const {assert(rep); return *rep;}
00097     void setRep(BodyRep& r) {assert(!rep); rep = &r;}
00098 protected:
00099     class BodyRep* rep;
00100 };
00101 
00102 class SimTK_SIMBODY_EXPORT Body::Rigid : public Body {
00103 public:
00104     Rigid(); // default mass properties (1,Vec3(0),Inertia(1,1,1))
00105     explicit Rigid(const MassProperties&);
00106 
00107     Rigid& addDecoration(const Transform& X_BD, const DecorativeGeometry& g) {
00108         (void)Body::addDecoration(X_BD,g);
00109         return *this;
00110     }
00111     Rigid& setDefaultRigidBodyMassProperties(const MassProperties& m) {
00112         (void)Body::setDefaultRigidBodyMassProperties(m);
00113         return *this;
00114     }
00115 
00116     class RigidRep; // local subclass
00117     SimTK_PIMPL_DOWNCAST(Rigid, Body);
00118 private:
00119     RigidRep&       updRep();
00120     const RigidRep& getRep() const;
00121 };
00122 
00123 class SimTK_SIMBODY_EXPORT Body::Linear : public Body {
00124 public:
00125     Linear(); // default mass properties (1,Vec3(0),Inertia(1,1,0))
00126     explicit Linear(const MassProperties&);
00127 
00128     Linear& addDecoration(const Transform& X_BD, const DecorativeGeometry& g) {
00129         (void)Body::addDecoration(X_BD,g);
00130         return *this;
00131     }
00132     Linear& setDefaultRigidBodyMassProperties(const MassProperties& m) {
00133         (void)Body::setDefaultRigidBodyMassProperties(m);
00134         return *this;
00135     }
00136 
00137     class LinearRep; // local subclass
00138     SimTK_PIMPL_DOWNCAST(Linear, Body);
00139 private:
00140     LinearRep&       updRep();
00141     const LinearRep& getRep() const;
00142 };
00143 
00144 class SimTK_SIMBODY_EXPORT Body::Ground : public Body {
00145 public:
00146     Ground();
00147 
00148     Ground& addDecoration(const Transform& X_BD, const DecorativeGeometry& g) {
00149         (void)Body::addDecoration(X_BD,g);
00150         return *this;
00151     }
00152 
00153     class GroundRep; // local subclass
00154     SimTK_PIMPL_DOWNCAST(Ground, Body);
00155 private:
00156     GroundRep&       updRep();
00157     const GroundRep& getRep() const;
00158 };
00159 
00160 class SimTK_SIMBODY_EXPORT Body::Massless : public Body {
00161 public:
00162     Massless();
00163 
00164     Massless& addDecoration(const Transform& X_BD, const DecorativeGeometry& g) {
00165         (void)Body::addDecoration(X_BD,g);
00166         return *this;
00167     }
00168 
00169     class MasslessRep; // local subclass
00170     SimTK_PIMPL_DOWNCAST(Massless, Body);
00171 private:
00172     MasslessRep&       updRep();
00173     const MasslessRep& getRep() const;
00174 };
00175 
00176 } // namespace SimTK
00177 
00178 #endif // SimTK_SIMBODY_BODY_H_
00179 
00180 
00181 

Generated on Fri Sep 26 07:44:08 2008 for SimTKcore by  doxygen 1.5.6