CoordinateSystem.cc
Go to the documentation of this file.
1 
9 #include <utl/CoordinateSystem.h>
10 #include <utl/TransformationMatrix.h>
11 #include <vector>
12 #include <algorithm>
13 
14 using namespace utl;
15 
16 
18  const CoordinateSystemPtr& theReferenceCS) :
19  fTransformation(theReferenceCS->GetTransformationForNewCS(theTransformation)),
20  fReferenceSystem(theReferenceCS->GetReferenceForNewCS())
21 {
22  CoordinateSystemValid(theReferenceCS);
23 }
24 
25 
27 {
28  delete fLastTransformation;
30 }
31 
32 
35  const
36 {
37  return shared_from_this();
38 }
39 
40 
46 
47 
50 {
53  return RootCoordinateSystem;
54 }
55 
56 
59  const
60 {
61  return GetReferenceSystem();
62 }
63 
64 
67  const
68 {
69  return GetThis();
70 }
71 
72 
75  const
76 {
77  return theTransformation * GetTransformation();
78 }
79 
80 
83  const
84 {
85  return theTransformation;
86 }
87 
88 
91  const CoordinateSystemPtr& theCS)
92 {
93  return CoordinateSystemPtr(new DerivedCSPolicy(theTrafo.Inverse(), theCS));
94 }
95 
96 
99  const CoordinateSystemPtr& theCS)
100 {
101  return CoordinateSystemPtr(new BaseCSPolicy(theTrafo.Inverse(), theCS));
102 }
103 
104 
107  const
108 {
110 
111  std::vector<CoordinateSystemPtr> myBases;
112  for (auto cs = GetReferenceSystem(); cs != root; cs = cs->GetReferenceSystem())
113  myBases.push_back(cs);
114 
115  for (auto cs = other->GetReferenceSystem(); cs != root; cs = cs->GetReferenceSystem()) {
116  const auto end = myBases.cend();
117  if (std::find(myBases.cbegin(), end, cs) != end)
118  return cs;
119  }
120  // not found, so the root CS must be the only common ancestor
121  return root;
122 }
123 
124 
127  const
128 {
130 
131  for (auto cs = GetReferenceSystem(); cs != target; cs = cs->GetReferenceSystem())
132  result *= cs->GetTransformation();
133 
134  return result;
135 }
136 
137 
140  const
141 {
142  if (target != fLastTarget.lock() || !fLastTransformation) {
143  delete fLastTransformation;
144  fLastTarget = target;
145 
146  const CoordinateSystemPtr commonBase = FindCommonBase(target);
147 
150  target->CollectTransformationFrom(commonBase) *
151  CollectTransformationFrom(commonBase).Inverse()
152  );
153  }
154 
155  return *fLastTransformation;
156 }
157 
158 
161  const
162 {
163  if (target != fLastTarget.lock() || !fLastInverseTransformation) {
166  new TransformationMatrix(GetTransformationTo(target).Inverse());
167  }
168 
170 }
TransformationMatrix CollectTransformationFrom(const CoordinateSystemPtr &target) const
Policy for base coordinate systems.
CoordinateSystemPtr FindCommonBase(const CoordinateSystemPtr &other) const
TransformationMatrix * fLastInverseTransformation
WeakCoordinateSystemPtr fLastTarget
const TransformationMatrix & GetTransformation() const
Get the transformation matrix relative to reference system.
virtual CoordinateSystemPtr GetReferenceForNewCS() const
Get reference system for the creation of new coordinate systems.
Transformations matrices for afine transformations.
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
static CoordinateSystemPtr RootCoordinateSystem
The root coordinate system - the unique, ultimate reference system.
const TransformationMatrix & GetTransformationTo(const CoordinateSystemPtr &target) const
Get the transformation to other coordinate system (with caching)
CoordinateSystemPtr GetReferenceSystem() const
Get the reference system for this coordinate system.
const Data result[]
static type FromTransformation(const TransformationMatrix &theTrafo, const CoordinateSystemPtr &theCS)
Generic factory for post-processing.
static CoordinateSystemPtr GetRootCoordinateSystem()
const TransformationMatrix & GetInverseTransformationTo(const CoordinateSystemPtr &target) const
Get the inverse transformation to other coordinate system (w/ caching)
virtual TransformationMatrix GetTransformationForNewCS(const TransformationMatrix &theTransformation) const
Calculate the correct transformation for the new CS.
TransformationMatrix Inverse() const
Inverse transformation.
CoordinateSystemPtr GetThis() const
Get a CoordinateSystemPointer for this.
TransformationMatrix * fLastTransformation
virtual CoordinateSystemPtr GetReferenceForNewCS() const
Get reference system for the creation of new coordinate systems.
void CoordinateSystemValid(const CoordinateSystemPtr &theCoordinateSystem)
virtual TransformationMatrix GetTransformationForNewCS(const TransformationMatrix &theTransformation) const
Calculate the correct transformation for the new CS.
static type FromTransformation(const TransformationMatrix &theTrafo, const CoordinateSystemPtr &theCS)
Generic factory for post-processing.

, generated on Tue Sep 26 2023.