Пример #1
0
int main()
{
	//cout<<fixed<<setprecision(0);
	int cnt=0;
	while(true)
	{
		int n;
		cin>>n;
		if (n==0) break;
		
		int l,b,r,t;
		cin>>l>>b>>r>>t;

		Segment rect[4];
		rect[0] = Segment(Point(l,b),Point(r,b));
		rect[1] = Segment(Point(l,b),Point(l,t));
		rect[2] = Segment(Point(l,t),Point(r,t));
		rect[3] = Segment(Point(r,t),Point(r,b));
		
		vector<Point> points;
		for (int i=0;i<n;i++)
		{
			int x,y;
			cin>>x>>y;
			points.push_back(Point(x,y));	
		}
		Triangulation DT;
		DT.insert(points.begin(),points.end());
		

		solve(DT,rect,points);

	}
	return 0;
}
Пример #2
0
void test_case(int n) {

	// cout << "---- " << n << " ----" << endl;

	// Read all infected people
	std::vector<K::Point_2> infected;
	infected.reserve(n);

	for(int i=0; i<n; i++) {
		// cin >> x[i] >> y[i];
		K::Point_2 p;
		cin >> p;
		infected.push_back(p);
		cout << "Read in point " << p << endl;
	}

	// Construct Delauney triangulation
	Triangulation t;
	t.insert(infected.begin(), infected.end());

	// Read all healthy people
	int m;
	cin >> m;

	for(int i=0; i<m; i++) {
		K::Point_2 escaper;
		long d;
		cin >> escaper >> d;

		// --- Find an escape path for this person ---
		// Find out at which face we are
		Face_handle current_face = t.locate(escaper);

		// Check if we are already outside
		if(t.is_infinite(current_face)) {
			cout << "y";
			continue;
		}
		// Check if we are already getting infected
		/*K::Point_2 nearest_infected = t.nearest_vertex(escaper, current_face)->point();
		cout << "Nearest infected person: " << nearest_infected << endl;
		int dx = nearest_infected.x() - escaper.x();
		int dy = nearest_infected.y() - escaper.y();
		long nearest_sqd = dx * dx + dy * dy;
		if(nearest_sqd < d) {
			cout << "n";
			continue;
		}*/

		// Recurse
		vector<Face_handle> visited;
		bool result = recurse(current_face, d, visited, t);

		if(result)
			cout << "POSSIBLE TO ESCAPE" << endl;
		else
			cout << "COULDN'T ESCAPE :(" << endl;
	}

}
Пример #3
0
int
main(int argc,char* argv[])
{
  const char* filename = (argc > 1) ? argv[1] : "data/points.xy";
  std::ifstream input(filename);
  Triangulation t;
  Filter is_finite(t);
  Finite_triangulation ft(t, is_finite, is_finite);

  Point p ;
  while(input >> p){
    t.insert(p);
  }

  vertex_iterator vit, ve;
  // Associate indices to the vertices
  int index = 0;
  // boost::tie assigns the first and second element of the std::pair
  // returned by boost::vertices to the variables vit and ve
  for(boost::tie(vit,ve)=boost::vertices(ft); vit!=ve; ++vit ){
    vertex_descriptor  vd = *vit;
    vertex_id_map[vd]= index++;
    }

  // Dijkstra's shortest path needs property maps for the predecessor and distance
  // We first declare a vector
  std::vector<vertex_descriptor> predecessor(boost::num_vertices(ft));
  // and then turn it into a property map
  boost::iterator_property_map<std::vector<vertex_descriptor>::iterator,
                               VertexIdPropertyMap>
    predecessor_pmap(predecessor.begin(), vertex_index_pmap);

  std::vector<double> distance(boost::num_vertices(ft));
  boost::iterator_property_map<std::vector<double>::iterator,
                               VertexIdPropertyMap>
    distance_pmap(distance.begin(), vertex_index_pmap);

  // start at an arbitrary vertex
  vertex_descriptor source = *boost::vertices(ft).first;
  std::cout << "\nStart dijkstra_shortest_paths at " << source->point() <<"\n";

  boost::dijkstra_shortest_paths(ft, source,
				 distance_map(distance_pmap)
				 .predecessor_map(predecessor_pmap)
				 .vertex_index_map(vertex_index_pmap));

  for(boost::tie(vit,ve)=boost::vertices(ft); vit!=ve; ++vit ){
    vertex_descriptor vd = *vit;
    std::cout << vd->point() << " [" <<  vertex_id_map[vd] << "] ";
    std::cout << " has distance = "  << boost::get(distance_pmap,vd)
	      << " and predecessor ";
    vd =  boost::get(predecessor_pmap,vd);
    std::cout << vd->point() << " [" <<  vertex_id_map[vd] << "]\n ";
  }

  return 0;
}
Пример #4
0
void create(Triangulation& Tp) {

  int N=simu.no_of_particles();
  std::vector<Point> points;
  //  points.reserve(N);

  if(simu.create_points()) {
    if(simu.at_random()) {
      points.reserve(N);

      CGAL::Random_points_in_square_2<Point,Creator> g(LL/2.0-0.0001);
      CGAL::cpp11::copy_n( g, N, std::back_inserter(points));


      cout << N << "  particles placed at random" << endl;
    } else {
      // if((plotting)&&(Nin%2==0)&&(spike)) {
      // 	cout << "Please enter an odd number of particles" << endl;
      // 	std::abort();
      // }

      int Nb=sqrt(N + 1e-12);

      N=Nb*Nb;

      simu.set_no_of_particles(N);

      points.reserve(N);
      cout << N << " particles placed on square lattice" << endl;

      FT spacing=LL/FT(Nb+0);
      FT side=LL-1*spacing;

      points_on_square_grid_2(side/2.0, N, std::back_inserter(points),Creator());;

      //      for(int i = 0 ; i < Nb ; ++i )
	
      
      if(simu.perturb()) {
	CGAL::perturb_points_2(
			       points.begin(), points.end(),
			       simu.pert_rel()* spacing );//,Creator());
	cout << "each particle perturbed about " << simu.pert_rel()* spacing  << endl;
      }

    }

   }

    cout << "Inserting" << endl;

    Tp.insert(points.begin(), points.end());

    return;

}
Пример #5
0
int main()
{
    cout<<fixed<<setprecision(0);
    while(true)
    {
        int n;
        cin>>n;
        if (n==0) break;

        vector<Point> points;
        for (int i=0; i<n; i++)
        {
            long x,y;
            cin>>x>>y;
            points.push_back(Point(x,y));
        }

        Triangulation DT;
        DT.insert(points.begin(),points.end());

        int m;
        cin>>m;
        vector<Point> newp;
        //double  min = -1;
        for (int i=0; i<m; i++)
        {
            long x,y;
            cin>>x>>y;
            Point np(x,y);
            newp.push_back(np);
        }

        vector<double> sol;
        for (int i=0; i<m; i++)
        {
            Point np = newp[i];
            Point p = DT.nearest_vertex(np)->point();

            double dist = CGAL::to_double(squared_distance(np,p));
            sol.push_back(dist);

        }

        for (int i=0; i<m; i++) cout<<sol[i]<<endl;



    }
    return 0;
}
Пример #6
0
void triangulate( Rand &prng, Graph &graph )
{
	typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
	typedef CGAL::Delaunay_triangulation_2<K>        Triangulation;
	typedef Triangulation::Edge_iterator             Edge_iterator;
	typedef Triangulation::Vertex_handle             Vertex_handle;
	typedef Triangulation::Point                     Point;
	typedef std::map<Vertex_handle, int>             VertexIndexMap;

	const static int minEdgeWeight = 1;
	const static int maxEdgeWeight = 20;

	// create the delaunay triangulation
	Triangulation triangulation;
	VertexIndexMap vertexIndexMap;

	// dump all of the BGL vertices into CGAL
	Graph::vertices_size_type numVertices = boost::num_vertices( graph );
	for ( int idx = 0; idx < numVertices; ++idx ) 
	{
		const VertexInfo &vertexInfo = boost::get( VertexInfoTag(), graph, idx );
		Point position( vertexInfo.position.x, vertexInfo.position.y );
		Vertex_handle handle = triangulation.insert( position );
		vertexIndexMap[ handle ] = idx;
	}

	// edge weight property map
	auto edgeWeightMap = boost::get( boost::edge_capacity, graph );

	// read out the edges and add them to BGL
	EdgeReverseMap edgeReverseMap = boost::get( boost::edge_reverse, graph );
	Edge_iterator ei_end = triangulation.edges_end();
	for (Edge_iterator ei = triangulation.edges_begin(); 
		ei != ei_end; ++ei)
	{
		int idxSourceInFace = ( ei->second + 2 ) % 3;
		int idxTargetInFace = ( ei->second + 1 ) % 3;
		Vertex_handle sourceVertex = ei->first->vertex( idxSourceInFace );
		Vertex_handle targetVertex = ei->first->vertex( idxTargetInFace );
		int idxSource = vertexIndexMap[ sourceVertex ];
		int idxTarget = vertexIndexMap[ targetVertex ];
		EdgeHandle forwardEdge = boost::add_edge( idxSource, idxTarget, graph );
		EdgeHandle backwardEdge = boost::add_edge( idxTarget, idxSource, graph );
		edgeReverseMap[ forwardEdge.first ] = backwardEdge.first;
		edgeReverseMap[ backwardEdge.first ] = forwardEdge.first;
		int edgeWeight = prng.nextInt( 1, 20 );
		edgeWeightMap[ forwardEdge.first ] = edgeWeight;
		edgeWeightMap[ backwardEdge.first ] = edgeWeight;
	}
}
Пример #7
0
int main()
{
  Triangulation tr;
  int a, b, d;
  for (a=0;a!=4;a++)
    for (b=0;b!=4;b++)
      for (d=0;d!=4;d++)
	tr.insert(Point((a*b-d*a)*10 +a ,(a-b+d +5*b)*100,
			    a*a-d*d-b));
  Triangulation::Finite_cells_iterator cit=tr.finite_cells_begin();
  for(; cit != tr.finite_cells_end(); ++cit) {
    Point circum = tr.dual(cit);
    CGAL_USE(circum);
  }
  return 0;
}
Пример #8
0
Файл: emst.cpp Проект: FMX/CGAL
int
main(int,char*[])
{
    Triangulation t;
    Filter is_finite(t);
    Finite_triangulation ft(t, is_finite, is_finite);

    Point p ;
    while(std::cin >> p) {
        t.insert(p);
    }

    vertex_iterator vit, ve;
    // Associate indices to the vertices
    int index = 0;
    // boost::tie assigns the first and second element of the std::pair
    // returned by boost::vertices to the variables vit and ve
    for(boost::tie(vit,ve)=boost::vertices(ft); vit!=ve; ++vit ) {
        vertex_descriptor  vd = *vit;
        vertex_id_map[vd]= index++;
    }


    // We use the default edge weight which is the squared length of the edge
    // This property map is defined in graph_traits_Triangulation_2.h

    // In the function call you can see a named parameter: vertex_index_map
    std::list<edge_descriptor> mst;
    boost::kruskal_minimum_spanning_tree(t,
                                         std::back_inserter(mst),
                                         vertex_index_map(vertex_index_pmap));


    std::cout << "The edges of the Euclidean mimimum spanning tree:" << std::endl;

    for(std::list<edge_descriptor>::iterator it = mst.begin(); it != mst.end(); ++it) {
        edge_descriptor ed = *it;
        vertex_descriptor svd = boost::source(ed,t);
        vertex_descriptor tvd = boost::target(ed,t);
        Triangulation::Vertex_handle sv = svd;
        Triangulation::Vertex_handle tv = tvd;
        std::cout << "[ " << sv->point() << "  |  " << tv->point() << " ] " << std::endl;
    }

    return 0;
}
Пример #9
0
int main() {
    std::ifstream in("data/triangulation_prog1.cin");
    std::istream_iterator<Point> begin(in);
    std::istream_iterator<Point> end;

    Triangulation t;
    t.insert(begin, end);

    Vertex_circulator vc = t.incident_vertices(t.infinite_vertex()),
                      done(vc);
    if (vc != 0) {
        do {
            std::cout << vc->point() << std::endl;
        } while(++vc != done);
    }
    return 0;
}
Пример #10
0
int main() {
  // some basic setup stuff
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  cout << fixed << setprecision(0);

  while(true) {
      int existing_count;
      cin >> existing_count;

      // kill switch for application
      if(existing_count == 0) {
        break;
      }

      // collect existing restaurants
      vector<K::Point_2> existing_locs;
      existing_locs.reserve(existing_count);

      for(int i=0; i < existing_count; i++) {
        double loc_x, loc_y;
        cin >> loc_x >> loc_y;

        existing_locs.push_back(K::Point_2(loc_x, loc_y));
      }

      // cosntruct triangulation
      Triangulation triang;
      triang.insert(existing_locs.begin(), existing_locs.end());

      // go through possible location
      int possible_count;
      cin >> possible_count;

      for(int i = 0; i < possible_count; i++) {
        int possible_x, possible_y;
        cin >> possible_x >> possible_y;
        
        K::Point_2 possible_point = K::Point_2(possible_x, possible_y);

        // find nearest vertex and by that the nearest point
        K::Point_2 nearest = triang.nearest_vertex(possible_point)->point();
        cout << CGAL::to_double(CGAL::squared_distance(nearest, possible_point)) << endl;
      }
    }
}
Пример #11
0
void testcase(int n) {
	vector<K::Point_2> delaunay_vertices;
	for(int i = 0; i < n; ++i) {
		K::Point_2 p; cin >> p;
		delaunay_vertices.push_back(p);
	}

	Triangulation t;
	t.insert(delaunay_vertices.begin(), delaunay_vertices.end());

	int points; cin >> points;
	for(int i = 0; i < points; ++i) {
		K::Point_2 p; cin >> p;
		Triangulation::Vertex_handle v = t.nearest_vertex(p);
		K::Point_2 vp = v->point();
		K::FT distance = CGAL::squared_distance(p, vp);
		cout << floor_to_double(distance) << "\n";
	}
}
Пример #12
0
int main( )
{
  std::ifstream in("data/voronoi.cin");
  std::istream_iterator<Point> begin(in);
  std::istream_iterator<Point> end;
  Triangulation T;
  T.insert(begin, end);

  int ns = 0;
  int nr = 0;
  Edge_iterator eit =T.edges_begin();
  for ( ; eit !=T.edges_end(); ++eit) {
    CGAL::Object o = T.dual(eit);
    if (CGAL::object_cast<K::Segment_2>(&o)) {++ns;}
    else if (CGAL::object_cast<K::Ray_2>(&o)) {++nr;}
  }
  std::cout << "The Voronoi diagram has " << ns << " finite edges "
	    << " and " << nr << " rays" << std::endl;
  return 0;
}
Пример #13
0
void test_case(int n) {

	// cout << "---- " << n << " ----" << endl;

	Triangulation t;

	std::vector<K::Point_2> pts;
	pts.reserve(n);

	// vector<int> x = vector<int>(n, 0);
	// vector<int> y = vector<int>(n, 0);

	for(int i=0; i<n; i++) {
		// cin >> x[i] >> y[i];
		K::Point_2 p;
		cin >> p;
		pts.push_back(p);
	}

	// Construct Delauney triangulation
	t.insert(pts.begin(), pts.end());

	long long min_sqd = -1;

	// Find shortest edge in triangulation
	for (Edge_iterator ei = t.finite_edges_begin(); ei != t.finite_edges_end(); ++ei) {
		Edge e = *ei;
		Triangulation::Vertex_handle v1 = e.first->vertex((e.second + 1) % 3);
		Triangulation::Vertex_handle v2 = e.first->vertex((e.second + 2) % 3);
		long dx = v1->point().x() - v2->point().x();
		long dy = v1->point().y() - v2->point().y();
		long long sqd = dx * dx + dy * dy;
		if(min_sqd == -1 || sqd < min_sqd)
			min_sqd = sqd;
 		//std::cout << "e = " << v1->point() << " <-> " << v2->point() << std::endl;
 		//std::cout << t.segment(e) << endl;
	}

	std::cout << ceil(sqrt(min_sqd) * 50) << endl;
}
Пример #14
0
void clone(const Triangulation& Tfrom,Triangulation& Tto) {

  for(F_v_it vit=Tfrom.vertices_begin();
      vit != Tfrom.vertices_end();
      vit++) {

    Periodic_point pp=Tfrom.periodic_point(vit);
    Point p=Tfrom.point(pp);

    Vertex_handle fv=Tto.insert( p );

    fv->rold.set( p );

    fv->U.set( vit->U.val() );
    fv->Uold.set( vit->U.val() );

    fv->idx.set( vit->idx.val() );

  }      

  return;
  
}
int main()
{
  Triangulation t;

  Random random(1284141159);
  std::cout << "Seed: " << random.get_seed () << std::endl;

  // Random_points_in_square g(0.495, random);
  Random_points_on_circle g(0.495, random);
  Vector midpoint(0.5, 0.5);

  for (int i = 0; i < N_PTS; ++i)
    {
      t.insert(*(++g) + midpoint);
    }

  if (!t.is_valid(true))
    {
      std::cout << "l:" << __LINE__ << std::endl;
      std::exit(1);
    }

  return 0;
}
Пример #16
0
int main()
{
  Random random(1284141159);
  Random_points_in_square g(0.495, random);
  Vector midpoint(0.5, 0.5);

#if 0
  // Should take 5 seconds on the iMac
  std::vector<Point> pts;
  pts.resize(500000);
  for (size_t i = 0; i < pts.size(); ++i) pts[i] = *(++g) + midpoint;

  Gt gt;
  for (size_t i = 0; i < pts.size() - 2; ++i) gt.orientation_2_object()(pts[i], pts[i + 1], pts[i + 2]);

  return 0;
#endif

  std::cout << "i" << ", \t"
            << "total time"  << ", \t"
            << "total_time cumm" << ", \t"
            << "locate_time" << ", \t" << "insert_time" << ", \t"
            << "periodic_insert_time" <<  ", \t" << "periodic_insert_time" << std::endl;


  // First run is for heating up the CPU, don't output the stats
  for (int run = 0; run < N_RUNS; ++run)
    {
      // Reset timings
      total_time = 0.0;
      locate_time = 0.0;
      insert_time = 0.0;
      periodic_locate_time = 0.0;
      periodic_insert_time = 0.0;

#ifdef PERIODIC
      Triangulation t;
      const bool insert_periodic_copies = false;
#else
      EuclideanTriangulation t;
      const bool insert_periodic_copies = false;
#endif

      std::clock_t start_time = std::clock();
      // Do one additional point to get the statistics right
      for (int i = 0; i <= N_PTS; ++i)
        {
          Point p = *(++g) + midpoint;
          t.insert(p);

          if (insert_periodic_copies)
            {
              for (int x = 0; x < 3; ++x)
                {
                  for (int y = 0; y < 3; ++y)
                    {
                      if (x + y > 0)
                        {
                          t.insert(p + Vector(x, y));
                        }
                    }
                }
            }

          if (i % 500 == 0)
            {
              std::cout << i << ", \t"
                        << (std::clock() - start_time) / (double)CLOCKS_PER_SEC << ", \t"
                        << total_time << ", \t"
                        << locate_time << ", \t" << insert_time << ", \t"
                        << periodic_insert_time <<  ", \t" << periodic_insert_time << std::endl;
            }
        }
      CGAL_assertion(t.is_valid());

      std::cout << std::endl;
    }

  return 0;
}
int main()
{
  Triangulation t;
  Face_handle fh;

  // Check the empty triangulation
  fh = test_point_location(t, Point(0.5, 0.5), Triangulation::EMPTY);
  CGAL_assertion(fh == Face_handle());

  // Insert the first point
  Point p0(0.5, 0.5);
  Vertex_handle vh0 = t.insert(p0);
  CGAL_assertion(t.is_valid(true));
  CGAL_USE(vh0);

  fh = test_point_location(t, p0, Triangulation::VERTEX);
  CGAL_assertion(fh->has_vertex(vh0));

  fh = test_point_location(t, p0 + Vector(0.1, 0.1), Triangulation::EDGE);
  CGAL_assertion(fh->has_vertex(vh0));

  fh = test_point_location(t, p0 + Vector(-0.1, -0.1), Triangulation::EDGE);
  CGAL_assertion(fh->has_vertex(vh0));

  fh = test_point_location(t, p0 + Vector(-0.2, -0.3), Triangulation::FACE);
  CGAL_assertion(fh->has_vertex(vh0));

  CGAL_assertion(t.is_valid(true));

  // Insert the second point on an edge
  Point p1(0.7, 0.7);
  Vertex_handle vh1 = t.insert(p1);
  CGAL_USE(vh1);
  CGAL_assertion(t.is_valid(true));

  fh = test_point_location(t, p0, Triangulation::VERTEX);
  CGAL_assertion(fh->has_vertex(vh0));

  fh = test_point_location(t, p1, Triangulation::VERTEX);
  CGAL_assertion(fh->has_vertex(vh1));

  fh = test_point_location(t, p0 + Vector(0.1, 0.1), Triangulation::EDGE);
  CGAL_assertion(fh->has_vertex(vh0));
  CGAL_assertion(fh->has_vertex(vh1));

  fh = test_point_location(t, p0 + Vector(-0.1, -0.1), Triangulation::EDGE);
  CGAL_assertion(fh->has_vertex(vh0));
  CGAL_assertion(!fh->has_vertex(vh1));

  fh = test_point_location(t, p1 + Vector(0.1, 0.1), Triangulation::EDGE);
  CGAL_assertion(!fh->has_vertex(vh0));
  CGAL_assertion(fh->has_vertex(vh1));

  fh = test_point_location(t, p0 + Vector(-0.02, -0.03), Triangulation::FACE);
  CGAL_assertion(fh->has_vertex(vh0));

  fh = test_point_location(t, p1 + Vector(-0.02, -0.03), Triangulation::FACE);
  CGAL_assertion(fh->has_vertex(vh1));

  CGAL_assertion(t.is_valid(true));

  // Insert the third point in a face
  Point p2(0.8, 0.6);
  Vertex_handle vh2 = t.insert(p2);
  CGAL_USE(vh2);
  CGAL_assertion(t.is_valid(true));

  fh = test_point_location(t, p0, Triangulation::VERTEX);
  CGAL_assertion(fh->has_vertex(vh0));
  fh = test_point_location(t, p1, Triangulation::VERTEX);
  CGAL_assertion(fh->has_vertex(vh1));
  fh = test_point_location(t, p2, Triangulation::VERTEX);
  CGAL_assertion(fh->has_vertex(vh2));

  fh = test_point_location(t, Point(0.6, 0.6), Triangulation::EDGE);
  CGAL_assertion(fh->has_vertex(vh0));
  CGAL_assertion(fh->has_vertex(vh1));

  test_point_location(t, Point(0.7, 0.6), Triangulation::FACE);
  test_point_location(t, p0 + Vector(-0.02, -0.03), Triangulation::FACE);
  test_point_location(t, p0 + Vector(0.02, -0.03), Triangulation::FACE);
  test_point_location(t, p0 + Vector(-0.02, 0.03), Triangulation::FACE);
  test_point_location(t, p0 + Vector(0.02, 0.03), Triangulation::FACE);

  return 0;
}
Пример #18
0
 CVCGEOM_NAMESPACE::cvcgeom_t* 
pocket_tunnel_fromsurf(const  CVCGEOM_NAMESPACE::cvcgeom_t*  molsurf, int num_pockets, int num_tunnels ) // input surface data.
{


  map<int, cell_cluster> cluster_set;
//  int output_seg_count = DEFAULT_OUTPUT_SEG_COUNT;
 
  // robust cocone parameters.
  double bb_ratio = DEFAULT_BIGBALL_RATIO;
  double theta_ff = M_PI/180.0*DEFAULT_THETA_FF_d;
  double theta_if = M_PI/180.0*DEFAULT_THETA_IF_d;

  vector<Point> pts_list;
  for(int i = 0; i < molsurf->points().size(); i++)
  {
     float x = molsurf->points()[i][0],
           y = molsurf->points()[i][1],
           z = molsurf->points()[i][2];
     pts_list.push_back(Point(x,y,z));
  }

  //CGAL::Timer timer;
  //timer.start();

 // cout <<"list size:" <<  pts_list.size() << endl;
  cerr << "Delaunay ";
  Triangulation triang;
  triang.insert(pts_list.begin(), pts_list.end());
  assert(triang.is_valid());
  cerr << "done." << endl;
  //cerr << "Time: " << timer.time() << endl; timer.reset();

  // ------------------------------------------
  // Initialization of all the required fields
  // needed for Tight Cocone and Segmentation
  // ------------------------------------------
  cerr << "Initialization ";
  initialize(triang);
  cerr << ".";
  // compute voronoi vertex
  compute_voronoi_vertex_and_cell_radius(triang);
  cerr << ". done." << endl;
  //cerr << "Time: " << timer.time() << endl; timer.reset();

  // ------------------------------------------
  // Surface Reconstruction using Tight Cocone
  // ------------------------------------------
  cerr << "Surface Reconstruction ";
  tcocone(DEFAULT_ANGLE, DEFAULT_SHARP, DEFAULT_FLAT, DEFAULT_RATIO, triang);
  cerr << " done." << endl;
  //cerr << "Time: " << timer.time() << endl; timer.reset();

#ifdef _DEBUG_OUTPUT_
  write_wt(triang, "debug_output/temp_recon");
#endif

  cerr << "Computing S_MAX ";
  double mr = 1.3; // not used in this routine.
  vector<int> sorted_smax_index_vector = compute_smax(triang, cluster_set, mr);
  cerr << " done." << endl;

  // detect pocket, tunnel, void.
  cerr << "Computing Pocket-Tunnels ";
  detect_handle(triang, cluster_set);
  cerr << " done." << endl;
  //cerr << "Time: " << timer.time() << endl; timer.reset();

#ifdef _DEBUG_OUTPUT_
  // write_handle(triang, cluster_set, sorted_smax_index_vector, output_seg_count, "debug_output/temp_PTV");
#endif

  // convert the handles into rawc geometries to be viewed by TexMol.
  CVCGEOM_NAMESPACE::cvcgeom_t* PTV;
  convert_pocket_tunnel_to_rawc_geometry(&PTV, triang, cluster_set, 
                                         sorted_smax_index_vector, num_pockets, num_tunnels);

  return PTV;
}
Пример #19
0
int
main(int,char*[])
{
  Triangulation t;

  t.insert(Point(0.1,0,1));
  t.insert(Point(1,0,1));
  t.insert(Point(0.2,0.2, 2));
  t.insert(Point(0,1,2));
  t.insert(Point(0,2,3));

  vertex_iterator vit, ve;
  // Associate indices to the vertices
  int index = 0;
  // boost::tie assigns the first and second element of the std::pair
  // returned by boost::vertices to the variables vit and ve
  for(boost::tie(vit,ve) = vertices(t); vit!=ve; ++vit ){
    vertex_descriptor  vd = *vit;
    if(! t.is_infinite(vd)){
      vertex_id_map[vd]= index++;
    }
  }

  std::cerr << index << " vertices" << std::endl;
  index = 0;
  face_iterator fit,fe;
  for(boost::tie(fit,fe) = faces(t); fit!= fe; ++fit){
    face_descriptor fd = *fit;
    halfedge_descriptor hd = halfedge(fd,t);
    halfedge_descriptor n = next(hd,t);
    
    halfedge_descriptor nn = next(n,t);
    if(next(nn,t) != hd){
      std::cerr << "the face is not a triangle" << std::endl;
    }
    
    ++index;
  }
  
  std::cerr << index << " faces" << std::endl;
  index = 0;

  edge_iterator eit,ee;
  for(boost::tie(eit,ee) = edges(t); eit!= ee; ++eit){
    edge_descriptor ed = *eit;
    vertex_descriptor vd = source(ed,t);
    CGAL_USE(vd);
    ++index;
  }

  std::cerr << index << " edges" << std::endl;
  index = 0;

  halfedge_iterator hit,he;
  for(boost::tie(hit,he) = halfedges(t); hit!= he; ++hit){
    halfedge_descriptor hd = *hit;
    vertex_descriptor vd = source(hd,t);
    CGAL_USE(vd);
    ++index;
  }
  std::cerr << index << " halfedges" << std::endl;

  std::cerr << num_vertices(t) << " " << num_edges(t) << " " << num_halfedges(t) << " " << num_faces(t) << std::endl;

  typedef boost::property_map<Triangulation, boost::vertex_point_t>::type Ppmap;
  Ppmap ppmap = get(boost::vertex_point, t);
 

  for(vertex_descriptor vd : vertices_around_target(*vertices(t).first, t)){
    std::cout <<  ppmap[vd] << std::endl;
  }


  ppmap[*(++vertices(t).first)] = Point(78,1,2);
  std::cout << " changed point of vertex " << ppmap[*(++vertices(t).first)] << std::endl;

  return 0;
}
Пример #20
0
int main()
{
  Triangulation t;

  Vector midpoint(0.5, 0.5);

  Face_handle fh;
  Triangulation::Locate_type lt;
  int i;
  fh = t.locate(Point(0, 0) + midpoint, lt, i);
  CGAL_assertion(lt == Triangulation::EMPTY);

  Vertex_handle vh_midpoint = t.insert(Point(0, 0) + midpoint);
  fh = t.locate(Point(0, 0) + midpoint, lt, i);
  CGAL_assertion(lt == Triangulation::VERTEX && fh->vertex(i) == vh_midpoint);
  t.remove(vh_midpoint);
  CGAL_assertion(t.empty());

  // High degree vertex
  for (int n = 3; n < 8; ++n)
    {
      vh_midpoint = t.insert(Point(0, 0) + midpoint);
      for (int i = 0; i < n; ++i)
        {
          t.insert(Point(0.3 * sin(i * 1.0 / n * 2 * M_PI), 0.3 * cos(i * 1.0 / n * 2 * M_PI)) + midpoint);
        }
      t.remove(vh_midpoint);
      CGAL_assertion(t.is_valid(true));
      while (!t.empty())
        {
          t.remove(t.vertices_begin());
          CGAL_assertion(t.is_valid(true));
        }
    }

  Random random(1284141159);
  std::cout << "Seed: " << random.get_seed () << std::endl;
  Random_points_in_square g(0.495, random);

  CGAL_assertion(t.is_valid());

  std::cout << "Removing first point" << std::endl;
  Vertex_handle vh0 = t.insert(Point(0.5, 0.5));
  CGAL_assertion(t.is_valid());
  t.remove(vh0);
  CGAL_assertion(t.is_valid());
  CGAL_assertion(t.empty());

  {
    Random random(1284141159);
    std::cout << "Seed: " << random.get_seed () << std::endl;

    Random_points_in_square g(0.495, random);
    Vector midpoint(0.5, 0.5);

    Triangulation t;
    CGAL_assertion(t.is_valid());

    std::cout << "Removing first point" << std::endl;
    Vertex_handle vh0 = t.insert(Point(0.5, 0.5));
    CGAL_assertion(t.is_valid());
    t.remove(vh0);
    CGAL_assertion(t.is_valid());
    CGAL_assertion(t.empty());

    std::cout << "Inserting random points and removing them." << std::endl;

    for (int i = 0; i < N_PTS; ++i)
      {
        t.insert(*(++g) + midpoint);
      }
    CGAL_assertion(t.is_valid());

    for (int i = 0; i < N_PTS; ++i)
      {
        // Find a random vertex
        Vertex_handle vh = t.locate(*(++g) + midpoint)->vertex(0);
        vh = t.get_original_vertex(vh);
        t.remove(vh);
        CGAL_assertion(t.is_valid());
      }
  }
  return 0;
}
Пример #21
0
	void create_triangulations(){
		red_t.insert(red_points.begin(), red_points.end());
		blue_red_t.insert(red_points.begin(), red_points.end());
		blue_red_t.insert(blue_points.begin(), blue_points.end());
	}
Пример #22
0
int main(int narg, char** argv)
{
  if (narg>1 && (!strcmp(argv[1],"-h") || !strcmp(argv[1],"-?")) )
  {
    std::cout<<"Usage : voronoi_3 filename"<<std::endl   
             <<"   filename being a fine containing 3D points used to "
             <<" compute the Delaunay_triangulation_3."<<std::endl;
    return EXIT_FAILURE;
  }

  std::string filename;
  if ( narg==1 )
  {
    filename=std::string("data/points_3");
    std::cout<<"No filename given: use data/points_3 by default."<<std::endl;
  }
  else
    filename=std::string(argv[1]);
  
  // 1) Compute the Delaunay_triangulation_3.
  Triangulation T;

  std::ifstream iFile(filename.c_str());
  if (!iFile)
  {
    std::cout << "Problem reading file " << filename << std::endl;
    return EXIT_FAILURE;
  }
  
  std::istream_iterator<Point> begin(iFile), end;
  T.insert(begin, end);
  CGAL_assertion(T.is_valid(false));
 
  // 2) Convert the triangulation into a 3D lcc.
  LCC_3 lcc;
  std::map<Triangulation::Cell_handle,
           LCC_3::Dart_handle > vol_to_dart;

  Dart_handle dh=CGAL::import_from_triangulation_3<LCC_3, Triangulation>
    (lcc, T, &vol_to_dart);

  std::cout<<"Delaunay triangulation :"<<std::endl<<"  ";
  lcc.display_characteristics(std::cout) << ", valid=" 
                                         << lcc.is_valid() << std::endl;

  // 3) Compute the dual lcc.
  LCC_3 dual_lcc;
  Dart_handle ddh=lcc.dual(dual_lcc, dh);
  // Here, dual_lcc is the 3D Voronoi diagram.
  CGAL_assertion(dual_lcc.is_without_boundary());

  // 4) We update the geometry of dual_lcc by using the std::map
  //    face_to_dart.
  transform_dart_to_their_dual<LCC_3,Triangulation>
    (lcc, dual_lcc, vol_to_dart);
  set_geometry_of_dual<LCC_3,Triangulation>(dual_lcc, T, vol_to_dart);
  
  // 5) Display the dual_lcc characteristics.
  std::cout<<"Voronoi subdvision :"<<std::endl<<"  ";
  dual_lcc.display_characteristics(std::cout) << ", valid=" 
                                              << dual_lcc.is_valid()
                                              << std::endl;
  display_voronoi(dual_lcc, ddh);

  return EXIT_SUCCESS;
}
Пример #23
0
int main() {

    while(true) {
        int bacteria_count;
        cin >> bacteria_count;

        // kill switch for application
        if(bacteria_count == 0) {
            break;
        }

        // read in boundaries of the dish
        double left_border, right_border, bottom_border, top_border;
        cin >> left_border >> bottom_border >> right_border >> top_border;

        // collect bacteria's center information
        vector<K::Point_2> bacteria_centers;
        bacteria_centers.reserve(bacteria_count);
        for(int i = 0; i < bacteria_count; i++) {
            double bacteria_x, bacteria_y;
            cin >> bacteria_x >> bacteria_y;

            bacteria_centers.push_back(K::Point_2(bacteria_x, bacteria_y));
        }

        // create triangulation
        Triangulation triang;
        triang.insert(bacteria_centers.begin(), bacteria_centers.end());

        // keep track of the distances for each bacteria
        map<Triangulation::Point, double> distances;
        //distances.reserve(bacteria_count);

        // calculate initial distance: distance between the bacteria and the nearest dish boundary
        for(Triangulation::Finite_vertices_iterator vertex_iter = triang.finite_vertices_begin(); vertex_iter != triang.finite_vertices_end(); ++vertex_iter) {
            Triangulation::Point vertex = vertex_iter->point();
            distances[vertex] = min(
                min(vertex.x() - left_border, right_border - vertex.x()), // left/right minimum
                min(vertex.y() - bottom_border, top_border - vertex.y()) // top/bottom minimum
            );

            distances[vertex] *= distances[vertex]; // square distance as we work with squared ones
        }

        // compute distance to other two neighbours and update distance if it is smaller
        for(Triangulation::Finite_edges_iterator edge_iter = triang.finite_edges_begin(); edge_iter != triang.finite_edges_end(); ++edge_iter) {
            Triangulation::Vertex_handle vertex1 = edge_iter->first->vertex(triang.cw(edge_iter->second));
            Triangulation::Vertex_handle vertex2 = edge_iter->first->vertex(triang.ccw(edge_iter->second));

            Triangulation::Point vertex1_point = vertex1->point();
            Triangulation::Point vertex2_point = vertex2->point();

            // calculate distance of the points of both vertex and half them (divide by 4 as distance is squared and 4 = 2^2)
            double vertex_distance = CGAL::to_double(CGAL::squared_distance(vertex1_point, vertex2_point)) / 4;

            // update distances to minimum
            distances[vertex1_point] = min(distances[vertex1_point], vertex_distance);
            distances[vertex2_point] = min(distances[vertex2_point], vertex_distance);
        }

        // now we know the minimum distance for each bacteria to another one or the borders of the dish

        // extract distances into a vector and sort it
        vector<double> only_distances;
        only_distances.reserve(bacteria_count);
        for(map<Triangulation::Point, double>::iterator iter = distances.begin(); iter != distances.end(); ++iter) {
            only_distances.push_back(iter->second);
        }

        // sort distances
        sort(only_distances.begin(), only_distances.end());

        // print out information
        cout << hours(only_distances[0]) << " " << hours(only_distances[bacteria_count/2]) << " " << hours(only_distances[bacteria_count - 1]) << endl;
    }
}
Пример #24
0
//
// Retriangulates a hole within the mesh. The hole is specified through an edgeloop(closed sequence of edges).
// In addition an optional number of points can be specified which will be included in the triangulation.
//
void MeshEx::retriangulateHole( std::vector<MeshEx::Edge *> &boundaryEdges, std::map<MeshEx::Vertex *, math::Vec2f> &boundaryVertexProjections, std::vector<std::pair<math::Vec3f, math::Vec2f> > &interiorPoints )
{
	std::map<Vertex_handle, MeshEx::Vertex*>                                 vertexMap; // used to map cgal vertex_handles to vertices
	std::vector<MeshEx::Edge *>                                                  edges; // this vector will hold all edges which were involved (for faster edge search)


	// algorithm:
	// - prepare data
	//		- find all boundary vertices
	// - prepare CGAL constrained triangulation
	//		- insert boundary vertices into triangulation and build mapping from Triangulation vertices to MeshEx::Vertices
	//		- use the boundary edges as constrained edges
	//		- insert points into triangulation from interiorPoints and build mapping from Triangulation vertices to MeshEx::Vertices
	// - extract triangulation results
	//		- ?


	// prepare algorithm ----------------------------------------------------------

	/*
	// obsolete since we get the boundary vertices with the boundaryVertexProjections
	// find boundary vertices
	for( std::vector<MeshEx::Edge *>::iterator it = boundaryEdges.begin(); it != boundaryEdges.end(); ++it )
	{
		MeshEx::Edge *e = *it;
		boundaryVertices.push_back( e->v1 );
		boundaryVertices.push_back( e->v2 );
	}
	// remove duplicate entries
	std::sort( boundaryVertices.begin(), boundaryVertices.end() );
	boundaryVertices.erase( std::unique( boundaryVertices.begin(), boundaryVertices.end() ), boundaryVertices.end() );
	*/
	
	// algorithm ------------------------------------------------------------------
	Triangulation t;

	// constrain triangulation with the boundary edges

	// iterate over all boundary vertices
	for( std::map<MeshEx::Vertex *, math::Vec2f>::iterator it = boundaryVertexProjections.begin(); it != boundaryVertexProjections.end(); ++it )
	{
		MeshEx::Vertex *v = it->first;

		// add boundary vertex to triangulation
		Vertex_handle vh = t.insert( Point( it->second.x, it->second.y ) );

		// we dont need to create the vertex
		vertexMap[vh] = v;
	}


	// iterate over all boundary edges
	for( std::vector<MeshEx::Edge *>::iterator it = boundaryEdges.begin(); it != boundaryEdges.end(); ++it )
	{
		MeshEx::Edge *e = *it;

		Vertex_handle v1, v2;


		bool v1_found  = false;
		bool v2_found  = false;
		// find vertex_handles for the given edge vertices
		for( std::map<Vertex_handle, MeshEx::Vertex*>::iterator vmit = vertexMap.begin(); vmit != vertexMap.end(); ++vmit )
		{
			if( e->v1 == vmit->second )
			{
				v1 = vmit->first;
				v1_found = true;
			}
			if( e->v2 == vmit->second )
			{
				v2 = vmit->first;
				v2_found = true;
			}
		}

		// add constrainedge to the triangulation
		t.insert_constraint( v1, v2 );

		// add edge to the list of created/existing edges
		edges.push_back( e );
	}

	// add additional and optional interior points
	for( std::vector<std::pair<math::Vec3f, math::Vec2f> >::iterator it = interiorPoints.begin(); it != interiorPoints.end(); ++it )
	{
		// update triangulation
		Vertex_handle v = t.insert( Point( it->second.x, it->second.y ) );

		// insertion may return a vertex which already exists (when the position is the same)
		if( vertexMap.find( v ) == vertexMap.end() )
			// create according MeshEx::Vertex and keep mapping to the CGAL vertices
			vertexMap[v] = createVertex( it->first );
	}


	// extract results and create triangles ----------------------------------------

	// now we have the triangulation of the convex hull of the whole problem, now we
	// have to find the faces which are inside the polygon - we mark each face with a
	// segment(inside or outside) property and by finding a face which is adjacent to
	// a infinite face, we find the segment which is outside


	// we employ some floodfilling scheme
	for( Triangulation::Finite_faces_iterator it = t.finite_faces_begin(); it != t.finite_faces_end(); ++it )
		// reset info to -1
		it->info() = -1;

	int outsideSegment = -1;
	findOutsideSegment( t, t.finite_faces_begin(), 0, -1, outsideSegment );

	if( outsideSegment == -1 )
		printf( "error : outsideSegment not found during triangulation\n" );

	for( Triangulation::Finite_faces_iterator it = t.finite_faces_begin(); it != t.finite_faces_end(); ++it )
		if( (it->info() == -1) && (!t.is_infinite(it)) )
			printf( "triangle not touched!\n" );

	// iterate over all faces of the triangulation and create edges/triangles
	for( Triangulation::Finite_faces_iterator it = t.finite_faces_begin(); it != t.finite_faces_end(); ++it )
	{
		Face_handle fh = it;

		// we are only interested in interior triangles
		if( fh->info() == outsideSegment )
			continue;

		MeshEx::Vertex *v0, *v1, *v2;

		v0 = vertexMap[ fh->vertex(0) ];
		v1 = vertexMap[ fh->vertex(1) ];
		v2 = vertexMap[ fh->vertex(2) ];

		MeshEx::Edge *e0, *e1, *e2;

		e0 = e1 = e2 = 0;

		// look for the edges in the edge vector
		for( std::vector<MeshEx::Edge*>::iterator eit = edges.begin(); eit != edges.end(); ++eit )
		{
			MeshEx::Edge *e = *eit;

			if( e->contains(v0) && e->contains(v1) )
				e0 = e;
			else
			if( e->contains(v1) && e->contains(v2) )
				e1 = e;
			else
			if( e->contains(v2) && e->contains(v0) )
				e2 = e;
		}

		// create the edges which could not be found
		if( !e0 )
		{
			e0 = createEdge( v0, v1 );
			edges.push_back(e0);
		}
		if( !e1 )
		{
			e1 = createEdge( v1, v2 );
			edges.push_back(e1);
		}
		if( !e2 )
		{
			e2 = createEdge( v2, v0 );
			edges.push_back(e2);
		}

		// create triangle
		MeshEx::Triangle *tri = createTriangle( v0, v1, v2, e0, e1, e2 );
	}
}
Пример #25
0
FT move(Triangulation& Tp, const FT dt , FT& dd0 ) {

  vector<data_kept> prev;

  FT dd2=0;

  bool first=false;  // debug

  for(F_v_it fv=Tp.finite_vertices_begin();
      fv!=Tp.finite_vertices_end();
      fv++) {
    data_kept data(fv);

    Vector_2  vel = fv->U();

    Vector_2 disp = dt * vel;

    Periodic_point rr=Tp.periodic_point(fv);

    Point rnow=Tp.point(rr); // current point

    Point r0=fv->rold(); // starting point

    Point rnew= r0 + disp;

    Vector_2 disp2 = per_vect(rnew,rnow);

    FT rel_disp = sqrt(disp2.squared_length() ) / simu.h();

    FT rel_disp0= sqrt( disp.squared_length() ) / simu.h();

    if(first) {
     cout
       << "r0 " << r0 << "  "
       << "rnow " << rnow << "  "
       << "rnew " << rnew << "  "
       << "disp2 " << disp2 << "  "
       << " idx " << fv->idx() << " "
       << "rel_disp " << rel_disp
       << endl ;
     first=false;
    }

    dd2 += rel_disp;

    dd0 += rel_disp0;

    //    cout << "New position: " << r0 ;

    data.pos = per_point( rnew );

    //    cout << " ---> " << data.pos  << endl ;

    prev.push_back (data);

  }

//  cout << "relative displacement " << sqrt(dd2)/simu.no_of_points()/simu.h()  << endl ;
  dd2 /= simu.no_of_particles();
  dd0 /= simu.no_of_particles();

  //  cout << "relative displacement " << dd2 << endl ;

  Tp.clear(); // clears the triangulation !!

  for(vector<data_kept>::iterator data=prev.begin();
      data!=prev.end();
      data++) {

    //    cout << "Inserting back at " << data->pos << endl ;

    Vertex_handle fv=Tp.insert(data->pos);

    data->restore(fv);

    // return info to vertices


  }

//  cout << "Insertion done" << endl ;
  Tp.convert_to_1_sheeted_covering();

  return dd2;
}