Isis 3 Programmer Reference
ImageOverlap.cpp
1 #include <iostream>
2 #include <sstream>
3 
4 #include "geos/io/WKBReader.h"
5 #include "geos/io/WKBWriter.h"
6 
7 #include "PolygonTools.h"
8 #include "IException.h"
9 #include "FileName.h"
10 #include "ImageOverlap.h"
11 #include "IString.h"
12 
13 namespace Isis {
14 
20  Init();
21  }
22 
23 
32  ImageOverlap::ImageOverlap(QString serialNumber,
33  geos::geom::MultiPolygon &polygon) {
34  Init();
35  SetPolygon(polygon);
36  Add(serialNumber);
37  }
38 
39 
46  ImageOverlap::ImageOverlap(std::istream &inputStream) {
47  geos::io::WKBReader geosReader;
48 
49  std::string fileData;
50  getline(inputStream, fileData);
51 
52  QString serialNums = fileData.c_str();
53  foreach (QString serialNum, serialNums.split(",")) {
54  Add(serialNum);
55  }
56 
57  // now get the multipolygon on the next line
58  getline(inputStream, fileData);
59 
60  std::stringstream multiPolygon;
61  multiPolygon << fileData;
62  multiPolygon.seekg(0, std::ios::beg);
63 
65  geosReader.readHEX(multiPolygon));
66  }
67 
68 
74  delete p_polygon;
75  };
76 
77 
83  p_serialNumbers.clear();
84  p_polygon = NULL;
85  }
86 
87 
95  void ImageOverlap::SetPolygon(const geos::geom::MultiPolygon &polygon) {
96  if(p_polygon != NULL) {
97  delete p_polygon;
98  p_polygon = NULL;
99  }
100 
101  p_polygon = PolygonTools::CopyMultiPolygon(polygon);
102  }
103 
104 
112  void ImageOverlap::SetPolygon(const geos::geom::MultiPolygon *polygon) {
113  if(p_polygon != NULL) {
114  delete p_polygon;
115  p_polygon = NULL;
116  }
117 
118  p_polygon = PolygonTools::CopyMultiPolygon(polygon);
119  }
120 
121 
122  void ImageOverlap::Write(std::ostream &outputStream) {
123 
124  geos::io::WKBWriter geosWriter;
125 
126  QString serialNums;
127 
128  for(unsigned int sn = 0; sn < p_serialNumbers.size(); sn++) {
129  if(sn != 0) {
130  serialNums += ",";
131  }
132 
133  serialNums += p_serialNumbers[sn];
134  }
135 
136  serialNums += "\n";
137 
138  outputStream << serialNums;
139 
140  geosWriter.writeHEX(*p_polygon, outputStream);
141  }
142 
143 
151  void ImageOverlap::Add(QString &sn) {
152  for(unsigned int s = 0; s < p_serialNumbers.size(); ++s) {
153  if(sn == p_serialNumbers[s]) {
154  QString msg = "Duplicate SN added to [" +
155  QString::fromStdString(p_polygon->toString()) + "]";
157  }
158  }
159 
160  p_serialNumbers.push_back(sn);
161  return;
162  }
163 
164 
172  return p_polygon->getArea();
173  }
174 
175 
181  for(int thisSn = 0; thisSn < this->Size(); ++thisSn) {
182  for(int otherSn = 0; otherSn < other.Size(); ++otherSn) {
183  if(p_serialNumbers[thisSn] == other.p_serialNumbers[otherSn]) {
184  return true;
185  }
186  }
187  }
188  return false;
189  }
190 
191 
201  bool ImageOverlap::HasSerialNumber(QString &sn) const {
202  for(int thisSn = 0; thisSn < Size(); ++thisSn) {
203  if(p_serialNumbers[thisSn] == sn) {
204  return true;
205  }
206  }
207  return false;
208  }
209 }
static geos::geom::MultiPolygon * CopyMultiPolygon(const geos::geom::MultiPolygon *mpolygon)
This static method will create a deep copy of a geos::geom::MultiPolygon.
virtual ~ImageOverlap()
Destroy this 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...
void Add(QString &sn)
This method will add a new serial number to the list of serial numbers alread associated with the ove...
bool HasSerialNumber(QString &sn) const
This method will return true if input serial number exists in the ImageOverlap.
virtual void SetPolygon(const geos::geom::MultiPolygon &polygon)
This method will replace the existing polygon that defines the overlap with a new one...
void Init()
Initialize this object to a known state.
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:162
static geos::geom::MultiPolygon * MakeMultiPolygon(const geos::geom::Geometry *geom)
Make a geos::geom::MultiPolygon out of the components of the argument.
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
virtual double Area()
This method will return the area of the polygon.
ImageOverlap()
Construct an empty ImageOverlap object.
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
Individual overlap container.
Definition: ImageOverlap.h:56