1 #ifndef ldpk_lookup_table_sdv
2 #define ldpk_lookup_table_sdv
26 sample_type():done(
false)
30 typedef typename std::vector<sample_type> samples_type;
32 samples_type _samples;
40 int _ix_current,_iy_current;
42 void clip_index(
int& ix,
int& iy)
const
45 if(ix >= _nx) ix = _nx - 1;
47 if(iy >= _ny) iy = _ny - 1;
49 const sample_type& get_sample(
int ix,
int iy)
const
50 {
return _samples.at(ix + _nx * iy); }
51 sample_type& get_sample(
int ix,
int iy)
52 {
return _samples.at(ix + _nx * iy); }
54 void calc_index(
const vec2_type& p_fov,
int& ix,
int& iy)
const
56 ix = int(floor(p_fov[0] * (_nx - 1) + 0.5));
57 iy = int(floor(p_fov[1] * (_ny - 1) + 0.5));
60 vec2_type calc_position(
int ix,
int iy)
const
62 return vec2_type(
double(ix) / (_nx - 1),
double(iy) / (_ny - 1));
67 lookup_table():_nx(0),_ny(0),_lc_fov(.5,.5)
74 _samples.resize(_nx * _ny);
101 {
return _ix_current; }
104 {
return _iy_current; }
108 {
return calc_position(_ix_current,_iy_current); }
114 { _samples.at(_ix_current + _nx * _iy_current).value = q_fov; }
126 return _samples.at(ix + _nx * iy).value;
134 calc_index(p_fov,ix,iy);
136 return _samples[ix + _nx * iy].value;
151 for(
int iy = _ny - 1;iy >= 0;--iy)
153 for(
int ix = 0;ix < _nx;++ix)
155 if((ix == _ix_current) && (iy == _iy_current))
161 cout << (get_sample(ix,iy).done ?
'*' :
'.');
172 for(
int iy = 0;iy < _ny;++iy)
174 for(
int ix = 0;ix < _nx;++ix)
177 p = calc_position(ix,iy);
180 cout << p[0] <<
" " << p[1] <<
" " << d[0] <<
" " << d[1] << std::endl;
188 template <
class VEC2>
191 for(
typename samples_type::iterator i = _samples.begin();i != _samples.end();++i)
198 calc_index(_lc_fov,_ix_lc,_iy_lc);
200 template <
class VEC2>
204 if(_k >= _samples.size())
return false;
210 _ix_current = _ix_lc - kx;
215 _ix_current = _ix_lc + (kx - _ix_lc);
221 _iy_current = _iy_lc - ky;
226 _iy_current = _iy_lc + (ky - _iy_lc);
228 get_sample(_ix_current,_iy_current).done =
true;
232 template <
class VEC2>
235 if(_iy_current == _iy_lc)
237 if(_ix_current == _ix_lc)
239 return calc_position(_ix_current,_iy_current);
241 else if(_ix_current < _ix_lc)
243 return get_value(_ix_current + 1,_iy_current);
247 return get_value(_ix_current - 1,_iy_current);
250 else if(_iy_current < _iy_lc)
252 return get_value(_ix_current,_iy_current + 1);
256 return get_value(_ix_current,_iy_current - 1);
int get_iy_current() const
Current y-position while painting.
Definition: ldpk_lookup_table.h:103
bool next()
False means no value to be generated, loop is done. See example.
Definition: ldpk_lookup_table.h:201
Use your own two-dimensional double-valued vector type as VEC2.
Definition: ldpk_lookup_table.h:13
std::ostream & out_state(std::ostream &cout) const
Visualizing the paint algo for debugging purposes.
Definition: ldpk_lookup_table.h:149
const vec2_type & get_initial_value(const vec2_type &p_fov) const
Currently same as get_value(), but we might add more sophisticated methods to generate an initial val...
Definition: ldpk_lookup_table.h:140
VEC2 vec2_type
Your two-dimensional double-valued vector type.
Definition: ldpk_lookup_table.h:19
lookup_table< VEC2 > this_type
This class.
Definition: ldpk_lookup_table.h:17
int get_ix_current() const
Current x-position while painting.
Definition: ldpk_lookup_table.h:100
void reset()
Use reset() and next() to build a loop for generating positions. See example.
Definition: ldpk_lookup_table.h:189
const vec2_type & get_value(const vec2_type &p_fov) const
Once you have built the lookup table, use this method to extract an initial value from lookup table f...
Definition: ldpk_lookup_table.h:131
void init(int nx, int ny)
Initialize a grid with nx * ny sample points. Implies reset().
Definition: ldpk_lookup_table.h:70
vec2_type get_current_initial_value() const
Appropriate initial value for calculating warp at current position obtained with get_p_current_fov()...
Definition: ldpk_lookup_table.h:233
const vec2_type & get_value(int ix, int iy) const
Direct access to table data, raises exception if index is out of bounds.
Definition: ldpk_lookup_table.h:124
void set_lens_center_fov(const vec2_type &lc_fov)
Lens Center in normalized FOV-coordinates. LC is the fixed point of all distortion models...
Definition: ldpk_lookup_table.h:80
vec2_type get_p_current_fov() const
Current position in normalized FOV-coordinates. This is the position you want to warp next...
Definition: ldpk_lookup_table.h:107
std::ostream & out_gnuplot(std::ostream &cout) const
Output as a vector field for gnuplot Use command "plot 'test.i' with vector" or similar in gnuplot...
Definition: ldpk_lookup_table.h:170
void set_q_current_fov(const vec2_type &q_fov)
Set value for given index pair. Index pairs out of bounds will raise an exception. Use this method to insert the warped position from warping p_current_fov.
Definition: ldpk_lookup_table.h:113