lsst.jointcal  14.0-17-ge3cc87b+12
StarMatch.h
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 #ifndef LSST_JOINTCAL_STAR_MATCH_H
3 #define LSST_JOINTCAL_STAR_MATCH_H
4 
5 #include <iostream>
6 #include <iterator> // for std::ostream_iterator
7 #include <algorithm> // for swap
8 #include <string>
9 #include <list>
10 
11 #include "lsst/jointcal/Point.h"
12 #include "lsst/jointcal/BaseStar.h" // class definition used in inlined functions
13 #include "lsst/jointcal/Gtransfo.h" // inlined function calls Gtransfo::apply()
14 
15 namespace lsst {
16 namespace jointcal {
17 
29 
31 class StarMatch {
32  friend class StarMatchList;
33 
34 public:
35  /* if one sets that private, then fitting routines will be a nightmare. we could set all the Transfo
36  * classes friend... */
40  double distance;
41  double chi2;
42 
44 
46  StarMatch(const FatPoint &point1, const FatPoint &point2, std::shared_ptr<const BaseStar> star1,
48  : point1(point1), point2(point2), s1(std::move(star1)), s2(std::move(star2)), distance(0.){};
49 
50  // the next one would require that StarMatch knows BaseStar which is not mandatory for StarMatch to work
51  // StarMatch(BaseStar *star1, BaseStar *star2) : point1(*star1), point2(*star2), s1(star1), s2(star2) {};
52 
54  double computeDistance(const Gtransfo &gtransfo) const {
55  return point2.Distance(gtransfo.apply(point1));
56  };
57 
59  double computeChi2(const Gtransfo &gtransfo) const;
60 
62  void setDistance(const Gtransfo &gtransfo) { distance = computeDistance(gtransfo); };
64  double getDistance() const { return distance; }
65 
66  void swap() {
67  std::swap(point1, point2);
68  std::swap(s1, s2);
69  }
70 
71  /* comparison that ensures that after a sort, duplicates are next one another */
72  explicit StarMatch(){};
73 
74  friend std::ostream &operator<<(std::ostream &stream, const StarMatch &Match);
75 
77 
78 private:
79  // bool operator < (const StarMatch & other) const { return (s1 > other.s1) ? s1 > other.s1 : s2 >
80  // other.s2;}
81 
82  /* for unique to remove duplicates */
83  bool operator==(const StarMatch &other) const { return (s1 == other.s1 && s2 == other.s2); };
84  bool operator!=(const StarMatch &other) const { return (s1 != other.s1 || s2 != other.s2); };
85 
86  friend bool compareStar1(const StarMatch &one, const StarMatch &two);
87  friend bool sameStar1(const StarMatch &one, const StarMatch &two);
88  friend bool compareStar2(const StarMatch &one, const StarMatch &two);
89  friend bool sameStar2(const StarMatch &one, const StarMatch &two);
90 };
91 
92 inline bool compareStar1(const StarMatch &one, const StarMatch &two) {
93  return ((one.s1 == two.s1) ? (one.distance < two.distance) : (&(*one.s1) > &(*two.s1)));
94 }
95 
96 inline bool sameStar1(const StarMatch &one, const StarMatch &two) { return (one.s1 == two.s1); }
97 
98 inline bool compareStar2(const StarMatch &one, const StarMatch &two) {
99  return ((one.s2 == two.s2) ? (one.distance < two.distance) : (&(*one.s2) > &(*two.s2)));
100 }
101 
102 inline bool sameStar2(const StarMatch &one, const StarMatch &two) { return (one.s2 == two.s2); }
103 
104 /* =================================== StarMatchList
105  * ============================================================ */
106 
107 std::ostream &operator<<(std::ostream &stream, const StarMatch &match);
108 
109 //#ifdef TO_BE_FIXED
110 typedef ::std::list<StarMatch>::iterator StarMatchIterator;
111 typedef ::std::list<StarMatch>::const_iterator StarMatchCIterator;
112 //#endif
113 
115 
124 std::ostream &operator<<(std::ostream &stream, const StarMatchList &starMatchList);
125 
126 class StarMatchList : public std::list<StarMatch> {
127 public:
128  void refineTransfo(double nSigmas);
129 
132  void applyTransfo(StarMatchList &transformed, const Gtransfo *priorTransfo,
133  const Gtransfo *posteriorTransfo = nullptr) const;
134 
135  /* constructor */
136  StarMatchList() : _order(0), _chi2(0){};
137 
139 
141  std::shared_ptr<const Gtransfo> getTransfo() const { return _transfo; }
142 
144  double getDist2() const { return _dist2; }
145 
147  double getChi2() const { return _chi2; }
148 
150  int getTransfoOrder() const { return _order; }
151 
153  void swap();
154 
156  double computeResidual() const;
157 
161  unsigned removeAmbiguities(const Gtransfo &gtransfo, int which = 3);
162 
164  void setTransfo(const Gtransfo *gtransfo) { _transfo = gtransfo->clone(); }
166  void setTransfo(const Gtransfo &gtransfo) { _transfo = gtransfo.clone(); }
167  void setTransfo(std::shared_ptr<Gtransfo> gtransfo) { _transfo = std::move(gtransfo); }
168 
170  void setTransfoOrder(int order);
171 
174  std::unique_ptr<Gtransfo> inverseTransfo();
175 
177  void setDistance(const Gtransfo &gtransfo);
178 
180  void cutTail(int nKeep);
181 
183  int recoveredNumber(double mindist) const;
184 
186  void dumpTransfo(std::ostream &stream = std::cout) const;
187 
188  ~StarMatchList(){/* should delete the transfo.... or use counted refs*/};
189 
190 private:
191  StarMatchList(const StarMatchList &); // copies nor properly handled
192  void operator=(const StarMatchList &);
193 
194  int _order;
195  double _chi2;
196  double _dist2;
197  std::shared_ptr<Gtransfo> _transfo;
198 };
199 
201 double computeDist2(const StarMatchList &S, const Gtransfo &gtransfo);
202 
204 double computeChi2(const StarMatchList &L, const Gtransfo &gtransfo);
205 } // namespace jointcal
206 } // namespace lsst
207 
208 #endif // LSST_JOINTCAL_STAR_MATCH_H
CitizenInit one
A hanger for star associations.
Definition: StarMatch.h:31
T swap(T... args)
friend class StarMatchList
Definition: StarMatch.h:32
FatPoint point2
2 points
Definition: StarMatch.h:37
double computeChi2(const Gtransfo &gtransfo) const
returns the chi2 (using errors in the FatPoint&#39;s)
Definition: StarMatch.cc:20
void setTransfo(std::shared_ptr< Gtransfo > gtransfo)
Definition: StarMatch.h:167
STL namespace.
double computeDistance(const Gtransfo &gtransfo) const
returns the distance from gtransfo(point1) to point2.
Definition: StarMatch.h:54
double Distance(const Point &other) const
Definition: Point.h:27
A Point with uncertainties.
Definition: FatPoint.h:11
void setDistance(const Gtransfo &gtransfo)
to be used before sorting on distances.
Definition: StarMatch.h:62
double getDist2() const
access to the sum of squared residuals of the last call to refineTransfo.
Definition: StarMatch.h:144
double getChi2() const
access to the chi2 of the last call to refineTransfo.
Definition: StarMatch.h:147
std::shared_ptr< const Gtransfo > getTransfo() const
carries out a fit with outlier rejection
Definition: StarMatch.h:141
Class for a simple mapping implementing a generic Gtransfo.
int getTransfoOrder() const
returns the order of the used transfo
Definition: StarMatch.h:150
::std::list< StarMatch >::const_iterator StarMatchCIterator
Definition: StarMatch.h:111
friend bool sameStar2(const StarMatch &one, const StarMatch &two)
Definition: StarMatch.h:102
StarMatch(const FatPoint &point1, const FatPoint &point2, std::shared_ptr< const BaseStar > star1, std::shared_ptr< const BaseStar > star2)
constructor.
Definition: StarMatch.h:46
friend bool sameStar1(const StarMatch &one, const StarMatch &two)
Definition: StarMatch.h:96
::std::list< StarMatch >::iterator StarMatchIterator
Definition: StarMatch.h:110
STL class.
T move(T... args)
friend bool compareStar2(const StarMatch &one, const StarMatch &two)
Definition: StarMatch.h:98
void setTransfo(const Gtransfo *gtransfo)
sets a transfo between the 2 std::lists and deletes the previous or default one. No fit...
Definition: StarMatch.h:164
STL class.
friend std::ostream & operator<<(std::ostream &stream, const StarMatch &Match)
Definition: StarMatch.cc:32
double computeDist2(const StarMatchList &S, const Gtransfo &gtransfo)
sum of distance squared
Definition: StarMatch.cc:212
a virtual (interface) class for geometric transformations.
Definition: Gtransfo.h:39
std::shared_ptr< const BaseStar > s2
Definition: StarMatch.h:39
std::shared_ptr< const BaseStar > s1
Definition: StarMatch.h:39
Frame applyTransfo(const Frame &inputframe, const Gtransfo &gtransfo, const WhichTransformed which)
Transform a Frame through a Transfo.
Definition: AstroUtils.cc:15
friend bool compareStar1(const StarMatch &one, const StarMatch &two)
Definition: StarMatch.h:92
void setTransfo(const Gtransfo &gtransfo)
Definition: StarMatch.h:166
virtual std::unique_ptr< Gtransfo > clone() const =0
returns a copy (allocated by new) of the transformation.
STL class.
virtual void apply(const double xIn, const double yIn, double &xOut, double &yOut) const =0
double getDistance() const
returns the value computed by the above one.
Definition: StarMatch.h:64