6
6
from dash .dependencies import Input , Output , State
7
7
8
8
import random
9
+ import json
9
10
import numpy as np
10
11
import pyvista as pv
11
12
from pyvista import examples
@@ -44,6 +45,7 @@ def updateWarp(factor=1):
44
45
45
46
vtk_view = dash_vtk .View (
46
47
id = "vtk-view" ,
48
+ pickingModes = ["hover" ],
47
49
children = [
48
50
dash_vtk .GeometryRepresentation (
49
51
id = "vtk-representation" ,
@@ -68,8 +70,19 @@ def updateWarp(factor=1):
68
70
],
69
71
colorMapPreset = "erdc_blue2green_muted" ,
70
72
colorDataRange = color_range ,
71
- property = {"edgeVisibility" : True ,},
72
- )
73
+ property = {"edgeVisibility" : True },
74
+ showCubeAxes = True ,
75
+ cubeAxesStyle = {"axisLabels" : ["" , "" , "Altitude" ]},
76
+ ),
77
+ dash_vtk .GeometryRepresentation (
78
+ id = "pick-rep" ,
79
+ actor = {"visibility" : False },
80
+ children = [
81
+ dash_vtk .Algorithm (
82
+ id = "pick-sphere" , vtkClass = "vtkSphereSource" , state = {"radius" : 100 },
83
+ )
84
+ ],
85
+ ),
73
86
],
74
87
)
75
88
@@ -96,31 +109,86 @@ def updateWarp(factor=1):
96
109
value = "erdc_rainbow_bright" ,
97
110
),
98
111
),
112
+ dbc .Col (
113
+ children = dcc .Checklist (
114
+ id = "toggle-cube-axes" ,
115
+ options = [{"label" : " Show axis grid" , "value" : "grid" },],
116
+ value = [],
117
+ labelStyle = {"display" : "inline-block" },
118
+ ),
119
+ ),
99
120
],
100
121
style = {"height" : "12%" , "align-items" : "center" },
101
122
),
102
123
html .Div (
103
124
html .Div (vtk_view , style = {"height" : "100%" , "width" : "100%" }),
104
125
style = {"height" : "88%" },
105
126
),
127
+ html .Pre (
128
+ id = "tooltip" ,
129
+ style = {
130
+ "position" : "absolute" ,
131
+ "bottom" : "25px" ,
132
+ "left" : "25px" ,
133
+ "zIndex" : 1 ,
134
+ "color" : "white" ,
135
+ },
136
+ ),
106
137
],
107
138
)
108
139
109
140
110
141
@app .callback (
111
142
[
143
+ Output ("vtk-representation" , "showCubeAxes" ),
112
144
Output ("vtk-representation" , "colorMapPreset" ),
113
145
Output ("vtk-representation" , "colorDataRange" ),
114
146
Output ("vtk-polydata" , "points" ),
115
147
Output ("vtk-polydata" , "polys" ),
116
148
Output ("vtk-array" , "values" ),
117
149
Output ("vtk-view" , "triggerResetCamera" ),
118
150
],
119
- [Input ("dropdown-preset" , "value" ), Input ("scale-factor" , "value" )],
151
+ [
152
+ Input ("dropdown-preset" , "value" ),
153
+ Input ("scale-factor" , "value" ),
154
+ Input ("toggle-cube-axes" , "value" ),
155
+ ],
120
156
)
121
- def updatePresetName (name , scale_factor ):
157
+ def updatePresetName (name , scale_factor , cubeAxes ):
122
158
points , polys , elevation , color_range = updateWarp (scale_factor )
123
- return [name , color_range , points , polys , elevation , random .random ()]
159
+ return [
160
+ "grid" in cubeAxes ,
161
+ name ,
162
+ color_range ,
163
+ points ,
164
+ polys ,
165
+ elevation ,
166
+ random .random (),
167
+ ]
168
+
169
+
170
+ @app .callback (
171
+ [
172
+ Output ("tooltip" , "children" ),
173
+ Output ("pick-sphere" , "state" ),
174
+ Output ("pick-rep" , "actor" ),
175
+ ],
176
+ [Input ("vtk-view" , "clickInfo" ), Input ("vtk-view" , "hoverInfo" ),],
177
+ )
178
+ def onInfo (clickData , hoverData ):
179
+ info = hoverData if hoverData else clickData
180
+ if info :
181
+ if (
182
+ "representationId" in info
183
+ and info ["representationId" ] == "vtk-representation"
184
+ ):
185
+ return (
186
+ [json .dumps (info , indent = 2 )],
187
+ {"center" : info ["worldPosition" ]},
188
+ {"visibility" : True },
189
+ )
190
+ return dash .no_update , dash .no_update , dash .no_update
191
+ return ["" ], {}, {"visibility" : False }
124
192
125
193
126
194
if __name__ == "__main__" :
0 commit comments