mirror of https://github.com/CGAL/cgal
Drawing arrangement (1st rev.) and basic cleanup conic traits
This commit is contained in:
parent
2b547ec58a
commit
b64818cc99
|
|
@ -4,7 +4,7 @@
|
||||||
cmake_minimum_required(VERSION 3.1...3.23)
|
cmake_minimum_required(VERSION 3.1...3.23)
|
||||||
project(Arrangement_on_surface_2_Examples)
|
project(Arrangement_on_surface_2_Examples)
|
||||||
|
|
||||||
find_package(CGAL REQUIRED COMPONENTS Core)
|
find_package(CGAL REQUIRED COMPONENTS Core Qt5)
|
||||||
|
|
||||||
# create a target per cppfile
|
# create a target per cppfile
|
||||||
file(
|
file(
|
||||||
|
|
@ -14,3 +14,7 @@ file(
|
||||||
foreach(cppfile ${cppfiles})
|
foreach(cppfile ${cppfiles})
|
||||||
create_single_source_cgal_program("${cppfile}")
|
create_single_source_cgal_program("${cppfile}")
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
if(CGAL_Qt5_FOUND)
|
||||||
|
target_link_libraries(draw_arr PUBLIC CGAL::CGAL_Basic_viewer)
|
||||||
|
endif()
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||||
|
#include <CGAL/Arrangement_2.h>
|
||||||
|
#include <CGAL/Arr_segment_traits_2.h>
|
||||||
|
#include <CGAL/draw_arrangement_2.h>
|
||||||
|
|
||||||
|
using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel;
|
||||||
|
using Traits = CGAL::Arr_segment_traits_2<Kernel>;
|
||||||
|
using Point = Traits::Point_2;
|
||||||
|
using X_monotone_curve = Traits::X_monotone_curve_2;
|
||||||
|
using Arrangement_2 = CGAL::Arrangement_2<Traits>;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
Traits traits;
|
||||||
|
Arrangement_2 arr(&traits);
|
||||||
|
auto ctr_xcv = traits.construct_x_monotone_curve_2_object();
|
||||||
|
|
||||||
|
CGAL::insert(arr, ctr_xcv(Point(-1,-1), Point(1,-1)));
|
||||||
|
CGAL::insert(arr, ctr_xcv(Point(1,-1), Point(1,1)));
|
||||||
|
CGAL::insert(arr, ctr_xcv(Point(1,1), Point(-1,1)));
|
||||||
|
CGAL::insert(arr, ctr_xcv(Point(-1,1), Point(-1,-1)));
|
||||||
|
|
||||||
|
CGAL::draw(arr);
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,94 @@
|
||||||
|
#ifndef CGAL_DRAW_ARRANGEMENT_2_H
|
||||||
|
#define CGAL_DRAW_ARRANGEMENT_2_H
|
||||||
|
|
||||||
|
#include <CGAL/Qt/Basic_viewer_qt.h>
|
||||||
|
#include <CGAL/Qt/init_ogl_context.h>
|
||||||
|
#include <CGAL/Arrangement_2.h>
|
||||||
|
|
||||||
|
namespace CGAL {
|
||||||
|
|
||||||
|
// Viewer class for Polygon_2
|
||||||
|
template <typename Arrangement_2>
|
||||||
|
class Arr_2_viewer_qt : public Basic_viewer_qt {
|
||||||
|
typedef Basic_viewer_qt Base;
|
||||||
|
typedef Arrangement_2 Arr;
|
||||||
|
typedef typename Arr::Point_2 Point;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/// Construct the viewer.
|
||||||
|
/// @param arr the arrangement to view
|
||||||
|
/// @param title the title of the window
|
||||||
|
Arr_2_viewer_qt(QWidget* parent, const Arr& arr,
|
||||||
|
const char* title = "2D Arrangement Basic Viewer") :
|
||||||
|
// First draw: vertices; edges, faces; multi-color; no inverse normal
|
||||||
|
Base(parent, title, true, true, true, false, false),
|
||||||
|
m_arr(arr)
|
||||||
|
{ add_elements(); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void add_ccb(typename Arr::Ccb_halfedge_const_circulator circ) {
|
||||||
|
typename Arr::Ccb_halfedge_const_circulator curr = circ;
|
||||||
|
do {
|
||||||
|
typename Arr::Halfedge_const_handle e = curr;
|
||||||
|
add_segment(e->source()->point(), e->target()->point());
|
||||||
|
add_point(e->source()->point());
|
||||||
|
add_point_in_face(e->source()->point());
|
||||||
|
} while (++curr != circ);
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_face(typename Arr::Face_const_handle f, CGAL::IO::Color c) {
|
||||||
|
if (f->is_unbounded()) return;
|
||||||
|
face_begin(c);
|
||||||
|
add_ccb(f->outer_ccb());
|
||||||
|
for (auto iv = f->isolated_vertices_begin();
|
||||||
|
iv != f->isolated_vertices_end(); ++iv)
|
||||||
|
add_point(iv->point());
|
||||||
|
face_end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_elements() {
|
||||||
|
clear();
|
||||||
|
if (m_arr.is_empty()) return;
|
||||||
|
CGAL::IO::Color c(75,160,255);
|
||||||
|
for (auto fit = m_arr.faces_begin(); fit != m_arr.faces_end(); ++fit)
|
||||||
|
add_face(fit, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void keyPressEvent(QKeyEvent* e) {
|
||||||
|
// Test key pressed:
|
||||||
|
// const ::Qt::KeyboardModifiers modifiers = e->modifiers();
|
||||||
|
// if ((e->key()==Qt::Key_PageUp) && (modifiers==Qt::NoButton)) { ... }
|
||||||
|
|
||||||
|
// Call: * add_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 Arrangement_2& m_arr;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename GeometryTraits_2, typename Dcel>
|
||||||
|
void draw(const CGAL::Arrangement_2<GeometryTraits_2, Dcel>& arr,
|
||||||
|
const char* title = "2D Arrangement Basic Viewer") {
|
||||||
|
typedef GeometryTraits_2 Gt;
|
||||||
|
typedef CGAL::Arrangement_2<Gt, Dcel> Arr;
|
||||||
|
|
||||||
|
CGAL::Qt::init_ogl_context(4,3);
|
||||||
|
|
||||||
|
int argc = 1;
|
||||||
|
const char* argv[2] = {"t2_viewer", nullptr};
|
||||||
|
QApplication app(argc, const_cast<char**>(argv));
|
||||||
|
Arr_2_viewer_qt<Arr>mainwindow(app.activeWindow(), arr, title);
|
||||||
|
mainwindow.show();
|
||||||
|
app.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Reference in New Issue