Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
49 changes: 49 additions & 0 deletions opengeodeweb_viewer_schemas.json
Original file line number Diff line number Diff line change
Expand Up @@ -2350,6 +2350,55 @@
],
"additionalProperties": false
},
"clipping_planes": {
"$id": "opengeodeweb_viewer.viewer.clipping_planes",
"rpc": "clipping_planes",
"type": "object",
"properties": {
"ids": {
"type": "array",
"items": {
"type": "string",
"minLength": 32,
"maxLength": 32
}
},
"planes": {
"type": "array",
"items": {
"type": "object",
"properties": {
"origin": {
"type": "array",
"items": {
"type": "number"
},
"minItems": 3,
"maxItems": 3
},
"normal": {
"type": "array",
"items": {
"type": "number"
},
"minItems": 3,
"maxItems": 3
}
},
"required": [
"origin",
"normal"
],
"additionalProperties": false
}
}
},
"required": [
"ids",
"planes"
],
"additionalProperties": false
},
"axes": {
"$id": "opengeodeweb_viewer.viewer.axes",
"rpc": "axes",
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.1.4
55 changes: 12 additions & 43 deletions src/opengeodeweb_viewer/object/object_methods.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
# Standard library imports
import os

# Third party imports
from vtkmodules.vtkIOXML import vtkXMLDataReader, vtkXMLImageDataReader
from vtkmodules.vtkCommonExecutionModel import vtkAlgorithm
from vtkmodules.vtkCommonDataModel import (
vtkDataSet,
vtkMultiBlockDataSet,
)
from vtkmodules.vtkRenderingCore import (
vtkMapper,
vtkActor,
vtkTexture,
vtkCompositePolyDataMapper,
vtkCompositeDataDisplayAttributes,
vtkDataSetMapper,
)
from vtkmodules.vtkCommonDataModel import (
vtkDataSet,
vtkMultiBlockDataSet,
)
from vtkmodules.vtkFiltersExtraction import vtkExtractSelection

# Local application imports
from opengeodeweb_viewer.vtk_protocol import VtkView, VtkPipeline
from opengeodeweb_viewer.vtk_pipeline import VtkPipeline
from opengeodeweb_viewer.vtk_protocol import VtkView


class VtkObjectView(VtkView):
Expand Down Expand Up @@ -133,28 +125,6 @@ def SetPointsColor(
actor = self.get_vtk_pipeline(data_id).actor
actor.GetProperty().SetVertexColor([red / 255, green / 255, blue / 255])

def _prune_hidden_blocks(
self,
dataset: vtkMultiBlockDataSet,
visibility_attributes: vtkCompositeDataDisplayAttributes,
) -> vtkMultiBlockDataSet:
# Recursively construct a new multi-block dataset excluding hidden blocks.
pruned = vtkMultiBlockDataSet()
pruned.SetNumberOfBlocks(dataset.GetNumberOfBlocks())
for index in range(dataset.GetNumberOfBlocks()):
block = dataset.GetBlock(index)
if block is None:
continue
if not visibility_attributes.GetBlockVisibility(block):
continue
if isinstance(block, vtkMultiBlockDataSet):
pruned.SetBlock(
index, self._prune_hidden_blocks(block, visibility_attributes)
)
else:
pruned.SetBlock(index, block)
return pruned

def SetBlocksVisibility(
self, data_id: str, block_ids: list[int], visibility: bool
) -> None:
Expand All @@ -164,16 +134,17 @@ def SetBlocksVisibility(
raise Exception("Mapper is not a vtkCompositePolyDataMapper")
blocks = pipeline.blockDataSets
visibility_attributes = mapper.GetCompositeDataDisplayAttributes()
print(f"{visibility_attributes=}", flush=True)
for block_id in block_ids:
visibility_attributes.SetBlockVisibility(blocks[block_id], visibility)
dataset = (pipeline.filter or pipeline.reader).GetOutputDataObject(0)
dataset = mapper.GetInputDataObject(0, 0)
if not isinstance(dataset, vtkMultiBlockDataSet):
return
# Re-build a pruned dataset for the dedicated pick mapper
if pipeline.pick_mapper is None:
pipeline.pick_mapper = vtkCompositePolyDataMapper()
pipeline.pick_mapper.SetInputDataObject(
self._prune_hidden_blocks(dataset, visibility_attributes)
pipeline.prune_hidden_blocks(dataset, visibility_attributes)
)

def SetBlocksColor(
Expand Down Expand Up @@ -228,11 +199,9 @@ def _apply_highlight_style(self, actor: vtkActor, mapper: vtkDataSetMapper) -> N
def highlight(self, pipeline: VtkPipeline) -> None:
highlight = pipeline.highlight
self._apply_highlight_style(highlight.actor, highlight.mapper)
input_port = (
pipeline.filter.GetOutputPort()
if pipeline.filter
else pipeline.reader.GetOutputPort()
)
if pipeline.filter.GetNumberOfInputConnections(0) == 0:
pipeline.filter.SetInputConnection(pipeline.reader.GetOutputPort())
input_port = pipeline.filter.GetOutputPort()
highlight.selection.AddNode(highlight.selectionNode)
highlight.extractSelection.SetInputConnection(0, input_port)
highlight.extractSelection.SetInputData(1, highlight.selection)
Expand Down
63 changes: 30 additions & 33 deletions src/opengeodeweb_viewer/rpc/mesh/mesh_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,23 @@
import os

# Third party imports
from wslink import register as exportRpc # type: ignore
from opengeodeweb_microservice.database.data import Data
from opengeodeweb_microservice.schemas import get_schemas_dict
from vtkmodules.vtkIOXML import vtkXMLGenericDataObjectReader, vtkXMLImageDataReader
from vtkmodules.vtkRenderingCore import (
vtkColorTransferFunction,
vtkDataSetMapper,
vtkActor,
vtkTexture,
vtkColorTransferFunction,
)
from vtkmodules.vtkCommonDataModel import vtkDataSet, vtkCellTypes
from vtkmodules.vtkCommonExecutionModel import vtkAlgorithm
from vtkmodules.vtkCommonDataModel import vtkPolyData
from opengeodeweb_microservice.database.data import Data
from opengeodeweb_microservice.schemas import get_schemas_dict
from wslink import register as exportRpc # type: ignore

# Local application imports
from opengeodeweb_viewer.object.object_methods import VtkObjectView
from opengeodeweb_viewer.utils_functions import (
validate_schema,
RpcParams,
validate_schema,
)
from opengeodeweb_viewer.object.object_methods import VtkObjectView
from opengeodeweb_viewer.vtk_protocol import VtkPipeline
from opengeodeweb_viewer.vtk_pipeline import VtkPipeline
from . import schemas


Expand Down Expand Up @@ -50,12 +46,9 @@ def registerMesh(self, rpc_params: RpcParams) -> None:
reader = vtkXMLGenericDataObjectReader()
reader.SetFileName(os.path.join(self.DATA_FOLDER_PATH, data_id, file_name))
reader.Update()
dataset = reader.GetOutputDataObject(0)
if dataset:
dataset.SetObjectName(params.name)
mapper = vtkDataSetMapper()
mapper.SetInputConnection(reader.GetOutputPort())
data = VtkPipeline(reader, mapper)
self.setup_pipeline(data, params.name)
self.highlight(data)
self.registerObject(data_id, file_name, data)
except Exception as e:
Expand Down Expand Up @@ -107,16 +100,14 @@ def meshApplyTextures(self, rpc_params: RpcParams) -> None:
texture = vtkTexture()
texture.SetInputConnection(texture_reader.GetOutputPort())
texture.InterpolateOn()
reader = self.get_vtk_pipeline(mesh_id).reader
output = reader.GetOutputAsDataSet()
point_data = output.GetPointData()
for i in range(point_data.GetNumberOfArrays()):
array = point_data.GetArray(i)
if array.GetName() == tex_info.texture_name:
point_data.SetTCoords(array)
break
actor = self.get_vtk_pipeline(mesh_id).actor
actor.SetTexture(texture)
pipeline = self.get_vtk_pipeline(mesh_id)
output = pipeline.reader.GetOutputAsDataSet()
array = output.GetPointData().GetArray(tex_info.texture_name)
if array:
output.GetPointData().SetTCoords(array)
pipeline.filter.Modified()
pipeline.filter.Update()
pipeline.actor.SetTexture(texture)

def displayAttributeOnVertices(
self,
Expand All @@ -127,10 +118,13 @@ def displayAttributeOnVertices(
minimum: float,
maximum: float,
) -> None:
reader = self.get_vtk_pipeline(data_id).reader
points = reader.GetOutputAsDataSet().GetPointData()
points.SetActiveScalars(name)
mapper = self.get_vtk_pipeline(data_id).mapper
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:
active_ds.GetPointData().SetActiveScalars(name)
mapper = pipeline.mapper
mapper.ScalarVisibilityOn()
mapper.SetScalarModeToUsePointData()
mapper.SetArrayComponent(item)
Expand All @@ -145,10 +139,13 @@ def displayAttributeOnCells(
minimum: float,
maximum: float,
) -> None:
reader = self.get_vtk_pipeline(data_id).reader
cells = reader.GetOutputAsDataSet().GetCellData()
cells.SetActiveScalars(name)
mapper = self.get_vtk_pipeline(data_id).mapper
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:
active_ds.GetCellData().SetActiveScalars(name)
mapper = pipeline.mapper
mapper.ScalarVisibilityOn()
mapper.SetScalarModeToUseCellData()
mapper.SetArrayComponent(item)
Expand Down
Loading
Loading