9#include "ControlNetStatistics.h"
14#include <geos/algorithm/ConvexHull.h>
15#include <geos/geom/CoordinateSequence.h>
16#include <geos/geom/Envelope.h>
17#include <geos/geom/Geometry.h>
18#include <geos/geom/GeometryFactory.h>
19#include <geos/geom/Polygon.h>
21#include "ControlNet.h"
22#include "ControlPoint.h"
23#include "ControlMeasure.h"
24#include "ControlMeasureLogData.h"
26#include "CubeManager.h"
31#include "SpecialPixel.h"
32#include "Statistics.h"
37 QString
sPointType [] = {
"Fixed",
"Constrained",
"Free" };
99 for (
int i=0; i<numSn; i++) {
116 pStatsGrp =
PvlGroup(
"ControlNetSummary");
220 geos::geom::GeometryFactory::Ptr geosFactory = geos::geom::GeometryFactory::create();
233 foreach (QString sn, cnetSerials) {
234 geos::geom::CoordinateSequence ptCoordinates;
237 QVector<double> imgStats(numImageStats, 0);
247 double cubeArea = imgStats[imgSamples] * imgStats[imgLines];
252 if (!measures.isEmpty()) {
255 imgStats[imgTotalPoints]++;
256 if (parentPoint->IsIgnored()) {
257 imgStats[imgIgnoredPoints]++;
260 imgStats[imgFixedPoints]++;
263 imgStats[imgConstrainedPoints]++;
266 imgStats[imgFreePoints]++;
268 if (parentPoint->IsEditLocked()) {
269 imgStats[imgLockedPoints]++;
271 if (measure->IsEditLocked()) {
272 imgStats[imgLocked]++;
274 ptCoordinates.add(geos::geom::Coordinate(measure->GetSample(),
275 measure->GetLine()));
278 ptCoordinates.add(geos::geom::Coordinate(measures[0]->GetSample(),
279 measures[0]->GetLine()));
282 if (ptCoordinates.size() >= 4) {
288 geos::geom::Geometry * convexHull = geosFactory->createPolygon(
289 geosFactory->createLinearRing(ptCoordinates))->convexHull().release();
292 imgStats[imgConvexHullArea] = convexHull->getArea();
293 imgStats[imgConvexHullRatio] = imgStats[imgConvexHullArea] / cubeArea;
297 mConvexHullStats.
AddData(imgStats[imgConvexHullArea]);
321 QString msg =
"Serial Number of Images has not been provided to get Image Stats";
327 QString outName(outFile.expanded());
328 ostm.open(outName.toLatin1().data(), std::ios::out);
331 QString msg = QObject::tr(
"Cannot open file [%1]").arg(psImageFile);
339 ostm <<
"Filename, SerialNumber, TotalPoints, PointsIgnored, PointsEditLocked, Fixed, Constrained, Free, ConvexHullRatio" << endl;
344 bool serialNumExists = it.value();
345 if (serialNumExists) {
346 QVector<double> imgStats =
mImageMap[(it).key()] ;
347 ostm << imgStats[imgTotalPoints]<<
", " << imgStats[imgIgnoredPoints] <<
", " ;
348 ostm << imgStats[imgLockedPoints] <<
", " << imgStats[imgFixedPoints] <<
", " ;
349 ostm << imgStats[imgConstrainedPoints] <<
", " << imgStats[imgFreePoints] <<
", ";
350 ostm << imgStats[imgConvexHullRatio] << endl;
353 ostm <<
"0, 0, 0, 0, 0, 0, 0" << endl;
358 QString msg = QObject::tr(
"Error writing to file: [%1]").arg(psImageFile);
375 return (
mImageMap.find(psSerialNum)).value();
392 QString outName(outFile.expanded());
393 ostm.open(outName.toLatin1().data(), std::ios::out);
396 QString msg = QObject::tr(
"Cannot open file [%1]").arg(psPointFile);
400 ostm <<
" PointId, PointType, PointIgnore, PointEditLock, TotalMeasures, MeasuresValid, MeasuresIgnore, MeasuresEditLock" << endl;
405 if (
mProgress != NULL && iNumPoints > 0) {
411 for (
int i = 0; i < iNumPoints; i++) {
413 int iNumMeasures = cPoint->GetNumMeasures();
414 int iValidMeasures = cPoint->GetNumValidMeasures();
415 int iIgnoredMeasures = iNumMeasures - iValidMeasures;
418 ostm << cPoint->GetId() <<
", " <<
sPointType[(int)cPoint->GetType()] <<
", " <<
sBoolean[(int)cPoint->IsIgnored()] <<
", " ;
419 ostm <<
sBoolean[(int)cPoint->IsEditLocked()] <<
", " << iNumMeasures <<
", " << iValidMeasures <<
", ";
420 ostm << iIgnoredMeasures <<
", " << cPoint->GetNumLockedMeasures() << endl;
428 QString msg = QObject::tr(
"Error writing to file: [%1]").arg(psPointFile);
445 for (
int i=0; i<numPointIntStats; i++) {
454 for (
int i = 0; i < iNumPoints; i++) {
455 if (!
mCNet->GetPoint(i)->IsIgnored()) {
477 if (
mCNet->GetPoint(i)->IsEditLocked()) {
501 for (
int i = 0; i < numPointDblStats; i++) {
522 for (
int i = 0; i < iNumPoints; i++) {
525 if (!cp->IsIgnored()) {
526 for (
int cmIndex = 0; cmIndex < cp->GetNumMeasures(); cmIndex++) {
529 if (!cm->IsIgnored()) {
530 residualMagStats.AddData(cm->GetResidualMagnitude());
533 pixelShiftStats.AddData(fabs(cm->GetPixelShift()));
540 UpdateMinMaxStats(resMagStats, minResidual, maxResidual);
543 &ControlMeasure::GetLineResidual);
544 UpdateMinMaxStats(resLineStats, minLineResidual, maxLineResidual);
547 &ControlMeasure::GetSampleResidual);
548 UpdateMinMaxStats(resSampStats, minSampleResidual, maxSampleResidual);
551 &ControlMeasure::GetPixelShift);
552 UpdateMinMaxStats(pixShiftStats, minPixelShift, maxPixelShift);
555 &ControlMeasure::GetLineShift);
556 UpdateMinMaxStats(lineShiftStats, minLineShift, maxLineShift);
559 &ControlMeasure::GetSampleShift);
560 UpdateMinMaxStats(sampShiftStats, minSampleShift, maxSampleShift);
564 UpdateMinMaxStats(gFitStats, minGFit, maxGFit);
566 Statistics minPixelZScoreStats = cp->GetStatistic(
569 if (minPixelZScoreStats.ValidPixels()) {
570 dValue = fabs(minPixelZScoreStats.Minimum());
575 Statistics maxPixelZScoreStats = cp->GetStatistic(
578 if (maxPixelZScoreStats.ValidPixels()) {
579 dValue = fabs(maxPixelZScoreStats.Maximum());
593 void ControlNetStatistics::UpdateMinMaxStats(
const Statistics & stats,
594 ePointDoubleStats min, ePointDoubleStats max) {
595 if (stats.ValidPixels()) {
double GetResidualMagnitude() const
Return Residual magnitude.
@ MinimumPixelZScore
Control measures store z-scores in pairs.
@ GoodnessOfFit
GoodnessOfFit is pointreg information for reference measures.
int GetNumEditLockPoints()
Returns the number of edit locked control points.
int GetNumPoints() const
Return the number of control points in the network.
QList< ControlMeasure * > GetMeasuresInCube(QString serialNumber)
Get all the measures pertaining to a given cube serial number.
QList< QString > GetCubeSerials() const
Use this method to get a complete list of all the cube serial numbers in the network.
int GetNumEditLockMeasures()
Return the total number of edit locked measures for all control points in the network.
ControlNet * mCNet
Control Network.
int NumFixedPoints() const
Returns the Number of Fixed Points in the Control Net.
int NumValidPoints() const
Returns the Number of Valid (Not Ignored) Points in the Control Net.
double GetMinLineShift() const
Get Min and Max LineShift.
double GetMinimumResidual() const
Determine the minimum error of all points in the network.
double GetMaximumResidual() const
Determine the maximum error of all points in the network.
QMap< QString, QVector< double > > mImageMap
Contains stats by Image/Serial Num.
int NumFreePoints() const
Returns the number of Constrained Points in Control Net.
Statistics mConvexHullRatioStats
min, max, average convex hull stats
QVector< double > GetImageStatsBySerialNum(QString psSerialNum) const
Returns the Image Stats by Serial Number.
int NumValidMeasures() const
Returns the total Number of valid Measures in the Control Net.
double GetAvgPixelShift() const
Get network Avg PixelShift.
void PrintImageStats(const QString &psImageFile)
Print the Image Stats into specified output file.
void GetPointDoubleStats()
Get Point stats for Residuals and Shifts.
double GetMinSampleResidual() const
Determine the minimum sample error of all points in the network.
int NumIgnoredMeasures() const
Returns the total Number of Ignored Measures in the Control Net.
void InitPointDoubleStats()
Init Pointstats std::vector.
double GetMaxLineResidual() const
Determine the maximum line error of all points in the network.
void InitSerialNumMap()
Init SerialNum std::map.
double GetMaxLineShift() const
Get network Max LineShift.
QMap< int, int > mPointIntStats
Contains QMap of different count stats.
double GetMaxSampleResidual() const
Determine the maximum sample error of all points in the network.
void GenerateControlNetStats(PvlGroup &pStatsGrp)
Generate the Control Net Stats into the PvlGroup.
double GetMinPixelShift() const
Get network Min PixelShift.
double GetMaxSampleShift() const
Get network Max SampleShift.
int NumConstrainedPoints() const
Returns the number of Constrained Points in Control Net.
void GenerateImageStats()
Generate stats like Total, Ignored, Fixed Points in an Image.
SerialNumberList mSerialNumList
Serial Number List.
QMap< int, double > mPointDoubleStats
Contains QMap of different computed stats.
QMap< QString, bool > mSerialNumMap
Whether serial# is part of ControlNet.
void GeneratePointStats(const QString &psPointFile)
Generate stats like Ignored, Fixed, Total Measures, Ignored by Control Point.
Progress * mProgress
Progress state.
double GetAverageResidual() const
Determine the average error of all points in the network.
int NumMeasures() const
Returns the total Number of Measures in the Control Net.
double GetMaxPixelShift() const
Get network Max PixelShift.
double GetMinSampleShift() const
Get network Min SampleShift.
double GetMinLineResidual() const
Determine the minimum line error of all points in the network.
~ControlNetStatistics()
Destructor.
ControlNetStatistics(ControlNet *pCNet, const QString &psSerialNumFile, Progress *pProgress=0)
Constructor.
void GetPointIntStats()
Get point count stats.
PointType GetType() const
@ Constrained
A Constrained point is a Control Point whose lat/lon/radius is somewhat established and should not be...
@ Free
A Free point is a Control Point that identifies common measurements between two or more cubes.
@ Fixed
A Fixed point is a Control Point whose lat/lon is well established and should not be changed.
IO Handler for Isis Cubes.
Class for quick re-accessing of cubes based on file name.
void SetNumOpenCubes(unsigned int numCubes)
This sets the maximum number of opened cubes for this instance of CubeManager.
File name manipulation and expansion.
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
@ Io
A type of error that occurred when performing an actual I/O operation.
Program progress reporter.
void SetMaximumSteps(const int steps)
This sets the maximum number of steps in the process.
void SetText(const QString &text)
Changes the value of the text string reported just before 0% processed.
void CheckStatus()
Checks and updates the status.
Contains multiple PvlContainers.
A single keyword-value pair.
Serial Number list generator.
QString serialNumber(const QString &filename)
Return a serial number given a filename.
int size() const
How many serial number / filename combos are in the list.
QString fileName(const QString &sn)
Return a filename given a serial number.
This class is used to accumulate statistics on double arrays.
double Average() const
Computes and returns the average.
double Minimum() const
Returns the absolute minimum double found in all data passed through the AddData method.
void AddData(const double *data, const unsigned int count)
Add an array of doubles to the accumulators and counters.
double Maximum() const
Returns the absolute maximum double found in all data passed through the AddData method.
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
QString sPointType[]
String names for Point Type.
const double Null
Value for an Isis Null pixel.
QString sBoolean[]
String values for Boolean.
bool IsSpecial(const double d)
Returns if the input pixel is special.