58 #define ACG_BSPLINESURFACENODET_C 62 #include "BSplineSurfaceNodeT.hh" 63 #include <ACG/GL/gl.hh> 64 #include <ACG/GL/GLError.hh> 65 #include <ACG/GL/IRenderer.hh> 66 #include <ACG/Utils/VSToolsT.hh> 79 template <
class BSplineSurfaceType>
84 for (
unsigned int i = 0; i < bsplineSurface_.n_control_points_m(); ++i)
86 for (
unsigned int j = 0; j < bsplineSurface_.n_control_points_n(); ++j)
88 _bbMin.
minimize(bsplineSurface_(i,j));
89 _bbMax.
maximize(bsplineSurface_(i,j));
96 template <
class BSplineSurfaceType>
119 template <
class BSplineSurfaceType>
125 if ( bspline_selection_draw_mode_ == CONTROLPOINT
126 && controlPointSelectionTexture_valid_ ==
false)
127 updateControlPointSelectionTexture(_state);
128 if ( bspline_selection_draw_mode_ == KNOTVECTOR
129 && knotVectorSelectionTexture_valid_ ==
false)
130 updateKnotVectorSelectionTexture(_state);
147 if ( props->
textured() && arb_texture_idx_)
150 if (props->primitive() == DrawModes::PRIMITIVE_POLYGON || props->primitive() == DrawModes::PRIMITIVE_WIREFRAME)
158 if (props->primitive() == DrawModes::PRIMITIVE_WIREFRAME)
159 ro.fillMode = GL_LINE;
161 ro.fillMode = GL_FILL;
163 GLenum roPrimitives = GL_TRIANGLES;
165 #ifdef GL_ARB_tessellation_shader
168 if (tessellationMode)
172 if (!controlPointTex_.is_valid())
175 ro.
shaderDesc.tessControlTemplateFile =
"BSpline/tesscontrol_lod.glsl";
176 ro.
shaderDesc.tessEvaluationTemplateFile =
"BSpline/tesseval_lod.glsl";
181 shaderMacro.sprintf(
"#define BSPLINE_DEGREE_U %i", bsplineSurface_.degree_m());
184 shaderMacro.sprintf(
"#define BSPLINE_DEGREE_V %i", bsplineSurface_.degree_n());
187 shaderMacro.sprintf(
"#define BSPLINE_KNOTVEC_U %i", bsplineSurface_.degree_m() * 2 + 1);
190 shaderMacro.sprintf(
"#define BSPLINE_KNOTVEC_V %i", bsplineSurface_.degree_n() * 2 + 1);
198 ro.
setUniform(
"uvRange",
Vec4f(bsplineSurface_.loweru(), bsplineSurface_.upperu(),
199 bsplineSurface_.lowerv(), bsplineSurface_.upperv()));
205 roPrimitives = GL_PATCHES;
208 if (tessellationMode)
212 ro.glDrawElements(roPrimitives, surfaceIndexCount_, GL_UNSIGNED_INT, 0);
220 if (render_control_net_)
223 updateControlNetMesh();
224 updateControlNetMeshSel();
238 if (controlNetSelIndices_)
240 ro.
name =
"BSplineSurface_ControlPointSel";
244 Vec4f selColor = generateHighlightColor(controlnet_color_);
245 ro.emissive =
Vec3f(selColor[0], selColor[1], selColor[2]);
249 ro.glDrawElements(GL_POINTS, controlNetSelIndices_, GL_UNSIGNED_INT, 0);
256 ro.
name =
"BSplineSurface_ControlPoint";
259 ro.emissive =
Vec3f(controlnet_color_[0], controlnet_color_[1], controlnet_color_[2]);
261 GLsizei numPoints = bsplineSurface_.n_control_points_m() * bsplineSurface_.n_control_points_n();
262 ro.glDrawArrays(GL_POINTS, 0, numPoints);
271 ro.
name =
"BSplineSurface_ControlNetLines";
276 ro.glDrawElements(GL_LINES, controlNetLineIndices_, GL_UNSIGNED_INT, 0);
286 template <
class BSplineSurfaceType>
293 glPushAttrib(GL_ENABLE_BIT);
296 if ( bspline_selection_draw_mode_ == CONTROLPOINT
297 && controlPointSelectionTexture_valid_ ==
false)
298 updateControlPointSelectionTexture(_state);
299 if ( bspline_selection_draw_mode_ == KNOTVECTOR
300 && knotVectorSelectionTexture_valid_ ==
false)
301 updateKnotVectorSelectionTexture(_state);
308 render( _state,
false);
313 glPushAttrib(GL_ENABLE_BIT);
318 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
320 render( _state,
false);
322 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
331 clear_color[3] = 1.0;
336 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
341 render( _state,
true);
345 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
349 render( _state,
false);
352 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
366 render( _state,
true);
381 render( _state,
true);
395 render( _state,
true);
411 render( _state,
true);
426 arb_texture_used_ =
true;
427 drawTexturedSurface(_state, arb_texture_idx_ );
428 arb_texture_used_ =
false;
439 template <
class BSplineSurfaceType>
445 if (render_control_net_)
447 if (bspline_draw_mode_ == NORMAL)
448 drawControlNet(_state);
449 else if (bspline_draw_mode_ == FANCY)
450 drawFancyControlNet(_state);
454 if (render_bspline_surface_)
456 if (bspline_selection_draw_mode_ == NONE)
457 drawSurface(_state, _fill);
458 else if (bspline_selection_draw_mode_ == CONTROLPOINT)
459 drawTexturedSurface(_state, cp_selection_texture_idx_);
460 else if (bspline_selection_draw_mode_ == KNOTVECTOR)
461 drawTexturedSurface(_state, knot_selection_texture_idx_);
467 template <
class BSplineSurfaceType>
477 surfaceDecl_.activateFixedFunction();
480 glDrawElements(GL_TRIANGLES, surfaceIndexCount_, GL_UNSIGNED_INT, 0);
482 surfaceDecl_.deactivateFixedFunction();
484 surfaceIBO_.unbind();
485 surfaceVBO_.unbind();
490 template <
class BSplineSurfaceType>
495 glPushAttrib(GL_ALL_ATTRIB_BITS);
502 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
503 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
505 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
506 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
509 if( arb_texture_used_ )
511 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
512 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
516 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
520 drawSurface( _state);
530 template <
class BSplineSurfaceType>
540 glPushAttrib(GL_ALL_ATTRIB_BITS);
548 updateControlNetMesh();
549 updateControlNetMeshSel();
552 controlNetVBO_.bind();
553 controlNetDecl_.activateFixedFunction();
558 if (controlNetSelIndices_)
560 glColor(generateHighlightColor(controlnet_color_));
564 controlNetSelIBO_.bind();
565 glDrawElements(GL_POINTS, controlNetSelIndices_, GL_UNSIGNED_INT, 0);
572 glPointSize(point_size_old + 4);
574 GLsizei numControlPoints = bsplineSurface_.n_control_points_m() * bsplineSurface_.n_control_points_n();
575 glDrawArrays(GL_POINTS, 0, numControlPoints);
577 glPointSize((
int)point_size_old);
618 glLineWidth(line_width_old+2.0);
620 controlNetLineIBO_.bind();
621 glDrawElements(GL_LINES, controlNetLineIndices_, GL_UNSIGNED_INT, 0);
625 controlNetDecl_.deactivateFixedFunction();
626 controlNetLineIBO_.unbind();
627 controlNetVBO_.unbind();
630 glLineWidth(line_width_old);
637 template <
class BSplineSurfaceType>
647 glPushAttrib(GL_ALL_ATTRIB_BITS);
651 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
654 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
659 double sphereRadius = _state.
point_size() * 0.05;
662 if( bsplineSurface_.controlpoint_selections_available())
669 glColor(generateHighlightColor(controlnet_color_));
672 for (
unsigned int i = 0; i < bsplineSurface_.n_control_points_m(); ++i)
674 for (
unsigned int j = 0; j < bsplineSurface_.n_control_points_n(); ++j)
676 if( bsplineSurface_.controlpoint_selection(i, j))
677 draw_sphere(bsplineSurface_(i, j), sphereRadius, _state, fancySphere_);
681 glPointSize(point_size_old);
687 for (
unsigned int i = 0; i < bsplineSurface_.n_control_points_m(); ++i)
688 for (
unsigned int j = 0; j < bsplineSurface_.n_control_points_n(); ++j)
689 draw_sphere(bsplineSurface_(i, j), sphereRadius, _state, fancySphere_);
694 double cylinderRadius = _state.line_width() * 0.05;
699 for (
unsigned int i = 0; i < bsplineSurface_.n_control_points_m(); ++i)
701 for (
int j = 0; j < (int)bsplineSurface_.n_control_points_n() - 1; ++j)
703 Vec3d p = bsplineSurface_(i, j);
704 Vec3d p_next = bsplineSurface_(i, j+1);
705 draw_cylinder(p, p_next - p, cylinderRadius, _state);
709 for (
int j = 0; j < (int)bsplineSurface_.n_control_points_n(); ++j)
711 for (
int i = 0; i < (int)bsplineSurface_.n_control_points_m() - 1; ++i)
713 Vec3d p = bsplineSurface_(i, j);
714 Vec3d p_next = bsplineSurface_(i+1,j);
715 draw_cylinder(p, p_next - p, cylinderRadius, _state);
727 template <
class BSplineSurfaceType>
732 invalidateSurfaceMesh_ =
true;
733 invalidateControlNetMesh_ =
true;
738 template <
class BSplineSurfaceType>
743 if(pick_texture_idx_ == 0)
744 pick_init_texturing();
752 if(render_control_net_)
754 _state.
pick_set_maximum (bsplineSurface_.n_control_points_m() * bsplineSurface_.n_control_points_n());
755 pick_vertices(_state);
763 pick_surface(_state, 0);
776 _state.
pick_set_maximum (bsplineSurface_.n_control_points_m() * bsplineSurface_.n_control_points_n() + 1);
777 pick_vertices(_state);
778 pick_surface(_state, bsplineSurface_.n_control_points_m() * bsplineSurface_.n_control_points_n());
789 template <
class BSplineSurfaceType>
799 for (
unsigned int i = 0; i < bsplineSurface_.n_control_points_m(); ++i)
801 for (
unsigned int j = 0; j < bsplineSurface_.n_control_points_n(); ++j)
803 _state.
pick_set_name (i * bsplineSurface_.n_control_points_n() + j);
807 int px = round( window_pos[0]);
808 int py = round( window_pos[1]);
810 double l = (_state.
eye() - (
Vec3d)bsplineSurface_(i,j)).norm();
811 double r = l*tan(angle);
814 draw_sphere( bsplineSurface_(i,j), r, _state, sphere_);
821 template <
class BSplineSurfaceType>
826 glPushAttrib(GL_ALL_ATTRIB_BITS);
834 std::cout <<
"[BSplineSurface] pick_spline: \n" 835 <<
"pick_texture_baseidx_ = " << pick_texture_baseidx_
837 <<
", pick_texture_idx_ = " << pick_texture_idx_
843 pick_create_texture( _state);
848 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
849 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
851 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
852 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
854 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
868 template <
class BSplineSurfaceType>
873 bool sampling_mode_backup = adaptive_sampling_;
874 adaptive_sampling_ =
false;
878 drawSurface( _state);
880 adaptive_sampling_ = sampling_mode_backup;
885 template <
class BSplineSurfaceType>
892 _state.
translate( _p0[0], _p0[1], _p0[2]);
894 _sphere->draw(_state,_r);
901 template <
class BSplineSurfaceType>
907 _state.
translate(_p0[0], _p0[1], _p0[2]);
909 Point direction = _axis;
914 direction.normalize();
915 rot_angle = acos((z_axis | direction))*180/M_PI;
916 rot_normal = ((z_axis % direction).normalize());
918 if( fabs( rot_angle ) > 0.0001 && fabs( 180 - rot_angle ) > 0.0001)
919 _state.
rotate(rot_angle,rot_normal[0], rot_normal[1], rot_normal[2]);
921 _state.
rotate(rot_angle,1,0,0);
923 cylinder_->setBottomRadius(_r);
924 cylinder_->setTopRadius(_r);
925 cylinder_->draw(_state,_axis.norm());
932 template <
class BSplineSurfaceType>
937 create_cp_selection_texture(_state);
938 controlPointSelectionTexture_valid_ =
true;
941 invalidateControlNetMeshSel_ =
true;
946 template <
class BSplineSurfaceType>
951 create_knot_selection_texture(_state);
952 knotVectorSelectionTexture_valid_ =
true;
957 template <
class BSplineSurfaceType>
963 glGenTextures( 1, &_texture_idx );
967 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
968 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
970 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
971 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
973 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
980 template <
class BSplineSurfaceType>
985 if (bsplineSurface_.n_knots_m() == 0 || bsplineSurface_.n_knots_n() == 0)
988 if(cp_selection_texture_idx_ == 0)
989 selection_init_texturing(cp_selection_texture_idx_);
991 QImage b(cp_selection_texture_res_, cp_selection_texture_res_, QImage::Format_ARGB32);
993 int degree_m = bsplineSurface_.degree_m();
994 int degree_n = bsplineSurface_.degree_n();
996 int numKnots_m = bsplineSurface_.n_knots_m();
997 int numKnots_n = bsplineSurface_.n_knots_n();
999 Knotvector knotvec_m = bsplineSurface_.get_knotvector_m();
1000 Knotvector knotvec_n = bsplineSurface_.get_knotvector_n();
1002 double minu = bsplineSurface_.get_knot_m( degree_m );
1003 double maxu = bsplineSurface_.get_knot_m( numKnots_m - degree_m -1 );
1004 double diffu = maxu - minu;
1006 double minv = bsplineSurface_.get_knot_n( degree_n );
1007 double maxv = bsplineSurface_.get_knot_n( numKnots_n - degree_n -1 );
1008 double diffv = maxv - minv;
1010 if (diffu == 0.0 || diffv == 0.0 )
1015 for (
int m = 0; m < cp_selection_texture_res_; ++m)
1017 double step_m = (double)m / (
double)cp_selection_texture_res_;
1018 double u = step_m * diffu;
1021 ACG::Vec2i span_u = bsplineSurface_.spanm(u);
1023 if (span_u[0] < 0 || span_u[1] < 0)
1030 for (
int n = 0; n < cp_selection_texture_res_; ++n)
1032 double step_n = double(n) / (double)cp_selection_texture_res_;
1033 double v = step_n * diffv;
1036 ACG::Vec2i span_v = bsplineSurface_.spann(v);
1038 if (span_v[0] < 0 || span_v[1] < 0)
1042 for (
int i = 0; i < degree_m+1; ++i)
1044 int idx_m = span_u[0] + i;
1046 for (
int j = 0; j < degree_n+1; ++j)
1048 int idx_n = span_v[0] + j;
1051 if (bsplineSurface_.controlpoint_selection(idx_m, idx_n))
1052 alpha += bsplineSurface_.basisFunction( knotvec_m, idx_m, degree_m, u)
1053 * bsplineSurface_.basisFunction( knotvec_n, idx_n, degree_n, v);
1058 Vec4f color = surface_color_ * (1.0 - alpha) + surface_highlight_color_ * alpha;
1061 b.setPixel (texelIdx_u, 255-texelIdx_v, qRgba((
int)(color[0]*255.0), (
int)(color[1]*255.0), (
int)(color[2]*255.0), 255));
1073 cp_selection_texture_image_ = QGLWidget::convertToGLFormat( b );
1077 glTexImage2D( GL_TEXTURE_2D,
1078 0, GL_RGBA, cp_selection_texture_image_.width(), cp_selection_texture_image_.height(),
1079 0, GL_RGBA, GL_UNSIGNED_BYTE, cp_selection_texture_image_.bits() );
1084 template <
class BSplineSurfaceType>
1089 if (bsplineSurface_.n_knots_m() == 0 ||bsplineSurface_.n_knots_n() == 0)
1092 if(knot_selection_texture_idx_ == 0)
1093 selection_init_texturing(knot_selection_texture_idx_);
1095 QImage b(knot_selection_texture_res_, knot_selection_texture_res_, QImage::Format_ARGB32);
1097 int degree_m = bsplineSurface_.degree_m();
1098 int degree_n = bsplineSurface_.degree_n();
1100 int numKnots_m = bsplineSurface_.n_knots_m();
1101 int numKnots_n = bsplineSurface_.n_knots_n();
1103 Knotvector knotvec_m = bsplineSurface_.get_knotvector_m();
1104 Knotvector knotvec_n = bsplineSurface_.get_knotvector_n();
1106 double minu = bsplineSurface_.get_knot_m( degree_m );
1107 double maxu = bsplineSurface_.get_knot_m( numKnots_m - degree_m -1 );
1108 double diffu = maxu - minu;
1110 double minv = bsplineSurface_.get_knot_n( degree_n );
1111 double maxv = bsplineSurface_.get_knot_n( numKnots_n - degree_n -1 );
1112 double diffv = maxv - minv;
1114 if (diffu == 0.0 || diffv == 0.0 )
1120 std::vector<bool> selectedKnotSpans_m(numKnots_m,
false);
1121 for (
int i = 0; i < numKnots_m; ++i)
1123 if (bsplineSurface_.get_knotvector_m_ref()->selection(i))
1126 ACG::Vec2i span = bsplineSurface_.spanm(bsplineSurface_.get_knot_m(i));
1128 if (span[0] < 0 || span[1] < 0)
1131 for(
int j = span[0]; j <= span[1]+degree_m; ++j)
1132 selectedKnotSpans_m[j] =
true;
1141 std::vector<bool> selectedKnotSpans_n(numKnots_n,
false);
1142 for (
int i = 0; i < numKnots_n; ++i)
1144 if (bsplineSurface_.get_knotvector_n_ref()->selection(i))
1147 ACG::Vec2i span = bsplineSurface_.spann(bsplineSurface_.get_knot_n(i));
1149 if (span[0] < 0 || span[1] < 0)
1152 for(
int j = span[0]; j <= span[1]+degree_n; ++j)
1153 selectedKnotSpans_n[j] =
true;
1162 for (
int m = 0; m < knot_selection_texture_res_; ++m)
1164 double step_m = (double)m / (
double)knot_selection_texture_res_;
1165 double u = step_m * diffu;
1167 Vec2i interval_m = bsplineSurface_.interval_m(u);
1172 for (
int n = 0; n < knot_selection_texture_res_; ++n)
1174 double step_n = (double)n / (
double)knot_selection_texture_res_;
1175 double v = step_n * diffv;
1177 Vec2i interval_n = bsplineSurface_.interval_n(v);
1180 bool selected_m = (selectedKnotSpans_m[interval_m[0]] && selectedKnotSpans_m[interval_m[1]]);
1181 bool selected_n = (selectedKnotSpans_n[interval_n[0]] && selectedKnotSpans_n[interval_n[1]]);
1184 if (selected_m && selected_n)
1187 color = surface_highlight_color_;
1188 else if ((selected_m && !selected_n) || (!selected_m && selected_n) )
1191 color = surface_highlight_color_ * 0.5 + surface_color_ * 0.5;
1195 color = surface_color_;
1199 b.setPixel (texelIdx_u, 255-texelIdx_v, qRgba((
int)(color[0]*255.0), (
int)(color[1]*255.0), (
int)(color[2]*255.0), 255));
1210 knot_selection_texture_image_ = QGLWidget::convertToGLFormat( b );
1214 glTexImage2D( GL_TEXTURE_2D,
1215 0, GL_RGBA, knot_selection_texture_image_.width(), knot_selection_texture_image_.height(),
1216 0, GL_RGBA, GL_UNSIGNED_BYTE, knot_selection_texture_image_.bits() );
1221 template <
class BSplineSurfaceType>
1226 std::cout <<
"[BSplineSurface] pick_init_texturing()" << std::endl;
1228 pick_texture_res_ = 256;
1229 pick_texture_baseidx_ = 0;
1232 glGenTextures( 1, &pick_texture_idx_ );
1236 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
1237 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
1239 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1240 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
1242 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1249 template <
class BSplineSurfaceType>
1254 std::cout <<
"[BSplineSurface] pick_create_texture()" << std::endl;
1256 QImage b(pick_texture_res_, pick_texture_res_, QImage::Format_ARGB32);
1257 QImage texture(pick_texture_res_, pick_texture_res_, QImage::Format_ARGB32);
1261 for(
int i = 0; i < pick_texture_res_; ++i)
1263 for(
int j = pick_texture_res_ - 1; j >= 0; j--)
1266 b.setPixel ( i,j, qRgba((
int)cur_col[0], (
int)cur_col[1], (
int)cur_col[2], (
int)cur_col[3]));
1268 Vec4f testcol =
Vec4f((
float)cur_col[0], (
float)cur_col[1], (
float)cur_col[2], (
float)cur_col[3]);
1269 texture.setPixel ( i,j, qRgba((
int)(testcol[0]*255.0), (
int)(testcol[1]*255.0), (
int)(testcol[2]*255.0), 255));
1303 texture.save(
"surfacePickingTexture.png",
"PNG");
1305 pick_texture_image_ = QGLWidget::convertToGLFormat( b );
1309 glTexImage2D( GL_TEXTURE_2D,
1310 0, GL_RGBA, pick_texture_image_.width(), pick_texture_image_.height(),
1311 0, GL_RGBA, GL_UNSIGNED_BYTE, pick_texture_image_.bits() );
1316 template <
class BSplineSurfaceType>
1321 if(arb_texture_idx_ == 0)
1322 selection_init_texturing(arb_texture_idx_);
1326 arb_texture_repeat_ = _repeat;
1327 arb_texture_repeat_u_ = _u_repeat;
1328 arb_texture_repeat_v_ = _v_repeat;
1330 arb_texture_image_ = QGLWidget::convertToGLFormat( _texture );
1331 int u_res = arb_texture_image_.width();
1332 int v_res = arb_texture_image_.height();
1337 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1338 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1340 glTexImage2D( GL_TEXTURE_2D,
1341 0, GL_RGBA, u_res, v_res,
1342 0, GL_RGBA, GL_UNSIGNED_BYTE, arb_texture_image_.bits() );
1350 template <
class BSplineSurfaceType>
1355 float c1 = _color[0]*1.5;
1356 c1 = c1 > 255.0 ? 255 : c1;
1358 float c2 = _color[1]*1.5;
1359 c2 = c2 > 255.0 ? 255 : c2;
1361 float c3 = _color[2]*1.5;
1362 c3 = c3 > 255.0 ? 255 : c3;
1364 return Vec4f( c1, c2, c3, _color[3]);
1369 template <
class BSplineSurfaceType>
1374 if (!invalidateSurfaceMesh_)
1387 const bool provideDebugInfo =
false;
1389 if (!surfaceDecl_.getNumElements())
1395 if (provideDebugInfo)
1405 int numU = _vertexCountU,
1406 numV = _vertexCountV;
1408 GLsizeiptr vboSize = numU * numV * surfaceDecl_.getVertexStride();
1409 std::vector<float> vboData(vboSize / 4);
1412 int elementOffset = 0;
1414 for (
int i = 0; i < numU; ++i)
1417 float u01 = float(i) / float(numU - 1);
1420 float u = (1 - u01) * bsplineSurface_.loweru() + u01 * bsplineSurface_.upperu();
1422 for (
int k = 0; k < numV; ++k)
1425 float v01 = float(k) / float(numV - 1);
1428 float v = (1 - v01) * bsplineSurface_.lowerv() + v01 * bsplineSurface_.upperv();
1432 bsplineSurface_.surfacePointNormal(pos, normal, u, v);
1435 for (
int m = 0; m < 3; ++m)
1436 vboData[elementOffset++] =
float(pos[m]);
1439 for (
int m = 0; m < 3; ++m)
1440 vboData[elementOffset++] =
float(normal[m]);
1443 vboData[elementOffset++] = u01;
1444 vboData[elementOffset++] = v01;
1447 if (provideDebugInfo)
1450 Vec2i span_u = bsplineSurface_.spanm(u);
1451 Vec2i span_v = bsplineSurface_.spann(u);
1452 vboData[elementOffset++] = span_u[1];
1453 vboData[elementOffset++] = span_v[1];
1455 std::vector<typename Point::value_type> bvu(std::max(4, bsplineSurface_.degree_m() + 1), 0);
1456 std::vector<typename Point::value_type> bvv(std::max(4, bsplineSurface_.degree_n() + 1), 0);
1457 bsplineBasisFunctions<typename Point::value_type>(bvu, span_u, u, bsplineSurface_.get_knotvector_m().getKnotvector());
1458 bsplineBasisFunctions<typename Point::value_type>(bvv, span_v, v, bsplineSurface_.get_knotvector_n().getKnotvector());
1460 for (
int m = 0; m < 4; ++m) vboData[elementOffset++] = bvu[m];
1461 for (
int m = 0; m < 4; ++m) vboData[elementOffset++] = bvv[m];
1467 surfaceVBO_.upload(vboSize, &vboData[0], GL_STATIC_DRAW);
1474 int numIndices = (numU - 1) * (numV - 1) * 6;
1475 std::vector<int> iboData(numIndices);
1480 for (
int k = 0; k < numV - 1; ++k)
1482 for (
int i = 0; i < numU - 1; ++i)
1492 iboData[idxOffset++] = k * numU + i;
1493 iboData[idxOffset++] = (k+1) * numU + i;
1494 iboData[idxOffset++] = (k+1) * numU + i + 1;
1496 iboData[idxOffset++] = k * numU + i;
1497 iboData[idxOffset++] = (k+1) * numU + i+1;
1498 iboData[idxOffset++] = k * numU + i + 1;
1503 surfaceIBO_.upload(numIndices * 4, &iboData[0], GL_STATIC_DRAW);
1506 surfaceIndexCount_ = numIndices;
1509 invalidateSurfaceMesh_ =
false;
1514 template <
class BSplineSurfaceType>
1519 if (!invalidateControlNetMesh_)
1525 if (!controlNetDecl_.getNumElements())
1528 int numU = bsplineSurface_.n_control_points_m(),
1529 numV = bsplineSurface_.n_control_points_n();
1532 GLsizeiptr vboSize = bsplineSurface_.n_control_points_m() * bsplineSurface_.n_control_points_n() * controlNetDecl_.getVertexStride();
1533 std::vector<float> vboData(vboSize / 4);
1536 int elementOffset = 0;
1538 for (
int k = 0; k < numV; ++k)
1540 for (
int i = 0; i < numU; ++i)
1542 Point pt = bsplineSurface_.get_control_point(i, k);
1543 for (
int m = 0; m < 3; ++m)
1544 vboData[elementOffset++] = pt[m];
1549 controlNetVBO_.upload(vboSize, &vboData[0], GL_STATIC_DRAW);
1557 int numIndices = 2 *( (numU - 1) * (numV) + (numU) * (numV - 1) );
1558 std::vector<int> iboData(numIndices);
1564 for (
int k = 0; k < numV; ++k)
1566 for (
int i = 0; i < numU - 1; ++i)
1568 iboData[idxOffset++] = k * numU + i;
1569 iboData[idxOffset++] = k * numU + i + 1;
1574 for (
int k = 0; k < numV - 1; ++k)
1576 for (
int i = 0; i < numU; ++i)
1578 iboData[idxOffset++] = k * numU + i;
1579 iboData[idxOffset++] = (k+1) * numU + i;
1584 controlNetLineIBO_.upload(numIndices * 4, &iboData[0], GL_STATIC_DRAW);
1587 controlNetLineIndices_ = numIndices;
1590 invalidateControlNetMesh_ =
false;
1596 template <
class BSplineSurfaceType>
1601 if (!invalidateControlNetMeshSel_)
1604 controlNetSelIBO_.del();
1606 if (bsplineSurface_.controlpoint_selections_available())
1608 int numU = bsplineSurface_.n_control_points_m(),
1609 numV = bsplineSurface_.n_control_points_n();
1613 for (
int k = 0; k < numV; ++k)
1615 for (
int i = 0; i < numU; ++i)
1617 if (bsplineSurface_.controlpoint_selection(i, k))
1623 controlNetSelIndices_ = numSel;
1629 std::vector<int> iboData(numSel);
1631 for (
int k = 0; k < numV; ++k)
1633 for (
int i = 0; i < numU; ++i)
1635 if (bsplineSurface_.controlpoint_selection(i, k))
1639 iboData[numSel++] = k * numU + i;
1644 controlNetSelIBO_.upload(numSel * 4, &iboData[0], GL_STATIC_DRAW);
1648 invalidateControlNetMeshSel_ =
false;
1653 template <
class BSplineSurfaceType>
1658 const size_t knotBufSizeU = bsplineSurface_.get_knots_m().size();
1659 const size_t knotBufSizeV = bsplineSurface_.get_knots_n().size();
1661 const size_t numControlPointsU = bsplineSurface_.n_control_points_m();
1662 const size_t numControlPointsV = bsplineSurface_.n_control_points_n();
1667 std::vector<float> knotBufU(knotBufSizeU);
1669 for (
size_t i = 0; i < knotBufSizeU; ++i)
1670 knotBufU[i] =
float(bsplineSurface_.get_knot_m(i));
1672 knotTexBufferU_.setBufferData(knotBufSizeU * 4, &knotBufU[0], GL_R32F);
1677 std::vector<float> knotBufV(knotBufSizeV);
1679 for (
size_t i = 0; i < knotBufSizeV; ++i)
1680 knotBufV[i] =
float(bsplineSurface_.get_knot_n(i));
1682 knotTexBufferV_.setBufferData(knotBufSizeV * 4, &knotBufV[0], GL_R32F);
1686 #ifdef GL_VERSION_3_0 1688 const size_t controlPointBufSize = numControlPointsU * numControlPointsV;
1690 if (controlPointBufSize)
1692 std::vector<float> controlPointBuf(controlPointBufSize * 3);
1694 for (
size_t y = 0; y < numControlPointsV; ++y)
1696 for (
size_t x = 0; x < numControlPointsU; ++x)
1698 Point cp = bsplineSurface_.get_control_point(x, y);
1699 controlPointBuf[(y * numControlPointsU + x) * 3 + 0] = cp[0];
1700 controlPointBuf[(y * numControlPointsU + x) * 3 + 1] = cp[1];
1701 controlPointBuf[(y * numControlPointsU + x) * 3 + 2] = cp[2];
1705 controlPointTex_.bind();
1706 controlPointTex_.parameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1707 controlPointTex_.parameter(GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1708 controlPointTex_.setData(0, GL_RGB32F, numControlPointsU, numControlPointsV, GL_RGB, GL_FLOAT, &controlPointBuf[0]);
VectorT< float, 2 > Vec2f
static void bindTexture(GLenum _target, GLuint _buffer)
replaces glBindTexture, supports locking
unsigned int pick_current_index() const
Returns the current color picking index (can be used for caching)
void pick_create_texture(GLState &_state)
create texture image
const Vec4f & clear_color() const
get background color
Vec3d eye() const
get eye point
DrawMode SOLID_SMOOTH_SHADED
draw smooth shaded (Gouraud shaded) faces (requires halfedge normals)
void addTexture(const Texture &_t)
adds a texture to stage RenderObjects::numTextures()
void glColor(const Vec3f &_v)
Wrapper: glColor for Vec3f.
void updateTexBuffers()
update texture resources for gpu-based spline evaluation
DrawMode HIDDENLINE
draw hidden line (2 rendering passes needed)
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
DrawModeProperties stores a set of properties that defines, how to render an object.
VectorT< float, 4 > Vec4f
void setupShaderGenFromDrawmode(const SceneGraph::DrawModes::DrawModeProperties *_props)
Fills out ShaderGenDesc parameters based on Drawmode properties.
DrawMode WIREFRAME
draw wireframe
void push_modelview_matrix()
push modelview matrix
void create_knot_selection_texture(GLState &_state)
creates texture to put onto nurbs curve for visualization of knotvector selection ...
bool textured() const
Is texturing enabled?
GLuint indexBuffer
Use vertex array object.
defined by user via VertexElement::shaderInputName_
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
Vec4uc pick_get_name_color(unsigned int _idx)
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat)
create render objects
void pick(GLState &_state, PickTarget _target)
picking
int viewport_width() const
get viewport width
void set_arb_texture(const QImage &_texture, bool _repeat=false, float _u_repeat=1.0f, float _v_repeat=1.0f)
use arbitrary texture (in SOLID_TEXTURED mode)
unsigned int patchVertices
patch size if primitiveMode is GL_PATCHES for rendering with tessellation shaders ...
void selection_init_texturing(GLuint &_texture_idx)
generate index and setup texture parameters for selection visualization
DrawMode POINTS
draw unlighted points using the default base color
Vec3d project(const Vec3d &_point) const
project point in world coordinates to window coordinates
PickTarget
What target to use for picking.
bool openGLVersion(const int _major, const int _minor)
size_t getNumLayers() const
returns the layer count
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
static void enable(GLenum _cap)
replaces glEnable, but supports locking
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
DrawMode SOLID_TEXTURED
draw textured faces
VectorT< float, 3 > Vec3f
const Vec4f & base_color() const
get base color (used when lighting is off)
float point_size() const
get point size
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode)
draw lines and normals
DrawModes::DrawMode availableDrawModes() const
return available draw modes
void translate(double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
translate by (_x, _y, _z)
virtual void addRenderObject(RenderObject *_renderObject)
Callback for the scenegraph nodes, which send new render objects via this function.
void resetPointRendering()
Reset shader template names blocked by point rendering.
DrawMode SOLID_PHONG_SHADED
draw phong shaded faces
bool pick_set_maximum(unsigned int _idx)
Set the maximal number of primitives/components of your object.
void setupPointRendering(float _pointSize, const Vec2f &_screenSize)
Setup rendering of circle points.
void setUniform(const char *_name, GLint _value)
set values for int uniforms
std::string name
Name for logging.
const DrawModeProperties * getLayer(unsigned int _i) const
returns the property set at layer i
static void depthRange(GLclampd _zNear, GLclampd _zFar)
replaces glDepthRange, supports locking
static void disable(GLenum _cap)
replaces glDisable, but supports locking
Namespace providing different geometric functions concerning angles.
picks verices (may not be implemented for all nodes)
Pick spline curve or surface (picks u or u,v coords respectively)
void setupLineRendering(float _lineWidth, const Vec2f &_screenSize)
Setup rendering of thick lines.
void pop_modelview_matrix()
pop modelview matrix
void pick_set_name(unsigned int _idx)
sets the current name/color (like glLoadName(_idx))
void rotate(double _angle, double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
rotate around axis (_x, _y, _z) by _angle
DrawMode SOLID_ENV_MAPPED
draw environment mapped
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())
DrawMode SOLID_1DTEXTURED
draw textured faces
void updateSurfaceMesh(int _vertexCountU=50, int _vertexCountV=50)
update vertex + index buffer of surface mesh
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax)
update bounding box
void set_base_color(const Vec4f &_col)
set base color (used when lighting is off)
pick any of the prior targets (should be implemented for all nodes)
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
int viewport_height() const
get viewport height
float line_width() const
get line width
void updateControlNetMeshSel()
update index buffer of selected control points
Interface class between scenegraph and renderer.
void pick_init_texturing()
generate index and setup texture parameters
VectorT< double, 3 > Vec3d
picks faces (should be implemented for all nodes)
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
void updateControlNetMesh()
update vertex + index buffer of control net mesh
ShaderGenDesc shaderDesc
Drawmode and other shader params.
void updateGeometry()
update vertex buffer for rendering
void create_cp_selection_texture(GLState &_state)
creates texture to put onto nurbs curve for visualization of control point selection ...
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
Vec3d viewing_direction() const
get viewing ray