Simbody
3.4 (development)
|
00001 #ifndef SimTK_SIMBODY_BODY_H_ 00002 #define SimTK_SIMBODY_BODY_H_ 00003 00004 /* -------------------------------------------------------------------------- * 00005 * Simbody(tm) * 00006 * -------------------------------------------------------------------------- * 00007 * This is part of the SimTK 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/home/simbody. * 00011 * * 00012 * Portions copyright (c) 2007-13 Stanford University and the Authors. * 00013 * Authors: Michael Sherman * 00014 * Contributors: * 00015 * * 00016 * Licensed under the Apache License, Version 2.0 (the "License"); you may * 00017 * not use this file except in compliance with the License. You may obtain a * 00018 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. * 00019 * * 00020 * Unless required by applicable law or agreed to in writing, software * 00021 * distributed under the License is distributed on an "AS IS" BASIS, * 00022 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 00023 * See the License for the specific language governing permissions and * 00024 * limitations under the License. * 00025 * -------------------------------------------------------------------------- */ 00026 00032 #include "SimTKcommon.h" 00033 #include "simbody/internal/common.h" 00034 #include "simbody/internal/ContactSurface.h" 00035 00036 #include <cassert> 00037 00038 namespace SimTK { 00039 00040 class DecorativeGeometry; 00041 00042 //============================================================================== 00043 // BODY 00044 //============================================================================== 00055 class SimTK_SIMBODY_EXPORT Body { 00056 public: 00058 Body() : rep(0) { } 00060 ~Body(); 00063 Body(const Body& source); 00066 Body& operator=(const Body& source); 00067 00072 Body(const MassProperties& massProps); 00073 00078 Body& setDefaultRigidBodyMassProperties(const MassProperties&); 00079 00083 const MassProperties& getDefaultRigidBodyMassProperties() const; 00084 00091 int addDecoration(const Transform& X_BD, const DecorativeGeometry& geometry); 00092 00095 int addDecoration(const DecorativeGeometry& geometry) 00096 { return addDecoration(Transform(), geometry); } 00097 00101 int getNumDecorations() const; 00102 00106 const DecorativeGeometry& getDecoration(int i) const; 00107 00113 DecorativeGeometry& updDecoration(int i) const; 00114 00120 int addContactSurface(const Transform& X_BS, 00121 const ContactSurface& shape); 00122 00125 int addContactSurface(const ContactSurface& shape) 00126 { return addContactSurface(Transform(), shape); } 00127 00130 int getNumContactSurfaces() const; 00133 const ContactSurface& getContactSurface(int i) const; 00136 const Transform& getContactSurfaceTransform(int i) const; 00140 ContactSurface& updContactSurface(int i); 00144 Transform& updContactSurfaceTransform(int i); 00145 00146 // These are the built-in Body types. 00147 class Ground; // infinitely massive 00148 class Massless; // just a reference frame 00149 class Particle; // point mass only; com=0; no inertia 00150 class Linear; // point masses along a line; scalar inertia 00151 class Rigid; // general rigid body 00152 class Deformable; // base class for bodies with internal deformation coords 00153 00154 bool isOwnerHandle() const; 00155 bool isEmptyHandle() const; 00156 00157 // Internal use only 00158 class BodyRep; // local subclass 00159 explicit Body(class BodyRep* r) : rep(r) { } 00160 bool hasRep() const {return rep!=0;} 00161 const BodyRep& getRep() const {assert(rep); return *rep;} 00162 BodyRep& updRep() const {assert(rep); return *rep;} 00163 void setRep(BodyRep& r) {assert(!rep); rep = &r;} 00164 00165 protected: 00166 class BodyRep* rep; 00167 }; 00168 00169 00170 00171 //============================================================================== 00172 // BODY::RIGID 00173 //============================================================================== 00176 class SimTK_SIMBODY_EXPORT Body::Rigid : public Body { 00177 public: 00180 Rigid(); 00183 explicit Rigid(const MassProperties&); 00184 00185 Rigid& setDefaultRigidBodyMassProperties(const MassProperties& m) { 00186 (void)Body::setDefaultRigidBodyMassProperties(m); 00187 return *this; 00188 } 00189 00190 class RigidRep; // local subclass 00191 SimTK_PIMPL_DOWNCAST(Rigid, Body); 00192 private: 00193 RigidRep& updRep(); 00194 const RigidRep& getRep() const; 00195 }; 00196 00197 00198 00199 00200 //============================================================================== 00201 // BODY::LINEAR 00202 //============================================================================== 00206 class SimTK_SIMBODY_EXPORT Body::Linear : public Body { 00207 public: 00208 Linear(); // default mass properties (1,Vec3(0),Inertia(1,1,0)) 00209 explicit Linear(const MassProperties&); 00210 00211 Linear& setDefaultRigidBodyMassProperties(const MassProperties& m) { 00212 (void)Body::setDefaultRigidBodyMassProperties(m); 00213 return *this; 00214 } 00215 00216 class LinearRep; // local subclass 00217 SimTK_PIMPL_DOWNCAST(Linear, Body); 00218 private: 00219 LinearRep& updRep(); 00220 const LinearRep& getRep() const; 00221 }; 00222 00223 00224 00225 //============================================================================== 00226 // BODY::PARTICLE 00227 //============================================================================== 00231 class SimTK_SIMBODY_EXPORT Body::Particle : public Body { 00232 public: 00233 Particle(); // default mass properties (1,Vec3(0),Inertia(0)) 00234 explicit Particle(const Real& mass); 00235 00236 Particle& setDefaultRigidBodyMassProperties(const MassProperties& m) { 00237 (void)Body::setDefaultRigidBodyMassProperties(m); 00238 return *this; 00239 } 00240 00241 class ParticleRep; // local subclass 00242 SimTK_PIMPL_DOWNCAST(Particle, Body); 00243 private: 00244 ParticleRep& updRep(); 00245 const ParticleRep& getRep() const; 00246 }; 00247 00248 00249 00250 //============================================================================== 00251 // BODY::MASSLESS 00252 //============================================================================== 00255 class SimTK_SIMBODY_EXPORT Body::Massless : public Body { 00256 public: 00257 Massless(); 00258 00259 class MasslessRep; // local subclass 00260 SimTK_PIMPL_DOWNCAST(Massless, Body); 00261 private: 00262 MasslessRep& updRep(); 00263 const MasslessRep& getRep() const; 00264 }; 00265 00266 00267 00268 //============================================================================== 00269 // BODY::GROUND 00270 //============================================================================== 00273 class SimTK_SIMBODY_EXPORT Body::Ground : public Body { 00274 public: 00275 Ground(); 00276 00277 class GroundRep; // local subclass 00278 SimTK_PIMPL_DOWNCAST(Ground, Body); 00279 private: 00280 GroundRep& updRep(); 00281 const GroundRep& getRep() const; 00282 }; 00283 00284 } // namespace SimTK 00285 00286 #endif // SimTK_SIMBODY_BODY_H_ 00287 00288 00289