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>
// Mostafa Ashraf <mostaphaashraf1996@gmail.com>
#ifndef 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>
#ifdef DOXYGEN_RUNNING
@ -39,99 +42,65 @@ void draw(const P& ap);
#endif
#ifdef CGAL_USE_BASIC_VIEWER
#include <CGAL/Qt/init_ogl_context.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Qt/init_ogl_context.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;
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 <typename BufferType = float, class P2>
void add_in_graphic_buffer_p2(CGAL::GraphicBuffer<BufferType> &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<class T, class 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
#define CGAL_P2_TYPE CGAL::Polygon_2<T, C>
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<char**>(argv));
SimplePolygon2ViewerQt<CGAL::Polygon_2<T, C> >
mainwindow(app.activeWindow(), ap2, title);
mainwindow.show();
app.exec();
}
template <class T, class C>
void draw(const CGAL_P2_TYPE &ap2,
const char *title = "Polygon_2 Basic Viewer") {
// Drawing_functor<CGAL_P2_TYPE, typename CGAL_P2_TYPE::Vertex_const_handle,
// typename CGAL_P2_TYPE::Halfedge_const_handle,
// typename CGAL_P2_TYPE::Face_const_handle>
// drawingFunctor;
CGAL::GraphicBuffer<float> buffer;
add_in_graphic_buffer_p2(buffer, &ap2);
draw_buffer(buffer);
}
} // End namespace CGAL