Isis 3 Programmer Reference
TrackingTable.cpp
Go to the documentation of this file.
1 
23 #include "TrackingTable.h"
24 
25 #include <QList>
26 #include <QString>
27 
28 #include "FileName.h"
29 #include "IException.h"
30 #include "Pvl.h"
31 #include "SpecialPixel.h"
32 #include "Table.h"
33 #include "TableField.h"
34 #include "TableRecord.h"
35 
36 using namespace std;
37 namespace Isis {
38 
39 
43  TrackingTable::TrackingTable() {
44 
45  }
46 
47 
54  TrackingTable::TrackingTable(Table table) {
55 
56  for (int i=0; i < table.Records(); i++) {
57  TableRecord record = table[i];
58  QString nameField = QString(record["FileName"]).split("/").last();
59  QString extension(FileName(nameField).extension());
60  int found = nameField.lastIndexOf(extension);
61  if (found != -1) {
62  // clear the packing characters - get only the file name
63  nameField.remove(found + 3);
64  }
65  FileName fileName(nameField);
66  QString serialNumber = QString(record["SerialNumber"]);
67  m_fileList.append(QPair<FileName, QString>(fileName, serialNumber));
68  }
69  }
70 
71 
75  TrackingTable::~TrackingTable() {
76 
77  }
78 
79 
85  Table TrackingTable::toTable() {
86 
87  // Begin by establishing the length of the fields within the table. This would be the longest
88  // length that is needed to be stored.
89  int fieldLength = 0;
90 
91  for (int i=0; i < m_fileList.size(); i++) {
92  if (m_fileList[i].first.name().length() > fieldLength) {
93  fieldLength = m_fileList[i].first.name().length();
94  }
95  if (m_fileList[i].second.length() > fieldLength) {
96  fieldLength = m_fileList[i].second.length();
97  }
98  }
99 
100  // This record is never being used. It is simply to construct the Table object.
101  TableRecord dummyRecord;
102  TableField fileNameField("FileName", TableField::Text, fieldLength);
103  TableField serialNumberField("SerialNumber", TableField::Text, fieldLength);
104  TableField indexField("PixelValue", TableField::Integer);
105  dummyRecord += fileNameField;
106  dummyRecord += serialNumberField;
107  dummyRecord += indexField;
108  Table table(trackingTableName, dummyRecord);
109 
110  // Loop through m_fileList and add records to the table with the proper information.
111  for (int i=0; i < m_fileList.size(); i++) {
112 
113  fileNameField = m_fileList[i].first.name();
114  serialNumberField = m_fileList[i].second;
115  indexField = (int) (i + VALID_MINUI4);
116 
117  TableRecord record;
118  record += fileNameField;
119  record += serialNumberField;
120  record += indexField;
121 
122  table += record;
123 
124  }
125 
126  return table;
127  }
128 
129 
136  FileName TrackingTable::pixelToFileName(unsigned int pixel) {
137  if (pixel < VALID_MINUI4) {
138  QString msg = "Cannot convert pixel [" + toString(pixel)
139  + "] to a filename, pixel is below valid minimum ["
140  + toString(VALID_MINUI4) + "].";
141  throw IException(IException::Programmer, msg, _FILEINFO_);
142  }
143 
144  unsigned int index = pixel - VALID_MINUI4;
145  if (index >= (unsigned int)m_fileList.size()) {
146  QString msg = "Cannot convert pixel [" + toString(pixel)
147  + "] to a filename, pixel is above valid maximum ["
148  + toString(VALID_MINUI4 + m_fileList.size()) + "].";
149  throw IException(IException::Programmer, msg, _FILEINFO_);
150  }
151 
152  return m_fileList[index].first;
153  }
154 
155 
166  unsigned int TrackingTable::fileNameToPixel(FileName file, QString serialNumber) {
167  for (int i = 0; i < m_fileList.size(); i++) {
168  if (QString::compare(m_fileList[i].first.toString(), file.name()) == 0) {
169  return i + VALID_MINUI4;
170  }
171  }
172 
173  // At this point, the file is not in the internal file list so append it
174  // and return its new index.
175  m_fileList.append(QPair<FileName, QString>(file, serialNumber));
176  return m_fileList.size() - 1 + VALID_MINUI4;
177  }
178 
179 
186  QString TrackingTable::pixelToSN(unsigned int pixel) {
187  if (pixel < VALID_MINUI4) {
188  QString msg = "Cannot convert pixel [" + toString(pixel)
189  + "] to a serial number, pixel is below valid minimum ["
190  + toString(VALID_MINUI4) + "].";
191  throw IException(IException::Programmer, msg, _FILEINFO_);
192  }
193 
194  unsigned int index = pixel - VALID_MINUI4;
195  if (index >= (unsigned int)m_fileList.size()) {
196  QString msg = "Cannot convert pixel [" + toString(pixel)
197  + "] to a serial number, pixel is above valid maximum ["
198  + toString(VALID_MINUI4 + m_fileList.size()) + "].";
199  throw IException(IException::Programmer, msg, _FILEINFO_);
200  }
201 
202  return m_fileList[index].second;
203  }
204 
205 
216  int TrackingTable::fileNameToIndex(FileName file, QString serialNumber) {
217  for (int i = 0; i < m_fileList.size(); i++) {
218  if (m_fileList[i].first == file) {
219  return i;
220  }
221  }
222 
223  // At this point, the file is not in the internal file list so append it
224  // and return its new index.
225  m_fileList.append(QPair<FileName, QString>(file, serialNumber));
226  return m_fileList.size() - 1;
227  }
228 }
int Records() const
Returns the number of records.
Definition: Table.cpp:224
File name manipulation and expansion.
Definition: FileName.h:116
Namespace for the standard library.
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
Definition: FileName.cpp:178
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
QString name() const
Returns the name of the TableField.
Definition: TableField.cpp:113
Class for storing Table blobs information.
Definition: Table.h:77
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
Class for storing an Isis::Table&#39;s field information.
Definition: TableField.h:63