V-ART
sgpath.cpp
Go to the documentation of this file.
1 
5 #include "vart/sgpath.h"
6 #include "vart/transform.h"
7 #include "vart/joint.h"
8 
9 #include <cassert>
10 
11 using namespace std;
12 
14 {
15 }
16 
18 {
19  graphPath = path.graphPath;
20  return *this;
21 }
22 
23 void VART::SGPath::GetTransform(Transform* resultPtr) const
24 {
25  Transform* mTrans;
26 
27  assert(resultPtr != NULL);
28  resultPtr->MakeIdentity();
29 
30  // For each node in the path...
31  list<VART::SceneNode*>::const_iterator iter = graphPath.begin();
32  for(; iter != graphPath.end(); ++iter)
33  {
34  mTrans = dynamic_cast <VART::Transform*>(*iter);
35  // ... if the node is some kind of transform ...
36  if (mTrans != NULL)
37  {
38  // ... then accumulate it.
39  resultPtr->CopyMatrix((*resultPtr)*(*mTrans));
40  }
41  }
42 }
43 
45 {
46  list<VART::SceneNode*>::reverse_iterator rIter = graphPath.rbegin();
47  Joint* jointPtr;
48 
49  while (rIter != graphPath.rend())
50  {
51  jointPtr = dynamic_cast<Joint*>(*rIter);
52  if (jointPtr != NULL)
53  return jointPtr;
54  ++rIter;
55  }
56  return NULL;
57 }
58 
60 {
61  assert(!graphPath.empty());
62  return graphPath.front();
63 }
64 
65 void VART::SGPath::Traverse(SNOperator* operatorPtr) const
66 {
67  list<VART::SceneNode*>::const_iterator iter = graphPath.begin();
68  for(; iter != graphPath.end(); ++iter)
69  operatorPtr->OperateOn(*iter);
70 }
71 
72 ostream& VART::operator<<(ostream& output, const VART::SGPath& path)
73 {
74  list<VART::SceneNode*>::const_iterator iter = path.graphPath.begin();
75 
76  if (iter != path.graphPath.end())
77  {
78  cout << (*iter)->GetDescription();
79  ++iter;
80  while (iter != path.graphPath.end())
81  {
82  output << ", " << (*iter)->GetDescription();
83  ++iter;
84  }
85  }
86  return output;
87 }
Base class for objects that compose a scene graph.
Definition: scenenode.h:25
Representation of joints.
Definition: joint.h:34
void Traverse(SNOperator *operatorPtr) const
Process all nodes in path.
Definition: sgpath.cpp:65
std::ostream & operator<<(std::ostream &output, const Joint::DofID &dofId)
virtual void OperateOn(const SceneNode *nodePtr)=0
Objects that process scene nodes.
Definition: snoperator.h:19
Geometric transformations.
Definition: transform.h:24
std::list< SceneNode * > graphPath
Definition: sgpath.h:41
Header file for V-ART class "Joint".
void GetTransform(Transform *resultPtr) const
Combines and returns the multiplication of all transforms in a path.
Definition: sgpath.cpp:23
void MakeIdentity()
Turns transform into identity.
Definition: transform.cpp:49
Header file for V-ART class "Transform".
Header file for V-ART class "SGPath".
void CopyMatrix(const Transform &t)
Copies matrix data from another transform.
Definition: transform.cpp:138
Scene Graph Path.
Definition: sgpath.h:23
Joint * PointerToLastJoint()
Returns a pointer to the last joint in the path.
Definition: sgpath.cpp:44
SGPath & operator=(const SGPath &path)
Definition: sgpath.cpp:17
SceneNode * FrontPtr() const
Returns a pointer to the first node.
Definition: sgpath.cpp:59