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
53 changes: 53 additions & 0 deletions opengeodeweb_viewer_schemas.json
Original file line number Diff line number Diff line change
Expand Up @@ -2544,6 +2544,59 @@
"camera_options"
]
},
"threshold": {
"$id": "opengeodeweb_viewer.viewer.threshold",
"rpc": "threshold",
"type": "object",
"properties": {
"ids": {
"type": "array",
"items": {
"type": "string",
"minLength": 32,
"maxLength": 32
}
},
"attribute": {
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1
},
"location": {
"type": "string",
"enum": [
"point",
"cell"
]
},
"item": {
"type": "integer",
"minimum": 0
},
"minimum": {
"type": "number"
},
"maximum": {
"type": "number"
}
},
"required": [
"name",
"location",
"item",
"minimum",
"maximum"
],
"additionalProperties": false
}
},
"required": [
"ids"
],
"additionalProperties": false
},
"take_screenshot": {
"$id": "opengeodeweb_viewer.viewer.take_screenshot",
"rpc": "take_screenshot",
Expand Down
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.2
1 change: 1 addition & 0 deletions src/opengeodeweb_viewer/rpc/viewer/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .update_data import *
from .update_camera import *
from .threshold import *
from .take_screenshot import *
from .shrink import *
from .set_z_scaling import *
Expand Down
52 changes: 52 additions & 0 deletions src/opengeodeweb_viewer/rpc/viewer/schemas/threshold.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"rpc": "threshold",
"type": "object",
"properties": {
"ids": {
"type": "array",
"items": {
"type": "string",
"minLength": 32,
"maxLength": 32
}
},
"attribute": {
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1
},
"location": {
"type": "string",
"enum": [
"point",
"cell"
]
},
"item": {
"type": "integer",
"minimum": 0
},
"minimum": {
"type": "number"
},
"maximum": {
"type": "number"
}
},
"required": [
"name",
"location",
"item",
"minimum",
"maximum"
],
"additionalProperties": false
}
},
"required": [
"ids"
],
"additionalProperties": false
}
30 changes: 30 additions & 0 deletions src/opengeodeweb_viewer/rpc/viewer/schemas/threshold.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from dataclasses_json import DataClassJsonMixin
from enum import Enum
from dataclasses import dataclass
from typing import List, Optional


class Location(Enum):
CELL = "cell"
POINT = "point"


@dataclass
class Attribute(DataClassJsonMixin):
def __post_init__(self) -> None:
print(self, flush=True)

item: int
location: Location
maximum: float
minimum: float
name: str


@dataclass
class Threshold(DataClassJsonMixin):
def __post_init__(self) -> None:
print(self, flush=True)

ids: List[str]
attribute: Optional[Attribute] = None
8 changes: 8 additions & 0 deletions src/opengeodeweb_viewer/rpc/viewer/viewer_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,14 @@ def setShrink(self, rpc_params: RpcParams) -> None:
params = schemas.Shrink.from_dict(rpc_params)
self.set_shrink(params.ids, params.shrink_factor)

@exportRpc(viewer_prefix + viewer_schemas_dict["threshold"]["rpc"])
def setThreshold(self, rpc_params: RpcParams) -> None:
validate_schema(
rpc_params, self.viewer_schemas_dict["threshold"], self.viewer_prefix
)
params = schemas.Threshold.from_dict(rpc_params)
self.set_threshold(params.ids, params.attribute)

@exportRpc(viewer_prefix + viewer_schemas_dict["set_z_scaling"]["rpc"])
def setZScaling(self, rpc_params: RpcParams) -> None:
validate_schema(
Expand Down
2 changes: 2 additions & 0 deletions src/opengeodeweb_viewer/vtk_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
vtkExtractGeometry,
vtkExtractSelection,
)
from vtkmodules.vtkFiltersCore import vtkThreshold
from vtkmodules.vtkFiltersGeneral import vtkShrinkFilter
from vtkmodules.vtkFiltersGeometry import vtkGeometryFilter
from vtkmodules.vtkIOXML import vtkXMLReader
Expand Down Expand Up @@ -211,6 +212,7 @@ class VtkPipeline:
filter: vtkGeometryFilter = field(default_factory=vtkGeometryFilter)
actor: vtkActor = field(default_factory=vtkActor)
clipping_filter: vtkExtractGeometry | None = None
threshold_filter: vtkThreshold | None = None
shrink_filter: vtkShrinkFilter | None = None
highlight: HighlightPipeline = field(default_factory=HighlightPipeline)
blockDataSets: list[vtkDataObject | None] = field(default_factory=list)
Expand Down
32 changes: 31 additions & 1 deletion src/opengeodeweb_viewer/vtk_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
vtkPlane,
vtkSelectionNode,
)
from vtkmodules.vtkFiltersCore import vtkThreshold
from vtkmodules.vtkFiltersExtraction import vtkExtractGeometry
from vtkmodules.vtkFiltersGeneral import vtkShrinkFilter
from vtkmodules.vtkFiltersGeometry import vtkGeometryFilter
Expand All @@ -37,6 +38,7 @@
from opengeodeweb_microservice.database.connection import get_session
from opengeodeweb_microservice.database.data import Data
from opengeodeweb_viewer.rpc.viewer.schemas.clipping_planes import Plane
from opengeodeweb_viewer.rpc.viewer.schemas.threshold import Attribute, Location
from opengeodeweb_viewer.vtk_pipeline import (
RulerPipeline,
ViewerData,
Expand Down Expand Up @@ -179,7 +181,11 @@ def update_pipeline_filter(self, pipeline: VtkPipeline) -> None:
current_input_port = pipeline.reader.GetOutputPort()
active_filters = [
filter_obj
for filter_obj in (pipeline.clipping_filter, pipeline.shrink_filter)
for filter_obj in (
pipeline.clipping_filter,
pipeline.threshold_filter,
pipeline.shrink_filter,
)
if filter_obj is not None
]
for filter_obj in active_filters:
Expand Down Expand Up @@ -219,6 +225,30 @@ def set_clipping_planes(
pipeline.clipping_filter = None
self.update_pipeline_filter(pipeline)

def set_threshold(self, data_ids: list[str], attribute: Attribute | None) -> None:
for data_id in data_ids:
pipeline = self.get_vtk_pipeline(data_id)
if attribute:
threshold_filter = vtkThreshold()
threshold_filter.SetInputArrayToProcess(
0,
0,
0,
(
vtkDataObject.FIELD_ASSOCIATION_POINTS
if attribute.location == Location.POINT
else vtkDataObject.FIELD_ASSOCIATION_CELLS
),
attribute.name,
)
threshold_filter.SetSelectedComponent(attribute.item)
threshold_filter.SetLowerThreshold(attribute.minimum)
threshold_filter.SetUpperThreshold(attribute.maximum)
pipeline.threshold_filter = threshold_filter
else:
pipeline.threshold_filter = None
self.update_pipeline_filter(pipeline)

def set_shrink(self, data_ids: list[str], shrink_factor: float) -> None:
for data_id in data_ids:
pipeline = self.get_vtk_pipeline(data_id)
Expand Down
Binary file added tests/data/images/mesh/cells/threshold.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 added tests/data/images/model/blocks/threshold.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions tests/mesh/cells/test_mesh_cells_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,35 @@ def test_cells_shrink(
],
)
assert server.compare_image("mesh/cells/shrink.jpeg") == True


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

test_register(server, dataset_factory)

server.call(
VtkViewerView.viewer_prefix
+ VtkViewerView.viewer_schemas_dict["threshold"]["rpc"],
[
{
"ids": [mesh_id],
"attribute": {
"name": "RGB_data",
"location": "cell",
"item": 0,
"minimum": 0.0,
"maximum": 128.0,
},
}
],
)
assert server.compare_image("mesh/cells/threshold.jpeg") == True

server.call(
VtkViewerView.viewer_prefix
+ VtkViewerView.viewer_schemas_dict["threshold"]["rpc"],
[{"ids": [mesh_id]}],
)
assert server.compare_image("mesh/cells/register.jpeg") == True
25 changes: 25 additions & 0 deletions tests/model/blocks/test_model_blocks_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,28 @@ def test_blocks_shrink(
],
)
assert server.compare_image("model/blocks/shrink.jpeg") == True


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

test_register_model_cube(server, dataset_factory)

server.call(
VtkViewerView.viewer_prefix
+ VtkViewerView.viewer_schemas_dict["threshold"]["rpc"],
[
{
"ids": [model_id],
"attribute": {
"name": "tetrahedron_vertices",
"location": "cell",
"item": 0,
"minimum": 0.0,
"maximum": 300.0,
},
}
],
)
assert server.compare_image("model/blocks/threshold.jpeg") == True
Loading