示例#1
0
int main( )
{
  //construct two non-intersecting nested polygons  
  Polygon_2 polygon1;
  polygon1.push_back(Point(0,0));
  polygon1.push_back(Point(2,0));
  polygon1.push_back(Point(2,2));
  polygon1.push_back(Point(0,2));
  Polygon_2 polygon2;
  polygon2.push_back(Point(0.5,0.5));
  polygon2.push_back(Point(1.5,0.5));
  polygon2.push_back(Point(1.5,1.5));
  polygon2.push_back(Point(0.5,1.5));
  
  //Insert the polygons into a constrained triangulation
  CDT cdt;
  cdt.insert_constraint(polygon1.vertices_begin(), polygon1.vertices_end(), true);
  cdt.insert_constraint(polygon2.vertices_begin(), polygon2.vertices_end(), true);
  
  //Mark facets that are inside the domain bounded by the polygon
  mark_domains(cdt);
  
  int count=0;
  for (CDT::Finite_faces_iterator fit=cdt.finite_faces_begin();
                                  fit!=cdt.finite_faces_end();++fit)
  {
    if ( fit->info().in_domain() ) ++count;
  }
  
  std::cout << "There are " << count << " facets in the domain." << std::endl;

  return 0;
}
void VoronoiCgal_Patch::Compute()
{
	m_CgalPatchs = MakePatchs(m_ImageSpline);

	for (int i = 0; i < m_CgalPatchs.size(); ++i)
	{
		m_Delaunay = Delaunay();
		insert_polygon(m_Delaunay, m_ImageSpline, i);
		insert_polygonInter(m_Delaunay, m_ImageSpline, i);
		Mesher mesher(m_Delaunay);
		Criteria    criteria(0, 100);
		mesher.set_criteria(criteria);
		mesher.refine_mesh();
		mark_domains(m_Delaunay);
		LineSegs lineSegs;

		for (auto e = m_Delaunay.finite_edges_begin();
				e != m_Delaunay.finite_edges_end(); ++e)
		{
			Delaunay::Face_handle fn = e->first->neighbor(e->second);

			//CGAL::Object o = m_Delaunay.dual(e);
			if (!fn->is_in_domain() || !fn->info().in_domain())
			{
				continue;
			}

			if (!m_Delaunay.is_constrained(*e) && (!m_Delaunay.is_infinite(e->first))
					&& (!m_Delaunay.is_infinite(e->first->neighbor(e->second))))
			{
				Delaunay::Segment s = m_Delaunay.geom_traits().construct_segment_2_object()
									  (m_Delaunay.circumcenter(e->first),
									   m_Delaunay.circumcenter(e->first->neighbor(e->second)));
				const CgalInexactKernel::Segment_2* seg = &s;
				CgalPoint p1(seg->source().hx(), seg->source().hy());
				CgalPoint p2(seg->target().hx(), seg->target().hy());
				Vector2 pp1(p1.hx(), p1.hy());
				Vector2 pp2(p2.hx(), p2.hy());

				if (pp1 == pp2)
				{
					continue;
				}

				lineSegs.push_back(LineSeg(pp1, pp2));
			}
		}

		for (auto it = lineSegs.begin(); it != lineSegs.end(); ++it)
		{
			//m_PositionGraph.AddNewLine(it->beg, it->end, );
		}
	}

	m_PositionGraph.ComputeJoints();
	//printf("joints: %d\n", m_PositionGraph.m_Joints.size());
	//MakeLines();
	MakeGraphLines();
}
示例#3
0
void
mark_nested_domains(CDT& cdt)
{
  for(typename CDT::All_faces_iterator it = cdt.all_faces_begin(); it != cdt.all_faces_end(); ++it){
    it->info().nesting_level = -1;
  }
  std::list<typename CDT::Edge> border;
  mark_domains(cdt, cdt.infinite_face(), 0, border);
  while(! border.empty()){
    typename CDT::Edge e = border.front();
    border.pop_front();
    typename CDT::Face_handle n = e.first->neighbor(e.second);
    if(n->info().nesting_level == -1){
      mark_domains(cdt, n, e.first->info().nesting_level+1, border);
    }
  }
}
示例#4
0
文件: main.cpp 项目: Ezio47/SFCGAL
int main() {
	//construct two non-intersecting nested polygons
	Polygon_2 polygon1;
	polygon1.push_back(Point_2(0.0, 0.0));
	polygon1.push_back(Point_2(2.0, 0.0));
	polygon1.push_back(Point_2(1.7, 1.0));
	polygon1.push_back(Point_2(2.0, 2.0));
	polygon1.push_back(Point_2(0.0, 2.0));
	Polygon_2 polygon2;
	polygon2.push_back(Point_2(0.5, 0.5));
	polygon2.push_back(Point_2(1.5, 0.5));
	polygon2.push_back(Point_2(1.5, 1.5));
	polygon2.push_back(Point_2(0.5, 1.5));

	//Insert the polyons into a constrained triangulation
	CDT cdt;
	insert_polygon(cdt, polygon1);
	insert_polygon(cdt, polygon2);

	//Extract point and provide the an index
	std::vector< triangulation_point > points ;
	for ( CDT::Vertex_iterator it = cdt.vertices_begin(); it != cdt.vertices_end(); ++it ){
		it->info() = points.size() ;
		points.push_back( it->point() );
	}


	//Mark facets that are inside the domain bounded by the polygon
	mark_domains(cdt);

	//
	int count = 0;
	for (CDT::Finite_faces_iterator fit = cdt.finite_faces_begin(); fit != cdt.finite_faces_end(); ++fit) {
		if (fit->info().in_domain()){
			++count;
		}
	}


	/*
	 * export
	 */

	std::ofstream ofs("polygon_triangulation2.obj");
	if ( ! ofs.good() ){
		std::cout << "can't open file" << std::endl;
		return 1 ;
	}

	//-- print vertices
	ofs << "# " << points.size() << " vertices"<< std::endl ;
	for ( size_t i = 0; i < points.size(); i++ ){
		ofs << "v " << points[i] << " 0.0" << std::endl;
	}

	//-- print faces
	ofs << "# " << cdt.number_of_faces() << " faces"<< std::endl ;
	// warning : Delaunay_triangulation_2::All_faces_iterator iterator over infinite faces
	for ( CDT::Finite_faces_iterator it = cdt.finite_faces_begin(); it != cdt.finite_faces_end(); ++it )
	{
		//ignore holes
		if ( ! it->info().in_domain() ){
			continue ;
		}
		size_t ia = it->vertex(0)->info();
		size_t ib = it->vertex(1)->info();
		size_t ic = it->vertex(2)->info();

		assert( it->is_valid() );
		//assert ( ia < cdt.number_of_vertices() || ib < tri.number_of_vertices() || ic < tri.number_of_vertices() ) ;

		ofs << "f " << ( ia + 1 ) << " " << ( ib + 1 ) << " " << ( ic + 1 ) << std::endl;
	}

	return 0;
}
void VoronoiCgal_Patch::mark_domains(Delaunay& cdt)
{
	for (Delaunay::All_faces_iterator it = cdt.all_faces_begin();
			it != cdt.all_faces_end(); ++it)
	{
		it->info().nesting_level = TRIANGLE_NOT_INIT;
	}

	int index = 0;
	std::list<Delaunay::Edge> border;
	Delaunay::Finite_faces_iterator fc = cdt.finite_faces_begin();

	for (; fc != cdt.finite_faces_end(); ++fc)
	{
		int domain = fc->vertex(0)->info().nesting_level;
		domain = fc->vertex(1)->info().nesting_level == 0 ? fc->vertex(
					 1)->info().nesting_level : domain;
		domain = fc->vertex(2)->info().nesting_level == 0 ? fc->vertex(
					 2)->info().nesting_level : domain;

		if (TRIANGLE_NOT_INIT == fc->info().nesting_level && domain == 0)
		{
			mark_domains(cdt, fc, domain, border);
			break;
		}

//      fc->info().nesting_level = TRIANGLE_TRANSPARENT;
//      int constrained = 0;
//
//      for (int i = 0; i < 3; ++i)
//      {
//          Delaunay::Edge e(fc, i);
//
//          if (cdt.is_constrained(e))
//          {
//              constrained++;
//          }
//      }
//
//      if (constrained == 1)
//      {
//          fc->info().nesting_level = 10;
//      }

		if (TRIANGLE_NOT_INIT == fc->info().nesting_level && domain == 0)
		{
			mark_domains(cdt, fc, domain, border);
			break;
		}
	}

	while (! border.empty())
	{
		Delaunay::Edge e = border.front();
		border.pop_front();
		Delaunay::Face_handle n = e.first->neighbor(e.second);
		int domain = e.first->vertex(0)->info().nesting_level >= 0;
		domain += e.first->vertex(1)->info().nesting_level >= 0;
		domain += e.first->vertex(2)->info().nesting_level >= 0;
		int transparent = e.first->vertex(0)->info().nesting_level ==
						  TRIANGLE_TRANSPARENT;
		transparent += e.first->vertex(1)->info().nesting_level == TRIANGLE_TRANSPARENT;
		transparent += e.first->vertex(2)->info().nesting_level == TRIANGLE_TRANSPARENT;

		if (transparent >= 2 || domain < 2)
		{
			mark_domains(cdt, n, TRIANGLE_TRANSPARENT, border);
		}
		else if (n->info().nesting_level == TRIANGLE_NOT_INIT)
		{
			//mark_domains(cdt, n, e.first->info().nesting_level + 1, border);
			printf("domain: %d\n", domain);
			mark_domains(cdt, n, domain, border);
		}
	}
}