Isis 3 Programmer Reference
PolygonSeeder.cpp
1 #include "PolygonSeeder.h"
2 
3 #include "IException.h"
4 #include "LeastSquares.h"
5 #include "Plugin.h"
6 #include "PolygonTools.h"
7 #include "PolynomialBivariate.h"
8 #include "LeastSquares.h"
9 #include "FileName.h"
10 #include "ProjectionFactory.h"
11 #include "Pvl.h"
12 #include "PvlGroup.h"
13 
14 
15 namespace Isis {
25  invalidInput = NULL;
26  invalidInput = new Pvl(pvl);
27 
28  p_algorithmName = "Unknown";
29 
30  Parse(pvl);
31  }
32 
33 
47  }
48 
49 
54  if(invalidInput) {
55  delete invalidInput;
56  invalidInput = NULL;
57  }
58  }
59 
60 
80 
81  QString errorSpot;
82 
83  try {
84  // Get info from Algorithm group
85  errorSpot = "Algorithm";
86  PvlGroup &algo = pvl.findGroup("PolygonSeederAlgorithm", Pvl::Traverse);
87 
88  // algo is such a cool name for a PvlGroup that it begs to be out done
89  PvlGroup &invalgo = invalidInput->findGroup("PolygonSeederAlgorithm",
91 
92  // Set the algorithm name
93  errorSpot = "Name";
94  p_algorithmName = (QString) algo["Name"];
95 
96  if(invalgo.hasKeyword("Name"))
97  invalgo.deleteKeyword("Name");
98 
99  // Set the minimum thickness (Area / max(extent X, extent Y)**2
100  errorSpot = "MinimumThickness";
101  p_minimumThickness = 0.0;
102  if(algo.hasKeyword("MinimumThickness")) {
103  p_minimumThickness = (double) algo["MinimumThickness"];
104  }
105 
106  if(invalgo.hasKeyword("MinimumThickness"))
107  invalgo.deleteKeyword("MinimumThickness");
108 
109  // Set the minimum area
110  errorSpot = "MinimumArea";
111  p_minimumArea = 0.0;
112  if(algo.hasKeyword("MinimumArea")) {
113  p_minimumArea = (double) algo["MinimumArea"];
114  }
115 
116  if(invalgo.hasKeyword("MinimumArea"))
117  invalgo.deleteKeyword("MinimumArea");
118  }
119  catch(IException &e) {
120  QString msg = "Improper format for PolygonSeeder PVL [";
121  msg += pvl.fileName() + "]. Location [" + errorSpot + "]";
123  }
124 
125  return;
126  }
127 
128 
140  QString PolygonSeeder::StandardTests(const geos::geom::MultiPolygon *xymp,
141  const geos::geom::Envelope *xyBoundBox) {
142  if(xymp->getArea() < MinimumArea()) {
143  QString msg = "Polygon did not meet the minimum area of [";
144  msg += toString(MinimumArea()) + "]";
145  return msg;
146  }
147 
148  double thickness =
149  xymp->getArea() /
150  pow(std::max(xyBoundBox->getWidth(), xyBoundBox->getHeight()), 2.0);
151  if(thickness < MinimumThickness()) {
152  QString msg = "Polygon did not meet the minimum thickness ratio of [";
153  msg += toString(MinimumThickness()) + "]";
154  return msg;
155  }
156 
157  return "";
158  }
159 
166  QString PolygonSeeder::Algorithm() const {
167  return p_algorithmName;
168  }
169 
178  return p_minimumThickness;
179  }
180 
181 
190  return p_minimumArea;
191  }
192 
205  PvlGroup pluginInfo(grpName);
206 
207  PvlKeyword name("Name", p_algorithmName);
208  PvlKeyword minThickness("MinimumThickness", toString(p_minimumThickness));
209  PvlKeyword minArea("MinimumArea", toString(p_minimumArea));
210 
211  pluginInfo.addKeyword(name);
212  pluginInfo.addKeyword(minThickness);
213  pluginInfo.addKeyword(minArea);
214 
215  return pluginInfo;
216  }
217 
218 
226  return *invalidInput;
227  }
228 
244 
245  return *this;
246  }
247 
248 }
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:141
virtual ~PolygonSeeder()
Destroys the PolygonSeeder object.
Pvl InvalidInput()
This method returns a copy of the Pvl passed in by the constructor (from a def file probably) minus w...
PolygonSeeder(Pvl &pvl)
Create PolygonSeeder object.
QString Algorithm() const
The name of the algorithm, read from the Name Keyword in the PolygonSeeder Pvl passed into the constr...
Pvl * invalidInput
The Pvl passed in by the constructor minus what was used.
Definition: PolygonSeeder.h:94
This class is used as the base class for all PolygonSeeder objects.
Definition: PolygonSeeder.h:63
Search child objects.
Definition: PvlObject.h:170
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
void addKeyword(const PvlKeyword &keyword, const InsertMode mode=Append)
Add a keyword to the container.
double p_minimumThickness
The value for the &#39;MinimumThickness&#39; Keyword in the PolygonSeederAlgorithm group of the Pvl that is p...
Contains multiple PvlContainers.
Definition: PvlGroup.h:57
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
A type of error that could only have occurred due to a mistake on the user&#39;s part (e...
Definition: IException.h:142
A single keyword-value pair.
Definition: PvlKeyword.h:98
virtual void Parse(Pvl &pvl)
Initialize parameters in the PolygonSeeder class using a PVL specification.
Container for cube-like labels.
Definition: Pvl.h:135
QString StandardTests(const geos::geom::MultiPolygon *multiPoly, const geos::geom::Envelope *polyBoundBox)
Check the polygon to see if it meets standard criteria.
double MinimumThickness()
Return the minimum allowed thickness of the polygon.
QString fileName() const
Returns the filename used to initialise the Pvl object.
Definition: PvlContainer.h:246
double MinimumArea()
Return the minimum allowed area of the polygon.
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
virtual PvlGroup PluginParameters(QString grpName)
Plugin parameters.
const PolygonSeeder & operator=(const PolygonSeeder &other)
Assignment operator.
void deleteKeyword(const QString &name)
Remove a specified keyword.
double p_minimumArea
The value for the &#39;MinimumArea&#39; Keyword in the PolygonSeederAlgorithm group of the Pvl that is passed...
QString p_algorithmName
The value for the &#39;Name&#39; Keyword in the PolygonSeederAlgorithm group of the Pvl that is passed into t...
Definition: PolygonSeeder.h:98