From a84a2eea083a241385f7644db8c187226b87e27c Mon Sep 17 00:00:00 2001 From: Mostafa-ashraf19 Date: Sat, 24 Sep 2022 03:33:46 +0200 Subject: [PATCH] Applied new APIs version on Straight polygon 2. --- Polygon/include/CGAL/draw_polygon_2.h | 127 ++++++++++---------------- 1 file changed, 48 insertions(+), 79 deletions(-) diff --git a/Polygon/include/CGAL/draw_polygon_2.h b/Polygon/include/CGAL/draw_polygon_2.h index 1ab6ea14267..5173a7d5bb1 100644 --- a/Polygon/include/CGAL/draw_polygon_2.h +++ b/Polygon/include/CGAL/draw_polygon_2.h @@ -13,10 +13,13 @@ // // // Author(s) : Guillaume Damiand +// Mostafa Ashraf #ifndef CGAL_DRAW_POLYGON_2_H #define CGAL_DRAW_POLYGON_2_H +#include +#include #include #ifdef DOXYGEN_RUNNING @@ -39,99 +42,65 @@ void draw(const P& ap); #endif #ifdef CGAL_USE_BASIC_VIEWER -#include + #include +#include #include -namespace CGAL -{ +namespace CGAL { + +namespace draw_function_for_p2 { + +template +void compute_elements(CGAL::GraphicBuffer &graphic_buffer, + const P2 *p2) { -// Viewer class for Polygon_2 -template -class SimplePolygon2ViewerQt : public Basic_viewer_qt -{ - typedef Basic_viewer_qt Base; typedef typename P2::Point_2 Point; -public: - /// Construct the viewer. - /// @param ap2 the polygon to view - /// @param title the title of the window - SimplePolygon2ViewerQt(QWidget* parent, const P2& ap2, - const char* title="Basic Polygon_2 Viewer") : - // First draw: vertices; edges, faces; multi-color; no inverse normal - Base(parent, title, true, true, true, false, false), - p2(ap2) - { - compute_elements(); + if (p2->is_empty()) + return; + + Point prev = p2->vertex(p2->size() - 1); + + CGAL::IO::Color c(75, 160, 255); + graphic_buffer.face_begin(c); + + for (typename P2::Vertex_const_iterator i = p2->vertices_begin(); + i != p2->vertices_end(); ++i) { + graphic_buffer.add_point(*i); // Add vertex + graphic_buffer.add_segment(prev, *i); // Add segment with previous point + graphic_buffer.add_point_in_face(*i); // Add point in face + prev = *i; } -protected: - void compute_elements() - { - clear(); + graphic_buffer.face_end(); +} - if (p2.is_empty()) return; +} // namespace draw_function_for_p2 - Point prev=p2.vertex(p2.size()-1); - - CGAL::IO::Color c(75,160,255); - face_begin(c); - - for (typename P2::Vertex_const_iterator i=p2.vertices_begin(); - i!=p2.vertices_end(); ++i) - { - add_point(*i); // Add vertex - add_segment(prev, *i); // Add segment with previous point - add_point_in_face(*i); // Add point in face - prev=*i; - } - - face_end(); +template +void add_in_graphic_buffer_p2(CGAL::GraphicBuffer &graphic_buffer, + const P2 *p2 = nullptr) { + if (p2 != nullptr) { + draw_function_for_p2::compute_elements(graphic_buffer, p2); } - - virtual void keyPressEvent(QKeyEvent *e) - { - // Test key pressed: - // const ::Qt::KeyboardModifiers modifiers = e->modifiers(); - // if ((e->key()==Qt::Key_PageUp) && (modifiers==Qt::NoButton)) { ... } - - // Call: * compute_elements() if the model changed, followed by - // * redraw() if some viewing parameters changed that implies some - // modifications of the buffers - // (eg. type of normal, color/mono) - // * update() just to update the drawing - - // Call the base method to process others/classicals key - Base::keyPressEvent(e); - } - -protected: - const P2& p2; -}; +} // Specialization of draw function. -template -void draw(const CGAL::Polygon_2& ap2, - const char* title="Polygon_2 Basic Viewer") -{ -#if defined(CGAL_TEST_SUITE) - bool cgal_test_suite=true; -#else - bool cgal_test_suite=qEnvironmentVariableIsSet("CGAL_TEST_SUITE"); -#endif +#define CGAL_P2_TYPE CGAL::Polygon_2 - if (!cgal_test_suite) - { - CGAL::Qt::init_ogl_context(4,3); - int argc=1; - const char* argv[2]={"t2_viewer", nullptr}; - QApplication app(argc,const_cast(argv)); - SimplePolygon2ViewerQt > - mainwindow(app.activeWindow(), ap2, title); - mainwindow.show(); - app.exec(); - } +template +void draw(const CGAL_P2_TYPE &ap2, + const char *title = "Polygon_2 Basic Viewer") { + + // Drawing_functor + // drawingFunctor; + + CGAL::GraphicBuffer buffer; + add_in_graphic_buffer_p2(buffer, &ap2); + draw_buffer(buffer); } } // End namespace CGAL