Skip to content

Commit 65a335a

Browse files
committed
tests cells
1 parent 5aa1435 commit 65a335a

File tree

4 files changed

+724
-616
lines changed

4 files changed

+724
-616
lines changed

src/opengeodeweb_viewer/rpc/mesh/mesh_protocols.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def displayScalarRange(self, data_id: str, minimum: float, maximum: float) -> No
141141
def setupColorMap(
142142
self, data_id: str, points: list[float], minimum: float, maximum: float
143143
) -> None:
144-
data = self.get_object(data_id)
144+
data = self.get_vtk_pipeline(data_id)
145145
lut = vtkColorTransferFunction()
146146
data.mapper.SetLookupTable(lut)
147147

Lines changed: 361 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,361 @@
1+
# Standard library imports
2+
from typing import Callable
3+
4+
# Third party imports
5+
from opengeodeweb_viewer.rpc.mesh.mesh_protocols import VtkMeshView
6+
from opengeodeweb_viewer.rpc.mesh.cells.attribute.cell.cells_attribute_cell_protocols import (
7+
VtkMeshCellsAttributeCellView,
8+
)
9+
10+
# Local application imports
11+
from tests.conftest import ServerMonitor
12+
13+
# Local constants
14+
mesh_id = "123456789"
15+
16+
17+
def test_register(server: ServerMonitor, dataset_factory: Callable[..., str]) -> None:
18+
19+
dataset_factory(
20+
id=mesh_id, viewable_file="regular_grid_2d.vti", viewer_elements_type="cells"
21+
)
22+
23+
server.call(
24+
VtkMeshView.mesh_prefix + VtkMeshView.mesh_schemas_dict["register"]["rpc"],
25+
[{"id": mesh_id}],
26+
)
27+
28+
29+
def test_cells_cell_attribute(
30+
server: ServerMonitor, dataset_factory: Callable[..., str]
31+
) -> None:
32+
33+
test_register(server, dataset_factory)
34+
35+
server.call(
36+
VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_prefix
37+
+ VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_schemas_dict["name"][
38+
"rpc"
39+
],
40+
[{"id": mesh_id, "name": "RGB_data"}],
41+
)
42+
server.call(
43+
VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_prefix
44+
+ VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_schemas_dict[
45+
"scalar_range"
46+
]["rpc"],
47+
[{"id": mesh_id, "minimum": 0, "maximum": 255}],
48+
)
49+
assert server.compare_image("mesh/cells/cell_attribute.jpeg") == True
50+
51+
server.call(
52+
VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_prefix
53+
+ VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_schemas_dict[
54+
"scalar_range"
55+
]["rpc"],
56+
[{"id": mesh_id, "minimum": 0, "maximum": 10}],
57+
)
58+
assert server.compare_image("mesh/cells/cell_scalar_range.jpeg") == True
59+
60+
61+
def test_cells_cell_color_map(
62+
server: ServerMonitor, dataset_factory: Callable[..., str]
63+
) -> None:
64+
65+
test_register(server, dataset_factory)
66+
67+
# Set active attribute
68+
server.call(
69+
VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_prefix
70+
+ VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_schemas_dict["name"][
71+
"rpc"
72+
],
73+
[{"id": mesh_id, "name": "RGB_data"}],
74+
)
75+
76+
# Set color map: Blue to Red
77+
server.call(
78+
VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_prefix
79+
+ VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_schemas_dict[
80+
"color_map"
81+
]["rpc"],
82+
[
83+
{
84+
"id": mesh_id,
85+
"points": [
86+
0.0,
87+
0,
88+
0,
89+
1.0,
90+
255.0,
91+
1.0,
92+
0,
93+
0,
94+
],
95+
"minimum": 0.0,
96+
"maximum": 255.0,
97+
}
98+
],
99+
)
100+
101+
assert server.compare_image("mesh/cells/cell_color_map.jpeg") == True
102+
103+
104+
def test_cells_cell_color_map_range_update(
105+
server: ServerMonitor, dataset_factory: Callable[..., str]
106+
) -> None:
107+
108+
test_register(server, dataset_factory)
109+
110+
# Set active attribute
111+
server.call(
112+
VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_prefix
113+
+ VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_schemas_dict["name"][
114+
"rpc"
115+
],
116+
[{"id": mesh_id, "name": "RGB_data"}],
117+
)
118+
119+
# Set Blue to Red Map
120+
server.call(
121+
VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_prefix
122+
+ VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_schemas_dict[
123+
"color_map"
124+
]["rpc"],
125+
[
126+
{
127+
"id": mesh_id,
128+
"points": [
129+
0.0,
130+
0,
131+
0,
132+
1.0,
133+
255.0,
134+
1.0,
135+
0,
136+
0,
137+
],
138+
"minimum": 0.0,
139+
"maximum": 255.0,
140+
}
141+
],
142+
)
143+
144+
assert server.compare_image("mesh/cells/cell_color_map.jpeg") == True
145+
146+
# Update range via color map
147+
server.call(
148+
VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_prefix
149+
+ VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_schemas_dict[
150+
"color_map"
151+
]["rpc"],
152+
[
153+
{
154+
"id": mesh_id,
155+
"points": [
156+
100.0,
157+
0,
158+
0,
159+
1.0,
160+
150.0,
161+
1.0,
162+
0,
163+
0,
164+
],
165+
"minimum": 100.0,
166+
"maximum": 150.0,
167+
}
168+
],
169+
)
170+
171+
assert server.compare_image("mesh/cells/cell_color_map_range_update.jpeg") == True
172+
173+
174+
def test_cells_cell_color_map_red_shift(
175+
server: ServerMonitor, dataset_factory: Callable[..., str]
176+
) -> None:
177+
178+
test_register(server, dataset_factory)
179+
180+
# Set active attribute
181+
server.call(
182+
VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_prefix
183+
+ VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_schemas_dict["name"][
184+
"rpc"
185+
],
186+
[{"id": mesh_id, "name": "RGB_data"}],
187+
)
188+
189+
# Set Blue to Red Map
190+
server.call(
191+
VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_prefix
192+
+ VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_schemas_dict[
193+
"color_map"
194+
]["rpc"],
195+
[
196+
{
197+
"id": mesh_id,
198+
"points": [
199+
0.0,
200+
0,
201+
0,
202+
1.0,
203+
255.0,
204+
1.0,
205+
0,
206+
0,
207+
],
208+
"minimum": 0.0,
209+
"maximum": 255.0,
210+
}
211+
],
212+
)
213+
214+
assert server.compare_image("mesh/cells/cell_color_map.jpeg") == True
215+
216+
# Update range via color map
217+
server.call(
218+
VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_prefix
219+
+ VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_schemas_dict[
220+
"color_map"
221+
]["rpc"],
222+
[
223+
{
224+
"id": mesh_id,
225+
"points": [
226+
0.0,
227+
0,
228+
0,
229+
1.0,
230+
20.0,
231+
1.0,
232+
0,
233+
0,
234+
],
235+
"minimum": 0.0,
236+
"maximum": 20.0,
237+
}
238+
],
239+
)
240+
241+
assert server.compare_image("mesh/cells/cell_color_map_red_shift.jpeg") == True
242+
243+
244+
def test_cells_cell_color_map_rainbow(
245+
server: ServerMonitor, dataset_factory: Callable[..., str]
246+
) -> None:
247+
248+
test_register(server, dataset_factory)
249+
250+
# Set active attribute
251+
server.call(
252+
VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_prefix
253+
+ VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_schemas_dict["name"][
254+
"rpc"
255+
],
256+
[{"id": mesh_id, "name": "RGB_data"}],
257+
)
258+
259+
# Rainbow Desaturated Map
260+
server.call(
261+
VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_prefix
262+
+ VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_schemas_dict[
263+
"color_map"
264+
]["rpc"],
265+
[
266+
{
267+
"id": mesh_id,
268+
"points": [
269+
0.0,
270+
71 / 255,
271+
71 / 255,
272+
219 / 255,
273+
0.143 * 255,
274+
0,
275+
0,
276+
92 / 255,
277+
0.285 * 255,
278+
0,
279+
255 / 255,
280+
255 / 255,
281+
0.429 * 255,
282+
0,
283+
128 / 255,
284+
0,
285+
0.571 * 255,
286+
255 / 255,
287+
255 / 255,
288+
0,
289+
0.714 * 255,
290+
255 / 255,
291+
97 / 255,
292+
0,
293+
0.857 * 255,
294+
107 / 255,
295+
0,
296+
0,
297+
255.0,
298+
224 / 255,
299+
77 / 255,
300+
77 / 255,
301+
],
302+
"minimum": 0.0,
303+
"maximum": 255.0,
304+
}
305+
],
306+
)
307+
308+
assert (
309+
server.compare_image("mesh/cells/cell_color_map_rainbow_initial.jpeg") == True
310+
)
311+
312+
# Update range via color map
313+
server.call(
314+
VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_prefix
315+
+ VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_schemas_dict[
316+
"color_map"
317+
]["rpc"],
318+
[
319+
{
320+
"id": mesh_id,
321+
"points": [
322+
50.0,
323+
71 / 255,
324+
71 / 255,
325+
219 / 255,
326+
50.0 + 0.143 * 50,
327+
0,
328+
0,
329+
92 / 255,
330+
50.0 + 0.285 * 50,
331+
0,
332+
255 / 255,
333+
255 / 255,
334+
50.0 + 0.429 * 50,
335+
0,
336+
128 / 255,
337+
0,
338+
50.0 + 0.571 * 50,
339+
255 / 255,
340+
255 / 255,
341+
0,
342+
50.0 + 0.714 * 50,
343+
255 / 255,
344+
97 / 255,
345+
0,
346+
50.0 + 0.857 * 50,
347+
107 / 255,
348+
0,
349+
0,
350+
100.0,
351+
224 / 255,
352+
77 / 255,
353+
77 / 255,
354+
],
355+
"minimum": 50.0,
356+
"maximum": 100.0,
357+
}
358+
],
359+
)
360+
361+
assert server.compare_image("mesh/cells/cell_color_map_rainbow.jpeg") == True

0 commit comments

Comments
 (0)