From b58ebd3f74669112a40a055ffe2143fb3dfcbfa3 Mon Sep 17 00:00:00 2001 From: Fernando Cacciola Date: Wed, 27 Jan 2010 17:09:17 +0000 Subject: [PATCH] Entering circular polygons being added --- .../boolean_operations_2.cpp | 31 +-- .../include/CGAL/Qt/BezierCurves.h | 2 +- .../include/CGAL/Qt/CircularPolygons.h | 189 +++++++++++------- .../typedefs.h | 16 +- 4 files changed, 144 insertions(+), 94 deletions(-) diff --git a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/boolean_operations_2.cpp b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/boolean_operations_2.cpp index 13e82f01720..0eda1d9a5d2 100644 --- a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/boolean_operations_2.cpp +++ b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/boolean_operations_2.cpp @@ -84,7 +84,7 @@ void trace( std::string s ) #include #include #include -#include +#include //#include #include #include @@ -442,16 +442,17 @@ class MainWindow : private: - QGraphicsScene mScene; - bool mCircular_active ; - bool mBlue_active ; - Curve_set_container mCurve_sets ; - Circular_region_source_container mBlue_circular_sources ; - Circular_region_source_container mRed_circular_sources ; - Bezier_region_source_container mBlue_bezier_sources ; - Bezier_region_source_container mRed_bezier_sources ; - CGAL::Qt::GraphicsViewBezierPolygonInput* mBezierInput ; - CGAL::Qt::GraphicsViewGpsCircleSegmentInput* mCircularInput ; + QGraphicsScene mScene; + bool mCircular_active ; + bool mBlue_active ; + Curve_set_container mCurve_sets ; + Circular_region_source_container mBlue_circular_sources ; + Circular_region_source_container mRed_circular_sources ; + Bezier_region_source_container mBlue_bezier_sources ; + Bezier_region_source_container mRed_bezier_sources ; + CGAL::Qt::GraphicsViewBezierPolygonInput* mBezierInput ; + CGAL::Qt::GraphicsViewCircularPolygonInput* mCircularInput ; + //CGAL::Qt::GraphicsViewGpsCircleSegmentInput* mCircularInput ; //CGAL::Qt::GraphicsViewGpsCircleInput* mCircleInput ; public: @@ -624,8 +625,8 @@ MainWindow::MainWindow() this->addRecentFiles(this->menuFile, this->actionQuit); - mBezierInput = new CGAL::Qt::GraphicsViewBezierPolygonInput (this, &mScene); - mCircularInput = new CGAL::Qt::GraphicsViewGpsCircleSegmentInput (this, &mScene); + mBezierInput = new CGAL::Qt::GraphicsViewBezierPolygonInput (this, &mScene); + mCircularInput = new CGAL::Qt::GraphicsViewCircularPolygonInput(this, &mScene); //mCircleInput = new CGAL::Qt::GraphicsViewCircleInput (this, &mScene); QObject::connect(mBezierInput , SIGNAL(generate(CGAL::Object)), this, SLOT(processInput(CGAL::Object))); @@ -682,7 +683,7 @@ void MainWindow::dropEvent(QDropEvent *event) Circular_polygon linear_2_circ( Linear_polygon const& pgn ) { - CGAL::Cartesian_converter convert ; + CGAL::Cartesian_converter convert ; Circular_polygon rCP; @@ -753,7 +754,7 @@ bool read_dxf ( QString aFileName, Circular_polygon_set& rSet, Circular_region_s if ( in_file ) { - CGAL::Dxf_bsop_reader reader; + CGAL::Dxf_bsop_reader reader; std::vector circ_polygons; std::vector circ_polygons_with_holes; diff --git a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/BezierCurves.h b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/BezierCurves.h index 26b1d1797a1..89c2e02a75b 100644 --- a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/BezierCurves.h +++ b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/BezierCurves.h @@ -25,7 +25,7 @@ #include #include -#define USE_CLIPPING +//#define USE_CLIPPING namespace CGAL { diff --git a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/CircularPolygons.h b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/CircularPolygons.h index facbde134b1..a6831bfe612 100644 --- a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/CircularPolygons.h +++ b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/CircularPolygons.h @@ -35,7 +35,6 @@ struct Circular_X_monotone_bbox } } ; -#if 0 struct Circular_bbox { template @@ -67,9 +66,6 @@ struct Circular_bbox } } ; -#endif - - struct Draw_circular_X_monotone_curve { template @@ -157,8 +153,7 @@ struct Draw_circular_X_monotone_curve } } ; -#if 0 - + struct Draw_circular_curve { template @@ -174,75 +169,56 @@ struct Draw_circular_curve if ( curve.is_circular() ) { - typename X_monotone_circle_segment_2::Circle_2 const& circ = curve.supporting_circle(); - typename X_monotone_circle_segment_2::Kernel::Point_2 const& center = circ.center(); - - if ( curve.is_full() ) + typename Circle_segment_2::Circle_2 const& circ = curve.supporting_circle(); + typename Circle_segment_2::Kernel::Point_2 const& center = circ.center(); + typename Circle_segment_2::Point_2 const& source = curve.source(); + typename Circle_segment_2::Point_2 const& target = curve.target(); + + double sx = to_double(source.x()); + double sy = to_double(source.y()); + double tx = to_double(target.x()); + double ty = to_double(target.y()); + double cx = to_double(center.x()); + double cy = to_double(center.y()); + + bool degenerate = ( sx == tx ) && ( sy == ty ) ; + + if ( !degenerate ) { - double cx = to_double(center.x()); - double cy = to_double(center.y()); - - double rad = std::sqrt( to_double(circ.squared_radius() ) ; - + double sdy = sy - cy ; + double sdx = sx - cx ; + double tdy = ty - cy ; + double tdx = tx - cx ; + + double asource = std::atan2(sdy, sdx ); + double atarget = std::atan2(tdy, tdx ); + + if( asource < 0.0) + asource += 2 * CGAL_PI; + + if( atarget <= 0.0) + atarget += 2 * CGAL_PI; + + if ( atarget < asource ) + atarget += 2 * CGAL_PI; + + double aspan = atarget - asource ; + + const double to_deg = 180.0/CGAL_PI; + + Orientation lO = curve.orientation() ; + if ( aIdx == 0 ) - aPath.moveTo(cx+rad,cy) ; - else aPath.lineTo(cx+rad,cy) ; + aPath.moveTo(sx,sy) ; + else aPath.lineTo(sx,sy) ; QRectF bbox = convert(circ.bbox()) ; - aPath.arcTo(bbox , 0, 360 ); - } - else - { - typename X_monotone_circle_segment_2::Point_2 const& source = curve.source(); - typename X_monotone_circle_segment_2::Point_2 const& target = curve.target(); - - double sx = to_double(source.x()); - double sy = to_double(source.y()); - double tx = to_double(target.x()); - double ty = to_double(target.y()); - double cx = to_double(center.x()); - double cy = to_double(center.y()); + double dasource = std::atan2(-sdy, sdx ) * to_deg ; - bool degenerate = ( sx == tx ) && ( sy == ty ) ; + double daspan = aspan * to_deg * ( lO == COUNTERCLOCKWISE ? -1.0 : +1.0) ; - if ( !degenerate ) - { - double sdy = sy - cy ; - double sdx = sx - cx ; - double tdy = ty - cy ; - double tdx = tx - cx ; - - double asource = std::atan2(sdy, sdx ); - double atarget = std::atan2(tdy, tdx ); - - if( asource < 0.0) - asource += 2 * CGAL_PI; - - if( atarget <= 0.0) - atarget += 2 * CGAL_PI; - - if ( atarget < asource ) - atarget += 2 * CGAL_PI; - - double aspan = atarget - asource ; - - const double to_deg = 180.0/CGAL_PI; - - Orientation lO = curve.orientation() ; - - if ( aIdx == 0 ) - aPath.moveTo(sx,sy) ; - else aPath.lineTo(sx,sy) ; - - QRectF bbox = convert(circ.bbox()) ; - - double dasource = std::atan2(-sdy, sdx ) * to_deg ; - - double daspan = aspan * to_deg * ( lO == COUNTERCLOCKWISE ? -1.0 : +1.0) ; - - aPath.arcTo(bbox , dasource, daspan ); - } + aPath.arcTo(bbox , dasource, daspan ); } } else @@ -256,12 +232,85 @@ struct Draw_circular_curve aPath.lineTo( convert( lT ) ) ; } + } +} ; + +/* +struct Draw_circular_curve +{ + template + void operator()( Circle_segment_2 const& curve, Path& aPath, int aIdx ) const + { + if ( !cs_.is_full() ) + { + double sx = to_double(cs_.source().x()); + double sy = to_double(cs_.source().y()); + double tx = to_double(cs_.target().x()); + double ty = to_double(cs_.target().y()); + + if( cs_.orientation() == COLLINEAR) + { + painter->drawLine(sx,sy,tx,ty); + } + else + { + double cx = to_double(cs_.supporting_circle().center().x()); + double cy = to_double(cs_.supporting_circle().center().y()); + + double x0, y0, x1, y1 ; + if(cs_.orientation() == CLOCKWISE) + { + x0 = sx ; + y0 = sy ; + x1 = tx ; + y1 = ty ; + } + else + { + x0 = tx ; + y0 = ty ; + x1 = sx ; + y1 = sy ; + } + double rad = std::sqrt(CGAL::to_double(cs_.supporting_circle().squared_radius())); + + double a = std::atan2( y0 - cy, x0 - cx ) ; + double a2p = std::atan2( y1 - cy, x1 - cx ); + + if (a2p <= a) + a2p += 2 * CGAL_PI; + + double alen2 = a2p - a; + + double to_deg = 180 / CGAL_PI ; + + painter->drawArc(cx - rad, cy - rad, 2 * rad, 2 * rad, - a * to_deg * 16, - alen2 * to_deg * 16 ); + } + } + else + { + if( cs_.orientation() != COLLINEAR) + { + double cx = to_double(cs_.supporting_circle().center().x()); + double cy = to_double(cs_.supporting_circle().center().y()); + double rad = std::sqrt(CGAL::to_double(cs_.supporting_circle().squared_radius())); + painter->drawArc(cx -rad, cy - rad, 2 * rad, 2 * rad, 0, 360*16); + } + } } } ; +*/ -#endif - +template +class Circular_boundary_pieces_graphics_item : public Boundary_pieces_graphics_item +{ + typedef Boundary_pieces_graphics_item Base ; + +public : + + Circular_boundary_pieces_graphics_item( Circular_boundary_pieces* aPieces ) : Base(aPieces) {} +} ; template class Circular_boundary_graphics_item : public Piecewise_boundary_graphics_item diff --git a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/typedefs.h b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/typedefs.h index fa01a7a26d3..38b9cdde9c7 100644 --- a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/typedefs.h +++ b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/typedefs.h @@ -46,15 +46,15 @@ typedef Linear_kernel::Point_2 Linear_point ; typedef CGAL::Lazy_exact_nt Coord_type; -struct Circular_kernel : public CGAL::Cartesian {}; +struct Gps_circular_kernel : public CGAL::Cartesian {}; -typedef CGAL::Gps_circle_segment_traits_2 Circular_traits; -typedef Circular_traits::Curve_2 Circular_curve; -typedef Circular_traits::X_monotone_curve_2 Circular_X_monotone_curve; -typedef Circular_traits::Point_2 Circular_point ; -typedef Circular_traits::Polygon_2 Circular_polygon; -typedef CGAL::General_polygon_with_holes_2 Circular_polygon_with_holes; -typedef CGAL::General_polygon_set_2 Circular_polygon_set; +typedef CGAL::Gps_circle_segment_traits_2 Circular_traits; +typedef Circular_traits::Curve_2 Circular_curve; +typedef Circular_traits::X_monotone_curve_2 Circular_X_monotone_curve; +typedef Circular_traits::Point_2 Circular_point ; +typedef Circular_traits::Polygon_2 Circular_polygon; +typedef CGAL::General_polygon_with_holes_2 Circular_polygon_with_holes; +typedef CGAL::General_polygon_set_2 Circular_polygon_set; typedef CGAL::Qt::Circular_set_graphics_item Circular_GI;