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";
172 ro.
shaderDesc.macros.push_back(QString(
"#define BSPLINE_DEGREE_U %1").arg(bsplineSurface_.degree_m()));
173 ro.
shaderDesc.macros.push_back(QString(
"#define BSPLINE_DEGREE_V %1").arg(bsplineSurface_.degree_n()));
174 ro.
shaderDesc.macros.push_back(QString(
"#define BSPLINE_KNOTVEC_U %1").arg(bsplineSurface_.degree_m() * 2 + 1));
175 ro.
shaderDesc.macros.push_back(QString(
"#define BSPLINE_KNOTVEC_V %1").arg(bsplineSurface_.degree_n() * 2 + 1));
182 ro.
setUniform(
"uvRange",
Vec4f(bsplineSurface_.loweru(), bsplineSurface_.upperu(),
183 bsplineSurface_.lowerv(), bsplineSurface_.upperv()));
189 roPrimitives = GL_PATCHES;
192 if (tessellationMode)
196 ro.glDrawElements(roPrimitives, surfaceIndexCount_, GL_UNSIGNED_INT, 0);
204 if (render_control_net_)
207 updateControlNetMesh();
208 updateControlNetMeshSel();
222 if (controlNetSelIndices_)
224 ro.
name =
"BSplineSurface_ControlPointSel";
228 Vec4f selColor = generateHighlightColor(controlnet_color_);
229 ro.emissive =
Vec3f(selColor[0], selColor[1], selColor[2]);
233 ro.glDrawElements(GL_POINTS, controlNetSelIndices_, GL_UNSIGNED_INT, 0);
240 ro.
name =
"BSplineSurface_ControlPoint";
243 ro.emissive =
Vec3f(controlnet_color_[0], controlnet_color_[1], controlnet_color_[2]);
245 GLsizei numPoints = bsplineSurface_.n_control_points_m() * bsplineSurface_.n_control_points_n();
246 ro.glDrawArrays(GL_POINTS, 0, numPoints);
255 ro.
name =
"BSplineSurface_ControlNetLines";
260 ro.glDrawElements(GL_LINES, controlNetLineIndices_, GL_UNSIGNED_INT, 0);
270 template <
class BSplineSurfaceType>
277 glPushAttrib(GL_ENABLE_BIT);
280 if ( bspline_selection_draw_mode_ == CONTROLPOINT
281 && controlPointSelectionTexture_valid_ ==
false)
282 updateControlPointSelectionTexture(_state);
283 if ( bspline_selection_draw_mode_ == KNOTVECTOR
284 && knotVectorSelectionTexture_valid_ ==
false)
285 updateKnotVectorSelectionTexture(_state);
292 render( _state,
false);
297 glPushAttrib(GL_ENABLE_BIT);
302 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
304 render( _state,
false);
306 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
315 clear_color[3] = 1.0;
320 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
325 render( _state,
true);
329 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
333 render( _state,
false);
336 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
350 render( _state,
true);
365 render( _state,
true);
379 render( _state,
true);
395 render( _state,
true);
410 arb_texture_used_ =
true;
411 drawTexturedSurface(_state, arb_texture_idx_ );
412 arb_texture_used_ =
false;
423 template <
class BSplineSurfaceType>
429 if (render_control_net_)
431 if (bspline_draw_mode_ == NORMAL)
432 drawControlNet(_state);
433 else if (bspline_draw_mode_ == FANCY)
434 drawFancyControlNet(_state);
438 if (render_bspline_surface_)
440 if (bspline_selection_draw_mode_ == NONE)
441 drawSurface(_state, _fill);
442 else if (bspline_selection_draw_mode_ == CONTROLPOINT)
443 drawTexturedSurface(_state, cp_selection_texture_idx_);
444 else if (bspline_selection_draw_mode_ == KNOTVECTOR)
445 drawTexturedSurface(_state, knot_selection_texture_idx_);
451 template <
class BSplineSurfaceType>
461 surfaceDecl_.activateFixedFunction();
464 glDrawElements(GL_TRIANGLES, surfaceIndexCount_, GL_UNSIGNED_INT, 0);
466 surfaceDecl_.deactivateFixedFunction();
468 surfaceIBO_.unbind();
469 surfaceVBO_.unbind();
474 template <
class BSplineSurfaceType>
479 glPushAttrib(GL_ALL_ATTRIB_BITS);
486 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
487 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
489 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
490 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
493 if( arb_texture_used_ )
495 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
496 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
500 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
504 drawSurface( _state);
514 template <
class BSplineSurfaceType>
524 glPushAttrib(GL_ALL_ATTRIB_BITS);
532 updateControlNetMesh();
533 updateControlNetMeshSel();
536 controlNetVBO_.bind();
537 controlNetDecl_.activateFixedFunction();
542 if (controlNetSelIndices_)
544 glColor(generateHighlightColor(controlnet_color_));
548 controlNetSelIBO_.bind();
549 glDrawElements(GL_POINTS, controlNetSelIndices_, GL_UNSIGNED_INT, 0);
556 glPointSize(point_size_old + 4);
558 GLsizei numControlPoints = bsplineSurface_.n_control_points_m() * bsplineSurface_.n_control_points_n();
559 glDrawArrays(GL_POINTS, 0, numControlPoints);
561 glPointSize((
int)point_size_old);
602 glLineWidth(line_width_old+2.0);
604 controlNetLineIBO_.bind();
605 glDrawElements(GL_LINES, controlNetLineIndices_, GL_UNSIGNED_INT, 0);
609 controlNetDecl_.deactivateFixedFunction();
610 controlNetLineIBO_.unbind();
611 controlNetVBO_.unbind();
614 glLineWidth(line_width_old);
621 template <
class BSplineSurfaceType>
631 glPushAttrib(GL_ALL_ATTRIB_BITS);
635 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
638 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
643 double sphereRadius = _state.
point_size() * 0.05;
646 if( bsplineSurface_.controlpoint_selections_available())
653 glColor(generateHighlightColor(controlnet_color_));
656 for (
unsigned int i = 0; i < bsplineSurface_.n_control_points_m(); ++i)
658 for (
unsigned int j = 0; j < bsplineSurface_.n_control_points_n(); ++j)
660 if( bsplineSurface_.controlpoint_selection(i, j))
661 draw_sphere(bsplineSurface_(i, j), sphereRadius, _state, fancySphere_);
665 glPointSize(point_size_old);
671 for (
unsigned int i = 0; i < bsplineSurface_.n_control_points_m(); ++i)
672 for (
unsigned int j = 0; j < bsplineSurface_.n_control_points_n(); ++j)
673 draw_sphere(bsplineSurface_(i, j), sphereRadius, _state, fancySphere_);
678 double cylinderRadius = _state.line_width() * 0.05;
683 for (
unsigned int i = 0; i < bsplineSurface_.n_control_points_m(); ++i)
685 for (
int j = 0; j < (int)bsplineSurface_.n_control_points_n() - 1; ++j)
687 Vec3d p = bsplineSurface_(i, j);
688 Vec3d p_next = bsplineSurface_(i, j+1);
689 draw_cylinder(p, p_next - p, cylinderRadius, _state);
693 for (
int j = 0; j < (int)bsplineSurface_.n_control_points_n(); ++j)
695 for (
int i = 0; i < (int)bsplineSurface_.n_control_points_m() - 1; ++i)
697 Vec3d p = bsplineSurface_(i, j);
698 Vec3d p_next = bsplineSurface_(i+1,j);
699 draw_cylinder(p, p_next - p, cylinderRadius, _state);
711 template <
class BSplineSurfaceType>
716 invalidateSurfaceMesh_ =
true;
717 invalidateControlNetMesh_ =
true;
722 template <
class BSplineSurfaceType>
727 if(pick_texture_idx_ == 0)
728 pick_init_texturing();
736 if(render_control_net_)
738 _state.
pick_set_maximum (bsplineSurface_.n_control_points_m() * bsplineSurface_.n_control_points_n());
739 pick_vertices(_state);
747 pick_surface(_state, 0);
760 _state.
pick_set_maximum (bsplineSurface_.n_control_points_m() * bsplineSurface_.n_control_points_n() + 1);
761 pick_vertices(_state);
762 pick_surface(_state, bsplineSurface_.n_control_points_m() * bsplineSurface_.n_control_points_n());
773 template <
class BSplineSurfaceType>
783 for (
unsigned int i = 0; i < bsplineSurface_.n_control_points_m(); ++i)
785 for (
unsigned int j = 0; j < bsplineSurface_.n_control_points_n(); ++j)
787 _state.
pick_set_name (i * bsplineSurface_.n_control_points_n() + j);
791 int px = round( window_pos[0]);
792 int py = round( window_pos[1]);
794 double l = (_state.
eye() - (
Vec3d)bsplineSurface_(i,j)).norm();
795 double r = l*tan(angle);
798 draw_sphere( bsplineSurface_(i,j), r, _state, sphere_);
805 template <
class BSplineSurfaceType>
810 glPushAttrib(GL_ALL_ATTRIB_BITS);
818 std::cout <<
"[BSplineSurface] pick_spline: \n" 819 <<
"pick_texture_baseidx_ = " << pick_texture_baseidx_
821 <<
", pick_texture_idx_ = " << pick_texture_idx_
827 pick_create_texture( _state);
832 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
833 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
835 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
836 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
838 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
852 template <
class BSplineSurfaceType>
857 bool sampling_mode_backup = adaptive_sampling_;
858 adaptive_sampling_ =
false;
862 drawSurface( _state);
864 adaptive_sampling_ = sampling_mode_backup;
869 template <
class BSplineSurfaceType>
876 _state.
translate( _p0[0], _p0[1], _p0[2]);
878 _sphere->draw(_state,_r);
885 template <
class BSplineSurfaceType>
891 _state.
translate(_p0[0], _p0[1], _p0[2]);
893 Point direction = _axis;
898 direction.normalize();
899 rot_angle = acos((z_axis | direction))*180/M_PI;
900 rot_normal = ((z_axis % direction).normalize());
902 if( fabs( rot_angle ) > 0.0001 && fabs( 180 - rot_angle ) > 0.0001)
903 _state.
rotate(rot_angle,rot_normal[0], rot_normal[1], rot_normal[2]);
905 _state.
rotate(rot_angle,1,0,0);
907 cylinder_->setBottomRadius(_r);
908 cylinder_->setTopRadius(_r);
909 cylinder_->draw(_state,_axis.norm());
916 template <
class BSplineSurfaceType>
921 create_cp_selection_texture(_state);
922 controlPointSelectionTexture_valid_ =
true;
925 invalidateControlNetMeshSel_ =
true;
930 template <
class BSplineSurfaceType>
935 create_knot_selection_texture(_state);
936 knotVectorSelectionTexture_valid_ =
true;
941 template <
class BSplineSurfaceType>
947 glGenTextures( 1, &_texture_idx );
951 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
952 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
954 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
955 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
957 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
964 template <
class BSplineSurfaceType>
969 if (bsplineSurface_.n_knots_m() == 0 || bsplineSurface_.n_knots_n() == 0)
972 if(cp_selection_texture_idx_ == 0)
973 selection_init_texturing(cp_selection_texture_idx_);
975 QImage b(cp_selection_texture_res_, cp_selection_texture_res_, QImage::Format_ARGB32);
977 int degree_m = bsplineSurface_.degree_m();
978 int degree_n = bsplineSurface_.degree_n();
980 int numKnots_m = bsplineSurface_.n_knots_m();
981 int numKnots_n = bsplineSurface_.n_knots_n();
983 Knotvector knotvec_m = bsplineSurface_.get_knotvector_m();
984 Knotvector knotvec_n = bsplineSurface_.get_knotvector_n();
986 double minu = bsplineSurface_.get_knot_m( degree_m );
987 double maxu = bsplineSurface_.get_knot_m( numKnots_m - degree_m -1 );
988 double diffu = maxu - minu;
990 double minv = bsplineSurface_.get_knot_n( degree_n );
991 double maxv = bsplineSurface_.get_knot_n( numKnots_n - degree_n -1 );
992 double diffv = maxv - minv;
994 if (diffu == 0.0 || diffv == 0.0 )
999 for (
int m = 0; m < cp_selection_texture_res_; ++m)
1001 double step_m = (double)m / (
double)cp_selection_texture_res_;
1002 double u = step_m * diffu;
1005 ACG::Vec2i span_u = bsplineSurface_.spanm(u);
1007 if (span_u[0] < 0 || span_u[1] < 0)
1014 for (
int n = 0; n < cp_selection_texture_res_; ++n)
1016 double step_n = double(n) / (double)cp_selection_texture_res_;
1017 double v = step_n * diffv;
1020 ACG::Vec2i span_v = bsplineSurface_.spann(v);
1022 if (span_v[0] < 0 || span_v[1] < 0)
1026 for (
int i = 0; i < degree_m+1; ++i)
1028 int idx_m = span_u[0] + i;
1030 for (
int j = 0; j < degree_n+1; ++j)
1032 int idx_n = span_v[0] + j;
1035 if (bsplineSurface_.controlpoint_selection(idx_m, idx_n))
1036 alpha += bsplineSurface_.basisFunction( knotvec_m, idx_m, degree_m, u)
1037 * bsplineSurface_.basisFunction( knotvec_n, idx_n, degree_n, v);
1042 Vec4f color = surface_color_ * (1.0 - alpha) + surface_highlight_color_ * alpha;
1045 b.setPixel (texelIdx_u, 255-texelIdx_v, qRgba((
int)(color[0]*255.0), (
int)(color[1]*255.0), (
int)(color[2]*255.0), 255));
1057 cp_selection_texture_image_ = QGLWidget::convertToGLFormat( b );
1061 glTexImage2D( GL_TEXTURE_2D,
1062 0, GL_RGBA, cp_selection_texture_image_.width(), cp_selection_texture_image_.height(),
1063 0, GL_RGBA, GL_UNSIGNED_BYTE, cp_selection_texture_image_.bits() );
1068 template <
class BSplineSurfaceType>
1073 if (bsplineSurface_.n_knots_m() == 0 ||bsplineSurface_.n_knots_n() == 0)
1076 if(knot_selection_texture_idx_ == 0)
1077 selection_init_texturing(knot_selection_texture_idx_);
1079 QImage b(knot_selection_texture_res_, knot_selection_texture_res_, QImage::Format_ARGB32);
1081 int degree_m = bsplineSurface_.degree_m();
1082 int degree_n = bsplineSurface_.degree_n();
1084 int numKnots_m = bsplineSurface_.n_knots_m();
1085 int numKnots_n = bsplineSurface_.n_knots_n();
1087 Knotvector knotvec_m = bsplineSurface_.get_knotvector_m();
1088 Knotvector knotvec_n = bsplineSurface_.get_knotvector_n();
1090 double minu = bsplineSurface_.get_knot_m( degree_m );
1091 double maxu = bsplineSurface_.get_knot_m( numKnots_m - degree_m -1 );
1092 double diffu = maxu - minu;
1094 double minv = bsplineSurface_.get_knot_n( degree_n );
1095 double maxv = bsplineSurface_.get_knot_n( numKnots_n - degree_n -1 );
1096 double diffv = maxv - minv;
1098 if (diffu == 0.0 || diffv == 0.0 )
1104 std::vector<bool> selectedKnotSpans_m(numKnots_m,
false);
1105 for (
int i = 0; i < numKnots_m; ++i)
1107 if (bsplineSurface_.get_knotvector_m_ref()->selection(i))
1110 ACG::Vec2i span = bsplineSurface_.spanm(bsplineSurface_.get_knot_m(i));
1112 if (span[0] < 0 || span[1] < 0)
1115 for(
int j = span[0]; j <= span[1]+degree_m; ++j)
1116 selectedKnotSpans_m[j] =
true;
1125 std::vector<bool> selectedKnotSpans_n(numKnots_n,
false);
1126 for (
int i = 0; i < numKnots_n; ++i)
1128 if (bsplineSurface_.get_knotvector_n_ref()->selection(i))
1131 ACG::Vec2i span = bsplineSurface_.spann(bsplineSurface_.get_knot_n(i));
1133 if (span[0] < 0 || span[1] < 0)
1136 for(
int j = span[0]; j <= span[1]+degree_n; ++j)
1137 selectedKnotSpans_n[j] =
true;
1146 for (
int m = 0; m < knot_selection_texture_res_; ++m)
1148 double step_m = (double)m / (
double)knot_selection_texture_res_;
1149 double u = step_m * diffu;
1151 Vec2i interval_m = bsplineSurface_.interval_m(u);
1156 for (
int n = 0; n < knot_selection_texture_res_; ++n)
1158 double step_n = (double)n / (
double)knot_selection_texture_res_;
1159 double v = step_n * diffv;
1161 Vec2i interval_n = bsplineSurface_.interval_n(v);
1164 bool selected_m = (selectedKnotSpans_m[interval_m[0]] && selectedKnotSpans_m[interval_m[1]]);
1165 bool selected_n = (selectedKnotSpans_n[interval_n[0]] && selectedKnotSpans_n[interval_n[1]]);
1168 if (selected_m && selected_n)
1171 color = surface_highlight_color_;
1172 else if ((selected_m && !selected_n) || (!selected_m && selected_n) )
1175 color = surface_highlight_color_ * 0.5 + surface_color_ * 0.5;
1179 color = surface_color_;
1183 b.setPixel (texelIdx_u, 255-texelIdx_v, qRgba((
int)(color[0]*255.0), (
int)(color[1]*255.0), (
int)(color[2]*255.0), 255));
1194 knot_selection_texture_image_ = QGLWidget::convertToGLFormat( b );
1198 glTexImage2D( GL_TEXTURE_2D,
1199 0, GL_RGBA, knot_selection_texture_image_.width(), knot_selection_texture_image_.height(),
1200 0, GL_RGBA, GL_UNSIGNED_BYTE, knot_selection_texture_image_.bits() );
1205 template <
class BSplineSurfaceType>
1210 std::cout <<
"[BSplineSurface] pick_init_texturing()" << std::endl;
1212 pick_texture_res_ = 256;
1213 pick_texture_baseidx_ = 0;
1216 glGenTextures( 1, &pick_texture_idx_ );
1220 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
1221 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
1223 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1224 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
1226 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1233 template <
class BSplineSurfaceType>
1238 std::cout <<
"[BSplineSurface] pick_create_texture()" << std::endl;
1240 QImage b(pick_texture_res_, pick_texture_res_, QImage::Format_ARGB32);
1241 QImage texture(pick_texture_res_, pick_texture_res_, QImage::Format_ARGB32);
1245 for(
int i = 0; i < pick_texture_res_; ++i)
1247 for(
int j = pick_texture_res_ - 1; j >= 0; j--)
1250 b.setPixel ( i,j, qRgba((
int)cur_col[0], (
int)cur_col[1], (
int)cur_col[2], (
int)cur_col[3]));
1252 Vec4f testcol =
Vec4f((
float)cur_col[0], (
float)cur_col[1], (
float)cur_col[2], (
float)cur_col[3]);
1253 texture.setPixel ( i,j, qRgba((
int)(testcol[0]*255.0), (
int)(testcol[1]*255.0), (
int)(testcol[2]*255.0), 255));
1287 texture.save(
"surfacePickingTexture.png",
"PNG");
1289 pick_texture_image_ = QGLWidget::convertToGLFormat( b );
1293 glTexImage2D( GL_TEXTURE_2D,
1294 0, GL_RGBA, pick_texture_image_.width(), pick_texture_image_.height(),
1295 0, GL_RGBA, GL_UNSIGNED_BYTE, pick_texture_image_.bits() );
1300 template <
class BSplineSurfaceType>
1305 if(arb_texture_idx_ == 0)
1306 selection_init_texturing(arb_texture_idx_);
1310 arb_texture_repeat_ = _repeat;
1311 arb_texture_repeat_u_ = _u_repeat;
1312 arb_texture_repeat_v_ = _v_repeat;
1314 arb_texture_image_ = QGLWidget::convertToGLFormat( _texture );
1315 int u_res = arb_texture_image_.width();
1316 int v_res = arb_texture_image_.height();
1321 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1322 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1324 glTexImage2D( GL_TEXTURE_2D,
1325 0, GL_RGBA, u_res, v_res,
1326 0, GL_RGBA, GL_UNSIGNED_BYTE, arb_texture_image_.bits() );
1334 template <
class BSplineSurfaceType>
1339 float c1 = _color[0]*1.5;
1340 c1 = c1 > 255.0 ? 255 : c1;
1342 float c2 = _color[1]*1.5;
1343 c2 = c2 > 255.0 ? 255 : c2;
1345 float c3 = _color[2]*1.5;
1346 c3 = c3 > 255.0 ? 255 : c3;
1348 return Vec4f( c1, c2, c3, _color[3]);
1353 template <
class BSplineSurfaceType>
1358 if (!invalidateSurfaceMesh_)
1371 const bool provideDebugInfo =
false;
1373 if (!surfaceDecl_.getNumElements())
1379 if (provideDebugInfo)
1389 int numU = _vertexCountU,
1390 numV = _vertexCountV;
1392 GLsizeiptr vboSize = numU * numV * surfaceDecl_.getVertexStride();
1393 std::vector<float> vboData(vboSize / 4);
1396 int elementOffset = 0;
1398 for (
int i = 0; i < numU; ++i)
1401 float u01 = float(i) / float(numU - 1);
1404 float u = (1 - u01) * bsplineSurface_.loweru() + u01 * bsplineSurface_.upperu();
1406 for (
int k = 0; k < numV; ++k)
1409 float v01 = float(k) / float(numV - 1);
1412 float v = (1 - v01) * bsplineSurface_.lowerv() + v01 * bsplineSurface_.upperv();
1416 bsplineSurface_.surfacePointNormal(pos, normal, u, v);
1419 for (
int m = 0; m < 3; ++m)
1420 vboData[elementOffset++] =
float(pos[m]);
1423 for (
int m = 0; m < 3; ++m)
1424 vboData[elementOffset++] =
float(normal[m]);
1427 vboData[elementOffset++] = u01;
1428 vboData[elementOffset++] = v01;
1431 if (provideDebugInfo)
1434 Vec2i span_u = bsplineSurface_.spanm(u);
1435 Vec2i span_v = bsplineSurface_.spann(u);
1436 vboData[elementOffset++] = span_u[1];
1437 vboData[elementOffset++] = span_v[1];
1439 std::vector<typename Point::value_type> bvu(std::max(4, bsplineSurface_.degree_m() + 1), 0);
1440 std::vector<typename Point::value_type> bvv(std::max(4, bsplineSurface_.degree_n() + 1), 0);
1441 bsplineBasisFunctions<typename Point::value_type>(bvu, span_u, u, bsplineSurface_.get_knotvector_m().getKnotvector());
1442 bsplineBasisFunctions<typename Point::value_type>(bvv, span_v, v, bsplineSurface_.get_knotvector_n().getKnotvector());
1444 for (
int m = 0; m < 4; ++m) vboData[elementOffset++] = bvu[m];
1445 for (
int m = 0; m < 4; ++m) vboData[elementOffset++] = bvv[m];
1451 surfaceVBO_.upload(vboSize, &vboData[0], GL_STATIC_DRAW);
1458 int numIndices = (numU - 1) * (numV - 1) * 6;
1459 std::vector<int> iboData(numIndices);
1464 for (
int k = 0; k < numV - 1; ++k)
1466 for (
int i = 0; i < numU - 1; ++i)
1476 iboData[idxOffset++] = k * numU + i;
1477 iboData[idxOffset++] = (k+1) * numU + i;
1478 iboData[idxOffset++] = (k+1) * numU + i + 1;
1480 iboData[idxOffset++] = k * numU + i;
1481 iboData[idxOffset++] = (k+1) * numU + i+1;
1482 iboData[idxOffset++] = k * numU + i + 1;
1487 surfaceIBO_.upload(numIndices * 4, &iboData[0], GL_STATIC_DRAW);
1490 surfaceIndexCount_ = numIndices;
1493 invalidateSurfaceMesh_ =
false;
1498 template <
class BSplineSurfaceType>
1503 if (!invalidateControlNetMesh_)
1509 if (!controlNetDecl_.getNumElements())
1512 int numU = bsplineSurface_.n_control_points_m(),
1513 numV = bsplineSurface_.n_control_points_n();
1516 GLsizeiptr vboSize = bsplineSurface_.n_control_points_m() * bsplineSurface_.n_control_points_n() * controlNetDecl_.getVertexStride();
1517 std::vector<float> vboData(vboSize / 4);
1520 int elementOffset = 0;
1522 for (
int k = 0; k < numV; ++k)
1524 for (
int i = 0; i < numU; ++i)
1526 Point pt = bsplineSurface_.get_control_point(i, k);
1527 for (
int m = 0; m < 3; ++m)
1528 vboData[elementOffset++] = pt[m];
1533 controlNetVBO_.upload(vboSize, &vboData[0], GL_STATIC_DRAW);
1541 int numIndices = 2 *( (numU - 1) * (numV) + (numU) * (numV - 1) );
1542 std::vector<int> iboData(numIndices);
1548 for (
int k = 0; k < numV; ++k)
1550 for (
int i = 0; i < numU - 1; ++i)
1552 iboData[idxOffset++] = k * numU + i;
1553 iboData[idxOffset++] = k * numU + i + 1;
1558 for (
int k = 0; k < numV - 1; ++k)
1560 for (
int i = 0; i < numU; ++i)
1562 iboData[idxOffset++] = k * numU + i;
1563 iboData[idxOffset++] = (k+1) * numU + i;
1568 controlNetLineIBO_.upload(numIndices * 4, &iboData[0], GL_STATIC_DRAW);
1571 controlNetLineIndices_ = numIndices;
1574 invalidateControlNetMesh_ =
false;
1580 template <
class BSplineSurfaceType>
1585 if (!invalidateControlNetMeshSel_)
1588 controlNetSelIBO_.del();
1590 if (bsplineSurface_.controlpoint_selections_available())
1592 int numU = bsplineSurface_.n_control_points_m(),
1593 numV = bsplineSurface_.n_control_points_n();
1597 for (
int k = 0; k < numV; ++k)
1599 for (
int i = 0; i < numU; ++i)
1601 if (bsplineSurface_.controlpoint_selection(i, k))
1607 controlNetSelIndices_ = numSel;
1613 std::vector<int> iboData(numSel);
1615 for (
int k = 0; k < numV; ++k)
1617 for (
int i = 0; i < numU; ++i)
1619 if (bsplineSurface_.controlpoint_selection(i, k))
1623 iboData[numSel++] = k * numU + i;
1628 controlNetSelIBO_.upload(numSel * 4, &iboData[0], GL_STATIC_DRAW);
1632 invalidateControlNetMeshSel_ =
false;
1637 template <
class BSplineSurfaceType>
1642 const size_t knotBufSizeU = bsplineSurface_.get_knots_m().size();
1643 const size_t knotBufSizeV = bsplineSurface_.get_knots_n().size();
1650 std::vector<float> knotBufU(knotBufSizeU);
1652 for (
size_t i = 0; i < knotBufSizeU; ++i)
1653 knotBufU[i] =
float(bsplineSurface_.get_knot_m(i));
1655 knotTexBufferU_.setBufferData(knotBufSizeU * 4, &knotBufU[0], GL_R32F);
1660 std::vector<float> knotBufV(knotBufSizeV);
1662 for (
size_t i = 0; i < knotBufSizeV; ++i)
1663 knotBufV[i] =
float(bsplineSurface_.get_knot_n(i));
1665 knotTexBufferV_.setBufferData(knotBufSizeV * 4, &knotBufV[0], GL_R32F);
1669 #ifdef GL_VERSION_3_0 1671 const size_t numControlPointsU = bsplineSurface_.n_control_points_m();
1672 const size_t numControlPointsV = bsplineSurface_.n_control_points_n();
1673 const size_t controlPointBufSize = numControlPointsU * numControlPointsV;
1675 if (controlPointBufSize)
1677 std::vector<float> controlPointBuf(controlPointBufSize * 3);
1679 for (
size_t y = 0; y < numControlPointsV; ++y)
1681 for (
size_t x = 0; x < numControlPointsU; ++x)
1683 Point cp = bsplineSurface_.get_control_point(x, y);
1684 controlPointBuf[(y * numControlPointsU + x) * 3 + 0] = cp[0];
1685 controlPointBuf[(y * numControlPointsU + x) * 3 + 1] = cp[1];
1686 controlPointBuf[(y * numControlPointsU + x) * 3 + 2] = cp[2];
1690 controlPointTex_.bind();
1691 controlPointTex_.parameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1692 controlPointTex_.parameter(GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1693 controlPointTex_.setData(0, GL_RGB32F, numControlPointsU, numControlPointsV, GL_RGB, GL_FLOAT, &controlPointBuf[0]);
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
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
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
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 bindTexture(GLenum _target, GLuint _buffer)
replaces glBindTexture, 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.
static void depthRange(GLclampd _zNear, GLclampd _zFar)
replaces glDepthRange, supports locking
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
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
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)
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
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.
size_t getNumLayers() const
returns the layer count
const Vec4f & clear_color() const
get background color
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)
VectorT< double, 3 > Vec3d
void updateSurfaceMesh(int _vertexCountU=50, int _vertexCountV=50)
update vertex + index buffer of surface mesh