Пример #1
0
void
VoronoiSlabGenerator::Slab::SlabData::generatePeriodicImages()
{
  K::Vector_2 a, dr;
  for(Delaunay::Vertex_iterator it = dg.vertices_begin(), end =
      dg.vertices_end(); it != end; ++it)
    vertices.push_back(it);
  if(unitCell)
  {
    BOOST_FOREACH(const Delaunay::Vertex_handle vtx, vertices)
    {
      for(int i = -1; i <= 1; ++i)
      {
        a = toCgalVec2< K>(static_cast< double>(i) * unitCell->getAVec());
        for(int j = -1; j <= 1; ++j)
        {
          if(!(i == 0 && j == 0))
          {
            dr = a
                + toCgalVec2< K>(static_cast< double>(j) * unitCell->getBVec());
            const Delaunay::Vertex_handle image = dg.insert(vtx->point() + dr);
            image->info() = vtx->info();
            image->info().isImage = true;
            periodicImages.insert(
                PeriodicImages::value_type(vtx, std::make_pair(dr, image)));
          }
        }
      }
    }
  }
}
Пример #2
0
int main()
{
  Delaunay dt;
  Delaunay::Vertex_handle vh;

  vh  = dt.insert(Point(0,0,0));
  vh->info() = "Paris";
  vh = dt.insert(Point(1,0,0.1));
  vh->info() = "London";
  vh = dt.insert(Point(0,1,0.2));
  vh->info() = "New York";
  
  return 0;
}
void VoronoiCgal_Patch::insert_polygonInter2(Delaunay& cdt, ImageSpline& is,
		PatchSpline& ps)
{
	const int NESTING_LEVEL = TRIANGLE_TRANSPARENT;

	if (ps.m_LineIndexs.empty())
	{
		return;
	}

	LineIndex start_idx = ps.m_LineIndexs.front();
	CgalPoint last;

	if (start_idx.m_Forward)
	{
		Vector2 v = is.m_LineFragments[start_idx.m_id].m_Points.front();
		last = CgalPoint(v.x, v.y);
	}
	else
	{
		Vector2 v = is.m_LineFragments[start_idx.m_id].m_Points.back();
		last = CgalPoint(v.x, v.y);
	}

	CgalPoint start = last;
	Delaunay::Vertex_handle v_prev  = cdt.insert(last);
	v_prev->info().nesting_level = NESTING_LEVEL;

	for (auto it = ps.m_LineIndexs.begin(); it != ps.m_LineIndexs.end(); ++it)
	{
		Line pts = is.m_LineFragments[it->m_id].m_Points;

		if (it->m_Forward)
		{
			for (auto it2 = pts.begin(); it2 != pts.end(); ++it2)
			{
				CgalPoint now(it2->x, it2->y);

				if (now != last)
				{
					Delaunay::Vertex_handle vh = m_Delaunay.insert(now);

					if (vh->info().nesting_level == -1 || vh->info().nesting_level == NESTING_LEVEL)
					{
						vh->info().nesting_level = NESTING_LEVEL;
						cdt.insert_constraint(v_prev, vh);
						v_prev = vh;
						last = now;
					}
				}
			}
		}
		else
		{
			for (auto it2 = pts.rbegin(); it2 != pts.rend(); ++it2)
			{
				CgalPoint now(it2->x, it2->y);

				if (now != last)
				{
					Delaunay::Vertex_handle vh = m_Delaunay.insert(now);

					if (vh->info().nesting_level == -1 || vh->info().nesting_level == NESTING_LEVEL)
					{
						vh->info().nesting_level = NESTING_LEVEL;
						cdt.insert_constraint(v_prev, vh);
						v_prev = vh;
						last = now;
					}
				}
			}
		}
	}
}
void VoronoiCgal_Patch::insert_polygon(Delaunay& cdt,
									   ImageSpline& m_ImageSpline, int idx)
{
	PatchSpline& ps = m_ImageSpline.m_PatchSplines[idx];
	LineIndex start_idx = ps.m_LineIndexs.front();
	CgalPoint last;

	if (start_idx.m_Forward)
	{
		Vector2 v = m_ImageSpline.m_LineFragments[start_idx.m_id].m_Points.front();
		last = CgalPoint(v.x, v.y);
	}
	else
	{
		Vector2 v = m_ImageSpline.m_LineFragments[start_idx.m_id].m_Points.back();
		last = CgalPoint(v.x, v.y);
	}

	CgalPoint start = last;
	Delaunay::Vertex_handle v_prev  = cdt.insert(last);
	v_prev->info().nesting_level = idx;

	for (auto it = ps.m_LineIndexs.begin(); it != ps.m_LineIndexs.end(); ++it)
	{
		Line pts = m_ImageSpline.m_LineFragments[it->m_id].m_Points;

		if (it->m_Forward)
		{
			for (auto it2 = pts.begin(); it2 != pts.end(); ++it2)
			{
				CgalPoint now(it2->x, it2->y);

				if (now != last)
				{
					Delaunay::Vertex_handle vh = cdt.insert(now);

					if (vh->info().nesting_level == -1 || vh->info().nesting_level == idx)
					{
						vh->info().nesting_level = idx;
						cdt.insert_constraint(v_prev, vh);
						v_prev = vh;
						last = now;
					}
				}
			}
		}
		else
		{
			for (auto it2 = pts.rbegin(); it2 != pts.rend(); ++it2)
			{
				CgalPoint now(it2->x, it2->y);

				if (now != last)
				{
					Delaunay::Vertex_handle vh = cdt.insert(now);

					if (vh->info().nesting_level == -1 || vh->info().nesting_level == idx)
					{
						vh->info().nesting_level = idx;
						cdt.insert_constraint(v_prev, vh);
						v_prev = vh;
						last = now;
					}
				}
			}
		}
	}
}
Пример #5
0
void testcase(int N) {
    double left, bottom, right, top; cin >> left >> bottom >> right >> top;
    vector<K::Segment_2> rectangle;
    rectangle.push_back(K::Segment_2(K::Point_2(left, bottom), K::Point_2(left, top)));
    rectangle.push_back(K::Segment_2(K::Point_2(left, top), K::Point_2(right, top)));
    rectangle.push_back(K::Segment_2(K::Point_2(right, top), K::Point_2(right, bottom)));
    rectangle.push_back(K::Segment_2(K::Point_2(right, bottom), K::Point_2(left, bottom)));
    
    vector<pair<K::Point_2, int> > points;
    for(int b = 0; b < N; ++b) {
        double x, y; cin >> x >> y;
        points.push_back(make_pair(K::Point_2(x, y), b));
    }

    Delaunay t;
	t.insert(points.begin(), points.end());
    
    vector<pair<double, pair<int, int> > > edges;
    for(FEI e = t.finite_edges_begin(); e != t.finite_edges_end(); ++e) {
        Delaunay::Vertex_handle v1 = e->first->vertex((e->second + 1) % 3);
        Delaunay::Vertex_handle v2 = e->first->vertex((e->second + 2) % 3);
        K::FT edge_length = CGAL::sqrt(CGAL::squared_distance(v1->point(), v2->point()));
        edges.push_back(make_pair(edge_length, make_pair(v1->info(), v2->info())));
    }
    
    for(FVI p = t.finite_vertices_begin(); p != t.finite_vertices_end(); ++p) {
        Delaunay::Vertex_handle vertex = p;
        K::FT min; bool min_set = false;
        for(int seg = 0; seg < 4; ++seg) {
            K::FT seg_min = CGAL::squared_distance(rectangle[seg], vertex->point());
            if(min_set == false || min > seg_min) { min_set = true; min = seg_min; }    
        }
        edges.push_back(make_pair(2*CGAL::sqrt(min), make_pair(p->info(), p->info())));
    }
    
    sort(edges.begin(), edges.end());

    int dead = 0;
    int pointer = 0;
    int h = 0;
    bool first_time = true;
    vector<int> deadlist(N, 0);
   
    while(dead != N) {
        double min_length = 2 * (pow(h, 2.0) + 0.5);
        int temp_dead = 0;
        while(edges[pointer].first <= min_length && pointer < edges.size()) {
            int v1 = edges[pointer].second.first;
            int v2 = edges[pointer].second.second;
            if(deadlist[v1] == 0) { ++temp_dead; deadlist[v1] = 1; }
            if(deadlist[v2] == 0) { ++temp_dead; deadlist[v2] = 1; }
            ++pointer;
        }
        if(dead == 0 && temp_dead > 0) cout << h << " ";
        dead += temp_dead;
        if((N-dead)/(double)N < 0.5 && first_time) {
            cout << h << " ";
            first_time = false;
        }
        if(N == dead) cout << h << "\n";
        ++h;
    }
}