USGS

Isis 3.0 Object Programmers' Reference

Home

ControlPointList.cpp
1 #include "ControlPointList.h"
2 
3 #include <QList>
4 
5 #include "IException.h"
6 #include "FileList.h"
7 #include "FileName.h"
8 #include "IString.h"
9 
10 namespace Isis {
17  try {
18  QList<QString> qList;
19  FileList list(psListFile);
20  int size = list.size();
21  for(int i = 0; i < size; i++) {
22  qList.insert(i, list[i].toString());
23  mbFound.push_back(false);
24  }
25  mqCpList = QStringList(qList);
26 
27  //sort the list for faster searches - internally uses qsort()
28  mqCpList.sort();
29  }
30  catch(IException &e) {
31  QString msg = "Can't open or invalid file list [" +
32  psListFile.expanded() + "]";
33  throw IException(e, IException::User, msg, _FILEINFO_);
34  }
35  }
36 
41  }
42 
43 
52  bool ControlPointList::HasControlPoint(const QString &psCpId) {
53  int index = mqCpList.indexOf(QString(psCpId));
54 
55  if(index == -1 || index >= Size())
56  return false;
57 
58  mbFound[index] = true;
59  return true;
60  }
61 
62 
68  int ControlPointList::Size() const {
69  return mqCpList.size();
70  }
71 
72 
80  QString ControlPointList::ControlPointId(int piIndex) {
81  int size = Size();
82  if(piIndex >= 0 && piIndex < size) {
83  return (mqCpList.value(piIndex));
84  }
85  else {
86  QString num = toString(piIndex);
87  QString msg = "Index [" + num + "] is invalid";
89  }
90  }
91 
99  int ControlPointList::ControlPointIndex(const QString &psCpId) {
100  if(HasControlPoint(psCpId)) {
101  return mqCpList.indexOf(QString(psCpId));
102  }
103  else {
104  QString msg = "Requested control point id [" + psCpId + "] ";
105  msg += "does not exist in the list";
107  }
108  }
109 
117  int size = Size();
118  int iNotFound = 0;
119  QString sPointsNotFound = "";
120 
121  for(int i = 0; i < size; i++) {
122  if(!mbFound[i]) {
123  if(iNotFound) {
124  sPointsNotFound += ", ";
125  }
126  sPointsNotFound += mqCpList.value(i);
127  iNotFound++;
128  }
129  }
130 
131  pcPvlLog += Isis::PvlKeyword("TotalPoints", toString(size));
132  pcPvlLog += Isis::PvlKeyword("ValidPoints", toString(size - iNotFound));
133  pcPvlLog += Isis::PvlKeyword("InvalidPoints", toString(iNotFound));
134  pcPvlLog += Isis::PvlKeyword("InvalidPointIds", sPointsNotFound);
135  }
136 }
137