Beispiel #1
0
void computeViewCurvature(Mesh &mesh, OpenMesh::Vec3f camPos, OpenMesh::VPropHandleT<CurvatureInfo> &curvature, OpenMesh::VPropHandleT<double> &viewCurvature, OpenMesh::FPropHandleT<OpenMesh::Vec3f> &viewCurvatureDerivative) {
	// WRITE CODE HERE TO COMPUTE CURVATURE IN THE VIEW PROJECTION PROJECTED ON THE TANGENT PLANE ------------------
	// Compute vector to viewer and project onto tangent plane, then use components in principal directions to find curvature
	
    for (Mesh::VertexIter it = mesh.vertices_begin(); it != mesh.vertices_end(); ++it) {
        Vec3f normal = mesh.normal(it.handle());
		Vector3d currentNormal(normal[0],normal[1],normal[2]);
		Matrix3d projectionMatrix = Matrix3d::Identity() - currentNormal*currentNormal.transpose();
        Vec3f vertex = mesh.point(it.handle());
        Vector3d viewRay(vertex[0]-camPos[0],vertex[1]-camPos[1],vertex[2]-camPos[2]);
        
        //Calculate viewing ray's projection onto the vertex tangent plane
        Vector3d projectedRay = (projectionMatrix*viewRay).normalized();
    
        //Calculate viewing curvature
        double k1 = mesh.property(curvature,it).curvatures[0];
        double k2 = mesh.property(curvature,it).curvatures[1];
        Vec3f pD1 = mesh.property(curvature,it).directions[0];
        Vec3f pD2 = mesh.property(curvature,it).directions[1];
        Vector3d principalDirection1(pD1[0],pD1[1],pD1[2]);
        Vector3d principalDirection2(pD2[0],pD2[1],pD2[2]);
        
        double viewCurvatureDouble = k1*principalDirection1.dot(viewRay) + k2*principalDirection2.dot(viewRay);
        
        mesh.property(viewCurvature,it) = viewCurvatureDouble;
    }
    
    // -------------------------------------------------------------------------------------------------------------

	
    
    // We'll use the finite elements piecewise hat method to find per-face gradients of the view curvature
	// CS 348a doesn't cover how to differentiate functions on a mesh (Take CS 468! Spring 2013!) so we provide code here
	
	for (Mesh::FaceIter it = mesh.faces_begin(); it != mesh.faces_end(); ++it) {
		double c[3];
		Vec3f p[3];
		
		Mesh::ConstFaceVertexIter fvIt = mesh.cfv_iter(it);
		for (int i = 0; i < 3; i++) {
			p[i] = mesh.point(fvIt.handle());
			c[i] = mesh.property(viewCurvature,fvIt.handle());
			++fvIt;
		}
		
		Vec3f N = mesh.normal(it.handle());
		double area = mesh.calc_sector_area(mesh.halfedge_handle(it.handle()));

		mesh.property(viewCurvatureDerivative,it) = (N%(p[0]-p[2]))*(c[1]-c[0])/(2*area) + (N%(p[1]-p[0]))*(c[2]-c[0])/(2*area);
	}
}
Beispiel #2
0
bool
is_collapse_legal(Mesh &mesh,Mesh::HalfedgeHandle _hh)
{
    // collect vertices
    Mesh::VertexHandle v0, v1;
    v0 = mesh.from_vertex_handle(_hh);
    v1 = mesh.to_vertex_handle(_hh);
    
    
    // collect faces
    Mesh::FaceHandle fl = mesh.face_handle(_hh);
    Mesh::FaceHandle fr = mesh.face_handle(mesh.opposite_halfedge_handle(_hh));
    
    
    // backup point positions
    Mesh::Point p0 = mesh.point(v0);
    Mesh::Point p1 = mesh.point(v1);
    
    
    // topological test
    if (!mesh.is_collapse_ok(_hh))
        return false;
    
    // test boundary stuff
    if (mesh.is_boundary(v0) && !mesh.is_boundary(v1))
        return false;
    
    for (Mesh::VertexFaceIter vfIt = mesh.vf_iter(v0); vfIt; ++vfIt) {
        if (vfIt.handle() == fl || vfIt.handle() == fr) continue;
        
        Mesh::Point p[3];
        
        Mesh::ConstFaceVertexIter cfvIt = mesh.cfv_iter(vfIt.handle());
        p[0] = mesh.point(cfvIt.handle());
        p[1] = mesh.point((++cfvIt).handle());
        p[2] = mesh.point((++cfvIt).handle());
        
        Mesh::Point q[3];
        
        for (int i = 0; i < 3; i++)
            q[i] = (p[i] == p0)? p1 : p[i];
        
        Mesh::Point n1 = (p[1]-p[0])%(p[2]-p[0]);
        Mesh::Point n2 = (q[1]-q[0])%(q[2]-q[0]);
        
        if ((n1|n2) < n1.length()*n2.length()/sqrt(2.)) return false;
    }
    
    return true;
}
Beispiel #3
0
void MeshView::drawMesh( DRAW_MODE d )
{
    if( m_meshPtr )
    {
        std::cout << "MeshView::drawMesh()" << std::endl;

        m_meshPtr->lock();

        Mesh::ConstFaceIter fIt(m_meshPtr->faces_begin()),
             fEnd(m_meshPtr->faces_end());
        Mesh::ConstFaceVertexIter fvIt;
        Mesh::ConstVertexIter vIt(m_meshPtr->vertices_begin());

        float color[4] = { 1.0, 1.0, 1.0, 1.0 };

        switch( d )
        {
        case POINTS_ONLY:
            glBegin(GL_POINTS);
            glColor3fv(color);
            for(; vIt!=m_meshPtr->vertices_end(); ++vIt)
            {
                if( prepareColor( color, m_meshPtr->color(vIt) ) )
                    glColor3fv(color);
                glVertex3dv(m_meshPtr->point(vIt));
            }
            glEnd();
            break;
        case WIREFRAME:
            for (; fIt!=fEnd; ++fIt)
            {
                glBegin(GL_LINE_STRIP);
                glColor3fv(color);
                fvIt = m_meshPtr->cfv_iter(fIt.handle());
                if( prepareColor( color, m_meshPtr->color(fvIt) ) )
                    glColor3fv(color);
                glVertex3dv(m_meshPtr->point(fvIt));
                ++fvIt;
                if( prepareColor( color, m_meshPtr->color(fvIt) ) )
                    glColor3fv(color);
                glVertex3dv(m_meshPtr->point(fvIt));
                ++fvIt;
                if( prepareColor( color, m_meshPtr->color(fvIt) ) )
                    glColor3fv(color);
                glVertex3dv(m_meshPtr->point(fvIt));
                glEnd();
            }
            break;
        case FACETS:
        case FLAT_FACET:
            glBegin(GL_TRIANGLES);
            glColor3fv(color);
            for (; fIt!=fEnd; ++fIt)
            {
                glNormal3fv( m_meshPtr->normal( fIt.handle() ) );
                fvIt = m_meshPtr->cfv_iter(fIt.handle());
                if( prepareColor( color, m_meshPtr->color(fvIt) ) )
                    glColor3fv(color);
                glVertex3dv(m_meshPtr->point(fvIt));
                ++fvIt;
                if( prepareColor( color, m_meshPtr->color(fvIt) ) )
                    glColor3fv(color);
                glVertex3dv(m_meshPtr->point(fvIt));
                ++fvIt;
                if( prepareColor( color, m_meshPtr->color(fvIt) ) )
                    glColor3fv(color);
                glVertex3dv(m_meshPtr->point(fvIt));
            }
            glEnd();
            break;
        case SMOOTH_FACET:
            glBegin(GL_TRIANGLES);
            glColor3fv(color);
            for (; fIt!=fEnd; ++fIt)
            {
                fvIt = m_meshPtr->cfv_iter(fIt.handle());
                glNormal3fv(m_meshPtr->normal(fvIt.handle()) );
                if( prepareColor( color, m_meshPtr->color(fvIt) ) )
                    glColor3fv(color);
                glVertex3dv(m_meshPtr->point(fvIt));
                ++fvIt;
                glNormal3fv(m_meshPtr->normal(fvIt.handle()));
                if( prepareColor( color, m_meshPtr->color(fvIt) ) )
                    glColor3fv(color);
                glVertex3dv(m_meshPtr->point(fvIt));
                ++fvIt;
                glNormal3fv(m_meshPtr->normal(fvIt.handle()));
                if( prepareColor( color, m_meshPtr->color(fvIt) ) )
                    glColor3fv(color);
                glVertex3dv(m_meshPtr->point(fvIt));
            }
            glEnd();
            break;
        default:
            break;
        }
        //glFlush();
        m_meshPtr->unlock();
        setDirty(false);
        //std::cout << " } MeshView::drawMesh()" << std::endl;
    }
}