Isis 3 Programmer Reference
CameraStatistics.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include "IsisDebug.h"
8 #include "CameraStatistics.h"
9 
10 #include "Camera.h"
11 #include "Cube.h"
12 #include "Distance.h"
13 #include "Progress.h"
14 #include "Statistics.h"
15 
16 namespace Isis {
17 
18 
33  CameraStatistics::CameraStatistics(QString filename, int sinc, int linc) {
34  Cube cube;
35  cube.open(filename);
36  Camera *cam = cube.camera();
37  init(cam, sinc, linc, filename);
38  }
39 
40 
55  CameraStatistics::CameraStatistics(Camera *cam, int sinc, int linc) {
56  init(cam, sinc, linc, "");
57  }
58 
59 
74  CameraStatistics::CameraStatistics(Camera *cam, int sinc, int linc,
75  QString filename) {
76  init(cam, sinc, linc, filename);
77  }
78 
79 
92  void CameraStatistics::init(Camera *cam, int sinc, int linc,
93  QString filename) {
94 
95  m_filename = filename;
96  m_sinc = sinc;
97  m_linc = linc;
98 
99  m_latStat = new Statistics();
100  m_lonStat = new Statistics();
101  m_resStat = new Statistics();
102 
103 
107 
108 
109  m_sampleResStat = new Statistics();
110  m_lineResStat = new Statistics();
112  m_phaseStat = new Statistics();
113  m_emissionStat = new Statistics();
114  m_incidenceStat = new Statistics();
118 
119  int eband = cam->Bands();
120 
121  // If the camera is band independent then only run one band
122  if (cam->IsBandIndependent()) eband = 1;
123 
124  int pTotal = eband * ((cam->Lines() - 2) / linc + 2);
125  Progress progress;
126  progress.SetMaximumSteps(pTotal);
127  progress.CheckStatus();
128 
129  for (int band = 1; band <= eband; band++) {
130  cam->SetBand(band);
131  for (int line = 1; line < (int)cam->Lines(); line = line + linc) {
132  for (int sample = 1; sample < cam->Samples(); sample = sample + sinc) {
133  addStats(cam, sample, line);
134  }
135 
136  // Set the sample value to the last sample and run buildstats
137  int sample = cam->Samples();
138  addStats(cam, sample, line);
139  progress.CheckStatus();
140  }
141 
142  // Set the line value to the last line and run on all samples (sample +
143  // sinc)
144  int line = cam->Lines();
145  for (int sample = 1; sample < cam->Samples(); sample = sample + sinc) {
146  addStats(cam, sample, line);
147  }
148 
149  // Set last sample and run with last line
150  int sample = cam->Samples();
151  addStats(cam, sample, line);
152  progress.CheckStatus();
153  }
154  }
155 
156 
161  if (m_latStat != NULL) {
162  delete m_latStat;
163  m_latStat = NULL;
164  }
165  if (m_lonStat != NULL) {
166  delete m_lonStat;
167  m_lonStat = NULL;
168  }
169  if (m_resStat != NULL) {
170  delete m_resStat;
171  m_resStat = NULL;
172  }
173 
174 
175  if (m_obliqueLineResStat != NULL) {
176  delete m_obliqueLineResStat;
177  m_obliqueLineResStat = NULL;
178 
179  }
180 
181  if (m_obliqueSampleResStat != NULL) {
182  delete m_obliqueSampleResStat;
183  m_obliqueSampleResStat = NULL;
184 
185  }
186 
187  if (m_obliqueResStat != NULL) {
188  delete m_obliqueResStat;
189  m_obliqueResStat = NULL;
190  }
191 
192  if (m_sampleResStat != NULL) {
193  delete m_sampleResStat;
194  m_sampleResStat = NULL;
195  }
196  if (m_lineResStat != NULL) {
197  delete m_lineResStat;
198  m_lineResStat = NULL;
199  }
200  if (m_aspectRatioStat != NULL) {
201  delete m_aspectRatioStat;
202  m_aspectRatioStat = NULL;
203  }
204  if (m_phaseStat != NULL) {
205  delete m_phaseStat;
206  m_phaseStat = NULL;
207  }
208  if (m_emissionStat != NULL) {
209  delete m_emissionStat;
210  m_emissionStat = NULL;
211  }
212  if (m_incidenceStat != NULL) {
213  delete m_incidenceStat;
214  m_incidenceStat = NULL;
215  }
216  if (m_localSolarTimeStat != NULL) {
217  delete m_localSolarTimeStat;
218  m_localSolarTimeStat = NULL;
219  }
220  if (m_localRaduisStat != NULL) {
221  delete m_localRaduisStat;
222  m_localRaduisStat = NULL;
223  }
224  if (m_northAzimuthStat != NULL) {
225  delete m_northAzimuthStat;
226  m_northAzimuthStat = NULL;
227  }
228  }
229 
230 
239  void CameraStatistics::addStats(Camera *cam, int &sample, int &line) {
240  cam->SetImage(sample, line);
241  if(cam->HasSurfaceIntersection()) {
244 
245 
249 
250 
251 
255  m_phaseStat->AddData(cam->PhaseAngle());
260  // if IsValid
262 
263  // if resolution not equal to -1.0
264  double aspectRatio = cam->LineResolution() / cam->SampleResolution();
265  m_aspectRatioStat->AddData(aspectRatio);
266  }
267  }
268 
269 
282  double value, QString unit="") const {
283 
284  if(IsSpecial(value)) {
285  return (PvlKeyword(keyname, "NULL"));
286  }
287  else {
288  return (PvlKeyword(keyname, toString(value), unit));
289  }
290  }
291 
292 
368  // Set up the Pvl groups and get min, max, avg, and sd for each statstics
369  // object
370  PvlGroup pUser("User Parameters");
371  if (m_filename != "") pUser += PvlKeyword("Filename", m_filename);
372  pUser += PvlKeyword("Linc", toString(m_linc));
373  pUser += PvlKeyword("Sinc", toString(m_sinc));
374 
375  PvlGroup pLat("Latitude");
376  pLat += constructKeyword("LatitudeMinimum", m_latStat->Minimum());
377  pLat += constructKeyword("LatitudeMaximum", m_latStat->Maximum());
378  pLat += constructKeyword("LatitudeAverage", m_latStat->Average());
379  pLat += constructKeyword("LatitudeStandardDeviation", m_latStat->StandardDeviation());
380 
381  PvlGroup pLon("Longitude");
382  pLon += constructKeyword("LongitudeMinimum", m_lonStat->Minimum());
383  pLon += constructKeyword("LongitudeMaximum", m_lonStat->Maximum());
384  pLon += constructKeyword("LongitudeAverage", m_lonStat->Average());
385  pLon += constructKeyword("LongitudeStandardDeviation", m_lonStat->StandardDeviation());
386 
387  PvlGroup pObliqueSampleRes("ObliqueSampleResolution");
388  pObliqueSampleRes += constructKeyword("ObliqueSampleResolutionMinimum",
389  m_obliqueSampleResStat->Minimum(), "meters/pixel");
390  pObliqueSampleRes += constructKeyword("ObliqueSampleResolutionMaximum",
391  m_obliqueSampleResStat->Maximum(),"meters/pixel");
392  pObliqueSampleRes += constructKeyword("ObliqueSampleResolutionAverage",
393  m_obliqueSampleResStat->Average(),"meters/pixel");
394  pObliqueSampleRes += constructKeyword("ObliqueSampleResolutionStandardDeviation",
395  m_obliqueSampleResStat->StandardDeviation(), "meters/pixel");
396 
397  PvlGroup pObliqueLineRes("ObliqueLineResolution");
398  pObliqueLineRes += constructKeyword("ObliqueLineResolutionMinimum", m_obliqueLineResStat->Minimum(),
399  "meters/pixel");
400  pObliqueLineRes += constructKeyword("ObliqueLineResolutionMaximum", m_obliqueLineResStat->Maximum(),
401  "meters/pixel");
402  pObliqueLineRes += constructKeyword("ObliqueLineResolutionAverage", m_obliqueLineResStat->Average(),
403  "meters/pixel");
404  pObliqueLineRes += constructKeyword("ObliqueLineResolutionStandardDeviation",
405  m_obliqueLineResStat->StandardDeviation(), "meters/pixel");
406 
407  PvlGroup pObliqueResolution("ObliqueResolution");
408  pObliqueResolution += constructKeyword("ObliqueResolutionMinimum", m_obliqueResStat->Minimum(),
409  "meters/pixel");
410  pObliqueResolution += constructKeyword("ObliqueResolutionMaximum", m_obliqueResStat->Maximum(),
411  "meters/pixel");
412  pObliqueResolution += constructKeyword("ObliqueResolutionAverage", m_obliqueResStat->Average(),
413  "meters/pixel");
414  pObliqueResolution += constructKeyword("ObliqueResolutionStandardDeviation",
415  m_obliqueResStat->StandardDeviation(), "meters/pixel");
416 
417 
418  PvlGroup pSampleRes("SampleResolution");
419  pSampleRes += constructKeyword("SampleResolutionMinimum", m_sampleResStat->Minimum(),
420  "meters/pixel");
421  pSampleRes += constructKeyword("SampleResolutionMaximum", m_sampleResStat->Maximum(),
422  "meters/pixel");
423  pSampleRes += constructKeyword("SampleResolutionAverage", m_sampleResStat->Average(),
424  "meters/pixel");
425  pSampleRes += constructKeyword("SampleResolutionStandardDeviation",
426  m_sampleResStat->StandardDeviation(), "meters/pixel");
427 
428  PvlGroup pLineRes("LineResolution");
429  pLineRes += constructKeyword("LineResolutionMinimum", m_lineResStat->Minimum(),
430  "meters/pixel");
431  pLineRes += constructKeyword("LineResolutionMaximum", m_lineResStat->Maximum(),
432  "meters/pixel");
433  pLineRes += constructKeyword("LineResolutionAverage", m_lineResStat->Average(),
434  "meters/pixel");
435  pLineRes += constructKeyword("LineResolutionStandardDeviation",
436  m_lineResStat->StandardDeviation(), "meters/pixel");
437 
438  PvlGroup pResolution("Resolution");
439  pResolution += constructKeyword("ResolutionMinimum", m_resStat->Minimum(),
440  "meters/pixel");
441  pResolution += constructKeyword("ResolutionMaximum", m_resStat->Maximum(),
442  "meters/pixel");
443  pResolution += constructKeyword("ResolutionAverage", m_resStat->Average(),
444  "meters/pixel");
445  pResolution += constructKeyword("ResolutionStandardDeviation",
446  m_resStat->StandardDeviation(), "meters/pixel");
447 
448  PvlGroup pAspectRatio("AspectRatio");
449  pAspectRatio += constructKeyword("AspectRatioMinimum", m_aspectRatioStat->Minimum());
450  // Note: Maximum is spelled wrong here.
451  pAspectRatio += constructKeyword("AspectRatioMaximun", m_aspectRatioStat->Maximum());
452  pAspectRatio += constructKeyword("AspectRatioAverage", m_aspectRatioStat->Average());
453  pAspectRatio += constructKeyword("AspectRatioStandardDeviation",
455 
456  PvlGroup pPhase("PhaseAngle");
457  pPhase += constructKeyword("PhaseMinimum", m_phaseStat->Minimum());
458  pPhase += constructKeyword("PhaseMaximum", m_phaseStat->Maximum());
459  pPhase += constructKeyword("PhaseAverage", m_phaseStat->Average());
460  pPhase += constructKeyword("PhaseStandardDeviation", m_phaseStat->StandardDeviation());
461 
462  PvlGroup pEmission("EmissionAngle");
463  pEmission += constructKeyword("EmissionMinimum", m_emissionStat->Minimum());
464  pEmission += constructKeyword("EmissionMaximum", m_emissionStat->Maximum());
465  pEmission += constructKeyword("EmissionAverage", m_emissionStat->Average());
466  pEmission += constructKeyword("EmissionStandardDeviation",
468 
469  PvlGroup pIncidence("IncidenceAngle");
470  pIncidence += constructKeyword("IncidenceMinimum", m_incidenceStat->Minimum());
471  pIncidence += constructKeyword("IncidenceMaximum", m_incidenceStat->Maximum());
472  pIncidence += constructKeyword("IncidenceAverage", m_incidenceStat->Average());
473  pIncidence += constructKeyword("IncidenceStandardDeviation",
475 
476  PvlGroup pTime("LocalSolarTime");
477  pTime += constructKeyword("LocalSolarTimeMinimum", m_localSolarTimeStat->Minimum(),
478  "hours");
479  pTime += constructKeyword("LocalSolarTimeMaximum", m_localSolarTimeStat->Maximum(),
480  "hours");
481  pTime += constructKeyword("LocalSolarTimeAverage", m_localSolarTimeStat->Average(),
482  "hours");
483  pTime += constructKeyword("LocalSolarTimeStandardDeviation",
485 
486  PvlGroup pLocalRadius("LocalRadius");
487  pLocalRadius += constructKeyword("LocalRadiusMinimum", m_localRaduisStat->Minimum());
488  pLocalRadius += constructKeyword("LocalRadiusMaximum", m_localRaduisStat->Maximum());
489  pLocalRadius += constructKeyword("LocalRadiusAverage", m_localRaduisStat->Average());
490  pLocalRadius += constructKeyword("LocalRadiusStandardDeviation",
492 
493  PvlGroup pNorthAzimuth("NorthAzimuth");
494  pNorthAzimuth += constructKeyword("NorthAzimuthMinimum", m_northAzimuthStat->Minimum());
495  pNorthAzimuth += constructKeyword("NorthAzimuthMaximum", m_northAzimuthStat->Maximum());
496  pNorthAzimuth += constructKeyword("NorthAzimuthAverage", m_northAzimuthStat->Average());
497  pNorthAzimuth += constructKeyword("NorthAzimuthStandardDeviation",
499 
500  Pvl returnPvl;
501  returnPvl.setTerminator("");
502  returnPvl.addGroup(pUser);
503  returnPvl.addGroup(pLat);
504  returnPvl.addGroup(pLon);
505  returnPvl.addGroup(pSampleRes);
506  returnPvl.addGroup(pLineRes);
507  returnPvl.addGroup(pResolution);
508 
509  returnPvl.addGroup(pObliqueSampleRes);
510  returnPvl.addGroup(pObliqueLineRes);
511  returnPvl.addGroup(pObliqueResolution);
512 
513  returnPvl.addGroup(pAspectRatio);
514  returnPvl.addGroup(pPhase);
515  returnPvl.addGroup(pEmission);
516  returnPvl.addGroup(pIncidence);
517  returnPvl.addGroup(pTime);
518  returnPvl.addGroup(pLocalRadius);
519  returnPvl.addGroup(pNorthAzimuth);
520  return returnPvl;
521  }
522 }
Isis::Camera::SetBand
virtual void SetBand(const int band)
Virtual method that sets the band number.
Definition: Camera.cpp:2680
Isis::Statistics
This class is used to accumulate statistics on double arrays.
Definition: Statistics.h:94
Isis::Statistics::AddData
void AddData(const double *data, const unsigned int count)
Add an array of doubles to the accumulators and counters.
Definition: Statistics.cpp:141
Isis::Progress::CheckStatus
void CheckStatus()
Checks and updates the status.
Definition: Progress.cpp:105
Isis::Camera::ObliquePixelResolution
virtual double ObliquePixelResolution()
Returns the oblique pixel resolution at the current position in meters/pixel.
Definition: Camera.cpp:685
Isis::PvlKeyword
A single keyword-value pair.
Definition: PvlKeyword.h:82
Isis::CameraStatistics::m_sinc
int m_sinc
Sample increment for composing statistics.
Definition: CameraStatistics.h:227
Isis::Sensor::HasSurfaceIntersection
bool HasSurfaceIntersection() const
Returns if the last call to either SetLookDirection or SetUniversalGround had a valid intersection wi...
Definition: Sensor.cpp:186
Isis::Camera::SetImage
virtual 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:154
Isis::CameraStatistics::m_emissionStat
Statistics * m_emissionStat
Emission angle statistics.
Definition: CameraStatistics.h:244
Isis::Progress::SetMaximumSteps
void SetMaximumSteps(const int steps)
This sets the maximum number of steps in the process.
Definition: Progress.cpp:85
Isis::CameraStatistics::m_resStat
Statistics * m_resStat
Pixel resolution statistics.
Definition: CameraStatistics.h:239
Isis::Statistics::Maximum
double Maximum() const
Returns the absolute maximum double found in all data passed through the AddData method.
Definition: Statistics.cpp:403
Isis::Camera::ObliqueSampleResolution
virtual double ObliqueSampleResolution()
Returns the oblique sample resolution at the current position in m.
Definition: Camera.cpp:639
Isis::Pvl
Container for cube-like labels.
Definition: Pvl.h:119
Isis::Sensor::LocalSolarTime
double LocalSolarTime()
Return the local solar time in hours.
Definition: Sensor.cpp:660
Isis::Camera
Definition: Camera.h:236
Isis::CameraStatistics::m_obliqueSampleResStat
Statistics * m_obliqueSampleResStat
Oblique sample resolution statistics.
Definition: CameraStatistics.h:236
Isis::CameraStatistics::m_localRaduisStat
Statistics * m_localRaduisStat
Local radius statistics (in meters).
Definition: CameraStatistics.h:247
Isis::CameraStatistics::toPvl
Pvl toPvl() const
Constructs a Pvl object from the values in the various statistics objects.
Definition: CameraStatistics.cpp:367
Isis::toString
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:211
Isis::IsSpecial
bool IsSpecial(const double d)
Returns if the input pixel is special.
Definition: SpecialPixel.h:197
Isis::CameraStatistics::addStats
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...
Definition: CameraStatistics.cpp:239
Isis::CameraStatistics::m_obliqueResStat
Statistics * m_obliqueResStat
Oblique pixel resolution statistics.
Definition: CameraStatistics.h:235
Isis::CameraStatistics::m_phaseStat
Statistics * m_phaseStat
Phase angle statistics.
Definition: CameraStatistics.h:243
Isis::CameraStatistics::m_incidenceStat
Statistics * m_incidenceStat
Incidence angle statistics.
Definition: CameraStatistics.h:245
Isis::PvlGroup
Contains multiple PvlContainers.
Definition: PvlGroup.h:41
Isis::Sensor::UniversalLongitude
virtual double UniversalLongitude() const
Returns the positive east, 0-360 domain longitude, in degrees, at the surface intersection point in t...
Definition: Sensor.cpp:233
Isis::CameraStatistics::m_aspectRatioStat
Statistics * m_aspectRatioStat
Aspect ratio statistics.
Definition: CameraStatistics.h:242
Isis::Statistics::StandardDeviation
double StandardDeviation() const
Computes and returns the standard deviation.
Definition: Statistics.cpp:312
Isis::Statistics::Minimum
double Minimum() const
Returns the absolute minimum double found in all data passed through the AddData method.
Definition: Statistics.cpp:382
Isis::CameraStatistics::m_filename
QString m_filename
FileName of the Cube the Camera was derived from.
Definition: CameraStatistics.h:226
Isis::Camera::LineResolution
virtual double LineResolution()
Returns the line resolution at the current position in meters.
Definition: Camera.cpp:649
Isis::CameraStatistics::~CameraStatistics
virtual ~CameraStatistics()
Destroy this instance, deletes all the Statistics objects.
Definition: CameraStatistics.cpp:160
Isis::CameraStatistics::m_lineResStat
Statistics * m_lineResStat
Line resolution statistics.
Definition: CameraStatistics.h:241
Isis::CameraStatistics::m_linc
int m_linc
Line increment for composing statistics.
Definition: CameraStatistics.h:228
Isis::Camera::NorthAzimuth
double NorthAzimuth()
Returns the North Azimuth.
Definition: Camera.cpp:1893
Isis::Cube
IO Handler for Isis Cubes.
Definition: Cube.h:167
Isis::Sensor::IncidenceAngle
virtual double IncidenceAngle() const
Returns the incidence angle in degrees.
Definition: Sensor.cpp:335
Isis::CameraStatistics::CameraStatistics
CameraStatistics(QString filename, int sinc, int linc)
Constructs the Camera Statistics object from a Cube filename.
Definition: CameraStatistics.cpp:33
Isis::Progress
Program progress reporter.
Definition: Progress.h:42
Isis::Camera::Bands
int Bands() const
Returns the number of bands in the image.
Definition: Camera.cpp:2796
Isis::CameraStatistics::m_northAzimuthStat
Statistics * m_northAzimuthStat
North azimuth statistics.
Definition: CameraStatistics.h:248
Isis::PvlObject::addGroup
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
Definition: PvlObject.h:186
Isis::Camera::IsBandIndependent
virtual bool IsBandIndependent()
Virtual method that checks if the band is independent.
Definition: Camera.cpp:2649
Isis::Camera::Samples
int Samples() const
Returns the number of samples in the image.
Definition: Camera.cpp:2776
Isis::Statistics::Average
double Average() const
Computes and returns the average.
Definition: Statistics.cpp:300
Isis::CameraStatistics::init
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...
Definition: CameraStatistics.cpp:92
Isis::Cube::camera
Camera * camera()
Return a camera associated with the cube.
Definition: Cube.cpp:1451
Isis::CameraStatistics::m_lonStat
Statistics * m_lonStat
Universal longitude statistics.
Definition: CameraStatistics.h:231
Isis::Camera::PixelResolution
virtual double PixelResolution()
Returns the pixel resolution at the current position in meters/pixel.
Definition: Camera.cpp:670
Isis::CameraStatistics::constructKeyword
PvlKeyword constructKeyword(QString keyname, double value, QString unit) const
Takes a name, value, and optionally units and constructs a PVL Keyword.
Definition: CameraStatistics.cpp:281
Isis::Distance::meters
double meters() const
Get the distance in meters.
Definition: Distance.cpp:85
Isis::Sensor::PhaseAngle
virtual double PhaseAngle() const
Returns the phase angle in degrees.
Definition: Sensor.cpp:312
Isis::Camera::Lines
int Lines() const
Returns the number of lines in the image.
Definition: Camera.cpp:2786
Isis::Sensor::EmissionAngle
virtual double EmissionAngle() const
Returns the emission angle in degrees.
Definition: Sensor.cpp:324
Isis::Camera::SampleResolution
virtual double SampleResolution()
Returns the sample resolution at the current position in meters.
Definition: Camera.cpp:629
Isis::CameraStatistics::m_localSolarTimeStat
Statistics * m_localSolarTimeStat
Local solar time statistics.
Definition: CameraStatistics.h:246
Isis::Cube::open
void open(const QString &cfile, QString access="r")
This method will open an isis cube for reading or reading/writing.
Definition: Cube.cpp:627
Isis::Camera::ObliqueLineResolution
virtual double ObliqueLineResolution()
Returns the oblique line resolution at the current position in meters.
Definition: Camera.cpp:661
Isis::CameraStatistics::m_obliqueLineResStat
Statistics * m_obliqueLineResStat
Oblique line resolution statistics.
Definition: CameraStatistics.h:237
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::Pvl::setTerminator
void setTerminator(const QString &term)
Sets the terminator used to signify the end of the PVL informationDefaults to "END".
Definition: Pvl.h:144
Isis::Sensor::LocalRadius
Distance LocalRadius() const
Returns the local radius at the intersection point.
Definition: Sensor.cpp:267
Isis::CameraStatistics::m_sampleResStat
Statistics * m_sampleResStat
Sample resolution statistics.
Definition: CameraStatistics.h:240
Isis::Sensor::UniversalLatitude
virtual double UniversalLatitude() const
Returns the planetocentric latitude, in degrees, at the surface intersection point in the body fixed ...
Definition: Sensor.cpp:210
Isis::CameraStatistics::m_latStat
Statistics * m_latStat
Universal latitude statistics.
Definition: CameraStatistics.h:230