OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimImageViewAffineTransform.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: See top level LICENSE.txt file.
5 //
6 // Author: Garrett Potts
7 //
8 //*******************************************************************
9 // $Id: ossimImageViewAffineTransform.cpp 23423 2015-07-13 19:07:38Z dburken $
10 
14 #include <ossim/base/ossimString.h>
15 
16 RTTI_DEF1(ossimImageViewAffineTransform, "ossimImageViewAffineTransform", ossimImageViewTransform)
17 
19  double imageScaleX,
20  double imageScaleY,
21  double scaleXValue,
22  double scaleYValue,
23  double translateXValue,
24  double translateYValue,
25  double pivotXValue,
26  double pivotYValue)
27  :m_transform(3,3),
28  m_inverseTransform(3,3),
29  m_rotation(rotateDegrees),
30  m_imageSpaceScale(imageScaleX,imageScaleY),
31  m_scale(scaleXValue, scaleYValue),
32  m_translate(translateXValue, translateYValue),
33  m_pivot(pivotXValue, pivotYValue)
34 {
35  m_transform << 1 << 0 << 0
36  << 0 << 1 << 0
37  << 0 << 0 << 1;
38 
39  m_inverseTransform << 1 << 0 << 0
40  << 0 << 1 << 0
41  << 0 << 0 << 1;
42 
43 
44  rotate(rotateDegrees);
45  scale(scaleXValue, scaleYValue);
46  translate(translateXValue, translateYValue);
47  pivot(m_pivot.x, m_pivot.y);
48 }
49 
51 {
52 }
53 
55  ossimDpt& viewPoint)const
56 {
57 
58  viewPoint.x = m_transform[0][0]*imagePoint.x + m_transform[0][1]*imagePoint.y + m_transform[0][2];
59  viewPoint.y = m_transform[1][0]*imagePoint.x + m_transform[1][1]*imagePoint.y + m_transform[1][2];
60 }
61 
63  ossimDpt& imagePoint)const
64 {
65  imagePoint.x = m_inverseTransform[0][0]*viewPoint.x + m_inverseTransform[0][1]*viewPoint.y + m_inverseTransform[0][2];
66  imagePoint.y = m_inverseTransform[1][0]*viewPoint.x + m_inverseTransform[1][1]*viewPoint.y + m_inverseTransform[1][2];
67 }
68 
69 void ossimImageViewAffineTransform::setMatrix(NEWMAT::Matrix& matrix)
70 {
71  m_transform = matrix;
73 }
74 
75 const NEWMAT::Matrix& ossimImageViewAffineTransform::getMatrix()const
76 {
77  return m_transform;
78 }
79 
81  double deltaY)
82 {
83  m_translate = ossimDpt(deltaX, deltaY);
85 // NEWMAT::Matrix m(3,3);
86 
87 // m << 1 << 0 << deltaX
88 // << 0 << 1 << deltaY
89 // << 0 << 0 << 1;
90 
91 
92 // m_transform = m*m_transform;
93 // m_inverseTransform = m_transform.i();
94 }
95 
97 {
98  translate(deltaX, m_translate.y);
99 }
100 
102 {
103  translate(m_translate.x, deltaY);
104 }
105 
107 {
110 }
111 
113 {
115 }
116 
118 {
120 }
121 
123 {
124 // NEWMAT::Matrix m(3, 3);
125 
126 // m << x << 0 << 0
127 // << 0 << y << 0
128 // << 0 << 0 << 1;
129 
130 
131 // m_transform = (m*m_transform);
132 
133 // m_inverseTransform = m_transform.i();
134 
135  m_scale = ossimDpt(x,y);
137 }
138 
140 {
141  scale(x, m_scale.y);
142 }
143 
145 {
146  scale(m_scale.x, y);
147 }
148 
149 void ossimImageViewAffineTransform::pivot(double originX, double originY)
150 {
151  m_pivot.x = originX;
152  m_pivot.y = originY;
154 }
155 
157 {
158  pivot(originX,m_pivot.y);
159 }
160 
162 {
163  pivot(m_pivot.x, originY);
164 }
165 
167 {
168  m_rotation = degrees;
170 // m_transform = (m_transform * ossimMatrix3x3::createRotationZMatrix(degrees));
171 // m_transform = ossimMatrix3x3::createRotationZMatrix(degrees) * m_transform;
172 
173 // m_inverseTransform = m_transform.i();
174 }
175 
177 {
178  NEWMAT::Matrix imageSpaceScaleM(3,3);
179  NEWMAT::Matrix scaleM(3, 3);
180  NEWMAT::Matrix rotzM = ossimMatrix3x3::createRotationZMatrix(m_rotation);
181  NEWMAT::Matrix transM(3,3);
182  NEWMAT::Matrix transOriginM(3,3);
183  NEWMAT::Matrix transOriginNegatedM(3,3);
184 
185  transM << 1 << 0 << m_translate.x
186  << 0 << 1 << m_translate.y
187  << 0 << 0 << 1;
188 
189  transOriginM << 1 << 0 << m_pivot.x
190  << 0 << 1 << m_pivot.y
191  << 0 << 0 << 1;
192 
193  transOriginNegatedM << 1 << 0 << -m_pivot.x
194  << 0 << 1 << -m_pivot.y
195  << 0 << 0 << 1;
196 
197  scaleM << m_scale.x << 0 << 0
198  << 0 << m_scale.y << 0
199  << 0 << 0 << 1;
200 
201  imageSpaceScaleM << m_imageSpaceScale.x << 0 << 0
202  << 0 << m_imageSpaceScale.y << 0
203  << 0 << 0 << 1;
204 
205 // m_transform = transOriginM*transM*scaleM*rotzM*transOriginNegatedM;
206  // pivot should just be around the rotation
207  m_transform = transM*scaleM*transOriginM*rotzM*imageSpaceScaleM*transOriginNegatedM;
209 
210 }
211 
212 
214  const char* prefix)
215 {
216  ossimString imageScaleString(kwl.find(prefix,"image_scale"));
217  ossimString scaleString(kwl.find(prefix,"scale"));
218  ossimString pivotString(kwl.find(prefix,"pivot"));
219  ossimString translateString(kwl.find(prefix,"translate"));
220  ossimString rotateString(kwl.find(prefix,"rotate"));
221 
222  if(!imageScaleString.empty())
223  {
224  m_imageSpaceScale.toPoint(imageScaleString);
225  }
226  if(!scaleString.empty())
227  {
228  m_scale.toPoint(scaleString);
229  }
230  if(!pivotString.empty())
231  {
232  m_pivot.toPoint(pivotString);
233  }
234  if(!translateString.empty())
235  {
236  m_translate.toPoint(translateString);
237  }
238  if(!rotateString.empty())
239  {
240  m_rotation = rotateString.toDouble();
241  }
244  return true;
245 }
246 
248  const char* prefix)const
249 {
250  kwl.add(prefix,
251  "image_scale",
253  true);
254  kwl.add(prefix,
255  "rotation",
256  m_rotation,
257  true);
258 
259  // Fixed for multithread sequencer load, this uses saveState/loadState to
260  // clone image chains and rotate was not cloning, producing invalid tiles
261  kwl.add(prefix,
262  "rotate",
263  m_rotation,
264  true);
265  kwl.add(prefix,
266  "pivot",
267  m_pivot.toString(),
268  true);
269  kwl.add(prefix,
270  "scale",
271  m_scale.toString(),
272  true);
273  kwl.add(prefix,
274  "translate",
276  true);
277 
278  return ossimImageViewTransform::saveState(kwl,prefix);
279 }
280 
282 {
283  return true;
284 }
285 
287 {
289  if(view)
290  {
291  m_transform = view->m_transform;
293  m_rotation = view->m_rotation;
295  m_scale = view->m_scale;
296  m_translate = view->m_translate;
297  m_pivot = view->m_pivot;
298  }
299  return (view!=0);
300 }
301 
303 {
304  return this;
305 }
306 
308 {
309  return this;
310 }
311 
313 {
314  return ossimDpt(1,1);
315 }
316 
318 {
319  ossimDpt result;
320 
321  result.makeNan();
322 
323  return result;
324 }
325 
327 {
328  bool result = ossimImageViewTransform::isEqualTo(obj,compareType);
329 
330  if(result)
331  {
332  result = false;
333  const ossimImageViewAffineTransform* rhs = dynamic_cast<const ossimImageViewAffineTransform*> (&obj);
334  if(rhs)
335  {
336  result = (ossim::almostEqual(m_rotation, rhs->m_rotation)&&
338  (m_scale.isEqualTo(rhs->m_scale))&&
340  (m_pivot.isEqualTo(rhs->m_pivot))
341  );
342  }
343  }
344 
345  return result;
346 }
ossim_uint32 x
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
virtual bool isEqualTo(const ossimObject &obj, ossimCompareType compareType=OSSIM_COMPARE_FULL) const
bool isEqualTo(const ossimDpt &rhs, ossimCompareType compareType=OSSIM_COMPARE_FULL) const
Definition: ossimDpt.cpp:153
Represents serializable keyword/value map.
ossim_uint32 y
const char * find(const char *key) const
bool almostEqual(T x, T y, T tolerance=FLT_EPSILON)
Definition: ossimCommon.h:53
double y
Definition: ossimDpt.h:165
ossimCompareType
virtual bool setView(ossimObject *obj)
virtual void imageToView(const ossimDpt &imagePoint, ossimDpt &viewPoint) const
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
void toPoint(const std::string &s)
Initializes this point from string.
Definition: ossimDpt.cpp:192
virtual bool isEqualTo(const ossimObject &obj, ossimCompareType compareType=OSSIM_COMPARE_FULL) const
virtual void imageSpaceScale(double x, double y)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
ossimString toString(ossim_uint32 precision=15) const
Definition: ossimDpt.cpp:160
virtual void pivot(double originX, double originY)
static NEWMAT::Matrix createRotationZMatrix(double angle, ossimCoordSysOrientMode orientationMode=OSSIM_RIGHT_HANDED)
double x
Definition: ossimDpt.h:164
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
virtual void scale(double x, double y)
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
virtual void translate(double deltaX, double deltaY)
const NEWMAT::Matrix & getMatrix() const
virtual void viewToImage(const ossimDpt &viewPoint, ossimDpt &imagePoint) const
void makeNan()
Definition: ossimDpt.h:65