Project

General

Profile

Statistics
| Branch: | Revision:

root / rgbdslam / gicp / ann_1.1.1 / include / ANN / ANNx.h @ 9240aaa3

History | View | Annotate | Download (6.09 KB)

1 9240aaa3 Alex
//----------------------------------------------------------------------
2
//        File:                        ANNx.h
3
//        Programmer:         Sunil Arya and David Mount
4
//        Last modified:        03/04/98 (Release 0.1)
5
//        Description:        Internal include file for ANN
6
//
7
//        These declarations are of use in manipulating some of
8
//        the internal data objects appearing in ANN, but are not
9
//        needed for applications just using the nearest neighbor
10
//        search.
11
//
12
//        Typical users of ANN should not need to access this file.
13
//----------------------------------------------------------------------
14
// Copyright (c) 1997-2005 University of Maryland and Sunil Arya and
15
// David Mount.  All Rights Reserved.
16
// 
17
// This software and related documentation is part of the Approximate
18
// Nearest Neighbor Library (ANN).  This software is provided under
19
// the provisions of the Lesser GNU Public License (LGPL).  See the
20
// file ../ReadMe.txt for further information.
21
// 
22
// The University of Maryland (U.M.) and the authors make no
23
// representations about the suitability or fitness of this software for
24
// any purpose.  It is provided "as is" without express or implied
25
// warranty.
26
//----------------------------------------------------------------------
27
//        History:
28
//        Revision 0.1  03/04/98
29
//            Initial release
30
//        Revision 1.0  04/01/05
31
//            Changed LO, HI, IN, OUT to ANN_LO, ANN_HI, etc.
32
//----------------------------------------------------------------------
33
34
#ifndef ANNx_H
35
#define ANNx_H
36
37
#include <iomanip>                                // I/O manipulators
38
#include <ANN/ANN.h>                        // ANN includes
39
40
//----------------------------------------------------------------------
41
//        Global constants and types
42
//----------------------------------------------------------------------
43
enum        {ANN_LO=0, ANN_HI=1};        // splitting indices
44
enum        {ANN_IN=0, ANN_OUT=1};        // shrinking indices
45
                                                                // what to do in case of error
46
enum ANNerr {ANNwarn = 0, ANNabort = 1};
47
48
//----------------------------------------------------------------------
49
//        Maximum number of points to visit
50
//        We have an option for terminating the search early if the
51
//        number of points visited exceeds some threshold.  If the
52
//        threshold is 0 (its default)  this means there is no limit
53
//        and the algorithm applies its normal termination condition.
54
//----------------------------------------------------------------------
55
56
extern int                ANNmaxPtsVisited;        // maximum number of pts visited
57
extern int                ANNptsVisited;                // number of pts visited in search
58
59
//----------------------------------------------------------------------
60
//        Global function declarations
61
//----------------------------------------------------------------------
62
63
void annError(                                        // ANN error routine
64
        char                        *msg,                // error message
65
        ANNerr                        level);                // level of error
66
67
void annPrintPt(                                // print a point
68
        ANNpoint                pt,                        // the point
69
        int                                dim,                // the dimension
70
        std::ostream        &out);                // output stream
71
72
//----------------------------------------------------------------------
73
//        Orthogonal (axis aligned) rectangle
74
//        Orthogonal rectangles are represented by two points, one
75
//        for the lower left corner (min coordinates) and the other
76
//        for the upper right corner (max coordinates).
77
//
78
//        The constructor initializes from either a pair of coordinates,
79
//        pair of points, or another rectangle.  Note that all constructors
80
//        allocate new point storage. The destructor deallocates this
81
//        storage.
82
//
83
//        BEWARE: Orthogonal rectangles should be passed ONLY BY REFERENCE.
84
//        (C++'s default copy constructor will not allocate new point
85
//        storage, then on return the destructor free's storage, and then
86
//        you get into big trouble in the calling procedure.)
87
//----------------------------------------------------------------------
88
89
class ANNorthRect {
90
public:
91
        ANNpoint                lo;                        // rectangle lower bounds
92
        ANNpoint                hi;                        // rectangle upper bounds
93
//
94
        ANNorthRect(                                // basic constructor
95
        int                                dd,                        // dimension of space
96
        ANNcoord                l=0,                // default is empty
97
        ANNcoord                h=0)
98
        {  lo = annAllocPt(dd, l);  hi = annAllocPt(dd, h); }
99
100
        ANNorthRect(                                // (almost a) copy constructor
101
        int                                dd,                        // dimension
102
        const                        ANNorthRect &r) // rectangle to copy
103
        {  lo = annCopyPt(dd, r.lo);  hi = annCopyPt(dd, r.hi);  }
104
105
        ANNorthRect(                                // construct from points
106
        int                                dd,                        // dimension
107
        ANNpoint                l,                        // low point
108
        ANNpoint                h)                        // hight point
109
        {  lo = annCopyPt(dd, l);  hi = annCopyPt(dd, h);  }
110
111
        ~ANNorthRect()                                // destructor
112
    {  annDeallocPt(lo);  annDeallocPt(hi);  }
113
114
        ANNbool inside(int dim, ANNpoint p);// is point p inside rectangle?
115
};
116
117
void annAssignRect(                                // assign one rect to another
118
        int                                dim,                // dimension (both must be same)
119
        ANNorthRect                &dest,                // destination (modified)
120
        const ANNorthRect &source);        // source
121
122
//----------------------------------------------------------------------
123
//        Orthogonal (axis aligned) halfspace
124
//        An orthogonal halfspace is represented by an integer cutting
125
//        dimension cd, coordinate cutting value, cv, and side, sd, which is
126
//        either +1 or -1. Our convention is that point q lies in the (closed)
127
//        halfspace if (q[cd] - cv)*sd >= 0.
128
//----------------------------------------------------------------------
129
130
class ANNorthHalfSpace {
131
public:
132
        int                                cd;                        // cutting dimension
133
        ANNcoord                cv;                        // cutting value
134
        int                                sd;                        // which side
135
//
136
        ANNorthHalfSpace()                        // default constructor
137
        {  cd = 0; cv = 0;  sd = 0;  }
138
139
        ANNorthHalfSpace(                        // basic constructor
140
        int                                cdd,                // dimension of space
141
        ANNcoord                cvv,                // cutting value
142
        int                                sdd)                // side
143
        {  cd = cdd;  cv = cvv;  sd = sdd;  }
144
145
        ANNbool in(ANNpoint q) const        // is q inside halfspace?
146
        {  return  (ANNbool) ((q[cd] - cv)*sd >= 0);  }
147
148
        ANNbool out(ANNpoint q) const        // is q outside halfspace?
149
        {  return  (ANNbool) ((q[cd] - cv)*sd < 0);  }
150
151
        ANNdist dist(ANNpoint q) const        // (squared) distance from q
152
        {  return  (ANNdist) ANN_POW(q[cd] - cv);  }
153
154
        void setLowerBound(int d, ANNpoint p)// set to lower bound at p[i]
155
        {  cd = d;  cv = p[d];  sd = +1;  }
156
157
        void setUpperBound(int d, ANNpoint p)// set to upper bound at p[i]
158
        {  cd = d;  cv = p[d];  sd = -1;  }
159
160
        void project(ANNpoint &q)                // project q (modified) onto halfspace
161
        {  if (out(q)) q[cd] = cv;  }
162
};
163
164
                                                                // array of halfspaces
165
typedef ANNorthHalfSpace *ANNorthHSArray;
166
167
#endif