USGS

Isis 3.0 Object Programmers' Reference

Home

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