38 #include "lsst/afw/table/io/Persistable.cc" 44 template <
class FromEndpo
int,
class ToEndpo
int>
46 : _fromEndpoint(mapping.getNIn()),
47 _mapping(simplify ? mapping.
simplified() : mapping.copy()),
48 _toEndpoint(mapping.getNOut()) {}
50 template <
typename FromEndpo
int,
typename ToEndpo
int>
52 : _fromEndpoint(frameSet.getNIn()), _mapping(), _toEndpoint(frameSet.getNOut()) {
53 auto frameSetCopy = frameSet.
copy();
61 _toEndpoint.normalizeFrame(frameSetCopy);
65 const int baseIndex = frameSetCopy->getBase();
66 const int currentIndex = frameSetCopy->getCurrent();
67 frameSetCopy->setCurrent(baseIndex);
68 _fromEndpoint.normalizeFrame(frameSetCopy);
69 frameSetCopy->setBase(baseIndex);
70 frameSetCopy->setCurrent(currentIndex);
71 _mapping = simplify ? frameSetCopy->getMapping()->simplified() : frameSetCopy->getMapping();
74 template <
typename FromEndpo
int,
typename ToEndpo
int>
76 : _fromEndpoint(mapping->getNIn()), _mapping(mapping), _toEndpoint(mapping->getNOut()) {}
78 template <
class FromEndpo
int,
class ToEndpo
int>
80 typename FromEndpoint::Point
const &point)
const {
81 auto const rawFromData = _fromEndpoint.dataFromPoint(point);
83 return _toEndpoint.pointFromData(rawToData);
86 template <
class FromEndpo
int,
class ToEndpo
int>
88 typename FromEndpoint::Array
const &array)
const {
89 auto const rawFromData = _fromEndpoint.dataFromArray(array);
91 return _toEndpoint.arrayFromData(rawToData);
94 template <
class FromEndpo
int,
class ToEndpo
int>
96 typename ToEndpoint::Point
const &point)
const {
97 auto const rawFromData = _toEndpoint.dataFromPoint(point);
99 return _fromEndpoint.pointFromData(rawToData);
102 template <
class FromEndpo
int,
class ToEndpo
int>
104 typename ToEndpoint::Array
const &array)
const {
105 auto const rawFromData = _toEndpoint.dataFromArray(array);
107 return _fromEndpoint.arrayFromData(rawToData);
110 template <
class FromEndpo
int,
class ToEndpo
int>
116 buffer <<
"Mapping.inverted() does not return a Mapping. Called from: " << _mapping;
119 return std::make_shared<Transform<ToEndpoint, FromEndpoint>>(*inverse);
122 template <
class FromEndpo
int,
class ToEndpo
int>
124 int const nIn = _fromEndpoint.getNAxes();
125 int const nOut = _toEndpoint.getNAxes();
128 Eigen::MatrixXd jacobian(nOut, nIn);
129 for (
int i = 0; i < nOut; ++i) {
130 for (
int j = 0; j < nIn; ++j) {
131 jacobian(i, j) = _mapping->rate(point, i + 1, j + 1);
137 template <
class FromEndpo
int,
class ToEndpo
int>
140 os <<
"Transform" << FromEndpoint::getClassPrefix() <<
"To" << ToEndpoint::getClassPrefix();
144 template <
class FromEndpo
int,
class ToEndpo
int>
147 return detail::readStream<Transform<FromEndpoint, ToEndpoint>>(is);
150 template <
class FromEndpo
int,
class ToEndpo
int>
157 template <
class FromEndpo
int,
class ToEndpo
int>
159 detail::writeStream<Transform<FromEndpoint, ToEndpoint>>(*
this,
os);
162 template <
class FromEndpo
int,
class ToEndpo
int>
169 template <
class FromEndpo
int,
class ToEndpo
int>
170 template <
class NextToEndpo
int>
175 auto combinedMapping = getMapping()->then(*next.
getMapping());
177 return std::make_shared<Transform<FromEndpoint, NextToEndpoint>>(*combinedMapping.simplified());
179 return std::make_shared<Transform<FromEndpoint, NextToEndpoint>>(combinedMapping);
182 auto message =
"Cannot match " +
std::to_string(_toEndpoint.getNAxes()) +
"-D to-endpoint to " +
188 template <
class FromEndpo
int,
class ToEndpo
int>
196 class TransformPersistenceHelper {
199 table::Key<table::Array<std::uint8_t>>
bytes;
201 static TransformPersistenceHelper
const &
get() {
202 static TransformPersistenceHelper instance;
207 TransformPersistenceHelper(TransformPersistenceHelper
const &) =
delete;
208 TransformPersistenceHelper &operator=(TransformPersistenceHelper
const &) =
delete;
211 TransformPersistenceHelper(TransformPersistenceHelper &&) =
delete;
212 TransformPersistenceHelper &operator=(TransformPersistenceHelper &&) =
delete;
215 TransformPersistenceHelper()
217 bytes(schema.addField<table::Array<std::uint8_t>>(
218 "bytes",
"a bytestring containing the output of Transform.writeString",
"")) {
219 schema.getCitizen().markPersistent();
223 template <
typename FromEndpo
int,
typename ToEndpo
int>
224 class TransformFactory :
public table::io::PersistableFactory {
226 explicit TransformFactory(
std::string const &
name) : table::io::PersistableFactory(name) {}
229 CatalogVector
const &catalogs)
const override {
230 auto const &
keys = TransformPersistenceHelper::get();
234 auto const &record = catalogs.front().front();
236 return Transform<FromEndpoint, ToEndpoint>::readString(stringRep);
242 template <
class FromEndpo
int,
class ToEndpo
int>
244 auto const &
keys = TransformPersistenceHelper::get();
251 #define INSTANTIATE_OVERLOADS(FromEndpoint, ToEndpoint, NextToEndpoint) \ 252 template std::shared_ptr<Transform<FromEndpoint, NextToEndpoint>> \ 253 Transform<FromEndpoint, ToEndpoint>::then<NextToEndpoint>( \ 254 Transform<ToEndpoint, NextToEndpoint> const &next, bool) const; 256 #define INSTANTIATE_TRANSFORM(FromEndpoint, ToEndpoint) \ 258 template std::shared_ptr<geom::Transform<geom::FromEndpoint, geom::ToEndpoint>> \ 259 table::io::PersistableFacade<geom::Transform<geom::FromEndpoint, geom::ToEndpoint>>::dynamicCast( \ 260 std::shared_ptr<table::io::Persistable> const &); \ 262 template class Transform<FromEndpoint, ToEndpoint>; \ 263 template std::ostream &operator<<<FromEndpoint, ToEndpoint>( \ 264 std::ostream &os, Transform<FromEndpoint, ToEndpoint> const &transform); \ 266 TransformFactory<FromEndpoint, ToEndpoint> registration##FromEndpoint##ToEndpoint( \ 267 Transform<FromEndpoint, ToEndpoint>::getShortClassName()); \ 269 INSTANTIATE_OVERLOADS(FromEndpoint, ToEndpoint, GenericEndpoint) \ 270 INSTANTIATE_OVERLOADS(FromEndpoint, ToEndpoint, Point2Endpoint) \ 271 INSTANTIATE_OVERLOADS(FromEndpoint, ToEndpoint, SpherePointEndpoint)
An object passed to Persistable::write to allow it to persist itself.
std::shared_ptr< Transform > readStream(std::istream &is)
Deserialize a Transform from an input stream.
void writeStream(Transform const &transform, std::ostream &os)
Serialize a Transform to an output stream.
table::Key< int > transform
An abstract base class for objects which transform one set of coordinates to another.
PolynomialFunction1d simplified(ScaledPolynomialFunction1d const &f)
Calculate the standard polynomial function that is equivalent to a scaled standard polynomial functio...
std::shared_ptr< FrameSet > copy() const
Return a deep copy of this object.
A base class for image defects.
T dynamic_pointer_cast(T... args)
Reports errors in the logical structure of the program.
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Reports invalid arguments.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
A FrameSet consists of a set of one or more Frames (which describe coordinate systems), connected together by Mappings (which describe how the coordinate systems are inter-related).
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.