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
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/afw/table/fwd.h"
32 #include "lsst/afw/table/Simple.h"
33 #include "lsst/afw/table/Source.h"
34 #include "lsst/afw/table/Catalog.h"
35 #include "lsst/afw/geom/Angle.h"
36 
37 namespace lsst { namespace afw { namespace table {
38 
46 template <typename Record1, typename Record2>
47 struct Match {
48  PTR(Record1) first;
49  PTR(Record2) second;
50  double distance; // may be pixels or radians
51 
52  Match() : first(), second(), distance(0.0) {}
53 
54  Match(PTR(Record1) const & r1, PTR(Record2) const & r2, double dist)
55  : first(r1), second(r2), distance(dist) {}
56 
57  template <typename R1, typename R2>
58  Match(Match<R1,R2> const & other) : first(other.first), second(other.second), distance(other.distance) {}
59 
60 };
61 
62 typedef Match<SimpleRecord,SimpleRecord> SimpleMatch;
63 typedef Match<SimpleRecord,SourceRecord> ReferenceMatch;
64 typedef Match<SourceRecord,SourceRecord> SourceMatch;
65 
66 typedef std::vector<SimpleMatch> SimpleMatchVector;
67 typedef std::vector<ReferenceMatch> ReferenceMatchVector;
68 typedef std::vector<SourceMatch> SourceMatchVector;
69 
82  SourceCatalog const &cat1, SourceCatalog const &cat2,
83  double radius, bool closest=true
84 );
85 
96 SourceMatchVector matchXy(SourceCatalog const &cat, double radius, bool symmetric = true);
97 
98 #ifndef SWIG // swig will be confused by the nested names below; repeated with typedefs in match.i
99 
113 template <typename Cat1, typename Cat2>
114 std::vector< Match< typename Cat1::Record, typename Cat2::Record> > matchRaDec(
115  Cat1 const & cat1,
116  Cat2 const & cat2,
117  Angle radius, bool closest = true
118 );
119 
120 /*
121  * Compute all tuples (s1,s2,d) where s1 != s2, s1 and s2 both belong to @a cat,
122  * and d, the distance between s1 and s2, is at most @a radius. The
123  * match is performed in ra, dec space.
124  *
125  * @param[in] cat the catalog to self-match
126  * @param[in] radius match radius
127  * @param[in] symmetric if cat to @c true symmetric matches are produced: i.e.
128  * if (s1, s2, d) is reported, then so is (s2, s1, d).
129  * @param[in] key key used to extract the center
130  *
131  * This is instantiated for Simple and Source catalogs.
132  */
133 template <typename Cat>
134 std::vector< Match< typename Cat::Record, typename Cat::Record> > matchRaDec(
135  Cat const & cat,
136  Angle radius,
137  bool symmetric = true
138 );
139 
148 template <typename Record1, typename Record2>
149 BaseCatalog packMatches(std::vector< Match<Record1,Record2> > const & matches);
150 
170 template <typename Cat1, typename Cat2>
171 std::vector< Match< typename Cat1::Record, typename Cat2::Record> >
172 unpackMatches(BaseCatalog const & matches, Cat1 const & cat1, Cat2 const & cat2);
173 
174 #endif // !SWIG
175 
176 }}} // namespace lsst::afw::table
177 
178 #endif // #ifndef LSST_AFW_TABLE_MATCH_H
lsst::afw::geom::Angle Angle
Definition: misc.h:39
boost::shared_ptr< Record1 > first
Definition: Match.h:48
boost::shared_ptr< Record2 > second
Definition: Match.h:49
CatalogT< BaseRecord > BaseCatalog
Definition: fwd.h:61
SourceMatchVector matchXy(SourceCatalog const &cat1, SourceCatalog const &cat2, double radius, bool closest=true)
Match< SimpleRecord, SimpleRecord > SimpleMatch
Definition: fwd.h:90
#define PTR(...)
Definition: base.h:41
std::vector< ReferenceMatch > ReferenceMatchVector
Definition: fwd.h:97
Match(Match< R1, R2 > const &other)
Definition: Match.h:58
std::vector< Match< typename Cat1::Record, typename Cat2::Record > > matchRaDec(Cat1 const &cat1, Cat2 const &cat2, Angle radius, bool closest=true)
Lightweight representation of a geometric match between two records.
Definition: fwd.h:90
std::vector< SimpleMatch > SimpleMatchVector
Definition: fwd.h:96
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.
SortedCatalogT< SourceRecord > SourceCatalog
Definition: fwd.h:75
Match< SourceRecord, SourceRecord > SourceMatch
Definition: fwd.h:94
Match(boost::shared_ptr< Record1 > const &r1, boost::shared_ptr< Record2 > const &r2, double dist)
Definition: Match.h:54
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