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