Go to the documentation of this file.00001
00010
00011
00012
00013 #pragma once
00014
00015 #ifndef WIN32
00016 #pragma interface
00017 #endif // WIN32
00018
00019 #include <string>
00020 #include "cube.h"
00021
00022
00023
00025 class data_access
00026
00027 {
00028 public :
00029 Level _max_level;
00030 real _iso_val;
00031 float _sx ;
00032 float _sy ;
00033 float _sz ;
00034
00035
00036 public :
00038 data_access( Level max_level_ = 4, real iso_val_ = 0.0 ) : _max_level(max_level_), _iso_val(iso_val_), _sx(1.0f), _sy(1.0f), _sz(1.0f) {}
00040 virtual ~data_access() {}
00042 virtual bool need_refine( const Cube &c ) = 0 ;
00044 virtual real value_at ( const Cube &c ) = 0 ;
00046 virtual void interpolate( real ci, real cj, const Point &pi, const Point &pj, Point &p )
00047 {
00048 real u = ( ci ) / ( ci - cj ) ;
00049 p = ((1-u)*pi) + (u*pj) ;
00050 }
00051 } ;
00052
00053
00054
00055
00056
00057 #ifndef RAND_THRES
00058 # define RAND_THRES 0.2
00059 #endif // RAND_THRES
00060
00061
00063 class data_rand : public data_access
00064
00065 {
00066 public:
00068 bool need_refine( const Cube &c )
00069 {
00070 int l = c.lv() ;
00071 if( l < 2 ) return true ;
00072 if( l >= _max_level ) return false ;
00073 return value_at(c) > RAND_THRES ;
00074 }
00075
00077 real value_at( const Cube &c ) { return ( (real)rand() ) / ( RAND_MAX >> 1 ) - 1.0 ; }
00078
00080 void interpolate( real ci, real cj, const Point &pi, const Point &pj, Point &p )
00081 {
00082 real u = ( (real)rand() ) / ( RAND_MAX ) ;
00083 p = ((1-u)*pi) + (u*pj) ;
00084 }
00085
00086
00087
00088 public:
00090 data_rand( Level max_level_ ) : data_access(max_level_) {}
00092 virtual ~data_rand() {}
00093 } ;
00094
00095
00096
00097
00098 #include "fptypes.h"
00099 #include "fparser.h"
00100
00101
00103 class data_func : public data_access
00104
00105 {
00106 public:
00108 std::string _formula ;
00109
00110 protected:
00111 double _v[3] ;
00112 FunctionParser _parser ;
00113
00114 protected:
00115 void parse() ;
00116
00117 public:
00119 bool need_refine( const Cube &c ) ;
00120
00122 real value_at( const Cube &c )
00123 {
00124 if( _parser.GetParseErrorType() != FunctionParser::FP_NO_ERROR ) return false ;
00125 _v[X] = c.cx() ;
00126 _v[Y] = c.cy() ;
00127 _v[Z] = c.cz() ;
00128 real v = _parser.Eval(_v) - _iso_val ;
00129 if( _parser.EvalError() ) return -1.0 ;
00130 return v ;
00131 }
00132
00134 void interpolate( real ci, real cj, const Point &pi, const Point &pj, Point &p ) ;
00135
00136
00137
00138 public:
00140 data_func( Level max_level_, real iso_val_, const std::string &formula_ ) : data_access(max_level_,iso_val_), _formula(formula_) { parse() ; }
00142 virtual ~data_func() {}
00143 } ;
00144
00145
00146
00147
00148
00149
00151 class data_file : public data_access
00152
00153 {
00154 public:
00155 uint _size_x ;
00156 uint _size_y ;
00157 uint _size_z ;
00158
00159 protected:
00160 float *_data ;
00161 uint _size_yz ;
00162 uint _max_size ;
00165 public:
00166 bool load_data ( const char *fn ) ;
00167 bool has_data ( uint i, uint j, uint k ) { return (i < _size_x) && (j < _size_y) && (k < _size_z) ; }
00168 float get_data ( uint i, uint j, uint k ) { return _data[ k + j*_size_z + i*_size_yz] - _iso_val ; }
00169
00171 bool need_refine( const Cube &c ) ;
00173 real value_at( const Cube &c )
00174 {
00175 uint i = (uint)(c.cx()*_max_size) ;
00176 uint j = (uint)(c.cy()*_max_size) ;
00177 uint k = (uint)(c.cz()*_max_size) ;
00178 if( has_data(i,j,k) ) return (real)get_data(i,j,k) ;
00179 return -1.0 ;
00180 }
00181
00182
00183
00184
00185 public:
00187 data_file( Level max_level_, real iso_val_, const char *fn ) : data_access(max_level_,iso_val_), _data((float*)NULL) { load_data( fn ) ; }
00189 virtual ~data_file() {}
00190 } ;
00191