IsoEx
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
ImplicitGridT.hh
1 //=============================================================================
2 //
3 // CLASS ImplicitGrid
4 //
5 //=============================================================================
6 
7 
8 #ifndef ISOEX_IMPLICITGRID_HH
9 #define ISOEX_IMPLICITGRID_HH
10 
11 
12 //== INCLUDES =================================================================
13 
14 #include <IsoEx/Grids/RegularGridT.hh>
15 #include <IsoEx/Implicits/Implicit.hh>
16 #include <OpenMesh/Core/Geometry/VectorT.hh>
17 #include <vector>
18 
19 //== NAMESPACES ===============================================================
20 
21 namespace IsoEx {
22 
23 //== CLASS DEFINITION =========================================================
24 
25 
38 template <class Vec3 >
39 class ImplicitGrid : public RegularGrid< Vec3 >
40 {
41 public:
42 
43  typedef typename Vec3::value_type real;
44 
46  typedef typename Grid< Vec3 >::CubeIdx CubeIdx;
47 
49  typedef typename Grid< Vec3 >::PointIdx PointIdx;
50 
51  //------------------------------------------------------------ public methods
52 
53 
55  ImplicitGrid(const Implicit<Vec3>& _implicit,
56  const Vec3& _origin,
57  const Vec3& _x_axis,
58  const Vec3& _y_axis,
59  const Vec3& _z_axis,
60  unsigned int _x_res,
61  unsigned int _y_res,
62  unsigned int _z_res)
63  : RegularGrid< Vec3 >(_origin, _x_axis, _y_axis, _z_axis, _x_res, _y_res, _z_res),
64  implicit_(_implicit)
65  {}
66 
68  virtual ~ImplicitGrid() {}
69 
70 
71 
73 
74 
76  virtual bool is_inside(PointIdx _pidx) const {
77  return (is_inside_cache_.empty() ? implicit_.is_inside(this->point(_pidx)) : is_inside_cache_[_pidx]);
78  }
79 
81  virtual real scalar_distance(PointIdx _pidx) const {
82  return (scalar_distance_cache_.empty() ? implicit_.scalar_distance(this->point(_pidx)) : scalar_distance_cache_[_pidx]);
83  }
84 
86  virtual bool directed_distance(const Vec3& _p0,
87  const Vec3& _p1,
88  Vec3& _point,
89  Vec3& _normal,
90  real& _distance) const {
91  return implicit_.directed_distance(_p0, _p1, _point, _normal, _distance);
92  }
93 
95 
96 
97 
99 
100 
103  {
104  int i, np( this->n_points() );
105 
106  is_inside_cache_.clear();
107  is_inside_cache_.resize( this->n_points());
108 
109  for (i=0; i<np; ++i)
110  is_inside_cache_[i] = implicit_.is_inside(this->point(i));
111  }
112 
115  {
116  int i, np(this->n_points());
117 
118  scalar_distance_cache_.clear();
119  scalar_distance_cache_.resize(np);
120 
121  for (i=0; i<np; ++i)
122  scalar_distance_cache_[i] = implicit_.scalar_distance(this->point(i));
123  }
124 
126 
127 
128 
129 protected:
130 
131  const Implicit<Vec3>& implicit_;
132 
133  mutable std::vector<bool> is_inside_cache_;
134  mutable std::vector<real> scalar_distance_cache_;
135 };
136 
137 
138 //=============================================================================
139 } // namespace IsoEx
140 //=============================================================================
141 #endif // ISOEX_IMPLICITGRID_HH defined
142 //=============================================================================
virtual real scalar_distance(PointIdx _pidx) const
See IsoEx::Implicit::scalar_distance()
Definition: ImplicitGridT.hh:81
void build_is_inside_cache() const
Cache results of is_inside()
Definition: ImplicitGridT.hh:102
ImplicitGrid(const Implicit< Vec3 > &_implicit, const Vec3 &_origin, const Vec3 &_x_axis, const Vec3 &_y_axis, const Vec3 &_z_axis, unsigned int _x_res, unsigned int _y_res, unsigned int _z_res)
Default constructor.
Definition: ImplicitGridT.hh:55
Definition: ImplicitGridT.hh:39
virtual ~ImplicitGrid()
Destructor.
Definition: ImplicitGridT.hh:68
void build_scalar_distance_cache() const
Cache results of scalar_distance()
Definition: ImplicitGridT.hh:114
virtual bool directed_distance(const Vec3 &_p0, const Vec3 &_p1, Vec3 &_point, Vec3 &_normal, real &_distance) const
See IsoEx::Implicit::directed_distance()
Definition: ImplicitGridT.hh:86
unsigned int n_points() const
Return number of points.
Definition: RegularGridT.hh:115
Grid< Vec3 >::CubeIdx CubeIdx
CubeIdx can be used to refer to cubes.
Definition: ImplicitGridT.hh:46
virtual bool is_inside(PointIdx _pidx) const
See IsoEx::Implicit::is_inside()
Definition: ImplicitGridT.hh:76
Definition: Implicit.hh:57
A type for volume images, or 3D textures.
Vec3 point(PointIdx _idx) const
Return the 3D point refered to by _idx.
Definition: RegularGridT.cc:156
Grid< Vec3 >::PointIdx PointIdx
The grid points can be referred to by PointIdx.
Definition: ImplicitGridT.hh:49
Definition: RegularGridT.hh:56
Definition: Grid.hh:58