Change orientation cube text logic.

This commit is contained in:
Krad
2022-10-24 17:34:16 +08:00
parent 2f5ad333da
commit 356ea373ed
2 changed files with 108 additions and 2 deletions

View File

@@ -10,6 +10,7 @@
#include <vtkRenderWindowInteractor.h>
#include <vtkCamera.h>
#include <vtkImageData.h>
#include <vtkProperty.h>
#include <vtkVolume.h>
#include <vtkVolumeProperty.h>
#include <vtkFixedPointVolumeRayCastMapper.h>
@@ -19,6 +20,8 @@
#include <vtkCornerAnnotation.h>
#include <vtkPlane.h>
#include <vtkBoundingBox.h>
#include <vtkOrientationMarkerWidget.h>
#include <vtkAnnotatedCubeActor.h>
#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<vtkAnnotatedCubeActor> 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();
}

View File

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