File size: 1,895 Bytes
a577b73
 
 
 
 
806f947
2eea8e7
 
a577b73
91fb569
 
806f947
a577b73
 
 
806f947
 
 
 
a577b73
4274c54
b39fc9a
a577b73
b39fc9a
2eea8e7
a577b73
 
806f947
efaebf1
2eea8e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
beebf2b
 
91fb569
4274c54
 
fb4f232
8150c29
4274c54
 
 
fb4f232
4274c54
 
a577b73
 
4274c54
 
 
 
a577b73
4274c54
a577b73
4274c54
 
a577b73
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import streamlit as st
import pyvista as pv
from dcgan import DCGAN3D_G
import torch
import requests
import time
import numpy as np
import streamlit.components.v1 as components

st.title("Generating Porous Media with GANs")

url = "https://github.com/LukasMosser/PorousMediaGan/blob/master/checkpoints/berea/berea_generator_epoch_24.pth?raw=true"

# If repo is private - we need to add a token in header:
resp = requests.get(url)

with open('berea_generator_epoch_24.pth', 'wb') as f:
    f.write(resp.content)

pv.set_plot_theme("document")


netG = DCGAN3D_G(64, 512, 1, 32, 1)
netG.load_state_dict(torch.load("berea_generator_epoch_24.pth", map_location=torch.device('cpu')))
z = torch.randn(1, 512, 1, 1, 1)
with torch.no_grad():
    X = netG(z)

img = 1-(X[0, 0].numpy()+1)/2

a = 0.9

# create a uniform grid to sample the function with
x_min, y_min, z_min = 0, 0, 0
grid = pv.UniformGrid(
    dims=img.shape,
    spacing=(1, 1, 1),
    origin=(x_min, y_min, z_min),
)
x, y, z = grid.points.T

# sample and plot
values = img.flatten()
grid.point_data['my_array'] = values
slices = grid.slice_orthogonal()
mesh = grid.contour(1, values, method='marching_cubes', rng=[1, 0], preference="points")
dist = np.linalg.norm(mesh.points, axis=1)

pl = pv.Plotter(shape=(1, 1),
                     window_size=(400, 400))
_ = pl.add_mesh(slices, cmap="gray")
pl.export_html('slices.html')

pl = pv.Plotter(shape=(1, 1),
                     window_size=(400, 400))
_ = pl.add_mesh(mesh, scalars=dist)
pl.export_html('mesh.html')


st.header("test html import")
view_width = 400
view_height = 400

HtmlFile = open("slices.html", 'r', encoding='utf-8')
source_code = HtmlFile.read()
components.html(source_code, width=view_width, height=view_height)

HtmlFile = open("mesh.html", 'r', encoding='utf-8')
source_code = HtmlFile.read()
components.html(source_code, width=view_width, height=view_height)