make
./spinxform ./examples/bumpy/sphere.obj ./examples/bumpy/bumpy.tga ./examples/bumpy/testout.obj
- というような使い方をすることで、sphere.obj(頂点3次元座標がv始まりの行で、それに引き続いて頂点IDの3つ組の行がf始まりで続いているファイル)を読み込み(これは球形の三角メッシュ)、それにbumpy.tgaなるグレースケールファイルを指定することで、その値から曲がり具合を受け取って、変形した後のobjファイルを吐き出してくれる
- Macなどでは、objファイルとtgaファイルをその順序でファイル読み込みすることで、ぐりぐり動かせる3次元プロットを見せるGUIが立ち上がる
- さて、興味があるのは、この変形変換
- その結果をRでも表示できるようにしてみよう
library(Matrix)
library(onion)
library(rgl)
library(Ronlyryamada)
my.read.obj <- function(f){
tmp <- read.delim(f,header=FALSE,sep=" ")
vf <- tmp$V1
n.v <- length(which(vf=="v"))
n.f <- length(which(vf=="f"))
xyz <- as.matrix(tmp[1:n.v,2:4])
faces.v <- as.matrix(tmp[(n.v+1):(n.v+n.f),2:4])
xyz.q <- xyz[,1]*Hi+xyz[,2]*Hj+xyz[,3]*Hk
return(list(xyz=xyz,xyz.q=xyz.q,faces.v=faces.v))
}
my.mesh.tri.plot <- function(vertices,faces.v,rho.f=NULL){
if(is.null(rho.f)){
rho.cot <- my.curvature.cot(vertices,faces.v)
rho.f <- rho.cot[[3]] * Mod(Im(rho.cot[[2]]))
}
xyz <- as.matrix(vertices)[2:4,]
plot3d(t(xyz))
mesh.tri <- tmesh3d(xyz,faces.v,homogeneous=FALSE)
rho.f <- rho.cot[[3]] * Mod(Im(rho.cot[[2]]))
rho.f <- rep(rho.f,each=3)
rho.f1 <- rho.f2 <- rep(0,length(rho.f))
rho.f1[which(rho.f>0)] <- rho.f[which(rho.f>0)]
rho.f2[which(rho.f<0)] <- -rho.f[which(rho.f<0)]
red <- rep(0,length(rho.f))
green <- rep(0,length(rho.f))
if(max(rho.f1)!=0){
red <- rho.f1/max(rho.f1)
}
if(max(rho.f2)!=0){
green <- rho.f2/max(rho.f2)
}
col2 <- rgb(red,green,0.5)
shade3d(mesh.tri,col=col2)
}
f <- "reference_solution.obj"
obj <- my.read.obj(f)
my.mesh.tri.plot(obj$xyz.q,t(obj$faces.v))