42 template <
class FromEndpo
int,
class ToEndpo
int>
44 : _fromEndpoint(mapping.getNIn()),
45 _mapping(simplify ? mapping.simplify() : mapping.copy()), _toEndpoint(mapping.getNOut()) {}
47 template <
typename FromEndpo
int,
typename ToEndpo
int>
49 : _fromEndpoint(frameSet.getNIn()), _mapping(), _toEndpoint(frameSet.getNOut()) {
50 auto frameSetCopy = frameSet.
copy();
58 _toEndpoint.normalizeFrame(frameSetCopy);
62 const int baseIndex = frameSetCopy->getBase();
63 const int currentIndex = frameSetCopy->getCurrent();
64 frameSetCopy->setCurrent(baseIndex);
65 _fromEndpoint.normalizeFrame(frameSetCopy);
66 frameSetCopy->setBase(baseIndex);
67 frameSetCopy->setCurrent(currentIndex);
68 _mapping = simplify ? frameSetCopy->getMapping()->simplify() : frameSetCopy->getMapping();
71 template <
typename FromEndpo
int,
typename ToEndpo
int>
73 : _fromEndpoint(mapping->getNIn()), _mapping(mapping), _toEndpoint(mapping->getNOut()) {
76 template <
class FromEndpo
int,
class ToEndpo
int>
78 typename FromEndpoint::Point
const &point)
const {
79 auto const rawFromData = _fromEndpoint.dataFromPoint(point);
81 return _toEndpoint.pointFromData(rawToData);
84 template <
class FromEndpo
int,
class ToEndpo
int>
86 typename FromEndpoint::Array
const &array)
const {
87 auto const rawFromData = _fromEndpoint.dataFromArray(array);
89 return _toEndpoint.arrayFromData(rawToData);
92 template <
class FromEndpo
int,
class ToEndpo
int>
94 typename ToEndpoint::Point
const &point)
const {
95 auto const rawFromData = _toEndpoint.dataFromPoint(point);
97 return _fromEndpoint.pointFromData(rawToData);
100 template <
class FromEndpo
int,
class ToEndpo
int>
102 typename ToEndpoint::Array
const &array)
const {
103 auto const rawFromData = _toEndpoint.dataFromArray(array);
105 return _fromEndpoint.arrayFromData(rawToData);
108 template <
class FromEndpo
int,
class ToEndpo
int>
114 buffer <<
"Mapping.getInverse() does not return a Mapping. Called from: " << _mapping;
117 return std::make_shared<Transform<ToEndpoint, FromEndpoint>>(*inverse);
120 template <
class FromEndpo
int,
class ToEndpo
int>
122 int const nIn = _fromEndpoint.getNAxes();
123 int const nOut = _toEndpoint.getNAxes();
126 Eigen::MatrixXd jacobian(nOut, nIn);
127 for (
int i = 0; i < nOut; ++i) {
128 for (
int j = 0; j < nIn; ++j) {
129 jacobian(i, j) = _mapping->rate(point, i + 1, j + 1);
135 template <
class FromEndpo
int,
class ToEndpo
int>
138 os <<
"Transform" << FromEndpoint::getClassPrefix() <<
"To" << ToEndpoint::getClassPrefix();
142 template <
class FromEndpo
int,
class ToEndpo
int>
145 return detail::readStream<Transform<FromEndpoint, ToEndpoint>>(is);
148 template <
class FromEndpo
int,
class ToEndpo
int>
155 template <
class FromEndpo
int,
class ToEndpo
int>
157 detail::writeStream<Transform<FromEndpoint, ToEndpoint>>(*
this,
os);
160 template <
class FromEndpo
int,
class ToEndpo
int>
167 template <
class FromEndpo
int,
class ToEndpo
int>
168 template <
class NextToEndpo
int>
173 auto combinedMapping = getMapping()->then(*next.
getMapping());
175 return std::make_shared<Transform<FromEndpoint, NextToEndpoint>>(*combinedMapping.simplify());
177 return std::make_shared<Transform<FromEndpoint, NextToEndpoint>>(combinedMapping);
180 auto message =
"Cannot match " +
std::to_string(_toEndpoint.getNAxes()) +
"-D to-endpoint to " +
186 template <
class FromEndpo
int,
class ToEndpo
int>
194 class TransformPersistenceHelper {
197 table::Key<table::Array<std::uint8_t>>
bytes;
199 static TransformPersistenceHelper
const &
get() {
200 static TransformPersistenceHelper instance;
205 TransformPersistenceHelper(TransformPersistenceHelper
const &) =
delete;
206 TransformPersistenceHelper& operator=(TransformPersistenceHelper
const &) =
delete;
209 TransformPersistenceHelper(TransformPersistenceHelper&&) =
delete;
210 TransformPersistenceHelper& operator=(TransformPersistenceHelper&&) =
delete;
213 TransformPersistenceHelper() :
216 schema.addField<table::Array<std::uint8_t>>(
218 "a bytestring containing the output of Transform.writeString",
"" 222 schema.getCitizen().markPersistent();
227 template <
typename FromEndpo
int,
typename ToEndpo
int>
228 class TransformFactory :
public table::io::PersistableFactory {
230 explicit TransformFactory(
std::string const &
name) : table::io::PersistableFactory(name) {}
233 CatalogVector
const& catalogs)
const {
234 auto const &
keys = TransformPersistenceHelper::get();
238 auto const & record = catalogs.front().front();
240 return Transform<FromEndpoint, ToEndpoint>::readString(stringRep);
248 template <
class FromEndpo
int,
class ToEndpo
int>
250 auto const&
keys = TransformPersistenceHelper::get();
258 #define INSTANTIATE_OVERLOADS(FromEndpoint, ToEndpoint, NextToEndpoint) \ 259 template std::shared_ptr<Transform<FromEndpoint, NextToEndpoint>> \ 260 Transform<FromEndpoint, ToEndpoint>::then<NextToEndpoint>( \ 261 Transform<ToEndpoint, NextToEndpoint> const &next, bool) const; 263 #define INSTANTIATE_TRANSFORM(FromEndpoint, ToEndpoint) \ 264 template class Transform<FromEndpoint, ToEndpoint>; \ 265 template std::ostream &operator<<<FromEndpoint, ToEndpoint>( \ 266 std::ostream &os, Transform<FromEndpoint, ToEndpoint> const &transform); \ 268 TransformFactory<FromEndpoint, ToEndpoint> registration ## FromEndpoint ## ToEndpoint( \ 269 Transform<FromEndpoint, ToEndpoint>::getShortClassName() \ 272 INSTANTIATE_OVERLOADS(FromEndpoint, ToEndpoint, GenericEndpoint) \ 273 INSTANTIATE_OVERLOADS(FromEndpoint, ToEndpoint, Point2Endpoint) \ 274 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.
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)
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 and message and optionally other arguments (dependent on the ty...
#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.