NTRT Simulator  v1.1
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgPairs.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 
27 #ifndef TG_PAIRS_H
28 #define TG_PAIRS_H
29 
30 #include <string>
31 #include <vector>
32 #include <algorithm> // std::find, std::remove
33 #include "core/tgTaggables.h"
34 #include "tgPair.h"
35 #include "tgUtil.h"
36 
37 class tgPairs : public tgTaggables<tgPair>
38 {
39 public:
40 
41  // @todo: do we need to initialize the pairs here?
42  tgPairs() : tgTaggables() {}
43 
44  // tgPairs(std::vector<tgPair>& pairs) : tgTaggables(pairs) { // @todo: Fix this -- casting is a problem...
45  tgPairs(std::vector<tgPair>& pairs) : tgTaggables() {
46  // @todo: make sure each pair is unique
47  for(int i = 0; i < pairs.size(); i++) {
48  addElement(pairs[i]);
49  }
50  }
51 
52  ~tgPairs() {}
53 
54  std::vector<tgPair>& getPairs()
55  {
56  return getElements();
57  }
58 
59  const std::vector<tgPair>& getPairs() const
60  {
61  return getElements();
62  }
63 
64  int addPair(const tgPair& pair) {
65  // @todo: make sure the pair is unique (both ways -- (a.from != b.from && a.to != b.to) && (a.from != b.to && a.to != b.from) )
66  return addElement(pair);
67  }
68 
69  int addPair(tgPair pair, const tgTags& tags)
70  {
71  pair.addTags(tags);
72  return addPair(pair);
73  }
74 
75  int addPair(tgPair pair, const std::string& space_separated_tags)
76  {
77  pair.addTags(space_separated_tags);
78  return addPair(pair);
79  }
80 
81  void setPair(int key, tgPair pair) {
82  setElement(key, pair);
83  }
84 
85  void move(const btVector3& offset)
86  {
87  std::vector<tgPair>& pairs = getPairs();
88  for(int i = 0; i < pairs.size(); i++) {
89  pairs[i].move(offset);
90  }
91  }
92 
93  void addRotation(const btVector3& fixedPoint,
94  const btVector3& axis,
95  double angle)
96  {
97  btQuaternion rotation(axis, angle);
98  addRotation(fixedPoint, rotation);
99  }
100 
101  void addRotation(const btVector3& fixedPoint,
102  const btVector3& fromOrientation,
103  const btVector3& toOrientation)
104  {
105  btQuaternion rotation = tgUtil::getQuaternionBetween(fromOrientation,
106  toOrientation);
107  addRotation(fixedPoint, rotation);
108  }
109 
110  void addRotation(const btVector3& fixedPoint,
111  const btQuaternion& rotation)
112  {
113  std::vector<tgPair>& pairs = getPairs();
114  for(int i = 0; i < pairs.size(); i++) {
115  pairs[i].addRotation(fixedPoint, rotation);
116  }
117  }
118 
119 
123  tgPairs& operator-=(const tgPairs& other) {
124  this->removeElements(other.getElements());
125  return *this;
126  }
127 
128  tgPairs& operator-=(const std::vector<tgPair*> other) {
129  this->removeElements(other);
130  return *this;
131  }
132 
133 };
134 
135 
136 inline tgPairs operator-(tgPairs lhs, const tgPairs& rhs)
137 {
138  lhs -= rhs;
139  return lhs;
140 }
141 
142 inline tgPairs operator-(tgPairs lhs, const std::vector<tgPair*>& rhs)
143 {
144  lhs -= rhs;
145  return lhs;
146 }
147 
148 
156 inline std::ostream&
157 operator<<(std::ostream& os, const tgPairs& p)
158 {
159 
160  os << "tgPairs(" << std::endl;
161  const std::vector<tgPair>& pairs = p.getPairs();
162  for(int i = 0; i < pairs.size(); i++) {
163  os << " " << pairs[i] << std::endl;
164  }
165  os << ")";
166 
167  return os;
168 }
169 
170 #endif
tgPairs & operator-=(const tgPairs &other)
Definition: tgPairs.h:123
Definition of class tgPair.
static btQuaternion getQuaternionBetween(btVector3 a, btVector3 b)
Definition: tgUtil.h:196
Contains the definition of class tgTaggables.
Definition: tgPair.h:48
std::ostream & operator<<(std::ostream &os, const tgPairs &p)
Definition: tgPairs.h:157
Contains the definition of class tgUtil and overloaded operator<<() free functions.
Definition: tgTags.h:44