OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
ossimThinPlateSpline Class Reference

#include <ossimThinPlateSpline.h>

Public Types

enum  vizGeorefInterType {
  VIZ_GEOREF_SPLINE_ZERO_POINTS, VIZ_GEOREF_SPLINE_ONE_POINT, VIZ_GEOREF_SPLINE_TWO_POINTS, VIZ_GEOREF_SPLINE_ONE_DIMENSIONAL,
  VIZ_GEOREF_SPLINE_FULL, VIZ_GEOREF_SPLINE_POINT_WAS_ADDED, VIZ_GEOREF_SPLINE_POINT_WAS_DELETED
}
 

Public Member Functions

 ossimThinPlateSpline (int nof_vars=1)
 
 ~ossimThinPlateSpline ()
 
int getNumberOfPoints () const
 
void setToler (double tx, double ty)
 
void getToler (double &tx, double &ty) const
 
vizGeorefInterType getInterpolationType () const
 
int deleteList ()
 
void growPoints ()
 
int addPoint (const double Px, const double Py, const double *Pvars)
 
int deletePoint (const double Px, const double Py)
 
int getPoint (const double Px, const double Py, double *Pvars) const
 
bool getXy (int index, double &x, double &y) const
 
bool changePoint (int index, double x, double y, double *Pvars)
 
void reset (void)
 
int solve (void)
 

Private Member Functions

double baseFunc (const double x1, const double y1, const double x2, const double y2) const
 

Private Attributes

vizGeorefInterType type
 
int _nof_vars
 
int _nof_points
 
int _max_nof_points
 
int _nof_eqs
 
double _tx
 
double _ty
 
double _ta
 
double _dx
 
double _dy
 
std::vector< double > x
 
std::vector< double > y
 
std::vector< std::vector< double > > rhs
 
std::vector< std::vector< double > > coef
 
std::vector< double > u
 
std::vector< int > unused
 
std::vector< int > index
 
std::vector< double > _AA
 
std::vector< double > _Ainv
 

Detailed Description

Definition at line 37 of file ossimThinPlateSpline.h.

Member Enumeration Documentation

◆ vizGeorefInterType

Constructor & Destructor Documentation

◆ ossimThinPlateSpline()

ossimThinPlateSpline::ossimThinPlateSpline ( int  nof_vars = 1)
inline

Definition at line 53 of file ossimThinPlateSpline.h.

53  {
54  _tx = _ty = 0.0;
55  _ta = 10.0;
56  _nof_points = 0;
57  _nof_vars = nof_vars;
58  _max_nof_points = 0;
59  rhs.resize(_nof_vars);
60  coef.resize(_nof_vars);
61  growPoints();
62  for ( int v = 0; v < _nof_vars; v++ )
63  for ( int i = 0; i < 3; i++ )
64  // rhs[i][v] = 0.0;
65  rhs[v][i] = 0.0;
67  }
std::vector< std::vector< double > > rhs
std::vector< std::vector< double > > coef
vizGeorefInterType type

◆ ~ossimThinPlateSpline()

ossimThinPlateSpline::~ossimThinPlateSpline ( )
inline

Definition at line 69 of file ossimThinPlateSpline.h.

References x, and y.

69  {
70  _AA.clear();
71  _Ainv.clear();
72  x.clear();
73  y.clear();
74  u.clear();
75  unused.clear();
76  index.clear();
77  rhs.clear();
78  coef.clear();
79  }
std::vector< int > unused
std::vector< std::vector< double > > rhs
std::vector< std::vector< double > > coef
std::vector< double > _AA
std::vector< double > y
std::vector< int > index
std::vector< double > _Ainv
std::vector< double > u
std::vector< double > x

Member Function Documentation

◆ addPoint()

int ossimThinPlateSpline::addPoint ( const double  Px,
const double  Py,
const double *  Pvars 
)

Definition at line 77 of file ossimThinPlateSpline.cpp.

References _max_nof_points, _nof_points, _nof_vars, growPoints(), rhs, type, VIZ_GEOREF_SPLINE_POINT_WAS_ADDED, x, and y.

Referenced by ossimHistogram::fillInteriorEmptyBins().

78 {
80  int i;
81 
83  growPoints();
84 
85  i = _nof_points;
86  //A new point is added
87  x[i] = Px;
88  y[i] = Py;
89  for ( int j = 0; j < _nof_vars; j++ )
90  rhs[j][i+3] = Pvars[j];
91  _nof_points++;
92  return 1;
93 }
std::vector< std::vector< double > > rhs
vizGeorefInterType type
std::vector< double > y
std::vector< double > x

◆ baseFunc()

double ossimThinPlateSpline::baseFunc ( const double  x1,
const double  y1,
const double  x2,
const double  y2 
) const
private

Definition at line 391 of file ossimThinPlateSpline.cpp.

Referenced by getPoint(), and solve().

393 {
394  if ( ( x1 == x2 ) && (y1 == y2 ) )
395  return 0.0;
396 
397  double dist = ( x2 - x1 ) * ( x2 - x1 ) + ( y2 - y1 ) * ( y2 - y1 );
398 
399  return dist * log( dist );
400 }

◆ changePoint()

bool ossimThinPlateSpline::changePoint ( int  index,
double  x,
double  y,
double *  Pvars 
)

Definition at line 95 of file ossimThinPlateSpline.cpp.

References _nof_points, _nof_vars, index, rhs, x, and y.

96 {
97  if ( index < _nof_points )
98  {
99  int i = index;
100  x[i] = Px;
101  y[i] = Py;
102  for ( int j = 0; j < _nof_vars; j++ )
103  rhs[j][i+3] = Pvars[j];
104  }
105 
106  return( true );
107 }
std::vector< std::vector< double > > rhs
std::vector< double > y
std::vector< int > index
std::vector< double > x

◆ deleteList()

int ossimThinPlateSpline::deleteList ( )
inline

Definition at line 99 of file ossimThinPlateSpline.h.

100  {
101  _nof_points = 0;
103  _AA.clear();
104  _Ainv.clear();
105  return _nof_points;
106  }
std::vector< double > _AA
vizGeorefInterType type
std::vector< double > _Ainv

◆ deletePoint()

int ossimThinPlateSpline::deletePoint ( const double  Px,
const double  Py 
)

Definition at line 128 of file ossimThinPlateSpline.cpp.

References _nof_points, _nof_vars, _tx, _ty, ossim::abs(), rhs, type, VIZ_GEOREF_SPLINE_POINT_WAS_DELETED, x, and y.

129 {
130  for ( int i = 0; i < _nof_points; i++ )
131  {
132  if ( ( ossim::abs(Px - x[i]) <= _tx ) && ( ossim::abs(Py - y[i]) <= _ty ) )
133  {
134  for ( int j = i; j < _nof_points - 1; j++ )
135  {
136  x[j] = x[j+1];
137  y[j] = y[j+1];
138  for ( int k = 0; k < _nof_vars; k++ )
139  rhs[k][j+3] = rhs[k][j+3+1];
140  }
141  _nof_points--;
143  return(1);
144  }
145  }
146  return(0);
147 }
std::vector< std::vector< double > > rhs
T abs(const T &value)
Definition: ossimCommon.h:138
vizGeorefInterType type
std::vector< double > y
std::vector< double > x

◆ getInterpolationType()

vizGeorefInterType ossimThinPlateSpline::getInterpolationType ( ) const
inline

Definition at line 95 of file ossimThinPlateSpline.h.

95  {
96  return type;
97  }
vizGeorefInterType type

◆ getNumberOfPoints()

int ossimThinPlateSpline::getNumberOfPoints ( ) const
inline

Definition at line 81 of file ossimThinPlateSpline.h.

82  {
83  return _nof_points;
84  }

◆ getPoint()

int ossimThinPlateSpline::getPoint ( const double  Px,
const double  Py,
double *  Pvars 
) const

Definition at line 309 of file ossimThinPlateSpline.cpp.

References _dx, _dy, _nof_points, _nof_vars, baseFunc(), coef, index, rhs, type, u, VIZ_GEOREF_SPLINE_FULL, VIZ_GEOREF_SPLINE_ONE_DIMENSIONAL, VIZ_GEOREF_SPLINE_ONE_POINT, VIZ_GEOREF_SPLINE_POINT_WAS_ADDED, VIZ_GEOREF_SPLINE_POINT_WAS_DELETED, VIZ_GEOREF_SPLINE_TWO_POINTS, VIZ_GEOREF_SPLINE_ZERO_POINTS, x, and y.

Referenced by ossimHistogram::fillInteriorEmptyBins().

310 {
311  int v, r;
312  double tmp, Pu;
313  double fact;
314  int leftP=0, rightP=0, found = 0;
315 
316  switch ( type )
317  {
319  for ( v = 0; v < _nof_vars; v++ )
320  vars[v] = 0.0;
321  break;
323  for ( v = 0; v < _nof_vars; v++ )
324  vars[v] = rhs[v][3];
325  break;
327  fact = _dx * ( Px - x[0] ) + _dy * ( Py - y[0] );
328  for ( v = 0; v < _nof_vars; v++ )
329  vars[v] = ( 1 - fact ) * rhs[v][3] + fact * rhs[v][4];
330  break;
332  Pu = _dx * ( Px - x[0] ) + _dy * ( Py - y[0] );
333  if ( Pu <= u[index[0]] )
334  {
335  leftP = index[0];
336  rightP = index[1];
337  }
338  else if ( Pu >= u[index[_nof_points-1]] )
339  {
340  leftP = index[_nof_points-2];
341  rightP = index[_nof_points-1];
342  }
343  else
344  {
345  for ( r = 1; !found && r < _nof_points; r++ )
346  {
347  leftP = index[r-1];
348  rightP = index[r];
349  if ( Pu >= u[leftP] && Pu <= u[rightP] )
350  found = 1;
351  }
352  }
353 
354  fact = ( Pu - u[leftP] ) / ( u[rightP] - u[leftP] );
355  for ( v = 0; v < _nof_vars; v++ )
356  vars[v] = ( 1.0 - fact ) * rhs[v][leftP+3] +
357  fact * rhs[v][rightP+3];
358  break;
360  for ( v = 0; v < _nof_vars; v++ )
361  vars[v] = coef[v][0] + coef[v][1] * Px + coef[v][2] * Py;
362 
363  for ( r = 0; r < _nof_points; r++ )
364  {
365  tmp = baseFunc( Px, Py, x[r], y[r] );
366  for ( v= 0; v < _nof_vars; v++ )
367  vars[v] += coef[v][r+3] * tmp;
368  }
369  break;
371  fprintf(stderr, " A point was added after the last solve\n");
372  fprintf(stderr, " NO interpolation - return values are zero\n");
373  for ( v = 0; v < _nof_vars; v++ )
374  vars[v] = 0.0;
375  return(0);
376  break;
378  fprintf(stderr, " A point was deleted after the last solve\n");
379  fprintf(stderr, " NO interpolation - return values are zero\n");
380  for ( v = 0; v < _nof_vars; v++ )
381  vars[v] = 0.0;
382  return(0);
383  break;
384  default :
385  return(0);
386  break;
387  }
388  return(1);
389 }
double baseFunc(const double x1, const double y1, const double x2, const double y2) const
std::vector< std::vector< double > > rhs
std::vector< std::vector< double > > coef
vizGeorefInterType type
std::vector< double > y
std::vector< int > index
std::vector< double > u
std::vector< double > x

◆ getToler()

void ossimThinPlateSpline::getToler ( double &  tx,
double &  ty 
) const
inline

Definition at line 90 of file ossimThinPlateSpline.h.

90  {
91  tx = _tx;
92  ty = _ty;
93  }

◆ getXy()

bool ossimThinPlateSpline::getXy ( int  index,
double &  x,
double &  y 
) const

Definition at line 109 of file ossimThinPlateSpline.cpp.

References _nof_points, index, x, and y.

110 {
111  bool ok;
112 
113  if ( index < _nof_points )
114  {
115  ok = true;
116  outX = x[index];
117  outY = y[index];
118  }
119  else
120  {
121  ok = false;
122  outX = outY = 0.0f;
123  }
124 
125  return(ok);
126 }
std::vector< double > y
std::vector< int > index
std::vector< double > x

◆ growPoints()

void ossimThinPlateSpline::growPoints ( )

Definition at line 57 of file ossimThinPlateSpline.cpp.

References _max_nof_points, _nof_vars, coef, index, rhs, u, unused, x, and y.

Referenced by addPoint().

59 {
60  int new_max = _max_nof_points*2 + 2 + 3;
61  int i;
62 
63  x.resize( new_max );
64  y.resize( new_max );
65  u.resize( new_max );
66  unused.resize( new_max );
67  index.resize( new_max );
68  for( i = 0; i < _nof_vars; i++ )
69  {
70  rhs[i].resize( new_max );
71  coef[i].resize( new_max );
72  }
73 
74  _max_nof_points = new_max - 3;
75 }
std::vector< int > unused
std::vector< std::vector< double > > rhs
std::vector< std::vector< double > > coef
std::vector< double > y
std::vector< int > index
std::vector< double > u
std::vector< double > x

◆ reset()

void ossimThinPlateSpline::reset ( void  )
inline

Definition at line 114 of file ossimThinPlateSpline.h.

◆ setToler()

void ossimThinPlateSpline::setToler ( double  tx,
double  ty 
)
inline

Definition at line 85 of file ossimThinPlateSpline.h.

85  {
86  _tx = tx;
87  _ty = ty;
88  }

◆ solve()

int ossimThinPlateSpline::solve ( void  )

Definition at line 149 of file ossimThinPlateSpline.cpp.

References _AA, _Ainv, _dx, _dy, _nof_eqs, _nof_points, A, baseFunc(), index, ossim::max(), ossim::min(), status, type, u, unused, VIZ_GEOREF_SPLINE_FULL, VIZ_GEOREF_SPLINE_ONE_DIMENSIONAL, VIZ_GEOREF_SPLINE_ONE_POINT, VIZ_GEOREF_SPLINE_TWO_POINTS, VIZ_GEOREF_SPLINE_ZERO_POINTS, x, and y.

Referenced by ossimHistogram::fillInteriorEmptyBins().

150 {
151  int r, c, v;
152  int p;
153 
154  // No points at all
155  if ( _nof_points < 1 )
156  {
158  return(0);
159  }
160 
161  // Only one point
162  if ( _nof_points == 1 )
163  {
165  return(1);
166  }
167  // Just 2 points - it is necessarily 1D case
168  if ( _nof_points == 2 )
169  {
170  _dx = x[1] - x[0];
171  _dy = y[1] - y[0];
172  double fact = 1.0 / ( _dx * _dx + _dy * _dy );
173  _dx *= fact;
174  _dy *= fact;
175 
177  return(2);
178  }
179 
180  // More than 2 points - first we have to check if it is 1D or 2D case
181 
182  double xmax = x[0], xmin = x[0], ymax = y[0], ymin = y[0];
183  double delx, dely;
184  double xx, yy;
185  double sumx = 0.0f, sumy= 0.0f, sumx2 = 0.0f, sumy2 = 0.0f, sumxy = 0.0f;
186  double SSxx, SSyy, SSxy;
187 
188  for ( p = 0; p < _nof_points; p++ )
189  {
190  xx = x[p];
191  yy = y[p];
192 
193  xmax = ossim::max( xmax, xx );
194  xmin = ossim::min( xmin, xx );
195  ymax = ossim::max( ymax, yy );
196  ymin = ossim::min( ymin, yy );
197 
198  sumx += xx;
199  sumx2 += xx * xx;
200  sumy += yy;
201  sumy2 += yy * yy;
202  sumxy += xx * yy;
203  }
204  delx = xmax - xmin;
205  dely = ymax - ymin;
206 
207  SSxx = sumx2 - sumx * sumx / _nof_points;
208  SSyy = sumy2 - sumy * sumy / _nof_points;
209  SSxy = sumxy - sumx * sumy / _nof_points;
210 
211  if ( delx < 0.001 * dely || dely < 0.001 * delx ||
212  fabs ( SSxy * SSxy / ( SSxx * SSyy ) ) > 0.99 )
213  {
214  int p1;
215 
217 
218  _dx = _nof_points * sumx2 - sumx * sumx;
219  _dy = _nof_points * sumy2 - sumy * sumy;
220  double fact = 1.0 / sqrt( _dx * _dx + _dy * _dy );
221  _dx *= fact;
222  _dy *= fact;
223 
224  for ( p = 0; p < _nof_points; p++ )
225  {
226  double dxp = x[p] - x[0];
227  double dyp = y[p] - y[0];
228  u[p] = _dx * dxp + _dy * dyp;
229  unused[p] = 1;
230  }
231 
232  for ( p = 0; p < _nof_points; p++ )
233  {
234  int min_index = -1;
235  double min_u = 0;
236  for ( p1 = 0; p1 < _nof_points; p1++ )
237  {
238  if ( unused[p1] )
239  {
240  if ( min_index < 0 || u[p1] < min_u )
241  {
242  min_index = p1;
243  min_u = u[p1];
244  }
245  }
246  }
247  index[p] = min_index;
248  unused[min_index] = 0;
249  }
250 
251  return(3);
252  }
253 
255 
256  _nof_eqs = _nof_points + 3;
257 
258  _AA.resize( _nof_eqs * _nof_eqs );
259  _Ainv.resize(_nof_eqs * _nof_eqs );
260 
261  // Calc the values of the matrix A
262  for ( r = 0; r < 3; r++ )
263  for ( c = 0; c < 3; c++ )
264  A(r,c) = 0.0;
265 
266  for ( c = 0; c < _nof_points; c++ )
267  {
268  A(0,c+3) = 1.0;
269  A(1,c+3) = x[c];
270  A(2,c+3) = y[c];
271 
272  A(c+3,0) = 1.0;
273  A(c+3,1) = x[c];
274  A(c+3,2) = y[c];
275  }
276 
277  for ( r = 0; r < _nof_points; r++ )
278  for ( c = r; c < _nof_points; c++ )
279  {
280  A(r+3,c+3) = baseFunc( x[r], y[r], x[c], y[c] );
281  if ( r != c )
282  A(c+3,r+3 ) = A(r+3,c+3);
283  }
284 
285 
286  // Invert the matrix
287  int status = matrixInvert( _nof_eqs, &_AA.front(), &_Ainv.front() );
288 
289  if ( !status )
290  {
292  << " There is a problem to invert the interpolation matrix\n"
293  << std::endl;
294  return 0;
295  }
296 
297  // calc the coefs
298  for ( v = 0; v < _nof_vars; v++ )
299  for ( r = 0; r < _nof_eqs; r++ )
300  {
301  coef[v][r] = 0.0;
302  for ( c = 0; c < _nof_eqs; c++ )
303  coef[v][r] += Ainv(r,c) * rhs[v][c];
304  }
305 
306  return(4);
307 }
double baseFunc(const double x1, const double y1, const double x2, const double y2) const
std::vector< int > unused
T max(T a, T b)
Definition: ossimCommon.h:236
std::vector< std::vector< double > > rhs
std::vector< std::vector< double > > coef
#define Ainv(r, c)
#define A(r, c)
std::vector< double > _AA
vizGeorefInterType type
std::vector< double > y
T min(T a, T b)
Definition: ossimCommon.h:203
std::vector< int > index
return status
std::vector< double > _Ainv
std::vector< double > u
std::vector< double > x
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

Member Data Documentation

◆ _AA

std::vector<double> ossimThinPlateSpline::_AA
private

Definition at line 142 of file ossimThinPlateSpline.h.

Referenced by solve().

◆ _Ainv

std::vector<double> ossimThinPlateSpline::_Ainv
private

Definition at line 142 of file ossimThinPlateSpline.h.

Referenced by solve().

◆ _dx

double ossimThinPlateSpline::_dx
private

Definition at line 130 of file ossimThinPlateSpline.h.

Referenced by getPoint(), and solve().

◆ _dy

double ossimThinPlateSpline::_dy
private

Definition at line 130 of file ossimThinPlateSpline.h.

Referenced by getPoint(), and solve().

◆ _max_nof_points

int ossimThinPlateSpline::_max_nof_points
private

Definition at line 125 of file ossimThinPlateSpline.h.

Referenced by addPoint(), and growPoints().

◆ _nof_eqs

int ossimThinPlateSpline::_nof_eqs
private

Definition at line 126 of file ossimThinPlateSpline.h.

Referenced by solve().

◆ _nof_points

int ossimThinPlateSpline::_nof_points
private

Definition at line 124 of file ossimThinPlateSpline.h.

Referenced by addPoint(), changePoint(), deletePoint(), getPoint(), getXy(), and solve().

◆ _nof_vars

int ossimThinPlateSpline::_nof_vars
private

Definition at line 123 of file ossimThinPlateSpline.h.

Referenced by addPoint(), changePoint(), deletePoint(), getPoint(), and growPoints().

◆ _ta

double ossimThinPlateSpline::_ta
private

Definition at line 129 of file ossimThinPlateSpline.h.

◆ _tx

double ossimThinPlateSpline::_tx
private

Definition at line 128 of file ossimThinPlateSpline.h.

Referenced by deletePoint().

◆ _ty

double ossimThinPlateSpline::_ty
private

Definition at line 128 of file ossimThinPlateSpline.h.

Referenced by deletePoint().

◆ coef

std::vector<std::vector<double> > ossimThinPlateSpline::coef
private

Definition at line 136 of file ossimThinPlateSpline.h.

Referenced by getPoint(), and growPoints().

◆ index

std::vector<int> ossimThinPlateSpline::index
private

Definition at line 140 of file ossimThinPlateSpline.h.

Referenced by changePoint(), getPoint(), getXy(), growPoints(), and solve().

◆ rhs

std::vector<std::vector<double> > ossimThinPlateSpline::rhs
private

Definition at line 135 of file ossimThinPlateSpline.h.

Referenced by addPoint(), changePoint(), deletePoint(), getPoint(), and growPoints().

◆ type

vizGeorefInterType ossimThinPlateSpline::type
private

Definition at line 121 of file ossimThinPlateSpline.h.

Referenced by addPoint(), deletePoint(), getPoint(), and solve().

◆ u

std::vector<double> ossimThinPlateSpline::u
private

Definition at line 138 of file ossimThinPlateSpline.h.

Referenced by getPoint(), growPoints(), and solve().

◆ unused

std::vector<int> ossimThinPlateSpline::unused
private

Definition at line 139 of file ossimThinPlateSpline.h.

Referenced by growPoints(), and solve().

◆ x

std::vector<double> ossimThinPlateSpline::x
private

◆ y

std::vector<double> ossimThinPlateSpline::y
private

The documentation for this class was generated from the following files: