1 /* Copyright 2006-2009 Brad King, Chuck Stewart
2    Distributed under the Boost Software License, Version 1.0.
3    (See accompanying file rgtl_license_1_0.txt or copy at
4    http://www.boost.org/LICENSE_1_0.txt) */
5 #ifndef rgtl_octree_cell_geometry_h
6 #define rgtl_octree_cell_geometry_h
7 
8 //:
9 // \file
10 // \brief Represent the geometry of an octree cell.
11 // \author Brad King
12 // \date February 2007
13 
14 #include "rgtl_octree_cell_location.h"
15 
16 template <unsigned int D> class rgtl_octree_cell_bounds;
17 
18 //: Represent the geometry of an octree cell.
19 //
20 // This class efficiently maintains octree cell geometry as the tree
21 // is traversed.
22 template <unsigned int D>
23 class rgtl_octree_cell_geometry
24 {
25 public:
26   //: Type representing a logical cell location.
27   typedef rgtl_octree_cell_location<D> cell_location_type;
28 
29   //: Type representing the octree cell bounds.
30   typedef rgtl_octree_cell_bounds<D> cell_bounds_type;
31 
32   //: Default constructor used only to create array.
33   rgtl_octree_cell_geometry();
34 
35   //: Construct the geometry of a given cell location.
36   explicit rgtl_octree_cell_geometry(cell_location_type const& cell,
37                                      cell_bounds_type const& root_bounds);
38 
39   //: Get the logical cell location.
40   cell_location_type const& location() const;
41 
42   //: Get the cell bounding sphere.
43   void get_sphere(double center[D], double& radius) const;
44   double const* get_sphere_center() const;
45   double get_sphere_radius() const;
46 
47   //: Get the cell bounding box range on each axis.
48   double const* get_lower() const;
49   double const* get_upper() const;
50 
51   //: Get the cell bounding box corners.
52   double const* get_corner(unsigned int i) const;
get_corners()53   double const (*get_corners() const)[D] { return this->corners_; }
54 
55   //: Compute the child cell geometries.
56   void get_children(rgtl_octree_cell_geometry children[1<<D]) const;
57 
58 private:
59 
60   void compute_corners();
61 
62   // Type-safe index to a child.
63   typedef typename cell_location_type::child_index_type child_index_type;
64 
65   // The cell location.
66   cell_location_type location_;
67 
68   // The cell geometry.
69   double center_[D];        // Bounding sphere center.
70   double radius_;           // Bounding sphere radius.
71   double lower_[D];         // Lower bounding plane positions.
72   double upper_[D];         // Upper bounding plane positions.
73   double corners_[1<<D][D]; // Bounding box corners.
74 };
75 
76 #endif
77