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
19namespace Isis {
20
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
70 p_polygon = PolygonTools::MakeMultiPolygon(geosReader.readHEX(multiPolygon).release());
71 }
72
73
79 delete p_polygon;
80 };
81
82
88 p_serialNumbers.clear();
89 p_polygon = NULL;
90 }
91
92
100 void ImageOverlap::SetPolygon(const geos::geom::MultiPolygon &polygon) {
101 if(p_polygon != NULL) {
102 delete p_polygon;
103 p_polygon = NULL;
104 }
105
106 p_polygon = PolygonTools::CopyMultiPolygon(polygon);
107 }
108
109
117 void ImageOverlap::SetPolygon(const geos::geom::MultiPolygon *polygon) {
118 if(p_polygon != NULL) {
119 delete p_polygon;
120 p_polygon = NULL;
121 }
122
123 p_polygon = PolygonTools::CopyMultiPolygon(polygon);
124 }
125
126
127 void ImageOverlap::Write(std::ostream &outputStream) {
128
129 geos::io::WKBWriter geosWriter;
130
131 QString serialNums;
132
133 for(unsigned int sn = 0; sn < p_serialNumbers.size(); sn++) {
134 if(sn != 0) {
135 serialNums += ",";
136 }
137
138 serialNums += p_serialNumbers[sn];
139 }
140
141 serialNums += "\n";
142
143 outputStream << serialNums;
144
145 geosWriter.writeHEX(*p_polygon, outputStream);
146 }
147
148
156 void ImageOverlap::Add(QString &sn) {
157 for(unsigned int s = 0; s < p_serialNumbers.size(); ++s) {
158 if(sn == p_serialNumbers[s]) {
159 QString msg = "Duplicate SN added to [" +
160 QString::fromStdString(p_polygon->toString()) + "]";
161 throw IException(IException::Programmer, msg, _FILEINFO_);
162 }
163 }
164
165 p_serialNumbers.push_back(sn);
166 return;
167 }
168
169
177 return p_polygon->getArea();
178 }
179
180
186 for(int thisSn = 0; thisSn < this->Size(); ++thisSn) {
187 for(int otherSn = 0; otherSn < other.Size(); ++otherSn) {
188 if(p_serialNumbers[thisSn] == other.p_serialNumbers[otherSn]) {
189 return true;
190 }
191 }
192 }
193 return false;
194 }
195
196
206 bool ImageOverlap::HasSerialNumber(QString &sn) const {
207 for(int thisSn = 0; thisSn < Size(); ++thisSn) {
208 if(p_serialNumbers[thisSn] == sn) {
209 return true;
210 }
211 }
212 return false;
213 }
214}
Isis exception class.
Definition IException.h:91
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
Individual overlap container.
virtual void SetPolygon(const geos::geom::MultiPolygon &polygon)
This method will replace the existing polygon that defines the overlap with a new one.
virtual double Area()
This method will return the area of the polygon.
void Init()
Initialize this object to a known state.
void Add(QString &sn)
This method will add a new serial number to the list of serial numbers alread associated with the ove...
ImageOverlap()
Construct an empty ImageOverlap object.
bool HasAnySameSerialNumber(ImageOverlap &other) const
This method will return true if any serial number from this ImageOverlap is also in the other ImageOv...
bool HasSerialNumber(QString &sn) const
This method will return true if input serial number exists in the ImageOverlap.
virtual ~ImageOverlap()
Destroy this ImageOverlap object.
static geos::geom::MultiPolygon * CopyMultiPolygon(const geos::geom::MultiPolygon *mpolygon)
This static method will create a deep copy of a geos::geom::MultiPolygon.
static geos::geom::MultiPolygon * MakeMultiPolygon(const geos::geom::Geometry *geom)
Make a geos::geom::MultiPolygon out of the components of the argument.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16