diff --git a/GraphicsView/include/CGAL/Buffer_for_vao.h b/GraphicsView/include/CGAL/Buffer_for_vao.h index c6790f79c9f..dbb440a9496 100644 --- a/GraphicsView/include/CGAL/Buffer_for_vao.h +++ b/GraphicsView/include/CGAL/Buffer_for_vao.h @@ -35,7 +35,7 @@ #include #include #include -#include +#include namespace CGAL { @@ -161,6 +161,9 @@ public: m_flat_normal_buffer(flat_normal), m_gouraud_normal_buffer(gouraud_normal), m_bb(bbox), + m_zero_x(true), + m_zero_y(true), + m_zero_z(true), m_face_started(false) {} @@ -171,6 +174,10 @@ public: if (m_index_buffer!=nullptr) { m_index_buffer->clear(); } if (m_flat_normal_buffer!=nullptr) { m_flat_normal_buffer->clear(); } if (m_gouraud_normal_buffer!=nullptr) { m_gouraud_normal_buffer->clear(); } + + m_zero_x=true; + m_zero_y=true; + m_zero_z=true; } bool is_empty() const @@ -198,6 +205,15 @@ public: bool has_gouraud_normal() const { return m_gouraud_normal_buffer!=nullptr; } + bool has_zero_x() const + { return m_zero_x; } + + bool has_zero_y() const + { return m_zero_y; } + + bool has_zero_z() const + { return m_zero_z; } + // 1.1) Add a point, without color. Return the index of the added point. template std::size_t add_point(const KPoint& kp) @@ -209,6 +225,10 @@ public: if (m_bb!=nullptr) { (*m_bb)=(*m_bb)+p.bbox(); } + + if (m_zero_x && p.x()!=0) { m_zero_x=false; } + if (m_zero_y && p.y()!=0) { m_zero_y=false; } + if (m_zero_z && p.z()!=0) { m_zero_z=false; } return m_pos_buffer->size()-3; } @@ -605,8 +625,23 @@ protected: { P_traits cdt_traits(normal); CDT cdt(cdt_traits); - bool with_vertex_normal=(m_vertex_normals_for_face.size()==m_points_of_face.size()); + Local_point p1, p2; + + // For each point of the face, store the list of adjacent points and the number of time + // the edge is found in the face. For an edge p1, p2, store edge min(p1,p2)->max(p1,p2) + std::map > edges; + for (unsigned int i=0; i m; m[p2]=1; edges[p1]=m; } + else if (edges[p1].count(p2)==0) { edges[p1][p2]=1; } + else { ++(edges[p1][p2]); } + } // (1) We insert all the edges as contraint in the CDT. typename CDT::Vertex_handle previous=nullptr, first=nullptr; @@ -625,12 +660,22 @@ protected: { vh->info().index=m_indices_of_points_of_face[i]; } if(previous!=nullptr && previous!=vh) - { cdt.insert_constraint(previous, vh); } + { + p1=m_points_of_face[i]; p2=m_points_of_face[i-1]; + if (p2 constraint + { cdt.insert_constraint(previous, vh); } + } previous=vh; } if (previous!=nullptr && previous!=first) - { cdt.insert_constraint(previous, first); } + { + p1=m_points_of_face[m_points_of_face.size()-1]; p2=m_points_of_face[0]; + if (p2 constraint + { cdt.insert_constraint(previous, first); } + } // (2) We mark all external triangles // (2.1) We initialize is_external and is_process values @@ -782,6 +827,10 @@ protected: std::vector* m_gouraud_normal_buffer; CGAL::Bbox_3* m_bb; + + bool m_zero_x; /// True iff all points have x==0 + bool m_zero_y; /// True iff all points have y==0 + bool m_zero_z; /// True iff all points have z==0 // Local variables, used when we started a new face. bool m_face_started; diff --git a/GraphicsView/include/CGAL/Qt/Basic_viewer_qt.h b/GraphicsView/include/CGAL/Qt/Basic_viewer_qt.h index e4ae0184c19..1d2fbd751e9 100644 --- a/GraphicsView/include/CGAL/Qt/Basic_viewer_qt.h +++ b/GraphicsView/include/CGAL/Qt/Basic_viewer_qt.h @@ -55,6 +55,7 @@ #include #include +#include #include namespace CGAL @@ -253,6 +254,39 @@ public: const CGAL::Bbox_3& bounding_box() const { return m_bounding_box; } + bool has_zero_x() const + { + return + m_buffer_for_mono_points.has_zero_x() && + m_buffer_for_colored_points.has_zero_x() && + m_buffer_for_mono_segments.has_zero_x() && + m_buffer_for_colored_segments.has_zero_x() && + m_buffer_for_mono_faces.has_zero_x() && + m_buffer_for_colored_faces.has_zero_x(); + } + + bool has_zero_y() const + { + return + m_buffer_for_mono_points.has_zero_y() && + m_buffer_for_colored_points.has_zero_y() && + m_buffer_for_mono_segments.has_zero_y() && + m_buffer_for_colored_segments.has_zero_y() && + m_buffer_for_mono_faces.has_zero_y() && + m_buffer_for_colored_faces.has_zero_y(); + } + + bool has_zero_z() const + { + return + m_buffer_for_mono_points.has_zero_z() && + m_buffer_for_colored_points.has_zero_z() && + m_buffer_for_mono_segments.has_zero_z() && + m_buffer_for_colored_segments.has_zero_z() && + m_buffer_for_mono_faces.has_zero_z() && + m_buffer_for_colored_faces.has_zero_z(); + } + template void add_point(const KPoint& p) { m_buffer_for_mono_points.add_point(p); } @@ -732,6 +766,23 @@ protected: rendering_program_face.release(); } + + if (!is_empty() && (has_zero_x() || has_zero_y() || has_zero_z())) + { + camera()->setType(CGAL::qglviewer::Camera::ORTHOGRAPHIC); + // Camera Constraint: + constraint.setRotationConstraintType(CGAL::qglviewer::AxisPlaneConstraint::AXIS); + constraint.setTranslationConstraintType(CGAL::qglviewer::AxisPlaneConstraint::FREE); + + double cx=0., cy=0., cz=0.; + if (has_zero_x()) { cx=1.; } + else if (has_zero_y()) { cy=1.; } + else { cz=1.; } + + camera()->setViewDirection(CGAL::qglviewer::Vec(-cx,-cy,-cz)); + constraint.setRotationConstraintDirection(CGAL::qglviewer::Vec(cx, cy, cz)); + camera()->frame()->setConstraint(&constraint); + } } virtual void redraw() @@ -775,7 +826,7 @@ protected: glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); compile_shaders(); - + CGAL::Bbox_3 bb; if (bb==bounding_box()) // Case of "empty" bounding box { @@ -1000,7 +1051,10 @@ protected: bool m_are_buffers_initialized; CGAL::Bbox_3 m_bounding_box; - + + // CGAL::qglviewer::LocalConstraint constraint; + CGAL::qglviewer::WorldConstraint constraint; + // The following enum gives the indices of different elements of arrays vectors. enum { @@ -1059,36 +1113,14 @@ protected: #else // CGAL_USE_BASIC_VIEWER -namespace CGAL +namespace CGAL { -template -void draw(const T&, const char*, bool, const ColorFunctor&) -{ - std::cerr<<"Impossible to draw because CGAL_USE_BASIC_VIEWER is not defined." - < -void draw(const T&, const char*, bool) -{ - std::cerr<<"Impossible to draw because CGAL_USE_BASIC_VIEWER is not defined." - < -void draw(const T&, const char*) -{ - std::cerr<<"Impossible to draw because CGAL_USE_BASIC_VIEWER is not defined." - < -void draw(const T&) -{ - std::cerr<<"Impossible to draw because CGAL_USE_BASIC_VIEWER is not defined." - < + void draw(const T&, const char* ="", bool=false) + { + std::cerr<<"Impossible to draw, CGAL_USE_BASIC_VIEWER is not defined."<() \endlink function as shown in the following example. This function opens a new window showing the given linear cell complex. A call to this function is blocking, that is the program continues as soon as the user closes the window. \cgalExample{Linear_cell_complex/draw_linear_cell_complex.cpp} diff --git a/Linear_cell_complex/doc/Linear_cell_complex/PackageDescription.txt b/Linear_cell_complex/doc/Linear_cell_complex/PackageDescription.txt index c57f67ee8ec..42da9fd9276 100644 --- a/Linear_cell_complex/doc/Linear_cell_complex/PackageDescription.txt +++ b/Linear_cell_complex/doc/Linear_cell_complex/PackageDescription.txt @@ -19,7 +19,7 @@ /// \defgroup PkgLinearCellComplexOperations Operations for Linear Cell Complex /// \ingroup PkgLinearCellComplexRef -/*! Draw. +/*! \code #include \endcode @@ -75,7 +75,7 @@ - `CGAL::compute_normal_of_cell_2` \cgalCRPSubsection{Draw a Linear Cell Complex} -- `CGAL::draw` +- \link PkgDrawLinearCellComplex CGAL::draw() \endlink */ diff --git a/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt b/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt index 270c76321d8..b9b86d10fc5 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt +++ b/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt @@ -16,7 +16,7 @@ endif() find_package(CGAL COMPONENTS Qt5) if(CGAL_Qt5_FOUND) - add_definitions(-DCGAL_USE_BASIC_VIEWER -DQT_NO_KEYWORDS) + add_definitions(-DCGAL_USE_BASIC_VIEWER -DQT_NO_KEYWORDS) endif() # For Gprof. diff --git a/Linear_cell_complex/include/CGAL/draw_linear_cell_complex.h b/Linear_cell_complex/include/CGAL/draw_linear_cell_complex.h index 2e2c09cc36a..1b750f2dc0b 100644 --- a/Linear_cell_complex/include/CGAL/draw_linear_cell_complex.h +++ b/Linear_cell_complex/include/CGAL/draw_linear_cell_complex.h @@ -25,6 +25,7 @@ #ifdef CGAL_USE_BASIC_VIEWER +#include #include namespace CGAL @@ -371,49 +372,45 @@ protected: bool m_random_face_color; const DrawingFunctorLCC& m_drawing_functor; }; - -template -void draw(const LCC& alcc, - const char* title, - bool nofill, - const DrawingFunctorLCC& drawing_functor) + +// Specialization of draw function. +#define CGAL_LCC_TYPE CGAL::Linear_cell_complex_base \ + + +template < unsigned int d_, unsigned int ambient_dim, + class Traits_, + class Items_, + class Alloc_, + template + class Map, + class Refs, + class Storage_> +void draw(const CGAL_LCC_TYPE& alcc, + const char* title="LCC for CMap Basic Viewer", + bool nofill=false) { #if defined(CGAL_TEST_SUITE) bool cgal_test_suite=true; #else - bool cgal_test_suite=false; + bool cgal_test_suite=qEnvironmentVariableIsSet("CGAL_TEST_SUITE"); #endif - + if (!cgal_test_suite) { int argc=1; const char* argv[2]={"lccviewer","\0"}; QApplication app(argc,const_cast(argv)); - SimpleLCCViewerQt mainwindow(app.activeWindow(), - &alcc, - title, - nofill, - drawing_functor); + DefaultDrawingFunctorLCC fcolor; + SimpleLCCViewerQt + mainwindow(app.activeWindow(), &alcc, title, nofill, fcolor); mainwindow.show(); app.exec(); } } -template -void draw(const LCC& alcc, const char* title, bool nofill) -{ - DefaultDrawingFunctorLCC f; - draw(alcc, title, nofill, f); -} - -template -void draw(const LCC& alcc, const char* title) -{ draw(alcc, title, false); } - -template -void draw(const LCC& alcc) -{ draw(alcc, "Basic LCC Viewer"); } - +// Todo a function taking a const DrawingFunctorLCC& drawing_functor as parameter +#undef CGAL_LCC_TYPE + } // End namespace CGAL #endif // CGAL_USE_BASIC_VIEWER diff --git a/Point_set_3/doc/Point_set_3/PackageDescription.txt b/Point_set_3/doc/Point_set_3/PackageDescription.txt index 0ce7749a122..83cbc94046a 100644 --- a/Point_set_3/doc/Point_set_3/PackageDescription.txt +++ b/Point_set_3/doc/Point_set_3/PackageDescription.txt @@ -1,6 +1,16 @@ /// \defgroup PkgPointSet3Ref 3D Point Set Reference /*! + \code + #include + \endcode +*/ +/// \defgroup PkgDrawPointSet3D Draw a 3D Point Set +/// \ingroup PkgPointSet3Ref + +/*! +\addtogroup PkgPointSet3Ref + \cgalPkgDescriptionBegin{3D Point Set, PkgPointSet3} \cgalPkgPicture{point_set_3.png} \cgalPkgSummaryBegin @@ -21,6 +31,9 @@ \cgalCRPSection{Class} - `CGAL::Point_set_3` +\cgalCRPSection{Draw a 3D Point Set} +- \link PkgDrawPointSet3D CGAL::draw() \endlink + \defgroup PkgPointSet3IO Input/Output \ingroup PkgPointSet3Ref diff --git a/Point_set_3/doc/Point_set_3/Point_set_3.txt b/Point_set_3/doc/Point_set_3/Point_set_3.txt index 288d44d4911..2a765f352bf 100644 --- a/Point_set_3/doc/Point_set_3/Point_set_3.txt +++ b/Point_set_3/doc/Point_set_3/Point_set_3.txt @@ -163,6 +163,18 @@ overload provided for `CGAL::Point_set_3`: \cgalExample{Point_set_3/point_set_advanced.cpp} +\subsection Point_set_3_Draw Draw a Point Set + +A 3D point set can be visualized by calling the \link PkgDrawPointSet3D CGAL::draw() \endlink function as shown in the following example. This function opens a new window showing the given point set. A call to this function is blocking, that is the program continues as soon as the user closes the window. + +\cgalExample{Point_set_3/draw_point_set_3.cpp} + +This function requires CGAL_Qt5, and is only available if the flag CGAL_USE_BASIC_VIEWER is defined at compile time. + +\cgalFigureBegin{fig_draw_point_set,draw_point_set.png} +Result of the run of the draw_point_set_3 program. A window shows the 3D points and allows to navigate through the 3D scene. +\cgalFigureEnd + \section Point_set_3_History History This package has been created to fill the need for a practical data diff --git a/Point_set_3/doc/Point_set_3/examples.txt b/Point_set_3/doc/Point_set_3/examples.txt index 269700c266a..d8711deceed 100644 --- a/Point_set_3/doc/Point_set_3/examples.txt +++ b/Point_set_3/doc/Point_set_3/examples.txt @@ -5,4 +5,5 @@ \example Point_set_3/point_set_read_xyz.cpp \example Point_set_3/point_set_read_ply.cpp \example Point_set_3/point_set_advanced.cpp +\example Point_set_3/draw_point_set_3.cpp */ diff --git a/Point_set_3/doc/Point_set_3/fig/draw_point_set.png b/Point_set_3/doc/Point_set_3/fig/draw_point_set.png new file mode 100644 index 00000000000..21cec33e55d Binary files /dev/null and b/Point_set_3/doc/Point_set_3/fig/draw_point_set.png differ diff --git a/Point_set_3/examples/Point_set_3/CMakeLists.txt b/Point_set_3/examples/Point_set_3/CMakeLists.txt index 100e1919211..45172ef603d 100644 --- a/Point_set_3/examples/Point_set_3/CMakeLists.txt +++ b/Point_set_3/examples/Point_set_3/CMakeLists.txt @@ -7,7 +7,7 @@ project( Point_set_3_Examples ) # CGAL and its components -find_package( CGAL QUIET COMPONENTS ) +find_package( CGAL QUIET COMPONENTS Qt5 ) if ( NOT CGAL_FOUND ) @@ -16,6 +16,10 @@ if ( NOT CGAL_FOUND ) endif() +if(CGAL_Qt5_FOUND) + add_definitions(-DCGAL_USE_BASIC_VIEWER -DQT_NO_KEYWORDS) +endif() + # Boost and its components find_package( Boost REQUIRED ) @@ -50,5 +54,7 @@ else() create_single_source_cgal_program( "point_set_algo.cpp" ) endif() - - +create_single_source_cgal_program("draw_point_set_3.cpp" ) +if(CGAL_Qt5_FOUND) + target_link_libraries(draw_point_set_3 PUBLIC CGAL::CGAL_Qt5) +endif() diff --git a/Point_set_3/examples/Point_set_3/draw_point_set_3.cpp b/Point_set_3/examples/Point_set_3/draw_point_set_3.cpp new file mode 100644 index 00000000000..3e9cfae71b7 --- /dev/null +++ b/Point_set_3/examples/Point_set_3/draw_point_set_3.cpp @@ -0,0 +1,29 @@ +#include +#include +#include +#include +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; +typedef Kernel::FT FT; +typedef Kernel::Point_3 Point; +typedef Kernel::Vector_3 Vector; +typedef CGAL::Point_set_3 Point_set; + +int main (int argc, char** argv) +{ + std::ifstream f (argc > 1 ? argv[1] : "data/oni.xyz"); + Point_set point_set; + + // Reading input in XYZ format + if (!f || !CGAL::read_xyz_point_set (f, point_set)) + { + std::cerr<<"Can't read input file " + <<(argc > 1 ? argv[1] : "data/oni.xyz")<< std::endl; + return EXIT_FAILURE; + } + + CGAL::draw(point_set); + + return EXIT_SUCCESS; +} diff --git a/Point_set_3/include/CGAL/draw_point_set_3.h b/Point_set_3/include/CGAL/draw_point_set_3.h new file mode 100644 index 00000000000..ca5d094b3a5 --- /dev/null +++ b/Point_set_3/include/CGAL/draw_point_set_3.h @@ -0,0 +1,127 @@ +// Copyright (c) 2016 GeometryFactory Sarl (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ +// +// +// Author(s) : Guillaume Damiand + +#ifndef CGAL_DRAW_POINT_SET_3_H +#define CGAL_DRAW_POINT_SET_3_H + +#include +#include + +#ifdef DOXYGEN_RUNNING +namespace CGAL { + +/*! +\ingroup PkgDrawPointSet3D + +opens a new window and draws `aps`, an instance of the `CGAL::Point_set_3` class. A call to this function is blocking, that is the program continues as soon as the user closes the window. This function requires CGAL_Qt5, and is only available if the flag CGAL_USE_BASIC_VIEWER is defined at compile time. +\tparam PS an instance of the `CGAL::Point_set_3` class. +\param aps the point set to draw. + +*/ +template +void draw(const PS& aps); + +} /* namespace CGAL */ +#endif + +#ifdef CGAL_USE_BASIC_VIEWER + +#include +#include + +namespace CGAL +{ + +// Viewer class for Point_set +template +class SimplePointSetViewerQt : public Basic_viewer_qt +{ + typedef Basic_viewer_qt Base; + typedef typename PointSet::Point_map::value_type Point; + +public: + /// Construct the viewer. + /// @param apointset the point set to view + /// @param title the title of the window + SimplePointSetViewerQt(QWidget* parent, + const PointSet& apointset, const char* title="") : + // First draw: vertices; no-edge, no-face; mono-color; no inverse normal + Base(parent, title, true, false, false, true, false), + pointset(apointset) + { + compute_elements(); + } + +protected: + void compute_vertex(const Point& p) + { + add_point(p); + // We can use add_point(p, c) with c a CGAL::Color to add a colored point + } + + void compute_elements() + { + clear(); + + for (typename PointSet::const_iterator it=pointset.begin(); + it!=pointset.end(); ++it) + { compute_vertex(pointset.point(*it)); } + } + + virtual void keyPressEvent(QKeyEvent *e) + { + // const ::Qt::KeyboardModifiers modifiers = e->modifiers(); + Base::keyPressEvent(e); + } + +protected: + const PointSet& pointset; +}; + +// Specialization of draw function. +template +void draw(const Point_set_3& apointset, + const char* title="Point_set_3 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) + { + int argc=1; + const char* argv[2]={"point_set_viewer","\0"}; + QApplication app(argc,const_cast(argv)); + SimplePointSetViewerQt > mainwindow(app.activeWindow(), + apointset, + title); + mainwindow.show(); + app.exec(); + } +} + +} // End namespace CGAL + +#endif // CGAL_USE_BASIC_VIEWER + +#endif // CGAL_DRAW_POINT_SET_3_H diff --git a/Point_set_3/package_info/Point_set_3/dependencies b/Point_set_3/package_info/Point_set_3/dependencies index d5ec00a4fea..cab851ef527 100644 --- a/Point_set_3/package_info/Point_set_3/dependencies +++ b/Point_set_3/package_info/Point_set_3/dependencies @@ -1,5 +1,6 @@ Algebraic_foundations BGL +GraphicsView Installation Interval_support Kernel_23 diff --git a/Polygon/doc/Polygon/Doxyfile.in b/Polygon/doc/Polygon/Doxyfile.in index f4a3edd012e..8cfb32b528f 100644 --- a/Polygon/doc/Polygon/Doxyfile.in +++ b/Polygon/doc/Polygon/Doxyfile.in @@ -4,7 +4,6 @@ PROJECT_NAME = "CGAL ${CGAL_DOC_VERSION} - 2D Polygons" EXAMPLE_PATH = ${CGAL_PACKAGE_DIR}/examples \ ${CGAL_Stream_support_EXAMPLE_DIR} - EXTRACT_ALL = false HIDE_UNDOC_MEMBERS = true HIDE_UNDOC_CLASSES = true diff --git a/Polygon/doc/Polygon/PackageDescription.txt b/Polygon/doc/Polygon/PackageDescription.txt index e9867f1bb65..b5057669497 100644 --- a/Polygon/doc/Polygon/PackageDescription.txt +++ b/Polygon/doc/Polygon/PackageDescription.txt @@ -6,6 +6,22 @@ /// \defgroup PkgPolygon2Functions Global Functions /// \ingroup PkgPolygon2Ref +/*! + \code + #include + \endcode +*/ +/// \defgroup PkgDrawPolygon2 Draw a 2D Polygon +/// \ingroup PkgPolygon2Ref + +/*! + \code + #include + \endcode +*/ +/// \defgroup PkgDrawPolygonWithHoles2 Draw a 2D Polygon with Holes +/// \ingroup PkgPolygon2Ref + /*! \addtogroup PkgPolygon2Ref @@ -53,5 +69,11 @@ The assertion flags for the polygons and polygon operations use - `CGAL::right_vertex_2()` - `CGAL::top_vertex_2()` +\cgalCRPSection{Draw a Polygon_2} +- \link PkgDrawPolygon2 CGAL::draw

() \endlink + +\cgalCRPSection{Draw a Polygon_with_holes_2} +- \link PkgDrawPolygonWithHoles2 CGAL::draw() \endlink + */ diff --git a/Polygon/doc/Polygon/Polygon.txt b/Polygon/doc/Polygon/Polygon.txt index 279d24c457f..9b34746cee1 100644 --- a/Polygon/doc/Polygon/Polygon.txt +++ b/Polygon/doc/Polygon/Polygon.txt @@ -70,6 +70,18 @@ and 3D Linear Geometric %Kernel. \cgalExample{Polygon/projected_polygon.cpp} +\subsection subsecPolygonDraw Draw a Polygon + +A polygon can be visualized by calling the \link PkgDrawPolygon2 CGAL::draw

() \endlink function as shown in the following example. This function opens a new window showing the given polygon. A call to this function is blocking, that is the program continues as soon as the user closes the window (a version exists for polygon with holes, cf. \link PkgDrawPolygonWithHoles2 CGAL::draw() \endlink). + +\cgalExample{Polygon/draw_polygon.cpp} + +This function requires CGAL_Qt5, and is only available if the flag CGAL_USE_BASIC_VIEWER is defined at compile time. + +\cgalFigureBegin{fig_draw_polygon,draw_polygon.png} +Result of the run of the draw_polygon program. A window shows the polygon and allows to navigate through the scene. +\cgalFigureEnd + */ \section secPolygonWithHole Polygons with Holes diff --git a/Polygon/doc/Polygon/examples.txt b/Polygon/doc/Polygon/examples.txt index 0e102b3f83e..d176af36d0a 100644 --- a/Polygon/doc/Polygon/examples.txt +++ b/Polygon/doc/Polygon/examples.txt @@ -4,4 +4,6 @@ \example Polygon/Polygon.cpp \example Polygon/projected_polygon.cpp \example Stream_support/Polygon_WKT.cpp +\example Polygon/draw_polygon.cpp +\example Polygon/draw_polygon_with_holes.cpp */ diff --git a/Polygon/doc/Polygon/fig/draw_polygon.png b/Polygon/doc/Polygon/fig/draw_polygon.png new file mode 100644 index 00000000000..6da8e0ae0c9 Binary files /dev/null and b/Polygon/doc/Polygon/fig/draw_polygon.png differ diff --git a/Polygon/examples/Polygon/CMakeLists.txt b/Polygon/examples/Polygon/CMakeLists.txt index fbd4cbe65e2..eebdf3979e0 100644 --- a/Polygon/examples/Polygon/CMakeLists.txt +++ b/Polygon/examples/Polygon/CMakeLists.txt @@ -6,7 +6,11 @@ cmake_minimum_required(VERSION 3.1...3.15) project( Polygon_Examples ) -find_package(CGAL QUIET) +find_package(CGAL QUIET COMPONENTS Qt5) + +if(CGAL_Qt5_FOUND) + add_definitions(-DCGAL_USE_BASIC_VIEWER -DQT_NO_KEYWORDS) +endif() if ( CGAL_FOUND ) @@ -16,6 +20,11 @@ if ( CGAL_FOUND ) create_single_source_cgal_program( "${cppfile}" ) endforeach() + if(CGAL_Qt5_FOUND) + target_link_libraries(draw_polygon PUBLIC CGAL::CGAL_Qt5) + target_link_libraries(draw_polygon_with_holes PUBLIC CGAL::CGAL_Qt5) + endif() + else() message(STATUS "This program requires the CGAL library, and will not be compiled.") diff --git a/Polygon/examples/Polygon/draw_polygon.cpp b/Polygon/examples/Polygon/draw_polygon.cpp new file mode 100644 index 00000000000..072e41387e3 --- /dev/null +++ b/Polygon/examples/Polygon/draw_polygon.cpp @@ -0,0 +1,22 @@ +#include +#include +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +typedef CGAL::Polygon_2 Polygon_2; +typedef CGAL::Point_2 Point; + +int main() +{ + // create a polygon and put some points in it + Polygon_2 p; + p.push_back(Point(0,0)); + p.push_back(Point(4,0)); + p.push_back(Point(4,4)); + p.push_back(Point(2,2)); + p.push_back(Point(0,4)); + + CGAL::draw(p); + + return EXIT_SUCCESS; +} diff --git a/Polygon/examples/Polygon/draw_polygon_with_holes.cpp b/Polygon/examples/Polygon/draw_polygon_with_holes.cpp new file mode 100644 index 00000000000..b2a551b7f12 --- /dev/null +++ b/Polygon/examples/Polygon/draw_polygon_with_holes.cpp @@ -0,0 +1,37 @@ +#include +#include +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +typedef CGAL::Polygon_with_holes_2 Polygon_with_holes_2; +typedef CGAL::Polygon_2 Polygon_2; +typedef CGAL::Point_2 Point; + +int main() +{ + // create a polygon with three holes + Polygon_2 outer_polygon; + outer_polygon.push_back(Point(0,0)); outer_polygon.push_back(Point(9,0)); + outer_polygon.push_back(Point(6,8)); outer_polygon.push_back(Point(5,3)); + outer_polygon.push_back(Point(2,8)); outer_polygon.push_back(Point(0,8)); + + std::vector holes(3); + holes[0].push_back(Point(6,2)); holes[0].push_back(Point(7,1)); + holes[0].push_back(Point(7,3)); holes[0].push_back(Point(6,3)); + holes[0].push_back(Point(5,2)); + + holes[1].push_back(Point(2,1)); holes[1].push_back(Point(3,1)); + holes[1].push_back(Point(3,3)); holes[1].push_back(Point(2,2)); + holes[1].push_back(Point(1,2)); + + holes[2].push_back(Point(1,4)); holes[2].push_back(Point(2,4)); + holes[2].push_back(Point(2,5)); holes[2].push_back(Point(3,5)); + holes[2].push_back(Point(3,6)); holes[2].push_back(Point(1,6)); + + Polygon_with_holes_2 p(outer_polygon, holes.begin(), holes.end()); + + // And draw it. + CGAL::draw(p); + + return EXIT_SUCCESS; +} diff --git a/Polygon/include/CGAL/draw_polygon_2.h b/Polygon/include/CGAL/draw_polygon_2.h new file mode 100644 index 00000000000..8b7bdd296a6 --- /dev/null +++ b/Polygon/include/CGAL/draw_polygon_2.h @@ -0,0 +1,148 @@ +// Copyright (c) 1997 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// +// Author(s) : Guillaume Damiand + +#ifndef CGAL_DRAW_POLYGON_2_H +#define CGAL_DRAW_POLYGON_2_H + +#include + +#ifdef DOXYGEN_RUNNING +namespace CGAL { + +/*! +\ingroup PkgDrawPolygon2 + +opens a new window and draws `ap`, an instance of the `CGAL::Polygon_2` class. A call to this function is blocking, that is the program continues as soon as the user closes the window. This function requires CGAL_Qt5, and is only available if the flag CGAL_USE_BASIC_VIEWER is defined at compile time. +\tparam P an instance of the `CGAL::Polygon_2` class. +\param ap the polygon to draw. + +*/ +template +void draw(const P& ap); + +} /* namespace CGAL */ + +#endif + +#ifdef CGAL_USE_BASIC_VIEWER + +#include +#include + +namespace CGAL +{ + +// 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(); + } + +protected: + void compute_elements() + { + clear(); + + if (p2.is_empty()) return; + + Point prev=p2.vertex(p2.size()-1); + + CGAL::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(); + } + + 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 + + if (!cgal_test_suite) + { + int argc=1; + const char* argv[2]={"t2_viewer","\0"}; + QApplication app(argc,const_cast(argv)); + SimplePolygon2ViewerQt > + mainwindow(app.activeWindow(), ap2, title); + mainwindow.show(); + app.exec(); + } +} + +} // End namespace CGAL + +#endif // CGAL_USE_BASIC_VIEWER + +#endif // CGAL_DRAW_POLYGON_2_H diff --git a/Polygon/include/CGAL/draw_polygon_with_holes_2.h b/Polygon/include/CGAL/draw_polygon_with_holes_2.h new file mode 100644 index 00000000000..33806eb1b38 --- /dev/null +++ b/Polygon/include/CGAL/draw_polygon_with_holes_2.h @@ -0,0 +1,164 @@ +// Copyright (c) 1997 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// +// Author(s) : Guillaume Damiand + +#ifndef CGAL_DRAW_POLYGON_WITH_HOLES_2_H +#define CGAL_DRAW_POLYGON_WITH_HOLES_2_H + +#include + +#ifdef DOXYGEN_RUNNING +namespace CGAL { + +/*! +\ingroup PkgDrawPolygonWithHoles2 + +opens a new window and draws `aph`, an instance of the `CGAL::Polygon_with_holes_2` class. A call to this function is blocking, that is the program continues as soon as the user closes the window. This function requires CGAL_Qt5, and is only available if the flag CGAL_USE_BASIC_VIEWER is defined at compile time. +\tparam PH an instance of the `CGAL::Polygon_with_holes_2` class. +\param aph the polygon with holes to draw. + +*/ +template +void draw(const PH& aph); + +} /* namespace CGAL */ +#endif + +#ifdef CGAL_USE_BASIC_VIEWER + +#include +#include + +namespace CGAL +{ + +// Viewer class for Polygon_2 +template +class SimplePolygonWithHoles2ViewerQt : public Basic_viewer_qt +{ + typedef Basic_viewer_qt Base; + typedef typename P2::General_polygon_2::Point_2 Point; + +public: + /// Construct the viewer. + /// @param ap2 the polygon to view + /// @param title the title of the window + SimplePolygonWithHoles2ViewerQt(QWidget* parent, const P2& ap2, + const char* title="Basic Polygon_with_holes_2 Viewer") : + // First draw: vertices; edges, faces; multi-color; no inverse normal + Base(parent, title, true, true, true, false, false), + p2(ap2) + { + compute_elements(); + } + +protected: + void compute_one_loop_elements(const typename P2::General_polygon_2& p, bool hole) + { + if (hole) + { add_point_in_face(p.vertex(p.size()-1)); } + + typename P2::General_polygon_2::Vertex_const_iterator prev; + for (typename P2::General_polygon_2::Vertex_const_iterator i=p.vertices_begin(); + i!=p.vertices_end(); ++i) + { + add_point(*i); // Add vertex + if (i!=p.vertices_begin()) + { add_segment(*prev, *i); } // Add segment with previous point + add_point_in_face(*i); // Add point in face + prev=i; + } + + // Add the last segment between the last point and the first one + add_segment(*prev, *(p.vertices_begin())); + } + + void compute_elements() + { + clear(); + + if (p2.outer_boundary().is_empty()) return; + + CGAL::Color c(75,160,255); + face_begin(c); + + compute_one_loop_elements(p2.outer_boundary(), false); + + for (typename P2::Hole_const_iterator it=p2.holes_begin(); it!=p2.holes_end(); ++it) + { + compute_one_loop_elements(*it, true); + add_point_in_face(p2.outer_boundary().vertex(p2.outer_boundary().size()-1)); + } + + 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. +template +void draw(const CGAL::Polygon_with_holes_2& ap2, + const char* title="Polygon_with_holes_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) + { + int argc=1; + const char* argv[2]={"t2_viewer","\0"}; + QApplication app(argc,const_cast(argv)); + SimplePolygonWithHoles2ViewerQt > + mainwindow(app.activeWindow(), ap2, title); + mainwindow.show(); + app.exec(); + } +} + +} // End namespace CGAL + +#endif // CGAL_USE_BASIC_VIEWER + +#endif // CGAL_DRAW_POLYGON_WITH_HOLES_2_H diff --git a/Polygon/package_info/Polygon/dependencies b/Polygon/package_info/Polygon/dependencies index ad435cca369..3312eb37e46 100644 --- a/Polygon/package_info/Polygon/dependencies +++ b/Polygon/package_info/Polygon/dependencies @@ -1,5 +1,6 @@ Algebraic_foundations Circulator +GraphicsView Installation Kernel_23 Number_types diff --git a/Polyhedron/doc/Polyhedron/CGAL/draw_polyhedron.h b/Polyhedron/doc/Polyhedron/CGAL/draw_polyhedron.h index 8ac1c401b79..5e8a22595c7 100644 --- a/Polyhedron/doc/Polyhedron/CGAL/draw_polyhedron.h +++ b/Polyhedron/doc/Polyhedron/CGAL/draw_polyhedron.h @@ -3,7 +3,7 @@ namespace CGAL { /*! \ingroup PkgDrawPolyhedron -Open a new window and draw `apoly`, an instance of the `CGAL::Polyhedron_3` class. The function is blocking, that is the program continues as soon as the user closes the window. This function requires CGAL_Qt5, and is only available if the flag CGAL_USE_BASIC_VIEWER is defined at compile time. +opens a new window and draws `apoly`, an instance of the `CGAL::Polyhedron_3` class. A call to this function is blocking, that is the program continues as soon as the user closes the window. This function requires CGAL_Qt5, and is only available if the flag CGAL_USE_BASIC_VIEWER is defined at compile time. \tparam POLY an instance of the `CGAL::Polyhedron_3` class. \param apoly the polyhedron to draw. diff --git a/Polyhedron/doc/Polyhedron/PackageDescription.txt b/Polyhedron/doc/Polyhedron/PackageDescription.txt index 9cc3663b547..67f938ec4b7 100644 --- a/Polyhedron/doc/Polyhedron/PackageDescription.txt +++ b/Polyhedron/doc/Polyhedron/PackageDescription.txt @@ -5,7 +5,7 @@ /// \defgroup PkgPolyhedronIOFunc I/O Functions /// \ingroup PkgPolyhedronRef -/*! Draw. +/*! \code #include \endcode @@ -73,7 +73,7 @@ surface can be used without knowing the halfedge data structure. - \link PkgPolyhedronIOFunc `read_off()` \endlink \cgalCRPSection{Draw a Polyhedron 3} -- `CGAL::draw` +- \link PkgDrawPolyhedron CGAL::draw() \endlink */ diff --git a/Polyhedron/doc/Polyhedron/Polyhedron.txt b/Polyhedron/doc/Polyhedron/Polyhedron.txt index b960089fa00..c5ba15dd26b 100644 --- a/Polyhedron/doc/Polyhedron/Polyhedron.txt +++ b/Polyhedron/doc/Polyhedron/Polyhedron.txt @@ -278,7 +278,7 @@ are also marked in the program code. \subsection PolyhedronDraw Draw a Polyhedron \anchor ssecDrawPolyhedron -A polyhedron can be visualized by calling the `CGAL::draw()` function as shown in the following example. This function opens a new window showing the given polyhedron. The function is blocking, that is the program continues as soon as the user closes the window. +A polyhedron can be visualized by calling the \link PkgDrawPolyhedron CGAL::draw() \endlink function as shown in the following example. This function opens a new window showing the given polyhedron. A call to this function is blocking, that is the program continues as soon as the user closes the window. \cgalExample{Polyhedron/draw_polyhedron.cpp} diff --git a/Polyhedron/include/CGAL/draw_polyhedron.h b/Polyhedron/include/CGAL/draw_polyhedron.h index 52dc930075d..66cf3a7f3bd 100644 --- a/Polyhedron/include/CGAL/draw_polyhedron.h +++ b/Polyhedron/include/CGAL/draw_polyhedron.h @@ -26,6 +26,7 @@ #ifdef CGAL_USE_BASIC_VIEWER +#include #include namespace CGAL @@ -194,45 +195,40 @@ protected: bool m_nofaces; const ColorFunctor& m_fcolor; }; - -template -void draw(const Polyhedron& apoly, - const char* title, - bool nofill, - const ColorFunctor& fcolor) -{ + +// Specialization of draw function. +#define CGAL_POLY_TYPE CGAL::Polyhedron_3 \ + + +template + class T_HDS, + class Alloc> +void draw(const CGAL_POLY_TYPE& apoly, + const char* title="Polyhedron Basic Viewer", + bool nofill=false) +{ #if defined(CGAL_TEST_SUITE) bool cgal_test_suite=true; #else - bool cgal_test_suite=false; + bool cgal_test_suite=qEnvironmentVariableIsSet("CGAL_TEST_SUITE"); #endif - + if (!cgal_test_suite) { int argc=1; const char* argv[2]={"polyhedron_viewer","\0"}; QApplication app(argc,const_cast(argv)); - SimplePolyhedronViewerQt + DefaultColorFunctorPolyhedron fcolor; + SimplePolyhedronViewerQt mainwindow(app.activeWindow(), apoly, title, nofill, fcolor); mainwindow.show(); app.exec(); } } -template -void draw(const Polyhedron& apoly, const char* title, bool nofill) -{ - DefaultColorFunctorPolyhedron c; - draw(apoly, title, nofill, c); -} - -template -void draw(const Polyhedron& apoly, const char* title) -{ draw(apoly, title, false); } - -template -void draw(const Polyhedron& apoly) -{ draw(apoly, "Basic Polyhedron Viewer"); } +#undef CGAL_POLY_TYPE } // End namespace CGAL diff --git a/Surface_mesh/doc/Surface_mesh/PackageDescription.txt b/Surface_mesh/doc/Surface_mesh/PackageDescription.txt index 6d8ed2ad4a7..5d00ad2253f 100644 --- a/Surface_mesh/doc/Surface_mesh/PackageDescription.txt +++ b/Surface_mesh/doc/Surface_mesh/PackageDescription.txt @@ -1,6 +1,6 @@ /// \defgroup PkgSurface_mesh Surface Mesh Reference -/*! Draw. +/*! \code #include \endcode @@ -39,7 +39,8 @@ and faces is much simpler and can be used at runtime and not at compile time.} - `CGAL::Surface_mesh

` \cgalCRPSection{Draw a Surface Mesh} -- `CGAL::draw` + +- \link PkgDrawSurfaceMesh CGAL::draw() \endlink */ diff --git a/Surface_mesh/doc/Surface_mesh/Surface_mesh.txt b/Surface_mesh/doc/Surface_mesh/Surface_mesh.txt index 9856b42bccc..754f49ac762 100644 --- a/Surface_mesh/doc/Surface_mesh/Surface_mesh.txt +++ b/Surface_mesh/doc/Surface_mesh/Surface_mesh.txt @@ -347,7 +347,7 @@ refering to the right vertices. \section SurfaceMeshDraw Draw a Surface Mesh \anchor ssecDrawSurfaceMesh -A surface mesh can be visualized by calling the `CGAL::draw()` function as shown in the following example. This function opens a new window showing the given surface mesh. The function is blocking, that is the program continues as soon as the user closes the window. +A surface mesh can be visualized by calling the \link PkgDrawSurfaceMesh CGAL::draw() \endlink as shown in the following example. This function opens a new window showing the given surface mesh. A call to this function is blocking, that is the program continues as soon as the user closes the window. \cgalExample{Surface_mesh/draw_surface_mesh.cpp} diff --git a/Surface_mesh/examples/Surface_mesh/CMakeLists.txt b/Surface_mesh/examples/Surface_mesh/CMakeLists.txt index 6f5b413973d..7ce13885fc5 100644 --- a/Surface_mesh/examples/Surface_mesh/CMakeLists.txt +++ b/Surface_mesh/examples/Surface_mesh/CMakeLists.txt @@ -38,10 +38,12 @@ if ( CGAL_FOUND ) create_single_source_cgal_program( "sm_properties.cpp" ) create_single_source_cgal_program("draw_surface_mesh.cpp") + create_single_source_cgal_program("sm_draw_small_faces.cpp") if(CGAL_Qt5_FOUND ) target_link_libraries(draw_surface_mesh PUBLIC CGAL::CGAL_Qt5) + target_link_libraries(sm_draw_small_faces PUBLIC CGAL::CGAL_Qt5) endif() - + else() message(STATUS "This program requires the CGAL library, and will not be compiled.") diff --git a/Surface_mesh/examples/Surface_mesh/draw_surface_mesh.cpp b/Surface_mesh/examples/Surface_mesh/draw_surface_mesh.cpp index 4735193c89f..a04a092fc5c 100644 --- a/Surface_mesh/examples/Surface_mesh/draw_surface_mesh.cpp +++ b/Surface_mesh/examples/Surface_mesh/draw_surface_mesh.cpp @@ -10,7 +10,7 @@ typedef CGAL::Surface_mesh Mesh; int main(int argc, char* argv[]) { Mesh sm1; - std::ifstream in1((argc>1)?argv[1]:"data/triangle.off"); + std::ifstream in1((argc>1)?argv[1]:"data/elephant.off"); in1 >> sm1; CGAL::draw(sm1); diff --git a/Surface_mesh/examples/Surface_mesh/draw_surface_mesh_small_faces.h b/Surface_mesh/examples/Surface_mesh/draw_surface_mesh_small_faces.h new file mode 100644 index 00000000000..b50c3a36a27 --- /dev/null +++ b/Surface_mesh/examples/Surface_mesh/draw_surface_mesh_small_faces.h @@ -0,0 +1,294 @@ +// Copyright (c) 2018 GeometryFactory (France) +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ +// +// Author(s) : Guillaume Damiand + +#ifndef CGAL_DRAW_SURFACE_MESH_SMALL_FACES_H +#define CGAL_DRAW_SURFACE_MESH_SMALL_FACES_H + +#include +#include + +#ifdef CGAL_USE_BASIC_VIEWER + +#include +#include + +template +class SimpleSurfaceMeshWithSmallFacesViewerQt : public CGAL::Basic_viewer_qt +{ + typedef CGAL::Basic_viewer_qt Base; + typedef typename SM::Point Point; + typedef typename CGAL::Kernel_traits::Kernel Kernel; + typedef typename SM::Vertex_index vertex_descriptor; + typedef typename SM::Face_index face_descriptor; + typedef typename SM::Edge_index edge_descriptor; + typedef typename SM::Halfedge_index halfedge_descriptor; + typedef typename Kernel::FT FT; + +public: + /// Construct the viewer. + /// @param amesh the surface mesh to view + SimpleSurfaceMeshWithSmallFacesViewerQt(QWidget* parent, + SM& amesh) : + // First draw: no vertex; no edge, faces; multi-color; inverse normal + Base(parent, "Surface mesh viewer with small faces", false, false, true, false, false), + sm(amesh), + m_threshold(85), + m_draw_small_faces(true), + m_draw_big_faces(true) + { + // Add custom key description (see keyPressEvent). + setKeyDescription(Qt::Key_I, "Increment threshold for small faces"); + setKeyDescription(Qt::Key_D, "Decrement threshold for small faces"); + setKeyDescription(Qt::Key_S, "Draw small faces only , big faces only, both"); + + if (sm.faces().begin()!=sm.faces().end()) + { + bool exist; + typename SM::template Property_map faces_size; + boost::tie(faces_size, exist)=sm.template property_map("f:size"); + CGAL_assertion(exist); + + m_min_size=faces_size[*(sm.faces().begin())]; + m_max_size=m_min_size; + FT cur_size; + + for (typename SM::Face_range::iterator f=sm.faces().begin(); f!=sm.faces().end(); ++f) + { + cur_size=faces_size[*f]; + if (cur_sizem_max_size) m_max_size=cur_size; + } + } + + compute_elements(); + } + +protected: + void compute_face(face_descriptor fh) + { + // [Face creation] + bool issmall=false; + + // Default color of faces + CGAL::Color c(75,160,255); + + // Compare the size of the face with the % m_threshold + bool exist; + typename SM::template Property_map faces_size; + boost::tie(faces_size, exist)=sm.template property_map("f:size"); + CGAL_assertion(exist); + + // It it is smaller, color the face in red. + if (get(faces_size, fh)::null_face()) + { compute_face(*f); } + } + + for (typename SM::Edge_range::iterator e=sm.edges().begin(); + e!=sm.edges().end(); ++e) + { compute_edge(*e); } + + for (typename SM::Vertex_range::iterator v=sm.vertices().begin(); + v!=sm.vertices().end(); ++v) + { compute_vertex(*v); } + } + + // 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 + virtual void keyPressEvent(QKeyEvent *e) + { + /// [Keypress] + const ::Qt::KeyboardModifiers modifiers = e->modifiers(); + if ((e->key()==Qt::Key_I) && (modifiers==Qt::NoButton)) + { + if (m_threshold<100) { ++m_threshold; } + displayMessage(QString("Threshold percent=%1%.").arg(m_threshold)); + compute_elements(); + redraw(); + } + else if ((e->key()==Qt::Key_D) && (modifiers==Qt::NoButton)) + { + if (m_threshold>0) { --m_threshold; } + displayMessage(QString("Threshold percent=%1%.").arg(m_threshold)); + compute_elements(); + redraw(); + } + else if ((e->key()==Qt::Key_S) && (modifiers==Qt::NoButton)) + { + QString msg; + if (m_draw_small_faces) + { + if (m_draw_big_faces) + { + m_draw_big_faces=false; + msg=QString("Draw small faces only."); + } + else + { + m_draw_big_faces=true; m_draw_small_faces=false; + msg=QString("Draw big faces only."); + } + } + else + { + assert(m_draw_big_faces); + m_draw_small_faces=true; + msg=QString("Draw small and big faces."); + } + + displayMessage(msg); + compute_elements(); + redraw(); + } + else + { + // Call the base method to process others/classicals key + Base::keyPressEvent(e); + } + /// [Keypress] + } + +protected: + typename Kernel::Vector_3 get_face_normal(halfedge_descriptor he) + { + typename Kernel::Vector_3 normal=CGAL::NULL_VECTOR; + halfedge_descriptor end=he; + unsigned int nb=0; + do + { + CGAL::internal::newell_single_step_3(sm.point(sm.source(he)), + sm.point(sm.target(he)), normal); + ++nb; + he=sm.next(he); + } + while (he!=end); + assert(nb>0); + return (typename Kernel::Construct_scaled_vector_3()(normal, 1.0/nb)); + } + + typename Kernel::Vector_3 get_vertex_normal(halfedge_descriptor he) + { + typename Kernel::Vector_3 normal=CGAL::NULL_VECTOR; + halfedge_descriptor end=he; + do + { + if (!sm.is_border(he)) + { + typename Kernel::Vector_3 n=get_face_normal(he); + normal=typename Kernel::Construct_sum_of_vectors_3()(normal, n); + } + he=sm.next(sm.opposite(he)); + } + while (he!=end); + + if (!typename Kernel::Equal_3()(normal, CGAL::NULL_VECTOR)) + { normal=(typename Kernel::Construct_scaled_vector_3() + (normal, 1.0/CGAL::sqrt(normal.squared_length()))); } + + return normal; + } + +protected: + SM& sm; + unsigned int m_threshold; + FT m_min_size, m_max_size; + bool m_draw_small_faces; + bool m_draw_big_faces; +}; + +template +void draw_surface_mesh_with_small_faces(CGAL::Surface_mesh& amesh) +{ +#if defined(CGAL_TEST_SUITE) + bool cgal_test_suite=true; +#else + bool cgal_test_suite=qEnvironmentVariableIsSet("CGAL_TEST_SUITE"); +#endif + + if (!cgal_test_suite) + { + int argc=1; + const char* argv[2]={"surface_mesh_viewer","\0"}; + QApplication app(argc,const_cast(argv)); + SimpleSurfaceMeshWithSmallFacesViewerQt> + mainwindow(app.activeWindow(), amesh); + mainwindow.show(); + app.exec(); + } +} + +#else // CGAL_USE_BASIC_VIEWER + +template +void draw_surface_mesh_with_small_faces(CGAL::Surface_mesh&) +{ + std::cerr<<"Impossible to draw, CGAL_USE_BASIC_VIEWER is not defined."< +#include +#include +#include +#include +#include +#include +#include "draw_surface_mesh_small_faces.h" + +typedef CGAL::Simple_cartesian K; +typedef CGAL::Surface_mesh Mesh; +typedef Mesh::Vertex_index vertex_descriptor; +typedef Mesh::Face_index face_descriptor; +typedef K::FT FT; + +int main(int argc, char* argv[]) +{ + Mesh sm; + std::ifstream input((argc>1)?argv[1]:"data/elephant.off"); + input>>sm; + + CGAL::Polygon_mesh_processing::triangulate_faces(sm); + + Mesh::Property_map faces_size; + bool created; + boost::tie(faces_size, created)=sm.add_property_map("f:size",0.); + CGAL_assertion(created); + + BOOST_FOREACH(face_descriptor fd, sm.faces()) + { faces_size[fd]=CGAL::Polygon_mesh_processing::face_area(fd, sm); } + + draw_surface_mesh_with_small_faces(sm); + + sm.remove_property_map(faces_size); + + return EXIT_SUCCESS; +} + diff --git a/Surface_mesh/include/CGAL/draw_surface_mesh.h b/Surface_mesh/include/CGAL/draw_surface_mesh.h index 6d34dd96f90..bfd76350505 100644 --- a/Surface_mesh/include/CGAL/draw_surface_mesh.h +++ b/Surface_mesh/include/CGAL/draw_surface_mesh.h @@ -41,6 +41,7 @@ void draw(const SM& asm); #ifdef CGAL_USE_BASIC_VIEWER +#include #include namespace CGAL @@ -202,16 +203,16 @@ protected: const ColorFunctor& m_fcolor; }; -template -void draw(const SM& amesh, - const char* title, - bool nofill, - const ColorFunctor& fcolor) +// Specialization of draw function. +template +void draw(const Surface_mesh& amesh, + const char* title="Surface_mesh Basic Viewer", + bool nofill=false) { #if defined(CGAL_TEST_SUITE) bool cgal_test_suite=true; #else - bool cgal_test_suite=false; + bool cgal_test_suite=qEnvironmentVariableIsSet("CGAL_TEST_SUITE"); #endif if (!cgal_test_suite) @@ -219,31 +220,14 @@ void draw(const SM& amesh, int argc=1; const char* argv[2]={"surface_mesh_viewer","\0"}; QApplication app(argc,const_cast(argv)); - SimpleSurfaceMeshViewerQt mainwindow(app.activeWindow(), - amesh, - title, - nofill, - fcolor); + DefaultColorFunctorSM fcolor; + SimpleSurfaceMeshViewerQt, DefaultColorFunctorSM> + mainwindow(app.activeWindow(), amesh, title, nofill, fcolor); mainwindow.show(); app.exec(); } } -template -void draw(const SM& amesh, const char* title, bool nofill) -{ - DefaultColorFunctorSM c; - draw(amesh, title, nofill, c); -} - -template -void draw(const SM& amesh, const char* title) -{ draw(amesh, title, false); } - -template -void draw(const SM& amesh) -{ draw(amesh, "Basic Surface_mesh Viewer"); } - } // End namespace CGAL #endif // CGAL_USE_BASIC_VIEWER diff --git a/Triangulation_2/doc/Triangulation_2/CGAL/draw_triangulation_2.h b/Triangulation_2/doc/Triangulation_2/CGAL/draw_triangulation_2.h index 11d13a005a1..88c9644d30a 100644 --- a/Triangulation_2/doc/Triangulation_2/CGAL/draw_triangulation_2.h +++ b/Triangulation_2/doc/Triangulation_2/CGAL/draw_triangulation_2.h @@ -3,7 +3,7 @@ namespace CGAL { /*! \ingroup PkgDrawTriangulation2 -Open a new window and draw `at2`, a model of the `TriangulationDataStructure_2` concept. The function is blocking, that is the program continues as soon as the user closes the window. This function requires CGAL_Qt5, and is only available if the flag CGAL_USE_BASIC_VIEWER is defined at compile time. +opens a new window and draws `at2`, a model of the `TriangulationDataStructure_2` concept. A call to this function is blocking, that is the program continues as soon as the user closes the window. This function requires CGAL_Qt5, and is only available if the flag CGAL_USE_BASIC_VIEWER is defined at compile time. \tparam T2 a model of the `TriangulationDataStructure_2` concept. \param at2 the triangulation to draw. diff --git a/Triangulation_2/doc/Triangulation_2/PackageDescription.txt b/Triangulation_2/doc/Triangulation_2/PackageDescription.txt index d199da9f5a3..5cb5b93e1b2 100644 --- a/Triangulation_2/doc/Triangulation_2/PackageDescription.txt +++ b/Triangulation_2/doc/Triangulation_2/PackageDescription.txt @@ -13,7 +13,7 @@ /// \defgroup PkgTriangulation2Miscellaneous Miscellaneous /// \ingroup PkgTriangulation2Ref -/*! Draw. +/*! \code #include \endcode @@ -107,7 +107,7 @@ are described in Chapter \ref PkgTDS2Ref "2D Triangulation Data Structure". - \link CGAL::Triangulation_2::Locate_type `CGAL::Triangulation_2::Locate_type` \endlink \cgalCRPSection{Draw a Triangulation 2} -- `CGAL::draw` +- \link PkgDrawTriangulation2 CGAL::draw() \endlink */ diff --git a/Triangulation_2/doc/Triangulation_2/Triangulation_2.txt b/Triangulation_2/doc/Triangulation_2/Triangulation_2.txt index 6bee3b8a77f..742ea922347 100644 --- a/Triangulation_2/doc/Triangulation_2/Triangulation_2.txt +++ b/Triangulation_2/doc/Triangulation_2/Triangulation_2.txt @@ -493,7 +493,7 @@ Finally points on the convex hull are written to cout. \subsection Triangulation2Draw Draw a 2D Triangulation \anchor ssecDrawT2 -A 2D triangulation can be visualized by calling the `CGAL::draw()` function as shown in the following example. This function opens a new window showing the given 2D triangulation. The function is blocking, that is the program continues as soon as the user closes the window. +A 2D triangulation can be visualized by calling the \link PkgDrawTriangulation2 CGAL::draw() \endlink function as shown in the following example. This function opens a new window showing the given 2D triangulation. A call to this function is blocking, that is the program continues as soon as the user closes the window. \cgalExample{Triangulation_2/draw_triangulation_2.cpp} diff --git a/Triangulation_2/include/CGAL/draw_triangulation_2.h b/Triangulation_2/include/CGAL/draw_triangulation_2.h index 193e12e20ea..bfa1fbaa04c 100644 --- a/Triangulation_2/include/CGAL/draw_triangulation_2.h +++ b/Triangulation_2/include/CGAL/draw_triangulation_2.h @@ -26,6 +26,7 @@ #ifdef CGAL_USE_BASIC_VIEWER +#include #include namespace CGAL @@ -135,48 +136,35 @@ protected: bool m_nofaces; const ColorFunctor& m_fcolor; }; + +// Specialization of draw function. +#define CGAL_T2_TYPE CGAL::Triangulation_2 -template -void draw(const T2& at2, - const char* title, - bool nofill, - const ColorFunctor& fcolor) +template +void draw(const CGAL_T2_TYPE& at2, + const char* title="Triangulation_2 Basic Viewer", + bool nofill=false) { #if defined(CGAL_TEST_SUITE) bool cgal_test_suite=true; #else - bool cgal_test_suite=false; + bool cgal_test_suite=qEnvironmentVariableIsSet("CGAL_TEST_SUITE"); #endif - + if (!cgal_test_suite) { int argc=1; const char* argv[2]={"t2_viewer","\0"}; - QApplication app(argc,const_cast(argv)); - SimpleTriangulation2ViewerQt mainwindow(app.activeWindow(), - at2, - title, - nofill, - fcolor); + QApplication app(argc,const_cast(argv)); + DefaultColorFunctorT2 fcolor; + SimpleTriangulation2ViewerQt + mainwindow(app.activeWindow(), at2, title, nofill, fcolor); mainwindow.show(); app.exec(); } } -template -void draw(const T2& at2, const char* title, bool nofill) -{ - DefaultColorFunctorT2 c; - draw(at2, title, nofill, c); -} - -template -void draw(const T2& at2, const char* title) -{ draw(at2, title, false); } - -template -void draw(const T2& at2) -{ draw(at2, "Basic T2 Viewer"); } +#undef CGAL_T2_TYPE } // End namespace CGAL diff --git a/Triangulation_3/doc/Triangulation_3/CGAL/draw_triangulation_3.h b/Triangulation_3/doc/Triangulation_3/CGAL/draw_triangulation_3.h index b7704903210..4b33db6062f 100644 --- a/Triangulation_3/doc/Triangulation_3/CGAL/draw_triangulation_3.h +++ b/Triangulation_3/doc/Triangulation_3/CGAL/draw_triangulation_3.h @@ -3,7 +3,7 @@ namespace CGAL { /*! \ingroup PkgDrawTriangulation3 -Open a new window and draw `at3`, a model of the `TriangulationDataStructure_3` concept. The function is blocking, that is the program continues as soon as the user closes the window. This function requires CGAL_Qt5, and is only available if the flag CGAL_USE_BASIC_VIEWER is defined at compile time. +opens a new window and draws `at3`, a model of the `TriangulationDataStructure_3` concept. A call to this function is blocking, that is the program continues as soon as the user closes the window. This function requires CGAL_Qt5, and is only available if the flag CGAL_USE_BASIC_VIEWER is defined at compile time. \tparam T3 a model of the `TriangulationDataStructure_3` concept. \param at3 the triangulation to draw. diff --git a/Triangulation_3/doc/Triangulation_3/PackageDescription.txt b/Triangulation_3/doc/Triangulation_3/PackageDescription.txt index a7b80f3c621..1804cdccaf7 100644 --- a/Triangulation_3/doc/Triangulation_3/PackageDescription.txt +++ b/Triangulation_3/doc/Triangulation_3/PackageDescription.txt @@ -13,7 +13,7 @@ /// \defgroup PkgTriangulation3VertexCellClasses Vertex and Cell Classes /// \ingroup PkgTriangulation3Ref -/*! Draw. +/*! \code #include \endcode @@ -118,7 +118,8 @@ is opposite to the vertex with the same index. See - `CGAL::Triangulation_3::Locate_type` \cgalCRPSection{Draw a Triangulation 3} -- `CGAL::draw` + +- \link PkgDrawTriangulation3 CGAL::draw() \endlink */ diff --git a/Triangulation_3/doc/Triangulation_3/Triangulation_3.txt b/Triangulation_3/doc/Triangulation_3/Triangulation_3.txt index 4284b30705b..66fdb0cdee7 100644 --- a/Triangulation_3/doc/Triangulation_3/Triangulation_3.txt +++ b/Triangulation_3/doc/Triangulation_3/Triangulation_3.txt @@ -557,7 +557,7 @@ removal of the first 100,000 vertices. \subsection Triangulation3Draw Draw a 3D Triangulation \anchor ssecDrawT3 -A 3D triangulation can be visualized by calling the `CGAL::draw()` function as shown in the following example. This function opens a new window showing the given 3D triangulation. The function is blocking, that is the program continues as soon as the user closes the window. +A 3D triangulation can be visualized by calling the \link PkgDrawTriangulation3 CGAL::draw() \endlink function as shown in the following example. This function opens a new window showing the given 3D triangulation. A call to this function is blocking, that is the program continues as soon as the user closes the window. \cgalExample{Triangulation_3/draw_triangulation_3.cpp} diff --git a/Triangulation_3/include/CGAL/draw_triangulation_3.h b/Triangulation_3/include/CGAL/draw_triangulation_3.h index 065eba016a3..ea9520ae0cb 100644 --- a/Triangulation_3/include/CGAL/draw_triangulation_3.h +++ b/Triangulation_3/include/CGAL/draw_triangulation_3.h @@ -26,6 +26,7 @@ #ifdef CGAL_USE_BASIC_VIEWER +#include #include namespace CGAL @@ -141,49 +142,35 @@ protected: bool m_nofaces; const ColorFunctor& m_fcolor; }; - -template -void draw(const T3& at3, - const char* title, - bool nofill, - const ColorFunctor& fcolor) -{ +// Specialization of draw function. +#define CGAL_T3_TYPE CGAL::Triangulation_3 + +template +void draw(const CGAL_T3_TYPE& at3, + const char* title="T3 Basic Viewer", + bool nofill=false) +{ #if defined(CGAL_TEST_SUITE) bool cgal_test_suite=true; #else - bool cgal_test_suite=false; + bool cgal_test_suite=qEnvironmentVariableIsSet("CGAL_TEST_SUITE"); #endif - + if (!cgal_test_suite) { int argc=1; const char* argv[2]={"t3_viewer","\0"}; QApplication app(argc,const_cast(argv)); - SimpleTriangulation3ViewerQt mainwindow(app.activeWindow(), - at3, - title, - nofill, - fcolor); + DefaultColorFunctorT3 fcolor; + SimpleTriangulation3ViewerQt + mainwindow(app.activeWindow(), at3, title, nofill, fcolor); mainwindow.show(); app.exec(); } } -template -void draw(const T3& at3, const char* title, bool nofill) -{ - DefaultColorFunctorT3 c; - draw(at3, title, nofill, c); -} - -template -void draw(const T3& at3, const char* title) -{ draw(at3, title, false); } - -template -void draw(const T3& at3) -{ draw(at3, "Basic T3 Viewer"); } +#undef CGAL_T3_TYPE } // End namespace CGAL