NTRT Simulator
 All Classes Files Functions Variables Typedefs Friends Pages
tgRodInfo.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 BTEN_ROD_H
20 #define BTEN_ROD_H
21 
29 // This library
30 #include "tgPairs.h"
31 #include "tgRigidInfo.h"
32 // The NTRT Core Library
33 #include "tgUtil.h"
34 #include "core/tgRod.h"
35 
36 // The Bullet Physics library
37 #include "btBulletDynamicsCommon.h"
38 
39 class btVector3;
40 
41 // @todo: Need to take tags into account...
42 
47 class tgRodInfo : public tgRigidInfo {
48 public:
49 
55  tgRodInfo(const tgRod::Config& config);
56 
62  tgRodInfo(const tgRod::Config& config, tgTags tags);
63 
71  tgRodInfo(const tgRod::Config& config, const tgPair& pair);
72 
80  tgRodInfo(const tgRod::Config& config, tgTags tags, const tgPair& pair);
81 
85  virtual ~tgRodInfo() {}
86 
90  tgRigidInfo* createRigidInfo(const tgPair& pair);
91 
98  virtual void initRigidBody(tgWorld& world);
99 
100  tgModel* createModel(tgWorld& world);
101 
106  const tgRod::Config& getConfig() const { return m_config; }
107 
109  const btVector3& getFrom() const { return m_pair.getFrom(); }
110 
112  const btVector3& getTo() const { return m_pair.getTo(); }
113 
118  virtual btCollisionShape* getCollisionShape(tgWorld& world) const;
119 
124  virtual btTransform getTransform() const
125  {
126  return tgUtil::getTransform(getFrom(), getTo());
127  }
128 
134  virtual double getMass() const;
140  virtual btVector3 getCenterOfMass() const
141  {
142  return (getFrom() + getTo()) / 2.0;
143  }
144 
153  virtual btVector3
154  getConnectionPoint(const btVector3& referencePoint,
155  const btVector3& destinationPoint) const;
156 
165  virtual btVector3
166  getConnectionPoint(const btVector3& referencePoint,
167  const btVector3& destinationPoint,
168  const double rotation) const;
169 
175  virtual tgCompoundRigidInfo* getCompound() { return 0; }
176 
182  virtual const tgCompoundRigidInfo* getCompound() const { return 0; }
183 
190  virtual std::set<tgRigidInfo*> getLeafRigids();
191 
197  virtual bool containsNode(const btVector3& nodeVector) const
198  {
199  return (getFrom() == nodeVector) || (getTo() == nodeVector);
200  }
201 
209  virtual bool sharesNodesWith(const tgRigidInfo& other) const;
210 
215  virtual std::set<btVector3> getContainedNodes() const;
216 
221  double getLength() const {
222  return getFrom().distance(getTo());
223  }
224 
225 private:
226 
228  tgRodInfo(const tgRodInfo&);
229 
231  tgRodInfo& operator=(const tgRodInfo&);
232 
233 private:
234 
236  const tgPair m_pair;
237 
239  const tgRod::Config& m_config;
240 
241 };
242 
249 inline std::ostream& operator<<(std::ostream& os, const tgRodInfo& rod)
250 {
251  os << "tgRodInfo(" << rod.getFrom() << ", " << rod.getTo() <<")";
252  return os;
253 }
254 
255 #endif
const btVector3 & getFrom() const
Definition: tgRodInfo.h:109
Definition of abstract class tgRigidInfo.
virtual ~tgRodInfo()
Definition: tgRodInfo.h:85
virtual void initRigidBody(tgWorld &world)
Definition: tgRodInfo.cpp:71
tgRodInfo(const tgRod::Config &config)
Definition: tgRodInfo.cpp:42
virtual btCollisionShape * getCollisionShape(tgWorld &world) const
Definition: tgRodInfo.cpp:98
virtual std::set< tgRigidInfo * > getLeafRigids()
Definition: tgRodInfo.cpp:178
tgRigidInfo * createRigidInfo(const tgPair &pair)
Definition: tgRodInfo.cpp:66
std::ostream & operator<<(std::ostream &os, const tgRodInfo &rod)
Definition: tgRodInfo.h:249
virtual std::set< btVector3 > getContainedNodes() const
Definition: tgRodInfo.cpp:210
virtual btVector3 getCenterOfMass() const
Definition: tgRodInfo.h:140
Definition of class tgPairs.
virtual bool sharesNodesWith(const tgRigidInfo &other) const
Definition: tgRodInfo.cpp:185
double getLength() const
Definition: tgRodInfo.h:221
virtual btVector3 getConnectionPoint(const btVector3 &referencePoint, const btVector3 &destinationPoint) const
Definition: tgRodInfo.cpp:125
virtual btTransform getTransform() const
Definition: tgRodInfo.h:124
virtual const tgCompoundRigidInfo * getCompound() const
Definition: tgRodInfo.h:182
const tgRod::Config & getConfig() const
Definition: tgRodInfo.h:106
virtual bool containsNode(const btVector3 &nodeVector) const
Definition: tgRodInfo.h:197
static btTransform getTransform(const btVector3 &startOrientation, const btVector3 &start, const btVector3 &end)
Definition: tgUtil.h:89
Definition: tgPair.h:47
const btVector3 & getTo() const
Definition: tgRodInfo.h:112
Contains the definition of class tgUtil and overloaded operator<<() free functions.
virtual tgCompoundRigidInfo * getCompound()
Definition: tgRodInfo.h:175
Contains the definition of class tgRod $Id$.
virtual double getMass() const
Definition: tgRodInfo.cpp:115
btVector3 & getTo()
Definition: tgPair.cpp:75
btVector3 & getFrom()
Definition: tgPair.cpp:51
Definition: tgTags.h:43