Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 7 additions & 0 deletions src/opengeodeweb_viewer/rpc/schemas/take_screenshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"rpc": "screenshot",
"type": "object",
"properties": {},
"required": [],
"additionalProperties": false
}
29 changes: 28 additions & 1 deletion src/opengeodeweb_viewer/vtk_protocol.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# Standard library imports
import json
import os

# Third party imports
import vtk
from vtk.web import protocols as vtk_protocols
from vtkmodules.vtkIOImage import vtkPNGWriter
from vtkmodules.vtkRenderingCore import (vtkWindowToImageFilter)
from wslink import register as exportRpc
import vtk

# Local application imports
from .function import validate_schemas



schemas = os.path.join(os.path.dirname(__file__), "rpc/schemas")

with open(os.path.join(schemas, "create_visualization.json"), "r") as file:
Expand Down Expand Up @@ -35,6 +44,8 @@
set_color_json = json.load(file)
with open(os.path.join(schemas, "set_vertex_attribute.json"), "r") as file:
set_vertex_attribute_json = json.load(file)
with open(os.path.join(schemas, "take_screenshot.json"), "r") as file:
take_screenshot_json = json.load(file)


class VtkView(vtk_protocols.vtkWebProtocol):
Expand Down Expand Up @@ -271,6 +282,22 @@ def setVertexAttribute(self, params):
mapper.SetScalarModeToUsePointFieldData()
self.render()

@exportRpc(take_screenshot_json["rpc"])
def takeScreenshot(self, params):
validate_schemas(params, take_screenshot_json)
print(f"{params=}", flush=True)
renderWindow = self.getView("-1")
w2if = vtkWindowToImageFilter()
w2if.SetInput(renderWindow)
w2if.SetInputBufferTypeToRGB()
w2if.ReadFrontBufferOff()
w2if.Update()

writer = vtkPNGWriter()
writer.SetFileName(os.path.join(self.DATA_FOLDER_PATH, 'screenshot.png'))
writer.SetInputConnection(w2if.GetOutputPort())
writer.Write()

def get_data_base(self):
return self.getSharedObject("db")

Expand Down