lsst.afw  15.0-17-g0b88e3da8
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/afw/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 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 }
84 }
85 } // namespace boost::geometry::traits
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::afw::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::afw::geom::Point2D(x - 0.5, y - 0.5),
124  lsst::afw::geom::Point2D(x + 0.5, y + 0.5));
125  boost::geometry::intersection(poly, pixel, overlap);
126  double area = 0.0;
127  for (std::vector<BoostPolygon>::const_iterator i = overlap.begin(); i != overlap.end(); ++i) {
128  double const polyArea = boost::geometry::area(*i);
129  area += std::min(polyArea, 1.0); // remove any rounding error
130  }
131  return area;
132 }
133 
135 void pixelRowOverlap(std::shared_ptr<lsst::afw::image::Image<float>> const image, BoostPolygon const& poly,
136  int const xStart, int const xStop, int const y) {
137  int x = xStart;
138  for (lsst::afw::image::Image<float>::x_iterator i = image->x_at(x - image->getX0(), y - image->getY0());
139  x <= xStop; ++i, ++x) {
140  *i = pixelOverlap(poly, x, y);
141  }
142 }
143 
144 } // anonymous namespace
145 
146 namespace lsst {
147 namespace afw {
148 namespace geom {
149 namespace polygon {
150 
152 std::ostream& operator<<(std::ostream& os, std::vector<LsstPoint> const& vertices) {
153  os << "[";
154  size_t num = vertices.size();
155  for (size_t i = 0; i < num - 1; ++i) {
156  os << vertices[i] << ",";
157  }
158  os << vertices[vertices.size() - 1] << "]";
159  return os;
160 }
161 
164  return os << "BoostPolygon(" << poly.outer() << ")";
165 }
166 
168  os << "Polygon(" << poly.getVertices() << ")";
169  return os;
170 }
171 
173  Impl() : poly() {}
174  explicit Impl(Polygon::Box const& box) : poly() {
175  boost::geometry::assign(poly, box);
176  // Assignment from a box is correctly handled by BoostPolygon, so doesn't need a "check()"
177  }
178  explicit Impl(std::vector<LsstPoint> const& vertices) : poly() {
179  boost::geometry::assign(poly, vertices);
180  check(); // because the vertices might not have the correct orientation (CW vs CCW) or be open
181  }
182  explicit Impl(BoostPolygon const& _poly) : poly(_poly) {}
183 
184  void check() { boost::geometry::correct(poly); }
185 
187  static std::vector<std::shared_ptr<Polygon>> convertBoostPolygons(
188  std::vector<BoostPolygon> const& boostPolygons);
189 
190  template <class PolyT>
191  bool overlaps(PolyT const& other) const {
192  return !boost::geometry::disjoint(poly, other);
193  }
194 
195  template <class PolyT>
196  std::shared_ptr<Polygon> intersectionSingle(PolyT const& other) const;
197 
198  template <class PolyT>
199  std::vector<std::shared_ptr<Polygon>> intersection(PolyT const& other) const;
200 
201  template <class PolyT>
202  std::shared_ptr<Polygon> unionSingle(PolyT const& other) const;
203 
204  template <class PolyT>
205  std::vector<std::shared_ptr<Polygon>> union_(PolyT const& other) const;
206 
207  template <class PolyT>
208  std::vector<std::shared_ptr<Polygon>> symDifference(PolyT const& other) const;
209 
211 };
212 
213 std::vector<std::shared_ptr<Polygon>> Polygon::Impl::convertBoostPolygons(
214  std::vector<BoostPolygon> const& boostPolygons) {
216  lsstPolygons.reserve(boostPolygons.size());
217  for (std::vector<BoostPolygon>::const_iterator i = boostPolygons.begin(); i != boostPolygons.end(); ++i) {
219  lsstPolygons.push_back(tmp);
220  }
221  return lsstPolygons;
222 }
223 
224 template <class PolyT>
225 std::shared_ptr<Polygon> Polygon::Impl::intersectionSingle(PolyT const& other) const {
227  boost::geometry::intersection(poly, other, result);
228  if (result.size() == 0) {
229  throw LSST_EXCEPT(SinglePolygonException, "Polygons have no intersection");
230  }
231  if (result.size() > 1) {
232  throw LSST_EXCEPT(
234  (boost::format("Multiple polygons (%d) created by intersection()") % result.size()).str());
235  }
236  return std::shared_ptr<Polygon>(new Polygon(std::shared_ptr<Impl>(new Impl(result[0]))));
237 }
238 
239 template <class PolyT>
240 std::vector<std::shared_ptr<Polygon>> Polygon::Impl::intersection(PolyT const& other) const {
241  std::vector<BoostPolygon> boostResult;
242  boost::geometry::intersection(poly, other, boostResult);
243  return convertBoostPolygons(boostResult);
244 }
245 
246 template <class PolyT>
247 std::shared_ptr<Polygon> Polygon::Impl::unionSingle(PolyT const& other) const {
249  boost::geometry::union_(poly, other, result);
250  if (result.size() != 1) {
251  throw LSST_EXCEPT(
253  (boost::format("Multiple polygons (%d) created by union_()") % result.size()).str());
254  }
255  return std::shared_ptr<Polygon>(new Polygon(std::shared_ptr<Impl>(new Impl(result[0]))));
256 }
257 
258 template <class PolyT>
259 std::vector<std::shared_ptr<Polygon>> Polygon::Impl::union_(PolyT const& other) const {
260  std::vector<BoostPolygon> boostResult;
261  boost::geometry::union_(poly, other, boostResult);
262  return convertBoostPolygons(boostResult);
263 }
264 
265 template <class PolyT>
266 std::vector<std::shared_ptr<Polygon>> Polygon::Impl::symDifference(PolyT const& other) const {
267  std::vector<BoostPolygon> boostResult;
268  boost::geometry::sym_difference(poly, other, boostResult);
269  return convertBoostPolygons(boostResult);
270 }
271 
272 Polygon::Polygon(Polygon const&) = default;
273 Polygon::Polygon(Polygon&&) = default;
274 Polygon& Polygon::operator=(Polygon const&) = default;
275 Polygon& Polygon::operator=(Polygon&&) = default;
276 
277 Polygon::~Polygon() = default;
278 
279 Polygon::Polygon(Polygon::Box const& box) : _impl(new Polygon::Impl(box)) {}
280 
281 Polygon::Polygon(std::vector<LsstPoint> const& vertices) : _impl(new Polygon::Impl(vertices)) {}
282 
284  : _impl(new Polygon::Impl()) {
285  auto corners = transform.applyForward(boxToCorners(box));
286  boost::geometry::assign(_impl->poly, corners);
287  _impl->check();
288 }
289 
291  : _impl(new Polygon::Impl()) {
292  std::vector<LsstPoint> corners = boxToCorners(box);
293  for (std::vector<LsstPoint>::iterator p = corners.begin(); p != corners.end(); ++p) {
294  *p = transform(*p);
295  }
296  boost::geometry::assign(_impl->poly, corners);
297  _impl->check();
298 }
299 
300 size_t Polygon::getNumEdges() const {
301  // boost::geometry::models::polygon uses a "closed" polygon: the start/end point is included twice
302  return boost::geometry::num_points(_impl->poly) - 1;
303 }
304 
306  return boostBoxToLsst(boost::geometry::return_envelope<BoostBox>(_impl->poly));
307 }
308 
310  return boost::geometry::return_centroid<LsstPoint>(_impl->poly);
311 }
312 
313 double Polygon::calculateArea() const { return boost::geometry::area(_impl->poly); }
314 
315 double Polygon::calculatePerimeter() const { return boost::geometry::perimeter(_impl->poly); }
316 
318  std::vector<LsstPoint> const vertices = getVertices();
320  edges.reserve(getNumEdges());
321  for (std::vector<LsstPoint>::const_iterator i = vertices.begin(), j = vertices.begin() + 1;
322  j != vertices.end(); ++i, ++j) {
323  edges.push_back(std::make_pair(*i, *j));
324  }
325  return edges;
326 }
327 
328 std::vector<LsstPoint> Polygon::getVertices() const { return _impl->poly.outer(); }
329 
330 std::vector<LsstPoint>::const_iterator Polygon::begin() const { return _impl->poly.outer().begin(); }
331 
333  return _impl->poly.outer().end() - 1; // Note removal of final "closed" point
334 }
335 
336 bool Polygon::operator==(Polygon const& other) const {
337  return boost::geometry::equals(_impl->poly, other._impl->poly);
338 }
339 
340 bool Polygon::contains(LsstPoint const& point) const { return boost::geometry::within(point, _impl->poly); }
341 
342 bool Polygon::overlaps(Polygon const& other) const { return _impl->overlaps(other._impl->poly); }
343 
344 bool Polygon::overlaps(Box const& box) const { return _impl->overlaps(box); }
345 
347  return _impl->intersectionSingle(other._impl->poly);
348 }
349 
351  return _impl->intersectionSingle(box);
352 }
353 
355  return _impl->intersection(other._impl->poly);
356 }
357 
359  return _impl->intersection(box);
360 }
361 
363  return _impl->unionSingle(other._impl->poly);
364 }
365 
366 std::shared_ptr<Polygon> Polygon::unionSingle(Box const& box) const { return _impl->unionSingle(box); }
367 
369  return _impl->union_(other._impl->poly);
370 }
371 
372 std::vector<std::shared_ptr<Polygon>> Polygon::union_(Box const& box) const { return _impl->union_(box); }
373 
375  return _impl->symDifference(other._impl->poly);
376 }
377 
379  return _impl->symDifference(box);
380 }
381 
384  boost::geometry::simplify(_impl->poly, result, distance);
386 }
387 
389  BoostPolygon hull;
390  boost::geometry::convex_hull(_impl->poly, hull);
392 }
393 
395  auto newVertices = transform.applyForward(getVertices());
396  return std::shared_ptr<Polygon>(new Polygon(std::shared_ptr<Impl>(new Impl(newVertices))));
397 }
398 
400  std::vector<LsstPoint> vertices; // New vertices
401  vertices.reserve(getNumEdges());
402  for (std::vector<LsstPoint>::const_iterator i = _impl->poly.outer().begin();
403  i != _impl->poly.outer().end(); ++i) {
404  vertices.push_back(transform(*i));
405  }
406  return std::shared_ptr<Polygon>(new Polygon(std::shared_ptr<Impl>(new Impl(vertices))));
407 }
408 
410  std::vector<LsstPoint> vertices; // New vertices
411  vertices.reserve(getNumEdges() * num);
413  for (std::vector<std::pair<Point, Point>>::const_iterator i = edges.begin(); i != edges.end(); ++i) {
414  addSubSampledEdge(vertices, i->first, i->second, num);
415  }
416  return std::shared_ptr<Polygon>(new Polygon(std::shared_ptr<Impl>(new Impl(vertices))));
417 }
418 
420  std::vector<LsstPoint> vertices; // New vertices
421  vertices.reserve(getNumEdges() + static_cast<size_t>(::ceil(calculatePerimeter() / maxLength)));
423  for (std::vector<std::pair<Point, Point>>::const_iterator i = edges.begin(); i != edges.end(); ++i) {
424  Point const &p1 = i->first, p2 = i->second;
425  double const dist = ::sqrt(p1.distanceSquared(p2));
426  addSubSampledEdge(vertices, p1, p2, static_cast<size_t>(::ceil(dist / maxLength)));
427  }
428  return std::shared_ptr<Polygon>(new Polygon(std::shared_ptr<Impl>(new Impl(vertices))));
429 }
430 
432  typedef afw::image::Image<float> Image;
433  std::shared_ptr<Image> image = std::make_shared<Image>(bbox);
434  image->setXY0(bbox.getMin());
435  *image = 0.0;
436  afw::geom::Box2D bounds = getBBox(); // Polygon bounds
437  int xMin = std::max(static_cast<int>(bounds.getMinX()), bbox.getMinX());
438  int xMax = std::min(static_cast<int>(::ceil(bounds.getMaxX())), bbox.getMaxX());
439  int yMin = std::max(static_cast<int>(bounds.getMinY()), bbox.getMinY());
440  int yMax = std::min(static_cast<int>(::ceil(bounds.getMaxY())), bbox.getMaxY());
441  for (int y = yMin; y <= yMax; ++y) {
442  double const yPixelMin = (double)y - 0.5, yPixelMax = (double)y + 0.5;
443  BoostPolygon row; // A polygon of row y
444  boost::geometry::assign(
445  row, LsstBox(afw::geom::Point2D(xMin, yPixelMin), afw::geom::Point2D(xMax, yPixelMax)));
446  std::vector<BoostPolygon> intersections;
447  boost::geometry::intersection(_impl->poly, row, intersections);
448 
449  if (intersections.size() == 1 && boost::geometry::num_points(intersections[0]) == 5) {
450  // This row is fairly tame, and should have a long run of pixels within the polygon
451  BoostPolygon const& row = intersections[0];
452  std::vector<double> top, bottom;
453  top.reserve(2);
454  bottom.reserve(2);
455  bool failed = false;
456  for (std::vector<Point>::const_iterator i = row.outer().begin(); i != row.outer().end() - 1;
457  ++i) {
458  double const xCoord = i->getX(), yCoord = i->getY();
459  if (yCoord == yPixelMin) {
460  bottom.push_back(xCoord);
461  } else if (yCoord == yPixelMax) {
462  top.push_back(xCoord);
463  } else {
464  failed = true;
465  break;
466  }
467  }
468  if (!failed && top.size() == 2 && bottom.size() == 2) {
469  std::sort(top.begin(), top.end());
470  std::sort(bottom.begin(), bottom.end());
471  int const xMin = std::min(top[0], bottom[0]);
472  int const xStart = ::ceil(std::max(top[0], bottom[0])) + 1;
473  int const xStop = std::min(top[1], bottom[1]) - 1;
474  int const xMax = ::ceil(std::max(top[1], bottom[1]));
475  pixelRowOverlap(image, _impl->poly, std::max(xMin, bbox.getMinX()),
476  std::min(xStart, bbox.getMaxX()), y);
477  int x = xStart;
478  for (Image::x_iterator i = image->x_at(std::max(xStart, bbox.getMinX()) - image->getX0(),
479  y - image->getY0());
480  x <= std::min(xStop, bbox.getMaxX()); ++i, ++x) {
481  *i = 1.0;
482  }
483  pixelRowOverlap(image, _impl->poly, std::max(xStop, bbox.getMinX()),
484  std::min(xMax, bbox.getMaxX()), y);
485  continue;
486  }
487  }
488 
489  // Last resort: do each pixel independently...
490  for (std::vector<BoostPolygon>::const_iterator p = intersections.begin(); p != intersections.end();
491  ++p) {
492  double xMinRow = xMax, xMaxRow = xMin;
493  std::vector<LsstPoint> const vertices = p->outer();
494  for (std::vector<LsstPoint>::const_iterator q = vertices.begin(); q != vertices.end(); ++q) {
495  double const x = q->getX();
496  if (x < xMinRow) xMinRow = x;
497  if (x > xMaxRow) xMaxRow = x;
498  }
499 
500  pixelRowOverlap(image, _impl->poly, std::max(static_cast<int>(xMinRow), bbox.getMinX()),
501  std::min(static_cast<int>(::ceil(xMaxRow)), bbox.getMaxX()), y);
502  }
503  }
504  return image;
505 }
506 
507 // -------------- Table-based Persistence -------------------------------------------------------------------
508 
509 /*
510  *
511  */
512 namespace {
513 
514 struct PolygonSchema {
515  afw::table::Schema schema;
516  afw::table::PointKey<double> vertices;
517 
518  static PolygonSchema const& get() {
519  static PolygonSchema instance;
520  return instance;
521  }
522 
523  // No copying
524  PolygonSchema(const PolygonSchema&) = delete;
525  PolygonSchema& operator=(const PolygonSchema&) = delete;
526 
527  // No moving
528  PolygonSchema(PolygonSchema&&) = delete;
529  PolygonSchema& operator=(PolygonSchema&&) = delete;
530 
531 private:
532  PolygonSchema()
533  : schema(),
534  vertices(afw::table::PointKey<double>::addFields(schema, "vertices", "list of vertex points",
535  "")) {
536  schema.getCitizen().markPersistent();
537  }
538 };
539 
540 class PolygonFactory : public table::io::PersistableFactory {
541 public:
542  explicit PolygonFactory(std::string const& name) : table::io::PersistableFactory(name) {}
543 
544  virtual std::shared_ptr<table::io::Persistable> read(InputArchive const& archive,
545  CatalogVector const& catalogs) const {
546  static PolygonSchema const& keys = PolygonSchema::get();
547 
548  LSST_ARCHIVE_ASSERT(catalogs.size() == 1u);
549  afw::table::BaseCatalog const& cat = catalogs.front();
550 
552  for (afw::table::BaseCatalog::const_iterator iter = cat.begin(); iter != cat.end(); ++iter) {
553  vertices.push_back(iter->get(keys.vertices));
554  }
555  std::shared_ptr<Polygon> result(new Polygon(vertices));
556  return result;
557  }
558 };
559 
560 std::string getPolygonPersistenceName() { return "Polygon"; }
561 
562 PolygonFactory registration(getPolygonPersistenceName());
563 
564 } // anonymous namespace
565 
566 std::string Polygon::getPersistenceName() const { return getPolygonPersistenceName(); }
567 
568 void Polygon::write(OutputArchiveHandle& handle) const {
569  static PolygonSchema const& keys = PolygonSchema::get();
570  afw::table::BaseCatalog catalog = handle.makeCatalog(keys.schema);
571 
572  std::vector<LsstPoint> vertices = this->getVertices();
573  for (std::vector<LsstPoint>::const_iterator i = vertices.begin(); i != vertices.end(); ++i) {
575  record->set(keys.vertices, *i);
576  }
577 
578  handle.saveCatalog(catalog);
579 }
580 }
581 }
582 }
583 } // namespace lsst::afw::geom::polygon
std::shared_ptr< Polygon > convexHull() const
Produce a polygon from the convex hull.
Definition: Polygon.cc:388
bool operator==(Polygon const &other) const
Definition: Polygon.cc:336
std::vector< Point >::const_iterator begin() const
Iterator for vertices.
Definition: Polygon.cc:330
Point2I const getMin() const
Definition: Box.h:123
std::vector< std::shared_ptr< Polygon > > intersection(Polygon const &other) const
Returns the intersection of two polygons.
Definition: Polygon.cc:354
ToPoint applyForward(FromPoint const &point) const
Transform one point in the forward direction ("from" to "to")
Definition: Transform.cc:77
Polygon & operator=(Polygon const &)
def keys(self)
afw::table::Key< afw::table::Array< ImagePixelT > > image
int getMinX() const
Definition: Box.h:124
Impl(BoostPolygon const &_poly)
Definition: Polygon.cc:182
bool overlaps(Polygon const &other) const
Returns whether the polygons overlap each other.
Definition: Polygon.cc:342
CatalogT< BaseRecord > BaseCatalog
Definition: fwd.h:71
virtual std::string getPersistenceName() const
Whether Polygon is persistable which is always true.
Definition: Polygon.cc:566
An object passed to Persistable::write to allow it to persist itself.
#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:178
Polygon(Box const &box)
Construct a rectangular Polygon whose vertices are the corners of a box.
Definition: Polygon.cc:279
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
Definition: ImageBase.h:137
std::vector< LsstPoint > LsstRing
Definition: Polygon.cc:18
bool overlaps(PolyT const &other) const
Definition: Polygon.cc:191
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
T end(T... args)
double getMaxX() const
Definition: Box.h:343
ItemVariant const * other
Definition: Schema.cc:55
boost::geometry::model::box< LsstPoint > BoostBox
Definition: Polygon.cc:20
A coordinate class intended to represent absolute positions.
An integer coordinate rectangle.
Definition: Box.h:55
std::vector< std::shared_ptr< Polygon > > symDifference(Polygon const &other) const
Return the symmetric difference of two polygons.
Definition: Polygon.cc:374
STL class.
T min(T... args)
std::shared_ptr< Polygon > unionSingle(Polygon const &other) const
Returns the union of two polygons.
Definition: Polygon.cc:362
Box getBBox() const
Return bounding box.
Definition: Polygon.cc:305
T push_back(T... args)
virtual void write(OutputArchiveHandle &handle) const
Whether Polygon is persistable which is always true.
Definition: Polygon.cc:568
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:317
An affine coordinate transformation consisting of a linear transformation and an offset.
std::vector< std::shared_ptr< Polygon > > union_(Polygon const &other) const
Returns the union of two polygons.
Definition: Polygon.cc:368
double getMaxY() const
Definition: Box.h:344
double getMinX() const
Definition: Box.h:339
boost::geometry::model::linestring< LsstPoint > BoostLineString
Definition: Polygon.cc:21
Impl(Polygon::Box const &box)
Definition: Polygon.cc:174
T make_pair(T... args)
double distanceSquared(PointBase< T, N > const &other) const
Definition: Point.h:126
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:409
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
Extent< int, N > ceil(Extent< double, N > const &input)
Return the component-wise ceil (round towards more positive).
Definition: Extent.cc:115
std::vector< Point > getVertices() const
Get vector of vertices.
Definition: Polygon.cc:328
T size(T... args)
#define LSST_EXCEPT(type,...)
STL class.
T begin(T... args)
size_t getNumEdges() const
Return number of edges.
Definition: Polygon.cc:300
std::shared_ptr< Polygon > simplify(double const distance) const
Return a simplified polygon.
Definition: Polygon.cc:382
std::shared_ptr< Polygon > intersectionSingle(Polygon const &other) const
Returns the intersection of two polygons.
Definition: Polygon.cc:346
int getMaxX() const
Definition: Box.h:128
std::ostream & operator<<(std::ostream &os, BoostPolygon const &poly)
Definition: Polygon.cc:163
std::vector< Point >::const_iterator end() const
Iterator for vertices.
Definition: Polygon.cc:332
table::Box2IKey bbox
table::PointKey< int > pixel
Cartesian polygons.
Definition: Polygon.h:58
T sort(T... args)
afw::table::Schema schema
Definition: Polygon.cc:515
int getMaxY() const
Definition: Box.h:129
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
A floating-point coordinate rectangle geometry.
Definition: Box.h:266
std::shared_ptr< afw::image::Image< float > > createImage(Box2I const &bbox) const
Create image of polygon.
Definition: Polygon.cc:431
std::ostream * os
Definition: Schema.cc:736
int getMinY() const
Definition: Box.h:125
bool contains(Point const &point) const
Returns whether the polygon contains the point.
Definition: Polygon.cc:340
STL class.
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:69
std::shared_ptr< Polygon > transform(TransformPoint2ToPoint2 const &transform) const
Transform the polygon.
Definition: Polygon.cc:394
int y
Definition: SpanSet.cc:44
lsst::afw::geom::polygon::Polygon::Box LsstBox
Definition: Polygon.cc:17
Transform LSST spatial data, such as Point2D and SpherePoint, using an AST mapping.
Definition: Transform.h:67
T reserve(T... args)
afw::table::PointKey< double > vertices
Definition: Polygon.cc:516
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 getMinY() const
Definition: Box.h:340
Point2D const getMax() const
Definition: Box.h:342
Point2D const getMin() const
Definition: Box.h:338
double calculatePerimeter() const
Definition: Polygon.cc:315