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


Generated on OURCE_DATE_EPOCH for elastix by doxygen 1.8.18 elastix logo