Isis 3 Programmer Reference
TrackingTable.cpp
1
6/* SPDX-License-Identifier: CC0-1.0 */
7#include "TrackingTable.h"
8
9#include <QList>
10#include <QString>
11
12#include "FileName.h"
13#include "IException.h"
14#include "Pvl.h"
15#include "SpecialPixel.h"
16#include "Table.h"
17#include "TableField.h"
18#include "TableRecord.h"
19
20using namespace std;
21namespace Isis {
22
23
30
31
39
40 for (int i=0; i < table.Records(); i++) {
41 TableRecord record = table[i];
42 QString nameField = QString(record["FileName"]).split("/").last();
43 QString extension(FileName(nameField).extension());
44 int found = nameField.lastIndexOf(extension);
45 if (found != -1) {
46 // clear the packing characters - get only the file name
47 nameField.remove(found + 3);
48 }
49 FileName fileName(nameField);
50 QString serialNumber = QString(record["SerialNumber"]);
51 m_fileList.append(QPair<FileName, QString>(fileName, serialNumber));
52 }
53 }
54
55
62
63
70
71 // Begin by establishing the length of the fields within the table. This would be the longest
72 // length that is needed to be stored.
73 int fieldLength = 0;
74
75 for (int i=0; i < m_fileList.size(); i++) {
76 if (m_fileList[i].first.name().length() > fieldLength) {
77 fieldLength = m_fileList[i].first.name().length();
78 }
79 if (m_fileList[i].second.length() > fieldLength) {
80 fieldLength = m_fileList[i].second.length();
81 }
82 }
83
84 // This record is never being used. It is simply to construct the Table object.
85 TableRecord dummyRecord;
86 TableField fileNameField("FileName", TableField::Text, fieldLength);
87 TableField serialNumberField("SerialNumber", TableField::Text, fieldLength);
88 TableField indexField("PixelValue", TableField::Integer);
89 dummyRecord += fileNameField;
90 dummyRecord += serialNumberField;
91 dummyRecord += indexField;
92 Table table(trackingTableName, dummyRecord);
93
94 // Loop through m_fileList and add records to the table with the proper information.
95 for (int i=0; i < m_fileList.size(); i++) {
96
97 fileNameField = m_fileList[i].first.name();
98 serialNumberField = m_fileList[i].second;
99 indexField = (int) (i + VALID_MINUI4);
100
101 TableRecord record;
102 record += fileNameField;
103 record += serialNumberField;
104 record += indexField;
105
106 table += record;
107
108 }
109
110 return table;
111 }
112
113
121 if (pixel < VALID_MINUI4) {
122 QString msg = "Cannot convert pixel [" + toString(pixel)
123 + "] to a filename, pixel is below valid minimum ["
124 + toString(VALID_MINUI4) + "].";
125 throw IException(IException::Programmer, msg, _FILEINFO_);
126 }
127
128 unsigned int index = pixel - VALID_MINUI4;
129 if (index >= (unsigned int)m_fileList.size()) {
130 QString msg = "Cannot convert pixel [" + toString(pixel)
131 + "] to a filename, pixel is above valid maximum ["
132 + toString(VALID_MINUI4 + m_fileList.size()) + "].";
133 throw IException(IException::Programmer, msg, _FILEINFO_);
134 }
135
136 return m_fileList[index].first;
137 }
138
139
150 unsigned int TrackingTable::fileNameToPixel(FileName file, QString serialNumber) {
151 for (int i = 0; i < m_fileList.size(); i++) {
152 if (QString::compare(m_fileList[i].first.toString(), file.name()) == 0) {
153 return i + VALID_MINUI4;
154 }
155 }
156
157 // At this point, the file is not in the internal file list so append it
158 // and return its new index.
159 m_fileList.append(QPair<FileName, QString>(file, serialNumber));
160 return m_fileList.size() - 1 + VALID_MINUI4;
161 }
162
163
170 QString TrackingTable::pixelToSN(unsigned int pixel) {
171 if (pixel < VALID_MINUI4) {
172 QString msg = "Cannot convert pixel [" + toString(pixel)
173 + "] to a serial number, pixel is below valid minimum ["
174 + toString(VALID_MINUI4) + "].";
175 throw IException(IException::Programmer, msg, _FILEINFO_);
176 }
177
178 unsigned int index = pixel - VALID_MINUI4;
179 if (index >= (unsigned int)m_fileList.size()) {
180 QString msg = "Cannot convert pixel [" + toString(pixel)
181 + "] to a serial number, pixel is above valid maximum ["
182 + toString(VALID_MINUI4 + m_fileList.size()) + "].";
183 throw IException(IException::Programmer, msg, _FILEINFO_);
184 }
185
186 return m_fileList[index].second;
187 }
188
189
200 int TrackingTable::fileNameToIndex(FileName file, QString serialNumber) {
201 for (int i = 0; i < m_fileList.size(); i++) {
202 if (m_fileList[i].first == file) {
203 return i;
204 }
205 }
206
207 // At this point, the file is not in the internal file list so append it
208 // and return its new index.
209 m_fileList.append(QPair<FileName, QString>(file, serialNumber));
210 return m_fileList.size() - 1;
211 }
212}
File name manipulation and expansion.
Definition FileName.h:100
Isis exception class.
Definition IException.h:91
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
Class for storing an Isis::Table's field information.
Definition TableField.h:47
@ Integer
The values in the field are 4 byte integers.
Definition TableField.h:53
@ Text
The values in the field are text strings with 1 byte per character.
Definition TableField.h:55
Class for storing Table blobs information.
Definition Table.h:61
int Records() const
Returns the number of records.
Definition Table.cpp:313
QString pixelToSN(unsigned int pixel)
Returns the serial number that corresponds to a pixel value.
Table toTable()
Constrcts and returns a Table object based on values in m_fileList.
FileName pixelToFileName(unsigned int pixel)
Returns the FileName that corresponds to a pixel value.
TrackingTable()
Default constructor.
~TrackingTable()
Destroys the TrackingTable object.
QList< QPair< FileName, QString > > m_fileList
The list to keep track of images.
int fileNameToIndex(FileName file, QString serialNumber)
Returns the index of the filename/serialnumber combination.
unsigned int fileNameToPixel(FileName file, QString serialNumber)
Returns the pixel value of the filename/serialnumber combination.
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
Namespace for the standard library.