New slice logic. (Make mouse down always be increase slice index )

This commit is contained in:
Krad
2022-04-08 14:03:36 +08:00
parent 8c7ef57279
commit 50f7a50946
4 changed files with 118 additions and 78 deletions

View File

@@ -603,6 +603,14 @@ int infinitiViewer::GetSlice() {
return this->ImageMapper->GetSliceNumber();
}
void infinitiViewer::ChangeSlice(vtkObject *, unsigned long eventid, void *calldata) {
int lastSlice = GetSlice();
int* p = (int*)calldata;
int newSlice = lastSlice+(*p);
newSlice = newSlice<0?GetSliceMax():(newSlice>GetSliceMax()?0:newSlice);
SetSlice(newSlice);
}
void infinitiViewer::SetZoomScale(double scale) {
if (Renderer)
{
@@ -625,80 +633,6 @@ void infinitiViewer::SetPanOffset(double* p) {
}
//----------------------------------------------------------------------------
void infinitiViewer::SetSliceOrientation(int orientation)
{
if (orientation < infinitiViewer::SLICE_ORIENTATION_YZ ||
orientation > infinitiViewer::SLICE_ORIENTATION_XY)
{
vtkErrorMacro("Error - invalid slice orientation " << orientation);
return;
}
if (this->SliceOrientation == orientation)
{
return;
}
this->SliceOrientation = orientation;
// Update the viewer
int* range = this->GetSliceRange();
if (range)
{
this->Slice = static_cast<int>((range[0] + range[1]) * 0.5);
}
this->UpdateOrientation();
updateOrienInfo();
// this->UpdateDisplayExtent();
if (this->Renderer && this->GetInput())
{
double scale = this->Renderer->GetActiveCamera()->GetParallelScale();
this->Renderer->ResetCamera();
this->Renderer->GetActiveCamera()->SetParallelScale(scale);
}
// first render to update imageMapper slice
this->Render();
//use SetSlice as second render the first image
SetSlice(0);
}
//----------------------------------------------------------------------------
void infinitiViewer::UpdateOrientation()
{
// Set the camera position
vtkCamera* cam = this->Renderer ? this->Renderer->GetActiveCamera() : nullptr;
if (cam)
{
switch (this->SliceOrientation)
{
case infinitiViewer::SLICE_ORIENTATION_XY:
cam->SetFocalPoint(0, 0, 0);
cam->SetPosition(0, 0, 1); // -1 if medical ?
cam->SetViewUp(0, 1, 0);
break;
case infinitiViewer::SLICE_ORIENTATION_XZ:
cam->SetFocalPoint(0, 0, 0);
cam->SetPosition(0, 1, 0); // 1 if medical ?
cam->SetViewUp(0, 0, -1);
break;
case infinitiViewer::SLICE_ORIENTATION_YZ:
cam->SetFocalPoint(0, 0, 0);
cam->SetPosition( 1, 0, 0); // -1 if medical ?
cam->SetViewUp(0, 0, -1);
break;
}
}
}
//----------------------------------------------------------------------------
void infinitiViewer::SetPosition(int x, int y)
{
@@ -801,6 +735,7 @@ void infinitiViewer::InstallPipeline()
this->InteractorStyle->AddObserver(ActorDraggableInteractorStyle::DraggableStyleEvents::EndMeasureEvent, this, &infinitiViewer::AddMeasures);
this->InteractorStyle->AddObserver(ActorDraggableInteractorStyle::DraggableStyleEvents::DeleteMeasureEvent, this, &infinitiViewer::RemoveMeasures);
this->InteractorStyle->AddObserver(ActorDraggableInteractorStyle::DraggableStyleEvents::SliceEvent, this, &infinitiViewer::ChangeSlice);
this->InteractorStyle->AddObserver(ActorDraggableInteractorStyle::DraggableStyleEvents::SlicedEvent, this, &infinitiViewer::LoadMeasures);
//for convert vtkEvent to Qt signal
@@ -1145,6 +1080,80 @@ public:
}
};
//----------------------------------------------------------------------------
void infinitiViewer::SetSliceOrientation(int orientation)
{
if (orientation < infinitiViewer::SLICE_ORIENTATION_YZ ||
orientation > infinitiViewer::SLICE_ORIENTATION_XY)
{
vtkErrorMacro("Error - invalid slice orientation " << orientation);
return;
}
if (this->SliceOrientation == orientation)
{
return;
}
this->SliceOrientation = orientation;
// Update the viewer
int* range = this->GetSliceRange();
if (range)
{
this->Slice = static_cast<int>((range[0] + range[1]) * 0.5);
}
this->UpdateOrientation();
updateOrienInfo();
// this->UpdateDisplayExtent();
if (this->Renderer && this->GetInput())
{
double scale = this->Renderer->GetActiveCamera()->GetParallelScale();
this->Renderer->ResetCamera();
this->Renderer->GetActiveCamera()->SetParallelScale(scale);
}
// first render to update imageMapper slice
this->Render();
//use SetSlice as second render the first image
SetSlice(0);
}
//----------------------------------------------------------------------------
void infinitiViewer::UpdateOrientation()
{
// Set the camera position
vtkCamera* cam = this->Renderer ? this->Renderer->GetActiveCamera() : nullptr;
if (cam)
{
switch (this->SliceOrientation)
{
case infinitiViewer::SLICE_ORIENTATION_XY:
cam->SetFocalPoint(0, 0, 0);
cam->SetPosition(0, 0, -1); // -1 if medical ?
cam->SetViewUp(0, -1, 0);
break;
case infinitiViewer::SLICE_ORIENTATION_XZ:
cam->SetFocalPoint(0, 0, 0);
cam->SetPosition(0, 1, 0); // 1 if medical ?
cam->SetViewUp(0, 0, -1);
break;
case infinitiViewer::SLICE_ORIENTATION_YZ:
cam->SetFocalPoint(0, 0, 0);
cam->SetPosition( -1, 0, 0); // -1 if medical ?
cam->SetViewUp(0, 0, -1);
break;
}
}
}
void infinitiViewer::updateTopLeftCornerInfo()
{
if (AnnoHelper::IsAnno()) {
@@ -1288,7 +1297,7 @@ int getOrientationIndex(double* v){
if(fabs(v[1])>=fabs(v[2])) max_index=1;
else max_index = 2;
}
return v[max_index]>0?max_index*2:2*max_index+1;
return v[max_index]<0?max_index*2:2*max_index+1;
}
int getOppositeOrientation(int f){
@@ -1298,13 +1307,14 @@ int getOppositeOrientation(int f){
void infinitiViewer::updateOrienInfo()
{
static const char* dds[6] ={"R","L","P","A","F","H"};
static const char* dds[6] ={"R","L","A","P","F","H"};
double proj[4] ={0,0,0,1};
Renderer->GetActiveCamera()->GetDirectionOfProjection(proj);
double invertProj[4] ={-proj[0],-proj[1],-proj[2],1};
double viewUp[4]= {0,0,0,1};
this->Renderer->GetActiveCamera()->GetViewUp(viewUp);
double viewRight[4] = {0, 0, 0, 1};
vtkMath::Cross(viewUp,proj, viewRight);
vtkMath::Cross(proj,viewUp, viewRight);
double viewUpVector[4]= {0,0,0,1};
double viewRightVector[4]= {0,0,0,1};

View File

@@ -134,6 +134,8 @@ public:
virtual int* GetSliceRange();
//@}
void ChangeSlice(vtkObject*,unsigned long eventid,void* calldata);
//@{
/**
* Set window and level for mapping pixels to colors.

View File

@@ -321,6 +321,32 @@ void ActorDraggableInteractorStyle::WindowLevel()
}
}
void ActorDraggableInteractorStyle::Slice()
{
if (this->CurrentRenderer == nullptr)
{
return;
}
vtkRenderWindowInteractor *rwi = this->Interactor;
int dy = (-rwi->GetEventPosition()[1] + rwi->GetLastEventPosition()[1])/2;
// vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
//
//
// // scale the interaction by the height of the viewport
// double viewportHeight = 0.0;
// viewportHeight = camera->GetParallelScale();
//
//
// int *size = this->CurrentRenderer->GetSize();
// double delta = dy*viewportHeight/size[1];
// int dSlice = -(int)round(delta);
// printf("dy:%d,delta:%f,dslice:%d\r\n",dy,delta,dSlice);
void* p = &dy;
this->InvokeEvent(SliceEvent,p);
}
void ActorDraggableInteractorStyle::OnRightButtonDown()
{
this->InvokeEvent(AfterViewerClicked);

View File

@@ -37,6 +37,7 @@ public:
DragEndEvent,
StartMeasureEvent,
EndMeasureEvent,
SliceEvent,
SlicedEvent,
EndDollyEvent,
PopPropEvent,
@@ -74,7 +75,8 @@ public:
void EndDolly() override;
void WindowLevel()override;
void WindowLevel() override;
void Slice() override;
void SetCurrentImageNumber(int i) override;