LSSTApplications  11.0-24-g0a022a1,15.0+8,15.0+9,15.0-1-g19261fa+1,15.0-1-g1eca518+10,15.0-1-g60afb23+8,15.0-1-g615e0bb,15.0-1-g6668b0b+5,15.0-1-g788a293+8,15.0-1-ga91101e+8,15.0-1-gae1598d+7,15.0-1-gc45031d+10,15.0-1-gd076f1f+8,15.0-1-gdf18595+1,15.0-1-gf4f1c34+7,15.0-18-g5f205baaa,15.0-2-g100d730+1,15.0-2-g18f3f21,15.0-2-g35685a8+1,15.0-2-g947dc0d+10,15.0-2-ge3d7f4b+1,15.0-2-gf38729e,15.0-3-g150fc43+9,15.0-3-g6f085af+1,15.0-3-g9103c06+7,15.0-3-ga03b4ca+10,15.0-3-gaec6799+5,15.0-3-gb7a597c+8,15.0-3-ge6a6747,15.0-4-g45f767a+7,15.0-4-g654b129+6,15.0-4-gff20472+11,15.0-5-g389937dc+6,15.0-5-ga70c291+1,15.0-6-gbad5ef12+1,15.0-6-ge2d9597+10
LSSTDataManagementBasePackage
SimplePolyMapping.h
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 #ifndef LSST_JOINTCAL_SIMPLE_POLY_MAPPING_H
3 #define LSST_JOINTCAL_SIMPLE_POLY_MAPPING_H
4 
5 #include <memory> // for unique_ptr
6 
10 
12 
16 namespace lsst {
17 namespace jointcal {
18 
20 public:
22  : toFit(toFit), transfo(gtransfo.clone()), errorProp(transfo), lin(new GtransfoLin) {
23  // in this order:
24  // take a copy of the input transfo,
25  // assign the transformation used to propagate errors to the transfo itself
26  // reserve some memory space to compute the derivatives (efficiency).
27  }
28 
34 
35  virtual void freezeErrorTransform() {
36  // from there on, updating the transfo does not change the errors.
37  errorProp = transfo->clone();
38  }
39 
40  // interface Mapping functions:
41 
43  unsigned getNpar() const {
44  if (toFit)
45  return transfo->getNpar();
46  else
47  return 0;
48  }
49 
52  if (indices.size() < getNpar()) indices.resize(getNpar());
53  for (unsigned k = 0; k < getNpar(); ++k) indices[k] = index + k;
54  }
55 
57  void transformPosAndErrors(FatPoint const &where, FatPoint &outPoint) const {
58  transfo->transformPosAndErrors(where, outPoint);
59  FatPoint tmp;
60  errorProp->transformPosAndErrors(where, tmp);
61  outPoint.vx = tmp.vx;
62  outPoint.vy = tmp.vy;
63  outPoint.vxy = tmp.vxy;
64  }
65 
67  void positionDerivative(Point const &where, Eigen::Matrix2d &derivative, double epsilon) const {
68  errorProp->computeDerivative(where, *lin, epsilon);
69  derivative(0, 0) = lin->coeff(1, 0, 0);
70  //
71  /* This does not work : it was proved by rotating the frame
72  see the compilation switch ROTATE_T2 in constrainedpolymodel.cc
73  derivative(1,0) = lin->coeff(1,0,1);
74  derivative(0,1) = lin->coeff(0,1,0);
75  */
76  derivative(1, 0) = lin->coeff(0, 1, 0);
77  derivative(0, 1) = lin->coeff(1, 0, 1);
78  derivative(1, 1) = lin->coeff(0, 1, 1);
79  }
80 
82  void offsetParams(Eigen::VectorXd const &delta) { transfo->offsetParams(delta); }
83 
85  unsigned getIndex() const { return index; }
86 
88  void setIndex(unsigned i) { index = i; }
89 
90  virtual void computeTransformAndDerivatives(FatPoint const &where, FatPoint &outPoint,
91  Eigen::MatrixX2d &H) const {
92  transformPosAndErrors(where, outPoint);
93  transfo->paramDerivatives(where, &H(0, 0), &H(0, 1));
94  }
95 
97  virtual Gtransfo const &getTransfo() const { return *transfo; }
98 
99 protected:
100  bool toFit;
101  unsigned index;
102  /* inheritance may also work. Perhaps with some trouble because
103  some routines in Mapping and Gtransfo have the same name */
105 
107  /* to avoid allocation at every call of positionDerivative.
108  use a pointer for constness */
110 };
111 
114 public:
116 
117  // ! contructor.
120  SimplePolyMapping(GtransfoLin const &CenterAndScale, GtransfoPoly const &gtransfo)
121  : SimpleGtransfoMapping(gtransfo), _centerAndScale(CenterAndScale) {
122  // We assume that the initialization was done properly, for example that
123  // gtransfo = pix2TP*CenterAndScale.invert(), so we do not touch transfo.
124  /* store the (spatial) derivative of _centerAndScale. For the extra
125  diagonal terms, just copied the ones in positionDerivatives */
126  preDer(0, 0) = _centerAndScale.coeff(1, 0, 0);
127  preDer(1, 0) = _centerAndScale.coeff(0, 1, 0);
128  preDer(0, 1) = _centerAndScale.coeff(1, 0, 1);
129  preDer(1, 1) = _centerAndScale.coeff(0, 1, 1);
130 
131  // check of matrix indexing (once for all)
132  MatrixX2d H(3, 2);
133  assert((&H(1, 0) - &H(0, 0)) == 1);
134  }
135 
137  SimplePolyMapping(SimplePolyMapping const &) = delete;
139  SimplePolyMapping &operator=(SimplePolyMapping const &) = delete;
141 
142  /* The SimpleGtransfoMapping version does not account for the
143  _centerAndScale transfo */
144 
145  void positionDerivative(Point const &where, Eigen::Matrix2d &derivative, double epsilon) const {
146  Point tmp = _centerAndScale.apply(where);
147  errorProp->computeDerivative(tmp, *lin, epsilon);
148  derivative(0, 0) = lin->coeff(1, 0, 0);
149  //
150  /* This does not work : it was proved by rotating the frame
151  see the compilation switch ROTATE_T2 in constrainedpolymodel.cc
152  derivative(1,0) = lin->coeff(1,0,1);
153  derivative(0,1) = lin->coeff(0,1,0);
154  */
155  derivative(1, 0) = lin->coeff(0, 1, 0);
156  derivative(0, 1) = lin->coeff(1, 0, 1);
157  derivative(1, 1) = lin->coeff(0, 1, 1);
158  derivative = preDer * derivative;
159  }
160 
162  /* We should put the computation of error propagation and
163  parameter derivatives into the same Gtransfo routine because
164  it could be significantly faster */
165  virtual void computeTransformAndDerivatives(FatPoint const &where, FatPoint &outPoint,
166  Eigen::MatrixX2d &H) const {
167  FatPoint mid;
168  _centerAndScale.transformPosAndErrors(where, mid);
169  transfo->transformPosAndErrors(mid, outPoint);
170  FatPoint tmp;
171  errorProp->transformPosAndErrors(mid, tmp);
172  outPoint.vx = tmp.vx;
173  outPoint.vy = tmp.vy;
174  outPoint.vxy = tmp.vxy;
175  transfo->paramDerivatives(mid, &H(0, 0), &H(0, 1));
176  }
177 
179  void transformPosAndErrors(FatPoint const &where, FatPoint &outPoint) const {
180  FatPoint mid;
181  _centerAndScale.transformPosAndErrors(where, mid);
182  transfo->transformPosAndErrors(mid, outPoint);
183  FatPoint tmp;
184  errorProp->transformPosAndErrors(mid, tmp);
185  outPoint.vx = tmp.vx;
186  outPoint.vy = tmp.vy;
187  outPoint.vxy = tmp.vxy;
188  }
189 
191  Gtransfo const &getTransfo() const {
192  // Cannot fail given the contructor:
193  const GtransfoPoly *fittedPoly = dynamic_cast<const GtransfoPoly *>(&(*transfo));
194  actualResult = (*fittedPoly) * _centerAndScale;
195  return actualResult;
196  }
197 
198 private:
199  /* to better condition the 2nd derivative matrix, the
200  transformed coordinates are mapped (roughly) on [-1,1].
201  We need both the transform and its derivative. */
202  GtransfoLin _centerAndScale;
203  Eigen::Matrix2d preDer;
204 
205  /* Where we store the combination. */
206  mutable GtransfoPoly actualResult;
207 };
208 
209 #ifdef STORAGE
210 
212 class SimpleIdentityMapping : public SimpleGtransfoMapping<GtransfoIdentity> {
213 public:
215  virtual void computeTransformAndDerivatives(FatPoint const &where, FatPoint &outPoint,
216  Eigen::MatrixX2d &H) const {
217  outPoint = where;
218  }
219 };
220 #endif
221 } // namespace jointcal
222 } // namespace lsst
223 
224 #endif // LSST_JOINTCAL_SIMPLE_POLY_MAPPING_H
implements the linear transformations (6 real coefficients).
Definition: Gtransfo.h:294
virtual class needed in the abstraction of the distortion model
Definition: Mapping.h:15
SimpleGtransfoMapping & operator=(SimpleGtransfoMapping const &)=delete
A point in a plane.
Definition: Point.h:13
Mapping implementation for a polynomial transformation.
virtual Gtransfo const & getTransfo() const
Access to the (fitted) transfo.
SimplePolyMapping(GtransfoLin const &CenterAndScale, GtransfoPoly const &gtransfo)
The transformation will be initialized to gtransfo, so that the effective transformation reads gtrans...
void positionDerivative(Point const &where, Eigen::Matrix2d &derivative, double epsilon) const
The derivative w.r.t. position.
Polynomial transformation class.
Definition: Gtransfo.h:195
A Point with uncertainties.
Definition: FatPoint.h:11
T resize(T... args)
unsigned getNpar() const
Number of parameters in total.
A base class for image defects.
Definition: cameraGeom.dox:3
void transformPosAndErrors(FatPoint const &where, FatPoint &outPoint) const
Implements as well the centering and scaling of coordinates.
SimpleGtransfoMapping(Gtransfo const &gtransfo, bool toFit=true)
void offsetParams(Eigen::VectorXd const &delta)
Remember the error scale and freeze it.
virtual void computeTransformAndDerivatives(FatPoint const &where, FatPoint &outPoint, Eigen::MatrixX2d &H) const
Actually applies the mapping and evaluates the derivatives w.r.t the fitted parameters.
Eigen::Matrix< double, Eigen::Dynamic, 2 > MatrixX2d
Definition: Eigenstuff.h:9
void getMappingIndices(std::vector< unsigned > &indices) const
Sets how this set of parameters (of length Npar()) map into the "grand" fit Expects that indices has ...
T size(T... args)
STL class.
unsigned getIndex() const
position of the parameters within the grand fitting scheme
virtual void computeTransformAndDerivatives(FatPoint const &where, FatPoint &outPoint, Eigen::MatrixX2d &H) const
Calls the transforms and implements the centering and scaling of coordinates.
a virtual (interface) class for geometric transformations.
Definition: Gtransfo.h:41
Gtransfo const & getTransfo() const
Access to the (fitted) transfo.
void positionDerivative(Point const &where, Eigen::Matrix2d &derivative, double epsilon) const
The derivative w.r.t. position.
void transformPosAndErrors(FatPoint const &where, FatPoint &outPoint) const
The same as above but without the parameter derivatives (used to evaluate chi^2)
std::unique_ptr< GtransfoLin > lin
std::shared_ptr< Gtransfo > errorProp
std::shared_ptr< Gtransfo > transfo