OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimObservationSet.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: David Hicks
6 //
7 // Description: Storage class for observations.
8 //----------------------------------------------------------------------------
9 #include <iostream>
10 #include <iomanip>
11 
13 #include <ossim/base/ossimNotify.h>
14 #include <ossim/base/ossimTrace.h>
16 
17 static ossimTrace traceExec ("ossimObservationSet:exec");
18 static ossimTrace traceDebug ("ossimObservationSet:debug");
19 
20 
21 
23 theNumAdjPar(0),
24 theNumMeas(0),
25 theNumPartials(0)
26 {
27  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG)
28  << "DEBUG: ossimObservationSet(): returning..." << std::endl;
29 }
30 
31 
33 {
34  for (ossim_uint32 i=0; i<theImageHandlers.size(); ++i)
35  theImageHandlers[i] = 0;
36  // for (int i=0; i<theObs.size(); ++i)
37  // theObs[i] = 0;
38 
39  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG)
40  << "DEBUG: ~ossimObservationSet(): returning..." << std::endl;
41 }
42 
43 
44 bool
46 {
47  if (traceDebug())
48  {
50  <<"\n ossimObservationSet::addObservation: "<<obs->ID()<<endl;
51  }
52 
53  theObs.push_back(obs);
54  theNumMeas += obs->numMeas();
55 
56 
57  // Update image list
58  for (ossim_uint32 i=0; i<obs->numImages(); ++i)
59  {
60  if (traceDebug())
61  {
62  ossimNotify(ossimNotifyLevel_DEBUG)<<" i="<<i<<endl;
63  }
64 
65  bool found = false;
66 
67  // Check for image already in list
68  for (ossim_uint32 j=0; j<theImageFiles.size(); ++j)
69  {
70  if (theImageFiles[j] == obs->imageFile(i))
71  {
72  found = true;
73  theImageIndex.push_back(j);
74  int nAdjPar = obs->numPars(i);
75  theNumPartials += nAdjPar;
76  }
77  }
78 
79  // If not found yet, add to image list
80  if (!found)
81  {
82  theImageFiles.push_back(obs->imageFile(i));
83 
84  // Geometry
87  theImageHandlers.push_back(ih);
88 
89  theImageIndex.push_back( (int)(theImageHandlers.size()-1) );
90 
91  // Handle ossimAdjustableParameterInterface
92  ossimAdjustableParameterInterface* adjParIface =
94  if (!adjParIface)
95  {
96  return false;
97  }
98  else
99  {
100  if (traceDebug())
101  {
102  ossimNotify(ossimNotifyLevel_DEBUG)<<" Found new image... "<<i<<endl;
103  }
104  int nAdjPar = adjParIface->getNumberOfAdjustableParameters();
105  theNumAdjPar += nAdjPar;
106  theNumPartials += nAdjPar;
107  theNumAdjParams.push_back(nAdjPar);
108  }
109  }
110  }
111 
112  if (traceDebug())
113  {
114  ossimNotify(ossimNotifyLevel_DEBUG)<<" theNumAdjPar = "<<theNumAdjPar<<endl;
115  ossimNotify(ossimNotifyLevel_DEBUG)<<" theNumPartials = "<<theNumPartials<<endl;
116  }
117 
118  return true;
119 }
120 
121 
123 {
124  return theImageHandlers[index]->getImageGeometry().get();
125 }
126 
127 
129 {
130  theImageHandlers[index]->setImageGeometry(geom);
131 }
132 
133 
134 bool ossimObservationSet::evaluate(NEWMAT::Matrix& measResiduals,
135  NEWMAT::Matrix& objPartials,
136  NEWMAT::Matrix& parPartials)
137 {
138 
139  // Dimension output matrices
140  measResiduals = NEWMAT::Matrix(numMeas(), 2);
141  objPartials = NEWMAT::Matrix(numMeas()*3, 2);
142  parPartials = NEWMAT::Matrix(theNumPartials, 2);
143 
144  int img = 1;
145  int cParIndex = 1;
146  int cObjIndex = 1;
147  for (ossim_uint32 cObs=0; cObs<numObs(); ++cObs)
148  {
149  int numMeasPerObs = theObs[cObs]->numMeas();
150  if (traceDebug())
151  {
152  ossimNotify(ossimNotifyLevel_DEBUG)<<"\n cObs= "<<cObs;
153  }
154 
155  for (int cImg=0; cImg<numMeasPerObs; ++cImg)
156  {
157  NEWMAT::Matrix cResid(1, 2);
158  theObs[cObs]->getResiduals(cImg, cResid);
159  if (traceDebug())
160  {
162  <<"\n cImg, img, cObjIndex, cParIndex, cResid: "
163  <<cImg<<" "<<img<<" "<<cObjIndex<<" "<<cParIndex<<" "<<cResid;
164  }
165  measResiduals.Row(img) = cResid;
166  img++;
167 
168  NEWMAT::Matrix cObjPar(3, 2);
169  theObs[cObs]->getObjSpacePartials(cImg, cObjPar);
170  objPartials.SubMatrix(cObjIndex,cObjIndex+2,1,2) << cObjPar;
171  cObjIndex += 3;
172 
173  int numPar = theObs[cObs]->numPars(cImg);
174  NEWMAT::Matrix cParamPar(numPar, 2);
175  theObs[cObs]->getParameterPartials(cImg, cParamPar);
176  parPartials.SubMatrix(cParIndex,cParIndex+numPar-1,1,2) << cParamPar;
177  cParIndex += numPar;
178  }
179  }
180 
181  return true;
182 }
183 
184 
186 {
187  int idx = 0;
188 
189  os<<"\nImages:\n";
190  ossim_uint32 spaces = 0;
191  for (ossim_uint32 i=0; i<numImages(); ++i)
192  {
193  if (theImageFiles[i].size() > spaces)
194  spaces = (ossim_uint32)theImageFiles[i].size();
195  }
196  for (ossim_uint32 i=0; i<numImages(); ++i)
197  {
198  int nAdj = theNumAdjParams[i];
199  os << " "<<i+1<<": " << setw(spaces) << theImageFiles[i] << " nPar: "<< setw(2) << nAdj <<endl;
200  }
201 
202  os<<"\nObservations:";
203  for (ossim_uint32 cObs=0; cObs<numObs(); ++cObs)
204  {
205  os << "\n " << theObs[cObs]->ID();
206  if (ossim::isnan(theObs[cObs]->getScore()) == false)
207  {
208  os << std::setiosflags(std::ios::fixed) << std::setprecision(2);
209  os << "\t" << theObs[cObs]->getScore();
210  }
211  else
212  {
213  os << "\t" << "nan";
214  }
215  os << "\t";
216  theObs[cObs]->getGroundPoint().print(os);
217 
218  int numMeasPerObs = theObs[cObs]->numMeas();
219  for (int cImg=0; cImg<numMeasPerObs; ++cImg)
220  {
221  os << "\n\t\t" << theImageIndex[idx]+1;
222  os << "\t";
223  theObs[cObs]->getMeasurement(cImg).print(os,1);
224  idx++;
225  }
226  }
227  return os;
228 }
std::ostream & print(std::ostream &os) const
text output : header + tab separated tie points
virtual ossimImageHandler * open(const ossimFilename &fileName, bool trySuffixFirst=true, bool openOverview=true) const
open that takes a filename.
ossimImageGeometry * getImageGeom(const int index)
ossim_uint32 numImages() const
ossim_uint32 numObs() const
ossim_uint32 numMeas() const
std::vector< int > theNumAdjParams
std::vector< ossimRefPtr< ossimPointObservation > > theObs
virtual ossimAdjustableParameterInterface * getAdjustableParameterInterface()
std::vector< int > theImageIndex
yy_size_t size
unsigned int ossim_uint32
std::vector< ossimRefPtr< ossimImageHandler > > theImageHandlers
int numPars(const int index) const
Container class that holds both 2D transform and 3D projection information for an image Only one inst...
unsigned int numImages() const
ossimFilename imageFile(const int index) const
void setImageGeom(const int index, ossimImageGeometry *geom)
unsigned int numMeas() const
static ossimImageHandlerRegistry * instance()
bool addObservation(ossimRefPtr< ossimPointObservation > obs)
operations
ossimString ID() const
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
std::vector< ossimFilename > theImageFiles
ossimImageGeometry * getImageGeom(const int index)
bool evaluate(NEWMAT::Matrix &measResiduals, NEWMAT::Matrix &objPartials, NEWMAT::Matrix &parPartials)
standard evaluation [1] measResiduals: [x,y] residuals (numMeas X 2) [2] objPartials: object point pa...
bool isnan(const float &v)
isnan Test for floating point Not A Number (NAN) value.
Definition: ossimCommon.h:91