43 template <
class FromEndpo
int,
class ToEndpo
int>
45 : _fromEndpoint(mapping.getNIn()),
46 _mapping(simplify ? mapping.simplify() : mapping.copy()),
47 _toEndpoint(mapping.getNOut()) {}
49 template <
typename FromEndpo
int,
typename ToEndpo
int>
51 : _fromEndpoint(frameSet.getNIn()), _mapping(), _toEndpoint(frameSet.getNOut()) {
52 auto frameSetCopy = frameSet.
copy();
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()->simplify() : frameSetCopy->getMapping();
73 template <
typename FromEndpo
int,
typename ToEndpo
int>
75 : _fromEndpoint(mapping->getNIn()), _mapping(mapping), _toEndpoint(mapping->getNOut()) {}
77 template <
class FromEndpo
int,
class ToEndpo
int>
79 typename FromEndpoint::Point
const &point)
const {
80 auto const rawFromData = _fromEndpoint.dataFromPoint(point);
82 return _toEndpoint.pointFromData(rawToData);
85 template <
class FromEndpo
int,
class ToEndpo
int>
87 typename FromEndpoint::Array
const &array)
const {
88 auto const rawFromData = _fromEndpoint.dataFromArray(array);
90 return _toEndpoint.arrayFromData(rawToData);
93 template <
class FromEndpo
int,
class ToEndpo
int>
95 typename ToEndpoint::Point
const &point)
const {
96 auto const rawFromData = _toEndpoint.dataFromPoint(point);
98 return _fromEndpoint.pointFromData(rawToData);
101 template <
class FromEndpo
int,
class ToEndpo
int>
103 typename ToEndpoint::Array
const &array)
const {
104 auto const rawFromData = _toEndpoint.dataFromArray(array);
106 return _fromEndpoint.arrayFromData(rawToData);
109 template <
class FromEndpo
int,
class ToEndpo
int>
115 buffer <<
"Mapping.getInverse() does not return a Mapping. Called from: " << _mapping;
118 return std::make_shared<Transform<ToEndpoint, FromEndpoint>>(*inverse);
121 template <
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);
136 template <
class FromEndpo
int,
class ToEndpo
int>
139 os <<
"Transform" << FromEndpoint::getClassPrefix() <<
"To" << ToEndpoint::getClassPrefix();
143 template <
class FromEndpo
int,
class ToEndpo
int>
146 return detail::readStream<Transform<FromEndpoint, ToEndpoint>>(is);
149 template <
class FromEndpo
int,
class ToEndpo
int>
156 template <
class FromEndpo
int,
class ToEndpo
int>
158 detail::writeStream<Transform<FromEndpoint, ToEndpoint>>(*
this,
os);
161 template <
class FromEndpo
int,
class ToEndpo
int>
168 template <
class FromEndpo
int,
class ToEndpo
int>
169 template <
class NextToEndpo
int>
174 auto combinedMapping = getMapping()->then(*next.
getMapping());
176 return std::make_shared<Transform<FromEndpoint, NextToEndpoint>>(*combinedMapping.simplify());
178 return std::make_shared<Transform<FromEndpoint, NextToEndpoint>>(combinedMapping);
181 auto message =
"Cannot match " +
std::to_string(_toEndpoint.getNAxes()) +
"-D to-endpoint to " +
187 template <
class FromEndpo
int,
class ToEndpo
int>
195 class TransformPersistenceHelper {
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",
"")) {
218 schema.getCitizen().markPersistent();
222 template <
typename FromEndpo
int,
typename ToEndpo
int>
223 class TransformFactory :
public table::io::PersistableFactory {
225 explicit TransformFactory(
std::string const &
name) : table::io::PersistableFactory(name) {}
228 CatalogVector
const &catalogs)
const {
229 auto const &
keys = TransformPersistenceHelper::get();
233 auto const &record = catalogs.front().front();
235 return Transform<FromEndpoint, ToEndpoint>::readString(stringRep);
241 template <
class FromEndpo
int,
class ToEndpo
int>
243 auto const &
keys = TransformPersistenceHelper::get();
250 #define INSTANTIATE_OVERLOADS(FromEndpoint, ToEndpoint, NextToEndpoint) \ 251 template std::shared_ptr<Transform<FromEndpoint, NextToEndpoint>> \ 252 Transform<FromEndpoint, ToEndpoint>::then<NextToEndpoint>( \ 253 Transform<ToEndpoint, NextToEndpoint> const &next, bool) const; 255 #define INSTANTIATE_TRANSFORM(FromEndpoint, ToEndpoint) \ 256 template class Transform<FromEndpoint, ToEndpoint>; \ 257 template std::ostream &operator<<<FromEndpoint, ToEndpoint>( \ 258 std::ostream &os, Transform<FromEndpoint, ToEndpoint> const &transform); \ 260 TransformFactory<FromEndpoint, ToEndpoint> registration##FromEndpoint##ToEndpoint( \ 261 Transform<FromEndpoint, ToEndpoint>::getShortClassName()); \ 263 INSTANTIATE_OVERLOADS(FromEndpoint, ToEndpoint, GenericEndpoint) \ 264 INSTANTIATE_OVERLOADS(FromEndpoint, ToEndpoint, Point2Endpoint) \ 265 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.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
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.
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.
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.