Isis 3 Programmer Reference
PolygonSeeder.cpp
1
6/* SPDX-License-Identifier: CC0-1.0 */
7#include "PolygonSeeder.h"
8
9#include "IException.h"
10#include "LeastSquares.h"
11#include "Plugin.h"
12#include "PolygonTools.h"
13#include "PolynomialBivariate.h"
14#include "LeastSquares.h"
15#include "FileName.h"
16#include "ProjectionFactory.h"
17#include "Pvl.h"
18#include "PvlGroup.h"
19
20
21namespace Isis {
31 invalidInput = NULL;
32 invalidInput = new Pvl(pvl);
33
34 p_algorithmName = "Unknown";
35
36 Parse(pvl);
37 }
38
39
50 p_algorithmName = other.p_algorithmName;
51 p_minimumThickness = other.p_minimumThickness;
52 p_minimumArea = other.p_minimumArea;
53 }
54
55
60 if(invalidInput) {
61 delete invalidInput;
62 invalidInput = NULL;
63 }
64 }
65
66
86
87 QString errorSpot;
88
89 try {
90 // Get info from Algorithm group
91 errorSpot = "Algorithm";
92 PvlGroup &algo = pvl.findGroup("PolygonSeederAlgorithm", Pvl::Traverse);
93
94 // algo is such a cool name for a PvlGroup that it begs to be out done
95 PvlGroup &invalgo = invalidInput->findGroup("PolygonSeederAlgorithm",
97
98 // Set the algorithm name
99 errorSpot = "Name";
100 p_algorithmName = (QString) algo["Name"];
101
102 if(invalgo.hasKeyword("Name"))
103 invalgo.deleteKeyword("Name");
104
105 // Set the minimum thickness (Area / max(extent X, extent Y)**2
106 errorSpot = "MinimumThickness";
107 p_minimumThickness = 0.0;
108 if(algo.hasKeyword("MinimumThickness")) {
109 p_minimumThickness = (double) algo["MinimumThickness"];
110 }
111
112 if(invalgo.hasKeyword("MinimumThickness"))
113 invalgo.deleteKeyword("MinimumThickness");
114
115 // Set the minimum area
116 errorSpot = "MinimumArea";
117 p_minimumArea = 0.0;
118 if(algo.hasKeyword("MinimumArea")) {
119 p_minimumArea = (double) algo["MinimumArea"];
120 }
121
122 if(invalgo.hasKeyword("MinimumArea"))
123 invalgo.deleteKeyword("MinimumArea");
124 }
125 catch(IException &e) {
126 QString msg = "Improper format for PolygonSeeder PVL [";
127 msg += pvl.fileName() + "]. Location [" + errorSpot + "]";
128 throw IException(IException::User, msg, _FILEINFO_);
129 }
130
131 return;
132 }
133
134
146 QString PolygonSeeder::StandardTests(const geos::geom::MultiPolygon *xymp,
147 const geos::geom::Envelope *xyBoundBox) {
148 if(xymp->getArea() < MinimumArea()) {
149 QString msg = "Polygon did not meet the minimum area of [";
150 msg += toString(MinimumArea()) + "]";
151 return msg;
152 }
153
154 double thickness =
155 xymp->getArea() /
156 pow(std::max(xyBoundBox->getWidth(), xyBoundBox->getHeight()), 2.0);
157 if(thickness < MinimumThickness()) {
158 QString msg = "Polygon did not meet the minimum thickness ratio of [";
159 msg += toString(MinimumThickness()) + "]";
160 return msg;
161 }
162
163 return "";
164 }
165
172 QString PolygonSeeder::Algorithm() const {
173 return p_algorithmName;
174 }
175
186
187
196 return p_minimumArea;
197 }
198
211 PvlGroup pluginInfo(grpName);
212
213 PvlKeyword name("Name", p_algorithmName);
214 PvlKeyword minThickness("MinimumThickness", toString(p_minimumThickness));
215 PvlKeyword minArea("MinimumArea", toString(p_minimumArea));
216
217 pluginInfo.addKeyword(name);
218 pluginInfo.addKeyword(minThickness);
219 pluginInfo.addKeyword(minArea);
220
221 return pluginInfo;
222 }
223
224
234
247 p_algorithmName = other.p_algorithmName;
248 p_minimumThickness = other.p_minimumThickness;
249 p_minimumArea = other.p_minimumArea;
250
251 return *this;
252 }
253
254}
Isis exception class.
Definition IException.h:91
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition IException.h:126
This class is used as the base class for all PolygonSeeder objects.
Pvl InvalidInput()
This method returns a copy of the Pvl passed in by the constructor (from a def file probably) minus w...
virtual void Parse(Pvl &pvl)
Initialize parameters in the PolygonSeeder class using a PVL specification.
Pvl * invalidInput
The Pvl passed in by the constructor minus what was used.
QString StandardTests(const geos::geom::MultiPolygon *multiPoly, const geos::geom::Envelope *polyBoundBox)
Check the polygon to see if it meets standard criteria.
virtual PvlGroup PluginParameters(QString grpName)
Plugin parameters.
virtual ~PolygonSeeder()
Destroys the PolygonSeeder object.
double p_minimumThickness
The value for the 'MinimumThickness' Keyword in the PolygonSeederAlgorithm group of the Pvl that is p...
QString p_algorithmName
The value for the 'Name' Keyword in the PolygonSeederAlgorithm group of the Pvl that is passed into t...
PolygonSeeder(Pvl &pvl)
Create PolygonSeeder object.
double MinimumArea()
Return the minimum allowed area of the polygon.
double MinimumThickness()
Return the minimum allowed thickness of the polygon.
QString Algorithm() const
The name of the algorithm, read from the Name Keyword in the PolygonSeeder Pvl passed into the constr...
double p_minimumArea
The value for the 'MinimumArea' Keyword in the PolygonSeederAlgorithm group of the Pvl that is passed...
const PolygonSeeder & operator=(const PolygonSeeder &other)
Assignment operator.
Contains multiple PvlContainers.
Definition PvlGroup.h:41
Container for cube-like labels.
Definition Pvl.h:119
A single keyword-value pair.
Definition PvlKeyword.h:87
@ Traverse
Search child objects.
Definition PvlObject.h:158
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition PvlObject.h:129
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition IString.cpp:211