mirror of https://github.com/CGAL/cgal
Merge branch 'Polyhedron-new_opengl_REBASED_to_ignore_reindentations-gf' into CGAL-Qt5_support-GF
Conflicts: Polyhedron/demo/Polyhedron/CMakeLists.txt Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_3_plugin.cpp Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_3_plugin_cgal_code.cpp Polyhedron/demo/Polyhedron/Polyhedron_demo_selection_plugin.cpp Polyhedron/demo/Polyhedron/Polyhedron_demo_trivial_plugin.cpp Polyhedron/demo/Polyhedron/Scene.cpp
This commit is contained in:
commit
ed3298ee2f
|
|
@ -23,12 +23,15 @@
|
|||
|
||||
#include <CGAL/Bbox_3.h>
|
||||
#include <CGAL/gl.h>
|
||||
#include <vector>
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
template<typename Primitive, typename Node>
|
||||
struct AABB_drawing_traits
|
||||
{
|
||||
std::vector<float> *v_edges;
|
||||
|
||||
typedef CGAL::Bbox_3 Bbox;
|
||||
bool go_further() { return true; }
|
||||
|
||||
|
|
@ -45,7 +48,7 @@ struct AABB_drawing_traits
|
|||
}
|
||||
|
||||
// draw bbox
|
||||
static void gl_draw(const Bbox& bb)
|
||||
void gl_draw(const Bbox& bb)
|
||||
{
|
||||
::glBegin(GL_LINES);
|
||||
gl_draw_edge(bb.xmin(), bb.ymin(), bb.zmin(),
|
||||
|
|
@ -79,11 +82,16 @@ struct AABB_drawing_traits
|
|||
::glEnd();
|
||||
}
|
||||
|
||||
static void gl_draw_edge(double px, double py, double pz,
|
||||
void gl_draw_edge(double px, double py, double pz,
|
||||
double qx, double qy, double qz)
|
||||
{
|
||||
::glVertex3d(px,py,pz);
|
||||
::glVertex3d(qx,qy,qz);
|
||||
v_edges->push_back((float)px);
|
||||
v_edges->push_back((float)py);
|
||||
v_edges->push_back((float)pz);
|
||||
|
||||
v_edges->push_back((float)qx);
|
||||
v_edges->push_back((float)qy);
|
||||
v_edges->push_back((float)qz);
|
||||
}
|
||||
}; // AABB_drawing_traits
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -61,8 +61,7 @@ find_package(CGAL REQUIRED COMPONENTS Qt5)
|
|||
include( ${CGAL_USE_FILE} )
|
||||
find_package(Qt5 COMPONENTS OpenGL Script Xml ScriptTools)
|
||||
|
||||
# Find Glew (optional), for splatting
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/GlSplat/cmake)
|
||||
# Find Glew (required)
|
||||
find_package(GLEW)
|
||||
set(GLEW_FOUND FALSE)#TEMP to be removed once GlSplat has been redone
|
||||
# Find OpenGL
|
||||
|
|
@ -72,6 +71,7 @@ find_package(OpenGL)
|
|||
if(Qt5_FOUND)
|
||||
include_directories( ${QT_INCLUDE_DIR}/QtScriptTools )
|
||||
find_package(QGLViewer )
|
||||
|
||||
endif(Qt5_FOUND)
|
||||
if(GLEW_FOUND)
|
||||
include_directories ( ${GLEW_INCLUDE_DIR} )
|
||||
|
|
@ -80,17 +80,20 @@ else(GLEW_FOUND)
|
|||
message(STATUS "NOTICE: GLEW library is not found. Splat rendering will not be available.")
|
||||
endif(GLEW_FOUND)
|
||||
|
||||
|
||||
find_package(Eigen3 3.1.0) #(requires 3.1.0 or greater)
|
||||
if (EIGEN3_FOUND)
|
||||
include( ${EIGEN3_USE_FILE} )
|
||||
endif(EIGEN3_FOUND)
|
||||
|
||||
|
||||
if(CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND)
|
||||
|
||||
set(Boost_USE_MULTITHREADED ON)
|
||||
find_package(Boost COMPONENTS thread system)
|
||||
|
||||
include_directories ( ${QGLVIEWER_INCLUDE_DIR} )
|
||||
include_directories ( ${GLEW_INCLUDE_DIR} )
|
||||
|
||||
qt5_wrap_ui( MainWindowUI_files MainWindow.ui )
|
||||
qt5_wrap_ui( FileLoaderDialogUI_files FileLoaderDialog.ui )
|
||||
|
|
@ -224,6 +227,7 @@ if(CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND)
|
|||
add_item(scene_polygon_soup_item Scene_polygon_soup_item.cpp)# Scene_polygon_soup_item.moc)
|
||||
target_link_libraries(scene_polygon_soup_item scene_polyhedron_item)
|
||||
add_item(scene_nef_polyhedron_item Scene_nef_polyhedron_item.cpp# Scene_nef_polyhedron_item.moc
|
||||
|
||||
Scene_nef_rendering.cpp)
|
||||
target_link_libraries(scene_nef_polyhedron_item scene_polyhedron_item)
|
||||
add_item(scene_points_with_normal_item Scene_points_with_normal_item.cpp)# Scene_points_with_normal_item.moc)
|
||||
|
|
@ -516,4 +520,5 @@ else (CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND)
|
|||
|
||||
message(STATUS "NOTICE: This demo requires ${POLYHEDRON_MISSING_DEPS}and will not be compiled.")
|
||||
|
||||
|
||||
endif (CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND)
|
||||
|
|
|
|||
|
|
@ -35,10 +35,11 @@ interpolate(const double v) const
|
|||
{
|
||||
return prev->second;
|
||||
}
|
||||
|
||||
|
||||
const double& a = prev->first;
|
||||
const double& b = next->first;
|
||||
return (b-v)/(b-a) * prev->second + (v-a)/(b-a) * next->second;
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -1,105 +0,0 @@
|
|||
# Copyright (c) 2009 Boudewijn Rempt <boud@valdyas.org>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
#
|
||||
# - try to find glew library and include files
|
||||
# GLEW_INCLUDE_DIR, where to find GL/glew.h, etc.
|
||||
# GLEW_LIBRARIES, the libraries to link against
|
||||
# GLEW_FOUND, If false, do not try to use GLEW.
|
||||
# Also defined, but not for general use are:
|
||||
# GLEW_GLEW_LIBRARY = the full path to the glew library.
|
||||
|
||||
IF (WIN32)
|
||||
|
||||
IF(CYGWIN)
|
||||
|
||||
FIND_PATH( GLEW_INCLUDE_DIR GL/glew.h)
|
||||
|
||||
FIND_LIBRARY( GLEW_GLEW_LIBRARY glew32
|
||||
${OPENGL_LIBRARY_DIR}
|
||||
/usr/lib/w32api
|
||||
/usr/X11R6/lib
|
||||
)
|
||||
|
||||
|
||||
ELSE(CYGWIN)
|
||||
|
||||
FIND_PATH( GLEW_INCLUDE_DIR GL/glew.h
|
||||
$ENV{GLEW_ROOT_PATH}/include
|
||||
)
|
||||
|
||||
FIND_LIBRARY( GLEW_GLEW_LIBRARY
|
||||
NAMES glew glew32
|
||||
PATHS
|
||||
$ENV{GLEW_ROOT_PATH}/lib
|
||||
${OPENGL_LIBRARY_DIR}
|
||||
)
|
||||
|
||||
ENDIF(CYGWIN)
|
||||
|
||||
ELSE (WIN32)
|
||||
|
||||
IF (APPLE)
|
||||
# These values for Apple could probably do with improvement.
|
||||
FIND_PATH( GLEW_INCLUDE_DIR glew.h
|
||||
/System/Library/Frameworks/GLEW.framework/Versions/A/Headers
|
||||
${OPENGL_LIBRARY_DIR}
|
||||
)
|
||||
SET(GLEW_GLEW_LIBRARY "-framework GLEW" CACHE STRING "GLEW library for OSX")
|
||||
SET(GLEW_cocoa_LIBRARY "-framework Cocoa" CACHE STRING "Cocoa framework for OSX")
|
||||
ELSE (APPLE)
|
||||
|
||||
FIND_PATH( GLEW_INCLUDE_DIR GL/glew.h
|
||||
/usr/include/GL
|
||||
/usr/openwin/share/include
|
||||
/usr/openwin/include
|
||||
/usr/X11R6/include
|
||||
/usr/include/X11
|
||||
/opt/graphics/OpenGL/include
|
||||
/opt/graphics/OpenGL/contrib/libglew
|
||||
)
|
||||
|
||||
FIND_LIBRARY( GLEW_GLEW_LIBRARY GLEW
|
||||
/usr/openwin/lib
|
||||
/usr/X11R6/lib
|
||||
)
|
||||
|
||||
ENDIF (APPLE)
|
||||
|
||||
ENDIF (WIN32)
|
||||
|
||||
SET( GLEW_FOUND "NO" )
|
||||
IF(GLEW_INCLUDE_DIR)
|
||||
IF(GLEW_GLEW_LIBRARY)
|
||||
# Is -lXi and -lXmu required on all platforms that have it?
|
||||
# If not, we need some way to figure out what platform we are on.
|
||||
SET( GLEW_LIBRARIES
|
||||
${GLEW_GLEW_LIBRARY}
|
||||
${GLEW_cocoa_LIBRARY}
|
||||
)
|
||||
SET( GLEW_FOUND "YES" )
|
||||
|
||||
#The following deprecated settings are for backwards compatibility with CMake1.4
|
||||
SET (GLEW_LIBRARY ${GLEW_LIBRARIES})
|
||||
SET (GLEW_INCLUDE_PATH ${GLEW_INCLUDE_DIR})
|
||||
|
||||
ENDIF(GLEW_GLEW_LIBRARY)
|
||||
ENDIF(GLEW_INCLUDE_DIR)
|
||||
|
||||
IF(GLEW_FOUND)
|
||||
IF(NOT GLEW_FIND_QUIETLY)
|
||||
MESSAGE(STATUS "Found Glew: ${GLEW_LIBRARIES}")
|
||||
ENDIF(NOT GLEW_FIND_QUIETLY)
|
||||
ELSE(GLEW_FOUND)
|
||||
IF(GLEW_FIND_REQUIRED)
|
||||
MESSAGE(FATAL_ERROR "Could not find Glew")
|
||||
ENDIF(GLEW_FIND_REQUIRED)
|
||||
ENDIF(GLEW_FOUND)
|
||||
|
||||
MARK_AS_ADVANCED(
|
||||
GLEW_INCLUDE_DIR
|
||||
GLEW_GLEW_LIBRARY
|
||||
GLEW_Xmu_LIBRARY
|
||||
GLEW_Xi_LIBRARY
|
||||
)
|
||||
|
|
@ -170,7 +170,8 @@ void Polyhedron_demo_corefinement_plugin::corefinement()
|
|||
new_item->setName(tr("boundary intersection"));
|
||||
new_item->setColor(Qt::green);
|
||||
new_item->setRenderingMode(Wireframe);
|
||||
scene->addItem(new_item);
|
||||
scene->addItem(new_item);
|
||||
new_item->changed();
|
||||
std::cout << "ok (" << time.elapsed() << " ms)" << std::endl;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,21 @@ class Q_DECL_EXPORT Scene_aabb_item : public Scene_item_with_display_list
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Scene_aabb_item(const AABB_tree& tree_) : tree(tree_) {}
|
||||
Scene_aabb_item(const AABB_tree& tree_) : tree(tree_)
|
||||
{
|
||||
positions_lines.resize(0);
|
||||
glGenVertexArrays(1, vao);
|
||||
//Generates an integer which will be used as ID for each buffer
|
||||
glGenBuffers(1, buffer);
|
||||
compile_shaders();
|
||||
}
|
||||
|
||||
~Scene_aabb_item()
|
||||
{
|
||||
glDeleteBuffers(1, buffer);
|
||||
glDeleteVertexArrays(1, vao);
|
||||
glDeleteProgram(rendering_program_lines);
|
||||
}
|
||||
|
||||
bool isFinite() const { return true; }
|
||||
bool isEmpty() const { return tree.empty(); }
|
||||
|
|
@ -75,19 +89,164 @@ public:
|
|||
|
||||
// Wireframe OpenGL drawing in a display list
|
||||
void direct_draw() const {
|
||||
CGAL::AABB_drawing_traits<AABB_primitive, CGAL::AABB_node<AABB_traits> > traits;
|
||||
tree.traversal(0, traits);
|
||||
// CGAL::AABB_drawing_traits<AABB_primitive, CGAL::AABB_node<AABB_traits> > traits;
|
||||
// tree.traversal(0, traits, new std::vector<float>(0));
|
||||
}
|
||||
|
||||
void changed()
|
||||
{
|
||||
compute_elements();
|
||||
initialize_buffers();
|
||||
}
|
||||
public:
|
||||
const AABB_tree& tree;
|
||||
private:
|
||||
std::vector<float> positions_lines;
|
||||
|
||||
GLint location[2];
|
||||
GLuint vao[1];
|
||||
GLuint buffer[1];
|
||||
GLuint rendering_program_lines;
|
||||
|
||||
void initialize_buffers()
|
||||
{
|
||||
glBindVertexArray(vao[0]);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER,
|
||||
(positions_lines.size())*sizeof(float),
|
||||
positions_lines.data(),
|
||||
GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(0, //number of the buffer
|
||||
3, //number of floats to be taken
|
||||
GL_FLOAT, // type of data
|
||||
GL_FALSE, //not normalized
|
||||
0, //compact data (not in a struct)
|
||||
NULL //no offset (seperated in several buffers)
|
||||
);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
void compile_shaders()
|
||||
{
|
||||
//fill the vertex shader
|
||||
static const GLchar* vertex_shader_source[] =
|
||||
{
|
||||
"#version 300 es \n"
|
||||
" \n"
|
||||
"layout (location = 0) in vec3 positions; \n"
|
||||
|
||||
"uniform mat4 mvp_matrix; \n"
|
||||
"uniform vec3 color; \n"
|
||||
"out highp vec3 fColors; \n"
|
||||
"vec4 positions_lines = vec4(positions, 1.0); \n"
|
||||
" \n"
|
||||
|
||||
"void main(void) \n"
|
||||
"{ \n"
|
||||
" fColors = color; \n"
|
||||
" gl_Position = mvp_matrix * positions_lines; \n"
|
||||
"} \n"
|
||||
};
|
||||
|
||||
//fill the fragment shader
|
||||
static const GLchar* fragment_shader_source[]=
|
||||
{
|
||||
"#version 300 es \n"
|
||||
" \n"
|
||||
"in highp vec3 fColors; \n"
|
||||
|
||||
"out highp vec3 color; \n"
|
||||
" \n"
|
||||
"void main(void) \n"
|
||||
"{ \n"
|
||||
" color = fColors; \n"
|
||||
"} \n"
|
||||
};
|
||||
|
||||
GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertex_shader, 1, vertex_shader_source, NULL);
|
||||
glCompileShader(vertex_shader);
|
||||
GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragment_shader, 1, fragment_shader_source, NULL);
|
||||
glCompileShader(fragment_shader);
|
||||
|
||||
GLuint program = glCreateProgram();
|
||||
glAttachShader(program, vertex_shader);
|
||||
glAttachShader(program, fragment_shader);
|
||||
glLinkProgram(program);
|
||||
|
||||
glDeleteShader(vertex_shader);
|
||||
glDeleteShader(fragment_shader);
|
||||
rendering_program_lines = program;
|
||||
}
|
||||
void uniform_attrib(Viewer_interface* viewer) const
|
||||
{
|
||||
GLfloat colors[3];
|
||||
GLfloat mvp_mat[16];
|
||||
|
||||
//fills the MVP and MV matrices.
|
||||
|
||||
GLdouble d_mat[16];
|
||||
viewer->camera()->getModelViewProjectionMatrix(d_mat);
|
||||
for (int i=0; i<16; ++i)
|
||||
mvp_mat[i] = GLfloat(d_mat[i]);
|
||||
|
||||
|
||||
//fills the arraw of colors with the current color
|
||||
colors[0] = this->color().redF();
|
||||
colors[1] = this->color().greenF();
|
||||
colors[2] = this->color().blueF();
|
||||
|
||||
|
||||
glUseProgram(rendering_program_lines);
|
||||
glUniformMatrix4fv(location[0], 1, GL_FALSE, mvp_mat);
|
||||
glUniform3fv(location[1],1,colors);
|
||||
}
|
||||
void compute_elements()
|
||||
{
|
||||
positions_lines.clear();
|
||||
|
||||
CGAL::AABB_drawing_traits<AABB_primitive, CGAL::AABB_node<AABB_traits> > traits;
|
||||
traits.v_edges = &positions_lines;
|
||||
|
||||
tree.traversal(0, traits);
|
||||
|
||||
location[0] = glGetUniformLocation(rendering_program_lines, "mvp_matrix");
|
||||
location[1] = glGetUniformLocation(rendering_program_lines, "color");
|
||||
}
|
||||
void draw_edges(Viewer_interface* viewer) const
|
||||
{
|
||||
glBindVertexArray(vao[0]);
|
||||
glUseProgram(rendering_program_lines);
|
||||
uniform_attrib(viewer);
|
||||
glDrawArrays(GL_LINES, 0, positions_lines.size()/3);
|
||||
glUseProgram(0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
}
|
||||
}; // end class Scene_aabb_item
|
||||
|
||||
class Q_DECL_EXPORT Scene_edges_item : public Scene_item
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
bool isFinite() const { return true; }
|
||||
Scene_edges_item()
|
||||
{
|
||||
positions_lines.resize(0);
|
||||
glGenVertexArrays(1, vao);
|
||||
//Generates an integer which will be used as ID for each buffer
|
||||
glGenBuffers(1, buffer);
|
||||
compile_shaders();
|
||||
}
|
||||
~Scene_edges_item()
|
||||
{
|
||||
glDeleteBuffers(1, buffer);
|
||||
glDeleteVertexArrays(1, vao);
|
||||
glDeleteProgram(rendering_program_lines);
|
||||
}
|
||||
bool isFinite() const { return true; }
|
||||
bool isEmpty() const { return edges.empty(); }
|
||||
Bbox bbox() const {
|
||||
if(isEmpty())
|
||||
|
|
@ -103,9 +262,14 @@ public:
|
|||
bbox.ymax(),
|
||||
bbox.zmax());
|
||||
}
|
||||
void changed()
|
||||
{
|
||||
compute_elements();
|
||||
initialize_buffers();
|
||||
}
|
||||
|
||||
Scene_edges_item* clone() const {
|
||||
Scene_edges_item* item = new Scene_edges_item;
|
||||
Scene_edges_item* item = new Scene_edges_item();
|
||||
item->edges = edges;
|
||||
return item;
|
||||
}
|
||||
|
|
@ -127,11 +291,12 @@ public:
|
|||
}
|
||||
|
||||
// Flat/Gouraud OpenGL drawing
|
||||
void draw() const {}
|
||||
void draw() const {
|
||||
}
|
||||
|
||||
// Wireframe OpenGL drawing
|
||||
void draw_edges() const {
|
||||
::glBegin(GL_LINES);
|
||||
/*::glBegin(GL_LINES);
|
||||
for(size_t i = 0, end = edges.size();
|
||||
i < end; ++i)
|
||||
{
|
||||
|
|
@ -140,7 +305,7 @@ public:
|
|||
::glVertex3d(a.x(), a.y(), a.z());
|
||||
::glVertex3d(b.x(), b.y(), b.z());
|
||||
}
|
||||
::glEnd();
|
||||
::glEnd();*/
|
||||
}
|
||||
|
||||
bool save(std::ostream& os) const
|
||||
|
|
@ -154,6 +319,138 @@ public:
|
|||
|
||||
public:
|
||||
std::vector<Epic_kernel::Segment_3> edges;
|
||||
|
||||
private:
|
||||
std::vector<float> positions_lines;
|
||||
|
||||
GLint location[2];
|
||||
GLuint vao[1];
|
||||
GLuint buffer[1];
|
||||
GLuint rendering_program_lines;
|
||||
|
||||
void initialize_buffers()
|
||||
{
|
||||
glBindVertexArray(vao[0]);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER,
|
||||
(positions_lines.size())*sizeof(float),
|
||||
positions_lines.data(),
|
||||
GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(0, //number of the buffer
|
||||
3, //number of floats to be taken
|
||||
GL_FLOAT, // type of data
|
||||
GL_FALSE, //not normalized
|
||||
0, //compact data (not in a struct)
|
||||
NULL //no offset (seperated in several buffers)
|
||||
);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
void compile_shaders()
|
||||
{
|
||||
//fill the vertex shader
|
||||
static const GLchar* vertex_shader_source[] =
|
||||
{
|
||||
"#version 300 es \n"
|
||||
" \n"
|
||||
"layout (location = 0) in vec3 positions; \n"
|
||||
|
||||
"uniform mat4 mvp_matrix; \n"
|
||||
"uniform vec3 color; \n"
|
||||
"out highp vec3 fColors; \n"
|
||||
"vec4 positions_lines = vec4(positions, 1.0); \n"
|
||||
" \n"
|
||||
|
||||
"void main(void) \n"
|
||||
"{ \n"
|
||||
" fColors = color; \n"
|
||||
" gl_Position = mvp_matrix * positions_lines; \n"
|
||||
"} \n"
|
||||
};
|
||||
|
||||
//fill the fragment shader
|
||||
static const GLchar* fragment_shader_source[]=
|
||||
{
|
||||
"#version 300 es \n"
|
||||
" \n"
|
||||
"in highp vec3 fColors; \n"
|
||||
|
||||
"out highp vec3 color; \n"
|
||||
" \n"
|
||||
"void main(void) \n"
|
||||
"{ \n"
|
||||
" color = fColors; \n"
|
||||
"} \n"
|
||||
};
|
||||
|
||||
GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertex_shader, 1, vertex_shader_source, NULL);
|
||||
glCompileShader(vertex_shader);
|
||||
GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragment_shader, 1, fragment_shader_source, NULL);
|
||||
glCompileShader(fragment_shader);
|
||||
|
||||
GLuint program = glCreateProgram();
|
||||
glAttachShader(program, vertex_shader);
|
||||
glAttachShader(program, fragment_shader);
|
||||
glLinkProgram(program);
|
||||
|
||||
glDeleteShader(vertex_shader);
|
||||
glDeleteShader(fragment_shader);
|
||||
rendering_program_lines = program;
|
||||
}
|
||||
void uniform_attrib(Viewer_interface* viewer) const
|
||||
{
|
||||
GLfloat colors[3];
|
||||
GLfloat mvp_mat[16];
|
||||
|
||||
//fills the MVP and MV matrices.
|
||||
|
||||
GLdouble d_mat[16];
|
||||
viewer->camera()->getModelViewProjectionMatrix(d_mat);
|
||||
for (int i=0; i<16; ++i)
|
||||
mvp_mat[i] = GLfloat(d_mat[i]);
|
||||
|
||||
|
||||
//fills the arraw of colors with the current color
|
||||
colors[0] = this->color().redF();
|
||||
colors[1] = this->color().greenF();
|
||||
colors[2] = this->color().blueF();
|
||||
|
||||
|
||||
glUseProgram(rendering_program_lines);
|
||||
glUniformMatrix4fv(location[0], 1, GL_FALSE, mvp_mat);
|
||||
glUniform3fv(location[1],1,colors);
|
||||
}
|
||||
void compute_elements()
|
||||
{
|
||||
positions_lines.clear();
|
||||
|
||||
for(size_t i = 0, end = edges.size();
|
||||
i < end; ++i)
|
||||
{
|
||||
const Epic_kernel::Point_3& a = edges[i].source();
|
||||
const Epic_kernel::Point_3& b = edges[i].target();
|
||||
positions_lines.push_back(a.x()); positions_lines.push_back(a.y()); positions_lines.push_back(a.z());
|
||||
positions_lines.push_back(b.x()); positions_lines.push_back(b.y()); positions_lines.push_back(b.z());
|
||||
}
|
||||
|
||||
location[0] = glGetUniformLocation(rendering_program_lines, "mvp_matrix");
|
||||
location[1] = glGetUniformLocation(rendering_program_lines, "color");
|
||||
}
|
||||
void draw_edges(Viewer_interface* viewer) const
|
||||
{
|
||||
glBindVertexArray(vao[0]);
|
||||
glUseProgram(rendering_program_lines);
|
||||
uniform_attrib(viewer);
|
||||
glDrawArrays(GL_LINES, 0, positions_lines.size()/3);
|
||||
glUseProgram(0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
}
|
||||
|
||||
}; // end class Scene_edges_item
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -213,6 +213,7 @@ void Polyhedron_demo_intersection_plugin::intersection()
|
|||
new_item->setColor(Qt::green);
|
||||
new_item->setRenderingMode(Wireframe);
|
||||
scene->addItem(new_item);
|
||||
new_item->changed();
|
||||
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,6 @@ void Polyhedron_demo_jet_fitting_plugin::on_actionEstimateCurvature_triggered()
|
|||
Scene_polylines_item* max_curv = new Scene_polylines_item;
|
||||
max_curv->setColor(Qt::red);
|
||||
max_curv->setName(tr("%1 (max curvatures)").arg(poly_item->name()));
|
||||
|
||||
Scene_polylines_item* min_curv = new Scene_polylines_item;
|
||||
min_curv->setColor(Qt::green);
|
||||
min_curv->setName(tr("%1 (min curvatures)").arg(poly_item->name()));
|
||||
|
|
@ -125,6 +124,8 @@ void Polyhedron_demo_jet_fitting_plugin::on_actionEstimateCurvature_triggered()
|
|||
|
||||
scene->addItem(max_curv);
|
||||
scene->addItem(min_curv);
|
||||
max_curv->changed();
|
||||
min_curv->changed();
|
||||
|
||||
// default cursor
|
||||
QApplication::restoreOverrideCursor();
|
||||
|
|
|
|||
|
|
@ -26,164 +26,166 @@ Scene_item* cgal_code_mesh_3(const Polyhedron*,
|
|||
Scene_interface* scene);
|
||||
|
||||
class Polyhedron_demo_mesh_3_plugin :
|
||||
public QObject,
|
||||
protected Polyhedron_demo_plugin_helper
|
||||
public QObject,
|
||||
protected Polyhedron_demo_plugin_helper
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Polyhedron_demo_plugin_interface)
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Polyhedron_demo_plugin_interface)
|
||||
|
||||
#if QT_VERSION >= 0x050000
|
||||
Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0")//New for Qt5 version !
|
||||
#endif
|
||||
|
||||
public:
|
||||
void init(QMainWindow* mainWindow, Scene_interface* scene_interface) {
|
||||
this->scene = scene_interface;
|
||||
this->mw = mainWindow;
|
||||
actionMesh_3 = new QAction("Create a tetrahedral mesh", mw);
|
||||
if(actionMesh_3) {
|
||||
connect(actionMesh_3, SIGNAL(triggered()),
|
||||
this, SLOT(mesh_3()));
|
||||
void init(QMainWindow* mainWindow, Scene_interface* scene_interface) {
|
||||
this->scene = scene_interface;
|
||||
this->mw = mainWindow;
|
||||
actionMesh_3 = new QAction("Create a tetrahedral mesh", mw);
|
||||
if(actionMesh_3) {
|
||||
connect(actionMesh_3, SIGNAL(triggered()),
|
||||
this, SLOT(mesh_3()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QList<QAction*> actions() const {
|
||||
return QList<QAction*>() << actionMesh_3;
|
||||
}
|
||||
QList<QAction*> actions() const {
|
||||
return QList<QAction*>() << actionMesh_3;
|
||||
}
|
||||
|
||||
|
||||
bool applicable(QAction*) const {
|
||||
return qobject_cast<Scene_polyhedron_item*>(scene->item(scene->mainSelectionIndex()));
|
||||
}
|
||||
|
||||
bool applicable(QAction*) const {
|
||||
return qobject_cast<Scene_polyhedron_item*>(scene->item(scene->mainSelectionIndex()));
|
||||
}
|
||||
public slots:
|
||||
void mesh_3();
|
||||
void mesh_3();
|
||||
|
||||
private:
|
||||
QAction* actionMesh_3;
|
||||
QAction* actionMesh_3;
|
||||
}; // end class Polyhedron_demo_mesh_3_plugin
|
||||
|
||||
double
|
||||
get_approximate(double d, int precision, int& decimals)
|
||||
{
|
||||
if ( d<0 ) { return 0; }
|
||||
if ( d<0 ) { return 0; }
|
||||
|
||||
double i = std::pow(10.,precision-1);
|
||||
double i = std::pow(10.,precision-1);
|
||||
|
||||
decimals = 0;
|
||||
while ( d > i*10 ) { d = d/10.; ++decimals; }
|
||||
while ( d < i ) { d = d*10.; --decimals; }
|
||||
decimals = 0;
|
||||
while ( d > i*10 ) { d = d/10.; ++decimals; }
|
||||
while ( d < i ) { d = d*10.; --decimals; }
|
||||
|
||||
return std::floor(d)*std::pow(10.,decimals);
|
||||
return std::floor(d)*std::pow(10.,decimals);
|
||||
}
|
||||
|
||||
void Polyhedron_demo_mesh_3_plugin::mesh_3()
|
||||
{
|
||||
const Scene_interface::Item_id index = scene->mainSelectionIndex();
|
||||
|
||||
Scene_polyhedron_item* item =
|
||||
qobject_cast<Scene_polyhedron_item*>(scene->item(index));
|
||||
const Scene_interface::Item_id index = scene->mainSelectionIndex();
|
||||
|
||||
if(!item) return;
|
||||
Scene_polyhedron_item* item =
|
||||
qobject_cast<Scene_polyhedron_item*>(scene->item(index));
|
||||
|
||||
Polyhedron* pMesh = item->polyhedron();
|
||||
if(!item) return;
|
||||
|
||||
if(!pMesh) return;
|
||||
Polyhedron* pMesh = item->polyhedron();
|
||||
|
||||
// -----------------------------------
|
||||
// Create Mesh dialog
|
||||
// -----------------------------------
|
||||
QDialog dialog(mw);
|
||||
Ui::Meshing_dialog ui;
|
||||
ui.setupUi(&dialog);
|
||||
connect(ui.buttonBox, SIGNAL(accepted()),
|
||||
&dialog, SLOT(accept()));
|
||||
connect(ui.buttonBox, SIGNAL(rejected()),
|
||||
&dialog, SLOT(reject()));
|
||||
if(!pMesh) return;
|
||||
|
||||
// Connect checkboxes to spinboxes
|
||||
connect(ui.noApprox, SIGNAL(toggled(bool)),
|
||||
ui.approx, SLOT(setEnabled(bool)));
|
||||
// -----------------------------------
|
||||
// Create Mesh dialog
|
||||
// -----------------------------------
|
||||
QDialog dialog(mw);
|
||||
Ui::Meshing_dialog ui;
|
||||
ui.setupUi(&dialog);
|
||||
connect(ui.buttonBox, SIGNAL(accepted()),
|
||||
&dialog, SLOT(accept()));
|
||||
connect(ui.buttonBox, SIGNAL(rejected()),
|
||||
&dialog, SLOT(reject()));
|
||||
|
||||
connect(ui.noFacetSizing, SIGNAL(toggled(bool)),
|
||||
ui.facetSizing, SLOT(setEnabled(bool)));
|
||||
// Connect checkboxes to spinboxes
|
||||
connect(ui.noApprox, SIGNAL(toggled(bool)),
|
||||
ui.approx, SLOT(setEnabled(bool)));
|
||||
|
||||
connect(ui.noAngle, SIGNAL(toggled(bool)),
|
||||
ui.facetAngle, SLOT(setEnabled(bool)));
|
||||
connect(ui.noFacetSizing, SIGNAL(toggled(bool)),
|
||||
ui.facetSizing, SLOT(setEnabled(bool)));
|
||||
|
||||
connect(ui.noTetSizing, SIGNAL(toggled(bool)),
|
||||
ui.tetSizing, SLOT(setEnabled(bool)));
|
||||
connect(ui.noAngle, SIGNAL(toggled(bool)),
|
||||
ui.facetAngle, SLOT(setEnabled(bool)));
|
||||
|
||||
connect(ui.noTetShape, SIGNAL(toggled(bool)),
|
||||
ui.tetShape, SLOT(setEnabled(bool)));
|
||||
connect(ui.noTetSizing, SIGNAL(toggled(bool)),
|
||||
ui.tetSizing, SLOT(setEnabled(bool)));
|
||||
|
||||
// Set default parameters
|
||||
Scene_interface::Bbox bbox = item->bbox();
|
||||
ui.objectName->setText(item->name());
|
||||
ui.objectNameSize->setText(tr("Object bbox size (w,h,d): <b>%1</b>, <b>%2</b>, <b>%3</b>")
|
||||
.arg(bbox.width(),0,'g',3)
|
||||
.arg(bbox.height(),0,'g',3)
|
||||
.arg(bbox.depth(),0,'g',3) );
|
||||
connect(ui.noTetShape, SIGNAL(toggled(bool)),
|
||||
ui.tetShape, SLOT(setEnabled(bool)));
|
||||
|
||||
double diag = bbox.diagonal_length();
|
||||
int decimals = 0;
|
||||
double sizing_default = get_approximate(diag * 0.05, 2, decimals);
|
||||
ui.facetSizing->setDecimals(-decimals+2);
|
||||
ui.facetSizing->setSingleStep(std::pow(10.,decimals));
|
||||
ui.facetSizing->setRange(diag * 10e-6, // min
|
||||
// Set default parameters
|
||||
Scene_interface::Bbox bbox = item->bbox();
|
||||
ui.objectName->setText(item->name());
|
||||
ui.objectNameSize->setText(tr("Object bbox size (w,h,d): <b>%1</b>, <b>%2</b>, <b>%3</b>")
|
||||
.arg(bbox.width(),0,'g',3)
|
||||
.arg(bbox.height(),0,'g',3)
|
||||
.arg(bbox.depth(),0,'g',3) );
|
||||
|
||||
double diag = bbox.diagonal_length();
|
||||
int decimals = 0;
|
||||
double sizing_default = get_approximate(diag * 0.05, 2, decimals);
|
||||
ui.facetSizing->setDecimals(-decimals+2);
|
||||
ui.facetSizing->setSingleStep(std::pow(10.,decimals));
|
||||
ui.facetSizing->setRange(diag * 10e-6, // min
|
||||
diag); // max
|
||||
ui.facetSizing->setValue(sizing_default); // default value
|
||||
|
||||
ui.tetSizing->setDecimals(-decimals+2);
|
||||
ui.tetSizing->setSingleStep(std::pow(10.,decimals));
|
||||
ui.tetSizing->setRange(diag * 10e-6, // min
|
||||
diag); // max
|
||||
ui.facetSizing->setValue(sizing_default); // default value
|
||||
ui.tetSizing->setValue(sizing_default); // default value
|
||||
|
||||
ui.tetSizing->setDecimals(-decimals+2);
|
||||
ui.tetSizing->setSingleStep(std::pow(10.,decimals));
|
||||
ui.tetSizing->setRange(diag * 10e-6, // min
|
||||
diag); // max
|
||||
ui.tetSizing->setValue(sizing_default); // default value
|
||||
double approx_default = get_approximate(diag * 0.005, 2, decimals);
|
||||
ui.approx->setDecimals(-decimals+2);
|
||||
ui.approx->setSingleStep(std::pow(10.,decimals));
|
||||
ui.approx->setRange(diag * 10e-7, // min
|
||||
diag); // max
|
||||
ui.approx->setValue(approx_default);
|
||||
|
||||
double approx_default = get_approximate(diag * 0.005, 2, decimals);
|
||||
ui.approx->setDecimals(-decimals+2);
|
||||
ui.approx->setSingleStep(std::pow(10.,decimals));
|
||||
ui.approx->setRange(diag * 10e-7, // min
|
||||
diag); // max
|
||||
ui.approx->setValue(approx_default);
|
||||
// -----------------------------------
|
||||
// Get values
|
||||
// -----------------------------------
|
||||
int i = dialog.exec();
|
||||
if( i == QDialog::Rejected ) { return; }
|
||||
|
||||
// -----------------------------------
|
||||
// Get values
|
||||
// -----------------------------------
|
||||
int i = dialog.exec();
|
||||
if( i == QDialog::Rejected ) { return; }
|
||||
// 0 means parameter is not considered
|
||||
const double angle = !ui.noAngle->isChecked() ? 0 : ui.facetAngle->value();
|
||||
const double approx = !ui.noApprox->isChecked() ? 0 : ui.approx->value();
|
||||
const double facet_sizing = !ui.noFacetSizing->isChecked() ? 0 : ui.facetSizing->value();
|
||||
const double radius_edge = !ui.noTetShape->isChecked() ? 0 : ui.tetShape->value();
|
||||
const double tet_sizing = !ui.noTetSizing->isChecked() ? 0 : ui.tetSizing->value();
|
||||
const bool protect_features = ui.protect->isChecked();
|
||||
|
||||
// 0 means parameter is not considered
|
||||
const double angle = !ui.noAngle->isChecked() ? 0 : ui.facetAngle->value();
|
||||
const double approx = !ui.noApprox->isChecked() ? 0 : ui.approx->value();
|
||||
const double facet_sizing = !ui.noFacetSizing->isChecked() ? 0 : ui.facetSizing->value();
|
||||
const double radius_edge = !ui.noTetShape->isChecked() ? 0 : ui.tetShape->value();
|
||||
const double tet_sizing = !ui.noTetSizing->isChecked() ? 0 : ui.tetSizing->value();
|
||||
const bool protect_features = ui.protect->isChecked();
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
||||
Scene_item* result_item = cgal_code_mesh_3(pMesh,
|
||||
item->name(),
|
||||
angle,
|
||||
facet_sizing,
|
||||
approx,
|
||||
tet_sizing,
|
||||
radius_edge,
|
||||
protect_features,
|
||||
scene);
|
||||
if(result_item) {
|
||||
result_item->setName(tr("%1 3d mesh (%2 %3 %4 %5)")
|
||||
.arg(item->name())
|
||||
.arg(angle)
|
||||
.arg(facet_sizing)
|
||||
.arg(tet_sizing)
|
||||
.arg(approx));
|
||||
result_item->setColor(Qt::magenta);
|
||||
result_item->setRenderingMode(item->renderingMode());
|
||||
item->setVisible(false);
|
||||
scene->itemChanged(index);
|
||||
scene->addItem(result_item);
|
||||
}
|
||||
QApplication::restoreOverrideCursor();
|
||||
Scene_item* result_item = cgal_code_mesh_3(pMesh,
|
||||
item->name(),
|
||||
angle,
|
||||
facet_sizing,
|
||||
approx,
|
||||
tet_sizing,
|
||||
radius_edge,
|
||||
protect_features,
|
||||
scene);
|
||||
if(result_item) {
|
||||
result_item->setName(tr("%1 3d mesh (%2 %3 %4 %5)")
|
||||
.arg(item->name())
|
||||
.arg(angle)
|
||||
.arg(facet_sizing)
|
||||
.arg(tet_sizing)
|
||||
.arg(approx));
|
||||
result_item->setColor(Qt::magenta);
|
||||
result_item->setRenderingMode(item->renderingMode());
|
||||
item->setVisible(false);
|
||||
scene->itemChanged(index);
|
||||
scene->addItem(result_item);
|
||||
}
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -103,6 +103,7 @@ void Polyhedron_demo_normal_estimation_plugin::on_actionNormalInversion_triggere
|
|||
for(Point_set::iterator it = points->begin(); it != points->end(); ++it){
|
||||
it->normal() = -1 * it->normal();
|
||||
}
|
||||
item->changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@ void Polyhedron_demo_poisson_plugin::on_actionPoissonReconstruction_triggered()
|
|||
new_item->setColor(Qt::lightGray);
|
||||
scene->addItem(new_item);
|
||||
|
||||
|
||||
// Hide point set
|
||||
point_set_item->setVisible(false);
|
||||
scene->itemChanged(index);
|
||||
|
|
|
|||
|
|
@ -313,6 +313,7 @@ void Polyhedron_demo_polyhedron_slicer_plugin::on_Generate_button_clicked()
|
|||
new_polylines_item->setColor(Qt::green);
|
||||
new_polylines_item->setRenderingMode(Wireframe);
|
||||
scene->addItem(new_polylines_item);
|
||||
new_polylines_item->changed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -136,6 +136,7 @@ void Polyhedron_demo_polyhedron_stitching_plugin::on_actionDetectBorders_trigger
|
|||
new_item->setName(tr("Boundary of %1").arg(item->name()));
|
||||
new_item->setColor(Qt::red);
|
||||
scene->addItem(new_item);
|
||||
new_item->changed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ Polyhedron_demo_polylines_io_plugin::load(QFileInfo fileinfo) {
|
|||
item->setColor(Qt::black);
|
||||
item->setProperty("polylines metadata", polylines_metadata);
|
||||
std::cerr << "Number of polylines in item: " << item->polylines.size() << std::endl;
|
||||
item->changed();
|
||||
return item;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ public:
|
|||
mw = mainWindow;
|
||||
scene = scene_interface;
|
||||
messages = m;
|
||||
|
||||
actionSelection = new QAction(tr("Selection"), mw);
|
||||
connect(actionSelection, SIGNAL(triggered()), this, SLOT(selection_action()));
|
||||
|
||||
|
|
|
|||
|
|
@ -1,153 +1,324 @@
|
|||
#include <GL/glew.h>
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#include "Scene_item.h"
|
||||
#include "Scene_interface.h"
|
||||
#include <CGAL/gl.h>
|
||||
|
||||
#include "Viewer_interface.h"
|
||||
#include <QAction>
|
||||
#include <QMainWindow>
|
||||
|
||||
class Q_DECL_EXPORT Scene_bbox_item : public Scene_item
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
Scene_bbox_item(const Scene_interface* scene_interface)
|
||||
: scene(scene_interface)
|
||||
{}
|
||||
Scene_bbox_item(const Scene_interface* scene_interface)
|
||||
: scene(scene_interface)
|
||||
{
|
||||
|
||||
bool isFinite() const { return true; }
|
||||
bool isEmpty() const { return true; }
|
||||
Bbox bbox() const { return Bbox(); }
|
||||
positions_lines.resize(0);
|
||||
glGenVertexArrays(1, vao);
|
||||
//Generates an integer which will be used as ID for each buffer
|
||||
glGenBuffers(1, buffer);
|
||||
compile_shaders();
|
||||
}
|
||||
~Scene_bbox_item()
|
||||
{
|
||||
glDeleteBuffers(1, buffer);
|
||||
glDeleteVertexArrays(1, vao);
|
||||
glDeleteProgram(rendering_program_lines);
|
||||
}
|
||||
bool isFinite() const { return true; }
|
||||
bool isEmpty() const { return true; }
|
||||
Bbox bbox() const { return Bbox(); }
|
||||
|
||||
Scene_bbox_item* clone() const {
|
||||
return 0;
|
||||
}
|
||||
Scene_bbox_item* clone() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
QString toolTip() const {
|
||||
const Bbox& bb = scene->bbox();
|
||||
return QString("<p><b>Scene bounding box</b></p>"
|
||||
"<p>x range: (%1, %2)<br />"
|
||||
"y range: (%3, %4)<br />"
|
||||
"z range: (%5, %6)</p>")
|
||||
.arg(bb.xmin).arg(bb.xmax)
|
||||
.arg(bb.ymin).arg(bb.ymax)
|
||||
.arg(bb.zmin).arg(bb.zmax);
|
||||
}
|
||||
QString toolTip() const {
|
||||
const Bbox& bb = scene->bbox();
|
||||
return QString("<p><b>Scene bounding box</b></p>"
|
||||
"<p>x range: (%1, %2)<br />"
|
||||
"y range: (%3, %4)<br />"
|
||||
"z range: (%5, %6)</p>")
|
||||
.arg(bb.xmin).arg(bb.xmax)
|
||||
.arg(bb.ymin).arg(bb.ymax)
|
||||
.arg(bb.zmin).arg(bb.zmax);
|
||||
}
|
||||
|
||||
// Indicate if rendering mode is supported
|
||||
bool supportsRenderingMode(RenderingMode m) const {
|
||||
return (m == Wireframe);
|
||||
}
|
||||
// Indicate if rendering mode is supported
|
||||
bool supportsRenderingMode(RenderingMode m) const {
|
||||
return (m == Wireframe);
|
||||
}
|
||||
|
||||
// Flat/Gouraud OpenGL drawing
|
||||
void draw() const {}
|
||||
// Flat/Gouraud OpenGL drawing
|
||||
void draw() const {}
|
||||
|
||||
// Wireframe OpenGL drawing
|
||||
void draw_edges() const {
|
||||
const Bbox& bb = scene->bbox();
|
||||
::glBegin(GL_LINES);
|
||||
gl_draw_edge(bb.xmin, bb.ymin, bb.zmin,
|
||||
bb.xmax, bb.ymin, bb.zmin);
|
||||
gl_draw_edge(bb.xmin, bb.ymin, bb.zmin,
|
||||
bb.xmin, bb.ymax, bb.zmin);
|
||||
gl_draw_edge(bb.xmin, bb.ymin, bb.zmin,
|
||||
bb.xmin, bb.ymin, bb.zmax);
|
||||
|
||||
gl_draw_edge(bb.xmax, bb.ymin, bb.zmin,
|
||||
bb.xmax, bb.ymax, bb.zmin);
|
||||
gl_draw_edge(bb.xmax, bb.ymin, bb.zmin,
|
||||
bb.xmax, bb.ymin, bb.zmax);
|
||||
|
||||
gl_draw_edge(bb.xmin, bb.ymax, bb.zmin,
|
||||
bb.xmax, bb.ymax, bb.zmin);
|
||||
gl_draw_edge(bb.xmin, bb.ymax, bb.zmin,
|
||||
bb.xmin, bb.ymax, bb.zmax);
|
||||
|
||||
gl_draw_edge(bb.xmin, bb.ymin, bb.zmax,
|
||||
bb.xmax, bb.ymin, bb.zmax);
|
||||
gl_draw_edge(bb.xmin, bb.ymin, bb.zmax,
|
||||
bb.xmin, bb.ymax, bb.zmax);
|
||||
|
||||
gl_draw_edge(bb.xmax, bb.ymax, bb.zmax,
|
||||
bb.xmin, bb.ymax, bb.zmax);
|
||||
gl_draw_edge(bb.xmax, bb.ymax, bb.zmax,
|
||||
bb.xmax, bb.ymin, bb.zmax);
|
||||
gl_draw_edge(bb.xmax, bb.ymax, bb.zmax,
|
||||
bb.xmax, bb.ymax, bb.zmin);
|
||||
::glEnd();
|
||||
}
|
||||
// Wireframe OpenGL drawing
|
||||
void draw_edges() const {
|
||||
const Bbox& bb = scene->bbox();
|
||||
::glBegin(GL_LINES);
|
||||
gl_draw_edge(bb.xmin, bb.ymin, bb.zmin,
|
||||
bb.xmax, bb.ymin, bb.zmin);
|
||||
gl_draw_edge(bb.xmin, bb.ymin, bb.zmin,
|
||||
bb.xmin, bb.ymax, bb.zmin);
|
||||
gl_draw_edge(bb.xmin, bb.ymin, bb.zmin,
|
||||
bb.xmin, bb.ymin, bb.zmax);
|
||||
|
||||
gl_draw_edge(bb.xmax, bb.ymin, bb.zmin,
|
||||
bb.xmax, bb.ymax, bb.zmin);
|
||||
gl_draw_edge(bb.xmax, bb.ymin, bb.zmin,
|
||||
bb.xmax, bb.ymin, bb.zmax);
|
||||
|
||||
gl_draw_edge(bb.xmin, bb.ymax, bb.zmin,
|
||||
bb.xmax, bb.ymax, bb.zmin);
|
||||
gl_draw_edge(bb.xmin, bb.ymax, bb.zmin,
|
||||
bb.xmin, bb.ymax, bb.zmax);
|
||||
|
||||
gl_draw_edge(bb.xmin, bb.ymin, bb.zmax,
|
||||
bb.xmax, bb.ymin, bb.zmax);
|
||||
gl_draw_edge(bb.xmin, bb.ymin, bb.zmax,
|
||||
bb.xmin, bb.ymax, bb.zmax);
|
||||
|
||||
gl_draw_edge(bb.xmax, bb.ymax, bb.zmax,
|
||||
bb.xmin, bb.ymax, bb.zmax);
|
||||
gl_draw_edge(bb.xmax, bb.ymax, bb.zmax,
|
||||
bb.xmax, bb.ymin, bb.zmax);
|
||||
gl_draw_edge(bb.xmax, bb.ymax, bb.zmax,
|
||||
bb.xmax, bb.ymax, bb.zmin);
|
||||
::glEnd();
|
||||
}
|
||||
void draw_edges(Viewer_interface* viewer) const
|
||||
{
|
||||
glBindVertexArray(vao[0]);
|
||||
glUseProgram(rendering_program_lines);
|
||||
uniform_attrib(viewer);
|
||||
glDrawArrays(GL_LINES, 0, positions_lines.size()/3);
|
||||
glUseProgram(0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
}
|
||||
|
||||
void changed()
|
||||
{
|
||||
compute_elements();
|
||||
initialize_buffers();
|
||||
}
|
||||
|
||||
private:
|
||||
static void gl_draw_edge(double px, double py, double pz,
|
||||
double qx, double qy, double qz)
|
||||
{
|
||||
::glVertex3d(px,py,pz);
|
||||
::glVertex3d(qx,qy,qz);
|
||||
}
|
||||
static void gl_draw_edge(double px, double py, double pz,
|
||||
double qx, double qy, double qz)
|
||||
{
|
||||
::glVertex3d(px,py,pz);
|
||||
::glVertex3d(qx,qy,qz);
|
||||
}
|
||||
|
||||
const Scene_interface* scene;
|
||||
std::vector<float> positions_lines;
|
||||
GLint location[2];
|
||||
GLuint vao[1];
|
||||
GLuint buffer[1];
|
||||
GLuint rendering_program_lines;
|
||||
|
||||
void initialize_buffers()
|
||||
{
|
||||
glBindVertexArray(vao[0]);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER,
|
||||
(positions_lines.size())*sizeof(float),
|
||||
positions_lines.data(),
|
||||
GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(0, //number of the buffer
|
||||
3, //number of floats to be taken
|
||||
GL_FLOAT, // type of data
|
||||
GL_FALSE, //not normalized
|
||||
0, //compact data (not in a struct)
|
||||
NULL //no offset (seperated in several buffers)
|
||||
);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
void compile_shaders()
|
||||
{
|
||||
//fill the vertex shader
|
||||
static const GLchar* vertex_shader_source[] =
|
||||
{
|
||||
"#version 300 es \n"
|
||||
" \n"
|
||||
"layout (location = 0) in vec3 positions; \n"
|
||||
|
||||
"uniform mat4 mvp_matrix; \n"
|
||||
"uniform vec3 color; \n"
|
||||
"out highp vec3 fColors; \n"
|
||||
"vec4 positions_lines = vec4(positions, 1.0); \n"
|
||||
" \n"
|
||||
|
||||
"void main(void) \n"
|
||||
"{ \n"
|
||||
" fColors = color; \n"
|
||||
" gl_Position = mvp_matrix * positions_lines; \n"
|
||||
"} \n"
|
||||
};
|
||||
|
||||
//fill the fragment shader
|
||||
static const GLchar* fragment_shader_source[]=
|
||||
{
|
||||
"#version 300 es \n"
|
||||
" \n"
|
||||
"in highp vec3 fColors; \n"
|
||||
|
||||
"out highp vec3 color; \n"
|
||||
" \n"
|
||||
"void main(void) \n"
|
||||
"{ \n"
|
||||
" color = fColors; \n"
|
||||
"} \n"
|
||||
};
|
||||
|
||||
GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertex_shader, 1, vertex_shader_source, NULL);
|
||||
glCompileShader(vertex_shader);
|
||||
GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragment_shader, 1, fragment_shader_source, NULL);
|
||||
glCompileShader(fragment_shader);
|
||||
|
||||
GLuint program = glCreateProgram();
|
||||
glAttachShader(program, vertex_shader);
|
||||
glAttachShader(program, fragment_shader);
|
||||
glLinkProgram(program);
|
||||
|
||||
glDeleteShader(vertex_shader);
|
||||
glDeleteShader(fragment_shader);
|
||||
rendering_program_lines = program;
|
||||
}
|
||||
void uniform_attrib(Viewer_interface* viewer) const
|
||||
{
|
||||
GLfloat colors[3];
|
||||
GLfloat mvp_mat[16];
|
||||
|
||||
//fills the MVP and MV matrices.
|
||||
|
||||
GLdouble d_mat[16];
|
||||
viewer->camera()->getModelViewProjectionMatrix(d_mat);
|
||||
for (int i=0; i<16; ++i)
|
||||
mvp_mat[i] = GLfloat(d_mat[i]);
|
||||
|
||||
|
||||
//fills the arraw of colors with the current color
|
||||
colors[0] = this->color().redF();
|
||||
colors[1] = this->color().greenF();
|
||||
colors[2] = this->color().blueF();
|
||||
|
||||
|
||||
glUseProgram(rendering_program_lines);
|
||||
glUniformMatrix4fv(location[0], 1, GL_FALSE, mvp_mat);
|
||||
glUniform3fv(location[1],1,colors);
|
||||
}
|
||||
void compute_elements()
|
||||
{
|
||||
positions_lines.clear();
|
||||
const Bbox& bb = scene->bbox();
|
||||
positions_lines.push_back(bb.xmin); positions_lines.push_back(bb.ymin); positions_lines.push_back(bb.zmin);
|
||||
positions_lines.push_back(bb.xmax); positions_lines.push_back(bb.ymin); positions_lines.push_back(bb.zmin);
|
||||
positions_lines.push_back(bb.xmin); positions_lines.push_back(bb.ymin); positions_lines.push_back(bb.zmin);
|
||||
positions_lines.push_back(bb.xmin); positions_lines.push_back(bb.ymax); positions_lines.push_back(bb.zmin);
|
||||
positions_lines.push_back(bb.xmin); positions_lines.push_back(bb.ymin); positions_lines.push_back(bb.zmin);
|
||||
positions_lines.push_back(bb.xmin); positions_lines.push_back(bb.ymin); positions_lines.push_back(bb.zmax);
|
||||
|
||||
positions_lines.push_back(bb.xmax); positions_lines.push_back(bb.ymin); positions_lines.push_back(bb.zmin);
|
||||
positions_lines.push_back(bb.xmax); positions_lines.push_back(bb.ymax); positions_lines.push_back(bb.zmin);
|
||||
positions_lines.push_back(bb.xmax); positions_lines.push_back(bb.ymin); positions_lines.push_back(bb.zmin);
|
||||
positions_lines.push_back(bb.xmax); positions_lines.push_back(bb.ymin); positions_lines.push_back(bb.zmax);
|
||||
|
||||
positions_lines.push_back(bb.xmin); positions_lines.push_back(bb.ymax); positions_lines.push_back(bb.zmin);
|
||||
positions_lines.push_back(bb.xmax); positions_lines.push_back(bb.ymax); positions_lines.push_back(bb.zmin);
|
||||
positions_lines.push_back(bb.xmin); positions_lines.push_back(bb.ymax); positions_lines.push_back(bb.zmin);
|
||||
positions_lines.push_back(bb.xmin); positions_lines.push_back(bb.ymax); positions_lines.push_back(bb.zmax);
|
||||
|
||||
positions_lines.push_back(bb.xmin); positions_lines.push_back(bb.ymin); positions_lines.push_back(bb.zmax);
|
||||
positions_lines.push_back(bb.xmax); positions_lines.push_back(bb.ymin); positions_lines.push_back(bb.zmax);
|
||||
positions_lines.push_back(bb.xmin); positions_lines.push_back(bb.ymin); positions_lines.push_back(bb.zmax);
|
||||
positions_lines.push_back(bb.xmin); positions_lines.push_back(bb.ymax); positions_lines.push_back(bb.zmax);
|
||||
|
||||
positions_lines.push_back(bb.xmax); positions_lines.push_back(bb.ymax); positions_lines.push_back(bb.zmax);
|
||||
positions_lines.push_back(bb.xmin); positions_lines.push_back(bb.ymax); positions_lines.push_back(bb.zmax);
|
||||
positions_lines.push_back(bb.xmax); positions_lines.push_back(bb.ymax); positions_lines.push_back(bb.zmax);
|
||||
positions_lines.push_back(bb.xmax); positions_lines.push_back(bb.ymin); positions_lines.push_back(bb.zmax);
|
||||
positions_lines.push_back(bb.xmax); positions_lines.push_back(bb.ymax); positions_lines.push_back(bb.zmax);
|
||||
positions_lines.push_back(bb.xmax); positions_lines.push_back(bb.ymax); positions_lines.push_back(bb.zmin);
|
||||
|
||||
location[0] = glGetUniformLocation(rendering_program_lines, "mvp_matrix");
|
||||
location[1] = glGetUniformLocation(rendering_program_lines, "color");
|
||||
}
|
||||
|
||||
const Scene_interface* scene;
|
||||
};
|
||||
|
||||
#include "Polyhedron_demo_plugin_interface.h"
|
||||
|
||||
class Polyhedron_demo_trivial_plugin :
|
||||
public QObject,
|
||||
public Polyhedron_demo_plugin_interface
|
||||
public QObject,
|
||||
public Polyhedron_demo_plugin_interface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Polyhedron_demo_plugin_interface)
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Polyhedron_demo_plugin_interface)
|
||||
|
||||
#if QT_VERSION >= 0x050000
|
||||
Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0")//New for Qt5 version !
|
||||
#endif
|
||||
|
||||
public:
|
||||
void init(QMainWindow* mainWindow, Scene_interface* scene_interface);
|
||||
QList<QAction*> actions() const {
|
||||
return QList<QAction*>() << actionBbox;
|
||||
}
|
||||
void init(QMainWindow* mainWindow, Scene_interface* scene_interface);
|
||||
QList<QAction*> actions() const {
|
||||
return QList<QAction*>() << actionBbox;
|
||||
}
|
||||
|
||||
bool applicable(QAction*) const {
|
||||
return true;
|
||||
}
|
||||
bool applicable(QAction*) const {
|
||||
return true;
|
||||
}
|
||||
public slots:
|
||||
void bbox();
|
||||
void enableAction();
|
||||
|
||||
void bbox();
|
||||
void enableAction();
|
||||
|
||||
private:
|
||||
Scene_interface* scene;
|
||||
QAction* actionBbox;
|
||||
Scene_interface* scene;
|
||||
QAction* actionBbox;
|
||||
|
||||
|
||||
}; // end Polyhedron_demo_trivial_plugin
|
||||
|
||||
void Polyhedron_demo_trivial_plugin::init(QMainWindow* mainWindow, Scene_interface* scene_interface)
|
||||
{
|
||||
scene = scene_interface;
|
||||
actionBbox = new QAction(tr("Create bbox"), mainWindow);
|
||||
connect(actionBbox, SIGNAL(triggered()),
|
||||
this, SLOT(bbox()));
|
||||
scene = scene_interface;
|
||||
actionBbox = new QAction(tr("Create bbox"), mainWindow);
|
||||
connect(actionBbox, SIGNAL(triggered()),
|
||||
this, SLOT(bbox()));
|
||||
}
|
||||
|
||||
void Polyhedron_demo_trivial_plugin::bbox()
|
||||
{
|
||||
for(int i = 0, end = scene->numberOfEntries();
|
||||
i < end; ++i)
|
||||
{
|
||||
if(qobject_cast<Scene_bbox_item*>(scene->item(i)))
|
||||
return;
|
||||
}
|
||||
Scene_item* item = new Scene_bbox_item(scene);
|
||||
connect(item, SIGNAL(destroyed()),
|
||||
this, SLOT(enableAction()));
|
||||
item->setName("Scene bbox");
|
||||
item->setColor(Qt::black);
|
||||
item->setRenderingMode(Wireframe);
|
||||
scene->addItem(item);
|
||||
actionBbox->setEnabled(false);
|
||||
for(int i = 0, end = scene->numberOfEntries();
|
||||
i < end; ++i)
|
||||
{
|
||||
if(qobject_cast<Scene_bbox_item*>(scene->item(i)))
|
||||
return;
|
||||
}
|
||||
Scene_item* item = new Scene_bbox_item(scene);
|
||||
connect(item, SIGNAL(destroyed()),
|
||||
this, SLOT(enableAction()));
|
||||
item->setName("Scene bbox");
|
||||
item->setColor(Qt::black);
|
||||
item->setRenderingMode(Wireframe);
|
||||
scene->addItem(item);
|
||||
actionBbox->setEnabled(false);
|
||||
}
|
||||
|
||||
void Polyhedron_demo_trivial_plugin::enableAction() {
|
||||
actionBbox->setEnabled(true);
|
||||
actionBbox->setEnabled(true);
|
||||
}
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -104,7 +104,6 @@ private:
|
|||
const Tr::Point& pc) {
|
||||
Tr::Geom_traits::Vector_3 n = cross_product(pb - pa, pc -pa);
|
||||
n = n / CGAL::sqrt(n*n);
|
||||
|
||||
::glNormal3d(n.x(),n.y(),n.z());
|
||||
|
||||
::glVertex3d(pa.x(),pa.y(),pa.z());
|
||||
|
|
|
|||
|
|
@ -6,8 +6,108 @@
|
|||
#include <QMenu>
|
||||
#include <QAction>
|
||||
#include <QtDebug>
|
||||
#include <QKeyEvent>
|
||||
#include <QKeyEvent>
|
||||
#include <CGAL/corefinement_operations.h>
|
||||
void Scene_combinatorial_map_item::initialize_buffers()
|
||||
{
|
||||
glBindVertexArray(vao);
|
||||
buffer[0] = QGLBuffer(QGLBuffer::VertexBuffer);
|
||||
if(!(buffer[0].create()))
|
||||
std::cout<<"ERROR lors de la creation"<<std::endl;
|
||||
buffer[0].bind();
|
||||
buffer[0].setUsagePattern(QGLBuffer::StaticDraw);
|
||||
buffer[0].allocate(positions.data(),positions.size()*sizeof(float));
|
||||
/*
|
||||
glVertexAttribPointer(0, //number of the buffer
|
||||
4, //number of floats to be taken
|
||||
GL_FLOAT, // type of data
|
||||
GL_FALSE, //not normalized
|
||||
0, //compact data (not in a struct)
|
||||
NULL //no offset (seperated in several buffers)
|
||||
);
|
||||
glEnableVertexAttribArray(0);*/
|
||||
|
||||
// Clean-up
|
||||
glBindVertexArray(0);
|
||||
|
||||
}
|
||||
|
||||
void Scene_combinatorial_map_item::compile_shaders(void)
|
||||
{
|
||||
|
||||
//fill the vertex shader
|
||||
static const char* vertex_shader_source =
|
||||
{
|
||||
"#version 300 es \n"
|
||||
" \n"
|
||||
"layout (location = 0) in vec3 positions; \n"
|
||||
|
||||
"out highp vec3 fColors; \n"
|
||||
" \n"
|
||||
|
||||
"void main(void) \n"
|
||||
"{ \n"
|
||||
" fColors = vec3(1.0,0.0,0.0); \n"
|
||||
" gl_Position = mvp_matrix * vec4(positions, 1.0); \n"
|
||||
"} \n"
|
||||
};
|
||||
//fill the fragment shader
|
||||
static const char* fragment_shader_source =
|
||||
{
|
||||
"#version 300 es \n"
|
||||
" \n"
|
||||
"in highp vec3 fColors; \n"
|
||||
|
||||
"out highp vec3 color; \n"
|
||||
" \n"
|
||||
"void main(void) \n"
|
||||
"{ \n"
|
||||
" color = fColors; \n"
|
||||
"} \n"
|
||||
};
|
||||
|
||||
QGLShader *vertex_shader = new QGLShader(QGLShader::Vertex);
|
||||
if(!vertex_shader->compileSourceCode(vertex_shader_source))
|
||||
std::cout<<vertex_shader->log().toStdString()<<std::endl;
|
||||
|
||||
QGLShader *fragment_shader = new QGLShader(QGLShader::Fragment);
|
||||
if(!fragment_shader->compileSourceCode(fragment_shader_source))
|
||||
std::cout<<fragment_shader->log().toStdString()<<std::endl;
|
||||
|
||||
|
||||
rendering_program = new QGLShaderProgram();
|
||||
if(!rendering_program->addShader(vertex_shader))
|
||||
std::cout<<rendering_program->log().toStdString()<<std::endl;
|
||||
if(!rendering_program->addShader(fragment_shader))
|
||||
std::cout<<rendering_program->log().toStdString()<<std::endl;
|
||||
rendering_program->link();
|
||||
|
||||
}
|
||||
|
||||
void Scene_combinatorial_map_item::compute_normals_and_vertices(void)
|
||||
{
|
||||
positions.push_back(-1.0);
|
||||
positions.push_back(-1.0);
|
||||
positions.push_back(0.0);
|
||||
|
||||
positions.push_back(0.0);
|
||||
positions.push_back(1.0);
|
||||
positions.push_back(0.0);
|
||||
|
||||
positions.push_back(1.0);
|
||||
positions.push_back(-1.0);
|
||||
positions.push_back(0.0);
|
||||
|
||||
}
|
||||
|
||||
void Scene_combinatorial_map_item::uniform_attrib(Viewer_interface*, int) const
|
||||
{
|
||||
|
||||
}
|
||||
void Scene_combinatorial_map_item::compute_colors()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Scene_combinatorial_map_item::Scene_combinatorial_map_item(Scene_interface* scene,void* address):last_known_scene(scene),volume_to_display(0),exportSelectedVolume(NULL),address_of_A(address){m_combinatorial_map=NULL;}
|
||||
Scene_combinatorial_map_item::~Scene_combinatorial_map_item(){if (m_combinatorial_map!=NULL) delete m_combinatorial_map;}
|
||||
|
|
@ -16,384 +116,384 @@ Scene_combinatorial_map_item* Scene_combinatorial_map_item::clone() const{return
|
|||
|
||||
Kernel::Vector_3 Scene_combinatorial_map_item::compute_face_normal(Combinatorial_map_3::Dart_const_handle adart) const
|
||||
{
|
||||
typedef Combinatorial_map_3::Dart_of_orbit_const_range<1> Dart_in_facet_range;
|
||||
typedef Kernel::Vector_3 Vector_3;
|
||||
Vector_3 normal = CGAL::NULL_VECTOR;
|
||||
|
||||
Dart_in_facet_range vertices=combinatorial_map().darts_of_orbit<1>(adart);
|
||||
Kernel::Point_3 points[3];
|
||||
int index=0;
|
||||
Dart_in_facet_range::const_iterator pit=vertices.begin();
|
||||
for (;pit!=vertices.end() && index!=3;++pit,++index ){
|
||||
points[index]=pit->attribute<0>()->point();
|
||||
}
|
||||
|
||||
if (index!=3) return normal;
|
||||
|
||||
do{
|
||||
Vector_3 n = CGAL::cross_product(points[2]-points[1],points[0]-points[1]);
|
||||
if (n != Vector_3(0,0,0) )
|
||||
normal = normal + (n / std::sqrt(n*n));
|
||||
points[0]=points[1];
|
||||
points[1]=points[2];
|
||||
if ( pit==vertices.end() ) break;
|
||||
|
||||
points[2]=pit->attribute<0>()->point();
|
||||
++pit;
|
||||
}while(true);
|
||||
|
||||
return normal == Vector_3(0,0,0)? normal : normal / std::sqrt(normal * normal);
|
||||
typedef Combinatorial_map_3::Dart_of_orbit_const_range<1> Dart_in_facet_range;
|
||||
typedef Kernel::Vector_3 Vector_3;
|
||||
Vector_3 normal = CGAL::NULL_VECTOR;
|
||||
|
||||
Dart_in_facet_range vertices=combinatorial_map().darts_of_orbit<1>(adart);
|
||||
Kernel::Point_3 points[3];
|
||||
int index=0;
|
||||
Dart_in_facet_range::const_iterator pit=vertices.begin();
|
||||
for (;pit!=vertices.end() && index!=3;++pit,++index ){
|
||||
points[index]=pit->attribute<0>()->point();
|
||||
}
|
||||
|
||||
if (index!=3) return normal;
|
||||
|
||||
do{
|
||||
Vector_3 n = CGAL::cross_product(points[2]-points[1],points[0]-points[1]);
|
||||
if (n != Vector_3(0,0,0) )
|
||||
normal = normal + (n / std::sqrt(n*n));
|
||||
points[0]=points[1];
|
||||
points[1]=points[2];
|
||||
if ( pit==vertices.end() ) break;
|
||||
|
||||
points[2]=pit->attribute<0>()->point();
|
||||
++pit;
|
||||
}while(true);
|
||||
|
||||
return normal == Vector_3(0,0,0)? normal : normal / std::sqrt(normal * normal);
|
||||
}
|
||||
|
||||
void Scene_combinatorial_map_item::set_next_volume(){
|
||||
++volume_to_display;
|
||||
volume_to_display=volume_to_display%(combinatorial_map().attributes<3>().size()+1);
|
||||
emit itemChanged();
|
||||
++volume_to_display;
|
||||
volume_to_display=volume_to_display%(combinatorial_map().attributes<3>().size()+1);
|
||||
emit itemChanged();
|
||||
|
||||
if (exportSelectedVolume!=NULL && ( volume_to_display==1 || volume_to_display==0 ) )
|
||||
exportSelectedVolume->setEnabled(!exportSelectedVolume->isEnabled());
|
||||
if (exportSelectedVolume!=NULL && ( volume_to_display==1 || volume_to_display==0 ) )
|
||||
exportSelectedVolume->setEnabled(!exportSelectedVolume->isEnabled());
|
||||
}
|
||||
|
||||
|
||||
template <class Predicate>
|
||||
void Scene_combinatorial_map_item::export_as_polyhedron(Predicate pred,const QString& name) const {
|
||||
typedef Combinatorial_map_3::Dart_const_handle Dart_handle;
|
||||
typedef Combinatorial_map_3::One_dart_per_cell_const_range<3> One_dart_per_vol_range;
|
||||
typedef CGAL::internal::Import_volume_as_polyhedron<Polyhedron::HalfedgeDS> Volume_import_modifier;
|
||||
|
||||
std::vector<Dart_handle> darts;
|
||||
One_dart_per_vol_range cell_range=combinatorial_map().template one_dart_per_cell<3>();
|
||||
typedef Combinatorial_map_3::Dart_const_handle Dart_handle;
|
||||
typedef Combinatorial_map_3::One_dart_per_cell_const_range<3> One_dart_per_vol_range;
|
||||
typedef CGAL::internal::Import_volume_as_polyhedron<Polyhedron::HalfedgeDS> Volume_import_modifier;
|
||||
|
||||
|
||||
for (One_dart_per_vol_range::const_iterator it = cell_range.begin();it!= cell_range.end() ; ++it )
|
||||
if ( pred(it) ){
|
||||
darts.push_back(it);
|
||||
if (Predicate::only_one_run) break;
|
||||
std::vector<Dart_handle> darts;
|
||||
One_dart_per_vol_range cell_range=combinatorial_map().template one_dart_per_cell<3>();
|
||||
|
||||
|
||||
for (One_dart_per_vol_range::const_iterator it = cell_range.begin();it!= cell_range.end() ; ++it )
|
||||
if ( pred(it) ){
|
||||
darts.push_back(it);
|
||||
if (Predicate::only_one_run) break;
|
||||
}
|
||||
|
||||
if (!darts.empty())
|
||||
{
|
||||
Volume_import_modifier modifier=Predicate::swap_orientation?
|
||||
Volume_import_modifier(combinatorial_map(),darts.begin(),darts.end(),Predicate::swap_orientation):
|
||||
Volume_import_modifier(combinatorial_map(),darts.begin(),darts.end());
|
||||
|
||||
Polyhedron* new_poly=new Polyhedron();
|
||||
new_poly->delegate(modifier);
|
||||
Scene_polyhedron_item* new_item = new Scene_polyhedron_item(new_poly);
|
||||
new_item->setName(name);
|
||||
last_known_scene->addItem(new_item);
|
||||
}
|
||||
|
||||
if (!darts.empty())
|
||||
{
|
||||
Volume_import_modifier modifier=Predicate::swap_orientation?
|
||||
Volume_import_modifier(combinatorial_map(),darts.begin(),darts.end(),Predicate::swap_orientation):
|
||||
Volume_import_modifier(combinatorial_map(),darts.begin(),darts.end());
|
||||
|
||||
Polyhedron* new_poly=new Polyhedron();
|
||||
new_poly->delegate(modifier);
|
||||
Scene_polyhedron_item* new_item = new Scene_polyhedron_item(new_poly);
|
||||
new_item->setName(name);
|
||||
last_known_scene->addItem(new_item);
|
||||
}
|
||||
}
|
||||
|
||||
struct Select_volume{
|
||||
static const bool only_one_run=true;
|
||||
static const bool swap_orientation=false;
|
||||
Select_volume(std::size_t i):volume_to_select(i),index(0){}
|
||||
template <class Dart_handle>
|
||||
bool operator() (Dart_handle){
|
||||
return ++index==volume_to_select;
|
||||
}
|
||||
static const bool only_one_run=true;
|
||||
static const bool swap_orientation=false;
|
||||
Select_volume(std::size_t i):volume_to_select(i),index(0){}
|
||||
template <class Dart_handle>
|
||||
bool operator() (Dart_handle){
|
||||
return ++index==volume_to_select;
|
||||
}
|
||||
private:
|
||||
std::size_t volume_to_select;
|
||||
std::size_t index;
|
||||
std::size_t volume_to_select;
|
||||
std::size_t index;
|
||||
};
|
||||
|
||||
void Scene_combinatorial_map_item::export_current_volume_as_polyhedron() const {
|
||||
if (volume_to_display==0) return; //no volume selected
|
||||
|
||||
Select_volume predicate(volume_to_display);
|
||||
export_as_polyhedron(predicate,QString("%1_%2").arg(this->name()).arg(volume_to_display-1));
|
||||
if (volume_to_display==0) return; //no volume selected
|
||||
|
||||
Select_volume predicate(volume_to_display);
|
||||
export_as_polyhedron(predicate,QString("%1_%2").arg(this->name()).arg(volume_to_display-1));
|
||||
}
|
||||
|
||||
struct Select_union{
|
||||
static const bool only_one_run=false;
|
||||
static const bool swap_orientation=true;
|
||||
template <class Dart_handle>
|
||||
bool operator() (Dart_handle d){ return d->template attribute<3>()->info().outside.size()==2; }
|
||||
static const bool only_one_run=false;
|
||||
static const bool swap_orientation=true;
|
||||
template <class Dart_handle>
|
||||
bool operator() (Dart_handle d){ return d->template attribute<3>()->info().outside.size()==2; }
|
||||
};
|
||||
|
||||
struct Select_inter{
|
||||
static const bool only_one_run=false;
|
||||
static const bool swap_orientation=false;
|
||||
template <class Dart_handle>
|
||||
bool operator() (Dart_handle d){ return d->template attribute<3>()->info().inside.size()==2; }
|
||||
static const bool only_one_run=false;
|
||||
static const bool swap_orientation=false;
|
||||
template <class Dart_handle>
|
||||
bool operator() (Dart_handle d){ return d->template attribute<3>()->info().inside.size()==2; }
|
||||
};
|
||||
|
||||
struct Select_A_minus_B{
|
||||
static const bool only_one_run=false;
|
||||
static const bool swap_orientation=false;
|
||||
Select_A_minus_B(void* address):address_of_A(address){}
|
||||
template <class Dart_handle>
|
||||
bool operator() (Dart_handle d){
|
||||
return d->template attribute<3>()->info().inside.size()==1 &&
|
||||
static_cast<void*>(*d->template attribute<3>()->info().inside.begin())==address_of_A;
|
||||
}
|
||||
static const bool only_one_run=false;
|
||||
static const bool swap_orientation=false;
|
||||
Select_A_minus_B(void* address):address_of_A(address){}
|
||||
template <class Dart_handle>
|
||||
bool operator() (Dart_handle d){
|
||||
return d->template attribute<3>()->info().inside.size()==1 &&
|
||||
static_cast<void*>(*d->template attribute<3>()->info().inside.begin())==address_of_A;
|
||||
}
|
||||
private:
|
||||
void* address_of_A;
|
||||
void* address_of_A;
|
||||
};
|
||||
|
||||
struct Select_B_minus_A{
|
||||
static const bool only_one_run=false;
|
||||
static const bool swap_orientation=false;
|
||||
Select_B_minus_A(void* address):address_of_A(address){}
|
||||
template <class Dart_handle>
|
||||
bool operator() (Dart_handle d){
|
||||
return d->template attribute<3>()->info().inside.size()==1 &&
|
||||
static_cast<void*>(*d->template attribute<3>()->info().inside.begin())!=address_of_A;
|
||||
}
|
||||
static const bool only_one_run=false;
|
||||
static const bool swap_orientation=false;
|
||||
Select_B_minus_A(void* address):address_of_A(address){}
|
||||
template <class Dart_handle>
|
||||
bool operator() (Dart_handle d){
|
||||
return d->template attribute<3>()->info().inside.size()==1 &&
|
||||
static_cast<void*>(*d->template attribute<3>()->info().inside.begin())!=address_of_A;
|
||||
}
|
||||
private:
|
||||
void* address_of_A;
|
||||
void* address_of_A;
|
||||
};
|
||||
|
||||
void Scene_combinatorial_map_item::export_union_as_polyhedron() const {
|
||||
export_as_polyhedron(Select_union(),QString("%1_union_%2").arg("A").arg("B"));
|
||||
export_as_polyhedron(Select_union(),QString("%1_union_%2").arg("A").arg("B"));
|
||||
}
|
||||
void Scene_combinatorial_map_item::export_intersection_as_polyhedron() const{
|
||||
export_as_polyhedron(Select_inter(),QString("%1_inter_%2").arg("A").arg("B"));
|
||||
export_as_polyhedron(Select_inter(),QString("%1_inter_%2").arg("A").arg("B"));
|
||||
}
|
||||
void Scene_combinatorial_map_item::export_A_minus_B_as_polyhedron() const{
|
||||
Select_A_minus_B predicate(address_of_A);
|
||||
export_as_polyhedron(predicate,QString("%1_minus_%2").arg("A").arg("B"));
|
||||
Select_A_minus_B predicate(address_of_A);
|
||||
export_as_polyhedron(predicate,QString("%1_minus_%2").arg("A").arg("B"));
|
||||
}
|
||||
void Scene_combinatorial_map_item::export_B_minus_A_as_polyhedron() const{
|
||||
Select_B_minus_A predicate(address_of_A);
|
||||
export_as_polyhedron(predicate,QString("%1_minus_%2").arg("B").arg("A"));
|
||||
Select_B_minus_A predicate(address_of_A);
|
||||
export_as_polyhedron(predicate,QString("%1_minus_%2").arg("B").arg("A"));
|
||||
}
|
||||
|
||||
QMenu* Scene_combinatorial_map_item::contextMenu()
|
||||
{
|
||||
const char* prop_name = "Menu modified by Scene_combinatorial_map_item.";
|
||||
const char* prop_name = "Menu modified by Scene_combinatorial_map_item.";
|
||||
|
||||
QMenu* menu = Scene_item::contextMenu();
|
||||
QMenu* menu = Scene_item::contextMenu();
|
||||
|
||||
// Use dynamic properties:
|
||||
// http://doc.trolltech.com/lastest/qobject.html#property
|
||||
bool menuChanged = menu->property(prop_name).toBool();
|
||||
// Use dynamic properties:
|
||||
// http://doc.trolltech.com/lastest/qobject.html#property
|
||||
bool menuChanged = menu->property(prop_name).toBool();
|
||||
|
||||
if(!menuChanged) {
|
||||
QAction* actionSelectNextVolume =
|
||||
menu->addAction(tr("Iterate over volumes"));
|
||||
actionSelectNextVolume->setObjectName("actionSelectNextVolume");
|
||||
connect(actionSelectNextVolume, SIGNAL(triggered()),this, SLOT(set_next_volume()));
|
||||
if(!menuChanged) {
|
||||
QAction* actionSelectNextVolume =
|
||||
menu->addAction(tr("Iterate over volumes"));
|
||||
actionSelectNextVolume->setObjectName("actionSelectNextVolume");
|
||||
connect(actionSelectNextVolume, SIGNAL(triggered()),this, SLOT(set_next_volume()));
|
||||
|
||||
exportSelectedVolume =
|
||||
menu->addAction(tr("Export current volume as polyhedron"));
|
||||
exportSelectedVolume->setObjectName("exportSelectedVolume");
|
||||
connect(exportSelectedVolume, SIGNAL(triggered()),this, SLOT(export_current_volume_as_polyhedron()));
|
||||
exportSelectedVolume->setEnabled(volume_to_display!=0);
|
||||
menu->setProperty(prop_name, true);
|
||||
|
||||
if(is_from_corefinement()){
|
||||
//Export union as polyhedron
|
||||
QAction* exportUnion =
|
||||
menu->addAction(tr("Export union as polyhedron"));
|
||||
exportUnion->setObjectName("exportUnion");
|
||||
connect(exportUnion, SIGNAL(triggered()),this, SLOT(export_union_as_polyhedron()));
|
||||
exportSelectedVolume =
|
||||
menu->addAction(tr("Export current volume as polyhedron"));
|
||||
exportSelectedVolume->setObjectName("exportSelectedVolume");
|
||||
connect(exportSelectedVolume, SIGNAL(triggered()),this, SLOT(export_current_volume_as_polyhedron()));
|
||||
exportSelectedVolume->setEnabled(volume_to_display!=0);
|
||||
menu->setProperty(prop_name, true);
|
||||
|
||||
//Export intersection as polyhedron
|
||||
QAction* exportIntersection =
|
||||
menu->addAction(tr("Export intersection as polyhedron"));
|
||||
exportIntersection->setObjectName("exportIntersection");
|
||||
connect(exportIntersection, SIGNAL(triggered()),this, SLOT(export_intersection_as_polyhedron()));
|
||||
if(is_from_corefinement()){
|
||||
//Export union as polyhedron
|
||||
QAction* exportUnion =
|
||||
menu->addAction(tr("Export union as polyhedron"));
|
||||
exportUnion->setObjectName("exportUnion");
|
||||
connect(exportUnion, SIGNAL(triggered()),this, SLOT(export_union_as_polyhedron()));
|
||||
|
||||
//Export A minus B as polyhedron
|
||||
QAction* exportAMinusB =
|
||||
menu->addAction(tr("Export A minus B as polyhedron"));
|
||||
exportAMinusB->setObjectName("exportAMinusB");
|
||||
connect(exportAMinusB, SIGNAL(triggered()),this, SLOT(export_A_minus_B_as_polyhedron()));
|
||||
//Export intersection as polyhedron
|
||||
QAction* exportIntersection =
|
||||
menu->addAction(tr("Export intersection as polyhedron"));
|
||||
exportIntersection->setObjectName("exportIntersection");
|
||||
connect(exportIntersection, SIGNAL(triggered()),this, SLOT(export_intersection_as_polyhedron()));
|
||||
|
||||
//Export B minus A as polyhedron
|
||||
QAction* exportBMinusA =
|
||||
menu->addAction(tr("Export B minus A as polyhedron"));
|
||||
exportBMinusA->setObjectName("exportBMinusA");
|
||||
connect(exportBMinusA, SIGNAL(triggered()),this, SLOT(export_B_minus_A_as_polyhedron()));
|
||||
|
||||
//Export A minus B as polyhedron
|
||||
QAction* exportAMinusB =
|
||||
menu->addAction(tr("Export A minus B as polyhedron"));
|
||||
exportAMinusB->setObjectName("exportAMinusB");
|
||||
connect(exportAMinusB, SIGNAL(triggered()),this, SLOT(export_A_minus_B_as_polyhedron()));
|
||||
|
||||
//Export B minus A as polyhedron
|
||||
QAction* exportBMinusA =
|
||||
menu->addAction(tr("Export B minus A as polyhedron"));
|
||||
exportBMinusA->setObjectName("exportBMinusA");
|
||||
connect(exportBMinusA, SIGNAL(triggered()),this, SLOT(export_B_minus_A_as_polyhedron()));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return menu;
|
||||
return menu;
|
||||
}
|
||||
|
||||
bool Scene_combinatorial_map_item::keyPressEvent(QKeyEvent* e){
|
||||
if (e->key()==Qt::Key_N){
|
||||
set_next_volume();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if (e->key()==Qt::Key_N){
|
||||
set_next_volume();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Scene_combinatorial_map_item::direct_draw() const {
|
||||
#if 0
|
||||
typedef Combinatorial_map_3::One_dart_per_cell_const_range<3> Volume_dart_range;
|
||||
typedef Combinatorial_map_3::One_dart_per_incident_cell_const_range<2,3> Facet_in_volume_drange;
|
||||
typedef Combinatorial_map_3::Dart_of_orbit_const_range<1> Dart_in_facet_range;
|
||||
Volume_dart_range dart_per_volume_range = combinatorial_map().one_dart_per_cell<3>();
|
||||
|
||||
std::size_t index = 0;
|
||||
for (Volume_dart_range::const_iterator vit=dart_per_volume_range.begin();vit!=dart_per_volume_range.end();++vit)
|
||||
{
|
||||
if (++index!=volume_to_display && volume_to_display!=0) continue;
|
||||
Facet_in_volume_drange facet_range=combinatorial_map().one_dart_per_incident_cell<2,3>(vit);
|
||||
|
||||
for(Facet_in_volume_drange::const_iterator fit=facet_range.begin();fit!=facet_range.end();++fit){
|
||||
Dart_in_facet_range vertices=combinatorial_map().darts_of_orbit<1>(fit);
|
||||
Kernel::Vector_3 normal = compute_face_normal(fit);
|
||||
|
||||
::glBegin(GL_POLYGON);
|
||||
::glNormal3d(normal.x(),normal.y(),normal.z());
|
||||
|
||||
for (Dart_in_facet_range::const_iterator pit=vertices.begin();pit!=vertices.end();++pit ){
|
||||
const Kernel::Point_3& p= pit->attribute<0>()->point();
|
||||
::glVertex3d(p.x(),p.y(),p.z());
|
||||
}
|
||||
::glEnd();
|
||||
}
|
||||
}
|
||||
#else
|
||||
std::size_t index = 0;
|
||||
int voltreated = combinatorial_map().get_new_mark();
|
||||
int facetreated = combinatorial_map().get_new_mark();
|
||||
Combinatorial_map_3::Dart_const_range::const_iterator
|
||||
darts_it=combinatorial_map().darts().begin(), darts_end=combinatorial_map().darts().end();
|
||||
for( ; darts_it!=darts_end; ++darts_it)
|
||||
{
|
||||
if ( !combinatorial_map().is_marked(darts_it,voltreated) )
|
||||
#if 0
|
||||
typedef Combinatorial_map_3::One_dart_per_cell_const_range<3> Volume_dart_range;
|
||||
typedef Combinatorial_map_3::One_dart_per_incident_cell_const_range<2,3> Facet_in_volume_drange;
|
||||
typedef Combinatorial_map_3::Dart_of_orbit_const_range<1> Dart_in_facet_range;
|
||||
Volume_dart_range dart_per_volume_range = combinatorial_map().one_dart_per_cell<3>();
|
||||
std::cout<<"COUCOU"<<std::endl;
|
||||
std::size_t index = 0;
|
||||
for (Volume_dart_range::const_iterator vit=dart_per_volume_range.begin();vit!=dart_per_volume_range.end();++vit)
|
||||
{
|
||||
++index;
|
||||
//iterate over all the darts of the volume
|
||||
Combinatorial_map_3::Dart_of_cell_const_range<3>::const_iterator
|
||||
vol_it=combinatorial_map().darts_of_cell<3>(darts_it).begin(),
|
||||
vol_end=combinatorial_map().darts_of_cell<3>(darts_it).end();
|
||||
if ( volume_to_display!=0 && index!=volume_to_display )
|
||||
{
|
||||
//only mark darts if the volume is not the one to display
|
||||
for ( ;vol_it!=vol_end; ++vol_it )
|
||||
{
|
||||
combinatorial_map().mark(vol_it,facetreated);
|
||||
combinatorial_map().mark(vol_it, voltreated);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( ;vol_it!=vol_end; ++vol_it )
|
||||
{
|
||||
if ( !combinatorial_map().is_marked(vol_it,facetreated) )
|
||||
{
|
||||
Kernel::Vector_3 normal = compute_face_normal(vol_it);
|
||||
if (++index!=volume_to_display && volume_to_display!=0) continue;
|
||||
Facet_in_volume_drange facet_range=combinatorial_map().one_dart_per_incident_cell<2,3>(vit);
|
||||
|
||||
for(Facet_in_volume_drange::const_iterator fit=facet_range.begin();fit!=facet_range.end();++fit){
|
||||
Dart_in_facet_range vertices=combinatorial_map().darts_of_orbit<1>(fit);
|
||||
Kernel::Vector_3 normal = compute_face_normal(fit);
|
||||
|
||||
::glBegin(GL_POLYGON);
|
||||
::glNormal3d(normal.x(),normal.y(),normal.z());
|
||||
|
||||
//iterate over all darts of facets
|
||||
for ( Combinatorial_map_3::Dart_of_orbit_const_range<1>::const_iterator
|
||||
face_it=combinatorial_map().darts_of_orbit<1>(vol_it).begin(),
|
||||
face_end=combinatorial_map().darts_of_orbit<1>(vol_it).end();
|
||||
face_it!=face_end; ++face_it)
|
||||
{
|
||||
const Kernel::Point_3& p= face_it->attribute<0>()->point();
|
||||
::glVertex3d(p.x(),p.y(),p.z());
|
||||
combinatorial_map().mark(face_it,facetreated);
|
||||
combinatorial_map().mark(face_it, voltreated);
|
||||
for (Dart_in_facet_range::const_iterator pit=vertices.begin();pit!=vertices.end();++pit ){
|
||||
const Kernel::Point_3& p= pit->attribute<0>()->point();
|
||||
::glVertex3d(p.x(),p.y(),p.z());
|
||||
}
|
||||
::glEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( index==volume_to_display ) break;
|
||||
}
|
||||
}
|
||||
//mark remaining darts to have an O(1) free_mark
|
||||
for( ; darts_it!=darts_end; ++darts_it)
|
||||
{
|
||||
combinatorial_map().mark(darts_it, facetreated);
|
||||
combinatorial_map().mark(darts_it, voltreated);
|
||||
}
|
||||
#else
|
||||
std::size_t index = 0;
|
||||
int voltreated = combinatorial_map().get_new_mark();
|
||||
int facetreated = combinatorial_map().get_new_mark();
|
||||
Combinatorial_map_3::Dart_const_range::const_iterator
|
||||
darts_it=combinatorial_map().darts().begin(), darts_end=combinatorial_map().darts().end();
|
||||
for( ; darts_it!=darts_end; ++darts_it)
|
||||
{
|
||||
if ( !combinatorial_map().is_marked(darts_it,voltreated) )
|
||||
{
|
||||
++index;
|
||||
//iterate over all the darts of the volume
|
||||
Combinatorial_map_3::Dart_of_cell_const_range<3>::const_iterator
|
||||
vol_it=combinatorial_map().darts_of_cell<3>(darts_it).begin(),
|
||||
vol_end=combinatorial_map().darts_of_cell<3>(darts_it).end();
|
||||
if ( volume_to_display!=0 && index!=volume_to_display )
|
||||
{
|
||||
//only mark darts if the volume is not the one to display
|
||||
for ( ;vol_it!=vol_end; ++vol_it )
|
||||
{
|
||||
combinatorial_map().mark(vol_it,facetreated);
|
||||
combinatorial_map().mark(vol_it, voltreated);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( ;vol_it!=vol_end; ++vol_it )
|
||||
{
|
||||
if ( !combinatorial_map().is_marked(vol_it,facetreated) )
|
||||
{
|
||||
Kernel::Vector_3 normal = compute_face_normal(vol_it);
|
||||
::glBegin(GL_POLYGON);
|
||||
::glNormal3d(normal.x(),normal.y(),normal.z());
|
||||
|
||||
combinatorial_map().free_mark(facetreated);
|
||||
combinatorial_map().free_mark(voltreated);
|
||||
#endif
|
||||
//iterate over all darts of facets
|
||||
for ( Combinatorial_map_3::Dart_of_orbit_const_range<1>::const_iterator
|
||||
face_it=combinatorial_map().darts_of_orbit<1>(vol_it).begin(),
|
||||
face_end=combinatorial_map().darts_of_orbit<1>(vol_it).end();
|
||||
face_it!=face_end; ++face_it)
|
||||
{
|
||||
const Kernel::Point_3& p= face_it->attribute<0>()->point();
|
||||
::glVertex3d(p.x(),p.y(),p.z());
|
||||
combinatorial_map().mark(face_it,facetreated);
|
||||
combinatorial_map().mark(face_it, voltreated);
|
||||
}
|
||||
::glEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( index==volume_to_display ) break;
|
||||
}
|
||||
}
|
||||
//mark remaining darts to have an O(1) free_mark
|
||||
for( ; darts_it!=darts_end; ++darts_it)
|
||||
{
|
||||
combinatorial_map().mark(darts_it, facetreated);
|
||||
combinatorial_map().mark(darts_it, voltreated);
|
||||
}
|
||||
|
||||
combinatorial_map().free_mark(facetreated);
|
||||
combinatorial_map().free_mark(voltreated);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Scene_combinatorial_map_item::direct_draw_edges() const {
|
||||
typedef Combinatorial_map_3::One_dart_per_cell_const_range<1> Edge_darts;
|
||||
Edge_darts darts=combinatorial_map().one_dart_per_cell<1>();
|
||||
::glBegin(GL_LINES);
|
||||
for (Edge_darts::const_iterator dit=darts.begin();dit!=darts.end();++dit){
|
||||
CGAL_assertion(!dit->is_free(1));
|
||||
const Kernel::Point_3& a = dit->attribute<0>()->point();
|
||||
const Kernel::Point_3& b = dit->beta(1)->attribute<0>()->point();
|
||||
::glVertex3d(a.x(),a.y(),a.z());
|
||||
::glVertex3d(b.x(),b.y(),b.z());
|
||||
}
|
||||
::glEnd();
|
||||
typedef Combinatorial_map_3::One_dart_per_cell_const_range<1> Edge_darts;
|
||||
Edge_darts darts=combinatorial_map().one_dart_per_cell<1>();
|
||||
::glBegin(GL_LINES);
|
||||
for (Edge_darts::const_iterator dit=darts.begin();dit!=darts.end();++dit){
|
||||
CGAL_assertion(!dit->is_free(1));
|
||||
const Kernel::Point_3& a = dit->attribute<0>()->point();
|
||||
const Kernel::Point_3& b = dit->beta(1)->attribute<0>()->point();
|
||||
::glVertex3d(a.x(),a.y(),a.z());
|
||||
::glVertex3d(b.x(),b.y(),b.z());
|
||||
}
|
||||
::glEnd();
|
||||
}
|
||||
|
||||
void Scene_combinatorial_map_item::draw_points() const{
|
||||
typedef Combinatorial_map_3::Attribute_const_range<0>::type Point_range;
|
||||
const Point_range& points=combinatorial_map().attributes<0>();
|
||||
::glBegin(GL_POINTS);
|
||||
for(Point_range::const_iterator pit=boost::next(points.begin());pit!=points.end();++pit){
|
||||
const Kernel::Point_3& p=pit->point();
|
||||
::glVertex3d(p.x(),p.y(),p.z());
|
||||
}
|
||||
::glEnd();
|
||||
typedef Combinatorial_map_3::Attribute_const_range<0>::type Point_range;
|
||||
const Point_range& points=combinatorial_map().attributes<0>();
|
||||
::glBegin(GL_POINTS);
|
||||
for(Point_range::const_iterator pit=boost::next(points.begin());pit!=points.end();++pit){
|
||||
const Kernel::Point_3& p=pit->point();
|
||||
::glVertex3d(p.x(),p.y(),p.z());
|
||||
}
|
||||
::glEnd();
|
||||
}
|
||||
|
||||
bool Scene_combinatorial_map_item::isEmpty() const {return combinatorial_map().number_of_darts()==0;}
|
||||
|
||||
Scene_combinatorial_map_item::Bbox
|
||||
Scene_combinatorial_map_item::bbox() const {
|
||||
typedef Combinatorial_map_3::Attribute_const_range<0>::type Point_range;
|
||||
const Point_range& points=combinatorial_map().attributes<0>();
|
||||
CGAL::Bbox_3 bbox=points.begin()->point().bbox();
|
||||
for(Point_range::const_iterator pit=boost::next(points.begin());pit!=points.end();++pit)
|
||||
bbox=bbox+pit->point().bbox();
|
||||
return Bbox(bbox.xmin(),bbox.ymin(),bbox.zmin(),
|
||||
bbox.xmax(),bbox.ymax(),bbox.zmax());
|
||||
typedef Combinatorial_map_3::Attribute_const_range<0>::type Point_range;
|
||||
const Point_range& points=combinatorial_map().attributes<0>();
|
||||
CGAL::Bbox_3 bbox=points.begin()->point().bbox();
|
||||
for(Point_range::const_iterator pit=boost::next(points.begin());pit!=points.end();++pit)
|
||||
bbox=bbox+pit->point().bbox();
|
||||
return Bbox(bbox.xmin(),bbox.ymin(),bbox.zmin(),
|
||||
bbox.xmax(),bbox.ymax(),bbox.zmax());
|
||||
}
|
||||
|
||||
|
||||
QString Scene_combinatorial_map_item::toolTip() const{
|
||||
if(!m_combinatorial_map)
|
||||
return QString();
|
||||
if(!m_combinatorial_map)
|
||||
return QString();
|
||||
|
||||
std::vector<unsigned int> cells(5);
|
||||
for (unsigned int i=0; i<=4; ++i)
|
||||
cells[i]=i;
|
||||
std::vector<unsigned int> res = combinatorial_map().count_cells(cells);
|
||||
if (volume_to_display==0)
|
||||
std::vector<unsigned int> cells(5);
|
||||
for (unsigned int i=0; i<=4; ++i)
|
||||
cells[i]=i;
|
||||
std::vector<unsigned int> res = combinatorial_map().count_cells(cells);
|
||||
if (volume_to_display==0)
|
||||
return QObject::tr("<p>Combinatorial_map_3 <b>%1</b> (mode: %8, color: %9)</p>"
|
||||
"<p>Number of darts: %2<br />"
|
||||
"Number of vertices: %3<br />"
|
||||
"Number of edges: %4<br />"
|
||||
"Number of facets: %5<br />"
|
||||
"Number of volumes: %6<br />"
|
||||
"Number of connected components: %7</p>")
|
||||
.arg(this->name())
|
||||
.arg(combinatorial_map().number_of_darts())
|
||||
.arg(res[0])
|
||||
.arg(res[1])
|
||||
.arg(res[2])
|
||||
.arg(res[3])
|
||||
.arg(res[4])
|
||||
.arg(this->renderingModeName())
|
||||
.arg(this->color().name());
|
||||
return QObject::tr("<p>Combinatorial_map_3 <b>%1</b> (mode: %8, color: %9)</p>"
|
||||
"<p>Number of darts: %2<br />"
|
||||
"Number of vertices: %3<br />"
|
||||
"Number of edges: %4<br />"
|
||||
"Number of facets: %5<br />"
|
||||
"Number of volumes: %6<br />"
|
||||
"Number of connected components: %7</p>")
|
||||
.arg(this->name())
|
||||
.arg(combinatorial_map().number_of_darts())
|
||||
.arg(res[0])
|
||||
.arg(res[1])
|
||||
.arg(res[2])
|
||||
.arg(res[3])
|
||||
.arg(res[4])
|
||||
.arg(this->renderingModeName())
|
||||
.arg(this->color().name());
|
||||
return QObject::tr("<p>Combinatorial_map_3 <b>%1</b> (mode: %8, color: %9)</p>"
|
||||
"<p>Number of darts: %2<br />"
|
||||
"Number of vertices: %3<br />"
|
||||
"Number of edges: %4<br />"
|
||||
"Number of facets: %5<br />"
|
||||
"Number of volumes: %6<br />"
|
||||
"Number of connected components: %7 <br />"
|
||||
"Currently Displaying facets of volume: %10 </p>")
|
||||
.arg(this->name())
|
||||
.arg(combinatorial_map().number_of_darts())
|
||||
.arg(res[0])
|
||||
.arg(res[1])
|
||||
.arg(res[2])
|
||||
.arg(res[3])
|
||||
.arg(res[4])
|
||||
.arg(this->renderingModeName())
|
||||
.arg(this->color().name())
|
||||
.arg(volume_to_display-1);
|
||||
"Number of connected components: %7 <br />"
|
||||
"Currently Displaying facets of volume: %10 </p>")
|
||||
.arg(this->name())
|
||||
.arg(combinatorial_map().number_of_darts())
|
||||
.arg(res[0])
|
||||
.arg(res[1])
|
||||
.arg(res[2])
|
||||
.arg(res[3])
|
||||
.arg(res[4])
|
||||
.arg(this->renderingModeName())
|
||||
.arg(this->color().name())
|
||||
.arg(volume_to_display-1);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@
|
|||
#include "Scene_combinatorial_map_item_config.h"
|
||||
#include "Scene_item_with_display_list.h"
|
||||
#include <iostream>
|
||||
|
||||
#include <QGLBuffer>
|
||||
#include <QGLShader>
|
||||
#include <QGLShaderProgram>
|
||||
#include "Polyhedron_type.h"
|
||||
|
||||
typedef CGAL::internal_IOP::Item_with_points_and_volume_info<Kernel,Polyhedron> Items;
|
||||
|
|
@ -19,64 +21,81 @@ class Scene_interface;
|
|||
class Scene_polyhedron_item;
|
||||
|
||||
class SCENE_COMBINATORIAL_MAP_ITEM_EXPORT Scene_combinatorial_map_item
|
||||
: public Scene_item_with_display_list
|
||||
: public Scene_item_with_display_list
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
Scene_combinatorial_map_item(Scene_interface*,void* ad_A=NULL);
|
||||
~Scene_combinatorial_map_item();
|
||||
Scene_combinatorial_map_item(Scene_interface*,void* ad_A=NULL);
|
||||
~Scene_combinatorial_map_item();
|
||||
|
||||
Scene_combinatorial_map_item* clone() const;
|
||||
// Function to override the context menu
|
||||
QMenu* contextMenu();
|
||||
Scene_combinatorial_map_item* clone() const;
|
||||
// Function to override the context menu
|
||||
QMenu* contextMenu();
|
||||
|
||||
// bool load(std::istream& in);
|
||||
// void load(Scene_polyhedron_item*);
|
||||
// bool save(std::ostream& out) const;
|
||||
// bool load(std::istream& in);
|
||||
// void load(Scene_polyhedron_item*);
|
||||
// bool save(std::ostream& out) const;
|
||||
|
||||
QString toolTip() const;
|
||||
QString toolTip() const;
|
||||
|
||||
// Indicate if rendering mode is supported
|
||||
virtual bool supportsRenderingMode(RenderingMode m) const { return (m != Gouraud && m!=PointsPlusNormals && m!=Splatting); } // CHECK THIS!
|
||||
//Event handling
|
||||
virtual bool keyPressEvent(QKeyEvent*);
|
||||
// OpenGL drawing in a display list
|
||||
void direct_draw() const;
|
||||
void direct_draw_edges() const;
|
||||
void draw_points() const;
|
||||
// Indicate if rendering mode is supported
|
||||
virtual bool supportsRenderingMode(RenderingMode m) const { return (m != Gouraud && m!=PointsPlusNormals && m!=Splatting); } // CHECK THIS!
|
||||
//Event handling
|
||||
virtual bool keyPressEvent(QKeyEvent*);
|
||||
// OpenGL drawing in a display list
|
||||
void direct_draw() const;
|
||||
void direct_draw_edges() const;
|
||||
void draw_points() const;
|
||||
|
||||
bool isFinite() const { return true; }
|
||||
bool is_from_corefinement() const {return address_of_A!=NULL;}
|
||||
bool isEmpty() const;
|
||||
Bbox bbox() const;
|
||||
|
||||
const Combinatorial_map_3& combinatorial_map() const
|
||||
{
|
||||
return *m_combinatorial_map;
|
||||
}
|
||||
bool isFinite() const { return true; }
|
||||
bool is_from_corefinement() const {return address_of_A!=NULL;}
|
||||
bool isEmpty() const;
|
||||
Bbox bbox() const;
|
||||
|
||||
const Combinatorial_map_3& combinatorial_map() const
|
||||
{
|
||||
return *m_combinatorial_map;
|
||||
}
|
||||
|
||||
Combinatorial_map_3& combinatorial_map()
|
||||
{
|
||||
return *m_combinatorial_map;
|
||||
}
|
||||
|
||||
Combinatorial_map_3* m_combinatorial_map;
|
||||
|
||||
Combinatorial_map_3& combinatorial_map()
|
||||
{
|
||||
return *m_combinatorial_map;
|
||||
}
|
||||
|
||||
Combinatorial_map_3* m_combinatorial_map;
|
||||
|
||||
private:
|
||||
Kernel::Vector_3 compute_face_normal(Combinatorial_map_3::Dart_const_handle adart) const;
|
||||
Scene_interface* last_known_scene;
|
||||
std::size_t volume_to_display;
|
||||
QAction* exportSelectedVolume;
|
||||
void* address_of_A;
|
||||
template <class Predicate> void export_as_polyhedron(Predicate,const QString&) const;
|
||||
Kernel::Vector_3 compute_face_normal(Combinatorial_map_3::Dart_const_handle adart) const;
|
||||
Scene_interface* last_known_scene;
|
||||
std::size_t volume_to_display;
|
||||
QAction* exportSelectedVolume;
|
||||
void* address_of_A;
|
||||
template <class Predicate> void export_as_polyhedron(Predicate,const QString&) const;
|
||||
|
||||
std::vector<float> positions;
|
||||
std::vector<float> normals;
|
||||
std::vector<float> color_lines;
|
||||
std::vector<float> color_facets;
|
||||
|
||||
QGLShaderProgram *rendering_program;
|
||||
GLint location[9];
|
||||
|
||||
GLuint vao;
|
||||
QGLBuffer buffer[5];
|
||||
void initialize_buffers();
|
||||
void compile_shaders(void);
|
||||
void compute_normals_and_vertices(void);
|
||||
void uniform_attrib(Viewer_interface*, int) const;
|
||||
void compute_colors();
|
||||
|
||||
public slots:
|
||||
void set_next_volume();
|
||||
void export_current_volume_as_polyhedron() const;
|
||||
void export_union_as_polyhedron() const;
|
||||
void export_intersection_as_polyhedron() const;
|
||||
void export_A_minus_B_as_polyhedron() const;
|
||||
void export_B_minus_A_as_polyhedron() const;
|
||||
void set_next_volume();
|
||||
void export_current_volume_as_polyhedron() const;
|
||||
void export_union_as_polyhedron() const;
|
||||
void export_intersection_as_polyhedron() const;
|
||||
void export_A_minus_B_as_polyhedron() const;
|
||||
void export_B_minus_A_as_polyhedron() const;
|
||||
|
||||
}; // end class Scene_combinatorial_map_item
|
||||
|
||||
#endif // SCENE_COMBINATORIAL_MAP_ITEM_H
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -21,6 +21,9 @@
|
|||
#include "ui_Deform_mesh.h"
|
||||
#include <CGAL/Surface_mesh_deformation.h>
|
||||
#include <boost/function_output_iterator.hpp>
|
||||
#include <QGLBuffer>
|
||||
#include <QGLShader>
|
||||
#include <QGLShaderProgram>
|
||||
|
||||
|
||||
typedef Polyhedron::Vertex_handle Vertex_handle;
|
||||
|
|
@ -197,9 +200,11 @@ public:
|
|||
return m == Gouraud;
|
||||
}
|
||||
// Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list
|
||||
void draw() const;
|
||||
void draw_edges() const;
|
||||
void draw_bbox(const Scene_interface::Bbox& bb ) const;
|
||||
void draw() const{}
|
||||
void draw(Viewer_interface*) const;
|
||||
void draw_edges() const{};
|
||||
void draw_edges(Viewer_interface*) const;
|
||||
void draw_bbox(const Scene_interface::Bbox&) const;
|
||||
void gl_draw_edge(double px, double py, double pz,
|
||||
double qx, double qy, double qz) const;
|
||||
void gl_draw_point(const Point& p) const;
|
||||
|
|
@ -227,7 +232,7 @@ public:
|
|||
|
||||
protected:
|
||||
void timerEvent(QTimerEvent *event);
|
||||
void draw_ROI_and_control_vertices() const;
|
||||
void draw_ROI_and_control_vertices(Viewer_interface *viewer) const;
|
||||
|
||||
public slots:
|
||||
void changed();
|
||||
|
|
@ -264,10 +269,42 @@ private:
|
|||
Ui::DeformMesh* ui_widget;
|
||||
Scene_polyhedron_item* poly_item;
|
||||
// For drawing
|
||||
std::vector<double> positions;
|
||||
std::vector<GLdouble> positions;
|
||||
std::vector<unsigned int> tris;
|
||||
std::vector<unsigned int> edges;
|
||||
std::vector<double> normals;
|
||||
std::vector<GLdouble> color_lines;
|
||||
std::vector<GLdouble> color_bbox;
|
||||
std::vector<GLdouble> color_edges;
|
||||
std::vector<GLdouble> ROI_points;
|
||||
std::vector<GLdouble> control_points;
|
||||
std::vector<GLdouble> ROI_color;
|
||||
std::vector<GLdouble> control_color;
|
||||
std::vector<GLdouble> normals;
|
||||
std::vector<GLdouble> pos_bbox;
|
||||
std::vector<GLdouble> pos_axis;
|
||||
std::vector<GLdouble> pos_sphere;
|
||||
std::vector<GLdouble> normals_sphere;
|
||||
std::vector<GLdouble> centers_control;
|
||||
std::vector<GLdouble> centers_ROI;
|
||||
std::vector<GLdouble> color_sphere_ROI;
|
||||
std::vector<GLdouble> color_sphere_control;
|
||||
GLuint rendering_program_facets;
|
||||
GLuint rendering_program_lines;
|
||||
GLuint rendering_program_points;
|
||||
GLuint rendering_program_spheres;
|
||||
GLint location[22];
|
||||
GLuint vao[3];
|
||||
GLuint buffer[19];
|
||||
|
||||
void initialize_buffers();
|
||||
void compile_shaders(void);
|
||||
void compute_normals_and_vertices(void);
|
||||
void uniform_attrib(Viewer_interface*, int) const;
|
||||
void compute_bbox(const Scene_interface::Bbox&);
|
||||
void create_Sphere(double);
|
||||
|
||||
|
||||
|
||||
|
||||
Deform_mesh deform_mesh;
|
||||
typedef std::list<Control_vertices_data> Ctrl_vertices_group_data_list;
|
||||
|
|
@ -664,6 +701,7 @@ protected:
|
|||
normals[id*3] = n.x();
|
||||
normals[id*3+1] = n.y();
|
||||
normals[id*3+2] = n.z();
|
||||
|
||||
}
|
||||
}
|
||||
protected:
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -6,7 +6,6 @@
|
|||
#include "Scene_implicit_function_item_config.h"
|
||||
#include "implicit_functions/Implicit_function_interface.h"
|
||||
#include "Color_ramp.h"
|
||||
|
||||
#include <QGLViewer/manipulatedFrame.h>
|
||||
#include <QGLViewer/qglviewer.h>
|
||||
|
||||
|
|
@ -14,7 +13,30 @@
|
|||
|
||||
class Viewer_interface;
|
||||
|
||||
class Texture{
|
||||
private:
|
||||
int Width;
|
||||
int Height;
|
||||
int size;
|
||||
GLubyte *data;
|
||||
public:
|
||||
Texture(int w, int h)
|
||||
{
|
||||
Width = w;
|
||||
Height = h;
|
||||
size = 3*Height*Width;
|
||||
data = new GLubyte[size];
|
||||
}
|
||||
int getWidth() const {return Width;}
|
||||
int getHeight() const {return Height;}
|
||||
int getSize() const {return size;}
|
||||
void setData(int i, int j, int r, int g, int b){
|
||||
data[j*Width*3 +i*3] = r;
|
||||
data[j*Width*3 +i*3+1] = g;
|
||||
data[j*Width*3 +i*3+2] = b;}
|
||||
GLubyte* getData(){return data; }
|
||||
|
||||
};
|
||||
class SCENE_IMPLICIT_FUNCTION_ITEM_EXPORT Scene_implicit_function_item
|
||||
: public Scene_item_with_display_list
|
||||
{
|
||||
|
|
@ -40,13 +62,15 @@ public:
|
|||
virtual ManipulatedFrame* manipulatedFrame() { return frame_; }
|
||||
|
||||
// draw (overload only direct_draw() to use display list of base class)
|
||||
virtual void direct_draw() const;
|
||||
virtual void direct_draw() const{}
|
||||
virtual void direct_draw(Viewer_interface*) const;
|
||||
// actually draw() is also overloaded to detect when the cut plane is moved
|
||||
virtual void draw(Viewer_interface*) const;
|
||||
virtual void draw_edges(Viewer_interface*) const;
|
||||
|
||||
virtual QString toolTip() const;
|
||||
|
||||
virtual void contextual_changed();
|
||||
virtual void changed();
|
||||
public slots:
|
||||
void plane_was_moved() { need_update_ = true; }
|
||||
void compute_function_grid() const;
|
||||
|
|
@ -77,6 +101,29 @@ private:
|
|||
|
||||
Color_ramp blue_color_ramp_;
|
||||
Color_ramp red_color_ramp_;
|
||||
|
||||
std::vector<float> positions_cube;
|
||||
std::vector<float> positions_grid;
|
||||
std::vector<float> positions_tex_quad;
|
||||
std::vector<GLdouble> texture_map;
|
||||
Texture *texture;
|
||||
|
||||
|
||||
GLuint rendering_program_tex_quad;
|
||||
GLuint rendering_program_cube;
|
||||
GLuint rendering_program_grid;
|
||||
GLuint textureId;
|
||||
GLint location[5];
|
||||
GLint sampler_location;
|
||||
|
||||
|
||||
GLuint vao;
|
||||
GLuint buffer[4];
|
||||
void initialize_buffers();
|
||||
void compile_shaders(void);
|
||||
void uniform_attrib(Viewer_interface*, int) const;
|
||||
void compute_vertices_and_texmap(void);
|
||||
void compute_texture(int, int);
|
||||
};
|
||||
|
||||
#endif // SCENE_IMPLICIT_FUNCTION_ITEM
|
||||
|
|
|
|||
|
|
@ -5,99 +5,104 @@
|
|||
const QColor Scene_item::defaultColor = QColor(100, 100, 255);
|
||||
|
||||
Scene_item::~Scene_item() {
|
||||
delete defaultContextMenu;
|
||||
delete defaultContextMenu;
|
||||
}
|
||||
|
||||
void Scene_item::itemAboutToBeDestroyed(Scene_item* item) {
|
||||
if(this == item)
|
||||
emit aboutToBeDestroyed();
|
||||
if(this == item)
|
||||
emit aboutToBeDestroyed();
|
||||
}
|
||||
|
||||
|
||||
QString modeName(RenderingMode mode) {
|
||||
switch(mode)
|
||||
{
|
||||
switch(mode)
|
||||
{
|
||||
case Points:
|
||||
return QObject::tr("points");
|
||||
return QObject::tr("points");
|
||||
case Wireframe:
|
||||
return QObject::tr("wire");
|
||||
return QObject::tr("wire");
|
||||
case Flat:
|
||||
return QObject::tr("flat");
|
||||
return QObject::tr("flat");
|
||||
case FlatPlusEdges:
|
||||
return QObject::tr("flat+edges");
|
||||
return QObject::tr("flat+edges");
|
||||
case Gouraud:
|
||||
return QObject::tr("Gouraud");
|
||||
return QObject::tr("Gouraud");
|
||||
case PointsPlusNormals:
|
||||
return QObject::tr("pts+normals");
|
||||
return QObject::tr("pts+normals");
|
||||
case Splatting:
|
||||
return QObject::tr("splats");
|
||||
return QObject::tr("splats");
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
return QObject::tr("unknown");
|
||||
}
|
||||
Q_ASSERT(false);
|
||||
return QObject::tr("unknown");
|
||||
}
|
||||
}
|
||||
|
||||
const char* slotName(RenderingMode mode) {
|
||||
switch(mode)
|
||||
{
|
||||
switch(mode)
|
||||
{
|
||||
case Points:
|
||||
return SLOT(setPointsMode());
|
||||
return SLOT(setPointsMode());
|
||||
case Wireframe:
|
||||
return SLOT(setWireframeMode());
|
||||
return SLOT(setWireframeMode());
|
||||
case Flat:
|
||||
return SLOT(setFlatMode());
|
||||
return SLOT(setFlatMode());
|
||||
case FlatPlusEdges:
|
||||
return SLOT(setFlatPlusEdgesMode());
|
||||
return SLOT(setFlatPlusEdgesMode());
|
||||
case Gouraud:
|
||||
return SLOT(setGouraudMode());
|
||||
return SLOT(setGouraudMode());
|
||||
case PointsPlusNormals:
|
||||
return SLOT(setPointsPlusNormalsMode());
|
||||
return SLOT(setPointsPlusNormalsMode());
|
||||
case Splatting:
|
||||
return SLOT(setSplattingMode());
|
||||
return SLOT(setSplattingMode());
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
return "";
|
||||
}
|
||||
Q_ASSERT(false);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// Rendering mode as a human readable string
|
||||
QString Scene_item::renderingModeName() const
|
||||
{
|
||||
return modeName(renderingMode());
|
||||
return modeName(renderingMode());
|
||||
}
|
||||
QMenu* Scene_item::contextMenu()
|
||||
{
|
||||
if(defaultContextMenu) {
|
||||
defaultContextMenu->setTitle(name());
|
||||
return defaultContextMenu;
|
||||
}
|
||||
if(defaultContextMenu) {
|
||||
defaultContextMenu->setTitle(name());
|
||||
return defaultContextMenu;
|
||||
}
|
||||
|
||||
defaultContextMenu = new QMenu(name());
|
||||
// defaultContextMenu->addAction(name());
|
||||
// defaultContextMenu->addSeparator();
|
||||
// QMenu* modeMenu = new QMenu(QObject::tr("Rendering mode"),
|
||||
// defaultContextMenu);
|
||||
for(unsigned int mode = 0; mode < NumberOfRenderingMode;
|
||||
++mode)
|
||||
{
|
||||
if(!supportsRenderingMode(RenderingMode(mode))) continue;
|
||||
QString mName = modeName(RenderingMode(mode));
|
||||
QAction* action =
|
||||
defaultContextMenu->addAction(tr("Set %1 mode")
|
||||
.arg(mName),
|
||||
this,
|
||||
slotName(RenderingMode(mode)));
|
||||
QObject::connect(action, SIGNAL(triggered()),
|
||||
this, SIGNAL(itemChanged()));
|
||||
}
|
||||
// defaultContextMenu->addAction(modeMenu->menuAction());
|
||||
return defaultContextMenu;
|
||||
defaultContextMenu = new QMenu(name());
|
||||
// defaultContextMenu->addAction(name());
|
||||
// defaultContextMenu->addSeparator();
|
||||
// QMenu* modeMenu = new QMenu(QObject::tr("Rendering mode"),
|
||||
// defaultContextMenu);
|
||||
for(unsigned int mode = 0; mode < NumberOfRenderingMode;
|
||||
++mode)
|
||||
{
|
||||
if(!supportsRenderingMode(RenderingMode(mode))) continue;
|
||||
QString mName = modeName(RenderingMode(mode));
|
||||
QAction* action =
|
||||
defaultContextMenu->addAction(tr("Set %1 mode")
|
||||
.arg(mName),
|
||||
this,
|
||||
slotName(RenderingMode(mode)));
|
||||
QObject::connect(action, SIGNAL(triggered()),
|
||||
this, SIGNAL(itemChanged()));
|
||||
}
|
||||
// defaultContextMenu->addAction(modeMenu->menuAction());
|
||||
return defaultContextMenu;
|
||||
}
|
||||
|
||||
void Scene_item::changed() {
|
||||
// emit itemChanged();
|
||||
// emit itemChanged();
|
||||
}
|
||||
|
||||
void Scene_item::selection_changed(bool) {
|
||||
// emit itemChanged();
|
||||
}
|
||||
|
||||
|
||||
void Scene_item::select(double /*orig_x*/,
|
||||
double /*orig_y*/,
|
||||
double /*orig_z*/,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#ifndef SCENE_ITEM_H
|
||||
#define SCENE_ITEM_H
|
||||
|
||||
#include "Scene_item_config.h"
|
||||
#include "Scene_interface.h"
|
||||
#include <QString>
|
||||
|
|
@ -43,16 +42,17 @@ public:
|
|||
virtual bool supportsRenderingMode(RenderingMode m) const = 0;
|
||||
// Flat/Gouraud OpenGL drawing
|
||||
virtual void draw() const = 0;
|
||||
virtual void draw(Viewer_interface*) const { draw(); }
|
||||
virtual void draw(Viewer_interface*) const { draw(); }
|
||||
// Wireframe OpenGL drawing
|
||||
virtual void draw_edges() const { draw(); }
|
||||
virtual void draw_edges(Viewer_interface*) const { draw_edges(); }
|
||||
virtual void draw_edges(Viewer_interface* viewer) const { draw(viewer); }
|
||||
// Points OpenGL drawing
|
||||
virtual void draw_points() const { draw(); }
|
||||
virtual void draw_points(Viewer_interface*) const { draw_points(); }
|
||||
// Splats OpenGL drawing
|
||||
virtual void draw_splats() const {}
|
||||
virtual void draw_splats(Viewer_interface*) const {draw_splats();}
|
||||
virtual void selection_changed(bool);
|
||||
|
||||
// Functions for displaying meta-data of the item
|
||||
virtual QString toolTip() const = 0;
|
||||
|
|
@ -85,6 +85,7 @@ public slots:
|
|||
// Call that once you have finished changing something in the item
|
||||
// (either the properties or internal data)
|
||||
virtual void changed();
|
||||
virtual void contextual_changed(){}
|
||||
|
||||
// Setters for the four basic properties
|
||||
virtual void setColor(QColor c) { color_ = c; }
|
||||
|
|
@ -147,9 +148,13 @@ protected:
|
|||
QString name_;
|
||||
QColor color_;
|
||||
bool visible_;
|
||||
bool is_selected;
|
||||
RenderingMode rendering_mode;
|
||||
QMenu* defaultContextMenu;
|
||||
|
||||
int prev_shading;
|
||||
int cur_shading;
|
||||
|
||||
}; // end class Scene_item
|
||||
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -5,14 +5,14 @@
|
|||
#include "Scene_item_with_display_list.h"
|
||||
#include "Nef_type_fwd.h"
|
||||
#include <iostream>
|
||||
|
||||
#include <queue>
|
||||
class Scene_polyhedron_item;
|
||||
|
||||
class SCENE_NEF_POLYHEDRON_ITEM_EXPORT Scene_nef_polyhedron_item
|
||||
: public Scene_item_with_display_list
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
public:
|
||||
Scene_nef_polyhedron_item();
|
||||
// Scene_nef_polyhedron_item(const Scene_nef_polyhedron_item&);
|
||||
Scene_nef_polyhedron_item(const Nef_polyhedron& p);
|
||||
|
|
@ -27,12 +27,18 @@ public:
|
|||
QFont font() const;
|
||||
QString toolTip() const;
|
||||
|
||||
virtual void changed();
|
||||
virtual void selection_changed(bool);
|
||||
// Indicate if rendering mode is supported
|
||||
virtual bool supportsRenderingMode(RenderingMode m) const { return m != Gouraud && m!=Splatting; } // CHECK THIS!
|
||||
// OpenGL drawing in a display list
|
||||
void direct_draw() const;
|
||||
|
||||
virtual void draw(Viewer_interface*) const;
|
||||
virtual void draw_edges() const {}
|
||||
virtual void draw_edges(Viewer_interface* viewer) const;
|
||||
virtual void draw_points(Viewer_interface*) const;
|
||||
// Wireframe OpenGL drawing
|
||||
void draw_edges() const;
|
||||
|
||||
bool isFinite() const { return true; }
|
||||
bool isEmpty() const;
|
||||
|
|
@ -42,7 +48,7 @@ public:
|
|||
const Nef_polyhedron* nef_polyhedron() const;
|
||||
|
||||
bool is_simple() const;
|
||||
|
||||
bool is_Triangle;
|
||||
// conversion operations
|
||||
static Scene_nef_polyhedron_item* from_polyhedron(Scene_polyhedron_item*);
|
||||
Scene_polyhedron_item* convert_to_polyhedron() const;
|
||||
|
|
@ -64,7 +70,34 @@ public:
|
|||
void convex_decomposition(std::list< Scene_polyhedron_item*>&);
|
||||
|
||||
private:
|
||||
typedef Scene_item Base;
|
||||
typedef std::vector<QColor> Color_vector;
|
||||
|
||||
Nef_polyhedron* nef_poly;
|
||||
|
||||
|
||||
std::vector<double> positions_lines;
|
||||
std::vector<double> positions_facets;
|
||||
std::vector<double> positions_points;
|
||||
std::vector<double> normals;
|
||||
std::vector<double> color_lines;
|
||||
std::vector<double> color_facets;
|
||||
std::vector<double> color_points;
|
||||
|
||||
GLuint rendering_program_facets;
|
||||
GLuint rendering_program_lines;
|
||||
GLuint rendering_program_points;
|
||||
GLint location[9];
|
||||
|
||||
GLuint vao[1];
|
||||
GLuint buffer[7];
|
||||
void initialize_buffers();
|
||||
void compile_shaders(void);
|
||||
void compute_normals_and_vertices(void);
|
||||
void uniform_attrib(Viewer_interface*, int) const;
|
||||
|
||||
void triangulate_facet();
|
||||
void triangulate_facet_color();
|
||||
}; // end class Scene_nef_polyhedron_item
|
||||
|
||||
#endif // SCENE_NEF_POLYHEDRON_ITEM_H
|
||||
|
|
|
|||
|
|
@ -1,3 +1,255 @@
|
|||
#include "Scene_plane_item.h"
|
||||
|
||||
#include "Scene_plane_item.moc"
|
||||
|
||||
|
||||
void Scene_plane_item::initialize_buffers()
|
||||
{
|
||||
glBindVertexArray(vao[0]);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER,
|
||||
(positions_quad.size())*sizeof(float),
|
||||
positions_quad.data(),
|
||||
GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(0, //number of the buffer
|
||||
3, //number of floats to be taken
|
||||
GL_FLOAT, // type of data
|
||||
GL_FALSE, //not normalized
|
||||
0, //compact data (not in a struct)
|
||||
NULL //no offset (seperated in several buffers)
|
||||
);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer[1]);
|
||||
glBufferData(GL_ARRAY_BUFFER,
|
||||
(positions_lines.size())*sizeof(float),
|
||||
positions_lines.data(),
|
||||
GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(1, //number of the buffer
|
||||
3, //number of floats to be taken
|
||||
GL_FLOAT, // type of data
|
||||
GL_FALSE, //not normalized
|
||||
0, //compact data (not in a struct)
|
||||
NULL //no offset (seperated in several buffers)
|
||||
);
|
||||
glEnableVertexAttribArray(1);
|
||||
}
|
||||
void Scene_plane_item::compile_shaders(void)
|
||||
{
|
||||
//fill the vertex shader
|
||||
static const GLchar* vertex_shader_source[] =
|
||||
{
|
||||
"#version 300 es \n"
|
||||
" \n"
|
||||
"layout (location = 0) in vec3 positions; \n"
|
||||
|
||||
"uniform mat4 mvp_matrix; \n"
|
||||
"uniform mat4 f_matrix; \n"
|
||||
"uniform vec3 color; \n"
|
||||
"out highp vec3 fColors; \n"
|
||||
|
||||
"vec4 positions_quad = vec4 (positions, 1.0); \n"
|
||||
" \n"
|
||||
"void main(void) \n"
|
||||
"{ \n"
|
||||
" fColors = color; \n"
|
||||
" gl_Position = mvp_matrix * f_matrix * positions_quad; \n"
|
||||
"} \n"
|
||||
};
|
||||
//fill the fragment shader
|
||||
static const GLchar* fragment_shader_source[]=
|
||||
{
|
||||
"#version 300 es \n"
|
||||
" \n"
|
||||
"in highp vec3 fColors; \n"
|
||||
"out highp vec3 color; \n"
|
||||
" \n"
|
||||
"void main(void) \n"
|
||||
"{ \n"
|
||||
" color = fColors; \n"
|
||||
"} \n"
|
||||
};
|
||||
|
||||
GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertex_shader, 1, vertex_shader_source, NULL);
|
||||
glCompileShader(vertex_shader);
|
||||
|
||||
|
||||
GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragment_shader, 1, fragment_shader_source, NULL);
|
||||
glCompileShader(fragment_shader);
|
||||
|
||||
|
||||
//creates the program, attaches and links the shaders
|
||||
GLuint program= glCreateProgram();
|
||||
glAttachShader(program, vertex_shader);
|
||||
glAttachShader(program, fragment_shader);
|
||||
glLinkProgram(program);
|
||||
|
||||
//Clean-up
|
||||
glDeleteShader(vertex_shader);
|
||||
|
||||
rendering_program_quad = program;
|
||||
|
||||
|
||||
//For the edges
|
||||
static const GLchar* vertex_shader_source_lines[] =
|
||||
{
|
||||
"#version 300 es \n"
|
||||
" \n"
|
||||
"layout (location = 1) in vec3 positions; \n"
|
||||
"uniform mat4 mvp_matrix; \n"
|
||||
"uniform mat4 f_matrix; \n"
|
||||
"vec4 positions_lines = vec4(positions,1.0); \n"
|
||||
"out highp vec3 fColors; \n"
|
||||
" \n"
|
||||
"void main(void) \n"
|
||||
"{ \n"
|
||||
" fColors = vec3(0.0,0.0,0.0); \n"
|
||||
" gl_Position = mvp_matrix * f_matrix * positions_lines; \n"
|
||||
"} \n"
|
||||
};
|
||||
|
||||
vertex_shader = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertex_shader, 1, vertex_shader_source_lines, NULL);
|
||||
glCompileShader(vertex_shader);
|
||||
|
||||
|
||||
glShaderSource(fragment_shader, 1, fragment_shader_source, NULL);
|
||||
glCompileShader(fragment_shader);
|
||||
|
||||
|
||||
program = glCreateProgram();
|
||||
glAttachShader(program, vertex_shader);
|
||||
glAttachShader(program, fragment_shader);
|
||||
glLinkProgram(program);
|
||||
|
||||
|
||||
//Clean-up
|
||||
glDeleteShader(vertex_shader);
|
||||
glDeleteShader(fragment_shader);
|
||||
rendering_program_lines = program;
|
||||
|
||||
}
|
||||
void Scene_plane_item::uniform_attrib(Viewer_interface* viewer, int mode) const
|
||||
{
|
||||
GLfloat mvp_mat[16];
|
||||
GLdouble d_mat[16];
|
||||
GLfloat f_mat[16];
|
||||
viewer->camera()->getModelViewProjectionMatrix(d_mat);
|
||||
//Convert the GLdoubles matrices in GLfloats
|
||||
for (int i=0; i<16; ++i){
|
||||
mvp_mat[i] = GLfloat(d_mat[i]);
|
||||
f_mat[i] = GLfloat(frame->matrix()[i]);
|
||||
}
|
||||
|
||||
GLfloat colors[3];
|
||||
|
||||
colors[0] =this->color().redF();
|
||||
colors[1] =this->color().greenF();
|
||||
colors[2] =this->color().blueF();
|
||||
|
||||
if(mode ==0)
|
||||
{
|
||||
glUseProgram(rendering_program_quad);
|
||||
glUniformMatrix4fv(location[0], 1, GL_FALSE, mvp_mat);
|
||||
glUniform3fv(location[1], 1, colors);
|
||||
glUniformMatrix4fv(location[2], 1, GL_FALSE, f_mat);
|
||||
|
||||
}
|
||||
else if(mode ==1)
|
||||
{
|
||||
glUseProgram(rendering_program_lines);
|
||||
glUniformMatrix4fv(location[3], 1, GL_FALSE, mvp_mat);
|
||||
glUniformMatrix4fv(location[4], 1, GL_FALSE, f_mat);
|
||||
}
|
||||
|
||||
}
|
||||
void Scene_plane_item::compute_normals_and_vertices(void)
|
||||
{
|
||||
positions_quad.clear();
|
||||
positions_lines.clear();
|
||||
|
||||
const double diag = scene_diag();
|
||||
//The quad
|
||||
{
|
||||
|
||||
positions_quad.push_back(-diag);
|
||||
positions_quad.push_back(-diag);
|
||||
positions_quad.push_back(0.0);
|
||||
positions_quad.push_back(-diag);
|
||||
positions_quad.push_back(diag);
|
||||
positions_quad.push_back(0.0);
|
||||
positions_quad.push_back(diag);
|
||||
positions_quad.push_back(-diag);
|
||||
positions_quad.push_back(0.0);
|
||||
|
||||
positions_quad.push_back(-diag);
|
||||
positions_quad.push_back(diag);
|
||||
positions_quad.push_back(0.0);
|
||||
positions_quad.push_back(diag);
|
||||
positions_quad.push_back(-diag);
|
||||
positions_quad.push_back(0.0);
|
||||
positions_quad.push_back(diag);
|
||||
positions_quad.push_back(diag);
|
||||
positions_quad.push_back(0.0);
|
||||
|
||||
}
|
||||
//The grid
|
||||
float x = (2*diag)/10.0;
|
||||
float y = (2*diag)/10.0;
|
||||
{
|
||||
for(int u = 0; u < 11; u++)
|
||||
{
|
||||
|
||||
positions_lines.push_back(-diag + x* u);
|
||||
positions_lines.push_back(-diag);
|
||||
positions_lines.push_back(0.0);
|
||||
|
||||
positions_lines.push_back(-diag + x* u);
|
||||
positions_lines.push_back(diag);
|
||||
positions_lines.push_back(0.0);
|
||||
}
|
||||
for(int v=0; v<11; v++)
|
||||
{
|
||||
|
||||
positions_lines.push_back(-diag);
|
||||
positions_lines.push_back(-diag + v * y);
|
||||
positions_lines.push_back(0.0);
|
||||
|
||||
positions_lines.push_back(diag);
|
||||
positions_lines.push_back(-diag + v * y);
|
||||
positions_lines.push_back(0.0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
location[0] = glGetUniformLocation(rendering_program_quad, "mvp_matrix");
|
||||
location[1] = glGetUniformLocation(rendering_program_quad, "color");
|
||||
location[2] = glGetUniformLocation(rendering_program_quad, "f_matrix");
|
||||
location[3] = glGetUniformLocation(rendering_program_lines, "mvp_matrix");
|
||||
location[4] = glGetUniformLocation(rendering_program_lines, "f_matrix");
|
||||
}
|
||||
|
||||
void Scene_plane_item::draw(Viewer_interface* viewer)const
|
||||
{
|
||||
glBindVertexArray(vao[0]);
|
||||
glUseProgram(rendering_program_quad);
|
||||
uniform_attrib(viewer,0);
|
||||
glDrawArrays(GL_TRIANGLES, 0, positions_quad.size()/3);\
|
||||
glUseProgram(0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
}
|
||||
|
||||
void Scene_plane_item::draw_edges(Viewer_interface* viewer)const
|
||||
{
|
||||
glBindVertexArray(vao[0]);
|
||||
glUseProgram(rendering_program_lines);
|
||||
uniform_attrib(viewer,1);
|
||||
glDrawArrays(GL_LINES, 0, positions_lines.size()/3);\
|
||||
glUseProgram(0);
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef SCENE_PLANE_ITEM_H
|
||||
#define SCENE_PLANE_ITEM_H
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include "Scene_item.h"
|
||||
#include "Scene_interface.h"
|
||||
|
||||
|
|
@ -8,6 +9,7 @@
|
|||
|
||||
#include <QGLViewer/manipulatedFrame.h>
|
||||
#include <QGLViewer/qglviewer.h>
|
||||
#include <Viewer_interface.h>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
|
|
@ -26,12 +28,23 @@ public:
|
|||
: scene(scene_interface),
|
||||
manipulable(false),
|
||||
can_clone(true),
|
||||
positions_lines(0),
|
||||
positions_quad(0),
|
||||
frame(new ManipulatedFrame())
|
||||
{
|
||||
setNormal(0., 0., 1.);
|
||||
glGenVertexArrays(1, vao);
|
||||
//Generates an integer which will be used as ID for each buffer
|
||||
glGenBuffers(2, buffer);
|
||||
compile_shaders();
|
||||
changed();
|
||||
}
|
||||
|
||||
~Scene_plane_item() {
|
||||
glDeleteBuffers(2, buffer);
|
||||
glDeleteVertexArrays(1, vao);
|
||||
glDeleteProgram(rendering_program_lines);
|
||||
glDeleteProgram(rendering_program_quad);
|
||||
delete frame;
|
||||
}
|
||||
|
||||
|
|
@ -108,7 +121,7 @@ public:
|
|||
::glEnable(GL_LIGHTING);
|
||||
::glPopMatrix();
|
||||
};
|
||||
|
||||
virtual void draw(Viewer_interface*) const;
|
||||
// Wireframe OpenGL drawing
|
||||
void draw_edges() const {
|
||||
::glPushMatrix();
|
||||
|
|
@ -116,7 +129,7 @@ public:
|
|||
QGLViewer::drawGrid((float)scene_diag());
|
||||
::glPopMatrix();
|
||||
}
|
||||
|
||||
virtual void draw_edges(Viewer_interface* viewer)const;
|
||||
Plane_3 plane() const {
|
||||
const qglviewer::Vec& pos = frame->position();
|
||||
const qglviewer::Vec& n =
|
||||
|
|
@ -137,6 +150,12 @@ private:
|
|||
}
|
||||
|
||||
public slots:
|
||||
virtual void changed()
|
||||
{
|
||||
compute_normals_and_vertices();
|
||||
initialize_buffers();
|
||||
}
|
||||
|
||||
void setPosition(float x, float y, float z) {
|
||||
frame->setPosition(x, y, z);
|
||||
}
|
||||
|
|
@ -165,6 +184,24 @@ private:
|
|||
bool manipulable;
|
||||
bool can_clone;
|
||||
qglviewer::ManipulatedFrame* frame;
|
||||
std::vector<float> positions_lines;
|
||||
std::vector<float> positions_quad;
|
||||
|
||||
|
||||
|
||||
|
||||
GLuint rendering_program_quad;
|
||||
GLuint rendering_program_lines;
|
||||
GLint location[10];
|
||||
GLint sampler_location;
|
||||
|
||||
GLuint vao[1];
|
||||
GLuint buffer[2];
|
||||
bool smooth_shading;
|
||||
void initialize_buffers();
|
||||
void compile_shaders(void);
|
||||
void uniform_attrib(Viewer_interface*, int) const;
|
||||
void compute_normals_and_vertices(void);
|
||||
};
|
||||
|
||||
#endif // SCENE_PLANE_ITEM_H
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -45,16 +45,22 @@ public:
|
|||
// Function for displaying meta-data of the item
|
||||
virtual QString toolTip() const;
|
||||
|
||||
virtual void changed();
|
||||
virtual void selection_changed(bool);
|
||||
|
||||
// Indicate if rendering mode is supported
|
||||
virtual bool supportsRenderingMode(RenderingMode m) const;
|
||||
// Points OpenGL drawing in a display list
|
||||
virtual void direct_draw() const;
|
||||
virtual void draw_edges(Viewer_interface* viewer) const;
|
||||
virtual void draw_points(Viewer_interface*) const;
|
||||
// Normals OpenGL drawing
|
||||
void draw_normals() const;
|
||||
virtual void draw_edges() const { draw_normals(); }//to tweak scene
|
||||
|
||||
// Splat OpenGL drawing
|
||||
virtual void draw_splats() const;
|
||||
virtual void draw_splats(Viewer_interface*) const;
|
||||
|
||||
// Gets wrapped point set
|
||||
Point_set* point_set();
|
||||
|
|
@ -88,6 +94,34 @@ private:
|
|||
QAction* actionDeleteSelection;
|
||||
QAction* actionResetSelection;
|
||||
QAction* actionSelectDuplicatedPoints;
|
||||
|
||||
|
||||
std::vector<double> positions_lines;
|
||||
std::vector<double> positions_points;
|
||||
std::vector<double> positions_splats;
|
||||
std::vector<double> positions_selected_points;
|
||||
std::vector<double> color_lines;
|
||||
std::vector<double> color_points;
|
||||
std::vector<double> color_selected_points;
|
||||
std::vector<double> normals;
|
||||
std::vector<double> tex_coords;
|
||||
|
||||
int texture[3];
|
||||
|
||||
GLuint rendering_program_lines;
|
||||
GLuint rendering_program_points;
|
||||
GLuint rendering_program_splats;
|
||||
GLint location[9];
|
||||
GLuint textureId;
|
||||
GLint sampler_location;
|
||||
|
||||
GLuint vao[2];
|
||||
GLuint buffer[9];
|
||||
void initialize_buffers();
|
||||
void compile_shaders(void);
|
||||
void compute_normals_and_vertices(void);
|
||||
void uniform_attrib(Viewer_interface*, int) const;
|
||||
|
||||
}; // end class Scene_points_with_normal_item
|
||||
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,8 +1,9 @@
|
|||
#ifndef SCENE_POLYGON_SOUP_ITEM_H
|
||||
#define SCENE_POLYGON_SOUP_ITEM_H
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include "Scene_polygon_soup_item_config.h"
|
||||
#include "Scene_item_with_display_list.h"
|
||||
#include "Scene_item.h"
|
||||
#include "Viewer.h"
|
||||
#include "Polyhedron_type.h"
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
|
@ -13,154 +14,179 @@
|
|||
|
||||
struct Polygon_soup
|
||||
{
|
||||
typedef Kernel::Point_3 Point_3;
|
||||
typedef std::vector<Point_3> Points;
|
||||
typedef std::vector<std::size_t> Polygon_3;
|
||||
typedef std::map<std::pair<std::size_t, std::size_t>, std::set<std::size_t> > Edges_map;
|
||||
typedef boost::array<std::size_t, 2> Edge;
|
||||
typedef std::vector<Polygon_3> Polygons;
|
||||
typedef std::set<Edge> Edges;
|
||||
typedef Polygons::size_type size_type;
|
||||
Points points;
|
||||
Polygons polygons;
|
||||
Edges_map edges;
|
||||
Edges non_manifold_edges;
|
||||
bool display_non_manifold_edges;
|
||||
typedef Kernel::Point_3 Point_3;
|
||||
typedef std::vector<Point_3> Points;
|
||||
typedef std::vector<std::size_t> Polygon_3;
|
||||
typedef std::map<std::pair<std::size_t, std::size_t>, std::set<std::size_t> > Edges_map;
|
||||
typedef boost::array<std::size_t, 2> Edge;
|
||||
typedef std::vector<Polygon_3> Polygons;
|
||||
typedef std::set<Edge> Edges;
|
||||
typedef Polygons::size_type size_type;
|
||||
Points points;
|
||||
Polygons polygons;
|
||||
Edges_map edges;
|
||||
Edges non_manifold_edges;
|
||||
bool display_non_manifold_edges;
|
||||
|
||||
Polygon_soup():
|
||||
display_non_manifold_edges(false){}
|
||||
Polygon_soup():
|
||||
display_non_manifold_edges(false){}
|
||||
|
||||
Polygon_soup* clone() const {
|
||||
Polygon_soup* result = new Polygon_soup();
|
||||
result->points = points;
|
||||
result->polygons = polygons;
|
||||
result->edges = edges;
|
||||
result->non_manifold_edges = non_manifold_edges;
|
||||
result->display_non_manifold_edges = display_non_manifold_edges;
|
||||
return result;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
points.clear();
|
||||
polygons.clear();
|
||||
edges.clear();
|
||||
non_manifold_edges.clear();
|
||||
}
|
||||
|
||||
void fill_edges() {
|
||||
// Fill edges
|
||||
edges.clear();
|
||||
for(size_type i = 0; i < polygons.size(); ++i)
|
||||
{
|
||||
const size_type size = polygons[i].size();
|
||||
for(size_type j = 0; j < size; ++j) {
|
||||
const std::size_t& i0 = polygons[i][j];
|
||||
const std::size_t& i1 = polygons[i][ j+1 < size ? j+1: 0];
|
||||
edges[std::make_pair(i0, i1)].insert(i);
|
||||
// qDebug() << tr("edges[std::make_pair(%1, %2)].insert(%3). Size=%4")
|
||||
// .arg(i0).arg(i1).arg(i).arg(edges[std::make_pair(i0, i1)].size());
|
||||
}
|
||||
Polygon_soup* clone() const {
|
||||
Polygon_soup* result = new Polygon_soup();
|
||||
result->points = points;
|
||||
result->polygons = polygons;
|
||||
result->edges = edges;
|
||||
result->non_manifold_edges = non_manifold_edges;
|
||||
result->display_non_manifold_edges = display_non_manifold_edges;
|
||||
return result;
|
||||
}
|
||||
|
||||
// Fill non-manifold edges
|
||||
non_manifold_edges.clear();
|
||||
for(size_type i = 0; i < polygons.size(); ++i)
|
||||
{
|
||||
const size_type size = polygons[i].size();
|
||||
for(size_type j = 0; j < size; ++j) {
|
||||
const std::size_t& i0 = polygons[i][j];
|
||||
const std::size_t& i1 = polygons[i][ j+1 < size ? j+1: 0];
|
||||
if( (i0 < i1) &&
|
||||
(edges[std::make_pair(i0, i1)].size() +
|
||||
edges[std::make_pair(i1, i0)].size() > 2) )
|
||||
void clear() {
|
||||
points.clear();
|
||||
polygons.clear();
|
||||
edges.clear();
|
||||
non_manifold_edges.clear();
|
||||
}
|
||||
|
||||
void fill_edges() {
|
||||
// Fill edges
|
||||
edges.clear();
|
||||
for(size_type i = 0; i < polygons.size(); ++i)
|
||||
{
|
||||
Edge edge;
|
||||
edge[0] = i0;
|
||||
edge[1] = i1;
|
||||
if(i0 > i1) std::swap(edge[0], edge[1]);
|
||||
non_manifold_edges.insert(edge);
|
||||
const size_type size = polygons[i].size();
|
||||
for(size_type j = 0; j < size; ++j) {
|
||||
const std::size_t& i0 = polygons[i][j];
|
||||
const std::size_t& i1 = polygons[i][ j+1 < size ? j+1: 0];
|
||||
edges[std::make_pair(i0, i1)].insert(i);
|
||||
// qDebug() << tr("edges[std::make_pair(%1, %2)].insert(%3). Size=%4")
|
||||
// .arg(i0).arg(i1).arg(i).arg(edges[std::make_pair(i0, i1)].size());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void inverse_orientation(const std::size_t index) {
|
||||
std::reverse(polygons[index].begin(), polygons[index].end());
|
||||
}
|
||||
// Fill non-manifold edges
|
||||
non_manifold_edges.clear();
|
||||
for(size_type i = 0; i < polygons.size(); ++i)
|
||||
{
|
||||
const size_type size = polygons[i].size();
|
||||
for(size_type j = 0; j < size; ++j) {
|
||||
const std::size_t& i0 = polygons[i][j];
|
||||
const std::size_t& i1 = polygons[i][ j+1 < size ? j+1: 0];
|
||||
|
||||
if( (i0 < i1) &&
|
||||
(edges[std::make_pair(i0, i1)].size() +
|
||||
edges[std::make_pair(i1, i0)].size() > 2) )
|
||||
{
|
||||
Edge edge;
|
||||
edge[0] = i0;
|
||||
edge[1] = i1;
|
||||
if(i0 > i1) std::swap(edge[0], edge[1]);
|
||||
non_manifold_edges.insert(edge);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void inverse_orientation(const std::size_t index) {
|
||||
std::reverse(polygons[index].begin(), polygons[index].end());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class Scene_polyhedron_item;
|
||||
|
||||
class SCENE_POLYGON_SOUP_ITEM_EXPORT Scene_polygon_soup_item
|
||||
: public Scene_item_with_display_list
|
||||
: public Scene_item
|
||||
{
|
||||
typedef Kernel::Point_3 Point_3;
|
||||
typedef Kernel::Point_3 Point_3;
|
||||
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
Scene_polygon_soup_item();
|
||||
~Scene_polygon_soup_item();
|
||||
Scene_polygon_soup_item();
|
||||
~Scene_polygon_soup_item();
|
||||
|
||||
Scene_polygon_soup_item* clone() const;
|
||||
bool load(std::istream& in);
|
||||
void load(Scene_polyhedron_item*);
|
||||
Scene_polygon_soup_item* clone() const;
|
||||
bool load(std::istream& in);
|
||||
void load(Scene_polyhedron_item*);
|
||||
|
||||
template <class Point, class Polygon>
|
||||
inline void load(const std::vector<Point>& points, const std::vector<Polygon>& polygons)
|
||||
{
|
||||
if(!soup)
|
||||
soup = new Polygon_soup;
|
||||
soup->clear();
|
||||
template <class Point, class Polygon>
|
||||
inline void load(const std::vector<Point>& points, const std::vector<Polygon>& polygons)
|
||||
{
|
||||
if(!soup)
|
||||
soup = new Polygon_soup;
|
||||
soup->clear();
|
||||
|
||||
/// add points
|
||||
soup->points.reserve(points.size());
|
||||
BOOST_FOREACH(const Point& p, points)
|
||||
soup->points.push_back( Point_3(p[0], p[1], p[2]) );
|
||||
/// add points
|
||||
soup->points.reserve(points.size());
|
||||
BOOST_FOREACH(const Point& p, points)
|
||||
soup->points.push_back( Point_3(p[0], p[1], p[2]) );
|
||||
|
||||
/// add polygons
|
||||
std::size_t nb_polygons=polygons.size();
|
||||
soup->polygons.resize(nb_polygons);
|
||||
for(std::size_t i=0; i<nb_polygons; ++i)
|
||||
soup->polygons[i].assign(polygons[i].begin(), polygons[i].end());
|
||||
/// add polygons
|
||||
std::size_t nb_polygons=polygons.size();
|
||||
soup->polygons.resize(nb_polygons);
|
||||
for(std::size_t i=0; i<nb_polygons; ++i)
|
||||
soup->polygons[i].assign(polygons[i].begin(), polygons[i].end());
|
||||
|
||||
/// fill non-manifold edges container
|
||||
soup->fill_edges();
|
||||
oriented = false;
|
||||
}
|
||||
/// fill non-manifold edges container
|
||||
soup->fill_edges();
|
||||
oriented = false;
|
||||
}
|
||||
|
||||
bool save(std::ostream& out) const;
|
||||
bool save(std::ostream& out) const;
|
||||
|
||||
QString toolTip() const;
|
||||
QString toolTip() const;
|
||||
|
||||
// Indicate if rendering mode is supported
|
||||
virtual bool supportsRenderingMode(RenderingMode m) const { return (m!=Gouraud && m!=PointsPlusNormals && m!=Splatting); } // CHECK THIS!
|
||||
// OpenGL drawing in a display list
|
||||
void direct_draw() const;
|
||||
void draw_points() const;
|
||||
// Indicate if rendering mode is supported
|
||||
virtual bool supportsRenderingMode(RenderingMode m) const { return (m!=Gouraud && m!=PointsPlusNormals && m!=Splatting); } // CHECK THIS!
|
||||
// OpenGL drawing in a display list
|
||||
virtual void draw() const {}
|
||||
virtual void draw(Viewer_interface*) const;
|
||||
virtual void draw_points(Viewer_interface*) const;
|
||||
virtual void draw_edges(Viewer_interface* viewer) const;
|
||||
void changed();
|
||||
bool isFinite() const { return true; }
|
||||
bool isEmpty() const;
|
||||
Bbox bbox() const;
|
||||
|
||||
bool isFinite() const { return true; }
|
||||
bool isEmpty() const;
|
||||
Bbox bbox() const;
|
||||
void new_vertex(const double&, const double&, const double&);
|
||||
void new_triangle(const std::size_t, const std::size_t, const std::size_t);
|
||||
|
||||
void new_vertex(const double&, const double&, const double&);
|
||||
void new_triangle(const std::size_t, const std::size_t, const std::size_t);
|
||||
|
||||
void init_polygon_soup(std::size_t nb_pts, std::size_t nb_polygons);
|
||||
void finalize_polygon_soup();
|
||||
void init_polygon_soup(std::size_t nb_pts, std::size_t nb_polygons);
|
||||
void finalize_polygon_soup();
|
||||
|
||||
public slots:
|
||||
void shuffle_orientations();
|
||||
bool orient();
|
||||
bool exportAsPolyhedron(Polyhedron*);
|
||||
void inside_out();
|
||||
void shuffle_orientations();
|
||||
bool orient();
|
||||
bool exportAsPolyhedron(Polyhedron*);
|
||||
void inside_out();
|
||||
|
||||
void setDisplayNonManifoldEdges(const bool);
|
||||
bool displayNonManifoldEdges() const;
|
||||
void setDisplayNonManifoldEdges(const bool);
|
||||
bool displayNonManifoldEdges() const;
|
||||
|
||||
private:
|
||||
Polygon_soup* soup;
|
||||
bool oriented;
|
||||
typedef Polygon_soup::Polygons::const_iterator Polygons_iterator;
|
||||
Polygon_soup* soup;
|
||||
bool oriented;
|
||||
std::vector<float> positions_poly;
|
||||
std::vector<float> positions_lines;
|
||||
std::vector<float> normals;
|
||||
|
||||
GLuint rendering_program_poly;
|
||||
GLuint rendering_program_lines;
|
||||
GLint location[9];
|
||||
|
||||
|
||||
GLuint vertex_shader;
|
||||
GLuint fragment_shader;
|
||||
GLuint vao;
|
||||
GLuint buffer[3];
|
||||
void initialize_buffers();
|
||||
void compile_shaders(void);
|
||||
void compute_normals_and_vertices(void);
|
||||
void uniform_attrib(Viewer_interface*, int) const;
|
||||
//void is_Triangulated();
|
||||
void triangulate_polygon(Polygons_iterator );
|
||||
|
||||
}; // end class Scene_polygon_soup_item
|
||||
|
||||
#endif // SCENE_POLYGON_SOUP_ITEM_H
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,9 +1,12 @@
|
|||
#ifndef SCENE_POLYHEDRON_ITEM_H
|
||||
#define SCENE_POLYHEDRON_ITEM_H
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include "Scene_polyhedron_item_config.h"
|
||||
#include "Scene_item_with_display_list.h"
|
||||
#include "Scene_item.h" //<- modif ?
|
||||
#include "Polyhedron_type_fwd.h"
|
||||
#include "Polyhedron_type.h"
|
||||
#include "Viewer.h"
|
||||
#include <iostream>
|
||||
|
||||
#include <set>
|
||||
|
|
@ -15,86 +18,118 @@ class QMenu;
|
|||
|
||||
// This class represents a polyhedron in the OpenGL scene
|
||||
class SCENE_POLYHEDRON_ITEM_EXPORT Scene_polyhedron_item
|
||||
: public Scene_item_with_display_list {
|
||||
Q_OBJECT
|
||||
: public Scene_item{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Scene_polyhedron_item();
|
||||
// Scene_polyhedron_item(const Scene_polyhedron_item&);
|
||||
Scene_polyhedron_item(const Polyhedron& p);
|
||||
Scene_polyhedron_item(Polyhedron* const p);
|
||||
~Scene_polyhedron_item();
|
||||
Scene_polyhedron_item();
|
||||
// Scene_polyhedron_item(const Scene_polyhedron_item&);
|
||||
Scene_polyhedron_item(const Polyhedron& p);
|
||||
Scene_polyhedron_item(Polyhedron* const p);
|
||||
~Scene_polyhedron_item();
|
||||
|
||||
Scene_polyhedron_item* clone() const;
|
||||
|
||||
// IO
|
||||
bool load(std::istream& in);
|
||||
bool save(std::ostream& out) const;
|
||||
Scene_polyhedron_item* clone() const;
|
||||
|
||||
// Function for displaying meta-data of the item
|
||||
virtual QString toolTip() const;
|
||||
// IO
|
||||
bool load(std::istream& in);
|
||||
bool save(std::ostream& out) const;
|
||||
bool is_Triangle;
|
||||
|
||||
// Function to override the context menu
|
||||
QMenu* contextMenu();
|
||||
|
||||
// Indicate if rendering mode is supported
|
||||
virtual bool supportsRenderingMode(RenderingMode m) const { return (m!=PointsPlusNormals && m!=Splatting); }
|
||||
// Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list
|
||||
virtual void direct_draw() const;
|
||||
virtual void direct_draw_edges() const;
|
||||
// Function for displaying meta-data of the item
|
||||
virtual QString toolTip() const;
|
||||
|
||||
// Get wrapped polyhedron
|
||||
Polyhedron* polyhedron();
|
||||
const Polyhedron* polyhedron() const;
|
||||
// Function to override the context menu
|
||||
QMenu* contextMenu();
|
||||
|
||||
// Indicate if rendering mode is supported
|
||||
virtual bool supportsRenderingMode(RenderingMode m) const { return (m!=PointsPlusNormals && m!=Splatting); }
|
||||
// Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list
|
||||
void draw() const {}
|
||||
virtual void draw(Viewer_interface*) const;
|
||||
virtual void draw_edges() const {}
|
||||
virtual void draw_edges(Viewer_interface* viewer) const;
|
||||
virtual void draw_points(Viewer_interface*) const;
|
||||
|
||||
// Get wrapped polyhedron
|
||||
Polyhedron* polyhedron();
|
||||
const Polyhedron* polyhedron() const;
|
||||
|
||||
// Get dimensions
|
||||
bool isFinite() const { return true; }
|
||||
bool isEmpty() const;
|
||||
Bbox bbox() const;
|
||||
std::vector<QColor>& color_vector() {return colors_;}
|
||||
void set_color_vector_read_only(bool on_off) {plugin_has_set_color_vector_m=on_off;}
|
||||
|
||||
// Get dimensions
|
||||
bool isFinite() const { return true; }
|
||||
bool isEmpty() const;
|
||||
Bbox bbox() const;
|
||||
std::vector<QColor>& color_vector() {return colors_;}
|
||||
void set_color_vector_read_only(bool on_off) {plugin_has_set_color_vector_m=on_off;}
|
||||
|
||||
public slots:
|
||||
virtual void changed();
|
||||
void show_only_feature_edges(bool);
|
||||
void enable_facets_picking(bool);
|
||||
void set_erase_next_picked_facet(bool);
|
||||
virtual void changed();
|
||||
virtual void contextual_changed();
|
||||
virtual void selection_changed(bool);
|
||||
void show_only_feature_edges(bool);
|
||||
void enable_facets_picking(bool);
|
||||
void set_erase_next_picked_facet(bool);
|
||||
|
||||
void select(double orig_x,
|
||||
double orig_y,
|
||||
double orig_z,
|
||||
double dir_x,
|
||||
double dir_y,
|
||||
double dir_z);
|
||||
void select(double orig_x,
|
||||
double orig_y,
|
||||
double orig_z,
|
||||
double dir_x,
|
||||
double dir_y,
|
||||
double dir_z);
|
||||
|
||||
void update_vertex_indices();
|
||||
void update_facet_indices();
|
||||
void update_halfedge_indices();
|
||||
void update_vertex_indices();
|
||||
void update_facet_indices();
|
||||
void update_halfedge_indices();
|
||||
|
||||
signals:
|
||||
void selected_vertex(void*);
|
||||
void selected_facet(void*);
|
||||
void selected_edge(void*);
|
||||
void selected_halfedge(void*);
|
||||
void item_is_about_to_be_changed(); // emitted in changed()
|
||||
void selected_vertex(void*);
|
||||
void selected_facet(void*);
|
||||
void selected_edge(void*);
|
||||
void selected_halfedge(void*);
|
||||
void item_is_about_to_be_changed(); // emitted in changed()
|
||||
|
||||
private:
|
||||
// Initialization
|
||||
void init();
|
||||
|
||||
private:
|
||||
Polyhedron* poly;
|
||||
// Initialization
|
||||
void init();
|
||||
|
||||
private:
|
||||
typedef Scene_item_with_display_list Base;
|
||||
typedef std::vector<QColor> Color_vector;
|
||||
Polyhedron* poly;
|
||||
|
||||
private:
|
||||
typedef Scene_item Base;
|
||||
typedef std::vector<QColor> Color_vector;
|
||||
typedef typename Polyhedron::Facet_iterator Facet_iterator;
|
||||
|
||||
Color_vector colors_;
|
||||
Color_vector colors_;
|
||||
|
||||
bool show_only_feature_edges_m;
|
||||
bool facet_picking_m;
|
||||
bool erase_next_picked_facet_m;
|
||||
//the following variable is used to indicate if the color vector must not be automatically updated.
|
||||
bool plugin_has_set_color_vector_m;
|
||||
|
||||
std::vector<float> positions_lines;
|
||||
std::vector<float> positions_facets;
|
||||
std::vector<float> normals;
|
||||
std::vector<float> color_lines;
|
||||
std::vector<float> color_facets;
|
||||
|
||||
std::vector<float> color_lines_selected;
|
||||
std::vector<float> color_facets_selected;
|
||||
|
||||
GLuint rendering_program_facets;
|
||||
GLuint rendering_program_lines;
|
||||
GLint location[9];
|
||||
|
||||
GLuint vao[2];
|
||||
GLuint buffer[10];
|
||||
void initialize_buffers();
|
||||
void compile_shaders(void);
|
||||
void compute_normals_and_vertices(void);
|
||||
void uniform_attrib(Viewer_interface*, int) const;
|
||||
void compute_colors();
|
||||
void triangulate_facet(Facet_iterator );
|
||||
void triangulate_facet_color(Facet_iterator );
|
||||
void is_Triangulated();
|
||||
|
||||
bool show_only_feature_edges_m;
|
||||
bool facet_picking_m;
|
||||
bool erase_next_picked_facet_m;
|
||||
//the following variable is used to indicate if the color vector must not be automatically updated.
|
||||
bool plugin_has_set_color_vector_m;
|
||||
}; // end class Scene_polyhedron_item
|
||||
|
||||
#endif // SCENE_POLYHEDRON_ITEM_H
|
||||
|
|
|
|||
|
|
@ -1,2 +1,458 @@
|
|||
#include "Scene_polyhedron_selection_item.h"
|
||||
#include "Scene_polyhedron_selection_item.moc"
|
||||
struct light_info
|
||||
{
|
||||
//position
|
||||
GLfloat position[4];
|
||||
|
||||
//ambient
|
||||
GLfloat ambient[4];
|
||||
|
||||
//diffuse
|
||||
GLfloat diffuse[4];
|
||||
|
||||
//specular
|
||||
GLfloat specular[4];
|
||||
GLfloat spec_power;
|
||||
|
||||
};
|
||||
|
||||
void Scene_polyhedron_selection_item::initialize_buffers()
|
||||
{
|
||||
glBindVertexArray(vao[0]);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER,
|
||||
(positions_facets.size())*sizeof(float),
|
||||
positions_facets.data(),
|
||||
GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(0, //number of the buffer
|
||||
3, //number of floats to be taken
|
||||
GL_FLOAT, // type of data
|
||||
GL_FALSE, //not normalized
|
||||
0, //compact data (not in a struct)
|
||||
NULL //no offset (seperated in several buffers)
|
||||
);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer[1]);
|
||||
glBufferData(GL_ARRAY_BUFFER,
|
||||
(normals.size())*sizeof(float),
|
||||
normals.data(),
|
||||
GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(1, //number of the buffer
|
||||
3, //number of floats to be taken
|
||||
GL_FLOAT, // type of data
|
||||
GL_FALSE, //not normalized
|
||||
0, //compact data (not in a struct)
|
||||
NULL //no offset (seperated in several buffers)
|
||||
);
|
||||
glEnableVertexAttribArray(1);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer[2]);
|
||||
glBufferData(GL_ARRAY_BUFFER,
|
||||
(positions_lines.size())*sizeof(float),
|
||||
positions_lines.data(),
|
||||
GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(2, //number of the buffer
|
||||
3, //number of floats to be taken
|
||||
GL_FLOAT, // type of data
|
||||
GL_FALSE, //not normalized
|
||||
0, //compact data (not in a struct)
|
||||
NULL //no offset (seperated in several buffers)
|
||||
);
|
||||
glEnableVertexAttribArray(2);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer[3]);
|
||||
glBufferData(GL_ARRAY_BUFFER,
|
||||
(positions_points.size())*sizeof(float),
|
||||
positions_points.data(),
|
||||
GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(3, //number of the buffer
|
||||
3, //number of floats to be taken
|
||||
GL_FLOAT, // type of data
|
||||
GL_FALSE, //not normalized
|
||||
0, //compact data (not in a struct)
|
||||
NULL //no offset (seperated in several buffers)
|
||||
);
|
||||
glEnableVertexAttribArray(3);
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
}
|
||||
void Scene_polyhedron_selection_item::compile_shaders()
|
||||
{
|
||||
//The facets
|
||||
//fill the vertex shader
|
||||
static const GLchar* vertex_shader_source_facets[] =
|
||||
{
|
||||
"#version 300 es \n"
|
||||
" \n"
|
||||
"layout (location = 0) in vec3 positions; \n"
|
||||
"layout (location = 1) in vec3 vNormals; \n"
|
||||
"uniform mat4 mvp_matrix; \n"
|
||||
"uniform mat4 mv_matrix; \n"
|
||||
|
||||
"uniform int is_two_side; \n"
|
||||
"uniform vec3 light_pos; \n"
|
||||
"uniform vec3 light_diff; \n"
|
||||
"uniform vec3 light_spec; \n"
|
||||
"uniform vec3 light_amb; \n"
|
||||
"float spec_power = 128.0; \n"
|
||||
"vec4 positions_facets = vec4(positions, 1.0); \n"
|
||||
"out highp vec3 fColors; \n"
|
||||
" \n"
|
||||
|
||||
"void main(void) \n"
|
||||
"{ \n"
|
||||
"vec4 P = mv_matrix * positions_facets; \n"
|
||||
"vec3 N = mat3(mv_matrix)* vNormals; \n"
|
||||
"vec3 L = light_pos - P.xyz; \n"
|
||||
"vec3 V = -P.xyz; \n"
|
||||
|
||||
"N = normalize(N); \n"
|
||||
"L = normalize(L); \n"
|
||||
"V = normalize(V); \n"
|
||||
|
||||
"vec3 R = reflect(-L, N); \n"
|
||||
" vec3 diffuse; \n"
|
||||
"if(is_two_side == 1) \n"
|
||||
" diffuse = abs(dot(N,L)) * light_diff; \n"
|
||||
"else \n"
|
||||
" diffuse = max(dot(N,L), 0.0) * light_diff; \n"
|
||||
"vec3 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; \n"
|
||||
|
||||
"fColors = light_amb + diffuse + specular ; \n"
|
||||
"gl_Position = mvp_matrix * positions_facets; \n"
|
||||
"} \n"
|
||||
};
|
||||
|
||||
//fill the fragment shader
|
||||
static const GLchar* fragment_shader_source[]=
|
||||
{
|
||||
"#version 300 es \n"
|
||||
" \n"
|
||||
"in highp vec3 fColors; \n"
|
||||
|
||||
"out highp vec3 color; \n"
|
||||
" \n"
|
||||
"void main(void) \n"
|
||||
"{ \n"
|
||||
" color = fColors; \n"
|
||||
"} \n"
|
||||
};
|
||||
|
||||
GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertex_shader, 1, vertex_shader_source_facets, NULL);
|
||||
glCompileShader(vertex_shader);
|
||||
GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragment_shader, 1, fragment_shader_source, NULL);
|
||||
glCompileShader(fragment_shader);
|
||||
|
||||
GLuint program = glCreateProgram();
|
||||
glAttachShader(program, vertex_shader);
|
||||
glAttachShader(program, fragment_shader);
|
||||
glLinkProgram(program);
|
||||
|
||||
glDeleteShader(vertex_shader);
|
||||
rendering_program_facets = program;
|
||||
|
||||
//The lines
|
||||
//fill the vertex shader
|
||||
static const GLchar* vertex_shader_source_lines[] =
|
||||
{
|
||||
"#version 300 es \n"
|
||||
" \n"
|
||||
"layout (location = 2) in vec3 positions; \n"
|
||||
|
||||
"uniform mat4 mvp_matrix; \n"
|
||||
"uniform vec3 color; \n"
|
||||
"out highp vec3 fColors; \n"
|
||||
"vec4 positions_lines = vec4(positions, 1.0); \n"
|
||||
" \n"
|
||||
|
||||
"void main(void) \n"
|
||||
"{ \n"
|
||||
" fColors = color; \n"
|
||||
" gl_Position = mvp_matrix * positions_lines; \n"
|
||||
"} \n"
|
||||
};
|
||||
|
||||
|
||||
|
||||
vertex_shader = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertex_shader, 1, vertex_shader_source_lines, NULL);
|
||||
glCompileShader(vertex_shader);
|
||||
glShaderSource(fragment_shader, 1, fragment_shader_source, NULL);
|
||||
glCompileShader(fragment_shader);
|
||||
|
||||
program = glCreateProgram();
|
||||
glAttachShader(program, vertex_shader);
|
||||
glAttachShader(program, fragment_shader);
|
||||
glLinkProgram(program);
|
||||
|
||||
glDeleteShader(vertex_shader);
|
||||
rendering_program_lines = program;
|
||||
|
||||
//The points
|
||||
//fill the vertex shader
|
||||
static const GLchar* vertex_shader_source_points[] =
|
||||
{
|
||||
"#version 300 es \n"
|
||||
" \n"
|
||||
"layout (location = 3) in vec3 positions; \n"
|
||||
|
||||
"uniform mat4 mvp_matrix; \n"
|
||||
"uniform vec3 color; \n"
|
||||
"out highp vec3 fColors; \n"
|
||||
"vec4 positions_points = vec4(positions, 1.0); \n"
|
||||
" \n"
|
||||
|
||||
"void main(void) \n"
|
||||
"{ \n"
|
||||
" fColors = color; \n"
|
||||
" gl_Position = mvp_matrix * positions_points; \n"
|
||||
"} \n"
|
||||
};
|
||||
|
||||
|
||||
|
||||
vertex_shader = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertex_shader, 1, vertex_shader_source_points, NULL);
|
||||
glCompileShader(vertex_shader);
|
||||
glShaderSource(fragment_shader, 1, fragment_shader_source, NULL);
|
||||
glCompileShader(fragment_shader);
|
||||
|
||||
program = glCreateProgram();
|
||||
glAttachShader(program, vertex_shader);
|
||||
glAttachShader(program, fragment_shader);
|
||||
glLinkProgram(program);
|
||||
|
||||
glDeleteShader(vertex_shader);
|
||||
rendering_program_points = program;
|
||||
|
||||
|
||||
glDeleteShader(fragment_shader);
|
||||
|
||||
}
|
||||
void Scene_polyhedron_selection_item::uniform_attrib(Viewer_interface* viewer, int mode) const
|
||||
{
|
||||
GLfloat colors[3];
|
||||
light_info light;
|
||||
GLint is_both_sides = 0;
|
||||
GLfloat mvp_mat[16];
|
||||
GLfloat mv_mat[16];
|
||||
|
||||
//fills the MVP and MV matrices.
|
||||
|
||||
GLdouble d_mat[16];
|
||||
viewer->camera()->getModelViewProjectionMatrix(d_mat);
|
||||
//Convert the GLdoubles matrices in GLfloats
|
||||
for (int i=0; i<16; ++i)
|
||||
mvp_mat[i] = GLfloat(d_mat[i]);
|
||||
|
||||
viewer->camera()->getModelViewMatrix(d_mat);
|
||||
for (int i=0; i<16; ++i)
|
||||
mv_mat[i] = GLfloat(d_mat[i]);
|
||||
|
||||
|
||||
glGetIntegerv(GL_LIGHT_MODEL_TWO_SIDE, &is_both_sides);
|
||||
|
||||
//fills the arraw of colors with the current color
|
||||
colors[0] = facet_color.redF();
|
||||
colors[1] = facet_color.greenF();
|
||||
colors[2] = facet_color.blueF();
|
||||
//Gets lighting info :
|
||||
|
||||
//position
|
||||
glGetLightfv(GL_LIGHT0, GL_POSITION, light.position);
|
||||
|
||||
//ambient
|
||||
glGetLightfv(GL_LIGHT0, GL_AMBIENT, light.ambient);
|
||||
light.ambient[0]*=colors[0];
|
||||
light.ambient[1]*=colors[1];
|
||||
light.ambient[2]*=colors[2];
|
||||
|
||||
//specular
|
||||
glGetLightfv(GL_LIGHT0, GL_SPECULAR, light.specular);
|
||||
|
||||
//diffuse
|
||||
glGetLightfv(GL_LIGHT0, GL_DIFFUSE, light.diffuse);
|
||||
|
||||
light.diffuse[0]*=colors[0];
|
||||
light.diffuse[1]*=colors[1];
|
||||
light.diffuse[2]*=colors[2];
|
||||
|
||||
//For the Flat mode
|
||||
if(mode ==0)
|
||||
{
|
||||
glUseProgram(rendering_program_facets);
|
||||
glUniformMatrix4fv(location[0], 1, GL_FALSE, mvp_mat);
|
||||
glUniformMatrix4fv(location[1], 1, GL_FALSE, mv_mat);
|
||||
glUniform3fv(location[2], 1, light.position);
|
||||
glUniform3fv(location[3], 1, light.diffuse);
|
||||
glUniform3fv(location[4], 1, light.specular);
|
||||
glUniform3fv(location[5], 1, light.ambient);
|
||||
glUniform1i(location[6], is_both_sides);
|
||||
|
||||
|
||||
}
|
||||
//For the Wire mode
|
||||
else if(mode ==1)
|
||||
{
|
||||
glUseProgram(rendering_program_lines);
|
||||
glUniformMatrix4fv(location[7], 1, GL_FALSE, mvp_mat);
|
||||
colors[0] = edge_color.redF();
|
||||
colors[1] = edge_color.greenF();
|
||||
colors[2] = edge_color.blueF();
|
||||
glUniform3fv(location[8],1,colors);
|
||||
}
|
||||
//For the points mode
|
||||
else if(mode ==2)
|
||||
{
|
||||
glUseProgram(rendering_program_points);
|
||||
glUniformMatrix4fv(location[9], 1, GL_FALSE, mvp_mat);
|
||||
colors[0] = vertex_color.redF();
|
||||
colors[1] = vertex_color.greenF();
|
||||
colors[2] = vertex_color.blueF();
|
||||
glUniform3fv(location[10],1,colors);
|
||||
}
|
||||
}
|
||||
void Scene_polyhedron_selection_item::compute_elements()
|
||||
{
|
||||
positions_facets.clear();
|
||||
positions_lines.clear();
|
||||
positions_points.clear();
|
||||
normals.clear();
|
||||
//The facets
|
||||
{
|
||||
|
||||
|
||||
for(Selection_set_facet::iterator
|
||||
it = selected_facets.begin(),
|
||||
end = selected_facets.end();
|
||||
it != end; ++it)
|
||||
{
|
||||
const Kernel::Vector_3 n =
|
||||
compute_facet_normal<Polyhedron::Facet,Kernel>(**it);
|
||||
|
||||
normals.push_back(n.x());
|
||||
normals.push_back(n.y());
|
||||
normals.push_back(n.z());
|
||||
|
||||
normals.push_back(n.x());
|
||||
normals.push_back(n.y());
|
||||
normals.push_back(n.z());
|
||||
|
||||
normals.push_back(n.x());
|
||||
normals.push_back(n.y());
|
||||
normals.push_back(n.z());
|
||||
|
||||
|
||||
Polyhedron::Halfedge_around_facet_circulator
|
||||
he = (*it)->facet_begin(),
|
||||
cend = he;
|
||||
|
||||
CGAL_For_all(he,cend)
|
||||
{
|
||||
const Kernel::Point_3& p = he->vertex()->point();
|
||||
positions_facets.push_back(p.x());
|
||||
positions_facets.push_back(p.y());
|
||||
positions_facets.push_back(p.z());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//The Lines
|
||||
{
|
||||
|
||||
for(Selection_set_edge::iterator it = selected_edges.begin(); it != selected_edges.end(); ++it) {
|
||||
const Kernel::Point_3& a = (it->halfedge())->vertex()->point();
|
||||
const Kernel::Point_3& b = (it->halfedge())->opposite()->vertex()->point();
|
||||
positions_lines.push_back(a.x());
|
||||
positions_lines.push_back(a.y());
|
||||
positions_lines.push_back(a.z());
|
||||
|
||||
positions_lines.push_back(b.x());
|
||||
positions_lines.push_back(b.y());
|
||||
positions_lines.push_back(b.z());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//The points
|
||||
{
|
||||
for(Selection_set_vertex::iterator
|
||||
it = selected_vertices.begin(),
|
||||
end = selected_vertices.end();
|
||||
it != end; ++it)
|
||||
{
|
||||
const Kernel::Point_3& p = (*it)->point();
|
||||
positions_points.push_back(p.x());
|
||||
positions_points.push_back(p.y());
|
||||
positions_points.push_back(p.z());
|
||||
}
|
||||
}
|
||||
|
||||
location[0] = glGetUniformLocation(rendering_program_facets, "mvp_matrix");
|
||||
location[1] = glGetUniformLocation(rendering_program_facets, "mv_matrix");
|
||||
location[2] = glGetUniformLocation(rendering_program_facets, "light_pos");
|
||||
location[3] = glGetUniformLocation(rendering_program_facets, "light_diff");
|
||||
location[4] = glGetUniformLocation(rendering_program_facets, "light_spec");
|
||||
location[5] = glGetUniformLocation(rendering_program_facets, "light_amb");
|
||||
location[6] = glGetUniformLocation(rendering_program_facets, "is_two_side");
|
||||
|
||||
location[7] = glGetUniformLocation(rendering_program_lines, "mvp_matrix");
|
||||
location[8] = glGetUniformLocation(rendering_program_lines, "color");
|
||||
|
||||
location[9] = glGetUniformLocation(rendering_program_points, "mvp_matrix");
|
||||
location[10] = glGetUniformLocation(rendering_program_points, "color");
|
||||
}
|
||||
|
||||
void Scene_polyhedron_selection_item::draw(Viewer_interface* viewer) const
|
||||
{
|
||||
|
||||
draw_points(viewer);
|
||||
GLfloat offset_factor;
|
||||
GLfloat offset_units;
|
||||
glGetFloatv( GL_POLYGON_OFFSET_FACTOR, &offset_factor);
|
||||
glGetFloatv(GL_POLYGON_OFFSET_UNITS, &offset_units);
|
||||
glPolygonOffset(-1.f, 1.f);
|
||||
glBindVertexArray(vao[0]);
|
||||
uniform_attrib(viewer,0);
|
||||
glUseProgram(rendering_program_facets);
|
||||
glDrawArrays(GL_TRIANGLES, 0, positions_facets.size()/3);
|
||||
glUseProgram(0);
|
||||
glBindVertexArray(0);
|
||||
glPolygonOffset(offset_factor, offset_units);
|
||||
draw_edges(viewer);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Scene_polyhedron_selection_item::draw_edges(Viewer_interface* viewer) const
|
||||
{
|
||||
|
||||
glLineWidth(3.f);
|
||||
glBindVertexArray(vao[0]);
|
||||
uniform_attrib(viewer,1);
|
||||
glUseProgram(rendering_program_lines);
|
||||
glDrawArrays(GL_LINES, 0, positions_lines.size()/3);
|
||||
glUseProgram(0);
|
||||
glBindVertexArray(0);
|
||||
glLineWidth(1.f);
|
||||
}
|
||||
|
||||
void Scene_polyhedron_selection_item::draw_points(Viewer_interface* viewer) const
|
||||
{
|
||||
std::cout<<"draw_points"<<std::endl;
|
||||
glPointSize(5.f);
|
||||
glBindVertexArray(vao[0]);
|
||||
uniform_attrib(viewer,2);
|
||||
glUseProgram(rendering_program_points);
|
||||
glDrawArrays(GL_POINTS, 0, positions_points.size()/3);
|
||||
glUseProgram(0);
|
||||
glBindVertexArray(0);
|
||||
glPointSize(1.f);
|
||||
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -3,65 +3,223 @@
|
|||
#include "Polyhedron_type.h"
|
||||
|
||||
Scene_polyhedron_transform_item::Scene_polyhedron_transform_item(const qglviewer::Vec& pos,const Scene_polyhedron_item* poly_item_,const Scene_interface*):
|
||||
poly_item(poly_item_),
|
||||
manipulable(false),
|
||||
frame(new ManipulatedFrame()),
|
||||
poly(poly_item->polyhedron()),
|
||||
center_(pos) { frame->setPosition(pos); }
|
||||
poly_item(poly_item_),
|
||||
manipulable(false),
|
||||
frame(new ManipulatedFrame()),
|
||||
positions_lines(0),
|
||||
poly(poly_item->polyhedron()),
|
||||
center_(pos) {
|
||||
frame->setPosition(pos);
|
||||
|
||||
glGenVertexArrays(1, vao);
|
||||
//Generates an integer which will be used as ID for each buffer
|
||||
glGenBuffers(1, buffer);
|
||||
compile_shaders();
|
||||
|
||||
}
|
||||
|
||||
Scene_polyhedron_transform_item::~Scene_polyhedron_transform_item()
|
||||
{
|
||||
|
||||
glDeleteBuffers(1, buffer);
|
||||
glDeleteVertexArrays(1, vao);
|
||||
glDeleteProgram(rendering_program);
|
||||
delete frame;
|
||||
emit killed();
|
||||
}
|
||||
|
||||
void Scene_polyhedron_transform_item::initialize_buffers()
|
||||
{
|
||||
|
||||
glBindVertexArray(vao[0]);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER,
|
||||
(positions_lines.size())*sizeof(float),
|
||||
positions_lines.data(),
|
||||
GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(0, //number of the buffer
|
||||
3, //number of floats to be taken
|
||||
GL_FLOAT, // type of data
|
||||
GL_FALSE, //not normalized
|
||||
0, //compact data (not in a struct)
|
||||
NULL //no offset (seperated in several buffers)
|
||||
);
|
||||
glEnableVertexAttribArray(0);
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
void Scene_polyhedron_transform_item::compile_shaders()
|
||||
{
|
||||
//fill the vertex shader
|
||||
static const GLchar* vertex_shader_source_lines[] =
|
||||
{
|
||||
"#version 300 es \n"
|
||||
" \n"
|
||||
"layout (location = 0) in vec3 positions; \n"
|
||||
|
||||
"uniform mat4 mvp_matrix; \n"
|
||||
"uniform mat4 f_matrix; \n"
|
||||
"uniform vec3 color_lines; \n"
|
||||
"vec4 positions_lines = vec4(positions, 1.0); \n"
|
||||
"out highp vec3 fColors; \n"
|
||||
" \n"
|
||||
|
||||
"void main(void) \n"
|
||||
"{ \n"
|
||||
" fColors = color_lines; \n"
|
||||
" gl_Position = mvp_matrix * f_matrix * positions_lines; \n"
|
||||
"} \n"
|
||||
};
|
||||
|
||||
//fill the fragment shader
|
||||
static const GLchar* fragment_shader_source[]=
|
||||
{
|
||||
"#version 300 es \n"
|
||||
" \n"
|
||||
"in highp vec3 fColors; \n"
|
||||
|
||||
"out highp vec3 color; \n"
|
||||
" \n"
|
||||
"void main(void) \n"
|
||||
"{ \n"
|
||||
" color = fColors; \n"
|
||||
"} \n"
|
||||
};
|
||||
|
||||
GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertex_shader, 1, vertex_shader_source_lines, NULL);
|
||||
glCompileShader(vertex_shader);
|
||||
GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragment_shader, 1, fragment_shader_source, NULL);
|
||||
glCompileShader(fragment_shader);
|
||||
|
||||
GLuint program = glCreateProgram();
|
||||
glAttachShader(program, vertex_shader);
|
||||
glAttachShader(program, fragment_shader);
|
||||
glLinkProgram(program);
|
||||
|
||||
glDeleteShader(vertex_shader);
|
||||
glDeleteShader(fragment_shader);
|
||||
rendering_program = program;
|
||||
|
||||
}
|
||||
void Scene_polyhedron_transform_item::uniform_attrib(Viewer_interface* viewer) const
|
||||
{
|
||||
GLfloat mvp_mat[16];
|
||||
GLfloat f_mat[16];
|
||||
GLdouble d_mat[16];
|
||||
viewer->camera()->getModelViewProjectionMatrix(d_mat);
|
||||
for (int i=0; i<16; ++i){
|
||||
mvp_mat[i] = GLfloat(d_mat[i]);
|
||||
f_mat[i] = frame->matrix()[i];
|
||||
}
|
||||
|
||||
GLfloat colors[3];
|
||||
colors[0] = this->color().redF();
|
||||
colors[1] = this->color().greenF();
|
||||
colors[2] = this->color().blueF();
|
||||
glUseProgram(rendering_program);
|
||||
glUniformMatrix4fv(location[0], 1, GL_FALSE, mvp_mat);
|
||||
glUniform3fv(location[1], 1, colors);
|
||||
glUniformMatrix4fv(location[2], 1, GL_FALSE, f_mat);
|
||||
}
|
||||
void Scene_polyhedron_transform_item::compute_elements()
|
||||
{
|
||||
positions_lines.clear();
|
||||
typedef Kernel::Point_3 Point;
|
||||
typedef Polyhedron::Edge_const_iterator Edge_iterator;
|
||||
|
||||
Edge_iterator he;
|
||||
for(he = poly->edges_begin();
|
||||
he != poly->edges_end();
|
||||
he++)
|
||||
{
|
||||
const Point& a = he->vertex()->point();
|
||||
const Point& b = he->opposite()->vertex()->point();
|
||||
positions_lines.push_back(a.x()-center_.x);
|
||||
positions_lines.push_back(a.y()-center_.y);
|
||||
positions_lines.push_back(a.z()-center_.z);
|
||||
|
||||
positions_lines.push_back(b.x()-center_.x);
|
||||
positions_lines.push_back(b.y()-center_.y);
|
||||
positions_lines.push_back(b.z()-center_.z);
|
||||
|
||||
}
|
||||
|
||||
location[0] = glGetUniformLocation(rendering_program, "mvp_matrix");
|
||||
location[1] = glGetUniformLocation(rendering_program, "color_lines");
|
||||
location[2] = glGetUniformLocation(rendering_program, "f_matrix");
|
||||
}
|
||||
|
||||
|
||||
void Scene_polyhedron_transform_item::draw() const{
|
||||
glPushMatrix();
|
||||
glMultMatrixd(frame->matrix());
|
||||
direct_draw_edges();
|
||||
//Scene_item_with_display_list::draw();
|
||||
glPopMatrix();
|
||||
glPushMatrix();
|
||||
glMultMatrixd(frame->matrix());
|
||||
direct_draw_edges();
|
||||
//Scene_item_with_display_list::draw();
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void Scene_polyhedron_transform_item::direct_draw_edges() const {
|
||||
typedef Kernel::Point_3 Point;
|
||||
typedef Polyhedron::Edge_const_iterator Edge_iterator;
|
||||
void Scene_polyhedron_transform_item::draw_edges(Viewer_interface* viewer) const
|
||||
{
|
||||
glBindVertexArray(vao[0]);
|
||||
glUseProgram(rendering_program);
|
||||
uniform_attrib(viewer);
|
||||
glDrawArrays(GL_LINES, 0, positions_lines.size()/3);
|
||||
glUseProgram(0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
::glDisable(GL_LIGHTING);
|
||||
::glBegin(GL_LINES);
|
||||
Edge_iterator he;
|
||||
for(he = poly->edges_begin();
|
||||
he != poly->edges_end();
|
||||
he++)
|
||||
{
|
||||
const Point& a = he->vertex()->point();
|
||||
const Point& b = he->opposite()->vertex()->point();
|
||||
::glVertex3d(a.x()-center_.x,a.y()-center_.y,a.z()-center_.z);
|
||||
::glVertex3d(b.x()-center_.x,b.y()-center_.y,b.z()-center_.z);
|
||||
}
|
||||
::glEnd();
|
||||
::glEnable(GL_LIGHTING);
|
||||
}
|
||||
void Scene_polyhedron_transform_item::direct_draw_edges() const {
|
||||
typedef Kernel::Point_3 Point;
|
||||
typedef Polyhedron::Edge_const_iterator Edge_iterator;
|
||||
|
||||
::glDisable(GL_LIGHTING);
|
||||
::glBegin(GL_LINES);
|
||||
Edge_iterator he;
|
||||
for(he = poly->edges_begin();
|
||||
he != poly->edges_end();
|
||||
he++)
|
||||
{
|
||||
const Point& a = he->vertex()->point();
|
||||
const Point& b = he->opposite()->vertex()->point();
|
||||
::glVertex3d(a.x()-center_.x,a.y()-center_.y,a.z()-center_.z);
|
||||
::glVertex3d(b.x()-center_.x,b.y()-center_.y,b.z()-center_.z);
|
||||
}
|
||||
::glEnd();
|
||||
::glEnable(GL_LIGHTING);
|
||||
}
|
||||
QString Scene_polyhedron_transform_item::toolTip() const {
|
||||
return QObject::tr("<p>Affine transformation of <b>%1</b></p>"
|
||||
"<p>Keep <b>Ctrl</b> pressed and use the arcball to define an affine transformation.<br />"
|
||||
"Press <b>S</b> to apply the affine transformation to a copy of <b>%1</b>.</p>")
|
||||
.arg(getBase()->name());
|
||||
return QObject::tr("<p>Affine transformation of <b>%1</b></p>"
|
||||
"<p>Keep <b>Ctrl</b> pressed and use the arcball to define an affine transformation.<br />"
|
||||
"Press <b>S</b> to apply the affine transformation to a copy of <b>%1</b>.</p>")
|
||||
.arg(getBase()->name());
|
||||
}
|
||||
bool Scene_polyhedron_transform_item::keyPressEvent(QKeyEvent* e){
|
||||
if (e->key()==Qt::Key_S){
|
||||
emit stop();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if (e->key()==Qt::Key_S){
|
||||
emit stop();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Scene_polyhedron_transform_item::Bbox
|
||||
Scene_polyhedron_transform_item::bbox() const {
|
||||
const Kernel::Point_3& p = *(poly->points_begin());
|
||||
CGAL::Bbox_3 bbox(p.x(), p.y(), p.z(), p.x(), p.y(), p.z());
|
||||
for(Polyhedron::Point_const_iterator it = poly->points_begin();
|
||||
it != poly->points_end();
|
||||
++it) {
|
||||
bbox = bbox + it->bbox();
|
||||
}
|
||||
return Bbox(bbox.xmin(),bbox.ymin(),bbox.zmin(),
|
||||
bbox.xmax(),bbox.ymax(),bbox.zmax());
|
||||
const Kernel::Point_3& p = *(poly->points_begin());
|
||||
CGAL::Bbox_3 bbox(p.x(), p.y(), p.z(), p.x(), p.y(), p.z());
|
||||
for(Polyhedron::Point_const_iterator it = poly->points_begin();
|
||||
it != poly->points_end();
|
||||
++it) {
|
||||
bbox = bbox + it->bbox();
|
||||
}
|
||||
return Bbox(bbox.xmin(),bbox.ymin(),bbox.zmin(),
|
||||
bbox.xmax(),bbox.ymax(),bbox.zmax());
|
||||
}
|
||||
|
||||
|
||||
void Scene_polyhedron_transform_item::changed()
|
||||
{
|
||||
compute_elements();
|
||||
initialize_buffers();
|
||||
}
|
||||
#include "Scene_polyhedron_transform_item.moc"
|
||||
|
||||
|
|
|
|||
|
|
@ -9,41 +9,56 @@
|
|||
|
||||
// This class represents a polyhedron in the OpenGL scene
|
||||
class SCENE_POLYHEDRON_TRANSFORM_ITEM_EXPORT Scene_polyhedron_transform_item
|
||||
: public Scene_item {
|
||||
// : public Scene_item_with_display_list {
|
||||
Q_OBJECT
|
||||
: public Scene_item {
|
||||
// : public Scene_item_with_display_list {
|
||||
Q_OBJECT
|
||||
|
||||
typedef Scene_polyhedron_item Base;
|
||||
typedef Scene_polyhedron_item Base;
|
||||
|
||||
public:
|
||||
Scene_polyhedron_transform_item(const qglviewer::Vec& pos,const Scene_polyhedron_item* poly_item,const Scene_interface* scene_interface);
|
||||
void direct_draw_edges() const;
|
||||
Scene_item* clone() const{return NULL;}
|
||||
QString toolTip() const;
|
||||
void direct_draw() const {}
|
||||
void draw() const;
|
||||
Bbox bbox() const;
|
||||
~Scene_polyhedron_transform_item() {delete frame; emit killed();}
|
||||
Scene_polyhedron_transform_item(const qglviewer::Vec& pos,const Scene_polyhedron_item* poly_item,const Scene_interface* scene_interface);
|
||||
void direct_draw_edges() const;
|
||||
Scene_item* clone() const{return NULL;}
|
||||
QString toolTip() const;
|
||||
void direct_draw() const {}
|
||||
void draw() const;
|
||||
void draw_edges(Viewer_interface*) const;
|
||||
void draw_edges() const{direct_draw_edges();}
|
||||
Bbox bbox() const;
|
||||
~Scene_polyhedron_transform_item();
|
||||
bool manipulatable() const { return manipulable; }
|
||||
ManipulatedFrame* manipulatedFrame() { return frame; }
|
||||
void setManipulatable(bool b = true) { manipulable = b;}
|
||||
const Scene_polyhedron_item* getBase() const{ return poly_item; };
|
||||
const qglviewer::Vec& center() const { return center_; }
|
||||
virtual bool supportsRenderingMode(RenderingMode m) const { return m==Wireframe ; }
|
||||
virtual void changed();
|
||||
virtual bool keyPressEvent(QKeyEvent*);
|
||||
|
||||
bool manipulatable() const { return manipulable; }
|
||||
ManipulatedFrame* manipulatedFrame() { return frame; }
|
||||
void setManipulatable(bool b = true) { manipulable = b;}
|
||||
const Scene_polyhedron_item* getBase() const{ return poly_item; };
|
||||
const qglviewer::Vec& center() const { return center_; }
|
||||
virtual bool supportsRenderingMode(RenderingMode m) const { return m==Wireframe ; }
|
||||
|
||||
virtual bool keyPressEvent(QKeyEvent*);
|
||||
|
||||
private:
|
||||
const Scene_polyhedron_item* poly_item;
|
||||
bool manipulable;
|
||||
qglviewer::ManipulatedFrame* frame;
|
||||
const Polyhedron* poly;
|
||||
qglviewer::Vec center_;
|
||||
|
||||
const Scene_polyhedron_item* poly_item;
|
||||
bool manipulable;
|
||||
qglviewer::ManipulatedFrame* frame;
|
||||
const Polyhedron* poly;
|
||||
qglviewer::Vec center_;
|
||||
|
||||
std::vector<float> positions_lines;
|
||||
|
||||
|
||||
|
||||
GLint location[3];
|
||||
GLuint vao[1];
|
||||
GLuint buffer[1];
|
||||
GLuint rendering_program;
|
||||
|
||||
void initialize_buffers();
|
||||
void compile_shaders();
|
||||
void uniform_attrib(Viewer_interface*) const;
|
||||
void compute_elements();
|
||||
|
||||
signals:
|
||||
void stop();
|
||||
void killed();
|
||||
void stop();
|
||||
void killed();
|
||||
}; // end class Scene_polyhedron_transform_item
|
||||
|
||||
#endif // SCENE_POLYHEDRON_TRANSFORM_ITEM_H
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef SCENE_POLYLINES_ITEM_H
|
||||
#define SCENE_POLYLINES_ITEM_H
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include "Scene_polylines_item_config.h"
|
||||
|
||||
#include "Viewer_interface.h"
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
#include "Scene_item.h"
|
||||
|
||||
|
|
@ -16,77 +16,111 @@ class Scene_polylines_item_private;
|
|||
|
||||
class SCENE_POLYLINES_ITEM_EXPORT Scene_polylines_item : public Scene_item
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
|
||||
typedef K::Point_3 Point_3;
|
||||
typedef std::vector<Point_3> Polyline;
|
||||
typedef std::list<Polyline> Polylines_container;
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
|
||||
typedef K::Point_3 Point_3;
|
||||
typedef std::vector<Point_3> Polyline;
|
||||
typedef std::list<Polyline> Polylines_container;
|
||||
|
||||
typedef K::Iso_cuboid_3 Iso_cuboid_3;
|
||||
typedef K::Iso_cuboid_3 Iso_cuboid_3;
|
||||
|
||||
Scene_polylines_item();
|
||||
virtual ~Scene_polylines_item();
|
||||
Scene_polylines_item();
|
||||
virtual ~Scene_polylines_item();
|
||||
|
||||
bool isFinite() const { return true; }
|
||||
bool isEmpty() const;
|
||||
Bbox bbox() const;
|
||||
bool isFinite() const { return true; }
|
||||
bool isEmpty() const;
|
||||
Bbox bbox() const;
|
||||
|
||||
Scene_polylines_item* clone() const;
|
||||
Scene_polylines_item* clone() const;
|
||||
|
||||
QString toolTip() const;
|
||||
QString toolTip() const;
|
||||
|
||||
// Indicate if rendering mode is supported
|
||||
bool supportsRenderingMode(RenderingMode m) const;
|
||||
// Indicate if rendering mode is supported
|
||||
bool supportsRenderingMode(RenderingMode m) const;
|
||||
|
||||
QMenu* contextMenu();
|
||||
|
||||
// Flat/Gouraud OpenGL drawing
|
||||
void draw() const;
|
||||
QMenu* contextMenu();
|
||||
|
||||
// Wireframe OpenGL drawing
|
||||
void draw_edges() const;
|
||||
// Flat/Gouraud OpenGL drawing
|
||||
void draw() const {}
|
||||
void draw(Viewer_interface*) const;
|
||||
|
||||
void draw_points() const;
|
||||
|
||||
void smooth(std::vector<Point_3>& polyline){
|
||||
bool is_closed = polyline.front()==polyline.back();
|
||||
typedef K::Vector_3 Vector_3;
|
||||
|
||||
std::size_t start = is_closed ? 0:1;
|
||||
std::size_t end = polyline.size()-1;
|
||||
|
||||
Vector_3 prev = (is_closed ? polyline[end-1] : polyline[0]) - CGAL::ORIGIN;
|
||||
|
||||
for (std::size_t i=start; i!=end; ++i)
|
||||
{
|
||||
Vector_3 curr = polyline[i] - CGAL::ORIGIN;
|
||||
Vector_3 next = polyline[i+1] - CGAL::ORIGIN;
|
||||
|
||||
polyline[i] = CGAL::ORIGIN+(prev+2*curr+next)/4;
|
||||
prev=curr;
|
||||
// Wireframe OpenGL drawing
|
||||
void draw_edges() const{}
|
||||
void draw_edges(Viewer_interface*) const;
|
||||
|
||||
void draw_points() const{}
|
||||
void draw_points(Viewer_interface*) const;
|
||||
|
||||
|
||||
void smooth(std::vector<Point_3>& polyline){
|
||||
bool is_closed = polyline.front()==polyline.back();
|
||||
typedef K::Vector_3 Vector_3;
|
||||
|
||||
std::size_t start = is_closed ? 0:1;
|
||||
std::size_t end = polyline.size()-1;
|
||||
|
||||
Vector_3 prev = (is_closed ? polyline[end-1] : polyline[0]) - CGAL::ORIGIN;
|
||||
|
||||
for (std::size_t i=start; i!=end; ++i)
|
||||
{
|
||||
Vector_3 curr = polyline[i] - CGAL::ORIGIN;
|
||||
Vector_3 next = polyline[i+1] - CGAL::ORIGIN;
|
||||
|
||||
polyline[i] = CGAL::ORIGIN+(prev+2*curr+next)/4;
|
||||
prev=curr;
|
||||
}
|
||||
|
||||
if (is_closed) polyline[end]=polyline[0];
|
||||
}
|
||||
|
||||
if (is_closed) polyline[end]=polyline[0];
|
||||
}
|
||||
|
||||
|
||||
public slots:
|
||||
void change_corner_radii(double);
|
||||
void change_corner_radii();
|
||||
void split_at_sharp_angles();
|
||||
virtual void changed();
|
||||
void change_corner_radii(double);
|
||||
void change_corner_radii();
|
||||
void split_at_sharp_angles();
|
||||
|
||||
void merge(Scene_polylines_item*);
|
||||
void merge(Scene_polylines_item*);
|
||||
|
||||
void smooth(){
|
||||
for (Polylines_container::iterator pit=polylines.begin(),pit_end=polylines.end();pit!=pit_end;++pit)
|
||||
smooth(*pit);
|
||||
emit itemChanged();
|
||||
}
|
||||
void smooth(){
|
||||
for (Polylines_container::iterator pit=polylines.begin(),pit_end=polylines.end();pit!=pit_end;++pit)
|
||||
smooth(*pit);
|
||||
emit itemChanged();
|
||||
}
|
||||
public:
|
||||
Polylines_container polylines;
|
||||
Polylines_container polylines;
|
||||
|
||||
// http://en.wikipedia.org/wiki/D-pointer
|
||||
Scene_polylines_item_private* d;
|
||||
private:
|
||||
std::vector<float> positions_lines;
|
||||
std::vector<float> positions_spheres;
|
||||
std::vector<float> positions_wire_spheres;
|
||||
std::vector<float> positions_center;
|
||||
std::vector<float> normals_spheres;
|
||||
std::vector<float> color_spheres;
|
||||
|
||||
|
||||
|
||||
GLint location[11];
|
||||
GLuint vao[1];
|
||||
GLuint buffer[6];
|
||||
GLuint rendering_program_spheres;
|
||||
GLuint rendering_program_lines;
|
||||
GLuint rendering_program_WireSpheres;
|
||||
GLuint nbSpheres;
|
||||
//The more small they are, the more precise the Sphere will be.
|
||||
// Must be a multiple of 360 and 180.
|
||||
int rings;
|
||||
int sectors;
|
||||
typedef std::map<Point_3, int> Point_to_int_map;
|
||||
typedef Point_to_int_map::iterator iterator;
|
||||
void create_Sphere(double);
|
||||
void initialize_buffers();
|
||||
void compile_shaders();
|
||||
void uniform_attrib(Viewer_interface*, int) const;
|
||||
void compute_elements();
|
||||
|
||||
// http://en.wikipedia.org/wiki/D-pointer
|
||||
Scene_polylines_item_private* d;
|
||||
|
||||
}; // end class Scene_polylines_item
|
||||
|
||||
|
|
|
|||
|
|
@ -6,26 +6,512 @@
|
|||
#include <CGAL/gl_render.h>
|
||||
|
||||
typedef EPIC_kernel::Point_3 Point;
|
||||
struct light_info
|
||||
{
|
||||
//position
|
||||
GLfloat position[4];
|
||||
|
||||
//ambient
|
||||
GLfloat ambient[4];
|
||||
|
||||
//diffuse
|
||||
GLfloat diffuse[4];
|
||||
|
||||
//specular
|
||||
GLfloat specular[4];
|
||||
};
|
||||
|
||||
void Scene_textured_polyhedron_item::initialize_buffers()
|
||||
{
|
||||
glBindVertexArray(vao[0]);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER,
|
||||
(positions_facets.size())*sizeof(float),
|
||||
positions_facets.data(),
|
||||
GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(0, //number of the buffer
|
||||
4, //number of floats to be taken
|
||||
GL_FLOAT, // type of data
|
||||
GL_FALSE, //not normalized
|
||||
0, //compact data (not in a struct)
|
||||
NULL //no offset (seperated in several buffers)
|
||||
);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer[1]);
|
||||
glBufferData(GL_ARRAY_BUFFER,
|
||||
(positions_lines.size())*sizeof(float),
|
||||
positions_lines.data(),
|
||||
GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(1, //number of the buffer
|
||||
4, //number of floats to be taken
|
||||
GL_FLOAT, // type of data
|
||||
GL_FALSE, //not normalized
|
||||
0, //compact data (not in a struct)
|
||||
NULL //no offset (seperated in several buffers)
|
||||
);
|
||||
glEnableVertexAttribArray(1);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer[2]);
|
||||
glBufferData(GL_ARRAY_BUFFER,
|
||||
(normals.size())*sizeof(float),
|
||||
normals.data(), GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(2,
|
||||
3,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
0,
|
||||
NULL
|
||||
);
|
||||
glEnableVertexAttribArray(2);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer[3]);
|
||||
glBufferData(GL_ARRAY_BUFFER,
|
||||
(textures_map_facets.size())*sizeof(float),
|
||||
textures_map_facets.data(), GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(3,
|
||||
2,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
0,
|
||||
NULL
|
||||
);
|
||||
glEnableVertexAttribArray(3);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer[4]);
|
||||
glBufferData(GL_ARRAY_BUFFER,
|
||||
(textures_map_lines.size())*sizeof(float),
|
||||
textures_map_lines.data(), GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(4,
|
||||
2,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
0,
|
||||
NULL
|
||||
);
|
||||
glEnableVertexAttribArray(4);
|
||||
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, textureId);
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGB,
|
||||
texture.GetWidth(),
|
||||
texture.GetHeight(),
|
||||
0,
|
||||
GL_RGB,
|
||||
GL_UNSIGNED_BYTE,
|
||||
texture.GetData());
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
|
||||
// Clean-up
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
void Scene_textured_polyhedron_item::compile_shaders(void)
|
||||
{
|
||||
//fill the vertex shader
|
||||
static const GLchar* vertex_shader_source[] =
|
||||
{
|
||||
"#version 300 es \n"
|
||||
" \n"
|
||||
"layout (location = 0) in vec4 positions_facets; \n"
|
||||
"layout (location = 2) in vec3 vNormals; \n"
|
||||
"layout (location = 3) in vec2 v_texCoord; \n"
|
||||
|
||||
"uniform mat4 mvp_matrix; \n"
|
||||
"uniform mat4 mv_matrix; \n"
|
||||
"uniform int is_two_side; \n"
|
||||
"uniform vec3 light_pos; \n"
|
||||
"uniform vec3 light_diff; \n"
|
||||
"uniform vec3 light_spec; \n"
|
||||
"uniform vec3 light_amb; \n"
|
||||
"uniform vec3 color_facets; \n"
|
||||
"float spec_power = 128.0; \n"
|
||||
"out highp vec3 fColors; \n"
|
||||
"out highp vec2 f_texCoord; \n"
|
||||
" \n"
|
||||
"void main(void) \n"
|
||||
"{ \n"
|
||||
" vec4 P = mv_matrix * positions_facets; \n"
|
||||
" vec3 N = mat3(mv_matrix)* vNormals; \n"
|
||||
" vec3 L = light_pos - P.xyz; \n"
|
||||
" N = normalize(N); \n"
|
||||
" L = normalize(L); \n"
|
||||
" vec3 diffuse; \n"
|
||||
" if(is_two_side == 1) \n"
|
||||
" diffuse = abs(dot(N,L)) * light_diff; \n"
|
||||
" else \n"
|
||||
" diffuse = max(dot(N,L), 0.0) * light_diff; \n"
|
||||
" f_texCoord = v_texCoord; \n"
|
||||
" fColors = color_facets * (light_amb + diffuse); \n"
|
||||
" gl_Position = mvp_matrix *positions_facets; \n"
|
||||
"} \n"
|
||||
};
|
||||
//fill the fragment shader
|
||||
static const GLchar* fragment_shader_source[]=
|
||||
{
|
||||
"#version 300 es \n"
|
||||
" \n"
|
||||
"in highp vec3 fColors; \n"
|
||||
"in highp vec2 f_texCoord; \n"
|
||||
"uniform sampler2D s_texture; \n"
|
||||
"out highp vec3 color; \n"
|
||||
" \n"
|
||||
"void main(void) \n"
|
||||
"{ \n"
|
||||
" color = vec3(texture(s_texture, f_texCoord)) * fColors; \n"
|
||||
"} \n"
|
||||
};
|
||||
|
||||
GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertex_shader, 1, vertex_shader_source, NULL);
|
||||
glCompileShader(vertex_shader);
|
||||
|
||||
|
||||
GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragment_shader, 1, fragment_shader_source, NULL);
|
||||
glCompileShader(fragment_shader);
|
||||
|
||||
|
||||
//creates the program, attaches and links the shaders
|
||||
GLuint program= glCreateProgram();
|
||||
glAttachShader(program, vertex_shader);
|
||||
glAttachShader(program, fragment_shader);
|
||||
glLinkProgram(program);
|
||||
|
||||
//Clean-up
|
||||
glDeleteShader(vertex_shader);
|
||||
|
||||
rendering_program_facets = program;
|
||||
GLint result;
|
||||
glGetShaderiv(vertex_shader,GL_COMPILE_STATUS,&result);
|
||||
if(result == GL_TRUE){
|
||||
std::cout<<"Vertex compilation OK"<<std::endl;
|
||||
} else {
|
||||
int maxLength;
|
||||
int length;
|
||||
glGetShaderiv(vertex_shader,GL_INFO_LOG_LENGTH,&maxLength);
|
||||
char* log = new char[maxLength];
|
||||
glGetShaderInfoLog(vertex_shader,maxLength,&length,log);
|
||||
std::cout<<"link error : Length = "<<length<<", log ="<<log<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
glGetShaderiv(fragment_shader,GL_COMPILE_STATUS,&result);
|
||||
if(result == GL_TRUE){
|
||||
std::cout<<"Fragment compilation OK"<<std::endl;
|
||||
} else {
|
||||
int maxLength;
|
||||
int length;
|
||||
glGetShaderiv(fragment_shader,GL_INFO_LOG_LENGTH,&maxLength);
|
||||
char* log = new char[maxLength];
|
||||
glGetShaderInfoLog(fragment_shader,maxLength,&length,log);
|
||||
std::cout<<"link error : Length = "<<length<<", log ="<<log<<std::endl;
|
||||
}
|
||||
//For the edges
|
||||
static const GLchar* vertex_shader_source_lines[] =
|
||||
{
|
||||
"#version 300 es \n"
|
||||
" \n"
|
||||
"layout (location = 1) in vec4 positions_lines; \n"
|
||||
"layout (location = 4) in vec2 v_texCoord; \n"
|
||||
"uniform vec3 color_lines; \n"
|
||||
"uniform mat4 mvp_matrix; \n"
|
||||
"out highp vec3 fColors; \n"
|
||||
"out highp vec2 f_texCoord; \n"
|
||||
" \n"
|
||||
"void main(void) \n"
|
||||
"{ \n"
|
||||
" f_texCoord = v_texCoord; \n"
|
||||
" fColors = color_lines; \n"
|
||||
" gl_Position = mvp_matrix * positions_lines; \n"
|
||||
"} \n"
|
||||
};
|
||||
|
||||
vertex_shader = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertex_shader, 1, vertex_shader_source_lines, NULL);
|
||||
glCompileShader(vertex_shader);
|
||||
|
||||
|
||||
glShaderSource(fragment_shader, 1, fragment_shader_source, NULL);
|
||||
glCompileShader(fragment_shader);
|
||||
|
||||
|
||||
program = glCreateProgram();
|
||||
glAttachShader(program, vertex_shader);
|
||||
glAttachShader(program, fragment_shader);
|
||||
glLinkProgram(program);
|
||||
rendering_program_lines = program;
|
||||
glGetShaderiv(vertex_shader,GL_COMPILE_STATUS,&result);
|
||||
if(result == GL_TRUE){
|
||||
std::cout<<"Vertex compilation OK"<<std::endl;
|
||||
} else {
|
||||
int maxLength;
|
||||
int length;
|
||||
glGetShaderiv(vertex_shader,GL_INFO_LOG_LENGTH,&maxLength);
|
||||
char* log = new char[maxLength];
|
||||
glGetShaderInfoLog(vertex_shader,maxLength,&length,log);
|
||||
std::cout<<"link error : Length = "<<length<<", log ="<<log<<std::endl;
|
||||
}
|
||||
|
||||
//Clean-up
|
||||
glDeleteShader(vertex_shader);
|
||||
glDeleteShader(fragment_shader);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Scene_textured_polyhedron_item::uniform_attrib(Viewer_interface* viewer, int mode) const
|
||||
{
|
||||
light_info light;
|
||||
GLint is_both_sides = 0;
|
||||
GLfloat mvp_mat[16];
|
||||
GLfloat mv_mat[16];
|
||||
|
||||
//fills the MVP and MV matrices.
|
||||
GLdouble d_mat[16];
|
||||
viewer->camera()->getModelViewProjectionMatrix(d_mat);
|
||||
//Convert the GLdoubles matrices in GLfloats
|
||||
for (int i=0; i<16; ++i){
|
||||
mvp_mat[i] = GLfloat(d_mat[i]);
|
||||
}
|
||||
|
||||
viewer->camera()->getModelViewMatrix(d_mat);
|
||||
for (int i=0; i<16; ++i)
|
||||
mv_mat[i] = GLfloat(d_mat[i]);
|
||||
|
||||
|
||||
glGetIntegerv(GL_LIGHT_MODEL_TWO_SIDE, &is_both_sides);
|
||||
|
||||
//Gets lighting info :
|
||||
|
||||
//position
|
||||
glGetLightfv(GL_LIGHT0, GL_POSITION, light.position);
|
||||
|
||||
//ambient
|
||||
glGetLightfv(GL_LIGHT0, GL_AMBIENT, light.ambient);
|
||||
|
||||
|
||||
//specular
|
||||
glGetLightfv(GL_LIGHT0, GL_SPECULAR, light.specular);
|
||||
|
||||
//diffuse
|
||||
glGetLightfv(GL_LIGHT0, GL_DIFFUSE, light.diffuse);
|
||||
|
||||
//set the colors
|
||||
GLfloat colors_facet[3];
|
||||
GLfloat colors_lines[3];
|
||||
QColor temp = this->color();
|
||||
if(is_selected)
|
||||
{
|
||||
colors_facet[0] = temp.lighter(120).redF();
|
||||
colors_facet[1] = temp.lighter(120).greenF();
|
||||
colors_facet[2] = temp.lighter(120).blueF();
|
||||
|
||||
colors_lines[0] = 0.0;
|
||||
colors_lines[1] = 0.0;
|
||||
colors_lines[2] = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
colors_facet[0] = temp.redF();
|
||||
colors_facet[1] = temp.greenF();
|
||||
colors_facet[2] = temp.blueF();
|
||||
|
||||
colors_lines[0] = temp.lighter(50).redF();
|
||||
colors_lines[1] = temp.lighter(50).greenF();
|
||||
colors_lines[2] = temp.lighter(50).blueF();
|
||||
}
|
||||
if(mode ==0)
|
||||
{
|
||||
glUseProgram(rendering_program_facets);
|
||||
glUniformMatrix4fv(location[0], 1, GL_FALSE, mvp_mat);
|
||||
glUniformMatrix4fv(location[1], 1, GL_FALSE, mv_mat);
|
||||
glUniform3fv(location[2], 1, light.position);
|
||||
glUniform3fv(location[3], 1, light.diffuse);
|
||||
glUniform3fv(location[4], 1, light.specular);
|
||||
glUniform3fv(location[5], 1, light.ambient);
|
||||
glUniform1i(location[6], is_both_sides);
|
||||
glUniform3fv(location[8], 1, colors_facet);
|
||||
glUniform1i(sampler_location, 0);
|
||||
|
||||
}
|
||||
else if(mode ==1)
|
||||
{
|
||||
glUseProgram(rendering_program_lines);
|
||||
glUniformMatrix4fv(location[7], 1, GL_FALSE, mvp_mat);
|
||||
glUniform3fv(location[9], 1, colors_lines);
|
||||
}
|
||||
}
|
||||
void
|
||||
Scene_textured_polyhedron_item::compute_normals_and_vertices(void)
|
||||
{
|
||||
positions_facets.clear();
|
||||
positions_lines.clear();
|
||||
textures_map_facets.clear();
|
||||
textures_map_lines.clear();
|
||||
normals.clear();
|
||||
|
||||
typedef typename ::EPIC_kernel Kernel;
|
||||
typedef typename CGAL::Textured_items Items;
|
||||
typedef typename Kernel::Point_3 Point;
|
||||
typedef typename Kernel::Vector_3 Vector;
|
||||
typedef typename CGAL::Polyhedron_3<Kernel,Items> Base;
|
||||
|
||||
typedef typename Base::Halfedge_around_facet_circulator Halfedge_around_facet_circulator;
|
||||
typedef typename Base::Edge_iterator Edge_iterator;
|
||||
typedef typename Base::Facet Facet;
|
||||
typedef typename Base::Facet_iterator Facet_iterator;
|
||||
|
||||
//Facets
|
||||
Facet_iterator f = poly->facets_begin();
|
||||
|
||||
for(f = poly->facets_begin();
|
||||
f != poly->facets_end();
|
||||
f++)
|
||||
{
|
||||
|
||||
Halfedge_around_facet_circulator he = f->facet_begin();
|
||||
Halfedge_around_facet_circulator end = he;
|
||||
CGAL_For_all(he,end)
|
||||
{
|
||||
|
||||
// If Flat shading:1 normal per polygon added once per vertex
|
||||
if (cur_shading == GL_FLAT)
|
||||
{
|
||||
|
||||
Vector n = compute_facet_normal<Facet,Kernel>(*f);
|
||||
normals.push_back(n[0]);
|
||||
normals.push_back(n[1]);
|
||||
normals.push_back(n[2]);
|
||||
}
|
||||
|
||||
// If Gouraud shading: 1 normal per vertex
|
||||
else if(cur_shading == GL_SMOOTH)
|
||||
{
|
||||
|
||||
const typename Facet::Normal_3& n = he->vertex()->normal();
|
||||
normals.push_back(n[0]);
|
||||
normals.push_back(n[1]);
|
||||
normals.push_back(n[2]);
|
||||
}
|
||||
|
||||
//position
|
||||
const Point& p = he->vertex()->point();
|
||||
positions_facets.push_back(p.x());
|
||||
positions_facets.push_back(p.y());
|
||||
positions_facets.push_back(p.z());
|
||||
positions_facets.push_back(1.0);
|
||||
|
||||
const double u = he->vertex()->u();
|
||||
const double v = he->vertex()->v();
|
||||
textures_map_facets.push_back(u);
|
||||
textures_map_facets.push_back(v);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//Lines
|
||||
typedef Kernel::Point_3 Point;
|
||||
typedef Base::Edge_iterator Edge_iterator;
|
||||
|
||||
Edge_iterator he;
|
||||
|
||||
for(he = poly->edges_begin();
|
||||
he != poly->edges_end();
|
||||
he++)
|
||||
{
|
||||
|
||||
const Point& a = he->vertex()->point();
|
||||
const Point& b = he->opposite()->vertex()->point();
|
||||
positions_lines.push_back(a.x());
|
||||
positions_lines.push_back(a.y());
|
||||
positions_lines.push_back(a.z());
|
||||
positions_lines.push_back(1.0);
|
||||
|
||||
const double u = he->vertex()->u();
|
||||
const double v = he->vertex()->v();
|
||||
textures_map_lines.push_back(u);
|
||||
textures_map_lines.push_back(v);
|
||||
|
||||
positions_lines.push_back(b.x());
|
||||
positions_lines.push_back(b.y());
|
||||
positions_lines.push_back(b.z());
|
||||
positions_lines.push_back(1.0);
|
||||
|
||||
const double ou = he->opposite()->vertex()->u();
|
||||
const double ov = he->opposite()->vertex()->v();
|
||||
textures_map_lines.push_back(ou);
|
||||
textures_map_lines.push_back(ov);
|
||||
|
||||
}
|
||||
|
||||
|
||||
location[0] = glGetUniformLocation(rendering_program_facets, "mvp_matrix");
|
||||
location[1] = glGetUniformLocation(rendering_program_facets, "mv_matrix");
|
||||
location[2] = glGetUniformLocation(rendering_program_facets, "light_pos");
|
||||
location[3] = glGetUniformLocation(rendering_program_facets, "light_diff");
|
||||
location[4] = glGetUniformLocation(rendering_program_facets, "light_spec");
|
||||
location[5] = glGetUniformLocation(rendering_program_facets, "light_amb");
|
||||
location[6] = glGetUniformLocation(rendering_program_facets, "is_two_side");
|
||||
location[8] = glGetUniformLocation(rendering_program_facets, "color_facets");
|
||||
sampler_location = glGetUniformLocation(rendering_program_facets, "s_texture");
|
||||
location[7] = glGetUniformLocation(rendering_program_lines, "mvp_matrix");
|
||||
location[9] = glGetUniformLocation(rendering_program_lines, "color_lines");
|
||||
|
||||
}
|
||||
|
||||
Scene_textured_polyhedron_item::Scene_textured_polyhedron_item()
|
||||
: Scene_item_with_display_list(),
|
||||
poly(new Textured_polyhedron)
|
||||
: Scene_item(),positions_lines(0),positions_facets(0),normals(0),textures_map_facets(0),
|
||||
textures_map_lines(0),poly(new Textured_polyhedron)
|
||||
{
|
||||
texture.GenerateCheckerBoard(2048,2048,128,0,0,0,250,250,255);
|
||||
texture.GenerateCheckerBoard(2048,2048,128,0,0,0,250,250,255);
|
||||
cur_shading=GL_FLAT;
|
||||
is_selected=false;
|
||||
glGenVertexArrays(1, vao);
|
||||
//Generates an integer which will be used as ID for each buffer
|
||||
glGenBuffers(5, buffer);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glGenTextures(1, &textureId);
|
||||
compile_shaders();
|
||||
changed();
|
||||
}
|
||||
|
||||
Scene_textured_polyhedron_item::Scene_textured_polyhedron_item(Textured_polyhedron* const p)
|
||||
: Scene_item_with_display_list(),
|
||||
poly(p)
|
||||
: Scene_item(),smooth_shading(true),positions_lines(0),positions_facets(0),textures_map_facets(0),
|
||||
textures_map_lines(0), poly(p)
|
||||
{
|
||||
texture.GenerateCheckerBoard(2048,2048,128,0,0,0,250,250,255);
|
||||
cur_shading=GL_FLAT;
|
||||
is_selected=false;
|
||||
texture.GenerateCheckerBoard(2048,2048,128,0,0,0,250,250,255);
|
||||
glGenVertexArrays(1, vao);
|
||||
//Generates an integer which will be used as ID for each buffer
|
||||
glGenBuffers(5, buffer);
|
||||
|
||||
compile_shaders();
|
||||
changed();
|
||||
}
|
||||
|
||||
Scene_textured_polyhedron_item::Scene_textured_polyhedron_item(const Textured_polyhedron& p)
|
||||
: Scene_item_with_display_list(),
|
||||
poly(new Textured_polyhedron(p))
|
||||
: Scene_item(),smooth_shading(true),positions_lines(0),positions_facets(0),textures_map_facets(0),
|
||||
textures_map_lines(0), poly(new Textured_polyhedron(p))
|
||||
{
|
||||
texture.GenerateCheckerBoard(2048,2048,128,0,0,0,250,250,255);
|
||||
texture.GenerateCheckerBoard(2048,2048,128,0,0,0,250,250,255);
|
||||
cur_shading=GL_FLAT;
|
||||
is_selected=false;
|
||||
glGenVertexArrays(1, vao);
|
||||
//Generates an integer which will be used as ID for each buffer
|
||||
glGenBuffers(5, buffer);
|
||||
|
||||
compile_shaders();
|
||||
changed();
|
||||
}
|
||||
|
||||
// Scene_textured_polyhedron_item::Scene_textured_polyhedron_item(const Scene_textured_polyhedron_item& item)
|
||||
|
|
@ -36,68 +522,75 @@ Scene_textured_polyhedron_item::Scene_textured_polyhedron_item(const Textured_po
|
|||
|
||||
Scene_textured_polyhedron_item::~Scene_textured_polyhedron_item()
|
||||
{
|
||||
delete poly;
|
||||
glDeleteBuffers(5, buffer);
|
||||
glDeleteVertexArrays(1, vao);
|
||||
glDeleteProgram(rendering_program_lines);
|
||||
glDeleteProgram(rendering_program_facets);
|
||||
delete poly;
|
||||
}
|
||||
|
||||
Scene_textured_polyhedron_item*
|
||||
Scene_textured_polyhedron_item::clone() const {
|
||||
return new Scene_textured_polyhedron_item(*poly);
|
||||
return new Scene_textured_polyhedron_item(*poly);
|
||||
}
|
||||
|
||||
// Load textured_polyhedron from .OFF file
|
||||
bool
|
||||
Scene_textured_polyhedron_item::load(std::istream& in)
|
||||
{
|
||||
in >> *poly;
|
||||
return in && !isEmpty();
|
||||
std::cout<<"LOAD"<<std::endl;
|
||||
in >> *poly;
|
||||
changed();
|
||||
return in && !isEmpty();
|
||||
}
|
||||
|
||||
// Write textured_polyhedron to .OFF file
|
||||
bool
|
||||
Scene_textured_polyhedron_item::save(std::ostream& out) const
|
||||
{
|
||||
out << *poly;
|
||||
return (bool) out;
|
||||
out << *poly;
|
||||
return (bool) out;
|
||||
}
|
||||
|
||||
QString
|
||||
Scene_textured_polyhedron_item::toolTip() const
|
||||
{
|
||||
if(!poly)
|
||||
return QString();
|
||||
if(!poly)
|
||||
return QString();
|
||||
|
||||
return QObject::tr("<p>Textured polyhedron <b>%1</b> (mode: %5, color: %6)</p>"
|
||||
"<p>Number of vertices: %2<br />"
|
||||
"Number of edges: %3<br />"
|
||||
"Number of facets: %4</p>")
|
||||
.arg(this->name())
|
||||
.arg(poly->size_of_vertices())
|
||||
.arg(poly->size_of_halfedges()/2)
|
||||
.arg(poly->size_of_facets())
|
||||
.arg(this->renderingModeName())
|
||||
.arg(this->color().name());
|
||||
return QObject::tr("<p>Textured polyhedron <b>%1</b> (mode: %5, color: %6)</p>"
|
||||
"<p>Number of vertices: %2<br />"
|
||||
"Number of edges: %3<br />"
|
||||
"Number of facets: %4</p>")
|
||||
.arg(this->name())
|
||||
.arg(poly->size_of_vertices())
|
||||
.arg(poly->size_of_halfedges()/2)
|
||||
.arg(poly->size_of_facets())
|
||||
.arg(this->renderingModeName())
|
||||
.arg(this->color().name());
|
||||
}
|
||||
|
||||
// Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list
|
||||
void Scene_textured_polyhedron_item::direct_draw() const {
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGB,
|
||||
texture.GetWidth(),
|
||||
texture.GetHeight(),
|
||||
0,
|
||||
GL_RGB,
|
||||
GL_UNSIGNED_BYTE,
|
||||
texture.GetData());
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
void Scene_textured_polyhedron_item::draw(Viewer_interface* viewer) const {
|
||||
|
||||
poly->gl_draw_textured_triangles(true, true, 1.0);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glBindVertexArray(vao[0]);
|
||||
glUseProgram(rendering_program_facets);
|
||||
uniform_attrib(viewer,0);
|
||||
glDrawArrays(GL_TRIANGLES, 0, positions_facets.size()/4);
|
||||
//Clean-up
|
||||
glUseProgram(0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
}
|
||||
void Scene_textured_polyhedron_item::draw_edges(Viewer_interface* viewer) const {
|
||||
glBindVertexArray(vao[0]);
|
||||
|
||||
glUseProgram(rendering_program_lines);
|
||||
uniform_attrib(viewer,1);
|
||||
glDrawArrays(GL_LINES, 0, positions_lines.size()/4);
|
||||
// Clean-up
|
||||
glUseProgram(0);
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
Textured_polyhedron*
|
||||
|
|
@ -107,20 +600,49 @@ Scene_textured_polyhedron_item::textured_polyhedron() const { return poly; }
|
|||
|
||||
bool
|
||||
Scene_textured_polyhedron_item::isEmpty() const {
|
||||
return (poly == 0) || poly->empty();
|
||||
return (poly == 0) || poly->empty();
|
||||
}
|
||||
|
||||
Scene_textured_polyhedron_item::Bbox
|
||||
Scene_textured_polyhedron_item::bbox() const {
|
||||
const Point& p = *(poly->points_begin());
|
||||
CGAL::Bbox_3 bbox(p.x(), p.y(), p.z(), p.x(), p.y(), p.z());
|
||||
for(Textured_polyhedron::Point_iterator it = poly->points_begin();
|
||||
it != poly->points_end();
|
||||
++it) {
|
||||
bbox = bbox + it->bbox();
|
||||
}
|
||||
return Bbox(bbox.xmin(),bbox.ymin(),bbox.zmin(),
|
||||
bbox.xmax(),bbox.ymax(),bbox.zmax());
|
||||
const Point& p = *(poly->points_begin());
|
||||
CGAL::Bbox_3 bbox(p.x(), p.y(), p.z(), p.x(), p.y(), p.z());
|
||||
for(Textured_polyhedron::Point_iterator it = poly->points_begin();
|
||||
it != poly->points_end();
|
||||
++it) {
|
||||
bbox = bbox + it->bbox();
|
||||
}
|
||||
return Bbox(bbox.xmin(),bbox.ymin(),bbox.zmin(),
|
||||
bbox.xmax(),bbox.ymax(),bbox.zmax());
|
||||
}
|
||||
void
|
||||
Scene_textured_polyhedron_item::changed()
|
||||
{
|
||||
compute_normals_and_vertices();
|
||||
initialize_buffers();
|
||||
}
|
||||
void
|
||||
Scene_textured_polyhedron_item::
|
||||
contextual_changed()
|
||||
{
|
||||
GLint new_shading;
|
||||
glGetIntegerv(GL_SHADE_MODEL, &new_shading);
|
||||
prev_shading = cur_shading;
|
||||
cur_shading = new_shading;
|
||||
if(prev_shading != cur_shading)
|
||||
{
|
||||
changed();
|
||||
}
|
||||
}
|
||||
void
|
||||
Scene_textured_polyhedron_item::selection_changed(bool p_is_selected)
|
||||
{
|
||||
if(p_is_selected != is_selected)
|
||||
{
|
||||
is_selected = p_is_selected;
|
||||
initialize_buffers();
|
||||
}
|
||||
else
|
||||
is_selected = p_is_selected;
|
||||
}
|
||||
|
||||
#include "Scene_textured_polyhedron_item.moc"
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
#ifndef SCENE_TEXTURED_POLYHEDRON_ITEM_H
|
||||
#define SCENE_TEXTURED_POLYHEDRON_ITEM_H
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include "Scene_textured_polyhedron_item_config.h"
|
||||
#include "Scene_item_with_display_list.h"
|
||||
#include "Scene_item.h"
|
||||
#include "Viewer_interface.h"
|
||||
#include "Textured_polyhedron_type_fwd.h"
|
||||
#include <iostream>
|
||||
#include "texture.h"
|
||||
|
||||
// This class represents a textured polyhedron in the OpenGL scene
|
||||
class SCENE_TEXTURED_POLYHEDRON_ITEM_EXPORT Scene_textured_polyhedron_item
|
||||
: public Scene_item_with_display_list {
|
||||
: public Scene_item {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Scene_textured_polyhedron_item();
|
||||
|
|
@ -30,7 +31,10 @@ public:
|
|||
// Indicate if rendering mode is supported
|
||||
virtual bool supportsRenderingMode(RenderingMode m) const { return m != Splatting; }
|
||||
// Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list
|
||||
virtual void direct_draw() const;
|
||||
void draw() const {}
|
||||
virtual void draw(Viewer_interface*) const;
|
||||
virtual void draw_edges() const {}
|
||||
virtual void draw_edges(Viewer_interface* viewer) const;
|
||||
|
||||
// Get wrapped textured_polyhedron
|
||||
Textured_polyhedron* textured_polyhedron();
|
||||
|
|
@ -41,9 +45,34 @@ public:
|
|||
bool isEmpty() const;
|
||||
Bbox bbox() const;
|
||||
|
||||
virtual void changed();
|
||||
virtual void contextual_changed();
|
||||
virtual void selection_changed(bool);
|
||||
|
||||
private:
|
||||
Textured_polyhedron* poly;
|
||||
Texture texture;
|
||||
std::vector<float> positions_lines;
|
||||
std::vector<float> positions_facets;
|
||||
std::vector<float> normals;
|
||||
std::vector<float> textures_map_facets;
|
||||
std::vector<float> textures_map_lines;
|
||||
|
||||
|
||||
GLuint rendering_program_facets;
|
||||
GLuint rendering_program_lines;
|
||||
GLuint textureId;
|
||||
GLint location[10];
|
||||
GLint sampler_location;
|
||||
|
||||
GLuint vao[1];
|
||||
GLuint buffer[5];
|
||||
bool smooth_shading;
|
||||
void initialize_buffers();
|
||||
void compile_shaders(void);
|
||||
void uniform_attrib(Viewer_interface*, int) const;
|
||||
void compute_normals_and_vertices(void);
|
||||
|
||||
|
||||
}; // end class Scene_textured_polyhedron_item
|
||||
|
||||
|
|
|
|||
|
|
@ -139,13 +139,17 @@ void Viewer::keyPressEvent(QKeyEvent* e)
|
|||
}
|
||||
else if(e->key() == Qt::Key_M) {
|
||||
d->macro_mode = ! d->macro_mode;
|
||||
|
||||
if(d->macro_mode) {
|
||||
camera()->setZNearCoefficient(0.0005f);
|
||||
camera()->setZNearCoefficient(0.0005f);
|
||||
} else {
|
||||
camera()->setZNearCoefficient(0.005f);
|
||||
}
|
||||
this->displayMessage(tr("Macro mode: %1").
|
||||
arg(d->macro_mode ? tr("on") : tr("off")));
|
||||
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
# Output of a CGAL tool
|
||||
#CBP
|
||||
# polyhedral_surface 0
|
||||
# halfedges 0
|
||||
# triangulated 0
|
||||
# non_empty_facets 0
|
||||
# terrain 0
|
||||
# normalized_to_sphere 0
|
||||
# radius 0
|
||||
# rounded 0
|
||||
# rounded_bits 0
|
||||
# ENDCBP
|
||||
|
||||
OFF
|
||||
8 12 0
|
||||
|
||||
# 8 vertices
|
||||
# ------------------------------------------
|
||||
|
||||
|
||||
-1 -1 -1
|
||||
-1 1 -1
|
||||
1 1 -1
|
||||
1 -1 -1
|
||||
-1 -1 1
|
||||
-1 1 1
|
||||
1 1 1
|
||||
1 -1 1
|
||||
|
||||
# 12 facets
|
||||
# ------------------------------------------
|
||||
|
||||
3 3 1 0
|
||||
3 3 1 2
|
||||
3 1 4 0
|
||||
3 1 4 5
|
||||
3 3 2 7
|
||||
3 7 2 6
|
||||
3 3 0 4
|
||||
3 7 4 3
|
||||
3 7 4 6
|
||||
3 6 5 4
|
||||
3 6 5 1
|
||||
3 2 1 6
|
||||
|
||||
|
||||
# End of OFF #
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
# Output of a CGAL tool
|
||||
#CBP
|
||||
# polyhedral_surface 0
|
||||
# halfedges 0
|
||||
# triangulated 0
|
||||
# non_empty_facets 0
|
||||
# terrain 0
|
||||
# normalized_to_sphere 0
|
||||
# radius 0
|
||||
# rounded 0
|
||||
# rounded_bits 0
|
||||
# ENDCBP
|
||||
|
||||
OFF
|
||||
8 6 0
|
||||
|
||||
# 8 vertices
|
||||
# ------------------------------------------
|
||||
|
||||
|
||||
-1 -1 -1
|
||||
-1 1 -1
|
||||
1 1 -1
|
||||
1 -1 -1
|
||||
-1 -1 1
|
||||
-1 1 1
|
||||
1 1 1
|
||||
1 -1 1
|
||||
|
||||
# 6 facets
|
||||
# ------------------------------------------
|
||||
|
||||
4 1 2 3 0
|
||||
4 0 1 5 4
|
||||
4 2 6 7 3
|
||||
4 3 7 4 0
|
||||
4 6 5 4 7
|
||||
4 6 2 1 5
|
||||
|
||||
|
||||
# End of OFF #
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -14,143 +14,143 @@ namespace CGAL
|
|||
template <class Refs, class T, class P, class Norm>
|
||||
class Textured_facet : public CGAL::HalfedgeDS_face_base<Refs, T>
|
||||
{
|
||||
// normal
|
||||
Norm m_normal;
|
||||
// normal
|
||||
Norm m_normal;
|
||||
|
||||
public:
|
||||
|
||||
// life cycle
|
||||
// no constructors to repeat, since only
|
||||
// default constructor mandatory
|
||||
// life cycle
|
||||
// no constructors to repeat, since only
|
||||
// default constructor mandatory
|
||||
|
||||
Textured_facet()
|
||||
{
|
||||
}
|
||||
Textured_facet()
|
||||
{
|
||||
}
|
||||
|
||||
// normal
|
||||
typedef Norm Normal_3;
|
||||
Normal_3& normal() { return m_normal; }
|
||||
const Normal_3& normal() const { return m_normal; }
|
||||
// normal
|
||||
typedef Norm Normal_3;
|
||||
Normal_3& normal() { return m_normal; }
|
||||
const Normal_3& normal() const { return m_normal; }
|
||||
};
|
||||
|
||||
template <class Refs, class Tprev, class Tvertex, class Tface, class Norm>
|
||||
class Textured_halfedge : public CGAL::HalfedgeDS_halfedge_base<Refs,Tprev,Tvertex,Tface>
|
||||
{
|
||||
public:
|
||||
// life cycle
|
||||
Textured_halfedge()
|
||||
{
|
||||
}
|
||||
// life cycle
|
||||
Textured_halfedge()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template <class Refs, class T, class P, class Norm>
|
||||
class Textured_vertex : public CGAL::HalfedgeDS_vertex_base<Refs, T, P>
|
||||
{
|
||||
// normal
|
||||
Norm m_normal;
|
||||
double m_u;
|
||||
double m_v;
|
||||
// normal
|
||||
Norm m_normal;
|
||||
double m_u;
|
||||
double m_v;
|
||||
|
||||
public:
|
||||
// life cycle
|
||||
Textured_vertex() {}
|
||||
// life cycle
|
||||
Textured_vertex() {}
|
||||
|
||||
// repeat mandatory constructors
|
||||
Textured_vertex(const P& pt)
|
||||
: CGAL::HalfedgeDS_vertex_base<Refs, T, P>(pt)
|
||||
{
|
||||
}
|
||||
// repeat mandatory constructors
|
||||
Textured_vertex(const P& pt)
|
||||
: CGAL::HalfedgeDS_vertex_base<Refs, T, P>(pt)
|
||||
{
|
||||
}
|
||||
|
||||
// normal
|
||||
typedef Norm Normal_3;
|
||||
Normal_3& normal() { return m_normal; }
|
||||
const Normal_3& normal() const { return m_normal; }
|
||||
// normal
|
||||
typedef Norm Normal_3;
|
||||
Normal_3& normal() { return m_normal; }
|
||||
const Normal_3& normal() const { return m_normal; }
|
||||
|
||||
// u,v coordinates
|
||||
double& u() { return m_u; }
|
||||
const double& u() const { return m_u; }
|
||||
double& v() { return m_v; }
|
||||
const double& v() const { return m_v; }
|
||||
// u,v coordinates
|
||||
double& u() { return m_u; }
|
||||
const double& u() const { return m_u; }
|
||||
double& v() { return m_v; }
|
||||
const double& v() const { return m_v; }
|
||||
};
|
||||
|
||||
struct Textured_items : public CGAL::Polyhedron_items_3
|
||||
{
|
||||
// wrap vertex
|
||||
template<class Refs, class Traits> struct Vertex_wrapper
|
||||
{
|
||||
typedef typename Traits::Point_3 Point;
|
||||
typedef typename Traits::Vector_3 Normal;
|
||||
typedef Textured_vertex<Refs,
|
||||
CGAL::Tag_true,
|
||||
Point,
|
||||
Normal> Vertex;
|
||||
};
|
||||
// wrap vertex
|
||||
template<class Refs, class Traits> struct Vertex_wrapper
|
||||
{
|
||||
typedef typename Traits::Point_3 Point;
|
||||
typedef typename Traits::Vector_3 Normal;
|
||||
typedef Textured_vertex<Refs,
|
||||
CGAL::Tag_true,
|
||||
Point,
|
||||
Normal> Vertex;
|
||||
};
|
||||
|
||||
// wrap face
|
||||
template<class Refs, class Traits> struct Face_wrapper
|
||||
{
|
||||
typedef typename Traits::Point_3 Point;
|
||||
typedef typename Traits::Vector_3 Normal;
|
||||
typedef Textured_facet<Refs,
|
||||
CGAL::Tag_true,
|
||||
Point,
|
||||
Normal> Face;
|
||||
};
|
||||
// wrap face
|
||||
template<class Refs, class Traits> struct Face_wrapper
|
||||
{
|
||||
typedef typename Traits::Point_3 Point;
|
||||
typedef typename Traits::Vector_3 Normal;
|
||||
typedef Textured_facet<Refs,
|
||||
CGAL::Tag_true,
|
||||
Point,
|
||||
Normal> Face;
|
||||
};
|
||||
|
||||
// wrap halfedge
|
||||
template<class Refs, class Traits> struct Halfedge_wrapper
|
||||
{
|
||||
typedef typename Traits::Vector_3 Normal;
|
||||
typedef Textured_halfedge<Refs,
|
||||
CGAL::Tag_true,
|
||||
CGAL::Tag_true,
|
||||
CGAL::Tag_true,
|
||||
Normal> Halfedge;
|
||||
};
|
||||
// wrap halfedge
|
||||
template<class Refs, class Traits> struct Halfedge_wrapper
|
||||
{
|
||||
typedef typename Traits::Vector_3 Normal;
|
||||
typedef Textured_halfedge<Refs,
|
||||
CGAL::Tag_true,
|
||||
CGAL::Tag_true,
|
||||
CGAL::Tag_true,
|
||||
Normal> Halfedge;
|
||||
};
|
||||
};
|
||||
|
||||
// compute facet normal
|
||||
struct Facet_normal // (functor)
|
||||
{
|
||||
template<class Facet> void operator()(Facet& f)
|
||||
{
|
||||
typename Facet::Normal_3 sum = CGAL::NULL_VECTOR;
|
||||
typename Facet::Halfedge_around_facet_circulator h = f.facet_begin();
|
||||
do
|
||||
template<class Facet> void operator()(Facet& f)
|
||||
{
|
||||
typename Facet::Normal_3 normal = CGAL::cross_product(h->next()->vertex()->point() - h->vertex()->point(), h->next()->next()->vertex()->point() - h->next()->vertex()->point());
|
||||
double sqnorm = normal * normal;
|
||||
if (sqnorm != 0)
|
||||
normal = normal / (float)std::sqrt(sqnorm);
|
||||
sum = sum + normal;
|
||||
} while (++h != f.facet_begin());
|
||||
float sqnorm = sum * sum;
|
||||
if (sqnorm != 0.0)
|
||||
f.normal() = sum / std::sqrt(sqnorm);
|
||||
else
|
||||
f.normal() = CGAL::NULL_VECTOR;
|
||||
}
|
||||
typename Facet::Normal_3 sum = CGAL::NULL_VECTOR;
|
||||
typename Facet::Halfedge_around_facet_circulator h = f.facet_begin();
|
||||
do
|
||||
{
|
||||
typename Facet::Normal_3 normal = CGAL::cross_product(h->next()->vertex()->point() - h->vertex()->point(), h->next()->next()->vertex()->point() - h->next()->vertex()->point());
|
||||
double sqnorm = normal * normal;
|
||||
if (sqnorm != 0)
|
||||
normal = normal / (float)std::sqrt(sqnorm);
|
||||
sum = sum + normal;
|
||||
} while (++h != f.facet_begin());
|
||||
float sqnorm = sum * sum;
|
||||
if (sqnorm != 0.0)
|
||||
f.normal() = sum / std::sqrt(sqnorm);
|
||||
else
|
||||
f.normal() = CGAL::NULL_VECTOR;
|
||||
}
|
||||
};
|
||||
|
||||
// compute vertex normal
|
||||
struct Vertex_normal // (functor)
|
||||
{
|
||||
template<class Vertex> void operator()(Vertex& v)
|
||||
{
|
||||
typename Vertex::Normal_3 normal = CGAL::NULL_VECTOR;
|
||||
typename Vertex::Halfedge_around_vertex_const_circulator pHalfedge =
|
||||
v.vertex_begin();
|
||||
typename Vertex::Halfedge_around_vertex_const_circulator begin =
|
||||
pHalfedge;
|
||||
CGAL_For_all(pHalfedge,begin)
|
||||
if(!pHalfedge->is_border())
|
||||
normal = normal + pHalfedge->facet()->normal();
|
||||
float sqnorm = normal * normal;
|
||||
if (sqnorm != 0.0f)
|
||||
v.normal() = normal / (float)std::sqrt(sqnorm);
|
||||
else
|
||||
v.normal() = CGAL::NULL_VECTOR;
|
||||
}
|
||||
template<class Vertex> void operator()(Vertex& v)
|
||||
{
|
||||
typename Vertex::Normal_3 normal = CGAL::NULL_VECTOR;
|
||||
typename Vertex::Halfedge_around_vertex_const_circulator pHalfedge =
|
||||
v.vertex_begin();
|
||||
typename Vertex::Halfedge_around_vertex_const_circulator begin =
|
||||
pHalfedge;
|
||||
CGAL_For_all(pHalfedge,begin)
|
||||
if(!pHalfedge->is_border())
|
||||
normal = normal + pHalfedge->facet()->normal();
|
||||
float sqnorm = normal * normal;
|
||||
if (sqnorm != 0.0f)
|
||||
v.normal() = normal / (float)std::sqrt(sqnorm);
|
||||
else
|
||||
v.normal() = CGAL::NULL_VECTOR;
|
||||
}
|
||||
};
|
||||
|
||||
//*********************************************************
|
||||
|
|
@ -158,93 +158,93 @@ template <class Kernel, class Items>
|
|||
class Textured_polyhedron : public CGAL::Polyhedron_3<Kernel,Items>
|
||||
{
|
||||
public :
|
||||
typedef typename Kernel::FT FT;
|
||||
typedef typename Kernel::Point_3 Point;
|
||||
typedef typename Kernel::Vector_3 Vector;
|
||||
typedef typename CGAL::Polyhedron_3<Kernel,Items> Base;
|
||||
typedef typename CGAL::Polyhedron_3<Kernel,CGAL::Polyhedron_items_3> Basic_polyhedron;
|
||||
typedef typename Kernel::FT FT;
|
||||
typedef typename Kernel::Point_3 Point;
|
||||
typedef typename Kernel::Vector_3 Vector;
|
||||
typedef typename CGAL::Polyhedron_3<Kernel,Items> Base;
|
||||
typedef typename CGAL::Polyhedron_3<Kernel,CGAL::Polyhedron_items_3> Basic_polyhedron;
|
||||
|
||||
typedef typename Base::Vertex_handle Vertex_handle;
|
||||
typedef typename Base::Vertex_iterator Vertex_iterator;
|
||||
typedef typename Base::Halfedge_handle Halfedge_handle;
|
||||
typedef typename Base::Halfedge_iterator Halfedge_iterator;
|
||||
typedef typename Base::Halfedge_around_facet_circulator Halfedge_around_facet_circulator;
|
||||
typedef typename Base::Halfedge_around_vertex_circulator Halfedge_around_vertex_circulator;
|
||||
typedef typename Base::Edge_iterator Edge_iterator;
|
||||
typedef typename Base::Facet Facet;
|
||||
typedef typename Base::Facet_iterator Facet_iterator;
|
||||
typedef typename Base::Facet_handle Facet_handle;
|
||||
typedef typename Base::Vertex_handle Vertex_handle;
|
||||
typedef typename Base::Vertex_iterator Vertex_iterator;
|
||||
typedef typename Base::Halfedge_handle Halfedge_handle;
|
||||
typedef typename Base::Halfedge_iterator Halfedge_iterator;
|
||||
typedef typename Base::Halfedge_around_facet_circulator Halfedge_around_facet_circulator;
|
||||
typedef typename Base::Halfedge_around_vertex_circulator Halfedge_around_vertex_circulator;
|
||||
typedef typename Base::Edge_iterator Edge_iterator;
|
||||
typedef typename Base::Facet Facet;
|
||||
typedef typename Base::Facet_iterator Facet_iterator;
|
||||
typedef typename Base::Facet_handle Facet_handle;
|
||||
|
||||
public :
|
||||
|
||||
// life cycle
|
||||
Textured_polyhedron()
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~Textured_polyhedron()
|
||||
{
|
||||
}
|
||||
|
||||
// normals (per facet, then per vertex)
|
||||
void compute_normals_per_facet()
|
||||
{
|
||||
std::for_each(this->facets_begin(),this->facets_end(),Facet_normal());
|
||||
}
|
||||
void compute_normals_per_vertex()
|
||||
{
|
||||
std::for_each(this->vertices_begin(),this->vertices_end(),Vertex_normal());
|
||||
}
|
||||
void compute_normals()
|
||||
{
|
||||
compute_normals_per_facet();
|
||||
compute_normals_per_vertex();
|
||||
}
|
||||
|
||||
void gl_draw_textured_triangles(bool smooth_shading,
|
||||
bool use_normals,
|
||||
const double scaling_tex_coordinates)
|
||||
{
|
||||
::glBegin(GL_TRIANGLES);
|
||||
Facet_iterator f = this->facets_begin();
|
||||
for(;f!= this->facets_end();f++)
|
||||
gl_draw_textured_facet(f,smooth_shading,use_normals,scaling_tex_coordinates);
|
||||
::glEnd();
|
||||
}
|
||||
|
||||
void gl_draw_textured_facet(Facet_handle f,
|
||||
bool smooth_shading,
|
||||
bool use_normals,
|
||||
const double scaling_tex_coordinates)
|
||||
{
|
||||
// one normal per face
|
||||
if(use_normals && !smooth_shading)
|
||||
// life cycle
|
||||
Textured_polyhedron()
|
||||
{
|
||||
const typename Facet::Normal_3& n = f->normal();
|
||||
::glNormal3f(n[0],n[1],n[2]);
|
||||
}
|
||||
|
||||
// revolve around current face to get vertices
|
||||
Halfedge_around_facet_circulator he = f->facet_begin();
|
||||
do
|
||||
virtual ~Textured_polyhedron()
|
||||
{
|
||||
// one normal per vertex
|
||||
if(use_normals && smooth_shading)
|
||||
{
|
||||
const typename Facet::Normal_3& n = he->vertex()->normal();
|
||||
::glNormal3d(n[0],n[1],n[2]);
|
||||
}
|
||||
|
||||
// polygon assembly is performed per vertex
|
||||
const Point& p = he->vertex()->point();
|
||||
const double u = he->vertex()->u();
|
||||
const double v = he->vertex()->v();
|
||||
// std::cout << u << " " << v << std::endl;
|
||||
::glTexCoord2d(u * scaling_tex_coordinates, v * scaling_tex_coordinates);
|
||||
::glVertex3d(p[0],p[1],p[2]);
|
||||
}
|
||||
while(++he != f->facet_begin());
|
||||
}
|
||||
|
||||
// normals (per facet, then per vertex)
|
||||
void compute_normals_per_facet()
|
||||
{
|
||||
std::for_each(this->facets_begin(),this->facets_end(),Facet_normal());
|
||||
}
|
||||
void compute_normals_per_vertex()
|
||||
{
|
||||
std::for_each(this->vertices_begin(),this->vertices_end(),Vertex_normal());
|
||||
}
|
||||
void compute_normals()
|
||||
{
|
||||
compute_normals_per_facet();
|
||||
compute_normals_per_vertex();
|
||||
}
|
||||
|
||||
void gl_draw_textured_triangles(bool smooth_shading,
|
||||
bool use_normals,
|
||||
const double scaling_tex_coordinates)
|
||||
{
|
||||
::glBegin(GL_TRIANGLES);
|
||||
Facet_iterator f = this->facets_begin();
|
||||
for(;f!= this->facets_end();f++)
|
||||
gl_draw_textured_facet(f,smooth_shading,use_normals,scaling_tex_coordinates);
|
||||
::glEnd();
|
||||
}
|
||||
|
||||
void gl_draw_textured_facet(Facet_handle f,
|
||||
bool smooth_shading,
|
||||
bool use_normals,
|
||||
const double scaling_tex_coordinates)
|
||||
{
|
||||
// one normal per face
|
||||
if(use_normals && !smooth_shading)
|
||||
{
|
||||
const typename Facet::Normal_3& n = f->normal();
|
||||
::glNormal3f(n[0],n[1],n[2]);
|
||||
}
|
||||
|
||||
// revolve around current face to get vertices
|
||||
Halfedge_around_facet_circulator he = f->facet_begin();
|
||||
do
|
||||
{
|
||||
// one normal per vertex
|
||||
if(use_normals && smooth_shading)
|
||||
{
|
||||
const typename Facet::Normal_3& n = he->vertex()->normal();
|
||||
::glNormal3d(n[0],n[1],n[2]);
|
||||
}
|
||||
|
||||
// polygon assembly is performed per vertex
|
||||
const Point& p = he->vertex()->point();
|
||||
const double u = he->vertex()->u();
|
||||
const double v = he->vertex()->v();
|
||||
// std::cout << u << " " << v << std::endl;
|
||||
::glTexCoord2d(u * scaling_tex_coordinates, v * scaling_tex_coordinates);
|
||||
::glVertex3d(p[0],p[1],p[2]);
|
||||
}
|
||||
while(++he != f->facet_begin());
|
||||
}
|
||||
}; // end class Textured_polyhedron
|
||||
|
||||
} // end namespace CGAL
|
||||
|
|
|
|||
Loading…
Reference in New Issue