Prepare to refactor arrangement graphics items.

This commit is contained in:
Alex Tsui 2012-06-22 16:19:35 +00:00
parent 2bbfd7b8a1
commit 0a440bf0f0
12 changed files with 633 additions and 198 deletions

2
.gitattributes vendored
View File

@ -320,10 +320,12 @@ Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementDemoWindow.cpp
Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementDemoWindow.h -text
Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementDemoWindow.qrc -text
Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementDemoWindow.ui -text
Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementGraphicsItem.h -text
Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementSegmentInputCallback.h -text
Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementTypes.h -text
Arrangement_on_surface_2/demo/Arrangement_on_surface_2/Callback.cpp -text
Arrangement_on_surface_2/demo/Arrangement_on_surface_2/Callback.h -text
Arrangement_on_surface_2/demo/Arrangement_on_surface_2/CurveGraphicsItem.h -text
Arrangement_on_surface_2/demo/Arrangement_on_surface_2/DeleteCurveCallback.h -text
Arrangement_on_surface_2/demo/Arrangement_on_surface_2/EnvelopeCallback.cpp -text
Arrangement_on_surface_2/demo/Arrangement_on_surface_2/EnvelopeCallback.h -text

View File

@ -3,7 +3,7 @@
#include <QWidget>
#include <QGridLayout>
#include <CGAL/Qt/ArrangementGraphicsItem.h>
#include "ArrangementGraphicsItem.h"
#include "ArrangementDemoGraphicsView.h"
#include "ArrangementSegmentInputCallback.h"
#include "DeleteCurveCallback.h"

View File

@ -2,7 +2,7 @@
#define ARRANGEMENT_DEMO_WINDOW_H
#include <CGAL/Qt/DemosMainWindow.h>
#include "ui_ArrangementDemoWindow.h"
#include <CGAL/Qt/ArrangementGraphicsItem.h>
#include "ArrangementGraphicsItem.h"
#include <CGAL/IO/pixmaps/hand.xpm>
#include "ArrangementTypes.h"
#include "ArrangementSegmentInputCallback.h"

View File

@ -0,0 +1,260 @@
// Copyright (c) 2008 GeometryFactory Sarl (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
// You can redistribute it and/or modify it under the terms of the GNU
// General Public License as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// 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.
#ifndef CGAL_QT_ARRANGEMENT_GRAPHICS_ITEM_H
#define CGAL_QT_ARRANGEMENT_GRAPHICS_ITEM_H
#include <CGAL/Bbox_2.h>
//#include <CGAL/apply_to_range.h>
#include <CGAL/Kernel/global_functions.h> // TODO: should be included in PainterOstream.h
#include <CGAL/Qt/ArrangementPainterOstream.h>
#include <CGAL/Qt/GraphicsItem.h>
#include <CGAL/Qt/Converter.h>
#include <QGraphicsScene>
#include <QPainter>
#include <QStyleOption>
namespace CGAL {
namespace Qt {
class ArrangementGraphicsItemBase : public GraphicsItem
{
};
template <typename TArr >
class ArrangementGraphicsItem : public ArrangementGraphicsItemBase
{
typedef typename TArr::Geometry_traits_2 Traits;
typedef typename TArr::Vertex_iterator Vertex_iterator;
typedef typename TArr::Edge_iterator Edge_iterator;
typedef typename Traits::Kernel Kernel;
typedef typename Kernel::Point_2 Point_2;
typedef typename Kernel::Segment_2 Segment_2;
public:
ArrangementGraphicsItem(TArr* t_);
void modelChanged();
public:
// QGraphicsItem overrides
QRectF boundingRect() const;
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
const QPen& getVerticesPen() const
{
return this->verticesPen;
}
const QPen& getEdgesPen() const
{
return this->edgesPen;
}
void setVerticesPen(const QPen& pen)
{
this->verticesPen = pen;
}
void setEdgesPen(const QPen& pen)
{
this->edgesPen = pen;
}
bool visibleVertices() const
{
return this->visible_vertices;
}
void setVisibleVertices(const bool b)
{
this->visible_vertices = b;
this->update();
}
bool visibleEdges() const
{
return this->visible_edges;
}
void setVisibleEdges(const bool b)
{
this->visible_edges = b;
this->update();
}
protected:
void updateBoundingBox();
TArr* arr;
QPainter* m_painter;
ArrangementPainterOstream< Kernel > painterostream;
//typename Traits::Point_2 p;
CGAL::Bbox_2 bb;
bool bb_initialized;
QRectF bounding_rect;
QPen verticesPen;
QPen edgesPen;
bool visible_edges;
bool visible_vertices;
CGAL::Qt::Converter< Traits > convert;
};
template < typename TArr >
ArrangementGraphicsItem< TArr >::ArrangementGraphicsItem( TArr * arr_ )
: arr( arr_ ), painterostream( 0 ),
bb( 0, 0, 0, 0 ), bb_initialized( false ),
visible_edges( true ), visible_vertices( true )
{
this->setVerticesPen( QPen( ::Qt::black, 3. ) );
this->setEdgesPen( QPen( ::Qt::black, 1. ) );
if ( this->arr->number_of_vertices() == 0 ) {
this->hide( );
}
//this->updateBoundingBox( );
this->setZValue( 3 );
}
template <typename TArr>
QRectF
ArrangementGraphicsItem< TArr >::boundingRect() const
{
QRectF rect = this->convert( this->bb );
return rect;
}
template <typename TArr>
void
ArrangementGraphicsItem< TArr >::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget * /*widget*/)
{
//painter->drawRect( this->boundingRect( ) );
painter->setPen( this->verticesPen );
this->painterostream = ArrangementPainterOstream< Kernel >( painter, this->boundingRect( ) );
for ( Vertex_iterator it = this->arr->vertices_begin( ); it != this->arr->vertices_end( ); ++it )
{
this->painterostream << it->point( );
}
painter->setPen( this->edgesPen );
for ( Edge_iterator it = this->arr->edges_begin( ); it != this->arr->edges_end( ); ++it )
{
Point_2 p1 = it->source( )->point( );
Point_2 p2 = it->target( )->point( );
Segment_2 edge( p1, p2 );
this->painterostream << edge;
}
#if 0
painter->setPen(this->edgesPen());
// painter->drawRect(boundingRect());
if ( t->dimension()<2 || option->exposedRect.contains(boundingRect()) ) {
drawAll(painter);
} else {
m_painter = painter;
painterostream = PainterOstream<Traits>(painter);
CGAL::apply_to_range (*t,
typename T::Point(option->exposedRect.left(),
option->exposedRect.bottom()),
typename T::Point(option->exposedRect.right(),
option->exposedRect.top()),
*this);
}
#endif
}
// We let the bounding box only grow, so that when vertices get removed
// the maximal bbox gets refreshed in the GraphicsView
template <typename TArr>
void
ArrangementGraphicsItem< TArr >::updateBoundingBox()
{
this->prepareGeometryChange( );
if ( this->arr->number_of_vertices( ) == 0 )
{
this->bb = Bbox_2( 0, 0, 0, 0 );
this->bb_initialized = false;
return;
}
else
{
this->bb = this->arr->vertices_begin( )->point( ).bbox( );
this->bb_initialized = true;
}
for ( Vertex_iterator it = this->arr->vertices_begin( );
it != this->arr->vertices_end( );
++it )
{
this->bb = this->bb + it->point( ).bbox( );
}
#if 0
prepareGeometryChange();
if(t->number_of_vertices() == 0){
bb = Bbox_2(0,0,0,0);
bb_initialized = false;
return;
} else if(! bb_initialized){
bb = t->finite_vertices_begin()->point().bbox();
bb_initialized = true;
}
if(t->dimension() <2){
for(typename T::Finite_vertices_iterator it = t->finite_vertices_begin();
it != t->finite_vertices_end();
++it){
bb = bb + it->point().bbox();
}
} else {
typename T::Vertex_handle inf = t->infinite_vertex();
typename T::Vertex_circulator vc = t->incident_vertices(inf), done(vc);
do {
bb = bb + vc->point().bbox();
++vc;
} while(vc != done);
}
bounding_rect = QRectF(bb.xmin(),
bb.ymin(),
bb.xmax()-bb.xmin(),
bb.ymax()-bb.ymin());
#endif
}
template <typename TArr>
void
ArrangementGraphicsItem< TArr >::modelChanged()
{
if ( this->arr->is_empty( ) )
{
this->hide( );
}
else
{
this->show( );
}
this->updateBoundingBox();
this->update();
}
} // namespace Qt
} // namespace CGAL
#endif // CGAL_QT_ARRANGEMENT_GRAPHICS_ITEM_H

View File

@ -0,0 +1,132 @@
#ifndef CGAL_QT_CURVE_GRAPHICS_ITEM_H
#define CGAL_QT_CURVE_GRAPHICS_ITEM_H
#include <CGAL/Qt/ArrangementPainterOstream.h>
#include <CGAL/Qt/Converter.h>
#include <CGAL/Qt/GraphicsItem.h>
namespace CGAL {
namespace Qt {
template < class ArrTraits >
class CurveGraphicsItem : public GraphicsItem
{
public:
// known curve types
typedef ArrTraits Traits;
typedef typename Traits::Kernel Kernel;
typedef typename Traits::Curve_2 Curve_2;
typedef typename Traits::X_monotone_curve_2 X_monotone_curve_2;
CurveGraphicsItem( );
virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget );
void updateBoundingBox( );
void insert( const X_monotone_curve_2& curve );
void clear( );
QRectF boundingRect( ) const;
public slots:
void modelChanged( );
protected:
CGAL::Qt::Converter< Kernel > convert;
ArrangementPainterOstream< ArrTraits > painterOstream;
std::vector< X_monotone_curve_2 > curves;
CGAL::Bbox_2 boundingBox;
bool boundingBoxInitialized;
}; // class CurveGraphicsItem
template < class ArrTraits >
CurveGraphicsItem< ArrTraits >::
CurveGraphicsItem( ):
painterOstream( 0 ),
boundingBox( 0, 0, 0, 0 ),
boundingBoxInitialized( false )
{
this->setZValue( 4 );
}
template < class ArrTraits >
void
CurveGraphicsItem< ArrTraits >::
paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget )
{
painter->setPen( QPen( ::Qt::red, 1. ) );
this->painterOstream = ArrangementPainterOstream< ArrTraits >( painter/*, clippingRectangle */ );
for ( int i = 0; i < this->curves.size( ); ++i )
{
X_monotone_curve_2 curve = this->curves[ i ];
this->painterOstream << curve;
}
}
template < class ArrTraits >
void
CurveGraphicsItem< ArrTraits >::
modelChanged( )
{
if ( this->curves.size( ) == 0 )
{
this->hide( );
}
else
{
this->show( );
}
this->updateBoundingBox( );
this->update( );
}
template < class ArrTraits >
void
CurveGraphicsItem< ArrTraits >::
updateBoundingBox( )
{
this->prepareGeometryChange( );
if ( this->curves.size( ) == 0 )
{
this->boundingBox = Bbox_2( 0, 0, 0, 0 );
this->boundingBoxInitialized = false;
return;
}
else
{
this->boundingBox = this->curves[ 0 ].bbox( );
this->boundingBoxInitialized = true;
}
for ( int i = 1; i < this->curves.size( ); ++i )
{
this->boundingBox = this->boundingBox + this->curves[ i ].bbox( );
}
}
template < class ArrTraits >
void
CurveGraphicsItem< ArrTraits >::
insert( const X_monotone_curve_2& segment )
{
this->curves.push_back( segment );
}
template < class ArrTraits >
void
CurveGraphicsItem< ArrTraits >::
clear( )
{
this->curves.clear( );
}
template < class ArrTraits >
QRectF
CurveGraphicsItem< ArrTraits >::
boundingRect( ) const
{
QRectF boundingRectangle = this->convert( this->boundingBox );
return boundingRectangle;
}
} // namespace Qt
} // namespace CGAL
#endif // CGAL_QT_CURVE_GRAPHICS_ITEM_H

View File

@ -5,7 +5,7 @@
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <CGAL/Qt/Converter.h>
#include <CGAL/Qt/CurveGraphicsItem.h>
#include "CurveGraphicsItem.h"
#include <CGAL/Arrangement_with_history_2.h>
#include "Utils.h"

View File

@ -1,7 +1,7 @@
#ifndef ENVELOPE_CALLBACK_H
#define ENVELOPE_CALLBACK_H
#include "Callback.h"
#include <CGAL/Qt/CurveGraphicsItem.h>
#include "CurveGraphicsItem.h"
#include <CGAL/envelope_2.h>
#include <CGAL/Envelope_diagram_1.h>
#include <list>

View File

@ -5,7 +5,7 @@
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <CGAL/Qt/Converter.h>
#include <CGAL/Qt/CurveGraphicsItem.h>
#include "CurveGraphicsItem.h"
#include <CGAL/Arrangement_with_history_2.h>
#include "Utils.h"

View File

@ -6,7 +6,7 @@
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <CGAL/Qt/Converter.h>
#include <CGAL/Qt/CurveGraphicsItem.h>
#include "CurveGraphicsItem.h"
#include <CGAL/Arrangement_with_history_2.h>
#include <CGAL/Arr_trapezoid_ric_point_location.h>
#include <CGAL/Arr_simple_point_location.h>
@ -58,7 +58,6 @@ protected:
CGAL::Object locate( const Point_2& point );
using Callback::scene;
Compute_squared_distance_2< Traits > squaredDistance;
CGAL::Qt::Converter< Kernel > convert;
CGAL::Object pointLocationStrategy;
TArr* arr;

View File

@ -5,7 +5,7 @@
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <CGAL/Qt/Converter.h>
#include <CGAL/Qt/CurveGraphicsItem.h>
#include "CurveGraphicsItem.h"
#include <CGAL/Arrangement_with_history_2.h>
#include "Utils.h"
#include "ISnappable.h"

View File

@ -1,6 +1,7 @@
#ifndef CGAL_ARRANGEMENTS_DEMO_UTILS_H
#define CGAL_ARRANGEMENTS_DEMO_UTILS_H
#include <CGAL/Arr_segment_traits_2.h>
#include <CGAL/Arr_polyline_traits_2.h>
#include <CGAL/iterator.h>
#include <CGAL/Qt/Converter.h>
#include <QGraphicsSceneMouseEvent>
@ -36,9 +37,9 @@ class Compute_squared_distance_2< CGAL::Arr_segment_traits_2< Kernel_ > > :
public Compute_squared_distance_2_base< CGAL::Arr_segment_traits_2< Kernel_ > >
{
public:
typedef CGAL::Arr_segment_traits_2< Kernel_ > Traits;
typedef Compute_squared_distance_2_base< Traits > Superclass;
typedef Kernel_ Kernel;
typedef CGAL::Arr_segment_traits_2< Kernel > Traits;
typedef Compute_squared_distance_2_base< Traits > Superclass;
typedef typename Kernel::FT FT;
typedef typename Kernel::Point_2 Point_2;
typedef typename Kernel::Segment_2 Segment_2;
@ -54,115 +55,157 @@ public:
}
};
template < class Kernel_ >
class Compute_squared_distance_2< CGAL::Arr_polyline_traits_2< Kernel_ > > :
public Compute_squared_distance_2_base< CGAL::Arr_polyline_traits_2< Kernel_ > >
{
public:
typedef Kernel_ Kernel;
typedef CGAL::Arr_polyline_traits_2< Kernel > Traits;
typedef Compute_squared_distance_2_base< Traits > Superclass;
typedef typename Kernel::FT FT;
typedef typename Kernel::Point_2 Point_2;
typedef typename Kernel::Segment_2 Segment_2;
typedef typename Traits::Curve_2 Curve_2;
typedef typename Curve_2::const_iterator Curve_const_iterator;
typedef typename Traits::X_monotone_curve_2 X_monotone_curve_2;
FT operator() ( const Point_2& p, const X_monotone_curve_2& c ) const
{
Curve_const_iterator ps = c.begin();
Curve_const_iterator pt = ps; pt++;
bool first = true;
FT min_dist = 0;
while ( pt != c.end() )
{
const Point_2& source = *ps;
const Point_2& target = *pt;
Segment_2 seg( source, target );
FT dist = this->squared_distance( p, seg );
if ( first || dist < min_dist )
{
first = false;
min_dist = dist;
}
ps++; pt++;
}
return min_dist;
}
};
template < class ArrTraits >
class Construct_x_monotone_subcurve_2
{
public:
typedef typename ArrTraits::Kernel Kernel;
typedef typename ArrTraits::X_monotone_curve_2 X_monotone_curve_2;
typedef typename ArrTraits::Split_2 Split_2;
typedef typename ArrTraits::Intersect_2 Intersect_2;
typedef typename ArrTraits::Multiplicity Multiplicity;
typedef typename ArrTraits::Construct_x_monotone_curve_2 Construct_x_monotone_curve_2;
typedef typename ArrTraits::Construct_min_vertex_2 Construct_min_vertex_2;
typedef typename ArrTraits::Construct_max_vertex_2 Construct_max_vertex_2;
typedef typename ArrTraits::Compare_x_2 Compare_x_2;
typedef typename Kernel::FT FT;
typedef typename Kernel::Point_2 Point_2;
typedef typename Kernel::Line_2 Line_2;
typedef typename Kernel::Compute_y_at_x_2 Compute_y_at_x_2;
public:
typedef typename ArrTraits::Kernel Kernel;
typedef typename ArrTraits::X_monotone_curve_2 X_monotone_curve_2;
typedef typename ArrTraits::Split_2 Split_2;
typedef typename ArrTraits::Intersect_2 Intersect_2;
typedef typename ArrTraits::Multiplicity Multiplicity;
typedef typename ArrTraits::Construct_x_monotone_curve_2 Construct_x_monotone_curve_2;
typedef typename ArrTraits::Construct_min_vertex_2 Construct_min_vertex_2;
typedef typename ArrTraits::Construct_max_vertex_2 Construct_max_vertex_2;
typedef typename ArrTraits::Compare_x_2 Compare_x_2;
typedef typename Kernel::FT FT;
typedef typename Kernel::Point_2 Point_2;
typedef typename Kernel::Line_2 Line_2;
typedef typename Kernel::Compute_y_at_x_2 Compute_y_at_x_2;
/*
Return the subcurve of curve bracketed by pLeft and pRight.
/*
Return the subcurve of curve bracketed by pLeft and pRight.
We assume pLeft and pRight don't lie on the curve and always do a vertical
projection.
*/
X_monotone_curve_2 operator() ( const X_monotone_curve_2& curve, const Point_2& pLeft, const Point_2& pRight )
{
Point_2 pMin = this->construct_min_vertex_2( curve );
Point_2 pMax = this->construct_max_vertex_2( curve );
X_monotone_curve_2 subcurve;
X_monotone_curve_2 unusedTrimmings;
X_monotone_curve_2 finalSubcurve;
if ( this->compare_x_2( pLeft, pMin ) == CGAL::LARGER )
We assume pLeft and pRight don't lie on the curve and always do a vertical
projection.
*/
X_monotone_curve_2 operator() ( const X_monotone_curve_2& curve, const Point_2& pLeft, const Point_2& pRight )
{
// FIXME: handle vertical lines properly
CGAL::Bbox_2 c_bbox = curve.bbox( );
FT splitLineYMin( c_bbox.ymin( ) - 1.0 );
FT splitLineYMax( c_bbox.ymax( ) + 1.0 );
Point_2 splitLinePBottom( pLeft.x( ), splitLineYMin );
Point_2 splitLinePTop( pLeft.x( ), splitLineYMax );
X_monotone_curve_2 splitLine =
this->construct_x_monotone_curve_2( splitLinePBottom, splitLinePTop );
CGAL::Object res;
CGAL::Oneset_iterator< CGAL::Object > oi( res );
this->intersect_2( splitLine, curve, oi );
std::pair< Point_2, Multiplicity > pair;
if ( CGAL::assign( pair, res ) )
Point_2 pMin = this->construct_min_vertex_2( curve );
Point_2 pMax = this->construct_max_vertex_2( curve );
X_monotone_curve_2 subcurve;
X_monotone_curve_2 unusedTrimmings;
X_monotone_curve_2 finalSubcurve;
if ( this->compare_x_2( pLeft, pMin ) == CGAL::LARGER )
{
Point_2 splitPoint = pair.first;
this->split_2( curve, splitPoint, unusedTrimmings, subcurve );
// FIXME: handle vertical lines properly
CGAL::Bbox_2 c_bbox = curve.bbox( );
FT splitLineYMin( c_bbox.ymin( ) - 1.0 );
FT splitLineYMax( c_bbox.ymax( ) + 1.0 );
Point_2 splitLinePBottom( pLeft.x( ), splitLineYMin );
Point_2 splitLinePTop( pLeft.x( ), splitLineYMax );
X_monotone_curve_2 splitLine =
this->construct_x_monotone_curve_2( splitLinePBottom, splitLinePTop );
CGAL::Object res;
CGAL::Oneset_iterator< CGAL::Object > oi( res );
this->intersect_2( splitLine, curve, oi );
std::pair< Point_2, Multiplicity > pair;
if ( CGAL::assign( pair, res ) )
{
Point_2 splitPoint = pair.first;
this->split_2( curve, splitPoint, unusedTrimmings, subcurve );
}
}
}
else
{
subcurve = curve;
}
if ( this->compare_x_2( pRight, pMax ) == CGAL::SMALLER )
{
CGAL::Bbox_2 c_bbox = subcurve.bbox( );
FT splitLineYMin( c_bbox.ymin( ) - 1.0 );
FT splitLineYMax( c_bbox.ymax( ) + 1.0 );
Point_2 splitLinePBottom( pRight.x( ), splitLineYMin );
Point_2 splitLinePTop( pRight.x( ), splitLineYMax );
X_monotone_curve_2 splitLine =
this->construct_x_monotone_curve_2( splitLinePBottom, splitLinePTop );
CGAL::Object res;
CGAL::Oneset_iterator< CGAL::Object > oi( res );
this->intersect_2( splitLine, subcurve, oi );
std::pair< Point_2, Multiplicity > pair;
if ( CGAL::assign( pair, res ) )
else
{
Point_2 splitPoint = pair.first;
//return X_monotone_curve_2( splitLinePBottom, splitPoint );
this->split_2( subcurve, splitPoint, finalSubcurve, unusedTrimmings );
subcurve = curve;
}
}
else
{
finalSubcurve = subcurve;
if ( this->compare_x_2( pRight, pMax ) == CGAL::SMALLER )
{
CGAL::Bbox_2 c_bbox = subcurve.bbox( );
FT splitLineYMin( c_bbox.ymin( ) - 1.0 );
FT splitLineYMax( c_bbox.ymax( ) + 1.0 );
Point_2 splitLinePBottom( pRight.x( ), splitLineYMin );
Point_2 splitLinePTop( pRight.x( ), splitLineYMax );
X_monotone_curve_2 splitLine =
this->construct_x_monotone_curve_2( splitLinePBottom, splitLinePTop );
CGAL::Object res;
CGAL::Oneset_iterator< CGAL::Object > oi( res );
this->intersect_2( splitLine, subcurve, oi );
std::pair< Point_2, Multiplicity > pair;
if ( CGAL::assign( pair, res ) )
{
Point_2 splitPoint = pair.first;
//return X_monotone_curve_2( splitLinePBottom, splitPoint );
this->split_2( subcurve, splitPoint, finalSubcurve, unusedTrimmings );
}
}
else
{
finalSubcurve = subcurve;
}
return finalSubcurve;
}
return finalSubcurve;
}
protected:
protected:
Intersect_2 intersect_2;
Split_2 split_2;
Compare_x_2 compare_x_2;
Construct_x_monotone_curve_2 construct_x_monotone_curve_2;
Construct_min_vertex_2 construct_min_vertex_2;
Construct_max_vertex_2 construct_max_vertex_2;
Intersect_2 intersect_2;
Split_2 split_2;
Compare_x_2 compare_x_2;
Construct_x_monotone_curve_2 construct_x_monotone_curve_2;
Construct_min_vertex_2 construct_min_vertex_2;
Construct_max_vertex_2 construct_max_vertex_2;
};
template < class K_ >
class SnapStrategy
{
public:
typedef K_ Kernel;
typedef typename Kernel::Point_2 Point_2;
public:
typedef K_ Kernel;
typedef typename Kernel::Point_2 Point_2;
virtual Point_2 snapPoint( QGraphicsSceneMouseEvent* event ) = 0;
void setScene( QGraphicsScene* scene_ );
virtual Point_2 snapPoint( QGraphicsSceneMouseEvent* event ) = 0;
void setScene( QGraphicsScene* scene_ );
protected:
SnapStrategy( QGraphicsScene* scene_ );
QRectF viewportRect( ) const;
protected:
SnapStrategy( QGraphicsScene* scene_ );
QRectF viewportRect( ) const;
QGraphicsScene* scene;
QGraphicsScene* scene;
}; // class SnapStrategy
template < class K_ >
@ -207,134 +250,134 @@ setScene( QGraphicsScene* scene_ )
template < class K_ >
class SnapToGridStrategy : public SnapStrategy< K_ >
{
public:
typedef K_ Kernel;
typedef typename Kernel::Point_2 Point_2;
typedef SnapStrategy< Kernel > Superclass;
public:
typedef K_ Kernel;
typedef typename Kernel::Point_2 Point_2;
typedef SnapStrategy< Kernel > Superclass;
SnapToGridStrategy( ):
Superclass( NULL ),
gridSize( 50 )
SnapToGridStrategy( ):
Superclass( NULL ),
gridSize( 50 )
{ }
SnapToGridStrategy( QGraphicsScene* scene ):
Superclass( scene ),
gridSize( 50 )
SnapToGridStrategy( QGraphicsScene* scene ):
Superclass( scene ),
gridSize( 50 )
{ }
Point_2 snapPoint( QGraphicsSceneMouseEvent* event )
{
QPointF clickedPoint = event->scenePos( );
QRectF viewportRect = this->viewportRect( );
if ( viewportRect == QRectF( ) )
Point_2 snapPoint( QGraphicsSceneMouseEvent* event )
{
return this->convert( event->scenePos( ) );
}
qreal d( this->gridSize / 2.0 );
int left = int( viewportRect.left( ) ) - (int( viewportRect.left( ) ) % this->gridSize);
int right = int( viewportRect.right( ) ) + (this->gridSize - int( viewportRect.right( ) ) % this->gridSize);
int x = clickedPoint.x( );
int y = clickedPoint.y( );
for ( int i = left - this->gridSize; i <= right; i += this->gridSize )
{
if ( i - d <= clickedPoint.x( ) && clickedPoint.x( ) <= i + d )
QPointF clickedPoint = event->scenePos( );
QRectF viewportRect = this->viewportRect( );
if ( viewportRect == QRectF( ) )
{
x = i;
break;
return this->convert( event->scenePos( ) );
}
}
int top = int( viewportRect.top( ) ) - (int( viewportRect.top( ) ) % this->gridSize);
int bottom = int( viewportRect.bottom( ) ) + (this->gridSize - int( viewportRect.bottom( ) ) % this->gridSize);
for ( int i = top - this->gridSize; i <= bottom; i += this->gridSize )
{
if ( i - d <= clickedPoint.y( ) && clickedPoint.y( ) <= i + d )
qreal d( this->gridSize / 2.0 );
int left = int( viewportRect.left( ) ) - (int( viewportRect.left( ) ) % this->gridSize);
int right = int( viewportRect.right( ) ) + (this->gridSize - int( viewportRect.right( ) ) % this->gridSize);
int x = clickedPoint.x( );
int y = clickedPoint.y( );
for ( int i = left - this->gridSize; i <= right; i += this->gridSize )
{
y = i;
break;
if ( i - d <= clickedPoint.x( ) && clickedPoint.x( ) <= i + d )
{
x = i;
break;
}
}
int top = int( viewportRect.top( ) ) - (int( viewportRect.top( ) ) % this->gridSize);
int bottom = int( viewportRect.bottom( ) ) + (this->gridSize - int( viewportRect.bottom( ) ) % this->gridSize);
for ( int i = top - this->gridSize; i <= bottom; i += this->gridSize )
{
if ( i - d <= clickedPoint.y( ) && clickedPoint.y( ) <= i + d )
{
y = i;
break;
}
}
return this->convert( QPointF( x, y ) );
}
return this->convert( QPointF( x, y ) );
}
void setGridSize( int size )
{
this->gridSize = size;
}
void setGridSize( int size )
{
this->gridSize = size;
}
protected:
int gridSize;
CGAL::Qt::Converter< Kernel > convert;
protected:
int gridSize;
CGAL::Qt::Converter< Kernel > convert;
}; // class SnapToGridStrategy
template < class Arr_ >
class SnapToArrangementVertexStrategy:
public SnapStrategy< typename Arr_::Geometry_traits_2::Kernel >
{
public:
typedef Arr_ Arrangement;
typedef typename Arrangement::Geometry_traits_2 Traits;
typedef typename Traits::Kernel Kernel;
typedef SnapStrategy< Kernel > Superclass;
typedef typename Arrangement::Vertex_iterator Vertex_iterator;
typedef typename Kernel::Compute_squared_distance_2 Compute_squared_distance_2;
typedef typename Kernel::FT FT;
typedef typename Kernel::Point_2 Point_2;
public:
typedef Arr_ Arrangement;
typedef typename Arrangement::Geometry_traits_2 Traits;
typedef typename Traits::Kernel Kernel;
typedef SnapStrategy< Kernel > Superclass;
typedef typename Arrangement::Vertex_iterator Vertex_iterator;
typedef typename Kernel::Compute_squared_distance_2 Compute_squared_distance_2;
typedef typename Kernel::FT FT;
typedef typename Kernel::Point_2 Point_2;
SnapToArrangementVertexStrategy( ):
Superclass( NULL ),
arrangement( NULL )
SnapToArrangementVertexStrategy( ):
Superclass( NULL ),
arrangement( NULL )
{ }
SnapToArrangementVertexStrategy( Arrangement* arr, QGraphicsScene* scene_ ):
Superclass( scene_ ),
arrangement( arr )
SnapToArrangementVertexStrategy( Arrangement* arr, QGraphicsScene* scene_ ):
Superclass( scene_ ),
arrangement( arr )
{ }
Point_2 snapPoint( QGraphicsSceneMouseEvent* event )
{
Point_2 clickedPoint = this->convert( event->scenePos( ) );
Point_2 closestPoint = clickedPoint;
bool first = true;
FT minDist( 0 );
QRectF viewportRect = this->viewportRect( );
if ( viewportRect == QRectF( ) )
Point_2 snapPoint( QGraphicsSceneMouseEvent* event )
{
return this->convert( event->scenePos( ) );
}
FT maxDist( ( viewportRect.right( ) - viewportRect.left( ) ) / 4.0 );
for ( Vertex_iterator vit = this->arrangement->vertices_begin( );
vit != this->arrangement->vertices_end( ); ++vit )
{
Point_2 point = vit->point( );
FT dist = this->compute_squared_distance_2( clickedPoint, point );
if ( first || ( dist < minDist ) )
Point_2 clickedPoint = this->convert( event->scenePos( ) );
Point_2 closestPoint = clickedPoint;
bool first = true;
FT minDist( 0 );
QRectF viewportRect = this->viewportRect( );
if ( viewportRect == QRectF( ) )
{
first = false;
minDist = dist;
closestPoint = point;
return this->convert( event->scenePos( ) );
}
FT maxDist( ( viewportRect.right( ) - viewportRect.left( ) ) / 4.0 );
for ( Vertex_iterator vit = this->arrangement->vertices_begin( );
vit != this->arrangement->vertices_end( ); ++vit )
{
Point_2 point = vit->point( );
FT dist = this->compute_squared_distance_2( clickedPoint, point );
if ( first || ( dist < minDist ) )
{
first = false;
minDist = dist;
closestPoint = point;
}
}
if ( ! first && minDist < maxDist )
{
return closestPoint;
}
else
{
return this->convert( event->scenePos( ) );
}
}
if ( ! first && minDist < maxDist )
{
return closestPoint;
}
else
{
return this->convert( event->scenePos( ) );
}
}
void setArrangement( Arrangement* arr )
{
this->arrangement = arr;
}
void setArrangement( Arrangement* arr )
{
this->arrangement = arr;
}
protected:
Arrangement* arrangement;
Compute_squared_distance_2 compute_squared_distance_2;
CGAL::Qt::Converter< Kernel > convert;
protected:
Arrangement* arrangement;
Compute_squared_distance_2 compute_squared_distance_2;
CGAL::Qt::Converter< Kernel > convert;
}; // class SnapToArrangementVertexStrategy
#endif // CGAL_ARRANGEMENTS_DEMO_UTILS_H

View File

@ -7,7 +7,7 @@
#include <QGraphicsView>
#include <QGraphicsSceneMouseEvent>
#include <CGAL/Qt/Converter.h>
#include <CGAL/Qt/CurveGraphicsItem.h>
#include "CurveGraphicsItem.h"
#include <CGAL/Arrangement_with_history_2.h>
#include <CGAL/Arr_trapezoid_ric_point_location.h>
#include <CGAL/Arr_simple_point_location.h>
@ -80,7 +80,6 @@ protected:
using Superclass::scene;
using Superclass::shootingUp;
TArr* arr;
Compute_squared_distance_2< Traits > squaredDistance;
Construct_x_monotone_curve_2 construct_x_monotone_curve_2;
Intersect_2 intersectCurves;
CGAL::Qt::Converter< Kernel > convert;