Volume measure preparing1.

This commit is contained in:
Krad
2022-11-08 14:26:11 +08:00
parent 236294b971
commit 5840c44766
3 changed files with 88 additions and 15 deletions

View File

@@ -14,18 +14,22 @@
#include <vtkPropCollection.h>
#include <vtkAssemblyPath.h>
#include <vtkVolumeProperty.h>
#include <vtkPropPicker.h>
#include <vtkPiecewiseFunction.h>
#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,16 +253,10 @@ void VolumeInteractorStyle::GetCurrentVolumeProperty() {
{
vtkProp *tryProp = path->GetLastNode()->GetViewProp();
volumeProp = vtkVolume::SafeDownCast(tryProp);
if (volumeProp)
{
if (volumeProp->GetPickable())
{
if (volumeProp) {
foundImageProp = true;
break;
}
volumeProp = nullptr;
j++;
}
}
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();
}

View File

@@ -9,6 +9,11 @@
#include "Rendering/Core/RenderingDefines.h"
class vtkVolumeProperty;
class vtkPropPicker;
class vtkProp;
class Measure;
#include <vtkRenderer.h>
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};

View File

@@ -125,6 +125,7 @@ VolumeRenderingViewer::VolumeRenderingViewer()
volumeProperty->SetSpecular(0.2);
volumeProperty->SetSpecularPower(10.0);
VolumeActor->SetProperty(volumeProperty);
VolumeActor->SetPickable(false);
VolumeActor->SetMapper(VolumeMapper);
vtkNew<vtkTextProperty> prop;
prop->SetFontFamilyToArial();