IsoEx
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
RegularGridT.hh
1 /*===========================================================================*\
2  * *
3  * IsoEx *
4  * Copyright (C) 2002 by Computer Graphics Group, RWTH Aachen *
5  * www.rwth-graphics.de *
6  * *
7  *---------------------------------------------------------------------------*
8  * *
9  * License *
10  * *
11  * This library is free software; you can redistribute it and/or modify it *
12  * under the terms of the GNU Library General Public License as published *
13  * by the Free Software Foundation, version 2. *
14  * *
15  * This library is distributed in the hope that it will be useful, but *
16  * WITHOUT ANY WARRANTY; without even the implied warranty of *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
18  * Library General Public License for more details. *
19  * *
20  * You should have received a copy of the GNU Library General Public *
21  * License along with this library; if not, write to the Free Software *
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
23  * *
24 \*===========================================================================*/
25 
26 //=============================================================================
27 //
28 // CLASS RegularGrid
29 //
30 //=============================================================================
31 
32 
33 #ifndef ISOEX_REGULARGRID_HH
34 #define ISOEX_REGULARGRID_HH
35 
36 
37 //== INCLUDES =================================================================
38 
39 #include "Grid.hh"
40 #include <IsoEx/Math/Matrix4x4T.hh>
41 #include <IsoEx/Config/IsoExDefines.hh>
42 
43 //== NAMESPACES ===============================================================
44 
45 namespace IsoEx
46 {
47 
48 //== CLASS DEFINITION =========================================================
49 
50 
55 template <class Vec3 >
56 class ISOEXDLLEXPORT RegularGrid : public Grid< Vec3 >
57 {
58 public:
59 
61 
62  typedef typename Vec3::value_type real;
63 
65  typedef typename Grid< Vec3 >::CubeIdx CubeIdx;
66 
68  typedef typename Grid< Vec3 >::PointIdx PointIdx;
69 
70 
71 
72  // ray plane intersections
73  struct Intersection
74  {
75  real lambda;
76  bool enter;
77  };
78 
89  RegularGrid( const Vec3& _origin = Vec3( 0, 0, 0 ),
90  const Vec3& _x_axis = Vec3( 1, 0, 0 ),
91  const Vec3& _y_axis = Vec3( 0, 1, 0 ),
92  const Vec3& _z_axis = Vec3( 0, 0, 1 ),
93  unsigned int _x_res = 1,
94  unsigned int _y_res = 1,
95  unsigned int _z_res = 1 )
96  { initialize( _origin, _x_axis, _y_axis, _z_axis, _x_res, _y_res, _z_res ); }
97 
99  void initialize( const Vec3& _origin,
100  const Vec3& _x_axis,
101  const Vec3& _y_axis,
102  const Vec3& _z_axis,
103  unsigned int _x_res,
104  unsigned int _y_res,
105  unsigned int _z_res );
106 
107 
108 
109  //------------------------------------------------------- mandatory interface
110 
112  unsigned int n_cubes() const { return n_cubes_; }
113 
115  unsigned int n_points() const { return n_points_; }
116 
118  PointIdx point_idx( CubeIdx _idx, unsigned char _corner ) const;
119 
121  Vec3 point( PointIdx _idx ) const;
122 
124  Vec3 point( int x, int y, int z ) const;
125 
127  PointIdx nearest_point( const Vec3 &_p );
128 
129  const Vec3& origin() const { return origin_; }
130  const Vec3& x_axis() const { return x_axis_; }
131  const Vec3& y_axis() const { return y_axis_; }
132  const Vec3& z_axis() const { return z_axis_; }
133  const Vec3& dx() const { return dx_; }
134  const Vec3& dy() const { return dy_; }
135  const Vec3& dz() const { return dz_; }
136 
137  unsigned int x_resolution() const { return x_res_; }
138  unsigned int y_resolution() const { return y_res_; }
139  unsigned int z_resolution() const { return z_res_; }
140 
142  Vec3 to_local( const Vec3 &_pw );
143 
145  Vec3 to_world( const Vec3 &_pl );
146 
148  bool ray_intersect_local( const Vec3 &_o, const Vec3 &_d,
149  Vec3 &_entry, Vec3 &_exit );
150 
152  real volume() { return this->x_axis().norm()*this->y_axis().norm()*this->z_axis().norm(); }
153 
155  virtual real outer_surface()
156  {
157  return ( this->x_axis().norm()*this->y_axis().norm()*2.0 +
158  this->y_axis().norm()*this->z_axis().norm()*2.0 +
159  this->x_axis().norm()*this->z_axis().norm()*2.0 );
160  }
161 
162 protected:
163 
164  // matrices which transform points to local and world coordinates
165  Matrix to_local_;
166  Matrix to_world_;
167 
168  Vec3 origin_, x_axis_, y_axis_, z_axis_, dx_, dy_, dz_;
169  unsigned int x_res_, y_res_, z_res_, n_cubes_, n_points_;
170  CubeIdx offsets_[8];
171 };
172 
173 
174 //=============================================================================
175 } // namespace IsoEx
176 //=============================================================================
177 
178 #if !defined(ISOEX_REGULAR_GRID_C)
179 #define ISOEX_REGULAR_GRID_TEMPLATES
180 #include "RegularGridT.cc"
181 #endif
182 
183 #endif // ISOEX_REGULARGRID_HH defined
184 //=============================================================================
185 
Grid< Vec3 >::CubeIdx CubeIdx
CubeIdx can be used to refer to cubes.
Definition: RegularGridT.hh:65
real volume()
returns the volume of the grid
Definition: RegularGridT.hh:152
virtual real outer_surface()
returns the outer surface of the grid
Definition: RegularGridT.hh:155
RegularGrid(const Vec3 &_origin=Vec3(0, 0, 0), const Vec3 &_x_axis=Vec3(1, 0, 0), const Vec3 &_y_axis=Vec3(0, 1, 0), const Vec3 &_z_axis=Vec3(0, 0, 1), unsigned int _x_res=1, unsigned int _y_res=1, unsigned int _z_res=1)
Definition: RegularGridT.hh:89
unsigned int n_points() const
Return number of points.
Definition: RegularGridT.hh:115
Definition: RegularGridT.hh:73
A type for volume images, or 3D textures.
unsigned int n_cubes() const
Return number of cubes.
Definition: RegularGridT.hh:112
Grid< Vec3 >::PointIdx PointIdx
The grid points can be referred to by PointIdx.
Definition: RegularGridT.hh:68
Definition: RegularGridT.hh:56
Definition: Grid.hh:58