From 5840c4476637196e2f731f20c1cfbeee6a6be79d Mon Sep 17 00:00:00 2001 From: Krad Date: Tue, 8 Nov 2022 14:26:11 +0800 Subject: [PATCH] Volume measure preparing1. --- src/src/Interaction/VolumeInteractorStyle.cpp | 62 +++++++++++++++---- src/src/Interaction/VolumeInteractorStyle.h | 40 +++++++++++- .../Viewer/VolumeRenderingViewer.cpp | 1 + 3 files changed, 88 insertions(+), 15 deletions(-) diff --git a/src/src/Interaction/VolumeInteractorStyle.cpp b/src/src/Interaction/VolumeInteractorStyle.cpp index f010078..b37131d 100644 --- a/src/src/Interaction/VolumeInteractorStyle.cpp +++ b/src/src/Interaction/VolumeInteractorStyle.cpp @@ -14,18 +14,22 @@ #include #include #include +#include #include +#include "Rendering/Core/DraggableActor.h" + vtkStandardNewMacro(VolumeInteractorStyle) VolumeInteractorStyle::VolumeInteractorStyle():vtkInteractorStyleTrackballCamera() -,InteractionMode(VOLUME_ROTATE3D) +,InteractionMode(VTKIS_VOLUME_ROTATE3D) +,picker(vtkPropPicker::New()) { } VolumeInteractorStyle::~VolumeInteractorStyle() { - + picker->Delete(); } void VolumeInteractorStyle::OnLeftButtonDown() { @@ -38,6 +42,36 @@ void VolumeInteractorStyle::OnLeftButtonDown() { } this->GrabFocus(this->EventCallbackCommand); + if (selectedProp) { + selectedProp->InvokeEvent(DraggableActor::DraggableActorEvents::UnSelectedEvent); + selectedProp = nullptr; + } + if (dragProp) { + selectedProp = dragProp; + selectedProp->InvokeEvent(DraggableActor::DraggableActorEvents::SelectedEvent); + if (this->Interactor->GetRepeatCount()) { + dragProp->InvokeEvent(DraggableStyleEvents::PopPropEvent, nullptr); + } + DragStartOrigin[0] = x; + DragStartOrigin[1] = y; + this->StartDrag(); + return; + } + if (Interactor->GetRepeatCount()) { + if (measure) { + measure->SetPlacing(measure->onMeasureDoubleClick(this->Interactor)); + if (!measure->isMeasurePlacing()) { + this->EndMeasure(); + auto temp = measure; + measure = measure->GetNextMeasure(); + if (!temp->Valid()) { + temp->ForceDelete(); + temp = nullptr; + } + } + return; + } + } switch(this->InteractionMode) { case VTKIS_VOLUME_ROTATE3D: { this->StartRotate(); @@ -122,7 +156,8 @@ void VolumeInteractorStyle::OnMouseMove() { this->InvokeEvent(vtkCommand::InteractionEvent, nullptr); break; } - this->Superclass::OnMouseMove(); + vtkInteractorStyleTrackballCamera::OnMouseMove(); + } void VolumeInteractorStyle::WindowLevel() { @@ -201,7 +236,7 @@ void VolumeInteractorStyle::GetCurrentVolumeProperty() { { return; } - + if (VolumeProperty)return; vtkPropCollection *props = this->CurrentRenderer->GetViewProps(); vtkProp *prop = nullptr; vtkAssemblyPath *path; @@ -218,15 +253,9 @@ void VolumeInteractorStyle::GetCurrentVolumeProperty() { { vtkProp *tryProp = path->GetLastNode()->GetViewProp(); volumeProp = vtkVolume::SafeDownCast(tryProp); - if (volumeProp) - { - if (volumeProp->GetPickable()) - { - foundImageProp = true; - break; - } - volumeProp = nullptr; - j++; + if (volumeProp) { + foundImageProp = true; + break; } } if (foundImageProp) @@ -251,3 +280,10 @@ void VolumeInteractorStyle::GetCurrentVolumeProperty() { } } +void VolumeInteractorStyle::Drag() { + int *pos = this->Interactor->GetEventPosition(); + this->FindPokedRenderer(pos[0], pos[1]); + DraggableActor::SafeDownCast(dragProp)->Transform(pos[0] - DragStartOrigin[0], pos[1] - DragStartOrigin[1]); + this->Interactor->Render(); +} + diff --git a/src/src/Interaction/VolumeInteractorStyle.h b/src/src/Interaction/VolumeInteractorStyle.h index 30c8f2f..a92cf59 100644 --- a/src/src/Interaction/VolumeInteractorStyle.h +++ b/src/src/Interaction/VolumeInteractorStyle.h @@ -9,6 +9,11 @@ #include "Rendering/Core/RenderingDefines.h" class vtkVolumeProperty; +class vtkPropPicker; +class vtkProp; +class Measure; + +#include class VolumeInteractorStyle:public vtkInteractorStyleTrackballCamera { public: @@ -16,9 +21,11 @@ public: vtkTypeMacro(VolumeInteractorStyle, vtkInteractorStyleTrackballCamera); - vtkSetClampMacro(InteractionMode, int, VOLUME_ROTATE3D, VOLUME_WINDOW); + vtkSetClampMacro(InteractionMode, int, VTKIS_VOLUME_ROTATE3D, VTKIS_VOLUME_WINDOW); vtkGetMacro(InteractionMode, int); +// vtkSetObjectMacro(MainRenderer,vtkRenderer) + virtual void StartWindowLevel(); virtual void EndWindowLevel(); void OnLeftButtonDown() override; @@ -37,6 +44,30 @@ protected: ~VolumeInteractorStyle() override; + void StartDrag() { + this->StartState(VTKIS_DRAG); + } + + void EndDrag() { + if (this->State != VTKIS_DRAG) { + return; + } + this->StopState(); + } + + void Drag(); + + void StartMeasure() { + this->StartState(VTKIS_MEASURE); + } + + void EndMeasure() { + if (this->State != VTKIS_MEASURE) { + return; + } + this->StopState(); + this->InvokeEvent(EndMeasureEvent, this->measure); + } private: VolumeInteractorStyle(const VolumeInteractorStyle &) = delete; @@ -47,7 +78,12 @@ private: int InteractionMode; vtkVolumeProperty* VolumeProperty = nullptr; - + vtkPropPicker* picker; + vtkProp *dragProp = nullptr; + vtkProp *selectedProp = nullptr; + Measure *measure = nullptr; + vtkRenderer* MainRenderer; + int DragStartOrigin[2] = {0, 0}; double WindowLevelInitial[2] = {0.0, 0.0}; double WindowLevelStartPosition[2] = {0.0, 0.0}; double WindowLevelCurrentPosition[2] = {0.0, 0.0}; diff --git a/src/src/Rendering/Viewer/VolumeRenderingViewer.cpp b/src/src/Rendering/Viewer/VolumeRenderingViewer.cpp index 43c9226..d699933 100644 --- a/src/src/Rendering/Viewer/VolumeRenderingViewer.cpp +++ b/src/src/Rendering/Viewer/VolumeRenderingViewer.cpp @@ -125,6 +125,7 @@ VolumeRenderingViewer::VolumeRenderingViewer() volumeProperty->SetSpecular(0.2); volumeProperty->SetSpecularPower(10.0); VolumeActor->SetProperty(volumeProperty); + VolumeActor->SetPickable(false); VolumeActor->SetMapper(VolumeMapper); vtkNew prop; prop->SetFontFamilyToArial();