Skip to content
Merged
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,3 @@ wslink==1.12.4
yarl>=1
# via aiohttp

opengeodeweb-microservice==1.*,>=1.2.0rc1
33 changes: 18 additions & 15 deletions src/opengeodeweb_viewer/rpc/mesh/mesh_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,12 @@ def displayAttributeOnVertices(
pipeline = self.get_vtk_pipeline(data_id)
pipeline.reader.GetOutputAsDataSet().GetPointData().SetActiveScalars(name)
pipeline.filter.Update()
active_ds = pipeline.mapper.GetInputDataObject(0, 0)
if active_ds:
if active_ds := pipeline.mapper.GetInputDataObject(0, 0):
active_ds.GetPointData().SetActiveScalars(name)
mapper = pipeline.mapper
mapper.ScalarVisibilityOn()
mapper.SetScalarModeToUsePointData()
mapper.SetArrayComponent(item)
self.setupColorMap(data_id, color_map, minimum, maximum)
pipeline.mapper.ScalarVisibilityOn()
pipeline.mapper.SetScalarModeToUsePointData()
pipeline.mapper.ColorByArrayComponent(name, item)
self.setupColorMap(data_id, color_map, minimum, maximum, item)

def displayAttributeOnCells(
self,
Expand All @@ -142,14 +140,12 @@ def displayAttributeOnCells(
pipeline = self.get_vtk_pipeline(data_id)
pipeline.reader.GetOutputAsDataSet().GetCellData().SetActiveScalars(name)
pipeline.filter.Update()
active_ds = pipeline.mapper.GetInputDataObject(0, 0)
if active_ds:
if active_ds := pipeline.mapper.GetInputDataObject(0, 0):
active_ds.GetCellData().SetActiveScalars(name)
mapper = pipeline.mapper
mapper.ScalarVisibilityOn()
mapper.SetScalarModeToUseCellData()
mapper.SetArrayComponent(item)
self.setupColorMap(data_id, color_map, minimum, maximum)
pipeline.mapper.ScalarVisibilityOn()
pipeline.mapper.SetScalarModeToUseCellData()
pipeline.mapper.ColorByArrayComponent(name, item)
self.setupColorMap(data_id, color_map, minimum, maximum, item)

def displayScalarRange(self, data_id: str, minimum: float, maximum: float) -> None:
print(
Expand All @@ -161,10 +157,17 @@ def displayScalarRange(self, data_id: str, minimum: float, maximum: float) -> No
data.mapper.SetUseLookupTableScalarRange(False)

def setupColorMap(
self, data_id: str, points: list[float], minimum: float, maximum: float
self,
data_id: str,
points: list[float],
minimum: float,
maximum: float,
item: int = 0,
) -> None:
data = self.get_vtk_pipeline(data_id)
lut = vtkColorTransferFunction()
lut.SetVectorModeToComponent()
lut.SetVectorComponent(item)
data.mapper.SetLookupTable(lut)

if not points:
Expand Down
48 changes: 23 additions & 25 deletions src/opengeodeweb_viewer/vtk_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,25 @@ def update_block_colors(self, block_id: int) -> None:
block.GetPointData().SetActiveScalars("")
block.GetCellData().SetActiveScalars("")
return
field_data = (
block.GetPointData()
if style["attribute_location"] == "point"
else block.GetCellData()
)
is_point = style["attribute_location"] == "point"
field_data = block.GetPointData() if is_point else block.GetCellData()
other_field_data = block.GetCellData() if is_point else block.GetPointData()

scalar_array = field_data.GetArray(style["name"])
if not scalar_array:
return

lut = vtkColorTransferFunction()
points = style["points"]
field_data.SetActiveScalars(style["name"])
other_field_data.SetActiveScalars("")

item = style.get("item", 0)
minimum = style["minimum"]
maximum = style["maximum"]
points = style["points"]
lut = vtkColorTransferFunction()
lut.SetVectorModeToComponent()
lut.SetVectorComponent(item)
lut.SetRange(minimum, maximum)
if points:
x_min, x_max = points[0], points[-4]
span = x_max - x_min
Expand All @@ -164,27 +170,19 @@ def update_block_colors(self, block_id: int) -> None:
lut.AddRGBPoint(minimum, 0, 0, 0)
lut.AddRGBPoint(maximum, 1, 1, 1)

lut.SetRange(minimum, maximum)
rgba_colors = lut.MapScalars(scalar_array, 0, style.get("item", 0))
rgba_colors.SetName(f"__colors_{style['name']}")

field_data.AddArray(rgba_colors)
field_data.SetActiveScalars(rgba_colors.GetName())

other_field_data = (
block.GetCellData()
if style["attribute_location"] == "point"
else block.GetPointData()
)
other_field_data.SetActiveScalars("")

if isinstance(self.mapper, vtkCompositePolyDataMapper):
attributes = self.mapper.GetCompositeDataDisplayAttributes()
if attributes:
if attributes := self.mapper.GetCompositeDataDisplayAttributes():
attributes.RemoveBlockColor(block)
self.mapper.ScalarVisibilityOn()
self.mapper.SetColorModeToDirectScalars()
self.mapper.SetScalarModeToDefault()
self.mapper.SetLookupTable(lut)
self.mapper.SetScalarRange(minimum, maximum)
self.mapper.SetColorModeToMapScalars()
if is_point:
self.mapper.SetScalarModeToUsePointData()
else:
self.mapper.SetScalarModeToUseCellData()
self.mapper.ColorByArrayComponent(style["name"], item)
self.mapper.InterpolateScalarsBeforeMappingOn()
self.mapper.Modified()

def sync_block_display_attributes(
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/data/images/model/blocks/updated_vertex_color_map.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/data/images/model/blocks/vertex_color_map.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/data/images/model/blocks/vertex_color_map_rainbow.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/data/images/model/corners/vertex_color_map.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/data/images/model/edges/visibility.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/data/images/model/lines/updated_vertex_color_map.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/data/images/model/lines/vertex_attribute.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/data/images/model/lines/vertex_color_map.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/data/images/model/lines/vertex_color_map_rainbow.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/data/images/model/lines/vertex_color_map_rainbow_initial.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/data/images/model/lines/vertex_color_map_red_shift.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/data/images/model/lines/visibility.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/data/images/model/points/size.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/data/images/model/points/visibility.jpeg
Binary file modified tests/data/images/model/register.jpeg
Binary file modified tests/data/images/model/surfaces/color.jpeg
Binary file modified tests/data/images/model/surfaces/updated_vertex_color_map.jpeg
Binary file modified tests/data/images/model/surfaces/vertex_color_map.jpeg
Binary file modified tests/data/images/model/surfaces/vertex_color_map_rainbow.jpeg
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,38 @@ def test_cells_cell_color_map_rainbow(
)

assert server.compare_image("mesh/cells/cell_color_map_rainbow.jpeg") == True


def test_cells_cell_attribute_item(
server: ServerMonitor, dataset_factory: Callable[..., str]
) -> None:

test_register(server, dataset_factory)

server.call(
VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_prefix
+ VtkMeshCellsAttributeCellView.mesh_cells_attribute_cell_schemas_dict[
"attribute"
]["rpc"],
[
{
"id": mesh_id,
"name": "RGB_data",
"item": 1,
"points": [
0.0,
0,
0,
1.0,
255.0,
1.0,
0,
0,
],
"minimum": 0.0,
"maximum": 255.0,
}
],
)

assert server.compare_image("mesh/cells/cell_color_map_item.jpeg") == True
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def test_cells_vertex_color_map_rainbow(
assert server.compare_image("mesh/cells/vertex_color_map_rainbow.jpeg") == True


def test_cells_vertex_vector_component(
def test_cells_vertex_attribute_item(
server: ServerMonitor, dataset_factory: Callable[..., str]
) -> None:
test_register(server, dataset_factory)
Expand Down Expand Up @@ -339,10 +339,4 @@ def test_cells_vertex_vector_component(
],
)

# Render and assert we receive non-empty image bytes (no backend crashes)
server.call("opengeodeweb_viewer.viewer.render")
while True:
response = server.ws.recv()
if isinstance(response, bytes):
assert len(response) > 0
break
assert server.compare_image("mesh/cells/vertex_attribute_item.jpeg") == True
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,38 @@ def test_edges_edge_color_map_rainbow(
)

assert server.compare_image("mesh/edges/edge_color_map_rainbow.jpeg") == True


def test_edges_edge_attribute_item(
server: ServerMonitor, dataset_factory: Callable[..., str]
) -> None:

test_register(server, dataset_factory)

server.call(
VtkMeshEdgesAttributeEdgeView.mesh_edges_attribute_edge_prefix
+ VtkMeshEdgesAttributeEdgeView.mesh_edges_attribute_edge_schemas_dict[
"attribute"
]["rpc"],
[
{
"id": mesh_id,
"name": "cycle_id",
"item": 1,
"points": [
0.0,
0,
0,
1.0,
8.0,
1.0,
0,
0,
],
"minimum": 0.0,
"maximum": 8.0,
}
],
)

assert server.compare_image("mesh/edges/edge_attribute_item.jpeg") == True
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,38 @@ def test_edges_vertex_color_map_rainbow(
)

assert server.compare_image("mesh/edges/vertex_color_map_rainbow.jpeg") == True


def test_edges_vertex_attribute_item(
server: ServerMonitor, dataset_factory: Callable[..., str]
) -> None:

test_register(server, dataset_factory)

server.call(
VtkMeshEdgesAttributeVertexView.mesh_edges_attribute_vertex_prefix
+ VtkMeshEdgesAttributeVertexView.mesh_edges_attribute_vertex_schemas_dict[
"attribute"
]["rpc"],
[
{
"id": mesh_id,
"name": "points",
"item": 1,
"points": [
0.0,
0,
0,
1.0,
50.0,
1.0,
0,
0,
],
"minimum": 0.0,
"maximum": 50.0,
}
],
)

assert server.compare_image("mesh/edges/vertex_attribute_item.jpeg") == True
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,37 @@ def test_points_vertex_color_map_rainbow(
)

assert server.compare_image("mesh/points/vertex_color_map_rainbow.jpeg") == True


def test_points_vertex_attribute_item(
server: ServerMonitor, dataset_factory: Callable[..., str]
) -> None:

test_register(server, dataset_factory)

server.call(
VtkMeshPointsAttributeVertexView.mesh_points_attribute_vertex_prefix
+ VtkMeshPointsAttributeVertexView.mesh_points_attribute_vertex_schemas_dict[
"attribute"
]["rpc"],
[
{
"id": mesh_id,
"name": "points",
"item": 1,
"points": [
2.0,
0,
0,
1.0,
498.0,
1.0,
0,
0,
],
"minimum": 2.0,
"maximum": 498.0,
}
],
)
assert server.compare_image("mesh/points/vertex_attribute_item.jpeg") == True
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,40 @@ def test_polygons_polygon_color_map_rainbow(
)

assert server.compare_image("mesh/polygons/polygon_color_map_rainbow.jpeg") == True


def test_polygons_polygon_attribute_item(
server: ServerMonitor, dataset_factory: Callable[..., str]
) -> None:

test_register(server, dataset_factory)

server.call(
VtkMeshPolygonsAttributePolygonView.mesh_polygons_attribute_polygon_prefix
+ VtkMeshPolygonsAttributePolygonView.mesh_polygons_attribute_polygon_schemas_dict[
"attribute"
][
"rpc"
],
[
{
"id": mesh_id,
"name": "triangle_vertices",
"item": 1,
"points": [
0.0,
0,
0,
1.0,
50.0,
1.0,
0,
0,
],
"minimum": 0.0,
"maximum": 50.0,
}
],
)

assert server.compare_image("mesh/polygons/polygon_attribute_item.jpeg") == True
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,39 @@ def test_polygons_vertex_color_map_rainbow(
)

assert server.compare_image("mesh/polygons/vertex_color_map_rainbow.jpeg") == True


def test_polygons_vertex_attribute_item(
server: ServerMonitor, dataset_factory: Callable[..., str]
) -> None:
test_register(server, dataset_factory)

server.call(
VtkMeshPolygonsAttributeVertexView.mesh_polygons_attribute_vertex_prefix
+ VtkMeshPolygonsAttributeVertexView.mesh_polygons_attribute_vertex_schemas_dict[
"attribute"
][
"rpc"
],
[
{
"id": mesh_id,
"name": "points",
"item": 1,
"points": [
2.0,
0,
0,
1.0,
498.0,
1.0,
0,
0,
],
"minimum": 2.0,
"maximum": 498.0,
}
],
)

assert server.compare_image("mesh/polygons/vertex_attribute_item.jpeg") == True
Loading
Loading