Fix Reslice Image orientation bug.

This commit is contained in:
Krad
2023-01-09 16:51:36 +08:00
parent 679170af7c
commit 6f51e1e7f5
2 changed files with 24 additions and 8 deletions

View File

@@ -254,13 +254,13 @@ void ResliceImageViewer::SetDefaultSliceOrientation(int orientation) {
double position[4] = {.0, .0, .0, 1.};
double ViewUp[4] = {.0, .0, .0, 1.};
switch (orientation){
case 1:{
position[1] = -1.0;
case 0:{
position[0] = 1.0;
ViewUp[2] = 1.0;
break;
}
case 0:{
position[0] = 1.0;
case 1:{
position[1] = -1.0;
ViewUp[2] = 1.0;
break;
}
@@ -275,6 +275,7 @@ void ResliceImageViewer::SetDefaultSliceOrientation(int orientation) {
DefaultOrientation = orientation;
OrientationMatrix->MultiplyPoint(position,position);
OrientationMatrix->MultiplyPoint(ViewUp,ViewUp);
vtkCamera* camera = Renderer->GetActiveCamera();
camera->SetFocalPoint(.0, .0, .0);
camera->SetPosition(position);
@@ -284,9 +285,18 @@ void ResliceImageViewer::SetDefaultSliceOrientation(int orientation) {
}
void ResliceImageViewer::SetCoordsTransformMatrix(vtkMatrix4x4 *matrix4X4) {
OrientationMatrix->DeepCopy(matrix4X4);
OrientationMatrix->Invert();
//TODO:暂时使用特殊处理解决负向堆叠问题,考虑如何去除特殊处理
//默认的横断面Slice 需要考虑奇葩的负向堆叠
if (OrientationMatrix->IsIdentity()){
double zVec = Mapper->GetInput()->GetSpacing()[2];
OrientationMatrix->SetElement(2,2, zVec>0.0?1.0:-1.0);
}
}
void ResliceImageViewer::updateHandle(vtkObject* sender, unsigned long eventID, void* callData) {
@@ -387,8 +397,14 @@ void ResliceImageViewer::AdjustOrthogonalScale() {
vtkImageData * data = Mapper->GetInput();
int index = abs(((int)viewUp[0]) * 0 + ((int)viewUp[1]) * 1 + ((int)viewUp[2]) * 2);
double ratio = Renderer->GetTiledAspectRatio();
double pixelScale = data->GetDimensions()[index]*data->GetSpacing()[index];
camera->SetParallelScale(pixelScale/2-3);
if (ratio<1.0){
camera->SetParallelScale(pixelScale/2/ratio+3);
}
else{
camera->SetParallelScale(pixelScale/2+3);
}
}
void ResliceImageViewer::UpdateDirectionAnnotation() {

View File

@@ -210,20 +210,20 @@ void MPRResliceWindow::setRenderWindowLayout(LayoutType type) {
void MPRResliceWindow::loadData(SeriesImageSet *series) {
mViewerC->SetRenderWindow(mWidgetCoronal->renderWindow());
mViewerC->SetCoordsTransformMatrix(series->GetProperty()->GetOrientationMatrix());
mViewerC->SetInputData(series->GetData());
mViewerC->SetCoordsTransformMatrix(series->GetProperty()->GetOrientationMatrix());
mViewerC->SetDefaultSliceOrientation(2);
mViewerC->SetWindowLevel(mWindowLevel);
mViewerC->Render();
mViewerS->SetRenderWindow(mWidgetSagittal->renderWindow());
mViewerS->SetCoordsTransformMatrix(series->GetProperty()->GetOrientationMatrix());
mViewerS->SetInputData(series->GetData());
mViewerS->SetCoordsTransformMatrix(series->GetProperty()->GetOrientationMatrix());
mViewerS->SetDefaultSliceOrientation(1);
mViewerS->SetWindowLevel(mWindowLevel);
mViewerS->Render();
mViewerA->SetRenderWindow(mWidgetAxial->renderWindow());
mViewerA->SetCoordsTransformMatrix(series->GetProperty()->GetOrientationMatrix());
mViewerA->SetInputData(series->GetData());
mViewerA->SetCoordsTransformMatrix(series->GetProperty()->GetOrientationMatrix());
mViewerA->SetDefaultSliceOrientation(0);
mViewerA->SetWindowLevel(mWindowLevel);
mViewerA->Render();