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"
28 #include "XmlStackedHandlerReader.h"
45 m_lineResolution =
Null;
46 m_sampleResolution =
Null;
62 m_id =
new QUuid(QUuid::createUuid());
82 m_lineResolution =
Null;
83 m_sampleResolution =
Null;
95 m_id =
new QUuid(QUuid::createUuid());
113 m_aspectRatio =
Null;
115 m_lineResolution =
Null;
116 m_sampleResolution =
Null;
118 xmlReader->pushContentHandler(
new XmlHandler(
this, imageFolder));
155 QString pvlFileName = ((
IString)pvl[
"FileName"][0]).ToQt();
158 tr(
"Tried to load Image [%1] with properties/information from [%2].")
166 QByteArray hexValues(pvl[
"ID"][0].toAscii());
167 QDataStream valuesStream(QByteArray::fromHex(hexValues));
168 valuesStream >> *
m_id;
193 dataBuffer.open(QIODevice::ReadWrite);
195 QDataStream idStream(&dataBuffer);
200 output +=
PvlKeyword(
"ID", QString(dataBuffer.data().toHex()));
222 QString blobType = example.
Type();
223 QString blobName = example.
Name();
227 for (
int i = 0; i < labels.
objects(); i++) {
230 if (obj.
isNamed(blobType) && obj.
hasKeyword(
"Name") && obj[
"Name"][0] == blobName)
309 *
m_id = QUuid(QString(
"{%1}").arg(
id));
330 initQuickFootprint();
337 IString msg =
"Could not read the footprint from cube [" +
339 "sure footprintinit has been run";
356 return m_aspectRatio;
366 return m_id->toString().remove(QRegExp(
"[{}]"));
388 return m_emissionAngle;
399 return m_incidenceAngle;
410 return m_lineResolution;
421 return m_localRadius;
432 return m_northAzimuth;
454 return m_sampleResolution;
468 QScopedPointer<Cube> newExternalLabel(
473 if (!origImage.storesDnData()) {
478 FileName newDnFileName = newExternalLabelFileName.setExtension(
"cub");
483 newExternalLabel->relocateDnData(newDnFileName.name());
503 tr(
"Could not remove file [%1]").arg(
m_fileName),
509 if (!QFile::remove(cubFile.expanded())) {
511 tr(
"Could not remove file [%1]").arg(
m_fileName),
534 stream.writeStartElement(
"image");
536 stream.writeAttribute(
"id",
m_id->toString());
540 stream.writeAttribute(
"aspectRatio",
IString(m_aspectRatio).ToQt());
544 stream.writeAttribute(
"resolution",
IString(m_resolution).ToQt());
547 if (m_emissionAngle.
isValid()) {
548 stream.writeAttribute(
"emissionAngle",
IString(m_emissionAngle.
radians()).ToQt());
551 if (m_incidenceAngle.
isValid()) {
552 stream.writeAttribute(
"incidenceAngle",
IString(m_incidenceAngle.
radians()).ToQt());
556 stream.writeAttribute(
"lineResolution",
IString(m_lineResolution).ToQt());
560 stream.writeAttribute(
"localRadius",
IString(m_localRadius.
meters()).ToQt());
563 if (m_northAzimuth.
isValid()) {
564 stream.writeAttribute(
"northAzimuth",
IString(m_northAzimuth.
radians()).ToQt());
568 stream.writeAttribute(
"phaseAngle",
IString(m_phaseAngle.
radians()).ToQt());
572 stream.writeAttribute(
"sampleResolution",
IString(m_sampleResolution).ToQt());
576 stream.writeStartElement(
"footprint");
578 geos::io::WKTWriter wktWriter;
579 stream.writeCharacters(QString::fromStdString(wktWriter.write(
m_footprint)));
581 stream.writeEndElement();
586 stream.writeEndElement();
601 original.dir().dirName() +
"/" + original.name());
613 QMutexLocker lock(cameraMutex);
619 if (sampleStepSize <= 0) sampleStepSize = 1;
622 if (lineStepSize <= 0) lineStepSize = 1;
624 imgPoly.
Create(*
cube(), sampleStepSize, lineStepSize);
627 tr(
"Warning: Polygon re-calculated for [%1] which can be very slow")
636 void Image::initCamStats() {
637 bool hasCamStats =
false;
640 for (
int i = 0; !hasCamStats && i < label.
objects(); i++) {
644 if (obj.
name() ==
"Table") {
645 if (obj[
"Name"][0] ==
"CameraStatistics") {
650 catch (IException &) {
655 Table camStatsTable(
"CameraStatistics",
m_fileName, label);
657 int numRecords = camStatsTable.Records();
658 for (
int recordIndex = 0; recordIndex < numRecords; recordIndex++) {
659 TableRecord &record = camStatsTable[recordIndex];
663 QString recordName((QString)record[
"Name"]);
664 double avgValue = (double)record[
"Average"];
666 if (recordName ==
"AspectRatio") {
667 m_aspectRatio = avgValue;
669 else if (recordName ==
"Resolution") {
670 m_resolution = avgValue;
672 else if (recordName ==
"EmissionAngle") {
675 else if (recordName ==
"IncidenceAngle") {
678 else if (recordName ==
"LineResolution") {
679 m_lineResolution = avgValue;
681 else if (recordName ==
"LocalRadius") {
684 else if (recordName ==
"NorthAzimuth") {
687 else if (recordName ==
"PhaseAngle") {
690 else if (recordName ==
"SampleResolution") {
691 m_sampleResolution = avgValue;
698 void Image::initQuickFootprint() {
714 m_imageFolder = imageFolder;
724 const QString &qName,
const QXmlAttributes &atts) {
727 if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
728 if (localName ==
"image") {
729 QString
id = atts.value(
"id");
730 QString
fileName = atts.value(
"fileName");
732 QString aspectRatioStr = atts.value(
"aspectRatio");
733 QString resolutionStr = atts.value(
"resolution");
734 QString emissionAngleStr = atts.value(
"emissionAngle");
735 QString incidenceAngleStr = atts.value(
"incidenceAngle");
736 QString lineResolutionStr = atts.value(
"lineResolution");
737 QString localRadiusStr = atts.value(
"localRadius");
738 QString northAzimuthStr = atts.value(
"northAzimuth");
739 QString phaseAngleStr = atts.value(
"phaseAngle");
740 QString sampleResolutionStr = atts.value(
"sampleResolution");
743 delete m_image->m_id;
744 m_image->m_id = NULL;
745 m_image->m_id =
new QUuid(
id.toAscii());
748 if (!fileName.isEmpty()) {
749 m_image->m_fileName = m_imageFolder.expanded() +
"/" +
fileName;
752 if (!aspectRatioStr.isEmpty()) {
753 m_image->m_aspectRatio = aspectRatioStr.toDouble();
756 if (!resolutionStr.isEmpty()) {
757 m_image->m_resolution = resolutionStr.toDouble();
760 if (!emissionAngleStr.isEmpty()) {
764 if (!incidenceAngleStr.isEmpty()) {
768 if (!lineResolutionStr.isEmpty()) {
769 m_image->m_lineResolution = lineResolutionStr.toDouble();
772 if (!localRadiusStr.isEmpty()) {
776 if (!northAzimuthStr.isEmpty()) {
780 if (!phaseAngleStr.isEmpty()) {
784 if (!sampleResolutionStr.isEmpty()) {
785 m_image->m_sampleResolution = sampleResolutionStr.toDouble();
788 else if (localName ==
"displayProperties") {
798 bool Image::XmlHandler::characters(
const QString &ch) {
801 return XmlStackedHandler::characters(ch);
806 bool Image::XmlHandler::endElement(
const QString &namespaceURI,
const QString &localName,
807 const QString &qName) {
808 if (localName ==
"footprint" && !m_characters.isEmpty()) {
809 geos::io::WKTReader wktReader(&globalFactory);
811 wktReader.read(m_characters.toStdString()));
813 else if (localName ==
"image" && !m_image->m_footprint) {
815 m_image->initFootprint(&mutex);
816 m_image->closeCube();
820 return XmlStackedHandler::endElement(namespaceURI, localName, qName);