From 85c987473713c7a9f6462a955cd28a5c94ed3d51 Mon Sep 17 00:00:00 2001 From: Jaswant Panchumarti <jaswant.panchumarti@kitware.com> Date: Fri, 3 May 2024 12:55:05 -0400 Subject: [PATCH] Add resetCamera method in vtkWasmSceneManager --- Web/WebAssembly/vtkWasmSceneManager.cxx | 13 +++++++++++++ Web/WebAssembly/vtkWasmSceneManager.h | 16 ++++++++++++---- Web/WebAssembly/vtkWasmSceneManagerEmBinding.cxx | 8 ++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Web/WebAssembly/vtkWasmSceneManager.cxx b/Web/WebAssembly/vtkWasmSceneManager.cxx index b7d0c5ccc41..5dbd3265866 100644 --- a/Web/WebAssembly/vtkWasmSceneManager.cxx +++ b/Web/WebAssembly/vtkWasmSceneManager.cxx @@ -8,6 +8,7 @@ #include "vtkRenderWindow.h" #include "vtkRenderWindowInteractor.h" +#include "vtkRenderer.h" VTK_ABI_NAMESPACE_BEGIN //------------------------------------------------------------------------------- @@ -52,6 +53,18 @@ bool vtkWasmSceneManager::Render(vtkTypeUInt32 identifier) return false; } +//------------------------------------------------------------------------------- +bool vtkWasmSceneManager::ResetCamera(vtkTypeUInt32 identifier) +{ + auto object = this->GetObjectAtId(identifier); + if (auto renderer = vtkRenderer::SafeDownCast(object)) + { + renderer->ResetCamera(); + return true; + } + return false; +} + //------------------------------------------------------------------------------- bool vtkWasmSceneManager::StartEventLoop(vtkTypeUInt32 identifier) { diff --git a/Web/WebAssembly/vtkWasmSceneManager.h b/Web/WebAssembly/vtkWasmSceneManager.h index 493fa82a25b..d386a267f7f 100644 --- a/Web/WebAssembly/vtkWasmSceneManager.h +++ b/Web/WebAssembly/vtkWasmSceneManager.h @@ -33,7 +33,7 @@ public: * Set the size of the `vtkRenderWindow` object at `identifier` to * the supplied dimesions. * - * Returns `true` if the obejct at `identifier` is a `vtkRenderWindow` + * Returns `true` if the object at `identifier` is a `vtkRenderWindow` * with a `vtkRenderWindowInteractor` attached to it, * `false` otherwise. */ @@ -42,15 +42,23 @@ public: /** * Render the `vtkRenderWindow` object at `identifier`. * - * Returns `true` if the obejct at `identifier` is a `vtkRenderWindow` + * Returns `true` if the object at `identifier` is a `vtkRenderWindow` * `false` otherwise. */ bool Render(vtkTypeUInt32 identifier); + /** + * Reset the active camera of the `vtkRenderer` object at `identifier`. + * + * Returns `true` if the object at `identifier` is a `vtkRenderer` + * `false` otherwise. + */ + bool ResetCamera(vtkTypeUInt32 identifier); + /** * Start event loop of the `vtkRenderWindowInteractor` object at `identifier`. * - * Returns `true` if the obejct at `identifier` is a `vtkRenderWindowInteractor` + * Returns `true` if the object at `identifier` is a `vtkRenderWindowInteractor` * `false` otherwise. */ bool StartEventLoop(vtkTypeUInt32 identifier); @@ -58,7 +66,7 @@ public: /** * Stop event loop of the `vtkRenderWindowInteractor` object at `identifier`. * - * Returns `true` if the obejct at `identifier` is a `vtkRenderWindowInteractor` + * Returns `true` if the object at `identifier` is a `vtkRenderWindowInteractor` * `false` otherwise. */ bool StopEventLoop(vtkTypeUInt32 identifier); diff --git a/Web/WebAssembly/vtkWasmSceneManagerEmBinding.cxx b/Web/WebAssembly/vtkWasmSceneManagerEmBinding.cxx index dcd19e40564..39be3f6788b 100644 --- a/Web/WebAssembly/vtkWasmSceneManagerEmBinding.cxx +++ b/Web/WebAssembly/vtkWasmSceneManagerEmBinding.cxx @@ -177,6 +177,13 @@ bool render(vtkTypeUInt32 identifier) return Manager->Render(identifier); } +//------------------------------------------------------------------------------- +bool resetCamera(vtkTypeUInt32 identifier) +{ + CHECK_INIT; + return Manager->ResetCamera(identifier); +} + //------------------------------------------------------------------------------- bool startEventLoop(vtkTypeUInt32 identifier) { @@ -249,6 +256,7 @@ EMSCRIPTEN_BINDINGS(vtkWasmSceneManager) function("setSize", ::setSize); function("render", ::render); + function("resetCamera", ::resetCamera); function("startEventLoop", ::startEventLoop); function("stopEventLoop", ::stopEventLoop); -- GitLab