Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SER431 Lecture 20

SER431 Lecture 20

Advanced Graphics
NURBS II
(201811)

Javier Gonzalez-Sanchez

November 05, 2018
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. jgs SER 431 Advanced Graphics Lecture 20: Non-Uniform Rational Basis

    Splines II Javier Gonzalez-Sanchez [email protected] PERALTA 230U Office Hours: By appointment
  2. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 2 jgs

    Screenshot https://github.com/javiergs/SER431/blob/master/Lecture19/nurbs_surface_grid.cpp https://github.com/javiergs/SER431/blob/master/Lecture19/nurbs_surface_solid.cpp
  3. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 3 jgs

    Code // control points GLfloat ctlpoints[4][4][3] = { { { 20, 0, 10 },{ 0, 0, 10 },{ -5, 0, 10 },{ -10, 0, 10 } }, { { 20, 0, 5 },{ 0, 15, 5 },{ -5, 15, 5 },{ -10, 0, 5 } }, { { 20, 0, -5 },{ 0, 10, -5 },{ -5, 10, -5 },{ -10, 0, -5 } }, { { 20, 0, -10 },{ 0, 0, -10 },{ -5, 0, -10 },{ -10, 0, -10 } } }; GLfloat knots[8] = { 0.0, 0.0, 0.0, 0.0, 3.0, 3.0, 3.0, 3.0 }; GLUnurbsObj *theNurb;
  4. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 4 jgs

    Code // init void init(void) { // Materials and Light GLfloat mat_diffuse[] = { 1.0f, 0.5f, 0.31f, 1. }; GLfloat mat_specular[] = { 0.5f, 0.5f, 0.5f, 1. }; GLfloat mat_ambient[] = { 1.0f, 0.5f, 0.31f, 1. }; GLfloat mat_shininess[] = { 100.0 }; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); glEnable(GL_AUTO_NORMAL); glEnable(GL_NORMALIZE); theNurb = gluNewNurbsRenderer(); gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 25.0); gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL); }
  5. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 5 jgs

    // display void display(void) { // camera and others configurations here... // NURBS glColor3f(0, 1, 0); gluBeginSurface(theNurb); gluNurbsSurface(theNurb, 8, knots, 8, knots, // knots u and v 4 * 3, 3, // offset u and v &ctlpoints[0][0][0], 4, 4, // function degree u and v GL_MAP2_VERTEX_3); gluEndSurface(theNurb); // more ... }
  6. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 6 jgs

    Numbers to be considered // V_size curves with U_size control points each // V_size + ORDER knots per curve and // U_size + ORDER knots per inter-curve connection // offsets are V_size*3 and 3 // cubic equations ORDER = 4 GLfloat ctlpoints[U_size][V_size][3] = { … }; GLfloat vknots [V_size + ORDER] = { …}; GLfloat uknots [U_size + ORDER] = { …} gluNurbsSurface(theNurb,U_size + ORDER, uknots, V_size + ORDER, vknots, V_size * 3, 3, &ctlpoints[0][0][0], ORDER, ORDER, GL_MAP2_VERTEX_3);
  7. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 7 jgs

    Screenshot 6 curves 6 control points each 5 curves 6 control points each 4 curves 6 control points each
  8. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 8 jgs

    6 curves x 6 control points per curve const int V_size = 6; const int U_size = 6; // curves in blue color const int ORDER = 4; GLfloat ctlpoints[U_size][V_size][3] = { { { 25, 5, 15 } ,{ 20, 5, 15 },{ 0, 0, 15 },{ -5, 0, 15 },{ -10, 5, 15 } ,{ -15, 5, 15 } }, { { 25, 5, 10 } ,{ 20, 0, 10 },{ 0, 0, 10 },{ -5, 0, 10 },{ -10, 0, 10 } ,{ -15, 5, 10 } }, { { 25, 0, 5 } ,{ 20, 0, 5 },{ 0, 15, 5 },{ -5, 15, 5 },{ -10, 0, 5 } ,{ -15, 0, 5 } }, { { 25, 0, -5 } ,{ 20, 0, -5 },{ 0, 10, -5 },{ -5, 10, -5 },{ -10, 0, -5 } ,{ -15, 0, -5 } }, { { 25, 5, -10 } ,{ 20, 0, -10 },{ 0, 0, -10 },{ -5, 0, -10 },{ -10, 0, -10 } ,{ -15, 5, -10 } }, { { 25, 5, -15 } ,{ 20, 5, -15 },{ 0, 0, -15 },{ -5, 0, -15 },{ -10, 5, -15 } ,{ -15, 5, -15 } } }; GLfloat uknots[U_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 1.0, 3.0, 5.0, 5.0, 5.0, 5.0 }; GLfloat vknots[V_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 1.0, 3.0, 5.0, 5.0, 5.0, 5.0 }; gluBeginSurface(theNurb); gluNurbsSurface(theNurb, U_size + ORDER, uknots, V_size + ORDER, vknots, V_size * 3, 3, &ctlpoints[0][0][0], ORDER, ORDER, GL_MAP2_VERTEX_3); gluEndSurface(theNurb);
  9. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 9 jgs

    5 curves x 6 control points per curve const int V_size = 6; const int U_size = 5; // curves in blue color const int ORDER = 4; GLfloat ctlpoints[U_size][V_size][3] = { { { 25, 5, 15 } ,{ 20, 5, 15 },{ 0, 0, 15 },{ -5, 0, 15 },{ -10, 5, 15 } ,{ -15, 5, 15 } }, { { 25, 5, 10 } ,{ 20, 0, 10 },{ 0, 0, 10 },{ -5, 0, 10 },{ -10, 0, 10 } ,{ -15, 5, 10 } }, { { 25, 0, 5 } ,{ 20, 0, 5 },{ 0, 15, 5 },{ -5, 15, 5 },{ -10, 0, 5 } ,{ -15, 0, 5 } }, { { 25, 0, -5 } ,{ 20, 0, -5 },{ 0, 10, -5 },{ -5, 10, -5 },{ -10, 0, -5 } ,{ -15, 0, -5 } }, { { 25, 5, -10 } ,{ 20, 0, -10 },{ 0, 0, -10 },{ -5, 0, -10 },{ -10, 0, -10 } ,{ -15, 5, -10 } } }; GLfloat uknots[U_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 1.0, 4.0, 4.0, 4.0, 4.0}; GLfloat vknots[V_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 1.0, 3.0, 5.0, 5.0, 5.0, 5.0 }; gluBeginSurface(theNurb); gluNurbsSurface(theNurb, U_size + ORDER, uknots, V_size + ORDER, vknots, V_size * 3, 3, &ctlpoints[0][0][0], ORDER, ORDER, GL_MAP2_VERTEX_3); gluEndSurface(theNurb);
  10. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 10 jgs

    4 curves x 6 control points per curve const int V_size = 6; const int U_size = 4; // curves in blue color const int ORDER = 4; GLfloat ctlpoints[U_size][V_size][3] = { { { 25, 5, 15 } ,{ 20, 5, 15 },{ 0, 0, 15 },{ -5, 0, 15 },{ -10, 5, 15 } ,{ -15, 5, 15 } }, { { 25, 5, 10 } ,{ 20, 0, 10 },{ 0, 0, 10 },{ -5, 0, 10 },{ -10, 0, 10 } ,{ -15, 5, 10 } }, { { 25, 0, 5 } ,{ 20, 0, 5 },{ 0, 15, 5 },{ -5, 15, 5 },{ -10, 0, 5 } ,{ -15, 0, 5 } }, { { 25, 0, -5 } ,{ 20, 0, -5 },{ 0, 10, -5 },{ -5, 10, -5 },{ -10, 0, -5 } ,{ -15, 0, -5 } } }; GLfloat uknots[U_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 3.0, 3.0, 3.0, 3.0}; GLfloat vknots[V_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 1.0, 3.0, 5.0, 5.0, 5.0, 5.0 }; gluBeginSurface(theNurb); gluNurbsSurface(theNurb, U_size + ORDER, uknots, V_size + ORDER, vknots, V_size * 3, 3, &ctlpoints[0][0][0], ORDER, ORDER, GL_MAP2_VERTEX_3); gluEndSurface(theNurb);
  11. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 12 jgs

    Test Yourselves What about 3? We need at least 4 using Cubic B-splines
  12. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 13 jgs

    Screenshot 4 curves 6 control points each 4 curves 5 control points each 4 curves 4 control points each
  13. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 14 jgs

    4 curves x 6 control points per curve const int V_size = 6; const int U_size = 4; // curves in blue color const int ORDER = 4; GLfloat ctlpoints[U_size][V_size][3] = { { { 25, 5, 15 } ,{ 20, 5, 15 },{ 0, 0, 15 },{ -5, 0, 15 },{ -10, 5, 15 } ,{ -15, 5, 15 } }, { { 25, 5, 10 } ,{ 20, 0, 10 },{ 0, 0, 10 },{ -5, 0, 10 },{ -10, 0, 10 } ,{ -15, 5, 10 } }, { { 25, 0, 5 } ,{ 20, 0, 5 },{ 0, 15, 5 },{ -5, 15, 5 },{ -10, 0, 5 } ,{ -15, 0, 5 } }, { { 25, 0, -5 } ,{ 20, 0, -5 },{ 0, 10, -5 },{ -5, 10, -5 },{ -10, 0, -5 } ,{ -15, 0, -5 } } }; GLfloat uknots[U_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 3.0, 3.0, 3.0, 3.0}; GLfloat vknots[V_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 1.0, 3.0, 5.0, 5.0, 5.0, 5.0 }; gluBeginSurface(theNurb); gluNurbsSurface(theNurb, U_size + ORDER, uknots, V_size + ORDER, vknots, V_size * 3, 3, &ctlpoints[0][0][0], ORDER, ORDER, GL_MAP2_VERTEX_3); gluEndSurface(theNurb);
  14. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 15 jgs

    4 curves x 5 control points per curve const int V_size = 5; const int U_size = 4; // curves in blue color const int ORDER = 4; GLfloat ctlpoints[U_size][V_size][3] = { { { 20, 5, 15 },{ 0, 0, 15 },{ -5, 0, 15 },{ -10, 5, 15 } ,{ -15, 5, 15 } }, { { 20, 0, 10 },{ 0, 0, 10 },{ -5, 0, 10 },{ -10, 0, 10 } ,{ -15, 5, 10 } }, { { 20, 0, 5 },{ 0, 15, 5 },{ -5, 15, 5 },{ -10, 0, 5 } ,{ -15, 0, 5 } }, { { 20, 0, -5 },{ 0, 10, -5 },{ -5, 10, -5 },{ -10, 0, -5 } ,{ -15, 0, -5 } } }; GLfloat uknots[U_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 3.0, 3.0, 3.0, 3.0}; GLfloat vknots[V_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 1.0, 4.0, 4.0, 4.0, 4.0 }; gluBeginSurface(theNurb); gluNurbsSurface(theNurb, U_size + ORDER, uknots, V_size + ORDER, vknots, V_size * 3, 3, &ctlpoints[0][0][0], ORDER, ORDER, GL_MAP2_VERTEX_3); gluEndSurface(theNurb);
  15. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 16 jgs

    4 curves x 4 control points per curve const int V_size = 4; const int U_size = 4; // curves in blue color const int ORDER = 4; GLfloat ctlpoints[U_size][V_size][3] = { { { 0, 0, 15 },{ -5, 0, 15 },{ -10, 5, 15 } ,{ -15, 5, 15 } }, { { 0, 0, 10 },{ -5, 0, 10 },{ -10, 0, 10 } ,{ -15, 5, 10 } }, { { 0, 15, 5 },{ -5, 15, 5 },{ -10, 0, 5 } ,{ -15, 0, 5 } }, { { 0, 10, -5 },{ -5, 10, -5 },{ -10, 0, -5 } ,{ -15, 0, -5 } } }; GLfloat uknots[U_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 3.0, 3.0, 3.0, 3.0}; GLfloat vknots[V_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 3.0, 3.0, 3.0, 3.0}; gluBeginSurface(theNurb); gluNurbsSurface(theNurb, U_size + ORDER, uknots, V_size + ORDER, vknots, V_size * 3, 3, &ctlpoints[0][0][0], ORDER, ORDER, GL_MAP2_VERTEX_3); gluEndSurface(theNurb);
  16. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 17 jgs

    Note § GLfloat uknots[U_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 2.0, 4.0, 4.0, 4.0, 3.0}; § GLfloat uknots[U_size + ORDER] = { 0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 1.0, 1.0, 1.0};
  17. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 19 jgs

    Problem A https://github.com/javiergs/SER431/blob/master/Lecture20/nurbs_surface_controlled.cpp
  18. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 20 jgs

    Problem B https://github.com/javiergs/SER431/blob/master/Lecture20/nurbs_surface_controlled.cpp * There are 7 squares (i.e., 7 curves)in blue. * You need 8 control points per square; BUT since you want to close the curve. You may should need to add the first one again. Thus 8 + 1
  19. jgs SER431 Advanced Graphics Javier Gonzalez-Sanchez [email protected] Fall 2018 Disclaimer.

    These slides can only be used as study material for the class SER431 at ASU. They cannot be distributed or used for another purpose.