Skip to content

Commit

Permalink
brol
Browse files Browse the repository at this point in the history
  • Loading branch information
stla committed Oct 14, 2023
1 parent 44cc264 commit e6d41ac
Show file tree
Hide file tree
Showing 18 changed files with 239 additions and 10 deletions.
Binary file added inst/images/Klein01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added inst/images/KleinFibonacciMoebius_cm4.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion inst/images/TorusSigma2.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ torusMesh <- function(nu = 50, nv = 30, rgl = TRUE){
}


mesh <- Rvcg::vcgUpdateNormals(torusMesh(nu = 400, nv = 400))
mesh <- Rvcg::vcgUpdateNormals(torusMesh(nu = 256, nv = 256))

coords <- function(xyz){
x <- xyz[, 1L]
Expand Down
89 changes: 89 additions & 0 deletions inst/images/torus_wp_Sobel.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
library(jacobi)
library(RcppColors)

x <- y <- seq(-4, 0, length.out = 1024L)

f <- function(x, y) {
z <- complex(real = x, imaginary = y)
wp(z, omega = c(0.5, 0.5 + 0.5i))
}

Z <- outer(x, y, f)
img <- colorMap5(Z)

opar <- par(mar = c(0,0,0,0), bg="black")
plot(c(-100, 100), c(-100, 100), type = "n", xaxs ="i", yaxs = "i",
xlab = NA, ylab = NA, axes = FALSE, asp = 1)
rasterImage(img, -100, -100, 100, 100)
par(opar)


svg("x.svg", width = 16, height = 16)
opar <- par(mar = c(0,0,0,0), bg = "black")
plot(c(-100, 100), c(-100, 100), type = "n", xaxs ="i", yaxs = "i",
xlab = NA, ylab = NA, axes = FALSE, asp = 1)
rasterImage(img, -100, -100, 100, 100)
par(opar)
dev.off()
rsvg::rsvg_png(
"x.svg", "wp4x4_cm5.png", width = 1024, height = 1024
)

# Sobelize
library(imager)
# transform the raster to an 'imager' image
im1 <- as.cimg(
aperm(
array(
col2rgb(img) / 255,
dim = c(3, 1024, 1024)
), c(2L, 3L, 1L)
)
)
# Sobel transformation
Sobel <- function(im) {
M <- rbind(
c(-1, -2, -1),
c( 0, 0, 0),
c( 1, 2, 1)
)
imX <- convolve(im, as.cimg(M))
imY <- convolve(im, as.cimg(t(M)))
imXY <- enorm(list(imX, imY))
pmax(pmin(imXY, 1), 0)
}
# apply Sobel transformation and get the colors as hex codes
im2 <- Sobel(im1)
r <- c(squeeze(R(im2)))
g <- c(squeeze(G(im2)))
b <- c(squeeze(B(im2)))
clrs <- rgb(r, g, b)

source("C:/SL/R/imagesProcessing/savePNG.R")
savePNG(im2, "wp4x4_cm5_Sobel.png", 1024L, 1024L)


##################################################################
library(rgl)
library(cgalMeshes)
mesh1 <- torusMesh(
R = sqrt(2), r = 1, nu = 1024L, nv = 1024L, conformal = FALSE
)
mesh2 <- torusMesh(
R = sqrt(2), r = 1, nu = 1024L, nv = 1024L, conformal = TRUE
)
#clrs <- c(img)
mesh1[["material"]] <- mesh2[["material"]] <- list("color" = clrs)
# plot
open3d(windowRect = 50 + c(0, 0, 640, 320))
clear3d(type = "lights") # destroy current lights
light3d(x = -50, y = 100, z = 100)
bg3d("#363940")
mfrow3d(1, 2)
view3d(-25, -25, zoom = 0.75)
shade3d(mesh1, specular = "gold")
next3d()
view3d(-25, -25, zoom = 0.75)
shade3d(mesh2, specular = "gold")

snapshot3d("tori_square_wp_Sobel.png", webshot = FALSE)
91 changes: 91 additions & 0 deletions inst/images/torus_wp_Sobel_rectangular.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
library(jacobi)
library(RcppColors)

x <- y <- seq(-4, 0, length.out = 512L)

f <- function(x, y) {
z <- complex(real = x, imaginary = y)
wp(z, omega = c(0.5, 0.5 + 0.5i), derivative = 0L)
}

Z <- outer(x, y, f)
img <- colorMap5(Z)
img <- cbind(img, img)

opar <- par(mar = c(0,0,0,0), bg="black")
plot(c(-200, 200), c(-100, 100), type = "n", xaxs ="i", yaxs = "i",
xlab = NA, ylab = NA, axes = FALSE, asp = 1)
rasterImage(img, -200, -100, 200, 100)
par(opar)

library(imager)

im1 <- as.cimg(
aperm(
array(
col2rgb(c(img)) / 255,
dim = c(3, 512, 1024)
), c(3L, 2L, 1L)
)
)


svg("x.svg", width = 16, height = 8)
opar <- par(mar = c(0,0,0,0), bg = "black")
plot(c(-200, 200), c(-100, 100), type = "n", xaxs ="i", yaxs = "i",
xlab = NA, ylab = NA, axes = FALSE, asp = 1)
rasterImage(img, -200, -100, 200, 100)
par(opar)
dev.off()
rsvg::rsvg_png(
"x.svg", "wp8x4_cm5_Sobel.png", width = 512, height = 256
)

# Sobelize
sobel <- function(im) {
M <- rbind(
c(-1, -2, -1),
c(0, 0, 0),
c(1, 2, 1)
)
imX <- convolve(im, as.cimg(M))
imY <- convolve(im, as.cimg(t(M)))
imXY <- enorm(list(imX, imY))
pmax(pmin(imXY, 1), 0)
}

im2 <- sobel(im1)
r <- c(squeeze(R(im2)))
g <- c(squeeze(G(im2)))
b <- c(squeeze(B(im2)))
clrs <- rgb(r, g, b)
img <- as.raster(im2)

source("C:/SL/R/imagesProcessing/savePNG.R")
savePNG(im2, "wp8x4_cm5_Sobel.png", 512L, 256L)


##################################################################
library(rgl)
library(cgalMeshes)
mesh1 <- torusMesh(
R = sqrt(5), r = 1, nu = 1024L, nv = 512L, conformal = FALSE
)
mesh2 <- torusMesh(
R = sqrt(5), r = 1, nu = 1024L, nv = 512L, conformal = TRUE
)
#clrs <- c(img)
mesh1[["material"]] <- mesh2[["material"]] <- list("color" = clrs)
# plot
open3d(windowRect = 50 + c(0, 0, 640, 320))
clear3d(type = "lights") # destroy current lights
light3d(x = -50, y = 100, z = 100)
bg3d("#363940")
mfrow3d(1, 2)
view3d(-25, -25, zoom = 0.75)
shade3d(mesh1, specular = "gold")
next3d()
view3d(-25, -25, zoom = 0.75)
shade3d(mesh2, specular = "gold")

snapshot3d("tori_nonsquare_wp_Sobel.png", webshot = FALSE)
49 changes: 49 additions & 0 deletions inst/images/wp.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
library(jacobi)
library(RcppColors)

x <- seq(4, 8, len = 1024)-8
y <- seq(4, 8, len = 1024)-8

f <- function(x, y) {
z <- complex(real = x, imaginary = y)
wp(z, omega = c(0.5, 0.5+0.5i), derivative = 0L)
}

Z <- outer(x, y, f)
img <- colorMap5(Z)

opar <- par(mar = c(0,0,0,0), bg="black")
plot(c(-100, 100), c(-100, 100), type = "n", xaxs ="i", yaxs = "i",
xlab = NA, ylab = NA, axes = FALSE, asp = 1)
rasterImage(img, -100, -100, 100, 100)
par(opar)


svg("x.svg", width = 16, height = 16)
opar <- par(mar = c(0,0,0,0), bg = "black")
plot(c(-100, 100), c(-100, 100), type = "n", xaxs ="i", yaxs = "i",
xlab = NA, ylab = NA, axes = FALSE, asp = 1)
rasterImage(img, -100, -100, 100, 100)
par(opar)
dev.off()

rsvg::rsvg_png(
"x.svg", "wp4x4_cm5.png", width = 1024, height = 1024
)

##################################################################
library(rgl)
library(cgalMeshes)
mesh <- torusMesh(
R = sqrt(2), r = 1, nu = 1024, nv = 1024, conformal = FALSE, normals = FALSE
)

#clrs <- c(img)
mesh[["material"]] <- list("color" = clrs)

open3d(windowRect = 50 + c(0, 0, 512, 512))
bg3d("#363940")
view3d(-25, -25, zoom = 0.75)
clear3d(type = "lights") # destroy current lights
light3d(x = -50, y = 100, z = 100)
shade3d(mesh, specular = "forestgreen")
Binary file added inst/images/wp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added inst/images/wp2x1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added inst/images/wp2x2_cm1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added inst/images/wp2x2_cm11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added inst/images/wp4x4_cm1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added inst/images/wp4x4_cm11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added inst/images/wp4x4_cm5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added inst/images/wp4x4_cm5_Sobel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added inst/images/wp8x4_cm5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added inst/images/wp8x4_cm5_Sobel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added inst/images/wppprime.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions inst/images/wpprime02.R
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
library(jacobi)
library(RcppColors)

x <- seq(0, 1, len = 1024)
y <- seq(0, 1, len = 1024)
x <- seq(-1, 1, len = 1024)
y <- seq(-1, 1, len = 1024)

f <- function(x, y) {
z <- complex(real = x, imaginary = y)
wp(z, omega = c(1/2, 1i/2), derivative = 0L)
wp(z, g = c(189, 0), derivative = 0L)
}

Z <- outer(x, y, f)
img <- colorMap1(Z)

opar <- par(mar = c(0,0,0,0), bg="black")
plot(c(-100, 100), c(-100, 100), type = "n",
xlab = "", ylab = "", axes = FALSE, asp = 1)
plot(c(-100, 100), c(-100, 100), type = "n", xaxs ="i", yaxs = "i",
xlab = NA, ylab = NA, axes = FALSE, asp = 1)
rasterImage(img, -100, -100, 100, 100)
par(opar)


svg("x.svg", width = 12, height = 12)
svg("x.svg", width = 16, height = 8)
opar <- par(mar = c(0,0,0,0), bg = "black")
plot(
c(-100, 100), c(-100, 100), type = "n", xaxs = "i", yaxs = "i",
c(-200, 200), c(-100, 100), type = "n", xaxs = "i", yaxs = "i",
xlab = NA, ylab = NA, axes = FALSE, asp = 1
)
rasterImage(img, -100, -100, 100, 100)
rasterImage(img, -200, -100, 200, 100)
par(opar)
dev.off()

rsvg::rsvg_png("x.svg", "wp.png", width = 1024, height = 1024)
rsvg::rsvg_png("x.svg", "wp2x1.png", width = 1024, height = 512)

0 comments on commit e6d41ac

Please sign in to comment.