示例#1
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 );
    }
}
示例#2
0
void OffsetWorker::offsetPolygon(Polygon_2 poly, double offset)  {
	typedef CGAL::Gps_circle_segment_traits_2<SFCGAL::Kernel>  Gps_traits_2;
	typedef Gps_traits_2::Polygon_2                            Offset_polygon_2;

	if(!poly.is_simple()) {
		DM::Logger(DM::Warning) << "Can't perform offset polygon is not simple";
	}
	CGAL::Orientation orient = poly.orientation();
	if (orient == CGAL::CLOCKWISE) {
		poly.reverse_orientation();
	}

	const double                           err_bound = 0.00001;
	std::list<Offset_polygon_2>            inset_polygons;

	CGAL::approximated_inset_2 (poly, offset, err_bound, std::back_inserter (inset_polygons));

	foreach (Offset_polygon_2 p, inset_polygons) {
		SFCGAL::Polygon po(this->approximate(p));
		QString wkt = QString(po.asText(9).c_str());
		module->addToSystem(wkt);
		//emit resultPolygon(wkt);
	}
示例#3
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;

};