OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimAffineTransform.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // AUTHOR: Oscar Kramer (okramer@imagelinks.com)
6 //
7 // DESCRIPTION: Contains implementation of class ossimAffineTransform
8 //
9 // LIMITATIONS: None.
10 //
11 //*****************************************************************************
12 // $Id: ossimAffineTransform.cpp 15766 2009-10-20 12:37:09Z gpotts $
13 
14 #include <cstdlib>
16 RTTI_DEF1(ossimAffineTransform, "ossimAffineTransform", ossim2dTo2dTransform);
17 
21 #include <ossim/base/ossimString.h>
22 //*****************************************************************************
23 // CONSTRUCTOR:
24 //*****************************************************************************
26  :
28  theScale(1.0, 1.0),
29  theRotation(0.0),
30  theTranslation(0.0, 0.0),
31  theAffineEnabledFlag(true),
32  theForwardXform(3, 3),
33  theInverseXform(3, 3)
34 {
35  setIdentity();
36 }
37 
39  :
41  theScale(src.theScale),
42  theRotation(src.theRotation),
43  theTranslation(src.theTranslation),
44  theAffineEnabledFlag(src.theAffineEnabledFlag),
45  theForwardXform(src.theForwardXform),
46  theInverseXform(src.theInverseXform)
47 {
48 }
49 
51  const ossimAffineTransform& rhs)
52 {
53  if (this != &rhs)
54  {
56 
57  theScale = rhs.theScale;
63  }
64  return *this;
65 }
66 
67 //*****************************************************************************
68 // METHOD:
69 //*****************************************************************************
71  ossimDpt& output) const
72 {
74  {
75  output.x = theForwardXform[0][0]*input.x+
76  theForwardXform[0][1]*input.y+
77  theForwardXform[0][2];
78  output.y = theForwardXform[1][0]*input.x+
79  theForwardXform[1][1]*input.y+
80  theForwardXform[1][2];
81  }
82  else
83  {
84  output = input;
85  }
86 }
87 
88 //*****************************************************************************
89 // METHOD:
90 //*****************************************************************************
92  ossimDpt& output) const
93 {
95  {
96  output.x = theInverseXform[0][0]*input.x+
97  theInverseXform[0][1]*input.y+
98  theInverseXform[0][2];
99  output.y = theInverseXform[1][0]*input.x+
100  theInverseXform[1][1]*input.y+
101  theInverseXform[1][2];
102  }
103  else
104  {
105  output = input;
106  }
107 }
108 
109 //*****************************************************************************
110 // METHOD:
111 //*****************************************************************************
113  const char* prefix) const
114 {
115  kwl.add(prefix,
117  theScale.x,
118  true);
119  kwl.add(prefix,
121  theScale.y,
122  true);
123  kwl.add(prefix,
126  true);
127  kwl.add(prefix,
130  true);
131  kwl.add(prefix,
133  theRotation,
134  true);
135 
136  ossim2dTo2dTransform::saveState(kwl, prefix);
137 
138  return true;
139 }
140 
141 //*****************************************************************************
142 // METHOD:
143 //*****************************************************************************
145  const char* prefix)
146 {
147  const char* buf;
148 
149  if (!ossim2dTo2dTransform::loadState(kwl, prefix))
150  goto BAD_KEYWORD;
151 
152  buf= kwl.find(prefix, ossimKeywordNames::SCALE_X_KW);
153  if (!buf) goto BAD_KEYWORD;
154  theScale.x = std::atof(buf);
155 
156  buf= kwl.find(prefix, ossimKeywordNames::SCALE_Y_KW);
157  if (!buf) goto BAD_KEYWORD;
158  theScale.y = std::atof(buf);
159 
160  buf= kwl.find(prefix, ossimKeywordNames::TRANSLATION_X_KW);
161  if (!buf) goto BAD_KEYWORD;
162  theTranslation.x = std::atof(buf);
163 
164  buf= kwl.find(prefix, ossimKeywordNames::TRANSLATION_Y_KW);
165  if (!buf) goto BAD_KEYWORD;
166  theTranslation.y = std::atof(buf);
167 
168  buf= kwl.find(prefix, ossimKeywordNames::ROTATION_KW);
169  if (!buf) goto BAD_KEYWORD;
170  theRotation = std::atof(buf);
171 
172  computeMatrix();
173  return true;
174 
175  BAD_KEYWORD:
176  return false;
177 }
178 
179 //*****************************************************************************
180 // METHOD:
181 //*****************************************************************************
182 void ossimAffineTransform::setMatrix(double rotation,
183  const ossimDpt& scale,
184  const ossimDpt& translation)
185 {
186  theScale = scale;
187  theRotation = rotation;
188  theTranslation = translation;
189 
190  computeMatrix();
191 }
192 
193 //*****************************************************************************
194 // METHOD:
195 //*****************************************************************************
197 {
198  theScale.x = 1;
199  theScale.y = 1;
200  theTranslation.x = 0;
201  theTranslation.y = 0;
202  theRotation = 0.0;
203 
204  computeMatrix();
205 }
206 
207 //*****************************************************************************
208 // METHOD:
209 //*****************************************************************************
211 {
214  theTranslation.y)*
217  theScale.y,
218  1.0);
219 
220  //***
221  // The inverse transform is just the matrix inverse:
222  //***
224 }
225 
226 
227 //*****************************************************************************
228 // METHOD:
229 //*****************************************************************************
231 {
232  os << "ossimAffineTransform:"
233  << "\n theScale = " << theScale
234  << "\n theTranslation = " << theTranslation
235  << "\n theRotation = " << theRotation << std::endl;
236  return os;
237 }
virtual const ossimAffineTransform & operator=(const ossimAffineTransform &rhs)
assignment operator=
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
void setMatrix(double rotation, const ossimDpt &scale, const ossimDpt &translation)
RTTI_DEF1(ossimAffineTransform, "ossimAffineTransform", ossim2dTo2dTransform)
bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Represents serializable keyword/value map.
const char * find(const char *key) const
double y
Definition: ossimDpt.h:165
static const char * SCALE_X_KW
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
static const char * ROTATION_KW
virtual const ossim2dTo2dTransform & operator=(const ossim2dTo2dTransform &rhs)
static const char * SCALE_Y_KW
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual void inverse(const ossimDpt &input, ossimDpt &output) const
NEWMAT::Matrix theInverseXform
static const char * TRANSLATION_X_KW
NEWMAT::Matrix theForwardXform
static const char * TRANSLATION_Y_KW
virtual std::ostream & print(std::ostream &out) const
Generic print method.
static NEWMAT::Matrix createTranslationMatrix(double dx, double dy)
static NEWMAT::Matrix createRotationZMatrix(double angle, ossimCoordSysOrientMode orientationMode=OSSIM_RIGHT_HANDED)
double x
Definition: ossimDpt.h:164
static NEWMAT::Matrix createScaleMatrix(double X, double Y, double Z)
bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
virtual void forward(const ossimDpt &input, ossimDpt &output) const