11import pyvista as pv
2-
32import sys
43
54last_mesh = None
1211
1312plotter = None
1413
14+ spacing_ = 50
1515
16- def add_sibernetic_model (pl ):
17- points = []
1816
17+ def add_sibernetic_model (pl , swap_y_z = False , spacing = 50 ):
18+ global all_points , all_point_types , last_mesh , plotter , spacing_
19+ spacing_ = spacing
20+ plotter = pl
21+
22+ points = []
1923 types = []
2024
2125 file = "pressure_buffer.txt"
2226 file = "position_buffer.txt"
2327
2428 line_count = 0
2529 pcount = 0
26-
27- global all_points , all_point_types , last_mesh , plotter
28- plotter = pl
29-
3030 time_count = 0
31-
3231 logStep = None
3332
3433 include_boundary = False
@@ -51,7 +50,10 @@ def add_sibernetic_model(pl):
5150 type = float (ws [3 ])
5251
5352 if not (type == 3 and not include_boundary ):
54- points .append ([float (ws [0 ]), float (ws [1 ]), float (ws [2 ])])
53+ if swap_y_z :
54+ points .append ([float (ws [1 ]), 1 * float (ws [0 ]), float (ws [2 ])])
55+ else :
56+ points .append ([float (ws [0 ]), float (ws [1 ]), float (ws [2 ])])
5557 types .append (type )
5658
5759 if logStep is not None :
@@ -91,10 +93,10 @@ def add_sibernetic_model(pl):
9193
9294 create_mesh (0 )
9395
96+ plotter .remove_scalar_bar ("types" )
97+
9498 max_time = len (all_points ) - 1
95- pl .add_slider_widget (
96- create_mesh , rng = [0 , max_time ], value = max_time , title = "Time point"
97- )
99+ pl .add_slider_widget (create_mesh , rng = [0 , max_time ], value = 0 , title = "Time point" )
98100 pl .add_timer_event (max_steps = 5 , duration = 2 , callback = create_mesh )
99101
100102
@@ -103,13 +105,14 @@ def create_mesh(step):
103105
104106 step_count = step
105107 value = step_count
106- global all_points , all_point_types , last_mesh , plotter
108+ global all_points , all_point_types , last_mesh , plotter , spacing_
107109
108110 index = int (value )
109111
110112 print ("Changing to time point: %s (%s) " % (index , value ))
111113 curr_points = all_points [index ]
112114 curr_types = all_point_types [index ]
115+
113116 if last_mesh is None :
114117 last_mesh = pv .PolyData (curr_points )
115118 last_mesh ["types" ] = curr_types
@@ -125,7 +128,7 @@ def create_mesh(step):
125128 )
126129 else :
127130 last_mesh .points = curr_points
128- last_mesh .translate ((0 , - 00 , - 100 ), inplace = True )
131+ last_mesh .translate ((spacing_ , - 50 , - 100 ), inplace = True )
129132
130133 plotter .render ()
131134
@@ -134,44 +137,13 @@ def create_mesh(step):
134137 return
135138
136139
137- '''
138- mesh = pv.read("bwm.obj")
139- mesh.scale(20, inplace=True)
140- mesh.translate((-40, 0, 0), inplace=True)
141-
142- pl.add_mesh(mesh, smooth_shading=True, color="green")
143-
144- mesh2 = pv.read("neurons.obj")
145- mesh2.scale(20, inplace=True)
146- mesh2.translate((-80, 0, 0), inplace=True)
147-
148- pl.add_mesh(mesh2, smooth_shading=True, color="orange")
149- """
150- conn = mesh2.connectivity('all')
151- print(conn)
152- # Format scalar bar text for integer values.
153- scalar_bar_args = dict(
154- fmt='%.f',
155- )
156-
157- cpos = [(10.5, 12.2, 18.3), (0.0, 0.0, 0.0), (0.0, 1.0, 0.0)]
158-
159- conn.plot(
160- categories=True,
161- cmap='jet',
162- scalar_bar_args=scalar_bar_args,
163- cpos=cpos,
164- )"""
165-
166- '''
167-
168-
169140if __name__ == "__main__" :
170141 plotter = pv .Plotter ()
171142
172- add_sibernetic_model (plotter )
143+ add_sibernetic_model (plotter , swap_y_z = True )
173144 plotter .set_background ("lightgrey" )
174145 plotter .add_axes ()
146+ # plotter.set_viewup([0, 0, 10])
175147
176148 if "-nogui" not in sys .argv :
177149 plotter .show ()
0 commit comments