26 #include <type_traits> 29 #include "boost/optional.hpp" 36 namespace cameraGeom {
52 auto mapping = _getMapping(fromSys, toSys);
59 auto mapping = _getMapping(fromSys, toSys);
67 return std::make_shared<geom::TransformPoint2ToPoint2>(*_getMapping(fromSys, toSys));
70 int TransformMap::_getFrame(
CameraSys const &system)
const {
72 return _frameIds.
at(system);
75 buffer <<
"Unsupported coordinate system: " << system;
82 return _transforms->
getMapping(_getFrame(fromSys), _getFrame(toSys));
108 if (fromSys == toSys) {
110 buffer <<
"Identity connection detected for " << fromSys <<
".";
113 if (!transform->hasForward()) {
115 buffer <<
"Connection from " << fromSys <<
" to " 116 << toSys <<
" has no forward transform.";
119 if (!transform->hasInverse()) {
121 buffer <<
"Connection from " << fromSys <<
" to " 122 << toSys <<
" has no inverse transform.";
135 for (
auto const & item : transforms) {
136 other.
connect(fromSys, item.first, item.second);
138 _connections.
insert(_connections.
end(), other._connections.
begin(), other._connections.
end());
148 template <
typename Callable>
152 explicit OnScopeExit(Callable callable) : _callable(
std::move(callable)) {}
154 ~OnScopeExit() noexcept(noexcept(std::declval<Callable>())) {
163 template <
typename Callable>
164 OnScopeExit<Callable> onScopeExit(Callable callable) {
165 return OnScopeExit<Callable>(
std::move(callable));
178 auto findFrameIdForSys = [&frameIds](
CameraSys const & sys) -> boost::optional<int> {
179 auto iter = frameIds.
find(sys);
180 if (iter != frameIds.
end()) {
181 return boost::optional<int>(iter->second);
191 frameIds.
emplace(sys, ++nFrames);
192 return ast::Frame(2,
"Ident=" + sys.getSysName());
197 auto frameSet = std::make_unique<ast::FrameSet>(addFrameForSys(_reference));
200 auto guard = onScopeExit(
202 for (
auto const & c : _connections) { c.processed =
false; }
207 while (nProcessedTotal != _connections.size()) {
212 for (
auto const & c : _connections) {
213 if (c.processed)
continue;
214 auto fromId = findFrameIdForSys(c.fromSys);
215 auto toId = findFrameIdForSys(c.toSys);
216 if (fromId && toId) {
218 buffer <<
"Duplicate connection from " << c.fromSys <<
" to " << c.toSys <<
".";
221 frameSet->addFrame(*fromId, *c.transform->getMapping(), addFrameForSys(c.toSys));
223 ++nProcessedThisPass;
225 frameSet->addFrame(*toId, *c.transform->inverted()->getMapping(), addFrameForSys(c.fromSys));
227 ++nProcessedThisPass;
233 if (nProcessedThisPass == 0u) {
237 for (
auto const & c : _connections) {
239 orphaned.
insert(c.fromSys);
244 auto o = orphaned.
begin();
245 buffer <<
"Orphaned coordinate system(s) found: " << *o;
246 for (++o; o != orphaned.
end(); ++o) {
247 buffer <<
", " << *o;
253 nProcessedTotal += nProcessedThisPass;
258 assert(
frameSet->getNFrame() == nFrames);
Camera coordinate system; used as a key in in TransformMap.
Point pointFromData(std::vector< double > const &data) const override
Get a single point from raw data.
ItemVariant const * other
Array arrayFromData(ndarray::Array< double, 2, 2 > const &data) const override
Get an array of points from raw data.
A base class for image defects.
T throw_with_nested(T... args)
std::vector< double > dataFromPoint(Point const &point) const override
#define LSST_EXCEPT(type,...)
An endpoint for lsst::geom::Point2D.
std::shared_ptr< Mapping > getMapping(int from=BASE, int to=CURRENT) const
ndarray::Array< double, 2, 2 > dataFromArray(Array const &arr) const override