7 #include "OverlapStatistics.h"
15 #include "IException.h"
16 #include "MultivariateStatistics.h"
18 #include "Projection.h"
19 #include "ProjectionFactory.h"
21 #include "PvlKeyword.h"
22 #include "PvlObject.h"
32 OverlapStatistics::OverlapStatistics(
const PvlObject &inStats) {
52 QString progressMsg,
double sampPercent) {
57 if (sampPercent <= 0.0 || sampPercent > 100.0) {
58 string msg =
"The sampling percent must be a decimal (0.0, 100.0]";
59 throw IException(IException::Programmer, msg, _FILEINFO_);
62 p_sampPercent = sampPercent;
70 QString msg =
"Number of bands do not match between cubes [" +
71 p_xFile.name() +
"] and [" + p_yFile.name() +
"]";
72 throw IException(IException::User, msg, _FILEINFO_);
75 p_stats.resize(p_bands);
82 if (*projX != *projY) {
83 QString msg =
"Mapping groups do not match between cubes [" +
84 p_xFile.name() +
"] and [" + p_yFile.name() +
"]";
85 throw IException(IException::Programmer, msg, _FILEINFO_);
100 if ((Xmin1 < Xmax2) && (Xmax1 > Xmin2) && (Ymin1 < Ymax2) && (Ymax1 > Ymin2)) {
101 double minX = Xmin1 > Xmin2 ? Xmin1 : Xmin2;
102 double minY = Ymin1 > Ymin2 ? Ymin1 : Ymin2;
103 double maxX = Xmax1 < Xmax2 ? Xmax1 : Xmax2;
104 double maxY = Ymax1 < Ymax2 ? Ymax1 : Ymax2;
107 p_minSampX = (int)(projX->
ToWorldX(minX) + 0.5);
108 p_maxSampX = (int)(projX->
ToWorldX(maxX) + 0.5);
109 p_minSampY = (int)(projY->
ToWorldX(minX) + 0.5);
110 p_maxSampY = (int)(projY->
ToWorldX(maxX) + 0.5);
111 p_sampRange = p_maxSampX - p_minSampX + 1;
114 if (p_sampRange <= 0)
return;
117 p_minLineX = (int)(projX->
ToWorldY(maxY) + 0.5);
118 p_maxLineX = (int)(projX->
ToWorldY(minY) + 0.5);
119 p_minLineY = (int)(projY->
ToWorldY(maxY) + 0.5);
120 p_maxLineY = (int)(projY->
ToWorldY(minY) + 0.5);
121 p_lineRange = p_maxLineX - p_minLineX + 1;
127 int linc = (int)(100.0 / sampPercent + 0.5);
132 int maxSteps = (int)(p_lineRange / linc + 0.5);
134 if (p_lineRange % linc != 0) maxSteps += 1;
142 for (
int band = 1; band <= p_bands; band++) {
147 while(i < p_lineRange) {
155 if (i + linc > p_lineRange - 1 && i != p_lineRange - 1) {
175 bool OverlapStatistics::HasOverlap()
const {
176 for (
int b = 0; b < p_bands; b++) {
177 if (p_stats[b].ValidPixels() > 0)
return true;
192 PvlObject OverlapStatistics::toPvl(QString name)
const {
195 if (name.isEmpty()) {
196 name =
"OverlapStatistics";
218 for (
int band = 1; band <= Bands(); band++) {
219 if (HasOverlap(band)) {
221 stdX +=
toString(GetMStats(band).X().StandardDeviation());
222 varX +=
toString(GetMStats(band).X().Variance());
242 for (
int band = 1; band <= Bands(); band++) {
243 if (HasOverlap(band)) {
245 stdY +=
toString(GetMStats(band).Y().StandardDeviation());
246 varY +=
toString(GetMStats(band).Y().Variance());
260 bool isValid =
false;
262 for (
int band = 1; band <= Bands(); band++) {
263 PvlKeyword validBand(
"ValidOverlap",
"false");
265 if (HasOverlap(band)) {
272 QString mStatsName =
"MultivariateStatistics" +
toString(band);
273 PvlObject mStats(GetMStats(band).toPvl(mStatsName));
277 PvlKeyword valid(
"Valid", (isValid) ?
"true" :
"false");
283 QString msg =
"Trivial overlap between [" + FileNameX().
name();
284 msg +=
"] and [" + FileNameY().name() +
"]";
285 throw IException(IException::User, msg, _FILEINFO_);
295 void OverlapStatistics::fromPvl(
const PvlObject &inStats) {
300 p_xFile = inStats[
"File1"][0];
301 p_yFile = inStats[
"File2"][0];
302 p_sampRange = inStats[
"Width"];
303 p_lineRange = inStats[
"Height"];
304 p_bands = inStats[
"Bands"];
305 p_sampPercent = inStats[
"SamplingPercent"];
307 p_minSampX = fileX[
"StartSample"];
308 p_maxSampX = fileX[
"EndSample"];
309 p_minLineX = fileX[
"StartLine"];
310 p_maxLineX = fileX[
"EndLine"];
312 p_minSampY = fileY[
"StartSample"];
313 p_maxSampY = fileY[
"EndSample"];
314 p_minLineY = fileY[
"StartLine"];
315 p_maxLineY = fileY[
"EndLine"];
317 p_mincnt = inStats[
"MinCount"];
320 for (
int band = 1; band <= Bands(); band++) {
321 QString name =
"MultivariateStatistics" +
toString(band);
332 void OverlapStatistics::init() {