mirror of https://github.com/CGAL/cgal
Periodic Lloyd demo initial commit
This commit is contained in:
parent
9cf8c7227d
commit
d26f570f3c
|
|
@ -2386,6 +2386,16 @@ Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/icons/wireframe.png -
|
||||||
Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/icons/wireframeOff.png -text
|
Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/icons/wireframeOff.png -text
|
||||||
Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/resources/about.html -text
|
Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/resources/about.html -text
|
||||||
Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/resources/about_CGAL.html -text
|
Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/resources/about_CGAL.html -text
|
||||||
|
Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/MainWindow.ui -text
|
||||||
|
Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/Periodic_Lloyd_3.qrc -text
|
||||||
|
Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/about_CGAL.html svneol=native#text/html
|
||||||
|
Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/about_Periodic_Lloyd_3.html svneol=native#text/html
|
||||||
|
Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/icons/cp8.png -text svneol=unset#image/png
|
||||||
|
Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/icons/fileNew.png -text svneol=unset#image/png
|
||||||
|
Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/icons/pause.png -text svneol=unset#image/png
|
||||||
|
Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/icons/planar.png -text svneol=unset#image/png
|
||||||
|
Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/icons/play.png -text svneol=unset#image/png
|
||||||
|
Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/icons/step.png -text svneol=unset#image/png
|
||||||
Periodic_3_triangulation_3/doc_tex/Periodic_3_triangulation_3/offsets.gif -text
|
Periodic_3_triangulation_3/doc_tex/Periodic_3_triangulation_3/offsets.gif -text
|
||||||
Periodic_3_triangulation_3/doc_tex/Periodic_3_triangulation_3/offsets.pdf -text
|
Periodic_3_triangulation_3/doc_tex/Periodic_3_triangulation_3/offsets.pdf -text
|
||||||
Periodic_3_triangulation_3/doc_tex/Periodic_3_triangulation_3/orient.gif -text svneol=unset#image/gif
|
Periodic_3_triangulation_3/doc_tex/Periodic_3_triangulation_3/orient.gif -text svneol=unset#image/gif
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
#include <QTimer>
|
||||||
#include "Scene.h"
|
#include "Scene.h"
|
||||||
|
|
||||||
#include <QtAssistant/QAssistantClient>
|
#include <QtAssistant/QAssistantClient>
|
||||||
|
|
@ -140,6 +141,7 @@ private:
|
||||||
public:
|
public:
|
||||||
Ui::MainWindow* ui;
|
Ui::MainWindow* ui;
|
||||||
Scene* s;
|
Scene* s;
|
||||||
|
QTimer* timer;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QAssistantClient *assistantClient;
|
QAssistantClient *assistantClient;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
# Created by the script cgal_create_cmake_script
|
||||||
|
# This is the CMake script for compiling a CGAL application.
|
||||||
|
|
||||||
|
project (Periodic_Lloyd_3)
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 2.4.5)
|
||||||
|
|
||||||
|
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
|
||||||
|
|
||||||
|
if ( COMMAND cmake_policy )
|
||||||
|
cmake_policy( SET CMP0003 NEW )
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_package(CGAL COMPONENTS Qt4)
|
||||||
|
include(${CGAL_USE_FILE})
|
||||||
|
|
||||||
|
set( QT_USE_QTXML TRUE )
|
||||||
|
set( QT_USE_QTMAIN TRUE )
|
||||||
|
set( QT_USE_QTSCRIPT TRUE )
|
||||||
|
set( QT_USE_QTOPENGL TRUE )
|
||||||
|
find_package(Qt4)
|
||||||
|
|
||||||
|
find_package(OpenGL)
|
||||||
|
find_package(QGLViewer)
|
||||||
|
|
||||||
|
if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND )
|
||||||
|
|
||||||
|
include(${QT_USE_FILE})
|
||||||
|
|
||||||
|
include_directories (${QGLVIEWER_INCLUDE_DIR})
|
||||||
|
include_directories (BEFORE ../../include ./ )
|
||||||
|
|
||||||
|
# ui file, created wih Qt Designer
|
||||||
|
qt4_wrap_ui( uis MainWindow.ui )
|
||||||
|
|
||||||
|
# qrc files (resources files, that contain icons, at least)
|
||||||
|
qt4_add_resources ( RESOURCE_FILES ./Periodic_Lloyd_3.qrc )
|
||||||
|
|
||||||
|
qt4_automoc( MainWindow.cpp Viewer.cpp)
|
||||||
|
|
||||||
|
add_executable ( Periodic_Lloyd_3 Periodic_Lloyd_3.cpp MainWindow.cpp Viewer.cpp ${uis} ${RESOURCE_FILES} )
|
||||||
|
|
||||||
|
add_to_cached_list( CGAL_EXECUTABLE_TARGETS Periodic_Lloyd_3 )
|
||||||
|
|
||||||
|
target_link_libraries( Periodic_Lloyd_3 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES})
|
||||||
|
target_link_libraries( Periodic_Lloyd_3 ${QT_LIBRARIES} ${QGLVIEWER_LIBRARIES} )
|
||||||
|
target_link_libraries( Periodic_Lloyd_3 ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} )
|
||||||
|
|
||||||
|
else()
|
||||||
|
|
||||||
|
message(STATUS "NOTICE: This demo requires CGAL, the QGLViewer, OpenGL and Qt4, and will not be compiled.")
|
||||||
|
|
||||||
|
endif()
|
||||||
|
|
@ -0,0 +1,136 @@
|
||||||
|
|
||||||
|
#include "MainWindow.h"
|
||||||
|
|
||||||
|
MainWindow::MainWindow(QWidget* parent): CGAL::Qt::DemosMainWindow(parent)
|
||||||
|
{
|
||||||
|
setupUi(this);
|
||||||
|
this->viewer->setScene(&scene);
|
||||||
|
connectActions();
|
||||||
|
this->addAboutDemo(":/cgal/help/about_Periodic_Lloyd_3.html");
|
||||||
|
this->addAboutCGAL();
|
||||||
|
|
||||||
|
scene.eight_copies=false;
|
||||||
|
scene.two_dimensional=false;
|
||||||
|
|
||||||
|
qtimer = new QTimer(this);
|
||||||
|
connect(qtimer, SIGNAL(timeout()), this, SLOT(lloydStep()));
|
||||||
|
int slider_value = speedSlider->value();
|
||||||
|
int speed = (100-slider_value)*100;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MainWindow::connectActions()
|
||||||
|
{
|
||||||
|
QObject::connect(this->actionNew_Point_Set, SIGNAL(triggered()),
|
||||||
|
this, SLOT(newPointSet()));
|
||||||
|
|
||||||
|
QObject::connect(this->speedSlider, SIGNAL(valueChanged(int)),
|
||||||
|
this, SLOT(speedChanged(int)));
|
||||||
|
|
||||||
|
QObject::connect(this->viewer, SIGNAL(valueChanged(int)),
|
||||||
|
this, SLOT(speedChanged(int)));
|
||||||
|
|
||||||
|
QObject::connect(this, SIGNAL(sceneChanged()),
|
||||||
|
this->viewer, SLOT(sceneChanged()));
|
||||||
|
|
||||||
|
QObject::connect(this->actionStep, SIGNAL(triggered()),
|
||||||
|
this, SLOT(lloydStep()));
|
||||||
|
|
||||||
|
QObject::connect(this->actionStop, SIGNAL(toggled(bool)),
|
||||||
|
this, SLOT(togglePause(bool)));
|
||||||
|
|
||||||
|
QObject::connect(this->actionShow_8_Copies, SIGNAL(toggled(bool)),
|
||||||
|
this, SLOT(toggle8Copies(bool)));
|
||||||
|
|
||||||
|
QObject::connect(this->action2D_version, SIGNAL(toggled(bool)),
|
||||||
|
this, SLOT(toggle2D(bool)));
|
||||||
|
|
||||||
|
QObject::connect(this->actionQuit, SIGNAL(triggered()),
|
||||||
|
qApp, SLOT(quit()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MainWindow::togglePause(bool p)
|
||||||
|
{
|
||||||
|
if (p)
|
||||||
|
qtimer->stop();
|
||||||
|
else {
|
||||||
|
int speed = (100-(speedSlider->value()))*100;
|
||||||
|
qtimer->start(speed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MainWindow::toggle8Copies(bool on)
|
||||||
|
{
|
||||||
|
scene.eight_copies = on;
|
||||||
|
emit(sceneChanged());
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MainWindow::toggle2D(bool on)
|
||||||
|
{
|
||||||
|
scene.two_dimensional = on;
|
||||||
|
if (on) newPointSet();
|
||||||
|
else emit(sceneChanged());
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MainWindow::newPointSet()
|
||||||
|
{
|
||||||
|
bool ok;
|
||||||
|
int numberOfPoints = QInputDialog::getInteger(this,
|
||||||
|
"Periodic Lloyd", "Number of points: ", 100, 0, 2147483647, 1, &ok );
|
||||||
|
|
||||||
|
if (ok) newPoints(numberOfPoints);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::lloydStep() {
|
||||||
|
scene.lloyd_step();
|
||||||
|
viewer->updateGL();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MainWindow::speedChanged(int i)
|
||||||
|
{
|
||||||
|
int speed = (100-i)*100;
|
||||||
|
if (qtimer->isActive()) {
|
||||||
|
qtimer->stop();
|
||||||
|
qtimer->start(speed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MainWindow::newPoints(int n)
|
||||||
|
{
|
||||||
|
scene.periodic_triangulation.clear();
|
||||||
|
scene.points.clear();
|
||||||
|
|
||||||
|
CGAL::Random rnd(std::time(NULL));
|
||||||
|
CGAL::Random_points_in_cube_3<Point_3, Creator> in_cube(1,rnd);
|
||||||
|
|
||||||
|
for (int i=0 ; i<n ; i++)
|
||||||
|
if (scene.two_dimensional) {
|
||||||
|
Point_3 rdpt = *in_cube++;
|
||||||
|
scene.points.push_back(Point_3(rdpt.x(),rdpt.y(),0.));
|
||||||
|
} else
|
||||||
|
scene.points.push_back(*in_cube++);
|
||||||
|
|
||||||
|
timer.reset();
|
||||||
|
timer.start();
|
||||||
|
scene.periodic_triangulation.set_domain(Iso_cuboid_3(-1,-1,-1,1,1,1));
|
||||||
|
scene.periodic_triangulation.insert(scene.points.begin(), scene.points.end());
|
||||||
|
timer.stop();
|
||||||
|
|
||||||
|
|
||||||
|
speedSlider->setRange(0,100);
|
||||||
|
speedSlider->setSliderPosition(100);
|
||||||
|
|
||||||
|
emit (sceneChanged());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#include "MainWindow.moc"
|
||||||
|
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
#ifndef MAIN_WINDOW_H
|
||||||
|
#define MAIN_WINDOW_H
|
||||||
|
|
||||||
|
#include "ui_MainWindow.h"
|
||||||
|
#include <CGAL/Qt/DemosMainWindow.h>
|
||||||
|
#include <QInputDialog>
|
||||||
|
#include <QSlider>
|
||||||
|
#include <QTimer>
|
||||||
|
class QWidget;
|
||||||
|
|
||||||
|
class MainWindow : public CGAL::Qt::DemosMainWindow, private Ui::MainWindow
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
MainWindow(QWidget* parent = 0);
|
||||||
|
|
||||||
|
void connectActions();
|
||||||
|
|
||||||
|
Scene scene;
|
||||||
|
Timer timer;
|
||||||
|
QTimer * qtimer;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void newPoints(int i);
|
||||||
|
void newPointSet();
|
||||||
|
void speedChanged(int i);
|
||||||
|
void togglePause(bool p);
|
||||||
|
void toggle8Copies(bool on);
|
||||||
|
void toggle2D(bool on);
|
||||||
|
void lloydStep();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void sceneChanged();
|
||||||
|
void speedChanged();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,224 @@
|
||||||
|
<ui version="4.0" >
|
||||||
|
<class>MainWindow</class>
|
||||||
|
<widget class="QMainWindow" name="MainWindow" >
|
||||||
|
<property name="geometry" >
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>635</width>
|
||||||
|
<height>504</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle" >
|
||||||
|
<string>CGAL 3D Periodic Lloyd</string>
|
||||||
|
</property>
|
||||||
|
<property name="windowIcon" >
|
||||||
|
<iconset resource="../resources/CGAL.qrc" >
|
||||||
|
<normaloff>:/cgal/logos/cgal_icon</normaloff>:/cgal/logos/cgal_icon</iconset>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralwidget" >
|
||||||
|
<layout class="QVBoxLayout" >
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout" >
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="alphaLabel" >
|
||||||
|
<property name="sizePolicy" >
|
||||||
|
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="font" >
|
||||||
|
<font>
|
||||||
|
<weight>75</weight>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Speed:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSlider" name="speedSlider" >
|
||||||
|
<property name="sizePolicy" >
|
||||||
|
<sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimum" >
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum" >
|
||||||
|
<number>100</number>
|
||||||
|
</property>
|
||||||
|
<property name="singleStep" >
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="value" >
|
||||||
|
<number>100</number>
|
||||||
|
</property>
|
||||||
|
<property name="orientation" >
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="Viewer" native="1" name="viewer" />
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenuBar" name="menubar" >
|
||||||
|
<property name="geometry" >
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>635</width>
|
||||||
|
<height>22</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<widget class="QMenu" name="menuFile" >
|
||||||
|
<property name="title" >
|
||||||
|
<string>File</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionNew_Point_Set" />
|
||||||
|
<addaction name="separator" />
|
||||||
|
<addaction name="actionRender_Video" />
|
||||||
|
<addaction name="separator" />
|
||||||
|
<addaction name="actionQuit" />
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenu" name="menuControl" >
|
||||||
|
<property name="title" >
|
||||||
|
<string>Control</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionStep" />
|
||||||
|
<addaction name="actionStop" />
|
||||||
|
<addaction name="separator" />
|
||||||
|
<addaction name="actionShow_8_Copies" />
|
||||||
|
<addaction name="action2D_version" />
|
||||||
|
</widget>
|
||||||
|
<addaction name="menuFile" />
|
||||||
|
<addaction name="menuControl" />
|
||||||
|
</widget>
|
||||||
|
<widget class="QStatusBar" name="statusbar" />
|
||||||
|
<widget class="QToolBar" name="toolBar" >
|
||||||
|
<property name="windowTitle" >
|
||||||
|
<string>toolBar</string>
|
||||||
|
</property>
|
||||||
|
<attribute name="toolBarArea" >
|
||||||
|
<enum>TopToolBarArea</enum>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="toolBarBreak" >
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
|
<addaction name="actionNew_Point_Set" />
|
||||||
|
<addaction name="separator" />
|
||||||
|
<addaction name="actionStep" />
|
||||||
|
<addaction name="actionStop" />
|
||||||
|
<addaction name="separator" />
|
||||||
|
<addaction name="actionShow_8_Copies" />
|
||||||
|
<addaction name="action2D_version" />
|
||||||
|
</widget>
|
||||||
|
<action name="actionQuit" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Quit</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionRender_Video" >
|
||||||
|
<property name="enabled" >
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Render Video</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionNew_Point_Set" >
|
||||||
|
<property name="icon" >
|
||||||
|
<iconset>
|
||||||
|
<normaloff>icons/fileNew.png</normaloff>icons/fileNew.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>New Point Set</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut" >
|
||||||
|
<string>Ctrl+N</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionStop" >
|
||||||
|
<property name="checkable" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="checked" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="icon" >
|
||||||
|
<iconset>
|
||||||
|
<normaloff>icons/pause.png</normaloff>
|
||||||
|
<normalon>icons/play.png</normalon>icons/pause.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Stop</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut" >
|
||||||
|
<string>P</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionShow_8_Copies" >
|
||||||
|
<property name="checkable" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="icon" >
|
||||||
|
<iconset>
|
||||||
|
<normaloff>icons/cp8.png</normaloff>icons/cp8.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Show 8 Copies</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut" >
|
||||||
|
<string>C</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="action2D_version" >
|
||||||
|
<property name="checkable" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="icon" >
|
||||||
|
<iconset>
|
||||||
|
<normaloff>icons/planar.png</normaloff>icons/planar.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>2D version</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut" >
|
||||||
|
<string>2</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionStep" >
|
||||||
|
<property name="icon" >
|
||||||
|
<iconset>
|
||||||
|
<normaloff>icons/step.png</normaloff>icons/step.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Step</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut" >
|
||||||
|
<string>Return, Enter</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>Viewer</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>Viewer.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<resources>
|
||||||
|
<include location="../resources/CGAL.qrc" />
|
||||||
|
<include location="Periodic_Lloyd_3.qrc" />
|
||||||
|
</resources>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
#include "MainWindow.h"
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
QApplication application(argc,argv);
|
||||||
|
|
||||||
|
application.setOrganizationDomain("inria.fr");
|
||||||
|
application.setOrganizationName("INRIA");
|
||||||
|
application.setApplicationName("3D Periodic Lloyd");
|
||||||
|
|
||||||
|
// Import resources from libCGALQt4.
|
||||||
|
// See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE
|
||||||
|
Q_INIT_RESOURCE(File);
|
||||||
|
Q_INIT_RESOURCE(Periodic_Lloyd_3);
|
||||||
|
Q_INIT_RESOURCE(CGAL);
|
||||||
|
MainWindow mw;
|
||||||
|
mw.show();
|
||||||
|
|
||||||
|
return application.exec();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<RCC>
|
||||||
|
<qresource prefix="/cgal/help" >
|
||||||
|
<file>about_Periodic_Lloyd_3.html</file>
|
||||||
|
<file>about_CGAL.html</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
||||||
|
|
@ -0,0 +1,77 @@
|
||||||
|
#ifndef SCENE_H
|
||||||
|
#define SCENE_H
|
||||||
|
|
||||||
|
#include "typedefs.h"
|
||||||
|
|
||||||
|
struct Scene {
|
||||||
|
|
||||||
|
std::list<Point_3> points;
|
||||||
|
P3DT3 periodic_triangulation;
|
||||||
|
|
||||||
|
bool eight_copies;
|
||||||
|
bool two_dimensional;
|
||||||
|
|
||||||
|
void lloyd_step() {
|
||||||
|
Timer timer;
|
||||||
|
timer.reset();
|
||||||
|
|
||||||
|
std::vector<Vertex_handle> vts;
|
||||||
|
for (Periodic_point_iterator ppit
|
||||||
|
= periodic_triangulation.periodic_points_begin(P3DT3::UNIQUE) ;
|
||||||
|
ppit != periodic_triangulation.periodic_points_end(P3DT3::UNIQUE) ;
|
||||||
|
++ppit)
|
||||||
|
vts.push_back(ppit.get_vertex());
|
||||||
|
|
||||||
|
points.clear();
|
||||||
|
for (std::vector<Vertex_handle>::iterator vit = vts.begin();
|
||||||
|
vit != vts.end(); ++vit) {
|
||||||
|
std::vector<Point_3> dual_vertices;
|
||||||
|
periodic_triangulation.dual(*vit,std::back_inserter(dual_vertices));
|
||||||
|
Point_3 new_point = (two_dimensional ?
|
||||||
|
compute_barycenter_2D(dual_vertices) :
|
||||||
|
compute_barycenter(dual_vertices) );
|
||||||
|
dual_vertices.clear();
|
||||||
|
points.push_back(new_point);
|
||||||
|
}
|
||||||
|
periodic_triangulation.clear();
|
||||||
|
periodic_triangulation.insert(points.begin(),points.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
Point_3 compute_barycenter(std::vector<Point_3> dual_pts) const {
|
||||||
|
FT x(0), y(0), z(0);
|
||||||
|
int i;
|
||||||
|
for ( i=0 ; i<dual_pts.size() ; i++) {
|
||||||
|
x += dual_pts[i].x();
|
||||||
|
y += dual_pts[i].y();
|
||||||
|
z += dual_pts[i].z();
|
||||||
|
}
|
||||||
|
x /= i;
|
||||||
|
y /= i;
|
||||||
|
z /= i;
|
||||||
|
|
||||||
|
x = (x < -1 ? x+2 : (x >= 1 ? x-2 : x));
|
||||||
|
y = (y < -1 ? y+2 : (y >= 1 ? y-2 : y));
|
||||||
|
z = (z < -1 ? z+2 : (z >= 1 ? z-2 : z));
|
||||||
|
|
||||||
|
return Point_3(x,y,z);
|
||||||
|
}
|
||||||
|
|
||||||
|
Point_3 compute_barycenter_2D(std::vector<Point_3> dual_pts) const {
|
||||||
|
FT x(0), y(0);
|
||||||
|
int i;
|
||||||
|
for ( i=0 ; i<dual_pts.size() ; i++) {
|
||||||
|
x += dual_pts[i].x();
|
||||||
|
y += dual_pts[i].y();
|
||||||
|
}
|
||||||
|
x /= i;
|
||||||
|
y /= i;
|
||||||
|
|
||||||
|
x = (x < -1 ? x+2 : (x >= 1 ? x-2 : x));
|
||||||
|
y = (y < -1 ? y+2 : (y >= 1 ? y-2 : y));
|
||||||
|
|
||||||
|
return Point_3(x,y,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //SCENE_H
|
||||||
|
|
@ -0,0 +1,193 @@
|
||||||
|
#include "Viewer.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <CGAL/bounding_box.h>
|
||||||
|
#include <QGLViewer/vec.h>
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Viewer::init()
|
||||||
|
{
|
||||||
|
setBackgroundColor(::Qt::white);
|
||||||
|
this->camera()->setSceneBoundingBox(
|
||||||
|
qglviewer::Vec(-1.,-1.,-1.),
|
||||||
|
qglviewer::Vec( 1., 1., 1.));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Viewer::sceneChanged()
|
||||||
|
{
|
||||||
|
this->showEntireScene();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Viewer::draw()
|
||||||
|
{
|
||||||
|
|
||||||
|
// define material
|
||||||
|
float ambient[] = { 0.25f,
|
||||||
|
0.20725f,
|
||||||
|
0.20725f,
|
||||||
|
0.922f };
|
||||||
|
float diffuse[] = { 1.0f,
|
||||||
|
0.829f,
|
||||||
|
0.829f,
|
||||||
|
0.922f };
|
||||||
|
|
||||||
|
float specular[] = { 0.296648f,
|
||||||
|
0.296648f,
|
||||||
|
0.296648f,
|
||||||
|
0.522f };
|
||||||
|
|
||||||
|
float emission[] = { 0.3f,
|
||||||
|
0.3f,
|
||||||
|
0.3f,
|
||||||
|
1.0f };
|
||||||
|
float shininess[] = { 11.264f };
|
||||||
|
|
||||||
|
// apply material
|
||||||
|
::glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
|
||||||
|
::glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
|
||||||
|
::glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, specular);
|
||||||
|
::glMaterialfv( GL_FRONT_AND_BACK, GL_SHININESS, shininess);
|
||||||
|
::glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, emission);
|
||||||
|
|
||||||
|
// anti-aliasing (if the OpenGL driver permits that)
|
||||||
|
::glEnable(GL_LINE_SMOOTH);
|
||||||
|
|
||||||
|
::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
|
||||||
|
// draw surface mesh
|
||||||
|
bool m_view_surface = true;
|
||||||
|
bool draw_triangles_edges = true;
|
||||||
|
|
||||||
|
if(m_view_surface)
|
||||||
|
{
|
||||||
|
::glEnable(GL_LIGHTING);
|
||||||
|
::glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
|
||||||
|
::glColor3f(0.2f, 0.2f, 1.f);
|
||||||
|
::glEnable(GL_POLYGON_OFFSET_FILL);
|
||||||
|
::glPolygonOffset(3.0f,-3.0f);
|
||||||
|
gl_draw_surface();
|
||||||
|
|
||||||
|
if(draw_triangles_edges)
|
||||||
|
{
|
||||||
|
::glDisable(GL_LIGHTING);
|
||||||
|
::glLineWidth(1.);
|
||||||
|
::glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
|
||||||
|
::glColor3ub(0,0,0);
|
||||||
|
::glDisable(GL_POLYGON_OFFSET_FILL);
|
||||||
|
gl_draw_surface();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Viewer::gl_draw_surface()
|
||||||
|
{
|
||||||
|
::glColor3f(1.0f, 0.72f, 0.06f);
|
||||||
|
::glDisable(GL_LIGHTING);
|
||||||
|
::glEnable(GL_POINT_SMOOTH);
|
||||||
|
::glPointSize(5);
|
||||||
|
::glBegin(GL_POINTS);
|
||||||
|
for(Periodic_point_iterator ppit
|
||||||
|
= scene->periodic_triangulation.periodic_points_begin(
|
||||||
|
P3DT3::UNIQUE) ;
|
||||||
|
ppit != scene->periodic_triangulation.periodic_points_end(P3DT3::UNIQUE);
|
||||||
|
++ppit){
|
||||||
|
Point_3 p(scene->periodic_triangulation.point(*ppit));
|
||||||
|
::glVertex3d(p.x(), p.y(), p.z());
|
||||||
|
}
|
||||||
|
::glEnd();
|
||||||
|
::glDisable(GL_POINT_SMOOTH);
|
||||||
|
|
||||||
|
::glBegin(GL_LINES);
|
||||||
|
|
||||||
|
::glColor3f(0.27f, 0.51f, 0.7f);
|
||||||
|
|
||||||
|
for (Periodic_triangle_iterator ptit
|
||||||
|
= scene->periodic_triangulation.periodic_triangles_begin(
|
||||||
|
P3DT3::UNIQUE);
|
||||||
|
ptit != scene->periodic_triangulation.periodic_triangles_end(
|
||||||
|
P3DT3::UNIQUE);
|
||||||
|
++ptit) {
|
||||||
|
for (int i=0 ; i<4 ; i++) {
|
||||||
|
Segment_3 dual = scene->periodic_triangulation.segment(
|
||||||
|
scene->periodic_triangulation.dual(*(ptit.get_facet())));
|
||||||
|
|
||||||
|
FT sz = dual.source().z();
|
||||||
|
FT tz = dual.target().z();
|
||||||
|
|
||||||
|
if (scene->two_dimensional && ((sz-tz > 0.5) || (sz-tz < -0.5))) continue;
|
||||||
|
|
||||||
|
if (scene->two_dimensional) { sz = 0.; tz = 0.; }
|
||||||
|
FT sx = dual.source().x();
|
||||||
|
FT tx = dual.target().x();
|
||||||
|
FT sy = dual.source().y();
|
||||||
|
FT ty = dual.target().y();
|
||||||
|
|
||||||
|
::glVertex3d(sx,sy,sz); ::glVertex3d(tx,ty,tz);
|
||||||
|
if (scene->eight_copies) {
|
||||||
|
::glColor3f(0.69f, 0.77f, 0.87f);
|
||||||
|
::glVertex3d(sx+0.,sy+2.,sz+0.);
|
||||||
|
::glVertex3d(tx+0.,ty+2.,tz+0.);
|
||||||
|
::glVertex3d(sx+2.,sy+0.,sz+0.);
|
||||||
|
::glVertex3d(tx+2.,ty+0.,tz+0.);
|
||||||
|
::glVertex3d(sx+2.,sy+2.,sz+0.);
|
||||||
|
::glVertex3d(tx+2.,ty+2.,tz+0.);
|
||||||
|
if (!scene->two_dimensional) {
|
||||||
|
::glVertex3d(sx+0.,sy+0.,sz+2.);
|
||||||
|
::glVertex3d(tx+0.,ty+0.,tz+2.);
|
||||||
|
::glVertex3d(sx+0.,sy+2.,sz+2.);
|
||||||
|
::glVertex3d(tx+0.,ty+2.,tz+2.);
|
||||||
|
::glVertex3d(sx+2.,sy+0.,sz+2.);
|
||||||
|
::glVertex3d(tx+2.,ty+0.,tz+2.);
|
||||||
|
::glVertex3d(sx+2.,sy+2.,sz+2.);
|
||||||
|
::glVertex3d(tx+2.,ty+2.,tz+2.);
|
||||||
|
}
|
||||||
|
::glColor3f(0.27f, 0.51f, 0.7f);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
::glEnd();
|
||||||
|
::glEnable(GL_LIGHTING);
|
||||||
|
}
|
||||||
|
|
||||||
|
Viewer::Vec
|
||||||
|
Viewer::next_around_circle(const float& phi, const Vec& pos, const Vec& ori) {
|
||||||
|
Vec cam = pos-ori;
|
||||||
|
Vec cam_norm = cam/cam.norm();
|
||||||
|
|
||||||
|
Vec y(cam_norm.z, 0, -cam_norm.x);
|
||||||
|
Vec y_norm = y/y.norm();
|
||||||
|
|
||||||
|
Vec new_cam = ori + (cam_norm*cos(phi) + y_norm*sin(phi)) * cam.norm();
|
||||||
|
return new_cam;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Viewer::render_video()
|
||||||
|
{
|
||||||
|
setSnapshotFormat("PNG");
|
||||||
|
for (int alpha=0 ; alpha <= 100 ; alpha++ ) {
|
||||||
|
emit (valueChanged(alpha));
|
||||||
|
std::cout<<alpha<<std::endl;
|
||||||
|
QString alpha_str;
|
||||||
|
alpha_str.setNum(alpha);
|
||||||
|
displayMessage(QString("alpha: ") + alpha_str + QString("%"),10000);
|
||||||
|
|
||||||
|
for (int fr=0 ; fr < 50 ; fr++) {
|
||||||
|
Vec cam = camera()->position();
|
||||||
|
Vec ori = sceneCenter();
|
||||||
|
Vec new_cam = next_around_circle(0.01,cam,ori);
|
||||||
|
camera()->setPosition(new_cam);
|
||||||
|
camera()->lookAt(ori);
|
||||||
|
this->showEntireScene();
|
||||||
|
saveSnapshot(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#include "Viewer.moc"
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
#ifndef VIEWER_H
|
||||||
|
#define VIEWER_H
|
||||||
|
|
||||||
|
#include "Scene.h"
|
||||||
|
#include <QGLViewer/qglviewer.h>
|
||||||
|
|
||||||
|
|
||||||
|
class Viewer : public QGLViewer {
|
||||||
|
|
||||||
|
typedef qglviewer::Vec Vec;
|
||||||
|
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
CGAL::Timer timer;
|
||||||
|
Scene* scene;
|
||||||
|
|
||||||
|
int nr_of_facets;
|
||||||
|
public:
|
||||||
|
Viewer(QWidget* parent)
|
||||||
|
: QGLViewer(parent)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void setScene(Scene* scene_)
|
||||||
|
{
|
||||||
|
scene = scene_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init();
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
public:
|
||||||
|
void draw();
|
||||||
|
|
||||||
|
void gl_draw_surface();
|
||||||
|
|
||||||
|
|
||||||
|
public slots :
|
||||||
|
|
||||||
|
void sceneChanged();
|
||||||
|
void render_video();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void valueChanged(int i);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Vec next_around_circle(const float& phi, const Vec& pos, const Vec& ori);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<h2>Computational Geometry Algorithms Library</h2>
|
||||||
|
<p>CGAL provides efficient and reliable geometric algorithms in the form of a C++ library.</p>
|
||||||
|
<p>For more information visit <a href="http://www.cgal.org/">www.cgal.org</a>.</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<h2>3D Periodic Lloyd</h2>
|
||||||
|
<p>Copyright © 2009 INRIA</p>
|
||||||
|
<p>This application illustrates the Lloyd algorithm in 3D periodic space
|
||||||
|
using <a href="http://www.cgal.org/">CGAL</a>.</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 768 B |
Binary file not shown.
|
After Width: | Height: | Size: 640 B |
Binary file not shown.
|
After Width: | Height: | Size: 2.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
|
|
@ -0,0 +1,64 @@
|
||||||
|
#ifndef TYPEDEFS_H
|
||||||
|
#define TYPEDEFS_H
|
||||||
|
|
||||||
|
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||||
|
#include <CGAL/Periodic_3_triangulation_traits_3.h>
|
||||||
|
#include <CGAL/Periodic_3_Delaunay_triangulation_3.h>
|
||||||
|
#include <CGAL/Random.h>
|
||||||
|
#include <CGAL/point_generators_3.h>
|
||||||
|
#include <CGAL/Timer.h>
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
#include <list>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
|
||||||
|
typedef double coord_type;
|
||||||
|
|
||||||
|
typedef CGAL::Exact_predicates_inexact_constructions_kernel EPIC;
|
||||||
|
typedef CGAL::Periodic_3_triangulation_traits_3<EPIC> K;
|
||||||
|
|
||||||
|
typedef K::FT FT;
|
||||||
|
typedef K::Point_3 Point_3;
|
||||||
|
typedef K::Vector_3 Vector_3;
|
||||||
|
typedef K::Segment_3 Segment_3;
|
||||||
|
typedef K::Ray_3 Ray_3;
|
||||||
|
typedef K::Line_3 Line;
|
||||||
|
typedef K::Triangle_3 Triangle_3;
|
||||||
|
typedef K::Iso_cuboid_3 Iso_cuboid_3;
|
||||||
|
typedef K::Tetrahedron_3 Tetrahedron_3;
|
||||||
|
|
||||||
|
typedef CGAL::Creator_uniform_3<double,Point_3> Creator;
|
||||||
|
|
||||||
|
typedef CGAL::Periodic_3_Delaunay_triangulation_3<K> P3DT3;
|
||||||
|
|
||||||
|
typedef P3DT3::Cell Cell;
|
||||||
|
typedef P3DT3::Vertex Vertex;
|
||||||
|
typedef P3DT3::Edge Edge;
|
||||||
|
typedef P3DT3::Facet Facet;
|
||||||
|
typedef P3DT3::Cell_handle Cell_handle;
|
||||||
|
typedef P3DT3::Vertex_handle Vertex_handle;
|
||||||
|
|
||||||
|
typedef P3DT3::Cell_circulator Cell_circulator;
|
||||||
|
|
||||||
|
typedef P3DT3::Locate_type Locate_type;
|
||||||
|
|
||||||
|
typedef P3DT3::Cell_iterator Cell_iterator;
|
||||||
|
typedef P3DT3::Vertex_iterator Vertex_iterator;
|
||||||
|
typedef P3DT3::Edge_iterator Edge_iterator;
|
||||||
|
typedef P3DT3::Facet_iterator Facet_iterator;
|
||||||
|
|
||||||
|
typedef P3DT3::Periodic_point_iterator Periodic_point_iterator;
|
||||||
|
typedef P3DT3::Periodic_triangle_iterator Periodic_triangle_iterator;
|
||||||
|
|
||||||
|
typedef P3DT3::Periodic_tetrahedron_iterator Periodic_tetrahedron_iterator;
|
||||||
|
|
||||||
|
typedef CGAL::Timer Timer;
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Reference in New Issue