31 #ifndef LSST_AP_MATCH_DETAIL_SWEEPSTRUCTURE_CC
32 #define LSST_AP_MATCH_DETAIL_SWEEPSTRUCTURE_CC
42 #include "../../utils/SpatialUtils.h"
45 namespace lsst {
namespace ap {
namespace match {
namespace detail {
67 reach(b->getMaxCoord0()),
68 minCoord0(b->getMinCoord0()),
92 inline bool operator<(std::pair<double, CartesianNode *>
const &n1,
93 std::pair<double, CartesianNode *>
const &n2)
95 return n1.first > n2.first;
161 inline bool operator<(std::pair<double, SphericalNode *>
const &left,
162 std::pair<double, SphericalNode *>
const &right)
164 return left.first > right.first;
172 template <
typename Node>
179 template <
typename Node>
187 template <
typename Node>
196 template <
typename Node>
198 double reach = n->maxCoord0;
199 Node
const *c0 = n->link[0];
200 if (c0 != 0 && c0->reach > reach) {
203 Node
const *c1 = n->link[1];
204 if (c1 != 0 && c1->reach > reach) {
212 template <
typename Node>
214 Node *r = n->link[!dir];
215 n->link[!dir] = r->link[dir];
220 n->reach = _reach(n);
226 template <
typename Node>
228 n->link[!dir] = _rotate(n->link[!dir], !dir);
229 return _rotate(n, dir);
237 template <
typename Region>
250 template <
typename Region>
251 template <
typename RegionProcessor>
256 while (!
_heap.empty() &&
_heap.front().first < to) {
261 f(dynamic_cast<Region *>(n->bbox));
274 template <
typename Region>
275 template <
typename RegionProcessor>
277 typedef std::vector<HeapEntry>::iterator Iter;
278 for (Iter i =
_heap.begin(), e =
_heap.end(); i != e; ++i) {
280 f(dynamic_cast<Region *>(n->
bbox));
298 template <
typename Region>
299 template <
typename OtherRegion,
typename MatchProcessor>
305 int dir[2*
sizeof(size_t)*CHAR_BIT];
310 double const min = r->getMinCoord0();
311 double const max = r->getMaxCoord0();
315 if (n->reach >= min) {
316 if (n->minCoord0 <= max && n->maxCoord0 >= min) {
317 f(r, dynamic_cast<Region *>(n->bbox));
319 if (n->link[0] != 0) {
325 }
else if (n->link[1] != 0) {
333 for (--s; s >= 0 && (dir[s] == 1 || node[s]->link[1] == 0); --s) { }
334 if (s < 0 || node[s]->minCoord0 > max) {
338 n = node[s]->link[1];
349 template <
typename Region>
363 template <
typename Region>
364 template <
typename RegionProcessor>
369 while (!
_heap.empty() &&
_heap.front().first < to) {
379 f(dynamic_cast<Region *>(n->bbox));
393 template <
typename Region>
394 template <
typename RegionProcessor>
396 typedef std::vector<HeapEntry>::iterator Iter;
397 for (Iter i =
_heap.begin(), e =
_heap.end(); i != e; ++i) {
404 f(dynamic_cast<Region *>(n->
bbox));
424 template <
typename Region>
425 template <
typename OtherRegion,
typename MatchProcessor>
441 _search(r, f, 0.0, static_cast<double>(max));
444 _search(r, f, static_cast<double>(min), static_cast<double>(max));
446 if (_searchId == 0) {
452 typedef std::vector<HeapEntry>::iterator Iter;
453 for (Iter i =
_heap.begin(), e =
_heap.end(); i != e; ++i) {
454 i->second->foundBy = 0;
460 template <
typename Region>
467 typedef std::vector<HeapEntry>::const_iterator Iter;
468 for (Iter i =
_heap.begin(), e =
_heap.end(); i != e; ++i) {
469 if (i->second->foundBy >= _searchId) {
480 template <
typename Region>
482 typedef std::vector<HeapEntry>::iterator Iter;
487 if (searchId < _searchId) {
489 for (Iter i =
_heap.begin(), e =
_heap.end(); i != e; ++i) {
490 i->second->foundBy = 0;
493 _searchId = searchId;
499 template <
typename Region>
500 template <
typename OtherRegion,
typename MatchProcessor>
508 int dir[2*
sizeof(size_t)*CHAR_BIT];
513 if (n->
reach >= min) {
518 f(r, dynamic_cast<Region *>(n->
bbox));
521 if (n->
link[0] != 0) {
527 }
else if (n->
link[1] != 0) {
535 for (--s; s >= 0 && (dir[s] == 1 || node[s]->link[1] == 0); --s) { }
536 if (s < 0 || node[s]->minCoord0 > max) {
540 n = node[s]->
link[1];
548 #endif // LSST_AP_MATCH_DETAIL_SWEEPSTRUCTURE_CC
An include file to include the public header files for lsst::afw::math.
lsst::afw::geom::Angle Angle
void search(OtherRegion *r, MatchProcessor &f)
void advance(double to, RegionProcessor &f)
void _search(OtherRegion *r, MatchProcessor &f, double min, double max)
void search(OtherRegion *r, MatchProcessor &f)
void clear(RegionProcessor &f)
virtual bool isValid() const
std::pair< double, Node * > HeapEntry
Node * _doubleRotate(Node *n, int dir)
void advance(double to, RegionProcessor &f)
Node * _rotate(Node *n, int dir)
static double _reach(Node const *n)
size_t getNumBytes() const
Include files required for standard LSST Exception handling.
AngleUnit const radians
constant with units of radians
bool markFound(unsigned int searchId)
void insert(Region *region)
void insert(Region *region)
bool lessThan(CartesianNode const *a, CartesianNode const *b)
void setSearchId(unsigned int searchId)
void clear(RegionProcessor &f)
std::vector< std::pair< Angle, Ref * > > _heap
Arena< MatchablePos > _arena
afw::table::Key< double > b
Sweep line data structures useful for region-region matching.
void thetaRangeReduce(Angle &min, Angle &max)