NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgRigidInfo.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The NASA Tensegrity Robotics Toolkit (NTRT) v1 platform is licensed
7  * under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * http://www.apache.org/licenses/LICENSE-2.0.
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15  * either express or implied. See the License for the specific language
16  * governing permissions and limitations under the License.
17 */
18 
19 #ifndef TG_RIGID_INFO_H
20 #define TG_RIGID_INFO_H
21 
30 // The C++ Standard Library
31 #include <set>
32 // This library
33 #include "core/tgTaggable.h"
34 #include "core/tgModel.h"
35 //Bullet Physics
36 #include "LinearMath/btVector3.h"
37 #include "LinearMath/btQuaternion.h"
38 
39 // Forward references
41 class tgNode;
42 class tgNodes;
43 class tgPair;
44 class tgPairs;
45 class tgTagSearch;
46 class tgWorld;
47 
48 class btCollisionObject;
49 class btRigidBody;
50 class btCollisionShape;
51 class btTransform;
52 
75 class tgRigidInfo : public tgTaggable {
76 public:
77 
78  tgRigidInfo() :
79  tgTaggable(),
80  m_collisionShape(NULL),
81  m_rigidInfoGroup(NULL),
82  m_collisionObject(NULL)
83  {}
84 
85  tgRigidInfo(tgTags tags) :
86  tgTaggable(tags),
87  m_collisionShape(NULL),
88  m_rigidInfoGroup(NULL),
89  m_collisionObject(NULL)
90  {}
91 
92  tgRigidInfo(const std::string& space_separated_tags) :
93  tgTaggable(space_separated_tags),
94  m_collisionShape(NULL),
95  m_rigidInfoGroup(NULL),
96  m_collisionObject(NULL)
97  {}
98 
100  virtual ~tgRigidInfo()
101  {
102  }
103 
104  // To be overridden by subclasses
105  virtual tgRigidInfo* createRigidInfo(const tgNode& node)
106  {
107  return 0;
108  }
109 
110  virtual tgRigidInfo* createRigidInfo(const tgPair& pair)
111  {
112  return 0;
113  }
114 
115  virtual tgRigidInfo* createRigidInfo(const tgNode& node, const tgTagSearch& tagSearch);
116 
117  virtual tgRigidInfo* createRigidInfo(const tgPair& pair, const tgTagSearch& tagSearch);
118 
119  virtual std::vector<tgRigidInfo*> createRigidInfos(const tgNodes& nodes, const tgTagSearch& tagSearch);
120 
121  virtual std::vector<tgRigidInfo*> createRigidInfos(const tgPairs& pairs, const tgTagSearch& tagSearch);
122 
123  virtual void initRigidBody(tgWorld& world);
124 
125  virtual tgModel* createModel(tgWorld& world) = 0;
126 
131  virtual btCollisionShape* getCollisionShape(tgWorld& world) const = 0;
132 
137  void setCollisionShape(btCollisionShape* p_btCollisionShape)
138  {
140  m_collisionShape = p_btCollisionShape;
141  }
142 
150  {
151  return m_rigidInfoGroup;
152  }
153 
154  virtual const tgRigidInfo* getRigidInfoGroup() const
155  {
156  return m_rigidInfoGroup;
157  }
158 
163  virtual void setRigidInfoGroup(tgRigidInfo* rigidInfoGroup)
164  {
165  m_rigidInfoGroup = rigidInfoGroup;
166  }
167 
172  virtual btRigidBody* getRigidBody();
173 
178  virtual const btRigidBody* getRigidBody() const;
179 
184  virtual void setRigidBody(btRigidBody* rigidBody);
185 
190  virtual btCollisionObject* getCollisionObject()
191  {
192  return m_collisionObject;
193  }
194 
199  virtual const btCollisionObject* getCollisionObject() const
200  {
201  return m_collisionObject;
202  }
203 
208  virtual void setCollisionObject(btCollisionObject* collisionObject)
209  {
211  m_collisionObject = collisionObject;
212  }
213 
218  virtual btTransform getTransform() const = 0;
219 
224  virtual double getMass() const = 0;
225 
230  virtual btVector3 getCenterOfMass() const = 0;
231 
251  virtual btVector3
252  getConnectionPoint(const btVector3& referencePoint,
253  const btVector3& destinationPoint) const = 0;
254 
259  virtual btVector3
260  getConnectionPoint(const btVector3& referencePoint,
261  const btVector3& destinationPoint,
262  const double rotation) const
263  {
264  return getConnectionPoint(referencePoint, destinationPoint);
265  }
266 
273  bool isCompound() const { return getCompound() != 0; }
274 
282  virtual tgCompoundRigidInfo* getCompound() = 0;
283 
291  virtual const tgCompoundRigidInfo* getCompound() const = 0;
292 
298  virtual std::set<tgRigidInfo*> getLeafRigids() = 0;
299 
305  virtual bool containsNode(const btVector3& nodeVector) const = 0;
306 
312  virtual std::set<btVector3> getContainedNodes() const = 0;
313 
320  virtual bool sharesNodesWith(const tgRigidInfo& other) const;
321 
322  // Need these in order to see if we've already build a pair/node
323  // @todo: maybe -- don't like having to know about pairs and nodes here...
324  // virtual bool matches(const tgPair& pair) = 0;
325  // virtual bool matches(const tgNode& node) = 0;
326 
327 protected: // Protected, not private -- subclasses need access
328 
332  mutable btCollisionShape* m_collisionShape;
333 
342 
347  mutable btCollisionObject* m_collisionObject;
348 
349 };
350 
351 
360 inline std::ostream&
361 operator<<(std::ostream& os, const tgRigidInfo& obj)
362 {
363  os << "tgRigidInfo(" << obj.getRigidInfoGroup() << ", " << obj.getRigidBody() << ")";
364  return os;
365 }
366 
367 
368 #endif
bool isCompound() const
Definition: tgRigidInfo.h:273
virtual ~tgRigidInfo()
Definition: tgRigidInfo.h:100
std::ostream & operator<<(std::ostream &os, const tgRigidInfo &obj)
Definition: tgRigidInfo.h:361
virtual tgRigidInfo * getRigidInfoGroup()
Definition: tgRigidInfo.h:149
virtual bool containsNode(const btVector3 &nodeVector) const =0
virtual bool sharesNodesWith(const tgRigidInfo &other) const
virtual void setRigidBody(btRigidBody *rigidBody)
tgRigidInfo * m_rigidInfoGroup
Definition: tgRigidInfo.h:341
virtual tgCompoundRigidInfo * getCompound()=0
virtual btCollisionShape * getCollisionShape(tgWorld &world) const =0
virtual std::set< tgRigidInfo * > getLeafRigids()=0
virtual void setRigidInfoGroup(tgRigidInfo *rigidInfoGroup)
Definition: tgRigidInfo.h:163
Contains the definition of class tgModel.
virtual btRigidBody * getRigidBody()
virtual void setCollisionObject(btCollisionObject *collisionObject)
Definition: tgRigidInfo.h:208
btCollisionObject * m_collisionObject
Definition: tgRigidInfo.h:347
virtual btVector3 getCenterOfMass() const =0
Definition: tgPair.h:48
Definition: tgNode.h:45
virtual btVector3 getConnectionPoint(const btVector3 &referencePoint, const btVector3 &destinationPoint, const double rotation) const
Definition: tgRigidInfo.h:260
Contains the definition of class tgTaggable.
virtual double getMass() const =0
virtual btTransform getTransform() const =0
virtual btCollisionObject * getCollisionObject()
Definition: tgRigidInfo.h:190
virtual btVector3 getConnectionPoint(const btVector3 &referencePoint, const btVector3 &destinationPoint) const =0
virtual std::set< btVector3 > getContainedNodes() const =0
virtual const btCollisionObject * getCollisionObject() const
Definition: tgRigidInfo.h:199
Definition: tgTags.h:44
void setCollisionShape(btCollisionShape *p_btCollisionShape)
Definition: tgRigidInfo.h:137
btCollisionShape * m_collisionShape
Definition: tgRigidInfo.h:332