Ejemplo n.º 1
0
void KnotsViewer::draw_curvature_error_domain()
{

    if(surfacedata==NULL)
        return;
    if ((surfacedata->get_domain()).empty())
        return;
    MyMesh polymesh = surfacedata->get_polymesh();
    if (polymesh.edges_empty()==true)
        return;
    MyMesh::ConstFaceIter        f_it(polymesh.faces_begin()),f_end(polymesh.faces_end());
    MyMesh::ConstFaceVertexIter  fv_it;
    //glLineWidth(0.5);
    for (; f_it!=f_end; ++f_it)
    {

        glColor3ubv(polymesh.color(*f_it).data());
        glBegin(GL_POLYGON);
        fv_it = polymesh.cfv_iter(*f_it);
        glVertex3dv(&polymesh.point(fv_it)[0]);
        ++fv_it;
        glVertex3dv(&polymesh.point(fv_it)[0]);
        ++fv_it;
        glVertex3dv(&polymesh.point(fv_it)[0]);
        ++fv_it;
        glVertex3dv(&polymesh.point(fv_it)[0]);
        glEnd();
    }


}
Ejemplo n.º 2
0
void KnotsViewer::draw_curvature_mesh()
{
    if(surfacedata==NULL)
        return;
    if ((surfacedata->get_domain()).empty())
        return;
    Mesh *mesh = surfacedata->get_original_mesh();
    if (mesh==NULL)
        return;
    Mesh::ConstFaceIter        f_it(mesh->faces_begin()),f_end(mesh->faces_end());
    Mesh::ConstFaceVertexIter  fv_it;
    //glLineWidth(0.5);
    for (; f_it!=f_end; ++f_it)
    {

        glBegin(GL_TRIANGLES);
        fv_it = mesh->cfv_iter(*f_it);
        glColor3ubv(mesh->color(*fv_it).data());
        glVertex2dv(&mesh->texcoord2D(fv_it)[0]);
        ++fv_it;
        glColor3ubv(mesh->color(*fv_it).data());
        glVertex2dv(&mesh->texcoord2D(fv_it)[0]);
        ++fv_it;
        glColor3ubv(mesh->color(*fv_it).data());
        glVertex2dv(&mesh->texcoord2D(fv_it)[0]);
        glEnd();
    }



}
Ejemplo n.º 3
0
void HEMesh::get_feature(std::function<std::vector<unsigned int>(void)> feature)
{
	auto features_vector = feature();
	no_faces = features_vector.size();
	draw_mode = GL_TRIANGLES;

	std::vector<glm::vec3> faces_vertices;
	faces_vertices.reserve(no_faces * 3);

	for(auto const & face_idx : features_vector)
	{
		MyMesh::FaceHandle f_it(face_idx);

		for(MyMesh::FaceVertexIter fv_it = mesh.fv_iter(f_it); fv_it.is_valid(); ++fv_it)
		{
			auto vert = mesh.point(*fv_it);
			faces_vertices.push_back(glm::vec3(vert[0], vert[1], vert[2]));
		}
	}

	glDeleteBuffers(1, &this->VBO_feature);

	glBindVertexArray(this->VAO);
	glGenBuffers(1, &this->VBO_feature);
	glBindBuffer(GL_ARRAY_BUFFER, this->VBO_feature);
	glBufferData(GL_ARRAY_BUFFER, faces_vertices.size() * sizeof(glm::vec3), &faces_vertices[0], GL_STATIC_DRAW);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*) 0);
	glEnableVertexAttribArray(0);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindVertexArray(0);
}
Ejemplo n.º 4
0
void KnotsViewer::draw_domain_mesh()
{

    if(surfacedata==NULL)
        return;
    if ((surfacedata->get_domain()).empty())
        return;
    Mesh *mesh = surfacedata->get_original_mesh();
    if (mesh==NULL)
        return;
    Mesh::ConstFaceIter        f_it(mesh->faces_begin()),f_end(mesh->faces_end());
    Mesh::ConstFaceVertexIter  fv_it;
    glColor3d(0.4, 0.4, 0.5);
    glLineWidth(0.5);

    for (; f_it!=f_end; ++f_it)
    {
        glBegin(GL_LINE_LOOP);
        fv_it = mesh->cfv_iter(*f_it);
        glVertex2dv(&mesh->texcoord2D(fv_it)[0]);
        ++fv_it;
        glVertex2dv(&mesh->texcoord2D(fv_it)[0]);
        ++fv_it;
        glVertex2dv(&mesh->texcoord2D(fv_it)[0]);
        glEnd();
    }


    //检测每个条形所包含的点
    /*glColor3d(1.0, 0.0, 0.0);
    glPointSize(2);
    vector<int>  h=surfacedata->test;
    glBegin(GL_POINTS);
    for (vector<int>::iterator p=h.begin();p!=h.end();++p)
    {
       Mesh::VertexHandle f=mesh->vertex_handle(*p);
       glVertex2dv(&mesh->texcoord2D(f)[0]);
    }
    glEnd();*/

    //检测每个条形所包含的三角形
    //glColor3d(1.0, 0.0, 0.0);
    //set<int>  h=surfacedata->test2;
    //Mesh::FaceVertexIter  fv_it2;
//  for (set<int>::iterator p=h.begin();p!=h.end();++p)
//  {
    //   Mesh::FaceHandle f_it=mesh->face_handle(*p);
    //   glBegin(GL_TRIANGLES);
    //   fv_it2 = mesh->fv_iter(f_it);
    //   glVertex2dv(&mesh->texcoord2D(fv_it2)[0]);
    //   ++fv_it2;
    //   glVertex2dv(&mesh->texcoord2D(fv_it2)[0]);
    //   ++fv_it2;
    //   glVertex2dv(&mesh->texcoord2D(fv_it2)[0]);
    //   glEnd();
//  }


}
Ejemplo n.º 5
0
void MeshViewer::UpdateFaceIndices()
{
	txMesh::ConstFaceIter 
		f_it(m_Mesh.faces_sbegin()),
		f_end(m_Mesh.faces_end());

	txMesh::ConstFaceVertexIter fv_it;

	m_Indices = std::vector<unsigned int>();
	m_Indices.reserve(m_Mesh.n_faces()*3);
	std::cout << "mesh indices updated" << std::endl;

	for (; f_it!=f_end; ++f_it) {
		m_Indices.push_back((fv_it=m_Mesh.cfv_begin(f_it)).handle().idx());
		m_Indices.push_back((++fv_it).handle().idx());
		m_Indices.push_back((++fv_it).handle().idx());
	}
}
Ejemplo n.º 6
0
void DecimationModel::draw() {

    if (meshtype_toberendered_ == ORIGINAL) {


        MeshModel::draw();
    } else if (meshtype_toberendered_ == SIMPLIFIED || meshtype_toberendered_ == RESAMPLE_MIDPOINT) {
        // 第一步, 要是做了参数化的话先显示所有顶点, 包括那些被deleted但是参数化到base complex面上的点.
        for (TriMesh::VIter v_it(mesh2_.vertices_begin()), v_end(mesh2_.vertices_end()); v_it != v_end; ++v_it) {
            if ( v_it.handle() == test_vertex_||v_it.handle().idx() == 69000 ) {//|| v_it.handle().idx() == 1493
                glColor3f(0, 1, 0);
                glPointSize(10);
                glBegin(GL_POINTS);
                GL::glVertex(mesh2_.point(v_it));
                glEnd();
                glPointSize(1);
            }
            if (v_it.handle() == test_vertex1_ || v_it.handle().idx() == 56656 || v_it.handle().idx() == 66696 ||v_it.handle().idx() == 203340) {//
                glColor3f(0, 1, 1);
                glPointSize(10);
                glBegin(GL_POINTS);
                GL::glVertex(mesh2_.point(v_it));
                glEnd();
                glPointSize(1);
            }
        }
        for (TriMesh::VIter v_it(initial_control_mesh_.vertices_begin()), v_end(initial_control_mesh_.vertices_end()); v_it != v_end; ++v_it) {
            if (v_it.handle() == test_vertex_ ) { //显示新分裂的顶点
                glColor3f(0, 1, 0);
                glPointSize(10);
                glBegin(GL_POINTS);
                GL::glVertex(initial_control_mesh_.point(v_it));
                glEnd();
                glPointSize(1);
            }
        }


        //int fandisk_arr[] = { //这些是一部分特征边
        //	9, 269, 265,
        //	261, 257, 254,
        //	250, 246, 241,
        //	237, 233, 229,
        //	225, 221, 217,
        //	214, 210, 206,
        //	//202, 995, 9762

        //	9922, 9925, 9928,
        //	9931, 9934, 9939,
        //	9943, 9947, 9951,
        //	9954, 9958, 9962,
        //	9966, 9970, 9974,
        //	9978, 9982, 9986,
        //	9990, 9994, 9998,
        //	10002, 10006, 10011,
        //	10014, 784, 788

        //};
        //std::vector<int> fandisk(fandisk_arr, fandisk_arr+18+27);
        //for (int i = 0; i < 45; ++i) {
        //	glColor3f(1, 0, 1); // 显示特征边
        //	glLineWidth(3.5);
        //	glBegin(GL_LINES);
        //	GL::glVertex(mesh2_.point(mesh2_.to_vertex_handle(mesh2_.halfedge_handle(mesh2_.edge_handle(fandisk_arr[i]), 0))));
        //	GL::glVertex(mesh2_.point(mesh2_.to_vertex_handle(mesh2_.halfedge_handle(mesh2_.edge_handle(fandisk_arr[i]), 1))));
        //	glEnd();
        //	glLineWidth(1.0);

        //}

        if (do_parameterization_) {
            //(1) 先显示所有顶点, 包括那些被deleted但是参数化到base complex面上的点.
            // 但是后来我觉得这可以省略, 因为下面显示mesh_collapsed_时候就会显示这些被参数化的点了.
            glDisable(GL_LIGHTING);

            for (TriMesh::EIter e_it(mesh_.edges_begin()), e_end(mesh_.edges_end()); e_it != e_end; ++e_it) {
                if (mesh_.status(e_it).deleted() == false) {
                    if (mesh_.status(e_it).feature()) {
                        glColor3f(1, 0, 1); // 显示特征边
                        glLineWidth(3.5);
                        glBegin(GL_LINES);
                        GL::glVertex(mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it.handle(), 0))));
                        GL::glVertex(mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it.handle(), 1))));
                        glEnd();
                        glLineWidth(1.0);/**/

                    }
                    if (meshtype_toberendered_ == RESAMPLE_MIDPOINT) {
                        if (mesh_.property(empl_, e_it.handle()) == true) { //已经求出中点的了.
                            glColor3f(0, 1, 0);//黄色 显示那些采样点
                            glPointSize(4);
                            //glBegin(GL_POINTS);
                            //GL::glVertex(mesh_.property(emp_, e_it.handle()));
                            //glEnd();
                            glPointSize(1);
                            glPushMatrix();
                            glTranslatef( mesh_.property(emp_, e_it.handle())[0], mesh_.property(emp_, e_it.handle())[1], mesh_.property(emp_, e_it.handle())[2] );
                            glutSolidSphere(bb.diagonal_lenght*0.003, 20, 20);
                            glPopMatrix();
                        } else { // 还没有求出中点的
                            glColor3f(0.f, 1.f, 0.f);//绿色 显示那些没有对中点采样成功的边
                            glLineWidth(6.5);
                            glBegin(GL_LINES);
                            GL::glVertex(mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it, 0))));
                            GL::glVertex(mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it, 1))));
                            glEnd();
                            glLineWidth(1.0);
                        }
                    } // 如果是中点采样的话显示采样点或不成功的边.
                }
            }

            // (4) 显示被参数化的网格, 作为参考.用hiden line线框模式显示
            if (mesh_collapsed_render_or_not_) {
                DGP::hidderline_render(mesh_collapsed_, OpenMesh::Vec3f(0.0, 0.0, 1.0));
            }

            /////////////////////////////
            //draw_mode_ = HIDDENLINE;//LINEANDSOLIDFLAT; //NONE; // //这里设置了的话用户就不可以选择了.
        } //end of if (do_parameterization_).
        // 第二步, 正常显示.
        MeshModel::draw();
    } else if (meshtype_toberendered_ == REFINED_SIMPLIFIED) {
        //glBegin(GL_POINTS);
        //GL::glColor(OpenMesh::Vec3f(1, 0, 0));
        //glPointSize(3.0);
        //for (TriMesh::FIter f_it(mesh_.faces_begin()), f_end(mesh_.faces_end()); f_it != f_end; ++f_it) {
        //	for (std::vector<TriMesh::VHandle>::const_iterator it(mesh_.property(fvset_, f_it.handle()).begin()), it_end(mesh_.property(fvset_, f_it.handle()).end());
        //		it != it_end; ++it) {
        //			if (32 == mesh_.property(vf_of_rsm_, *it).idx())
        //			GL::glVertex(refined_simplified_mesh_.point(mesh_.property(vf0_of_rsm_, *it)) * mesh_.property(vbc_of_rsm_, *it)[0]
        //			+ refined_simplified_mesh_.point(mesh_.property(vf1_of_rsm_, *it)) * mesh_.property(vbc_of_rsm_, *it)[1]
        //			+ refined_simplified_mesh_.point(mesh_.property(vf2_of_rsm_, *it)) * mesh_.property(vbc_of_rsm_, *it)[2]);

        //	}
        //}glPointSize(1);
        //glEnd();
        MeshModel::draw();
    } else if (meshtype_toberendered_ == INITIAL_CONTROL ||meshtype_toberendered_ == LOOP_ONE
               || meshtype_toberendered_ == LIMIT) {

        if (upperbounding_mesh_.n_vertices()) {
            //if (upperbounding_mesh_.empty() == false) {// renc: 20150829
            DGP::hidderline_render(upperbounding_mesh_, OpenMesh::Vec3f(0, 0, 1));
            DGP::hidderline_render(lowerbounding_mesh_, OpenMesh::Vec3f(0, 1, 0));
        }
        glBegin(GL_LINES);
        glLineWidth(3);
        glColor3f(1, 0, 0);
        for (int i = 0; i < laplacian_.size(); ++i) {
            TriMesh::VHandle vh = refined_simplified_mesh_.vertex_handle(i);
            GL::glVertex(refined_simplified_mesh_.point(vh));
            GL::glVertex(refined_simplified_mesh_.point(vh) + laplacian_[i]);
        }
        glColor3f(0, 1, 0);
        for (int i = 0; i < laplacian_rcm_.size(); ++i) {
            TriMesh::VHandle vh = refined_simplified_mesh_.vertex_handle(i);
            GL::glVertex(refined_simplified_mesh_.point(vh));
            GL::glVertex(refined_simplified_mesh_.point(vh) + laplacian_rcm_[i]);
        }
        glEnd();
        // 下面画出采样点到evaluation坐标的连线, 也画出到closest坐标的连线, 可视化比较是否离采样点近了.
        glLineWidth(4);
        glBegin(GL_LINES);
        GL::glColor(OpenMesh::Vec3f(0, 1, 0));
        for (TriMesh::VIter v_it(mesh_.vertices_begin()), v_end(mesh_.vertices_end()); v_it != v_end; ++v_it) {
            if (mesh_.status(v_it).deleted()) { //原始网格的点到其在极限曲面上的位置的连线
                if (std::find(vsplit_array_.begin(), vsplit_array_.end(), v_it.handle()) != vsplit_array_.end())
                    if (mesh_.property(vp_eval_, v_it)) {
                        GL::glVertex(mesh_.property(vp_eval_pos_, v_it.handle()));
                        GL::glVertex(mesh2_.point(v_it));
                    }
            }
        }
        GL::glColor(OpenMesh::Vec3f(1, 1, 0));//最近点
        for (TriMesh::VIter v_it(mesh_.vertices_begin()), v_end(mesh_.vertices_end()); v_it != v_end; ++v_it) {
            if (mesh_.status(v_it).deleted()) {
                if (std::find(vsplit_array_.begin(), vsplit_array_.end(), v_it.handle()) != vsplit_array_.end())
                    if (mesh_.property(vp_closest_, v_it)) {
                        GL::glVertex(mesh_.property(vp_closest_pos_, v_it));
                        GL::glVertex(mesh2_.point(v_it));
                    }
            }
        }
        GL::glColor(OpenMesh::Vec3f(1, 0, 0));//project point
        for (TriMesh::VIter v_it(mesh_.vertices_begin()), v_end(mesh_.vertices_end()); v_it != v_end; ++v_it) {
            if (mesh_.status(v_it).deleted()) {
                if (std::find(vsplit_array_.begin(), vsplit_array_.end(), v_it.handle()) != vsplit_array_.end())
                    if (mesh_.property(vp_project_, v_it)) {
                        GL::glVertex(mesh_.property(vp_project_pos_, v_it));
                        GL::glVertex(mesh2_.point(v_it));
                    }
            }
        }
        glEnd();
        glLineWidth(1);

        if (is_view_fitting_error_of_mesh2_) {
            glDisable(GL_LIGHTING);
            glShadeModel(GL_SMOOTH);

            // 被取代的原因详见MeshViewer::draw(_draw_mode)函数
            glEnableClientState(GL_VERTEX_ARRAY);
            glEnableClientState(GL_NORMAL_ARRAY);
            glEnableClientState(GL_COLOR_ARRAY);
            GL::glVertexPointer(mesh2_.points());
            GL::glNormalPointer(mesh2_.vertex_normals());
            GL::glColorPointer(mesh2_.vertex_colors());

            glDrawElements(GL_TRIANGLES, mesh2_indices_for_render_.size(), GL_UNSIGNED_INT, &mesh2_indices_for_render_[0]);

            glDisableClientState(GL_VERTEX_ARRAY);
            glDisableClientState(GL_NORMAL_ARRAY);
            glDisableClientState(GL_COLOR_ARRAY);
        }
        if (is_view_fitting_error_of_sm_) {
            glDisable(GL_LIGHTING);
            glShadeModel(GL_SMOOTH);

            glBegin(GL_TRIANGLES);
            for (TriMesh::FIter f_it(simplified_mesh_.faces_begin()), f_end(simplified_mesh_.faces_end()); f_it!=f_end; ++f_it) { // 这种方式应该学学啊
                TriMesh::FVIter fv_it = simplified_mesh_.fv_iter(f_it.handle());
                GL::glColor(simplified_mesh_.property(vp_color_fitting_error_sm_, fv_it));
                GL::glVertex(simplified_mesh_.point(fv_it));
                ++fv_it;
                GL::glColor(simplified_mesh_.property(vp_color_fitting_error_sm_, fv_it));
                GL::glVertex(simplified_mesh_.point(fv_it));
                ++fv_it;
                GL::glColor(simplified_mesh_.property(vp_color_fitting_error_sm_, fv_it));
                GL::glVertex(simplified_mesh_.point(fv_it));
            }
            glEnd();
        }
        MeshModel::draw();
    } else {
        std::cout << "Error: there isn't this render type.\n";
    }

    //draw_mesh2_ =  true;//false;
    if (draw_mesh2_ == true) { // 是否显示原始网格, 为了方便比较.
        DGP::hidderline_render(mesh2_, OpenMesh::Vec3f(1, 0, 0));
    }
}