Skip to content

Commit

Permalink
Merge topic 'zSpacePluginRework'
Browse files Browse the repository at this point in the history
a39752a Make zSpace plugin use dedicated VTK module
ac02164 Add renderer setter in vtkPVRenderView

Acked-by: Kitware Robot <[email protected]>
Reviewed-by: Mathieu Westphal <[email protected]>
Merge-request: !6024
  • Loading branch information
tomagal authored and kwrobot committed Jan 13, 2023
2 parents d5226af + a39752a commit 323a68a
Show file tree
Hide file tree
Showing 25 changed files with 81 additions and 3,304 deletions.
4 changes: 4 additions & 0 deletions Documentation/release/dev/zSpace-plugin-rework.md
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 0 additions & 11 deletions Plugins/ZSpace/cmake/FindzSpaceCompat.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
1 change: 1 addition & 0 deletions Plugins/ZSpace/paraview.plugin
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ DESCRIPTION
REQUIRES_MODULES
VTK::CommonCore
VTK::RenderingCore
VTK::RenderingZSpace
36 changes: 1 addition & 35 deletions Plugins/ZSpace/zSpace/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion Plugins/ZSpace/zSpace/ZSpaceView.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</IntVectorProperty>

<IntVectorProperty command="SetInteractivePicking"
default_values="1"
default_values="0"
name="InteractivePicking"
panel_visibility="advanced"
number_of_elements="1">
Expand Down
5 changes: 3 additions & 2 deletions Plugins/ZSpace/zSpace/vtk.module
Original file line number Diff line number Diff line change
Expand Up @@ -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
151 changes: 26 additions & 125 deletions Plugins/ZSpace/zSpace/vtkPVZSpaceView.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<vtkPVZSpaceView>* observer =
vtkMemberFunctionCommand<vtkPVZSpaceView>::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());
}
Expand All @@ -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())
{
Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -129,63 +130,10 @@ void vtkPVZSpaceView::ResetAllUserTransforms()
vtkActorCollection* actorCollection = this->GetRenderer()->GetActors();
vtkCollectionSimpleIterator ait;
vtkNew<vtkTransform> 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);
}
}

Expand All @@ -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();
}

Expand All @@ -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<vtkCamera> 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);
}
Loading

0 comments on commit 323a68a

Please sign in to comment.