7 #include <QMutexLocker>
8 #include <QScopedPointer>
11 #include <QXmlStreamWriter>
13 #include <geos/geom/MultiPolygon.h>
14 #include <geos/io/WKTReader.h>
15 #include <geos/io/WKTWriter.h>
20 #include "DisplayProperties.h"
30 #include "XmlStackedHandlerReader.h"
66 m_id =
new QUuid(QUuid::createUuid());
99 m_id =
new QUuid(QUuid::createUuid());
122 xmlReader->pushContentHandler(
new XmlHandler(
this, imageFolder));
163 QString pvlFileName = ((
IString)pvl[
"FileName"][0]).ToQt();
166 tr(
"Tried to load Image [%1] with properties/information from [%2].")
174 QByteArray hexValues(pvl[
"ID"][0].toLatin1());
175 QDataStream valuesStream(QByteArray::fromHex(hexValues));
176 valuesStream >> *
m_id;
201 dataBuffer.open(QIODevice::ReadWrite);
203 QDataStream idStream(&dataBuffer);
208 output +=
PvlKeyword(
"ID", QString(dataBuffer.data().toHex()));
231 QString blobType = example.
Type();
232 QString blobName = example.
Name();
236 for (
int i = 0; i < labels.
objects(); i++) {
239 if (obj.
isNamed(blobType) && obj.
hasKeyword(
"Name") && obj[
"Name"][0] == blobName)
334 *
m_id = QUuid(QString(
"{%1}").arg(
id));
368 IString msg =
"Could not read the footprint from cube [" +
370 "sure footprintinit has been run";
395 return m_id->toString().remove(QRegExp(
"[{}]"));
490 QScopedPointer<Cube> newExternalLabel(
495 if (!origImage.storesDnData() ) {
500 FileName newDnFileName = newExternalLabelFileName.setExtension(
"cub");
504 newExternalLabel->relocateDnData(newDnFileName.name());
525 tr(
"Could not remove file [%1]").arg(
m_fileName),
531 if (!QFile::remove(cubFile.expanded() ) ) {
533 tr(
"Could not remove file [%1]").arg(
m_fileName),
561 stream.writeStartElement(
"image");
563 stream.writeAttribute(
"id",
m_id->toString());
605 stream.writeStartElement(
"footprint");
607 geos::io::WKTWriter wktWriter;
608 stream.writeCharacters(QString::fromStdString(wktWriter.write(
m_footprint)));
610 stream.writeEndElement();
615 stream.writeEndElement();
629 original.dir().dirName() +
"/" + original.name());
640 QMutexLocker lock(cameraMutex);
646 if (sampleStepSize <= 0) sampleStepSize = 1;
649 if (lineStepSize <= 0) lineStepSize = 1;
651 imgPoly.
Create(*
cube(), sampleStepSize, lineStepSize);
654 tr(
"Warning: Polygon re-calculated for [%1] which can be very slow")
668 bool hasCamStats =
false;
671 for (
int i = 0; !hasCamStats && i < label.
objects(); i++) {
675 if (obj.
name() ==
"Table") {
676 if (obj[
"Name"][0] ==
"CameraStatistics") {
688 int numRecords = camStatsTable.
Records();
689 for (
int recordIndex = 0; recordIndex < numRecords; recordIndex++) {
694 QString recordName((QString)record[
"Name"]);
695 double avgValue = (double)record[
"Average"];
697 if (recordName ==
"AspectRatio") {
700 else if (recordName ==
"Resolution") {
703 else if (recordName ==
"EmissionAngle") {
706 else if (recordName ==
"IncidenceAngle") {
709 else if (recordName ==
"LineResolution") {
712 else if (recordName ==
"LocalRadius") {
715 else if (recordName ==
"NorthAzimuth") {
718 else if (recordName ==
"PhaseAngle") {
721 else if (recordName ==
"SampleResolution") {
727 for (
int i = 0; i < label.
objects(); i++) {
784 const QString &qName,
const QXmlAttributes &atts) {
787 if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
788 if (localName ==
"image") {
789 QString
id = atts.value(
"id");
790 QString
fileName = atts.value(
"fileName");
791 QString instrumentId = atts.value(
"instrumentId");
792 QString spacecraftName = atts.value(
"spacecraftName");
794 QString aspectRatioStr = atts.value(
"aspectRatio");
795 QString resolutionStr = atts.value(
"resolution");
796 QString emissionAngleStr = atts.value(
"emissionAngle");
797 QString incidenceAngleStr = atts.value(
"incidenceAngle");
798 QString lineResolutionStr = atts.value(
"lineResolution");
799 QString localRadiusStr = atts.value(
"localRadius");
800 QString northAzimuthStr = atts.value(
"northAzimuth");
801 QString phaseAngleStr = atts.value(
"phaseAngle");
802 QString sampleResolutionStr = atts.value(
"sampleResolution");
805 delete m_image->m_id;
806 m_image->m_id = NULL;
807 m_image->m_id =
new QUuid(
id.toLatin1());
810 if (!fileName.isEmpty()) {
811 m_image->m_fileName = m_imageFolder.expanded() +
"/" +
fileName;
814 if (!instrumentId.isEmpty()) {
815 m_image->m_instrumentId = m_imageFolder.expanded() +
"/" + instrumentId;
818 if (!spacecraftName.isEmpty()) {
819 m_image->m_spacecraftName = m_imageFolder.expanded() +
"/" + spacecraftName;
822 if (!aspectRatioStr.isEmpty()) {
823 m_image->m_aspectRatio = aspectRatioStr.toDouble();
826 if (!resolutionStr.isEmpty()) {
827 m_image->m_resolution = resolutionStr.toDouble();
830 if (!emissionAngleStr.isEmpty()) {
834 if (!incidenceAngleStr.isEmpty()) {
838 if (!lineResolutionStr.isEmpty()) {
839 m_image->m_lineResolution = lineResolutionStr.toDouble();
842 if (!localRadiusStr.isEmpty()) {
846 if (!northAzimuthStr.isEmpty()) {
850 if (!phaseAngleStr.isEmpty()) {
854 if (!sampleResolutionStr.isEmpty()) {
855 m_image->m_sampleResolution = sampleResolutionStr.toDouble();
858 else if (localName ==
"displayProperties") {
880 return XmlStackedHandler::characters(ch);
896 const QString &qName) {
897 if (localName ==
"footprint" && !m_characters.isEmpty()) {
898 geos::io::WKTReader wktReader(&globalFactory);
900 wktReader.read(m_characters.toStdString()));
902 else if (localName ==
"image" && !m_image->m_footprint) {
904 m_image->initFootprint(&mutex);
905 m_image->closeCube();
909 return XmlStackedHandler::endElement(namespaceURI, localName, qName);
PvlObject & object(const int index)
Return the object at the specified index.
PvlObject toPvl() const
Convert to Pvl for project files.
Angle incidenceAngle() const
Get the incidence angle of this image, as calculated and attached by camstats.
int Records() const
Returns the number of records.
void initQuickFootprint()
Creates a default ImagePolygon option which is read into the Cube.
const double Null
Value for an Isis Null pixel.
The main project for cnetsuite.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
QString id() const
Get a unique, identifying string associated with this 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...
File name manipulation and expansion.
FileName externalCubeFileName() const
If this is an external cube label file, this will give you the cube dn file that this label reference...
~Image()
Clean up this image.
QString m_instrumentId
Instrument id associated with this Image.
void deleteFromDisk()
Delete the image data from disk.
double radians() const
Convert an angle to a double.
QUuid * m_id
A unique ID for this Image (useful for others to reference this Image when saving to disk)...
QString fileName() const
Get the file name of the cube that this image represents.
bool isFootprintable() const
Test to see if it's possible to create a footprint from this image.
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
Pvl * label() const
Returns a pointer to the IsisLabel object associated with the cube.
Distance m_localRadius
Local radius of the image.
Image * m_image
Pointer to the Image.
double sampleResolution() const
Get the sample resolution of this image, as calculated and attached by camstats.
double lineResolution() const
Get the line resolution of this image, as calculated and attached by camstats.
double m_resolution
Resolution of the image.
void read(Blob &blob) const
This method will read data from the specified Blob object.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
This error is for when a programmer made an API call that was illegal.
A type of error that occurred when performing an actual I/O operation.
Angle m_northAzimuth
North Azimuth for the image.
Distance measurement, usually in meters.
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.
Distance localRadius() const
Get the local radius of this image, as calculated and attached by camstats.
Angle m_emissionAngle
Emmission angle of the image.
void setId(QString id)
Override the automatically generated ID with the given ID.
double m_aspectRatio
Aspect ratio of the image.
QString m_spacecraftName
Spacecraft name associated with this Image.
Create cube polygons, read/write polygons to blobs.
Cube * m_cube
The cube associated with this Image.
static QString Compose(Pvl &label, bool def2filename=false)
Compose a SerialNumber from a PVL.
bool hasKeyword(const QString &kname, FindOptions opts) const
See if a keyword is in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within ...
void copyToNewProjectRoot(const Project *project, FileName newProjectRoot)
Copy the cub/ecub files associated with this image into the new project.
PvlObject toPvl() const
Convert this Image to PVL.
SpiceInt * m_bodyCode
The NaifBodyCode value, if it exists in the labels.
This is the GUI communication mechanism for cubes.
double meters() const
Get the distance in meters.
virtual bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts)
The XML reader invokes this method at the start of every element in the XML document.
Degrees are generally considered more human readable, 0-360 is one circle, however most math does not...
Angle m_phaseAngle
Phase angle for the image.
Angle m_incidenceAngle
Incidence angle of the image.
QString displayName() const
Returns the display name.
QString m_fileName
The on-disk file name of the cube associated with this Image.
Contains multiple PvlContainers.
#define _FILEINFO_
Macro for the filename and line number.
void print() const
Prints a string representation of this exception to stderr.
bool isValid() const
Test if this distance has been initialized or not.
Image(QString imageFileName, QObject *parent=0)
Create an image from a cube file on disk.
int objects() const
Returns the number of objects.
Manipulate and parse attributes of output cube filenames.
A type of error that could only have occurred due to a mistake on the user's part (e...
A single keyword-value pair.
virtual bool characters(const QString &ch)
This implementation of a virtual function calls QXmlDefaultHandler::characters(QString &ch) which in ...
A type of error that cannot be classified as any of the other error types.
double aspectRatio() const
Get the aspect ratio of this image, as calculated and attached by camstats.
QString Type() const
Accessor method that returns a string containing the Blob type.
double m_lineResolution
Line resolution of the image.
bool IsSpecial(const double d)
Returns if the input pixel is special.
This represents a cube in a project-based GUI interface.
ImageDisplayProperties * displayProperties()
Get the display (GUI) properties (information) associated with this image.
Container for cube-like labels.
double resolution() const
Get the resolution of this image, as calculated and attached by camstats.
bool isValid() const
This indicates whether we have a legitimate angle stored or are in an unset, or invalid, state.
ImageDisplayProperties * m_displayProperties
The GUI information for how this Image ought to be displayed.
virtual bool endElement(const QString &namespaceURI, const QString &localName, const QString &qName)
The XML reader invokes this method at the end of every element in the XML document.
Angle northAzimuth() const
Get the north azimuth of this image, as calculated and attached by camstats.
Defines an angle and provides unit conversions.
void initCamStats()
Checks to see if the Cube label contains Camera Statistics.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Write the Image properties out to an XML file.
FileName m_imageFolder
The Name/path of the image.
Class for storing Table blobs information.
bool initFootprint(QMutex *cameraMutex)
Calculate a footprint for this image.
QString Name() const
Accessor method that returns a string containing the Blob name.
double m_sampleResolution
Sample resolution of the image.
XmlHandler(Image *image, FileName imageFolder)
Create an XML Handler (reader) that can populate the Image class data.
QString serialNumber()
Returns the serial number of the Cube.
geos::geom::MultiPolygon * footprint()
Get the footprint of this image (if available).
Adds specific functionality to C++ strings.
Cube * cube()
Get the Cube pointer associated with this display property.
Child class for XmlStackedHandler which is used to process XML in a stack-oriented way...
bool isNamed(const QString &match) const
Returns whether the given string is equal to the container name or not.
QString fileName() const
Returns the opened cube's filename.
The distance is being specified in meters.
bool hasGroup(const QString &name) const
Returns a boolean value based on whether the object has the specified group or not.
Radians are generally used in mathematical equations, 0-2*PI is one circle, however these are more di...
static QString imageDataRoot(QString projectRoot)
Appends the root directory name 'images' to the project .
geos::geom::MultiPolygon * Polys()
Return a geos Multipolygon.
void fromPvl(const PvlObject &pvl)
Read the image settings from a Pvl.
Contains Pvl Groups and Pvl Objects.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Output format:
QString path() const
Returns the path.
his enables stack-based XML parsing of XML files.
QString projectRoot() const
Get the top-level folder of the project.
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
Angle phaseAngle() const
Get the phase angle of this image, as calculated and attached by camstats.
geos::geom::MultiPolygon * m_footprint
A 0-360 ocentric lon,lat degrees footprint of this Image.
QString name() const
Returns the container name.
void closeCube()
Cleans up the Cube pointer.
QString imageDataRoot() const
Accessor for the root directory of the image data.
geos::geom::MultiPolygon * createFootprint(QMutex *cameraMutex)
Calculates a footprint for an Image using the camera or projection information.
IO Handler for Isis Cubes.