Isis 3 Programmer Reference
CameraStatistics.cpp
1 #include "IsisDebug.h"
2 #include "CameraStatistics.h"
3 
4 #include "Camera.h"
5 #include "Cube.h"
6 #include "Distance.h"
7 #include "Progress.h"
8 #include "Statistics.h"
9 
10 namespace Isis {
11 
12 
27  CameraStatistics::CameraStatistics(QString filename, int sinc, int linc) {
28  Cube cube;
29  cube.open(filename);
30  Camera *cam = cube.camera();
31  init(cam, sinc, linc, filename);
32  }
33 
34 
49  CameraStatistics::CameraStatistics(Camera *cam, int sinc, int linc) {
50  init(cam, sinc, linc, "");
51  }
52 
53 
68  CameraStatistics::CameraStatistics(Camera *cam, int sinc, int linc,
69  QString filename) {
70  init(cam, sinc, linc, filename);
71  }
72 
73 
86  void CameraStatistics::init(Camera *cam, int sinc, int linc,
87  QString filename) {
88 
89  m_filename = filename;
90  m_sinc = sinc;
91  m_linc = linc;
92 
93  m_latStat = new Statistics();
94  m_lonStat = new Statistics();
95  m_resStat = new Statistics();
96 
97 
101 
102 
103  m_sampleResStat = new Statistics();
104  m_lineResStat = new Statistics();
106  m_phaseStat = new Statistics();
107  m_emissionStat = new Statistics();
108  m_incidenceStat = new Statistics();
112 
113  int eband = cam->Bands();
114 
115  // If the camera is band independent then only run one band
116  if (cam->IsBandIndependent()) eband = 1;
117 
118  int pTotal = eband * ((cam->Lines() - 2) / linc + 2);
119  Progress progress;
120  progress.SetMaximumSteps(pTotal);
121  progress.CheckStatus();
122 
123  for (int band = 1; band <= eband; band++) {
124  cam->SetBand(band);
125  for (int line = 1; line < (int)cam->Lines(); line = line + linc) {
126  for (int sample = 1; sample < cam->Samples(); sample = sample + sinc) {
127  addStats(cam, sample, line);
128  }
129 
130  // Set the sample value to the last sample and run buildstats
131  int sample = cam->Samples();
132  addStats(cam, sample, line);
133  progress.CheckStatus();
134  }
135 
136  // Set the line value to the last line and run on all samples (sample +
137  // sinc)
138  int line = cam->Lines();
139  for (int sample = 1; sample < cam->Samples(); sample = sample + sinc) {
140  addStats(cam, sample, line);
141  }
142 
143  // Set last sample and run with last line
144  int sample = cam->Samples();
145  addStats(cam, sample, line);
146  progress.CheckStatus();
147  }
148  }
149 
150 
155  if (m_latStat != NULL) {
156  delete m_latStat;
157  m_latStat = NULL;
158  }
159  if (m_lonStat != NULL) {
160  delete m_lonStat;
161  m_lonStat = NULL;
162  }
163  if (m_resStat != NULL) {
164  delete m_resStat;
165  m_resStat = NULL;
166  }
167 
168 
169  if (m_obliqueLineResStat != NULL) {
170  delete m_obliqueLineResStat;
171  m_obliqueLineResStat = NULL;
172 
173  }
174 
175  if (m_obliqueSampleResStat != NULL) {
176  delete m_obliqueSampleResStat;
177  m_obliqueSampleResStat = NULL;
178 
179  }
180 
181  if (m_obliqueResStat != NULL) {
182  delete m_obliqueResStat;
183  m_obliqueResStat = NULL;
184  }
185 
186  if (m_sampleResStat != NULL) {
187  delete m_sampleResStat;
188  m_sampleResStat = NULL;
189  }
190  if (m_lineResStat != NULL) {
191  delete m_lineResStat;
192  m_lineResStat = NULL;
193  }
194  if (m_aspectRatioStat != NULL) {
195  delete m_aspectRatioStat;
196  m_aspectRatioStat = NULL;
197  }
198  if (m_phaseStat != NULL) {
199  delete m_phaseStat;
200  m_phaseStat = NULL;
201  }
202  if (m_emissionStat != NULL) {
203  delete m_emissionStat;
204  m_emissionStat = NULL;
205  }
206  if (m_incidenceStat != NULL) {
207  delete m_incidenceStat;
208  m_incidenceStat = NULL;
209  }
210  if (m_localSolarTimeStat != NULL) {
211  delete m_localSolarTimeStat;
212  m_localSolarTimeStat = NULL;
213  }
214  if (m_localRaduisStat != NULL) {
215  delete m_localRaduisStat;
216  m_localRaduisStat = NULL;
217  }
218  if (m_northAzimuthStat != NULL) {
219  delete m_northAzimuthStat;
220  m_northAzimuthStat = NULL;
221  }
222  }
223 
224 
233  void CameraStatistics::addStats(Camera *cam, int &sample, int &line) {
234  cam->SetImage(sample, line);
235  if(cam->HasSurfaceIntersection()) {
238 
239 
243 
244 
245 
249  m_phaseStat->AddData(cam->PhaseAngle());
254  // if IsValid
256 
257  // if resolution not equal to -1.0
258  double aspectRatio = cam->LineResolution() / cam->SampleResolution();
259  m_aspectRatioStat->AddData(aspectRatio);
260  }
261  }
262 
263 
276  double value, QString unit="") const {
277 
278  if(IsSpecial(value)) {
279  return (PvlKeyword(keyname, "NULL"));
280  }
281  else {
282  return (PvlKeyword(keyname, toString(value), unit));
283  }
284  }
285 
286 
362  // Set up the Pvl groups and get min, max, avg, and sd for each statstics
363  // object
364  PvlGroup pUser("User Parameters");
365  if (m_filename != "") pUser += PvlKeyword("Filename", m_filename);
366  pUser += PvlKeyword("Linc", toString(m_linc));
367  pUser += PvlKeyword("Sinc", toString(m_sinc));
368 
369  PvlGroup pLat("Latitude");
370  pLat += constructKeyword("LatitudeMinimum", m_latStat->Minimum());
371  pLat += constructKeyword("LatitudeMaximum", m_latStat->Maximum());
372  pLat += constructKeyword("LatitudeAverage", m_latStat->Average());
373  pLat += constructKeyword("LatitudeStandardDeviation", m_latStat->StandardDeviation());
374 
375  PvlGroup pLon("Longitude");
376  pLon += constructKeyword("LongitudeMinimum", m_lonStat->Minimum());
377  pLon += constructKeyword("LongitudeMaximum", m_lonStat->Maximum());
378  pLon += constructKeyword("LongitudeAverage", m_lonStat->Average());
379  pLon += constructKeyword("LongitudeStandardDeviation", m_lonStat->StandardDeviation());
380 
381  PvlGroup pObliqueSampleRes("ObliqueSampleResolution");
382  pObliqueSampleRes += constructKeyword("ObliqueSampleResolutionMinimum",
383  m_obliqueSampleResStat->Minimum(), "meters/pixel");
384  pObliqueSampleRes += constructKeyword("ObliqueSampleResolutionMaximum",
385  m_obliqueSampleResStat->Maximum(),"meters/pixel");
386  pObliqueSampleRes += constructKeyword("ObliqueSampleResolutionAverage",
387  m_obliqueSampleResStat->Average(),"meters/pixel");
388  pObliqueSampleRes += constructKeyword("ObliqueSampleResolutionStandardDeviation",
389  m_obliqueSampleResStat->StandardDeviation(), "meters/pixel");
390 
391  PvlGroup pObliqueLineRes("ObliqueLineResolution");
392  pObliqueLineRes += constructKeyword("ObliqueLineResolutionMinimum", m_obliqueLineResStat->Minimum(),
393  "meters/pixel");
394  pObliqueLineRes += constructKeyword("ObliqueLineResolutionMaximum", m_obliqueLineResStat->Maximum(),
395  "meters/pixel");
396  pObliqueLineRes += constructKeyword("ObliqueLineResolutionAverage", m_obliqueLineResStat->Average(),
397  "meters/pixel");
398  pObliqueLineRes += constructKeyword("ObliqueLineResolutionStandardDeviation",
399  m_obliqueLineResStat->StandardDeviation(), "meters/pixel");
400 
401  PvlGroup pObliqueResolution("ObliqueResolution");
402  pObliqueResolution += constructKeyword("ObliqueResolutionMinimum", m_obliqueResStat->Minimum(),
403  "meters/pixel");
404  pObliqueResolution += constructKeyword("ObliqueResolutionMaximum", m_obliqueResStat->Maximum(),
405  "meters/pixel");
406  pObliqueResolution += constructKeyword("ObliqueResolutionAverage", m_obliqueResStat->Average(),
407  "meters/pixel");
408  pObliqueResolution += constructKeyword("ObliqueResolutionStandardDeviation",
409  m_obliqueResStat->StandardDeviation(), "meters/pixel");
410 
411 
412  PvlGroup pSampleRes("SampleResolution");
413  pSampleRes += constructKeyword("SampleResolutionMinimum", m_sampleResStat->Minimum(),
414  "meters/pixel");
415  pSampleRes += constructKeyword("SampleResolutionMaximum", m_sampleResStat->Maximum(),
416  "meters/pixel");
417  pSampleRes += constructKeyword("SampleResolutionAverage", m_sampleResStat->Average(),
418  "meters/pixel");
419  pSampleRes += constructKeyword("SampleResolutionStandardDeviation",
420  m_sampleResStat->StandardDeviation(), "meters/pixel");
421 
422  PvlGroup pLineRes("LineResolution");
423  pLineRes += constructKeyword("LineResolutionMinimum", m_lineResStat->Minimum(),
424  "meters/pixel");
425  pLineRes += constructKeyword("LineResolutionMaximum", m_lineResStat->Maximum(),
426  "meters/pixel");
427  pLineRes += constructKeyword("LineResolutionAverage", m_lineResStat->Average(),
428  "meters/pixel");
429  pLineRes += constructKeyword("LineResolutionStandardDeviation",
430  m_lineResStat->StandardDeviation(), "meters/pixel");
431 
432  PvlGroup pResolution("Resolution");
433  pResolution += constructKeyword("ResolutionMinimum", m_resStat->Minimum(),
434  "meters/pixel");
435  pResolution += constructKeyword("ResolutionMaximum", m_resStat->Maximum(),
436  "meters/pixel");
437  pResolution += constructKeyword("ResolutionAverage", m_resStat->Average(),
438  "meters/pixel");
439  pResolution += constructKeyword("ResolutionStandardDeviation",
440  m_resStat->StandardDeviation(), "meters/pixel");
441 
442  PvlGroup pAspectRatio("AspectRatio");
443  pAspectRatio += constructKeyword("AspectRatioMinimum", m_aspectRatioStat->Minimum());
444  pAspectRatio += constructKeyword("AspectRatioMaximun", m_aspectRatioStat->Maximum());
445  pAspectRatio += constructKeyword("AspectRatioAverage", m_aspectRatioStat->Average());
446  pAspectRatio += constructKeyword("AspectRatioStandardDeviation",
448 
449  PvlGroup pPhase("PhaseAngle");
450  pPhase += constructKeyword("PhaseMinimum", m_phaseStat->Minimum());
451  pPhase += constructKeyword("PhaseMaximum", m_phaseStat->Maximum());
452  pPhase += constructKeyword("PhaseAverage", m_phaseStat->Average());
453  pPhase += constructKeyword("PhaseStandardDeviation", m_phaseStat->StandardDeviation());
454 
455  PvlGroup pEmission("EmissionAngle");
456  pEmission += constructKeyword("EmissionMinimum", m_emissionStat->Minimum());
457  pEmission += constructKeyword("EmissionMaximum", m_emissionStat->Maximum());
458  pEmission += constructKeyword("EmissionAverage", m_emissionStat->Average());
459  pEmission += constructKeyword("EmissionStandardDeviation",
461 
462  PvlGroup pIncidence("IncidenceAngle");
463  pIncidence += constructKeyword("IncidenceMinimum", m_incidenceStat->Minimum());
464  pIncidence += constructKeyword("IncidenceMaximum", m_incidenceStat->Maximum());
465  pIncidence += constructKeyword("IncidenceAverage", m_incidenceStat->Average());
466  pIncidence += constructKeyword("IncidenceStandardDeviation",
468 
469  PvlGroup pTime("LocalSolarTime");
470  pTime += constructKeyword("LocalSolarTimeMinimum", m_localSolarTimeStat->Minimum(),
471  "hours");
472  pTime += constructKeyword("LocalSolarTimeMaximum", m_localSolarTimeStat->Maximum(),
473  "hours");
474  pTime += constructKeyword("LocalSolarTimeAverage", m_localSolarTimeStat->Average(),
475  "hours");
476  pTime += constructKeyword("LocalSolarTimeStandardDeviation",
478 
479  PvlGroup pLocalRadius("LocalRadius");
480  pLocalRadius += constructKeyword("LocalRadiusMinimum", m_localRaduisStat->Minimum());
481  pLocalRadius += constructKeyword("LocalRadiusMaximum", m_localRaduisStat->Maximum());
482  pLocalRadius += constructKeyword("LocalRadiusAverage", m_localRaduisStat->Average());
483  pLocalRadius += constructKeyword("LocalRadiusStandardDeviation",
485 
486  PvlGroup pNorthAzimuth("NorthAzimuth");
487  pNorthAzimuth += constructKeyword("NorthAzimuthMinimum", m_northAzimuthStat->Minimum());
488  pNorthAzimuth += constructKeyword("NorthAzimuthMaximum", m_northAzimuthStat->Maximum());
489  pNorthAzimuth += constructKeyword("NorthAzimuthAverage", m_northAzimuthStat->Average());
490  pNorthAzimuth += constructKeyword("NorthAzimuthStandardDeviation",
492 
493  Pvl returnPvl;
494  returnPvl.setTerminator("");
495  returnPvl.addGroup(pUser);
496  returnPvl.addGroup(pLat);
497  returnPvl.addGroup(pLon);
498  returnPvl.addGroup(pSampleRes);
499  returnPvl.addGroup(pLineRes);
500  returnPvl.addGroup(pResolution);
501 
502  returnPvl.addGroup(pObliqueSampleRes);
503  returnPvl.addGroup(pObliqueLineRes);
504  returnPvl.addGroup(pObliqueResolution);
505 
506  returnPvl.addGroup(pAspectRatio);
507  returnPvl.addGroup(pPhase);
508  returnPvl.addGroup(pEmission);
509  returnPvl.addGroup(pIncidence);
510  returnPvl.addGroup(pTime);
511  returnPvl.addGroup(pLocalRadius);
512  returnPvl.addGroup(pNorthAzimuth);
513  return returnPvl;
514  }
515 }
516 
double meters() const
Get the distance in meters.
Definition: Distance.cpp:97
Statistics * m_emissionStat
Emission angle statistics.
double ObliqueLineResolution()
Returns the oblique line resolution at the current position in meters.
Definition: Camera.cpp:679
Statistics * m_latStat
Universal latitude statistics.
Statistics * m_obliqueResStat
Oblique pixel resolution statistics.
void SetMaximumSteps(const int steps)
This sets the maximum number of steps in the process.
Definition: Progress.cpp:101
double StandardDeviation() const
Computes and returns the standard deviation.
Definition: Statistics.cpp:325
double Minimum() const
Returns the absolute minimum double found in all data passed through the AddData method.
Definition: Statistics.cpp:395
double UniversalLatitude() const
Returns the planetocentric latitude, in degrees, at the surface intersection point in the body fixed ...
Definition: Sensor.cpp:225
Camera * camera()
Return a camera associated with the cube.
Definition: Cube.cpp:1166
Statistics * m_phaseStat
Phase angle statistics.
Statistics * m_localSolarTimeStat
Local solar time statistics.
Statistics * m_lonStat
Universal longitude statistics.
int m_linc
Line increment for composing statistics.
double ObliquePixelResolution()
Returns the oblique pixel resolution at the current position in meters/pixel.
Definition: Camera.cpp:704
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
double ObliqueSampleResolution()
Returns the oblique sample resolution at the current position in m.
Definition: Camera.cpp:656
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
Statistics * m_northAzimuthStat
North azimuth statistics.
void CheckStatus()
Checks and updates the status.
Definition: Progress.cpp:121
Distance LocalRadius() const
Returns the local radius at the intersection point.
Definition: Sensor.cpp:282
void setTerminator(const QString &term)
Sets the terminator used to signify the end of the PVL informationDefaults to "END".
Definition: Pvl.h:159
double Maximum() const
Returns the absolute maximum double found in all data passed through the AddData method.
Definition: Statistics.cpp:416
double EmissionAngle() const
Returns the emission angle in degrees.
Definition: Sensor.cpp:339
Statistics * m_localRaduisStat
Local radius statistics (in meters).
bool SetImage(const double sample, const double line)
Sets the sample/line values of the image to get the lat/lon values.
Definition: Camera.cpp:170
This class is used to accumulate statistics on double arrays.
Definition: Statistics.h:107
Program progress reporter.
Definition: Progress.h:58
void addStats(Camera *cam, int &sample, int &line)
Add statistics data to Statistics objects if the Camera position given by the provided line and sampl...
int m_sinc
Sample increment for composing statistics.
Statistics * m_sampleResStat
Sample resolution statistics.
Pvl toPvl() const
Constructs a Pvl object from the values in the various statistics objects.
Statistics * m_resStat
Pixel resolution statistics.
virtual ~CameraStatistics()
Destroy this instance, deletes all the Statistics objects.
Contains multiple PvlContainers.
Definition: PvlGroup.h:57
CameraStatistics(QString filename, int sinc, int linc)
Constructs the Camera Statistics object from a Cube filename.
A single keyword-value pair.
Definition: PvlKeyword.h:98
Statistics * m_obliqueLineResStat
Oblique line resolution statistics.
double NorthAzimuth()
Returns the North Azimuth.
Definition: Camera.cpp:1912
bool IsSpecial(const double d)
Returns if the input pixel is special.
Definition: SpecialPixel.h:212
void open(const QString &cfile, QString access="r")
This method will open an isis cube for reading or reading/writing.
Definition: Cube.cpp:544
QString m_filename
FileName of the Cube the Camera was derived from.
PvlKeyword constructKeyword(QString keyname, double value, QString unit) const
Takes a name, value, and optionally units and constructs a PVL Keyword.
void init(Camera *cam, int sinc, int linc, QString filename)
Initializes this collection of statistics by incrementing over sample/line positions in the Camera an...
Container for cube-like labels.
Definition: Pvl.h:135
double UniversalLongitude() const
Returns the positive east, 0-360 domain longitude, in degrees, at the surface intersection point in t...
Definition: Sensor.cpp:248
Statistics * m_obliqueSampleResStat
Oblique sample resolution statistics.
Statistics * m_aspectRatioStat
Aspect ratio statistics.
double PhaseAngle() const
Returns the phase angle in degrees.
Definition: Sensor.cpp:327
virtual bool IsBandIndependent()
Virtual method that checks if the band is independent.
Definition: Camera.cpp:2661
int Bands() const
Returns the number of bands in the image.
Definition: Camera.cpp:2808
int Lines() const
Returns the number of lines in the image.
Definition: Camera.cpp:2798
int Samples() const
Returns the number of samples in the image.
Definition: Camera.cpp:2788
double PixelResolution()
Returns the pixel resolution at the current position in meters/pixel.
Definition: Camera.cpp:689
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
double LineResolution()
Returns the line resolution at the current position in meters.
Definition: Camera.cpp:667
double IncidenceAngle() const
Returns the incidence angle in degrees.
Definition: Sensor.cpp:350
Statistics * m_incidenceStat
Incidence angle statistics.
double LocalSolarTime()
Return the local solar time in hours.
Definition: Sensor.cpp:671
void AddData(const double *data, const unsigned int count)
Add an array of doubles to the accumulators and counters.
Definition: Statistics.cpp:154
double Average() const
Computes and returns the average.
Definition: Statistics.cpp:313
double SampleResolution()
Returns the sample resolution at the current position in meters.
Definition: Camera.cpp:645
virtual void SetBand(const int band)
Virtual method that sets the band number.
Definition: Camera.cpp:2692
Statistics * m_lineResStat
Line resolution statistics.
bool HasSurfaceIntersection() const
Returns if the last call to either SetLookDirection or SetUniversalGround had a valid intersection wi...
Definition: Sensor.cpp:201
IO Handler for Isis Cubes.
Definition: Cube.h:170