OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimImageViewTransform.cpp
Go to the documentation of this file.
1 #include <math.h>
6 
8 
10  :
12  ossimViewInterface(NULL)
13 {
15 }
16 
18  ossimDpt& output) const
19 {
20  imageToView(input, output);
21 }
22 
24  ossimDpt& output) const
25 {
26  viewToImage(input, output);
27 }
28 
30  ossimDpt& viewPoint)const
31 {
32  viewPoint = imagePoint;
33 }
34 
36  ossimDpt& imagePoint)const
37 {
38  ossim2dTo2dTransform::inverse(viewPoint, imagePoint);
39 }
40 
42 {
43  ossimDpt tempPt;
44 
45  imageToView(imagePoint, tempPt);
46 
47  return tempPt;
48 }
49 
51 {
52  ossimDpt tempPt;
53 
54  viewToImage(viewPoint, tempPt);
55 
56  return tempPt;
57 }
58 
60  const ossimDpt& viewPt )const
61 {
62  ossimDpt ipt;
63  ossimDpt vpt;
64  viewToImage(viewPt, ipt);
65  if(ipt.hasNans())
66  {
67  vpt.makeNan();
68  }
69  else
70  {
71  imageToView(ipt, vpt);
72  }
73 
74  if(vpt.hasNans())
75  {
76  result.makeNan();
77  }
78  else
79  {
80  result = viewPt-vpt;
81  }
82  // result = ossimDpt(0,0);
83 }
84 
86 {
87  ossimDpt result;
88  getRoundTripErrorView(result, viewPt);
89  return result;
90 }
91 
93  const ossimDpt& imagePt )const
94 {
95  ossimDpt ipt;
96  ossimDpt vpt;
97  imageToView(imagePt, vpt);
98  if(vpt.hasNans())
99  {
100  ipt.makeNan();
101  }
102  else
103  {
104  viewToImage(vpt, ipt);
105  }
106 
107  if(ipt.hasNans())
108  {
109  result.makeNan();
110  }
111  else
112  {
113  result = imagePt-ipt;
114  }
115 
116 // result = ossimDpt(0,0);
117 }
118 
120 {
121  ossimDpt result;
122  getRoundTripErrorView(result, imagePt);
123  return result;
124 }
125 
127  const char* prefix)
128 {
129  return ossim2dTo2dTransform::loadState(kwl, prefix);
130 }
131 
133  const char* prefix)const
134 {
135  return ossim2dTo2dTransform::saveState(kwl, prefix);
136 }
137 
139  const ossimDrect& imageRect)
140 {
141  result.makeNan();
142  if(!imageRect.hasNans())
143  {
144  ossimDpt vul;
145  ossimDpt vur;
146  ossimDpt vlr;
147  ossimDpt vll;
148 
149  imageToView(imageRect.ul(),
150  vul);
151  imageToView(imageRect.ur(),
152  vur);
153  imageToView(imageRect.lr(),
154  vlr);
155  imageToView(imageRect.ll(),
156  vll);
157 
158  if(!vul.hasNans()&&
159  !vur.hasNans()&&
160  !vlr.hasNans()&&
161  !vll.hasNans())
162  {
163 
164  double deltaTop = (vul - vur).length();
165  double deltaBottom = (vll - vlr).length();
166  double deltaRight = (vur - vlr).length();
167 
168  double w = imageRect.width();
169  double h = imageRect.height();
170  result.x = (deltaTop/w + deltaBottom/w)*.5;
171  result.y = (deltaRight/h + deltaRight/h)*.5;
172  }
173  }
174 }
175 
177  const ossimDrect& viewRect)
178 {
179  result.makeNan();
180  if(!viewRect.hasNans())
181  {
182  ossimDpt iul;
183  ossimDpt iur;
184  ossimDpt ilr;
185  ossimDpt ill;
186 
187  imageToView(viewRect.ul(),
188  iul);
189  imageToView(viewRect.ur(),
190  iur);
191  imageToView(viewRect.lr(),
192  ilr);
193  imageToView(viewRect.ll(),
194  ill);
195 
196  if(!iul.hasNans()&&
197  !iur.hasNans()&&
198  !ilr.hasNans()&&
199  !ill.hasNans())
200  {
201 
202  double deltaTop = (iul - iur).length();
203  double deltaBottom = (ill - ilr).length();
204  double deltaRight = (iur - ilr).length();
205 
206  double w = viewRect.width();
207  double h = viewRect.height();
208  result.x = (deltaTop/w + deltaBottom/w)*.5;
209  result.y = (deltaRight/h + deltaRight/h)*.5;
210  }
211  }
212 }
213 
215  const ossimDpt& imagePoint,
216  const ossimDpt& deltaImagePointXY)const
217 {
218  ossimDpt p1 = imagePoint;
219  ossimDpt p2(imagePoint.x + deltaImagePointXY.x,
220  imagePoint.y);
221  ossimDpt p3(imagePoint.x,
222  imagePoint.y + deltaImagePointXY.y);
223 
224  ossimDpt transformedP1;
225  ossimDpt transformedP2;
226  ossimDpt transformedP3;
227 
228  imageToView(p1, transformedP1);
229  imageToView(p2, transformedP2);
230  imageToView(p3, transformedP3);
231 
232  ossimDpt deltaP1P2 = transformedP1 - transformedP2;
233  ossimDpt deltaP1P3 = transformedP1 - transformedP3;
234 
235  // now compute the distances.
236  double sumSquaredSqrtP1P2 = sqrt((deltaP1P2.x*deltaP1P2.x) +
237  (deltaP1P2.y*deltaP1P2.y));
238  double sumSquaredSqrtP1P3 = sqrt((deltaP1P3.x*deltaP1P3.x) +
239  (deltaP1P3.y*deltaP1P3.y));
240 
241  resultScale.x = 0;
242  resultScale.y = 0;
243 
244  if(sumSquaredSqrtP1P2 > FLT_EPSILON)
245  {
246  resultScale.x = sumSquaredSqrtP1P2/deltaImagePointXY.x;
247  }
248  if(sumSquaredSqrtP1P3 > FLT_EPSILON)
249  {
250  resultScale.y = sumSquaredSqrtP1P3/deltaImagePointXY.y;
251  }
252 }
253 
255  const ossimDpt& viewPoint,
256  const ossimDpt& deltaViewPointXY)const
257 {
258  ossimDpt p1 = viewPoint;
259  ossimDpt p2(viewPoint.x + deltaViewPointXY.x,
260  viewPoint.y);
261  ossimDpt p3(viewPoint.x,
262  viewPoint.y + deltaViewPointXY.y);
263 
264  ossimDpt transformedP1;
265  ossimDpt transformedP2;
266  ossimDpt transformedP3;
267 
268  viewToImage(p1, transformedP1);
269  viewToImage(p2, transformedP2);
270  viewToImage(p3, transformedP3);
271 
272  ossimDpt deltaP1P2 = transformedP1 - transformedP2;
273  ossimDpt deltaP1P3 = transformedP1 - transformedP3;
274 
275  // now compute the distances.
276  double sumSquaredSqrtP1P2 = sqrt((deltaP1P2.x*deltaP1P2.x) +
277  (deltaP1P2.y*deltaP1P2.y));
278  double sumSquaredSqrtP1P3 = sqrt((deltaP1P3.x*deltaP1P3.x) +
279  (deltaP1P3.y*deltaP1P3.y));
280 
281  resultScale.x = 0;
282  resultScale.y = 0;
283 
284  if(sumSquaredSqrtP1P2 > FLT_EPSILON)
285  {
286  resultScale.x = sumSquaredSqrtP1P2/deltaViewPointXY.x;
287  }
288  if(sumSquaredSqrtP1P3 > FLT_EPSILON)
289  {
290  resultScale.y = sumSquaredSqrtP1P3/deltaViewPointXY.y;
291  }
292 }
293 
295 {
296  ossimDpt p1;
297  ossimDpt p2;
298  ossimDpt p3;
299  ossimDpt p4;
300 
301  imageToView(imageRect.ul(), p1);
302  imageToView(imageRect.ur(), p2);
303  imageToView(imageRect.lr(), p3);
304  imageToView(imageRect.ll(), p4);
305 
306  return ossimDrect(p1, p2, p3, p4);
307 }
308 
310 {
311  ossimDpt p1;
312  ossimDpt p2;
313  ossimDpt p3;
314  ossimDpt p4;
315 
316  viewToImage(viewRect.ul(), p1);
317  viewToImage(viewRect.ur(), p2);
318  viewToImage(viewRect.lr(), p3);
319  viewToImage(viewRect.ll(), p4);
320 
321  return ossimDrect(p1, p2, p3, p4);
322 }
323 
325 {
326  return out;
327 }
328 
330  const ossimImageViewTransform& data)
331 {
332  return data.print(out);
333 }
334 
ossimObject * theObject
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
virtual void getViewToImageScale(ossimDpt &resultScale, const ossimDpt &imagePoint, const ossimDpt &deltaImagePointXY) const
ossim_float64 width() const
Definition: ossimDrect.h:522
virtual void getScaleChangeViewToImage(ossimDpt &result, const ossimDrect &viewRect)
Represents serializable keyword/value map.
const ossimDpt & ul() const
Definition: ossimDrect.h:339
double y
Definition: ossimDpt.h:165
virtual void forward(const ossimDpt &input, ossimDpt &output) const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
std::ostream & operator<<(std::ostream &out, const ossimImageViewTransform &data)
virtual void getRoundTripErrorImage(ossimDpt &result, const ossimDpt &imagePt) const
virtual ossimDrect getViewToImageBounds(const ossimDrect &viewRect) const
Computes the bounding rect in image space of the quad formed by the transformed view points of the in...
#define RTTI_DEF2(cls, name, b1, b2)
Definition: ossimRtti.h:493
virtual ossimDrect getImageToViewBounds(const ossimDrect &imageRect) const
Computes the bounding rect in view space of the quad formed by the transformed image points of the in...
virtual void inverse(const ossimDpt &input, ossimDpt &output) const
#define FLT_EPSILON
bool hasNans() const
Definition: ossimDrect.h:396
bool hasNans() const
Definition: ossimDpt.h:67
ossim_float64 height() const
Definition: ossimDrect.h:517
virtual void getRoundTripErrorView(ossimDpt &result, const ossimDpt &viewPt) const
virtual void getScaleChangeImageToView(ossimDpt &result, const ossimDrect &imageRect)
virtual std::ostream & print(std::ostream &out) const
Generic print method.
const ossimDpt & ur() const
Definition: ossimDrect.h:340
double x
Definition: ossimDpt.h:164
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
virtual void imageToView(const ossimDpt &imagePoint, ossimDpt &viewPoint) const
virtual void inverse(const ossimDpt &input, ossimDpt &output) const
const ossimDpt & ll() const
Definition: ossimDrect.h:342
const ossimDpt & lr() const
Definition: ossimDrect.h:341
void makeNan()
Definition: ossimDpt.h:65
virtual void viewToImage(const ossimDpt &viewPoint, ossimDpt &imagePoint) const
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
virtual void getImageToViewScale(ossimDpt &resultScale, const ossimDpt &imagePoint, const ossimDpt &deltaImagePointXY) const