Blame view

stim/visualization/aaboundingbox.h 3.03 KB
9c97e126   David Mayerich   added an axis-ali...
1
2
3
4
5
6
7
8
  #ifndef STIM_AABB
  #define STIM_AABB
  
  namespace stim{
  
  
  /// This class describes a structure for an axis-aligned bounding box
  template< typename T >
b3a38641   David Mayerich   added the ability...
9
  class aaboundingbox{
9c97e126   David Mayerich   added an axis-ali...
10
11
12
  
  public:
  	bool set;				//has the bounding box been set to include any points?
308a743c   David Mayerich   fixed class compa...
13
14
  	stim::vec3<T> A;			//minimum point in the bounding box
  	stim::vec3<T> B;			//maximum point in the bounding box
9c97e126   David Mayerich   added an axis-ali...
15
  
b3a38641   David Mayerich   added the ability...
16
  	aaboundingbox(){					//constructor generates an empty bounding box
9c97e126   David Mayerich   added an axis-ali...
17
18
19
20
21
22
23
  		set = false;
  	}
  
  
  	/// Test if a point is inside of the bounding box and returns true if it is.
  
  	/// @param p is the point to be tested
308a743c   David Mayerich   fixed class compa...
24
  	bool test(stim::vec3<T> p){
9c97e126   David Mayerich   added an axis-ali...
25
26
27
28
29
30
31
32
33
34
35
  
  		for(unsigned d = 0; d < p.size(); p++){		//for each dimension
  			if(p[d] < A[d]) return false;			//if the point is less than the minimum bound, return false
  			if(p[d] > B[d]) return false;			//if the point is greater than the max bound, return false
  		}
  		return true;
  	}
  
  	/// Expand the bounding box to include the specified point.
  
  	/// @param p is the point to be included
308a743c   David Mayerich   fixed class compa...
36
  	void expand(stim::vec3<T> p){
9c97e126   David Mayerich   added an axis-ali...
37
38
39
40
41
42
43
44
45
46
47
48
49
  
  		if(!set){							//if the bounding box is empty, fill it with the current point
  			A = B = p;
  			set = true;
  		}
  
  		for(unsigned d = 0; d < p.size(); d++){		//for each dimension
  			if(p[d] < A[d]) A[d] = p[d];			//expand the bounding box as necessary
  			if(p[d] > B[d]) B[d] = p[d];
  		}
  	}
  
  	/// Return the center point of the bounding box as a stim::vec
308a743c   David Mayerich   fixed class compa...
50
  	stim::vec3<T> center(){
9c97e126   David Mayerich   added an axis-ali...
51
52
53
54
  		return (B + A) * 0.5;
  	}
  
  	/// Return the size of the bounding box as a stim::vec
308a743c   David Mayerich   fixed class compa...
55
  	stim::vec3<T> size(){
9c97e126   David Mayerich   added an axis-ali...
56
57
58
59
60
61
62
63
64
65
  		return (B - A);
  	}
  
  	/// Generate a string for the bounding box
  	std::string str(){
  		std::stringstream ss;
  		ss<<A.str()<<"----->"<<B.str();
  		return ss.str();
  	}
  
c11e5e01   Pavel Govyadinov   Added a method fo...
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
          ///resamples the boundingbox by a factor of N
          std::vector<stim::aaboundingbox<T> >
          resample(unsigned int n)
          {   
                  stim::vec3<T> step_size = (B-A)/n;
                  std::vector<stim::aaboundingbox<T> > boundingboxes(n*n*n);
                  for(int x = 0; x < n; x++)
                  {   
                          for(int y = 0; y < n; y++)
                          {   
                                  for(int z = 0; z < n; z++)
                                  {
                                          ///create the bounding box
                                          stim::aaboundingbox<T> box;
                                          box.A[0] = A[0]+step_size[0]*x;
                                          box.A[1] = A[1]+step_size[1]*y;
                                          box.A[2] = A[2]+step_size[2]*z;
  
                                          box.B[0] = A[0]+step_size[0]*(x+1);
                                          box.B[1] = A[1]+step_size[1]*(y+1);
                                          box.B[2] = A[2]+step_size[2]*(z+1);
                                          ///put the new bounding box into the right place
                                          boundingboxes[x*n*n + y*n + z] = box;
                                  }
                          }
                  }
                  return boundingboxes;
          }
  
9c97e126   David Mayerich   added an axis-ali...
95
96
97
98
99
100
  
  };		//end stim::aabb
  
  
  };		//end namespace stim
  
c11e5e01   Pavel Govyadinov   Added a method fo...
101
  #endif