Fix Fusion Actor block bug.

This commit is contained in:
Krad
2022-04-15 09:27:00 +08:00
parent a8c67717a9
commit cba0b17c50
4 changed files with 75 additions and 17 deletions

View File

@@ -24,7 +24,7 @@
#include "ExtendMedicalImageProperties.h" #include "ExtendMedicalImageProperties.h"
#include "util/ColorMapReader.h" #include "util/ColorMapReader.h"
#include "vtkMath.h" #include "vtkMath.h"
#include "vtkImageStack.h"
@@ -44,12 +44,17 @@ void infinitiViewer::SetFusionInputData(vtkImageData* data)
if (!this->GetInput()) return; if (!this->GetInput()) return;
if (!simpleFusionableCheck(data, this->GetInput())) return; if (!simpleFusionableCheck(data, this->GetInput())) return;
if (!this->FusionMapper) { if (!this->FusionMapper) {
this->FusionMapper = vtkImageSliceMapper::New(); auto m = vtkImageSliceMapper::New();
// m->SetBaseImageMapper(ImageMapper);
this->FusionMapper = m;
this->FusionMapper->SliceAtFocalPointOn(); this->FusionMapper->SliceAtFocalPointOn();
this->FusionMapper->SliceFacesCameraOn(); this->FusionMapper->SliceFacesCameraOn();
FusionMapper->SetInputData(data); FusionMapper->SetInputData(data);
this->FusionActor = vtkImageSlice::New(); this->FusionActor = vtkImageSlice::New();
FusionActor->SetPickable(false); //must set fusion image slice layer to 1 to make main image is active layer of image stack
FusionActor->GetProperty()->SetLayerNumber(1);
FusionActor->SetPickable(false);
FusionActor->SetMapper(FusionMapper); FusionActor->SetMapper(FusionMapper);
} }
else if (data == FusionMapper->GetInput()) return; else if (data == FusionMapper->GetInput()) return;
@@ -286,7 +291,9 @@ void infinitiViewer::RemoveFusionActor()
void infinitiViewer::RemoveFusionData() void infinitiViewer::RemoveFusionData()
{ {
if (!FusionMapper) return; if (!FusionMapper) return;
if (Renderer->HasViewProp(FusionActor)) Renderer->RemoveViewProp(FusionActor); if (ImageStack->HasImage(FusionActor)) {
ImageStack->RemoveImage(FusionActor);
}
FusionMapper->Delete(); FusionMapper->Delete();
FusionMapper = nullptr; FusionMapper = nullptr;
FusionActor->Delete(); FusionActor->Delete();
@@ -303,12 +310,14 @@ infinitiViewer::infinitiViewer()
{ {
this->RenderWindow = nullptr; this->RenderWindow = nullptr;
this->Renderer = nullptr; this->Renderer = nullptr;
this->ImageStack = vtkImageStack::New();
this->ImageActor = vtkImageSlice::New(); this->ImageActor = vtkImageSlice::New();
this->ImageMapper = vtkImageSliceMapper::New(); this->ImageMapper = vtkImageSliceMapper::New();
this->ImageMapper->SliceAtFocalPointOn(); this->ImageMapper->SliceAtFocalPointOn();
this->ImageMapper->SliceFacesCameraOn(); this->ImageMapper->SliceFacesCameraOn();
this->ImageActor->SetPickable(true);
this->ImageActor->SetMapper(this->ImageMapper); this->ImageActor->SetMapper(this->ImageMapper);
ImageStack->AddImage(ImageActor);
this->FusionActor = nullptr; this->FusionActor = nullptr;
this->FusionMapper = nullptr; this->FusionMapper = nullptr;
this->Interactor = nullptr; this->Interactor = nullptr;
@@ -595,7 +604,12 @@ void infinitiViewer::SetSlice(int slice)
double npv = origin[this->SliceOrientation] + this->Slice * spacing[this->SliceOrientation]; double npv = origin[this->SliceOrientation] + this->Slice * spacing[this->SliceOrientation];
camera->SetDistance(fabs(npv - pos[this->SliceOrientation])); camera->SetDistance(fabs(npv - pos[this->SliceOrientation]));
if (Fusion && FusionMapper){
FusionMapper->SetClippingPlanes(ImageMapper->GetClippingPlanes());
}
this->Render(); this->Render();
this->InvokeEvent(infinitiViewerEvents::SlicedEvent, nullptr); this->InvokeEvent(infinitiViewerEvents::SlicedEvent, nullptr);
} }
@@ -611,6 +625,37 @@ void infinitiViewer::ChangeSlice(vtkObject *, unsigned long eventid, void *calld
SetSlice(newSlice); SetSlice(newSlice);
} }
vtkSmartPointer<vtkPoints> infinitiViewer::GetSliceBoundPoints(){
double bounds[6] ={.0, .0, .0, .0, .0, .0};
ImageMapper->GetBounds(bounds);
vtkCamera* camera = this->Renderer->GetActiveCamera();
double fpt[3] = {.0, .0, .0};
camera->GetFocalPoint(fpt);
bounds[SliceOrientation*2] = fpt[SliceOrientation];
vtkSmartPointer<vtkPoints> pts = vtkSmartPointer<vtkPoints>::New();
//只取4个点
pts->InsertNextPoint(bounds[0],bounds[2],bounds[4]);
if (SliceOrientation!=1){
pts->InsertNextPoint(bounds[0],bounds[3],bounds[4]);
if (SliceOrientation!=2) {
pts->InsertNextPoint(bounds[0], bounds[3], bounds[5]);
pts->InsertNextPoint(bounds[0], bounds[2], bounds[5]);
}
}
if (SliceOrientation!=0){
if (SliceOrientation!=1){
pts->InsertNextPoint(bounds[1],bounds[3],bounds[4]);
pts->InsertNextPoint(bounds[1],bounds[2],bounds[4]);
}
else{
pts->InsertNextPoint(bounds[1],bounds[2],bounds[4]);
pts->InsertNextPoint(bounds[1],bounds[2],bounds[5]);
pts->InsertNextPoint(bounds[0],bounds[2],bounds[5]);
}
}
return pts;
}
void infinitiViewer::SetZoomScale(double scale) { void infinitiViewer::SetZoomScale(double scale) {
if (Renderer) if (Renderer)
{ {
@@ -751,13 +796,14 @@ void infinitiViewer::InstallPipeline()
if (this->Renderer && this->ImageActor) if (this->Renderer && this->ImageActor)
{ {
this->Renderer->AddViewProp(this->ImageActor); this->Renderer->AddViewProp(this->ImageStack);
// this->Renderer->AddViewProp(this->ImageActor);
this->Renderer->GetActiveCamera()->SetParallelProjection(1); this->Renderer->GetActiveCamera()->SetParallelProjection(1);
this->Renderer->SetBackground(0.0, 0.0, 0.0); this->Renderer->SetBackground(0.0, 0.0, 0.0);
} }
if (this->Renderer && this->FusionActor && Fusion) if (this->Renderer && this->FusionActor && Fusion)
{ {
this->Renderer->AddViewProp(this->FusionActor); this->ImageStack->AddImage(this->FusionActor);
} }
if (this->Renderer && this->cornerAnnotation) if (this->Renderer && this->cornerAnnotation)
{ {
@@ -933,12 +979,16 @@ void infinitiViewer::Render()
} }
if (this->GetInput()) if (this->GetInput())
{ {
if (Fusion && FusionActor && !this->Renderer->HasViewProp(FusionActor)) { if (Fusion && FusionActor && !this->ImageStack->HasImage(FusionActor)) {
this->Renderer->AddActor(FusionActor); // this->Renderer->AddActor(FusionActor);
this->ImageStack->AddImage(FusionActor);
} }
if (!Fusion && FusionActor && this->Renderer->HasViewProp(FusionActor)) if (!Fusion && FusionActor && this->ImageStack->HasImage(FusionActor))
{ {
this->Renderer->RemoveViewProp(FusionActor); // this->Renderer->RemoveViewProp(FusionActor);
this->ImageStack->RemoveImage(FusionActor);
} }
this->LoadMeasures(); this->LoadMeasures();
this->RenderWindow->Render(); this->RenderWindow->Render();

View File

@@ -15,6 +15,7 @@
class vtkAlgorithm; class vtkAlgorithm;
class vtkAlgorithmOutput; class vtkAlgorithmOutput;
class vtkImageStack;
class vtkImageSlice; class vtkImageSlice;
class vtkLookupTable; class vtkLookupTable;
class vtkScalarsToColors; class vtkScalarsToColors;
@@ -135,6 +136,7 @@ public:
//@} //@}
void ChangeSlice(vtkObject*,unsigned long eventid,void* calldata); void ChangeSlice(vtkObject*,unsigned long eventid,void* calldata);
vtkSmartPointer<vtkPoints> GetSliceBoundPoints();
//@{ //@{
/** /**
@@ -330,6 +332,7 @@ protected:
vtkRenderWindow* RenderWindow; vtkRenderWindow* RenderWindow;
vtkRenderer* Renderer; vtkRenderer* Renderer;
vtkImageStack* ImageStack;
vtkImageSlice* ImageActor; vtkImageSlice* ImageActor;
vtkImageSlice* FusionActor; vtkImageSlice* FusionActor;
vtkImageSliceMapper* ImageMapper; vtkImageSliceMapper* ImageMapper;
@@ -367,7 +370,7 @@ private:
void updateTopLeftCornerInfo(); void updateTopLeftCornerInfo();
infinitiViewer(const infinitiViewer&) = delete; infinitiViewer(const infinitiViewer&) = delete;
void operator=(const infinitiViewer&) = delete; void operator=(const infinitiViewer&) = delete;

View File

@@ -13,6 +13,7 @@
#include "vtkProp.h" #include "vtkProp.h"
#include "vtkPropCollection.h" #include "vtkPropCollection.h"
#include "vtkImageSlice.h" #include "vtkImageSlice.h"
#include "vtkImageStack.h"
#include "vtkAssemblyPath.h" #include "vtkAssemblyPath.h"
#include "vtkRenderer.h" #include "vtkRenderer.h"
#include "vtkImageSliceMapper.h" #include "vtkImageSliceMapper.h"
@@ -489,6 +490,7 @@ void ActorDraggableInteractorStyle::DispatchEvent() {
//重写部分逻辑在取imageProperty的时候把ImageSlice也取了。 //重写部分逻辑在取imageProperty的时候把ImageSlice也取了。
void ActorDraggableInteractorStyle::SetCurrentImageNumber(int i) void ActorDraggableInteractorStyle::SetCurrentImageNumber(int i)
{ {
// return;
this->CurrentImageNumber = i; this->CurrentImageNumber = i;
if (!this->CurrentRenderer) if (!this->CurrentRenderer)
{ {
@@ -512,7 +514,7 @@ void ActorDraggableInteractorStyle::SetCurrentImageNumber(int i)
imageProp = vtkImageSlice::SafeDownCast(tryProp); imageProp = vtkImageSlice::SafeDownCast(tryProp);
if (imageProp) if (imageProp)
{ {
if (j == i && imageProp->GetPickable()) if (j == i)
{ {
foundImageProp = true; foundImageProp = true;
break; break;

View File

@@ -7,6 +7,7 @@
#include <vtkPropPicker.h> #include <vtkPropPicker.h>
#include <vtkPointPicker.h> #include <vtkPointPicker.h>
#include <vtkImageSlice.h>
#include "vtkInteractorStyleImage.h" #include "vtkInteractorStyleImage.h"
#include "vtkNew.h" // For ivars #include "vtkNew.h" // For ivars
#include "functional" #include "functional"
@@ -120,10 +121,12 @@ public:
} }
void ActiveMeasure(Measure* m); void ActiveMeasure(Measure* m);
void UnActiveMeasure(); void UnActiveMeasure();
//void SetCornderAnnoEna(bool enable)
//{ void SetCurrentImageSlice(vtkImageSlice* slice){
// isCornderAnno = enable; CurrentImageSlice = slice;
//} CurrentImageProperty = slice->GetProperty();
}
protected: protected:
ActorDraggableInteractorStyle(); ActorDraggableInteractorStyle();