LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
LSSTDataManagementBasePackage
Match.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 #ifndef LSST_AFW_TABLE_MATCH_H
26 #define LSST_AFW_TABLE_MATCH_H
27 
28 #include <vector>
29 
30 #include "lsst/pex/config.h"
31 #include "lsst/afw/table/fwd.h"
33 #include "lsst/afw/table/Simple.h"
34 #include "lsst/afw/table/Source.h"
35 #include "lsst/afw/table/Catalog.h"
36 #include "lsst/afw/geom/Angle.h"
37 
38 namespace lsst { namespace afw { namespace table {
39 
44 class MatchControl {
45 public:
47  : findOnlyClosest(true),
48  symmetricMatch(true),
49  includeMismatches(false)
50  { }
51  LSST_CONTROL_FIELD(findOnlyClosest, bool, "Return only the closest match if more than one is found " \
52  "(default: true)");
53  LSST_CONTROL_FIELD(symmetricMatch, bool, "Produce symmetric matches (default: true):\n" \
54  "i.e. if (s1, s2, d) is reported, then so is (s2, s1, d)");
55  LSST_CONTROL_FIELD(includeMismatches, bool, "Include failed matches (i.e. one 'match' is NULL) " \
56  "(default: false)");
57 };
58 
66 template <typename Record1, typename Record2>
67 struct Match {
68  PTR(Record1) first;
69  PTR(Record2) second;
70  double distance; // may be pixels or radians
71 
72  Match() : first(), second(), distance(0.0) {}
73 
74  Match(PTR(Record1) const & r1, PTR(Record2) const & r2, double dist)
75  : first(r1), second(r2), distance(dist) {}
76 
77  template <typename R1, typename R2>
78  Match(Match<R1,R2> const & other) : first(other.first), second(other.second), distance(other.distance) {}
79 
80 };
81 
82 typedef Match<SimpleRecord,SimpleRecord> SimpleMatch;
83 typedef Match<SimpleRecord,SourceRecord> ReferenceMatch;
84 typedef Match<SourceRecord,SourceRecord> SourceMatch;
85 
86 typedef std::vector<SimpleMatch> SimpleMatchVector;
87 typedef std::vector<ReferenceMatch> ReferenceMatchVector;
88 typedef std::vector<SourceMatch> SourceMatchVector;
89 
97  SourceCatalog const &cat1,
98  SourceCatalog const &cat2,
99  double radius,
100  MatchControl const& mc=MatchControl()
101 );
102 
109  SourceCatalog const &cat,
110  double radius,
111  MatchControl const& mc=MatchControl()
112 );
113 
128  SourceCatalog const &cat1,
129  SourceCatalog const &cat2,
130  double radius,
131  bool closest
132 );
133 
146 SourceMatchVector matchXy(SourceCatalog const &cat, double radius, bool symmetric);
147 
148 #ifndef SWIG // swig will be confused by the nested names below; repeated with typedefs in match.i
149 
150 /************************************************************************************************************/
159 template <typename Cat1, typename Cat2>
160 std::vector< Match< typename Cat1::Record, typename Cat2::Record> > matchRaDec(
161  Cat1 const & cat1,
162  Cat2 const & cat2,
163  Angle radius,
164  MatchControl const& mc=MatchControl()
165 );
166 
167 /*
168  * Compute all tuples (s1,s2,d) where s1 != s2, s1 and s2 both belong to @a cat,
169  * and d, the distance between s1 and s2, is at most @a radius. The
170  * match is performed in ra, dec space.
171  *
172  * This is instantiated for Simple and Source catalogs.
173  */
174 template <typename Cat>
175 std::vector< Match< typename Cat::Record, typename Cat::Record> > matchRaDec(
176  Cat const & cat,
177  Angle radius,
178  MatchControl const& mc=MatchControl()
179 );
180 
181 /************************************************************************************************************/
197 template <typename Cat1, typename Cat2>
198 std::vector< Match< typename Cat1::Record, typename Cat2::Record> > matchRaDec(
199  Cat1 const & cat1,
200  Cat2 const & cat2,
201  Angle radius, bool closest
202 );
203 
204 /*
205  * Compute all tuples (s1,s2,d) where s1 != s2, s1 and s2 both belong to @a cat,
206  * and d, the distance between s1 and s2, is at most @a radius. The
207  * match is performed in ra, dec space.
208  *
209  * @deprecated. Use the matchRaDec(..., MatchControl) version
210  *
211  * @param[in] cat the catalog to self-match
212  * @param[in] radius match radius
213  * @param[in] symmetric if cat to @c true symmetric matches are produced: i.e.
214  * if (s1, s2, d) is reported, then so is (s2, s1, d).
215  * @param[in] key key used to extract the center
216  *
217  * This is instantiated for Simple and Source catalogs.
218  */
219 template <typename Cat>
220 std::vector< Match< typename Cat::Record, typename Cat::Record> > matchRaDec(
221  Cat const & cat,
222  Angle radius,
223  bool symmetric
224 );
225 
234 template <typename Record1, typename Record2>
235 BaseCatalog packMatches(std::vector< Match<Record1,Record2> > const & matches);
236 
256 template <typename Cat1, typename Cat2>
257 std::vector< Match< typename Cat1::Record, typename Cat2::Record> >
258 unpackMatches(BaseCatalog const & matches, Cat1 const & cat1, Cat2 const & cat2);
259 
260 #endif // !SWIG
261 
262 }}} // namespace lsst::afw::table
263 
264 #endif // #ifndef LSST_AFW_TABLE_MATCH_H
Match(Match< R1, R2 > const &other)
Definition: Match.h:78
CatalogT< BaseRecord > BaseCatalog
Definition: fwd.h:61
Match< SimpleRecord, SimpleRecord > SimpleMatch
Definition: fwd.h:90
std::vector< ReferenceMatch > ReferenceMatchVector
Definition: fwd.h:97
bool findOnlyClosest
&quot;Return only the closest match if more than one is found &quot; \ &quot;(default: true)&quot; ;
Definition: Match.h:52
Forward declarations and typedefs for afw::table.
#define LSST_CONTROL_FIELD(NAME, TYPE, DOC)
A preprocessor macro used to define fields in C++ &quot;control object&quot; structs.
Definition: config.h:36
boost::shared_ptr< Record2 > second
Definition: Match.h:69
Pass parameters to algorithms that match list of sources.
Definition: Match.h:44
Lightweight representation of a geometric match between two records.
Definition: fwd.h:90
std::vector< SimpleMatch > SimpleMatchVector
Definition: fwd.h:96
std::vector< Match< typename Cat1::Record, typename Cat2::Record > > matchRaDec(Cat1 const &cat1, Cat2 const &cat2, Angle radius, MatchControl const &mc=MatchControl())
Compute all tuples (s1,s2,d) where s1 belings to cat1, s2 belongs to cat2 and d, the distance between...
Match< SimpleRecord, SourceRecord > ReferenceMatch
Definition: fwd.h:93
BaseCatalog packMatches(std::vector< Match< Record1, Record2 > > const &matches)
Return a table representation of a MatchVector that can be used to persist it.
lsst::afw::geom::Angle Angle
Definition: misc.h:38
#define PTR(...)
Definition: base.h:41
SourceMatchVector matchXy(SourceCatalog const &cat1, SourceCatalog const &cat2, double radius, MatchControl const &mc=MatchControl())
Compute all tuples (s1,s2,d) where s1 belings to cat1, s2 belongs to cat2 and d, the distance between...
boost::shared_ptr< Record1 > first
Definition: Match.h:68
Match(boost::shared_ptr< Record1 > const &r1, boost::shared_ptr< Record2 > const &r2, double dist)
Definition: Match.h:74
bool includeMismatches
&quot;Include failed matches (i.e. one &#39;match&#39; is NULL) &quot; \ &quot;(default: false)&quot; ;
Definition: Match.h:56
bool symmetricMatch
&quot;Produce symmetric matches (default: true):\n&quot; \ &quot;i.e. if (s1, s2, d) is reported, then so is (s2, s1, d)&quot; ;
Definition: Match.h:54
Match< SourceRecord, SourceRecord > SourceMatch
Definition: fwd.h:94
std::vector< Match< typename Cat1::Record, typename Cat2::Record > > unpackMatches(BaseCatalog const &matches, Cat1 const &cat1, Cat2 const &cat2)
Reconstruct a MatchVector from a BaseCatalog representation of the matches and a pair of catalogs...
std::vector< SourceMatch > SourceMatchVector
Definition: fwd.h:98
SortedCatalogT< SourceRecord > SourceCatalog
Definition: fwd.h:75