Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ frozenlist>=1
# via
# aiohttp
# aiosignal
idna==3.18
idna>=3
# via yarl
kiwisolver>=1
# via matplotlib
Expand All @@ -36,7 +36,7 @@ numpy>=2
# via
# contourpy
# matplotlib
packaging==26.3
packaging>=26

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah top mes changements d'actions ont marché

# via matplotlib
pillow>=12
# via matplotlib
Expand All @@ -56,11 +56,10 @@ typing-extensions>=4
# aiosignal
vtk==9.5.2
# via -r requirements.in
websocket-client>=1
websocket-client==1.8.0
# via -r requirements.in
wslink==1.12.4
# via -r requirements.in
yarl>=1
# via aiohttp

opengeodeweb-microservice==1.*,>=1.2.0rc2
18 changes: 18 additions & 0 deletions src/opengeodeweb_viewer/object/object_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def deregisterObject(self, data_id: str) -> None:
renderer.RemoveActor(pipeline.actor)
renderer.RemoveActor(pipeline.highlight.actor)
renderer.RemoveActor2D(pipeline.scalarBar)
for bar in pipeline.scalar_bars.values():
renderer.RemoveActor2D(bar)
self.deregister_object(data_id)
self.update_scalar_bars_layout()

Expand All @@ -61,12 +63,20 @@ def SetVisibility(self, data_id: str, visibility: bool) -> None:
pipeline.actor.SetVisibility(visibility)
if not visibility:
pipeline.scalarBar.SetVisibility(False)
for bar in pipeline.scalar_bars.values():
bar.SetVisibility(False)
else:
if (
pipeline.mapper.GetScalarVisibility()
and pipeline.mapper.GetLookupTable() is not None
):
pipeline.scalarBar.SetVisibility(True)
for style in pipeline.block_styles.values():
if style and style.get("name"):
for bar in pipeline.scalar_bars.values():
if bar.GetLookupTable() is not None:
bar.SetVisibility(True)
break
self.update_scalar_bars_layout()

def SetOpacity(self, data_id: str, opacity: float) -> None:
Expand Down Expand Up @@ -176,8 +186,16 @@ def clearColors(self, data_id: str) -> None:
if isinstance(output, vtkDataSet):
output.GetPointData().SetActiveScalars("")
output.GetCellData().SetActiveScalars("")
elif isinstance(mapper, vtkCompositePolyDataMapper):
pipeline.block_styles.clear()
for block in pipeline.blockDataSets:
if isinstance(block, vtkDataSet):
block.GetPointData().SetActiveScalars("")
block.GetCellData().SetActiveScalars("")
mapper.ScalarVisibilityOff()
pipeline.scalarBar.SetVisibility(False)
for bar in pipeline.scalar_bars.values():
bar.SetVisibility(False)
self.update_scalar_bars_layout()

def _apply_highlight_style(self, actor: vtkActor, mapper: vtkDataSetMapper) -> None:
Expand Down
22 changes: 2 additions & 20 deletions src/opengeodeweb_viewer/rpc/mesh/mesh_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# Local application imports
from opengeodeweb_viewer.object.object_methods import VtkObjectView
from opengeodeweb_viewer.utils_functions import (
create_color_transfer_function,
RpcParams,
validate_schema,
)
Expand Down Expand Up @@ -165,28 +166,9 @@ def setupColorMap(
item: int = 0,
) -> None:
data = self.get_vtk_pipeline(data_id)
lut = vtkColorTransferFunction()
lut.SetVectorModeToComponent()
lut.SetVectorComponent(item)
lut = create_color_transfer_function(points, minimum, maximum, item)
data.mapper.SetLookupTable(lut)

if not points:
lut.AddRGBPoint(minimum, 0, 0, 0)
lut.AddRGBPoint(maximum, 1, 1, 1)
else:
x_values = points[::4]
x_min = min(x_values)
x_max = max(x_values)
x_range = x_max - x_min
target_range = maximum - minimum

for x, r, g, b in zip(*[iter(points)] * 4):
if x_range != 0:
new_x = minimum + (x - x_min) / x_range * target_range
else:
new_x = minimum
lut.AddRGBPoint(new_x, r, g, b)

data.mapper.SetScalarRange(minimum, maximum)
lut.SetRange(minimum, maximum)
data.mapper.SetUseLookupTableScalarRange(False)
Expand Down
33 changes: 32 additions & 1 deletion src/opengeodeweb_viewer/rpc/model/model_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
from vtkmodules.vtkCommonDataModel import vtkMultiBlockDataSet
from vtkmodules.vtkFiltersCore import vtkAppendDataSets
from vtkmodules.vtkIOXML import vtkXMLMultiBlockDataReader
from vtkmodules.vtkRenderingAnnotation import vtkScalarBarActor
from vtkmodules.vtkRenderingCore import (
vtkColorTransferFunction,
vtkCompositeDataDisplayAttributes,
vtkCompositePolyDataMapper,
)
Expand All @@ -21,11 +23,12 @@
# Local application imports
from opengeodeweb_viewer.object.object_methods import VtkObjectView
from opengeodeweb_viewer.utils_functions import (
create_color_transfer_function,
deterministic_color,
RpcParams,
validate_schema,
)
from opengeodeweb_viewer.vtk_pipeline import VtkPipeline
from opengeodeweb_viewer.vtk_pipeline import BlockStyle, VtkPipeline
from . import schemas


Expand Down Expand Up @@ -104,8 +107,33 @@ def apply_color(
attr.SetBlockColor(block_dataset, [red, green, blue])
attr.SetBlockOpacity(block_dataset, alpha)
mapper.Modified()
self.setup_model_color_map(pipeline)
return colors

def setup_model_color_map(self, pipeline: VtkPipeline) -> None:
active_attrs: dict[str, BlockStyle] = {}
for style in pipeline.block_styles.values():
if style and style.get("name"):
active_attrs[style["name"]] = style
for name, style in active_attrs.items():
if name not in pipeline.scalar_bars:
bar = vtkScalarBarActor()
self.get_renderer().AddActor2D(bar)
pipeline.scalar_bars[name] = bar
bar = pipeline.scalar_bars[name]
item = style.get("item", 0)
minimum = style.get("minimum", 0.0)
maximum = style.get("maximum", 1.0)
points = style.get("points", [])
lut = create_color_transfer_function(points, minimum, maximum, item)
bar.SetLookupTable(lut)
bar.SetVisibility(True)
for name, bar in pipeline.scalar_bars.items():
if name not in active_attrs:
bar.SetVisibility(False)

self.update_scalar_bars_layout()

def displayAttributeOnVertices(
self,
data_id: str,
Expand All @@ -126,6 +154,7 @@ def displayAttributeOnVertices(
style["minimum"] = minimum
style["maximum"] = maximum
pipeline.update_block_colors(block_id)
self.setup_model_color_map(pipeline)

def displayAttributeOnCells(
self,
Expand All @@ -147,6 +176,7 @@ def displayAttributeOnCells(
style["minimum"] = minimum
style["maximum"] = maximum
pipeline.update_block_colors(block_id)
self.setup_model_color_map(pipeline)

def setupColorMap(
self,
Expand All @@ -162,6 +192,7 @@ def setupColorMap(
style["minimum"] = minimum
style["maximum"] = maximum
pipeline.update_block_colors(block_id)
self.setup_model_color_map(pipeline)

@exportRpc(model_prefix + model_schemas_dict["register"]["rpc"])
def registerModel(self, rpc_params: RpcParams) -> None:
Expand Down
23 changes: 23 additions & 0 deletions src/opengeodeweb_viewer/utils_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Third party imports
import fastjsonschema # type: ignore
import math
from vtkmodules.vtkRenderingCore import vtkColorTransferFunction

from opengeodeweb_microservice.schemas import SchemaDict

Expand Down Expand Up @@ -55,3 +56,25 @@ def component(phase: int) -> float:
return round(255 * intensity) / 255

return (component(0), component(PHASE_GREEN), component(4))


def create_color_transfer_function(
points: list[float], minimum: float, maximum: float, item: int = 0
) -> vtkColorTransferFunction:
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
for i in range(0, len(points), 4):
x, r, g, b = points[i : i + 4]
new_x = (
minimum + (x - x_min) / span * (maximum - minimum) if span else minimum
)
lut.AddRGBPoint(new_x, r, g, b)
else:
lut.AddRGBPoint(minimum, 0, 0, 0)
lut.AddRGBPoint(maximum, 1, 1, 1)
return lut
48 changes: 12 additions & 36 deletions src/opengeodeweb_viewer/vtk_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
ViewerElementsType,
ViewerType,
)
from opengeodeweb_viewer.utils_functions import create_color_transfer_function


@dataclass
Expand Down Expand Up @@ -73,6 +74,7 @@ class VtkPipeline:
blockDataSets: list[vtkDataObject | None] = field(default_factory=list)
blockGeodeIds: list[str] = field(default_factory=list)
scalarBar: vtkScalarBarActor = field(default_factory=vtkScalarBarActor)
scalar_bars: dict[str, vtkScalarBarActor] = field(default_factory=dict)
block_styles: dict[int, BlockStyle] = field(default_factory=dict)
pick_mapper: vtkMapper | None = None

Expand Down Expand Up @@ -139,50 +141,24 @@ def update_block_colors(self, block_id: int) -> None:
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

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
for i in range(0, len(points), 4):
x, r, g, b = points[i : i + 4]
new_x = (
minimum + (x - x_min) / span * (maximum - minimum)
if span
else minimum
)
lut.AddRGBPoint(new_x, r, g, b)
else:
lut.AddRGBPoint(minimum, 0, 0, 0)
lut.AddRGBPoint(maximum, 1, 1, 1)

lut = create_color_transfer_function(
style["points"], style["minimum"], style["maximum"], item
)
rgba_colors = lut.MapScalars(scalar_array, 1, item)
rgba_colors.SetName(f"__colors_{style['name']}")
field_data.AddArray(rgba_colors)
field_data.SetActiveScalars(rgba_colors.GetName())
other_field_data.SetActiveScalars("")
if isinstance(self.mapper, vtkCompositePolyDataMapper):
if attributes := self.mapper.GetCompositeDataDisplayAttributes():
attributes.RemoveBlockColor(block)
self.mapper.ScalarVisibilityOn()
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.SetColorModeToDirectScalars()
self.mapper.SetScalarModeToDefault()
self.mapper.Modified()

def sync_block_display_attributes(
Expand Down
37 changes: 22 additions & 15 deletions src/opengeodeweb_viewer/vtk_protocol.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Standard library imports
from vtkmodules.vtkRenderingAnnotation import vtkScalarBarActor
import math
import os
from typing import Any, cast
Expand Down Expand Up @@ -389,12 +390,26 @@ def get_dist(axis: int) -> float:
self.reset_camera_clipping_range()

def update_scalar_bars_layout(self) -> None:
visible_bars = [
(data_id, pipeline)
for data_id, pipeline in self.get_data_base().items()
if pipeline.scalarBar.GetVisibility()
and pipeline.scalarBar.GetLookupTable() is not None
]
visible_bars: list[tuple[vtkScalarBarActor, str, str, VtkPipeline]] = []
for data_id, pipeline in self.get_data_base().items():
if (
pipeline.scalarBar.GetVisibility()
and pipeline.scalarBar.GetLookupTable() is not None
):
dataset = pipeline.filter.GetOutputDataObject(0)
scalars = (
dataset.GetPointData().GetScalars()
or dataset.GetCellData().GetScalars()
if isinstance(dataset, vtkDataSet)
else None
)
attr_name = scalars.GetName() if scalars else "Attribute"
visible_bars.append((pipeline.scalarBar, attr_name, data_id, pipeline))

for attr_name, bar in pipeline.scalar_bars.items():
if bar.GetVisibility() and bar.GetLookupTable() is not None:
visible_bars.append((bar, attr_name, data_id, pipeline))

if not visible_bars:
return

Expand All @@ -407,16 +422,8 @@ def update_scalar_bars_layout(self) -> None:
actual_width = 0.10
row_height = 0.12

for i, (data_id, pipeline) in enumerate(visible_bars):
bar = pipeline.scalarBar
for i, (bar, attr_name, data_id, pipeline) in enumerate(visible_bars):
dataset = pipeline.filter.GetOutputDataObject(0)
scalars = (
dataset.GetPointData().GetScalars()
or dataset.GetCellData().GetScalars()
if dataset
else None
)
attr_name = scalars.GetName() if scalars else "Attribute"
data_name = (
dataset.GetObjectName()
if dataset and dataset.GetObjectName()
Expand Down
Binary file modified tests/data/images/model/blocks/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/blocks/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/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/blocks/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/blocks/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/blocks/updated_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/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/blocks/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/blocks/vertex_attribute_item.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.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/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/corners/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/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.
Binary file modified tests/data/images/model/corners/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/lines/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/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/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/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/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/updated_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/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
Binary file modified tests/data/images/model/lines/vertex_color_map_rainbow.jpeg
Binary file modified tests/data/images/model/lines/vertex_color_map_rainbow_initial.jpeg
Binary file modified tests/data/images/model/lines/vertex_color_map_red_shift.jpeg
Binary file modified tests/data/images/model/surfaces/attribute.jpeg
Binary file modified tests/data/images/model/surfaces/color_map.jpeg
Binary file modified tests/data/images/model/surfaces/color_map_rainbow.jpeg
Binary file modified tests/data/images/model/surfaces/color_map_rainbow_initial.jpeg
Binary file modified tests/data/images/model/surfaces/color_map_red_shift.jpeg
Binary file modified tests/data/images/model/surfaces/updated_color_map.jpeg
Binary file modified tests/data/images/model/surfaces/updated_vertex_color_map.jpeg
Binary file modified tests/data/images/model/surfaces/vertex_attribute.jpeg
Binary file modified tests/data/images/model/surfaces/vertex_attribute_item.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
Loading