Skip to content

Commit

Permalink
chore: update plotter settings for off-screen rendering and high-reso…
Browse files Browse the repository at this point in the history
…lution output
  • Loading branch information
liblaf committed May 27, 2024
1 parent 0545054 commit 81a7592
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/mkit/physics/mtm.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def force(self, disp: npt.ArrayLike) -> npt.NDArray[np.floating]:

def stiffness_sparse_matrix(self) -> scipy.sparse.coo_array:
builder = ti.linalg.SparseMatrixBuilder(
self.n_verts * 3, self.n_verts * 3, int(1e6)
self.n_verts * 3, self.n_verts * 3, int(1e7)
)
self._stiffness_matrix(builder)
K_ti: ti.linalg.SparseMatrix = builder.build()
Expand Down
34 changes: 26 additions & 8 deletions tasks/00-register/plot/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,47 @@
import pyvista as pv
from pyvista.plotting.plotter import Plotter
from pyvista.plotting.themes import DocumentProTheme
from vtkmodules.vtkRenderingAnnotation import vtkLegendBoxActor
from vtkmodules.vtkRenderingCore import vtkTextProperty

DATA_DIR = pathlib.Path("/home/liblaf/Documents/data/target/120056/pre")
TEMPLATE_DIR = pathlib.Path("/home/liblaf/Documents/data/template")

pl = Plotter(window_size=(600, 800), theme=DocumentProTheme())
pl = Plotter(
off_screen=True,
window_size=(2880, 3840),
theme=DocumentProTheme(),
)
pl.add_axes()

target: pv.PolyData = pv.read(DATA_DIR / "02-face.ply")
template: pv.PolyData = pv.read(DATA_DIR / "03-face.vtu")
pl.add_mesh(target, label="Target Face", opacity=0.3)
pl.add_mesh(template, label="Template Face", opacity=0.3)
pl.add_mesh(target, label="目标面部", opacity=0.3)
pl.add_mesh(template, label="模板面部", opacity=0.3)
pl.view_vector([1.0, 0.0, 0.0], viewup=[0.0, 0.0, -1.0])
pl.zoom_camera(1.6)
pl.add_legend(size=(0.5, 0.2), loc="upper center")
legend: vtkLegendBoxActor = pl.add_legend(size=(0.5, 0.2), loc="upper center")
text: vtkTextProperty = legend.GetEntryTextProperty()
text.SetFontFamily(4)
text.SetFontFile("/usr/share/fonts/noto-cjk/NotoSansCJK-Light.ttc")
# legend.SetEntryTextProperty(text)
# pl.render()
pl.save_graphic("align-face.pdf")
pl.save_graphic("align-face.svg")
pl.screenshot("align-face.png")
pl.clear_actors()

pl.set_color_cycler("default")
target: pv.PolyData = pv.read(DATA_DIR / "02-skull.ply")
pl.add_mesh(target, label="Target Skull", opacity=0.3)
pl.add_mesh(target, label="目标颌骨", opacity=0.3)
template: pv.PolyData = pv.read(DATA_DIR / "03-mandible.vtu")
pl.add_mesh(template, label="Template Mandible", opacity=0.3)
pl.add_mesh(template, label="模板下颌骨", opacity=0.3)
template: pv.PolyData = pv.read(DATA_DIR / "03-maxilla.vtu")
pl.add_mesh(template, label="Template Maxilla", opacity=0.3)
pl.add_legend(size=(0.5, 0.2), loc="upper center")
pl.add_mesh(template, label="模板上颌骨", opacity=0.3)
legend: vtkLegendBoxActor = pl.add_legend(size=(0.5, 0.2), loc="upper center")
text: vtkTextProperty = legend.GetEntryTextProperty()
text.SetFontFamily(4)
text.SetFontFile("/usr/share/fonts/noto-cjk/NotoSansCJK-Light.ttc")
pl.save_graphic("align-skull.pdf")
pl.save_graphic("align-skull.svg")
pl.screenshot("align-skull.png")
26 changes: 17 additions & 9 deletions tasks/00-register/plot/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import pyvista as pv
from pyvista.plotting.plotter import Plotter
from pyvista.plotting.themes import DocumentProTheme
from vtkmodules.vtkRenderingAnnotation import vtkLegendBoxActor
from vtkmodules.vtkRenderingCore import vtkTextProperty

DATA_DIR = pathlib.Path("/home/liblaf/Documents/data/target/120056/pre")
TEMPLATE_DIR = pathlib.Path("/home/liblaf/Documents/data/template")
Expand All @@ -12,20 +14,26 @@

target: pv.PolyData = pv.read(DATA_DIR / "02-face.ply")
template: pv.PolyData = pv.read(DATA_DIR / "99-face.vtu")
pl.add_mesh(target, label="Target Face", opacity=0.3)
pl.add_mesh(template, label="Result Face", opacity=0.3)
pl.add_mesh(target, label="目标面部", opacity=0.3)
pl.add_mesh(template, label="配准结果", opacity=0.3)
pl.view_vector([1.0, 0.0, 0.0], viewup=[0.0, 0.0, -1.0])
pl.zoom_camera(1.6)
pl.add_legend(size=(0.5, 0.2), loc="upper center")
pl.save_graphic("register-face.pdf")
legend: vtkLegendBoxActor = pl.add_legend(size=(0.5, 0.2), loc="upper center")
text: vtkTextProperty = legend.GetEntryTextProperty()
text.SetFontFamily(4)
text.SetFontFile("/usr/share/fonts/noto-cjk/NotoSansCJK-Light.ttc")
pl.save_graphic("register-face.svg")
pl.clear_actors()

pl.set_color_cycler("default")
target: pv.PolyData = pv.read(DATA_DIR / "02-skull.ply")
pl.add_mesh(target, label="Target Skull", opacity=0.3)
pl.add_mesh(target, label="目标颌骨", opacity=0.3)
template: pv.PolyData = pv.read(DATA_DIR / "99-mandible.vtu")
pl.add_mesh(template, label="Result Mandible", opacity=0.3)
pl.add_mesh(template, label="配准结果下颌骨", opacity=0.3)
template: pv.PolyData = pv.read(DATA_DIR / "99-maxilla.vtu")
pl.add_mesh(template, label="Result Maxilla", opacity=0.3)
pl.add_legend(size=(0.5, 0.2), loc="upper center")
pl.save_graphic("register-skull.pdf")
pl.add_mesh(template, label="配准结果上颌骨", opacity=0.3)
legend: vtkLegendBoxActor = pl.add_legend(size=(0.5, 0.2), loc="upper center")
text: vtkTextProperty = legend.GetEntryTextProperty()
text.SetFontFamily(4)
text.SetFontFile("/usr/share/fonts/noto-cjk/NotoSansCJK-Light.ttc")
pl.save_graphic("register-skull.svg")
3 changes: 2 additions & 1 deletion tasks/02-simulation/src/mtm-inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def n_free(self) -> int:
def main(
input_file: Annotated[pathlib.Path, typer.Argument(exists=True, dir_okay=False)],
*,
poisson_ratio: Annotated[float, typer.Option()] = 0.46,
poisson_ratio: Annotated[float, typer.Option()] = 0.01,
) -> None:
ti.init(ti.cpu, default_fp=ti.float64, debug=True)
mesh: meshio.Mesh = mkit.io.load_meshio(input_file)
Expand All @@ -69,6 +69,7 @@ def main(
free_mask: npt.NDArray[np.bool_] = np.repeat(model.free_mask, 3)
stiffness = stiffness[free_mask][:, free_mask]
ic(np.linalg.cond(stiffness))
print(poisson_ratio, np.linalg.cond(stiffness), sep=",")


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion tasks/03-eval/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DATA_DIR ?= $(HOME)/Documents/data
TARGET_ID ?= 117412
TARGET_ID ?= 120056
export DATA_DIR
export TARGET_ID

Expand Down
51 changes: 51 additions & 0 deletions tasks/03-eval/data/cond.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
nu,cond
0.00,6.3216632112124
0.01,6.425992097565894
0.02,6.536583509940744
0.03,6.653991008986903
0.04,6.7788815904816095
0.05,6.911926247768419
0.06,7.054012417855549
0.07,7.205995589659337
0.08,7.369009434500302
0.09,7.544270358474558
0.10,7.733122270924384
0.11,7.937246362846694
0.12,8.158617156783983
0.13,8.399324971054927
0.14,8.662023352223873
0.15,8.94995579255462
0.16,9.266778190678961
0.17,9.617087022211244
0.18,10.006358607119566
0.19,10.441505284968741
0.20,10.930866313310464
0.21,11.48520225627498
0.22,12.118299733405518
0.23,12.848061127468158
0.24,13.698155536667251
0.25,14.700664785846378
0.26,15.900497076142639
0.27,17.361214454432965
0.28,19.177840088004288
0.29,21.497719207337607
0.30,24.56098929293268
0.31,28.790231187652594
0.32,35.00342622929775
0.33,45.011194795853136
0.34,63.78844975910162
0.35,111.71071604776593
0.36,486.89897529114353
0.37,1173.055330029466
0.38,329.11342089331515
0.39,108.38521611031145
0.40,66.30942337933283
0.41,50.54704097490089
0.42,90.6608314669174
0.43,913.7044933275236
0.44,238.70778498695006
0.45,16756.052460450795
0.46,445.0688078835202
0.47,1173.4515413664415
0.48,1033.0825022180727
0.49,1180.0497537036363
48 changes: 48 additions & 0 deletions tasks/03-eval/data/poisson-ratio.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
nu,mean,std,50%,90%,95%,99%,2mm,max,Acond
0.00,0.6436854944406247,0.508211514275162,0.5143301651452407,1.3370014676800135,1.6562352607449118,2.3856813186703696,97.17798594847775,2.964648973890964,3.7232e+01
0.01,0.6425192296882204,0.5072221223054793,0.5133229118201252,1.334911193899578,1.6549733531778785,2.3804235679136463,97.20140515222484,2.9647040056459804,3.8539e+01
0.02,0.6417020508384645,0.5059991730617928,0.5131156767870105,1.3342556624245328,1.6549871776039193,2.372087496171505,97.28337236533959,2.9641486509349364,3.5464e+01
0.03,0.6406087573245044,0.5049140049512655,0.5122620582678784,1.3335104647408678,1.6521015896447466,2.363165054665815,97.29508196721312,2.9638158734508777,3.5637e+01
0.04,0.6400059125442199,0.503529342097124,0.5116878715512917,1.331013605441007,1.6453670090682202,2.3506383152581427,97.33021077283374,2.96255635244046,3.8166e+01
0.05,0.6387471336104931,0.5024972014548974,0.5100829046783557,1.3292563472207706,1.6426809039725765,2.3432977318630943,97.34192037470727,2.962080732947801,3.6228e+01
0.06,0.6380526944300415,0.5011348982695332,0.5098212544377858,1.3281777834448956,1.6417092183934994,2.3341678243065855,97.41217798594849,2.960467200945664,3.7570e+01
0.07,0.6371055169000541,0.4998883430449226,0.5096740438966975,1.328276379387855,1.640691237805295,2.323944690095794,97.45901639344262,2.958966996475687,3.6433e+01
0.08,0.6359396640044177,0.49873761536663225,0.5093077404339731,1.3259614492974252,1.6368394531754147,2.312227472222196,97.51756440281031,2.957523081645553,3.6907e+01
0.09,0.6350499727154633,0.4974092046074097,0.5088457576185332,1.324452889702656,1.636861774602664,2.302326447107868,97.58782201405153,2.9552551282952533,3.7159e+01
0.10,0.6336232975628493,0.4963388562524495,0.5078224528870998,1.32293641016397,1.6344098094319388,2.2938586371853407,97.63466042154568,2.9534863048211486,3.7897e+01
0.11,0.6328871251379288,0.4948986936893204,0.5072726266968172,1.3220048916240252,1.6298731176883654,2.283968071884734,97.66978922716628,2.950104554809719,3.6044e+01
0.12,0.6319417114639978,0.4935389011957286,0.5066836654756367,1.3219893540446148,1.6288930441404024,2.2765695811529425,97.75175644028104,2.946556137391195,3.9119e+01
0.13,0.6307032721182066,0.4923146597913789,0.5059721392785546,1.3214274184069739,1.6254671022346907,2.2706564911948015,97.78688524590164,2.9429117389567825,3.4510e+01
0.14,0.6291140606352214,0.49122182536604647,0.5045645943492305,1.316833190029764,1.6187740641482138,2.265076743193898,97.88056206088994,2.9391193958627224,3.1368e+01
0.15,0.628029694313524,0.4898731765802,0.5032201643114704,1.3164806689994315,1.6151437418294903,2.2575759416735,97.92740046838408,2.933732162177898,3.7691e+01
0.16,0.6269032693696117,0.4885303958618954,0.5019103812370003,1.3165186340537345,1.614251658624402,2.246413562711069,97.9625292740047,2.9274891089290453,3.6289e+01
0.17,0.6257608850879047,0.48718374820645943,0.5015277780052758,1.3156990458908027,1.6134377670684046,2.229561375326008,97.97423887587823,2.9201973301625705,3.8606e+01
0.18,0.6243383244961367,0.48594507899915607,0.4999516410814028,1.3145126814920296,1.6078600350945689,2.2159348996747137,98.00936768149883,2.905503419423471,3.6173e+01
0.19,0.6229589402970617,0.48467685684759176,0.49897181839630067,1.3140136660591566,1.6035198662178007,2.211654134256098,98.02107728337238,2.8775667420624815,3.6633e+01
0.20,0.6216216832141159,0.4834038829887474,0.49748969404613996,1.3130582352198874,1.5995976821102393,2.202273391591223,98.06791569086651,2.847149040489746,3.7089e+01
0.21,0.6196793589377662,0.48232320587498395,0.4942325118951646,1.3112711582941745,1.59615228200651,2.1933161473636202,98.0913348946136,2.815935289211311,3.9145e+01
0.22,0.6182801217040707,0.4811077799622207,0.49294592913412716,1.3081767549930328,1.594729292034007,2.186889874275234,98.13817330210773,2.779920105682111,3.7102e+01
0.23,0.616395359539496,0.48002685360983693,0.49132074792056424,1.3056235841695414,1.5909562941442896,2.174188825572754,98.19672131147541,2.742095148886994,3.7875e+01
0.24,0.6144882255747562,0.47896485670167854,0.4882527345531119,1.306683200692286,1.591722717478634,2.1617022415318115,98.23185011709603,2.74760562502443,3.8145e+01
0.25,0.6130620293122008,0.4779134643848884,0.48608295601361645,1.3071372274618978,1.5857794306410966,2.1338233111405502,98.33723653395785,2.755221792306614,3.9462e+01
0.26,0.6107974998994434,0.4770882988972844,0.48397926222155796,1.3058638238351536,1.5849625495206883,2.1208621526500924,98.4192037470726,2.7630602158647917,4.0864e+01
0.27,0.6085847945206262,0.47643682181461067,0.4817113607508198,1.3040670207941512,1.5799688352199603,2.0935324145262646,98.48946135831382,2.774012469297665,4.1044e+01
0.28,0.6056241890666662,0.4760337026037962,0.4780667280813017,1.3011754989645432,1.5734648255668975,2.075366621307315,98.53629976580797,2.7891600963862655,4.1919e+01
0.29,0.6027459803600431,0.47592909356414886,0.4746249212070599,1.3001069628193591,1.5666741730263045,2.0628396993010965,98.53629976580797,2.810226732296211,4.2724e+01
0.30,0.5972980517265462,0.4758877408362762,0.4680538806869471,1.2900974284439213,1.570463315582105,2.090667468720454,98.44262295081968,2.8461063530547177,4.3442e+01
0.31,0.602624711800535,0.47984766764525205,0.4734759631477259,1.3057545066244154,1.5767821153575858,2.117025649118628,98.32552693208432,2.8932390440054623,4.4058e+01
0.32,0.6018427786187228,0.4838653137466017,0.4712897704233062,1.3053145393916639,1.56358367566278,2.171073597077213,98.20843091334895,2.9551145825807006,4.4554e+01
0.33,0.6042746884631574,0.4941413574976656,0.4695118866678002,1.3041074675334878,1.5754890854077703,2.2449344175330532,97.74004683840751,3.022677838790262,4.4912e+01
0.34,0.6103855961057112,0.5153554386931599,0.4675369711211894,1.3115180217767297,1.6102797012278425,2.403126636726336,97.21311475409837,3.4889949767913238,4.5115e+01
0.35,0.6316175275555828,0.5517676511780409,0.47172890457594263,1.360923927448038,1.6983795909758477,2.5982871790480573,96.60421545667448,4.218038393028542,4.5143e+01
0.36,0.6485992670987134,0.5763403291228087,0.4827247220023939,1.3858452281371398,1.7205406442031776,2.7629697837291163,96.29976580796253,5.132279644038273,4.4979e+01
0.37,0.7275060903534227,0.7192597641967652,0.5093183000847857,1.5273123128085746,2.156192457887878,3.6280452001615524,94.25058548009369,7.22054594921821,4.4603e+01
0.38,0.8587846698629444,0.9487642275220576,0.5595124875742967,1.8328660900279894,2.811192951155063,4.73938376202156,91.10070257611243,8.85002466415335,4.3999e+01
0.39,0.9163322496927252,1.1561986671796836,0.5331476720281825,2.078954462441546,3.276599994145661,5.850787609032701,89.47306791569088,11.095714607298383,4.3153e+01
0.40,1.0064287722485084,1.3124994183206873,0.5827131536914274,2.297846357706188,3.570401834415907,6.659170572669691,88.37236533957847,13.647526402765415,4.3847e+01
0.41,1.0289822677910443,1.316109946464314,0.625840331229708,2.243063930319991,3.5268398927994165,6.590908698713706,88.11475409836066,15.707958431218472,4.3869e+01
0.42,1.090555797388937,1.443613796730073,0.6427055056165487,2.5810007266690946,3.839781909750283,7.270436553224068,86.97892271662764,16.20036833449145,4.4665e+01
0.43,1.2183316498814967,1.5557783673886707,0.6853741531740467,3.0890556003913416,4.441663670158224,7.479709823734423,83.58313817330212,14.842204253742333,4.4656e+01
0.44,1.2598922604062681,1.6389171591360208,0.7047160013134127,3.1895872483648398,4.619434533094917,8.014194078211913,83.24355971896956,16.625172888370745,4.4686e+01
0.45,1.2746480395277013,1.868450471423506,0.6801870312572966,3.0574946531309695,4.56745651027739,9.308980277826091,83.77049180327869,25.44521859813193,4.5663e+01
0.46,1.3507084026101197,1.9190740049021635,0.7506665031475351,3.278187764352422,4.830121522054622,9.367187330365441,82.0608899297424,28.484339055781746,4.6349e+01
36 changes: 36 additions & 0 deletions tasks/03-eval/plot/poisson-ratio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import matplotlib.pyplot as plt
import pandas as pd


def main() -> None:
df: pd.DataFrame = pd.read_csv("data/poisson-ratio.csv")
df = df[df["nu"] < 0.39]
plt.figure()
plt.plot(df["nu"], df["mean"])
plt.xlabel("Poisson's ratio")
plt.ylabel("Mean Error (mm)")
plt.savefig("img/mean.pdf")

plt.figure()
plt.plot(df["nu"], df["95%"])
plt.xlabel("Poisson's ratio")
plt.ylabel("95% Error (mm)")
plt.savefig("img/95.pdf")

plt.figure()
plt.plot(df["nu"], df["max"])
plt.xlabel("Poisson's ratio")
plt.ylabel("Max Error (mm)")
plt.savefig("img/max.pdf")

df: pd.DataFrame = pd.read_csv("data/cond.csv")
df = df[df["nu"] < 0.38]
plt.figure()
plt.plot(df["nu"], df["cond"])
plt.xlabel("Poisson's ratio")
plt.ylabel("cond(K11)")
plt.savefig("img/cond.pdf")


if __name__ == "__main__":
main()

0 comments on commit 81a7592

Please sign in to comment.