Isis 3 Programmer Reference
StripPolygonSeeder.cpp
Go to the documentation of this file.
1 
24 #include <string>
25 #include <vector>
26 
27 #include "Pvl.h"
28 #include "PvlGroup.h"
29 #include "IException.h"
30 #include "PolygonTools.h"
31 
32 #include "StripPolygonSeeder.h"
33 
34 namespace Isis {
35 
44  Parse(pvl);
45  };
46 
47 
67  std::vector<geos::geom::Point *> StripPolygonSeeder::Seed(const geos::geom::MultiPolygon *multiPoly) {
68 
69  // Storage for the points to be returned
70  std::vector<geos::geom::Point *> points;
71 
72  // Create some things we will need shortly
73  const geos::geom::Envelope *polyBoundBox = multiPoly->getEnvelopeInternal();
74 
75  // Call the parents standardTests member
76  QString msg = StandardTests(multiPoly, polyBoundBox);
77  if(!msg.isEmpty()) {
78  return points;
79  }
80 
81  // Do strip seeder specific tests to make sure this poly should be seeded
82  // (none for now)
83 
84  // Starting at the centroid of the xy polygon populate the polygon with
85  // staggered points with the requested spacing
86  geos::geom::Point *centroid = multiPoly->getCentroid();
87  double centerX = centroid->getX();
88  double centerY = centroid->getY();
89  delete centroid;
90 
91  int xStepsToCentroid = (int)((centerX - polyBoundBox->getMinX()) / p_Xspacing + 0.5);
92  int yStepsToCentroid = (int)((centerY - polyBoundBox->getMinY()) / p_Yspacing + 0.5);
93  double dRealMinX = centerX - (xStepsToCentroid * p_Xspacing);
94  double dRealMinY = centerY - (yStepsToCentroid * p_Yspacing);
95  double dDeltaXToReal = p_Xspacing * 1.0 / 6.0;
96  double dDeltaYToReal = p_Yspacing * 1.0 / 6.0;
97 
98  for(double y = dRealMinY; y <= polyBoundBox->getMaxY(); y += p_Yspacing) {
99  //printf("Grid Line,%.10f,%.10f,Through,%.10f,%.10f\n",dRealMinX, y, xyBoundBox->getMaxX(), y);
100  for(double x = dRealMinX; x <= polyBoundBox->getMaxX(); x += p_Xspacing) {
101  geos::geom::Coordinate c(x + dDeltaXToReal, y + dDeltaYToReal);
102  geos::geom::Point *p = Isis::globalFactory.createPoint(c);
103  if(p->within(multiPoly)) {
104  points.push_back(Isis::globalFactory.createPoint(c));
105  }
106 
107  geos::geom::Coordinate c2(x - dDeltaXToReal, y - dDeltaYToReal);
108  p = Isis::globalFactory.createPoint(c2);
109  if(p->within(multiPoly)) {
110  points.push_back(Isis::globalFactory.createPoint(c2));
111  }
112  }
113  }
114 
115  return points;
116  }
117 
125  // Call the parents Parse method
127 
128  // Pull parameters specific to this algorithm out
129  try {
130  // Get info from Algorithm group
131  PvlGroup &algo = pvl.findGroup("PolygonSeederAlgorithm", Pvl::Traverse);
132  PvlGroup &invalgo = invalidInput->findGroup("PolygonSeederAlgorithm",
133  Pvl::Traverse);
134 
135  // Set the spacing
136  p_Xspacing = 0.0;
137  if(algo.hasKeyword("XSpacing")) {
138  p_Xspacing = (double) algo["XSpacing"];
139  if(invalgo.hasKeyword("XSpacing")) {
140  invalgo.deleteKeyword("XSpacing");
141  }
142  }
143  else {
144  QString msg = "PVL for StripSeeder must contain [XSpacing] in [";
145  msg += pvl.fileName() + "]";
147  }
148 
149  p_Yspacing = 0.0;
150  if(algo.hasKeyword("YSpacing")) {
151  p_Yspacing = (double) algo["YSpacing"];
152  if(invalgo.hasKeyword("YSpacing")) {
153  invalgo.deleteKeyword("YSpacing");
154  }
155  }
156  else {
157  QString msg = "PVL for StripSeeder must contain [YSpacing] in [";
158  msg += pvl.fileName() + "]";
160  }
161  }
162  catch(IException &e) {
163  QString msg = "Improper format for PolygonSeeder PVL [" + pvl.fileName() + "]";
165  }
166 
167  if(p_Xspacing <= 0.0) {
168  IString msg = "X Spacing must be greater that 0.0 [(" + IString(p_Xspacing) + "]";
170  }
171  if(p_Yspacing <= 0.0) {
172  IString msg = "Y Spacing must be greater that 0.0 [(" + IString(p_Yspacing) + "]";
174  }
175  }
176 
178  PvlGroup pluginInfo(grpName);
179 
180  PvlKeyword name("Name", Algorithm());
181  PvlKeyword minThickness("MinimumThickness", toString(MinimumThickness()));
182  PvlKeyword minArea("MinimumArea", toString(MinimumArea()));
183  PvlKeyword xSpac("XSpacing", toString(p_Xspacing));
184  PvlKeyword ySpac("YSpacing", toString(p_Yspacing));
185 
186  pluginInfo.addKeyword(name);
187  pluginInfo.addKeyword(minThickness);
188  pluginInfo.addKeyword(minArea);
189  pluginInfo.addKeyword(xSpac);
190  pluginInfo.addKeyword(ySpac);
191 
192  return pluginInfo;
193  }
194 
195 }; // End of namespace Isis
196 
197 
210  return new Isis::StripPolygonSeeder(pvl);
211 }
212 
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
Isis::PolygonSeeder * StripPolygonSeederPlugin(Isis::Pvl &pvl)
Create a StripSeeder object.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:141
QString Algorithm() const
The name of the algorithm, read from the Name Keyword in the PolygonSeeder Pvl passed into the constr...
StripPolygonSeeder(Pvl &pvl)
Construct a StripPolygonSeeder algorithm.
Pvl * invalidInput
The Pvl passed in by the constructor minus what was used.
Definition: PolygonSeeder.h:94
virtual void Parse(Pvl &pvl)
Parse the StripSeeder spicific parameters from the PVL.
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.
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
double p_Xspacing
The spacing in the x direction between points.
Seed points using a grid with a staggered pattern.
std::vector< geos::geom::Point * > Seed(const geos::geom::MultiPolygon *mp)
Seed a polygon with points.
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 p_Yspacing
The spacing in the y direction between points.
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
Adds specific functionality to C++ strings.
Definition: IString.h:181
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
virtual PvlGroup PluginParameters(QString grpName)
Plugin parameters.
void deleteKeyword(const QString &name)
Remove a specified keyword.