Isis 3 Programmer Reference
ControlPointList.cpp
1
7/* SPDX-License-Identifier: CC0-1.0 */
8
9#include "ControlPointList.h"
10
11#include <QList>
12
13#include "IException.h"
14#include "FileList.h"
15#include "FileName.h"
16#include "IString.h"
17
18namespace Isis {
25 try {
26 QList<QString> qList;
27 FileList list(psListFile);
28 int size = list.size();
29 for(int i = 0; i < size; i++) {
30 qList.insert(i, list[i].toString());
31 mbFound.push_back(false);
32 }
33 mqCpList = QStringList(qList);
34
35 //sort the list for faster searches - internally uses qsort()
36 mqCpList.sort();
37 }
38 catch(IException &e) {
39 QString msg = "Can't open or invalid file list [" +
40 psListFile.expanded() + "]";
41 throw IException(e, IException::User, msg, _FILEINFO_);
42 }
43 }
44
50
51
60 bool ControlPointList::HasControlPoint(const QString &psCpId) {
61 int index = mqCpList.indexOf(QString(psCpId));
62
63 if(index == -1 || index >= Size())
64 return false;
65
66 mbFound[index] = true;
67 return true;
68 }
69
70
77 return mqCpList.size();
78 }
79
80
88 QString ControlPointList::ControlPointId(int piIndex) {
89 int size = Size();
90 if(piIndex >= 0 && piIndex < size) {
91 return (mqCpList.value(piIndex));
92 }
93 else {
94 QString num = toString(piIndex);
95 QString msg = "Index [" + num + "] is invalid";
96 throw IException(IException::Programmer, msg, _FILEINFO_);
97 }
98 }
99
107 int ControlPointList::ControlPointIndex(const QString &psCpId) {
108 if(HasControlPoint(psCpId)) {
109 return mqCpList.indexOf(QString(psCpId));
110 }
111 else {
112 QString msg = "Requested control point id [" + psCpId + "] ";
113 msg += "does not exist in the list";
114 throw IException(IException::Programmer, msg, _FILEINFO_);
115 }
116 }
117
125 int size = Size();
126 int iNotFound = 0;
127 QString sPointsNotFound = "";
128
129 for(int i = 0; i < size; i++) {
130 if(!mbFound[i]) {
131 if(iNotFound) {
132 sPointsNotFound += ", ";
133 }
134 sPointsNotFound += mqCpList.value(i);
135 iNotFound++;
136 }
137 }
138
139 pcPvlLog += Isis::PvlKeyword("TotalPoints", toString(size));
140 pcPvlLog += Isis::PvlKeyword("ValidPoints", toString(size - iNotFound));
141 pcPvlLog += Isis::PvlKeyword("InvalidPoints", toString(iNotFound));
142 pcPvlLog += Isis::PvlKeyword("InvalidPointIds", sPointsNotFound);
143 }
144}
bool HasControlPoint(const QString &psCpId)
Determines whether or not the requested control point id exists in the list.
QVector< bool > mbFound
holds one to one correspondence with "mqCpList" on whether the point was valid
void RegisterStatistics(Pvl &pcPvlLog)
Register invalid control point and calculate the valid & invalid point count.
ControlPointList(const FileName &psFileName)
Creates a ControlPointList from a list of control point ids'.
int ControlPointIndex(const QString &psCpId)
return a list index given a control point id
QString ControlPointId(int piIndex)
Return a control point id given an index.
virtual ~ControlPointList()
Destructor.
int Size() const
How many control points in the list.
Internalizes a list of files.
Definition FileList.h:54
File name manipulation and expansion.
Definition FileName.h:100
Isis exception class.
Definition IException.h:91
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition IException.h:126
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
Container for cube-like labels.
Definition Pvl.h:119
A single keyword-value pair.
Definition PvlKeyword.h:87
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition IString.cpp:211