NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgNode.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_NODE_H
20 #define TG_NODE_H
21 
30 #include "tgUtil.h"
31 #include "core/tgTaggable.h"
32 
33 //Bullet Physics
34 #include "LinearMath/btVector3.h"
35 #include "LinearMath/btQuaternion.h"
36 
37 // NOTE: Should tgNode hold a quaternion to specify rotation/orientation?
38 
39 
45 class tgNode : public btVector3, public tgTaggable
46 {
47 public:
48 
49  tgNode(const btVector3& v = btVector3(),
50  const std::string& tags = "") :
51  btVector3(v), tgTaggable(tags)
52  {}
53 
54  tgNode(double x, double y, double z,
55  const std::string& tags = "") :
56  btVector3(x,y,z), tgTaggable(tags)
57  {}
58 
62  void addRotation(const btVector3& fixedPoint,
63  const btVector3& fromOrientation,
64  const btVector3& toOrientation)
65  {
66  // Note: there's likely a more efficient way to do this...
67  addRotation(fixedPoint,
68  tgUtil::getQuaternionBetween(fromOrientation,
69  toOrientation));
70  }
71 
75  void addRotation(const btVector3& fixedPoint,
76  const btVector3& axis,
77  double angle)
78  {
79  tgUtil::addRotation(*this, fixedPoint, axis, angle);
80  }
81 
82 
86  void addRotation(const btVector3& fixedPoint,
87  const btQuaternion& rotation)
88  {
89  addRotation(fixedPoint,
90  rotation.getAxis(),
91  rotation.getAngle());
92  }
93 
94  // Note: Required for extending tgTaggable
95  bool operator==(const tgNode& other) const
96  {
97  return (this->x() == other.x()) &&
98  (this->y() == other.y()) &&
99  (this->z() == other.z());
100  }
101 
102 };
103 
104 
105 
113 inline std::ostream&
114 operator<<(std::ostream& os, const tgNode& node)
115 {
116  os << "tgNode(" << node.x() << ", " << node.y() << ", " << node.z() << ", {" << node.getTagStr(", ") << "})";
117  return os;
118 };
119 
120 
125 inline std::string asYamlItem(const tgNode& node, int indentLevel=0)
126 {
127  std::stringstream os;
128  std::string indent = std::string(2 * (indentLevel), ' ');
129  os << indent << "- tags: " << asYamlList(node.getTags()) << std::endl;
130  os << indent << " xyz: [" << node.x() << ", " << node.y() << ", " << node.z() << "]" << std::endl;
131  return os.str();
132 };
133 
134 
135 #endif
std::string asYamlList(const tgTags &tags)
Definition: tgTags.h:356
static btQuaternion getQuaternionBetween(btVector3 a, btVector3 b, const btVector3 &fallbackAxis=btVector3(0, 0, 0))
Definition: tgUtil.h:199
void addRotation(const btVector3 &fixedPoint, const btVector3 &fromOrientation, const btVector3 &toOrientation)
Definition: tgNode.h:62
void addRotation(const btVector3 &fixedPoint, const btQuaternion &rotation)
Definition: tgNode.h:86
Definition: tgNode.h:45
Contains the definition of class tgTaggable.
std::string asYamlItem(const tgNode &node, int indentLevel=0)
Definition: tgNode.h:125
std::ostream & operator<<(std::ostream &os, const tgNode &node)
Definition: tgNode.h:114
Rand seeding simular to the evolution and terrain classes.
static void addRotation(btVector3 &v, const btVector3 &fixedPoint, const btVector3 &axis, double angle)
Definition: tgUtil.h:274
void addRotation(const btVector3 &fixedPoint, const btVector3 &axis, double angle)
Definition: tgNode.h:75