IsoEx
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
VolumeImageT.hh
1 #ifndef _VOLUMEIMAGET_H_
2 #define _VOLUMEIMAGET_H_
3 
4 /*******************************************************************************
5  * volimage.h
6  *
7  * Defines a type for a 3D volume image.
8  *
9  * (C)2005,2006
10  * Lehrstuhl I8 RWTH-Aachen, http://www-i8.informatik.rwth-aachen.de
11  * Author: Dominik Sibbing
12  *
13  ******************************************************************************/
14 
15 //==============================================================================
16 
17 #include <cassert>
18 
19 #include <string>
20 #include <vector>
21 #include <IsoEx/Grids/ScalarGridT.hh>
22 #include <IsoEx/Grids/VectorFieldT.hh>
23 // #include "Types.hh"
24 
25 // qt
26 #include <QDateTime>
27 #include <QDataStream>
28 #include <QFile>
29 #include <QFileInfo>
30 #include <QString>
31 #include <QDir>
32 
33 //==============================================================================
34 
35 #define THRESHOLD 0.05
36 
37 
65 namespace IsoEx
66 {
67 
68 
69 template <class Scalar>
70 class VolumeImageT : public ScalarGridT<Scalar>
71 {
72 public:
73 
74 
76  typedef typename VectorField::Vector Vec3;
77 
79  VolumeImageT( const Vec3& _origin = Vec3( 0,0,0 ),
80  const Vec3& _x_axis = Vec3( 1,0,0 ),
81  const Vec3& _y_axis = Vec3( 0,1,0 ),
82  const Vec3& _z_axis = Vec3( 0,0,1 ),
83  unsigned int _x_res = 10,
84  unsigned int _y_res = 10,
85  unsigned int _z_res = 10 )
86  : ScalarGridT<Scalar>( _origin, _x_axis, _y_axis, _z_axis, _x_res, _y_res, _z_res )
87  {}
88 
90  virtual ~VolumeImageT() {}
91 
92 
93  struct Dimension
94  {
95  Dimension( unsigned int _x = 1, unsigned int _y = 1, unsigned int _z = 1,
96  Scalar _sx = 1, Scalar _sy = 1, Scalar _sz = 1,
97  Scalar _tx = 0, Scalar _ty = 0, Scalar _tz = 0,
98  Scalar _scale = 1 )
99  : x( _x ), y( _y ), z( _z ),
100  sx( _sx ), sy( _sy ), sz( _sz ),
101  tx( _tx ), ty( _ty ), tz( _tz ),
102  scale( _scale )
103  { }
104 
105  unsigned int x, y, z;
106  Scalar sx, sy, sz;
107  Scalar tx, ty, tz;
108  Scalar scale;
109 
112  bool operator!=( const Dimension &di )
113  {
114  return ( x != di.x &&
115  y != di.y &&
116  z != di.z &&
117  sx != di.sx &&
118  sy != di.sy &&
119  sz != di.sz );
120  }
121 
122  int max_di(){return std::max( std::max( x,y ),z );}
123  };
124 
125  struct Neighbor
126  {
127  Neighbor( int _x, int _y, int _z, Scalar _w ) :
128  x( _x ),
129  y( _y ),
130  z( _z ),
131  w_dist( _w )
132  {
133  }
134  int x;
135  int y;
136  int z;
137 
138  Scalar w_dist;
139  };
140  typedef std::vector< Neighbor > GaussKernel;
141 
142 
144  typedef enum Formats
145  {
151  } VolumeImageMode;
152 
153  void init( const Vec3& _origin,
154  const Vec3& _x_axis,
155  const Vec3& _y_axis,
156  const Vec3& _z_axis,
157  unsigned int _x_res,
158  unsigned int _y_res,
159  unsigned int _z_res );
160 
162  virtual bool read( const char* _fname );
163  virtual bool write( const char* _filename, VolumeImageMode _mode );
164 
165  void getByteData( std::vector<unsigned char> &_result ) const;
166  void getByteDataGradient( std::vector<unsigned char> &_result ) const;
167 
168  void getData( std::vector<float> &_result ) const;
169  void getDataGradient( std::vector<float> &_result ) const;
170 
172  void update_min_max();
173  Scalar max_value(){return max_value_;}
174  Scalar min_value(){return min_value_;}
175 
177  void bilateral_filter( Scalar _hs, Scalar _hr, int _iterations );
178  void bilateral_filter_simple( Scalar _sigma_s, Scalar _sigma_r, int _iterations );
179 
181  void normalize();
182  void normalize( double _min, double _max );
183  void clamp( double _min, double _max );
184  void normalize_with_histogram( Scalar _max, Scalar _percent, int _n_bins = 1000 );
185  void histogram( const int _n_bins,
186  std::vector<unsigned int> &_bins,
187  Scalar &_size,
188  bool _to_image = false );
189 
190  void set_border();
191 
192 
194  void assign_gradients();
195  void normalize_gradients();
196  Vec3 calcGradient( const unsigned int &_x,
197  const unsigned int &_y,
198  const unsigned int &_z );
199 
201  VectorField &grad_field(){return grad_field_;}
202 
203 private:
204 
205  Dimension di_;
206  Scalar min_value_;
207  Scalar max_value_;
208 
209  Scalar threshold_;
210 
212  VectorField grad_field_;
213 
215  void i_to_xyz( int _i, int &_x, int &_y, int &_z );
216  void get_neighbors_in_r( const unsigned int &_p, const int _r, std::vector<unsigned int> &_n );
217  void set_bandwidth( Scalar _hs, Scalar _hr );
218  void bilateral_update( std::vector<Scalar> &_src,
219  std::vector<Scalar> &_dst,
220  const unsigned int &_point_idx,
221  const Scalar &_hr,
222  const Scalar &_hs );
223  void bilateral_update_simple( std::vector<Scalar> &_src,
224  std::vector<Scalar> &_dst,
225  int _x, int _y, int _z, Scalar _hs );
226  void precalculate_gauss_kernel( Scalar _sigma_s, Scalar _threshold = 0.08 );
227 
228 
230  GaussKernel cur_gauss_kernel_;
231 };
232 
233 } //end namespace IsoEx
234 #if defined(INCLUDE_TEMPLATES) && !defined(ISOEX_VOLUMEIMAGET_C)
235 #define ISOEX_VOLUMEIMAGET_TEMPLATES
236 #include "VolumeImageT.cc"
237 #endif
238 // _VOLIMAGE_H_
239 #endif
void histogram(const int _n_bins, std::vector< unsigned int > &_bins, Scalar &_size, bool _to_image=false)
Definition: VolumeImageT.cc:1364
Image will use 32 bit Scalars.
Definition: VolumeImageT.hh:149
Scalar sz
Thickness of each dimension.
Definition: VolumeImageT.hh:106
Image will use 16 bit integers.
Definition: VolumeImageT.hh:147
unsigned int z
Dimensions of the image.
Definition: VolumeImageT.hh:105
bool operator!=(const Dimension &di)
Compares two Dimension structures.
Definition: VolumeImageT.hh:112
Scalar scale
A scaling factor for the data.
Definition: VolumeImageT.hh:108
Image will use bytes.
Definition: VolumeImageT.hh:146
Image will use 16 bit Scalars.
Definition: VolumeImageT.hh:148
virtual ~VolumeImageT()
Destructor.
Definition: VolumeImageT.hh:90
Definition: VolumeImageT.hh:70
void normalize()
normalization and clamping
Definition: VolumeImageT.cc:1038
VectorField & grad_field()
access to gradient field
Definition: VolumeImageT.hh:201
void assign_gradients()
Gradient calculation.
Definition: VolumeImageT.cc:1300
void getByteData(std::vector< unsigned char > &_result) const
Returns an array of bytes.
Definition: VolumeImageT.cc:545
void bilateral_filter(Scalar _hs, Scalar _hr, int _iterations)
Filter.
Definition: VolumeImageT.cc:699
A type for volume images, or 3D textures.
VolumeImageT(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=10, unsigned int _y_res=10, unsigned int _z_res=10)
Default constructor.
Definition: VolumeImageT.hh:79
Image will use logarithmic byte encoding.
Definition: VolumeImageT.hh:150
Definition: VolumeImageT.hh:125
Definition: VolumeImageT.hh:93
Scalar tz
Translation to origin.
Definition: VolumeImageT.hh:107
virtual bool read(const char *_fname)
load and save
Definition: VolumeImageT.cc:40
enum IsoEx::VolumeImageT::Formats VolumeImageMode
Determines data type of stored image.
Formats
Determines data type of stored image.
Definition: VolumeImageT.hh:144
void update_min_max()
min/max scalar value
Definition: VolumeImageT.cc:513
Definition: ScalarGridT.hh:39