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 vec2_type p_ext = (1.0/1.5) * (p_fov +
vec2_type(0.25,0.25));
57 ix = int(floor(p_ext[0] * (_nx - 1) + 0.5));
58 iy = int(floor(p_ext[1] * (_ny - 1) + 0.5));
61 vec2_type calc_position(
int ix,
int iy)
const 63 vec2_type p_ext(
double(ix) / (_nx - 1),
double(iy) / (_ny - 1));
64 return (1.5) * p_ext -
vec2_type(0.25,0.25);
76 _samples.resize(_nx * _ny);
103 {
return _ix_current; }
106 {
return _iy_current; }
110 {
return calc_position(_ix_current,_iy_current); }
116 { _samples.at(_ix_current + _nx * _iy_current).value = q_fov; }
128 return _samples.at(ix + _nx * iy).value;
133 const vec2_type&
get_value(
const vec2_type& p_fov)
const 136 calc_index(p_fov,ix,iy);
138 return _samples[ix + _nx * iy].value;
153 for(
int iy = _ny - 1;iy >= 0;--iy)
155 for(
int ix = 0;ix < _nx;++ix)
157 if((ix == _ix_current) && (iy == _iy_current))
163 cout << (get_sample(ix,iy).done ?
'*' :
'.');
174 for(
int iy = 0;iy < _ny;++iy)
176 for(
int ix = 0;ix < _nx;++ix)
179 p = calc_position(ix,iy);
182 cout << p[0] <<
" " << p[1] <<
" " << d[0] <<
" " << d[1] << std::endl;
190 template <
class VEC2>
193 for(
typename samples_type::iterator i = _samples.begin();i != _samples.end();++i)
200 calc_index(_lc_fov,_ix_lc,_iy_lc);
202 template <
class VEC2>
206 if(_k >= _samples.size())
return false;
212 _ix_current = _ix_lc - kx;
217 _ix_current = _ix_lc + (kx - _ix_lc);
223 _iy_current = _iy_lc - ky;
228 _iy_current = _iy_lc + (ky - _iy_lc);
230 get_sample(_ix_current,_iy_current).done =
true;
234 template <
class VEC2>
237 if(_iy_current == _iy_lc)
239 if(_ix_current == _ix_lc)
241 return calc_position(_ix_current,_iy_current);
243 else if(_ix_current < _ix_lc)
245 return get_value(_ix_current + 1,_iy_current);
249 return get_value(_ix_current - 1,_iy_current);
252 else if(_iy_current < _iy_lc)
254 return get_value(_ix_current,_iy_current + 1);
258 return get_value(_ix_current,_iy_current - 1);
int get_iy_current() const
Current y-position while painting.
Definition: ldpk_lookup_table.h:105
bool next()
False means no value to be generated, loop is done. See example.
Definition: ldpk_lookup_table.h:203
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:151
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:142
The namespace of (most of the) things related to the Lens Distortion Plugin Kit.
Definition: ldpk.h:180
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:102
void reset()
Use reset() and next() to build a loop for generating positions. See example.
Definition: ldpk_lookup_table.h:191
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:133
void init(int nx, int ny)
Initialize a grid with nx * ny sample points. Implies reset().
Definition: ldpk_lookup_table.h:72
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:235
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:126
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:82
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:109
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:172
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:115