mirror of https://github.com/CGAL/cgal
Updates to Boolean_operations_2 Qt4 demo (entering beziers)
This commit is contained in:
parent
aec98e49c2
commit
c0558dad87
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (c) 2005 Tel-Aviv University (Israel).
|
// Copyright (c) 2009 GeometryFactory Sarl (France).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// This file is part of CGAL (www.cgal.org); you may redistribute it under
|
// 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 $
|
// $Id: boolean_operations_2.cpp 45454 2008-09-09 21:42:42Z lrineau $
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Author(s) : Baruch Zukerman <baruchzu@post.tau.ac.il>
|
// Author(s) : Fernando Cacciola <fernando.cacciola@geometryfactory.com>
|
||||||
|
|
||||||
|
|
||||||
//#define ENABLE_TRACE
|
//#define ENABLE_TRACE
|
||||||
|
|
@ -82,8 +82,8 @@ void trace( std::string s )
|
||||||
#include <CGAL/Quotient.h>
|
#include <CGAL/Quotient.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <CGAL/Qt/GeneralPolygonSetGraphicsItem.h>
|
#include <CGAL/Qt/Piecewise_set_graphics_item.h>
|
||||||
#include <CGAL/Qt/GraphicsViewPolygonWithHolesInput.h>
|
//#include <CGAL/Qt/GraphicsViewPolygonWithHolesInput.h>
|
||||||
#include <CGAL/Qt/Converter.h>
|
#include <CGAL/Qt/Converter.h>
|
||||||
#include <CGAL/Qt/DemosMainWindow.h>
|
#include <CGAL/Qt/DemosMainWindow.h>
|
||||||
#include <CGAL/Qt/utility.h>
|
#include <CGAL/Qt/utility.h>
|
||||||
|
|
@ -443,7 +443,7 @@ private:
|
||||||
bool mCircular_active ;
|
bool mCircular_active ;
|
||||||
bool mBlue_active ;
|
bool mBlue_active ;
|
||||||
Curve_set_vector mCurve_sets ;
|
Curve_set_vector mCurve_sets ;
|
||||||
CGAL::Qt::GraphicsViewPolygonWithHolesInput<Linear_kernel>* mPWHI ;
|
// CGAL::Qt::GraphicsViewPolygonWithHolesInput<Linear_kernel>* mPWHI ;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
@ -592,9 +592,9 @@ MainWindow::MainWindow()
|
||||||
|
|
||||||
this->addRecentFiles(this->menuFile, this->actionQuit);
|
this->addRecentFiles(this->menuFile, this->actionQuit);
|
||||||
|
|
||||||
mPWHI = new CGAL::Qt::GraphicsViewPolygonWithHolesInput<Linear_kernel>(this, &mScene);
|
// mPWHI = new CGAL::Qt::GraphicsViewPolygonWithHolesInput<Linear_kernel>(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->actionQuit, SIGNAL(triggered()), this, SLOT(close()));
|
||||||
QObject::connect(this, SIGNAL(openRecentFile(QString)), this, SLOT(open(QString)));
|
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);
|
Bezier_curve B = read_bezier_curve(in_file, lDoubleFormat);
|
||||||
if ( B.number_of_control_points() >= 2 )
|
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));
|
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))
|
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);
|
xcvs.push_back (xcv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -834,11 +834,11 @@ bool read_bezier ( QString aFileName, Bezier_polygon_set& rSet )
|
||||||
Bezier_polygon pgn (xcvs.begin(), xcvs.end());
|
Bezier_polygon pgn (xcvs.begin(), xcvs.end());
|
||||||
|
|
||||||
CGAL::Orientation orient = pgn.orientation();
|
CGAL::Orientation orient = pgn.orientation();
|
||||||
TRACE( " Orientation: " << orient ) ;
|
//TRACE( " Orientation: " << orient ) ;
|
||||||
|
|
||||||
if (( b == 0 && orient == CGAL::CLOCKWISE) || ( b > 0 && orient == CGAL::COUNTERCLOCKWISE))
|
if (( b == 0 && orient == CGAL::CLOCKWISE) || ( b > 0 && orient == CGAL::COUNTERCLOCKWISE))
|
||||||
{
|
{
|
||||||
TRACE( "Reversing orientation: " ) ;
|
//TRACE( "Reversing orientation: " ) ;
|
||||||
pgn.reverse_orientation();
|
pgn.reverse_orientation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -992,9 +992,9 @@ void MainWindow::open( QString fileName )
|
||||||
|
|
||||||
void MainWindow::on_actionInsertPWH_toggled(bool aChecked)
|
void MainWindow::on_actionInsertPWH_toggled(bool aChecked)
|
||||||
{
|
{
|
||||||
if(aChecked)
|
// if(aChecked)
|
||||||
mScene.installEventFilter(mPWHI);
|
// mScene.installEventFilter(mPWHI);
|
||||||
else mScene.removeEventFilter (mPWHI);
|
// else mScene.removeEventFilter (mPWHI);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::processInput(CGAL::Object o )
|
void MainWindow::processInput(CGAL::Object o )
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (c) 2008 GeometryFactory Sarl (France).
|
// Copyright (c) 2009 GeometryFactory Sarl (France).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// This file is part of CGAL (www.cgal.org); you may redistribute it under
|
// 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
|
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||||
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
// 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 $
|
// $URL:$
|
||||||
// $Id: Polyline_simplification_2_graphics_item.h 48710 2009-04-07 21:41:12Z fcacciola $
|
// $Id:$
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Author(s) : Fernando Cacciola <Fernando.Cacciola @geometryfactory.com>
|
// Author(s) : Fernando Cacciola <fernando.cacciola@geometryfactory.com>
|
||||||
|
|
||||||
#ifndef CGAL_BEZIER_POLYGONAL_SAMPLER_2_H
|
#ifndef CGAL_BEZIER_POLYGONAL_SAMPLER_2_H
|
||||||
#define CGAL_BEZIER_POLYGONAL_SAMPLER_2_H
|
#define CGAL_BEZIER_POLYGONAL_SAMPLER_2_H
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (c) 2008 GeometryFactory Sarl (France).
|
// Copyright (c) 2009 GeometryFactory Sarl (France).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// This file is part of CGAL (www.cgal.org); you may redistribute it under
|
// 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
|
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||||
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
// 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 $
|
// $URL:$
|
||||||
// $Id: Polyline_simplification_2_graphics_item.h 48710 2009-04-07 21:41:12Z fcacciola $
|
// $Id:$
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Author(s) : Fernando Cacciola <Fernando.Cacciola @geometryfactory.com>
|
// Author(s) : Fernando Cacciola <fernando.Cacciola@geometryfactory.com>
|
||||||
|
|
||||||
#ifndef CGAL_CIRCULAR_POLYGONAL_SAMPLER_2_H
|
#ifndef CGAL_CIRCULAR_POLYGONAL_SAMPLER_2_H
|
||||||
#define CGAL_CIRCULAR_POLYGONAL_SAMPLER_2_H
|
#define CGAL_CIRCULAR_POLYGONAL_SAMPLER_2_H
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (c) 2008 GeometryFactory Sarl (France).
|
// Copyright (c) 2009 GeometryFactory Sarl (France).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// This file is part of CGAL (www.cgal.org); you may redistribute it under
|
// 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
|
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||||
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
// 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 $
|
// $URL:$
|
||||||
// $Id: Polyline_simplification_2_graphics_item.h 48710 2009-04-07 21:41:12Z fcacciola $
|
// $Id:$
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Author(s) : Fernando Cacciola <Fernando.Cacciola @geometryfactory.com>
|
// Author(s) : Fernando Cacciola <fernando.cacciola@geometryfactory.com>
|
||||||
|
|
||||||
#ifndef CGAL_QT_GENERAL_POLYGON_SET_GRAPHICS_ITEM_H
|
#ifndef CGAL_QT_GENERAL_POLYGON_SET_GRAPHICS_ITEM_H
|
||||||
#define 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;
|
typedef typename PS::Traits_2 Traits_2;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
template<class Point>
|
template<class TPoint,class SPoint>
|
||||||
struct arbitrary_point_helper
|
struct point_cast_helper
|
||||||
{
|
{
|
||||||
static std::pair<double,double> 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 <class R, class A, class N, class B>
|
template <class TPoint, class R, class A, class N, class B>
|
||||||
struct arbitrary_point_helper< _Bezier_point_2<R,A,N,B> >
|
struct point_cast_helper<TPoint, CGAL::_Bezier_point_2<R,A,N,B> >
|
||||||
{
|
{
|
||||||
static std::pair<double,double> approximate( _Bezier_point_2<R,A,N,B> const& p )
|
static TPoint convert( CGAL::_Bezier_point_2<R,A,N,B> const& p )
|
||||||
{
|
{
|
||||||
return p.approximate();
|
std::pair<double,double> xy = p.approximate();
|
||||||
|
return TPoint(xy.first, xy.second);
|
||||||
}
|
}
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
template<class TPoint, class SPoint>
|
||||||
|
TPoint point_cast ( SPoint const& aP ) { return point_cast_helper<TPoint,SPoint>::convert(aP); }
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class General_polygon_set_, class Compute_XM_curve_bbox_, class Draw_XM_curve_>
|
template <class General_polygon_set_, class Compute_XM_curve_bbox_, class Draw_XM_curve_>
|
||||||
|
|
@ -245,58 +249,9 @@ template <class G, class B, class D>
|
||||||
template<class Visitor>
|
template<class Visitor>
|
||||||
void GeneralPolygonSetGraphicsItem<G,B,D>::traverse_polygon( General_polygon const& aP, Visitor& aVisitor)
|
void GeneralPolygonSetGraphicsItem<G,B,D>::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<General_X_monotone_curve_2> 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<Point>::approximate(curves[0].source());
|
|
||||||
boost::tie(t0x,t0y) = CGALi::arbitrary_point_helper<Point>::approximate(curves[0].target());
|
|
||||||
boost::tie(s1x,s1y) = CGALi::arbitrary_point_helper<Point>::approximate(curves[1].source());
|
|
||||||
boost::tie(t1x,t1y) = CGALi::arbitrary_point_helper<Point>::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 ;
|
int c = 0 ;
|
||||||
if ( lFwd )
|
for( General_curve_const_iterator cit = aP.curves_begin(); cit != aP.curves_end(); ++ cit )
|
||||||
{
|
|
||||||
for( typename XMC_vector::const_iterator cit = curves.begin(); cit != curves.end(); ++ cit )
|
|
||||||
aVisitor(*cit,c++);
|
aVisitor(*cit,c++);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for( typename XMC_vector::const_reverse_iterator cit = curves.rbegin(); cit != curves.rend(); ++ cit )
|
|
||||||
aVisitor(*cit,c++);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class G, class B, class D>
|
template <class G, class B, class D>
|
||||||
|
|
|
||||||
|
|
@ -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 <Andreas.Fabri@geometryfactory.com>
|
||||||
|
// Laurent Rineau <Laurent.Rineau@geometryfactory.com>
|
||||||
|
|
||||||
|
#ifndef CGAL_QT_GRAPHICS_VIEW_POLYLINE_INPUT_H
|
||||||
|
#define CGAL_QT_GRAPHICS_VIEW_POLYLINE_INPUT_H
|
||||||
|
|
||||||
|
#include <CGAL/auto_link/Qt4.h>
|
||||||
|
#include <QPolygonF>
|
||||||
|
#include <QPointF>
|
||||||
|
|
||||||
|
#include <CGAL/Qt/GraphicsViewInput.h>
|
||||||
|
#include <CGAL/Qt/Converter.h>
|
||||||
|
|
||||||
|
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 <typename K>
|
||||||
|
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<typename K::Point_2> points;
|
||||||
|
Converter<K> 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
|
||||||
|
|
@ -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 <Andreas.Fabri@geometryfactory.com>
|
||||||
|
// Laurent Rineau <Laurent.Rineau@geometryfactory.com>
|
||||||
|
|
||||||
|
#ifndef CGAL_QT_GRAPHICS_VIEW_BEZIER_POLYGON_WITH_HOLES_INPUT_H
|
||||||
|
#define CGAL_QT_GRAPHICS_VIEW_BEZIER_POLYGON_WITH_HOLES_INPUT_H
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
|
||||||
|
#include <QGraphicsView>
|
||||||
|
#include <QGraphicsItem>
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
|
||||||
|
#include <CGAL/Polygon_with_holes_2.h>
|
||||||
|
#include <CGAL/Qt/GraphicsViewInput.h>
|
||||||
|
#include <CGAL/Qt/PolygonWithHolesGraphicsItem.h>
|
||||||
|
#include <CGAL/Qt/GraphicsViewBezierPolylineInput.h>
|
||||||
|
#include <CGAL/array.h>
|
||||||
|
|
||||||
|
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 <typename K>
|
||||||
|
class GraphicsViewBezierPolygonWithHolesInput : public GraphicsViewInput
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GraphicsViewBezierPolygonWithHolesInput(QObject *parent, QGraphicsScene* s);
|
||||||
|
~GraphicsViewBezierPolygonWithHolesInput();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void processInput(CGAL::Object o);
|
||||||
|
|
||||||
|
typedef CGAL::Polygon_2<K> Bezier_polygon;
|
||||||
|
typedef CGAL::Polygon_with_holes_2<K> Bezier_polygon_with_holes;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual void keyPressEvent(QKeyEvent *event);
|
||||||
|
|
||||||
|
bool eventFilter(QObject *obj, QEvent *event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
Bezier_polygon polygon;
|
||||||
|
std::vector<Bezier_polygon> boundaries;
|
||||||
|
Bezier_polygon_with_holes pwh; // this one collects the input polygons
|
||||||
|
|
||||||
|
CGAL::Qt::PolygonWithHolesGraphicsItem<Bezier_polygon_with_holes> * pwhItem;
|
||||||
|
CGAL::Qt::GraphicsViewPolylineInput<K> * pi;
|
||||||
|
|
||||||
|
bool polygon_input;
|
||||||
|
typedef typename K::Point_2 Point_2;
|
||||||
|
QGraphicsScene *scene_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template <typename K>
|
||||||
|
GraphicsViewBezierPolygonWithHolesInput<K>::GraphicsViewBezierPolygonWithHolesInput(QObject *parent, QGraphicsScene* s)
|
||||||
|
: GraphicsViewInput(parent), scene_(s), polygon_input(false)
|
||||||
|
{
|
||||||
|
pwhItem = new CGAL::Qt::PolygonWithHolesGraphicsItem<Bezier_polygon_with_holes>(&pwh);
|
||||||
|
pwhItem->setBrush(::Qt::yellow);
|
||||||
|
scene_->addItem(pwhItem);
|
||||||
|
pwhItem->hide();
|
||||||
|
|
||||||
|
pi = new CGAL::Qt::GraphicsViewPolylineInput<K>(parent,s);
|
||||||
|
QObject::connect(pi, SIGNAL(generate(CGAL::Object)),
|
||||||
|
this, SLOT(processInput(CGAL::Object)));
|
||||||
|
|
||||||
|
QObject::connect(this, SIGNAL(modelChanged()),
|
||||||
|
pwhItem, SLOT(modelChanged()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename K>
|
||||||
|
GraphicsViewBezierPolygonWithHolesInput<K>::~GraphicsViewBezierPolygonWithHolesInput()
|
||||||
|
{
|
||||||
|
//delete pwhItem;
|
||||||
|
//delete pi;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename K>
|
||||||
|
void
|
||||||
|
GraphicsViewBezierPolygonWithHolesInput<K>::processInput(CGAL::Object o)
|
||||||
|
{
|
||||||
|
std::list<Point_2> 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<Bezier_polygon>::iterator it = boundaries.begin();
|
||||||
|
it++;
|
||||||
|
pwh = Bezier_polygon_with_holes(boundaries.front(), it, boundaries.end());
|
||||||
|
}
|
||||||
|
emit(modelChanged());
|
||||||
|
polygon_input = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename K>
|
||||||
|
void
|
||||||
|
GraphicsViewBezierPolygonWithHolesInput<K>::keyPressEvent ( QKeyEvent * event )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template <typename K>
|
||||||
|
bool
|
||||||
|
GraphicsViewBezierPolygonWithHolesInput<K>::eventFilter(QObject *obj, QEvent *event)
|
||||||
|
{
|
||||||
|
if(polygon_input){
|
||||||
|
return pi->eventFilter(obj, event);
|
||||||
|
} else {
|
||||||
|
if (event->type() == QEvent::GraphicsSceneMousePress) {
|
||||||
|
QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(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<QKeyEvent *>(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
|
||||||
|
|
@ -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 <fernando.cacciola@geometryfactory.com>
|
||||||
|
|
||||||
|
#ifndef CGAL_QT_PIECEWISE_BOUNDARY_GRAPHICS_ITEM_H
|
||||||
|
#define CGAL_QT_PIECEWISE_BOUNDARY_GRAPHICS_ITEM_H
|
||||||
|
|
||||||
|
#include <CGAL/Qt/Piecewise_graphics_item_base.h>
|
||||||
|
|
||||||
|
namespace CGAL {
|
||||||
|
|
||||||
|
namespace Qt {
|
||||||
|
|
||||||
|
template <class Piecewise_boundary_, class Draw_piece_>
|
||||||
|
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 <class B, class D>
|
||||||
|
void Piecewise_boundary_graphics_item<B,D>::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
|
||||||
|
|
@ -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 <fernando.cacciola@geometryfactory.com>
|
||||||
|
|
||||||
|
#ifndef CGAL_QT_PIECEWISE_GRAPHICS_ITEM_BASE_H
|
||||||
|
#define CGAL_QT_PIECEWISE_GRAPHICS_ITEM_BASE_H
|
||||||
|
|
||||||
|
#include <boost/optional.hpp>
|
||||||
|
#include <boost/utility.hpp>
|
||||||
|
|
||||||
|
#include <CGAL/function_objects.h>
|
||||||
|
#include <CGAL/Bbox_2.h>
|
||||||
|
#include <CGAL/Qt/GraphicsItem.h>
|
||||||
|
#include <CGAL/Qt/Converter.h>
|
||||||
|
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QBrush>
|
||||||
|
#include <QPen>
|
||||||
|
|
||||||
|
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<double> > ToQtConverter;
|
||||||
|
|
||||||
|
struct Bbox_builder
|
||||||
|
{
|
||||||
|
void add ( Bbox_2 const& aBbox )
|
||||||
|
{
|
||||||
|
if ( bbox )
|
||||||
|
bbox = *bbox + aBbox;
|
||||||
|
else bbox = aBbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::optional<Bbox_2> 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
|
||||||
|
|
@ -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 <fernando.cacciola@geometryfactory.com>
|
||||||
|
|
||||||
|
#ifndef CGAL_QT_PIECEWISE_REGION_GRAPHICS_ITEM_H
|
||||||
|
#define CGAL_QT_PIECEWISE_REGION_GRAPHICS_ITEM_H
|
||||||
|
|
||||||
|
#include <CGAL/Qt/Piecewise_boundary_graphics_item.h>
|
||||||
|
|
||||||
|
namespace CGAL {
|
||||||
|
|
||||||
|
namespace Qt {
|
||||||
|
|
||||||
|
template <class Piecewise_region_, class Draw_piece_>
|
||||||
|
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 <class R, class D>
|
||||||
|
void Piecewise_region_graphics_item<R,D>::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 <class R, class D>
|
||||||
|
void Piecewise_region_graphics_item<R,D>::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
|
||||||
|
|
@ -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 <fernando.cacciola@geometryfactory.com>
|
||||||
|
|
||||||
|
#ifndef CGAL_QT_PIECEWISE_SET_GRAPHICS_ITEM_H
|
||||||
|
#define CGAL_QT_PIECEWISE_SET_GRAPHICS_ITEM_H
|
||||||
|
|
||||||
|
#include <CGAL/Qt/Piecewise_region_graphics_item.h>
|
||||||
|
|
||||||
|
namespace CGAL {
|
||||||
|
|
||||||
|
namespace Qt {
|
||||||
|
|
||||||
|
namespace CGALi
|
||||||
|
{
|
||||||
|
template<class Piecewise_set>
|
||||||
|
struct Piecewise_set_traits
|
||||||
|
{
|
||||||
|
typedef typename Piecewise_set::Base base ;
|
||||||
|
|
||||||
|
typedef typename base::Polygon_with_holes_2 Region ;
|
||||||
|
} ;
|
||||||
|
|
||||||
|
template<class K, class C, class D>
|
||||||
|
struct Piecewise_set_traits< Polygon_set_2<K,C,D> >
|
||||||
|
{
|
||||||
|
typedef Polygon_set_2<K,C,D> PS ;
|
||||||
|
|
||||||
|
typedef typename PS::Polygon_with_holes_2 Region ;
|
||||||
|
} ;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Piecewise_set_, class Draw_piece_>
|
||||||
|
class Piecewise_set_graphics_item : public Piecewise_region_graphics_item< typename CGALi::Piecewise_set_traits<Piecewise_set_>::Region, Draw_piece_ >
|
||||||
|
{
|
||||||
|
typedef Piecewise_set_ Piecewise_set ;
|
||||||
|
typedef Draw_piece_ Draw_piece ;
|
||||||
|
|
||||||
|
typedef typename CGALi::Piecewise_set_traits<Piecewise_set_>::Region Region ;
|
||||||
|
|
||||||
|
typedef Piecewise_region_graphics_item<Region, Draw_piece> Base ;
|
||||||
|
|
||||||
|
typedef std::vector<Region> 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 <class S, class D>
|
||||||
|
void Piecewise_set_graphics_item<S,D>::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 <class S, class D>
|
||||||
|
void Piecewise_set_graphics_item<S,D>::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
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (c) 2005 Tel-Aviv University (Israel).
|
// Copyright (c) 2009 GeometryFactory Sarl (France).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// This file is part of CGAL (www.cgal.org); you may redistribute it under
|
// 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 $
|
// $Id: typedefs.h 37003 2007-03-10 16:55:12Z spion $
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Author(s) : Baruch Zukerman <baruchzu@post.tau.ac.il>
|
// Author(s) : Fernando Cacciola <fernando.cacciola@geometryfactory.com>
|
||||||
//
|
//
|
||||||
#ifndef CGAL_TYPEDEFS_H
|
#ifndef CGAL_TYPEDEFS_H
|
||||||
#define 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> Circular_polygon_with_holes;
|
typedef CGAL::General_polygon_with_holes_2<Circular_polygon> Circular_polygon_with_holes;
|
||||||
typedef CGAL::General_polygon_set_2<Circular_traits> Circular_polygon_set;
|
typedef CGAL::General_polygon_set_2<Circular_traits> 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
|
struct Draw_circular_X_monotone_cuve
|
||||||
{
|
{
|
||||||
template<class Path, class Converter>
|
template<class Path, class Converter>
|
||||||
|
|
@ -79,7 +71,7 @@ struct Draw_circular_X_monotone_cuve
|
||||||
aPath->lineTo( aConvert( lT ) ) ;
|
aPath->lineTo( aConvert( lT ) ) ;
|
||||||
}
|
}
|
||||||
} ;
|
} ;
|
||||||
typedef CGAL::Qt::GeneralPolygonSetGraphicsItem<Circular_polygon_set,Compute_circular_X_monotone_cuve_bbox,Draw_circular_X_monotone_cuve> Circular_GI;
|
typedef CGAL::Qt::Piecewise_set_graphics_item<Circular_polygon_set,Draw_circular_X_monotone_cuve> 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<Linear_point> 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
|
struct Draw_bezier_X_monotone_cuve
|
||||||
{
|
{
|
||||||
template<class Path, class Converter>
|
template<class Path, class Converter>
|
||||||
|
|
@ -269,7 +247,7 @@ struct Draw_bezier_X_monotone_cuve
|
||||||
}
|
}
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
typedef CGAL::Qt::GeneralPolygonSetGraphicsItem<Bezier_polygon_set,Compute_bezier_X_monotone_cuve_bbox,Draw_bezier_X_monotone_cuve> Bezier_GI;
|
typedef CGAL::Qt::Piecewise_set_graphics_item<Bezier_polygon_set,Draw_bezier_X_monotone_cuve> Bezier_GI;
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue