Skip to content

Commit

Permalink
Merge pull request #3 from Geode-solutions/next
Browse files Browse the repository at this point in the history
Next
  • Loading branch information
BotellaA authored Sep 7, 2023
2 parents fb00bc3 + dc1c26d commit 6f6d6c6
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 92 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
requirements.in
.github
README.md
.gitignore
20 changes: 0 additions & 20 deletions .github/workflows/CD.yml

This file was deleted.

13 changes: 13 additions & 0 deletions .github/workflows/docker-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Docker Image CD

on:
push:
branches: [ master, next ]
jobs:
docker-build-squash-push:
uses: Geode-solutions/actions/.github/workflows/docker-build-squash-push.yml@master
with:
image_name: 'opengeodeweb_viewer'
tag: ${{ github.ref_name }}
secrets:
TOKEN: ${{secrets.GITHUB_TOKEN}}
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
.pytest_cache
dist
dist
env/
venv/
.vscode/
__pycache__/
data/
6 changes: 0 additions & 6 deletions .pypirc

This file was deleted.

11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM ghcr.io/geode-solutions/vtk:3.9-cpu

WORKDIR /app

COPY . .
RUN pip3 install --user -r requirements.txt && pip3 cache purge
ENV PYTHONPATH="/usr/local:$PYTHONPATH"

CMD python vtkw-server.py --port 1234 --host 0.0.0.0

EXPOSE 1234
45 changes: 0 additions & 45 deletions pyproject.toml

This file was deleted.

8 changes: 2 additions & 6 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
OpenGeode-core
OpenGeode-IO
OpenGeode-Inspector
OpenGeode-Geosciences
OpenGeode-GeosciencesIO
Geode-Viewables
wslink
numpy
32 changes: 32 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile requirements.in
#
aiohttp==3.8.5
# via wslink
aiosignal==1.3.1
# via aiohttp
async-timeout==4.0.3
# via aiohttp
attrs==23.1.0
# via aiohttp
charset-normalizer==3.2.0
# via aiohttp
frozenlist==1.4.0
# via
# aiohttp
# aiosignal
idna==3.4
# via yarl
multidict==6.0.4
# via
# aiohttp
# yarl
numpy==1.25.2
# via -r requirements.in
wslink==1.11.1
# via -r requirements.in
yarl==1.9.2
# via aiohttp
File renamed without changes.
68 changes: 63 additions & 5 deletions src/opengeodeback_viewer/vtk_protocol.py → vtk_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,22 @@ def create_object_pipeline(self, params):
file_name = params["file_name"]

actor = vtk.vtkActor()
mapper = vtk.vtkDataSetMapper()
actor.SetMapper(mapper)
if ".vtm" in file_name:
reader = vtk.vtkXMLMultiBlockDataReader()
filter = vtk.vtkCompositeDataGeometryFilter()
filter = vtk.vtkGeometryFilter()
filter.SetInputConnection(reader.GetOutputPort())
mapper = vtk.vtkCompositePolyDataMapper()
mapper.SetInputConnection(filter.GetOutputPort())
self.register_object(id, reader, filter, actor, mapper, {})
else:
reader = vtk.vtkXMLGenericDataObjectReader()
mapper = vtk.vtkDataSetMapper()
mapper.SetInputConnection(reader.GetOutputPort())
self.register_object(id, reader, {}, actor, mapper, {})

reader.SetFileName(f"/data/{file_name}")

actor.SetMapper(mapper)
mapper.SetColorModeToMapScalars()
mapper.SetResolveCoincidentTopologyLineOffsetParameters(1, -0.1)
mapper.SetResolveCoincidentTopologyPolygonOffsetParameters(2, 0)
Expand Down Expand Up @@ -133,8 +134,18 @@ def update_data(self, params):

data = self.get_object(id)
reader = data["reader"]
reader.Modified()

reader.Update()
mapper = data["mapper"]
tag = vtk.reference(0)
scalars = vtk.vtkAbstractMapper.GetAbstractScalars(
reader.GetOutput(),
mapper.GetScalarMode(),
mapper.GetArrayAccessMode(),
mapper.GetArrayId(),
mapper.GetArrayName(),
tag,
)
mapper.SetScalarRange(scalars.GetRange())
self.render()

@exportRpc("get_point_position")
Expand All @@ -155,6 +166,53 @@ def reset(self):
renderWindow.GetRenderers().GetFirstRenderer().RemoveAllViewProps()
print("reset")

@exportRpc("toggle_edge_visibility")
def setEdgeVisibility(self, params):
print(f"{params=}", flush=True)
id = params["id"]
visibility = bool(params["visibility"])
actor = self.get_object(id)["actor"]
actor.GetProperty().SetEdgeVisibility(visibility)
self.render()

@exportRpc("toggle_point_visibility")
def setPointVisibility(self, params):
id = params["id"]
visibility = bool(params["visibility"])
actor = self.get_object(id)["actor"]
actor.GetProperty().SetVertexVisibility(visibility)
self.render()

@exportRpc("point_size")
def setPointSize(self, params):
id = params["id"]
size = float(params["size"])
actor = self.get_object(id)["actor"]
actor.GetProperty().SetPointSize(size)
self.render()

@exportRpc("set_color")
def setColor(self, params):
id = params["id"]
red = params["red"]
green = params["green"]
blue = params["blue"]
self.get_object(id)["mapper"].ScalarVisibilityOff()
actor = self.get_object(id)["actor"]
actor.GetProperty().SetColor(red, green, blue)
self.render()

@exportRpc("set_vertex_attribute")
def setVertexAttribute(self, params):
print(f"{params=}", flush=True)
id = params["id"]
name = params["name"]
mapper = self.get_object(id)["mapper"]
mapper.SelectColorArray(name)
mapper.ScalarVisibilityOn()
mapper.SetScalarModeToUsePointFieldData()
self.render()

def getProtocol(self, name):
for p in self.coreServer.getLinkProtocols():
if type(p).__name__ == name:
Expand Down
29 changes: 20 additions & 9 deletions src/opengeodeback_viewer/vtkw-server.py → vtkw-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import argparse

# Try handle virtual env if provided
if '--virtual-env' in sys.argv:
virtualEnvPath = sys.argv[sys.argv.index('--virtual-env') + 1]
virtualEnv = virtualEnvPath + '/bin/activate_this.py'
if "--virtual-env" in sys.argv:
virtualEnvPath = sys.argv[sys.argv.index("--virtual-env") + 1]
virtualEnv = virtualEnvPath + "/bin/activate_this.py"
with open(virtualEnv) as venv:
exec(venv.read(), dict(__file__=virtualEnv))

Expand All @@ -53,8 +53,9 @@ class _Server(vtk_wslink.ServerProtocol):

@staticmethod
def add_arguments(parser):
parser.add_argument("--virtual-env", default=None,
help="Path to virtual environment to use")
parser.add_argument(
"--virtual-env", default=None, help="Path to virtual environment to use"
)

@staticmethod
def configure(args):
Expand All @@ -66,7 +67,8 @@ def initialize(self):
self.registerVtkWebProtocol(vtk_protocols.vtkWebMouseHandler())
self.registerVtkWebProtocol(vtk_protocols.vtkWebViewPort())
self.registerVtkWebProtocol(
vtk_protocols.vtkWebPublishImageDelivery(decode=False))
vtk_protocols.vtkWebPublishImageDelivery(decode=False)
)
self.setSharedObject("db", dict())

# Custom API
Expand All @@ -85,13 +87,22 @@ def initialize(self):
renderWindow.AddRenderer(renderer)
self.setSharedObject("renderer", renderer)


renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)
renderWindowInteractor.GetInteractorStyle().SetCurrentStyleToTrackballCamera()
renderWindowInteractor.EnableRenderOff()
self.getApplication().GetObjectIdMap().SetActiveObject("VIEW", renderWindow)

widget = vtk.vtkOrientationMarkerWidget()
widget.SetInteractor(renderWindowInteractor)
widget.SetViewport(0.0, 0.0, 0.2, 0.2)
axes = vtk.vtkAxesActor()
widget.SetOrientationMarker(axes)
widget.EnabledOn()
widget.InteractiveOff()
self.setSharedObject("marker", widget)


# =============================================================================
# Main: Parse args and start serverviewId
# =============================================================================
Expand All @@ -105,9 +116,9 @@ def initialize(self):
server.add_arguments(parser)
_Server.add_arguments(parser)
args = parser.parse_args()
print('args :', args)
print("args :", args)
_Server.configure(args)

print('start')
print("start")
# Start server
server.start_webserver(options=args, protocol=_Server)

0 comments on commit 6f6d6c6

Please sign in to comment.