IsoEx
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
ScalarGridT.hh
1 
2 //=============================================================================
3 //
4 // CLASS ScalarGridT
5 //
6 //=============================================================================
7 
8 
9 #ifndef ISOEX_SCALARGRIDT_HH
10 #define ISOEX_SCALARGRIDT_HH
11 
12 
13 //== INCLUDES =================================================================
14 
15 #include <OpenMesh/Core/IO/BinaryHelper.hh>
16 #include <OpenMesh/Core/Geometry/VectorT.hh>
17 
18 #include "RegularGrid.hh"
19 #include "../Implicits/Implicit.hh"
20 
21 #include <vector>
22 #include <iostream>
23 
24 //== NAMESPACES ===============================================================
25 
26 namespace IsoEx
27 {
28 
29 //== CLASS DEFINITION =========================================================
30 
31 
38 template <typename Scalar>
39 class ScalarGridT : public RegularGrid
40 {
41 public:
42 
43  //typedef _Scalar Scalar;
44  typedef std::vector<Scalar> Values;
45 
47  ScalarGridT( const Vec3& _origin = Vec3( 0, 0, 0 ),
48  const Vec3& _x_axis = Vec3( 1, 0, 0 ),
49  const Vec3& _y_axis = Vec3( 0, 1, 0 ),
50  const Vec3& _z_axis = Vec3( 0, 0, 1 ),
51  unsigned int _x_res = 1,
52  unsigned int _y_res = 1,
53  unsigned int _z_res = 1 )
54  {
55  initialize( _origin, _x_axis, _y_axis, _z_axis, _x_res, _y_res, _z_res );
56  }
57 
59  virtual ~ScalarGridT() {}
60 
62  void initialize( const Vec3& _origin,
63  const Vec3& _x_axis,
64  const Vec3& _y_axis,
65  const Vec3& _z_axis,
66  unsigned int _x_res,
67  unsigned int _y_res,
68  unsigned int _z_res )
69  {
70  RegularGrid::initialize( _origin, _x_axis, _y_axis, _z_axis,
71  _x_res, _y_res, _z_res );
72  values_.resize( n_points_, 0.0 );
73  }
74 
75 
76 
77  virtual real scalar_distance( PointIdx _pidx ) const
78  {
79  return values_[_pidx];
80  }
81 
82  virtual bool is_inside( PointIdx _pidx ) const
83  {
84  return values_[_pidx] < 0.0;
85  }
86 
87  virtual bool directed_distance( const Vec3& /*_p0*/,
88  const Vec3& /*_p1*/,
89  Vec3& /*_point*/,
90  Vec3& /*_normal*/,
91  real& /*_distance*/ ) const
92  {
93  return false;
94  }
95 
96  void sample( const Implicit& _implicit );
97 
98 
99  virtual bool read( const char* _filename );
100  virtual bool write( const char* _filename );
101  virtual bool read( FILE* _in );
102  virtual bool write( FILE* _out );
103 
105  Scalar& operator()( unsigned int x, unsigned int y, unsigned int z )
106  {
107  return values_[x + y*x_resolution() + z*x_resolution()*y_resolution()];
108  }
109 
110  Scalar operator()( unsigned int x, unsigned int y, unsigned int z ) const
111  {
112  return values_[x + y*x_resolution() + z*x_resolution()*y_resolution()];
113  }
114 
115  Scalar& value( unsigned int x, unsigned int y, unsigned int z )
116  {
117  return ( *this )( x, y, z );
118  }
119 
120  Scalar value( unsigned int x, unsigned int y, unsigned int z ) const
121  {
122  return ( *this )( x, y, z );
123  }
124 
126  Scalar value_range( int x, int y, int z ) const;
127 
128 // void resize() {values_ = Values( n_points(), 0 );} // changed
129 
131  Scalar lerp_local( Scalar _x, Scalar _y, Scalar _z );
132 
134  Scalar lerp_world( Scalar _x, Scalar _y, Scalar _z );
135 
137  void get_isosurface_intersections_local( const Vec3 &_o,
138  const Vec3 &_d,
139  Scalar _iso,
140  std::vector< Vec3 > &_intersections );
141 
143  void get_isosurface_intersections_world( const Vec3 &_o,
144  const Vec3 &_d,
145  Scalar _iso,
146  std::vector< Vec3 > &_intersections );
147 
148 protected:
149 
150  Values values_;
151 };
152 
153 
154 //=============================================================================
155 } // namespace IsoEx
156 //=============================================================================
157 #if defined(INCLUDE_TEMPLATES) && !defined(ISOEX_SCALARGRIDT_C)
158 #define ISOEX_SCALARGRIDT_TEMPLATES
159 #include "ScalarGridT.cc"
160 #endif
161 //=============================================================================
162 #endif // ISOEX_SCALARGRIDT_HH defined
163 //=============================================================================
164 
virtual ~ScalarGridT()
Destructor.
Definition: ScalarGridT.hh:59
virtual bool directed_distance(const Vec3 &, const Vec3 &, Vec3 &, Vec3 &, real &) const
See IsoEx::Implicit::directed_distance()
Definition: ScalarGridT.hh:87
Scalar & operator()(unsigned int x, unsigned int y, unsigned int z)
data access
Definition: ScalarGridT.hh:105
Scalar value_range(int x, int y, int z) const
get scalar value, returns 0.0 if position is not in range
Definition: ScalarGridT.cc:134
void initialize(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)
function to initialize the grid
Definition: RegularGridT.cc:49
void get_isosurface_intersections_world(const Vec3 &_o, const Vec3 &_d, Scalar _iso, std::vector< Vec3 > &_intersections)
get intersections with isosurface in world coordinates
Definition: ScalarGridT.cc:209
Scalar lerp_world(Scalar _x, Scalar _y, Scalar _z)
funciton to lineary interploate a scalar value at a world point
Definition: ScalarGridT.cc:197
void initialize(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)
function to initialize the grid
Definition: ScalarGridT.hh:62
Scalar lerp_local(Scalar _x, Scalar _y, Scalar _z)
function to lineary interpolate a scalar value at a local point
Definition: ScalarGridT.cc:151
Definition: Implicit.hh:57
A type for volume images, or 3D textures.
ScalarGridT(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)
Default constructor.
Definition: ScalarGridT.hh:47
Grid< Vec3 >::PointIdx PointIdx
The grid points can be referred to by PointIdx.
Definition: RegularGridT.hh:68
void get_isosurface_intersections_local(const Vec3 &_o, const Vec3 &_d, Scalar _iso, std::vector< Vec3 > &_intersections)
get intersections with isosurface in local coordinates
Definition: ScalarGridT.cc:229
Definition: RegularGridT.hh:56
Definition: ScalarGridT.hh:39