/* draw the polycone shape */ void DrawStuff (void) { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* set up some matrices so that the object spins with the mouse */ glPushMatrix (); glTranslatef (0.0, 0.0, -80.0); glRotatef (lastx, 0.0, 1.0, 0.0); glRotatef (lasty, 1.0, 0.0, 0.0); /* Phew. FINALLY, Draw the polycone -- */ glePolyCone_c4f (idx, points, colors, radii_small); glePolyCone_c4f (idx, points, colors_thin, radii); glPopMatrix (); glutSwapBuffers (); }
void drawBranchObject(node a, BranchAttributeObj branchAttributes, float radius1,float radius2) // Draw a cylinder subtending a node, using precomputed values from trig routine // This is currently the only place in the code I need GL_LIGHTING on // This is drawn in the original object coordinate system in which the tree is centered on 0,0 // TO DO enable attenuate on/off flag // Not doing blending or lod_cutoff for tubes yet // Currently doing the lod_cutoff for branchStyle==line only ; makes a big difference { extern GLUquadricObj *qobj; GLfloat params[4]; GLboolean valid; float darkness; float xdist,ydist,zdist; float sknots[8] = { 0,0,0,0,1,1,1,1}; GLfloat ctlpoints[4][4]; // four control points = 2 end points + two "control" points area A,Aanc; double dx,dy,dz,zr,xcross,ycross,theta, color, color_anc; A=(area)(a->data); float r1,r2,z1,z2; if (branchAttributes->branchCurvy == nurbs) // set up control points { // TO DO. CURRENTLY THESE CONTROL POINTS ARE ALL IN A VERTICAL PLANE. MAKE THE TREE CURVIER YET BY MOVING THEM OFF THIS PLANE. // Setting up the two endpoints of the edge; cubic spline will interpolate these two points // NB. These are bogus for circle layout, because there is no variation in the z-axis there, ctlpoints[0][0]=A->x_anc; ctlpoints[0][1]=A->y_anc; ctlpoints[0][2]=A->z_anc; ctlpoints[0][3]=1.0; ctlpoints[3][0]=A->x_center; ctlpoints[3][1]=A->y_center; ctlpoints[3][2]=A->z; ctlpoints[3][3]=1.0; // Setting up the two control points. These are each tweaked with a z parameter and an r parameter in the vertical plane // defined by the two endpoints of the edge, such that both when (r,z) is (0,0) at anc node and (1,1) at desc node. // So we need an (r,z) for each control point: r1,z1,r2,z2. xdist = A->x_center - A->x_anc; ydist = A->y_center - A->y_anc; zdist = A->z - A->z_anc; extern float gr1,gr2,gz1,gz2; r1 = gr1; //branchAttributes->ctlpointParms[0]; z1 = gz1; //branchAttributes->ctlpointParms[1]; r2 = gr2; //branchAttributes->ctlpointParms[2]; z2 = gz2; //branchAttributes->ctlpointParms[3]; ctlpoints[1][0]=A->x_anc + xdist*r1; ctlpoints[1][1]=A->y_anc + ydist*r1; ctlpoints[1][2]=A->z_anc + zdist*z1; ctlpoints[1][3]=1.0; ctlpoints[2][0]=A->x_anc + xdist*r2; ctlpoints[2][1]=A->y_anc + ydist*r2; ctlpoints[2][2]=A->z_anc + zdist*z2; ctlpoints[2][3]=1.0; } switch (branchAttributes->branchStyle) { case tube: { glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); switch (branchAttributes->branchCurvy) { case nurbs: { if (a->marked) { darkness=1; glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); } else darkness = setColorWithAttenuationLineSegment(A->x_center,A->y_center,A->z, A->x_anc,A->y_anc,A->z_anc, &(branchAttributes->color[0]), branchAttributes->attenuateFactor); // Turn off actual rendering here...no need to draw the line, just get callbacks...use GLU_tesselator gluNurbsProperty(theNurbs,GLU_NURBS_MODE,GLU_NURBS_TESSELLATOR); gluBeginCurve(theNurbs); gluNurbsCurve(theNurbs, 8, sknots, 4, &ctlpoints[0][0], 4, GL_MAP1_VERTEX_4); gluEndCurve(theNurbs); gluNurbsProperty(theNurbs,GLU_NURBS_MODE,GLU_NURBS_RENDERER); int i; float gleColor[500][4]; double gleRadius[500]; for (i=0; i<gNpoints; i++) // set the vectors of colors and radii { if (gNpoints > 500) exit(1); gleColor[i][0]= branchAttributes->color[0]; gleColor[i][1]= branchAttributes->color[1]; gleColor[i][2]= branchAttributes->color[2]; gleColor[i][3]= darkness; // don't seem to need this shit; taken care of by glMaterial if (gNpoints > 1) gleRadius[i] = radius1 + (radius2-radius1)*i/(gNpoints-1); // interpolate to vary radius between nodes of branch else gleRadius[i] = radius1; } params[0]=branchAttributes->color[0]; params[1]=branchAttributes->color[1]; params[2]=branchAttributes->color[2]; params[3]=darkness; params[3]=1.0; //override for now; I don't like how the blending looks glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); //glEnable(GL_LINE_SMOOTH); //glHint(GL_LINE_SMOOTH_HINT,GL_NICEST); // Antialiasing not working in this gle environment //glEnable(GL_POLYGON_SMOOTH); //glHint(GL_POLYGON_SMOOTH_HINT,GL_NICEST); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, params); gleSetJoinStyle(TUBE_JN_ROUND) ; //glePolyCylinder(gNpoints,gPoint_array,gleColor,radius2); //glePolyCone_c4f(gNpoints,gPoint_array,gleColor,gleRadius); // Note if we pass gleColor, that overrides the material color and its alpha blending; // so to enable blending pass NULL in place of gleColor, and set glMaterial above glePolyCone_c4f(gNpoints,gPoint_array,NULL,gleRadius); //drawCylinder(gPoint_array[0][0],gPoint_array[0][1],gPoint_array[0][2], gPoint_array[1][0],gPoint_array[1][1],gPoint_array[1][2],radius1, radius1); // add gumby cyls at ends of gle cylinder //drawCylinder(gPoint_array[gNpoints-2][0],gPoint_array[gNpoints-2][1],gPoint_array[gNpoints-2][2], gPoint_array[gNpoints-1][0],gPoint_array[gNpoints-1][1],gPoint_array[gNpoints-1][2],radius2, radius2); // Because gle does not extrude at the two endpoints, I draw cylinders at each endpoint. To avoid gappiness at borders, I overlap the cylinder with the extruded tube by one segment (one point on the polyline), thus I run the cylinder from, e.g., point 0 to point 2, where the extrusion starts at 1. drawCylinder(gPoint_array[0][0],gPoint_array[0][1],gPoint_array[0][2], gPoint_array[2][0],gPoint_array[2][1],gPoint_array[2][2],gleRadius[0], gleRadius[2]); // add gumby cyls at ends of gle cylinder drawCylinder(gPoint_array[gNpoints-3][0],gPoint_array[gNpoints-3][1],gPoint_array[gNpoints-3][2], gPoint_array[gNpoints-1][0],gPoint_array[gNpoints-1][1],gPoint_array[gNpoints-1][2],gleRadius[gNpoints-3],gleRadius[gNpoints-1]); //glDisable(GL_LIGHTING); break; } case straight: { params[0]=branchAttributes->color[0]; params[1]=branchAttributes->color[1]; params[2]=branchAttributes->color[2]; params[3]=darkness; glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, params); drawCylinder(A->x_anc,A->y_anc,A->z_anc, A->x_center,A->y_center,A->z, radius1, radius2); break; } } glDisable(GL_LIGHTING); break; } case line: { if (!isRoot(a)) { glLineWidth(branchAttributes->lineWidth); if (a->marked) { darkness=1; glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glColor4f(branchAttributes->color[0],branchAttributes->color[1],branchAttributes->color[2],darkness); } else darkness = setColorWithAttenuationLineSegment(A->x_center,A->y_center,A->z, A->x_anc,A->y_anc,A->z_anc, &(branchAttributes->color[0]), branchAttributes->attenuateFactor); // there is similar code in function setColorWithAttenuation() in tree_openGL, but here we have something more elaborate... switch (branchAttributes->branchCurvy) { case nurbs: { if (branchAttributes->lod_cutoff < darkness) { gluNurbsProperty(theNurbs,GLU_NURBS_MODE,GLU_NURBS_RENDERER); gluBeginCurve(theNurbs); gluNurbsCurve(theNurbs, 8, sknots, 4, &ctlpoints[0][0], 4, GL_MAP1_VERTEX_4); gluEndCurve(theNurbs); } break; } case straight: { if (branchAttributes->lod_cutoff < darkness) { glBegin(GL_LINES); glVertex3d(A->x_anc,A->y_anc,A->z_anc); glVertex3d(A->x_center,A->y_center,A->z); glEnd(); } } } break; } } } }
/* draw the helix shape */ void DrawStuff (void) { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f (0.8, 0.3, 0.6); glPushMatrix (); /* set up some matrices so that the object spins with the mouse */ glTranslatef (0.0,0.0,-300.0); glRotatef (rotate_frame[1], 1.0, 0.0, 0.0); glRotatef (rotate_frame[0], 0.0, 0.0, 1.0); //change thread, if necessary if (move_end[0] != 0.0 || move_end[1] != 0.0 || tangent_end[0] != 0.0 || tangent_end[1] != 0.0) { GLdouble model_view[16]; glGetDoublev(GL_MODELVIEW_MATRIX, model_view); GLdouble projection[16]; glGetDoublev(GL_PROJECTION_MATRIX, projection); GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); double winX, winY, winZ; //change end positions gluProject(positions[1](0), positions[1](1), positions[1](2), model_view, projection, viewport, &winX, &winY, &winZ); winX += move_end[0]; winY += move_end[1]; move_end[0] = 0.0; move_end[1] = 0.0; gluUnProject(winX, winY, winZ, model_view, projection, viewport, &positions[1](0), &positions[1](1), &positions[1](2)); // std::cout << "X: " << positions[1](0) << " Y: " << positions[1](1) << " Z: " << positions[1](2) << std::endl; //change tangents gluProject(tangents[1](0), tangents[1](1), tangents[1](2), model_view, projection, viewport, &winX, &winY, &winZ); winX += tangent_end[0]; winY += tangent_end[1]; tangent_end[0] = 0.0; tangent_end[1] = 0.0; gluUnProject(winX, winY, winZ, model_view, projection, viewport, &tangents[1](0), &tangents[1](1), &tangents[1](2)); tangents[1].normalize(); //change thread thread->setConstraints(positions, tangents); thread->upsampleAndOptimize_minLength(0.065); thread->minimize_energy(); Point2i start; updateIms(start); vision_draw.resize(0); threadStereo->optimizeThread(vision_draw, start); threadStereo->display(); //std::cout << "objX: " <<objX << " objY: " << objY << " objZ: " << objZ << " winX: " << winX << " winY: " << winY << " winZ: " << winZ << std::endl; } //Draw Axes glBegin(GL_LINES); glEnable(GL_LINE_SMOOTH); glColor3d(1.0, 0.0, 0.0); //red glVertex3f(0.0f, 0.0f, 0.0f); //x glVertex3f(20.0f, 0.0f, 0.0f); glColor3d(0.0, 1.0, 0.0); //green glVertex3f(0.0f, 0.0f, 0.0f); //y glVertex3f(0.0f, 20.0f, 0.0f); glColor3d(0.0, 0.0, 1.0); //blue glVertex3f(0.0f, 0.0f, 0.0f); //z glVertex3f(0.0f, 0.0f, 20.0f); glColor3d(0.5, 0.5, 1.0); glVertex3f(positions[1](0)-positions[0](0), positions[1](1)-positions[0](1), positions[1](2)-positions[0](2)); //z glVertex3f(positions[1](0)-positions[0](0)+tangents[1](0)*4.0, positions[1](1)-positions[0](1)+tangents[1](1)*4.0, positions[1](2)-positions[0](2)+tangents[1](2)*4.0); //z glEnd( ); //label axes void * font = GLUT_BITMAP_HELVETICA_18; glColor3d(1.0, 0.0, 0.0); //red glRasterPos3i(20.0, 0.0, -1.0); glutBitmapCharacter(font, 'X'); glColor3d(0.0, 1.0, 0.0); //red glRasterPos3i(0.0, 20.0, -1.0); glutBitmapCharacter(font, 'Y'); glColor3d(0.0, 0.0, 1.0); //red glRasterPos3i(-1.0, 0.0, 20.0); glutBitmapCharacter(font, 'Z'); //Draw lines from vision for (int i=0; i < vision_draw.size(); i++) { glline_draw_params& currP = vision_draw[i]; glBegin(GL_LINE_STRIP); glColor4f(currP.color[0], currP.color[1], currP.color[2], 1.0); for (int j=0; j < currP.size; j++) { glVertex3f(currP.vertices[j].x-positions[0](0), currP.vertices[j].y-positions[0](1), currP.vertices[j].z-positions[0](2)); } glEnd(); } //Draw Thread glColor4f (0.5, 0.5, 0.2, 0.5); thread->getPoints(points); double pts_cpy[NUM_PTS][3]; for (int i=0; i < NUM_PTS; i++) { pts_cpy[i][0] = points(i,0)-(double)positions[0](0); pts_cpy[i][1] = points(i,1)-(double)positions[0](1); pts_cpy[i][2] = points(i,2)-(double)positions[0](2); } glePolyCone_c4f (NUM_PTS, pts_cpy, 0x0, radii); glPopMatrix (); glutSwapBuffers (); }