Applied new APIs version on Straight polygon 2.

This commit is contained in:
Mostafa-ashraf19 2022-09-24 03:33:46 +02:00
parent fcdad212b5
commit a84a2eea08
1 changed files with 48 additions and 79 deletions

View File

@ -13,10 +13,13 @@
// //
// //
// Author(s) : Guillaume Damiand <guillaume.damiand@liris.cnrs.fr> // Author(s) : Guillaume Damiand <guillaume.damiand@liris.cnrs.fr>
// Mostafa Ashraf <mostaphaashraf1996@gmail.com>
#ifndef CGAL_DRAW_POLYGON_2_H #ifndef CGAL_DRAW_POLYGON_2_H
#define CGAL_DRAW_POLYGON_2_H #define CGAL_DRAW_POLYGON_2_H
#include <CGAL/Drawing_functor.h>
#include <CGAL/Graphic_buffer.h>
#include <CGAL/Qt/Basic_viewer_qt.h> #include <CGAL/Qt/Basic_viewer_qt.h>
#ifdef DOXYGEN_RUNNING #ifdef DOXYGEN_RUNNING
@ -39,99 +42,65 @@ void draw(const P& ap);
#endif #endif
#ifdef CGAL_USE_BASIC_VIEWER #ifdef CGAL_USE_BASIC_VIEWER
#include <CGAL/Qt/init_ogl_context.h>
#include <CGAL/Polygon_2.h> #include <CGAL/Polygon_2.h>
#include <CGAL/Qt/init_ogl_context.h>
#include <CGAL/Random.h> #include <CGAL/Random.h>
namespace CGAL namespace CGAL {
{
namespace draw_function_for_p2 {
template <typename BufferType = float, class P2>
void compute_elements(CGAL::GraphicBuffer<BufferType> &graphic_buffer,
const P2 *p2) {
// Viewer class for Polygon_2
template<class P2>
class SimplePolygon2ViewerQt : public Basic_viewer_qt
{
typedef Basic_viewer_qt Base;
typedef typename P2::Point_2 Point; typedef typename P2::Point_2 Point;
public: if (p2->is_empty())
/// Construct the viewer. return;
/// @param ap2 the polygon to view
/// @param title the title of the window Point prev = p2->vertex(p2->size() - 1);
SimplePolygon2ViewerQt(QWidget* parent, const P2& ap2,
const char* title="Basic Polygon_2 Viewer") : CGAL::IO::Color c(75, 160, 255);
// First draw: vertices; edges, faces; multi-color; no inverse normal graphic_buffer.face_begin(c);
Base(parent, title, true, true, true, false, false),
p2(ap2) for (typename P2::Vertex_const_iterator i = p2->vertices_begin();
{ i != p2->vertices_end(); ++i) {
compute_elements(); 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: graphic_buffer.face_end();
void compute_elements() }
{
clear();
if (p2.is_empty()) return; } // namespace draw_function_for_p2
Point prev=p2.vertex(p2.size()-1); template <typename BufferType = float, class P2>
void add_in_graphic_buffer_p2(CGAL::GraphicBuffer<BufferType> &graphic_buffer,
CGAL::IO::Color c(75,160,255); const P2 *p2 = nullptr) {
face_begin(c); if (p2 != nullptr) {
draw_function_for_p2::compute_elements(graphic_buffer, p2);
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();
} }
}
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. // Specialization of draw function.
template<class T, class C> #define CGAL_P2_TYPE CGAL::Polygon_2<T, C>
void draw(const CGAL::Polygon_2<T, C>& 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
if (!cgal_test_suite) template <class T, class C>
{ void draw(const CGAL_P2_TYPE &ap2,
CGAL::Qt::init_ogl_context(4,3); const char *title = "Polygon_2 Basic Viewer") {
int argc=1;
const char* argv[2]={"t2_viewer", nullptr}; // Drawing_functor<CGAL_P2_TYPE, typename CGAL_P2_TYPE::Vertex_const_handle,
QApplication app(argc,const_cast<char**>(argv)); // typename CGAL_P2_TYPE::Halfedge_const_handle,
SimplePolygon2ViewerQt<CGAL::Polygon_2<T, C> > // typename CGAL_P2_TYPE::Face_const_handle>
mainwindow(app.activeWindow(), ap2, title); // drawingFunctor;
mainwindow.show();
app.exec(); CGAL::GraphicBuffer<float> buffer;
} add_in_graphic_buffer_p2(buffer, &ap2);
draw_buffer(buffer);
} }
} // End namespace CGAL } // End namespace CGAL