Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] How to improve the speed of polygons offsettingin CGAL?

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] How to improve the speed of polygons offsettingin CGAL?


Chronological Thread 
  • From: "罗恒" <>
  • To:
  • Subject: Re: [cgal-discuss] How to improve the speed of polygons offsettingin CGAL?
  • Date: Tue, 31 Aug 2010 09:20:01 +0800

Dear Fernando Cacciola,
Thank you for your reply.I have defined _SECURE_SCL=0 NDEBUG as
#define _SECURE_SCL 0 #define NDEBUG in the main.cpp attached in the
email,but the speed doesnot change at all.What is the reason? Could you give
me some detail instruction.
Best regards!



------------------ 原始邮件 ------------------
>From: Fernando Cacciola
><>
>Reply-To:
>
>To:
>
>Subject: Re: [cgal-discuss] How to improve the speed of polygons
>offsettingin CGAL?
>Date: Mon, 30 Aug 2010 12:28:42 -0300
>
>Hi,
>
>Can you try building CGAL and your code with the following macros defined:
>
>_SECURE_SCL=0
>NDEBUG
>
>That running time you are reporting looks 10 times slower than it should.
>
>Best
>
>--
>Fernando Cacciola
>SciSoft Consulting, Founder
>http://www.scisoft-consulting.com
>
>--
>You are currently subscribed to cgal-discuss.
>To unsubscribe or access the archives, go to
>https://lists-sop.inria.fr/wws/info/cgal-discuss
>
>
> #include <iostream>
#include <fstream>
#include <boost/shared_ptr.hpp>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Polygon_with_holes_2.h>
#include <CGAL/create_offset_polygons_from_polygon_with_holes_2.h>

#define _SECURE_SCL 0
#define NDEBUG

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_2 Point_2;
typedef CGAL::Straight_skeleton_2<K> Ss ;
typedef CGAL::Polygon_2<K> Contour;
typedef boost::shared_ptr<Ss> SsPtr ;
typedef boost::shared_ptr<Contour> PolygonPtr ;
typedef std::vector<PolygonPtr> PolygonPtr_vector ;
typedef CGAL::Polygon_with_holes_2<K> PolygonWithHoles ;
typedef boost::shared_ptr<PolygonWithHoles> PolygonWithHolesPtr ;
typedef std::vector<PolygonWithHolesPtr> PolygonWithHolesPtrVector;

int main(int argc, char **argv)
{
const char *filename = "F:\\input.txt";
std::ifstream ifile(filename, std::ios::in);
if (!ifile)
{
std::cout<<"failed to read data from file";
return 1;
}

int iContour,iNode;
double x,y;

PolygonWithHoles temp_pwhs;

ifile>>iContour;
std::cout<<"contours:"<<iContour<<"\n";

std::vector<Contour> temp_poly_list;

for (int contour=0;contour<iContour;++contour)
{
Contour temp_contour;
temp_contour.clear();

ifile >> iNode;
std::cout<<"nodes:"<<iNode<<"\n";

for(int i=0;i<iNode;++i)
{
ifile>>x>>y;
temp_contour.push_back(Point_2(x,y));
std::cout<<"read a point from file:
"<<x<<","<<y<<"\n";
}

if ((temp_contour[0])==(temp_contour[temp_contour.size()-1]))
{

temp_contour.erase(temp_contour.vertices_begin());
std::cout<<" there are same points in the polygon. \n
after delete the last the size is"<<temp_contour.size()<<"\n";
}
temp_poly_list.push_back(temp_contour);
}

std::vector<Contour>::iterator the_max_area;
double max_area=0;
double area_value;
for (std::vector<Contour>::iterator
ic=temp_poly_list.begin();ic!=temp_poly_list.end();ic++)
{
area_value=(*ic).area();
std::cout<<"the area:"<<area_value<<"\n";
if (area_value>max_area)
{
max_area=area_value;
the_max_area=ic;
}
}
std::cout<<"the max area:"<<max_area<<"\n";

for (std::vector<Contour>::iterator
ic=temp_poly_list.begin();ic!=temp_poly_list.end();ic++)
{
if (ic==the_max_area)
{
std::cout<<"found the outer boundary"<<"\n";
if(!(*ic) .is_counterclockwise_oriented())
(*ic).reverse_orientation();
temp_pwhs.outer_boundary().clear();
temp_pwhs.outer_boundary()=(*ic);
break;
}
}


for (std::vector<Contour>::iterator
ic=temp_poly_list.begin();ic!=temp_poly_list.end();ic++)
{
if (ic!=the_max_area)
{
if(! (*ic).is_clockwise_oriented())
(*ic).reverse_orientation();
temp_pwhs.add_hole((*ic));
std::cout<<"insert one hole"<<"\n";
}
}
ifile.close();

std::cout<<"begin to offset"<<"\n";


double off=0.1;
PolygonWithHolesPtrVector inner_generated_pswhs =

CGAL::create_interior_skeleton_and_offset_polygons_with_holes_2(off,temp_pwhs);
std::cout<<"generated "<<inner_generated_pswhs.size()<<"pwhs"<<"\n";


const char *ofilename = "output.txt";
std::ofstream ofile(ofilename, std::ios::out);

for( PolygonWithHolesPtrVector::const_iterator pi =
inner_generated_pswhs.begin() ; pi != inner_generated_pswhs.end() ; ++ pi )
{

for(Contour::Edge_const_iterator vi =
(**pi).outer_boundary().edges_begin() ; vi !=
(**pi).outer_boundary().edges_end() ; ++ vi )
{
std::cout<< " segment" << ":" << vi->source().x() <<
"," << vi->source().y() <<"------"<< vi->end().x() << "," <<
vi->end().y()<<"\n";
ofile<< " segment" << ":" << vi->source().x() << ","
<< vi->source().y() << vi->end().x() << "," << vi->end().y();

}
std::cout<<"\n";
ofile<<"\n";
for (PolygonWithHoles::Hole_const_iterator
hit=(**pi).holes_begin();hit!=(**pi).holes_end();++hit)
{
for(Contour::Vertex_const_iterator vi =
hit->vertices_begin() ; vi !=hit->vertices_end() ; ++ vi )
{
std::cout<<"
point"<<":"<<vi->x()<<","<<vi->y()<<"\n";
ofile<<"
segment"<<":"<<vi->x()<<","<<vi->y()<<vi->x()<<","<<vi->y();
}
std::cout<<"\n";
ofile<<"\n";
}
}

ofile.close();


}


Archive powered by MHonArc 2.6.16.

Top of Page