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
SweepStructure.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_MATCH_DETAIL_SWEEPSTRUCTURE_H
32 #define LSST_AP_MATCH_DETAIL_SWEEPSTRUCTURE_H
33 
34 #include <vector>
35 
36 #include "../BBox.h"
37 #include "../../utils/Arena.h"
38 
39 
40 namespace lsst { namespace ap { namespace match { namespace detail {
41 
42 // -- Interval tree nodes ----
43 
46 enum Color {
47  BLACK = 0, RED
48 };
49 
52 struct CartesianNode {
55  double reach;
56  double minCoord0;
57  double maxCoord0;
59 
60  inline CartesianNode();
61  inline CartesianNode(BBox *b);
62  inline ~CartesianNode();
63 };
64 
65 inline bool lessThan(CartesianNode const *left, CartesianNode const *right);
66 
67 inline bool operator<(std::pair<double, CartesianNode *> const &left,
68  std::pair<double, CartesianNode *> const &right);
69 
70 
74 struct SphericalNode {
77  unsigned int foundBy;
78  double reach;
79  double minCoord0;
80  double maxCoord0;
83 
84  inline SphericalNode();
85  inline SphericalNode(BBox *b, double minC0, double maxC0);
86  inline ~SphericalNode();
87 
88  inline bool markFound(unsigned int searchId);
89 };
90 
91 inline bool lessThan(SphericalNode const *left, SphericalNode const *right);
92 
93 inline bool operator<(std::pair<double, SphericalNode *> const &left,
94  std::pair<double, SphericalNode *> const &right);
95 
96 
97 // -- Sweep structures ----
98 
101 template <typename Node>
103 public:
104  SweepStructure() : _arena(), _root(0), _heap() { }
105  virtual ~SweepStructure();
106 
107  inline size_t size() const;
108  inline bool empty() const;
109  inline size_t getNumBytes() const;
110 
111  virtual bool isValid() const;
112 
113 protected:
114  typedef std::pair<double, Node *> HeapEntry;
115 
116  void _insert(Node *i);
117  void _insert(BBox *b);
118  void _remove(Node *n);
119  void _grow(typename std::vector<HeapEntry>::size_type n);
120 
122  Node *_root;
123  std::vector<HeapEntry> _heap;
124 
125 private:
126  // Disable copy construction and assignment
129 
130  // Low-level implementation
131  static inline double _reach(Node const *n);
132  inline Node * _rotate(Node *n, int dir);
133  inline Node * _doubleRotate(Node *n, int dir);
134 
135  // Invariant checks
136  static bool _isBinarySearchTree(Node const *n);
137  static bool _isRedChildBlack(Node const *n);
138  static bool _isBalanced(Node const *n, int numBlack);
139  static double _checkReach(Node const *n);
140  bool _isBalanced() const;
141  bool _isIntervalTree() const;
142 };
143 
144 
179 template <typename Region>
180 class CartesianSweep : public SweepStructure<CartesianNode> {
181 public:
183  virtual ~CartesianSweep() { }
184 
185  inline void insert(Region *region);
186 
187  template <typename RegionProcessor>
188  void advance(double to, RegionProcessor &f);
189 
190  template <typename RegionProcessor>
191  void clear(RegionProcessor &f);
192 
193  template <typename OtherRegion, typename MatchProcessor>
194  void search(OtherRegion *r, MatchProcessor &f);
195 };
196 
197 
264 template <typename Region>
265 class SphericalSweep : public SweepStructure<SphericalNode> {
266 public:
268  virtual ~SphericalSweep() { }
269 
270  inline void insert(Region *region);
271 
272  template <typename RegionProcessor>
273  void advance(double to, RegionProcessor &f);
274 
275  template <typename RegionProcessor>
276  void clear(RegionProcessor &f);
277 
278  template <typename OtherRegion, typename MatchProcessor>
279  void search(OtherRegion *r, MatchProcessor &f);
280 
281  virtual bool isValid() const;
282 
283  void setSearchId(unsigned int searchId);
284 
285 private:
286  template <typename OtherRegion, typename MatchProcessor>
287  void _search(OtherRegion *r, MatchProcessor &f, double min, double max);
288 
289  unsigned int _searchId;
290 };
292 
293 }}}} // namespace lsst::ap::match::detail
294 
295 
296 #include "SweepStructure.cc"
297 
298 #endif // LSST_AP_MATCH_DETAIL_SWEEPSTRUCTURE_H
299 
SweepStructure & operator=(SweepStructure const &)
static bool _isBinarySearchTree(Node const *n)
void search(OtherRegion *r, MatchProcessor &f)
static bool _isRedChildBlack(Node const *n)
void advance(double to, RegionProcessor &f)
void _search(OtherRegion *r, MatchProcessor &f, double min, double max)
void search(OtherRegion *r, MatchProcessor &f)
std::pair< double, Node * > HeapEntry
Node * _doubleRotate(Node *n, int dir)
lsst::ap::utils::Arena< Node > _arena
void advance(double to, RegionProcessor &f)
double min
Definition: attributes.cc:216
static double _reach(Node const *n)
double max
Definition: attributes.cc:218
bool markFound(unsigned int searchId)
std::vector< HeapEntry > _heap
Min-heap on maximum coordinate-1 value.
bool lessThan(CartesianNode const *a, CartesianNode const *b)
void setSearchId(unsigned int searchId)
Node * _root
Root of the interval tree.
void _grow(typename std::vector< HeapEntry >::size_type n)
static double _checkReach(Node const *n)
afw::table::Key< double > b
Inline/templated sweep-line data structure method implementations.