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();
    }


}
void MsInterpolation::build_hierarchy_on_face()
{
	if( face_root == NULL)
	{
		face_root = new FaceNode();
	}else
	{
		printf("face root已经被创建了!\n");
		return ;
	}

	MyMesh::FaceIter f_iter, f_end( m_mesh.faces_end() );
	MyFaceHandle fh;

	for(f_iter = m_mesh.faces_begin(); f_iter != f_end; ++f_iter)
	{
		fh = f_iter.handle();

		{
			face_root->idx.push_back( fh.idx() );
		}
	}

	build_hierarchy_based_on_face(face_root, 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();
    }



}
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();
//  }


}
void MeshPara::draw(const std::string& _draw_mode)
{
	MeshViewer::draw(_draw_mode);
	if (_draw_mode == "Texture")
	{
		if (indices_.empty())
		{
			//std::cout << "Need to load a TRIANGLE MESH!" << std::endl;
			return ;
		}

		if (!is_Parameterized)
		{
			std::cout << "Have No Texture Coordinates!" << std::endl;
			std::cout << "Need Parameterization." << std::endl;
			LSCM();
			std::cout << "Parameterization End." << std::endl;
		}	

		glEnable(GL_TEXTURE_2D);
		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
		glBindTexture(GL_TEXTURE_2D, tex_name);
		glEnable(GL_LIGHTING);
		//glShadeModel(GL_FLAT);

		Mesh::FaceIter f_it, f_end(mesh_.faces_end());
		glBegin(GL_TRIANGLES);
		for (f_it = mesh_.faces_begin(); f_it != f_end; ++f_it)
		{
			//GL::glNormal(mesh_.normal(f_it));
			auto fv_it = mesh_.fv_iter(*f_it);
			while (fv_it.is_valid())
			{
				Mesh::Point pt = mesh_.point(*fv_it);
				Mesh::TexCoord2D tx = mesh_.texcoord2D(*fv_it);
				GL::glTexCoord(tx);
				GL::glVertex(pt);
				++fv_it;
			}
		}
		glEnd();

		glDisable(GL_TEXTURE_2D);
	}
}
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());
	}
}
Example #7
0
void Data::read(string xmlFile)
{
  if(_xml.size() == 0)
  {
    _xml = xmlFile;
    if(xmlFile[0] != '/')
    {
      char buf[1024];
      getcwd(buf, 1024);
      stringstream sst;
      sst << buf << "/" << xmlFile;
      _xml = sst.str();
    }
  }
  cout << "reading xml file: " << _xml << endl;
  YarsXSDSaxParser *parser = new YarsXSDSaxParser();
  parser->read(xmlFile);
  if(parser->errors() > 0)
  {
    FORF(vector<string>, i, parser, w_begin(), w_end()) cout << "WARNING: " << *i << endl;
    FORF(vector<string>, i, parser, e_begin(), e_end()) cout << "ERROR:   " << *i << endl;
    FORF(vector<string>, i, parser, f_begin(), f_end()) cout << "FATAL:   " << *i << endl;
    delete parser;
    exit(-1);
  }
  delete parser;

  __writeCfg();

  if(_initialisationCompleted == false)
  {
    if(_root->population() == NULL)
    {
      _root->initialiseFirstPopulationFromConfiguration();
    }
    _root->population()->addObserver(this);
    _initialisationCompleted = true;
  }
}
Example #8
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));
    }
}
void DeformationGraph::GenerateDensePointSet(std::list<PointWithID>& pointcoll, double delta)
{
#ifdef DEBUGTRACE
	meshtalent::DebugTrace dt("./sample.log");
#endif
	assert(pointcoll.size() == 0);

	typedef DeformableMesh3d::InterMesh InterMesh;
	InterMesh* pMesh = dmesh.pMesh;
	int vertexnum = pMesh->n_vertices();
	//int edgenum = pMesh->n_edges();
	//int facetnum = pMesh->n_faces();
	// sample points on vertices.
	InterMesh::VertexIter v_it, v_end(pMesh->vertices_end());
	for (v_it = pMesh->vertices_begin(); v_it != v_end; ++v_it) {
		InterMesh::Point& p = pMesh->point(v_it);
		P3d p3d(p[0], p[1], p[2]);
		pointcoll.push_back(PointWithID(p3d, PointWithID::VERTEX, v_it.handle().idx()));
	}
#ifdef DEBUGTRACE
	dt.Trace("There %d vertex_points sampled.\n", vertexnum);
#endif
	// sample points on edges.
	int epcount = 0;
	InterMesh::EdgeIter e_it, e_end(pMesh->edges_end());
	for (e_it = pMesh->edges_begin(); e_it != e_end; ++e_it) {
		InterMesh::EdgeHandle eh = pMesh->handle(*e_it);
		InterMesh::HalfedgeHandle heh = pMesh->halfedge_handle(eh, 0); // always select the first edge, but if it's a boundary??
		InterMesh::VertexHandle phfrom = pMesh->from_vertex_handle(heh);
		InterMesh::VertexHandle phto = pMesh->to_vertex_handle(heh);
		InterMesh::Point pf = pMesh->point(phfrom);
		InterMesh::Point pt = pMesh->point(phto);
		P3d p3dfrom(pf[0], pf[1], pf[2]);
		P3d p3dto(pt[0], pt[1], pt[2]);
		double dist = (p3dto - p3dfrom).mag();
		//compute delta vector and sample on this edge.
		V3d deltaV = (p3dto - p3dfrom) * delta;
		int times = static_cast<int>(dist / delta) - 1;
		P3d p3dnow = p3dfrom;
		for (int j = 0; j < times; ++j) {
			p3dnow += deltaV;
			pointcoll.push_back(PointWithID(p3dnow, PointWithID::EDGE, e_it.handle().idx()));
		}
		epcount += (times < 0 ? 0 : times);
	}
#ifdef DEBUGTRACE
	dt.Trace("There are %d edge_points sampled.\n", epcount);
#endif
	// sample points on facet.
	int fpcount = 0;
	InterMesh::FaceIter f_it, f_end(pMesh->faces_end());
	for (f_it = pMesh->faces_begin(); f_it != f_end; ++f_it) {
		P3d trivertices[3];
		//assert((*f_it).is_triangle());
		InterMesh::FaceVertexIter fv_it(pMesh->fv_iter(f_it.handle()));
		int j = 0;
		for (; fv_it; ++fv_it, ++j) {
			InterMesh::Point& p = pMesh->point(fv_it);
			trivertices[j] = P3d(p[0], p[1], p[2]);
		}
		// compute num should be sampled.
		V3d v1 = trivertices[1] - trivertices[0];
		V3d v2 = trivertices[2] - trivertices[0];
		//double lenv1 = v1.mag();
		//double lenv2 = v2.mag();
		double area = (v1 % v2).mag() / 2;
		int samplenum = static_cast<int>(area / (delta * delta));
		fpcount += samplenum;
		RandDoubleGenerator drand;
		drand.srand(time(NULL));
		while (samplenum > 0) {
			double lamada1 = drand(0, 1);
			double lamada2 = drand(0, 1);
			if (lamada1 + lamada2 >= 1) { // judge if this point is not in triangle.
				continue;
			}
			P3d tp3d = trivertices[0] + (v1 * lamada1 + v2 * lamada2);
			pointcoll.push_back(PointWithID(tp3d, PointWithID::FACE, f_it.handle().idx()));
			--samplenum;
		} // end of while.
	} // end of for.
#ifdef DEBUGTRACE
	dt.Trace("There are %d facet_points sampled.\n", fpcount);
	dt.Trace("There are %d points sampled totally.\n", pointcoll.size());
#endif
}