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();
228 mProgress->SetText(
"Generating Image Stats.....");
229 mProgress->SetMaximumSteps(cnetSerials.size());
233 foreach (QString sn, cnetSerials) {
234 geos::geom::CoordinateSequence ptCoordinates;
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]++;
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;
343 ostm <<
mSerialNumList.fileName(it.key()) <<
", " << it.key() <<
", ";
344 bool serialNumExists = it.value();
345 if (serialNumExists) {
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;
402 int iNumPoints =
mCNet->GetNumPoints();
405 if (
mProgress != NULL && iNumPoints > 0) {
406 mProgress->SetText(
"Point Stats: Loading Control Points...");
411 for (
int i = 0; i < iNumPoints; i++) {
413 int iNumMeasures = cPoint->GetNumMeasures();
415 int iIgnoredMeasures = iNumMeasures - iValidMeasures;
419 ostm <<
sBoolean[(int)cPoint->IsEditLocked()] <<
", " << iNumMeasures <<
", " << iValidMeasures <<
", ";
428 QString msg = QObject::tr(
"Error writing to file: [%1]").arg(psPointFile);
445 for (
int i=0; i<numPointIntStats; i++) {
449 int iNumPoints =
mCNet->GetNumPoints();
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++) {
516 int iNumPoints =
mCNet->GetNumPoints();
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()) {
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);
570 dValue = fabs(minPixelZScoreStats.
Minimum());
579 dValue = fabs(maxPixelZScoreStats.
Maximum());
593 void ControlNetStatistics::UpdateMinMaxStats(
const Statistics & stats,
594 ePointDoubleStats min, ePointDoubleStats max) {
bool IsEditLocked() const
Return value for p_editLock or implicit lock on reference measure.
double GetResidualMagnitude() const
Return Residual magnitude.
@ MinimumPixelZScore
Control measures store z-scores in pairs.
@ GoodnessOfFit
GoodnessOfFit is pointreg information for reference measures.
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.
int GetNumValidMeasures() const
int GetNumLockedMeasures() const
Returns the number of locked control measures.
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.
const ControlMeasure * GetMeasure(QString serialNumber) const
Get a control measure based on its cube's serial number.
Statistics GetStatistic(double(ControlMeasure::*statFunc)() const) const
This function will call a given method on every control measure that this point has.
QString GetId() const
Return the Id of the control point.
IO Handler for Isis Cubes.
Class for quick re-accessing of cubes based on file name.
Cube * OpenCube(const QString &cubeFileName)
This method opens a cube.
void SetNumOpenCubes(unsigned int numCubes)
This sets the maximum number of opened cubes for this instance of CubeManager.
File name manipulation and expansion.
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
@ 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.
Contains multiple PvlContainers.
A single keyword-value pair.
Serial Number list generator.
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.
BigInt ValidPixels() const
Returns the total number of valid pixels processed.
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.
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.