diff --git a/Documentation/release/dev/zSpace-plugin-rework.md b/Documentation/release/dev/zSpace-plugin-rework.md new file mode 100644 index 00000000000..cc9636b624e --- /dev/null +++ b/Documentation/release/dev/zSpace-plugin-rework.md @@ -0,0 +1,4 @@ +## zSpace plugin rework + +Pure VTK classes of the zSpace plugin have been moved to a dedicated VTK module. +Now, the plugin only contains the zSpace custom render view and the zSpace manager. diff --git a/Plugins/ZSpace/cmake/FindzSpaceCompat.cmake b/Plugins/ZSpace/cmake/FindzSpaceCompat.cmake index 0c5f49cd42e..854802b0f46 100644 --- a/Plugins/ZSpace/cmake/FindzSpaceCompat.cmake +++ b/Plugins/ZSpace/cmake/FindzSpaceCompat.cmake @@ -97,16 +97,5 @@ if (zSpaceCompat_FOUND) add_library(zSpaceImpl MODULE IMPORTED) set_target_properties(zSpaceImpl PROPERTIES IMPORTED_LOCATION "${zSpace_LIBRARY}") - - # Copy the .dll file to the build location - add_custom_target(zSpaceCopy - COMMAND - ${CMAKE_COMMAND} -E copy - "${zSpace_LIBRARY}" - "${CMAKE_BINARY_DIR}/bin/") - - # In order to launch the command - add_dependencies(zSpaceHeaders - zSpaceCopy) endif () endif () diff --git a/Plugins/ZSpace/paraview.plugin b/Plugins/ZSpace/paraview.plugin index baed5b6ed6d..0d3dd5fe672 100644 --- a/Plugins/ZSpace/paraview.plugin +++ b/Plugins/ZSpace/paraview.plugin @@ -5,3 +5,4 @@ DESCRIPTION REQUIRES_MODULES VTK::CommonCore VTK::RenderingCore + VTK::RenderingZSpace diff --git a/Plugins/ZSpace/zSpace/CMakeLists.txt b/Plugins/ZSpace/zSpace/CMakeLists.txt index f6708b6f178..1be8ee220c0 100644 --- a/Plugins/ZSpace/zSpace/CMakeLists.txt +++ b/Plugins/ZSpace/zSpace/CMakeLists.txt @@ -1,42 +1,8 @@ set(classes - vtkPVZSpaceView - vtkZSpaceCamera - vtkZSpaceInteractorStyle - vtkZSpaceRayActor - vtkZSpaceRenderWindowInteractor - vtkZSpaceSDKManager) - -set(ZSPACE_USE_COMPAT_SDK "ON" CACHE BOOL - "Set to \"ON\" to use the newer version of the zSpace SDK - (\"Core Compatibility SDK\") instead of the legacy one - (\"Core SDK\")") -mark_as_advanced(ZSPACE_USE_COMPAT_SDK) - -if(ZSPACE_USE_COMPAT_SDK) - list(APPEND classes vtkZSpaceCoreCompatibilitySDKManager) - vtk_module_find_package(PACKAGE zSpaceCompat) - message(zSpace_INCLUDE_DIR:${zSpace_INCLUDE_DIR}) -else() - list(APPEND classes vtkZSpaceCoreSDKManager) - vtk_module_find_package(PACKAGE zSpace) -endif() + vtkPVZSpaceView) vtk_module_add_module(zSpace::vtkZSpaceView CLASSES ${classes}) - -if(ZSPACE_USE_COMPAT_SDK) - # Just provide the headers as there are no library - # link during compile time - vtk_module_link(zSpace::vtkZSpaceView - PUBLIC zSpaceHeaders) -else() - vtk_module_link(zSpace::vtkZSpaceView - PUBLIC zSpace::zSpace) -endif() - -configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/vtkZSpaceSDKVersion.h.in" - "${CMAKE_CURRENT_BINARY_DIR}/vtkZSpaceSDKVersion.h") paraview_add_server_manager_xmls( XMLS ZSpaceView.xml) diff --git a/Plugins/ZSpace/zSpace/ZSpaceView.xml b/Plugins/ZSpace/zSpace/ZSpaceView.xml index 126c5e849ba..aeb3be99d59 100644 --- a/Plugins/ZSpace/zSpace/ZSpaceView.xml +++ b/Plugins/ZSpace/zSpace/ZSpaceView.xml @@ -42,7 +42,7 @@ diff --git a/Plugins/ZSpace/zSpace/vtk.module b/Plugins/ZSpace/zSpace/vtk.module index 25d9ed7ab88..c2ed237e3e0 100644 --- a/Plugins/ZSpace/zSpace/vtk.module +++ b/Plugins/ZSpace/zSpace/vtk.module @@ -4,11 +4,12 @@ LIBRARY_NAME vtkZSpaceView DEPENDS ParaView::RemotingViews + ParaView::RemotingMisc + ParaView::VTKExtensionsInteractionStyle VTK::CommonCore VTK::CommonDataModel VTK::CommonExecutionModel - ParaView::VTKExtensionsInteractionStyle - ParaView::RemotingMisc + VTK::RenderingZSpace PRIVATE_DEPENDS ParaView::RemotingCore VTK::RenderingOpenGL2 diff --git a/Plugins/ZSpace/zSpace/vtkPVZSpaceView.cxx b/Plugins/ZSpace/zSpace/vtkPVZSpaceView.cxx index bde79b522c5..0d5b99eda75 100644 --- a/Plugins/ZSpace/zSpace/vtkPVZSpaceView.cxx +++ b/Plugins/ZSpace/zSpace/vtkPVZSpaceView.cxx @@ -14,51 +14,50 @@ =========================================================================*/ #include "vtkPVZSpaceView.h" -#include "vtkCamera.h" #include "vtkCommand.h" #include "vtkCullerCollection.h" -#include "vtkMatrix4x4.h" #include "vtkMemberFunctionCommand.h" #include "vtkObjectFactory.h" #include "vtkPVAxesWidget.h" -#include "vtkPVHardwareSelector.h" -#include "vtkPolyDataMapper.h" -#include "vtkProperty.h" -#include "vtkRenderer.h" +#include "vtkRenderViewBase.h" +#include "vtkRenderWindow.h" #include "vtkTransform.h" #include "vtkZSpaceCamera.h" #include "vtkZSpaceInteractorStyle.h" #include "vtkZSpaceRayActor.h" #include "vtkZSpaceRenderWindowInteractor.h" +#include "vtkZSpaceRenderer.h" #include "vtkZSpaceSDKManager.h" vtkStandardNewMacro(vtkPVZSpaceView); + //---------------------------------------------------------------------------- vtkPVZSpaceView::vtkPVZSpaceView() { - if (this->InteractorStyle) // bother creating interactor styles only if superclass did as well. - { - this->ZSpaceInteractorStyle->SetZSpaceRayActor(this->StylusRayActor); - this->ZSpaceInteractorStyle->SetZSpaceView(this); - } + this->ZSpaceInteractorStyle->SetZSpaceRayActor(this->StylusRayActor); - // Set our custom camera to the renderer - this->GetRenderer()->SetActiveCamera(this->ZSpaceCamera); + // Setup the zSpace rendering pipeline + this->ZSpaceRenderer->AddActor(this->StylusRayActor); + this->ZSpaceRenderer->SetActiveCamera(this->ZSpaceCamera); - this->GetRenderer()->AddActor(this->StylusRayActor); + this->SetupAndSetRenderer(this->ZSpaceRenderer); + this->ZSpaceInteractorStyle->SetCurrentRenderer(this->ZSpaceRenderer); + + // Must be done after SetRenderer. + // Mandatory in VR-like env. to be able to see actors + this->ZSpaceRenderer->GetCullers()->RemoveAllItems(); + + // Hide axes + this->OrientationWidget->SetParentRenderer(nullptr); // Override ResetCameraEvent to use the zSpace reset camera vtkMemberFunctionCommand* observer = vtkMemberFunctionCommand::New(); + observer->SetCallback(*this, &vtkPVZSpaceView::ResetCamera); this->AddObserver(vtkCommand::ResetCameraEvent, observer); observer->FastDelete(); - this->GetRenderer()->GetCullers()->RemoveAllItems(); - - // Hide axes - this->OrientationWidget->SetParentRenderer(nullptr); - // Set the zSpace SDK Manager render window vtkZSpaceSDKManager::GetInstance()->SetRenderWindow(this->GetRenderWindow()); } @@ -82,6 +81,7 @@ void vtkPVZSpaceView::SetupInteractor(vtkRenderWindowInteractor* vtkNotUsed(rwi) void vtkPVZSpaceView::SetInteractionMode(int mode) { this->Superclass::SetInteractionMode(mode); + if (this->Interactor && this->Interactor->GetInteractorStyle() != this->ZSpaceInteractorStyle.GetPointer()) { @@ -103,12 +103,13 @@ void vtkPVZSpaceView::SetInteractionMode(int mode) void vtkPVZSpaceView::ResetCamera() { this->Update(); + if (this->GeometryBounds.IsValid() && !this->LockBounds && this->DiscreteCameras == nullptr) { double bounds[6]; this->GeometryBounds.GetBounds(bounds); // Insure an optimal initial position of the geometry in the scene - this->CalculateFit(bounds); + this->GetRenderer()->ResetCamera(bounds); } } @@ -118,7 +119,7 @@ void vtkPVZSpaceView::ResetCamera(double bounds[6]) if (!this->LockBounds && this->DiscreteCameras == nullptr) { // Insure an optimal initial position of the geometry in the scene - this->CalculateFit(bounds); + this->GetRenderer()->ResetCamera(bounds); } } @@ -129,63 +130,10 @@ void vtkPVZSpaceView::ResetAllUserTransforms() vtkActorCollection* actorCollection = this->GetRenderer()->GetActors(); vtkCollectionSimpleIterator ait; vtkNew identity; - for (actorCollection->InitTraversal(ait); (actor = actorCollection->GetNextActor(ait));) - { - actor->SetUserTransform(identity); - } -} - -//------------------------------------------------------------------------------ -void vtkPVZSpaceView::CalculateFit(double* bounds) -{ - vtkZSpaceSDKManager* sdkManager = vtkZSpaceSDKManager::GetInstance(); - // Get the viewer scale, camera position and camera view up from zSpace - double position[3]; - double viewUp[3]; - sdkManager->CalculateFrustumFit(bounds, position, viewUp); - - // Set the position, view up and focal point - double center[3]; - center[0] = (bounds[0] + bounds[1]) / 2.0; - center[1] = (bounds[2] + bounds[3]) / 2.0; - center[2] = (bounds[4] + bounds[5]) / 2.0; - - double vn[3]; - this->ZSpaceCamera->GetViewPlaneNormal(vn); - - this->ZSpaceCamera->SetViewUp(viewUp[0], viewUp[1], viewUp[2]); - this->ZSpaceCamera->SetFocalPoint(center[0], center[1], center[2]); - this->ZSpaceCamera->SetPosition(center[0] + vn[0] * position[0], center[1] + vn[1] * position[1], - center[2] + vn[2] * position[2]); - - // Set the near and far clip depending on the vtk clipping range and the viewer scale - this->GetRenderer()->ResetCameraClippingRange(bounds); - double clippingRange[2]; - this->ZSpaceCamera->GetClippingRange(clippingRange); - - const float viewerScale = sdkManager->GetViewerScale(); - const float nearPlane = 0.5 * clippingRange[0] / viewerScale; - const float farPlane = 5.0 * clippingRange[1] / viewerScale; - - // Give the near and far plane to zSpace SDK - sdkManager->SetClippingRange(nearPlane, farPlane); - - // Check every actors. In case of a surface with edges representation, - // modify the unit of the offset of edges depending on the viewer scale. - // Depending on the Z orientation of the camera, the unit is positive or negative - const double* orientation = this->ZSpaceCamera->GetOrientation(); - const double sign = orientation[2] < 0 ? -1 : 1; - vtkActor* actor; - vtkActorCollection* actorCollection = this->GetRenderer()->GetActors(); - vtkCollectionSimpleIterator ait; for (actorCollection->InitTraversal(ait); (actor = actorCollection->GetNextActor(ait));) { - if (actor->GetProperty()->GetRepresentation() == VTK_SURFACE) - { - actor->GetMapper()->SetResolveCoincidentTopologyLineOffsetParameters( - 0, sign * 4 / viewerScale); - } + actor->SetUserTransform(identity); } } @@ -197,11 +145,10 @@ void vtkPVZSpaceView::Render(bool interactive, bool skip_rendering) if (!this->GetMakingSelection()) { - vtkZSpaceRenderWindowInteractor::SafeDownCast(this->Interactor)->HandleInteractions(); + vtkZSpaceRenderWindowInteractor::SafeDownCast(this->Interactor)->ProcessEvents(); } this->Superclass::Render(interactive, skip_rendering || this->GetMakingSelection()); - sdkManager->EndFrame(); } @@ -227,57 +174,11 @@ void vtkPVZSpaceView::SetInterPupillaryDistance(float interPupillaryDistance) //------------------------------------------------------------------------------ void vtkPVZSpaceView::SetDrawStylus(bool drawStylus) { - this->DrawStylus = drawStylus; - this->StylusRayActor->SetVisibility(this->DrawStylus); + this->StylusRayActor->SetVisibility(drawStylus); } //------------------------------------------------------------------------------ void vtkPVZSpaceView::SetInteractivePicking(bool interactivePicking) { - this->ZSpaceInteractorStyle->SetInteractivePicking(interactivePicking); -} - -//------------------------------------------------------------------------------ -void vtkPVZSpaceView::SelectWithRay(const double p0[3]) -{ - // Change the camera to disable projection/view matrix of zSpace - // To make sure the picked point will be at the middle of the viewport - vtkNew defaultCamera; - this->GetRenderer()->SetActiveCamera(defaultCamera); - - // Set the camera in the ray direction to select the middle of the - // viewport - vtkTransform* rayTransform = vtkZSpaceSDKManager::GetInstance()->GetStylusTransformRowMajor(); - - double pin[4] = { 0.0, 0.0, 1.0, 1.0 }; - double dop[4]; - rayTransform->MultiplyPoint(pin, dop); - - for (int i = 0; i < 3; ++i) - { - dop[i] = dop[i] / dop[3]; - } - vtkMath::Normalize(dop); - - // An actor should already be picked so get the length - // between the origin of the ray and the picked actor - double rayLength = this->StylusRayActor->GetLength(); - - defaultCamera->SetPosition(p0); - defaultCamera->SetFocalPoint( - p0[0] + dop[0] * rayLength, p0[1] + dop[1] * rayLength, p0[2] + dop[2] * rayLength); - defaultCamera->OrthogonalizeViewUp(); - - // Make sure the picked cell/point is not clipped - defaultCamera->SetClippingRange(0.5 * rayLength, 2.0 * rayLength); - - int* size = this->GetRenderer()->GetSize(); - // pick at the middle - int region[4] = { size[0] / 2, size[1] / 2, size[0] / 2, size[1] / 2 }; - - this->Selector->Modified(); - this->Select(this->PickingFieldAssociation, region); - - // Reset to zSpace camera - this->GetRenderer()->SetActiveCamera(this->ZSpaceCamera); + this->ZSpaceInteractorStyle->SetHoverPick(interactivePicking); } diff --git a/Plugins/ZSpace/zSpace/vtkPVZSpaceView.h b/Plugins/ZSpace/zSpace/vtkPVZSpaceView.h index d0904996a6e..03b463d9fff 100644 --- a/Plugins/ZSpace/zSpace/vtkPVZSpaceView.h +++ b/Plugins/ZSpace/zSpace/vtkPVZSpaceView.h @@ -23,25 +23,6 @@ * This view is designed to work on full screen (or in a cave display). * * This only works on Windows as the zSpace SDK is only available on this OS. - * - * This class uses the singleton class vtkZSpaceSDKManager object to communicate with the zSpace SDK - * : - * - get the camera view and projection matrix from the zSpace sdk and give it to the - * actual camera - * - handle interactions by getting stylus state from zSpace sdk and invoking event for the zSpace - * interactor style. - * Notice that the interactor style responds to a Button3DEvent or Move3DEvent, so - * the EventDataDevice3D device, input and action need to be set for each action. - * Here is the list of associations ( in the format Device + Input + Action ) : - * - MiddleButton of the stylus : GenericTracker + Trigger + Press/Release - * - RightButton of the stylus : RightController + Trigger + Press/Release - * - LeftButton of the stylus : LeftController + Trigger + Press/Release - * - * Please refer to vtkZSpaceInteractorStyle to know what are the possible interactions. - * - * Notice that this PVView stores the current/last world event position and orientation - * to simulate the RenderWindowInteractor3D behavior, as ParaView doesn't support - * a RenderWindowInteractor3D for instance. This should be removed when this feature is supported. */ #ifndef vtkPVZSpaceView_h @@ -53,11 +34,9 @@ #include "vtkZSpaceViewModule.h" // for export macro class vtkZSpaceInteractorStyle; -class vtkZSpaceSDKManager; class vtkZSpaceRayActor; -class vtkProp3D; -class vtkEventDataDevice3D; class vtkZSpaceCamera; +class vtkZSpaceRenderer; class VTKZSPACEVIEW_EXPORT vtkPVZSpaceView : public vtkPVRenderView { @@ -67,7 +46,7 @@ class VTKZSPACEVIEW_EXPORT vtkPVZSpaceView : public vtkPVRenderView void PrintSelf(ostream& os, vtkIndent indent) override; /** - * Called when a ResetCameraEvent is fired. Call zSpaceSDKManager::CalculateFit + * Called when a ResetCameraEvent is fired. Call zSpaceSDKManager::CalculateFrustumFit * to update the viewer scale, near and far plane given by the zSpace SDK. */ void ResetCamera(); @@ -87,28 +66,18 @@ class VTKZSPACEVIEW_EXPORT vtkPVZSpaceView : public vtkPVRenderView void SetInterPupillaryDistance(float); /** - * If true, perform picking every frame + * If true, perform picking every frame to update the stylus ray length each frame. * Delegate to zSpaceInteractorStyle. - * Default is true. */ void SetInteractivePicking(bool); /** - * Draw or not the ray stylus + * Draw or not the ray stylus. * Delegate to zSpace renderer. * Default is true. */ void SetDrawStylus(bool); - /** - * Perform an hardware picking with a ray defined by the ZSpaceSDKManager - * ray transform. Configure the camera to be at the origin of the - * ray, looking in the direction of the ray, and pick the center of - * the viewport. - * Restore previous camera settings at the end. - */ - void SelectWithRay(const double pos[3]); - ///@{ /** * Select the field association used when picking. @@ -134,32 +103,26 @@ class VTKZSPACEVIEW_EXPORT vtkPVZSpaceView : public vtkPVRenderView */ void Render(bool interactive, bool skip_rendering) override; - /** - * Give to the zSpace SDK the scene bounds to let it choose the best - * viewer scale, near and far clip. The camera position is set with the - * zSpace advised position. - */ - void CalculateFit(double* bounds); - /** * Override ResetCameraClippingRange to disable automatic clipping range * calculations of the camera as it is done by the zSpace SDK. */ void ResetCameraClippingRange() override{}; + /** + * Overriden to set a vtkZSpaceRenderWindowInteractor instance as interactor. + * The interactor in parameter is not used. + */ void SetupInteractor(vtkRenderWindowInteractor*) override; private: vtkPVZSpaceView(const vtkPVZSpaceView&) = delete; void operator=(const vtkPVZSpaceView&) = delete; - friend class vtkPVZSpaceViewInteractorStyle; - vtkNew ZSpaceInteractorStyle; vtkNew StylusRayActor; vtkNew ZSpaceCamera; - - bool DrawStylus = true; + vtkNew ZSpaceRenderer; // The field association used when picking with the ray int PickingFieldAssociation = vtkDataObject::FIELD_ASSOCIATION_POINTS; diff --git a/Plugins/ZSpace/zSpace/vtkZSpaceCamera.cxx b/Plugins/ZSpace/zSpace/vtkZSpaceCamera.cxx deleted file mode 100644 index 15c61d4b565..00000000000 --- a/Plugins/ZSpace/zSpace/vtkZSpaceCamera.cxx +++ /dev/null @@ -1,60 +0,0 @@ -/*========================================================================= - -Program: Visualization Toolkit -Module: vtkZSpaceCamera.cxx - -Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen -All rights reserved. -See Copyright.txt or http://www.kitware.com/Copyright.htm for details. - -This software is distributed WITHOUT ANY WARRANTY; without even -the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -PURPOSE. See the above copyright notice for more information. - -=========================================================================*/ -#include "vtkZSpaceCamera.h" - -#include "vtkMatrix4x4.h" -#include "vtkObjectFactory.h" -#include "vtkPerspectiveTransform.h" -#include "vtkTransform.h" -#include "vtkZSpaceSDKManager.h" - -vtkStandardNewMacro(vtkZSpaceCamera); - -//---------------------------------------------------------------------------- -void vtkZSpaceCamera::PrintSelf(ostream& os, vtkIndent indent) -{ - this->Superclass::PrintSelf(os, indent); -} - -//------------------------------------------------------------------------------ -vtkMatrix4x4* vtkZSpaceCamera::GetModelViewTransformMatrix() -{ - vtkZSpaceSDKManager* sdkManager = vtkZSpaceSDKManager::GetInstance(); - - vtkMatrix4x4* zSpaceViewMatrix = this->GetStereo() - ? sdkManager->GetStereoViewMatrix(this->GetLeftEye()) - : sdkManager->GetCenterEyeViewMatrix(); - - this->ViewTransform->SetMatrix(zSpaceViewMatrix); - - this->Transform->Identity(); - this->Transform->SetupCamera(this->Position, this->FocalPoint, this->ViewUp); - - this->ViewTransform->Concatenate(this->Transform->GetMatrix()); - - return this->ViewTransform->GetMatrix(); -} - -//------------------------------------------------------------------------------ -vtkMatrix4x4* vtkZSpaceCamera::GetProjectionTransformMatrix( - double vtkNotUsed(aspect), double vtkNotUsed(nearz), double vtkNotUsed(farz)) -{ - vtkZSpaceSDKManager* sdkManager = vtkZSpaceSDKManager::GetInstance(); - - vtkMatrix4x4* zSpaceProjectionMatrix = this->GetStereo() - ? sdkManager->GetStereoProjectionMatrix(this->GetLeftEye()) - : sdkManager->GetCenterEyeProjectionMatrix(); - return zSpaceProjectionMatrix; -} diff --git a/Plugins/ZSpace/zSpace/vtkZSpaceCamera.h b/Plugins/ZSpace/zSpace/vtkZSpaceCamera.h deleted file mode 100644 index a054464f57a..00000000000 --- a/Plugins/ZSpace/zSpace/vtkZSpaceCamera.h +++ /dev/null @@ -1,56 +0,0 @@ -/*========================================================================= - -Program: Visualization Toolkit - -Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen -All rights reserved. -See Copyright.txt or http://www.kitware.com/Copyright.htm for details. - -This software is distributed WITHOUT ANY WARRANTY; without even -the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -PURPOSE. See the above copyright notice for more information. - -=========================================================================*/ -/** - * @class vtkZSpaceCamera - * @brief Extends vtkOpenGLCamera to use custom view and projection matrix given by zSpace SDK. - * - * This is needed to change the view / projection matrix during a render(), depending on the - * vtkCamera::LeftEye value (support for stereo). - */ - -#ifndef vtkZSpaceCamera_h -#define vtkZSpaceCamera_h - -#include "vtkOpenGLCamera.h" -#include "vtkZSpaceViewModule.h" // for export macro - -class vtkZSpaceSDKManager; - -class VTKZSPACEVIEW_EXPORT vtkZSpaceCamera : public vtkOpenGLCamera -{ -public: - static vtkZSpaceCamera* New(); - vtkTypeMacro(vtkZSpaceCamera, vtkOpenGLCamera); - void PrintSelf(ostream& os, vtkIndent indent) override; - - /** - * Return the model view matrix of model view transform given by zSpace SDK. - */ - vtkMatrix4x4* GetModelViewTransformMatrix() override; - - /** - * Return the projection transform matrix given by zSpace SDK. - */ - vtkMatrix4x4* GetProjectionTransformMatrix(double aspect, double nearz, double farz) override; - -protected: - vtkZSpaceCamera() = default; - ~vtkZSpaceCamera() override = default; - -private: - vtkZSpaceCamera(const vtkZSpaceCamera&) = delete; - void operator=(const vtkZSpaceCamera&) = delete; -}; - -#endif diff --git a/Plugins/ZSpace/zSpace/vtkZSpaceCoreCompatibilitySDKManager.cxx b/Plugins/ZSpace/zSpace/vtkZSpaceCoreCompatibilitySDKManager.cxx deleted file mode 100644 index 753d339928a..00000000000 --- a/Plugins/ZSpace/zSpace/vtkZSpaceCoreCompatibilitySDKManager.cxx +++ /dev/null @@ -1,515 +0,0 @@ - -/*========================================================================= - -Program: Visualization Toolkit -Module: vtkZSpaceCoreCompatibilitySDKManager.cxx - -Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen -All rights reserved. -See Copyright.txt or http://www.kitware.com/Copyright.htm for details. - -This software is distributed WITHOUT ANY WARRANTY; without even -the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -PURPOSE. See the above copyright notice for more information. - -=========================================================================*/ -#include "vtkZSpaceCoreCompatibilitySDKManager.h" - -#include "vtkBoundingBox.h" -#include "vtkGenericOpenGLRenderWindow.h" -#include "vtkMatrix4x4.h" -#include "vtkObjectFactory.h" -#include "vtkPVZSpaceView.h" -#include "vtkRenderWindow.h" -#include "vtkSmartPointer.h" -#include "vtkTransform.h" -#include "vtkVector.h" -#include "vtkVectorOperators.h" - -vtkStandardNewMacro(vtkZSpaceCoreCompatibilitySDKManager); - -#define ZSPACE_CHECK_ERROR(fn, error) \ - if (error != ZC_COMPAT_ERROR_OK) \ - { \ - std::string errorMessage = std::string("zSpace Core Compatibility API call \"") + \ - std::string(#fn) + \ - "\" failed with error " \ - "code " + \ - std::to_string(error) + "."; \ - vtkErrorMacro(<< "vtkZSpaceCoreCompatibilitySDKManager::" << #fn << " error : " << error); \ - } - -static const char* ZSPACE_CORE_COMPATIBILITY_DLL_FILE_PATH = "zSpaceCoreCompatibility" -#ifdef _WIN64 - "64" -#else - "32" -#endif - ; - -//------------------------------------------------------------------------------ -vtkZSpaceCoreCompatibilitySDKManager::vtkZSpaceCoreCompatibilitySDKManager() -{ - this->InitializeZSpace(); -} - -//------------------------------------------------------------------------------ -vtkZSpaceCoreCompatibilitySDKManager::~vtkZSpaceCoreCompatibilitySDKManager() -{ - ZCCompatError error; - - error = this->EntryPts.zccompatDestroyViewport(this->ViewportHandle); - ZSPACE_CHECK_ERROR(zccompatDestroyViewport, error); - - error = this->EntryPts.zccompatShutDown(this->ZSpaceContext); - ZSPACE_CHECK_ERROR(zccompatShutDown, error); -} - -//------------------------------------------------------------------------------ -bool vtkZSpaceCoreCompatibilitySDKManager::loadZspaceCoreCompatibilityEntryPoints( - const char* zSpaceCoreCompatDllFilePath, HMODULE& dllModuleHandle, - zSpaceCoreCompatEntryPoints& entryPoints) -{ - dllModuleHandle = LoadLibraryA(zSpaceCoreCompatDllFilePath); - - if (dllModuleHandle == nullptr) - { - // If the release variant of the zSpace Core Compatibility API DLL - // could not be loaded, attempt to the debug variant instead. - - std::string zSpaceCoreCompatDllDebugFilePath(zSpaceCoreCompatDllFilePath); - zSpaceCoreCompatDllDebugFilePath.append("_D"); - - dllModuleHandle = LoadLibraryA(zSpaceCoreCompatDllDebugFilePath.c_str()); - - if (dllModuleHandle == nullptr) - { - vtkErrorMacro(<< "Win32 Error : " - << "Failed to load zSpace Core Compatibility API DLL."); - - return false; - } - } - -#define ZC_COMPAT_SAMPLE_LOCAL_LOAD_ENTRY_POINT(undecoratedFuncName) \ - { \ - void* entryPointProcAddress = \ - GetProcAddress(dllModuleHandle, "zccompat" #undecoratedFuncName); \ - \ - if (entryPointProcAddress == nullptr) \ - { \ - vtkErrorMacro(<< "Win32 Error : " \ - << "Failed to get zSpace Core Compatibility entry point " \ - << "proc address for entry point " \ - << "\"zccompat" << #undecoratedFuncName << "\"."); \ - \ - return false; \ - } \ - \ - entryPoints.zccompat##undecoratedFuncName = \ - reinterpret_cast(entryPointProcAddress); \ - } \ - /**/ - - ZC_COMPAT_REFLECTION_LIST_UNDECORATED_FUNC_NAMES(ZC_COMPAT_SAMPLE_LOCAL_LOAD_ENTRY_POINT) - -#undef ZC_COMPAT_SAMPLE_LOCAL_LOAD_ENTRY_POINT - - return true; -} - -//------------------------------------------------------------------------------ -void vtkZSpaceCoreCompatibilitySDKManager::InitializeZSpace() -{ - const bool didSucceed = loadZspaceCoreCompatibilityEntryPoints( - ZSPACE_CORE_COMPATIBILITY_DLL_FILE_PATH, this->zSpaceCoreCompatDllModuleHandle, this->EntryPts); - - if (!didSucceed) - { - vtkErrorMacro("Unable to load the SDK functions entry points."); - return; - } - - ZCCompatError error; - - // Initialize the zSpace SDK. This MUST be called before - // calling any other zSpace API. - error = this->EntryPts.zccompatInitialize(nullptr, nullptr, &this->ZSpaceContext); - ZSPACE_CHECK_ERROR(zccompatInitialize, error); - - // Check the SDK version - ZSInt32 major, minor, patch; - error = this->EntryPts.zccompatGetRuntimeVersion(this->ZSpaceContext, &major, &minor, &patch); - ZSPACE_CHECK_ERROR(zccompatGetRuntimeVersion, error); - - vtkDebugMacro(<< "zSpace SDK version: " << major << "." << minor << "." << patch); - - int numDisplays; - error = this->EntryPts.zccompatGetNumDisplays(this->ZSpaceContext, &numDisplays); - - this->Displays.reserve(numDisplays); - - for (int i = 0; i < numDisplays; i++) - { - ZCCompatDisplay displayHandle; - error = this->EntryPts.zccompatGetDisplayByIndex(this->ZSpaceContext, i, &displayHandle); - ZSPACE_CHECK_ERROR(zccompatGetDisplayByIndex, error); - - ZCCompatDisplayType displayType; - error = this->EntryPts.zccompatGetDisplayType(displayHandle, &displayType); - ZSPACE_CHECK_ERROR(zccompatGetDisplayType, error); - - switch (displayType) - { - case ZC_COMPAT_DISPLAY_TYPE_GENERIC: - this->Displays.push_back("Generic"); - break; - case ZC_COMPAT_DISPLAY_TYPE_ZSPACE: - this->Displays.push_back("ZSpace"); - break; - default: - this->Displays.push_back("Unknown"); - break; - } - } - - // Retrieve the zSpace primary viewport object and grab its associated frustum. - // Note: The zSpace viewport is abstract and not an actual window/viewport - // that is created and registered through the Windows OS. It manages - // a zSpace stereo frustum, which is responsible for various stereoscopic - // 3D calculations such as calculating the view and projection matrices for - // each eye. - error = this->EntryPts.zccompatGetPrimaryViewport(this->ZSpaceContext, &this->ViewportHandle); - ZSPACE_CHECK_ERROR(zccompatCreateViewport, error); - - error = this->EntryPts.zccompatGetFrustum(this->ViewportHandle, &this->FrustumHandle); - ZSPACE_CHECK_ERROR(zccompatGetFrustum, error); - - // Enable auto stereo. - error = this->EntryPts.zccompatSetFrustumAttributeB( - this->FrustumHandle, ZC_COMPAT_FRUSTUM_ATTRIBUTE_AUTO_STEREO_ENABLED, true); - ZSPACE_CHECK_ERROR(zccompatSetFrustumAttributeB, error); - error = this->EntryPts.zccompatSetFrustumAttributeF32( - this->FrustumHandle, ZC_COMPAT_FRUSTUM_ATTRIBUTE_IPD, this->InterPupillaryDistance); - ZSPACE_CHECK_ERROR(zccompatSetFrustumAttributeF32, error); - error = this->EntryPts.zccompatSetFrustumAttributeF32( - this->FrustumHandle, ZC_COMPAT_FRUSTUM_ATTRIBUTE_HEAD_SCALE, 1.f); - ZSPACE_CHECK_ERROR(zccompatSetFrustumAttributeF32, error); - - // Disable the portal mode - error = this->EntryPts.zccompatSetFrustumPortalMode(this->FrustumHandle, 0); - ZSPACE_CHECK_ERROR(zccompatSetFrustumPortalMode, error); - - error = this->EntryPts.zccompatGetNumTargetsByType( - this->ZSpaceContext, ZC_COMPAT_TARGET_TYPE_PRIMARY, &this->StylusTargets); - ZSPACE_CHECK_ERROR(zccompatGetNumTargetsByType, error); - - error = this->EntryPts.zccompatGetNumTargetsByType( - this->ZSpaceContext, ZC_COMPAT_TARGET_TYPE_HEAD, &this->HeadTargets); - ZSPACE_CHECK_ERROR(zccompatGetNumTargetsByType, error); - - error = this->EntryPts.zccompatGetNumTargetsByType( - this->ZSpaceContext, ZC_COMPAT_TARGET_TYPE_SECONDARY, &this->SecondaryTargets); - ZSPACE_CHECK_ERROR(zccompatGetNumTargetsByType, error); - - // Grab a handle to the stylus target. - error = this->EntryPts.zccompatGetTargetByType( - this->ZSpaceContext, ZC_COMPAT_TARGET_TYPE_PRIMARY, 0, &this->StylusHandle); - ZSPACE_CHECK_ERROR(zccompatGetTargetByType, error); - - // Find the zSpace display and set the window position - // to be the top left corner of the zSpace display. - error = this->EntryPts.zccompatGetDisplayByType( - this->ZSpaceContext, ZC_COMPAT_DISPLAY_TYPE_ZSPACE, 0, &this->DisplayHandle); - ZSPACE_CHECK_ERROR(zccompatGetDisplayByType, error); - - error = - this->EntryPts.zccompatGetDisplayPosition(this->DisplayHandle, &this->WindowX, &this->WindowY); - ZSPACE_CHECK_ERROR(zccompatGetDisplayPosition, error); - - error = this->EntryPts.zccompatGetDisplayNativeResolution( - this->DisplayHandle, &this->WindowWidth, &this->WindowHeight); - ZSPACE_CHECK_ERROR(zccompatGetDisplayNativeResolution, error); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceCoreCompatibilitySDKManager::UpdateViewport() -{ - if (!this->RenderWindow) - { - vtkErrorMacro("No render window has been set to the zSpace SDK manager !"); - return; - } - - int* position = this->RenderWindow->GetPosition(); - int* size = this->RenderWindow->GetSize(); - - ZCCompatError error; - - error = - this->EntryPts.zccompatSetViewportPosition(this->ViewportHandle, position[0], position[1]); - ZSPACE_CHECK_ERROR(zccompatSetViewportPosition, error); - error = this->EntryPts.zccompatSetViewportSize(this->ViewportHandle, size[0], size[1]); - ZSPACE_CHECK_ERROR(zccompatSetViewportSize, error); - - // Update inter pupillary distance - error = this->EntryPts.zccompatSetFrustumAttributeF32( - this->FrustumHandle, ZC_COMPAT_FRUSTUM_ATTRIBUTE_IPD, this->InterPupillaryDistance); - ZSPACE_CHECK_ERROR(zccompatSetFrustumAttributeF32, error); - - // Near and far plane - error = this->EntryPts.zccompatSetFrustumAttributeF32( - this->FrustumHandle, ZC_COMPAT_FRUSTUM_ATTRIBUTE_NEAR_CLIP, this->NearPlane); - ZSPACE_CHECK_ERROR(zccompatSetFrustumAttributeF32, error); - error = this->EntryPts.zccompatSetFrustumAttributeF32( - this->FrustumHandle, ZC_COMPAT_FRUSTUM_ATTRIBUTE_FAR_CLIP, this->FarPlane); - ZSPACE_CHECK_ERROR(zccompatSetFrustumAttributeF32, error); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceCoreCompatibilitySDKManager::UpdateTrackers() -{ - ZCCompatError error; - - // Update the zSpace SDK. This updates both tracking information - // as well as the head poses for any frustums that have been created. - error = this->EntryPts.zccompatUpdate(this->ZSpaceContext); - ZSPACE_CHECK_ERROR(zccompatUpdate, error); - - // Update the stylus matrix - ZCCompatTrackerPose stylusPose; - error = this->EntryPts.zccompatGetTargetPose(this->StylusHandle, &stylusPose); - ZSPACE_CHECK_ERROR(zccompatGetTargetPose, error); - error = - this->EntryPts.zccompatTransformMatrix(this->ViewportHandle, ZC_COMPAT_COORDINATE_SPACE_TRACKER, - ZC_COMPAT_COORDINATE_SPACE_CAMERA, &stylusPose.matrix); // Manual transfo added - ZSPACE_CHECK_ERROR(zccompatGetTargetPose, error); - - this->ConvertZSpaceMatrixToVTKMatrix(stylusPose.matrix, this->StylusMatrixColMajor); - - // The stylus direction is the normalized negative Z axis of the pose - this->StylusMatrixColMajor->SetElement(2, 0, -this->StylusMatrixColMajor->GetElement(2, 0)); - this->StylusMatrixColMajor->SetElement(2, 1, -this->StylusMatrixColMajor->GetElement(2, 1)); - this->StylusMatrixColMajor->SetElement(2, 2, -this->StylusMatrixColMajor->GetElement(2, 2)); - - vtkNew invView; - vtkMatrix4x4::Invert(this->CenterEyeViewMatrix.GetPointer(), invView); - - // Convert from camera space to world space - vtkMatrix4x4::Multiply4x4(invView, this->StylusMatrixColMajor, this->StylusMatrixColMajor); - - // Transpose the matrix to be used by VTK - vtkMatrix4x4::Transpose(this->StylusMatrixColMajor, this->StylusMatrixRowMajor); - - this->StylusTransformRowMajor->SetMatrix(this->StylusMatrixRowMajor); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceCoreCompatibilitySDKManager::UpdateViewAndProjectionMatrix() -{ - ZCCompatError error; - - // Update the view matrix for each eye - ZSMatrix4 zccompatViewMatrix; - error = this->EntryPts.zccompatGetFrustumViewMatrix( - this->FrustumHandle, ZC_COMPAT_EYE_CENTER, &zccompatViewMatrix); - ZSPACE_CHECK_ERROR(zccompatGetFrustumViewMatrix, error); - this->ConvertAndTransposeZSpaceMatrixToVTKMatrix(zccompatViewMatrix, this->CenterEyeViewMatrix); - - error = this->EntryPts.zccompatGetFrustumViewMatrix( - this->FrustumHandle, ZC_COMPAT_EYE_LEFT, &zccompatViewMatrix); - ZSPACE_CHECK_ERROR(zccompatGetFrustumViewMatrix, error); - this->ConvertAndTransposeZSpaceMatrixToVTKMatrix(zccompatViewMatrix, this->LeftEyeViewMatrix); - - error = this->EntryPts.zccompatGetFrustumViewMatrix( - this->FrustumHandle, ZC_COMPAT_EYE_RIGHT, &zccompatViewMatrix); - ZSPACE_CHECK_ERROR(zccompatGetFrustumViewMatrix, error); - this->ConvertAndTransposeZSpaceMatrixToVTKMatrix(zccompatViewMatrix, this->RightEyeViewMatrix); - - // Update the projection matrix for each eye - ZSMatrix4 zccompatProjectionMatrix; - error = this->EntryPts.zccompatGetFrustumProjectionMatrix( - this->FrustumHandle, ZC_COMPAT_EYE_CENTER, &zccompatProjectionMatrix); - ZSPACE_CHECK_ERROR(zccompatGetFrustumProjectionMatrix, error); - this->ConvertAndTransposeZSpaceMatrixToVTKMatrix( - zccompatProjectionMatrix, this->CenterEyeProjectionMatrix); - - error = this->EntryPts.zccompatGetFrustumProjectionMatrix( - this->FrustumHandle, ZC_COMPAT_EYE_LEFT, &zccompatProjectionMatrix); - ZSPACE_CHECK_ERROR(zccompatGetFrustumProjectionMatrix, error); - this->ConvertAndTransposeZSpaceMatrixToVTKMatrix( - zccompatProjectionMatrix, this->LeftEyeProjectionMatrix); - - error = this->EntryPts.zccompatGetFrustumProjectionMatrix( - this->FrustumHandle, ZC_COMPAT_EYE_RIGHT, &zccompatProjectionMatrix); - ZSPACE_CHECK_ERROR(zccompatGetFrustumProjectionMatrix, error); - this->ConvertAndTransposeZSpaceMatrixToVTKMatrix( - zccompatProjectionMatrix, this->RightEyeProjectionMatrix); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceCoreCompatibilitySDKManager::UpdateButtonState() -{ - ZSBool isButtonPressed; - - for (int buttonId = vtkZSpaceSDKManager::MiddleButton; - buttonId < vtkZSpaceSDKManager::NumberOfButtons; ++buttonId) - { - this->EntryPts.zccompatIsTargetButtonPressed(this->StylusHandle, buttonId, &isButtonPressed); - - ButtonState& buttonState = *this->ButtonsState[buttonId]; - buttonState = isButtonPressed - ? buttonState != vtkZSpaceSDKManager::Pressed ? vtkZSpaceSDKManager::Down - : vtkZSpaceSDKManager::Pressed - : buttonState != vtkZSpaceSDKManager::None ? vtkZSpaceSDKManager::Up - : vtkZSpaceSDKManager::None; - } -} - -//------------------------------------------------------------------------------ -void vtkZSpaceCoreCompatibilitySDKManager::CalculateFrustumFit( - const double bounds[6], double position[3], double viewUp[3]) -{ - ZCCompatError error; - - vtkBoundingBox bBox; - bBox.SetBounds(bounds); - - // Expand the bounding box a little bit to make sure the object is not clipped - bBox.Scale(1.25, 1.25, 1.25); - - // Retrieve viewport size (pixels) - ZSInt32 viewportResWidth = 0; - ZSInt32 viewportResHeight = 0; - error = this->EntryPts.zccompatGetViewportSize( - this->ViewportHandle, &viewportResWidth, &viewportResHeight); - ZSPACE_CHECK_ERROR(zccompatGetViewportSize, error); - - // Retrieve display size (meters) - ZSFloat displayWidth = 0.0f; - ZSFloat displayHeight = 0.0f; - error = this->EntryPts.zccompatGetDisplaySize(this->DisplayHandle, &displayWidth, &displayHeight); - ZSPACE_CHECK_ERROR(zccompatGetViewportSize, error); - - // Retrieve display resolution - ZSInt32 displayResWidth = 0; - ZSInt32 displayResHeight = 0; - error = this->EntryPts.zccompatGetDisplayNativeResolution( - this->DisplayHandle, &displayResWidth, &displayResHeight); - - // Retrieve coupled zone maximum depth value for positive parallax - ZSFloat ppMaxDepth = 0.0f; - error = this->EntryPts.zccompatGetFrustumAttributeF32( - this->FrustumHandle, ZC_COMPAT_FRUSTUM_ATTRIBUTE_UC_DEPTH, &ppMaxDepth); - ZSPACE_CHECK_ERROR(zccompatGetViewportSize, error); - - // Retrieve coupled zone maximum depth value for negative parallax - ZSFloat npMaxDepth = 0.0f; - error = this->EntryPts.zccompatGetFrustumAttributeF32( - this->FrustumHandle, ZC_COMPAT_FRUSTUM_ATTRIBUTE_CC_DEPTH, &npMaxDepth); - ZSPACE_CHECK_ERROR(zccompatGetViewportSize, error); - - // Compute viewport size in meters - float viewportWidth = (static_cast(viewportResWidth) / displayResWidth) * displayWidth; - float viewportHeight = (static_cast(viewportResHeight) / displayResHeight) * displayHeight; - - double length[3] = { 0, 0, 0 }; - bBox.GetLengths(length); - - // Compute viewer scale as the maximum of widthScale, heightScale, and depthScale. - double widthScale = length[0] / viewportWidth; - double heightScale = length[1] / viewportHeight; - double depthScale = length[2] / (npMaxDepth - ppMaxDepth); - - this->ViewerScale = std::max({ depthScale, widthScale, heightScale }); - - // Get frustum's camera offset (distance to world center) - ZSVector3 zsCameraOffset = { 0.0, 0.0, 0.0 }; - error = this->EntryPts.zccompatGetFrustumCameraOffset(this->FrustumHandle, &zsCameraOffset); - ZSPACE_CHECK_ERROR(zccompatGetFrustumCameraOffset, error); - - // Compute new frustum's camera viewUp and position - double center[3] = { 0.0, 0.0, 0.0 }; - bBox.GetCenter(center); - - vtkVector3d worldCenter = { center[0], center[1], center[2] }; - vtkVector3d cameraOffset = { zsCameraOffset.x, zsCameraOffset.y, zsCameraOffset.z }; - vtkVector3d cameraForward = cameraOffset.Normalized(); - vtkVector3d cameraRight = { 1.0f, 0.0f, 0.0f }; - vtkVector3d cameraUp = cameraRight.Cross(-cameraForward); - vtkVector3d cameraPosition = - worldCenter + (cameraForward * cameraOffset.Norm() * this->ViewerScale); - - viewUp[0] = cameraUp.GetX(); - viewUp[1] = cameraUp.GetY(); - viewUp[2] = cameraUp.GetZ(); - - position[0] = cameraPosition.GetX(); - position[1] = cameraPosition.GetY(); - position[2] = cameraPosition.GetZ(); - - // Set the frustum's viewer scale with the value that was calculated. - error = this->EntryPts.zccompatSetFrustumAttributeF32( - this->FrustumHandle, ZC_COMPAT_FRUSTUM_ATTRIBUTE_VIEWER_SCALE, this->ViewerScale); - ZSPACE_CHECK_ERROR(zccompatGetFrustumCameraOffset, error); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceCoreCompatibilitySDKManager::BeginFrame() -{ - ZCCompatError error = this->EntryPts.zccompatBeginFrame(this->ZSpaceContext); - ZSPACE_CHECK_ERROR(zccompatBeginFrame, error); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceCoreCompatibilitySDKManager::EndFrame() -{ - ZCCompatError error = this->EntryPts.zccompatEndFrame(this->ZSpaceContext); - ZSPACE_CHECK_ERROR(zccompatEndFrame, error); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceCoreCompatibilitySDKManager::SetRenderWindow(vtkRenderWindow* renderWindow) -{ - auto* rw = vtkGenericOpenGLRenderWindow::SafeDownCast(renderWindow); - if (!rw) - { - vtkErrorMacro("Unable to set the zSpace Core Compatbility SDK Render Window:" - "unable to cast it to vtkGenericOpenGLRenderWindow."); - return; - } - - // Give the application window handle to the zSpace Core Compatibilty API. - HWND hWnd = static_cast(rw->GetGenericWindowId()); - ZCCompatError error = - this->EntryPts.zccompatSetApplicationWindowHandle(this->ZSpaceContext, hWnd); - ZSPACE_CHECK_ERROR(zccompatSetApplicationWindowHandle, error); - - vtkZSpaceSDKManager::SetRenderWindow(renderWindow); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceCoreCompatibilitySDKManager::ConvertAndTransposeZSpaceMatrixToVTKMatrix( - ZSMatrix4 zSpaceMatrix, vtkMatrix4x4* vtkMatrix) -{ - for (int i = 0; i < 16; ++i) - { - vtkMatrix->SetElement(i % 4, i / 4, zSpaceMatrix.f[i]); - } -} - -//------------------------------------------------------------------------------ -void vtkZSpaceCoreCompatibilitySDKManager::ConvertZSpaceMatrixToVTKMatrix( - ZSMatrix4 zSpaceMatrix, vtkMatrix4x4* vtkMatrix) -{ - for (int i = 0; i < 16; ++i) - { - vtkMatrix->SetElement(i / 4, i % 4, zSpaceMatrix.f[i]); - } -} - -//------------------------------------------------------------------------------ -void vtkZSpaceCoreCompatibilitySDKManager::PrintSelf(ostream& os, vtkIndent indent) -{ - this->Superclass::PrintSelf(os, indent); -} diff --git a/Plugins/ZSpace/zSpace/vtkZSpaceCoreCompatibilitySDKManager.h b/Plugins/ZSpace/zSpace/vtkZSpaceCoreCompatibilitySDKManager.h deleted file mode 100644 index 03a92fe284b..00000000000 --- a/Plugins/ZSpace/zSpace/vtkZSpaceCoreCompatibilitySDKManager.h +++ /dev/null @@ -1,156 +0,0 @@ -/*========================================================================= - -Program: Visualization Toolkit - -Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen -All rights reserved. -See Copyright.txt or http://www.kitware.com/Copyright.htm for details. - -This software is distributed WITHOUT ANY WARRANTY; without even -the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -PURPOSE. See the above copyright notice for more information. - -=========================================================================*/ -/** - * @class vtkZSpaceCoreCompatibilitySDKManager - * @brief zSpace Core Compatibility SDK manager class. - * - * Class handling the interactions between the zSpace plugin - * and the zSpace Core Compatibility SDK. - * - * @see vtkZSpaceSDKManager - */ - -#ifndef vtkZSpaceCoreCompatibilitySDKManager_h -#define vtkZSpaceCoreCompatibilitySDKManager_h - -#include "vtkZSpaceSDKManager.h" -#include "vtkZSpaceViewModule.h" // for export macro - -#include // for HMODULE -#include // for std::vector -#include // zspace header - -/** - * Structure holding the loaded zSpace Core Compatibility - * API entry point function pointers - */ -struct zSpaceCoreCompatEntryPoints -{ - // Use the zSpace Core Compatibilty API function name reflection macro to - // auto-generate function pointer members for all zSpace Core Compatibility - // API entry point functions. - -#define ZC_COMPAT_SAMPLE_LOCAL_ENTRY_POINT_MEMBER(undecoratedFuncName) \ - ZCCompat##undecoratedFuncName##FuncPtrType zccompat##undecoratedFuncName; \ - /**/ - - ZC_COMPAT_REFLECTION_LIST_UNDECORATED_FUNC_NAMES(ZC_COMPAT_SAMPLE_LOCAL_ENTRY_POINT_MEMBER) - -#undef ZC_COMPAT_SAMPLE_LOCAL_ENTRY_POINT_MEMBER -}; - -class vtkRenderWindow; -class vtkMatrix4x4; - -class VTKZSPACEVIEW_EXPORT vtkZSpaceCoreCompatibilitySDKManager : public vtkZSpaceSDKManager -{ -public: - static vtkZSpaceCoreCompatibilitySDKManager* New(); - vtkTypeMacro(vtkZSpaceCoreCompatibilitySDKManager, vtkObject); - void PrintSelf(ostream& os, vtkIndent indent) override; - - /** - * Initialize the zSpace SDK and check for zSpace devices : - * the display, the stylus and the head trackers. - */ - void InitializeZSpace() override; - - /** - * Update the zSpace viewport position and size based - * on the position and size of the application window. - */ - void UpdateViewport() override; - - /** - * Update the position of the stylus and head trakers. - */ - void UpdateTrackers() override; - - /** - * Update the zSpace view and projection matrix for each eye. - */ - void UpdateViewAndProjectionMatrix() override; - - /** - * Update the stylus buttons state. - */ - void UpdateButtonState() override; - - /** - * Let zSpace compute the viewer scale, camera position and camera view up from the - * input bounds. - */ - void CalculateFrustumFit(const double bounds[6], double position[3], double viewUp[3]) override; - - ///@{ - /** - * Notify the zSpace SDK for the begining/end of a frame. - */ - void BeginFrame() override; - void EndFrame() override; - ///@} - - ///@{ - /** - * Set the render windwow the manager makes viewport computations - * from. Overriden to pass the related Windows window handle to - * the SDK. - */ - void SetRenderWindow(vtkRenderWindow*) override; - ///@} - -protected: - vtkZSpaceCoreCompatibilitySDKManager(); - ~vtkZSpaceCoreCompatibilitySDKManager() override; - - ZCCompatContext ZSpaceContext = nullptr; - ZCCompatDisplay DisplayHandle = nullptr; - ZCCompatViewport ViewportHandle = nullptr; - ZCCompatFrustum FrustumHandle = nullptr; - ZCCompatTarget StylusHandle = nullptr; - - // Store the API functions entry points. - zSpaceCoreCompatEntryPoints EntryPts; - - // Handle to the zSpace Core Compatibility API dynamic library (.dll). - HMODULE zSpaceCoreCompatDllModuleHandle; - - // Handle to the current window - HWND WidondowHandle; - - /** - * Load the "zSpaceCoreCompatibility64.dll" shared library then load the - * zSpace Core Compatibility API entry point functions (at runtime) - */ - bool loadZspaceCoreCompatibilityEntryPoints(const char* zSpaceCoreCompatDllFilePath, - HMODULE& zSpaceCoreCompatDllModuleHandle, zSpaceCoreCompatEntryPoints& entryPoints); - - /** - * zSpace stores matrix in column-major format (as OpenGL). The matrix - * needs to be transposed to be used by VTK. - */ - void ConvertAndTransposeZSpaceMatrixToVTKMatrix(ZSMatrix4 zSpaceMatrix, vtkMatrix4x4* vtkMatrix); - - /** - * zSpace stores matrix in column-major format (as OpenGL). The matrix - * needs to be transposed to be used by VTK. - */ - void ConvertZSpaceMatrixToVTKMatrix(ZSMatrix4 zSpaceMatrix, vtkMatrix4x4* vtkMatrix); - -private: - vtkZSpaceCoreCompatibilitySDKManager(const vtkZSpaceCoreCompatibilitySDKManager&) = delete; - void operator=(const vtkZSpaceCoreCompatibilitySDKManager&) = delete; -}; - -#endif diff --git a/Plugins/ZSpace/zSpace/vtkZSpaceCoreSDKManager.cxx b/Plugins/ZSpace/zSpace/vtkZSpaceCoreSDKManager.cxx deleted file mode 100644 index ca761e757ed..00000000000 --- a/Plugins/ZSpace/zSpace/vtkZSpaceCoreSDKManager.cxx +++ /dev/null @@ -1,360 +0,0 @@ -/*========================================================================= - -Program: Visualization Toolkit -Module: vtkZSpaceCoreSDKManager.cxx - -Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen -All rights reserved. -See Copyright.txt or http://www.kitware.com/Copyright.htm for details. - -This software is distributed WITHOUT ANY WARRANTY; without even -the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -PURPOSE. See the above copyright notice for more information. - -=========================================================================*/ -#include "vtkZSpaceCoreSDKManager.h" - -#include "vtkMatrix4x4.h" -#include "vtkObjectFactory.h" -#include "vtkPVZSpaceView.h" -#include "vtkRenderWindow.h" -#include "vtkSmartPointer.h" -#include "vtkTransform.h" - -vtkStandardNewMacro(vtkZSpaceCoreSDKManager); - -#define ZSPACE_CHECK_ERROR(fn, error) \ - if (error != ZC_ERROR_OK) \ - { \ - char errorString[256]; \ - zcGetErrorString(error, errorString, sizeof(errorString)); \ - vtkErrorMacro(<< "vtkZSpaceCoreSDKManager::" << #fn << " error : " << errorString); \ - } - -//------------------------------------------------------------------------------ -vtkZSpaceCoreSDKManager::vtkZSpaceCoreSDKManager() -{ - this->InitializeZSpace(); -} - -//------------------------------------------------------------------------------ -vtkZSpaceCoreSDKManager::~vtkZSpaceCoreSDKManager() -{ - ZCError error; - error = zcDestroyStereoBuffer(this->BufferHandle); - ZSPACE_CHECK_ERROR(zcDestroyStereoBuffer, error); - error = zcDestroyViewport(this->ViewportHandle); - ZSPACE_CHECK_ERROR(zcDestroyViewport, error); - error = zcShutDown(this->ZSpaceContext); - ZSPACE_CHECK_ERROR(zcShutDown, error); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceCoreSDKManager::InitializeZSpace() -{ - ZCError error; - - // Initialize the zSpace SDK. This MUST be called before - // calling any other zSpace API. - error = zcInitialize(&this->ZSpaceContext); - ZSPACE_CHECK_ERROR(zcInitialize, error); - - // Check the SDK version - ZSInt32 major, minor, patch; - error = zcGetRuntimeVersion(this->ZSpaceContext, &major, &minor, &patch); - ZSPACE_CHECK_ERROR(zcGetRuntimeVersion, error); - - vtkDebugMacro(<< "zSpace SDK version: " << major << "." << minor << "." << patch); - - int numDisplays; - error = zcGetNumDisplays(this->ZSpaceContext, &numDisplays); - - this->Displays.reserve(numDisplays); - - for (int i = 0; i < numDisplays; i++) - { - ZCHandle displayHandle; - error = zcGetDisplayByIndex(this->ZSpaceContext, i, &displayHandle); - ZSPACE_CHECK_ERROR(zcGetDisplayByIndex, error); - - ZCDisplayType displayType; - error = zcGetDisplayType(displayHandle, &displayType); - ZSPACE_CHECK_ERROR(zcGetDisplayType, error); - - switch (displayType) - { - case ZC_DISPLAY_TYPE_GENERIC: - this->Displays.push_back("Generic"); - break; - case ZC_DISPLAY_TYPE_ZSPACE: - this->Displays.push_back("ZSpace"); - break; - default: - this->Displays.push_back("Unknown"); - break; - } - } - - // Create a stereo buffer to handle L/R detection. - error = - zcCreateStereoBuffer(this->ZSpaceContext, ZC_RENDERER_QUAD_BUFFER_GL, 0, &this->BufferHandle); - ZSPACE_CHECK_ERROR(zcCreateStereoBuffer, error); - - // Create a zSpace viewport object and grab its associated frustum. - // Note: The zSpace viewport is abstract and not an actual window/viewport - // that is created and registered through the Windows OS. It manages - // a zSpace stereo frustum, which is responsible for various stereoscopic - // 3D calculations such as calculating the view and projection matrices for - // each eye. - error = zcCreateViewport(this->ZSpaceContext, &this->ViewportHandle); - ZSPACE_CHECK_ERROR(zcCreateViewport, error); - - error = zcGetFrustum(this->ViewportHandle, &this->FrustumHandle); - ZSPACE_CHECK_ERROR(zcGetFrustum, error); - - // Enable auto stereo. - error = - zcSetFrustumAttributeB(this->FrustumHandle, ZC_FRUSTUM_ATTRIBUTE_AUTO_STEREO_ENABLED, true); - ZSPACE_CHECK_ERROR(zcSetFrustumAttributeB, error); - error = zcSetFrustumAttributeF32( - this->FrustumHandle, ZC_FRUSTUM_ATTRIBUTE_IPD, this->InterPupillaryDistance); - ZSPACE_CHECK_ERROR(zcSetFrustumAttributeF32, error); - error = zcSetFrustumAttributeF32(this->FrustumHandle, ZC_FRUSTUM_ATTRIBUTE_HEAD_SCALE, 1.f); - ZSPACE_CHECK_ERROR(zcSetFrustumAttributeF32, error); - - error = zcSetFrustumPortalMode(this->FrustumHandle, ZC_PORTAL_MODE_NONE); - ZSPACE_CHECK_ERROR(zcSetFrustumPortalMode, error); - - error = zcGetNumTargetsByType(this->ZSpaceContext, ZC_TARGET_TYPE_PRIMARY, &this->StylusTargets); - ZSPACE_CHECK_ERROR(zcGetNumTargetsByType, error); - - error = zcGetNumTargetsByType(this->ZSpaceContext, ZC_TARGET_TYPE_HEAD, &this->HeadTargets); - ZSPACE_CHECK_ERROR(zcGetNumTargetsByType, error); - - error = - zcGetNumTargetsByType(this->ZSpaceContext, ZC_TARGET_TYPE_SECONDARY, &this->SecondaryTargets); - ZSPACE_CHECK_ERROR(zcGetNumTargetsByType, error); - - // Grab a handle to the stylus target. - error = zcGetTargetByType(this->ZSpaceContext, ZC_TARGET_TYPE_PRIMARY, 0, &this->StylusHandle); - ZSPACE_CHECK_ERROR(zcGetTargetByType, error); - - // Find the zSpace display and set the window position - // to be the top left corner of the zSpace display. - error = zcGetDisplayByType(this->ZSpaceContext, ZC_DISPLAY_TYPE_ZSPACE, 0, &this->DisplayHandle); - ZSPACE_CHECK_ERROR(zcGetDisplayByType, error); - - error = zcGetDisplayPosition(this->DisplayHandle, &this->WindowX, &this->WindowY); - ZSPACE_CHECK_ERROR(zcGetDisplayPosition, error); - - error = - zcGetDisplayNativeResolution(this->DisplayHandle, &this->WindowWidth, &this->WindowHeight); - ZSPACE_CHECK_ERROR(zcGetDisplayNativeResolution, error); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceCoreSDKManager::UpdateViewport() -{ - ZCError error; - - if (!this->RenderWindow) - { - vtkErrorMacro("No render window has been set to the zSpace SDK manager !"); - return; - } - - int* position = this->RenderWindow->GetPosition(); - int* size = this->RenderWindow->GetSize(); - - error = zcSetViewportPosition(this->ViewportHandle, position[0], position[1]); - ZSPACE_CHECK_ERROR(zcSetViewportPosition, error); - error = zcSetViewportSize(this->ViewportHandle, size[0], size[1]); - ZSPACE_CHECK_ERROR(zcSetViewportSize, error); - - // Update inter pupillary distance - error = zcSetFrustumAttributeF32( - this->FrustumHandle, ZC_FRUSTUM_ATTRIBUTE_IPD, this->InterPupillaryDistance); - ZSPACE_CHECK_ERROR(zcSetFrustumAttributeF32, error); - - // Near and far plane - error = - zcSetFrustumAttributeF32(this->FrustumHandle, ZC_FRUSTUM_ATTRIBUTE_NEAR_CLIP, this->NearPlane); - ZSPACE_CHECK_ERROR(zcSetFrustumAttributeF32, error); - error = - zcSetFrustumAttributeF32(this->FrustumHandle, ZC_FRUSTUM_ATTRIBUTE_FAR_CLIP, this->FarPlane); - ZSPACE_CHECK_ERROR(zcSetFrustumAttributeF32, error); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceCoreSDKManager::UpdateTrackers() -{ - ZCError error; - - // Update the zSpace SDK. This updates both tracking information - // as well as the head poses for any frustums that have been created. - error = zcUpdate(this->ZSpaceContext); - ZSPACE_CHECK_ERROR(zcUpdate, error); - - // Update the stylus matrix - ZCTrackerPose stylusPose; - error = zcGetTargetTransformedPose( - this->StylusHandle, this->ViewportHandle, ZC_COORDINATE_SPACE_CAMERA, &stylusPose); - ZSPACE_CHECK_ERROR(zcGetTargetTransformedPose, error); - - vtkZSpaceCoreSDKManager::ConvertZSpaceMatrixToVTKMatrix( - stylusPose.matrix, this->StylusMatrixColMajor); - - // The stylus direction is the normalized negative Z axis of the pose - this->StylusMatrixColMajor->SetElement(2, 0, -this->StylusMatrixColMajor->GetElement(2, 0)); - this->StylusMatrixColMajor->SetElement(2, 1, -this->StylusMatrixColMajor->GetElement(2, 1)); - this->StylusMatrixColMajor->SetElement(2, 2, -this->StylusMatrixColMajor->GetElement(2, 2)); - - vtkNew invView; - vtkMatrix4x4::Invert(this->CenterEyeViewMatrix.GetPointer(), invView); - - // Convert from camera space to world space - vtkMatrix4x4::Multiply4x4(invView, this->StylusMatrixColMajor, this->StylusMatrixColMajor); - - // Transpose the matrix to be used by VTK - vtkMatrix4x4::Transpose(this->StylusMatrixColMajor, this->StylusMatrixRowMajor); - - this->StylusTransformRowMajor->SetMatrix(this->StylusMatrixRowMajor); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceCoreSDKManager::UpdateViewAndProjectionMatrix() -{ - ZCError error; - - // Update the view matrix for each eye - ZSMatrix4 zcViewMatrix; - error = zcGetFrustumViewMatrix(this->FrustumHandle, ZC_EYE_CENTER, &zcViewMatrix); - ZSPACE_CHECK_ERROR(zcGetFrustumViewMatrix, error); - vtkZSpaceCoreSDKManager::ConvertAndTransposeZSpaceMatrixToVTKMatrix( - zcViewMatrix, this->CenterEyeViewMatrix); - - error = zcGetFrustumViewMatrix(this->FrustumHandle, ZC_EYE_LEFT, &zcViewMatrix); - ZSPACE_CHECK_ERROR(zcGetFrustumViewMatrix, error); - vtkZSpaceCoreSDKManager::ConvertAndTransposeZSpaceMatrixToVTKMatrix( - zcViewMatrix, this->LeftEyeViewMatrix); - - error = zcGetFrustumViewMatrix(this->FrustumHandle, ZC_EYE_RIGHT, &zcViewMatrix); - ZSPACE_CHECK_ERROR(zcGetFrustumViewMatrix, error); - vtkZSpaceCoreSDKManager::ConvertAndTransposeZSpaceMatrixToVTKMatrix( - zcViewMatrix, this->RightEyeViewMatrix); - - // Update the projection matrix for each eye - ZSMatrix4 zcProjectionMatrix; - error = zcGetFrustumProjectionMatrix(this->FrustumHandle, ZC_EYE_CENTER, &zcProjectionMatrix); - ZSPACE_CHECK_ERROR(zcGetFrustumProjectionMatrix, error); - vtkZSpaceCoreSDKManager::ConvertAndTransposeZSpaceMatrixToVTKMatrix( - zcProjectionMatrix, this->CenterEyeProjectionMatrix); - - error = zcGetFrustumProjectionMatrix(this->FrustumHandle, ZC_EYE_LEFT, &zcProjectionMatrix); - ZSPACE_CHECK_ERROR(zcGetFrustumProjectionMatrix, error); - vtkZSpaceCoreSDKManager::ConvertAndTransposeZSpaceMatrixToVTKMatrix( - zcProjectionMatrix, this->LeftEyeProjectionMatrix); - - error = zcGetFrustumProjectionMatrix(this->FrustumHandle, ZC_EYE_RIGHT, &zcProjectionMatrix); - ZSPACE_CHECK_ERROR(zcGetFrustumProjectionMatrix, error); - vtkZSpaceCoreSDKManager::ConvertAndTransposeZSpaceMatrixToVTKMatrix( - zcProjectionMatrix, this->RightEyeProjectionMatrix); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceCoreSDKManager::UpdateButtonState() -{ - ZSBool isButtonPressed; - - for (int buttonId = vtkZSpaceSDKManager::MiddleButton; - buttonId < vtkZSpaceSDKManager::NumberOfButtons; ++buttonId) - { - ZCError error = zcIsTargetButtonPressed(this->StylusHandle, buttonId, &isButtonPressed); - ZSPACE_CHECK_ERROR(zcIsTargetButtonPressed, error); - - ButtonState& buttonState = *this->ButtonsState[buttonId]; - buttonState = isButtonPressed - ? buttonState != vtkZSpaceSDKManager::Pressed ? vtkZSpaceSDKManager::Down - : vtkZSpaceSDKManager::Pressed - : buttonState != vtkZSpaceSDKManager::None ? vtkZSpaceSDKManager::Up - : vtkZSpaceSDKManager::None; - } -} - -//------------------------------------------------------------------------------ -void vtkZSpaceCoreSDKManager::CalculateFrustumFit( - const double bounds[6], double position[3], double viewUp[3]) -{ - // Expand bounds a little bit to make sure object is not clipped - const double w1 = bounds[1] - bounds[0]; - const double w2 = bounds[3] - bounds[2]; - const double w3 = bounds[5] - bounds[4]; - - ZCBoundingBox zcBbox; - zcBbox.lower.x = bounds[0] - w1 / 4.0; - zcBbox.lower.y = bounds[2] - w2 / 4.0; - zcBbox.lower.z = bounds[4] - w3 / 4.0; - - zcBbox.upper.x = bounds[1] + w1 / 4.0; - zcBbox.upper.y = bounds[3] + w2 / 4.0; - zcBbox.upper.z = bounds[5] + w3 / 4.0; - - ZSMatrix4 zcLookAtMatrix; - ZSFloat zcViewerScale; - - // Calculate the appropriate viewer scale and camera lookat matrix - // such that content in the above bounding box will take up the entire - // viewport without being clipped. - ZCError error = - zcCalculateFrustumFit(this->FrustumHandle, &zcBbox, &zcViewerScale, &zcLookAtMatrix); - ZSPACE_CHECK_ERROR(zcCalculateFrustumFit, error); - - // Set the frustum's viewer scale with the value that was calculated - // by zcCalculateFrustumFit(). - error = - zcSetFrustumAttributeF32(this->FrustumHandle, ZC_FRUSTUM_ATTRIBUTE_VIEWER_SCALE, zcViewerScale); - ZSPACE_CHECK_ERROR(zcSetFrustumAttributeF32, error); - - this->ViewerScale = static_cast(zcViewerScale); - - position[0] = -zcLookAtMatrix.m03; - position[1] = -zcLookAtMatrix.m13; - position[2] = -zcLookAtMatrix.m23; - - viewUp[0] = zcLookAtMatrix.m01; - viewUp[1] = zcLookAtMatrix.m11; - viewUp[2] = zcLookAtMatrix.m21; -} - -//------------------------------------------------------------------------------ -void vtkZSpaceCoreSDKManager::BeginFrame() -{ - ZCError error = zcBeginStereoBufferFrame(this->BufferHandle); - ZSPACE_CHECK_ERROR(zcBeginStereoBufferFrame, error); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceCoreSDKManager::ConvertAndTransposeZSpaceMatrixToVTKMatrix( - ZSMatrix4 zSpaceMatrix, vtkMatrix4x4* vtkMatrix) -{ - for (int i = 0; i < 16; ++i) - { - vtkMatrix->SetElement(i % 4, i / 4, zSpaceMatrix.f[i]); - } -} - -//------------------------------------------------------------------------------ -void vtkZSpaceCoreSDKManager::ConvertZSpaceMatrixToVTKMatrix( - ZSMatrix4 zSpaceMatrix, vtkMatrix4x4* vtkMatrix) -{ - for (int i = 0; i < 16; ++i) - { - vtkMatrix->SetElement(i / 4, i % 4, zSpaceMatrix.f[i]); - } -} - -//------------------------------------------------------------------------------ -void vtkZSpaceCoreSDKManager::PrintSelf(ostream& os, vtkIndent indent) -{ - this->Superclass::PrintSelf(os, indent); -} diff --git a/Plugins/ZSpace/zSpace/vtkZSpaceCoreSDKManager.h b/Plugins/ZSpace/zSpace/vtkZSpaceCoreSDKManager.h deleted file mode 100644 index c4ed15751f7..00000000000 --- a/Plugins/ZSpace/zSpace/vtkZSpaceCoreSDKManager.h +++ /dev/null @@ -1,114 +0,0 @@ -/*========================================================================= - -Program: Visualization Toolkit - -Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen -All rights reserved. -See Copyright.txt or http://www.kitware.com/Copyright.htm for details. - -This software is distributed WITHOUT ANY WARRANTY; without even -the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -PURPOSE. See the above copyright notice for more information. - -=========================================================================*/ -/** - * @class vtkZSpaceCoreSDKManager - * @brief zSpace Core SDK manager class. - * - * Class handling the interactions between the zSpace plugin - * and the zSpace Core SDK. - * - * @see vtkZSpaceSDKManager - */ - -#ifndef vtkZSpaceCoreSDKManager_h -#define vtkZSpaceCoreSDKManager_h - -#include "vtkZSpaceSDKManager.h" -#include "vtkZSpaceViewModule.h" // for export macro - -#include // for std::vector -#include // zspace header - -class vtkRenderWindow; -class vtkMatrix4x4; - -class VTKZSPACEVIEW_EXPORT vtkZSpaceCoreSDKManager : public vtkZSpaceSDKManager -{ -public: - static vtkZSpaceCoreSDKManager* New(); - vtkTypeMacro(vtkZSpaceCoreSDKManager, vtkObject); - void PrintSelf(ostream& os, vtkIndent indent) override; - - /** - * Initialize the zSpace SDK and check for zSpace devices : - * the display, the stylus and the head trackers. - */ - void InitializeZSpace() override; - - /** - * Update the zSpace viewport position and size based - * on the position and size of the application window. - */ - void UpdateViewport() override; - - /** - * Update the position of the stylus and head trakers. - */ - void UpdateTrackers() override; - - /** - * Update the zSpace view and projection matrix for each eye. - */ - void UpdateViewAndProjectionMatrix() override; - - /** - * Update the stylus buttons state. - */ - void UpdateButtonState() override; - - /** - * Let zSpace compute the viewer scale, camera position and camera view up from the - * input bounds. - */ - void CalculateFrustumFit(const double bounds[6], double position[3], double viewUp[3]) override; - - ///@{ - /** - * Notify the zSpace SDK for the begining of a frame. - * There is no "end frame" notification to make in the - * case of the zSpace Core SDK. - */ - void BeginFrame() override; - void EndFrame() override{}; - ///@} - -protected: - vtkZSpaceCoreSDKManager(); - ~vtkZSpaceCoreSDKManager() override; - - ZCContext ZSpaceContext = nullptr; - ZCHandle DisplayHandle = nullptr; - ZCHandle BufferHandle = nullptr; - ZCHandle ViewportHandle = nullptr; - ZCHandle FrustumHandle = nullptr; - ZCHandle StylusHandle = nullptr; - - /** - * zSpace stores matrix in column-major format (as OpenGL). The matrix - * needs to be transposed to be used by VTK. - */ - void ConvertAndTransposeZSpaceMatrixToVTKMatrix(ZSMatrix4 zSpaceMatrix, vtkMatrix4x4* vtkMatrix); - - /** - * zSpace stores matrix in column-major format (as OpenGL). The matrix - * needs to be transposed to be used by VTK. - */ - void ConvertZSpaceMatrixToVTKMatrix(ZSMatrix4 zSpaceMatrix, vtkMatrix4x4* vtkMatrix); - -private: - vtkZSpaceCoreSDKManager(const vtkZSpaceCoreSDKManager&) = delete; - void operator=(const vtkZSpaceCoreSDKManager&) = delete; -}; - -#endif diff --git a/Plugins/ZSpace/zSpace/vtkZSpaceInteractorStyle.cxx b/Plugins/ZSpace/zSpace/vtkZSpaceInteractorStyle.cxx deleted file mode 100644 index affa0321777..00000000000 --- a/Plugins/ZSpace/zSpace/vtkZSpaceInteractorStyle.cxx +++ /dev/null @@ -1,683 +0,0 @@ -/*========================================================================= - -Program: Visualization Toolkit -Module: vtkZSpaceInteractorStyle.cxx - -Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen -All rights reserved. -See Copyright.txt or http://www.kitware.com/Copyright.htm for details. - -This software is distributed WITHOUT ANY WARRANTY; without even -the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -PURPOSE. See the above copyright notice for more information. - -=========================================================================*/ -#include "vtkZSpaceInteractorStyle.h" - -#include "vtkCamera.h" -#include "vtkCellData.h" -#include "vtkCellPicker.h" -#include "vtkCompositeDataSet.h" -#include "vtkDataObjectTreeIterator.h" -#include "vtkInformation.h" -#include "vtkNew.h" -#include "vtkPVDataRepresentation.h" -#include "vtkPVZSpaceView.h" -#include "vtkPointData.h" -#include "vtkPointSource.h" -#include "vtkPolyData.h" -#include "vtkPolyDataMapper.h" -#include "vtkProperty.h" -#include "vtkRenderWindow.h" -#include "vtkRenderWindowInteractor.h" -#include "vtkRenderer.h" -#include "vtkRendererCollection.h" -#include "vtkSMCoreUtilities.h" -#include "vtkSelection.h" -#include "vtkSelectionNode.h" -#include "vtkTextActor.h" -#include "vtkTextProperty.h" -#include "vtkTransform.h" -#include "vtkZSpaceRayActor.h" - -#include -#include - -vtkStandardNewMacro(vtkZSpaceInteractorStyle); - -//---------------------------------------------------------------------------- -vtkZSpaceInteractorStyle::vtkZSpaceInteractorStyle() -{ - // This is to ensure our events are processed before the other widgets events - // For example to hide the ray when moving a widget with the right button - this->SetPriority(1.0); - - vtkNew pdm; - this->PickActor->SetMapper(pdm); - this->PickActor->GetProperty()->SetLineWidth(4); - this->PickActor->GetProperty()->RenderLinesAsTubesOn(); - this->PickActor->GetProperty()->SetRepresentationToWireframe(); - this->PickActor->DragableOff(); - - this->TextActor->GetTextProperty()->SetFontSize(17); - - vtkNew exactPicker; - this->SetInteractionPicker(exactPicker); -} - -//---------------------------------------------------------------------------- -vtkZSpaceInteractorStyle::~vtkZSpaceInteractorStyle() -{ - this->CurrentRenderer = nullptr; -} - -//---------------------------------------------------------------------------- -void vtkZSpaceInteractorStyle::PrintSelf(ostream& os, vtkIndent indent) -{ - this->Superclass::PrintSelf(os, indent); - - os << indent << "InteractivePicking: " << this->InteractivePicking << endl; - - this->PickActor->PrintSelf(os, indent.GetNextIndent()); - this->PickedInteractionProp->PrintSelf(os, indent.GetNextIndent()); - this->TextActor->PrintSelf(os, indent.GetNextIndent()); -} - -//---------------------------------------------------------------------------- -// Generic events binding -//---------------------------------------------------------------------------- -void vtkZSpaceInteractorStyle::OnMove3D(vtkEventData* edata) -{ - vtkEventDataDevice3D* edd = edata->GetAsEventDataDevice3D(); - this->CurrentRenderer = this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer(); - if (!edd || !this->CurrentRenderer) - { - return; - } - - switch (this->State) - { - case VTKIS_POSITION_PROP: - this->PositionProp(edd); - this->InvokeEvent(vtkCommand::InteractionEvent, nullptr); - break; - } - - this->UpdateRay(edd); - - this->UpdatePickActor(); -} - -//---------------------------------------------------------------------------- -void vtkZSpaceInteractorStyle::OnPick3D(vtkEventData* edata) -{ - vtkEventDataDevice3D* edd = edata->GetAsEventDataDevice3D(); - this->CurrentRenderer = this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer(); - if (!edd || !this->CurrentRenderer) - { - return; - } - - this->State = VTKIS_PICK; - - switch (edd->GetAction()) - { - case vtkEventDataAction::Press: - this->StartAction(this->State, edd); - break; - case vtkEventDataAction::Release: - this->EndAction(this->State, edd); - break; - } -} - -//---------------------------------------------------------------------------- -void vtkZSpaceInteractorStyle::OnPositionProp3D(vtkEventData* edata) -{ - vtkEventDataDevice3D* edd = edata->GetAsEventDataDevice3D(); - this->CurrentRenderer = this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer(); - if (!edd || !this->CurrentRenderer) - { - return; - } - - this->State = VTKIS_POSITION_PROP; - - switch (edd->GetAction()) - { - case vtkEventDataAction::Press: - this->StartAction(this->State, edd); - break; - case vtkEventDataAction::Release: - this->EndAction(this->State, edd); - break; - } -} - -//---------------------------------------------------------------------------- -void vtkZSpaceInteractorStyle::OnSelect3D(vtkEventData* edata) -{ - vtkEventDataDevice3D* edd = edata->GetAsEventDataDevice3D(); - this->CurrentRenderer = this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer(); - if (!edd || !this->CurrentRenderer) - { - return; - } - - // This event is handled in some various widgets to move them - // But we want to disable the ray visibility during the interaction - switch (edd->GetAction()) - { - case vtkEventDataAction::Press: - this->ZSpaceRayActor->SetVisibility(false); - break; - case vtkEventDataAction::Release: - this->ZSpaceRayActor->SetVisibility(true); - break; - } -} - -//---------------------------------------------------------------------------- -// Interaction entry points -//---------------------------------------------------------------------------- -void vtkZSpaceInteractorStyle::StartPick(vtkEventDataDevice3D* edata) -{ - vtkDebugMacro("Start Pick"); - - this->RemovePickActor(); - this->State = VTKIS_PICK; - // update ray length - this->UpdateRay(edata); -} - -//---------------------------------------------------------------------------- -void vtkZSpaceInteractorStyle::EndPick(vtkEventDataDevice3D* edata) -{ - vtkDebugMacro("End Pick"); - - // perform probe - this->ProbeData(edata); - this->State = VTKIS_NONE; - this->UpdateRay(edata); -} - -//---------------------------------------------------------------------------- -bool vtkZSpaceInteractorStyle::HardwareSelect(const double p0[3]) -{ - vtkDebugMacro("Hardware Select"); - - if (!this->ZSpaceView) - { - return false; - } - - this->ZSpaceView->SelectWithRay(p0); - - return true; -} - -//---------------------------------------------------------------------------- -void vtkZSpaceInteractorStyle::StartPositionProp(vtkEventDataDevice3D* edata) -{ - vtkDebugMacro("Start Position Prop"); - - // Do not position another prop if one is already selected - if (this->InteractionProp != nullptr) - { - return; - } - - double pos[3]; - double orient[4]; - edata->GetWorldPosition(pos); - edata->GetWorldOrientation(orient); - - this->FindPickedActor(pos, orient); -} - -//---------------------------------------------------------------------------- -void vtkZSpaceInteractorStyle::EndPositionProp(vtkEventDataDevice3D* vtkNotUsed(edata)) -{ - vtkDebugMacro("End Position Prop"); - - this->State = VTKIS_NONE; - this->InteractionProp = nullptr; -} - -//---------------------------------------------------------------------------- -// Interaction methods -//---------------------------------------------------------------------------- -void vtkZSpaceInteractorStyle::ProbeData(vtkEventDataDevice3D* edata) -{ - vtkDebugMacro("Probe Data"); - - if (!edata) - { - return; - } - - // Invoke start pick method if defined - this->InvokeEvent(vtkCommand::StartPickEvent, edata); - - double pos[3]; - edata->GetWorldPosition(pos); - - if (!this->HardwareSelect(pos)) - { - return; - } - - // Invoke end pick method if defined - if (this->HandleObservers && this->HasObserver(vtkCommand::EndPickEvent)) - { - this->InvokeEvent(vtkCommand::EndPickEvent, this->ZSpaceView->GetLastSelection()); - } - else - { - this->EndPickCallback(this->ZSpaceView->GetLastSelection()); - } -} - -//---------------------------------------------------------------------------- -void vtkZSpaceInteractorStyle::EndPickCallback(vtkSelection* sel) -{ - vtkDebugMacro("End Pick Callback"); - - vtkSmartPointer ds; - vtkIdType aid; - if (!this->FindDataSet(sel, ds, aid)) - { - return; - } - - // Create the corresponding pick actor - if (this->ZSpaceView->GetPickingFieldAssociation() == vtkDataObject::FIELD_ASSOCIATION_CELLS) - { - vtkCell* cell = ds->GetCell(aid); - this->CreatePickCell(cell); - } - else - { - double* point = ds->GetPoint(aid); - this->CreatePickPoint(point); - } - - if (this->PickedInteractionProp) - { - this->PickActor->SetPosition(this->PickedInteractionProp->GetPosition()); - this->PickActor->SetScale(this->PickedInteractionProp->GetScale()); - this->PickActor->SetUserMatrix(this->PickedInteractionProp->GetUserMatrix()); - this->PickActor->SetOrientation(this->PickedInteractionProp->GetOrientation()); - } - else - { - this->PickActor->SetPosition(0.0, 0.0, 0.0); - this->PickActor->SetScale(1.0, 1.0, 1.0); - } - this->CurrentRenderer->AddActor(this->PickActor); - - // Compute the text info about cell or point - std::string pickedText = this->GetPickedText(ds, aid); - - this->TextActor->SetDisplayPosition(50, 50); - this->TextActor->SetInput(pickedText.c_str()); - this->CurrentRenderer->AddActor2D(this->TextActor); -} - -//---------------------------------------------------------------------------- -void vtkZSpaceInteractorStyle::PositionProp( - vtkEventData* ed, double* vtkNotUsed(lwpos), double* vtkNotUsed(lwori)) -{ - if (this->InteractionProp == nullptr || !this->InteractionProp->GetDragable()) - { - return; - } - this->Superclass::PositionProp(ed); -} - -//---------------------------------------------------------------------------- -// Utility routines -//---------------------------------------------------------------------------- - -//---------------------------------------------------------------------------- -void vtkZSpaceInteractorStyle::StartAction(int state, vtkEventDataDevice3D* edata) -{ - switch (state) - { - case VTKIS_POSITION_PROP: - this->StartPositionProp(edata); - break; - case VTKIS_PICK: - this->StartPick(edata); - break; - } -} -//---------------------------------------------------------------------------- -void vtkZSpaceInteractorStyle::EndAction(int state, vtkEventDataDevice3D* edata) -{ - switch (state) - { - case VTKIS_POSITION_PROP: - this->EndPositionProp(edata); - break; - case VTKIS_PICK: - this->EndPick(edata); - break; - } -} - -//---------------------------------------------------------------------------- -void vtkZSpaceInteractorStyle::UpdateRay(vtkEventDataDevice3D* edata) -{ - if (!this->Interactor) - { - return; - } - - double p0[3]; - double wxyz[4]; - edata->GetWorldPosition(p0); - edata->GetWorldOrientation(wxyz); - - // Create the appropriate ray user transform from event position and orientation - vtkNew stylusT; - stylusT->Identity(); - stylusT->Translate(p0); - stylusT->RotateWXYZ(wxyz[0], wxyz[1], wxyz[2], wxyz[3]); - - // The maximum ray length is the camera zfar - const double rayMaxLength = this->ZSpaceView->GetActiveCamera()->GetClippingRange()[1]; - - double rayLength = rayMaxLength; - if (this->State == VTKIS_POSITION_PROP) - { - rayLength = this->ZSpaceRayActor->GetLength(); - } - // Make sure that the ray length is updated in case of a pick - else if (this->InteractivePicking || this->State == VTKIS_PICK) - { - this->FindPickedActor(p0, wxyz); - // If something is picked, set the length accordingly - if (this->InteractionProp) - { - // Compute the length of the ray - double p1[3]; - this->InteractionPicker->GetPickPosition(p1); - rayLength = sqrt(vtkMath::Distance2BetweenPoints(p0, p1)); - } - } - - if (rayLength == rayMaxLength) - { - this->ZSpaceRayActor->SetNoPick(); - } - else - { - this->ZSpaceRayActor->SetPick(); - } - - this->ZSpaceRayActor->SetLength(rayLength); - stylusT->Scale(rayLength, rayLength, rayLength); - this->ZSpaceRayActor->SetUserTransform(stylusT); - - return; -} - -//---------------------------------------------------------------------------- -bool vtkZSpaceInteractorStyle::FindDataSet( - vtkSelection* sel, vtkSmartPointer& ds, vtkIdType& aid) -{ - if (!sel) - { - return false; - } - - vtkSelectionNode* node = sel->GetNode(0); - if (!node || !node->GetProperties()->Has(vtkSelectionNode::PROP())) - { - return false; - } - - vtkProp3D* prop = vtkProp3D::SafeDownCast(node->GetProperties()->Get(vtkSelectionNode::PROP())); - if (!prop) - { - return false; - } - - // Save this prop that is linked to the pick actor - this->PickedInteractionProp = prop; - - vtkPVDataRepresentation* repr = - vtkPVDataRepresentation::SafeDownCast(node->GetProperties()->Get(vtkSelectionNode::SOURCE())); - - if (!repr) - { - return false; - } - - vtkDataObject* dobj = repr->GetInput(); - vtkCompositeDataSet* cds = vtkCompositeDataSet::SafeDownCast(dobj); - // handle composite datasets - if (cds) - { - vtkIdType cid = node->GetProperties()->Get(vtkSelectionNode::COMPOSITE_INDEX()); - vtkNew iter; - iter->SetDataSet(cds); - iter->SkipEmptyNodesOn(); - iter->SetVisitOnlyLeaves(1); - iter->InitTraversal(); - while (iter->GetCurrentFlatIndex() != cid && !iter->IsDoneWithTraversal()) - { - iter->GoToNextItem(); - } - if (iter->GetCurrentFlatIndex() == cid) - { - ds.TakeReference(vtkDataSet::SafeDownCast(iter->GetCurrentDataObject())); - } - } - else - { - ds.TakeReference(vtkDataSet::SafeDownCast(dobj)); - } - if (!ds) - { - return false; - } - - // get the picked cell - vtkIdTypeArray* ids = vtkArrayDownCast(node->GetSelectionList()); - if (ids == 0) - { - return false; - } - aid = ids->GetComponent(0, 0); - - ds->Register(this); - - return true; -} - -//---------------------------------------------------------------------------- -std::string vtkZSpaceInteractorStyle::GetPickedText(vtkDataSet* ds, const vtkIdType& aid) -{ - // Compute the text from the selected point or cell - // It would be nice to be able to factorize this code - // with the vtkSMTooltipSelectionPipeline code - std::stringstream ssPickedText; - - vtkFieldData* fieldData = nullptr; - vtkDataArray* originalIds = nullptr; - // We selected a cell - if (this->ZSpaceView->GetPickingFieldAssociation() == vtkDataObject::FIELD_ASSOCIATION_CELLS) - { - ssPickedText << "Cell id : " << aid << "\n"; - vtkCellData* cellData = ds->GetCellData(); - fieldData = cellData; - - originalIds = cellData->GetArray("vtkOriginalCellIds"); - if (originalIds) - { - ssPickedText << "Id: " << originalIds->GetTuple1(0) << "\n"; - } - - // Cell type - vtkCell* cell = ds->GetCell(aid); - ssPickedText << "Type: " << vtkSMCoreUtilities::GetStringForCellType(cell->GetCellType()) - << "\n"; - } - else // or a point - { - ssPickedText << "Point id : " << aid << "\n"; - vtkPointData* pointData = ds->GetPointData(); - fieldData = pointData; - - originalIds = pointData->GetArray("vtkOriginalPointIds"); - if (originalIds) - { - ssPickedText << "Id: " << originalIds->GetTuple1(0) << "\n"; - } - - // Point coords - double* point = ds->GetPoint(aid); - ssPickedText << "Coords: (" << point[0] << ", " << point[1] << ", " << point[2] << ")\n"; - } - - if (fieldData) - { - // point attributes - vtkIdType nbArrays = fieldData->GetNumberOfArrays(); - for (vtkIdType i_arr = 0; i_arr < nbArrays; i_arr++) - { - vtkDataArray* array = fieldData->GetArray(i_arr); - if (!array || originalIds == array) - { - continue; - } - ssPickedText << array->GetName() << ": "; - if (array->GetNumberOfComponents() > 1) - { - ssPickedText << "("; - } - vtkIdType nbComps = array->GetNumberOfComponents(); - for (vtkIdType i_comp = 0; i_comp < nbComps; i_comp++) - { - ssPickedText << array->GetTuple(0)[i_comp]; - if (i_comp + 1 < nbComps) - { - ssPickedText << ", "; - } - } - if (array->GetNumberOfComponents() > 1) - { - ssPickedText << ")\n"; - } - else - { - ssPickedText << "\n"; - } - } - } - - return std::move(ssPickedText.str()); -} - -//---------------------------------------------------------------------------- -void vtkZSpaceInteractorStyle::CreatePickCell(vtkCell* cell) -{ - vtkNew pd; - vtkNew pdpts; - pdpts->SetDataTypeToDouble(); - vtkNew lines; - - this->PickActor->GetProperty()->SetColor(this->PickColor); - - int nedges = cell->GetNumberOfEdges(); - - if (nedges) - { - for (int edgenum = 0; edgenum < nedges; ++edgenum) - { - vtkCell* edge = cell->GetEdge(edgenum); - vtkPoints* pts = edge->GetPoints(); - int npts = edge->GetNumberOfPoints(); - lines->InsertNextCell(npts); - for (int ep = 0; ep < npts; ++ep) - { - vtkIdType newpt = pdpts->InsertNextPoint(pts->GetPoint(ep)); - lines->InsertCellPoint(newpt); - } - } - } - else if (cell->GetCellType() == VTK_LINE || cell->GetCellType() == VTK_POLY_LINE) - { - vtkPoints* pts = cell->GetPoints(); - int npts = cell->GetNumberOfPoints(); - lines->InsertNextCell(npts); - for (int ep = 0; ep < npts; ++ep) - { - vtkIdType newpt = pdpts->InsertNextPoint(pts->GetPoint(ep)); - lines->InsertCellPoint(newpt); - } - } - else - { - return; - } - - pd->SetPoints(pdpts.Get()); - pd->SetLines(lines.Get()); - - static_cast(this->PickActor->GetMapper())->SetInputData(pd); -} - -//---------------------------------------------------------------------------- -void vtkZSpaceInteractorStyle::CreatePickPoint(double* point) -{ - this->PickActor->GetProperty()->SetColor(this->PickColor); - this->PickActor->GetProperty()->SetPointSize(8.0); - - vtkNew pointSource; - pointSource->SetCenter(point); - pointSource->SetNumberOfPoints(1); - pointSource->SetRadius(0); - - pointSource->Update(); - static_cast(this->PickActor->GetMapper()) - ->SetInputData(pointSource->GetOutput()); -} - -//---------------------------------------------------------------------------- -void vtkZSpaceInteractorStyle::UpdatePickActor() -{ - - if (this->PickedInteractionProp) - { - // Remove the pick actor if it has been deleted - if (!this->CurrentRenderer->HasViewProp(this->PickedInteractionProp)) - { - this->RemovePickActor(); - return; - } - - // Update the visibility - this->PickActor->SetVisibility(this->PickedInteractionProp->GetVisibility()); - this->TextActor->SetVisibility(this->PickedInteractionProp->GetVisibility()); - - // Move the point/cell picked with the prop - if (this->PickedInteractionProp->GetUserMatrix() != nullptr) - { - this->PickActor->SetUserMatrix(this->PickedInteractionProp->GetUserMatrix()); - } - } -} - -//---------------------------------------------------------------------------- -void vtkZSpaceInteractorStyle::RemovePickActor() -{ - if (this->CurrentRenderer) - { - this->CurrentRenderer->RemoveActor(this->PickActor); - this->CurrentRenderer->RemoveActor2D(this->TextActor); - this->PickedInteractionProp = nullptr; - } -} diff --git a/Plugins/ZSpace/zSpace/vtkZSpaceInteractorStyle.h b/Plugins/ZSpace/zSpace/vtkZSpaceInteractorStyle.h deleted file mode 100644 index 4f70f4537da..00000000000 --- a/Plugins/ZSpace/zSpace/vtkZSpaceInteractorStyle.h +++ /dev/null @@ -1,191 +0,0 @@ -/*========================================================================= - -Program: Visualization Toolkit -Module: vtkZSpaceInteractorStyle.h - -Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen -All rights reserved. -See Copyright.txt or http://www.kitware.com/Copyright.htm for details. - -This software is distributed WITHOUT ANY WARRANTY; without even -the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -PURPOSE. See the above copyright notice for more information. - -=========================================================================*/ -/** - * @class vtkZSpaceInteractorStyle - * - * vtkZSpaceInteractorStyle extends vtkInteractorStyle3D to override command methods. - * - * This class maps EventDataDevice3D device and input to an interaction state : - * - * - LeftButton (LeftController + Trigger) maps to VTKIS_PICK. It asks vtkPVZSpaceView to use its - * own PVHardwareSelector to pick a cell or a point, depending on the value of - * vtkPVZSpaceView::PickingFieldAssociation. - * Then informations about picking is shown on the bottom left of the screen. A pick actor is - * also shown to visualize the picked cell or picked point. - * - * - MiddleButton (GenericTracker + Trigger) maps to VTKIS_POSITION_PROP. It allows the user to - * grab the picked actor and move it with the stylus. - * - * - RightButton (RightController + Trigger) allows to position the widgets that respond to - * this vtkEventDataDevice3D, such as vtkBoxWidget2, vtkHandleWidget, vtkImplicitPlaneWidget2 and - * vtkTensorWidget. It doesn't map to any VTKIS_XXX. - * - * The move event will then call the method to position the current picked prop - * if the state is VTKIS_POSITION_PROP. - */ - -#ifndef vtkZSpaceInteractorStyle_h -#define vtkZSpaceInteractorStyle_h - -#include "vtkZSpaceViewModule.h" // For export macro - -#include "vtkEventData.h" // for enums -#include "vtkInteractorStyle3D.h" -#include "vtkNew.h" // for ivars - -class vtkCell; -class vtkPlane; -class vtkSelection; -class vtkDataSet; -class vtkTextActor; -class vtkZSpaceRayActor; -class vtkPVZSpaceView; - -class VTKZSPACEVIEW_EXPORT vtkZSpaceInteractorStyle : public vtkInteractorStyle3D -{ -public: - static vtkZSpaceInteractorStyle* New(); - vtkTypeMacro(vtkZSpaceInteractorStyle, vtkInteractorStyle3D); - void PrintSelf(ostream& os, vtkIndent indent) override; - - ///@{ - /** - * Override generic event bindings to call the corresponding action. - */ - void OnPick3D(vtkEventData* edata) override; - void OnPositionProp3D(vtkEventData* edata) override; - void OnMove3D(vtkEventData* edata) override; - void OnSelect3D(vtkEventData* edata) override; - ///@} - - ///@{ - /** - * Interaction mode entry points. - */ - virtual void StartPick(vtkEventDataDevice3D*); - virtual void EndPick(vtkEventDataDevice3D*); - virtual void StartPositionProp(vtkEventDataDevice3D*); - virtual void EndPositionProp(vtkEventDataDevice3D*); - ///@} - - ///@{ - /** - * Methods for interaction. - */ - void ProbeData(vtkEventDataDevice3D*); - virtual void PositionProp(vtkEventData*, double* lwpos = nullptr, double* lwori = nullptr); - ///@} - - ///@{ - /** - * Indicates if picking should be updated every frame. If so, the interaction - * picker will try to pick a prop and ray will be updated accordingly. - * Default is set to off. - */ - vtkSetMacro(InteractivePicking, bool); - vtkGetMacro(InteractivePicking, bool); - vtkBooleanMacro(InteractivePicking, bool); - ///@} - - /** - * Use FindPickedActor to update the InteractionProp. - * Then update the ray length to the pick length if something is picked, - * else to its max length. - */ - void UpdateRay(vtkEventDataDevice3D*); - - /** - * Set the zSpaceRayActor that is used to draw the ray stylus. - */ - vtkSetMacro(ZSpaceRayActor, vtkZSpaceRayActor*); - - /** - * Set the zSpaceView to delegate the hardware select to its PVHardwareSelector. - */ - vtkSetMacro(ZSpaceView, vtkPVZSpaceView*); - -protected: - vtkZSpaceInteractorStyle(); - ~vtkZSpaceInteractorStyle() override; - - /** - * Create the text to display information about the selection, - * create the PickActor to draw the picked cell or point and add - * it to the renderer. - */ - void EndPickCallback(vtkSelection* sel); - - ///@{ - /** Utility routines - */ - void StartAction(int VTKIS_STATE, vtkEventDataDevice3D* edata); - void EndAction(int VTKIS_STATE, vtkEventDataDevice3D* edata); - ///@} - - /** - * Delegate the selection to the PVHardwareSelector of ZSpaceView. If - * something is picked, this->InteractionProp contains the picked actor. - */ - bool HardwareSelect(const double p0[3]); - - /** - * From the selection 'sel', find the corresponding dataset 'ds' and the point/cell id 'aid'. - */ - bool FindDataSet(vtkSelection* sel, vtkSmartPointer& ds, vtkIdType& aid); - - /** - * Create a string that contains informations about the point or cell defined by the - * index 'aid' in the dataset 'ds'. - */ - std::string GetPickedText(vtkDataSet* ds, const vtkIdType& aid); - - /** - * Create the PickActor to show the picked cell. - */ - void CreatePickCell(vtkCell* cell); - - /** - * Create the PickActor to show the picked point. - */ - void CreatePickPoint(double* point); - - /** - * Update the PickActor and the TextActor depending on - * the PickedInteractionProp position and visibility. - */ - void UpdatePickActor(); - - /** - * Remove the PickActor and the TextActor from the renderer. - */ - void RemovePickActor(); - - bool InteractivePicking = true; - - // Used to draw picked cells or points - vtkNew PickActor; - // The text actor is linked to this prop - vtkProp3D* PickedInteractionProp = nullptr; - vtkNew TextActor; - - vtkZSpaceRayActor* ZSpaceRayActor; - vtkPVZSpaceView* ZSpaceView; - -private: - vtkZSpaceInteractorStyle(const vtkZSpaceInteractorStyle&) = delete; - void operator=(const vtkZSpaceInteractorStyle&) = delete; -}; - -#endif diff --git a/Plugins/ZSpace/zSpace/vtkZSpaceRayActor.cxx b/Plugins/ZSpace/zSpace/vtkZSpaceRayActor.cxx deleted file mode 100644 index 363760b36b6..00000000000 --- a/Plugins/ZSpace/zSpace/vtkZSpaceRayActor.cxx +++ /dev/null @@ -1,69 +0,0 @@ -/*========================================================================= - -Program: Visualization Toolkit -Module: vtkZSpaceRayActor.cxx - -Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen -All rights reserved. -See Copyright.txt or http://www.kitware.com/Copyright.htm for details. - -This software is distributed WITHOUT ANY WARRANTY; without even -the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -PURPOSE. See the above copyright notice for more information. - -=========================================================================*/ -#include "vtkZSpaceRayActor.h" - -#include "vtkLineSource.h" -#include "vtkPolyDataMapper.h" -#include "vtkProperty.h" -#include "vtkTransform.h" - -vtkStandardNewMacro(vtkZSpaceRayActor); - -//------------------------------------------------------------------------------ -vtkZSpaceRayActor::vtkZSpaceRayActor() -{ - // Line source oriented in +Z - this->LineSource->SetPoint1(0.0, 0.0, 0.0); - this->LineSource->SetPoint2(0.0, 0.0, -1.0); - this->Mapper->SetInputConnection(this->LineSource->GetOutputPort()); - this->SetMapper(this->Mapper); - - this->GetProperty()->SetLineWidth(this->LineWidth); - - // The ray won't influence the scene bounds (and ResetCamera) - this->UseBoundsOff(); - // Do not pick itself - this->PickableOff(); - - // Start by setting the length and color without pick - this->SetNoPick(); -} - -//------------------------------------------------------------------------------ -vtkZSpaceRayActor::~vtkZSpaceRayActor() = default; - -//------------------------------------------------------------------------------ -void vtkZSpaceRayActor::PrintSelf(ostream& os, vtkIndent indent) -{ - this->Superclass::PrintSelf(os, indent); - - os << indent << "LineWidth: " << this->LineWidth << endl; - os << indent << "NoPickColor = (" << this->NoPickColor[0] << ", " << this->NoPickColor[1] << ", " - << this->NoPickColor[2] << endl; - os << indent << "PickColor = (" << this->PickColor[0] << ", " << this->PickColor[1] << ", " - << this->PickColor[2] << endl; -} - -//------------------------------------------------------------------------------ -void vtkZSpaceRayActor::SetNoPick() -{ - this->GetProperty()->SetColor(this->NoPickColor); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceRayActor::SetPick() -{ - this->GetProperty()->SetColor(this->PickColor); -} diff --git a/Plugins/ZSpace/zSpace/vtkZSpaceRayActor.h b/Plugins/ZSpace/zSpace/vtkZSpaceRayActor.h deleted file mode 100644 index f6799a8201c..00000000000 --- a/Plugins/ZSpace/zSpace/vtkZSpaceRayActor.h +++ /dev/null @@ -1,103 +0,0 @@ -/*========================================================================= - -Program: Visualization Toolkit - -Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen -All rights reserved. -See Copyright.txt or http://www.kitware.com/Copyright.htm for details. - -This software is distributed WITHOUT ANY WARRANTY; without even -the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -PURPOSE. See the above copyright notice for more information. - -=========================================================================*/ -/** -* @class vtkZSpaceRayActor -* @brief An actor for displaying a ray. - -* Represents a ray shooting from a VR controller, used for pointing or picking. -* Contains a line source. Use SetUserTransform to control the ray. -*/ - -#ifndef vtkZSpaceRayActor_h -#define vtkZSpaceRayActor_h - -#include "vtkNew.h" // for ivar -#include "vtkOpenGLActor.h" -#include "vtkZSpaceViewModule.h" // for export macro - -class vtkLineSource; -class vtkPolyDataMapper; - -class VTKZSPACEVIEW_EXPORT vtkZSpaceRayActor : public vtkOpenGLActor -{ -public: - static vtkZSpaceRayActor* New(); - vtkTypeMacro(vtkZSpaceRayActor, vtkOpenGLActor); - void PrintSelf(ostream& os, vtkIndent indent) override; - - /** - * Set the state of the ray when nothing is picked. - */ - void SetNoPick(); - - /** - * Set the state of the ray when something is picked. - */ - void SetPick(); - - ///@{ - /** - * Get/Set the color of the ray when nothing is - * picked. - * Default is Red. - */ - vtkGetVector3Macro(NoPickColor, double); - vtkSetVector3Macro(NoPickColor, double); - ///@} - - ///@{ - /** - * Get/Set the color of the ray when something is - * picked. - * Default is Green. - */ - vtkGetVector3Macro(PickColor, double); - vtkSetVector3Macro(PickColor, double); - ///@} - - ///@{ - /** - * Get/Set the thickness of the line. - * Default is 1.0. - */ - vtkGetMacro(LineWidth, double); - vtkSetMacro(LineWidth, double); - ///@} - - ///@{ - /** - * Get/Set the length of the ray. - */ - vtkGetMacro(Length, double); - vtkSetMacro(Length, double); - ///@} - -protected: - vtkZSpaceRayActor(); - ~vtkZSpaceRayActor() override; - - vtkNew LineSource; - vtkNew Mapper; - - double NoPickColor[3] = { 0.9, 0.3, 0.3 }; - double PickColor[3] = { 0.0, 1.0, 0.0 }; - double LineWidth = 1.5; - double Length = 10.0; - -private: - vtkZSpaceRayActor(const vtkZSpaceRayActor&) = delete; - void operator=(const vtkZSpaceRayActor&) = delete; -}; - -#endif diff --git a/Plugins/ZSpace/zSpace/vtkZSpaceRenderWindowInteractor.cxx b/Plugins/ZSpace/zSpace/vtkZSpaceRenderWindowInteractor.cxx deleted file mode 100644 index f34dedeb5db..00000000000 --- a/Plugins/ZSpace/zSpace/vtkZSpaceRenderWindowInteractor.cxx +++ /dev/null @@ -1,211 +0,0 @@ -/*========================================================================= - - Program: Visualization Toolkit - Module: vtkZSpaceRenderWindowInteractor.cxx - - Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen - All rights reserved. - See Copyright.txt or http://www.kitware.com/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notice for more information. - -=========================================================================*/ -#include "vtkZSpaceRenderWindowInteractor.h" - -#include "vtkCamera.h" -#include "vtkCommand.h" -#include "vtkEventData.h" -#include "vtkNew.h" -#include "vtkObjectFactory.h" -#include "vtkRenderWindow.h" -#include "vtkRendererCollection.h" -#include "vtkTransform.h" -#include "vtkZSpaceInteractorStyle.h" -#include "vtkZSpaceSDKManager.h" - -#include -#include -#include -#include -#include - -vtkStandardNewMacro(vtkZSpaceRenderWindowInteractor); - -//------------------------------------------------------------------------------ -// Construct object so that light follows camera motion. -vtkZSpaceRenderWindowInteractor::vtkZSpaceRenderWindowInteractor() -{ - vtkNew style; - this->SetInteractorStyle(style); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceRenderWindowInteractor::ProcessEvents() -{ - vtkZSpaceSDKManager::GetInstance()->Update(); - this->HandleInteractions(); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceRenderWindowInteractor::HandleInteractions() -{ - vtkZSpaceSDKManager* sdkManager = vtkZSpaceSDKManager::GetInstance(); - sdkManager->Update(); - - // Compute stylus position and orientation - vtkTransform* stylusT = sdkManager->GetStylusTransformRowMajor(); - - double pos[3]; - stylusT->GetPosition(pos); - double wxyz[4]; - stylusT->GetOrientationWXYZ(wxyz); - - // Offset stylus world position with the glasses position - vtkCamera* camera = - static_cast(this->GetRenderWindow()->GetRenderers()->GetItemAsObject(0)) - ->GetActiveCamera(); - double* camPos = camera->GetPosition(); - pos[0] += camPos[0]; - pos[1] += camPos[1]; - pos[2] += camPos[2]; - - this->SetWorldEventPosition(pos[0], pos[1], pos[2], this->PointerIndex); - this->SetWorldEventOrientation(wxyz[0], wxyz[1], wxyz[2], wxyz[3], this->PointerIndex); - - vtkNew ed3d; - ed3d->SetWorldPosition(pos); - ed3d->SetWorldOrientation(wxyz); - // We only have one stylus - ed3d->SetDevice(vtkEventDataDevice::RightController); - - switch (sdkManager->GetLeftButtonState()) - { - case vtkZSpaceSDKManager::Down: - this->OnLeftButtonDown(ed3d); - break; - case vtkZSpaceSDKManager::Up: - this->OnLeftButtonUp(ed3d); - break; - default: - break; - } - - switch (sdkManager->GetMiddleButtonState()) - { - case vtkZSpaceSDKManager::Down: - this->OnMiddleButtonDown(ed3d); - break; - case vtkZSpaceSDKManager::Up: - this->OnMiddleButtonUp(ed3d); - break; - default: - break; - } - - switch (sdkManager->GetRightButtonState()) - { - case vtkZSpaceSDKManager::Down: - this->OnRightButtonDown(ed3d); - break; - case vtkZSpaceSDKManager::Up: - this->OnRightButtonUp(ed3d); - break; - default: - break; - } - - // Always a move event - ed3d->SetType(vtkCommand::Move3DEvent); - this->InvokeEvent(vtkCommand::Move3DEvent, ed3d); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceRenderWindowInteractor::OnMiddleButtonDown(vtkEventDataDevice3D* ed3d) -{ - vtkZSpaceSDKManager::GetInstance()->SetMiddleButtonState(vtkZSpaceSDKManager::Pressed); - - ed3d->SetAction(vtkEventDataAction::Press); - - this->InvokeEvent(vtkCommand::PositionProp3DEvent, ed3d); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceRenderWindowInteractor::OnMiddleButtonUp(vtkEventDataDevice3D* ed3d) -{ - vtkZSpaceSDKManager::GetInstance()->SetMiddleButtonState(vtkZSpaceSDKManager::None); - - ed3d->SetAction(vtkEventDataAction::Release); - - this->InvokeEvent(vtkCommand::PositionProp3DEvent, ed3d); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceRenderWindowInteractor::OnRightButtonDown(vtkEventDataDevice3D* ed3d) -{ - vtkZSpaceSDKManager::GetInstance()->SetRightButtonState(vtkZSpaceSDKManager::Pressed); - - ed3d->SetType(vtkCommand::Select3DEvent); - ed3d->SetAction(vtkEventDataAction::Press); - - // Start selecting some vtkWidgets that respond to this event - this->InvokeEvent(vtkCommand::Select3DEvent, ed3d); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceRenderWindowInteractor::OnRightButtonUp(vtkEventDataDevice3D* ed3d) -{ - vtkZSpaceSDKManager::GetInstance()->SetRightButtonState(vtkZSpaceSDKManager::None); - - ed3d->SetType(vtkCommand::Select3DEvent); - ed3d->SetAction(vtkEventDataAction::Release); - - // End selecting some vtkWidgets that respond to this event - this->InvokeEvent(vtkCommand::Select3DEvent, ed3d); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceRenderWindowInteractor::OnLeftButtonDown(vtkEventDataDevice3D* ed3d) -{ - vtkZSpaceSDKManager::GetInstance()->SetLeftButtonState(vtkZSpaceSDKManager::Pressed); - - ed3d->SetAction(vtkEventDataAction::Press); - - this->InvokeEvent(vtkCommand::Pick3DEvent, ed3d); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceRenderWindowInteractor::OnLeftButtonUp(vtkEventDataDevice3D* ed3d) -{ - vtkZSpaceSDKManager::GetInstance()->SetLeftButtonState(vtkZSpaceSDKManager::None); - - ed3d->SetAction(vtkEventDataAction::Release); - - this->InvokeEvent(vtkCommand::Pick3DEvent, ed3d); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceRenderWindowInteractor::ExitCallback() -{ - if (this->HasObserver(vtkCommand::ExitEvent)) - { - this->InvokeEvent(vtkCommand::ExitEvent, nullptr); - } - - this->TerminateApp(); -} - -//------------------------------------------------------------------------------ -vtkEventDataDevice vtkZSpaceRenderWindowInteractor::GetPointerDevice() -{ - if (this->PointerIndex == 0) - { - return vtkEventDataDevice::RightController; - } - if (this->PointerIndex == 1) - { - return vtkEventDataDevice::LeftController; - } - return vtkEventDataDevice::Unknown; -} diff --git a/Plugins/ZSpace/zSpace/vtkZSpaceRenderWindowInteractor.h b/Plugins/ZSpace/zSpace/vtkZSpaceRenderWindowInteractor.h deleted file mode 100644 index 5bd84b18c04..00000000000 --- a/Plugins/ZSpace/zSpace/vtkZSpaceRenderWindowInteractor.h +++ /dev/null @@ -1,103 +0,0 @@ -/*========================================================================= - - Program: Visualization Toolkit - Module: vtkZSpaceRenderWindowInteractor.h - - Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen - All rights reserved. - See Copyright.txt or http://www.kitware.com/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notice for more information. - -=========================================================================*/ -/** - * @class vtkZSpaceRenderWindowInteractor - * @brief Implements zSpace specific interactions. - * - * This class implements the zSpace specific interactions, done - * with the stylus. Required by vtkRenderWindowInteractor. - */ - -#ifndef vtkZSpaceRenderWindowInteractor_h -#define vtkZSpaceRenderWindowInteractor_h - -#include "vtkEventData.h" // For vtkEventDataDevice -#include "vtkRenderWindowInteractor3D.h" -#include "vtkZSpaceViewModule.h" // For export macro - -class vtkCamera; -class VTKZSPACEVIEW_EXPORT vtkZSpaceRenderWindowInteractor : public vtkRenderWindowInteractor3D -{ -public: - /** - * Construct object so that light follows camera motion. - */ - static vtkZSpaceRenderWindowInteractor* New(); - - vtkTypeMacro(vtkZSpaceRenderWindowInteractor, vtkRenderWindowInteractor3D); - - /** - * These methods correspond to the Exit, User and Pick - * callbacks. They allow for the Style to invoke them. - */ - virtual void ExitCallback(); - - /** - * Run the event loop and return. This is provided so that you can - * implement your own event loop but yet use the vtk event handling as - * well. - */ - void ProcessEvents() override; - - /* - * Return the pointer index as a device - */ - vtkEventDataDevice GetPointerDevice(); - - /** - * Update WorldEventPosition and WorldEventOrientation, then - * call event functions depending on the zSpace buttons states. - */ - void HandleInteractions(); - - ///@{ - /** - * LeftButton event function (invoke Button3DEvent) - * Initiate a clip : choose a clipping plane origin - * and normal with the stylus. - */ - void OnLeftButtonDown(vtkEventDataDevice3D*); - void OnLeftButtonUp(vtkEventDataDevice3D*); - ///@} - - ///@{ - /** - * MiddleButton event function (invoke Button3DEvent) - * Allows to position a prop with the stylus. - */ - void OnMiddleButtonDown(vtkEventDataDevice3D*); - void OnMiddleButtonUp(vtkEventDataDevice3D*); - ///@} - - ///@{ - /** - * LeftButton event function (invoke Button3DEvent) - * Perform an hardware picking with the stylus - * and show picked data if ShowPickedData is true. - */ - void OnRightButtonDown(vtkEventDataDevice3D*); - void OnRightButtonUp(vtkEventDataDevice3D*); - ///@} - -protected: - vtkZSpaceRenderWindowInteractor(); - ~vtkZSpaceRenderWindowInteractor() override = default; - -private: - vtkZSpaceRenderWindowInteractor(const vtkZSpaceRenderWindowInteractor&) = delete; - void operator=(const vtkZSpaceRenderWindowInteractor&) = delete; -}; - -#endif diff --git a/Plugins/ZSpace/zSpace/vtkZSpaceSDKManager.cxx b/Plugins/ZSpace/zSpace/vtkZSpaceSDKManager.cxx deleted file mode 100644 index 35612294c3a..00000000000 --- a/Plugins/ZSpace/zSpace/vtkZSpaceSDKManager.cxx +++ /dev/null @@ -1,110 +0,0 @@ -/*========================================================================= - -Program: Visualization Toolkit -Module: vtkZSpaceSDKManager.cxx - -Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen -All rights reserved. -See Copyright.txt or http://www.kitware.com/Copyright.htm for details. - -This software is distributed WITHOUT ANY WARRANTY; without even -the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -PURPOSE. See the above copyright notice for more information. - -=========================================================================*/ -#include "vtkZSpaceSDKManager.h" - -#include "vtkMatrix4x4.h" -#include "vtkObjectFactory.h" -#include "vtkRenderWindow.h" -#include "vtkSmartPointer.h" -#include "vtkTransform.h" -#include "vtkZSpaceSDKVersion.h" - -#ifdef ZSPACE_USE_COMPAT_SDK -#include "vtkZSpaceCoreCompatibilitySDKManager.h" -#else -#include "vtkZSpaceCoreSDKManager.h" -#endif - -//------------------------------------------------------------------------------ -vtkZSpaceSDKManager::vtkZSpaceSDKManager() = default; - -//---------------------------------------------------------------------------- -vtkZSpaceSDKManager::~vtkZSpaceSDKManager() = default; - -//---------------------------------------------------------------------------- -vtkZSpaceSDKManager* vtkZSpaceSDKManager::GetInstance() -{ - static vtkSmartPointer instance = nullptr; - if (instance.GetPointer() == nullptr) - { -#ifdef ZSPACE_USE_COMPAT_SDK - instance = vtkSmartPointer::New(); -#else - instance = vtkSmartPointer::New(); -#endif - } - - return instance; -} - -//---------------------------------------------------------------------------- -void vtkZSpaceSDKManager::SetRenderWindow(vtkRenderWindow* renderWindow) -{ - this->RenderWindow = renderWindow; -}; - -//------------------------------------------------------------------------------ -void vtkZSpaceSDKManager::Update() -{ - this->UpdateViewport(); - this->UpdateViewAndProjectionMatrix(); - this->UpdateTrackers(); - this->UpdateButtonState(); -} - -//------------------------------------------------------------------------------ -void vtkZSpaceSDKManager::SetClippingRange(const float nearPlane, const float farPlane) -{ - this->NearPlane = nearPlane; - this->FarPlane = farPlane; -} - -//------------------------------------------------------------------------------ -vtkMatrix4x4* vtkZSpaceSDKManager::GetStereoViewMatrix(bool leftEye) -{ - return leftEye ? this->LeftEyeViewMatrix : this->RightEyeViewMatrix; -} - -//------------------------------------------------------------------------------ -vtkMatrix4x4* vtkZSpaceSDKManager::GetStereoProjectionMatrix(bool leftEye) -{ - return leftEye ? this->LeftEyeProjectionMatrix : this->RightEyeProjectionMatrix; -} - -//------------------------------------------------------------------------------ -void vtkZSpaceSDKManager::PrintSelf(ostream& os, vtkIndent indent) -{ - this->Superclass::PrintSelf(os, indent); - - os << indent << "WindowX: " << this->WindowX << "\n"; - os << indent << "WindowY: " << this->WindowY << "\n"; - os << indent << "WindowWidth: " << this->WindowWidth << "\n"; - os << indent << "WindowHeight: " << this->WindowHeight << "\n"; - os << indent << "NbDisplays: " << this->Displays.size() << "\n"; - for (auto const& display : this->Displays) - { - os << indent << "\t" << display << "\n"; - } - os << indent << "StylusTargets: " << this->StylusTargets << "\n"; - os << indent << "HeadTargets: " << this->HeadTargets << "\n"; - os << indent << "SecondaryTargets: " << this->SecondaryTargets << "\n"; - os << indent << "InterPupillaryDistance: " << this->InterPupillaryDistance << "\n"; - os << indent << "ViewerScale: " << this->ViewerScale << "\n"; - os << indent << "NearPlane: " << this->NearPlane << "\n"; - os << indent << "FarPlane: " << this->FarPlane << "\n"; - os << indent << "LeftButtonState: " << this->LeftButtonState << "\n"; - os << indent << "MiddleButtonState: " << this->MiddleButtonState << "\n"; - os << indent << "RightButtonState: " << this->RightButtonState << "\n"; -} diff --git a/Plugins/ZSpace/zSpace/vtkZSpaceSDKManager.h b/Plugins/ZSpace/zSpace/vtkZSpaceSDKManager.h deleted file mode 100644 index 7d1bbbfedc0..00000000000 --- a/Plugins/ZSpace/zSpace/vtkZSpaceSDKManager.h +++ /dev/null @@ -1,333 +0,0 @@ -/*========================================================================= - -Program: Visualization Toolkit - -Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen -All rights reserved. -See Copyright.txt or http://www.kitware.com/Copyright.htm for details. - -This software is distributed WITHOUT ANY WARRANTY; without even -the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -PURPOSE. See the above copyright notice for more information. - -=========================================================================*/ -/** - * @class vtkZSpaceSDKManager - * @brief Abstract zSpace SDK manager class. - * - * Abstract class handling the interactions between the zSpace plugin - * and the zSpace SDK. The implementation of virtual functions depend - * of the version of the zSpace SDK currently used : "zSpace Core SDK" - * (older) and zSpace Core Compatibility SDK (newer). - * - * This class encapsulates all the calls to the zSpace SDK : - * - Initializes the zSpace SDK via InitializeZSpace(). This method looks - * for a zSpace device and optional trackers. - * - Synchronizes the zSpace SDK and the plugin via the Update method. - * This method corresponds to these succesive calls : - * - UpdateViewport : send the viewport-relative informations to the - * zSpace SDK (position, interpupillary distance, near and far plane) - * in order to allow it to perform valid stereo frustum computations; - * - UpdateViewAndProjectionMatrix : retrieve the the view and projection - * matrix for each eye from the SDK (tied to the stereo frustum); - * - UpdateTrackers : retrieve the head pose and the trackers pose - * (such as the stylus) from the SDK; - * - UpdateButtonState : retrieve the state of the buttons of the stylus - * (Down, Pressed, Up or None) from the SDK. - * - * For button states, the states Down/Up are set by this class; whereas the states - * Pressed/None should be set by the calling class when the state Down/Up has been - * processed, to ensure that the same input won't be processed multiple times. - */ - -#ifndef vtkZSpaceSDKManager_h -#define vtkZSpaceSDKManager_h - -#include "vtkNew.h" // for vtkNew -#include "vtkObject.h" -#include "vtkZSpaceViewModule.h" // for export macro - -#include // for std::vector - -class vtkRenderWindow; -class vtkCamera; -class vtkMatrix4x4; -class vtkTransform; -class vtkPVZSpaceView; - -class VTKZSPACEVIEW_EXPORT vtkZSpaceSDKManager : public vtkObject -{ -public: - vtkTypeMacro(vtkZSpaceSDKManager, vtkObject); - void PrintSelf(ostream& os, vtkIndent indent) override; - - /** - * Return the singleton instance (with no reference counting) - * of a vtkZSpaceCoreSDKManager or vtkZSpaceCoreCompatibilitySDKManager - * depending on the curent zSpaceSDK in use. - */ - static vtkZSpaceSDKManager* GetInstance(); - - /** - * Initialize the zSpace SDK and check for zSpace devices : - * the display, the stylus and the head trackers. - */ - virtual void InitializeZSpace() = 0; - - /** - * Update the zSpace viewport position and size based - * on the position and size of the application window. - */ - virtual void UpdateViewport() = 0; - - /** - * Update the position of the stylus and head trakers. - */ - virtual void UpdateTrackers() = 0; - - /** - * Update the zSpace view and projection matrix for each eye. - */ - virtual void UpdateViewAndProjectionMatrix() = 0; - - /** - * Update the stylus buttons state. - */ - virtual void UpdateButtonState() = 0; - - /** - * Let zSpace compute the viewer scale, camera position and camera view up from the - * input bounds. - */ - virtual void CalculateFrustumFit( - const double bounds[6], double position[3], double viewUp[3]) = 0; - - ///@{ - /** - * Notify the zSpace SDK for the begining/end of a frame - * (vtkZSpaceCoreCompatibility only) - */ - virtual void BeginFrame() = 0; - virtual void EndFrame() = 0; - ///@} - - ///@{ - /** - * Set the render windwow the manager makes viewport computations - * from. - */ - virtual void SetRenderWindow(vtkRenderWindow* renderWindow); - ///@} - - /** - * Update the viewport, the trackers and the camera matrix - * by calling the zSpace SDK. - */ - void Update(); - - /** - * Get the x position of the upper left corner of the zSpace display - * in the virtual desktop. - */ - vtkGetMacro(WindowX, int); - - /** - * Get the y position of the upper left corner of the zSpace display - * in the virtual desktop. - */ - vtkGetMacro(WindowY, int); - - /** - * Get the x resolution in pixels of the zSpace display. - */ - vtkGetMacro(WindowWidth, int); - - /** - * Get the y resolution in pixels of the zSpace display. - */ - vtkGetMacro(WindowHeight, int); - - /** - * Get the number of stylus connected to the zSpace device. - */ - vtkGetMacro(StylusTargets, int); - - /** - * Get the number of glasses connected to the zSpace device. - */ - vtkGetMacro(HeadTargets, int); - - /** - * Get the number of secondary targets connected to the zSpace device. - */ - vtkGetMacro(SecondaryTargets, int); - - ///@{ - /** - * Get/Set the distance between the eyes in meters. - */ - vtkGetMacro(InterPupillaryDistance, float); - vtkSetClampMacro(InterPupillaryDistance, float, 0.f, 1.f); - ///@} - - /** - * Set the near and far plane. - */ - void SetClippingRange(const float nearPlane, const float farPlane); - - /** - * Get the viewer scale. - */ - vtkGetMacro(ViewerScale, float); - - /** - * Get the near plane. - */ - vtkGetMacro(NearPlane, float); - - /** - * Get the far plane. - */ - vtkGetMacro(FarPlane, float); - - /** - * Get the zSpace view matrix without stereo (eye set as EYE_CENTER) - * in row major format (VTK format) - */ - vtkGetObjectMacro(CenterEyeViewMatrix, vtkMatrix4x4); - - /** - * Get the zSpace view matrix for the right or left eye - * in row major format (VTK format) - */ - vtkMatrix4x4* GetStereoViewMatrix(bool leftEye); - - /** - * Get the zSpace projection matrix without stereo (eye set as EYE_CENTER) - * in row major format (VTK format) - */ - vtkGetObjectMacro(CenterEyeProjectionMatrix, vtkMatrix4x4); - - /** - * Get the zSpace projection matrix for the right or left eye - * in row major format (VTK format) - */ - vtkMatrix4x4* GetStereoProjectionMatrix(bool leftEye); - - /** - * Get the zSpace stylus matrix in world space. - * The matrix is in column major format and can be - * used by OpenGL. - */ - vtkGetObjectMacro(StylusMatrixColMajor, vtkMatrix4x4); - - /** - * Get the zSpace stylus matrix in world space. - * The matrix is in row major format and can be - * used by VTK. - */ - vtkGetObjectMacro(StylusMatrixRowMajor, vtkMatrix4x4); - - /** - * Get the zSpace stylus transform in world space. - * The transform has for matrix StylusMatrixRowMajor - */ - vtkGetObjectMacro(StylusTransformRowMajor, vtkTransform); - - enum ButtonIds - { - MiddleButton = 0, - RightButton = 1, - LeftButton = 2, - NumberOfButtons = 3 - }; - - enum ButtonState - { - Down = 0, - Pressed = 1, - Up = 2, - None = 3, - NumberOfStates = 4 - }; - - ///@{ - /** - * Get/Set the state of the left button of the stylus. - */ - vtkGetMacro(LeftButtonState, int); - vtkSetEnumMacro(LeftButtonState, ButtonState); - ///@} - - ///@{ - /** - * Get/Set the state of the middle button of the stylus. - */ - vtkGetMacro(MiddleButtonState, int); - vtkSetEnumMacro(MiddleButtonState, ButtonState); - ///@} - - ///@{ - /** - * Get/Set the state of the right button of the stylus. - */ - vtkGetMacro(RightButtonState, int); - vtkSetEnumMacro(RightButtonState, ButtonState); - ///@} - -protected: - vtkZSpaceSDKManager(); - ~vtkZSpaceSDKManager() override; - - vtkRenderWindow* RenderWindow; - - vtkNew CenterEyeViewMatrix; - vtkNew LeftEyeViewMatrix; - vtkNew RightEyeViewMatrix; - vtkNew CenterEyeProjectionMatrix; - vtkNew LeftEyeProjectionMatrix; - vtkNew RightEyeProjectionMatrix; - - // In column major format, used by openGL - vtkNew StylusMatrixColMajor; - - // In row major format, used by VTK - vtkNew StylusMatrixRowMajor; - vtkNew StylusTransformRowMajor; - - int WindowX = 0; - int WindowY = 0; - int WindowWidth = 0; - int WindowHeight = 0; - - // Store the type for each detected display devices - std::vector Displays; - // The number of stylus - int StylusTargets; - // The number of glasses - int HeadTargets; - // Additional targets - int SecondaryTargets; - - // Inter pupillary distance in meters - float InterPupillaryDistance = 0.056f; - float ViewerScale = 1.f; - // Camera near plane - float NearPlane = 0.01f; - // Camera far plane - float FarPlane = 10.f; - - // For interactions, store the state of each buttons - ButtonState LeftButtonState = None; - ButtonState MiddleButtonState = None; - ButtonState RightButtonState = None; - // Store buttons state to iterate over them - ButtonState* ButtonsState[NumberOfButtons] = { &MiddleButtonState, &RightButtonState, - &LeftButtonState }; - -private: - vtkZSpaceSDKManager(const vtkZSpaceSDKManager&) = delete; - void operator=(const vtkZSpaceSDKManager&) = delete; -}; - -#endif diff --git a/Plugins/ZSpace/zSpace/vtkZSpaceSDKVersion.h.in b/Plugins/ZSpace/zSpace/vtkZSpaceSDKVersion.h.in deleted file mode 100644 index 879a4cd8b4f..00000000000 --- a/Plugins/ZSpace/zSpace/vtkZSpaceSDKVersion.h.in +++ /dev/null @@ -1,20 +0,0 @@ -/*========================================================================= - -Program: Visualization Toolkit - -Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen -All rights reserved. -See Copyright.txt or http://www.kitware.com/Copyright.htm for details. - -This software is distributed WITHOUT ANY WARRANTY; without even -the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -PURPOSE. See the above copyright notice for more information. - -=========================================================================*/ - -#ifndef vtkZSpaceSDKVersion_h -#define vtkZSpaceSDKVersion_h - -#cmakedefine ZSPACE_USE_COMPAT_SDK - -#endif // vtkZSpaceSDKVersion_h diff --git a/Remoting/Views/vtkPVRenderView.cxx b/Remoting/Views/vtkPVRenderView.cxx index 529b3488115..578f38b4198 100644 --- a/Remoting/Views/vtkPVRenderView.cxx +++ b/Remoting/Views/vtkPVRenderView.cxx @@ -2767,6 +2767,35 @@ void vtkPVRenderView::ConfigureTexture(vtkTexture* texture) } } +//---------------------------------------------------------------------------- +void vtkPVRenderView::SetupAndSetRenderer(vtkRenderer* ren) +{ + // XXX We can consider to redesign the class in the future + // to find a cleaner way to change the renderer. + // All the following settings corresponds to those made on + // the initial renderer in the constructor. + ren->GetActiveCamera()->ParallelProjectionOff(); + ren->SetUseDepthPeeling(1); + ren->SetUseDepthPeelingForVolumes(1); + ren->SetAutomaticLightCreation(0); + + ren->AddCuller(this->Culler); + ren->AddActor(this->CenterAxes); + ren->AddActor(this->Skybox); + + vtkMemberFunctionCommand* observer = + vtkMemberFunctionCommand::New(); + observer->SetCallback(*this, &vtkPVRenderView::ResetCameraClippingRange); + ren->AddObserver(vtkCommand::ResetCameraClippingRangeEvent, observer); + observer->FastDelete(); + + this->RenderView->SetRenderer(ren); + this->SynchronizedRenderers->SetRenderer(ren); + this->CameraOrientationWidget->SetParentRenderer(ren); + this->OrientationWidget->SetParentRenderer(ren); + this->NonCompositedRenderer->SetActiveCamera(ren->GetActiveCamera()); +} + //---------------------------------------------------------------------------- void vtkPVRenderView::SetBackgroundMode(int val) { diff --git a/Remoting/Views/vtkPVRenderView.h b/Remoting/Views/vtkPVRenderView.h index 7e9ce40537e..e75518b8669 100644 --- a/Remoting/Views/vtkPVRenderView.h +++ b/Remoting/Views/vtkPVRenderView.h @@ -1182,6 +1182,13 @@ class VTKREMOTINGVIEWS_EXPORT vtkPVRenderView : public vtkPVView */ void ConfigureTexture(vtkTexture* texture); + /** + * Set the 3D renderer to use within the render view. + * This function modifies the input renderer in order + * to be usable by the render view. + */ + virtual void SetupAndSetRenderer(vtkRenderer* ren); + vtkLightKit* LightKit; vtkRenderViewBase* RenderView; vtkRenderer* NonCompositedRenderer;