Skip to content
Open
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
42 changes: 42 additions & 0 deletions opengeodeweb_viewer_schemas.json
Original file line number Diff line number Diff line change
Expand Up @@ -2625,6 +2625,48 @@
],
"additionalProperties": false
},
"slice": {
"$id": "opengeodeweb_viewer.viewer.slice",
"rpc": "slice",
"type": "object",
"properties": {
"ids": {
"type": "array",
"items": {
"type": "string",
"minLength": 32,
"maxLength": 32
}
},
"slices": {
"type": "array",
"items": {
"type": "object",
"properties": {
"axis": {
"type": "integer",
"minimum": 0,
"maximum": 2
},
"index": {
"type": "integer",
"minimum": 0
}
},
"required": [
"axis",
"index"
],
"additionalProperties": false
}
}
},
"required": [
"ids",
"slices"
],
"additionalProperties": false
},
"shrink": {
"$id": "opengeodeweb_viewer.viewer.shrink",
"rpc": "shrink",
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
Expand Up @@ -2,6 +2,7 @@
from .update_camera import *
from .threshold import *
from .take_screenshot import *
from .slice import *
from .shrink import *
from .set_z_scaling import *
from .set_background_color import *
Expand Down
41 changes: 41 additions & 0 deletions src/opengeodeweb_viewer/rpc/viewer/schemas/slice.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"rpc": "slice",
"type": "object",
"properties": {
"ids": {
"type": "array",
"items": {
"type": "string",
"minLength": 32,
"maxLength": 32
}
},
"slices": {
"type": "array",
"items": {
"type": "object",
"properties": {
"axis": {
"type": "integer",
"minimum": 0,
"maximum": 2
},
"index": {
"type": "integer",
"minimum": 0
}
},
"required": [
"axis",
"index"
],
"additionalProperties": false
}
}
},
"required": [
"ids",
"slices"
],
"additionalProperties": false
}
21 changes: 21 additions & 0 deletions src/opengeodeweb_viewer/rpc/viewer/schemas/slice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from dataclasses_json import DataClassJsonMixin
from dataclasses import dataclass
from typing import List


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

axis: int
index: int


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

ids: List[str]
slices: List[SliceElement]
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["slice"]["rpc"])
def setSlice(self, rpc_params: RpcParams) -> dict[str, list[int]]:
validate_schema(
rpc_params, self.viewer_schemas_dict["slice"], self.viewer_prefix
)
params = schemas.Slice.from_dict(rpc_params)
return {"max_indices": self.set_slice(params.ids, params.slices)}

@exportRpc(viewer_prefix + viewer_schemas_dict["threshold"]["rpc"])
def setThreshold(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 @@ -37,6 +37,7 @@
)
from vtkmodules.vtkFiltersCore import vtkThreshold
from vtkmodules.vtkFiltersGeneral import vtkShrinkFilter
from vtkmodules.vtkFiltersCore import vtkAppendFilter
from vtkmodules.vtkFiltersGeometry import vtkGeometryFilter
from vtkmodules.vtkIOXML import vtkXMLReader

Expand Down Expand Up @@ -211,6 +212,7 @@ class VtkPipeline:
mapper: vtkMapper
filter: vtkGeometryFilter = field(default_factory=vtkGeometryFilter)
actor: vtkActor = field(default_factory=vtkActor)
slice_filter: vtkAppendFilter | None = None
clipping_filter: vtkExtractGeometry | None = None
threshold_filter: vtkThreshold | None = None
shrink_filter: vtkShrinkFilter | None = None
Expand Down
46 changes: 44 additions & 2 deletions src/opengeodeweb_viewer/vtk_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
vtkDataObject,
vtkDataSet,
vtkImplicitBoolean,
vtkImageData,
vtkPlane,
vtkSelectionNode,
)
from vtkmodules.vtkFiltersCore import vtkThreshold
from vtkmodules.vtkFiltersExtraction import vtkExtractGeometry
from vtkmodules.vtkFiltersGeneral import vtkShrinkFilter
from vtkmodules.vtkFiltersGeometry import vtkGeometryFilter
from vtkmodules.vtkFiltersCore import vtkAppendFilter
from vtkmodules.vtkImagingCore import vtkExtractVOI
from vtkmodules.vtkCommonCore import vtkIdTypeArray, vtkStringArray
from vtkmodules.vtkRenderingAnnotation import (
vtkAxesActor,
Expand All @@ -38,6 +41,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.slice import SliceElement
from opengeodeweb_viewer.rpc.viewer.schemas.threshold import Attribute, Location
from opengeodeweb_viewer.vtk_pipeline import (
RulerPipeline,
Expand Down Expand Up @@ -178,7 +182,11 @@ def clear_highlights(self, data_ids: list[str]) -> None:
pipeline.highlight.actor.VisibilityOff()

def update_pipeline_filter(self, pipeline: VtkPipeline) -> None:
current_input_port = pipeline.reader.GetOutputPort()
current_input_port = (
pipeline.slice_filter.GetOutputPort()
if pipeline.slice_filter is not None
else pipeline.reader.GetOutputPort()
)
active_filters = [
filter_obj
for filter_obj in (
Expand All @@ -200,7 +208,7 @@ def update_pipeline_filter(self, pipeline: VtkPipeline) -> None:
pipeline.mapper.SetInputConnection(pipeline.filter.GetOutputPort())
target_dataset = (
cast(vtkDataSet, filtered_dataset)
if active_filters
if active_filters or pipeline.slice_filter is not None
else pipeline.reader.GetOutputAsDataSet()
)
pipeline.restore_active_scalars(target_dataset)
Expand Down Expand Up @@ -260,6 +268,40 @@ def set_shrink(self, data_ids: list[str], shrink_factor: float) -> None:
pipeline.shrink_filter = None
self.update_pipeline_filter(pipeline)

def set_slice(self, data_ids: list[str], slices: list[SliceElement]) -> list[int]:
max_indices = [0, 0, 0]
for data_id in data_ids:
pipeline = self.get_vtk_pipeline(data_id)
image = pipeline.reader.GetOutputAsDataSet()
if not isinstance(image, vtkImageData):
continue
extent = image.GetExtent()
last_indices = [
extent[2 * axis + 1] - extent[2 * axis] for axis in range(3)
]
max_indices = [
max(current, last) for current, last in zip(max_indices, last_indices)
]
if not slices:
if pipeline.slice_filter is None:
continue
pipeline.slice_filter = None
else:
slice_filter = vtkAppendFilter()
for slice_item in slices:
voi = list(extent)
voi[2 * slice_item.axis] += min(
slice_item.index, last_indices[slice_item.axis]
)
voi[2 * slice_item.axis + 1] = voi[2 * slice_item.axis]
extract_voi = vtkExtractVOI()
extract_voi.SetInputConnection(pipeline.reader.GetOutputPort())
extract_voi.SetVOI(voi)
slice_filter.AddInputConnection(extract_voi.GetOutputPort())
pipeline.slice_filter = slice_filter
self.update_pipeline_filter(pipeline)
return max_indices

def swap_pick_mappers(self, data_ids: list[str], use_pick_mapper: bool) -> None:
# Swap actor mappers between the default and the pick_mapper (where hidden blocks are pruned).
for data_id in data_ids:
Expand Down
Binary file added tests/data/images/mesh/cells/slice_grid_2d.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.
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/mesh/cells/slice_grid_3d.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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions tests/data/regular_grid_3d.vti
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<VTKFile type="ImageData" version="0.1" byte_order="LittleEndian" header_type="UInt32" compressor="vtkZLibDataCompressor">
<ImageData WholeExtent="0 10 0 8 0 6" Origin="0 0 0" Spacing="10 10 10" Direction="1 0 0 0 1 0 0 0 1">
<Piece Extent="0 10 0 8 0 6" >
<PointData>
</PointData>
<CellData>
<DataArray type="Float64" Name="cell_value" format="appended" RangeMin="0" RangeMax="479" offset="0" />
</CellData>
</Piece>
</ImageData>
<AppendedData encoding="base64">
_AQAAAACAAAAADwAAhwIAAA==eJxNzTeuIEUUBdAXEk5AQEDQQgghhFDjPVPA4F3jPRR28DTejvSW0EuoJfQSagm9hFpCL4Hgn4BKTl1dXb2I/7/zsk+54Dpe4vW8gTdy4k28mbfwVt7G23kHZ97Ju3g37+G9vI/38wE+yIf4MB/ho3yMl1kuTMbjMuMJmfGkzLgiM56SGU/LjGdkxrMy4zmZ8bzMeEFmvCgzXpIZL8uMV2TGcmFhsjNe1TPZGa/pmeyM1/VMdsYbeiY74009k53xlp7Jznhbz2RnvKNnsjPe1TPZGe/pmeyM9/VMdsYHeiY740M9k53xkZ7JzvhYz2Rn1AsnFlYmGzsH4xN7FlYmGzsH41N7FlYmGzsH4zN7FlYmGzsH43N7FlYmGzsH4wt7FlYmGzsH40t7FlYmGzsH46o9CyuTjZ2D8ZU9CyuTjZ2D8bU9CyuTjZ2D8Y09CyuTjZ2D8a09CyuTjZ2D8Z09CyuTjZ2D8b09CyuTjZ2D8YM9CyuTjZ2D8aM9CyuTjZ2DsV54iRNnFi6sXJnc2Liz8+DgyfjJfU6cWbiwcmVyY+POzoODJ+Nn9zlxZuHCypXJjY07Ow8Onoxf3OfEmYULK1cmNzbu7Dw4eDJ+dZ8TZxYurFyZ3Ni4s/Pg4Mn4zX1OnFm4sHJlcmPjzs6Dgyfjd/c5cWbhwsqVyY2NOzsPDp6MP9znxJmFCytXJjc27uw8OHgy/nSfE2cWLqxcmdzYuLPz4ODJ+Mt9TpxZuLByZXJj487Og4Mn42/3OXFm4cLKlcmNjTs7Dw6ejH/c58SZhQsrVyY3Nu7sPDh4Mv51nxNnFi6sXJnc2Liz8+DgybjmPifOLFxYuTK5sXFn58HB81r5DzOj+Q8=
</AppendedData>
</VTKFile>
Loading
Loading