43template <
class FromEndpo
int,
class ToEndpo
int>
45 : _fromEndpoint(mapping.getNIn()),
46 _mapping(simplify ? mapping.simplified() : mapping.copy()),
47 _toEndpoint(mapping.getNOut()) {}
49template <
typename FromEndpo
int,
typename ToEndpo
int>
51 : _fromEndpoint(
frameSet.getNIn()), _mapping(), _toEndpoint(
frameSet.getNOut()) {
60 _toEndpoint.normalizeFrame(frameSetCopy);
64 const int baseIndex = frameSetCopy->getBase();
65 const int currentIndex = frameSetCopy->getCurrent();
66 frameSetCopy->setCurrent(baseIndex);
67 _fromEndpoint.normalizeFrame(frameSetCopy);
68 frameSetCopy->setBase(baseIndex);
69 frameSetCopy->setCurrent(currentIndex);
70 _mapping = simplify ? frameSetCopy->getMapping()->
simplified() : frameSetCopy->getMapping();
73template <
typename FromEndpo
int,
typename ToEndpo
int>
75 : _fromEndpoint(mapping->getNIn()), _mapping(mapping), _toEndpoint(mapping->getNOut()) {}
77template <
class FromEndpo
int,
class ToEndpo
int>
79 typename FromEndpoint::Point
const &point)
const {
80 auto const rawFromData = _fromEndpoint.dataFromPoint(point);
81 auto rawToData = _mapping->applyForward(rawFromData);
82 return _toEndpoint.pointFromData(rawToData);
85template <
class FromEndpo
int,
class ToEndpo
int>
87 typename FromEndpoint::Array
const &array)
const {
88 auto const rawFromData = _fromEndpoint.dataFromArray(array);
89 auto rawToData = _mapping->applyForward(rawFromData);
90 return _toEndpoint.arrayFromData(rawToData);
93template <
class FromEndpo
int,
class ToEndpo
int>
95 typename ToEndpoint::Point
const &point)
const {
96 auto const rawFromData = _toEndpoint.dataFromPoint(point);
97 auto rawToData = _mapping->applyInverse(rawFromData);
98 return _fromEndpoint.pointFromData(rawToData);
101template <
class FromEndpo
int,
class ToEndpo
int>
103 typename ToEndpoint::Array
const &array)
const {
104 auto const rawFromData = _toEndpoint.dataFromArray(array);
105 auto rawToData = _mapping->applyInverse(rawFromData);
106 return _fromEndpoint.arrayFromData(rawToData);
109template <
class FromEndpo
int,
class ToEndpo
int>
111 auto inverse = std::dynamic_pointer_cast<ast::Mapping>(_mapping->inverted());
115 buffer <<
"Mapping.inverted() does not return a Mapping. Called from: " << _mapping;
118 return std::make_shared<Transform<ToEndpoint, FromEndpoint>>(*inverse);
121template <
class FromEndpo
int,
class ToEndpo
int>
123 int const nIn = _fromEndpoint.getNAxes();
124 int const nOut = _toEndpoint.getNAxes();
127 Eigen::MatrixXd jacobian(nOut, nIn);
128 for (
int i = 0; i < nOut; ++i) {
129 for (
int j = 0; j < nIn; ++j) {
130 jacobian(i, j) = _mapping->rate(point, i + 1, j + 1);
136template <
class FromEndpo
int,
class ToEndpo
int>
139 os <<
"Transform" << FromEndpoint::getClassPrefix() <<
"To" << ToEndpoint::getClassPrefix();
143template <
class FromEndpo
int,
class ToEndpo
int>
146 return detail::readStream<Transform<FromEndpoint, ToEndpoint>>(is);
149template <
class FromEndpo
int,
class ToEndpo
int>
156template <
class FromEndpo
int,
class ToEndpo
int>
158 detail::writeStream<Transform<FromEndpoint, ToEndpoint>>(*
this,
os);
161template <
class FromEndpo
int,
class ToEndpo
int>
168template <
class FromEndpo
int,
class ToEndpo
int>
169template <
class NextToEndpo
int>
172 if (_toEndpoint.getNAxes() == next.getFromEndpoint().getNAxes()) {
173 auto nextMapping = next.getMapping();
174 auto combinedMapping = getMapping()->then(*next.getMapping());
176 return std::make_shared<Transform<FromEndpoint, NextToEndpoint>>(*combinedMapping.simplified());
178 return std::make_shared<Transform<FromEndpoint, NextToEndpoint>>(combinedMapping);
181 auto message =
"Cannot match " +
std::to_string(_toEndpoint.getNAxes()) +
"-D to-endpoint to " +
182 std::to_string(next.getFromEndpoint().getNAxes()) +
"-D from-endpoint.";
187template <
class FromEndpo
int,
class ToEndpo
int>
189 os <<
"Transform<" << transform.getFromEndpoint() <<
", " << transform.getToEndpoint() <<
">";
195class TransformPersistenceHelper {
197 table::Schema schema;
198 table::Key<table::Array<std::uint8_t>>
bytes;
200 static TransformPersistenceHelper
const &get() {
201 static TransformPersistenceHelper instance;
206 TransformPersistenceHelper(TransformPersistenceHelper
const &) =
delete;
207 TransformPersistenceHelper &operator=(TransformPersistenceHelper
const &) =
delete;
210 TransformPersistenceHelper(TransformPersistenceHelper &&) =
delete;
211 TransformPersistenceHelper &operator=(TransformPersistenceHelper &&) =
delete;
214 TransformPersistenceHelper()
216 bytes(schema.addField<table::Array<
std::uint8_t>>(
217 "bytes",
"a bytestring containing the output of Transform.writeString",
"")) {}
220template <
typename FromEndpo
int,
typename ToEndpo
int>
221class TransformFactory :
public table::io::PersistableFactory {
223 explicit TransformFactory(
std::string const &name) : table::io::PersistableFactory(name) {}
226 CatalogVector
const &catalogs)
const override {
227 auto const &keys = TransformPersistenceHelper::get();
231 auto const &record = catalogs.front().front();
239template <
class FromEndpo
int,
class ToEndpo
int>
241 auto const &keys = TransformPersistenceHelper::get();
248#define INSTANTIATE_OVERLOADS(FromEndpoint, ToEndpoint, NextToEndpoint) \
249 template std::shared_ptr<Transform<FromEndpoint, NextToEndpoint>> \
250 Transform<FromEndpoint, ToEndpoint>::then<NextToEndpoint>( \
251 Transform<ToEndpoint, NextToEndpoint> const &next, bool) const;
253#define INSTANTIATE_TRANSFORM(FromEndpoint, ToEndpoint) \
255 template std::shared_ptr<geom::Transform<geom::FromEndpoint, geom::ToEndpoint>> \
256 table::io::PersistableFacade<geom::Transform<geom::FromEndpoint, geom::ToEndpoint>>::dynamicCast( \
257 std::shared_ptr<table::io::Persistable> const &); \
259 template class Transform<FromEndpoint, ToEndpoint>; \
260 template std::ostream &operator<<<FromEndpoint, ToEndpoint>( \
261 std::ostream &os, Transform<FromEndpoint, ToEndpoint> const &transform); \
263 TransformFactory<FromEndpoint, ToEndpoint> registration##FromEndpoint##ToEndpoint( \
264 Transform<FromEndpoint, ToEndpoint>::getShortClassName()); \
266 INSTANTIATE_OVERLOADS(FromEndpoint, ToEndpoint, GenericEndpoint) \
267 INSTANTIATE_OVERLOADS(FromEndpoint, ToEndpoint, Point2Endpoint) \
268 INSTANTIATE_OVERLOADS(FromEndpoint, ToEndpoint, SpherePointEndpoint)
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
table::Key< table::Array< std::uint8_t > > bytes
A FrameSet consists of a set of one or more Frames (which describe coordinate systems),...
An abstract base class for objects which transform one set of coordinates to another.
std::shared_ptr< Mapping > simplified() const
Return a simplied version of the mapping (which may be a compound Mapping such as a CmpMap).
A generic endpoint for data in the format used by ast::Mapping.
An endpoint for lsst::geom::Point2D.
An endpoint for lsst::geom::SpherePoint.
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
An object passed to Persistable::write to allow it to persist itself.
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
Reports invalid arguments.
Reports errors in the logical structure of the program.
std::ostream & operator<<(std::ostream &os, GenericEndpoint const &endpoint)
Print "GenericEndpoint(_n_)" to the ostream where _n_ is the number of axes, e.g. "GenericAxes(4)".
std::shared_ptr< table::io::Persistable > read(table::io::InputArchive const &archive, table::io::CatalogVector const &catalogs) const override