From 356ea373ed3561630459a07de45c549a15c66cbd Mon Sep 17 00:00:00 2001 From: Krad Date: Mon, 24 Oct 2022 17:34:16 +0800 Subject: [PATCH] Change orientation cube text logic. --- .../Viewer/VolumeRenderingViewer.cpp | 103 +++++++++++++++++- .../Rendering/Viewer/VolumeRenderingViewer.h | 7 ++ 2 files changed, 108 insertions(+), 2 deletions(-) diff --git a/src/src/Rendering/Viewer/VolumeRenderingViewer.cpp b/src/src/Rendering/Viewer/VolumeRenderingViewer.cpp index d20b1d8..bfd3bc0 100644 --- a/src/src/Rendering/Viewer/VolumeRenderingViewer.cpp +++ b/src/src/Rendering/Viewer/VolumeRenderingViewer.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -19,6 +20,8 @@ #include #include #include +#include +#include #include "Interaction/VolumeInteractorStyle.h" @@ -46,7 +49,8 @@ VolumeRenderingViewer::VolumeRenderingViewer() , VolumeMapper(vtkFixedPointVolumeRayCastMapper::New()) , InteractorStyle(nullptr) , Interactor(nullptr) -, firstRender(true){ +, firstRender(true) +, OrientationMarker(vtkOrientationMarkerWidget::New()){ if (gpuMode){ auto mapper = vtkGPUVolumeRayCastMapper::New(); mapper->SetUseJittering(1); @@ -155,7 +159,11 @@ void VolumeRenderingViewer::InstallPipeline() { Renderer->AddObserver(vtkCommand::EndEvent,this, &VolumeRenderingViewer::renderAnnotation); this->Renderer->SetBackground(0.0, 0.0, 0.0); } - //TODO: annotation for orientation + if (this->OrientationMarker && this->OrientationMarker->GetOrientationMarker()){ + this->OrientationMarker->SetInteractor(this->Interactor); + this->OrientationMarker->EnabledOn(); + this->OrientationMarker->InteractiveOn(); + } } void VolumeRenderingViewer::UnInstallPipeline() { @@ -180,6 +188,11 @@ void VolumeRenderingViewer::UnInstallPipeline() { this->Interactor->SetInteractorStyle(nullptr); this->Interactor->SetRenderWindow(nullptr); } + if (this->OrientationMarker){ + this->OrientationMarker->SetInteractor(nullptr); + this->OrientationMarker->EnabledOff(); + this->OrientationMarker->InteractiveOff(); + } } void VolumeRenderingViewer::SetupInteractor(vtkRenderWindowInteractor * arg) { @@ -331,8 +344,94 @@ void VolumeRenderingViewer::SetInteractorStyleMode(int mode) { } } +char VolumeRenderingViewer::GetDirectionChar(const double *directionVector , int& worldDirection) const { + if (fabs(directionVector[0]) > 0.7){ + worldDirection = 0; + return directionVector[0] > 0 ? 'L' : 'R'; + } + if (fabs(directionVector[1])>0.7){ + worldDirection = 1; + return directionVector[1]>0?'P':'A'; + } + if (fabs(directionVector[2])>0.7){ + worldDirection = 2; + return directionVector[2]>0?'H':'F'; + } +} + +void invertVector(double* vector){ + for (int i = 0; i < 3; ++i) { + vector[i] = - vector[i]; + } +} + void VolumeRenderingViewer::SetCoordsTransformMatrix(ExtendMedicalImageProperties *pSeries) { OrientationMatrix->DeepCopy(pSeries->GetOrientationMatrix()); + + if (!OrientationMarker->GetOrientationMarker()) + { + vtkNew cube; + double zVector[4] = {.0, .0, 1., 1.}; + double yVector[4] = {.0, 1., .0, 1.}; + double xVector[4] = {1., .0, .0, 1.}; + OrientationMatrix->MultiplyPoint(zVector,zVector); + OrientationMatrix->MultiplyPoint(yVector,yVector); + OrientationMatrix->MultiplyPoint(xVector,xVector); + char txt[2] = " "; + int direction = -1; + + txt[0] = GetDirectionChar(zVector, direction); + cube->SetZPlusFaceText(txt); + invertVector(zVector); + txt[0] = GetDirectionChar(zVector); + cube->SetZMinusFaceText(txt); + + txt[0] = GetDirectionChar(yVector); + cube->SetYPlusFaceText(txt); + invertVector(yVector); + txt[0] = GetDirectionChar(yVector); + cube->SetYMinusFaceText(txt); + + txt[0] = GetDirectionChar(xVector); + cube->SetXPlusFaceText(txt); + invertVector(xVector); + txt[0] = GetDirectionChar(xVector); + cube->SetXMinusFaceText(txt); + switch (direction){ + //冠状面 + case 1: + { + vtkErrorMacro("coronal") + cube->SetZFaceTextRotation(-90); + cube->SetXFaceTextRotation(90); + cube->SetYFaceTextRotation(180); + break; + } + //矢状面 + case 0: + { + vtkErrorMacro("sagittal") + cube->SetZFaceTextRotation(-90); + cube->SetXFaceTextRotation(90); + cube->SetYFaceTextRotation(-90); + break; + } + case 2: + default: + { + vtkErrorMacro("transverse") + cube->SetZFaceTextRotation(-90); + } + } + + cube->GetTextEdgesProperty()->SetColor(1.0,1.0,.0); + cube->GetTextEdgesProperty()->SetLineWidth(2.0); + cube->GetCubeProperty()->SetColor(.0,.0,1.0); + OrientationMarker->SetOrientationMarker(cube); + this->OrientationMarker->SetInteractor(this->Interactor); + this->OrientationMarker->EnabledOn(); + this->OrientationMarker->InteractiveOn(); + } //change to WToM OrientationMatrix->Invert(); } diff --git a/src/src/Rendering/Viewer/VolumeRenderingViewer.h b/src/src/Rendering/Viewer/VolumeRenderingViewer.h index 5fbb8e2..3db8cee 100644 --- a/src/src/Rendering/Viewer/VolumeRenderingViewer.h +++ b/src/src/Rendering/Viewer/VolumeRenderingViewer.h @@ -15,6 +15,7 @@ class vtkImageData; class vtkInformation; +class vtkOrientationMarkerWidget; class vtkRenderWindow; @@ -115,11 +116,17 @@ private: vtkInteractorStyle *InteractorStyle; vtkRenderWindowInteractor *Interactor; vtkCornerAnnotation* annotation; + vtkOrientationMarkerWidget* OrientationMarker; vtkNew OrientationMatrix; bool gpuMode = false; bool firstRender = true; void GetDirectionString(const double *directionVector, std::string &str) const; + char GetDirectionChar(const double *directionVector, int& worldDirection) const; + char GetDirectionChar(const double *directionVector) const{ + int a; + return GetDirectionChar(directionVector, a); + } };