278 glPushAttrib(GL_ENABLE_BIT);
281 if ( bspline_selection_draw_mode_ == CONTROLPOINT
282 && controlPointSelectionTexture_valid_ ==
false)
283 updateControlPointSelectionTexture(_state);
284 if ( bspline_selection_draw_mode_ == KNOTVECTOR
285 && knotVectorSelectionTexture_valid_ ==
false)
286 updateKnotVectorSelectionTexture(_state);
293 render( _state,
false);
298 glPushAttrib(GL_ENABLE_BIT);
303 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
305 render( _state,
false);
307 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
316 clear_color[3] = 1.0;
321 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
326 render( _state,
true);
330 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
334 render( _state,
false);
337 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
351 render( _state,
true);
366 render( _state,
true);
380 render( _state,
true);
396 render( _state,
true);
411 arb_texture_used_ =
true;
412 drawTexturedSurface(_state, arb_texture_idx_ );
413 arb_texture_used_ =
false;
424template <
class BSplineSurfaceType>
430 if (render_control_net_)
432 if (bspline_draw_mode_ == NORMAL)
433 drawControlNet(_state);
434 else if (bspline_draw_mode_ == FANCY)
435 drawFancyControlNet(_state);
439 if (render_bspline_surface_)
441 if (bspline_selection_draw_mode_ == NONE)
442 drawSurface(_state, _fill);
443 else if (bspline_selection_draw_mode_ == CONTROLPOINT)
444 drawTexturedSurface(_state, cp_selection_texture_idx_);
445 else if (bspline_selection_draw_mode_ == KNOTVECTOR)
446 drawTexturedSurface(_state, knot_selection_texture_idx_);
452template <
class BSplineSurfaceType>
454BSplineSurfaceNodeT<BSplineSurfaceType>::
455drawSurface(GLState& _state,
bool _fill)
462 surfaceDecl_.activateFixedFunction();
465 glDrawElements(GL_TRIANGLES, surfaceIndexCount_, GL_UNSIGNED_INT, 0);
467 surfaceDecl_.deactivateFixedFunction();
469 surfaceIBO_.unbind();
470 surfaceVBO_.unbind();
475template <
class BSplineSurfaceType>
477BSplineSurfaceNodeT<BSplineSurfaceType>::
478drawTexturedSurface(GLState& _state, GLuint _texture_idx)
480 glPushAttrib(GL_ALL_ATTRIB_BITS);
487 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
488 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
490 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
491 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
494 if( arb_texture_used_ )
496 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
497 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
501 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
505 drawSurface( _state);
515template <
class BSplineSurfaceType>
517BSplineSurfaceNodeT<BSplineSurfaceType>::
518drawControlNet(GLState& _state)
521 Vec4f base_color_old = _state.base_color();
525 glPushAttrib(GL_ALL_ATTRIB_BITS);
533 updateControlNetMesh();
534 updateControlNetMeshSel();
537 controlNetVBO_.bind();
538 controlNetDecl_.activateFixedFunction();
543 if (controlNetSelIndices_)
545 glColor(generateHighlightColor(controlnet_color_));
549 controlNetSelIBO_.bind();
550 glDrawElements(GL_POINTS, controlNetSelIndices_, GL_UNSIGNED_INT, 0);
556 float point_size_old = _state.point_size();
557 glPointSize(point_size_old + 4);
559 GLsizei numControlPoints = bsplineSurface_.n_control_points_m() * bsplineSurface_.n_control_points_n();
560 glDrawArrays(GL_POINTS, 0, numControlPoints);
562 glPointSize((
int)point_size_old);
602 float line_width_old = _state.line_width();
603 glLineWidth(line_width_old+2.0);
605 controlNetLineIBO_.bind();
606 glDrawElements(GL_LINES, controlNetLineIndices_, GL_UNSIGNED_INT, 0);
610 controlNetDecl_.deactivateFixedFunction();
611 controlNetLineIBO_.unbind();
612 controlNetVBO_.unbind();
615 glLineWidth(line_width_old);
622template <
class BSplineSurfaceType>
624BSplineSurfaceNodeT<BSplineSurfaceType>::
625drawFancyControlNet(GLState& _state)
628 Vec4f base_color_old = _state.base_color();
632 glPushAttrib(GL_ALL_ATTRIB_BITS);
636 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
639 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
644 double sphereRadius = _state.point_size() * 0.05;
647 if( bsplineSurface_.controlpoint_selections_available())
650 float point_size_old = _state.point_size();
654 glColor(generateHighlightColor(controlnet_color_));
657 for (
unsigned int i = 0; i < bsplineSurface_.n_control_points_m(); ++i)
659 for (
unsigned int j = 0; j < bsplineSurface_.n_control_points_n(); ++j)
661 if( bsplineSurface_.controlpoint_selection(i, j))
662 draw_sphere(bsplineSurface_(i, j), sphereRadius, _state, fancySphere_);
666 glPointSize(point_size_old);
672 for (
unsigned int i = 0; i < bsplineSurface_.n_control_points_m(); ++i)
673 for (
unsigned int j = 0; j < bsplineSurface_.n_control_points_n(); ++j)
674 draw_sphere(bsplineSurface_(i, j), sphereRadius, _state, fancySphere_);
679 double cylinderRadius = _state.line_width() * 0.05;
684 for (
unsigned int i = 0; i < bsplineSurface_.n_control_points_m(); ++i)
686 for (
int j = 0; j < (int)bsplineSurface_.n_control_points_n() - 1; ++j)
688 Vec3d p = bsplineSurface_(i, j);
689 Vec3d p_next = bsplineSurface_(i, j+1);
690 draw_cylinder(p, p_next - p, cylinderRadius, _state);
694 for (
int j = 0; j < (int)bsplineSurface_.n_control_points_n(); ++j)
696 for (
int i = 0; i < (int)bsplineSurface_.n_control_points_m() - 1; ++i)
698 Vec3d p = bsplineSurface_(i, j);
699 Vec3d p_next = bsplineSurface_(i+1,j);
700 draw_cylinder(p, p_next - p, cylinderRadius, _state);
712template <
class BSplineSurfaceType>
717 invalidateSurfaceMesh_ =
true;
718 invalidateControlNetMesh_ =
true;
723template <
class BSplineSurfaceType>
728 if(pick_texture_idx_ == 0)
729 pick_init_texturing();
737 if(render_control_net_)
739 _state.
pick_set_maximum (bsplineSurface_.n_control_points_m() * bsplineSurface_.n_control_points_n());
740 pick_vertices(_state);
748 pick_surface(_state, 0);
761 _state.
pick_set_maximum (bsplineSurface_.n_control_points_m() * bsplineSurface_.n_control_points_n() + 1);
762 pick_vertices(_state);
763 pick_surface(_state, bsplineSurface_.n_control_points_m() * bsplineSurface_.n_control_points_n());
774template <
class BSplineSurfaceType>
784 for (
unsigned int i = 0; i < bsplineSurface_.n_control_points_m(); ++i)
786 for (
unsigned int j = 0; j < bsplineSurface_.n_control_points_n(); ++j)
788 _state.
pick_set_name (i * bsplineSurface_.n_control_points_n() + j);
792 int px = round( window_pos[0]);
793 int py = round( window_pos[1]);
795 double l = (_state.
eye() - (
Vec3d)bsplineSurface_(i,j)).norm();
796 double r = l*tan(angle);
799 draw_sphere( bsplineSurface_(i,j), r, _state, sphere_);
806template <
class BSplineSurfaceType>
808BSplineSurfaceNodeT<BSplineSurfaceType>::
809pick_spline( GLState& _state )
811 glPushAttrib(GL_ALL_ATTRIB_BITS);
819 std::cout <<
"[BSplineSurface] pick_spline: \n"
820 <<
"pick_texture_baseidx_ = " << pick_texture_baseidx_
821 <<
", _state.pick_current_index () = " << _state.pick_current_index ()
822 <<
", pick_texture_idx_ = " << pick_texture_idx_
825 if( _state.pick_current_index () != pick_texture_baseidx_)
827 pick_texture_baseidx_ = _state.pick_current_index();
828 pick_create_texture( _state);
833 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
834 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
836 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
837 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
839 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
853template <
class BSplineSurfaceType>
855BSplineSurfaceNodeT<BSplineSurfaceType>::
856pick_surface( GLState& _state,
unsigned int _offset )
858 bool sampling_mode_backup = adaptive_sampling_;
859 adaptive_sampling_ =
false;
862 _state.pick_set_name ( _offset );
863 drawSurface( _state);
865 adaptive_sampling_ = sampling_mode_backup;
870template <
class BSplineSurfaceType>
872BSplineSurfaceNodeT<BSplineSurfaceType>::
873draw_sphere(
const Point& _p0,
double _r, GLState& _state, GLSphere* _sphere)
876 _state.push_modelview_matrix();
877 _state.translate( _p0[0], _p0[1], _p0[2]);
879 _sphere->draw(_state,_r);
881 _state.pop_modelview_matrix();
886template <
class BSplineSurfaceType>
888BSplineSurfaceNodeT<BSplineSurfaceType>::
889draw_cylinder(
const Point& _p0,
const Point& _axis,
double _r, GLState& _state)
891 _state.push_modelview_matrix();
892 _state.translate(_p0[0], _p0[1], _p0[2]);
894 Point direction = _axis;
899 direction.normalize();
900 rot_angle = acos((z_axis | direction))*180/M_PI;
901 rot_normal = ((z_axis % direction).normalize());
903 if( fabs( rot_angle ) > 0.0001 && fabs( 180 - rot_angle ) > 0.0001)
904 _state.rotate(rot_angle,rot_normal[0], rot_normal[1], rot_normal[2]);
906 _state.rotate(rot_angle,1,0,0);
908 cylinder_->setBottomRadius(_r);
909 cylinder_->setTopRadius(_r);
910 cylinder_->draw(_state,_axis.norm());
912 _state.pop_modelview_matrix();
917template <
class BSplineSurfaceType>
919BSplineSurfaceNodeT<BSplineSurfaceType>::
920updateControlPointSelectionTexture(GLState& _state)
922 create_cp_selection_texture(_state);
923 controlPointSelectionTexture_valid_ =
true;
926 invalidateControlNetMeshSel_ =
true;
931template <
class BSplineSurfaceType>
933BSplineSurfaceNodeT<BSplineSurfaceType>::
934updateKnotVectorSelectionTexture(GLState& _state)
936 create_knot_selection_texture(_state);
937 knotVectorSelectionTexture_valid_ =
true;
942template <
class BSplineSurfaceType>
948 glGenTextures( 1, &_texture_idx );
952 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
953 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
955 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
956 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
958 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
965template <
class BSplineSurfaceType>
970 if (bsplineSurface_.n_knots_m() == 0 || bsplineSurface_.n_knots_n() == 0)
973 if(cp_selection_texture_idx_ == 0)
974 selection_init_texturing(cp_selection_texture_idx_);
976 QImage b(cp_selection_texture_res_, cp_selection_texture_res_, QImage::Format_ARGB32);
978 int degree_m = bsplineSurface_.degree_m();
979 int degree_n = bsplineSurface_.degree_n();
981 int numKnots_m = bsplineSurface_.n_knots_m();
982 int numKnots_n = bsplineSurface_.n_knots_n();
984 Knotvector knotvec_m = bsplineSurface_.get_knotvector_m();
985 Knotvector knotvec_n = bsplineSurface_.get_knotvector_n();
987 double minu = bsplineSurface_.get_knot_m( degree_m );
988 double maxu = bsplineSurface_.get_knot_m( numKnots_m - degree_m -1 );
989 double diffu = maxu - minu;
991 double minv = bsplineSurface_.get_knot_n( degree_n );
992 double maxv = bsplineSurface_.get_knot_n( numKnots_n - degree_n -1 );
993 double diffv = maxv - minv;
995 if (diffu == 0.0 || diffv == 0.0 )
1000 for (
int m = 0; m < cp_selection_texture_res_; ++m)
1002 double step_m = (double)m / (
double)cp_selection_texture_res_;
1003 double u = step_m * diffu;
1006 ACG::Vec2i span_u = bsplineSurface_.spanm(u);
1008 if (span_u[0] < 0 || span_u[1] < 0)
1015 for (
int n = 0; n < cp_selection_texture_res_; ++n)
1017 double step_n = double(n) / (double)cp_selection_texture_res_;
1018 double v = step_n * diffv;
1021 ACG::Vec2i span_v = bsplineSurface_.spann(v);
1023 if (span_v[0] < 0 || span_v[1] < 0)
1027 for (
int i = 0; i < degree_m+1; ++i)
1029 int idx_m = span_u[0] + i;
1031 for (
int j = 0; j < degree_n+1; ++j)
1033 int idx_n = span_v[0] + j;
1036 if (bsplineSurface_.controlpoint_selection(idx_m, idx_n))
1037 alpha += bsplineSurface_.basisFunction( knotvec_m, idx_m, degree_m, u)
1038 * bsplineSurface_.basisFunction( knotvec_n, idx_n, degree_n, v);
1043 Vec4f color = surface_color_ * (1.0 - alpha) + surface_highlight_color_ * alpha;
1046 b.setPixel (texelIdx_u, 255-texelIdx_v, qRgba((
int)(color[0]*255.0), (
int)(color[1]*255.0), (
int)(color[2]*255.0), 255));
1058 cp_selection_texture_image_ = ACG::Util::convertToGLFormat( b );
1062 glTexImage2D( GL_TEXTURE_2D,
1063 0, GL_RGBA, cp_selection_texture_image_.width(), cp_selection_texture_image_.height(),
1064 0, GL_RGBA, GL_UNSIGNED_BYTE, cp_selection_texture_image_.bits() );
1069template <
class BSplineSurfaceType>
1074 if (bsplineSurface_.n_knots_m() == 0 ||bsplineSurface_.n_knots_n() == 0)
1077 if(knot_selection_texture_idx_ == 0)
1078 selection_init_texturing(knot_selection_texture_idx_);
1080 QImage b(knot_selection_texture_res_, knot_selection_texture_res_, QImage::Format_ARGB32);
1082 int degree_m = bsplineSurface_.degree_m();
1083 int degree_n = bsplineSurface_.degree_n();
1085 int numKnots_m = bsplineSurface_.n_knots_m();
1086 int numKnots_n = bsplineSurface_.n_knots_n();
1088 Knotvector knotvec_m = bsplineSurface_.get_knotvector_m();
1089 Knotvector knotvec_n = bsplineSurface_.get_knotvector_n();
1091 double minu = bsplineSurface_.get_knot_m( degree_m );
1092 double maxu = bsplineSurface_.get_knot_m( numKnots_m - degree_m -1 );
1093 double diffu = maxu - minu;
1095 double minv = bsplineSurface_.get_knot_n( degree_n );
1096 double maxv = bsplineSurface_.get_knot_n( numKnots_n - degree_n -1 );
1097 double diffv = maxv - minv;
1099 if (diffu == 0.0 || diffv == 0.0 )
1105 std::vector<bool> selectedKnotSpans_m(numKnots_m,
false);
1106 for (
int i = 0; i < numKnots_m; ++i)
1108 if (bsplineSurface_.get_knotvector_m_ref()->selection(i))
1111 ACG::Vec2i span = bsplineSurface_.spanm(bsplineSurface_.get_knot_m(i));
1113 if (span[0] < 0 || span[1] < 0)
1116 for(
int j = span[0]; j <= span[1]+degree_m; ++j)
1117 selectedKnotSpans_m[j] =
true;
1126 std::vector<bool> selectedKnotSpans_n(numKnots_n,
false);
1127 for (
int i = 0; i < numKnots_n; ++i)
1129 if (bsplineSurface_.get_knotvector_n_ref()->selection(i))
1132 ACG::Vec2i span = bsplineSurface_.spann(bsplineSurface_.get_knot_n(i));
1134 if (span[0] < 0 || span[1] < 0)
1137 for(
int j = span[0]; j <= span[1]+degree_n; ++j)
1138 selectedKnotSpans_n[j] =
true;
1147 for (
int m = 0; m < knot_selection_texture_res_; ++m)
1149 double step_m = (double)m / (
double)knot_selection_texture_res_;
1150 double u = step_m * diffu;
1152 Vec2i interval_m = bsplineSurface_.interval_m(u);
1157 for (
int n = 0; n < knot_selection_texture_res_; ++n)
1159 double step_n = (double)n / (
double)knot_selection_texture_res_;
1160 double v = step_n * diffv;
1162 Vec2i interval_n = bsplineSurface_.interval_n(v);
1165 bool selected_m = (selectedKnotSpans_m[interval_m[0]] && selectedKnotSpans_m[interval_m[1]]);
1166 bool selected_n = (selectedKnotSpans_n[interval_n[0]] && selectedKnotSpans_n[interval_n[1]]);
1169 if (selected_m && selected_n)
1172 color = surface_highlight_color_;
1173 else if ((selected_m && !selected_n) || (!selected_m && selected_n) )
1176 color = surface_highlight_color_ * 0.5 + surface_color_ * 0.5;
1180 color = surface_color_;
1184 b.setPixel (texelIdx_u, 255-texelIdx_v, qRgba((
int)(color[0]*255.0), (
int)(color[1]*255.0), (
int)(color[2]*255.0), 255));
1195 knot_selection_texture_image_ = ACG::Util::convertToGLFormat( b );
1199 glTexImage2D( GL_TEXTURE_2D,
1200 0, GL_RGBA, knot_selection_texture_image_.width(), knot_selection_texture_image_.height(),
1201 0, GL_RGBA, GL_UNSIGNED_BYTE, knot_selection_texture_image_.bits() );
1206template <
class BSplineSurfaceType>
1211 std::cout <<
"[BSplineSurface] pick_init_texturing()" << std::endl;
1213 pick_texture_res_ = 256;
1214 pick_texture_baseidx_ = 0;
1217 glGenTextures( 1, &pick_texture_idx_ );
1221 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
1222 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
1224 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1225 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
1227 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1234template <
class BSplineSurfaceType>
1239 std::cout <<
"[BSplineSurface] pick_create_texture()" << std::endl;
1241 QImage b(pick_texture_res_, pick_texture_res_, QImage::Format_ARGB32);
1242 QImage texture(pick_texture_res_, pick_texture_res_, QImage::Format_ARGB32);
1246 for(
int i = 0; i < pick_texture_res_; ++i)
1248 for(
int j = pick_texture_res_ - 1; j >= 0; j--)
1251 b.setPixel ( i,j, qRgba((
int)cur_col[0], (
int)cur_col[1], (
int)cur_col[2], (
int)cur_col[3]));
1253 Vec4f testcol =
Vec4f((
float)cur_col[0], (
float)cur_col[1], (
float)cur_col[2], (
float)cur_col[3]);
1254 texture.setPixel ( i,j, qRgba((
int)(testcol[0]*255.0), (
int)(testcol[1]*255.0), (
int)(testcol[2]*255.0), 255));
1288 texture.save(
"surfacePickingTexture.png",
"PNG");
1290 pick_texture_image_ = ACG::Util::convertToGLFormat( b );
1294 glTexImage2D( GL_TEXTURE_2D,
1295 0, GL_RGBA, pick_texture_image_.width(), pick_texture_image_.height(),
1296 0, GL_RGBA, GL_UNSIGNED_BYTE, pick_texture_image_.bits() );
1301template <
class BSplineSurfaceType>
1304set_arb_texture(
const QImage& _texture,
bool _repeat,
float _u_repeat,
float _v_repeat )
1306 if(arb_texture_idx_ == 0)
1307 selection_init_texturing(arb_texture_idx_);
1311 arb_texture_repeat_ = _repeat;
1312 arb_texture_repeat_u_ = _u_repeat;
1313 arb_texture_repeat_v_ = _v_repeat;
1315 arb_texture_image_ = ACG::Util::convertToGLFormat( _texture );
1316 int u_res = arb_texture_image_.width();
1317 int v_res = arb_texture_image_.height();
1322 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1323 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1325 glTexImage2D( GL_TEXTURE_2D,
1326 0, GL_RGBA, u_res, v_res,
1327 0, GL_RGBA, GL_UNSIGNED_BYTE, arb_texture_image_.bits() );
1335template <
class BSplineSurfaceType>
1340 float c1 = _color[0]*1.5;
1341 c1 = c1 > 255.0 ? 255 : c1;
1343 float c2 = _color[1]*1.5;
1344 c2 = c2 > 255.0 ? 255 : c2;
1346 float c3 = _color[2]*1.5;
1347 c3 = c3 > 255.0 ? 255 : c3;
1349 return Vec4f( c1, c2, c3, _color[3]);
1354template <
class BSplineSurfaceType>
1359 if (!invalidateSurfaceMesh_)
1372 const bool provideDebugInfo =
false;
1374 if (!surfaceDecl_.getNumElements())
1380 if (provideDebugInfo)
1390 int numU = _vertexCountU,
1391 numV = _vertexCountV;
1393 GLsizeiptr vboSize = numU * numV * surfaceDecl_.getVertexStride();
1394 std::vector<float> vboData(vboSize / 4);
1397 int elementOffset = 0;
1399 for (
int i = 0; i < numU; ++i)
1402 float u01 = float(i) / float(numU - 1);
1405 float u = (1 - u01) * bsplineSurface_.loweru() + u01 * bsplineSurface_.upperu();
1407 for (
int k = 0; k < numV; ++k)
1410 float v01 = float(k) / float(numV - 1);
1413 float v = (1 - v01) * bsplineSurface_.lowerv() + v01 * bsplineSurface_.upperv();
1417 bsplineSurface_.surfacePointNormal(pos, normal, u, v);
1420 for (
int m = 0; m < 3; ++m)
1421 vboData[elementOffset++] =
float(pos[m]);
1424 for (
int m = 0; m < 3; ++m)
1425 vboData[elementOffset++] =
float(normal[m]);
1428 vboData[elementOffset++] = u01;
1429 vboData[elementOffset++] = v01;
1432 if (provideDebugInfo)
1435 Vec2i span_u = bsplineSurface_.spanm(u);
1436 Vec2i span_v = bsplineSurface_.spann(u);
1437 vboData[elementOffset++] = span_u[1];
1438 vboData[elementOffset++] = span_v[1];
1440 std::vector<typename Point::value_type> bvu(std::max(4, bsplineSurface_.degree_m() + 1), 0);
1441 std::vector<typename Point::value_type> bvv(std::max(4, bsplineSurface_.degree_n() + 1), 0);
1442 bsplineBasisFunctions<typename Point::value_type>(bvu, span_u, u, bsplineSurface_.get_knotvector_m().getKnotvector());
1443 bsplineBasisFunctions<typename Point::value_type>(bvv, span_v, v, bsplineSurface_.get_knotvector_n().getKnotvector());
1445 for (
int m = 0; m < 4; ++m) vboData[elementOffset++] = bvu[m];
1446 for (
int m = 0; m < 4; ++m) vboData[elementOffset++] = bvv[m];
1452 surfaceVBO_.upload(vboSize, &vboData[0], GL_STATIC_DRAW);
1459 int numIndices = (numU - 1) * (numV - 1) * 6;
1460 std::vector<int> iboData(numIndices);
1465 for (
int k = 0; k < numV - 1; ++k)
1467 for (
int i = 0; i < numU - 1; ++i)
1477 iboData[idxOffset++] = k * numU + i;
1478 iboData[idxOffset++] = (k+1) * numU + i;
1479 iboData[idxOffset++] = (k+1) * numU + i + 1;
1481 iboData[idxOffset++] = k * numU + i;
1482 iboData[idxOffset++] = (k+1) * numU + i+1;
1483 iboData[idxOffset++] = k * numU + i + 1;
1488 surfaceIBO_.upload(numIndices * 4, &iboData[0], GL_STATIC_DRAW);
1491 surfaceIndexCount_ = numIndices;
1494 invalidateSurfaceMesh_ =
false;
1499template <
class BSplineSurfaceType>
1504 if (!invalidateControlNetMesh_)
1510 if (!controlNetDecl_.getNumElements())
1513 int numU = bsplineSurface_.n_control_points_m(),
1514 numV = bsplineSurface_.n_control_points_n();
1517 GLsizeiptr vboSize = bsplineSurface_.n_control_points_m() * bsplineSurface_.n_control_points_n() * controlNetDecl_.getVertexStride();
1518 std::vector<float> vboData(vboSize / 4);
1521 int elementOffset = 0;
1523 for (
int k = 0; k < numV; ++k)
1525 for (
int i = 0; i < numU; ++i)
1527 Point pt = bsplineSurface_.get_control_point(i, k);
1528 for (
int m = 0; m < 3; ++m)
1529 vboData[elementOffset++] = pt[m];
1534 controlNetVBO_.upload(vboSize, &vboData[0], GL_STATIC_DRAW);
1542 int numIndices = 2 *( (numU - 1) * (numV) + (numU) * (numV - 1) );
1543 std::vector<int> iboData(numIndices);
1549 for (
int k = 0; k < numV; ++k)
1551 for (
int i = 0; i < numU - 1; ++i)
1553 iboData[idxOffset++] = k * numU + i;
1554 iboData[idxOffset++] = k * numU + i + 1;
1559 for (
int k = 0; k < numV - 1; ++k)
1561 for (
int i = 0; i < numU; ++i)
1563 iboData[idxOffset++] = k * numU + i;
1564 iboData[idxOffset++] = (k+1) * numU + i;
1569 controlNetLineIBO_.upload(numIndices * 4, &iboData[0], GL_STATIC_DRAW);
1572 controlNetLineIndices_ = numIndices;
1575 invalidateControlNetMesh_ =
false;
1581template <
class BSplineSurfaceType>
1586 if (!invalidateControlNetMeshSel_)
1589 controlNetSelIBO_.del();
1591 if (bsplineSurface_.controlpoint_selections_available())
1593 int numU = bsplineSurface_.n_control_points_m(),
1594 numV = bsplineSurface_.n_control_points_n();
1598 for (
int k = 0; k < numV; ++k)
1600 for (
int i = 0; i < numU; ++i)
1602 if (bsplineSurface_.controlpoint_selection(i, k))
1608 controlNetSelIndices_ = numSel;
1614 std::vector<int> iboData(numSel);
1616 for (
int k = 0; k < numV; ++k)
1618 for (
int i = 0; i < numU; ++i)
1620 if (bsplineSurface_.controlpoint_selection(i, k))
1624 iboData[numSel++] = k * numU + i;
1629 controlNetSelIBO_.upload(numSel * 4, &iboData[0], GL_STATIC_DRAW);
1633 invalidateControlNetMeshSel_ =
false;
1638template <
class BSplineSurfaceType>
1643 const size_t knotBufSizeU = bsplineSurface_.get_knots_m().size();
1644 const size_t knotBufSizeV = bsplineSurface_.get_knots_n().size();
1651 std::vector<float> knotBufU(knotBufSizeU);
1653 for (
size_t i = 0; i < knotBufSizeU; ++i)
1654 knotBufU[i] =
float(bsplineSurface_.get_knot_m(i));
1656 knotTexBufferU_.setBufferData(knotBufSizeU * 4, &knotBufU[0], GL_R32F);
1661 std::vector<float> knotBufV(knotBufSizeV);
1663 for (
size_t i = 0; i < knotBufSizeV; ++i)
1664 knotBufV[i] =
float(bsplineSurface_.get_knot_n(i));
1666 knotTexBufferV_.setBufferData(knotBufSizeV * 4, &knotBufV[0], GL_R32F);
1670#ifdef GL_VERSION_3_0
1672 const size_t numControlPointsU = bsplineSurface_.n_control_points_m();
1673 const size_t numControlPointsV = bsplineSurface_.n_control_points_n();
1674 const size_t controlPointBufSize = numControlPointsU * numControlPointsV;
1676 if (controlPointBufSize)
1678 std::vector<float> controlPointBuf(controlPointBufSize * 3);
1680 for (
size_t y = 0; y < numControlPointsV; ++y)
1682 for (
size_t x = 0; x < numControlPointsU; ++x)
1684 Point cp = bsplineSurface_.get_control_point(x, y);
1685 controlPointBuf[(y * numControlPointsU + x) * 3 + 0] = cp[0];
1686 controlPointBuf[(y * numControlPointsU + x) * 3 + 1] = cp[1];
1687 controlPointBuf[(y * numControlPointsU + x) * 3 + 2] = cp[2];
1691 controlPointTex_.bind();
1692 controlPointTex_.parameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1693 controlPointTex_.parameter(GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1694 controlPointTex_.setData(0, GL_RGB32F, numControlPointsU, numControlPointsV, GL_RGB, GL_FLOAT, &controlPointBuf[0]);