LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
LSSTDataManagementBasePackage
KDTree.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 
31 #ifndef LSST_AP_CLUSTER_DETAIL_KDTREE_H
32 #define LSST_AP_CLUSTER_DETAIL_KDTREE_H
33 
34 #include <limits>
35 
36 #include "boost/scoped_array.hpp"
37 
38 #include "Eigen/Core"
39 
40 
41 namespace lsst { namespace ap { namespace cluster { namespace detail {
42 
51 struct KDTreeNode {
52  double split;
53  int splitDim;
54  int right;
55 
57  split(std::numeric_limits<double>::quiet_NaN()),
58  splitDim(-1),
59  right(-1)
60  { }
61 };
62 
63 
81 template <int K, typename DataT>
82 struct Point {
83  static int const PROCESSED = -2;
84  static int const UNPROCESSED = -1;
85 
86  Eigen::Matrix<double, K, 1> coords;
87  double dist;
88  double reach;
89  DataT data;
90  int next;
91  int state;
92 
93  Point() :
94  coords(),
95  dist(std::numeric_limits<double>::quiet_NaN()),
96  reach(std::numeric_limits<double>::infinity()),
97  data(),
98  next(-1),
100  { }
101 
102  ~Point() { }
103 };
104 
105 
132 template <int K, typename DataT>
133 class KDTree {
134 public:
135  typedef Eigen::Matrix<double, K, 1> Vector;
136 
137  static int const MAX_HEIGHT = 30;
138 
139  KDTree(Point<K, DataT> * points,
140  int numPoints,
141  int pointsPerLeaf,
142  double leafExtentThreshold);
143  ~KDTree();
144 
145  int size() const {
146  return _numPoints;
147  }
148  int height() const {
149  return _height;
150  }
151  Point<K, DataT> const * getPoints() const {
152  return _points;
153  }
154 
155  template <typename MetricT>
156  int inRange(Vector const & v, double const distance, MetricT const & metric);
157 
158 private:
161  int _height;
162  boost::scoped_array<KDTreeNode> _nodes;
163 
164  void build(double leafExtentThreshold);
165 };
166 
167 }}}} // namespace lsst::ap::cluster::detail
168 
169 #endif // LSST_AP_CLUSTER_DETAIL_KDTREE_H
double reach
Reachability distance (for OPTICS).
Definition: KDTree.h:88
int right
Index of first entry to the right of the split.
Definition: KDTree.h:54
double split
Splitting value.
Definition: KDTree.h:52
static int const UNPROCESSED
Definition: KDTree.h:84
std::vector< SourceCatalog > const cluster(SourceCatalog const &sources, ClusteringControl const &control)
Definition: clustering.cc:578
boost::scoped_array< KDTreeNode > _nodes
Definition: KDTree.h:162
static int const PROCESSED
Definition: KDTree.h:83
Point< K, DataT > * _points
Definition: KDTree.h:159
Eigen::Matrix< double, K, 1 > coords
Point coordinates.
Definition: KDTree.h:86
int next
Index of next range query result or -1.
Definition: KDTree.h:90
int splitDim
Dimension of splitting value, -1 for leaf nodes.
Definition: KDTree.h:53
int state
State of point ([un]processed or index in seed list)
Definition: KDTree.h:91
int inRange(Vector const &v, double const distance, MetricT const &metric)
Definition: KDTree.cc:168
KDTree(Point< K, DataT > *points, int numPoints, int pointsPerLeaf, double leafExtentThreshold)
Definition: KDTree.cc:115
Point< K, DataT > const * getPoints() const
Definition: KDTree.h:151
void build(double leafExtentThreshold)
Definition: KDTree.cc:243
Eigen::Matrix< double, K, 1 > Vector
Definition: KDTree.h:135
static int const MAX_HEIGHT
Maximum tree height.
Definition: KDTree.h:137
DataT data
Data object.
Definition: KDTree.h:89
double dist
Distance to query point.
Definition: KDTree.h:87