77 return SeedGrid(lonLatPoly);
84 std::vector<geos::geom::Point *> GridPolygonSeeder::SeedGrid(
const geos::geom::MultiPolygon *multiPoly) {
87 std::vector<geos::geom::Point *> points;
90 const geos::geom::Envelope *polyBoundBox = multiPoly->getEnvelopeInternal();
103 geos::geom::Point *centroid = multiPoly->getCentroid();
104 double centerX = centroid->getX();
105 double centerY = centroid->getY();
108 int xStepsLeft = (int)((centerX - polyBoundBox->getMinX()) / p_Xspacing + 0.5);
109 int yStepsLeft = (int)((centerY - polyBoundBox->getMinY()) / p_Yspacing + 0.5);
110 double dRealMinX = centerX - (xStepsLeft * p_Xspacing);
111 double dRealMinY = centerY - (yStepsLeft * p_Yspacing);
113 for(
double y = dRealMinY; y <= polyBoundBox->getMaxY(); y += p_Yspacing) {
114 for(
double x = dRealMinX; x <= polyBoundBox->getMaxX(); x += p_Xspacing) {
115 geos::geom::Coordinate c(x, y);
116 geos::geom::Point *p = Isis::globalFactory.createPoint(c);
118 if(p->within(multiPoly)) {
119 points.push_back(Isis::globalFactory.createPoint(c));
143 std::vector<geos::geom::Point *> points;
147 const geos::geom::Envelope *polyBoundBox = multiPoly->getEnvelopeInternal();
155 geos::geom::Point *centroid = multiPoly->getCentroid();
156 double centerX = centroid->getX();
157 double centerY = centroid->getY();
173 pointShouldSubGridCheck,
181 int xSteps = (int)((polyBoundBox->getMaxX() - polyBoundBox->getMinX()) / p_Xspacing + 1.5);
182 int ySteps = (int)((polyBoundBox->getMaxY() - polyBoundBox->getMinY()) / p_Yspacing + 1.5);
183 PointStatus pointCheck[xSteps][ySteps];
186 for(
int y = 0; y < ySteps; y++) {
187 for(
int x = 0; x < xSteps; x++) {
188 pointCheck[x][y] = pointShouldCheck;
201 bool bGridCleared =
true;
202 int xStepsToCentroid = (int)((centerX - polyBoundBox->getMinX()) / p_Xspacing + 0.5);
203 int yStepsToCentroid = (int)((centerY - polyBoundBox->getMinY()) / p_Yspacing + 0.5);
204 double dRealMinX = centerX - (xStepsToCentroid * p_Xspacing);
205 double dRealMinY = centerY - (yStepsToCentroid * p_Yspacing);
212 for(
int y = 0; y < ySteps; y++) {
213 double centerY = dRealMinY + p_Yspacing * y;
214 for(
int x = 0; x < xSteps; x++) {
215 double centerX = dRealMinX + p_Xspacing * x;
216 geos::geom::Point *p = NULL;
220 if(pointCheck[x][y] == pointShouldCheck) {
225 else if(pointCheck[x][y] == pointShouldSubGridCheck) {
226 p =
CheckSubGrid(*multiPoly, centerX, centerY, precision);
242 points.push_back(Isis::globalFactory.createPoint(
243 geos::geom::Coordinate(p->getX(), p->getY())));
246 bGridCleared =
false;
247 pointCheck[x][y] = pointFound;
250 if(pointCheck[x][y] == pointShouldCheck) {
251 pointCheck[x][y] = pointNotFound;
253 else if(pointCheck[x][y] == pointShouldSubGridCheck) {
254 pointCheck[x][y] = pointCantFind;
261 for(
int y = 0; y < ySteps; y++) {
262 for(
int x = 0; x < xSteps; x++) {
263 if(pointCheck[x][y] == pointFound) {
264 for(
int yOff = -1; yOff <= 1; yOff++) {
265 for(
int xOff = -1; xOff <= 1; xOff++) {
266 if(x + xOff >= 0 && x + xOff < xSteps &&
267 y + yOff >= 0 && y + yOff < ySteps &&
268 pointCheck[x+xOff][y+yOff] == pointNotFound) {
270 pointCheck[x+xOff][y+yOff] = pointShouldSubGridCheck;
273 bGridCleared =
false;
282 while(!bGridCleared);
309 const double ¢erY,
const int &precision) {
313 for(
int prec = 0; prec < precision && prec < 6; prec ++) {
315 gridSize = gridSize * 2 + 1;
326 GridPoint grid[gridSize][gridSize];
328 for(
int y = 0; y < gridSize; y++) {
329 for(
int x = 0; x < gridSize; x++) {
330 grid[x][y] = gridEmpty;
335 grid[gridSize/2][gridSize/2] = gridCheckPt;
338 for(
int prec = 0; prec < precision; prec ++) {
340 int checkDist = (gridSize + 1) / (
int)(4 * (pow(2.0, prec)) + 0.5);
343 for(
int y = 0; y < gridSize; y++) {
344 for(
int x = 0; x < gridSize; x++) {
345 if(grid[x][y] == gridCheckPt) {
347 if(x - checkDist > 0) grid[x-checkDist][y] = gridNewCheckPt;
348 if(y - checkDist > 0) grid[x][y-checkDist] = gridNewCheckPt;
349 if(x + checkDist < gridSize) grid[x+checkDist][y] = gridNewCheckPt;
350 if(y + checkDist < gridSize) grid[x][y+checkDist] = gridNewCheckPt;
357 for(
int y = 0; y < gridSize; y++) {
358 for(
int x = 0; x < gridSize; x++) {
359 if(grid[x][y] == gridNewCheckPt) grid[x][y] = gridCheckPt;
366 double deltaXSize = p_Xspacing / (gridSize + 1);
367 double deltaYSize = p_Yspacing / (gridSize + 1);
369 geos::geom::Point *result = NULL;
371 for(
int y = 0; !result && y < gridSize; y++) {
372 for(
int x = 0; !result && x < gridSize; x++) {
373 if(grid[x][y] != gridCheckPt)
continue;
375 double xPos = centerX + (x - gridSize / 2) * deltaXSize;
376 double yPos = centerY + (y - gridSize / 2) * deltaYSize;
377 geos::geom::Coordinate c(xPos, yPos);
378 geos::geom::Point *p = Isis::globalFactory.createPoint(c);
379 if(p->within(&xymp)) {
411 p_Xspacing = (double) algo[
"XSpacing"];
417 QString msg =
"PVL for GridPolygonSeeder must contain [XSpacing] in [";
424 p_Yspacing = (double) algo[
"YSpacing"];
430 QString msg =
"PVL for GridPolygonSeeder must contain [YSpacing] in [";
437 p_subGrid =
IString((QString)algo[
"SubGrid"]).
UpCase() !=
"FALSE";
444 QString msg =
"Improper format for PolygonSeeder PVL [" + pvl.
fileName() +
"]";
448 if(p_Xspacing <= 0.0) {
449 IString msg =
"X Spacing must be greater that 0.0 [(" +
IString(p_Xspacing) +
"]";
452 if(p_Yspacing <= 0.0) {
453 IString msg =
"Y Spacing must be greater that 0.0 [(" +
IString(p_Yspacing) +
"]";
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
virtual void Parse(Pvl &pvl)
Parse the GridPolygonSeeder spicific parameters from the PVL.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
virtual PvlGroup PluginParameters(QString grpName)
Plugin parameters.
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.
This class is used as the base class for all PolygonSeeder objects.
Seed points using a grid.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
void addKeyword(const PvlKeyword &keyword, const InsertMode mode=Append)
Add a keyword to the container.
Isis::PolygonSeeder * GridPolygonSeederPlugin(Isis::Pvl &pvl)
Create a GridPolygonSeeder object.
Contains multiple PvlContainers.
#define _FILEINFO_
Macro for the filename and line number.
A type of error that could only have occurred due to a mistake on the user's part (e...
A single keyword-value pair.
virtual void Parse(Pvl &pvl)
Initialize parameters in the PolygonSeeder class using a PVL specification.
Container for cube-like labels.
geos::geom::Point * CheckSubGrid(const geos::geom::MultiPolygon &, const double &, const double &, const int &)
This method is used to search for a valid point, on the polygon, within the square whose center is de...
QString StandardTests(const geos::geom::MultiPolygon *multiPoly, const geos::geom::Envelope *polyBoundBox)
Check the polygon to see if it meets standard criteria.
GridPolygonSeeder(Pvl &pvl)
Construct a GridPolygonSeeder algorithm.
double MinimumThickness()
Return the minimum allowed thickness of the polygon.
QString fileName() const
Returns the filename used to initialise the Pvl object.
double MinimumArea()
Return the minimum allowed area of the polygon.
Adds specific functionality to C++ strings.
Namespace for ISIS/Bullet specific routines.
std::vector< geos::geom::Point * > Seed(const geos::geom::MultiPolygon *mp)
Seed a polygon with points.
std::vector< geos::geom::Point * > SeedSubGrid(const geos::geom::MultiPolygon *mp)
This method works a lot like SeedGrid, except around the edges of known polygons. ...
IString UpCase()
Converst any lower case characters in the object IString with uppercase characters.
void deleteKeyword(const QString &name)
Remove a specified keyword.