1+ # Standard library imports 
2+ import  json 
3+ import  os 
4+ 
5+ # Third party imports 
6+ import  vtk 
7+ from  vtk .web  import  protocols  as  vtk_protocols 
8+ from  vtkmodules .vtkIOImage  import  vtkPNGWriter , vtkJPEGWriter 
9+ from  vtkmodules .vtkRenderingCore  import  (vtkWindowToImageFilter )
10+ from  wslink  import  register  as  exportRpc 
11+ 
12+ # Local application imports 
13+ from  opengeodeweb_viewer .utils_functions  import  get_schemas_dict , validate_schema 
14+ from  opengeodeweb_viewer .object .object_methods  import  VtkObjectView 
15+ 
16+ schemas_dir  =  os .path .join (os .path .dirname (__file__ ), "schemas" )
17+ schemas_dict  =  get_schemas_dict (schemas_dir )
18+ prefix  =  "opengeodeweb_viewer.mesh." 
19+ 
20+ class  VtkMeshView (VtkObjectView ):
21+     def  __init__ (self ):
22+         super ().__init__ ()
23+         self .prefix  =  prefix 
24+         self .schemas_dict  =  schemas_dict 
25+ 
26+     @exportRpc (prefix  +  schemas_dict ["register" ]["rpc" ]) 
27+     def  registerMesh (self , params ):
28+         print (schemas_dict ["register" ]["rpc" ], params , flush = True )
29+         validate_schema (params , schemas_dict ["register" ])
30+         id  =  params ["id" ]
31+         file_name  =  params ["file_name" ]
32+         try :
33+             reader  =  vtk .vtkXMLGenericDataObjectReader ()
34+             filter  =  {}
35+             mapper  =  vtk .vtkDataSetMapper ()
36+             mapper .SetInputConnection (reader .GetOutputPort ())
37+             self .register (id , file_name , reader , filter , mapper )
38+         except  Exception  as  e :
39+             print ("error : " , str (e ), flush = True )
40+ 
41+     @exportRpc (prefix  +  schemas_dict ["deregister" ]["rpc" ]) 
42+     def  deregisterMesh (self , params ):
43+         print (schemas_dict ["deregister" ]["rpc" ], params , flush = True )
44+         validate_schema (params , schemas_dict ["deregister" ])
45+         id  =  params ["id" ]
46+         self .deregister (id )
47+ 
48+     @exportRpc (prefix  +  schemas_dict ["set_visibility" ]["rpc" ]) 
49+     def  SetMeshVisibility (self , params ):
50+         print (schemas_dict ["set_visibility" ]["rpc" ], params , flush = True )
51+         validate_schema (params , schemas_dict ["set_visibility" ])
52+         id  =  params ["id" ]
53+         visibility  =  bool (params ["visibility" ])
54+         self .SetVisibility (id , visibility )
55+ 
56+     @exportRpc (prefix  +  schemas_dict ["set_opacity" ]["rpc" ]) 
57+     def  setMeshOpacity (self , params ):
58+         print (schemas_dict ["set_opacity" ]["rpc" ], params , flush = True )
59+         validate_schema (params , schemas_dict ["set_opacity" ])
60+         id  =  params ["id" ]
61+         opacity  =  float (params ["opacity" ])
62+         self .SetOpacity (id , opacity )
63+ 
64+     @exportRpc (prefix  +  schemas_dict ["set_edge_visibility" ]["rpc" ]) 
65+     def  setMeshEdgeVisibility (self , params ):
66+         print (schemas_dict ["set_edge_visibility" ]["rpc" ], params , flush = True )
67+         validate_schema (params , schemas_dict ["set_edge_visibility" ])
68+         id  =  params ["id" ]
69+         visibility  =  bool (params ["visibility" ])
70+         self .SetEdgeVisibility (id , visibility )
71+ 
72+     @exportRpc (prefix  +  schemas_dict ["set_point_visibility" ]["rpc" ]) 
73+     def  setMeshPointVisibility (self , params ):
74+         print (schemas_dict ["set_point_visibility" ]["rpc" ], params , flush = True )
75+         validate_schema (params , schemas_dict ["set_point_visibility" ])
76+         id  =  params ["id" ]
77+         visibility  =  bool (params ["visibility" ])
78+         self .SetVertexVisibility (id , visibility )
79+ 
80+     @exportRpc (prefix  +  schemas_dict ["set_point_size" ]["rpc" ]) 
81+     def  setMeshPointSize (self , params ):
82+         print (schemas_dict ["set_point_size" ]["rpc" ], params , flush = True )
83+         validate_schema (params , schemas_dict ["set_point_size" ])
84+         id  =  params ["id" ]
85+         size  =  float (params ["size" ])
86+         self .SetPointSize (id , size )
87+ 
88+     @exportRpc (prefix  +  schemas_dict ["set_color" ]["rpc" ]) 
89+     def  setMeshColor (self , params ):
90+         print (schemas_dict ["set_color" ]["rpc" ], params , flush = True )
91+         validate_schema (params , schemas_dict ["set_color" ])
92+         id  =  params ["id" ]
93+         red  =  params ["red" ]
94+         green  =  params ["green" ]
95+         blue  =  params ["blue" ]
96+         self .SetColor (id , red , green , blue )
97+ 
98+     @exportRpc (prefix  +  schemas_dict ["display_vertex_attribute" ]["rpc" ]) 
99+     def  setVertexAttribute (self , params ):
100+         print (schemas_dict ["display_vertex_attribute" ]["rpc" ], params , flush = True )
101+         validate_schema (params , schemas_dict ["display_vertex_attribute" ])
102+         id  =  params ["id" ]
103+         name  =  params ["name" ]
104+         reader  =  self .get_object (id )["reader" ]
105+         points  =  reader .GetOutput ().GetPointData ()
106+         points .SetActiveScalars (name )
107+         mapper  =  self .get_object (id )["mapper" ]
108+         mapper .ScalarVisibilityOn ()
109+         mapper .SetScalarModeToUsePointData ()
110+         mapper .SetScalarRange (points .GetScalars ().GetRange ())
111+         self .render ()
112+ 
113+     @exportRpc (prefix  +  schemas_dict ["display_polygon_attribute" ]["rpc" ]) 
114+     def  setPolygonAttribute (self , params ):
115+         print (schemas_dict ["display_polygon_attribute" ]["rpc" ], params , flush = True )
116+         validate_schema (params , schemas_dict ["display_polygon_attribute" ])
117+         id  =  params ["id" ]
118+         name  =  params ["name" ]
119+         reader  =  self .get_object (id )["reader" ]
120+         cells  =  reader .GetOutput ().GetCellData ()
121+         cells .SetActiveScalars (name )
122+         mapper  =  self .get_object (id )["mapper" ]
123+         mapper .ScalarVisibilityOn ()
124+         mapper .SetScalarModeToUseCellData ()
125+         mapper .SetScalarRange (cells .GetScalars ().GetRange ())
126+         self .render ()
0 commit comments