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

#include <ossimWLSBundleSolution.h>

Public Member Functions

 ossimWLSBundleSolution ()
 Constructor. More...
 
bool run (ossimAdjSolutionAttributes *solAttributes)
 Run solution. More...
 
 ~ossimWLSBundleSolution ()
 Destructor. More...
 

Protected Member Functions

bool solveSystem (double *d, double *c, double *delta, int jb)
 
bool recurFwd (double *d, double *c, std::vector< double > &rc, std::vector< int > &nz, int jb)
 
bool recurBack (double *d, int jb)
 
void trimv (double *pc, double *h, int pcIndex, int hIndex, int mr, std::vector< double > &sum)
 
void moveAndNegate (std::vector< double > &from, double *to, int indexFrom, int indexTo, int nElements)
 

Protected Attributes

bool theSolValid
 

Detailed Description

Definition at line 21 of file ossimWLSBundleSolution.h.

Constructor & Destructor Documentation

◆ ossimWLSBundleSolution()

ossimWLSBundleSolution::ossimWLSBundleSolution ( )

Constructor.

Definition at line 30 of file ossimWLSBundleSolution.cpp.

31 {
32 }

◆ ~ossimWLSBundleSolution()

ossimWLSBundleSolution::~ossimWLSBundleSolution ( )

Destructor.

Definition at line 41 of file ossimWLSBundleSolution.cpp.

42 {
43  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG)
44  << "DEBUG: ~ossimWLSBundleSolution(): returning..." << std::endl;
45 }
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

Member Function Documentation

◆ moveAndNegate()

void ossimWLSBundleSolution::moveAndNegate ( std::vector< double > &  from,
double *  to,
int  indexFrom,
int  indexTo,
int  nElements 
)
protected

Definition at line 444 of file ossimWLSBundleSolution.cpp.

Referenced by recurBack().

445 {
446  for (int i=indexFrom,j=indexTo; i<=indexFrom+nElements-1; i++,j++)
447  to[j] = -from[i];
448 }

◆ recurBack()

bool ossimWLSBundleSolution::recurBack ( double *  d,
int  jb 
)
protected

Definition at line 371 of file ossimWLSBundleSolution.cpp.

References moveAndNegate(), and trimv().

372 {
373  int jcol,iq,jcol1,nsize,i,j;
374  double sum;
375  std::vector<double> tmp(rank+1);//workspace vector
376 
377  if(d[1]==0.0)
378  {
379  return false;
380  }
381  else
382  d[1] = 1.0/d[1];
383 
384  for (jcol=2; jcol<=rank; jcol++)
385  {
386  nsize = jcol*(jcol+1)/2;
387  iq = nsize-jcol+1;
388  jcol1 = jcol-1;
389  trimv(d,d,1,iq,jcol1,tmp);
390  sum = 0.0;
391  for (i=iq,j=1; i<=iq+jcol1-1; i++,j++)
392  {
393  if (d[i] != 0.0)
394  sum += d[i]*tmp[j];
395  }
396  moveAndNegate(tmp, d, 1, iq, jcol1);
397  d[nsize] += sum;
398  }
399 
400  tmp.clear();
401 
402  return true;
403 }
void trimv(double *pc, double *h, int pcIndex, int hIndex, int mr, std::vector< double > &sum)
void moveAndNegate(std::vector< double > &from, double *to, int indexFrom, int indexTo, int nElements)

◆ recurFwd()

bool ossimWLSBundleSolution::recurFwd ( double *  d,
double *  c,
std::vector< double > &  rc,
std::vector< int > &  nz,
int  jb 
)
protected

Definition at line 306 of file ossimWLSBundleSolution.cpp.

Referenced by solveSystem().

307 {
308  int i,j,k,jj,jk,ik,nsize,jcol,kcol,ksize,nbr,ncol;
309  double r,q,diag;
310 
311  nsize = rank*(rank+1)/2;
312 
313  for (jcol=rank; jcol>=2; --jcol)
314  {
315  diag = d[nsize];
316 
317  if(diag!=0.0)
318  {
319  r = 1.0/diag;
320  tmp[jcol] = r*c[jcol];
321  kcol = jcol-1;
322  k = nsize-jcol;
323  ksize = k;
324  nbr = 0;
325  for (i=1;i<=kcol;++i)
326  {
327  k++;
328  if(d[k]!=0.0)
329  {
330  ++nbr;
331  nz[nbr] = k;
332  c[i] -= d[k]*tmp[jcol];
333  }
334  }
335 
336  if(nbr!=0.0)
337  {
338  for (jk=nbr; jk>=1; --jk)
339  {
340  j = nz[jk];
341  q = r*d[j];
342  ncol = j-ksize;
343  jj = ncol*(ncol-1)/2 - ksize;
344  for (ik=jk;ik>=1;--ik)
345  {
346  i = nz[ik];
347  k = jj+i;
348  d[k] -= d[i]*q;
349  }
350  d[j] = q;
351  }
352  }
353  d[nsize] = r;
354  nsize -= jcol;
355  }
356  else
357  {
358  return false;
359  }
360  }
361 
362  return true;
363 }

◆ run()

bool ossimWLSBundleSolution::run ( ossimAdjSolutionAttributes solAttributes)

Run solution.

Definition at line 54 of file ossimWLSBundleSolution.cpp.

55 {
56  if (traceDebug())
57  {
59  << "\nossimWLSBundleSolution::run DEBUG:" << std::endl;
60  }
61 
62  theSolValid = false;
63 
64 
65  // Initialize traits
66  int numObs = solAttributes->numObjObs();
67  int numImages = solAttributes->numImages();
68 
69  int Nrank = solAttributes->theImgNumparXref[0];
70  //int NdIndex[numImages];
71  std::vector<int> NdIndex(numImages);
72  NdIndex[0] = 1;
73  for (int n=1; n<numImages; ++n)
74  {
75  NdIndex[n] = NdIndex[n-1] + solAttributes->theImgNumparXref[n-1];
76  Nrank += solAttributes->theImgNumparXref[n];
77  }
78 
79  // N-dot rank before adding ground partition
80  int Nd_rank = Nrank;
81 
82  // Full rank
83  Nrank += numObs*3;
84 
85  if (traceDebug())
86  {
88  <<"\n Bundle........"
89  <<"\n numObs = "<<numObs
90  <<"\n numImages = "<<numImages
91  <<"\n Nd_rank = "<<Nd_rank
92  <<"\n Nrank = "<<Nrank;
93  for (int n=0; n<numImages; ++n)
95  <<"\n NdIndex = "<<n<<" "<<NdIndex[n];
97  }
98 
99 
100  // NORMAL EQUATION ARRAYS
101  NEWMAT::UpperTriangularMatrix N(Nrank);//coefficient matrix
102  NEWMAT::ColumnVector C(Nrank); // normal constant vector
103  NEWMAT::ColumnVector D(Nrank); // solution vector
104 
105  // IMAGE PARTITION ARRAYS (for image having "p" parameters)
106  NEWMAT::Matrix Bd; // [B-dot] matrix (2Xp)
107  NEWMAT::Matrix Bdt_w; // [B-dot(t) * w] matrix (2Xp)
108  NEWMAT::UpperTriangularMatrix Nd; // [N-dot] matrix (pXp)
109  NEWMAT::Matrix Cd; // [C-dot] matrix (pX1)
110  NEWMAT::Matrix Nb; // [N-bar] matrix (pX3)
111 
112  NEWMAT::ColumnVector eps(2); // image pt residual matrix (2X1)
113  NEWMAT::Matrix w(2,2); // image pt weight matrix (2X2)
114 
115  // GROUND PARTITION ARRAYS
116  NEWMAT::Matrix Bdd(2,3); // [B-dbl-dot] matrix (2X3)
117  NEWMAT::Matrix Bddt_w(2,3); // [B-dbl-dot(t) * w] matrix (2X3)
118  NEWMAT::UpperTriangularMatrix Ndd(3); // [N-dbl-dot] matrix (3X3)
119  NEWMAT::ColumnVector Cdd(3); // [C-dbl_dot] matrix (3X1)
120  NEWMAT::Matrix Wdd(3,3); // [W-dbl-dot] matrix (3X3)
121 
122 
123  // initialize N and C partions with weights
124  N = 0.0;
125  C = 0.0;
126 
127  for (int img=0; img<numImages; img++)
128  {
129  int size = solAttributes->theImgNumparXref[img];
130  int rcBeg = NdIndex[img];
131  int rcEnd = rcBeg+size-1;
132 
133  // TODO.... theAdjParCov is not stacked because npar/image may vary.
134  // However, it's not treated as a full matrix in the solution due to
135  // to current use of simple partitioning, assuming no correlation.
136  NEWMAT::Matrix Wd(size,size);
137  Wd = solAttributes->theAdjParCov.SubMatrix(rcBeg,rcEnd,rcBeg,rcEnd).i();
138 
139  NEWMAT::ColumnVector Ed(size);
140  Ed = solAttributes->theTotalCorrections.Rows(rcBeg,rcEnd);
141 
142  N.SymSubMatrix(rcBeg,rcEnd) << Wd;
143  C.Rows(rcBeg,rcEnd) = Wd * Ed;
144  }
145 
146  //*******************
147  // object point loop
148  //*******************
149  int cMeas = 1;
150  int cImgIdx = 1;
151  int cObjIdx = 1;
152 
153  for (int obs=0; obs<numObs; obs++)
154  {
155  // Initialize Ndd & Cdd partitions with weight matrix
156  int idx = obs*3 + 1;
157  Wdd = solAttributes->theObjectPtCov.Rows(idx,idx+2).i();
158  int NddIdx = Nd_rank + idx;
159  N.SymSubMatrix(NddIdx, NddIdx+2) << Wdd;
160 
161  NEWMAT::ColumnVector Edd(3);
162  Edd = solAttributes->theTotalCorrections.Rows(NddIdx, NddIdx+2);
163  C.Rows(NddIdx, NddIdx+2) = Wdd * Edd;
164 
165 
166  //*******************************************
167  // image point loop for current object point
168  //*******************************************
169  int nMeasOnObs = (int) solAttributes->theObjImgXref.count(obs);
170  ObjImgMapIterPair_t imgRng;
171  imgRng = solAttributes->theObjImgXref.equal_range(obs);
172  ObjImgMapIter_t currImg = imgRng.first;
173 
174  if (traceDebug())
175  {
177  <<"\n=========obs, nMeasOnObs ========="<<obs<<" "<<nMeasOnObs;
178  }
179 
180  for (int meas=0; meas<nMeasOnObs; meas++)
181  {
182 
183  // object point partials
184  Bdd = solAttributes->theObjPartials.Rows(cObjIdx,cObjIdx+2).t();
185  cObjIdx += 3;
186  if (traceDebug())
187  {
188  ossimNotify(ossimNotifyLevel_DEBUG)<<"\n cObjIdx "<<cObjIdx;
189  }
190 
191  //image parameter partials
192  int cNumPar = solAttributes->theImgNumparXref[currImg->second];
193  Bd = solAttributes->theParPartials.Rows(cImgIdx,cImgIdx+cNumPar-1).t();
194  if (traceDebug())
195  {
196  ossimNotify(ossimNotifyLevel_DEBUG)<<"\n cImgIdx,cNumPar "<<cImgIdx<<" "<<cNumPar;
197  }
198 
199  //***********************************************************
200  // form all image parameter & object pt parameter partitions
201  //***********************************************************
202  int NdIdx = NdIndex[currImg->second];
203  if (traceDebug())
204  {
205  ossimNotify(ossimNotifyLevel_DEBUG)<<"\n NdIdx,NddIdx "<<NdIdx<<" "<<NddIdx;
206  }
207 
208  // residuals
209  eps = solAttributes->theMeasResiduals.Row(cMeas).t();
210  if (traceDebug())
211  {
212  ossimNotify(ossimNotifyLevel_DEBUG)<<"\n resid ("<<eps(1)<<","<<eps(2)<<")";
213  }
214 
215  // compute N-dot & C-dot contributions
216  int start = (cMeas-1)*2 + 1;
217  w = solAttributes->theImagePtCov.Rows(start,start+1).i();
218  Bdt_w << Bd.t() * w;
219  Nd << Bdt_w * Bd;
220  Cd << Bdt_w * eps;
221 
222  // compute N-dd & C-dd contributions
223  Bddt_w << Bdd.t() * w;
224  Ndd << Bddt_w * Bdd;
225  Cdd << Bddt_w * eps;
226 
227  // compute N-bar for PT "obs" & IMAGE "meas"
228  Nb << Bdt_w * Bdd;
229 
230  // SUM Nd into N
231  N.SymSubMatrix(NdIdx,NdIdx+cNumPar-1) += Nd;
232 
233  // SUM Ndd into N
234  N.SymSubMatrix(NddIdx,NddIdx+2) += Ndd;
235 
236  // INSERT Nb into N
237  N.SubMatrix(NdIdx,NdIdx+cNumPar-1,NddIdx,NddIdx+2) = Nb;
238 
239  // SUM Cd into C
240  C.Rows(NdIdx,NdIdx+cNumPar-1) += Cd;
241 
242  // SUM Cdd into C
243  C.Rows(NddIdx,NddIdx+2) += Cdd;
244 
245  // Increment index counters
246  cImgIdx += cNumPar;
247  cMeas++;
248  currImg++;
249 
250  }
251  //**********************
252  // END image point loop
253  //**********************
254 
255  }
256  //***********************
257  // END object point loop
258  //***********************
259 
260 
261  //******************************
262  // solve normal equation system
263  //******************************
264  NEWMAT::LowerTriangularMatrix Nl = N.t();
265 
266  // Solve
267  // Note: solveSystem uses 1-based indexing
268  if (!solveSystem(Nl.Store()-1, C.Store()-1, D.Store()-1, Nrank))
269  {
270  theSolValid = false;
271  }
272  else
273  {
274  theSolValid = true;
275 
276  //******************
277  // load corrections
278  //******************
279  solAttributes->theLastCorrections = -D;
280  solAttributes->theTotalCorrections -= D;
281 
282 
283  //************************
284  // load covariance matrix
285  // Note: recurBack uses 1-based indexing
286  //************************
287  if (recurBack(Nl.Store()-1, Nrank))
288  {
289  solAttributes->theFullCovMatrix = Nl.t();
290  }
291  else
292  {
293  theSolValid = false;
294  }
295  }
296 
297  return theSolValid;
298 }
NEWMAT::UpperTriangularMatrix theFullCovMatrix
bool recurBack(double *d, int jb)
yy_size_t size
os2<< "> n<< " > nendobj n
bool solveSystem(double *d, double *c, double *delta, int jb)
std::pair< ObjImgMapIter_t, ObjImgMapIter_t > ObjImgMapIterPair_t
ObjImgMap_t::iterator ObjImgMapIter_t
NEWMAT::ColumnVector theTotalCorrections
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ solveSystem()

bool ossimWLSBundleSolution::solveSystem ( double *  d,
double *  c,
double *  delta,
int  jb 
)
protected

Definition at line 460 of file ossimWLSBundleSolution.cpp.

References recurFwd().

461 {
462  std::vector<int> nz(rank+1); //indexing vector
463  int i,j,jcol1,k;
464  std::vector<double> tmp(rank+1);//workspace vector
465  double sum;
466 
467 
468  if (!recurFwd(d, c, tmp, nz, rank))
469  return false;
470  else if (d[1]==0.0)
471  {
472  return false;
473  }
474  else
475  delta[1] = c[1]/d[1];
476 
477  for (j=2; j<=rank; j++)
478  {
479  jcol1 = j-1;
480  k = j*(j-1)/2;
481  sum = 0.0;
482  for (i=1; i<=jcol1; i++)
483  {
484  k++;
485  sum += d[k]*delta[i];
486  }
487  delta[j] = tmp[j]-sum;
488  }
489 
490  nz.clear();
491  tmp.clear();
492 
493  return true;
494 }
bool recurFwd(double *d, double *c, std::vector< double > &rc, std::vector< int > &nz, int jb)

◆ trimv()

void ossimWLSBundleSolution::trimv ( double *  pc,
double *  h,
int  pcIndex,
int  hIndex,
int  mr,
std::vector< double > &  sum 
)
protected

Definition at line 410 of file ossimWLSBundleSolution.cpp.

Referenced by recurBack().

411 {
412  for (int k=1; k<=mr; k++)
413  sum[k]=0.0;
414 
415  for (int j=1; j<=mr; j++)
416  {
417  if (h[j+hIndex-1]!=0.0)
418  {
419  int k = j*(j-1)/2+1;
420  int jadd = j;
421  double hj = h[j+hIndex-1];
422  for (int i=1; i<=mr; i++)
423  {
424  sum[i] += pc[k+pcIndex-1]*hj;
425  if (i<j)
426  k++;
427  else
428  {
429  k += jadd;
430  jadd++;
431  }
432  }
433  }
434  }
435 }

Member Data Documentation

◆ theSolValid

bool ossimWLSBundleSolution::theSolValid
protected

Definition at line 42 of file ossimWLSBundleSolution.h.


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