Isis 3 Programmer Reference
StripPolygonSeeder.cpp
1
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 *polyBoundBox = multiPoly->getEnvelopeInternal();
58
59 // Call the parents standardTests member
60 QString msg = StandardTests(multiPoly, polyBoundBox);
61 if(!msg.isEmpty()) {
62 return points;
63 }
64
65 // Do strip seeder specific tests to make sure this poly should be seeded
66 // (none for now)
67
68 // Starting at the centroid of the xy polygon populate the polygon with
69 // staggered points with the requested spacing
70 geos::geom::Point *centroid = multiPoly->getCentroid().release();
71 double centerX = centroid->getX();
72 double centerY = centroid->getY();
73 delete centroid;
74
75 int xStepsToCentroid = (int)((centerX - polyBoundBox->getMinX()) / p_Xspacing + 0.5);
76 int yStepsToCentroid = (int)((centerY - polyBoundBox->getMinY()) / p_Yspacing + 0.5);
77 double dRealMinX = centerX - (xStepsToCentroid * p_Xspacing);
78 double dRealMinY = centerY - (yStepsToCentroid * p_Yspacing);
79 double dDeltaXToReal = p_Xspacing * 1.0 / 6.0;
80 double dDeltaYToReal = p_Yspacing * 1.0 / 6.0;
81
82 for(double y = dRealMinY; y <= polyBoundBox->getMaxY(); y += p_Yspacing) {
83 //printf("Grid Line,%.10f,%.10f,Through,%.10f,%.10f\n",dRealMinX, y, xyBoundBox->getMaxX(), y);
84 for(double x = dRealMinX; x <= polyBoundBox->getMaxX(); x += p_Xspacing) {
85 geos::geom::Coordinate c(x + dDeltaXToReal, y + dDeltaYToReal);
86 geos::geom::Point *p = Isis::globalFactory->createPoint(c).release();
87 if(p->within(multiPoly)) {
88 points.push_back(Isis::globalFactory->createPoint(c).release());
89 }
90
91 geos::geom::Coordinate c2(x - dDeltaXToReal, y - dDeltaYToReal);
92 p = Isis::globalFactory->createPoint(c2).release();
93 if(p->within(multiPoly)) {
94 points.push_back(Isis::globalFactory->createPoint(c2).release());
95 }
96 }
97 }
98
99 return points;
100 }
101
109 // Call the parents Parse method
111
112 // Pull parameters specific to this algorithm out
113 try {
114 // Get info from Algorithm group
115 PvlGroup &algo = pvl.findGroup("PolygonSeederAlgorithm", Pvl::Traverse);
116 PvlGroup &invalgo = invalidInput->findGroup("PolygonSeederAlgorithm",
118
119 // Set the spacing
120 p_Xspacing = 0.0;
121 if(algo.hasKeyword("XSpacing")) {
122 p_Xspacing = (double) algo["XSpacing"];
123 if(invalgo.hasKeyword("XSpacing")) {
124 invalgo.deleteKeyword("XSpacing");
125 }
126 }
127 else {
128 QString msg = "PVL for StripSeeder must contain [XSpacing] in [";
129 msg += pvl.fileName() + "]";
130 throw IException(IException::User, msg, _FILEINFO_);
131 }
132
133 p_Yspacing = 0.0;
134 if(algo.hasKeyword("YSpacing")) {
135 p_Yspacing = (double) algo["YSpacing"];
136 if(invalgo.hasKeyword("YSpacing")) {
137 invalgo.deleteKeyword("YSpacing");
138 }
139 }
140 else {
141 QString msg = "PVL for StripSeeder must contain [YSpacing] in [";
142 msg += pvl.fileName() + "]";
143 throw IException(IException::User, msg, _FILEINFO_);
144 }
145 }
146 catch(IException &e) {
147 QString msg = "Improper format for PolygonSeeder PVL [" + pvl.fileName() + "]";
148 throw IException(IException::User, msg, _FILEINFO_);
149 }
150
151 if(p_Xspacing <= 0.0) {
152 IString msg = "X Spacing must be greater that 0.0 [(" + IString(p_Xspacing) + "]";
153 throw IException(IException::User, msg, _FILEINFO_);
154 }
155 if(p_Yspacing <= 0.0) {
156 IString msg = "Y Spacing must be greater that 0.0 [(" + IString(p_Yspacing) + "]";
157 throw IException(IException::User, msg, _FILEINFO_);
158 }
159 }
160
162 PvlGroup pluginInfo(grpName);
163
164 PvlKeyword name("Name", Algorithm());
165 PvlKeyword minThickness("MinimumThickness", toString(MinimumThickness()));
166 PvlKeyword minArea("MinimumArea", toString(MinimumArea()));
167 PvlKeyword xSpac("XSpacing", toString(p_Xspacing));
168 PvlKeyword ySpac("YSpacing", toString(p_Yspacing));
169
170 pluginInfo.addKeyword(name);
171 pluginInfo.addKeyword(minThickness);
172 pluginInfo.addKeyword(minArea);
173 pluginInfo.addKeyword(xSpac);
174 pluginInfo.addKeyword(ySpac);
175
176 return pluginInfo;
177 }
178
179}; // End of namespace Isis
180
181
193extern "C" Isis::PolygonSeeder *StripPolygonSeederPlugin(Isis::Pvl &pvl) {
194 return new Isis::StripPolygonSeeder(pvl);
195}
196
Isis exception class.
Definition IException.h:91
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition IException.h:126
Adds specific functionality to C++ strings.
Definition IString.h:165
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.
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...
Contains multiple PvlContainers.
Definition PvlGroup.h:41
Container for cube-like labels.
Definition Pvl.h:119
A single keyword-value pair.
Definition PvlKeyword.h:87
@ Traverse
Search child objects.
Definition PvlObject.h:158
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition PvlObject.h:129
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(bool boolToConvert)
Global function to convert a boolean to a string.
Definition IString.cpp:211