Loading [MathJax]/jax/output/NativeMML/config.js
Isis 3 Programmer Reference
ImageOverlap.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include <iostream>
8 #include <sstream>
9 
10 #include "geos/io/WKBReader.h"
11 #include "geos/io/WKBWriter.h"
12 
13 #include "PolygonTools.h"
14 #include "IException.h"
15 #include "FileName.h"
16 #include "ImageOverlap.h"
17 #include "IString.h"
18 
19 namespace Isis {
20 
26  Init();
27  }
28 
29 
38  ImageOverlap::ImageOverlap(QString serialNumber,
39  geos::geom::MultiPolygon &polygon) {
40  Init();
41  SetPolygon(polygon);
42  Add(serialNumber);
43  }
44 
45 
52  ImageOverlap::ImageOverlap(std::istream &inputStream) {
53  geos::io::WKBReader geosReader;
54 
55  std::string fileData;
56  getline(inputStream, fileData);
57 
58  QString serialNums = fileData.c_str();
59  foreach (QString serialNum, serialNums.split(",")) {
60  Add(serialNum);
61  }
62 
63  // now get the multipolygon on the next line
64  getline(inputStream, fileData);
65 
66  std::stringstream multiPolygon;
67  multiPolygon << fileData;
68  multiPolygon.seekg(0, std::ios::beg);
69 
71  geosReader.readHEX(multiPolygon));
72  }
73 
74 
80  delete p_polygon;
81  };
82 
83 
89  p_serialNumbers.clear();
90  p_polygon = NULL;
91  }
92 
93 
101  void ImageOverlap::SetPolygon(const geos::geom::MultiPolygon &polygon) {
102  if(p_polygon != NULL) {
103  delete p_polygon;
104  p_polygon = NULL;
105  }
106 
107  p_polygon = PolygonTools::CopyMultiPolygon(polygon);
108  }
109 
110 
118  void ImageOverlap::SetPolygon(const geos::geom::MultiPolygon *polygon) {
119  if(p_polygon != NULL) {
120  delete p_polygon;
121  p_polygon = NULL;
122  }
123 
124  p_polygon = PolygonTools::CopyMultiPolygon(polygon);
125  }
126 
127 
128  void ImageOverlap::Write(std::ostream &outputStream) {
129 
130  geos::io::WKBWriter geosWriter;
131 
132  QString serialNums;
133 
134  for(unsigned int sn = 0; sn < p_serialNumbers.size(); sn++) {
135  if(sn != 0) {
136  serialNums += ",";
137  }
138 
139  serialNums += p_serialNumbers[sn];
140  }
141 
142  serialNums += "\n";
143 
144  outputStream << serialNums;
145 
146  geosWriter.writeHEX(*p_polygon, outputStream);
147  }
148 
149 
157  void ImageOverlap::Add(QString &sn) {
158  for(unsigned int s = 0; s < p_serialNumbers.size(); ++s) {
159  if(sn == p_serialNumbers[s]) {
160  QString msg = "Duplicate SN added to [" +
161  QString::fromStdString(p_polygon->toString()) + "]";
162  throw IException(IException::Programmer, msg, _FILEINFO_);
163  }
164  }
165 
166  p_serialNumbers.push_back(sn);
167  return;
168  }
169 
170 
178  return p_polygon->getArea();
179  }
180 
181 
187  for(int thisSn = 0; thisSn < this->Size(); ++thisSn) {
188  for(int otherSn = 0; otherSn < other.Size(); ++otherSn) {
189  if(p_serialNumbers[thisSn] == other.p_serialNumbers[otherSn]) {
190  return true;
191  }
192  }
193  }
194  return false;
195  }
196 
197 
207  bool ImageOverlap::HasSerialNumber(QString &sn) const {
208  for(int thisSn = 0; thisSn < Size(); ++thisSn) {
209  if(p_serialNumbers[thisSn] == sn) {
210  return true;
211  }
212  }
213  return false;
214  }
215 }
Isis::ImageOverlap
Individual overlap container.
Definition: ImageOverlap.h:40
Isis::ImageOverlap::SetPolygon
virtual void SetPolygon(const geos::geom::MultiPolygon &polygon)
This method will replace the existing polygon that defines the overlap with a new one.
Definition: ImageOverlap.cpp:101
Isis::ImageOverlap::HasSerialNumber
bool HasSerialNumber(QString &sn) const
This method will return true if input serial number exists in the ImageOverlap.
Definition: ImageOverlap.cpp:207
Isis::ImageOverlap::HasAnySameSerialNumber
bool HasAnySameSerialNumber(ImageOverlap &other) const
This method will return true if any serial number from this ImageOverlap is also in the other ImageOv...
Definition: ImageOverlap.cpp:186
Isis::ImageOverlap::~ImageOverlap
virtual ~ImageOverlap()
Destroy this ImageOverlap object.
Definition: ImageOverlap.cpp:79
Isis::ImageOverlap::Init
void Init()
Initialize this object to a known state.
Definition: ImageOverlap.cpp:88
Isis::ImageOverlap::Add
void Add(QString &sn)
This method will add a new serial number to the list of serial numbers alread associated with the ove...
Definition: ImageOverlap.cpp:157
Isis::PolygonTools::CopyMultiPolygon
static geos::geom::MultiPolygon * CopyMultiPolygon(const geos::geom::MultiPolygon *mpolygon)
This static method will create a deep copy of a geos::geom::MultiPolygon.
Definition: PolygonTools.cpp:354
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
Isis::PolygonTools::MakeMultiPolygon
static geos::geom::MultiPolygon * MakeMultiPolygon(const geos::geom::Geometry *geom)
Make a geos::geom::MultiPolygon out of the components of the argument.
Definition: PolygonTools.cpp:1369
Isis::ImageOverlap::ImageOverlap
ImageOverlap()
Construct an empty ImageOverlap object.
Definition: ImageOverlap.cpp:25
Isis::ImageOverlap::Area
virtual double Area()
This method will return the area of the polygon.
Definition: ImageOverlap.cpp:177
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the USGS Astrogeology Discussion Board
To report a bug, or suggest a feature go to: ISIS Github
File Modified: 03/21/2022 06:55:56