Demo package EBSpatCGAL

Indications

  • Cliquer sur les titres pour les ouvrir
  • Pour des codes R cliquer sur le bouton pour copier le code afin de le coller dans RStudio

Graphe de Delaunay

Graphe de Delaunay
require(EBSpatCGAL)
del2 <- Delaunay()
insert(del2,x=runif(100),y=runif(100),m=rUnif(100,supp=c(1,2)))
##out | short=7,...,5
vertices(del2,"all")
R> require(EBSpatCGAL)
R> del2 <- Delaunay()
R> insert(del2,x=runif(100),y=runif(100),m=rUnif(100,supp=c(1,2)))
R> vertices(del2,"all")
             x           y m
1   0.11204203 0.739391953 1
2   0.03969415 0.382938783 2
3   0.39126219 0.193812428 2
4   0.23203213 0.421074094 2
5   0.71929143 0.366691000 1
6   0.99238673 0.788615259 2
...
96  0.94252140 0.262269409 1
97  0.10063119 0.289568867 1
98  0.18963108 0.255010305 2
99  0.56113406 0.651751125 1
100 0.88979642 0.154346140 2

image
# plot Delaunay par défaut
plot(del2)
image
# avec Couleurs selon Marques
plot(del2,col=m)
image
# Graphe de Voronoï avec Couleurs selon Marques
plot(del2,"vor",col=m)
image
# Création de Scène Graphique (Expérimental)
sc <- Scene(graph=del2)
sc %<<% window2d(xlab="x",ylab="y",main="User-defined plot!")
sc %<<% lines(graph) %<<% points(graph,col=m) %<<% lines(graph,"vor")
plot(sc)
image
# Réutilisation de la Scène en changeant graph
del2bis <- Delaunay()
insert(del2bis,
  x=runif(n<-20),
  y=runif(n),
  m=rUnif(n,supp=c(1,2))
)
# same scene plotted with del2bis
plot(sc,graph=del2bis)
Delaunay en 3D (Code à executer dans une session R)
require(rgl)
require(EBSpatCGAL)
del3 <- Delaunay(3)
insert(del3,
   x=runif(100),y=runif(100),
   z=runif(100),m=rUnif(100,supp=c(1,2))
)
vertices(del3,"all")
plot(del3,radius=0.01)
plot(del3,col=m,radius=0.01)
R> require(rgl)
R> require(EBSpatCGAL)
R> del3 <- Delaunay(3)
R> insert(del3,
R>    x=runif(100),y=runif(100),
R>    z=runif(100),m=rUnif(100,supp=c(1,2))
R> )
R> vertices(del3,"all")
R> plot(del3,radius=0.01)
R> plot(del3,col=m,radius=0.01)

image
# Deux graphes de Delaunay
del2 <- Delaunay();del2bis<-Delaunay()
insert(del2,x=runif(n<-20),y=runif(n))
insert(del2bis,x=runif(n,1,2),y=runif(n,1,2))
sc2 <- Scene(gr=del2,gr2=del2bis)
sc2 %<<% window2d(c(0,2),c(0,2),xlab="",ylab="")
sc2 %<<% lines(gr,col="blue") %<<% points(gr,col="blue")
sc2 %<<% lines(gr2,col="red") %<<% points(gr2,col="red");plot(sc2)
image
# Distinguer les classes de distances des arêtes
del2 <- Delaunay()
insert(del2,
    x=runif(n<-300,-350,350),
    y=runif(n,-350,350)
)
sc2g <- Scene(gr=del2) %<<% window2d(c(-350,350),c(-350,350))
sc2g %<<% lines(gr,when=40<length & length <= 80) %<<%
lines(gr,col="red",lwd=2,when= length <= 40)  %<<%
lines(gr,col="violet",lty=2,lwd=2,when=80<length) %<<%
points(gr);plot(sc2g)

Graphe de Laguerre (Regular graph)

Graphe de Laguerre
require(EBSpatCGAL)
reg2 <- Regular()
insert(reg2,x=runif(100),y=runif(100),w=runif(100))
##out | short=7,...,5
vertices(reg2)
R> require(EBSpatCGAL)
R> reg2 <- Regular()
R> insert(reg2,x=runif(100),y=runif(100),w=runif(100))
R> vertices(reg2)
             [,1]        [,2]
 [1,] 0.962736276 0.119468953
 [2,] 0.871959598 0.701895077
 [3,] 0.209989528 0.872756889
 [4,] 0.979528536 0.003618682
 [5,] 0.029740213 0.057277399
 [6,] 0.374684063 0.980861908
...
[22,] 0.701069751 0.130484080
[23,] 0.112103307 0.241883016
[24,] 0.442970233 0.252561653
[25,] 0.048738342 0.678763224
[26,] 0.677131450 0.993796061

Graphe de Laguerre
image
R> sc <- Scene()
R> sc %<<% window2d(xlab="x",ylab="y",main="Regular and dual graphs")
R> sc %<<% lines(graph) %<<% points(graph) %<<% lines(graph,"vor")
R> plot(sc,graph=reg2)

Graphe de Laguerre en 3D (Code à executer dans une session R)
require(rgl)
require(EBSpatCGAL)
reg3 <- Regular(3)
insert(reg3,
   x=runif(100),y=runif(100),
   z=runif(100),w=runif(100)
)
vertices(reg3)
(sc3 <- Scene()) %<<% window3d(windowRect=c(0,0,800,800))
sc3 %<<% lines(gr) %<<% points(gr,col="blue",radius=0.02)

plot(sc3,gr=reg3)
R> require(rgl)
R> require(EBSpatCGAL)
R> reg3 <- Regular(3)
R> insert(reg3,
R>    x=runif(100),y=runif(100),
R>    z=runif(100),w=runif(100)
R> )
R> vertices(reg3)
R> (sc3 <- Scene()) %<<% window3d(windowRect=c(0,0,800,800))
R> sc3 %<<% lines(gr) %<<% points(gr,col="blue",radius=0.02)

R> plot(sc3,gr=reg3)

Modèle de Gibbs à interaction de type Delaunay

Simulation

Simulation 2D
require(EBSpatCGAL)
# Delaunay
del2 <- Delaunay()
del2bis <- Delaunay()
# Gibbs simulation
gd2 <- SimGibbs(
  del2 ~ 2 + Del2(th[1]*(l<=20)+th[2]*(20<l & l<=80),th=c(2,4)),
  domain=Domain(c(-350,-350),c(350,350))
)
# Marked one
del2m <- Delaunay()
gd2m <- SimGibbs(
  del2m ~ 2 + Del2(th[1]*(l<=20) + th[2]*(20<l & l<=80)
        * abs(v[[1]]$m-v[[2]]$m), th=c(2,4))| m ~ Unif(supp=c(1,2))
)
R> require(EBSpatCGAL)
R> # Delaunay
R> del2 <- Delaunay()
R> del2bis <- Delaunay()
R> # Gibbs simulation
R> gd2 <- SimGibbs(
+   del2 ~ 2 + Del2(th[1]*(l<=20)+th[2]*(20<l & l<=80),th=c(2,4)),
+   domain=Domain(c(-350,-350),c(350,350))
+ )
R> # Marked one
R> del2m <- Delaunay()
R> gd2m <- SimGibbs(
+   del2m ~ 2 + Del2(th[1]*(l<=20) + th[2]*(20<l & l<=80)
+         * abs(v[[1]]$m-v[[2]]$m), th=c(2,4))| m ~ Unif(supp=c(1,2))
+ )

image
# run the simulator and plot the resulted Delaunay graph
run(gd2)
plot(del2)
image
# run the simulator and plot the resulted Delaunay graph
run(gd2)
plot(del2)