void Implicit::Render() { // Draw bounding box for debugging Bbox b = GetBoundingBox(); Vector3<float> & v0 = b.pMin; Vector3<float> & v1 = b.pMax; if(mSelected) { glLineWidth(2.0f); glColor3f(0.8f,0.8f,0.8f); } else glColor3f(0.1f,0.1f,0.1f); glBegin(GL_LINE_STRIP); glVertex3f(v0[0], v0[1], v0[2]); glVertex3f(v1[0], v0[1], v0[2]); glVertex3f(v1[0], v1[1], v0[2]); glVertex3f(v0[0], v1[1], v0[2]); glVertex3f(v0[0], v0[1], v0[2]); glEnd(); glBegin(GL_LINE_STRIP); glVertex3f(v0[0], v0[1], v1[2]); glVertex3f(v1[0], v0[1], v1[2]); glVertex3f(v1[0], v1[1], v1[2]); glVertex3f(v0[0], v1[1], v1[2]); glVertex3f(v0[0], v0[1], v1[2]); glEnd(); glBegin(GL_LINES); glVertex3f(v0[0], v0[1], v0[2]); glVertex3f(v0[0], v0[1], v1[2]); glVertex3f(v1[0], v0[1], v0[2]); glVertex3f(v1[0], v0[1], v1[2]); glVertex3f(v0[0], v1[1], v0[2]); glVertex3f(v0[0], v1[1], v1[2]); glVertex3f(v1[0], v1[1], v0[2]); glVertex3f(v1[0], v1[1], v1[2]); glEnd(); glLineWidth(1.0f); glPushMatrix(); glMultMatrixf(mTransform.ToGLMatrix().GetArrayPtr()); Geometry * mesh = dynamic_cast<Geometry *>(mMesh); if (mesh == NULL) std::cerr << "Error: implicit geometry not triangulated, add call to triangulate()" << std::endl; else { mesh->SetShowNormals(mShowNormals); mesh->SetWireframe(mWireframe); mesh->SetOpacity(mOpacity); mesh->Render(); } if (mVisualizationMode == Gradients) { if(typeid(*mMesh) == typeid(SimpleMesh)){ SimpleMesh * ptr = static_cast<SimpleMesh*>(mMesh); const std::vector<SimpleMesh::Vertex>& verts = ptr->GetVerts(); glDisable(GL_LIGHTING); Matrix4x4<float> M = GetTransform().Transpose(); glColor3f(0, 0, 1); glBegin(GL_LINES); for(unsigned int i=0; i < verts.size(); i++){ const Vector3<float> vObject = verts.at(i).pos; // Transform vertex position to world space Vector4<float> vWorld = GetTransform() * Vector4<float>(vObject[0],vObject[1],vObject[2],1); // Get gradient in world space Vector3<float> nWorld = GetGradient(vWorld[0], vWorld[1], vWorld[2]); // Transform gradient to object space Vector4<float> nObject = M * Vector4<float>(nWorld[0],nWorld[1],nWorld[2],0); Vector3<float> n = Vector3<float>(nObject[0], nObject[1], nObject[2]); glVertex3fv(vObject.GetArrayPtr()); glVertex3fv((vObject + n*0.1).GetArrayPtr()); } glEnd(); } else { std::cerr << "No Gradient visualization mode implemented for mesh type: " << typeid(*mMesh).name() << std::endl; } } glPopMatrix(); GLObject::Render(); }
void HalfEdgeMesh::Render() { glEnable(GL_LIGHTING); glMatrixMode(GL_MODELVIEW); // Apply transform glPushMatrix(); // Push modelview matrix onto stack // Convert transform-matrix to format matching GL matrix format // Load transform into modelview matrix glMultMatrixf( mTransform.ToGLMatrix().GetArrayPtr() ); if (mWireframe) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // Draw geometry glBegin(GL_TRIANGLES); const int numTriangles = GetNumFaces(); for (int i = 0; i < numTriangles; i++){ Face & face = f(i); HalfEdge* edge = &e(face.edge); Vertex & v1 = v(edge->vert); edge = &e(edge->next); Vertex & v2 = v(edge->vert); edge = &e(edge->next); Vertex & v3 = v(edge->vert); if (mVisualizationMode == CurvatureVertex) { glColor3fv(v1.color.GetArrayPtr()); glNormal3fv(v1.normal.GetArrayPtr()); glVertex3fv(v1.pos.GetArrayPtr()); glColor3fv(v2.color.GetArrayPtr()); glNormal3fv(v2.normal.GetArrayPtr()); glVertex3fv(v2.pos.GetArrayPtr()); glColor3fv(v3.color.GetArrayPtr()); glNormal3fv(v3.normal.GetArrayPtr()); glVertex3fv(v3.pos.GetArrayPtr()); } else { glColor3fv(face.color.GetArrayPtr()); glNormal3fv(face.normal.GetArrayPtr()); glVertex3fv(v1.pos.GetArrayPtr()); glVertex3fv(v2.pos.GetArrayPtr()); glVertex3fv(v3.pos.GetArrayPtr()); } } glEnd(); // Mesh normals by courtesy of Richard Khoury if (mShowNormals) { glDisable(GL_LIGHTING); glBegin(GL_LINES); const int numTriangles = GetNumFaces(); for (int i = 0; i < numTriangles; i++){ Face & face = f(i); HalfEdge* edge = &e(face.edge); Vertex & v1 = v(edge->vert); edge = &e(edge->next); Vertex & v2 = v(edge->vert); edge = &e(edge->next); Vertex & v3 = v(edge->vert); Vector3<float> faceStart = (v1.pos + v2.pos + v3.pos) / 3.0f; Vector3<float> faceEnd = faceStart + face.normal*0.1; glColor3f(1,0,0); // Red for face normal glVertex3fv(faceStart.GetArrayPtr()); glVertex3fv(faceEnd.GetArrayPtr()); glColor3f(0,1,0); // Vertex normals in Green glVertex3fv(v1.pos.GetArrayPtr()); glVertex3fv((v1.pos + v1.normal*0.1).GetArrayPtr()); glVertex3fv(v2.pos.GetArrayPtr()); glVertex3fv((v2.pos + v2.normal*0.1).GetArrayPtr()); glVertex3fv(v3.pos.GetArrayPtr()); glVertex3fv((v3.pos + v3.normal*0.1).GetArrayPtr()); } glEnd(); glEnable(GL_LIGHTING); } if (mWireframe) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // Restore modelview matrix glPopMatrix(); GLObject::Render(); }
void SimpleMesh::Render() { glEnable(GL_LIGHTING); glMatrixMode(GL_MODELVIEW); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Apply transform glPushMatrix(); // Push modelview matrix onto stack // Convert transform-matrix to format matching GL matrix format // Load transform into modelview matrix glMultMatrixf( mTransform.ToGLMatrix().GetArrayPtr() ); if (mWireframe) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // Draw geometry glBegin(GL_TRIANGLES); const int numFaces = mFaces.size(); for (int i = 0; i < numFaces; i++){ Face& triangle = mFaces[i]; Vector3<float>& p0 = mVerts[triangle.v1].pos; Vector3<float>& p1 = mVerts[triangle.v2].pos; Vector3<float>& p2 = mVerts[triangle.v3].pos; if (mVisualizationMode == CurvatureVertex) { Vector3<float>& c1 = mVerts.at(triangle.v1).color; glColor4f(c1[0], c1[1], c1[2], mOpacity); glNormal3fv(mVerts.at(triangle.v1).normal.GetArrayPtr()); glVertex3fv(p0.GetArrayPtr()); Vector3<float>& c2 = mVerts.at(triangle.v2).color; glColor4f(c2[0], c2[1], c2[2], mOpacity); glNormal3fv(mVerts.at(triangle.v2).normal.GetArrayPtr()); glVertex3fv(p1.GetArrayPtr()); Vector3<float>& c3 = mVerts.at(triangle.v3).color; glColor4f(c3[0], c3[1], c3[2], mOpacity); glNormal3fv(mVerts.at(triangle.v3).normal.GetArrayPtr()); glVertex3fv(p2.GetArrayPtr()); } else { Vector3<float>& color = triangle.color; glColor4f(color[0], color[1], color[2], mOpacity); glNormal3fv(triangle.normal.GetArrayPtr()); glVertex3fv(p0.GetArrayPtr()); glVertex3fv(p1.GetArrayPtr()); glVertex3fv(p2.GetArrayPtr()); } } glEnd(); // Mesh normals by courtesy of Richard Khoury if (mShowNormals) { glDisable(GL_LIGHTING); glBegin(GL_LINES); for (unsigned int i = 0; i < mFaces.size(); i++){ Face & face = mFaces.at(i); Vertex & v1 = mVerts.at(face.v1); Vertex & v2 = mVerts.at(face.v2); Vertex & v3 = mVerts.at(face.v3); Vector3<float> faceStart = (v1.pos + v2.pos + v3.pos) / 3.0f; Vector3<float> faceEnd = faceStart + face.normal*0.1; glColor3f(1,0,0); // Red for face normal glVertex3fv(faceStart.GetArrayPtr()); glVertex3fv(faceEnd.GetArrayPtr()); glColor3f(0,1,0); // Vertex normals in Green glVertex3fv(v1.pos.GetArrayPtr()); glVertex3fv((v1.pos + v1.normal*0.1).GetArrayPtr()); glVertex3fv(v2.pos.GetArrayPtr()); glVertex3fv((v2.pos + v2.normal*0.1).GetArrayPtr()); glVertex3fv(v3.pos.GetArrayPtr()); glVertex3fv((v3.pos + v3.normal*0.1).GetArrayPtr()); } glEnd(); glEnable(GL_LIGHTING); } if (mWireframe) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // Restore modelview matrix glPopMatrix(); GLObject::Render(); }