NTRT Simulator  v1.1
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgConnectorInfo.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_CONNECTOR_INFO_H
20 #define TG_CONNECTOR_INFO_H
21 
30 #include "core/tgTaggable.h"
31 
32 class btVector3;
33 class tgNode;
34 class tgPair;
35 class tgPairs;
36 class tgTagSearch;
37 class tgRigidInfo;
38 class btRigidBody;
39 class tgModel;
40 class tgWorld;
41 
42 #include "LinearMath/btVector3.h" // @todo: any way to move this to the .cpp file?
43 #include "tgPair.h"
44 
45 class tgConnectorInfo : public tgTaggable {
46 public:
47 
48  tgConnectorInfo() :
49  m_fromRigidInfo(0),
50  m_toRigidInfo(0),
51  //m_fromRigidBody(0),
52  //m_toRigidBody(0),
53  tgTaggable()
54  {
55  // Supress compiler warning for bullet's unused variable
56  (void) btInfinityMask;
57  }
58 
59  tgConnectorInfo(tgTags tags) :
60  m_fromRigidInfo(0),
61  m_toRigidInfo(0),
62  //m_fromRigidBody(0),
63  //m_toRigidBody(0),
64  tgTaggable(tags)
65  {}
66 
67  tgConnectorInfo(const std::string& space_separated_tags) :
68  m_fromRigidInfo(0),
69  m_toRigidInfo(0),
70  //m_fromRigidBody(0),
71  //m_toRigidBody(0),
72  tgTaggable(space_separated_tags)
73  {}
74 
75  tgConnectorInfo(const tgPair& pair) :
76  m_pair(pair),
77  m_fromRigidInfo(0),
78  m_toRigidInfo(0),
79  //m_fromRigidBody(0),
80  //m_toRigidBody(0),
81  tgTaggable(pair.getTags())
82  {}
83 
84 
85  virtual ~tgConnectorInfo() {};
86 
87 
88  virtual tgConnectorInfo* createConnectorInfo(const tgPair& pair) = 0;
89 
90  virtual tgConnectorInfo* createConnectorInfo(const tgPair& pair, const tgTagSearch& tagSearch);
91 
92  virtual std::vector<tgConnectorInfo*> createConnectorInfos(const tgPairs& pairs, const tgTagSearch& tagSearch);
93 
94  virtual void initConnector(tgWorld& world) = 0;
95 
96  virtual tgModel* createModel(tgWorld& world) = 0;
97 
98 
99  btVector3& getFrom() {
100  return m_pair.getFrom();
101  };
102  const btVector3& getFrom() const
103  {
104  return m_pair.getFrom();
105  };
106 
107  btVector3& getTo() {
108  return m_pair.getTo();
109  };
110  const btVector3& getTo() const {
111  return m_pair.getTo();
112  };
113 
114  tgRigidInfo* getFromRigidInfo() {
115  return m_fromRigidInfo;
116  };
117  const tgRigidInfo* getFromRigidInfo() const {
118  return m_fromRigidInfo;
119  };
120 
121  void setFromRigidInfo(tgRigidInfo* rigidInfo)
122  {
123  m_fromRigidInfo = rigidInfo;
124  }
125 
126  tgRigidInfo* getToRigidInfo() {
127  return m_toRigidInfo;
128  };
129  const tgRigidInfo* getToRigidInfo() const {
130  return m_toRigidInfo;
131  };
132 
133  void setToRigidInfo(tgRigidInfo* rigidInfo)
134  {
135  m_toRigidInfo = rigidInfo;
136  }
137 
138  // @todo: Do we want to have these separate or use the rigidBody from the rigidInfos??
139  btRigidBody* getToRigidBody();
140 
141  btRigidBody* getFromRigidBody();
142 
143  // @todo: how should we calculate mass?
144  // Note that different connectors will likely use different methods of calculating mass...
145  virtual double getMass() = 0;
146 
147 
148  // Choose the appropriate rigids for the connector and give the connector pointers to them
149  virtual void chooseRigids(std::set<tgRigidInfo*> rigids);
150 
151  // @todo: in the process of switching ti std::vector for these...
152  virtual void chooseRigids(std::vector<tgRigidInfo*> rigids)
153  {
154  std::set<tgRigidInfo*> s;
155  s.insert(rigids.begin(), rigids.end());
156  chooseRigids(s);
157  }
158 
159 
160  tgRigidInfo* chooseRigid(std::set<tgRigidInfo*> rigids, const btVector3& v);
161 
162 
163 protected:
164  tgRigidInfo* findClosestCenterOfMass(std::set<tgRigidInfo*> rigids, const btVector3& v);
165 
166  // @todo: should this be protected/private?
167  std::set<tgRigidInfo*> findRigidsContaining(std::set<tgRigidInfo*> rigids, const btVector3& toFind);
168 
169  // @todo: Remove this? Is it used by anything?
170  bool rigidFoundIn(std::set<tgRigidInfo*> rigids, tgRigidInfo* rigid);
171 
172 
173  // Step 1: Define the points that we're connecting
174  tgPair m_pair;
175 
176  // Step 2: Using the points from step 1, the builders will find the right tgRigidInfo objects
177  tgRigidInfo* m_fromRigidInfo;
178  tgRigidInfo* m_toRigidInfo;
179 
180 };
181 
189 inline std::ostream&
190 operator<<(std::ostream& os, const tgConnectorInfo& n)
191 {
192 
193  os << "tgConnectorInfo(";
194  os << n.getFrom() << ", ";
195  os << n.getTo() << ", ";
196  os << "fromRigidInfo: " << n.getFromRigidInfo() << ", ";
197  os << "toRigidInfo: " << n.getToRigidInfo() << ", ";
198  os << "Tags: " << n.getTags();
199  os << ")";
200 
201  return os;
202 }
203 
204 #endif
Definition of class tgPair.
std::ostream & operator<<(std::ostream &os, const tgConnectorInfo &n)
Definition: tgPair.h:48
Definition: tgNode.h:45
Contains the definition of class tgTaggable.
btVector3 & getTo()
Definition: tgPair.cpp:76
btVector3 & getFrom()
Definition: tgPair.cpp:52
Definition: tgTags.h:44