File failed to load: https://isis.astrogeology.usgs.gov/6.0.0/Object/assets/jax/output/NativeMML/config.js
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 
18 namespace Isis {
19 
28  Parse(pvl);
29  };
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();
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);
87  if(p->within(multiPoly)) {
88  points.push_back(Isis::globalFactory->createPoint(c));
89  }
90 
91  geos::geom::Coordinate c2(x - dDeltaXToReal, y - dDeltaYToReal);
92  p = Isis::globalFactory->createPoint(c2);
93  if(p->within(multiPoly)) {
94  points.push_back(Isis::globalFactory->createPoint(c2));
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",
117  Pvl::Traverse);
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 
193 extern "C" Isis::PolygonSeeder *StripPolygonSeederPlugin(Isis::Pvl &pvl) {
194  return new Isis::StripPolygonSeeder(pvl);
195 }
196 
Isis::PvlObject::findGroup
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:129
Isis::PvlKeyword
A single keyword-value pair.
Definition: PvlKeyword.h:82
Isis::StripPolygonSeeder::p_Yspacing
double p_Yspacing
The spacing in the y direction between points.
Definition: StripPolygonSeeder.h:67
Isis::PvlContainer::addKeyword
void addKeyword(const PvlKeyword &keyword, const InsertMode mode=Append)
Add a keyword to the container.
Definition: PvlContainer.cpp:202
Isis::StripPolygonSeeder::Parse
virtual void Parse(Pvl &pvl)
Parse the StripSeeder spicific parameters from the PVL.
Definition: StripPolygonSeeder.cpp:108
Isis::PvlContainer::hasKeyword
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
Definition: PvlContainer.cpp:159
Isis::Pvl
Container for cube-like labels.
Definition: Pvl.h:119
Isis::StripPolygonSeeder::PluginParameters
virtual PvlGroup PluginParameters(QString grpName)
Plugin parameters.
Definition: StripPolygonSeeder.cpp:161
Isis::PolygonSeeder::MinimumArea
double MinimumArea()
Return the minimum allowed area of the polygon.
Definition: PolygonSeeder.cpp:195
Isis::toString
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:211
Isis::StripPolygonSeeder
Seed points using a grid with a staggered pattern.
Definition: StripPolygonSeeder.h:51
Isis::PvlObject::Traverse
@ Traverse
Search child objects.
Definition: PvlObject.h:158
Isis::PolygonSeeder::MinimumThickness
double MinimumThickness()
Return the minimum allowed thickness of the polygon.
Definition: PolygonSeeder.cpp:183
Isis::PvlGroup
Contains multiple PvlContainers.
Definition: PvlGroup.h:41
Isis::PolygonSeeder::invalidInput
Pvl * invalidInput
The Pvl passed in by the constructor minus what was used.
Definition: PolygonSeeder.h:78
Isis::PvlContainer::fileName
QString fileName() const
Returns the filename used to initialise the Pvl object.
Definition: PvlContainer.h:232
Isis::StripPolygonSeeder::StripPolygonSeeder
StripPolygonSeeder(Pvl &pvl)
Construct a StripPolygonSeeder algorithm.
Definition: StripPolygonSeeder.cpp:27
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::PolygonSeeder::Parse
virtual void Parse(Pvl &pvl)
Initialize parameters in the PolygonSeeder class using a PVL specification.
Definition: PolygonSeeder.cpp:85
Isis::PvlContainer::deleteKeyword
void deleteKeyword(const QString &name)
Remove a specified keyword.
Definition: PvlContainer.cpp:97
Isis::StripPolygonSeeder::Seed
std::vector< geos::geom::Point * > Seed(const geos::geom::MultiPolygon *mp)
Seed a polygon with points.
Definition: StripPolygonSeeder.cpp:51
Isis::PolygonSeeder::Algorithm
QString Algorithm() const
The name of the algorithm, read from the Name Keyword in the PolygonSeeder Pvl passed into the constr...
Definition: PolygonSeeder.cpp:172
Isis::StripPolygonSeeder::p_Xspacing
double p_Xspacing
The spacing in the x direction between points.
Definition: StripPolygonSeeder.h:66
Isis::PolygonSeeder::StandardTests
QString StandardTests(const geos::geom::MultiPolygon *multiPoly, const geos::geom::Envelope *polyBoundBox)
Check the polygon to see if it meets standard criteria.
Definition: PolygonSeeder.cpp:146
Isis::IString
Adds specific functionality to C++ strings.
Definition: IString.h:165
Isis::PolygonSeeder
This class is used as the base class for all PolygonSeeder objects.
Definition: PolygonSeeder.h:47
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::IException::User
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition: IException.h:126

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the USGS Astrogeology Discussion Board
To report a bug, or suggest a feature go to: ISIS Github
File Modified: 07/13/2023 15:17:20