mirror of https://github.com/CGAL/cgal
cleanup - mainly by a patch provided by Shriramana Sharma
This commit is contained in:
parent
09ca243173
commit
c9f1fa974b
|
|
@ -16,7 +16,6 @@ int main ()
|
||||||
#include <CGAL/Cartesian.h>
|
#include <CGAL/Cartesian.h>
|
||||||
#include <CGAL/CORE_algebraic_number_traits.h>
|
#include <CGAL/CORE_algebraic_number_traits.h>
|
||||||
#include <CGAL/Arr_Bezier_curve_traits_2.h>
|
#include <CGAL/Arr_Bezier_curve_traits_2.h>
|
||||||
#include <CGAL/Arrangement_2.h>
|
|
||||||
#include <CGAL/Gps_traits_2.h>
|
#include <CGAL/Gps_traits_2.h>
|
||||||
#include <CGAL/Boolean_set_operations_2.h>
|
#include <CGAL/Boolean_set_operations_2.h>
|
||||||
#include <CGAL/General_polygon_set_2.h>
|
#include <CGAL/General_polygon_set_2.h>
|
||||||
|
|
@ -51,26 +50,19 @@ Bezier_curve read_bezier_curve ( std::istream& is, bool aDoubleFormat )
|
||||||
|
|
||||||
// Read the control points.
|
// Read the control points.
|
||||||
std::vector<Bezier_rat_point> ctrl_pts;
|
std::vector<Bezier_rat_point> ctrl_pts;
|
||||||
|
for (unsigned int k = 0; k < n; ++k) {
|
||||||
for ( unsigned int k = 0; k < n; k++)
|
|
||||||
{
|
|
||||||
Bezier_rat_point p;
|
Bezier_rat_point p;
|
||||||
if ( aDoubleFormat )
|
if (aDoubleFormat) {
|
||||||
{
|
|
||||||
double x, y;
|
double x, y;
|
||||||
is >> x >> y;
|
is >> x >> y;
|
||||||
p = Bezier_rat_point(x,y);
|
p = Bezier_rat_point(x,y);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
is >> p;
|
is >> p;
|
||||||
}
|
|
||||||
|
|
||||||
if ( k == 0 || ctrl_pts[k-1] != p )
|
if ((k == 0) || (ctrl_pts[k-1] != p))
|
||||||
{
|
|
||||||
ctrl_pts.push_back(p);
|
ctrl_pts.push_back(p);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return Bezier_curve(ctrl_pts.begin(), ctrl_pts.end());
|
return Bezier_curve(ctrl_pts.begin(), ctrl_pts.end());
|
||||||
}
|
}
|
||||||
|
|
@ -82,32 +74,28 @@ bool read_bezier ( char const* aFileName, Bezier_polygon_set& rSet )
|
||||||
|
|
||||||
std::ifstream in_file(aFileName);
|
std::ifstream in_file(aFileName);
|
||||||
|
|
||||||
if ( in_file )
|
if (in_file) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
std::cout << "Reading " << aFileName << std::endl;
|
std::cout << "Reading " << aFileName << std::endl;
|
||||||
|
|
||||||
std::string format;
|
std::string format;
|
||||||
std::getline(in_file, format);
|
std::getline(in_file, format);
|
||||||
|
|
||||||
bool lDoubleFormat = ( format.length() >= 6 &&
|
bool lDoubleFormat =
|
||||||
format.substr(0,6) == "DOUBLE") ;
|
((format.length() >= 6) && (format.substr(0,6) == "DOUBLE"));
|
||||||
|
|
||||||
// Red the number of bezier polygon with holes
|
// Red the number of bezier polygon with holes
|
||||||
unsigned int n_regions;
|
unsigned int n_regions;
|
||||||
in_file >> n_regions;
|
in_file >> n_regions;
|
||||||
|
|
||||||
for ( unsigned int r = 0 ; r < n_regions ; ++ r )
|
for (unsigned int r = 0; r < n_regions; ++r) {
|
||||||
{
|
|
||||||
Bezier_polygon_vector polygons;
|
Bezier_polygon_vector polygons;
|
||||||
|
|
||||||
// Read the number of bezier curves.
|
// Read the number of bezier curves.
|
||||||
unsigned int n_boundaries;
|
unsigned int n_boundaries;
|
||||||
in_file >> n_boundaries;
|
in_file >> n_boundaries;
|
||||||
|
|
||||||
for ( unsigned int b = 0 ; b < n_boundaries ; ++ b )
|
for (unsigned int b = 0; b < n_boundaries; ++b) {
|
||||||
{
|
|
||||||
// Read the number of bezier curves.
|
// Read the number of bezier curves.
|
||||||
unsigned int n_curves;
|
unsigned int n_curves;
|
||||||
in_file >> n_curves;
|
in_file >> n_curves;
|
||||||
|
|
@ -117,8 +105,7 @@ bool read_bezier ( char const* aFileName, Bezier_polygon_set& rSet )
|
||||||
|
|
||||||
std::list<Bezier_X_monotone_curve> xcvs;
|
std::list<Bezier_X_monotone_curve> xcvs;
|
||||||
|
|
||||||
for ( unsigned int k = 0; k < n_curves; ++ k )
|
for (unsigned int k = 0; k < n_curves; ++k) {
|
||||||
{
|
|
||||||
// Read the current curve and subdivide it into x-monotone subcurves.
|
// Read the current curve and subdivide it into x-monotone subcurves.
|
||||||
|
|
||||||
std::list<CGAL::Object> x_objs;
|
std::list<CGAL::Object> x_objs;
|
||||||
|
|
@ -129,28 +116,24 @@ bool read_bezier ( char const* aFileName, Bezier_polygon_set& rSet )
|
||||||
traits.make_x_monotone_2_object();
|
traits.make_x_monotone_2_object();
|
||||||
|
|
||||||
Bezier_curve B = read_bezier_curve(in_file, lDoubleFormat);
|
Bezier_curve B = read_bezier_curve(in_file, lDoubleFormat);
|
||||||
if ( B.number_of_control_points() >= 2 )
|
if (B.number_of_control_points() >= 2) {
|
||||||
{
|
|
||||||
|
|
||||||
make_x_monotone(B, std::back_inserter(x_objs));
|
make_x_monotone(B, std::back_inserter(x_objs));
|
||||||
|
|
||||||
for (xoit = x_objs.begin(); xoit != x_objs.end(); ++xoit)
|
for (xoit = x_objs.begin(); xoit != x_objs.end(); ++xoit) {
|
||||||
{
|
|
||||||
if (CGAL::assign(xcv, *xoit))
|
if (CGAL::assign(xcv, *xoit))
|
||||||
{
|
|
||||||
xcvs.push_back(xcv);
|
xcvs.push_back(xcv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Bezier_polygon pgn(xcvs.begin(), xcvs.end());
|
Bezier_polygon pgn(xcvs.begin(), xcvs.end());
|
||||||
|
|
||||||
CGAL::Orientation orient = pgn.orientation();
|
CGAL::Orientation orient = pgn.orientation();
|
||||||
std::cout << " Orientation: " << orient << std::endl;
|
std::cout << " Orientation: " << orient << std::endl;
|
||||||
|
|
||||||
if (( b == 0 && orient == CGAL::CLOCKWISE) ||
|
if (((b == 0) && (orient == CGAL::CLOCKWISE)) ||
|
||||||
( b > 0 && orient == CGAL::COUNTERCLOCKWISE))
|
((b > 0) && (orient == CGAL::COUNTERCLOCKWISE)))
|
||||||
{
|
{
|
||||||
std::cout << " Reversing orientation: " << std::endl;
|
std::cout << " Reversing orientation: " << std::endl;
|
||||||
pgn.reverse_orientation();
|
pgn.reverse_orientation();
|
||||||
|
|
@ -159,44 +142,37 @@ bool read_bezier ( char const* aFileName, Bezier_polygon_set& rSet )
|
||||||
polygons.push_back(pgn);
|
polygons.push_back(pgn);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( polygons.size() > 0 )
|
if (polygons.size() > 0) {
|
||||||
{
|
|
||||||
Bezier_polygon_with_holes pwh(polygons.front());
|
Bezier_polygon_with_holes pwh(polygons.front());
|
||||||
|
|
||||||
if ( polygons.size() > 1 )
|
if (polygons.size() > 1) {
|
||||||
{
|
|
||||||
Bezier_polygon_vector::const_iterator it;
|
Bezier_polygon_vector::const_iterator it;
|
||||||
for ( it = CGAL::cpp11::next(polygons.begin()); it != polygons.end();
|
for (it = CGAL::cpp11::next(polygons.begin());
|
||||||
++ it )
|
it != polygons.end(); ++it)
|
||||||
pwh.add_hole(*it);
|
pwh.add_hole(*it);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( is_valid_polygon_with_holes(pwh, rSet.traits() ) )
|
if (is_valid_polygon_with_holes(pwh, rSet.traits())) {
|
||||||
{
|
std::cout << " Inserting Bezier polygon with holes comprising "
|
||||||
std::cout << " Inserting bezier polygon with holes made of "
|
<< polygons.size() << " boundaries in total into set."
|
||||||
<< polygons.size() << " boundaries into Set."
|
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
rSet.join(pwh);
|
rSet.join(pwh);
|
||||||
std::cout << " Done." << std::endl;
|
std::cout << " Done." << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
std::cout << " **** Bezier polygon with holes is NOT VALID ****"
|
||||||
std::cout << " **** Bezier polygon wiht holes IS NOT VALID ****"
|
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
rOK = true;
|
rOK = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch( std::exception const& x )
|
catch(std::exception const& x) {
|
||||||
{
|
std::cout << "An exception ocurred during reading of Bezier polygon set:"
|
||||||
std::cout << "Exception ocurred during reading of bezier polygon set:"
|
|
||||||
<< x.what() << std::endl;
|
<< x.what() << std::endl;
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...) {
|
||||||
{
|
std::cout << "An exception ocurred during reading of Bezier polygon set."
|
||||||
std::cout << "Exception ocurred during reading of bezier polygon set."
|
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -235,26 +211,24 @@ int main (int argc, char* argv[])
|
||||||
std::cout << "Starting boolean operation..." << std::endl;
|
std::cout << "Starting boolean operation..." << std::endl;
|
||||||
timer.reset();
|
timer.reset();
|
||||||
timer.start();
|
timer.start();
|
||||||
try
|
try {
|
||||||
{
|
switch (bop[0]) {
|
||||||
switch ( bop[0] )
|
|
||||||
{
|
|
||||||
case 'i': S1.intersection(S2); break;
|
case 'i': S1.intersection(S2); break;
|
||||||
case 'u': S1.join(S2); break;
|
case 'u': S1.join(S2); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch( std::exception const& x )
|
catch(std::exception const& x) {
|
||||||
{
|
std::cout << "An exception occurred during the Boolean operation:"
|
||||||
std::cout << "Exception ocurred during the boolean operation:" << x.what()
|
<< x.what() << std::endl;
|
||||||
<< std::endl ;
|
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...) {
|
||||||
{
|
std::cout << "An exception occurred during the Boolean operation."
|
||||||
std::cout << "Exception ocurred during the boolean operation." << std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
timer.stop();
|
timer.stop();
|
||||||
|
|
||||||
std::cout << "The intersection computation took "
|
std::cout << "The " << ( bop[0] == 'i' ? "intersection" : "union" )
|
||||||
|
<< " computation took "
|
||||||
<< timer.time() << " seconds." << std::endl;
|
<< timer.time() << " seconds." << std::endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue