Spaces:
Paused
Paused
test files
Browse files- app.py +126 -14
- load.py +121 -0
- position_buffer.txt +0 -0
app.py
CHANGED
|
@@ -9,28 +9,140 @@ if "IS_XVFB_RUNNING" not in st.session_state:
|
|
| 9 |
stpyvista.utils.start_xvfb()
|
| 10 |
st.session_state.IS_XVFB_RUNNING = True
|
| 11 |
|
| 12 |
-
st.title("
|
| 13 |
-
st.info("""Code adapted from https://docs.pyvista.org/user-guide/jupyter/pythreejs.html#scalars-support""")
|
| 14 |
|
| 15 |
import pyvista as pv
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
plotter = pv.Plotter(window_size=[400,400])
|
| 19 |
|
| 20 |
-
|
| 21 |
-
mesh = pv.Cube(center=(0,0,0))
|
| 22 |
|
| 23 |
-
|
| 24 |
-
mesh['myscalar'] = mesh.points[:, 2] * mesh.points[:, 0]
|
| 25 |
|
| 26 |
-
|
| 27 |
-
plotter.add_mesh(mesh, scalars='myscalar', cmap='bwr')
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
from stpyvista import stpyvista as spv
|
| 34 |
## Send to streamlit
|
| 35 |
-
spv(
|
| 36 |
|
|
|
|
| 9 |
stpyvista.utils.start_xvfb()
|
| 10 |
st.session_state.IS_XVFB_RUNNING = True
|
| 11 |
|
| 12 |
+
st.title("Sibernetic a example")
|
|
|
|
| 13 |
|
| 14 |
import pyvista as pv
|
| 15 |
+
import numpy as np
|
| 16 |
|
| 17 |
+
import time
|
|
|
|
| 18 |
|
| 19 |
+
points = []
|
|
|
|
| 20 |
|
| 21 |
+
types = []
|
|
|
|
| 22 |
|
| 23 |
+
file = "position_buffer.txt"
|
|
|
|
| 24 |
|
| 25 |
+
|
| 26 |
+
colours = {1.1: "lightblue", 2.1: "green", 2.2: "turquoise", 3: "#eeeeee"}
|
| 27 |
+
colours = {1.1: "blue", 2.2: "turquoise"}
|
| 28 |
+
|
| 29 |
+
line_count = 0
|
| 30 |
+
pcount = 0
|
| 31 |
+
|
| 32 |
+
all_points = []
|
| 33 |
+
all_point_types = []
|
| 34 |
+
|
| 35 |
+
time_count = 0
|
| 36 |
+
|
| 37 |
+
logStep = None
|
| 38 |
+
|
| 39 |
+
include_boundary = False
|
| 40 |
+
|
| 41 |
+
for l in open(file):
|
| 42 |
+
ws = l.split()
|
| 43 |
+
#print(ws)
|
| 44 |
+
if line_count == 6:
|
| 45 |
+
numOfElasticP = int(ws[0])
|
| 46 |
+
if line_count == 7:
|
| 47 |
+
numOfLiquidP = int(ws[0])
|
| 48 |
+
if line_count == 8:
|
| 49 |
+
numOfBoundaryP = int(ws[0])
|
| 50 |
+
if line_count == 9:
|
| 51 |
+
timeStep = float(ws[0])
|
| 52 |
+
if line_count == 10:
|
| 53 |
+
logStep = int(ws[0])
|
| 54 |
+
|
| 55 |
+
if len(ws) == 4:
|
| 56 |
+
type = float(ws[3])
|
| 57 |
+
|
| 58 |
+
if not (type == 3 and not include_boundary):
|
| 59 |
+
points.append([float(ws[0]), float(ws[1]), float(ws[2])])
|
| 60 |
+
types.append(type)
|
| 61 |
+
|
| 62 |
+
if logStep is not None:
|
| 63 |
+
pcount+=1
|
| 64 |
+
|
| 65 |
+
if pcount==numOfBoundaryP+numOfElasticP+numOfLiquidP:
|
| 66 |
+
print('End of one batch of %i added, %i total points at line %i, time: %i'%(len(points),pcount, line_count, time_count))
|
| 67 |
+
all_points.append(points)
|
| 68 |
+
all_point_types.append(types)
|
| 69 |
+
|
| 70 |
+
points = []
|
| 71 |
+
types=[]
|
| 72 |
+
pcount = 0
|
| 73 |
+
numOfBoundaryP=0
|
| 74 |
+
|
| 75 |
+
time_count+=1
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
line_count += 1
|
| 79 |
+
|
| 80 |
+
#all_points_np = np.array(all_points)
|
| 81 |
+
|
| 82 |
+
print(f"Loaded positions with %i elastic, %i liquid and %i boundary points (%i total), %i lines"%(numOfElasticP,numOfLiquidP, numOfBoundaryP,numOfElasticP+numOfLiquidP+numOfBoundaryP, line_count))
|
| 83 |
+
|
| 84 |
+
print("Num of time points found: %i"%len(all_points))
|
| 85 |
+
|
| 86 |
+
pl = pv.Plotter(window_size=[400,400])
|
| 87 |
+
pl.set_background("pink")
|
| 88 |
+
|
| 89 |
+
last_mesh = None
|
| 90 |
+
|
| 91 |
+
def create_mesh(step):
|
| 92 |
+
'''
|
| 93 |
+
step_count = step
|
| 94 |
+
value=step_count
|
| 95 |
+
global last_mesh
|
| 96 |
+
index = int(value)
|
| 97 |
+
|
| 98 |
+
print('Changing to time point: %s (%s) '%(index,value))
|
| 99 |
+
curr_points = all_points[index]
|
| 100 |
+
curr_types = all_point_types[index]
|
| 101 |
+
if last_mesh is None:
|
| 102 |
+
|
| 103 |
+
last_mesh = pv.PolyData(curr_points)
|
| 104 |
+
last_mesh["types"] = curr_types
|
| 105 |
+
print(last_mesh)
|
| 106 |
+
|
| 107 |
+
last_actor = pl.add_mesh(
|
| 108 |
+
last_mesh,
|
| 109 |
+
render_points_as_spheres=True,
|
| 110 |
+
cmap=[c for c in colours.values()],
|
| 111 |
+
point_size=3,
|
| 112 |
+
)
|
| 113 |
+
else:
|
| 114 |
+
last_mesh.points = curr_points
|
| 115 |
+
|
| 116 |
+
#pl.render()
|
| 117 |
+
|
| 118 |
+
time.sleep(0.1)
|
| 119 |
+
'''
|
| 120 |
+
## Initialize a plotter object
|
| 121 |
+
#plotter = pv.Plotter(window_size=[400,400])
|
| 122 |
+
|
| 123 |
+
## Create a mesh with a cube
|
| 124 |
+
mesh = pv.Cube(center=(0,0,0))
|
| 125 |
+
|
| 126 |
+
## Add some scalar field associated to the mesh
|
| 127 |
+
mesh['myscalar'] = mesh.points[:, 2] * mesh.points[:, 0]
|
| 128 |
+
|
| 129 |
+
## Add mesh to the plotter
|
| 130 |
+
pl.add_mesh(mesh, scalars='myscalar', cmap='bwr')
|
| 131 |
+
|
| 132 |
+
## Final touches
|
| 133 |
+
pl.view_isometric()
|
| 134 |
+
|
| 135 |
+
return
|
| 136 |
+
|
| 137 |
+
create_mesh(0)
|
| 138 |
+
|
| 139 |
+
max_time = len(all_points)-1
|
| 140 |
+
#pl.add_slider_widget(create_mesh, rng=[0,max_time], value=max_time, title='Time point')
|
| 141 |
+
#pl.add_timer_event( max_steps=len(all_points), duration=200, callback=create_mesh)
|
| 142 |
+
|
| 143 |
+
print('Ready...')
|
| 144 |
|
| 145 |
from stpyvista import stpyvista as spv
|
| 146 |
## Send to streamlit
|
| 147 |
+
spv(pl, key="pv_cube")
|
| 148 |
|
load.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pyvista as pv
|
| 2 |
+
|
| 3 |
+
import sys
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
import time
|
| 7 |
+
|
| 8 |
+
points = []
|
| 9 |
+
|
| 10 |
+
types = []
|
| 11 |
+
|
| 12 |
+
file = "pressure_buffer.txt"
|
| 13 |
+
file = "position_buffer.txt"
|
| 14 |
+
if len(sys.argv) == 2:
|
| 15 |
+
file = sys.argv[1]
|
| 16 |
+
|
| 17 |
+
colours = {1.1: "lightblue", 2.1: "green", 2.2: "turquoise", 3: "#eeeeee"}
|
| 18 |
+
colours = {1.1: "blue", 2.2: "turquoise"}
|
| 19 |
+
|
| 20 |
+
line_count = 0
|
| 21 |
+
pcount = 0
|
| 22 |
+
|
| 23 |
+
all_points = []
|
| 24 |
+
all_point_types = []
|
| 25 |
+
|
| 26 |
+
time_count = 0
|
| 27 |
+
|
| 28 |
+
logStep = None
|
| 29 |
+
|
| 30 |
+
include_boundary = False
|
| 31 |
+
|
| 32 |
+
for l in open(file):
|
| 33 |
+
ws = l.split()
|
| 34 |
+
#print(ws)
|
| 35 |
+
if line_count == 6:
|
| 36 |
+
numOfElasticP = int(ws[0])
|
| 37 |
+
if line_count == 7:
|
| 38 |
+
numOfLiquidP = int(ws[0])
|
| 39 |
+
if line_count == 8:
|
| 40 |
+
numOfBoundaryP = int(ws[0])
|
| 41 |
+
if line_count == 9:
|
| 42 |
+
timeStep = float(ws[0])
|
| 43 |
+
if line_count == 10:
|
| 44 |
+
logStep = int(ws[0])
|
| 45 |
+
|
| 46 |
+
if len(ws) == 4:
|
| 47 |
+
type = float(ws[3])
|
| 48 |
+
|
| 49 |
+
if not (type == 3 and not include_boundary):
|
| 50 |
+
points.append([float(ws[0]), float(ws[1]), float(ws[2])])
|
| 51 |
+
types.append(type)
|
| 52 |
+
|
| 53 |
+
if logStep is not None:
|
| 54 |
+
pcount+=1
|
| 55 |
+
|
| 56 |
+
if pcount==numOfBoundaryP+numOfElasticP+numOfLiquidP:
|
| 57 |
+
print('End of one batch of %i added, %i total points at line %i, time: %i'%(len(points),pcount, line_count, time_count))
|
| 58 |
+
all_points.append(points)
|
| 59 |
+
all_point_types.append(types)
|
| 60 |
+
|
| 61 |
+
points = []
|
| 62 |
+
types=[]
|
| 63 |
+
pcount = 0
|
| 64 |
+
numOfBoundaryP=0
|
| 65 |
+
|
| 66 |
+
time_count+=1
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
line_count += 1
|
| 70 |
+
|
| 71 |
+
#all_points_np = np.array(all_points)
|
| 72 |
+
|
| 73 |
+
print(f"Loaded positions with %i elastic, %i liquid and %i boundary points (%i total), %i lines"%(numOfElasticP,numOfLiquidP, numOfBoundaryP,numOfElasticP+numOfLiquidP+numOfBoundaryP, line_count))
|
| 74 |
+
|
| 75 |
+
print("Num of time points found: %i"%len(all_points))
|
| 76 |
+
|
| 77 |
+
pl = pv.Plotter()
|
| 78 |
+
pl.set_background("lightgrey")
|
| 79 |
+
|
| 80 |
+
last_mesh = None
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def create_mesh(step):
|
| 84 |
+
step_count = step
|
| 85 |
+
value=step_count
|
| 86 |
+
global last_mesh
|
| 87 |
+
index = int(value)
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
print('Changing to time point: %s (%s) '%(index,value))
|
| 91 |
+
curr_points = all_points[index]
|
| 92 |
+
curr_types = all_point_types[index]
|
| 93 |
+
if last_mesh is None:
|
| 94 |
+
|
| 95 |
+
last_mesh = pv.PolyData(curr_points)
|
| 96 |
+
last_mesh["types"] = curr_types
|
| 97 |
+
print(last_mesh)
|
| 98 |
+
|
| 99 |
+
last_actor = pl.add_mesh(
|
| 100 |
+
last_mesh,
|
| 101 |
+
render_points_as_spheres=True,
|
| 102 |
+
cmap=[c for c in colours.values()],
|
| 103 |
+
point_size=3,
|
| 104 |
+
)
|
| 105 |
+
else:
|
| 106 |
+
last_mesh.points = curr_points
|
| 107 |
+
|
| 108 |
+
pl.render()
|
| 109 |
+
|
| 110 |
+
time.sleep(0.1)
|
| 111 |
+
|
| 112 |
+
return
|
| 113 |
+
|
| 114 |
+
create_mesh(0)
|
| 115 |
+
|
| 116 |
+
max_time = len(all_points)-1
|
| 117 |
+
pl.add_slider_widget(create_mesh, rng=[0,max_time], value=max_time, title='Time point')
|
| 118 |
+
pl.add_timer_event( max_steps=len(all_points), duration=200, callback=create_mesh)
|
| 119 |
+
|
| 120 |
+
pl.show()
|
| 121 |
+
|
position_buffer.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|