Simbody
3.5
|
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 // Particles aren't yet supported, so hide this in Doxygen. 00226 //============================================================================== 00227 // BODY::PARTICLE 00228 //============================================================================== 00232 class SimTK_SIMBODY_EXPORT Body::Particle : public Body { 00233 public: 00234 Particle(); // default mass properties (1,Vec3(0),Inertia(0)) 00235 explicit Particle(const Real& mass); 00236 00237 Particle& setDefaultRigidBodyMassProperties(const MassProperties& m) { 00238 (void)Body::setDefaultRigidBodyMassProperties(m); 00239 return *this; 00240 } 00241 00242 class ParticleRep; // local subclass 00243 SimTK_PIMPL_DOWNCAST(Particle, Body); 00244 private: 00245 ParticleRep& updRep(); 00246 const ParticleRep& getRep() const; 00247 }; 00252 //============================================================================== 00253 // BODY::MASSLESS 00254 //============================================================================== 00257 class SimTK_SIMBODY_EXPORT Body::Massless : public Body { 00258 public: 00259 Massless(); 00260 00261 class MasslessRep; // local subclass 00262 SimTK_PIMPL_DOWNCAST(Massless, Body); 00263 private: 00264 MasslessRep& updRep(); 00265 const MasslessRep& getRep() const; 00266 }; 00267 00268 00269 00270 //============================================================================== 00271 // BODY::GROUND 00272 //============================================================================== 00275 class SimTK_SIMBODY_EXPORT Body::Ground : public Body { 00276 public: 00277 Ground(); 00278 00279 class GroundRep; // local subclass 00280 SimTK_PIMPL_DOWNCAST(Ground, Body); 00281 private: 00282 GroundRep& updRep(); 00283 const GroundRep& getRep() const; 00284 }; 00285 00286 } // namespace SimTK 00287 00288 #endif // SimTK_SIMBODY_BODY_H_ 00289 00290 00291