27 #include "ndarray/eigen.h"
42 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
43 "To EndPoint of transform must have 1 axis but has " +
53 ndarray::Array<double const, 1>
const& y)
const {
54 if (x.getSize<0>() != y.getSize<0>()) {
55 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
56 "x length " + std::to_string(x.getSize<0>()) +
"!= y length " +
57 std::to_string(x.getSize<0>()));
61 int const nPoints = x.getSize<0>();
62 ndarray::Array<double, 2, 2> xy = ndarray::allocate(ndarray::makeVector(2, nPoints));
63 for (
int col = 0; col < nPoints; ++col) {
68 auto res2D = _transform.
getFrameSet()->applyForward(xy);
71 auto resShape = ndarray::makeVector(nPoints);
72 auto resStrides = ndarray::makeVector(1);
73 return ndarray::external(res2D.getData(), resShape, resStrides, res2D);
80 struct PersistenceHelper {
88 bboxMin(table::PointKey<int>::addFields(
schema,
"bbox_min",
"lower-left corner of bounding box",
91 "upper-right corner of bounding box",
"pixel")),
92 frameSet(
schema.addField<std::string>(
"frameSet",
"FrameSet contained in the Transform", 0,
95 PersistenceHelper(table::Schema
const& s)
99 class TransformBoundedFieldFactory :
public table::io::PersistableFactory {
101 explicit TransformBoundedFieldFactory(std::string
const&
name)
102 : afw::table::io::PersistableFactory(name) {}
104 std::shared_ptr<table::io::Persistable> read(InputArchive
const& archive,
105 CatalogVector
const& catalogs)
const override {
108 table::BaseRecord
const& record = catalogs.front().front();
109 PersistenceHelper
const keys(record.getSchema());
111 geom::Box2I bbox(record.get(keys.bboxMin), record.get(keys.bboxMax),
false);
112 auto frameSetStr = record.get(keys.frameSet);
115 return std::make_shared<TransformBoundedField>(bbox, transform);
119 std::string getTransformBoundedFieldPersistenceName() {
return "TransformBoundedField"; }
121 TransformBoundedFieldFactory registration(getTransformBoundedFieldPersistenceName());
126 return getTransformBoundedFieldPersistenceName();
132 PersistenceHelper
const keys;
134 std::shared_ptr<table::BaseRecord> record = catalog.
addNew();
135 record->set(keys.bboxMin,
getBBox().getMin());
136 record->set(keys.bboxMax,
getBBox().getMax());
137 record->set(keys.frameSet,
getTransform().writeString());
142 auto zoomMap = ast::ZoomMap(1, scale);
144 auto newTransform =
Transform(newMapping);
145 return std::make_shared<TransformBoundedField>(
getBBox(), newTransform);
150 if (!rhsCasted)
return false;
152 return getBBox() == rhsCasted->getBBox() &&
156 std::string TransformBoundedField::toString()
const {
157 std::ostringstream os;
158 os <<
"TransformBoundedField (containing " << _transform.
getFrameSet()->getNFrame() <<
" frames)";
An object passed to Persistable::write to allow it to persist itself.
A custom container class for records, based on std::vector.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
table::PointKey< int > bboxMin
table::PointKey< int > bboxMax
geom::Box2I getBBox() const
Return the bounding box that defines the region where the field is valid.
An integer coordinate rectangle.
table::Key< std::string > name
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
An abstract base class for 2-d functions defined on an integer bounding boxes.
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
afw::table::Schema schema
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.