libatomprobe
Library for Atom Probe Tomography (APT) computation
boundcube.h
Go to the documentation of this file.
1 /* boundcube.h : Bounding cube class
2  * Copyright (C) 2014 Daniel Haley
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #ifndef ATOMPROBE_BOUNDCUBE_H
18 #define ATOMPROBE_BOUNDCUBE_H
19 
21 
22 #include <vector>
23 
24 namespace AtomProbe{
25 
26 class IonHit;
27 
29 class BoundCube
30 {
32  float bounds[3][2];
33 #ifdef DEBUG
34  bool valid[3][2];
36 #endif
37 public:
38 
40  {
41 #ifdef DEBUG
42  setInvalid();
43 #endif
44  }
45 
46  BoundCube(const std::vector<Point3D> &pts)
47  {
48  setBounds(pts);
49  }
50 
51  BoundCube(const std::vector<IonHit> &pts)
52  {
53  setBounds(pts);
54  }
55 
56 
57  BoundCube(const Point3D &p1, const Point3D &p2);
58 
59  bool operator==(const BoundCube &other) const;
61  void setBounds(float xMin,float yMin,float zMin,
62  float xMax,float yMax,float zMax);
63 
65 
68  void setBound(unsigned int bound, unsigned int minMax, float value) ;
69 
71  void setBounds(const BoundCube &b);
73  void setBounds( const Point3D *ptArray, unsigned int nPoints);
75  void setBounds( const Point3D &p, const Point3D &q);
77  void setBounds(const std::vector<Point3D> &ptArray);
79  void setBounds(const std::vector<IonHit> &ptArray);
81 
84  void setBounds(const Point3D &p, float radius);
85 #ifdef DEBUG
86  bool isValid() const;
89  bool isValid(unsigned int dim) const;
90 
92  void setInvalid();
93 #endif
94  void setInverseLimits();
96 
98 
101  float getBound(unsigned int bound, unsigned int minMax) const ;
103  Point3D getCentroid() const;
104 
106  void getBounds(Point3D &low, Point3D &high) const ;
107 
108  //Return the lower left (min) bound
109  Point3D min() const;
110 
111  //Return the lower left (min) bound
112  Point3D max() const;
113 
115  float getSize(unsigned int dim) const;
116 
117 
119  bool isFlat() const;
120 
122  bool intersects(const Point3D &pt, float sqrRad) const;
123 
125  bool intersects(const BoundCube &b) const;
126 
127 
129  bool contains(const BoundCube &b) const;
131  bool containsPt(const Point3D &pt) const;
132 
134  bool containedInSphere(const Point3D &origin, float radius) const;
135 
137  BoundCube makeUnion(const BoundCube &b) const;
138 
140  BoundCube makeIntersection(const BoundCube &b) const;
141 
143  float getMaxDistanceToBox(const Point3D &pt) const;
144 
146  float getLargestDim() const;
147 
149  float getVolume() const;
150 
152  void setLimits();
154 
158  unsigned int segmentTriple(unsigned int dim, float slice) const;
159 
160  BoundCube operator=(const BoundCube &);
162  void expand(const BoundCube &b);
164  void expand(const Point3D &p);
165 
167  void expand(float f);
168 
169  friend std::ostream &operator<<(std::ostream &stream, const BoundCube& b);
170 
171  friend class K3DTreeExact;
172  friend class K3DTreeApprox;
173 };
174 }
175 #endif
bool containsPt(const Point3D &pt) const
Check to see if the point is contained in, or part of the walls of the cube.
Definition: boundcube.cpp:367
void setInverseLimits()
Set the cube to be "inside out" at the limits of numeric results;.
Definition: boundcube.cpp:94
BoundCube(const std::vector< Point3D > &pts)
Definition: boundcube.h:46
void setLimits()
Set min-max bounds to fp min/max.
Definition: boundcube.cpp:115
bool intersects(const Point3D &pt, float sqrRad) const
Checks if a point intersects a sphere of centre Pt, radius^2 sqrRad.
Definition: boundcube.cpp:434
3D specific KD tree
Definition: K3DTree-exact.h:54
void getBounds(Point3D &low, Point3D &high) const
Get the bounds of the cube as two points, the lower left (minimum bound) and upper right corner (max ...
Definition: boundcube.cpp:302
float getMaxDistanceToBox(const Point3D &pt) const
Returns maximum distance to box corners (which is an upper bound on max box distance).
Definition: boundcube.cpp:499
float getSize(unsigned int dim) const
Return the size of the side parallel to the given dimension.
Definition: boundcube.cpp:343
float getVolume() const
Obtain the volume of the cube.
Definition: boundcube.cpp:355
friend std::ostream & operator<<(std::ostream &stream, const BoundCube &b)
Definition: boundcube.cpp:563
Point3D max() const
Definition: boundcube.cpp:324
A 3D point data class storage.
Definition: point3D.h:39
unsigned int segmentTriple(unsigned int dim, float slice) const
Return a triplet to indicate a spatial partition value lies in.
Definition: boundcube.cpp:529
BoundCube makeUnion(const BoundCube &b) const
Create the box containing a union of two bounding cubes.
Definition: boundcube.cpp:399
float getLargestDim() const
Get the largest dimension of the bound cube.
Definition: boundcube.cpp:335
void setBound(unsigned int bound, unsigned int minMax, float value)
Set an individual bound.
Definition: boundcube.cpp:76
float getBound(unsigned int bound, unsigned int minMax) const
Return the bound on the given dimension.
Definition: boundcube.cpp:86
BoundCube makeIntersection(const BoundCube &b) const
Create the box which is the intersection of two bounding cubes this is either null, or a box.
Definition: boundcube.cpp:416
bool operator==(const BoundCube &other) const
Definition: boundcube.cpp:38
Helper class to define a bounding cube.
Definition: boundcube.h:29
bool containedInSphere(const Point3D &origin, float radius) const
Returns true if this box is contained by the sphere, represented by the origin+radius.
Definition: boundcube.cpp:379
bool isFlat() const
Returns true if any bound is of null thickness.
Definition: boundcube.cpp:136
3D specific KD tree
Point3D min() const
Definition: boundcube.cpp:312
Point3D getCentroid() const
Return the centroid.
Definition: boundcube.cpp:486
BoundCube operator=(const BoundCube &)
Definition: boundcube.cpp:546
bool contains(const BoundCube &b) const
Does this bounding box entirely contain another.
Definition: boundcube.cpp:360
BoundCube(const std::vector< IonHit > &pts)
Definition: boundcube.h:51
void setBounds(float xMin, float yMin, float zMin, float xMax, float yMax, float zMax)
Set the bounds by passing in minima and maxima of each dimension.
Definition: boundcube.cpp:49
void expand(const BoundCube &b)
Expand (as needed) volume such that the argument bounding cube is enclosed by this one...
Definition: boundcube.cpp:148