lsst.afw  15.0-33-g5c41f601f+4
Polygon.cc
Go to the documentation of this file.
1 #include <cmath>
2 #include <algorithm>
3 
4 #include "boost/geometry/geometry.hpp"
5 #include <memory>
6 
7 #include "lsst/pex/exceptions.h"
8 #include "lsst/geom/Extent.h"
10 
15 
19 typedef boost::geometry::model::polygon<LsstPoint> BoostPolygon;
20 typedef boost::geometry::model::box<LsstPoint> BoostBox;
21 typedef boost::geometry::model::linestring<LsstPoint> BoostLineString;
22 
23 namespace boost {
24 namespace geometry {
25 namespace traits {
26 
27 // Setting up LsstPoint
28 template <>
29 struct tag<LsstPoint> {
30  typedef point_tag type;
31 };
32 template <>
33 struct coordinate_type<LsstPoint> {
35 };
36 template <>
37 struct coordinate_system<LsstPoint> {
38  typedef cs::cartesian type;
39 };
40 template <>
41 struct dimension<LsstPoint> : boost::mpl::int_<2> {};
42 template <std::size_t dim>
43 struct access<LsstPoint, dim> {
44  static double get(LsstPoint const& p) { return p[dim]; }
45  static void set(LsstPoint& p, LsstPoint::Element const& value) { p[dim] = value; }
46 };
47 
48 // Setting up LsstBox
49 //
50 // No setters, because it's inefficient (can't set individual elements of lsst::geom::Box2D directly).
51 // For box outputs from boost::geometry we'll use BoostBox and then convert.
52 template <>
53 struct tag<LsstBox> {
54  typedef box_tag type;
55 };
56 template <>
57 struct point_type<LsstBox> {
58  typedef LsstPoint type;
59 };
60 template <>
61 struct indexed_access<LsstBox, 0, 0> {
62  static double get(LsstBox const& box) { return box.getMinX(); }
63 };
64 template <>
65 struct indexed_access<LsstBox, 1, 0> {
66  static double get(LsstBox const& box) { return box.getMaxX(); }
67 };
68 template <>
69 struct indexed_access<LsstBox, 0, 1> {
70  static double get(LsstBox const& box) { return box.getMinY(); }
71 };
72 template <>
73 struct indexed_access<LsstBox, 1, 1> {
74  static double get(LsstBox const& box) { return box.getMaxY(); }
75 };
76 
77 // Setting up LsstRing
78 template <>
79 struct tag<LsstRing> {
80  typedef ring_tag type;
81 };
82 // template<> struct range_value<LsstRing> { typedef LsstPoint type; };
83 } // namespace traits
84 } // namespace geometry
85 } // namespace boost
86 
87 namespace {
88 
90 LsstBox boostBoxToLsst(BoostBox const& box) { return LsstBox(box.min_corner(), box.max_corner()); }
91 
93 std::vector<LsstPoint> boxToCorners(LsstBox const& box) {
94  std::vector<LsstPoint> corners;
95  corners.reserve(4);
96  corners.push_back(box.getMin());
97  corners.push_back(LsstPoint(box.getMaxX(), box.getMinY()));
98  corners.push_back(box.getMax());
99  corners.push_back(LsstPoint(box.getMinX(), box.getMaxY()));
100  return corners;
101 }
102 
108 void addSubSampledEdge(std::vector<LsstPoint>& vertices, // Vector of points to which to add
109  LsstPoint const& first, // First vertex defining edge
110  LsstPoint const& second, // Second vertex defining edge
111  size_t const num // Number of parts to divide edge into
112 ) {
113  lsst::geom::Extent2D const delta = (second - first) / num;
114  vertices.push_back(first);
115  for (size_t i = 1; i < num; ++i) {
116  vertices.push_back(first + delta * i);
117  }
118 }
119 
121 double pixelOverlap(BoostPolygon const& poly, int const x, int const y) {
122  std::vector<BoostPolygon> overlap; // Overlap between pixel and polygon
123  LsstBox const pixel(lsst::geom::Point2D(x - 0.5, y - 0.5), lsst::geom::Point2D(x + 0.5, y + 0.5));
124  boost::geometry::intersection(poly, pixel, overlap);
125  double area = 0.0;
126  for (std::vector<BoostPolygon>::const_iterator i = overlap.begin(); i != overlap.end(); ++i) {
127  double const polyArea = boost::geometry::area(*i);
128  area += std::min(polyArea, 1.0); // remove any rounding error
129  }
130  return area;
131 }
132 
134 void pixelRowOverlap(std::shared_ptr<lsst::afw::image::Image<float>> const image, BoostPolygon const& poly,
135  int const xStart, int const xStop, int const y) {
136  int x = xStart;
137  for (lsst::afw::image::Image<float>::x_iterator i = image->x_at(x - image->getX0(), y - image->getY0());
138  x <= xStop; ++i, ++x) {
139  *i = pixelOverlap(poly, x, y);
140  }
141 }
142 
143 } // anonymous namespace
144 
145 namespace lsst {
146 namespace afw {
147 namespace geom {
148 namespace polygon {
149 
151 std::ostream& operator<<(std::ostream& os, std::vector<LsstPoint> const& vertices) {
152  os << "[";
153  size_t num = vertices.size();
154  for (size_t i = 0; i < num - 1; ++i) {
155  os << vertices[i] << ",";
156  }
157  os << vertices[vertices.size() - 1] << "]";
158  return os;
159 }
160 
163  return os << "BoostPolygon(" << poly.outer() << ")";
164 }
165 
167  os << "Polygon(" << poly.getVertices() << ")";
168  return os;
169 }
170 
172  Impl() : poly() {}
173  explicit Impl(Polygon::Box const& box) : poly() {
174  boost::geometry::assign(poly, box);
175  // Assignment from a box is correctly handled by BoostPolygon, so doesn't need a "check()"
176  }
177  explicit Impl(std::vector<LsstPoint> const& vertices) : poly() {
178  boost::geometry::assign(poly, vertices);
179  check(); // because the vertices might not have the correct orientation (CW vs CCW) or be open
180  }
181  explicit Impl(BoostPolygon const& _poly) : poly(_poly) {}
182 
183  void check() { boost::geometry::correct(poly); }
184 
186  static std::vector<std::shared_ptr<Polygon>> convertBoostPolygons(
187  std::vector<BoostPolygon> const& boostPolygons);
188 
189  template <class PolyT>
190  bool overlaps(PolyT const& other) const {
191  return !boost::geometry::disjoint(poly, other);
192  }
193 
194  template <class PolyT>
195  std::shared_ptr<Polygon> intersectionSingle(PolyT const& other) const;
196 
197  template <class PolyT>
198  std::vector<std::shared_ptr<Polygon>> intersection(PolyT const& other) const;
199 
200  template <class PolyT>
201  std::shared_ptr<Polygon> unionSingle(PolyT const& other) const;
202 
203  template <class PolyT>
204  std::vector<std::shared_ptr<Polygon>> union_(PolyT const& other) const;
205 
206  template <class PolyT>
207  std::vector<std::shared_ptr<Polygon>> symDifference(PolyT const& other) const;
208 
210 };
211 
212 std::vector<std::shared_ptr<Polygon>> Polygon::Impl::convertBoostPolygons(
213  std::vector<BoostPolygon> const& boostPolygons) {
215  lsstPolygons.reserve(boostPolygons.size());
216  for (std::vector<BoostPolygon>::const_iterator i = boostPolygons.begin(); i != boostPolygons.end(); ++i) {
218  lsstPolygons.push_back(tmp);
219  }
220  return lsstPolygons;
221 }
222 
223 template <class PolyT>
224 std::shared_ptr<Polygon> Polygon::Impl::intersectionSingle(PolyT const& other) const {
226  boost::geometry::intersection(poly, other, result);
227  if (result.size() == 0) {
228  throw LSST_EXCEPT(SinglePolygonException, "Polygons have no intersection");
229  }
230  if (result.size() > 1) {
231  throw LSST_EXCEPT(
233  (boost::format("Multiple polygons (%d) created by intersection()") % result.size()).str());
234  }
235  return std::shared_ptr<Polygon>(new Polygon(std::shared_ptr<Impl>(new Impl(result[0]))));
236 }
237 
238 template <class PolyT>
239 std::vector<std::shared_ptr<Polygon>> Polygon::Impl::intersection(PolyT const& other) const {
240  std::vector<BoostPolygon> boostResult;
241  boost::geometry::intersection(poly, other, boostResult);
242  return convertBoostPolygons(boostResult);
243 }
244 
245 template <class PolyT>
246 std::shared_ptr<Polygon> Polygon::Impl::unionSingle(PolyT const& other) const {
248  boost::geometry::union_(poly, other, result);
249  if (result.size() != 1) {
250  throw LSST_EXCEPT(
252  (boost::format("Multiple polygons (%d) created by union_()") % result.size()).str());
253  }
254  return std::shared_ptr<Polygon>(new Polygon(std::shared_ptr<Impl>(new Impl(result[0]))));
255 }
256 
257 template <class PolyT>
258 std::vector<std::shared_ptr<Polygon>> Polygon::Impl::union_(PolyT const& other) const {
259  std::vector<BoostPolygon> boostResult;
260  boost::geometry::union_(poly, other, boostResult);
261  return convertBoostPolygons(boostResult);
262 }
263 
264 template <class PolyT>
265 std::vector<std::shared_ptr<Polygon>> Polygon::Impl::symDifference(PolyT const& other) const {
266  std::vector<BoostPolygon> boostResult;
267  boost::geometry::sym_difference(poly, other, boostResult);
268  return convertBoostPolygons(boostResult);
269 }
270 
271 Polygon::Polygon(Polygon const&) = default;
272 Polygon::Polygon(Polygon&&) = default;
273 Polygon& Polygon::operator=(Polygon const&) = default;
274 Polygon& Polygon::operator=(Polygon&&) = default;
275 
276 Polygon::~Polygon() = default;
277 
278 Polygon::Polygon(Polygon::Box const& box) : _impl(new Polygon::Impl(box)) {}
279 
280 Polygon::Polygon(std::vector<LsstPoint> const& vertices) : _impl(new Polygon::Impl(vertices)) {}
281 
283  : _impl(new Polygon::Impl()) {
284  auto corners = transform.applyForward(boxToCorners(box));
285  boost::geometry::assign(_impl->poly, corners);
286  _impl->check();
287 }
288 
290  : _impl(new Polygon::Impl()) {
291  std::vector<LsstPoint> corners = boxToCorners(box);
292  for (std::vector<LsstPoint>::iterator p = corners.begin(); p != corners.end(); ++p) {
293  *p = transform(*p);
294  }
295  boost::geometry::assign(_impl->poly, corners);
296  _impl->check();
297 }
298 
299 size_t Polygon::getNumEdges() const {
300  // boost::geometry::models::polygon uses a "closed" polygon: the start/end point is included twice
301  return boost::geometry::num_points(_impl->poly) - 1;
302 }
303 
305  return boostBoxToLsst(boost::geometry::return_envelope<BoostBox>(_impl->poly));
306 }
307 
309  return boost::geometry::return_centroid<LsstPoint>(_impl->poly);
310 }
311 
312 double Polygon::calculateArea() const { return boost::geometry::area(_impl->poly); }
313 
314 double Polygon::calculatePerimeter() const { return boost::geometry::perimeter(_impl->poly); }
315 
319  edges.reserve(getNumEdges());
320  for (std::vector<LsstPoint>::const_iterator i = vertices.begin(), j = vertices.begin() + 1;
321  j != vertices.end(); ++i, ++j) {
322  edges.push_back(std::make_pair(*i, *j));
323  }
324  return edges;
325 }
326 
327 std::vector<LsstPoint> Polygon::getVertices() const { return _impl->poly.outer(); }
328 
329 std::vector<LsstPoint>::const_iterator Polygon::begin() const { return _impl->poly.outer().begin(); }
330 
332  return _impl->poly.outer().end() - 1; // Note removal of final "closed" point
333 }
334 
335 bool Polygon::operator==(Polygon const& other) const {
336  return boost::geometry::equals(_impl->poly, other._impl->poly);
337 }
338 
339 bool Polygon::contains(LsstPoint const& point) const { return boost::geometry::within(point, _impl->poly); }
340 
341 bool Polygon::overlaps(Polygon const& other) const { return _impl->overlaps(other._impl->poly); }
342 
343 bool Polygon::overlaps(Box const& box) const { return _impl->overlaps(box); }
344 
346  return _impl->intersectionSingle(other._impl->poly);
347 }
348 
350  return _impl->intersectionSingle(box);
351 }
352 
354  return _impl->intersection(other._impl->poly);
355 }
356 
358  return _impl->intersection(box);
359 }
360 
362  return _impl->unionSingle(other._impl->poly);
363 }
364 
365 std::shared_ptr<Polygon> Polygon::unionSingle(Box const& box) const { return _impl->unionSingle(box); }
366 
368  return _impl->union_(other._impl->poly);
369 }
370 
371 std::vector<std::shared_ptr<Polygon>> Polygon::union_(Box const& box) const { return _impl->union_(box); }
372 
374  return _impl->symDifference(other._impl->poly);
375 }
376 
378  return _impl->symDifference(box);
379 }
380 
383  boost::geometry::simplify(_impl->poly, result, distance);
385 }
386 
388  BoostPolygon hull;
389  boost::geometry::convex_hull(_impl->poly, hull);
391 }
392 
394  auto newVertices = transform.applyForward(getVertices());
395  return std::shared_ptr<Polygon>(new Polygon(std::shared_ptr<Impl>(new Impl(newVertices))));
396 }
397 
399  std::vector<LsstPoint> vertices; // New vertices
400  vertices.reserve(getNumEdges());
401  for (std::vector<LsstPoint>::const_iterator i = _impl->poly.outer().begin();
402  i != _impl->poly.outer().end(); ++i) {
403  vertices.push_back(transform(*i));
404  }
405  return std::shared_ptr<Polygon>(new Polygon(std::shared_ptr<Impl>(new Impl(vertices))));
406 }
407 
409  std::vector<LsstPoint> vertices; // New vertices
410  vertices.reserve(getNumEdges() * num);
412  for (std::vector<std::pair<Point, Point>>::const_iterator i = edges.begin(); i != edges.end(); ++i) {
413  addSubSampledEdge(vertices, i->first, i->second, num);
414  }
415  return std::shared_ptr<Polygon>(new Polygon(std::shared_ptr<Impl>(new Impl(vertices))));
416 }
417 
419  std::vector<LsstPoint> vertices; // New vertices
420  vertices.reserve(getNumEdges() + static_cast<size_t>(::ceil(calculatePerimeter() / maxLength)));
422  for (std::vector<std::pair<Point, Point>>::const_iterator i = edges.begin(); i != edges.end(); ++i) {
423  Point const &p1 = i->first, p2 = i->second;
424  double const dist = ::sqrt(p1.distanceSquared(p2));
425  addSubSampledEdge(vertices, p1, p2, static_cast<size_t>(::ceil(dist / maxLength)));
426  }
427  return std::shared_ptr<Polygon>(new Polygon(std::shared_ptr<Impl>(new Impl(vertices))));
428 }
429 
431  typedef afw::image::Image<float> Image;
432  std::shared_ptr<Image> image = std::make_shared<Image>(bbox);
433  image->setXY0(bbox.getMin());
434  *image = 0.0;
435  lsst::geom::Box2D bounds = getBBox(); // Polygon bounds
436  int xMin = std::max(static_cast<int>(bounds.getMinX()), bbox.getMinX());
437  int xMax = std::min(static_cast<int>(::ceil(bounds.getMaxX())), bbox.getMaxX());
438  int yMin = std::max(static_cast<int>(bounds.getMinY()), bbox.getMinY());
439  int yMax = std::min(static_cast<int>(::ceil(bounds.getMaxY())), bbox.getMaxY());
440  for (int y = yMin; y <= yMax; ++y) {
441  double const yPixelMin = (double)y - 0.5, yPixelMax = (double)y + 0.5;
442  BoostPolygon row; // A polygon of row y
443  boost::geometry::assign(
444  row, LsstBox(lsst::geom::Point2D(xMin, yPixelMin), lsst::geom::Point2D(xMax, yPixelMax)));
445  std::vector<BoostPolygon> intersections;
446  boost::geometry::intersection(_impl->poly, row, intersections);
447 
448  if (intersections.size() == 1 && boost::geometry::num_points(intersections[0]) == 5) {
449  // This row is fairly tame, and should have a long run of pixels within the polygon
450  BoostPolygon const& row = intersections[0];
451  std::vector<double> top, bottom;
452  top.reserve(2);
453  bottom.reserve(2);
454  bool failed = false;
455  for (std::vector<Point>::const_iterator i = row.outer().begin(); i != row.outer().end() - 1;
456  ++i) {
457  double const xCoord = i->getX(), yCoord = i->getY();
458  if (yCoord == yPixelMin) {
459  bottom.push_back(xCoord);
460  } else if (yCoord == yPixelMax) {
461  top.push_back(xCoord);
462  } else {
463  failed = true;
464  break;
465  }
466  }
467  if (!failed && top.size() == 2 && bottom.size() == 2) {
468  std::sort(top.begin(), top.end());
469  std::sort(bottom.begin(), bottom.end());
470  int const xMin = std::min(top[0], bottom[0]);
471  int const xStart = ::ceil(std::max(top[0], bottom[0])) + 1;
472  int const xStop = std::min(top[1], bottom[1]) - 1;
473  int const xMax = ::ceil(std::max(top[1], bottom[1]));
474  pixelRowOverlap(image, _impl->poly, std::max(xMin, bbox.getMinX()),
475  std::min(xStart, bbox.getMaxX()), y);
476  int x = xStart;
477  for (Image::x_iterator i = image->x_at(std::max(xStart, bbox.getMinX()) - image->getX0(),
478  y - image->getY0());
479  x <= std::min(xStop, bbox.getMaxX()); ++i, ++x) {
480  *i = 1.0;
481  }
482  pixelRowOverlap(image, _impl->poly, std::max(xStop, bbox.getMinX()),
483  std::min(xMax, bbox.getMaxX()), y);
484  continue;
485  }
486  }
487 
488  // Last resort: do each pixel independently...
489  for (std::vector<BoostPolygon>::const_iterator p = intersections.begin(); p != intersections.end();
490  ++p) {
491  double xMinRow = xMax, xMaxRow = xMin;
492  std::vector<LsstPoint> const vertices = p->outer();
493  for (std::vector<LsstPoint>::const_iterator q = vertices.begin(); q != vertices.end(); ++q) {
494  double const x = q->getX();
495  if (x < xMinRow) xMinRow = x;
496  if (x > xMaxRow) xMaxRow = x;
497  }
498 
499  pixelRowOverlap(image, _impl->poly, std::max(static_cast<int>(xMinRow), bbox.getMinX()),
500  std::min(static_cast<int>(::ceil(xMaxRow)), bbox.getMaxX()), y);
501  }
502  }
503  return image;
504 }
505 
506 // -------------- Table-based Persistence -------------------------------------------------------------------
507 
508 /*
509  *
510  */
511 namespace {
512 
513 struct PolygonSchema {
514  afw::table::Schema schema;
515  afw::table::PointKey<double> vertices;
516 
517  static PolygonSchema const& get() {
518  static PolygonSchema instance;
519  return instance;
520  }
521 
522  // No copying
523  PolygonSchema(const PolygonSchema&) = delete;
524  PolygonSchema& operator=(const PolygonSchema&) = delete;
525 
526  // No moving
527  PolygonSchema(PolygonSchema&&) = delete;
528  PolygonSchema& operator=(PolygonSchema&&) = delete;
529 
530 private:
531  PolygonSchema()
532  : schema(),
533  vertices(afw::table::PointKey<double>::addFields(schema, "vertices", "list of vertex points",
534  "")) {
535  schema.getCitizen().markPersistent();
536  }
537 };
538 
539 class PolygonFactory : public table::io::PersistableFactory {
540 public:
541  explicit PolygonFactory(std::string const& name) : table::io::PersistableFactory(name) {}
542 
543  virtual std::shared_ptr<table::io::Persistable> read(InputArchive const& archive,
544  CatalogVector const& catalogs) const {
545  static PolygonSchema const& keys = PolygonSchema::get();
546 
547  LSST_ARCHIVE_ASSERT(catalogs.size() == 1u);
548  afw::table::BaseCatalog const& cat = catalogs.front();
549 
551  for (afw::table::BaseCatalog::const_iterator iter = cat.begin(); iter != cat.end(); ++iter) {
552  vertices.push_back(iter->get(keys.vertices));
553  }
554  std::shared_ptr<Polygon> result(new Polygon(vertices));
555  return result;
556  }
557 };
558 
559 std::string getPolygonPersistenceName() { return "Polygon"; }
560 
561 PolygonFactory registration(getPolygonPersistenceName());
562 
563 } // anonymous namespace
564 
565 std::string Polygon::getPersistenceName() const { return getPolygonPersistenceName(); }
566 
567 void Polygon::write(OutputArchiveHandle& handle) const {
568  static PolygonSchema const& keys = PolygonSchema::get();
569  afw::table::BaseCatalog catalog = handle.makeCatalog(keys.schema);
570 
572  for (std::vector<LsstPoint>::const_iterator i = vertices.begin(); i != vertices.end(); ++i) {
574  record->set(keys.vertices, *i);
575  }
576 
577  handle.saveCatalog(catalog);
578 }
579 } // namespace polygon
580 } // namespace geom
581 } // namespace afw
582 } // namespace lsst
std::shared_ptr< Polygon > convexHull() const
Produce a polygon from the convex hull.
Definition: Polygon.cc:387
bool operator==(Polygon const &other) const
Definition: Polygon.cc:335
std::vector< Point >::const_iterator begin() const
Iterator for vertices.
Definition: Polygon.cc:329
std::vector< std::shared_ptr< Polygon > > intersection(Polygon const &other) const
Returns the intersection of two polygons.
Definition: Polygon.cc:353
ToPoint applyForward(FromPoint const &point) const
Transform one point in the forward direction ("from" to "to")
Definition: Transform.cc:78
Polygon & operator=(Polygon const &)
def keys(self)
afw::table::Key< afw::table::Array< ImagePixelT > > image
int getMaxY() const
Impl(BoostPolygon const &_poly)
Definition: Polygon.cc:181
bool overlaps(Polygon const &other) const
Returns whether the polygons overlap each other.
Definition: Polygon.cc:341
CatalogT< BaseRecord > BaseCatalog
Definition: fwd.h:71
virtual std::string getPersistenceName() const
Whether Polygon is persistable which is always true.
Definition: Polygon.cc:565
An object passed to Persistable::write to allow it to persist itself.
Point2I const getMin() const
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
Definition: Persistable.h:48
Impl(std::vector< LsstPoint > const &vertices)
Definition: Polygon.cc:177
Polygon(Box const &box)
Construct a rectangular Polygon whose vertices are the corners of a box.
Definition: Polygon.cc:278
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
Definition: ImageBase.h:135
std::vector< LsstPoint > LsstRing
Definition: Polygon.cc:18
bool overlaps(PolyT const &other) const
Definition: Polygon.cc:190
static PointKey addFields(Schema &schema, std::string const &name, std::string const &doc, std::string const &unit)
Add a pair of _x, _y fields to a Schema, and return a PointKey that points to them.
Definition: aggregates.cc:36
Point2D const getMin() const
double getMinX() const
T end(T... args)
ItemVariant const * other
Definition: Schema.cc:55
boost::geometry::model::box< LsstPoint > BoostBox
Definition: Polygon.cc:20
double distanceSquared(PointBase< double, N > const &other) const
std::vector< std::shared_ptr< Polygon > > symDifference(Polygon const &other) const
Return the symmetric difference of two polygons.
Definition: Polygon.cc:373
STL class.
T min(T... args)
std::shared_ptr< Polygon > unionSingle(Polygon const &other) const
Returns the union of two polygons.
Definition: Polygon.cc:361
Box getBBox() const
Return bounding box.
Definition: Polygon.cc:304
T push_back(T... args)
virtual void write(OutputArchiveHandle &handle) const
Whether Polygon is persistable which is always true.
Definition: Polygon.cc:567
lsst::afw::geom::polygon::Polygon::Point LsstPoint
Definition: Polygon.cc:16
A base class for image defects.
reference front() const
Return the first record.
Definition: Catalog.h:440
boost::geometry::model::polygon< LsstPoint > BoostPolygon
Definition: Polygon.cc:19
std::vector< std::pair< Point, Point > > getEdges() const
Get vector of edges.
Definition: Polygon.cc:316
double getMaxX() const
int getMinX() const
std::vector< std::shared_ptr< Polygon > > union_(Polygon const &other) const
Returns the union of two polygons.
Definition: Polygon.cc:367
Point2D const getMax() const
boost::geometry::model::linestring< LsstPoint > BoostLineString
Definition: Polygon.cc:21
Impl(Polygon::Box const &box)
Definition: Polygon.cc:173
T make_pair(T... args)
int getMinY() const
double x
T max(T... args)
An exception that indicates the single-polygon assumption has been violated.
Definition: Polygon.h:52
std::unique_ptr< SchemaItem< U > > result
Definition: Schema.cc:194
CatalogIterator< typename Internal::const_iterator > const_iterator
Definition: Catalog.h:111
std::shared_ptr< Polygon > subSample(size_t num) const
Sub-sample each edge.
Definition: Polygon.cc:408
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
std::vector< Point > getVertices() const
Get vector of vertices.
Definition: Polygon.cc:327
T size(T... args)
#define LSST_EXCEPT(type,...)
STL class.
int getMaxX() const
T begin(T... args)
size_t getNumEdges() const
Return number of edges.
Definition: Polygon.cc:299
std::shared_ptr< Polygon > simplify(double const distance) const
Return a simplified polygon.
Definition: Polygon.cc:381
std::shared_ptr< Polygon > intersectionSingle(Polygon const &other) const
Returns the intersection of two polygons.
Definition: Polygon.cc:345
std::ostream & operator<<(std::ostream &os, BoostPolygon const &poly)
Definition: Polygon.cc:162
std::vector< Point >::const_iterator end() const
Iterator for vertices.
Definition: Polygon.cc:331
table::Box2IKey bbox
table::PointKey< int > pixel
Cartesian polygons.
Definition: Polygon.h:58
T sort(T... args)
afw::table::Schema schema
Definition: Polygon.cc:514
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
std::ostream * os
Definition: Schema.cc:737
bool contains(Point const &point) const
Returns whether the polygon contains the point.
Definition: Polygon.cc:339
STL class.
std::shared_ptr< afw::image::Image< float > > createImage(lsst::geom::Box2I const &bbox) const
Create image of polygon.
Definition: Polygon.cc:430
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:67
std::shared_ptr< Polygon > transform(TransformPoint2ToPoint2 const &transform) const
Transform the polygon.
Definition: Polygon.cc:393
int y
Definition: SpanSet.cc:44
lsst::afw::geom::polygon::Polygon::Box LsstBox
Definition: Polygon.cc:17
double getMaxY() const
Transform LSST spatial data, such as lsst::geom::Point2D and lsst::geom::SpherePoint, using an AST mapping.
Definition: Transform.h:67
double getMinY() const
T reserve(T... args)
afw::table::PointKey< double > vertices
Definition: Polygon.cc:515
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
Definition: Catalog.h:472
double calculatePerimeter() const
Definition: Polygon.cc:314