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