From c0558dad87480c8d6815d5fce8f490f909a201cc Mon Sep 17 00:00:00 2001 From: Fernando Cacciola Date: Tue, 18 Aug 2009 16:24:24 +0000 Subject: [PATCH] Updates to Boolean_operations_2 Qt4 demo (entering beziers) --- .../boolean_operations_2.cpp | 28 +-- .../Bezier_polygon_with_holes_sampler_2.h | 8 +- .../Circular_polygon_with_holes_sampler_2.h | 8 +- .../CGAL/Qt/GeneralPolygonSetGraphicsItem.h | 79 ++----- .../Qt/Graphics_view_bezier_boundary_input.h | 108 ++++++++++ .../Qt/Graphics_view_bezier_region_input.h | 196 ++++++++++++++++++ .../Qt/Piecewise_boundary_graphics_item.h | 94 +++++++++ .../CGAL/Qt/Piecewise_graphics_item_base.h | 138 ++++++++++++ .../CGAL/Qt/Piecewise_region_graphics_item.h | 100 +++++++++ .../CGAL/Qt/Piecewise_set_graphics_item.h | 122 +++++++++++ .../typedefs.h | 30 +-- 11 files changed, 801 insertions(+), 110 deletions(-) create mode 100644 Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/Graphics_view_bezier_boundary_input.h create mode 100644 Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/Graphics_view_bezier_region_input.h create mode 100644 Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/Piecewise_boundary_graphics_item.h create mode 100644 Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/Piecewise_graphics_item_base.h create mode 100644 Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/Piecewise_region_graphics_item.h create mode 100644 Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/Piecewise_set_graphics_item.h 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 40f35e808d0..21bf5cb0f7b 100755 --- 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 @@ -1,4 +1,4 @@ -// Copyright (c) 2005 Tel-Aviv University (Israel). +// Copyright (c) 2009 GeometryFactory Sarl (France). // All rights reserved. // // This file is part of CGAL (www.cgal.org); you may redistribute it under @@ -15,7 +15,7 @@ // $Id: boolean_operations_2.cpp 45454 2008-09-09 21:42:42Z lrineau $ // // -// Author(s) : Baruch Zukerman +// Author(s) : Fernando Cacciola //#define ENABLE_TRACE @@ -82,8 +82,8 @@ void trace( std::string s ) #include #endif -#include -#include +#include +//#include #include #include #include @@ -443,7 +443,7 @@ private: bool mCircular_active ; bool mBlue_active ; Curve_set_vector mCurve_sets ; - CGAL::Qt::GraphicsViewPolygonWithHolesInput* mPWHI ; +// CGAL::Qt::GraphicsViewPolygonWithHolesInput* mPWHI ; public: @@ -592,9 +592,9 @@ MainWindow::MainWindow() this->addRecentFiles(this->menuFile, this->actionQuit); - mPWHI = new CGAL::Qt::GraphicsViewPolygonWithHolesInput(this, &mScene); +// mPWHI = new CGAL::Qt::GraphicsViewPolygonWithHolesInput(this, &mScene); - QObject::connect(mPWHI, SIGNAL(generate(CGAL::Object)), this, SLOT(processInput(CGAL::Object))); +// QObject::connect(mPWHI, SIGNAL(generate(CGAL::Object)), this, SLOT(processInput(CGAL::Object))); QObject::connect(this->actionQuit, SIGNAL(triggered()), this, SLOT(close())); QObject::connect(this, SIGNAL(openRecentFile(QString)), this, SLOT(open(QString))); @@ -816,7 +816,7 @@ bool read_bezier ( QString aFileName, Bezier_polygon_set& rSet ) Bezier_curve B = read_bezier_curve(in_file, lDoubleFormat); if ( B.number_of_control_points() >= 2 ) { - TRACE( "region " << r << " boundary " << b << " curve " << k ); + //TRACE( "region " << r << " boundary " << b << " curve " << k ); make_x_monotone (B, std::back_inserter (x_objs)); @@ -824,7 +824,7 @@ bool read_bezier ( QString aFileName, Bezier_polygon_set& rSet ) { if (CGAL::assign (xcv, *xoit)) { - TRACE( " X montonote: " << xcv.source() << " -> " << xcv.target() << ( xcv.is_directed_right() ? " RIGHT":" LEFT") << ( xcv.is_vertical() ? " VERTICAL" : "")) ; + //TRACE( " X montonote: " << xcv.source() << " -> " << xcv.target() << ( xcv.is_directed_right() ? " RIGHT":" LEFT") << ( xcv.is_vertical() ? " VERTICAL" : "")) ; xcvs.push_back (xcv); } } @@ -834,11 +834,11 @@ bool read_bezier ( QString aFileName, Bezier_polygon_set& rSet ) Bezier_polygon pgn (xcvs.begin(), xcvs.end()); CGAL::Orientation orient = pgn.orientation(); - TRACE( " Orientation: " << orient ) ; + //TRACE( " Orientation: " << orient ) ; if (( b == 0 && orient == CGAL::CLOCKWISE) || ( b > 0 && orient == CGAL::COUNTERCLOCKWISE)) { - TRACE( "Reversing orientation: " ) ; + //TRACE( "Reversing orientation: " ) ; pgn.reverse_orientation(); } @@ -992,9 +992,9 @@ void MainWindow::open( QString fileName ) void MainWindow::on_actionInsertPWH_toggled(bool aChecked) { - if(aChecked) - mScene.installEventFilter(mPWHI); - else mScene.removeEventFilter (mPWHI); +// if(aChecked) +// mScene.installEventFilter(mPWHI); +// else mScene.removeEventFilter (mPWHI); } void MainWindow::processInput(CGAL::Object o ) diff --git a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Bezier_polygon_with_holes_sampler_2.h b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Bezier_polygon_with_holes_sampler_2.h index 76141e77cbf..93b855f2b64 100755 --- a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Bezier_polygon_with_holes_sampler_2.h +++ b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Bezier_polygon_with_holes_sampler_2.h @@ -1,4 +1,4 @@ -// Copyright (c) 2008 GeometryFactory Sarl (France). +// Copyright (c) 2009 GeometryFactory Sarl (France). // All rights reserved. // // This file is part of CGAL (www.cgal.org); you may redistribute it under @@ -11,11 +11,11 @@ // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // -// $URL: svn+ssh://fcacciola@scm.gforge.inria.fr/svn/cgal/branches/experimental-packages/Polyline_simplification_2/demo/Polyline_simplification_2/include/CGAL/Qt/Polyline_simplification_2_graphics_item.h $ -// $Id: Polyline_simplification_2_graphics_item.h 48710 2009-04-07 21:41:12Z fcacciola $ +// $URL:$ +// $Id:$ // // -// Author(s) : Fernando Cacciola +// Author(s) : Fernando Cacciola #ifndef CGAL_BEZIER_POLYGONAL_SAMPLER_2_H #define CGAL_BEZIER_POLYGONAL_SAMPLER_2_H diff --git a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Circular_polygon_with_holes_sampler_2.h b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Circular_polygon_with_holes_sampler_2.h index 994c46a4719..332223a4328 100755 --- a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Circular_polygon_with_holes_sampler_2.h +++ b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Circular_polygon_with_holes_sampler_2.h @@ -1,4 +1,4 @@ -// Copyright (c) 2008 GeometryFactory Sarl (France). +// Copyright (c) 2009 GeometryFactory Sarl (France). // All rights reserved. // // This file is part of CGAL (www.cgal.org); you may redistribute it under @@ -11,11 +11,11 @@ // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // -// $URL: svn+ssh://fcacciola@scm.gforge.inria.fr/svn/cgal/branches/experimental-packages/Polyline_simplification_2/demo/Polyline_simplification_2/include/CGAL/Qt/Polyline_simplification_2_graphics_item.h $ -// $Id: Polyline_simplification_2_graphics_item.h 48710 2009-04-07 21:41:12Z fcacciola $ +// $URL:$ +// $Id:$ // // -// Author(s) : Fernando Cacciola +// Author(s) : Fernando Cacciola #ifndef CGAL_CIRCULAR_POLYGONAL_SAMPLER_2_H #define CGAL_CIRCULAR_POLYGONAL_SAMPLER_2_H diff --git a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/GeneralPolygonSetGraphicsItem.h b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/GeneralPolygonSetGraphicsItem.h index 69b7e812cc2..33c123ee99b 100755 --- a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/GeneralPolygonSetGraphicsItem.h +++ b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/GeneralPolygonSetGraphicsItem.h @@ -1,4 +1,4 @@ -// Copyright (c) 2008 GeometryFactory Sarl (France). +// Copyright (c) 2009 GeometryFactory Sarl (France). // All rights reserved. // // This file is part of CGAL (www.cgal.org); you may redistribute it under @@ -11,11 +11,11 @@ // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // -// $URL: svn+ssh://fcacciola@scm.gforge.inria.fr/svn/cgal/branches/experimental-packages/Polyline_simplification_2/demo/Polyline_simplification_2/include/CGAL/Qt/Polyline_simplification_2_graphics_item.h $ -// $Id: Polyline_simplification_2_graphics_item.h 48710 2009-04-07 21:41:12Z fcacciola $ +// $URL:$ +// $Id:$ // // -// Author(s) : Fernando Cacciola +// Author(s) : Fernando Cacciola #ifndef CGAL_QT_GENERAL_POLYGON_SET_GRAPHICS_ITEM_H #define CGAL_QT_GENERAL_POLYGON_SET_GRAPHICS_ITEM_H @@ -66,24 +66,28 @@ namespace Qt { typedef typename PS::Traits_2 Traits_2; } ; - template - struct arbitrary_point_helper + template + struct point_cast_helper { - static std::pair approximate( Point const& p ) + static TPoint convert( SPoint const& p ) { - return std::make_pair( to_double(p.x()), to_double(p.y()) ) ; + return TPoint( to_double(p.x()), to_double(p.y()) ) ; } }; - template - struct arbitrary_point_helper< _Bezier_point_2 > + template + struct point_cast_helper > { - static std::pair approximate( _Bezier_point_2 const& p ) + static TPoint convert( CGAL::_Bezier_point_2 const& p ) { - return p.approximate(); + std::pair xy = p.approximate(); + return TPoint(xy.first, xy.second); } } ; + + template + TPoint point_cast ( SPoint const& aP ) { return point_cast_helper::convert(aP); } } template @@ -245,58 +249,9 @@ template template void GeneralPolygonSetGraphicsItem::traverse_polygon( General_polygon const& aP, Visitor& aVisitor) { - // - // Hack to workaround some bezier incosistency proble where the ordering of the curves within the sequence is reversed - // w.r.t to the orientation of each curve in turn. - // - - typedef std::vector XMC_vector ; - - typedef typename General_X_monotone_curve_2::Point_2 Point ; - - XMC_vector curves ; - std::copy(aP.curves_begin(),aP.curves_end(), std::back_inserter(curves) ) ; - - bool lFwd = true ; - - if ( curves.size() >= 2 ) - { - double s0x ; - double s0y ; - double t0x ; - double t0y ; - double s1x ; - double s1y ; - double t1x ; - double t1y ; - - boost::tie(s0x,s0y) = CGALi::arbitrary_point_helper::approximate(curves[0].source()); - boost::tie(t0x,t0y) = CGALi::arbitrary_point_helper::approximate(curves[0].target()); - boost::tie(s1x,s1y) = CGALi::arbitrary_point_helper::approximate(curves[1].source()); - boost::tie(t1x,t1y) = CGALi::arbitrary_point_helper::approximate(curves[1].target()); - - // squared distance between c0.target <-> c1.source - double dts = ((s1x-t0x)*(s1x-t0x))+((s1y-t0y)*(s1y-t0y)); - - // squared distance between c1.source <-> c0.target - double dst = ((s0x-t1x)*(s0x-t1x))+((s0y-t1y)*(s0y-t1y)); - - // The curves are reversed if c1 is followed by c0 - if ( dst < dts ) - lFwd = false ; - } - int c = 0 ; - if ( lFwd ) - { - for( typename XMC_vector::const_iterator cit = curves.begin(); cit != curves.end(); ++ cit ) + for( General_curve_const_iterator cit = aP.curves_begin(); cit != aP.curves_end(); ++ cit ) aVisitor(*cit,c++); - } - else - { - for( typename XMC_vector::const_reverse_iterator cit = curves.rbegin(); cit != curves.rend(); ++ cit ) - aVisitor(*cit,c++); - } } template diff --git a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/Graphics_view_bezier_boundary_input.h b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/Graphics_view_bezier_boundary_input.h new file mode 100644 index 00000000000..5ec85826447 --- /dev/null +++ b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/Graphics_view_bezier_boundary_input.h @@ -0,0 +1,108 @@ +// Copyright (c) 2008 GeometryFactory Sarl (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you may redistribute it under +// the terms of the Q Public License version 1.0. +// See the file LICENSE.QPL distributed with CGAL. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// +// Author(s) : Andreas Fabri +// Laurent Rineau + +#ifndef CGAL_QT_GRAPHICS_VIEW_POLYLINE_INPUT_H +#define CGAL_QT_GRAPHICS_VIEW_POLYLINE_INPUT_H + +#include +#include +#include + +#include +#include + +class QGraphicsScene; +class QGraphicsSceneMouseEvent; +class QGraphicsItem; +class QGraphicsPathItem; +class QKeyEvent; +class QEvent; +class QObject; + +namespace CGAL { +namespace Qt { + +class GraphicsViewPolylineInput_non_templated_base : public GraphicsViewInput +{ +public: + void setNumberOfVertices(int n) + { + n_ = n; + } + + bool eventFilter(QObject *obj, QEvent *event); + +protected: + // protected constructor + GraphicsViewPolylineInput_non_templated_base(QObject* parent, + QGraphicsScene* s, + int n = 0, + bool closed = true); + + + // mousePressEvent returns true iff the event is consummed + bool mousePressEvent(QGraphicsSceneMouseEvent *event); + + void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + + // keyPressEvent returns true iff the event is consummed + bool keyPressEvent(QKeyEvent *event); + + void rubberbands(const QPointF& p); + + virtual void generate_polygon() = 0; + +protected: + QPolygonF polygon; + bool closed_; + +private: + QGraphicsPathItem *path_item; + QGraphicsLineItem *b, *e; + int n_; + QPointF sp; + QGraphicsScene *scene_; +}; // end class GraphicsViewPolylineInput_non_templated_base + +template +class GraphicsViewPolylineInput : public GraphicsViewPolylineInput_non_templated_base +{ +public: + GraphicsViewPolylineInput(QObject* parent, QGraphicsScene* s, int n = 0, bool closed = true) + : GraphicsViewPolylineInput_non_templated_base(parent, s, n, closed) + { + } + +protected: + void generate_polygon() { + std::list points; + Converter convert; + convert(points, this->polygon); + if(closed_){ + points.push_back(points.front()); + } + emit(generate(CGAL::make_object(points))); + } +}; // end class GraphicsViewPolylineInput + +} // namespace Qt +} // namespace CGAL + +#endif // CGAL_QT_GRAPHICS_VIEW_POLYLINE_INPUT_H diff --git a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/Graphics_view_bezier_region_input.h b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/Graphics_view_bezier_region_input.h new file mode 100644 index 00000000000..089e3b1d2b9 --- /dev/null +++ b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/Graphics_view_bezier_region_input.h @@ -0,0 +1,196 @@ +// Copyright (c) 2009 GeometryFactory Sarl (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you may redistribute it under +// the terms of the Q Public License version 1.0. +// See the file LICENSE.QPL distributed with CGAL. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// +// Author(s) : Andreas Fabri +// Laurent Rineau + +#ifndef CGAL_QT_GRAPHICS_VIEW_BEZIER_POLYGON_WITH_HOLES_INPUT_H +#define CGAL_QT_GRAPHICS_VIEW_BEZIER_POLYGON_WITH_HOLES_INPUT_H + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace CGAL { +namespace Qt { + + /* + We store a polygon with boundaries and display it with a graphics item + We use a PolygonInput tool for entering the boundary and the boundaries + We forward most events directly to the polygon input tool + We only deal with events when the polygon input is not active + - left click: enter new polygon + - right click: return result + - backspace: delete last polygon + - esc: return with empty result + + todo: check that polygons don't intersect + */ + + + +template +class GraphicsViewBezierPolygonWithHolesInput : public GraphicsViewInput +{ +public: + GraphicsViewBezierPolygonWithHolesInput(QObject *parent, QGraphicsScene* s); + ~GraphicsViewBezierPolygonWithHolesInput(); + +public slots: + void processInput(CGAL::Object o); + +typedef CGAL::Polygon_2 Bezier_polygon; +typedef CGAL::Polygon_with_holes_2 Bezier_polygon_with_holes; + +protected: + + virtual void keyPressEvent(QKeyEvent *event); + + bool eventFilter(QObject *obj, QEvent *event); + +private: + + Bezier_polygon polygon; + std::vector boundaries; + Bezier_polygon_with_holes pwh; // this one collects the input polygons + + CGAL::Qt::PolygonWithHolesGraphicsItem * pwhItem; + CGAL::Qt::GraphicsViewPolylineInput * pi; + + bool polygon_input; + typedef typename K::Point_2 Point_2; + QGraphicsScene *scene_; +}; + + +template +GraphicsViewBezierPolygonWithHolesInput::GraphicsViewBezierPolygonWithHolesInput(QObject *parent, QGraphicsScene* s) + : GraphicsViewInput(parent), scene_(s), polygon_input(false) +{ + pwhItem = new CGAL::Qt::PolygonWithHolesGraphicsItem(&pwh); + pwhItem->setBrush(::Qt::yellow); + scene_->addItem(pwhItem); + pwhItem->hide(); + + pi = new CGAL::Qt::GraphicsViewPolylineInput(parent,s); + QObject::connect(pi, SIGNAL(generate(CGAL::Object)), + this, SLOT(processInput(CGAL::Object))); + + QObject::connect(this, SIGNAL(modelChanged()), + pwhItem, SLOT(modelChanged())); + +} + +template +GraphicsViewBezierPolygonWithHolesInput::~GraphicsViewBezierPolygonWithHolesInput() +{ + //delete pwhItem; + //delete pi; +} + + +template +void +GraphicsViewBezierPolygonWithHolesInput::processInput(CGAL::Object o) +{ + std::list points; + if(CGAL::assign(points, o)){ + if((points.size() == 1)&& polygon.size()>0){ + + } else { + polygon.clear(); + if(points.front() == points.back()){ + points.pop_back(); + } + polygon.insert(polygon.vertices_begin(), points.begin(), points.end()); + if(boundaries.empty()){ + if(polygon.orientation() == CGAL::CLOCKWISE){ + polygon.reverse_orientation(); + } + } else { + if(polygon.orientation() == CGAL::COUNTERCLOCKWISE){ + polygon.reverse_orientation(); + } + } + boundaries.push_back(polygon); + typename std::list::iterator it = boundaries.begin(); + it++; + pwh = Bezier_polygon_with_holes(boundaries.front(), it, boundaries.end()); + } + emit(modelChanged()); + polygon_input = false; + } +} + + +template +void +GraphicsViewBezierPolygonWithHolesInput::keyPressEvent ( QKeyEvent * event ) +{ +} + + + +template +bool +GraphicsViewBezierPolygonWithHolesInput::eventFilter(QObject *obj, QEvent *event) +{ + if(polygon_input){ + return pi->eventFilter(obj, event); + } else { + if (event->type() == QEvent::GraphicsSceneMousePress) { + QGraphicsSceneMouseEvent *mouseEvent = static_cast(event); + + if(mouseEvent->modifiers() & ::Qt::ShiftModifier){ + return QObject::eventFilter(obj, event);; + } + if(mouseEvent->button() == ::Qt::LeftButton) { + polygon_input = true; + return pi->eventFilter(obj, event); + } else if(mouseEvent->button() == ::Qt::RightButton) { + emit(generate(CGAL::make_object(pwh))); + pwh.clear(); + boundaries.clear(); + polygon_input = false; + emit(modelChanged()); + } + return true; + } else if (event->type() == QEvent::KeyPress) { + QKeyEvent *keyEvent = static_cast(event); + keyPressEvent(keyEvent); + return true; + } else{ + // standard event processing + return QObject::eventFilter(obj, event); + } + } +} + +} // namespace Qt + +} // namespace CGAL + +#endif // CGAL_QT_GRAPHICS_VIEW_BEZIER_POLYGON_WITH_HOLES_INPUT_H diff --git a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/Piecewise_boundary_graphics_item.h b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/Piecewise_boundary_graphics_item.h new file mode 100644 index 00000000000..c50e6406ed3 --- /dev/null +++ b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/Piecewise_boundary_graphics_item.h @@ -0,0 +1,94 @@ +// Copyright (c) 2009 GeometryFactory Sarl (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you may redistribute it under +// the terms of the Q Public License version 1.0. +// See the file LICENSE.QPL distributed with CGAL. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// +// Author(s) : Fernando Cacciola + +#ifndef CGAL_QT_PIECEWISE_BOUNDARY_GRAPHICS_ITEM_H +#define CGAL_QT_PIECEWISE_BOUNDARY_GRAPHICS_ITEM_H + +#include + +namespace CGAL { + +namespace Qt { + +template +class Piecewise_boundary_graphics_item : public Piecewise_graphics_item_base +{ + typedef Piecewise_boundary_ Piecewise_boundary ; + typedef Draw_piece_ Draw_piece ; + + typedef typename Piecewise_boundary::Curve_const_iterator Curve_piece_const_iterator ; + +public: + + Piecewise_boundary_graphics_item( Piecewise_boundary* aBoundary, Draw_piece const& aPieceDrawer = Draw_piece() ) + : + mBoundary (aBoundary) + mPieceDrawer(aPieceDrawer) + {} + +public: + + virtual bool isModelEmpty() const { return !mBoundary || mBoundary->is_empty() ; } + +protected: + + Piecewise_boundary_graphics_item( Draw_piece const& aPieceDrawer = Draw_piece() ) + : + mBoundary (0) + mPieceDrawer(aPieceDrawer) + {} + + virtual void update_bbox( Bbox_builder& aBBoxBuilder) + { + if ( mBoundary ) + update_boundary_bbox(*mBoundary, aBBoxBuilder ) ; + } + + virtual void draw_model ( QPainterPath& aPath ) + { + if ( mBoundary ) + draw_boundary(*mBoundary,aPath); + } + + void update_boundary_bbox( Piecewise_boundary const& aBoundary, Bbox_builder& aBBoxBuilder ) + { + aBBoxBuilder.add( aBoundary.bbox() ) ; + } + + void draw_boundary( Piecewise_boundary const& aBoundary, QPainterPath& aPath ) ; + +protected: + + Piecewise_boundary* mBoundary; + Draw_piece mDrawer ; +}; + +template +void Piecewise_boundary_graphics_item::draw_boundary( Piecewise_boundary const& aBoundary, QPainterPath& aPath ) +{ + int c = 0 ; + for( Curve_piece_const_iterator pit = aBoundary.curves_begin(); pit != aBoundary.curves_end(); ++ pit ) + mPieceDrawer(*pit,aPath,ToQtConverter(),c); +} + + +} // namespace Qt +} // namespace CGAL + +#endif // CGAL_QT_PIECEWISE_BOUNDARY_GRAPHICS_ITEM_H diff --git a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/Piecewise_graphics_item_base.h b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/Piecewise_graphics_item_base.h new file mode 100644 index 00000000000..486bf133357 --- /dev/null +++ b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/Piecewise_graphics_item_base.h @@ -0,0 +1,138 @@ +// Copyright (c) 2009 GeometryFactory Sarl (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you may redistribute it under +// the terms of the Q Public License version 1.0. +// See the file LICENSE.QPL distributed with CGAL. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// +// Author(s) : Fernando Cacciola + +#ifndef CGAL_QT_PIECEWISE_GRAPHICS_ITEM_BASE_H +#define CGAL_QT_PIECEWISE_GRAPHICS_ITEM_BASE_H + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +namespace CGAL { + +namespace Qt { + +class Piecewise_graphics_item_base : public GraphicsItem +{ +protected: + + Piecewise_graphics_item_base() + { + updateBoundingBox(); + } + +public: + + void updateBoundingBox(); + + void modelChanged() + { + updateBoundingBox(); + update(); + } + + QRectF boundingRect() const { return mBounding_rect ; } + + void paint(QPainter* aPainter, const QStyleOptionGraphicsItem* aOption, QWidget* aWidget); + + const QBrush& brush() const { return mBrush; } + + void setBrush(const QBrush& aBrush ) { mBrush = aBrush; } + + const QPen& pen() const{ return mPen; } + + void setPen(const QPen& aPen) { mPen = aPen; } + +protected: + + typedef Converter< Simple_cartesian > ToQtConverter; + + struct Bbox_builder + { + void add ( Bbox_2 const& aBbox ) + { + if ( bbox ) + bbox = *bbox + aBbox; + else bbox = aBbox; + } + + boost::optional bbox ; + } ; + + virtual bool isModelEmpty() const = 0 ; + + virtual void draw_model ( QPainterPath& aPath ) = 0 ; + + virtual void update_bbox( Bbox_builder& aBBoxBuilder) = 0 ; + +protected: + + QRectF mBounding_rect; + QBrush mBrush; + QPen mPen; +}; + + +void Piecewise_graphics_item_base::paint( QPainter* aPainter, const QStyleOptionGraphicsItem* aOption, QWidget* aWidget ) +{ + if ( ! isModelEmpty() ) + { + QPainterPath lPath ; + + draw_model(lPath); + + aPainter->setPen (mPen ); + aPainter->setBrush(mBrush); + aPainter->drawPath(lPath); + } +} + +// We let the bounding box only grow, so that when vertices get removed +// the maximal bbox gets refreshed in the GraphicsView +void Piecewise_graphics_item_base::updateBoundingBox() +{ + if ( ! isModelEmpty() ) + { + prepareGeometryChange(); + + Bbox_builder lBBoxBuilder ; + + update_bbox(lBBoxBuilder); + + if ( lBBoxBuilder.bbox ) + { + ToQtConverter to_Qt ; + mBounding_rect = to_Qt(*lBBoxBuilder.bbox); + } + } +} + + +} // namespace Qt +} // namespace CGAL + +#endif // CGAL_QT_PIECEWISE_GRAPHICS_ITEM_BASE_H diff --git a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/Piecewise_region_graphics_item.h b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/Piecewise_region_graphics_item.h new file mode 100644 index 00000000000..fdc22f707bf --- /dev/null +++ b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/Piecewise_region_graphics_item.h @@ -0,0 +1,100 @@ +// Copyright (c) 2009 GeometryFactory Sarl (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you may redistribute it under +// the terms of the Q Public License version 1.0. +// See the file LICENSE.QPL distributed with CGAL. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// +// Author(s) : Fernando Cacciola + +#ifndef CGAL_QT_PIECEWISE_REGION_GRAPHICS_ITEM_H +#define CGAL_QT_PIECEWISE_REGION_GRAPHICS_ITEM_H + +#include + +namespace CGAL { + +namespace Qt { + +template +class Piecewise_region_graphics_item : public Piecewise_boundary_graphics_item< typename Piecewise_region_::General_polygon_2, Draw_piece_ > +{ + typedef Piecewise_boundary_graphics_item< typename Piecewise_region_::General_polygon_2, Draw_piece_> Base ; + + typedef Piecewise_region_ Piecewise_region ; + typedef Draw_piece_ Draw_piece ; + + typedef typename Piecewise_region::Hole_const_iterator Hole_const_itertator ; + +public: + + Piecewise_region_graphics_item( Piecewise_region* aRegion, Draw_piece const& aPieceDrawer = Draw_piece() ) + : + Base(aPieceDrawer) + ,mRegion (aRegion) + {} + +public: + + virtual bool isModelEmpty() const { return !mRegion || mRegion->outer_boundary().size() ; } + +protected: + + Piecewise_region_graphics_item( Draw_piece const& aPieceDrawer = Draw_piece() ) + : + Base(aPieceDrawer) + {} + + virtual void update_bbox( Bbox_builder& aBBoxBuilder) + { + if ( mRegion ) + update_region_bbox(*mRegion, aBBoxBuilder ) ; + } + + virtual void draw_model ( QPainterPath& aPath ) + { + if ( mRegion ) + draw_region(*mRegion,aPath); + } + + void update_region_bbox( Piecewise_region const& aRegion, Bbox_builder& aBBoxBuilder ) ; + void draw_region ( Piecewise_region const& aRegion, QPainterPath& aPath ) ; + +protected: + + Piecewise_region* mRegion; +}; + +template +void Piecewise_region_graphics_item::update_region_bbox( Piecewise_region const& aRegion, Bbox_builder& aBBoxBuilder ) +{ + update_boundary_bbox( aRegion.outer_boundary(), aBBoxBuilder ) ; + + for( Hole_const_itertator hit = aRegion.holes_begin(); hit != aRegion.holes_end(); ++ hit ) + update_boundary_bbox(*hit,aBBoxBuilder); +} + +template +void Piecewise_region_graphics_item::draw_region( Piecewise_region const& aRegion, QPainterPath& aPath ) +{ + draw_boundary( aRegion.outer_boundary(), aPath ) ; + + for( Hole_const_itertator hit = aRegion.holes_begin(); hit != aRegion.holes_end(); ++ hit ) + draw_boundary(*hit,aPath); +} + + +} // namespace Qt +} // namespace CGAL + +#endif // CGAL_QT_PIECEWISE_REGION_GRAPHICS_ITEM_H diff --git a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/Piecewise_set_graphics_item.h b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/Piecewise_set_graphics_item.h new file mode 100644 index 00000000000..4db5603b415 --- /dev/null +++ b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/Piecewise_set_graphics_item.h @@ -0,0 +1,122 @@ +// Copyright (c) 2009 GeometryFactory Sarl (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you may redistribute it under +// the terms of the Q Public License version 1.0. +// See the file LICENSE.QPL distributed with CGAL. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// +// Author(s) : Fernando Cacciola + +#ifndef CGAL_QT_PIECEWISE_SET_GRAPHICS_ITEM_H +#define CGAL_QT_PIECEWISE_SET_GRAPHICS_ITEM_H + +#include + +namespace CGAL { + +namespace Qt { + + namespace CGALi + { + template + struct Piecewise_set_traits + { + typedef typename Piecewise_set::Base base ; + + typedef typename base::Polygon_with_holes_2 Region ; + } ; + + template + struct Piecewise_set_traits< Polygon_set_2 > + { + typedef Polygon_set_2 PS ; + + typedef typename PS::Polygon_with_holes_2 Region ; + } ; + } + +template +class Piecewise_set_graphics_item : public Piecewise_region_graphics_item< typename CGALi::Piecewise_set_traits::Region, Draw_piece_ > +{ + typedef Piecewise_set_ Piecewise_set ; + typedef Draw_piece_ Draw_piece ; + + typedef typename CGALi::Piecewise_set_traits::Region Region ; + + typedef Piecewise_region_graphics_item Base ; + + typedef std::vector Region_vector ; + + typedef typename Region_vector::const_iterator Region_const_iterator ; + +public: + + Piecewise_set_graphics_item( Piecewise_set* aSet, Draw_piece const& aPieceDrawer = Draw_piece() ) + : + Base(aPieceDrawer) + ,mSet(aSet) + {} + +public: + + virtual bool isModelEmpty() const { return !mSet || mSet->is_empty() ; } + +protected: + + virtual void update_bbox( Bbox_builder& aBBoxBuilder) + { + if ( mSet ) + update_set_bbox(*mSet, aBBoxBuilder ) ; + } + + virtual void draw_model ( QPainterPath& aPath ) + { + if ( mSet ) + draw_set(*mSet,aPath); + } + + void update_set_bbox( Piecewise_set const& aSet, Bbox_builder& aBBoxBuilder ) ; + void draw_set ( Piecewise_set const& aSet, QPainterPath& aPath ) ; + +protected: + + Piecewise_set* mSet; +}; + +template +void Piecewise_set_graphics_item::update_set_bbox( Piecewise_set const& aSet, Bbox_builder& aBBoxBuilder ) +{ + Region_vector vec ; + + aSet.polygons_with_holes( std::back_inserter(vec) ) ; + + for( Region_const_iterator rit = vec.begin(); rit != vec.end() ; ++ rit ) + update_region_bbox(*rit,aBBoxBuilder); +} + +template +void Piecewise_set_graphics_item::draw_set( Piecewise_set const& aSet, QPainterPath& aPath ) +{ + Region_vector vec ; + + aSet.polygons_with_holes( std::back_inserter(vec) ) ; + + for( Region_const_iterator rit = vec.begin(); rit != vec.end() ; ++ rit ) + draw_region(*rit,aPath); +} + + +} // namespace Qt +} // namespace CGAL + +#endif // CGAL_QT_PIECEWISE_SET_GRAPHICS_ITEM_H 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 ed4b3ad4c81..71e2569629f 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 @@ -1,4 +1,4 @@ -// Copyright (c) 2005 Tel-Aviv University (Israel). +// Copyright (c) 2009 GeometryFactory Sarl (France). // All rights reserved. // // This file is part of CGAL (www.cgal.org); you may redistribute it under @@ -15,7 +15,7 @@ // $Id: typedefs.h 37003 2007-03-10 16:55:12Z spion $ // // -// Author(s) : Baruch Zukerman +// Author(s) : Fernando Cacciola // #ifndef CGAL_TYPEDEFS_H #define CGAL_TYPEDEFS_H @@ -56,14 +56,6 @@ 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; -struct Compute_circular_X_monotone_cuve_bbox -{ - CGAL::Bbox_2 operator()( Circular_X_monotone_curve const& curve ) const - { - return curve.bbox(); - } -} ; - struct Draw_circular_X_monotone_cuve { template @@ -79,7 +71,7 @@ struct Draw_circular_X_monotone_cuve aPath->lineTo( aConvert( lT ) ) ; } } ; -typedef CGAL::Qt::GeneralPolygonSetGraphicsItem Circular_GI; +typedef CGAL::Qt::Piecewise_set_graphics_item Circular_GI; @@ -199,20 +191,6 @@ struct Bezier_helper } } ; -struct Compute_bezier_X_monotone_cuve_bbox -{ - CGAL::Bbox_2 operator()( Bezier_X_monotone_curve const& aCurve ) const - { - return aCurve.supporting_curve().bbox(); - - std::vector lQ ; - - Bezier_helper::get_control_points(aCurve.supporting_curve(), true, std::back_inserter(lQ) ) ; - - return CGAL::bbox_2(lQ.begin(),lQ.end()); - } -} ; - struct Draw_bezier_X_monotone_cuve { template @@ -269,7 +247,7 @@ struct Draw_bezier_X_monotone_cuve } } ; -typedef CGAL::Qt::GeneralPolygonSetGraphicsItem Bezier_GI; +typedef CGAL::Qt::Piecewise_set_graphics_item Bezier_GI; #endif