USGS

Isis 3.0 Application Source Code Reference

Home

CnetRefByResolution.cpp
Go to the documentation of this file.
1 #include "Application.h"
2 #include "ControlNet.h"
3 #include "ControlPoint.h"
4 #include "ControlMeasure.h"
5 #include "PvlGroup.h"
6 #include "Camera.h"
7 #include "MeasureValidationResults.h"
8 #include "Portal.h"
9 #include "SpecialPixel.h"
10 #include "Pvl.h"
11 #include "SerialNumberList.h"
12 
13 #include "CnetRefByResolution.h"
14 
15 using namespace std;
16 
17 namespace Isis {
18  /**
19  * CnetRefByResolution constructor with the def file
20  *
21  * @author Sharmila Prasad (5/25/2010)
22  *
23  * @param pPvlDef - Pvl Definition File
24  * @param psSerialNumfile - Serial Number file attached to the ControlNet
25  * @param peType - Resolution Type
26  * @param pdResValue - Resolution value
27  * @param pdMinRes - Min Resolution value
28  * @param pdMaxRes - Max Resolution value
29  */
30  CnetRefByResolution::CnetRefByResolution(Pvl *pPvlDef, QString psSerialNumfile,
31  ResolutionType peType, double pdResValue, double pdMinRes, double pdMaxRes)
32  : ControlNetValidMeasure(pPvlDef) {
33  mdResValue = pdResValue;
34  mdMinRes = pdMinRes;
35  mdMaxRes = pdMaxRes;
36  meType = peType;
37  ReadSerialNumbers(psSerialNumfile);
38  SetCameraRequiredFlag(true);
39  }
40 
41  /**
42  * FindCnetRef traverses all the control points and measures in the network and checks for
43  * valid Measure which passes the Emission Incidence Angle, DN value tests and chooses the
44  * measure with the best Resolution criteria as the reference. Creates a new control network
45  * with these adjustments.
46  *
47  * @author Sharmila Prasad (5/25/2010)
48  * @history 2010-10-04 Sharmila Prasad - Modified for Binary CNet (Edit Lock)
49  *
50  * @param pNewNet - Modified output Control Net
51  *
52  */
53  void CnetRefByResolution::FindCnetRef(ControlNet &pNewNet) {
54  // Process each existing control point in the network
55  int iPointsModified = 0;
56  int iMeasuresModified = 0;
57  int iRefChanged = 0;
58 
59  //Status Report
60  mStatus.SetText("Choosing Reference by Resolution...");
61  mStatus.SetMaximumSteps(pNewNet.GetNumPoints());
62  mStatus.CheckStatus();
63 
64  //mPvlLog += GetStdOptions();
65  for (int point = 0; point < pNewNet.GetNumPoints(); ++point) {
66  ControlPoint *newPnt = pNewNet.GetPoint(point);
67  bool bError = false;
68 
69  // Create a copy of original control point
70  const ControlPoint origPnt(*newPnt);
71 
72  mdResVector.clear();
73 
74  // Logging
75  PvlObject pvlPointObj("PointDetails");
76  pvlPointObj += Isis::PvlKeyword("PointId", newPnt->GetId());
77 
78  // Edit Lock Option
79  bool bPntEditLock = newPnt->IsEditLocked();
80  if (!bPntEditLock) {
81  newPnt->SetDateTime(Application::DateTime());
82  }
83  else {
84  pvlPointObj += Isis::PvlKeyword("Reference", "No Change, PointEditLock");
85  }
86 
87  int iNumMeasuresLocked = newPnt->GetNumLockedMeasures();
88  bool bRefLocked = newPnt->GetRefMeasure()->IsEditLocked();
89  int numMeasures = newPnt->GetNumMeasures();
90 
91  int iRefIndex = -1;
92  if (newPnt->IsReferenceExplicit())
93  iRefIndex = newPnt->IndexOfRefMeasure();
94  QString istrTemp;
95 
96  std::vector <PvlGroup> pvlGrpVector;
97  int iBestIndex = 0;
98 
99  // Only perform the interest operation on points of type "Free" and
100  // Points having atleast 1 measure and Point is not Ignored
101  // Check for EditLock in the Measures and also verfify that
102  // only a Reference Measure can be Locked else error
103  if (!newPnt->IsIgnored() && newPnt->GetType() == ControlPoint::Free && numMeasures > 0 &&
104  (iNumMeasuresLocked == 0 || (iNumMeasuresLocked > 0 && bRefLocked))) {
105  int iNumIgnore = 0;
106  QString istrTemp;
107  for (int measure = 0; measure < newPnt->GetNumMeasures(); ++measure) {
108  ControlMeasure *newMsr = newPnt->GetMeasure(measure);
109  bool bMeasureLocked = newMsr->IsEditLocked();
110  double dSample = newMsr->GetSample();
111  double dLine = newMsr->GetLine();
112  QString sn = newMsr->GetCubeSerialNumber();
113 
114  if (!bPntEditLock && !bMeasureLocked) {
115  newMsr->SetDateTime(Application::DateTime());
116  newMsr->SetChooserName("Application cnetref(Resolution)");
117  }
118 
119  // Log
120  PvlGroup pvlMeasureGrp("MeasureDetails");
121  pvlMeasureGrp += Isis::PvlKeyword("SerialNum", sn);
122  pvlMeasureGrp += Isis::PvlKeyword("OriginalLocation", LocationString(dSample, dLine));
123 
124  if (bMeasureLocked)
125  pvlMeasureGrp += Isis::PvlKeyword("EditLock", "True");
126 
127  if (!newMsr->IsIgnored()) {
128  Cube *measureCube = mCubeMgr.OpenCube(mSerialNumbers.fileName(sn));
129 
130  MeasureValidationResults results =
131  ValidStandardOptions(newMsr, measureCube, &pvlMeasureGrp);
132  if (!results.isValid()) {
133  if (bPntEditLock) {
134  pvlMeasureGrp += Isis::PvlKeyword("UnIgnored", "Failed Validation Test but not Ignored as Point EditLock is True");
135  }
136  else if (bMeasureLocked) {
137  pvlMeasureGrp += Isis::PvlKeyword("UnIgnored", "Failed Validation Test but not Ignored as Measure EditLock is True");
138  }
139  else {
140  pvlMeasureGrp += Isis::PvlKeyword("Ignored", "For point [" + newPnt->GetId() + "] and measure [" + sn +
141  "], point failed to intersect body.");
142  newMsr->SetIgnored(true);
143  iNumIgnore++;
144  }
145  } // valid measure
146  else {
147  if (!bPntEditLock && !bRefLocked) {
148  newMsr->SetType(ControlMeasure::Candidate);
149  newMsr->SetIgnored(false);
150  mdResVector.push_back(mdResolution);
151  }
152  }
153  } // Ignore == false
154  else {
155  pvlMeasureGrp += Isis::PvlKeyword("Ignored", "Originally Ignored");
156  iNumIgnore++;
157  }
158  if (newMsr != origPnt.GetMeasure(measure)) {
159  iMeasuresModified++;
160  }
161 
162  //newPnt.UpdateMeasure(newMsr); // Redesign fixed this
163  pvlGrpVector.push_back(pvlMeasureGrp);
164  }// end Measure
165 
166  if ((newPnt->GetNumMeasures() - iNumIgnore) < 2) {
167  if (bPntEditLock) {
168  pvlPointObj += Isis::PvlKeyword("UnIgnored", "Good Measures less than 2 but not Ignored as Point EditLock is True");
169  }
170  else {
171  newPnt->SetIgnored(true);
172  pvlPointObj += Isis::PvlKeyword("Ignored", "Good Measures less than 2");
173  }
174  }
175  // Set the Reference if the Point is unlocked and Reference measure is unlocked
176  if (!newPnt->IsIgnored() && !bPntEditLock && !bRefLocked) {
177  iBestIndex = GetReferenceByResolution(newPnt);
178  if (iBestIndex >= 0 && !newPnt->GetMeasure(iBestIndex)->IsIgnored()) {
179  newPnt->SetRefMeasure(iBestIndex);
180  //newPnt.UpdateMeasure(cm); // Redesign fixed this
181  pvlGrpVector[iBestIndex] += Isis::PvlKeyword("Reference", "true");
182  }
183  else {
184  if (iBestIndex < 0 && meType == Range) {
185  pvlPointObj += Isis::PvlKeyword("NOTE", "No Valid Measures within the Resolution Range. Reference defaulted to the first Measure");
186  }
187  iBestIndex = 0;
188  newPnt->SetRefMeasure(iBestIndex);
189  //newPnt.UpdateMeasure(cm); // Redesign fixed this
190 
191  // Log info, if Point not locked, apriori source == Reference and a new reference
192  if (iRefIndex != iBestIndex &&
193  newPnt->GetAprioriSurfacePointSource() == ControlPoint::SurfacePointSource::Reference) {
194  pvlGrpVector[iBestIndex] += Isis::PvlKeyword("AprioriSource", "Reference is the source and has changed");
195  }
196  }
197  }
198 
199  for (int i = 0; i < newPnt->GetNumMeasures(); i++) {
200  pvlPointObj += pvlGrpVector[i];
201  }
202  } // end Free
203  else {
204  int iComment = 0;
205  if (numMeasures == 0) {
206  QString sComment = "Comment";
207  sComment += QString(++iComment);
208  pvlPointObj += Isis::PvlKeyword(sComment, "No Measures in the Point");
209  }
210 
211  if (newPnt->IsIgnored()) {
212  QString sComment = "Comment";
213  sComment += QString(++iComment);
214  pvlPointObj += Isis::PvlKeyword(sComment, "Point was originally Ignored");
215  }
216 
217  if (newPnt->GetType() == ControlPoint::Fixed) {
218  QString sComment = "Comment";
219  sComment += QString(++iComment);
220  pvlPointObj += Isis::PvlKeyword(sComment, "Fixed Point");
221  }
222  else if (newPnt->GetType() == ControlPoint::Constrained) {
223  QString sComment = "Comment";
224  sComment += QString(++iComment);
225  pvlPointObj += Isis::PvlKeyword(sComment, "Constrained Point");
226  }
227 
228  if (iNumMeasuresLocked > 0 && !bRefLocked) {
229  pvlPointObj += Isis::PvlKeyword("Error", "Point has a Measure with EditLock set to true "
230  "but the Reference is not Locked");
231  bError = true;
232  }
233  else {
234  for (int measure = 0; measure < newPnt->GetNumMeasures(); measure++) {
235  ControlMeasure *cm = newPnt->GetMeasure(iBestIndex);
236  cm->SetDateTime(Application::DateTime());
237  cm->SetChooserName("Application cnetref(Resolution)");
238  //newPnt.UpdateMeasure(cm); // Redesign fixed this
239  }
240  }
241  }
242 
243  if (*newPnt != origPnt) {
244  iPointsModified++;
245  }
246 
247  if (!bError && !newPnt->IsIgnored() && newPnt->IsReferenceExplicit() && iBestIndex != iRefIndex
248  && !bPntEditLock && !bRefLocked) {
249  iRefChanged++;
250  PvlGroup pvlRefChangeGrp("ReferenceChangeDetails");
251  if (iRefIndex >= 0) {
252  pvlRefChangeGrp += Isis::PvlKeyword("PrevSerialNumber",
253  origPnt.GetMeasure(iRefIndex)->GetCubeSerialNumber());
254  pvlRefChangeGrp += Isis::PvlKeyword("PrevResolution", toString(mdResVector[iRefIndex]));
255 
256  istrTemp = QString((int)origPnt.GetMeasure(iRefIndex)->GetSample());
257  istrTemp += ",";
258  istrTemp += QString((int)origPnt.GetMeasure(iRefIndex)->GetLine());
259  pvlRefChangeGrp += Isis::PvlKeyword("PrevLocation", istrTemp);
260  }
261  else {
262  pvlRefChangeGrp += Isis::PvlKeyword("PrevReference", "Not Set");
263  }
264 
265  pvlRefChangeGrp += Isis::PvlKeyword("NewSerialNumber",
266  newPnt->GetMeasure(iBestIndex)->GetCubeSerialNumber());
267  QString sKeyName = "NewHighestResolution";
268  if (meType == Low) {
269  sKeyName = "NewLeastResolution";
270  }
271  else if (meType == Mean) {
272  pvlRefChangeGrp += Isis::PvlKeyword("MeanResolution", toString(GetMeanResolution()));
273  sKeyName = "NewResolutionNeartoMean";
274  }
275  else if (meType == Nearest) {
276  sKeyName = "NewResolutionNeartoValue";
277  }
278  else if (meType == Range) {
279  sKeyName = "NewResolutionInRange";
280  }
281  pvlRefChangeGrp += Isis::PvlKeyword(sKeyName, toString(mdResVector[iBestIndex]));
282 
283  istrTemp = QString((int)newPnt->GetMeasure(iBestIndex)->GetSample());
284  istrTemp += ",";
285  istrTemp += QString((int)newPnt->GetMeasure(iBestIndex)->GetLine());
286  pvlRefChangeGrp += Isis::PvlKeyword("NewLocation", istrTemp);
287 
288  pvlPointObj += pvlRefChangeGrp;
289  }
290  else {
291  pvlPointObj += Isis::PvlKeyword("Reference", "No Change");
292  }
293 
294  //pNewNet.UpdatePoint(newPnt); // Redesign fixed this
295  mPvlLog += pvlPointObj;
296  mStatus.CheckStatus();
297  }// end Point
298 
299  // CnetRef Change Statistics
300  mStatisticsGrp += Isis::PvlKeyword("PointsModified", toString(iPointsModified));
301  mStatisticsGrp += Isis::PvlKeyword("ReferenceChanged", toString(iRefChanged));
302  mStatisticsGrp += Isis::PvlKeyword("MeasuresModified", toString(iMeasuresModified));
303 
304  mPvlLog += mStatisticsGrp;
305  }
306 
307  /**
308  * GetMeanResolution - Get Mean of all the resolutions of all the measures
309  * in the Control Point
310  *
311  * @author Sharmila Prasad (6/1/2010)
312  *
313  * @return double
314  */
316  double dTotal = 0;
317  for (int i = 0; i < (int)mdResVector.size(); i++) {
318  dTotal += mdResVector[i];
319  }
320 
321  return (dTotal / mdResVector.size());
322  }
323 
324  /**
325  * GetReferenceByResolution - Get the Reference for each Control Point by user defined
326  * Resolution criteria
327  *
328  * @author Sharmila Prasad (6/1/2010)
329  *
330  * @return int
331  */
332  int CnetRefByResolution::GetReferenceByResolution(ControlPoint *pNewPoint) {
333  int iBestIndex = -1;
334  double dBestResolution = -1;
335  double dMean = 0;
336  if (meType == Mean) {
337  dMean = GetMeanResolution();
338  }
339 
340  for (int i = 0; i < (int)mdResVector.size(); i++) {
341  if (pNewPoint->GetMeasure(i)->IsIgnored()) {
342  continue;
343  }
344  else {
345  double dDiff = dBestResolution - mdResVector[i];
346  if (meType == Low) {
347  if (dBestResolution == -1 || dDiff < 0) {
348  dBestResolution = mdResVector[i];
349  iBestIndex = i;
350  }
351  }
352  else if (meType == High) {
353  double dDiff = dBestResolution - mdResVector[i];
354  if (dBestResolution == -1 || dDiff > 0) {
355  dBestResolution = mdResVector[i];
356  iBestIndex = i;
357  }
358  }
359  else if (meType == Mean) {
360  if ((int)mdResVector.size() == 2) {
361  // Arbitrarily assign the 1st measure to be reference for a point with only 2 measures
362  iBestIndex = 0;
363  }
364  else {
365  double dDiff = fabs(dMean - mdResVector[i]);
366  if (dBestResolution == -1 || dDiff < dBestResolution) {
367  dBestResolution = dDiff;
368  iBestIndex = i;
369  }
370  }
371  }
372  else if (meType == Nearest) {
373  double dDiff = fabs(mdResValue - mdResVector[i]);
374  if (dBestResolution == -1 || dDiff < dBestResolution) {
375  dBestResolution = dDiff;
376  iBestIndex = i;
377  }
378  }
379  else if (meType == Range) {
380  if (mdResVector[i] >= mdMinRes && mdResVector[i] <= mdMaxRes) {
381  iBestIndex = i;
382  return iBestIndex;
383  }
384  }
385  }
386  }
387  return iBestIndex;
388  }
389 };
390 
double GetMeanResolution(void)
Get the Mean of all the Resolution in a Point.
PvlGroup results("Results")
ResolutionType
Enumeration containing different Resolution Types.
virtual void FindCnetRef(ControlNet &pNewNet)
Given Control Net, find the reference based on Resolution.