Official websites use .gov
A .gov website belongs to an official government organization in the United States.

Secure .gov websites use HTTPS
A lock ( ) or https:// means you’ve safely connected to the .gov website. Share sensitive information only on official, secure websites.

Isis 3 Programmer Reference
StripPolygonSeeder.cpp
1
5
6/* SPDX-License-Identifier: CC0-1.0 */
7
8#include <string>
9#include <vector>
10
11#include "Pvl.h"
12#include "PvlGroup.h"
13#include "IException.h"
14#include "PolygonTools.h"
15
16#include "StripPolygonSeeder.h"
17
18namespace Isis {
19
30
31
51 std::vector<geos::geom::Point *> StripPolygonSeeder::Seed(const geos::geom::MultiPolygon *multiPoly) {
52
53 // Storage for the points to be returned
54 std::vector<geos::geom::Point *> points;
55
56 // Create some things we will need shortly
57 const geos::geom::Envelope *mPolyBoundBox = multiPoly->getEnvelopeInternal();
58
59 // Call the parents standardTests member
60 QString msg = StandardTests(multiPoly, mPolyBoundBox);
61 if(!msg.isEmpty()) {
62 return points;
63 }
64
65 for(unsigned int i = 0; i < multiPoly->getNumGeometries(); ++i) {
66 const geos::geom::Polygon *poly = multiPoly->getGeometryN(i);
67 // Do strip seeder specific tests to make sure this poly should be seeded
68 // (none for now)
69
70 // Starting at the centroid of the xy polygon populate the polygon with
71 // staggered points with the requested spacing
72 geos::geom::Point *centroid = poly->getCentroid().release();
73 double centerX = centroid->getX();
74 double centerY = centroid->getY();
75 delete centroid;
76 const geos::geom::Envelope *polyBoundBox = poly->getEnvelopeInternal();
77
78 int xStepsToCentroid = (int)((centerX - polyBoundBox->getMinX()) / p_Xspacing + 0.5);
79 int yStepsToCentroid = (int)((centerY - polyBoundBox->getMinY()) / p_Yspacing + 0.5);
80 double dRealMinX = centerX - (xStepsToCentroid * p_Xspacing);
81 double dRealMinY = centerY - (yStepsToCentroid * p_Yspacing);
82 double dDeltaXToReal = p_Xspacing * 1.0 / 6.0;
83 double dDeltaYToReal = p_Yspacing * 1.0 / 6.0;
84
85 for(double y = dRealMinY; y <= polyBoundBox->getMaxY(); y += p_Yspacing) {
86 //printf("Grid Line,%.10f,%.10f,Through,%.10f,%.10f\n",dRealMinX, y, xyBoundBox->getMaxX(), y);
87 for(double x = dRealMinX; x <= polyBoundBox->getMaxX(); x += p_Xspacing) {
88 geos::geom::Coordinate c(x + dDeltaXToReal, y + dDeltaYToReal);
89 geos::geom::Point *p = Isis::globalFactory->createPoint(c).release();
90 if(p->within(poly)) {
91 points.push_back(Isis::globalFactory->createPoint(c).release());
92 }
93 delete p;
94
95 geos::geom::Coordinate c2(x - dDeltaXToReal, y - dDeltaYToReal);
96 p = Isis::globalFactory->createPoint(c2).release();
97 if(p->within(poly)) {
98 points.push_back(Isis::globalFactory->createPoint(c2).release());
99 }
100 delete p;
101 }
102 }
103 }
104
105 return points;
106 }
107
115 // Call the parents Parse method
117
118 // Pull parameters specific to this algorithm out
119 try {
120 // Get info from Algorithm group
121 PvlGroup &algo = pvl.findGroup("PolygonSeederAlgorithm", Pvl::Traverse);
122 PvlGroup &invalgo = invalidInput->findGroup("PolygonSeederAlgorithm",
123 Pvl::Traverse);
124
125 // Set the spacing
126 p_Xspacing = 0.0;
127 if(algo.hasKeyword("XSpacing")) {
128 p_Xspacing = (double) algo["XSpacing"];
129 if(invalgo.hasKeyword("XSpacing")) {
130 invalgo.deleteKeyword("XSpacing");
131 }
132 }
133 else {
134 QString msg = "PVL for StripSeeder must contain [XSpacing] in [";
135 msg += pvl.fileName() + "]";
136 throw IException(IException::User, msg, _FILEINFO_);
137 }
138
139 p_Yspacing = 0.0;
140 if(algo.hasKeyword("YSpacing")) {
141 p_Yspacing = (double) algo["YSpacing"];
142 if(invalgo.hasKeyword("YSpacing")) {
143 invalgo.deleteKeyword("YSpacing");
144 }
145 }
146 else {
147 QString msg = "PVL for StripSeeder must contain [YSpacing] in [";
148 msg += pvl.fileName() + "]";
149 throw IException(IException::User, msg, _FILEINFO_);
150 }
151 }
152 catch(IException &e) {
153 QString msg = "Improper format for PolygonSeeder PVL [" + pvl.fileName() + "]";
154 throw IException(IException::User, msg, _FILEINFO_);
155 }
156
157 if(p_Xspacing <= 0.0) {
158 IString msg = "X Spacing must be greater that 0.0 [(" + IString(p_Xspacing) + "]";
159 throw IException(IException::User, msg, _FILEINFO_);
160 }
161 if(p_Yspacing <= 0.0) {
162 IString msg = "Y Spacing must be greater that 0.0 [(" + IString(p_Yspacing) + "]";
163 throw IException(IException::User, msg, _FILEINFO_);
164 }
165 }
166
167 PvlGroup StripPolygonSeeder::PluginParameters(QString grpName) {
168 PvlGroup pluginInfo(grpName);
169
170 PvlKeyword name("Name", Algorithm());
171 PvlKeyword minThickness("MinimumThickness", toString(MinimumThickness()));
172 PvlKeyword minArea("MinimumArea", toString(MinimumArea()));
173 PvlKeyword xSpac("XSpacing", toString(p_Xspacing));
174 PvlKeyword ySpac("YSpacing", toString(p_Yspacing));
175
176 pluginInfo.addKeyword(name);
177 pluginInfo.addKeyword(minThickness);
178 pluginInfo.addKeyword(minArea);
179 pluginInfo.addKeyword(xSpac);
180 pluginInfo.addKeyword(ySpac);
181
182 return pluginInfo;
183 }
184
185}; // End of namespace Isis
186
187
199extern "C" Isis::PolygonSeeder *StripPolygonSeederPlugin(Isis::Pvl &pvl) {
200 return new Isis::StripPolygonSeeder(pvl);
201}
202
This class is used as the base class for all PolygonSeeder objects.
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.
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...
Seed points using a grid with a staggered pattern.
double p_Xspacing
The spacing in the x direction between points.
std::vector< geos::geom::Point * > Seed(const geos::geom::MultiPolygon *mp)
Seed a polygon with points.
StripPolygonSeeder(Pvl &pvl)
Construct a StripPolygonSeeder algorithm.
double p_Yspacing
The spacing in the y direction between points.
virtual void Parse(Pvl &pvl)
Parse the StripSeeder spicific parameters from the PVL.
virtual PvlGroup PluginParameters(QString grpName)
Plugin parameters.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(const LinearAlgebra::Vector &vector, int precision)
A global function to format LinearAlgebra::Vector as a QString with the given precision.