8 #include <OpenGLFramework/SpecializedBatches/DisparityInterpolator.hh>
13 DisparityInterpolator::DisparityInterpolator() {
20 fragmentShaderCode_ =
""
21 "uniform sampler2D dispMap;"
23 "uniform int interpType;"
25 "float Interpolate(float left_val, float left_x, "
26 "float right_val, float right_x, float x) {"
27 "if (left_val == right_val) {"
30 "return ((x - left_x) / (right_x - left_x)) * right_val + "
31 "((right_x - x) / (right_x - left_x))*left_val;"
37 "vec2 coord = gl_TexCoord[0];"
38 "float disp = texture2D(dispMap, coord).r;"
40 "if (disp == 0 && step > 0) {"
42 "vec2 coord_left = coord;"
43 "vec2 coord_right = coord;"
45 "float right_val = 0;"
47 "while (coord_right.x < 1.0 && right_val == 0) {"
49 "coord_right.x = coord_right.x+step;"
50 "right_val = texture2D(dispMap, coord_right).r;"
54 "while (coord_left.x > step && left_val == 0) {"
56 "coord_left.x = coord_left.x - step;"
57 "left_val = texture2D(dispMap, coord_left).r;"
61 "if (left_val!=0 && right_val!=0) {"
62 "if (interpType == 0) {"
63 "disp = Interpolate(left_val,coord_left.x,right_val,coord_right.x,coord.x);"
65 "disp = min(left_val,right_val);"
69 "disp = max(left_val,right_val);"
73 "gl_FragColor.r = disp;"
78 DisparityInterpolator::~DisparityInterpolator() {
82 void DisparityInterpolator::SetDisparityMap(
glfTexture2D* dispMap) {
86 void DisparityInterpolator::Init(
unsigned int width,
unsigned int height) {
89 SetViewPort(width_, height_);
90 SetDefaultFloatRenderTarget(width_, height_);
92 CreateFragmentShaderProgram(fragmentShaderCode_);
95 void DisparityInterpolator::Draw() {
97 if (dispMapP_ != NULL) {
98 GetRenderTarget()->ClearDepthBuffer(1.0);
99 GetRenderTarget()->ClearColorBuffer(0, 0, 0, 0);
100 GetBatch_()->SetTexture(dispMapP_, 0);
101 GetShaderProgram_()->SetUniform(
"dispMap", (
int) 0);
102 GetShaderProgram_()->SetUniform(
"step", 1.0f / (
float) width_);
103 GetShaderProgram_()->SetUniform(
"interpType", (
int) interp_type_);
107 BIASERR(
"set disparity map first !");