2 #ifndef LSST_JOINTCAL_GTRANSFO_H
3 #define LSST_JOINTCAL_GTRANSFO_H
10 #include "lsst/pex/exceptions.h"
13 namespace pexExcept = lsst::pex::exceptions;
40 virtual void apply(
const double xIn,
const double yIn,
double &xOut,
double &yOut)
const = 0;
50 return Point(xout, yout);
54 virtual void dump(std::ostream &stream = std::cout)
const = 0;
76 virtual std::unique_ptr<Gtransfo>
clone()
const = 0;
83 virtual double getJacobian(
const double x,
const double y)
const;
91 const double step = 0.01)
const;
104 virtual std::unique_ptr<Gtransfo>
inverseTransfo(
const double precision,
const Frame ®ion)
const;
113 virtual double paramRef(
const int i)
const;
116 virtual double &
paramRef(
const int i);
130 void write(
const std::string &fileName)
const;
132 virtual void write(std::ostream &stream)
const;
138 std::ostream &
operator<<(std::ostream &stream,
const Gtransfo >ransfo);
143 std::unique_ptr<Gtransfo>
gtransfoCompose(
const Gtransfo *left,
const Gtransfo *right);
154 void apply(
const double xIn,
const double yIn,
double &xOut,
double &yOut)
const {
160 throw pexExcept::TypeError(
161 "GtransfoIdentity is the identity transformation: it cannot be fit to anything.");
165 void dump(std::ostream &stream = std::cout)
const { stream <<
"x' = x\ny' = y" << std::endl; }
175 void write(std::ostream &s)
const;
177 void read(std::istream &s);
198 std::vector<double> _coeffs;
210 void computeMonomials(
double xIn,
double yIn,
double *monomial)
const;
223 void apply(
const double xIn,
const double yIn,
double &xOut,
double &yOut)
const;
238 void dump(std::ostream &stream = std::cout)
const;
254 std::unique_ptr<Gtransfo>
clone()
const {
return std::unique_ptr<Gtransfo>(
new GtransfoPoly(*
this)); }
257 double coeff(
const unsigned powX,
const unsigned powY,
const unsigned whichCoord)
const;
260 double &
coeff(
const unsigned powX,
const unsigned powY,
const unsigned whichCoord);
263 double coeffOrZero(
const unsigned powX,
const unsigned powY,
const unsigned whichCoord)
const;
277 void write(std::ostream &s)
const;
278 void read(std::istream &s);
281 double computeFit(
const StarMatchList &starMatchList,
const Gtransfo &InTransfo,
const bool UseErrors);
285 std::unique_ptr<GtransfoPoly>
inversePolyTransfo(
const Gtransfo &Direct,
const Frame &frame,
320 GtransfoLin(
const double ox,
const double oy,
const double aa11,
const double aa12,
const double aa21,
326 std::unique_ptr<Gtransfo>
clone()
const {
return std::unique_ptr<Gtransfo>(
new GtransfoLin(*
this)); }
328 std::unique_ptr<Gtransfo>
inverseTransfo(
const double precision,
const Frame ®ion)
const;
350 void setDegree(
const unsigned degree);
374 GtransfoLinRot(
const double angleRad,
const Point *center =
nullptr,
const double scaleFactor = 1.0);
400 std::unique_ptr<GtransfoPoly>
corr;
414 void apply(
const double xIn,
const double yIn,
double &xOut,
double &yOut)
const;
435 virtual void pix2TP(
double xPixel,
double yPixel,
double &xTangentPlane,
double &yTangentPlane)
const = 0;
455 virtual void pix2TP(
double xPixel,
double yPixel,
double &xTangentPlane,
double &yTangentPlane)
const;
472 std::unique_ptr<Gtransfo>
inverseTransfo(
const double precision,
const Frame ®ion)
const;
474 std::unique_ptr<Gtransfo>
clone()
const;
476 void dump(std::ostream &stream)
const;
494 virtual void pix2TP(
double xPixel,
double yPixel,
double &xTangentPlane,
double &yTangentPlane)
const;
500 std::unique_ptr<Gtransfo>
inverseTransfo(
const double precision,
const Frame ®ion)
const;
502 std::unique_ptr<Gtransfo>
clone()
const;
504 void dump(std::ostream &stream)
const;
541 void apply(
const double xIn,
const double yIn,
double &xOut,
double &yOut)
const;
553 std::unique_ptr<Gtransfo>
inverseTransfo(
const double precision,
const Frame ®ion)
const;
555 void dump(std::ostream &stream)
const;
557 std::unique_ptr<Gtransfo>
clone()
const;
563 typedef void(
GtransfoFun)(
const double,
const double,
double &,
double &,
const void *);
569 const void *_userData;
577 void apply(
const double xIn,
const double yIn,
double &xOut,
double &yOut)
const;
579 void dump(std::ostream &stream = std::cout)
const;
583 std::unique_ptr<Gtransfo>
clone()
const;
587 std::unique_ptr<Gtransfo>
gtransfoRead(
const std::string &fileName);
589 std::unique_ptr<Gtransfo>
gtransfoRead(std::istream &s);
593 #endif // LSST_JOINTCAL_GTRANSFO_H
GtransfoPoly operator-(const GtransfoPoly &right) const
Subtraction.
GtransfoLin linearApproximation(const Point &where, const double step=0.01) const
linear (local) approximation.
void write(std::ostream &s) const
Implements the (forward) SIP distorsion scheme.
implements the linear transformations (6 real coefficients).
GtransfoPoly getPix2TangentPlane() const
the transformation from pixels to tangent plane (coordinates in degrees)
virtual void transformPosAndErrors(const FatPoint &in, FatPoint &out) const
a mix of apply and Derivative
GtransfoLin getLinPart() const
The Linear part (corresponding to CD's and CRPIX's)
GtransfoPoly getPix2TangentPlane() const
the transformation from pixels to tangent plane (coordinates in degrees)
virtual void transformErrors(const Point &where, const double *vIn, double *vOut) const
transform errors (represented as double[3] in order V(xx),V(yy),Cov(xy))
std::unique_ptr< Gtransfo > clone() const
returns a copy (allocated by new) of the transformation.
std::unique_ptr< Gtransfo > gtransfoCompose(const Gtransfo *left, const Gtransfo *right)
Returns a pointer to a composition.
virtual std::unique_ptr< Gtransfo > roughInverse(const Frame ®ion) const
Rough inverse.
unsigned getDegree() const
returns degree
GtransfoPoly operator+(const GtransfoPoly &right) const
Addition.
GtransfoLin(const GtransfoIdentity &)
Handy converter:
the transformation that handles pix to sideral transfos (Gnomonic, possibly with polynomial distortio...
void setCorrections(std::unique_ptr< GtransfoPoly > corrections)
Assign the correction polynomial (what it means is left to derived classes)
GtransfoLinShift(double ox=0., double oy=0.)
Add ox and oy.
int getNpar() const
total number of parameters
virtual void pix2TP(double xPixel, double yPixel, double &xTangentPlane, double &yTangentPlane) const
transforms from pixel space to tangent plane
double coeff(const unsigned powX, const unsigned powY, const unsigned whichCoord) const
access to coefficients (read only)
virtual void pix2TP(double xPixel, double yPixel, double &xTangentPlane, double &yTangentPlane) const
transforms from pixel space to tangent plane
void computeDerivative(const Point &where, GtransfoLin &derivative, const double step=0.01) const
specialised analytic routine
std::unique_ptr< Gtransfo > inverseTransfo(const double precision, const Frame ®ion) const
Inverse transfo: returns a TanRaDec2Pix if there are no corrections, or the iterative solver if there...
std::unique_ptr< Gtransfo > clone() const
returns a copy (allocated by new) of the transformation.
virtual GtransfoLin linearApproximation(const Point &where, const double step=0.01) const
linear (local) approximation.
Point getTangentPoint() const
tangent point coordinates (in degrees)
GtransfoLinScale(const double scale=1)
void dump(std::ostream &stream=std::cout) const
dumps the transfo coefficients to stream.
std::unique_ptr< Gtransfo > roughInverse(const Frame ®ion) const
Overload the "generic routine" (available for all Gtransfo types.
std::unique_ptr< Gtransfo > inverseTransfo(const double precision, const Frame ®ion) const
returns an inverse transfo. Numerical if not overloaded.
GtransfoLinShift(const Point &point)
bool isIdentity(const Gtransfo *gtransfo)
Shorthand test to tell if a transfo belongs to the GtransfoIdentity class.
GtransfoLin operator*(const GtransfoLin &right) const
enables to combine linear tranformations: T1=T2*T3 is legal.
virtual double fit(const StarMatchList &starMatchList)=0
fits a transfo to a std::list of Point pairs (p1,p2, the Point fields in StarMatch).
double fit(const StarMatchList &starMatchList)
Not implemented yet, because we do it otherwise.
void dump(std::ostream &stream=std::cout) const
dumps the transfo coefficients to stream.
virtual double getJacobian(const Point &point) const
returns the local jacobian.
void dump(std::ostream &stream) const
dumps the transfo coefficients to stream.
virtual GtransfoLin linearApproximation(const Point &where, const double step=0.01) const
linear approximation.
void apply(const double xIn, const double yIn, double &xOut, double &yOut) const
xOut = xIn; yOut = yIn !
void write(const std::string &fileName) const
std::ostream & operator<<(std::ostream &stream, const Gtransfo >ransfo)
allows 'stream << Transfo;' (by calling gtransfo.dump(stream)).
std::unique_ptr< Gtransfo > clone() const
returns a copy (allocated by new) of the transformation.
Polynomial transformation class.
GtransfoLin normalizeCoordinatesTransfo(const Frame &frame)
Returns the transformation that maps the input frame along both axes to [-1,1].
A Point with uncertainties.
virtual std::unique_ptr< Gtransfo > inverseTransfo(const double precision, const Frame ®ion) const
returns an inverse transfo. Numerical if not overloaded.
void dump(std::ostream &stream) const
dumps the transfo coefficients to stream.
double fit(const StarMatchList &starMatchList)
fits a transfo to a std::list of Point pairs (p1,p2, the Point fields in StarMatch).
void dump(std::ostream &stream) const
dumps the transfo coefficients to stream.
void computeDerivative(const Point &where, GtransfoLin &derivative, const double step=0.01) const
specialised analytic routine
double coeffOrZero(const unsigned powX, const unsigned powY, const unsigned whichCoord) const
read access, zero if beyond degree
GtransfoLin getLinPart() const
The Linear part (corresponding to CD's and CRPIX's)
void apply(const double xIn, const double yIn, double &xOut, double &yOut) const
GtransfoLin()
the default constructor constructs the do-nothing transformation.
bool isIntegerShift(const Gtransfo *gtransfo)
Shorthand test to tell if a transfo is a simple integer shift.
std::unique_ptr< GtransfoPoly > inversePolyTransfo(const Gtransfo &Direct, const Frame &frame, const double Prec)
approximates the inverse by a polynomial, up to required precision.
just here to provide a specialized constructor, and fit.
void write(std::ostream &s) const
std::unique_ptr< Gtransfo > clone() const
returns a copy (allocated by new) of the transformation.
double determinant() const
void read(std::istream &s)
GtransfoLinScale(const double scaleX, const double scaleY)
rectangle with sides parallel to axes.
void apply(const double xIn, const double yIn, double &xOut, double &yOut) const
std::unique_ptr< Gtransfo > inverseTransfo(const double precision, const Frame ®ion) const
Inverse transfo: returns a TanRaDec2Pix if there are no corrections, or the iterative solver if there...
TanRaDec2Pix invert() const
approximate inverse : it ignores corrections;
double fit(const StarMatchList &starMatchList)
guess what
GtransfoPoly operator*(const GtransfoPoly &right) const
Composition (internal stuff in quadruple precision)
GtransfoIdentity()
constructor.
virtual void transformPosAndErrors(const FatPoint &in, FatPoint &out) const
const GtransfoPoly * getCorr() const
the "correction" (non-owning pointer)
std::unique_ptr< Gtransfo > clone() const
returns a copy (allocated by new) of the transformation.
void read(std::istream &s)
TanPix2RaDec operator*(const GtransfoLin &right) const
composition with GtransfoLin
double fit(const StarMatchList &starMatchList)
Not implemented yet, because we do it otherwise.
void apply(const double xIn, const double yIn, double &xOut, double &yOut) const
double fit(const StarMatchList &starMatchList)
fits a transfo to a std::list of Point pairs (p1,p2, the Point fields in StarMatch).
void offsetParams(const double *params)
virtual int getNpar() const
returns the number of parameters (to compute chi2's)
virtual std::unique_ptr< Gtransfo > reduceCompo(const Gtransfo *right) const
to be overloaded by derived classes if they can really "reduce" the composition (e.g.
TanPix2RaDec invert() const
exact typed inverse:
int getNpar() const
total number of parameters
void transformPosAndErrors(const FatPoint &in, FatPoint &out) const
transform with analytical derivatives
virtual void paramDerivatives(const Point &where, double *dx, double *dy) const
Derivative w.r.t parameters.
std::unique_ptr< Gtransfo > reduceCompo(const Gtransfo *right) const
to be overloaded by derived classes if they can really "reduce" the composition (e.g.
void paramDerivatives(const Point &where, double *dx, double *dy) const
Derivative w.r.t parameters.
int getNpar() const
returns the number of parameters (to compute chi2's)
A do-nothing transformation. It anyway has dummy routines to mimick a Gtransfo.
void setTangentPoint(const Point &tangentPoint)
Resets the projection (or tangent) point.
just here to provide a specialized constructor, and fit.
Point apply(const Point &in) const
All these apply(..) shadow the virtual one in derived classes, unless one writes "using Gtransfo::app...
int getNpar() const
total number of parameters
This one is the Tangent Plane (called gnomonic) projection (from celestial sphere to tangent plane) ...
void dump(std::ostream &stream=std::cout) const
print out of coefficients in a readable form.
std::unique_ptr< Gtransfo > reduceCompo(const Gtransfo *right) const
to be overloaded by derived classes if they can really "reduce" the composition (e.g.
double fit(const StarMatchList &starMatchList)
fits a transfo to a std::list of Point pairs (p1,p2, the Point fields in StarMatch).
Point getTangentPoint() const
The tangent point (in degrees)
std::unique_ptr< Gtransfo > roughInverse(const Frame ®ion) const
Overload the "generic routine" (available for all Gtransfo types.
just here to provide specialized constructors. GtransfoLin fit routine.
a virtual (interface) class for geometric transformations.
void transformStar(FatPoint &in) const
allows to write MyTransfo(MyStar)
GtransfoPoly(const unsigned degree=1)
Default transfo : identity for all degrees (>=1 ).
void setDegree(const unsigned degree)
virtual void computeDerivative(const Point &where, GtransfoLin &derivative, const double step=0.01) const
Computes the local Derivative of a transfo, w.r.t.
std::unique_ptr< GtransfoPoly > corr
void getParams(double *params) const
params should be at least Npar() long
void apply(const double xIn, const double yIn, double &xOut, double &yOut) const
void computeDerivative(const Point &where, GtransfoLin &derivative, const double step=0.01) const
Computes the local Derivative of a transfo, w.r.t.
BaseTanWcs(const GtransfoLin &pix2Tan, const Point &tangentPoint, const GtransfoPoly *corrections=nullptr)
void apply(const Point &in, Point &out) const
applies the tranfo to in and writes into out. Is indeed virtual.
double fit(const StarMatchList &starMatchList)
guess what
a run-time transfo that allows users to define a Gtransfo with minimal coding (just the transfo routi...
virtual GtransfoPoly getPix2TangentPlane() const =0
transfo from pix to tangent plane (defined by derived classes)
double paramRef(const int i) const
GtransfoLin invert() const
returns the inverse: T1 = T2.invert();
std::unique_ptr< Gtransfo > gtransfoRead(const std::string &fileName)
The virtual constructor from a file.
std::unique_ptr< Gtransfo > clone() const
returns a copy (allocated by new) of the transformation.
virtual std::unique_ptr< Gtransfo > clone() const =0
returns a copy (allocated by new) of the transformation.
double fit(const StarMatchList &starMatchList)
guess what
virtual void dump(std::ostream &stream=std::cout) const =0
dumps the transfo coefficients to stream.
UserTransfo(GtransfoFun &fun, const void *userData)
the transfo routine and extra data that it may need.
virtual void pix2TP(double xPixel, double yPixel, double &xTangentPlane, double &yTangentPlane) const =0
Transforms from pixel space to tangent plane. deferred to actual implementations. ...
void( GtransfoFun)(const double, const double, double &, double &, const void *)
signature of the user-provided routine that actually does the coordinate transfo for UserTransfo...
std::unique_ptr< Gtransfo > inverseTransfo(const double precision, const Frame ®ion) const
Inverse transfo: returns a TanPix2RaDec.
std::unique_ptr< Gtransfo > reduceCompo(const Gtransfo *right) const
to be overloaded by derived classes if they can really "reduce" the composition (e.g.
virtual void apply(const double xIn, const double yIn, double &xOut, double &yOut) const =0
int getNpar() const
total number of parameters
Point getCrPix() const
the CRPIX values (this is WCS jargon), in 0-based coordinates
virtual double paramRef(const int i) const
void operator=(const BaseTanWcs &original)
std::unique_ptr< Gtransfo > clone() const
returns a copy (allocated by new) of the transformation.