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_object_array_points_h 6 #define rgtl_object_array_points_h 7 8 //: 9 // \file 10 // \brief Hold a set of points for storage in spatial data structures. 11 // \author Brad King 12 // \date March 2007 13 14 #include <iostream> 15 #include <vector> 16 #include "rgtl_object_array.h" 17 #include "rgtl_serialize_access.h" 18 #include "rgtl_serialize_base.h" 19 #include "rgtl_serialize_stl_vector.h" 20 21 #include <vnl/vnl_vector_fixed.h> 22 #ifdef _MSC_VER 23 # include <vcl_msvc_warnings.h> 24 #endif 25 26 //---------------------------------------------------------------------------- 27 template <unsigned int D> 28 class rgtl_object_array_points: public rgtl_object_array<D> 29 { 30 typedef vnl_vector_fixed<double, D> point_type; 31 public: 32 typedef rgtl_object_array<D> derived; 33 34 //: Construct to hold a given number of points. 35 rgtl_object_array_points(int n = 0); 36 37 //: Construct to hold the points given. 38 rgtl_object_array_points(std::vector<point_type> const& points); 39 40 //: Set the number of points stored. 41 void set_number_of_points(int n); 42 43 //: Get the number of points stored. 44 int get_number_of_points() const; 45 46 //: Get a point location in space. 47 void get_point(int id, double x[D]) const; 48 49 //: Set a point location in space. 50 void set_point(int id, double const x[D]); 51 52 //: Add a point location in space. Returns the id of the point. 53 int add_point(double const x[D]); 54 55 //: Get the number of objects in the array. 56 virtual int number_of_objects() const; 57 58 //: Check whether one object intersects another. 59 virtual bool object_intersects_object(int idA, int idB) const; 60 61 //: Check whether an object intersects an axis-aligned bounding box. 62 virtual bool object_intersects_box(int id, 63 double const center[D], 64 double const radius, 65 double const lower[D], 66 double const upper[D], 67 double const corners[1<<D][D]) const; 68 69 //: Compute the closest point on an object to the point given. 70 virtual bool object_closest_point(int id, 71 double const x[D], 72 double y[D], 73 double bound_squared) const; 74 75 //: Compute the intersection of an object with a ray. 76 virtual bool object_intersects_ray(int id, 77 double const origin[D], 78 double const direction[D], 79 double y[D], double* s) const; 80 81 //: Compute an axis-aligned bounding box around the objects. 82 virtual void compute_bounds(double bounds[D][2]) const; 83 private: 84 std::vector<point_type> points_; 85 86 friend class rgtl_serialize_access; 87 template <class Serializer> serialize(Serializer & sr)88 void serialize(Serializer& sr) 89 { 90 sr & rgtl_serialize_base<derived>(*this); 91 sr & points_; 92 } 93 }; 94 95 96 #endif 97