Пример #1
0
void minkowskiSum( const LineString& gA, const Polygon_2& gB, Polygon_set_2& polygonSet )
{
    if ( gA.isEmpty() ) {
        return ;
    }

    int npt = gA.numPoints() ;

    for ( int i = 0; i < npt - 1 ; i++ ) {
        Polygon_2 P;
        P.push_back( gA.pointN( i ).toPoint_2() );
        P.push_back( gA.pointN( i+1 ).toPoint_2() );

        //
        // We want to compute the "minkowski sum" on each segment of the line string
        // This is not very well defined. But it appears CGAL supports it.
        // However we must use the explicit "full convolution" method for that particular case in CGAL >= 4.7
#if CGAL_VERSION_NR < 1040701000 // version 4.7
        Polygon_with_holes_2 part = minkowski_sum_2( P, gB );
#else
        Polygon_with_holes_2 part = minkowski_sum_by_full_convolution_2( P, gB );
#endif

        // merge into a polygon set
        if ( polygonSet.is_empty() ) {
            polygonSet.insert( part );
        }
        else {
            polygonSet.join( part );
        }
    }
}
Пример #2
0
/*
 * append gA+gB into the polygonSet
 */
void minkowskiSum( const Point& gA, const Polygon_2& gB, Polygon_set_2& polygonSet )
{
    BOOST_ASSERT( gB.size() );

    CGAL::Aff_transformation_2< Kernel > translate(
        CGAL::TRANSLATION,
        gA.toVector_2()
    );

    Polygon_2 sum ;

    for ( Polygon_2::Vertex_const_iterator it = gB.vertices_begin();
            it != gB.vertices_end(); ++it ) {
        sum.push_back( translate.transform( *it ) );
    }

    if ( sum.is_clockwise_oriented() ) {
        sum.reverse_orientation() ;
    }

    if ( polygonSet.is_empty() ) {
        polygonSet.insert( sum );
    }
    else {
        polygonSet.join( sum );
    }
}
Пример #3
0
Polygon_set_2 join_polygons_with_holes(Array pwhs){
	vector<Polygon_with_holes_2> polygon_vector;
	for (unsigned int i = 0; i < pwhs.size(); i++) {
		Polygon_with_holes_2 pwh = from_ruby<Polygon_with_holes_2>(pwhs[i]);
		polygon_vector.push_back(pwh);
	}
	Polygon_set_2 S;
	S.join(polygon_vector.begin(), polygon_vector.end());
	return S;
}
Пример #4
0
Polygon_set_2 join(Array polygons){
	vector<Polygon_2> polygon_vector;
	for (unsigned int i = 0; i < polygons.size(); i++) {
		Polygon_2 polygon = from_ruby<Polygon_2>(polygons[i]);
		if (polygon.is_simple()) {
			polygon_vector.push_back(polygon);
		}
	}
	Polygon_set_2 S;
	S.join(polygon_vector.begin(), polygon_vector.end());
	return S;
}
Пример #5
0
Array to_a(Polygon_set_2 S){
	Array ps;	
	list<Polygon_with_holes_2> res;
  list<Polygon_with_holes_2>::const_iterator it;
	S.polygons_with_holes (back_inserter (res));
  for (it = res.begin(); it != res.end(); ++it){
		Polygon_with_holes_2 pwh = *it;
		ps.push(pwh);
  }
	return ps;
}
Пример #6
0
void minkowskiSum( const LineString& gA, const Polygon_2 & gB, Polygon_set_2 & polygonSet ){
	if ( gA.isEmpty() ){
		return ;
	}

	int npt = gA.numPoints() ;
	for ( int i = 0; i < npt - 1 ; i++ ){
		Polygon_2 P;
		P.push_back( gA.pointN(i).toPoint_2() );
		P.push_back( gA.pointN(i+1).toPoint_2() );

		Polygon_with_holes_2 part = minkowski_sum_2( P, gB );

		// merge into a polygon set
		if ( polygonSet.is_empty() ){
			polygonSet.insert( part );
		}else{
			polygonSet.join( part );
		}
	}
}
Пример #7
0
void minkowskiSum( const Polygon& gA, const Polygon_2& gB, Polygon_set_2& polygonSet )
{
    if ( gA.isEmpty() ) {
        return ;
    }

    /*
     * Invoke minkowski_sum_2 for exterior ring
     */
    {
        Polygon_with_holes_2 sum = minkowski_sum_2( gA.exteriorRing().toPolygon_2(), gB ) ;

        if ( polygonSet.is_empty() ) {
            polygonSet.insert( sum );
        }
        else {
            polygonSet.join( sum );
        }
    }

    /*
     * Compute the Minkowski sum for each segment of the interior rings
     * and perform the union of the result. The result is a polygon, and its holes
     * correspond to the inset.
     *
     */
    if ( gA.hasInteriorRings() ) {
        Polygon_set_2 sumInteriorRings ;

        for ( size_t i = 0; i < gA.numInteriorRings(); i++ ) {
            minkowskiSum( gA.interiorRingN( i ), gB, sumInteriorRings ) ;
        }

        /*
         * compute the difference for each hole of the resulting polygons
         */
        std::list<Polygon_with_holes_2> interiorPolygons ;
        sumInteriorRings.polygons_with_holes( std::back_inserter( interiorPolygons ) ) ;

        for ( std::list<Polygon_with_holes_2>::iterator it_p = interiorPolygons.begin();
                it_p != interiorPolygons.end(); ++it_p ) {

            for ( Polygon_with_holes_2::Hole_iterator it_hole = it_p->holes_begin();
                    it_hole != it_p->holes_end(); ++it_hole ) {

                it_hole->reverse_orientation() ;
                polygonSet.difference( *it_hole ) ;
            } // foreach hole
        }// foreach polygon
    }
}
Пример #8
0
geoData mapload(char* path,VisiLibity::Environment & mapEnv,VisiLibity::Visibility_Graph & visGraph,float clearDist )
{


    std::ifstream in(path);
    std::string s;
    std::string s1="";

    while(getline(in, s)) { // Discards newline char
    s1=s1+s+"\n";
    }

    std::vector<char> xml_copy(s1.begin(), s1.end());
    xml_copy.push_back('\0');

    rapidxml::xml_document<> doc;    // character type defaults to char
    doc.parse<0>(&xml_copy[0]);    // 0 means default parse flags

    //std::cout << "Name of my first node is: " << doc.first_node()->name() << "\n";

    rapidxml::xml_node<char> *n1;

    n1=doc.first_node("svg");
    n1=n1->first_node("g")->first_node("path");

    //std::vector < VisiLibity::Point > poly_temp;

    //geoData vertices_temp(10,poly_temp);
    geoData vertices_temp;

    int i=0;

    while (n1)
    {
        vertices_temp.push_back(loadPath(n1->first_attribute("d")->value()));
        n1=n1->next_sibling("path");
        i++;
    }


   Polygon_2 mapEnvOB;

    for (int j=0;j<vertices_temp[0].size();j++)
        {
            Point_2 nextVert= Point_2(vertices_temp[0][j][0],vertices_temp[0][j][1]);
            mapEnvOB.push_back(nextVert);
        };


        Polygon_set_2 S;
    mapEnvOB.reverse_orientation();

        S.insert(mapEnvOB);



    for (int k=1;k<vertices_temp.size();k++)
    {
        Polygon_2 holeCGAL;
        for (int j=0;j<vertices_temp[k].size();j++)
        {
            holeCGAL.push_back(Point_2(vertices_temp[k][j][0],vertices_temp[k][j][1]));
        };

        //holeCGAL.reverse_orientation();

        S.difference(holeCGAL);

        holeCGAL.clear();
    };

  std::list<Polygon_with_holes_2> res;
  std::list<Polygon_with_holes_2>::const_iterator it;


   S.polygons_with_holes (std::back_inserter (res));

    std::vector<VisiLibity::Polygon> envPolys;

   for (it = res.begin(); it != res.end(); ++it)
   {
      if(CGAL::ON_BOUNDED_SIDE==CGAL::bounded_side_2(it->outer_boundary().vertices_begin(),it->outer_boundary().vertices_end(),Point_2(guest1.pos.x(),guest1.pos.y()),Kernel()))
      {
        envPolys.push_back(ConvertPolygonCGAL2Vis(it->outer_boundary()));

        Polygon_with_holes_2::Hole_const_iterator hi;
        for (hi=it->holes_begin();hi!=it->holes_end();++hi)
        {
            envPolys.push_back(ConvertPolygonCGAL2Vis(*hi));
        };

        break;
      };

  }


    for (int i=0;i<envPolys.size();i++){
        //envPolys.push_back(VisiLibity::Polygon(vertices_temp[i]));
        //i=0;
        envPolys[i].eliminate_redundant_vertices(0.0001);
        VisiLibity::Point cm=envPolys[i].centroid();
            for (int j=0;j<envPolys[i].n();j++)
            {
                    if (j<envPolys[i].n()-1){
                        VisiLibity::Point n1=clearDist*normal(envPolys[i][j+1]-envPolys[i][j]);
                        envPolys[i][j]=envPolys[i][j]+n1;
                        envPolys[i][j+1]=envPolys[i][j+1]+n1;
                    }
            }
            VisiLibity::Point norm1=clearDist*normal(envPolys[i][0]-envPolys[i][envPolys[i].n()-1]);
            envPolys[i][0]=envPolys[i][0]+norm1;
            envPolys[i][envPolys[i].n()-1]=envPolys[i][envPolys[i].n()-1]+norm1;
    };

    mapEnv = *(new VisiLibity::Environment(envPolys));
    mapEnv.enforce_standard_form();

    visGraph = *(new VisiLibity::Visibility_Graph(mapEnv,0.00000001));
    return vertices_temp;

};
Пример #9
0
bool is_empty(Polygon_set_2 S) {
    return S.is_empty();
}