Skip to content
Snippets Groups Projects
Commit 687b4b0f authored by Vincent Nivoliers's avatar Vincent Nivoliers
Browse files

debut de presentation

parent caae558d
No related branches found
No related tags found
No related merge requests found
Showing with 2191 additions and 39 deletions
......@@ -10,6 +10,8 @@
#include <sstream>
#include <cmath>
//{{{ struct vec
struct vec {
vec(float x, float y) : x(x), y(y) {}
float x ;
......@@ -36,33 +38,23 @@ struct vec {
}
} ;
using rational = boost::multiprecision::cpp_rational ;
//}}}
template<typename number = rational>
int orient(const vec& v0, const vec& v1) {
number v0x = v0.x ;
number v0y = v0.y ;
number v1x = v1.x ;
number v1y = v1.y ;
//determinant
float d = v0.x*v1.y - v0.y*v1.x ;
number d = v0x*v1y - v0y*v1x ;
//encode as sign
if(d > 0) return 1 ;
if(d < 0) return -1 ;
std::cout << "zero case" << std::endl ;
//return 0 ;
if(v1y > 0) return 1 ;
if(v1y < 0) return -1 ;
if(v1x > 0) return -1 ;
if(v1x < 0) return 1 ;
if(v0y > 0) return -1 ;
if(v0y < 0) return 1 ;
if(v0x > 0) return 1 ;
if(v0y < 0) return -1 ;
return 1 ;
return 0 ;
}
struct vec_compare {
//functor given leftmost point for sort
vec_compare(const vec& origin) : origin(origin) {}
//comparison
bool operator()(const vec& p0, const vec& p1) {
int o = orient(p0-origin, p1-origin) ;
return o < 0 ;
......@@ -70,6 +62,8 @@ struct vec_compare {
const vec& origin ;
} ;
//{{{leftmost
size_t leftmost(const std::vector<vec>& points) {
size_t min = 0 ;
for(size_t i = 1; i < points.size(); ++i) {
......@@ -80,18 +74,26 @@ size_t leftmost(const std::vector<vec>& points) {
return min ;
}
//}}}
void compute_hull(std::vector<vec>& points, std::vector<vec>& hull) {
//leftmost point ahead
size_t l = leftmost(points) ;
std::swap(*points.begin(), *(points.begin() + l)) ;
//sort the rest by angle
std::sort(points.begin() + 1, points.end(), vec_compare(points[0])) ;
//add the first two points to the hull
hull.push_back(points[0]) ;
hull.push_back(points[1]) ;
//sweep the remaining points
for(size_t i = 2; i < points.size(); ++i) {
//check whether the last segment creates a wrong turn
const vec& p = points[i] ;
vec v1 = p - *(hull.end() - 1) ;
vec v2 = *(hull.end() - 1) - *(hull.end() - 2) ;
while(hull.size() > 1 && orient(v1, v2) < 0) {
//in case of wrong turn, rease the last point of the hull and iterate
hull.erase(hull.end() - 1) ;
v1 = p - *(hull.end() - 1) ;
v2 = p - *(hull.end() - 2) ;
......@@ -100,6 +102,8 @@ void compute_hull(std::vector<vec>& points, std::vector<vec>& hull) {
}
}
//{{{ generate svg
void svg_hull(const std::string& filename, const std::vector<vec>& points, const std::vector<vec>& hull) {
std::ofstream file(filename) ;
SvgPad svg(file, 1024, 1024) ;
......@@ -118,12 +122,33 @@ void svg_hull(const std::string& filename, const std::vector<vec>& points, const
svg.close() ;
}
void svg_sort(const std::string& filename, const std::vector<vec>& points) {
std::ofstream file(filename) ;
SvgPad svg(file, 1024, 1024) ;
svg.open() ;
float col0[3] = { 1., 0.9, 0.3 } ;
float col1[3] = { 0.35, 0.2, 0.4 } ;
for(size_t i = 1; i < points.size(); ++i) {
float b = ((float) i-1) / (points.size() - 1) ;
float a = 1-b ;
svg.stroke(a*col0[0] + b*col1[0], a*col0[1] + b*col1[1], a*col0[2] + b*col1[2]) ;
svg.line(points[0].x, points[0].y, points[i].x, points[i].y) ;
}
svg.close() ;
}
//}}}
int main() {
unsigned int size = 100 ;
//{{{ random test
{
//random numbers
std::random_device rd ;
std::mt19937 alea(rd()) ;
std::uniform_real_distribution<float> uniform_float(0, 1) ;
......@@ -131,50 +156,42 @@ int main() {
std::vector<vec> points ;
for(unsigned int i = 0; i < size; ++i) {
//generate a uniform point in a ball
vec p(normal_float(alea), normal_float(alea)) ;
float n = sqrt(uniform_float(alea)) / 2 ;
p = p * (n / p.length()) + vec(0.5,0.5);
points.push_back(p) ;
}
//hull
std::vector<vec> hull ;
compute_hull(points, hull) ;
svg_hull("/tmp/test_hull.svg", points, hull) ;
svg_hull("/tmp/hull_test.svg", points, hull) ;
svg_sort("/tmp/hull_lines.svg", points) ;
}
{
unsigned int subdivisions = 30 ;
float near = 127 ;
float mid = 0.5 ;
for(unsigned int ratio = 1; ratio < subdivisions; ++ratio) {
std::vector<vec> points ;
points.emplace_back(1, 0) ;
points.emplace_back(0, 0) ;
points.emplace_back(mid, 1) ;
points.emplace_back(mid/near, 1./near) ;
points.emplace_back(mid/near + (mid - 1./near) * ((float) ratio) / subdivisions, 1./near + (1 - 2./near) * ((float) ratio) / subdivisions) ;
std::vector<vec> hull ;
compute_hull(points, hull) ;
std::stringstream fname ;
fname << "/tmp/pbm_hull" << ratio << ".svg" ;
svg_hull(fname.str(), points, hull) ;
}
}
//}}}
//{{{ wicked test
{
std::vector<vec> points ;
//aligned points
points.emplace_back(0, 0.5) ;
points.emplace_back(0, 1) ;
points.emplace_back(0, 0) ;
points.emplace_back(0, 0.8) ;
//make the hull non flat
points.emplace_back(1, 0.5) ;
//hull
std::vector<vec> hull ;
compute_hull(points, hull) ;
svg_hull("/tmp/ordered.svg", points, hull) ;
svg_hull("/tmp/hull_aligned.svg", points, hull) ;
}
//}}}
return 0 ;
}
File added
This diff is collapsed.
File added
<svg height="1024" width="1024">
<circle cx="51" cy="512" r="8" fill="rgb(0, 0, 0)" />
<circle cx="51" cy="51" r="8" fill="rgb(0, 0, 0)" />
<circle cx="51" cy="973" r="8" fill="rgb(0, 0, 0)" />
<circle cx="51" cy="235" r="8" fill="rgb(0, 0, 0)" />
<circle cx="973" cy="512" r="8" fill="rgb(0, 0, 0)" />
<circle cx="51" cy="512" r="12" stroke="rgb(0, 0, 0)" stroke-width="2" style="fill:none"/>
<line x1="51" y1="512" x2="51" y2="51" stroke="rgb(0, 0, 0)" stroke-width="2"/>
<circle cx="51" cy="51" r="12" stroke="rgb(0, 0, 0)" stroke-width="2" style="fill:none"/>
<line x1="51" y1="51" x2="51" y2="973" stroke="rgb(0, 0, 0)" stroke-width="2"/>
<circle cx="51" cy="973" r="12" stroke="rgb(0, 0, 0)" stroke-width="2" style="fill:none"/>
<line x1="51" y1="973" x2="51" y2="235" stroke="rgb(0, 0, 0)" stroke-width="2"/>
<circle cx="51" cy="235" r="12" stroke="rgb(0, 0, 0)" stroke-width="2" style="fill:none"/>
<line x1="51" y1="235" x2="973" y2="512" stroke="rgb(0, 0, 0)" stroke-width="2"/>
<circle cx="973" cy="512" r="12" stroke="rgb(0, 0, 0)" stroke-width="2" style="fill:none"/>
<line x1="973" y1="512" x2="51" y2="512" stroke="rgb(0, 0, 0)" stroke-width="2"/>
</svg>
File added
File added
File added
File added
File added
\documentclass[french,pdftex]{beamer}
\usepackage[french]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[rm={oldstyle=false}, sf={oldstyle=false}, tt={oldstyle=false}]{cfr-lm}
\usetheme[compress]{Nivoliev}
\usepackage{tabularx}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{amsmath, amssymb, amsfonts}
\usepackage{mathrsfs}
\usepackage{amsthm}
\usepackage{verbatim}
\usepackage{color}
\usepackage{colortbl}
\usepackage{multimedia}
\usepackage{listings}
\usepackage{multimedia}
\usepackage{xparse}
\usepackage{comment}
\usepackage{animate}
\setbeamersize{text margin left=0.5cm}
\setbeamersize{text margin right=0.5cm}
\definecolor{thcolor}{rgb}{0.8,0.3,0}
\setbeamercolor{structure}{fg=thcolor}
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{enumerate items}[default]
\setbeamercovered{transparent}
\lstset{breakatwhitespace,
basicstyle=\tiny\ttfamily,
columns=fullflexible,
keepspaces,
breaklines,
tabsize=3,
showstringspaces=false,
extendedchars=true}
\setcounter{tocdepth}{1}
\newcommand{\hl}[1]{\textcolor{structure}{#1}}
\newcommand{\lighten}{\xglobal\blendcolors*{!20!white}\color{black}}
\newcommand{\unlighten}{\xglobal\blendcolors{}\color{black}}
\newcommand{\li}{\linewidth}
%{fold} minipages
\newcommand{\minip}[2]{
\begin{minipage}[c]{#1\linewidth}
#2
\end{minipage}
}
\newcommand{\cminip}[2]{
\begin{minipage}[c]{#1\linewidth}
\begin{center}
#2
\end{center}
\end{minipage}
}
%{endfold}
%{fold} blocks
%\newsavebox{\blockbox}
%\NewDocumentEnvironment{myblock}{O{} O{} m}%
%{%
% \sbox{\blockbox}\bgroup%
%}
%{%
% \egroup
% \begin{tikzpicture}%
% \draw%
% node[ drop shadow,%
% rounded corners,%
% draw, fill=white,%
% inner sep = 3mm,%
% #2%
% ] (#1) {
% \usebox{\blockbox}
% } ;
% \end{tikzpicture}%
%}
\NewDocumentEnvironment{myblock}{O{} O{} m}%
{%
\begin{tikzpicture}%
\draw%
node[ drop shadow,%
rounded corners,%
draw, fill=white,%
inner sep = 3mm,%
#2%
] (#1) \bgroup%
\begin{minipage}[c]{#3}%
}
{%
\end{minipage}%
\egroup
;
\end{tikzpicture}%
}
\NewDocumentEnvironment{myoverlayblock}{O{} O{} m m}%
{%
\begin{tikzpicture}[overlay]%
\draw #4%
node[ drop shadow,%
rounded corners,%
draw, fill=white,%
inner sep = 3mm,%
#2%
]%
(#1)
\bgroup%
\begin{minipage}[c]{#3}%
}
{%
\end{minipage}%
\egroup ;%
\end{tikzpicture}%
}
%{endfold}
%{fold} Tikz
\everymath{\displaystyle}
\tikzstyle{every picture}+=[remember picture]
\usetikzlibrary{calc,fit,decorations.pathreplacing,decorations.pathmorphing,shadows}
\tikzstyle{rounded boxed}=[thick, draw=black, fill=white, rounded corners]
%blocks and arrows between them
\newcommand{\pin}[2]{
\tikz[baseline]{
\node[anchor=base,inner sep=0pt, outer sep=0pt, minimum height=1em] (#1) {#2};
}
}
\newcommand{\back}[3]{
\tikz[baseline]{
\node[rectangle,rounded corners,anchor=base,fill=#2!10] (#1) {#3};
}
}
\newcommand{\backcol}[3]{
\tikz[baseline]{
\node[very thin,rectangle,rounded corners,anchor=base,fill=#2] (#1) {#3};
}
}
\newcommand{\arrow}[3]{
\tikz[overlay]{
\path[->] (#2) edge [#1] (#3);
}
}
\newcommand{\tikzmark}[1]{
\tikz[overlay,baseline=0pt]{
\node [anchor=base, inner sep = 0pt, outer sep = 0pt] (#1) {};
}
}
%{endfold}
%{fold} listings
\newcommand{\CodeSymbol}[1]{\textcolor{red}{#1}}
\lstset{
showspaces=false,
showstringspaces=false,
basicstyle=\footnotesize,
numbersep=0pt,
keywordstyle=\color{structure!90!black},
belowskip=-0.8\baselineskip,
aboveskip=0pt,
escapechar=§
}
%{endfold}
%\renewcommand\textbullet{\ensuremath{\bullet}}
% Copyright 2007 by Vincent Nivoliers
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/licenses/LICENSE for more details.
\DeclareOptionBeamer{compress}{\beamer@compresstrue}
\ProcessOptionsBeamer
\mode<presentation>
\setbeamercolor{section in head/foot}{use=structure,bg=structure.fg!25!bg}
\useoutertheme[subsection=false]{miniframes}
\useinnertheme[shadow=true]{rounded}
\setbeamertemplate{frametitle}[default][center]
\AtBeginDocument{%
{
\usebeamercolor{section in head/foot}
}
\pgfdeclareverticalshading{beamer@headfade}{\paperwidth}
{%
color(0cm)=(bg);
color(1cm)=(section in head/foot.bg)%
}
\pgfdeclareverticalshading{beamer@footfade}{\paperwidth}
{%
color(0cm)=(section in head/foot.bg);
color(2.5ex)=(bg)%
}
\setbeamercolor{section in head/foot}{bg=}
}
\addtoheadtemplate{\pgfuseshading{beamer@headfade}\vskip-1cm}{}
\defbeamertemplate*{footline}{mytheme theme}
{
\leavevmode%
\pgfuseshading{beamer@footfade}%
\vskip-3.5ex
\begin{beamercolorbox}[wd=\textwidth,ht=2.25ex,dp=1.25ex]{section in head/foot}%
\hspace{1em}
\insertshorttitle
\hfill
\insertauthor
\hfill
\insertframenumber{} $/$ \inserttotalframenumber
\hspace{1em}
\end{beamercolorbox}
\vskip0pt%
}
\beamertemplatedotitem
\mode<all>
\input{beamer_preamble}
\usepackage{ucblalgo}
\setbeamercovered{invisible}
\newcommand{\vor}[1]{\ensuremath{\mathrm{Vor}(#1)}}
\newcommand{\site}{\mathbf{v}}
\newcommand{\sites}{\mathbf{V}}
\newcommand{\point}{\mathbf{p}}
\newcommand{\R}{\mathbb{R}}
\title{Robustesse des algorithmes géométriques : \\ prédicats, filtrage et perturbation}
\author{Vincent Nivoliers}
\begin{document}
\frame{
\maketitle
}
\section{Enveloppe Convexe}
\frame {
\frametitle{Enveloppe convexe}
\centering
\includegraphics[width=0.6\li]{Figures/hull.pdf}
}
\frame {
\frametitle{1 -- trier par angle}
\centering
\includegraphics[width=0.6\li]{Figures/hull_sort.pdf}
}
\frame {
\frametitle{2 -- balayage}
\centering
\only<1>{\includegraphics[width=0.6\li]{Figures/partial_hull.pdf}}%
\only<2>{\includegraphics[width=0.6\li]{Figures/increment_hull_1.pdf}}%
\only<3>{\includegraphics[width=0.6\li]{Figures/increment_hull_2.pdf}}%
\only<4>{\includegraphics[width=0.6\li]{Figures/increment_hull_3.pdf}}%
\only<5>{\includegraphics[width=0.6\li]{Figures/hull.pdf}}%
}
\frame {
\frametitle{Robustesse : alignements de points}
\centering
\includegraphics[width=0.6\li]{Figures/hull_aligned.pdf}
}
\frame {
\frametitle{Algorithme}
\centering
\begin{ucblalgo}
\SetKwData{pt}{p}
\SetKwData{hull}{enveloppe}
\Algorithme{
déterminer le point le plus à gauche \;
\only<1>{trier les points par angle \;}%
\only<2>{\hl{trier les points par angle} \;}
$\hull \leftarrow$ une nouvelle pile\;
ajouter les deux premiers points à \hull \;
\PourCh{autre point \pt dans l'ordre}{
$\pt_0 \leftarrow $ dernier point de l'\hull \;
$\pt_1 \leftarrow $ avant dernier point de l'\hull \;
\Tq{
\only<1>{$(\pt_0\pt)$ tourne à gauche par rapport à $(\pt_1\pt)$}%
\only<2>{\hl{$(\pt_0\pt)$ tourne à gauche par rapport à $(\pt_1\pt)$}}
}{
retirer le sommet de l'\hull \;
$\pt_0 \leftarrow $ dernier point de l'\hull \;
$\pt_1 \leftarrow $ avant dernier point de l'\hull \;
}
ajouter \pt à l'\hull \;
}
\Retour{l'\hull} \;
}
\end{ucblalgo}
}
\end{document}
\ProvidesPackage{ucblalgo}
\RequirePackage[vlined, french, nofillcomment]{algorithm2e}
\RequirePackage{xstring}
\RequirePackage{ifthen}
%\SetFuncSty{textsf}%
%\SetProcArgSty{textsf}%
%\SetFuncArgSty{textsf}%
%\SetArgSty{textrm}%
\SetCommentSty{}%
\SetKw{vrai}{vrai}
\SetKw{faux}{faux}
\SetKw{tableau}{tableau}
\SetKwInput{donres}{données-résultat}
\SetKwInput{donnee}{données}
\SetKwInput{resultat}{résultat}
\SetKwInput{variables}{variables}
\SetKwFor{FonctionInner}{Fonction}{}{fin}
\SetKwFor{ProcedureInner}{Procédure}{}{fin}
\newcommand{\algoname}[1]{%
\StrBefore{#1}{(}%
}
\newcommand{\algoargs}[1]{%
(\StrBehind{#1}{(}%
}
\newcommand{\Fonction}[2]{
%\def\ucblalgoname{\algoname{#1}}%
%\def\ucblalgoargs{\algoargs{#1}}%
\SetKwFunction{#1}{#1}%
\FonctionInner{\expandafter\csname#1\endcsname{} \ifthenelse{\equal{#2}{}}{}{$\rightarrow$ #2}}
}
\newcommand{\ArgFonction}[3]{
\SetKwFunction{#1}{#1}%
\FonctionInner{\expandafter\csname#1\endcsname{#2} \ifthenelse{\equal{#3}{}}{}{$\rightarrow$ #3}}
}
\newcommand{\Procedure}[1]{
\SetKwFunction{#1}{#1}%
\ProcedureInner{\expandafter\csname#1\endcsname}
}
\newlength{\forewordlen}
\newlength{\forewordantilen}
\newenvironment{foreword}[1]{%
\settowidth{\forewordlen}{#1 : }%
\setlength{\forewordantilen}{\linewidth}%
\addtolength{\forewordantilen}{-\forewordlen}%
\begin{minipage}[t]{\forewordlen}%
#1 : %
\end{minipage}%
\begin{minipage}[t]{\forewordantilen}%
}{%
\end{minipage}%
}
\newcommand{\precond}[1]{%
\begin{foreword}{précondition}%
\itshape{%
#1%
}%
\end{foreword}%
}
\newcommand{\postcond}[1]{%
\begin{foreword}{postcondition}%
\itshape{%
#1%
}%
\end{foreword}%
}
\newcommand{\incr}[1]{#1${+}{+}$}
\newcommand{\decr}[1]{#1${-}{-}$}
\newenvironment{ucblalgo}[1][H]{%
\renewcommand{\algorithmcfname}{Algorithme}%
\IncMargin{0em}%
\DontPrintSemicolon%
\begin{algorithm}[#1]%
\SetKwBlock{Algorithme}{Algorithme}{Fin}%
}{%
\end{algorithm}%
\DecMargin{0em}%
}
\endinput
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment