OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimPointObservation.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: Class container for multi-ray point observation.
8 //----------------------------------------------------------------------------
9 
11 #include <ossim/base/ossimString.h>
12 #include <ossim/base/ossimNotify.h>
13 #include <ossim/base/ossimTrace.h>
16 #include <iostream>
17 #include <iomanip>
18 
19 
20 static ossimTrace traceExec ("ossimPointObservation:exec");
21 static ossimTrace traceDebug ("ossimPointObservation:debug");
22 
23 
25  theID(""),
26  theScore(0.0)
27 {
28  thePt.makeNan();
29  for (int i=0; i<3; ++i) theObsSigmas[i] = 1000.0;
30 }
31 
33  theID(anID),
34  theScore(0.0)
35 {
36  thePt.makeNan();
37  for (int i=0; i<3; ++i) theObsSigmas[i] = 1000.0;
38 }
39 
41  const ossimString& anID,
42  const ossimColumnVector3d& latLonHgtSigmas) :
43  thePt(aPt),
44  theID(anID),
45  theScore(0.0)
46 {
47  for (int i=0; i<3; ++i) theObsSigmas[i] = latLonHgtSigmas[i];
48 }
49 
51  thePt(tpt.thePt),
52  theID(tpt.theID),
53  theScore(tpt.theScore)
54 {
55  for (int i=0; i<3; ++i) theObsSigmas[i] = tpt.theObsSigmas[i];
57  theMeas = tpt.theMeas;
60  theNumPars = tpt.theNumPars;
61 }
62 
63 
65 {
66  reset();
67 
68  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG)
69  << "DEBUG: ~ossimPointObservation(): returning..." << std::endl;
70 }
71 
72 
74 {
75  thePt.makeNan();
76  theID = "";
77  for (int i=0; i<3; ++i)
78  theObsSigmas[i] = 0.0;
79  theScore = 0.0;
80 
81  for (ossim_uint32 i=0; i<theImageHandlers.size(); ++i)
82  theImageHandlers[i] = 0;
83  theMeas.clear();
84  theMeasSigmas.clear();
85  theImageFiles.clear();
86  theNumPars.clear();
87  theImageHandlers.clear();
88 }
89 
90 
92  const double& y,
93  const std::string& imgFile,
94  const ossimDpt& measSigma)
95 {
96  ossimDpt meas(x, y);
97  addMeasurement(meas, imgFile, measSigma);
98 }
99 
100 
102  const ossimFilename& imgFile,
103  const ossimDpt& measSigma)
104 {
105  // Image handler
108  if ( ih.valid() )
109  {
110  theImageFiles.push_back(imgFile);
111  theImageHandlers.push_back(ih);
112 
113  // Image measurements & sigmas
114  theMeas.push_back(meas);
115  theMeasSigmas.push_back(measSigma);
116 
117  // Number of parameters
118  ossimAdjustableParameterInterface* adjParInterface =
120  theNumPars.push_back(adjParInterface->getNumberOfAdjustableParameters());
121  }
122 }
123 
124 
126 {
127  return theImageHandlers[index]->getImageGeometry().get();
128 }
129 
130 
132 {
133  theImageHandlers[index]->setImageGeometry(imgGeom);
134 }
135 
136 
137 void ossimPointObservation::getMeasurement(const int index, NEWMAT::Matrix& meas)const
138 {
139  meas = NEWMAT::Matrix(1, 2);
140  meas[0][0] = theMeas[index].x;
141  meas[0][1] = theMeas[index].y;
142 }
143 
144 
145 void ossimPointObservation::getMeasCov(const int index, NEWMAT::Matrix& cov)const
146 {
147  cov = NEWMAT::Matrix(2,2);
148  cov = 0.0;
149 
150  cov(1,1) = theMeasSigmas[index].x*theMeasSigmas[index].x;
151  cov(2,2) = theMeasSigmas[index].y*theMeasSigmas[index].y;
152 }
153 
154 
155 void ossimPointObservation::getObsCov(NEWMAT::Matrix& cov)const
156 {
157  cov = NEWMAT::Matrix(3,3);
158  cov = 0.0;
159 
160  double stdrp = theObsSigmas[0]/thePt.metersPerDegree().y/DEG_PER_RAD; //lat
161  double stdrl = theObsSigmas[1]/thePt.metersPerDegree().x/DEG_PER_RAD; //lon
162 
163  cov(1,1) = stdrp*stdrp;
164  cov(2,2) = stdrl*stdrl;
165  cov(3,3) = theObsSigmas[2]*theObsSigmas[2];
166 }
167 
168 
169 void ossimPointObservation::getResiduals(const int index, NEWMAT::Matrix& resid)
170 {
171  ossimDpt computedImagePosition;
172  getImageGeom(index)->worldToLocal(refGroundPoint(), computedImagePosition);
173  ossimDpt residual = theMeas[index] - computedImagePosition;
174 
175  if (traceDebug())
176  {
177  ossimNotify(ossimNotifyLevel_DEBUG)<<"\n========getResiduals======== "<<index;
178  theMeas[index].print(ossimNotify(ossimNotifyLevel_DEBUG),1);
179  computedImagePosition.print(ossimNotify(ossimNotifyLevel_DEBUG),1);
181  }
182 
183  resid = NEWMAT::Matrix(1, 2);
184  resid[0][0] = residual.x;
185  resid[0][1] = residual.y;
186 }
187 
188 
189 void ossimPointObservation::getParameterPartials(const int index, NEWMAT::Matrix& parPartials)
190 {
191  parPartials = NEWMAT::Matrix(theNumPars[index], 2);
193 }
194 
195 
196 void ossimPointObservation::getObjSpacePartials(const int index, NEWMAT::Matrix& objPartials)
197 {
198  objPartials = NEWMAT::Matrix(3, 2);
200 }
201 
202 
204 {
205  // Observation
206  os << "\n "<<theID;
207  if (ossim::isnan(theScore) == false)
208  {
209  os << std::setiosflags(std::ios::fixed) << std::setprecision(2);
210  os << "\t" << theScore;
211  }
212  else
213  {
214  os << "\t" << "nan";
215  }
216  os << "\t" << dynamic_cast<const ossimGpt&>(*this);
217 
218  // Measurements
219  for (ossim_uint32 i=0; i<numMeas(); ++i)
220  {
221  os << "\n\t\t\t";
222  theMeas[i].print(os,1);
223  }
224 
225  return os;
226 }
227 
228 
230 {
231  return pt.print(os);
232 }
ossim_uint32 x
std::vector< ossimFilename > theImageFiles
std::vector< int > theNumPars
virtual ossimImageHandler * open(const ossimFilename &fileName, bool trySuffixFirst=true, bool openOverview=true) const
open that takes a filename.
#define DEG_PER_RAD
ossim_uint32 y
bool valid() const
Definition: ossimRefPtr.h:75
std::vector< ossimDpt > theMeas
void getParameterPartials(const int index, NEWMAT::Matrix &parPartials)
bool computeGroundToImagePartials(NEWMAT::Matrix &result, const ossimGpt &gpt, const ossimDpt3d &deltaLlh)
double y
Definition: ossimDpt.h:165
void makeNan()
Definition: ossimGpt.h:130
void getObjSpacePartials(const int index, NEWMAT::Matrix &objPartials)
void getResiduals(const int index, NEWMAT::Matrix &resid)
virtual ossimAdjustableParameterInterface * getAdjustableParameterInterface()
void getObsCov(NEWMAT::Matrix &cov) const
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Returns the image geometry object associated with this tile source or NULL if non defined...
void setImageGeom(const int index, ossimImageGeometry *imgGeom)
unsigned int ossim_uint32
std::vector< ossimRefPtr< ossimImageHandler > > theImageHandlers
std::ostream & print(std::ostream &os, ossim_uint32 precision=15) const
Definition: ossimGpt.cpp:27
Container class that holds both 2D transform and 3D projection information for an image Only one inst...
void getMeasCov(const int index, NEWMAT::Matrix &cov) const
std::ostream & operator<<(std::ostream &os, const ossimPointObservation &pt)
void getMeasurement(const int index, NEWMAT::Matrix &meas) const
void addMeasurement(const ossimDpt &meas, const ossimFilename &imgFile, const ossimDpt &measSigma=ossimDpt(1.0, 1.0))
double x
Definition: ossimDpt.h:164
bool worldToLocal(const ossimGpt &world_pt, ossimDpt &local_pt) const
Exposes the 3D world-to-local image coordinate reverse projection.
ossimDpt metersPerDegree() const
Definition: ossimGpt.cpp:498
unsigned int numMeas() const
static ossimImageHandlerRegistry * instance()
std::ostream & print(std::ostream &os) const
Generic print method.
std::vector< ossimDpt > theMeasSigmas
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
ossimImageGeometry * getImageGeom(const int index)
bool isnan(const float &v)
isnan Test for floating point Not A Number (NAN) value.
Definition: ossimCommon.h:91
bool computeImageToGroundPartialsWRTAdjParams(NEWMAT::Matrix &result, const ossimGpt &gpt, ossim_float64 paramDelta=1.0)