OpenFrames
TransformAccumulator.hpp
Go to the documentation of this file.
1 /***********************************
2  Copyright 2018 Ravishankar Mathur
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 ***********************************/
16 
21 #ifndef _OF_TRANSFORMACCUMULATOR_
22 #define _OF_TRANSFORMACCUMULATOR_
23 
24 #include <OpenFrames/Export.h>
26 
27 #include <osg/Matrix>
28 #include <osg/NodeVisitor>
29 #include <osg/Referenced>
30 #include <osg/ref_ptr>
31 
32 namespace OpenFrames
33 {
34  class ReferenceFrame;
35 
44  class OF_EXPORT TransformVisitor : public osg::NodeVisitor
45  {
46  public:
47  enum CoordMode
48  {
49  WORLD_TO_LOCAL,
50  LOCAL_TO_WORLD
51  };
52 
54 
55  virtual void apply(osg::Transform& transform);
56  void accumulate(const FramePath &framePath);
57 
58  CoordMode _coordMode;
59  osg::Matrixd _matrix;
60 
61  protected:
62  virtual ~TransformVisitor();
63 
64  FramePath::const_iterator _itr;
65  };
66 
77  class OF_EXPORT TransformAccumulator : public osg::Referenced
78  {
79  public:
82 
84  ReferenceFrame* getRoot();
85  void setRoot( ReferenceFrame* root );
86 
88  ReferenceFrame* getOrigin();
89  bool setOrigin( ReferenceFrame* frame );
90 
92  bool isValid();
93 
95  osg::Matrixd& getLocalToWorld();
96 
98  osg::Matrixd& getWorldToLocal();
99 
100  protected:
101  virtual ~TransformAccumulator();
102  void _init();
103 
104  // FramePath from the root to the origin frame
105  osg::ref_ptr<DescendantTracker> _lookAtPath;
106 
107  // NodeVisitor that computes the transform from root to origin
108  osg::ref_ptr<TransformVisitor> _transformVisitor;
109  }; // !class TransformAccumulator
110 
111 } // !namespace OpenFrames
112 
113 #endif // !_OF_TRANSFORMACCUMULATOR_
Accumulates the transform along a path.
Definition: TransformAccumulator.hpp:44
Definition: CoordinateAxes.hpp:29
Computes the transformation of a ReferenceFrame wrt an ancestor.
Definition: TransformAccumulator.hpp:77
Definition: ReferenceFrame.hpp:54