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()) {
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);
82 auto rawToData = _mapping->applyForward(rawFromData);
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);
90 auto rawToData = _mapping->applyForward(rawFromData);
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);
98 auto rawToData = _mapping->applyInverse(rawFromData);
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);
106 auto rawToData = _mapping->applyInverse(rawFromData);
107 return _fromEndpoint.arrayFromData(rawToData);
110 template <
class FromEndpo
int,
class ToEndpo
int>
112 auto inverse = std::dynamic_pointer_cast<ast::Mapping>(_mapping->inverted());
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>
173 if (_toEndpoint.getNAxes() ==
next.getFromEndpoint().getNAxes()) {
174 auto nextMapping =
next.getMapping();
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()
218 "bytes",
"a bytestring containing the output of Transform.writeString",
"")) {}
221 template <
typename FromEndpo
int,
typename ToEndpo
int>
222 class TransformFactory :
public table::io::PersistableFactory {
227 CatalogVector
const &catalogs)
const override {
228 auto const &
keys = TransformPersistenceHelper::get();
232 auto const &record = catalogs.front().front();
240 template <
class FromEndpo
int,
class ToEndpo
int>
242 auto const &
keys = TransformPersistenceHelper::get();
249 #define INSTANTIATE_OVERLOADS(FromEndpoint, ToEndpoint, NextToEndpoint) \
250 template std::shared_ptr<Transform<FromEndpoint, NextToEndpoint>> \
251 Transform<FromEndpoint, ToEndpoint>::then<NextToEndpoint>( \
252 Transform<ToEndpoint, NextToEndpoint> const &next, bool) const;
254 #define INSTANTIATE_TRANSFORM(FromEndpoint, ToEndpoint) \
256 template std::shared_ptr<geom::Transform<geom::FromEndpoint, geom::ToEndpoint>> \
257 table::io::PersistableFacade<geom::Transform<geom::FromEndpoint, geom::ToEndpoint>>::dynamicCast( \
258 std::shared_ptr<table::io::Persistable> const &); \
260 template class Transform<FromEndpoint, ToEndpoint>; \
261 template std::ostream &operator<<<FromEndpoint, ToEndpoint>( \
262 std::ostream &os, Transform<FromEndpoint, ToEndpoint> const &transform); \
264 TransformFactory<FromEndpoint, ToEndpoint> registration##FromEndpoint##ToEndpoint( \
265 Transform<FromEndpoint, ToEndpoint>::getShortClassName()); \
267 INSTANTIATE_OVERLOADS(FromEndpoint, ToEndpoint, GenericEndpoint) \
268 INSTANTIATE_OVERLOADS(FromEndpoint, ToEndpoint, Point2Endpoint) \
269 INSTANTIATE_OVERLOADS(FromEndpoint, ToEndpoint, SpherePointEndpoint)