9#include <QRegularExpression>
10#include <QScopedPointer>
13#include <QXmlStreamWriter>
15#include <geos/geom/MultiPolygon.h>
16#include <geos/io/WKTReader.h>
17#include <geos/io/WKTWriter.h>
21#include "CubeAttribute.h"
22#include "DisplayProperties.h"
26#include "ImagePolygon.h"
28#include "ObservationNumber.h"
29#include "PolygonTools.h"
31#include "SerialNumber.h"
62 catch (IException &) {
67 m_id =
new QUuid(QUuid::createUuid());
95 catch (IException &e) {
100 m_id =
new QUuid(QUuid::createUuid());
171 QString pvlFileName = ((IString)pvl[
"FileName"][0]).ToQt();
173 throw IException(IException::Unknown,
174 tr(
"Tried to load Image [%1] with properties/information from [%2].")
181 if (pvl.hasKeyword(
"ID")) {
182 QByteArray hexValues(pvl[
"ID"][0].toLatin1());
183 QDataStream valuesStream(QByteArray::fromHex(hexValues));
184 valuesStream >> *
m_id;
203 PvlObject output(
"Image");
209 dataBuffer.open(QIODevice::ReadWrite);
211 QDataStream idStream(&dataBuffer);
216 output += PvlKeyword(
"ID", QString(dataBuffer.data().toHex()));
239 QString blobType = example.Type();
240 QString blobName = example.Name();
242 Pvl &labels = *
m_cube->label();
244 for (
int i = 0; i < labels.objects(); i++) {
245 PvlObject &obj = labels.object(i);
247 if (obj.isNamed(blobType) && obj.hasKeyword(
"Name") && obj[
"Name"][0] == blobName)
268 catch (IException &e) {
269 throw IException(e, IException::Programmer,
"Cube cannot be created", _FILEINFO_);
360 m_id =
new QUuid(
id);
390 catch (IException &e) {
394 catch (IException &e) {
395 IString msg =
"Could not read the footprint from cube [" +
397 "sure footprintinit has been run";
398 throw IException(e, IException::Io, msg, _FILEINFO_);
422 return m_id->toString().remove(QRegularExpression(
"[{}]"));
511 if (FileName(newProjectRoot) != FileName(project->
projectRoot())) {
519 if (
m_fileName != newExternalLabelFileName.toString()) {
524 QScopedPointer<Cube> newExternalLabel(
533 FileName newDnFileName = newExternalLabelFileName.setExtension(
"cub");
537 newExternalLabel->relocateDnData(newDnFileName.name());
545 newExternalLabel->relocateDnData(newExternalCubeFileName);
567 throw IException(IException::Io,
568 tr(
"Could not remove file [%1]").arg(
m_fileName),
573 FileName cubFile = FileName(
m_fileName).setExtension(
"cub");
574 if (!QFile::remove(cubFile.expanded() ) ) {
575 throw IException(IException::Io,
576 tr(
"Could not remove file [%1]").arg(
m_fileName),
604 stream.writeStartElement(
"image");
606 stream.writeAttribute(
"id",
m_id->toString());
607 stream.writeAttribute(
"fileName", FileName(
m_fileName).name());
612 stream.writeAttribute(
"aspectRatio", IString(
m_aspectRatio).ToQt());
616 stream.writeAttribute(
"resolution", IString(
m_resolution).ToQt());
620 stream.writeAttribute(
"emissionAngle", IString(
m_emissionAngle.radians()).ToQt());
624 stream.writeAttribute(
"incidenceAngle", IString(
m_incidenceAngle.radians()).ToQt());
632 stream.writeAttribute(
"localRadius", IString(
m_localRadius.meters()).ToQt());
636 stream.writeAttribute(
"northAzimuth", IString(
m_northAzimuth.radians()).ToQt());
640 stream.writeAttribute(
"phaseAngle", IString(
m_phaseAngle.radians()).ToQt());
648 stream.writeStartElement(
"footprint");
650 geos::io::WKTWriter wktWriter;
651 stream.writeCharacters(QString::fromStdString(wktWriter.write(
m_footprint)));
653 stream.writeEndElement();
658 stream.writeEndElement();
672 original.dir().dirName() +
"/" + original.name());
683 QMutexLocker lock(cameraMutex);
689 if (sampleStepSize <= 0) sampleStepSize = 1;
692 if (lineStepSize <= 0) lineStepSize = 1;
694 imgPoly.
Create(*
cube(), sampleStepSize, lineStepSize);
696 IException e = IException(IException::User,
697 tr(
"Warning: Polygon re-calculated for [%1] which can be very slow")
711 bool hasCamStats =
false;
714 for (
int i = 0; !hasCamStats && i < label.objects(); i++) {
715 PvlObject &obj = label.object(i);
718 if (obj.name() ==
"Table") {
719 if (obj[
"Name"][0] ==
"CameraStatistics") {
724 catch (IException &) {
729 Table camStatsTable(
"CameraStatistics",
m_fileName, label);
731 int numRecords = camStatsTable.Records();
732 for (
int recordIndex = 0; recordIndex < numRecords; recordIndex++) {
733 TableRecord &record = camStatsTable[recordIndex];
737 QString recordName((QString)record[
"Name"]);
738 double avgValue = (double)record[
"Average"];
740 if (recordName ==
"AspectRatio") {
743 else if (recordName ==
"Resolution") {
746 else if (recordName ==
"EmissionAngle") {
749 else if (recordName ==
"IncidenceAngle") {
752 else if (recordName ==
"LineResolution") {
755 else if (recordName ==
"LocalRadius") {
758 else if (recordName ==
"NorthAzimuth") {
761 else if (recordName ==
"PhaseAngle") {
764 else if (recordName ==
"SampleResolution") {
770 for (
int i = 0; i < label.objects(); i++) {
771 PvlObject &obj = label.object(i);
773 if (obj.hasGroup(
"Instrument")) {
774 PvlGroup instGroup = obj.findGroup(
"Instrument");
776 if (instGroup.hasKeyword(
"SpacecraftName"))
779 if (instGroup.hasKeyword(
"InstrumentId"))
783 catch (IException &) {
Defines an angle and provides unit conversions.
@ Degrees
Degrees are generally considered more human readable, 0-360 is one circle, however most math does not...
Manipulate and parse attributes of output cube filenames.
IO Handler for Isis Cubes.
ImagePolygon readFootprint() const
Read the footprint polygon for the Cube.
FileName externalCubeFileName() const
If this is an external cube label file, this will give you the cube dn file that this label reference...
@ ExternalLabel
The label is pointing to an external DN file - the label is also external to the data.
Cube * copy(FileName newFile, const CubeAttributeOutput &newFileAttributes)
Copies the cube to the new fileName.
LabelAttachment labelsAttached() const
Test if labels are attached.
virtual QString fileName() const
Returns the opened cube's filename.
Pvl * label() const
Returns a pointer to the IsisLabel object associated with the cube.
QString displayName() const
Returns the display name.
PvlObject toPvl() const
Convert to Pvl for project files.
Distance measurement, usually in meters.
@ Meters
The distance is being specified in meters.
This is the GUI communication mechanism for cubes.
Cube * cube()
Get the Cube pointer associated with this display property.
Angle incidenceAngle() const
Get the incidence angle of this image, as calculated and attached by camstats.
double m_sampleResolution
Sample resolution of the image.
void copyToNewProjectRoot(const Project *project, FileName newProjectRoot)
Copy the cub/ecub files associated with this image into the new project.
void setId(QString id)
Override the automatically generated ID with the given ID.
Distance m_localRadius
Local radius of the image.
Angle phaseAngle() const
Get the phase angle of this image, as calculated and attached by camstats.
QString m_instrumentId
Instrument id associated with this Image.
void closeCube()
Cleans up the Cube pointer.
Distance localRadius() const
Get the local radius of this image, as calculated and attached by camstats.
geos::geom::MultiPolygon * footprint()
Get the footprint of this image (if available).
SpiceInt * m_bodyCode
The NaifBodyCode value, if it exists in the labels.
double m_lineResolution
Line resolution of the image.
QString serialNumber()
Returns the serial number of the Cube.
QUuid * m_id
A unique ID for this Image (useful for others to reference this Image when saving to disk).
~Image()
Clean up this image.
double m_aspectRatio
Aspect ratio of the image.
QString m_serialNumber
The serial number for this image.
Angle m_incidenceAngle
Incidence angle of the image.
Angle emissionAngle() const
Get the emission angle of this image, as calculated and attached by camstats.
void updateFileName(Project *)
Change the on-disk file name for this cube to be where the image ought to be in the given project.
double lineResolution() const
Get the line resolution of this image, as calculated and attached by camstats.
bool isFootprintable() const
Test to see if it's possible to create a footprint from this image.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Write the Image properties out to an XML file.
Angle m_emissionAngle
Emmission angle of the image.
double aspectRatio() const
Get the aspect ratio of this image, as calculated and attached by camstats.
QString m_fileName
The on-disk file name of the cube associated with this Image.
PvlObject toPvl() const
Convert this Image to PVL.
Image(QString imageFileName, QObject *parent=0)
Create an image from a cube file on disk.
Angle m_phaseAngle
Phase angle for the image.
QString m_spacecraftName
Spacecraft name associated with this Image.
double m_resolution
Resolution of the image.
QString m_observationNumber
The observation number for this image.
Cube * m_cube
The cube associated with this Image.
ImageDisplayProperties * displayProperties()
Get the display (GUI) properties (information) associated with this image.
Angle northAzimuth() const
Get the north azimuth of this image, as calculated and attached by camstats.
QString observationNumber()
Returns the observation number of the Cube.
Angle m_northAzimuth
North Azimuth for the image.
QString fileName() const
Get the file name of the cube that this image represents.
void initCamStats()
Checks to see if the Cube label contains Camera Statistics.
QString id() const
Get a unique, identifying string associated with this image.
double resolution() const
Get the resolution of this image, as calculated and attached by camstats.
void fromPvl(const PvlObject &pvl)
Read the image settings from a Pvl.
bool initFootprint(QMutex *cameraMutex)
Calculate a footprint for this image.
void deleteFromDisk()
Delete the image data from disk.
geos::geom::MultiPolygon * createFootprint(QMutex *cameraMutex)
Calculates a footprint for an Image using the camera or projection information.
ImageDisplayProperties * m_displayProperties
The GUI information for how this Image ought to be displayed.
geos::geom::MultiPolygon * m_footprint
A 0-360 ocentric lon,lat degrees footprint of this Image.
void initQuickFootprint()
Creates a default ImagePolygon option which is read into the Cube.
double sampleResolution() const
Get the sample resolution of this image, as calculated and attached by camstats.
Create cube polygons, read/write polygons to blobs.
void Create(Cube &cube, int sinc=1, int linc=1, int ss=1, int sl=1, int ns=0, int nl=0, int band=1, bool increasePrecision=false)
Create a Polygon from given cube.
geos::geom::MultiPolygon * Polys()
Return a geos Multipolygon.
Blob toBlob() const
Serialize the ImagePolygon to a Blob.
static QString Compose(Pvl &label, bool def2filename=false)
Compose a ObservationNumber from a PVL.
The main project for ipce.
QString newProjectRoot() const
Get the top-level folder of the new project.
QString projectRoot() const
Get the top-level folder of the project.
static QString imageDataRoot(QString projectRoot)
Appends the root directory name 'images' to the project .
static QString Compose(Pvl &label, bool def2filename=false)
Compose a SerialNumber from a PVL.
This is free and unencumbered software released into the public domain.