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