NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgPair.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_PAIR_H
28 #define TG_PAIR_H
29 
30 #include "core/tgTaggable.h"
31 
32 #include "LinearMath/btVector3.h"
33 
34 #include <string>
35 #include <iostream>
36 
37 class btQuaternion;
38 
48 class tgPair : public tgTaggable
49 {
50 public:
51 
52  tgPair();
53 
60  tgPair(btVector3 from, btVector3 to);
61 
62  tgPair(btVector3 from, btVector3 to, std::string tags);
63 
70  btVector3& getFrom();
71 
72  const btVector3& getFrom() const;
73 
78  void setFrom(btVector3 from);
79 
86  btVector3& getTo();
87 
88  const btVector3& getTo() const;
89 
94  void setTo(btVector3 to);
95 
96  void addRotation(const btVector3& fixedPoint,
97  const btVector3& axis,
98  double angle);
99 
100  void addRotation(const btVector3& fixedPoint,
101  const btVector3& fromOrientation,
102  const btVector3& toOrientation);
103 
104  void addRotation(const btVector3& fixedPoint,
105  const btQuaternion& rotation);
106 
107  // Note: without this, tgTaggables will throw a 'Most vexing parse' error
108  // @see http://en.wikipedia.org/wiki/Most_vexing_parse
109  // @todo: Should we also compare the tags here? I think not...
110  inline bool operator==(const tgPair& other) const
111  {
112  return (this->getFrom() == other.getFrom() && this->getTo() == other.getTo());
113  }
114 
115  void move(const btVector3& offset);
116 
117  /*
118  * Scales pair relative to a reference point
119  * @param[in] referencePoint a btVector3 reference point to scale the pair from/to
120  * @param[in] scaleFactor the scale factor by which to scale the pair
121  */
122  void scale(const btVector3& referencePoint, double scaleFactor);
123 
124 protected:
125 
127  std::pair<btVector3, btVector3> m_pair;
128 };
129 
137 inline std::ostream&
138 operator<<(std::ostream& os, const tgPair& pair)
139 {
140  os << "tgPair(" << pair.getFrom() << ", " << pair.getTo()
141  << ", {" << pair.getTagStr(", ") << "})";
142  return os;
143 }
144 
145 
150 inline std::string asYamlItem(const tgPair& pair, int indentLevel=0)
151 {
152  std::stringstream os;
153  std::string indent = std::string(2 * (indentLevel), ' ');
154  os << indent << "- tags: " << asYamlList(pair.getTags()) << std::endl;
155  os << indent << " pair: ["
156  << "[" << pair.getFrom().x() << ", " << pair.getFrom().y() << ", " << pair.getFrom().z() << "]" << ", "
157  << "[" << pair.getTo().x() << ", " << pair.getTo().y() << ", " << pair.getTo().z() << "]"
158  << "]" << std::endl;
159  return os.str();
160 };
161 
162 
163 #endif
std::string asYamlList(const tgTags &tags)
Definition: tgTags.h:356
std::string asYamlItem(const tgPair &pair, int indentLevel=0)
Definition: tgPair.h:150
std::pair< btVector3, btVector3 > m_pair
Definition: tgPair.h:127
std::ostream & operator<<(std::ostream &os, const tgPair &pair)
Definition: tgPair.h:138
Definition: tgPair.h:48
Contains the definition of class tgTaggable.
void setFrom(btVector3 from)
Definition: tgPair.cpp:68
btVector3 & getTo()
Definition: tgPair.cpp:76
btVector3 & getFrom()
Definition: tgPair.cpp:52
void setTo(btVector3 to)
Definition: tgPair.cpp:92