zarquon42b / Morpho

R-package providing a toolset for (3D-based) Geometric Morphometrics
51 stars 16 forks source link

semi-lankmark sliding issue #23

Closed Ruiqi-CUB closed 3 years ago

Ruiqi-CUB commented 3 years ago

Hi Stefan,

I was trying to use slider3d to minimize bending energy of the curve/surface semilandmarks.

  1. There is an error messgae when running slider3d. I think it might because there are some issues of some specimens? Do you happen to know what is the specific issue? I checked with checkLM(DataSUR,text.lm=T,point="p") but the landmarks looks pretty good to me.

    
    > LMs_slide<-slider3d(dat.array = DataSUR, SMvector = 1:4,outlines=curlist2,surp=113:320,sur.path=".",sur.type = "ply",deselect = T)
    Points will be initially projected onto surfaces 
    ------------------------------------------- 
    
    ------------------------------------------- 
    Projection finished 
    ------------------------------------------- 
    Inital procrustes fit ...in...  0.05087185 secs 

Start sliding...


Iteration 1 .. Error in t.default(reprotmp$vb[1:3, ]) : argument is not a matrix


2. After removing the specimen 1 and 5, the command can be executed without any error messages. Although there is only two iterations. Moreover, the landmark are so messy after sliding (see the screenshots below). They are definitely not slided along the curve/surface. 

specimen 2: after and before sliding.

![image](https://user-images.githubusercontent.com/46695842/110868236-7596a400-8285-11eb-8d15-298ce6c68d4c.png)
![image](https://user-images.githubusercontent.com/46695842/110868255-7d564880-8285-11eb-9e0d-cc3885e1820f.png)

DataSUR_2_4<-DataSUR[1:320, 1:3, 2:4] LMs_slide<-slider3d(dat.array = DataSUR_2_4, SMvector = 1:4,outlines=curlist2,surp=113:320,sur.path=".",sur.type = "ply",deselect = T) Points will be initially projected onto surfaces



Projection finished


Inital procrustes fit ...in... 0.009305 secs

Start sliding...


Iteration 1 .. estimating sample mean shape...in... 0.00717783 secs

squared distance between means: 1.5800363915606e-05


Iteration 2 .. estimating sample mean shape...in... 0.007558107 secs

squared distance between means: 7.42220588217909e-06


checkLM(LMs_slide,text.lm=T,point="p") viewing # 1 (return=next | p=previous | m=mark current | s=stop viewing)

viewing # 2 (return=next | p=previous | m=mark current | s=stop viewing)

Error in xyz.coords(x, y, z, recycle = TRUE) : 'x' is a list, but does not have components 'x', 'y' and 'z'



Could you help me with this issue? I can send DataSur to you if you want to test it. Thank you so much!

Best
Ruiqi
zarquon42b commented 3 years ago

Hi, yes please send me the offending dataset and I'll have a look. A common error you might want to check is that the meshes and the landmarks are not in the same coordinate system.

Ruiqi-CUB commented 3 years ago

Thank you Stefan! I shared it with you via Google Drive. The ply files are in the directory Projection. I also attached my R script in that folder.

zarquon42b commented 3 years ago

Hi, I just had a look: you have weird singularities, loose parts and degenerate faces in your surfaces which might screw up the closest point search and the computation of the normal vector (to estimate the tangent plane, which you can't from a degenerate triangle). You can get rid of this by cleaning and smoothing the meshes. Here is a function to fix this and will write the cleaned meshes in a subfolder called "clean_meshes".

cleanMeshes <- function(x,folder="clean_meshes") {
    tmp <- vcgImport(x)
    tmp <- vcgIsolated(vcgSmooth(vcgClean(tmp,sel=0:6,iterate=T)),facenum = 10)
    dir.create(folder,showWarnings = F)
    vcgPlyWrite(tmp,paste0(folder,"/",basename(x)))    
}
mymeshes <- list.files("../Projection/",pattern=".ply",full.names = T)
lapply(mymeshes,cleanMeshes)

Afterwards, you simply need to

LMs_slide<-slider3d(dat.array = DataSUR, SMvector = 1:4,outlines=curlist2,surp=113:320,sur.path="./clean_meshes",sur.type = "ply",deselect = T)
zarquon42b commented 3 years ago

I also would urge you, to clean the atlas mesh:meshtempl1 <- vcgSmooth(vcgClean(meshtempl,sel=0:6,iterate = T))