当前位置: 首页>>代码示例>>C++>>正文


C++ Triangulation::cw方法代码示例

本文整理汇总了C++中Triangulation::cw方法的典型用法代码示例。如果您正苦于以下问题:C++ Triangulation::cw方法的具体用法?C++ Triangulation::cw怎么用?C++ Triangulation::cw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Triangulation的用法示例。


在下文中一共展示了Triangulation::cw方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: solve

void solve(Triangulation DT, Segment rect[],vector<Point> points)
{
	map<TP,double> vertex_dist;
	for (vertex_iterator vit = DT.finite_vertices_begin();vit!=DT.finite_vertices_end();vit++)
	{
		TP vertex_p = vit->point();
		double min_dist = min_segment(rect, vertex_p);
		vertex_dist[vertex_p] = min_dist;
	}	
	
	for(Edge_iterator eit=	DT.finite_edges_begin(); eit!=DT.finite_edges_end();eit++)
	{
		double min_dist = CGAL::to_double(DT.segment(eit).squared_length()/4);
		TP vertex_p1 = eit->first->vertex(DT.cw(eit->second))->point();
		TP vertex_p2 = eit->first->vertex(DT.ccw(eit->second))->point();

		vertex_dist[vertex_p1] = std::min(vertex_dist[vertex_p1], min_dist);
		vertex_dist[vertex_p2] = std::min(vertex_dist[vertex_p2], min_dist);
	}

	vector<double> dist;
	for (std::map<TP,double>::iterator it = vertex_dist.begin();it!= vertex_dist.end(); it++)
	{
		dist.push_back(it->second);
	}

	sort(dist.begin(),dist.end());

	int f,m,l;
	f = time(dist[0]);
	m = time(dist[points.size()/2]);
	l = time(dist[points.size() - 1]);

	cout<<f<<" "<<m<<" "<<l<<endl;	
}
开发者ID:MohitYnwa,项目名称:ETH-Algo-Lab,代码行数:35,代码来源:germs.cpp

示例2: main

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;
    }
}
开发者ID:evelinad,项目名称:eth-algolab,代码行数:76,代码来源:main.cpp


注:本文中的Triangulation::cw方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。