Work on generic display function.

This commit is contained in:
Guillaume Damiand 2017-11-15 18:59:20 +01:00 committed by Maxime Gimeno
parent 592d770dea
commit 9e4f2870b8
8 changed files with 1358 additions and 53 deletions

File diff suppressed because it is too large Load Diff

View File

@ -17,11 +17,7 @@ find_package(OpenGL REQUIRED)
add_definitions(${QT_DEFINITIONS})
add_definitions(-DQT_NO_KEYWORDS)
include_directories( ${QGLVIEWER_INCLUDE_DIR} )
add_definitions(${QGLVIEWER_DEFINITIONS})
set (BASIC_VIEWER_LIBRARIES ${QT_LIBRARIES} ${QGLVIEWER_LIBRARIES}
${OPENGL_gl_LIBRARY}) # ${OPENGL_glu_LIBRARY}
set (BASIC_VIEWER_LIBRARIES ${QT_LIBRARIES} )
set(BASIC_VIEWER_MODULES Xml OpenGL)

View File

@ -12,11 +12,10 @@ endif()
# If you want to visualize a linear cell complex, you can use the following viewer
# based on qt. Just uncomment the following two lines, plus the lines qt5_use_modules below
# find_package(CGAL COMPONENTS Qt5)
# include("CMakeBasicViewerQt.inc")
find_package(CGAL COMPONENTS Qt5)
# If you don't want to visualize, use the following line (otherwise comment it)
find_package(CGAL QUIET)
# find_package(CGAL QUIET)
# For Gprof.
# ADD_DEFINITIONS("-pg")
@ -27,6 +26,7 @@ find_package(CGAL QUIET)
if ( CGAL_FOUND )
include( ${CGAL_USE_FILE} )
find_package(CGALBasicViewer)
include( CGAL_CreateSingleSourceCGALProgram )
include_directories(BEFORE ../../include)
@ -44,10 +44,6 @@ if ( CGAL_FOUND )
add_executable(voronoi_2 voronoi_2.cpp)
target_link_libraries(voronoi_2 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES}
${BASIC_VIEWER_LIBRARIES})
if (USE_BASIC_VIEWER)
qt5_use_modules(voronoi_2 ${BASIC_VIEWER_MODULES})
endif(USE_BASIC_VIEWER)
add_executable(voronoi_3 voronoi_3.cpp)
target_link_libraries(voronoi_3 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES}
${BASIC_VIEWER_LIBRARIES})
@ -60,11 +56,7 @@ if ( CGAL_FOUND )
add_executable(linear_cell_complex_3_operations linear_cell_complex_3_operations.cpp)
target_link_libraries(linear_cell_complex_3_operations ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES}
${BASIC_VIEWER_LIBRARIES})
if (USE_BASIC_VIEWER)
qt5_use_modules(linear_cell_complex_3_operations ${BASIC_VIEWER_MODULES})
endif(USE_BASIC_VIEWER)
${BASIC_VIEWER_LIBRARIES})
else()
message(STATUS "This program requires the CGAL library, "

View File

@ -2,9 +2,9 @@
#include <CGAL/Linear_cell_complex_for_generalized_map.h>
#include <vector>
/* If you want to use a viewer, you can use qglviewer. */
#ifdef CGAL_USE_BASIC_VIEWER
#include "linear_cell_complex_3_viewer_qt.h"
#include "CGAL/Linear_cell_complex_viewer_qt.h"
#endif
typedef CGAL::Linear_cell_complex_for_combinatorial_map<3> LCC_3_cmap;
@ -55,7 +55,7 @@ void run_test()
lcc.other_orientation(lcc.template opposite<2>(lcc.previous(dh3))));
#ifdef CGAL_USE_BASIC_VIEWER
display_lcc(lcc);
display(lcc);
#endif // CGAL_USE_BASIC_VIEWER
lcc.insert_cell_1_in_cell_2(lcc.next(dh1),
@ -76,7 +76,7 @@ void run_test()
<< lcc.is_valid() << std::endl;
#ifdef CGAL_USE_BASIC_VIEWER
display_lcc(lcc);
display(lcc);
#endif // CGAL_USE_BASIC_VIEWER
}

View File

@ -6,9 +6,9 @@
#include <iostream>
#include <fstream>
/* If you want to use a viewer, you can use qglviewer. */
#ifdef CGAL_USE_BASIC_VIEWER
#include "linear_cell_complex_3_viewer_qt.h"
#include "CGAL/Linear_cell_complex_viewer_qt.h"
#endif
// This example works both with cmap and gmap as combinatorial data structure.
@ -58,7 +58,7 @@ void display_voronoi(LCC_2& alcc, Dart_handle adart)
<< std::endl;
#ifdef CGAL_USE_BASIC_VIEWER
display_lcc(alcc);
display(alcc);
#endif // CGAL_USE_BASIC_VIEWER
}

View File

@ -5,9 +5,8 @@
#include <iostream>
#include <fstream>
/* If you want to use a viewer, you can use one qglviewer. */
#ifdef CGAL_USE_BASIC_VIEWER
#include "linear_cell_complex_3_viewer_qt.h"
#include <CGAL/Linear_cell_complex_viewer_qt.h>
#endif
/* // If you want to use exact constructions.
@ -61,7 +60,7 @@ void display_voronoi(LCC_3& alcc, Dart_handle adart)
<< std::endl;
#ifdef CGAL_USE_BASIC_VIEWER
display_lcc(alcc);
display(alcc);
#endif // CGAL_USE_BASIC_VIEWER
}

View File

@ -14,14 +14,13 @@
//
// $URL$
// $Id$
// SPDX-License-Identifier: LGPL-3.0+
//
// Author(s) : Guillaume Damiand <guillaume.damiand@liris.cnrs.fr>
#ifndef CGAL_LCC_3_VIEWER_QT_H
#define CGAL_LCC_3_VIEWER_QT_H
#ifndef CGAL_LCC_VIEWER_QT_H
#define CGAL_LCC_VIEWER_QT_H
#include "basic_viewer.h"
#include "CGAL/Qt/Basic_viewer.h"
#include <CGAL/Linear_cell_complex.h>
#include <CGAL/Cartesian_converter.h>
#include <CGAL/Random.h>
@ -30,6 +29,20 @@ typedef CGAL::Exact_predicates_inexact_constructions_kernel Local_kernel;
typedef Local_kernel::Point_3 Local_point;
typedef Local_kernel::Vector_3 Local_vector;
CGAL::Color get_random_color(CGAL::Random& random)
{
CGAL::Color res;
do
{
res=CGAL::Color(random.get_int(0,256),
random.get_int(0,256),
random.get_int(0,256));
}
while(res.red()==255 && res.green()==255 && res.blue()==255);
return res;
}
// Default color functor; user can change it to have its own face color
struct DefaultColorFunctor
{
@ -42,15 +55,7 @@ struct DefaultColorFunctor
// Here dh is the smaller dart of its face
CGAL::Random random(alcc.darts().index(dh));
CGAL::Color res;
do
{
res=CGAL::Color(random.get_int(0,256),
random.get_int(0,256),
random.get_int(0,256));
}
while(res.red()==255 && res.green()==255 && res.blue()==255);
return res;
return get_random_color(random);
}
};
@ -142,7 +147,10 @@ protected:
if (c.red()<60 || c.green()<60 || c.blue()<60)
mono_face_begin();
else
{
// c=CGAL::Color(100,100,100);
colored_face_begin(c);
}
cur=dh;
do
@ -158,19 +166,36 @@ protected:
void compute_edge(Dart_const_handle dh)
{
CGAL::Random random((unsigned long int)&*dh);
CGAL::Color c=get_random_color(random); // TODO REMOVE LATER
Local_point p1 = geomutils.get_point(lcc, dh);
Dart_const_handle d2 = lcc.other_extremity(dh);
if ( d2!=NULL )
if (d2!=NULL)
{
Local_point p2 = geomutils.get_point(lcc, d2);
add_mono_segment(p1, p2);
if (c.red()<60 || c.green()<60 || c.blue()<60)
add_mono_segment(p1, p2);
else
{
c=CGAL::Color(100,100,100);
add_colored_segment(p1, p2, c); // TODO REMOVE LATER
}
}
}
void compute_vertex(Dart_const_handle dh, bool& empty)
void compute_vertex(Dart_const_handle dh)
{
CGAL::Random random((unsigned long int)&*dh); // TODO REMOVE LATER
CGAL::Color c=get_random_color(random);
Local_point p = geomutils.get_point(lcc, dh);
add_mono_point(p);
if (c.red()<60 || c.green()<60 || c.blue()<60)
add_mono_point(p);
else
{ //c=CGAL::Color(100,100,100);
add_colored_point(p, c); // TODO REMOVE LATER
}
}
void compute_elements()
@ -181,8 +206,6 @@ protected:
unsigned int markedges = lcc.get_new_mark();
unsigned int markvertices = lcc.get_new_mark();
bool empty = true;
for (typename LCC::Dart_range::const_iterator it=lcc.darts().begin(),
itend=lcc.darts().end(); it!=itend; ++it )
{
@ -200,7 +223,7 @@ protected:
if ( !lcc.is_marked(it, markvertices) )
{
compute_vertex(it, empty);
compute_vertex(it);
CGAL::mark_cell<LCC, 0>(lcc, it, markvertices);
}
}
@ -223,10 +246,10 @@ protected:
};
template<class LCC, class ColorFunctor=DefaultColorFunctor>
void display_lcc(const LCC& alcc,
const char* title="",
bool nofill=false)
template<class LCC, class ColorFunctor>
void display(const LCC& alcc,
const char* title="",
bool nofill=false)
{
int argc=1;
@ -239,4 +262,10 @@ void display_lcc(const LCC& alcc,
app.exec();
}
#endif // CGAL_LCC_3_VIEWER_QT_H
template<class LCC>
void display(const LCC& alcc,
const char* title="",
bool nofill=false)
{ return display<LCC, DefaultColorFunctor>(alcc, title, nofill); }
#endif // CGAL_LCC_VIEWER_QT_H

View File

@ -10,13 +10,14 @@ cmake_minimum_required(VERSION 2.8.10)
# based on qt. Just uncomment the following two lines, plus the lines qt5_use_modules below
find_package(CGAL COMPONENTS Qt5)
include("CMakeBasicViewerQt.inc")
# If you don't want to visualize, use the following line (otherwise comment it)
# find_package(CGAL QUIET)
if ( CGAL_FOUND )
include( ${CGAL_USE_FILE} )
find_package(CGALBasicViewer)
include( CGAL_CreateSingleSourceCGALProgram )