LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Private Attributes | List of all members
lsst::afw::geom::TransformMap< CoordSysT > Class Template Reference

#include <TransformMap.h>

Public Types

typedef std::map< CoordSysT,
boost::shared_ptr< XYTransform
const > > 
Transforms
 
typedef CoordSysT CoordSys
 

Public Member Functions

 TransformMap (CoordSysT const &nativeCoordSys, Transforms const &transforms)
 
 TransformMap ()
 null implementation to make SWIG willing to wrap a map that contains these More...
 
Point2D transform (Point2D const &fromPoint, CoordSysT const &fromSys, CoordSysT const &toCoordSys) const
 
std::vector< Point2Dtransform (std::vector< Point2D > const &pointList, CoordSysT const &fromCoordSys, CoordSysT const &toCoordSys) const
 
CoordSysT getNativeCoordSys () const
 
std::vector< CoordSysT > getCoordSysList () const
 
bool contains (CoordSysT const &coordSys) const
 
boost::shared_ptr< XYTransform
const > 
operator[] (CoordSysT const &coordSys) const
 
Transforms::const_iterator begin () const
 
Transforms::const_iterator end () const
 
size_t size () const
 

Private Attributes

CoordSysT _nativeCoordSys
 native coordinate system More...
 
Transforms _transforms
 map of coordSys: XYTransform More...
 

Detailed Description

template<typename CoordSysT>
class lsst::afw::geom::TransformMap< CoordSysT >

A registry of 2-dimensional coordinate transforms, templated on a coordinate system type

Contains a native CoordSysT and a map of CoordSysT:XYTransform (including an identity transform entry for native CoordSysT). Each map entry is an XYTransform whose forwardTransform method converts from the native system to CoordSysT.

TransformMap supports transforming between any two supported CoordSysT using the transform method. It also allows iteration over the map of CoordSysT: XYTransform:

If CoordSysT is not a plain old data type or std::string then:

At some point we will switch to using std::unordered_map (once we switch to C++11 and a SWIG that supports its collection classes). At that point instead of requiring CoordSysT.operator<, it will be necessary to specialize std::hash<CoordSysT>(CoordSysT const &).

Warning
: code that instantiates a templated version of TransformMap must include lsst/afw/geom/TransformMapImpl.h (else you will get linker errors).

Definition at line 65 of file TransformMap.h.

Member Typedef Documentation

template<typename CoordSysT>
typedef CoordSysT lsst::afw::geom::TransformMap< CoordSysT >::CoordSys

Definition at line 68 of file TransformMap.h.

template<typename CoordSysT>
typedef std::map<CoordSysT, boost::shared_ptr< XYTransform const> > lsst::afw::geom::TransformMap< CoordSysT >::Transforms

Definition at line 67 of file TransformMap.h.

Constructor & Destructor Documentation

template<typename CoordSysT>
lsst::afw::geom::TransformMap< CoordSysT >::TransformMap ( CoordSysT const &  nativeCoordSys,
Transforms const &  transforms 
)
explicit

Construct a TransformMap

Note
If transformMap includes a transform for nativeCoordSys then it is used (without checking); if not, then a unity transform is added.
Exceptions
pexExcept::InvalidParameterErrorif you specify the same coordSys more than once, or a transform is specified where coordSys == nativeCoordSys
Parameters
nativeCoordSysNative coordinate system for this registry
transformsa map of coordSys:xyTransform, where xyTransform.forward transforms coordSys to nativeCoordSys

Definition at line 38 of file TransformMapImpl.h.

41  :
42  _nativeCoordSys(nativeCoordSys), _transforms()
43 {
44  for (typename Transforms::const_iterator trIter = transforms.begin();
45  trIter != transforms.end(); ++trIter) {
46  if (_transforms.count(trIter->first) > 0) {
47  std::ostringstream os;
48  os << "Duplicate coordSys \"" << trIter->first << "\"";
49  throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError, os.str());
50  } else if (trIter->first == _nativeCoordSys) {
51  std::ostringstream os;
52  os << "coordSys \"" << trIter->first << "\" matches nativeCoordSys";
53  throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError, os.str());
54  }
55  _transforms.insert(*trIter);
56  }
57 
58  // insert identity transform for nativeCoordSys, if not already provided
59  if (!contains(nativeCoordSys)) {
60  _transforms.insert(std::make_pair(nativeCoordSys,
61  boost::make_shared<IdentityXYTransform>()));
62  }
63 }
Transforms _transforms
map of coordSys: XYTransform
Definition: TransformMap.h:150
CoordSysT _nativeCoordSys
native coordinate system
Definition: TransformMap.h:149
bool contains(CoordSysT const &coordSys) const
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
template<typename CoordSysT>
lsst::afw::geom::TransformMap< CoordSysT >::TransformMap ( )
explicit

null implementation to make SWIG willing to wrap a map that contains these

Definition at line 66 of file TransformMapImpl.h.

Transforms _transforms
map of coordSys: XYTransform
Definition: TransformMap.h:150
CoordSysT _nativeCoordSys
native coordinate system
Definition: TransformMap.h:149

Member Function Documentation

template<typename CoordSysT>
Transforms::const_iterator lsst::afw::geom::TransformMap< CoordSysT >::begin ( ) const
inline

Definition at line 142 of file TransformMap.h.

142 { return _transforms.begin(); }
Transforms _transforms
map of coordSys: XYTransform
Definition: TransformMap.h:150
template<typename CoordSysT>
bool lsst::afw::geom::TransformMap< CoordSysT >::contains ( CoordSysT const &  coordSys) const

Return true if the coordinate system is supported

In Python this is renamed to contains; use as follows: coordSys in transformMap

Parameters
coordSyscoordinate system

Definition at line 146 of file TransformMapImpl.h.

148  {
149  return _transforms.find(coordSys) != _transforms.end();
150 }
Transforms _transforms
map of coordSys: XYTransform
Definition: TransformMap.h:150
template<typename CoordSysT>
Transforms::const_iterator lsst::afw::geom::TransformMap< CoordSysT >::end ( ) const
inline

Definition at line 144 of file TransformMap.h.

144 { return _transforms.end(); }
Transforms _transforms
map of coordSys: XYTransform
Definition: TransformMap.h:150
template<typename CoordSysT >
std::vector< CoordSysT > lsst::afw::geom::TransformMap< CoordSysT >::getCoordSysList ( ) const

Get a list of supported coordinate systems

Returns
a list of coordinate systems, in undefined order.

Definition at line 123 of file TransformMapImpl.h.

123  {
124  std::vector<CoordSysT> coordSysList;
125  for (typename Transforms::const_iterator trIter = _transforms.begin();
126  trIter != _transforms.end(); ++trIter) {
127  coordSysList.push_back(trIter->first);
128  }
129  return coordSysList;
130 }
Transforms _transforms
map of coordSys: XYTransform
Definition: TransformMap.h:150
template<typename CoordSysT>
CoordSysT lsst::afw::geom::TransformMap< CoordSysT >::getNativeCoordSys ( ) const
inline

Definition at line 112 of file TransformMap.h.

112 { return _nativeCoordSys; }
CoordSysT _nativeCoordSys
native coordinate system
Definition: TransformMap.h:149
template<typename CoordSysT>
boost::shared_ptr< XYTransform const > lsst::afw::geom::TransformMap< CoordSysT >::operator[] ( CoordSysT const &  coordSys) const

Get an XYTransform that transforms from coordSys to nativeCoordSys in the forward direction

Returns
a shared_ptr to an XYTransform
Exceptions
pexExcept::InvalidParameterErrorif coordSys is unknown
Parameters
coordSyscoordinate system whose XYTransform is wanted

Definition at line 133 of file TransformMapImpl.h.

135  {
136  typename Transforms::const_iterator const foundIter = _transforms.find(coordSys);
137  if (foundIter == _transforms.end()) {
138  std::ostringstream os;
139  os << "Registry does not support coordSys \"" << coordSys << "\"";
140  throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError, os.str());
141  }
142  return foundIter->second;
143 }
Transforms _transforms
map of coordSys: XYTransform
Definition: TransformMap.h:150
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
template<typename CoordSysT>
size_t lsst::afw::geom::TransformMap< CoordSysT >::size ( ) const
inline

Definition at line 146 of file TransformMap.h.

146 { return _transforms.size(); }
Transforms _transforms
map of coordSys: XYTransform
Definition: TransformMap.h:150
template<typename CoordSysT>
Point2D lsst::afw::geom::TransformMap< CoordSysT >::transform ( Point2D const &  fromPoint,
CoordSysT const &  fromSys,
CoordSysT const &  toCoordSys 
) const

Convert a point from one coordinate system to another

Returns
the transformed value as a Point2D
Exceptions
pexExcept::InvalidParameterErrorif toCoordSys is unknown
Parameters
fromPointpoint from which to transform
fromSyscoordinate system from which to transform
toCoordSyscoordinate system to which to transform

Definition at line 70 of file TransformMapImpl.h.

74  {
75  if (fromCoordSys == toCoordSys) {
76  return fromPoint;
77  }
78 
79  // transform fromSys -> nativeSys -> toSys
80  CONST_PTR(XYTransform) fromTransform = (*this)[fromCoordSys];
81  CONST_PTR(XYTransform) toTransform = (*this)[toCoordSys];
82  return toTransform->forwardTransform(fromTransform->reverseTransform(fromPoint));
83 }
#define CONST_PTR(...)
Definition: base.h:47
template<typename CoordSysT>
std::vector< Point2D > lsst::afw::geom::TransformMap< CoordSysT >::transform ( std::vector< Point2D > const &  pointList,
CoordSysT const &  fromCoordSys,
CoordSysT const &  toCoordSys 
) const

Convert a list of Point2D from one coordinate system to another

Exceptions
pexExcept::InvalidParameterErrorif fromCoordSys or toCoordSys is unknown
Parameters
pointListlist of points to transform
fromCoordSysfrom coordinate system
toCoordSysto coordinate system

Definition at line 86 of file TransformMapImpl.h.

90  {
91  if (fromCoordSys == toCoordSys) {
92  return pointList;
93  }
94 
95  std::vector<Point2D> outList;
96 
97  // transform pointList from fromCoordSys to native coords, filling outList
98  if (fromCoordSys != _nativeCoordSys) {
99  CONST_PTR(XYTransform) fromTransform = (*this)[fromCoordSys];
100  for (std::vector<Point2D>::const_iterator fromPtIter = pointList.begin();
101  fromPtIter != pointList.end(); ++fromPtIter) {
102  outList.push_back(fromTransform->reverseTransform(*fromPtIter));
103  }
104  } else {
105  for (std::vector<Point2D>::const_iterator fromPtIter = pointList.begin();
106  fromPtIter != pointList.end(); ++fromPtIter) {
107  outList.push_back(*fromPtIter);
108  }
109  }
110 
111  // transform outList from native coords to toCoordSys, in place
112  if (toCoordSys != _nativeCoordSys) {
113  CONST_PTR(XYTransform) toTransform = (*this)[toCoordSys];
114  for (std::vector<Point2D>::iterator nativePtIter = outList.begin();
115  nativePtIter != outList.end(); ++nativePtIter) {
116  *nativePtIter = toTransform->forwardTransform(*nativePtIter);
117  }
118  }
119  return outList;
120 }
for(FootprintList::const_iterator ptr=feet->begin(), end=feet->end();ptr!=end;++ptr)
Definition: saturated.cc:82
CoordSysT _nativeCoordSys
native coordinate system
Definition: TransformMap.h:149
Point< double, 2 > Point2D
Definition: Point.h:286
Transforms::const_iterator end() const
Definition: TransformMap.h:144
Transforms::const_iterator begin() const
Definition: TransformMap.h:142
#define CONST_PTR(...)
Definition: base.h:47

Member Data Documentation

template<typename CoordSysT>
CoordSysT lsst::afw::geom::TransformMap< CoordSysT >::_nativeCoordSys
private

native coordinate system

Definition at line 149 of file TransformMap.h.

template<typename CoordSysT>
Transforms lsst::afw::geom::TransformMap< CoordSysT >::_transforms
private

map of coordSys: XYTransform

Definition at line 150 of file TransformMap.h.


The documentation for this class was generated from the following files: