LSSTApplications
19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
|
Go to the documentation of this file.
4 #include "boost/geometry/geometry.hpp"
5 #include <boost/container_hash/hash.hpp>
22 typedef boost::geometry::model::box<LsstPoint>
BoostBox;
36 typedef LsstPoint::Element
type;
40 typedef cs::cartesian
type;
43 struct dimension<
LsstPoint> : boost::mpl::int_<2> {};
44 template <std::
size_t dim>
47 static void set(
LsstPoint& p, LsstPoint::Element
const& value) { p[dim] = value; }
117 for (
size_t i = 1; i < num; ++i) {
126 boost::geometry::intersection(
poly,
pixel, overlap);
129 double const polyArea = boost::geometry::area(*i);
137 int const xStart,
int const xStop,
int const y) {
140 x <= xStop; ++i, ++
x) {
141 *i = pixelOverlap(
poly,
x,
y);
160 for (
size_t i = 0; i < num - 1; ++i) {
169 return os <<
"BoostPolygon(" <<
poly.outer() <<
")";
180 boost::geometry::assign(
poly, box);
195 template <
class PolyT>
197 return !boost::geometry::disjoint(
poly,
other);
200 template <
class PolyT>
203 template <
class PolyT>
206 template <
class PolyT>
209 template <
class PolyT>
212 template <
class PolyT>
229 template <
class PolyT>
239 (
boost::format(
"Multiple polygons (%d) created by intersection()") %
result.size()).str());
244 template <
class PolyT>
247 boost::geometry::intersection(
poly,
other, boostResult);
248 return convertBoostPolygons(boostResult);
251 template <
class PolyT>
263 template <
class PolyT>
266 boost::geometry::union_(
poly,
other, boostResult);
267 return convertBoostPolygons(boostResult);
270 template <
class PolyT>
273 boost::geometry::sym_difference(
poly,
other, boostResult);
274 return convertBoostPolygons(boostResult);
290 auto corners =
transform.applyForward(boxToCorners(box));
291 boost::geometry::assign(_impl->poly, corners);
301 boost::geometry::assign(_impl->poly, corners);
307 return boost::geometry::num_points(_impl->poly) - 1;
311 return boostBoxToLsst(boost::geometry::return_envelope<BoostBox>(_impl->poly));
315 return boost::geometry::return_centroid<LsstPoint>(_impl->poly);
338 return _impl->poly.outer().end() - 1;
342 return boost::geometry::equals(_impl->poly,
other._impl->poly);
348 static boost::hash<BoostPolygon::ring_type> polygonHash;
349 return polygonHash(_impl->poly.outer());
359 return _impl->intersectionSingle(
other._impl->poly);
363 return _impl->intersectionSingle(box);
367 return _impl->intersection(
other._impl->poly);
371 return _impl->intersection(box);
375 return _impl->unionSingle(
other._impl->poly);
381 return _impl->union_(
other._impl->poly);
387 return _impl->symDifference(
other._impl->poly);
391 return _impl->symDifference(box);
402 boost::geometry::convex_hull(_impl->poly, hull);
415 i != _impl->poly.outer().end(); ++i) {
426 addSubSampledEdge(
vertices, i->first, i->second, num);
436 Point const &p1 = i->first, p2 = i->second;
437 double const dist = ::sqrt(p1.distanceSquared(p2));
438 addSubSampledEdge(
vertices, p1, p2,
static_cast<size_t>(::
ceil(dist / maxLength)));
453 for (
int y = yMin;
y <= yMax; ++
y) {
454 double const yPixelMin = (double)
y - 0.5, yPixelMax = (
double)
y + 0.5;
456 boost::geometry::assign(
459 boost::geometry::intersection(_impl->poly,
row, intersections);
461 if (intersections.
size() == 1 && boost::geometry::num_points(intersections[0]) == 5) {
470 double const xCoord = i->getX(), yCoord = i->getY();
471 if (yCoord == yPixelMin) {
473 }
else if (yCoord == yPixelMax) {
480 if (!failed && top.
size() == 2 && bottom.
size() == 2) {
483 int const xMin =
std::min(top[0], bottom[0]);
485 int const xStop =
std::min(top[1], bottom[1]) - 1;
504 double xMinRow = xMax, xMaxRow = xMin;
507 double const x = q->getX();
508 if (
x < xMinRow) xMinRow =
x;
509 if (
x > xMaxRow) xMaxRow =
x;
512 pixelRowOverlap(
image, _impl->poly,
std::max(
static_cast<int>(xMinRow),
bbox.getMinX()),
526 struct PolygonSchema {
530 static PolygonSchema
const& get() {
531 static PolygonSchema instance;
536 PolygonSchema(
const PolygonSchema&) =
delete;
537 PolygonSchema& operator=(
const PolygonSchema&) =
delete;
540 PolygonSchema(PolygonSchema&&) =
delete;
541 PolygonSchema& operator=(PolygonSchema&&) =
delete;
546 vertices(
afw::table::PointKey<double>::addFields(
schema,
"vertices",
"list of vertex points",
550 class PolygonFactory :
public table::io::PersistableFactory {
555 CatalogVector
const& catalogs)
const override {
556 static PolygonSchema
const&
keys = PolygonSchema::get();
570 std::string getPolygonPersistenceName() {
return "Polygon"; }
572 PolygonFactory registration(getPolygonPersistenceName());
579 static PolygonSchema
const&
keys = PolygonSchema::get();
585 record->set(
keys.vertices, *i);
592 return std::make_unique<Polygon>(*
this);
597 buffer <<
"Polygon(" << this->
getVertices() <<
")";
602 return singleClassEquals(*
this,
other);
CatalogIterator< typename Internal::const_iterator > const_iterator
Point2D const getMin() const noexcept
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
std::shared_ptr< Polygon > transform(TransformPoint2ToPoint2 const &transform) const
Transform the polygon.
bool overlaps(PolyT const &other) const
Polygon(Box const &box)
Construct a rectangular Polygon whose vertices are the corners of a box.
static double get(LsstBox const &box)
std::shared_ptr< typehandling::Storable > cloneStorable() const override
Create a new Polygon that is a copy of this one.
afw::table::PointKey< double > vertices
std::vector< LsstPoint > LsstRing
double calculatePerimeter() const
An object passed to Persistable::write to allow it to persist itself.
lsst::afw::geom::polygon::Polygon::Point LsstPoint
std::vector< Point >::const_iterator end() const
boost::geometry::model::polygon< LsstPoint > BoostPolygon
double calculateArea() const
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
static void set(LsstPoint &p, LsstPoint::Element const &value)
std::shared_ptr< Polygon > intersectionSingle(PolyT const &other) const
boost::geometry::model::box< LsstPoint > BoostBox
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Interface supporting iteration over heterogenous containers.
Impl(BoostPolygon const &_poly)
static std::vector< std::shared_ptr< Polygon > > convertBoostPolygons(std::vector< BoostPolygon > const &boostPolygons)
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
std::shared_ptr< Polygon > subSample(size_t num) const
Sub-sample each edge.
bool overlaps(Polygon const &other) const
Returns whether the polygons overlap each other.
Impl(std::vector< LsstPoint > const &vertices)
std::shared_ptr< Polygon > unionSingle(Polygon const &other) const
Returns the union of two polygons.
std::shared_ptr< Polygon > unionSingle(PolyT const &other) const
bool equals(typehandling::Storable const &other) const noexcept override
Compare this object to another Storable.
double getMinY() const noexcept
An exception that indicates the single-polygon assumption has been violated.
std::size_t hash_value() const noexcept override
Return a hash of this object.
Polygon & operator=(Polygon const &)
boost::geometry::model::linestring< LsstPoint > BoostLineString
std::vector< std::shared_ptr< Polygon > > symDifference(PolyT const &other) const
double getMaxX() const noexcept
Impl(Polygon::Box const &box)
double getMinX() const noexcept
std::vector< std::shared_ptr< Polygon > > intersection(Polygon const &other) const
Returns the intersection of two polygons.
std::shared_ptr< afw::image::Image< float > > createImage(lsst::geom::Box2I const &bbox) const
Create image of polygon.
std::vector< std::shared_ptr< Polygon > > union_(Polygon const &other) const
Returns the union of two polygons.
ItemVariant const * other
Box getBBox() const
Return bounding box.
std::ostream & operator<<(std::ostream &os, Polygon const &poly)
Stream polygon.
static double get(LsstBox const &box)
Point2D const getMax() const noexcept
static double get(LsstBox const &box)
std::string toString() const override
Create a string representation of this object.
bool contains(Point const &point) const
Returns whether the polygon contains the point.
std::vector< std::shared_ptr< Polygon > > intersection(PolyT const &other) const
Point calculateCenter() const
table::PointKey< int > pixel
static double get(LsstPoint const &p)
std::vector< Point > getVertices() const
Get vector of vertices.
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
std::vector< std::shared_ptr< Polygon > > union_(PolyT const &other) const
A base class for image defects.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
std::shared_ptr< Polygon > simplify(double const distance) const
Return a simplified polygon.
CatalogT< BaseRecord > BaseCatalog
std::vector< std::pair< Point, Point > > getEdges() const
Get vector of edges.
reference front() const
Return the first record.
std::vector< Point >::const_iterator begin() const
Iterator for vertices.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
double getMaxY() const noexcept
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
An integer coordinate rectangle.
std::shared_ptr< Polygon > intersectionSingle(Polygon const &other) const
Returns the intersection of two polygons.
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
size_t getNumEdges() const
Return number of edges.
lsst::afw::geom::polygon::Polygon::Box LsstBox
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
std::shared_ptr< Polygon > convexHull() const
Produce a polygon from the convex hull.
A floating-point coordinate rectangle geometry.
static double get(LsstBox const &box)
Extent< int, N > ceil(Extent< double, N > const &input) noexcept
Return the component-wise ceil (round towards more positive).
std::vector< std::shared_ptr< Polygon > > symDifference(Polygon const &other) const
Return the symmetric difference of two polygons.
afw::table::Schema schema
bool operator==(Polygon const &other) const