Isis 3 Programmer Reference
Cube.h
1#ifndef Cube_h
2#define Cube_h
8/* SPDX-License-Identifier: CC0-1.0 */
9
10#include <vector>
11
12// This is needed for the QVariant macro
13#include <QMetaType>
14#include <QList>
15#include <QMap>
16
17#include <nlohmann/json.hpp>
18
19#include "Endian.h"
20#include "PixelType.h"
21#include "PvlKeyword.h"
22
23class QFile;
24class QMutex;
25class QString;
26
27namespace Isis {
28 class Blob;
29 class Buffer;
30 class Camera;
31 class CubeAttributeOutput;
32 class CubeCachingAlgorithm;
33 class CubeIoHandler;
34 class CubeStretch;
35 class FileName;
36 class Projection;
37 class Pvl;
38 class PvlGroup;
39 class Statistics;
40 class Table;
41 class Histogram;
42 class History;
43 class OriginalLabel;
44 class OriginalXmlLabel;
45 class ImagePolygon;
46
47
168 class Cube {
169 public:
170 Cube();
171 Cube(const FileName &fileName, QString access = "r");
172
173 virtual ~Cube();
174
179 enum Format {
233 Tile
234 };
235
236 void fromIsd(const FileName &fileName, Pvl &label, nlohmann::json &isd, QString access);
237 void fromIsd(const FileName &fileName, FileName &labelFile, FileName &isdFile, QString access);
238
239 void fromLabel(const FileName &fileName, Pvl &label, QString access);
240
241 bool isOpen() const;
242 bool isProjected() const;
243 bool isReadOnly() const;
244 bool isReadWrite() const;
245 bool labelsAttached() const;
246
247 void attachSpiceFromIsd(nlohmann::json Isd);
248
249 void close(bool remove = false);
250 Cube *copy(FileName newFile, const CubeAttributeOutput &newFileAttributes);
251 void create(const QString &cfile);
252 void create(const QString &cfile, const CubeAttributeOutput &att);
253 void open(const QString &cfile, QString access = "r");
254 void reopen(QString access = "r");
255
256 void read(Blob &blob,
257 const std::vector<PvlKeyword> keywords = std::vector<PvlKeyword>()) const;
258 void read(Buffer &rbuf) const;
259 OriginalLabel readOriginalLabel(const QString &name="IsisCube") const;
260 CubeStretch readCubeStretch(QString name="CubeStretch",
261 const std::vector<PvlKeyword> keywords = std::vector<PvlKeyword>()) const;
263 History readHistory(const QString &name = "IsisCube") const;
265 Table readTable(const QString &name);
266 void write(Blob &blob, bool overwrite=true);
267 void write(const Table &table);
268 void write(const CubeStretch &cubeStretch);
269 void write(OriginalLabel &lab);
270 void write(const OriginalXmlLabel &lab);
271 void write(History &history, const QString &name = "IsisCube");
272 void write(const ImagePolygon &polygon);
273 void write(Buffer &wbuf);
274
275 void setBaseMultiplier(double base, double mult);
276 void setMinMax(double min, double max);
278 void setDimensions(int ns, int nl, int nb);
279 void setExternalDnData(FileName cubeFileWithDnData);
280 void setFormat(Format format);
281 void setLabelsAttached(bool attached);
282 void setLabelSize(int labelBytes);
284 void setVirtualBands(const QList<QString> &vbands);
285 void setVirtualBands(const std::vector<QString> &vbands);
286
287 void relocateDnData(FileName dnDataFile);
288// static void relocateDnData(FileName externalLabelFile, FileName dnDataFile);
289
290 virtual int bandCount() const;
291 double base() const;
292 ByteOrder byteOrder() const;
293 Camera *camera();
295 virtual QString fileName() const;
296 Format format() const;
297 virtual Histogram *histogram(const int &band = 1,
298 QString msg = "Gathering histogram");
299 virtual Histogram *histogram(const int &band, const double &validMin,
300 const double &validMax,
301 QString msg = "Gathering histogram");
302 Pvl *label() const;
303 int labelSize(bool actual = false) const;
304 int lineCount() const;
305 double multiplier() const;
306 PixelType pixelType() const;
307 virtual int physicalBand(const int &virtualBand) const;
309 int sampleCount() const;
310 Statistics *statistics(const int &band = 1,
311 QString msg = "Gathering statistics");
312 Statistics *statistics(const int &band, const double &validMin,
313 const double &validMax,
314 QString msg = "Gathering statistics");
315 bool storesDnData() const;
316
318 void clearIoCache();
319 bool deleteBlob(QString BlobName, QString BlobType);
320 void deleteGroup(const QString &group);
321 PvlGroup &group(const QString &group) const;
322 bool hasGroup(const QString &group) const;
323 bool hasTable(const QString &name);
324 bool hasBlob(const QString &name, const QString &type);
325 void putGroup(const PvlGroup &group);
326 void latLonRange(double &minLatitude, double &maxLatitude, double &minLongitude,
327 double &maxLongitude);
328
329
330 private:
332 void cleanUp(bool remove);
333
334 void construct();
335 QFile *dataFile() const;
337
338 void initialize();
339 void initCoreFromLabel(const Pvl &label);
340 void initLabelFromFile(FileName labelFileName, bool readWrite);
341 void openCheck();
342 Pvl realDataFileLabel() const;
343 void reformatOldIsisLabel(const QString &oldCube);
344 void writeLabels();
345
346 private:
362
368
375
382
389
391 QMutex *m_mutex;
392
395
398
401
404
411
414
417
424
427
430
433
436
439
444 double m_base;
445
451
453 QList<int> *m_virtualBandList;
454 };
455}
456
458Q_DECLARE_METATYPE(Isis::Cube *);
459
460#endif
Buffer for reading and writing cube data.
Definition Buffer.h:53
Manipulate and parse attributes of output cube filenames.
This is the parent of the caching algorithms.
IO Handler for Isis Cubes.
Definition Cube.h:168
void addCachingAlgorithm(CubeCachingAlgorithm *)
This will add the given caching algorithm to the list of attempted caching algorithms.
Definition Cube.cpp:1928
void clearIoCache()
This will clear excess RAM used for quicker IO in the cube.
Definition Cube.cpp:1944
bool hasTable(const QString &name)
Check to see if the cube contains a pvl table by the provided name.
Definition Cube.cpp:2049
QFile * m_dataFile
This is only sometimes allocated.
Definition Cube.h:361
Pvl realDataFileLabel() const
Function to read data from a cube label and return it as a PVL object.
Definition Cube.cpp:2456
ImagePolygon readFootprint() const
Read the footprint polygon for the Cube.
Definition Cube.cpp:872
Cube()
Constructs a Cube object.
Definition Cube.cpp:49
void setPixelType(PixelType pixelType)
Used prior to the Create method, this will specify the output pixel type.
Definition Cube.cpp:1310
void latLonRange(double &minLatitude, double &maxLatitude, double &minLongitude, double &maxLongitude)
Returns the latitude and longitude range for the Cube.
Definition Cube.cpp:2516
void deleteGroup(const QString &group)
Deletes a group from the cube labels.
Definition Cube.cpp:1983
void reformatOldIsisLabel(const QString &oldCube)
This is a helper, used by open(...), that handles opening Isis 2 cubes as if they were Isis cubes.
Definition Cube.cpp:2486
void setFormat(Format format)
Used prior to the Create method, this will specify the format of the cube, either band,...
Definition Cube.cpp:1272
bool deleteBlob(QString BlobName, QString BlobType)
This method will delete a blob label object from the cube as specified by the Blob type and name.
Definition Cube.cpp:1961
int m_bands
The band count of the open cube or the cube that will be created.
Definition Cube.h:438
void initialize()
This sets Cube to its default state: Native byte order Format = Tile PixelType = Real (4 bytes per pi...
Definition Cube.cpp:2268
Format format() const
Definition Cube.cpp:1581
PixelType m_pixelType
This is the pixel type on disk.
Definition Cube.h:388
void relocateDnData(FileName dnDataFile)
Relocates the DN data for a cube to an external cube label file.
Definition Cube.cpp:1372
void construct()
Initialize members from their initial undefined states.
Definition Cube.cpp:2160
int m_labelBytes
The maximum allowed size of the label; the allocated space.
Definition Cube.h:429
virtual Histogram * histogram(const int &band=1, QString msg="Gathering histogram")
This method returns a pointer to a Histogram object which allows the program to obtain and use variou...
Definition Cube.cpp:1605
int lineCount() const
Definition Cube.cpp:1740
void initLabelFromFile(FileName labelFileName, bool readWrite)
This function initializes the Cube label from a file passed as a parameter.
Definition Cube.cpp:2337
double multiplier() const
Returns the multiplier value for converting 8-bit/16-bit pixels to 32-bit.
Definition Cube.cpp:1754
CubeIoHandler * m_ioHandler
This does the heavy lifting for cube DN IO and is always allocated when isOpen() is true.
Definition Cube.h:367
FileName realDataFileName() const
This gets the file name of the file which actually contains the DN data.
Definition Cube.cpp:2206
void setLabelsAttached(bool attached)
Use prior to calling create, this sets whether or not to use separate label and data files.
Definition Cube.cpp:1284
CubeStretch readCubeStretch(QString name="CubeStretch", const std::vector< PvlKeyword > keywords=std::vector< PvlKeyword >()) const
Read a Stretch from a cube.
Definition Cube.cpp:918
Statistics * statistics(const int &band=1, QString msg="Gathering statistics")
This method returns a pointer to a Statistics object which allows the program to obtain and use vario...
Definition Cube.cpp:1836
void setDimensions(int ns, int nl, int nb)
Used prior to the Create method to specify the size of the cube.
Definition Cube.cpp:1223
Camera * camera()
Return a camera associated with the cube.
Definition Cube.cpp:1457
FileName externalCubeFileName() const
If this is an external cube label file, this will give you the cube dn file that this label reference...
Definition Cube.cpp:1541
PvlGroup & group(const QString &group) const
Read a group from the cube into a Label.
Definition Cube.cpp:1997
double m_base
The base of the open cube or the cube that will be created; does not apply if m_pixelType is Real.
Definition Cube.h:444
int sampleCount() const
Definition Cube.cpp:1813
bool m_attached
True if labels are attached.
Definition Cube.h:416
void putGroup(const PvlGroup &group)
Adds a group in a Label to the cube.
Definition Cube.cpp:2062
bool m_storesDnData
True (most common case) when the cube DN data is inside the file we're writing to.
Definition Cube.h:423
bool isOpen() const
Test if a cube file has been opened/created.
Definition Cube.cpp:182
void setBaseMultiplier(double base, double mult)
Used prior to the Create method, this will specify the base and multiplier for converting 8-bit/16-bi...
Definition Cube.cpp:1157
bool isReadOnly() const
Test if the opened cube is read-only, that is write operations will fail if this is true.
Definition Cube.cpp:208
int m_lines
The line count of the open cube or the cube that will be created.
Definition Cube.h:435
double base() const
Returns the base value for converting 8-bit/16-bit pixels to 32-bit.
Definition Cube.cpp:1433
void fromIsd(const FileName &fileName, Pvl &label, nlohmann::json &isd, QString access)
Initialize Cube data from a PVL label and JSON ISD.
Definition Cube.cpp:98
void setMinMax(double min, double max)
Used prior to the Create method, this will compute a good base and multiplier value given the minimum...
Definition Cube.cpp:1174
QFile * dataFile() const
This returns the QFile with cube DN data in it.
Definition Cube.cpp:2191
Cube * copy(FileName newFile, const CubeAttributeOutput &newFileAttributes)
Copies the cube to the new fileName.
Definition Cube.cpp:271
void create(const QString &cfile)
This method will create an isis cube for writing.
Definition Cube.cpp:409
FileName * m_tempCube
If open was called with an Isis 2 cube, then this will be the name of the imported ISIS cube.
Definition Cube.h:410
bool hasBlob(const QString &name, const QString &type)
Check to see if the cube contains a BLOB.
Definition Cube.cpp:2025
void cleanUp(bool remove)
This clears all of the allocated memory associated with an open cube.
Definition Cube.cpp:2112
ByteOrder byteOrder() const
Returns the byte order/endian-ness of the cube file.
Definition Cube.cpp:1445
ByteOrder m_byteOrder
The byte order of the opened cube; if there is no open cube then this is the byte order that will be ...
Definition Cube.h:374
QFile * m_labelFile
This is the file that contains the labels always; if labels are attached then this contains the file ...
Definition Cube.h:355
bool labelsAttached() const
Test if labels are attached.
Definition Cube.cpp:243
void open(const QString &cfile, QString access="r")
This method will open an existing isis cube for reading or reading/writing.
Definition Cube.cpp:622
PixelType pixelType() const
Definition Cube.cpp:1764
bool storesDnData() const
This method returns a boolean value.
Definition Cube.cpp:1910
void setVirtualBands(const QList< QString > &vbands)
This allows the programmer to specify a subset of bands to work with.
Definition Cube.cpp:1327
FileName * m_formatTemplateFile
Label pvl format template file (describes how to format labels)
Definition Cube.h:413
Pvl * m_label
The label if IsOpen(), otherwise NULL.
Definition Cube.h:426
void read(Blob &blob, const std::vector< PvlKeyword > keywords=std::vector< PvlKeyword >()) const
This method will read data from the specified Blob object.
Definition Cube.cpp:813
bool isProjected() const
Returns true if the labels of the cube appear to have a valid mapping group.
Definition Cube.cpp:197
OriginalLabel readOriginalLabel(const QString &name="IsisCube") const
Read the original PDS3 label from a cube.
Definition Cube.cpp:895
Format
These are the possible storage formats of ISIS cubes.
Definition Cube.h:179
@ Tile
Cubes are stored in tile format, that is the order of the pixels in the file (on disk) is BSQ within ...
Definition Cube.h:233
@ Bsq
Cubes are stored in band-sequential format, that is the order of the pixels in the file (on disk) is:
Definition Cube.h:200
virtual int physicalBand(const int &virtualBand) const
This method will return the physical band number given a virtual band number.
Definition Cube.cpp:1779
Table readTable(const QString &name)
Read a Table from the cube.
Definition Cube.cpp:958
Camera * m_camera
Camera allocated from the camera() method.
Definition Cube.h:394
bool hasGroup(const QString &group) const
Return if the cube has a specified group in the labels.
Definition Cube.cpp:2010
void setLabelSize(int labelBytes)
Used prior to the Create method, this will allocate a specific number of bytes in the label area for ...
Definition Cube.cpp:1297
OriginalXmlLabel readOriginalXmlLabel() const
Read the original PDS4 label from a cube.
Definition Cube.cpp:937
virtual QString fileName() const
Returns the opened cube's filename.
Definition Cube.cpp:1569
void fromLabel(const FileName &fileName, Pvl &label, QString access)
Initialize Cube data from a PVL label.
Definition Cube.cpp:75
virtual ~Cube()
Destroys the Cube object.
Definition Cube.cpp:159
QList< int > * m_virtualBandList
If allocated, converts from physical on-disk band # to virtual band #.
Definition Cube.h:453
void write(Blob &blob, bool overwrite=true)
This method will write a blob of data (e.g.
Definition Cube.cpp:977
bool isReadWrite() const
Test if the opened cube is read-write, that is read and write operations should succeed if this is tr...
Definition Cube.cpp:230
FileName * m_labelFileName
The full filename of the label file (.lbl or .cub)
Definition Cube.h:400
void setExternalDnData(FileName cubeFileWithDnData)
Used to set external dn data to cube.
Definition Cube.cpp:1240
void close(bool remove=false)
Closes the cube and updates the labels.
Definition Cube.cpp:255
History readHistory(const QString &name="IsisCube") const
Read the History from the Cube.
Definition Cube.cpp:853
void writeLabels()
Write the Pvl labels to the cube's label file.
Definition Cube.cpp:2603
QMutex * m_mutex
Basic thread-safety mutex; this class is not optimized for threads.
Definition Cube.h:391
void initCoreFromLabel(const Pvl &label)
This function initializes the Cube core from a Pvl Label passed as a parameter.
Definition Cube.cpp:2293
int labelSize(bool actual=false) const
Returns the number of bytes used by the label.
Definition Cube.cpp:1719
int m_samples
The sample count of the open cube or the cube that will be created.
Definition Cube.h:432
void openCheck()
Throw an exception if the cube is not open.
Definition Cube.cpp:2443
Projection * projection()
Definition Cube.cpp:1800
double m_multiplier
The multiplier of the open cube or the cube that will be created; does not apply if m_pixelType is Re...
Definition Cube.h:450
virtual int bandCount() const
Returns the number of virtual bands for the cube.
Definition Cube.cpp:1416
Pvl * label() const
Returns a pointer to the IsisLabel object associated with the cube.
Definition Cube.cpp:1707
void reopen(QString access="r")
This method will reopen an isis sube for reading or reading/writing.
Definition Cube.cpp:780
Projection * m_projection
Projection allocated from the projection() method.
Definition Cube.h:397
void setByteOrder(ByteOrder byteOrder)
Used prior to the Create method, this will specify the byte order of pixels, either least or most sig...
Definition Cube.cpp:1208
FileName * m_dataFileName
The full filename of the data file (.cub)
Definition Cube.h:403
void applyVirtualBandsToLabel()
Applies virtual bands to label.
Definition Cube.cpp:2084
Format m_format
If isOpen() then this is the IO format that the cube uses.
Definition Cube.h:381
Handles converting buffers to and from disk.
Stores stretch information for a cube.
Definition CubeStretch.h:27
File name manipulation and expansion.
Definition FileName.h:100
Container of a cube histogram.
Definition Histogram.h:74
Create cube polygons, read/write polygons to blobs.
Read and store original labels.
Read and store original Xml labels.
Base class for Map Projections.
Definition Projection.h:155
Contains multiple PvlContainers.
Definition PvlGroup.h:41
Container for cube-like labels.
Definition Pvl.h:119
This class is used to accumulate statistics on double arrays.
Definition Statistics.h:94
Class for storing Table blobs information.
Definition Table.h:61
ByteOrder
Tests the current architecture for byte order.
Definition Endian.h:42
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
PixelType
Enumerations for Isis Pixel Types.
Definition PixelType.h:27