Entering circular polygons being added

This commit is contained in:
Fernando Cacciola 2010-01-27 17:09:17 +00:00
parent 15382fb248
commit b58ebd3f74
4 changed files with 144 additions and 94 deletions

View File

@ -84,7 +84,7 @@ void trace( std::string s )
#include <CGAL/Qt/BezierCurves.h>
#include <CGAL/Qt/CircularPolygons.h>
#include <CGAL/Qt/GraphicsViewBezierPolygonInput.h>
#include <CGAL/Qt/GraphicsViewGpsCircleSegmentInput.h>
#include <CGAL/Qt/GraphicsViewCircularPolygonInput.h>
//#include <CGAL/Qt/GraphicsViewGpsCircleInput.h>
#include <CGAL/Qt/Converter.h>
#include <CGAL/Qt/DemosMainWindow.h>
@ -442,16 +442,17 @@ class MainWindow :
private:
QGraphicsScene mScene;
bool mCircular_active ;
bool mBlue_active ;
Curve_set_container mCurve_sets ;
Circular_region_source_container mBlue_circular_sources ;
Circular_region_source_container mRed_circular_sources ;
Bezier_region_source_container mBlue_bezier_sources ;
Bezier_region_source_container mRed_bezier_sources ;
CGAL::Qt::GraphicsViewBezierPolygonInput<Bezier_traits>* mBezierInput ;
CGAL::Qt::GraphicsViewGpsCircleSegmentInput<Circular_curve>* mCircularInput ;
QGraphicsScene mScene;
bool mCircular_active ;
bool mBlue_active ;
Curve_set_container mCurve_sets ;
Circular_region_source_container mBlue_circular_sources ;
Circular_region_source_container mRed_circular_sources ;
Bezier_region_source_container mBlue_bezier_sources ;
Bezier_region_source_container mRed_bezier_sources ;
CGAL::Qt::GraphicsViewBezierPolygonInput<Bezier_traits>* mBezierInput ;
CGAL::Qt::GraphicsViewCircularPolygonInput<Gps_circular_kernel>* mCircularInput ;
//CGAL::Qt::GraphicsViewGpsCircleSegmentInput<Circular_curve>* mCircularInput ;
//CGAL::Qt::GraphicsViewGpsCircleInput<Circular_traits>* mCircleInput ;
public:
@ -624,8 +625,8 @@ MainWindow::MainWindow()
this->addRecentFiles(this->menuFile, this->actionQuit);
mBezierInput = new CGAL::Qt::GraphicsViewBezierPolygonInput<Bezier_traits> (this, &mScene);
mCircularInput = new CGAL::Qt::GraphicsViewGpsCircleSegmentInput <Circular_curve>(this, &mScene);
mBezierInput = new CGAL::Qt::GraphicsViewBezierPolygonInput <Bezier_traits> (this, &mScene);
mCircularInput = new CGAL::Qt::GraphicsViewCircularPolygonInput<Gps_circular_kernel>(this, &mScene);
//mCircleInput = new CGAL::Qt::GraphicsViewCircleInput <Circular_traits>(this, &mScene);
QObject::connect(mBezierInput , SIGNAL(generate(CGAL::Object)), this, SLOT(processInput(CGAL::Object)));
@ -682,7 +683,7 @@ void MainWindow::dropEvent(QDropEvent *event)
Circular_polygon linear_2_circ( Linear_polygon const& pgn )
{
CGAL::Cartesian_converter<Linear_kernel,Circular_kernel> convert ;
CGAL::Cartesian_converter<Linear_kernel,Gps_circular_kernel> convert ;
Circular_polygon rCP;
@ -753,7 +754,7 @@ bool read_dxf ( QString aFileName, Circular_polygon_set& rSet, Circular_region_s
if ( in_file )
{
CGAL::Dxf_bsop_reader<Circular_kernel> reader;
CGAL::Dxf_bsop_reader<Gps_circular_kernel> reader;
std::vector<Circular_polygon> circ_polygons;
std::vector<Circular_polygon_with_holes> circ_polygons_with_holes;

View File

@ -25,7 +25,7 @@
#include <CGAL/Qt/BoundaryPiecesGraphicsItem.h>
#include <CGAL/Qt/Converter.h>
#define USE_CLIPPING
//#define USE_CLIPPING
namespace CGAL {

View File

@ -35,7 +35,6 @@ struct Circular_X_monotone_bbox
}
} ;
#if 0
struct Circular_bbox
{
template<class Circle_segment_2>
@ -67,9 +66,6 @@ struct Circular_bbox
}
} ;
#endif
struct Draw_circular_X_monotone_curve
{
template<class X_monotone_circle_segment_2, class Path>
@ -157,8 +153,7 @@ struct Draw_circular_X_monotone_curve
}
} ;
#if 0
struct Draw_circular_curve
{
template<class Circle_segment_2, class Path>
@ -174,75 +169,56 @@ struct Draw_circular_curve
if ( curve.is_circular() )
{
typename X_monotone_circle_segment_2::Circle_2 const& circ = curve.supporting_circle();
typename X_monotone_circle_segment_2::Kernel::Point_2 const& center = circ.center();
if ( curve.is_full() )
typename Circle_segment_2::Circle_2 const& circ = curve.supporting_circle();
typename Circle_segment_2::Kernel::Point_2 const& center = circ.center();
typename Circle_segment_2::Point_2 const& source = curve.source();
typename Circle_segment_2::Point_2 const& target = curve.target();
double sx = to_double(source.x());
double sy = to_double(source.y());
double tx = to_double(target.x());
double ty = to_double(target.y());
double cx = to_double(center.x());
double cy = to_double(center.y());
bool degenerate = ( sx == tx ) && ( sy == ty ) ;
if ( !degenerate )
{
double cx = to_double(center.x());
double cy = to_double(center.y());
double rad = std::sqrt( to_double(circ.squared_radius() ) ;
double sdy = sy - cy ;
double sdx = sx - cx ;
double tdy = ty - cy ;
double tdx = tx - cx ;
double asource = std::atan2(sdy, sdx );
double atarget = std::atan2(tdy, tdx );
if( asource < 0.0)
asource += 2 * CGAL_PI;
if( atarget <= 0.0)
atarget += 2 * CGAL_PI;
if ( atarget < asource )
atarget += 2 * CGAL_PI;
double aspan = atarget - asource ;
const double to_deg = 180.0/CGAL_PI;
Orientation lO = curve.orientation() ;
if ( aIdx == 0 )
aPath.moveTo(cx+rad,cy) ;
else aPath.lineTo(cx+rad,cy) ;
aPath.moveTo(sx,sy) ;
else aPath.lineTo(sx,sy) ;
QRectF bbox = convert(circ.bbox()) ;
aPath.arcTo(bbox , 0, 360 );
}
else
{
typename X_monotone_circle_segment_2::Point_2 const& source = curve.source();
typename X_monotone_circle_segment_2::Point_2 const& target = curve.target();
double sx = to_double(source.x());
double sy = to_double(source.y());
double tx = to_double(target.x());
double ty = to_double(target.y());
double cx = to_double(center.x());
double cy = to_double(center.y());
double dasource = std::atan2(-sdy, sdx ) * to_deg ;
bool degenerate = ( sx == tx ) && ( sy == ty ) ;
double daspan = aspan * to_deg * ( lO == COUNTERCLOCKWISE ? -1.0 : +1.0) ;
if ( !degenerate )
{
double sdy = sy - cy ;
double sdx = sx - cx ;
double tdy = ty - cy ;
double tdx = tx - cx ;
double asource = std::atan2(sdy, sdx );
double atarget = std::atan2(tdy, tdx );
if( asource < 0.0)
asource += 2 * CGAL_PI;
if( atarget <= 0.0)
atarget += 2 * CGAL_PI;
if ( atarget < asource )
atarget += 2 * CGAL_PI;
double aspan = atarget - asource ;
const double to_deg = 180.0/CGAL_PI;
Orientation lO = curve.orientation() ;
if ( aIdx == 0 )
aPath.moveTo(sx,sy) ;
else aPath.lineTo(sx,sy) ;
QRectF bbox = convert(circ.bbox()) ;
double dasource = std::atan2(-sdy, sdx ) * to_deg ;
double daspan = aspan * to_deg * ( lO == COUNTERCLOCKWISE ? -1.0 : +1.0) ;
aPath.arcTo(bbox , dasource, daspan );
}
aPath.arcTo(bbox , dasource, daspan );
}
}
else
@ -256,12 +232,85 @@ struct Draw_circular_curve
aPath.lineTo( convert( lT ) ) ;
}
}
} ;
/*
struct Draw_circular_curve
{
template<class Circle_segment_2, class Path>
void operator()( Circle_segment_2 const& curve, Path& aPath, int aIdx ) const
{
if ( !cs_.is_full() )
{
double sx = to_double(cs_.source().x());
double sy = to_double(cs_.source().y());
double tx = to_double(cs_.target().x());
double ty = to_double(cs_.target().y());
if( cs_.orientation() == COLLINEAR)
{
painter->drawLine(sx,sy,tx,ty);
}
else
{
double cx = to_double(cs_.supporting_circle().center().x());
double cy = to_double(cs_.supporting_circle().center().y());
double x0, y0, x1, y1 ;
if(cs_.orientation() == CLOCKWISE)
{
x0 = sx ;
y0 = sy ;
x1 = tx ;
y1 = ty ;
}
else
{
x0 = tx ;
y0 = ty ;
x1 = sx ;
y1 = sy ;
}
double rad = std::sqrt(CGAL::to_double(cs_.supporting_circle().squared_radius()));
double a = std::atan2( y0 - cy, x0 - cx ) ;
double a2p = std::atan2( y1 - cy, x1 - cx );
if (a2p <= a)
a2p += 2 * CGAL_PI;
double alen2 = a2p - a;
double to_deg = 180 / CGAL_PI ;
painter->drawArc(cx - rad, cy - rad, 2 * rad, 2 * rad, - a * to_deg * 16, - alen2 * to_deg * 16 );
}
}
else
{
if( cs_.orientation() != COLLINEAR)
{
double cx = to_double(cs_.supporting_circle().center().x());
double cy = to_double(cs_.supporting_circle().center().y());
double rad = std::sqrt(CGAL::to_double(cs_.supporting_circle().squared_radius()));
painter->drawArc(cx -rad, cy - rad, 2 * rad, 2 * rad, 0, 360*16);
}
}
}
} ;
*/
#endif
template<class Circular_boundary_pieces>
class Circular_boundary_pieces_graphics_item : public Boundary_pieces_graphics_item<Circular_boundary_pieces,Draw_circular_curve,Circular_bbox>
{
typedef Boundary_pieces_graphics_item<Circular_boundary_pieces,Draw_circular_curve,Circular_bbox> Base ;
public :
Circular_boundary_pieces_graphics_item( Circular_boundary_pieces* aPieces ) : Base(aPieces) {}
} ;
template<class Circular_boundary>
class Circular_boundary_graphics_item : public Piecewise_boundary_graphics_item<Circular_boundary,Draw_circular_X_monotone_curve,Circular_X_monotone_bbox>

View File

@ -46,15 +46,15 @@ typedef Linear_kernel::Point_2 Linear_point ;
typedef CGAL::Lazy_exact_nt<Base_nt> Coord_type;
struct Circular_kernel : public CGAL::Cartesian<Coord_type> {};
struct Gps_circular_kernel : public CGAL::Cartesian<Coord_type> {};
typedef CGAL::Gps_circle_segment_traits_2<Circular_kernel> Circular_traits;
typedef Circular_traits::Curve_2 Circular_curve;
typedef Circular_traits::X_monotone_curve_2 Circular_X_monotone_curve;
typedef Circular_traits::Point_2 Circular_point ;
typedef Circular_traits::Polygon_2 Circular_polygon;
typedef CGAL::General_polygon_with_holes_2<Circular_polygon> Circular_polygon_with_holes;
typedef CGAL::General_polygon_set_2<Circular_traits> Circular_polygon_set;
typedef CGAL::Gps_circle_segment_traits_2<Gps_circular_kernel> Circular_traits;
typedef Circular_traits::Curve_2 Circular_curve;
typedef Circular_traits::X_monotone_curve_2 Circular_X_monotone_curve;
typedef Circular_traits::Point_2 Circular_point ;
typedef Circular_traits::Polygon_2 Circular_polygon;
typedef CGAL::General_polygon_with_holes_2<Circular_polygon> Circular_polygon_with_holes;
typedef CGAL::General_polygon_set_2<Circular_traits> Circular_polygon_set;
typedef CGAL::Qt::Circular_set_graphics_item<Circular_polygon_set> Circular_GI;