52 #define ACG_BSPLINESURFACENODET_C 56 #include "BSplineSurfaceNodeT.hh" 57 #include <ACG/GL/gl.hh> 58 #include <ACG/GL/GLError.hh> 59 #include <ACG/GL/IRenderer.hh> 60 #include <ACG/Utils/VSToolsT.hh> 73 template <
class BSplineSurfaceType>
78 for (
unsigned int i = 0; i < bsplineSurface_.n_control_points_m(); ++i)
80 for (
unsigned int j = 0; j < bsplineSurface_.n_control_points_n(); ++j)
82 _bbMin.
minimize(bsplineSurface_(i,j));
83 _bbMax.
maximize(bsplineSurface_(i,j));
90 template <
class BSplineSurfaceType>
113 template <
class BSplineSurfaceType>
119 if ( bspline_selection_draw_mode_ == CONTROLPOINT
120 && controlPointSelectionTexture_valid_ ==
false)
121 updateControlPointSelectionTexture(_state);
122 if ( bspline_selection_draw_mode_ == KNOTVECTOR
123 && knotVectorSelectionTexture_valid_ ==
false)
124 updateKnotVectorSelectionTexture(_state);
141 if ( props->
textured() && arb_texture_idx_)
144 if (props->primitive() == DrawModes::PRIMITIVE_POLYGON || props->primitive() == DrawModes::PRIMITIVE_WIREFRAME)
152 if (props->primitive() == DrawModes::PRIMITIVE_WIREFRAME)
153 ro.fillMode = GL_LINE;
155 ro.fillMode = GL_FILL;
157 GLenum roPrimitives = GL_TRIANGLES;
159 #ifdef GL_ARB_tessellation_shader
162 if (tessellationMode)
166 if (!controlPointTex_.is_valid())
169 ro.
shaderDesc.tessControlTemplateFile =
"BSpline/tesscontrol_lod.glsl";
170 ro.
shaderDesc.tessEvaluationTemplateFile =
"BSpline/tesseval_lod.glsl";
175 shaderMacro.sprintf(
"#define BSPLINE_DEGREE_U %i", bsplineSurface_.degree_m());
178 shaderMacro.sprintf(
"#define BSPLINE_DEGREE_V %i", bsplineSurface_.degree_n());
181 shaderMacro.sprintf(
"#define BSPLINE_KNOTVEC_U %i", bsplineSurface_.degree_m() * 2 + 1);
184 shaderMacro.sprintf(
"#define BSPLINE_KNOTVEC_V %i", bsplineSurface_.degree_n() * 2 + 1);
192 ro.
setUniform(
"uvRange",
Vec4f(bsplineSurface_.loweru(), bsplineSurface_.upperu(),
193 bsplineSurface_.lowerv(), bsplineSurface_.upperv()));
199 roPrimitives = GL_PATCHES;
202 if (tessellationMode)
206 ro.glDrawElements(roPrimitives, surfaceIndexCount_, GL_UNSIGNED_INT, 0);
214 if (render_control_net_)
217 updateControlNetMesh();
218 updateControlNetMeshSel();
232 if (controlNetSelIndices_)
234 ro.
name =
"BSplineSurface_ControlPointSel";
238 Vec4f selColor = generateHighlightColor(controlnet_color_);
239 ro.emissive =
Vec3f(selColor[0], selColor[1], selColor[2]);
243 ro.glDrawElements(GL_POINTS, controlNetSelIndices_, GL_UNSIGNED_INT, 0);
250 ro.
name =
"BSplineSurface_ControlPoint";
253 ro.emissive =
Vec3f(controlnet_color_[0], controlnet_color_[1], controlnet_color_[2]);
255 GLsizei numPoints = bsplineSurface_.n_control_points_m() * bsplineSurface_.n_control_points_n();
256 ro.glDrawArrays(GL_POINTS, 0, numPoints);
265 ro.
name =
"BSplineSurface_ControlNetLines";
270 ro.glDrawElements(GL_LINES, controlNetLineIndices_, GL_UNSIGNED_INT, 0);
280 template <
class BSplineSurfaceType>
287 glPushAttrib(GL_ENABLE_BIT);
290 if ( bspline_selection_draw_mode_ == CONTROLPOINT
291 && controlPointSelectionTexture_valid_ ==
false)
292 updateControlPointSelectionTexture(_state);
293 if ( bspline_selection_draw_mode_ == KNOTVECTOR
294 && knotVectorSelectionTexture_valid_ ==
false)
295 updateKnotVectorSelectionTexture(_state);
302 render( _state,
false);
307 glPushAttrib(GL_ENABLE_BIT);
312 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
314 render( _state,
false);
316 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
325 clear_color[3] = 1.0;
330 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
335 render( _state,
true);
339 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
343 render( _state,
false);
346 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
360 render( _state,
true);
375 render( _state,
true);
389 render( _state,
true);
405 render( _state,
true);
420 arb_texture_used_ =
true;
421 drawTexturedSurface(_state, arb_texture_idx_ );
422 arb_texture_used_ =
false;
433 template <
class BSplineSurfaceType>
439 if (render_control_net_)
441 if (bspline_draw_mode_ == NORMAL)
442 drawControlNet(_state);
443 else if (bspline_draw_mode_ == FANCY)
444 drawFancyControlNet(_state);
448 if (render_bspline_surface_)
450 if (bspline_selection_draw_mode_ == NONE)
451 drawSurface(_state, _fill);
452 else if (bspline_selection_draw_mode_ == CONTROLPOINT)
453 drawTexturedSurface(_state, cp_selection_texture_idx_);
454 else if (bspline_selection_draw_mode_ == KNOTVECTOR)
455 drawTexturedSurface(_state, knot_selection_texture_idx_);
461 template <
class BSplineSurfaceType>
471 surfaceDecl_.activateFixedFunction();
474 glDrawElements(GL_TRIANGLES, surfaceIndexCount_, GL_UNSIGNED_INT, 0);
476 surfaceDecl_.deactivateFixedFunction();
478 surfaceIBO_.unbind();
479 surfaceVBO_.unbind();
484 template <
class BSplineSurfaceType>
489 glPushAttrib(GL_ALL_ATTRIB_BITS);
496 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
497 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
499 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
500 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
503 if( arb_texture_used_ )
505 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
506 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
510 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
514 drawSurface( _state);
524 template <
class BSplineSurfaceType>
534 glPushAttrib(GL_ALL_ATTRIB_BITS);
542 updateControlNetMesh();
543 updateControlNetMeshSel();
546 controlNetVBO_.bind();
547 controlNetDecl_.activateFixedFunction();
552 if (controlNetSelIndices_)
554 glColor(generateHighlightColor(controlnet_color_));
558 controlNetSelIBO_.bind();
559 glDrawElements(GL_POINTS, controlNetSelIndices_, GL_UNSIGNED_INT, 0);
566 glPointSize(point_size_old + 4);
568 GLsizei numControlPoints = bsplineSurface_.n_control_points_m() * bsplineSurface_.n_control_points_n();
569 glDrawArrays(GL_POINTS, 0, numControlPoints);
571 glPointSize((
int)point_size_old);
612 glLineWidth(line_width_old+2.0);
614 controlNetLineIBO_.bind();
615 glDrawElements(GL_LINES, controlNetLineIndices_, GL_UNSIGNED_INT, 0);
619 controlNetDecl_.deactivateFixedFunction();
620 controlNetLineIBO_.unbind();
621 controlNetVBO_.unbind();
624 glLineWidth(line_width_old);
631 template <
class BSplineSurfaceType>
641 glPushAttrib(GL_ALL_ATTRIB_BITS);
645 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
648 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
653 double sphereRadius = _state.
point_size() * 0.05;
656 if( bsplineSurface_.controlpoint_selections_available())
663 glColor(generateHighlightColor(controlnet_color_));
666 for (
unsigned int i = 0; i < bsplineSurface_.n_control_points_m(); ++i)
668 for (
unsigned int j = 0; j < bsplineSurface_.n_control_points_n(); ++j)
670 if( bsplineSurface_.controlpoint_selection(i, j))
671 draw_sphere(bsplineSurface_(i, j), sphereRadius, _state, fancySphere_);
675 glPointSize(point_size_old);
681 for (
unsigned int i = 0; i < bsplineSurface_.n_control_points_m(); ++i)
682 for (
unsigned int j = 0; j < bsplineSurface_.n_control_points_n(); ++j)
683 draw_sphere(bsplineSurface_(i, j), sphereRadius, _state, fancySphere_);
688 double cylinderRadius = _state.line_width() * 0.05;
693 for (
unsigned int i = 0; i < bsplineSurface_.n_control_points_m(); ++i)
695 for (
int j = 0; j < (int)bsplineSurface_.n_control_points_n() - 1; ++j)
697 Vec3d p = bsplineSurface_(i, j);
698 Vec3d p_next = bsplineSurface_(i, j+1);
699 draw_cylinder(p, p_next - p, cylinderRadius, _state);
703 for (
int j = 0; j < (int)bsplineSurface_.n_control_points_n(); ++j)
705 for (
int i = 0; i < (int)bsplineSurface_.n_control_points_m() - 1; ++i)
707 Vec3d p = bsplineSurface_(i, j);
708 Vec3d p_next = bsplineSurface_(i+1,j);
709 draw_cylinder(p, p_next - p, cylinderRadius, _state);
721 template <
class BSplineSurfaceType>
726 invalidateSurfaceMesh_ =
true;
727 invalidateControlNetMesh_ =
true;
732 template <
class BSplineSurfaceType>
737 if(pick_texture_idx_ == 0)
738 pick_init_texturing();
746 if(render_control_net_)
748 _state.
pick_set_maximum (bsplineSurface_.n_control_points_m() * bsplineSurface_.n_control_points_n());
749 pick_vertices(_state);
757 pick_surface(_state, 0);
770 _state.
pick_set_maximum (bsplineSurface_.n_control_points_m() * bsplineSurface_.n_control_points_n() + 1);
771 pick_vertices(_state);
772 pick_surface(_state, bsplineSurface_.n_control_points_m() * bsplineSurface_.n_control_points_n());
783 template <
class BSplineSurfaceType>
793 for (
unsigned int i = 0; i < bsplineSurface_.n_control_points_m(); ++i)
795 for (
unsigned int j = 0; j < bsplineSurface_.n_control_points_n(); ++j)
797 _state.
pick_set_name (i * bsplineSurface_.n_control_points_n() + j);
801 int px = round( window_pos[0]);
802 int py = round( window_pos[1]);
804 double l = (_state.
eye() - (
Vec3d)bsplineSurface_(i,j)).norm();
805 double r = l*tan(angle);
808 draw_sphere( bsplineSurface_(i,j), r, _state, sphere_);
815 template <
class BSplineSurfaceType>
820 glPushAttrib(GL_ALL_ATTRIB_BITS);
828 std::cout <<
"[BSplineSurface] pick_spline: \n" 829 <<
"pick_texture_baseidx_ = " << pick_texture_baseidx_
831 <<
", pick_texture_idx_ = " << pick_texture_idx_
837 pick_create_texture( _state);
842 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
843 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
845 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
846 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
848 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
862 template <
class BSplineSurfaceType>
867 bool sampling_mode_backup = adaptive_sampling_;
868 adaptive_sampling_ =
false;
872 drawSurface( _state);
874 adaptive_sampling_ = sampling_mode_backup;
879 template <
class BSplineSurfaceType>
886 _state.
translate( _p0[0], _p0[1], _p0[2]);
888 _sphere->draw(_state,_r);
895 template <
class BSplineSurfaceType>
901 _state.
translate(_p0[0], _p0[1], _p0[2]);
903 Point direction = _axis;
908 direction.normalize();
909 rot_angle = acos((z_axis | direction))*180/M_PI;
910 rot_normal = ((z_axis % direction).normalize());
912 if( fabs( rot_angle ) > 0.0001 && fabs( 180 - rot_angle ) > 0.0001)
913 _state.
rotate(rot_angle,rot_normal[0], rot_normal[1], rot_normal[2]);
915 _state.
rotate(rot_angle,1,0,0);
917 cylinder_->setBottomRadius(_r);
918 cylinder_->setTopRadius(_r);
919 cylinder_->draw(_state,_axis.norm());
926 template <
class BSplineSurfaceType>
931 create_cp_selection_texture(_state);
932 controlPointSelectionTexture_valid_ =
true;
935 invalidateControlNetMeshSel_ =
true;
940 template <
class BSplineSurfaceType>
945 create_knot_selection_texture(_state);
946 knotVectorSelectionTexture_valid_ =
true;
951 template <
class BSplineSurfaceType>
957 glGenTextures( 1, &_texture_idx );
961 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
962 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
964 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
965 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
967 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
974 template <
class BSplineSurfaceType>
979 if (bsplineSurface_.n_knots_m() == 0 || bsplineSurface_.n_knots_n() == 0)
982 if(cp_selection_texture_idx_ == 0)
983 selection_init_texturing(cp_selection_texture_idx_);
985 QImage b(cp_selection_texture_res_, cp_selection_texture_res_, QImage::Format_ARGB32);
987 int degree_m = bsplineSurface_.degree_m();
988 int degree_n = bsplineSurface_.degree_n();
990 int numKnots_m = bsplineSurface_.n_knots_m();
991 int numKnots_n = bsplineSurface_.n_knots_n();
993 Knotvector knotvec_m = bsplineSurface_.get_knotvector_m();
994 Knotvector knotvec_n = bsplineSurface_.get_knotvector_n();
996 double minu = bsplineSurface_.get_knot_m( degree_m );
997 double maxu = bsplineSurface_.get_knot_m( numKnots_m - degree_m -1 );
998 double diffu = maxu - minu;
1000 double minv = bsplineSurface_.get_knot_n( degree_n );
1001 double maxv = bsplineSurface_.get_knot_n( numKnots_n - degree_n -1 );
1002 double diffv = maxv - minv;
1004 if (diffu == 0.0 || diffv == 0.0 )
1009 for (
int m = 0; m < cp_selection_texture_res_; ++m)
1011 double step_m = (double)m / (
double)cp_selection_texture_res_;
1012 double u = step_m * diffu;
1015 ACG::Vec2i span_u = bsplineSurface_.spanm(u);
1017 if (span_u[0] < 0 || span_u[1] < 0)
1024 for (
int n = 0; n < cp_selection_texture_res_; ++n)
1026 double step_n = double(n) / (double)cp_selection_texture_res_;
1027 double v = step_n * diffv;
1030 ACG::Vec2i span_v = bsplineSurface_.spann(v);
1032 if (span_v[0] < 0 || span_v[1] < 0)
1036 for (
int i = 0; i < degree_m+1; ++i)
1038 int idx_m = span_u[0] + i;
1040 for (
int j = 0; j < degree_n+1; ++j)
1042 int idx_n = span_v[0] + j;
1045 if (bsplineSurface_.controlpoint_selection(idx_m, idx_n))
1046 alpha += bsplineSurface_.basisFunction( knotvec_m, idx_m, degree_m, u)
1047 * bsplineSurface_.basisFunction( knotvec_n, idx_n, degree_n, v);
1052 Vec4f color = surface_color_ * (1.0 - alpha) + surface_highlight_color_ * alpha;
1055 b.setPixel (texelIdx_u, 255-texelIdx_v, qRgba((
int)(color[0]*255.0), (
int)(color[1]*255.0), (
int)(color[2]*255.0), 255));
1067 cp_selection_texture_image_ = QGLWidget::convertToGLFormat( b );
1071 glTexImage2D( GL_TEXTURE_2D,
1072 0, GL_RGBA, cp_selection_texture_image_.width(), cp_selection_texture_image_.height(),
1073 0, GL_RGBA, GL_UNSIGNED_BYTE, cp_selection_texture_image_.bits() );
1078 template <
class BSplineSurfaceType>
1083 if (bsplineSurface_.n_knots_m() == 0 ||bsplineSurface_.n_knots_n() == 0)
1086 if(knot_selection_texture_idx_ == 0)
1087 selection_init_texturing(knot_selection_texture_idx_);
1089 QImage b(knot_selection_texture_res_, knot_selection_texture_res_, QImage::Format_ARGB32);
1091 int degree_m = bsplineSurface_.degree_m();
1092 int degree_n = bsplineSurface_.degree_n();
1094 int numKnots_m = bsplineSurface_.n_knots_m();
1095 int numKnots_n = bsplineSurface_.n_knots_n();
1097 Knotvector knotvec_m = bsplineSurface_.get_knotvector_m();
1098 Knotvector knotvec_n = bsplineSurface_.get_knotvector_n();
1100 double minu = bsplineSurface_.get_knot_m( degree_m );
1101 double maxu = bsplineSurface_.get_knot_m( numKnots_m - degree_m -1 );
1102 double diffu = maxu - minu;
1104 double minv = bsplineSurface_.get_knot_n( degree_n );
1105 double maxv = bsplineSurface_.get_knot_n( numKnots_n - degree_n -1 );
1106 double diffv = maxv - minv;
1108 if (diffu == 0.0 || diffv == 0.0 )
1114 std::vector<bool> selectedKnotSpans_m(numKnots_m,
false);
1115 for (
int i = 0; i < numKnots_m; ++i)
1117 if (bsplineSurface_.get_knotvector_m_ref()->selection(i))
1120 ACG::Vec2i span = bsplineSurface_.spanm(bsplineSurface_.get_knot_m(i));
1122 if (span[0] < 0 || span[1] < 0)
1125 for(
int j = span[0]; j <= span[1]+degree_m; ++j)
1126 selectedKnotSpans_m[j] =
true;
1135 std::vector<bool> selectedKnotSpans_n(numKnots_n,
false);
1136 for (
int i = 0; i < numKnots_n; ++i)
1138 if (bsplineSurface_.get_knotvector_n_ref()->selection(i))
1141 ACG::Vec2i span = bsplineSurface_.spann(bsplineSurface_.get_knot_n(i));
1143 if (span[0] < 0 || span[1] < 0)
1146 for(
int j = span[0]; j <= span[1]+degree_n; ++j)
1147 selectedKnotSpans_n[j] =
true;
1156 for (
int m = 0; m < knot_selection_texture_res_; ++m)
1158 double step_m = (double)m / (
double)knot_selection_texture_res_;
1159 double u = step_m * diffu;
1161 Vec2i interval_m = bsplineSurface_.interval_m(u);
1166 for (
int n = 0; n < knot_selection_texture_res_; ++n)
1168 double step_n = (double)n / (
double)knot_selection_texture_res_;
1169 double v = step_n * diffv;
1171 Vec2i interval_n = bsplineSurface_.interval_n(v);
1174 bool selected_m = (selectedKnotSpans_m[interval_m[0]] && selectedKnotSpans_m[interval_m[1]]);
1175 bool selected_n = (selectedKnotSpans_n[interval_n[0]] && selectedKnotSpans_n[interval_n[1]]);
1178 if (selected_m && selected_n)
1181 color = surface_highlight_color_;
1182 else if ((selected_m && !selected_n) || (!selected_m && selected_n) )
1185 color = surface_highlight_color_ * 0.5 + surface_color_ * 0.5;
1189 color = surface_color_;
1193 b.setPixel (texelIdx_u, 255-texelIdx_v, qRgba((
int)(color[0]*255.0), (
int)(color[1]*255.0), (
int)(color[2]*255.0), 255));
1204 knot_selection_texture_image_ = QGLWidget::convertToGLFormat( b );
1208 glTexImage2D( GL_TEXTURE_2D,
1209 0, GL_RGBA, knot_selection_texture_image_.width(), knot_selection_texture_image_.height(),
1210 0, GL_RGBA, GL_UNSIGNED_BYTE, knot_selection_texture_image_.bits() );
1215 template <
class BSplineSurfaceType>
1220 std::cout <<
"[BSplineSurface] pick_init_texturing()" << std::endl;
1222 pick_texture_res_ = 256;
1223 pick_texture_baseidx_ = 0;
1226 glGenTextures( 1, &pick_texture_idx_ );
1230 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
1231 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
1233 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1234 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
1236 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1243 template <
class BSplineSurfaceType>
1248 std::cout <<
"[BSplineSurface] pick_create_texture()" << std::endl;
1250 QImage b(pick_texture_res_, pick_texture_res_, QImage::Format_ARGB32);
1251 QImage texture(pick_texture_res_, pick_texture_res_, QImage::Format_ARGB32);
1255 for(
int i = 0; i < pick_texture_res_; ++i)
1257 for(
int j = pick_texture_res_ - 1; j >= 0; j--)
1260 b.setPixel ( i,j, qRgba((
int)cur_col[0], (
int)cur_col[1], (
int)cur_col[2], (
int)cur_col[3]));
1262 Vec4f testcol =
Vec4f((
float)cur_col[0], (
float)cur_col[1], (
float)cur_col[2], (
float)cur_col[3]);
1263 texture.setPixel ( i,j, qRgba((
int)(testcol[0]*255.0), (
int)(testcol[1]*255.0), (
int)(testcol[2]*255.0), 255));
1297 texture.save(
"surfacePickingTexture.png",
"PNG");
1299 pick_texture_image_ = QGLWidget::convertToGLFormat( b );
1303 glTexImage2D( GL_TEXTURE_2D,
1304 0, GL_RGBA, pick_texture_image_.width(), pick_texture_image_.height(),
1305 0, GL_RGBA, GL_UNSIGNED_BYTE, pick_texture_image_.bits() );
1310 template <
class BSplineSurfaceType>
1315 if(arb_texture_idx_ == 0)
1316 selection_init_texturing(arb_texture_idx_);
1320 arb_texture_repeat_ = _repeat;
1321 arb_texture_repeat_u_ = _u_repeat;
1322 arb_texture_repeat_v_ = _v_repeat;
1324 arb_texture_image_ = QGLWidget::convertToGLFormat( _texture );
1325 int u_res = arb_texture_image_.width();
1326 int v_res = arb_texture_image_.height();
1331 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1332 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1334 glTexImage2D( GL_TEXTURE_2D,
1335 0, GL_RGBA, u_res, v_res,
1336 0, GL_RGBA, GL_UNSIGNED_BYTE, arb_texture_image_.bits() );
1344 template <
class BSplineSurfaceType>
1349 float c1 = _color[0]*1.5;
1350 c1 = c1 > 255.0 ? 255 : c1;
1352 float c2 = _color[1]*1.5;
1353 c2 = c2 > 255.0 ? 255 : c2;
1355 float c3 = _color[2]*1.5;
1356 c3 = c3 > 255.0 ? 255 : c3;
1358 return Vec4f( c1, c2, c3, _color[3]);
1363 template <
class BSplineSurfaceType>
1368 if (!invalidateSurfaceMesh_)
1381 const bool provideDebugInfo =
false;
1383 if (!surfaceDecl_.getNumElements())
1389 if (provideDebugInfo)
1399 int numU = _vertexCountU,
1400 numV = _vertexCountV;
1402 GLsizeiptr vboSize = numU * numV * surfaceDecl_.getVertexStride();
1403 std::vector<float> vboData(vboSize / 4);
1406 int elementOffset = 0;
1408 for (
int i = 0; i < numU; ++i)
1411 float u01 = float(i) / float(numU - 1);
1414 float u = (1 - u01) * bsplineSurface_.loweru() + u01 * bsplineSurface_.upperu();
1416 for (
int k = 0; k < numV; ++k)
1419 float v01 = float(k) / float(numV - 1);
1422 float v = (1 - v01) * bsplineSurface_.lowerv() + v01 * bsplineSurface_.upperv();
1426 bsplineSurface_.surfacePointNormal(pos, normal, u, v);
1429 for (
int m = 0; m < 3; ++m)
1430 vboData[elementOffset++] =
float(pos[m]);
1433 for (
int m = 0; m < 3; ++m)
1434 vboData[elementOffset++] =
float(normal[m]);
1437 vboData[elementOffset++] = u01;
1438 vboData[elementOffset++] = v01;
1441 if (provideDebugInfo)
1444 Vec2i span_u = bsplineSurface_.spanm(u);
1445 Vec2i span_v = bsplineSurface_.spann(u);
1446 vboData[elementOffset++] = span_u[1];
1447 vboData[elementOffset++] = span_v[1];
1449 std::vector<typename Point::value_type> bvu(std::max(4, bsplineSurface_.degree_m() + 1), 0);
1450 std::vector<typename Point::value_type> bvv(std::max(4, bsplineSurface_.degree_n() + 1), 0);
1451 bsplineBasisFunctions<typename Point::value_type>(bvu, span_u, u, bsplineSurface_.get_knotvector_m().getKnotvector());
1452 bsplineBasisFunctions<typename Point::value_type>(bvv, span_v, v, bsplineSurface_.get_knotvector_n().getKnotvector());
1454 for (
int m = 0; m < 4; ++m) vboData[elementOffset++] = bvu[m];
1455 for (
int m = 0; m < 4; ++m) vboData[elementOffset++] = bvv[m];
1461 surfaceVBO_.upload(vboSize, &vboData[0], GL_STATIC_DRAW);
1468 int numIndices = (numU - 1) * (numV - 1) * 6;
1469 std::vector<int> iboData(numIndices);
1474 for (
int k = 0; k < numV - 1; ++k)
1476 for (
int i = 0; i < numU - 1; ++i)
1486 iboData[idxOffset++] = k * numU + i;
1487 iboData[idxOffset++] = (k+1) * numU + i;
1488 iboData[idxOffset++] = (k+1) * numU + i + 1;
1490 iboData[idxOffset++] = k * numU + i;
1491 iboData[idxOffset++] = (k+1) * numU + i+1;
1492 iboData[idxOffset++] = k * numU + i + 1;
1497 surfaceIBO_.upload(numIndices * 4, &iboData[0], GL_STATIC_DRAW);
1500 surfaceIndexCount_ = numIndices;
1503 invalidateSurfaceMesh_ =
false;
1508 template <
class BSplineSurfaceType>
1513 if (!invalidateControlNetMesh_)
1519 if (!controlNetDecl_.getNumElements())
1522 int numU = bsplineSurface_.n_control_points_m(),
1523 numV = bsplineSurface_.n_control_points_n();
1526 GLsizeiptr vboSize = bsplineSurface_.n_control_points_m() * bsplineSurface_.n_control_points_n() * controlNetDecl_.getVertexStride();
1527 std::vector<float> vboData(vboSize / 4);
1530 int elementOffset = 0;
1532 for (
int k = 0; k < numV; ++k)
1534 for (
int i = 0; i < numU; ++i)
1536 Point pt = bsplineSurface_.get_control_point(i, k);
1537 for (
int m = 0; m < 3; ++m)
1538 vboData[elementOffset++] = pt[m];
1543 controlNetVBO_.upload(vboSize, &vboData[0], GL_STATIC_DRAW);
1551 int numIndices = 2 *( (numU - 1) * (numV) + (numU) * (numV - 1) );
1552 std::vector<int> iboData(numIndices);
1558 for (
int k = 0; k < numV; ++k)
1560 for (
int i = 0; i < numU - 1; ++i)
1562 iboData[idxOffset++] = k * numU + i;
1563 iboData[idxOffset++] = k * numU + i + 1;
1568 for (
int k = 0; k < numV - 1; ++k)
1570 for (
int i = 0; i < numU; ++i)
1572 iboData[idxOffset++] = k * numU + i;
1573 iboData[idxOffset++] = (k+1) * numU + i;
1578 controlNetLineIBO_.upload(numIndices * 4, &iboData[0], GL_STATIC_DRAW);
1581 controlNetLineIndices_ = numIndices;
1584 invalidateControlNetMesh_ =
false;
1590 template <
class BSplineSurfaceType>
1595 if (!invalidateControlNetMeshSel_)
1598 controlNetSelIBO_.del();
1600 if (bsplineSurface_.controlpoint_selections_available())
1602 int numU = bsplineSurface_.n_control_points_m(),
1603 numV = bsplineSurface_.n_control_points_n();
1607 for (
int k = 0; k < numV; ++k)
1609 for (
int i = 0; i < numU; ++i)
1611 if (bsplineSurface_.controlpoint_selection(i, k))
1617 controlNetSelIndices_ = numSel;
1623 std::vector<int> iboData(numSel);
1625 for (
int k = 0; k < numV; ++k)
1627 for (
int i = 0; i < numU; ++i)
1629 if (bsplineSurface_.controlpoint_selection(i, k))
1633 iboData[numSel++] = k * numU + i;
1638 controlNetSelIBO_.upload(numSel * 4, &iboData[0], GL_STATIC_DRAW);
1642 invalidateControlNetMeshSel_ =
false;
1647 template <
class BSplineSurfaceType>
1652 const size_t knotBufSizeU = bsplineSurface_.get_knots_m().size();
1653 const size_t knotBufSizeV = bsplineSurface_.get_knots_n().size();
1660 std::vector<float> knotBufU(knotBufSizeU);
1662 for (
size_t i = 0; i < knotBufSizeU; ++i)
1663 knotBufU[i] =
float(bsplineSurface_.get_knot_m(i));
1665 knotTexBufferU_.setBufferData(knotBufSizeU * 4, &knotBufU[0], GL_R32F);
1670 std::vector<float> knotBufV(knotBufSizeV);
1672 for (
size_t i = 0; i < knotBufSizeV; ++i)
1673 knotBufV[i] =
float(bsplineSurface_.get_knot_n(i));
1675 knotTexBufferV_.setBufferData(knotBufSizeV * 4, &knotBufV[0], GL_R32F);
1679 #ifdef GL_VERSION_3_0 1681 const size_t numControlPointsU = bsplineSurface_.n_control_points_m();
1682 const size_t numControlPointsV = bsplineSurface_.n_control_points_n();
1683 const size_t controlPointBufSize = numControlPointsU * numControlPointsV;
1685 if (controlPointBufSize)
1687 std::vector<float> controlPointBuf(controlPointBufSize * 3);
1689 for (
size_t y = 0; y < numControlPointsV; ++y)
1691 for (
size_t x = 0; x < numControlPointsU; ++x)
1693 Point cp = bsplineSurface_.get_control_point(x, y);
1694 controlPointBuf[(y * numControlPointsU + x) * 3 + 0] = cp[0];
1695 controlPointBuf[(y * numControlPointsU + x) * 3 + 1] = cp[1];
1696 controlPointBuf[(y * numControlPointsU + x) * 3 + 2] = cp[2];
1700 controlPointTex_.bind();
1701 controlPointTex_.parameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1702 controlPointTex_.parameter(GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1703 controlPointTex_.setData(0, GL_RGB32F, numControlPointsU, numControlPointsV, GL_RGB, GL_FLOAT, &controlPointBuf[0]);
void glColor(const Vec3f &_v)
Wrapper: glColor for Vec3f.
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
void pick_init_texturing()
generate index and setup texture parameters
Vec3d viewing_direction() const
get viewing ray
void pop_modelview_matrix()
pop modelview matrix
void setUniform(const char *_name, GLint _value)
set values for int uniforms
defined by user via VertexElement::shaderInputName_
float point_size() const
get point size
picks faces (should be implemented for all nodes)
DrawModes::DrawMode availableDrawModes() const override
return available draw modes
DrawMode SOLID_ENV_MAPPED
draw environment mapped
int viewport_width() const
get viewport width
void addTexture(const Texture &_t)
adds a texture to stage RenderObjects::numTextures()
VectorT< float, 2 > Vec2f
Namespace providing different geometric functions concerning angles.
void updateTexBuffers()
update texture resources for gpu-based spline evaluation
Vec3d project(const Vec3d &_point) const
project point in world coordinates to window coordinates
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax) override
update bounding box
VectorT< float, 4 > Vec4f
void updateControlNetMesh()
update vertex + index buffer of control net mesh
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
const Vec4f & base_color() const
get base color (used when lighting is off)
ShaderGenDesc shaderDesc
Drawmode and other shader params.
size_t pick_current_index() const
Returns the current color picking index (can be used for caching)
void create_knot_selection_texture(GLState &_state)
creates texture to put onto nurbs curve for visualization of knotvector selection ...
void pick(GLState &_state, PickTarget _target) override
picking
DrawMode HIDDENLINE
draw hidden line (2 rendering passes needed)
void updateGeometry()
update vertex buffer for rendering
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
std::string name
Name for logging.
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
Vec4uc pick_get_name_color(size_t _idx)
DrawMode SOLID_SMOOTH_SHADED
draw smooth shaded (Gouraud shaded) faces (requires halfedge normals)
void setupLineRendering(float _lineWidth, const Vec2f &_screenSize)
Setup rendering of thick lines.
void resetPointRendering()
Reset shader template names blocked by point rendering.
PickTarget
What target to use for picking.
void push_modelview_matrix()
push modelview matrix
DrawMode SOLID_PHONG_SHADED
draw phong shaded faces
bool textured() const
Is texturing enabled?
DrawMode SOLID_1DTEXTURED
draw textured faces
VectorT< float, 3 > Vec3f
void setupPointRendering(float _pointSize, const Vec2f &_screenSize)
Setup rendering of circle points.
unsigned int patchVertices
patch size if primitiveMode is GL_PATCHES for rendering with tessellation shaders ...
pick any of the prior targets (should be implemented for all nodes)
bool pick_set_maximum(size_t _idx)
Set the maximal number of primitives/components of your object.
DrawMode SOLID_TEXTURED
draw textured faces
picks verices (may not be implemented for all nodes)
GLuint indexBuffer
Use vertex array object.
int viewport_height() const
get viewport height
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
bool openGLVersion(const int _major, const int _minor, bool _verbose)
void pick_create_texture(GLState &_state)
create texture image
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
DrawMode POINTS
draw unlighted points using the default base color
DrawModeProperties stores a set of properties that defines, how to render an object.
void rotate(double _angle, double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
rotate around axis (_x, _y, _z) by _angle
virtual void addRenderObject(RenderObject *_renderObject)
Callback for the scenegraph nodes, which send new render objects via this function.
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
void selection_init_texturing(GLuint &_texture_idx)
generate index and setup texture parameters for selection visualization
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode) override
draw lines and normals
DrawMode WIREFRAME
draw wireframe
void create_cp_selection_texture(GLState &_state)
creates texture to put onto nurbs curve for visualization of control point selection ...
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat) override
create render objects
void pick_set_name(size_t _idx)
sets the current name/color (like glLoadName(_idx))
void set_base_color(const Vec4f &_col)
set base color (used when lighting is off)
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
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)
Pick spline curve or surface (picks u or u,v coords respectively)
void setupShaderGenFromDrawmode(const SceneGraph::DrawModes::DrawModeProperties *_props)
Fills out ShaderGenDesc parameters based on Drawmode properties.
void updateControlNetMeshSel()
update index buffer of selected control points
static void depthRange(GLclampd _zNear, GLclampd _zFar)
replaces glDepthRange, supports locking
float line_width() const
get line width
const DrawModeProperties * getLayer(unsigned int _i) const
returns the property set at layer i
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())
Interface class between scenegraph and renderer.
static void bindTexture(GLenum _target, GLuint _buffer)
replaces glBindTexture, supports locking
size_t getNumLayers() const
returns the layer count
const Vec4f & clear_color() const
get background color
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
Vec3d eye() const
get eye point
void translate(double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
translate by (_x, _y, _z)
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
VectorT< double, 3 > Vec3d
void updateSurfaceMesh(int _vertexCountU=50, int _vertexCountV=50)
update vertex + index buffer of surface mesh