--- /dev/null
+/**
+* Progam made by Olivier Bernard, associate professor
+* at Institut National des Sciences Appliquees (INSA) Lyon,
+* CREATIS-LRMN Laboratory,
+* 69621 Villeurbanne, France,
+* 20th of May 2014
+*/
+
+#include <vtkRenderer.h>
+#include <vtkRenderWindow.h>
+#include "vtkMyInteractorStyleTrackballCameraOpenHeart.h"
+
+
+using namespace std;
+
+
+void vtkMyInteractorStyleTrackballCameraOpenHeart::OnChar()
+{
+ vtkRenderWindowInteractor *rwi = this->Interactor;
+ switch (rwi->GetKeyCode())
+ {
+ case 'f':
+ {
+ int val = this->window->GetCurrentFrame();
+ if ( val < (this->window->GetNumberOfFrames()-1) )
+ this->window->scrollBar->setSliderPosition(val+1);
+ else {
+ this->window->SetFlagLoopEndToBegin(1);
+ this->window->scrollBar->setSliderPosition(0);
+ }
+ break;
+ }
+ case 'b':
+ {
+ int val = this->window->GetCurrentFrame();
+ if ( val > 0 )
+ this->window->scrollBar->setSliderPosition(val-1);
+ else {
+ this->window->SetFlagLoopBeginToEnd(1);
+ this->window->scrollBar->setSliderPosition(this->window->GetNumberOfFrames()-1);
+ }
+ break;
+ }
+ case 'o':
+ {
+ /// Deal with the display of a mask overlayed on the volume data
+ this->window->InterpolationManagement();
+ break;
+ }
+ case 'm':
+ {
+ /// Reset the sphere display
+ this->window->DisplayMeshManagement();
+ break;
+ }
+ case 'd':
+ {
+ /// Set the display mode
+ this->window->DisplayModeManagement();
+ break;
+ }
+ case 'h':
+ {
+ this->window->HidePlanModeManagement();
+ break;
+ }
+ case 'a':
+ {
+ this->window->DisplayMainAxisManagement();
+ }
+ default:
+ cout << "";
+ }
+
+}
+
+
+void vtkMyInteractorStyleTrackballCameraOpenHeart::OnMouseWheelForward()
+{
+
+ switch ( this->window->GetSelectedButton() ) {
+
+ case 1 :
+ this->MoveForwardYZPlan();
+ break;
+
+ case 2:
+
+ this->MoveForwardXZPlan();
+ break;
+
+ case 3:
+
+ this->MoveForwardXYPlan();
+ break;
+
+ default:
+
+ this->MoveForward();
+
+ }
+
+}
+
+
+void vtkMyInteractorStyleTrackballCameraOpenHeart::OnMouseWheelBackward()
+{
+
+ switch ( this->window->GetSelectedButton() )
+ {
+
+ case 1 :
+ this->MoveBackwardYZPlan();
+ break;
+
+ case 2:
+
+ this->MoveBackwardXZPlan();
+ break;
+
+ case 3:
+
+ this->MoveBackwardXYPlan();
+ break;
+
+ default:
+
+ this->MoveBackward();
+
+ }
+
+}
+
+
+void vtkMyInteractorStyleTrackballCameraOpenHeart::MoveForward()
+{
+
+ /// Get picker position
+ double pos[3];
+ this->GetPickerPosition(pos);
+
+ /// Go back to the initial coordinate system before reslicing
+ double posXYZ[3];
+ for (int i=0; i<3; i++)
+ posXYZ[i] = pos[i];
+ this->window->ComputePointBeforeRotation(posXYZ);
+
+ /// Compute point of interest for checking which plan is selected
+ double RefX[3];
+ for (int i=0; i<3; i++)
+ RefX[i] = this->window->GetRendererProperties()->xIPW->GetCenter()[i];
+ this->window->ComputePointBeforeRotation(RefX);
+ double RefY[3];
+ for (int i=0; i<3; i++)
+ RefY[i] = this->window->GetRendererProperties()->yIPW->GetCenter()[i];
+ this->window->ComputePointBeforeRotation(RefY);
+ double RefZ[3];
+ for (int i=0; i<3; i++)
+ RefZ[i] = this->window->GetRendererProperties()->zIPW->GetCenter()[i];
+ this->window->ComputePointBeforeRotation(RefZ);
+
+ /// Update Slice image
+ if ( this->IsInside(posXYZ) )
+ {
+
+ if ( fabs(posXYZ[0]-RefX[0]) < this->PadSliceDetection[0] )
+ {
+
+ /// Compute corresponding step
+ if ( (posXYZ[1] >= this->Limits[2] ) &&
+ (posXYZ[1] <= this->Limits[3] ) &&
+ (posXYZ[2] >= this->Limits[4] ) &&
+ (posXYZ[2] <= this->Limits[5] ) )
+ this->Step = 1;
+ else
+ this->Step = 5;
+
+ /// Compute new slice position
+ double limit = this->Bounds[1];
+ posXYZ[0] += this->Step * this->SpacingImg[0];
+ if ( posXYZ[0] <= limit )
+ this->window->GetRendererProperties()->position[0] += this->Step * this->SpacingImg[0];
+
+ /// Update Slice text
+ if ( this->window->GetFlagDisplayText() )
+ {
+ int slice = (int)( (this->window->GetRendererProperties()->position[0] -
+ this->OriginImg[0]) /
+ this->SpacingImg[0] + 0.5f );
+ QString strSlice;
+ strSlice.sprintf("Slice: %d",slice);
+ this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
+ }
+
+ /// Update renderers
+ this->window->GetRendererProperties()->xIPW->SetSlicePosition(this->window->GetRendererProperties()->position[0]);
+ this->window->GetRendererProperties()->yzIPW->SetSlicePosition(this->window->GetRendererProperties()->position[0]);
+ this->window->GetRenderWindow()->Render();
+ this->window->GetYZRenderer()->ResetCameraClippingRange();
+ this->window->GetRenderWindowYZ()->Render();
+ }
+
+ if ( fabs(posXYZ[1]-RefY[1]) < this->PadSliceDetection[1] )
+ {
+
+ /// Compute corresponding step
+ if ( (posXYZ[0] >= this->Limits[0] ) &&
+ (posXYZ[0] <= this->Limits[1] ) &&
+ (posXYZ[2] >= this->Limits[4] ) &&
+ (posXYZ[2] <= this->Limits[5] ) )
+ this->Step = 1;
+ else
+ this->Step = 5;
+
+ /// Compute new slice position
+ double limit = this->Bounds[3];
+ posXYZ[1] += this->Step * this->SpacingImg[1];
+ if ( posXYZ[1] <= limit )
+ this->window->GetRendererProperties()->position[1] += this->Step * this->SpacingImg[1];
+
+ /// Update Slice text
+ if ( this->window->GetFlagDisplayText() )
+ {
+ int slice = (int)( (this->window->GetRendererProperties()->position[1] -
+ this->OriginImg[1]) /
+ this->SpacingImg[1] + 0.5f );
+ QString strSlice;
+ strSlice.sprintf("Slice: %d",slice);
+ this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
+ }
+
+ /// Update renderers
+ this->window->GetRendererProperties()->yIPW->SetSlicePosition(this->window->GetRendererProperties()->position[1]);
+ this->window->GetRendererProperties()->xzIPW->SetSlicePosition(this->window->GetRendererProperties()->position[1]);
+ this->window->GetRenderWindow()->Render();
+ this->window->GetXZRenderer()->ResetCameraClippingRange();
+ this->window->GetRenderWindowXZ()->Render();
+ }
+
+ if ( fabs(posXYZ[2]-RefZ[2]) < this->PadSliceDetection[2] )
+ {
+
+ /// Compute corresponding step
+ if ( (posXYZ[0] >= this->Limits[0] ) &&
+ (posXYZ[0] <= this->Limits[1] ) &&
+ (posXYZ[1] >= this->Limits[2] ) &&
+ (posXYZ[1] <= this->Limits[3] ) )
+ this->Step = 1;
+ else
+ this->Step = 5;
+
+ /// Compute new slice position
+ double limit = this->Bounds[5];
+ posXYZ[2] += this->Step * this->SpacingImg[2];
+ if ( posXYZ[2] <= limit )
+ this->window->GetRendererProperties()->position[2] += this->Step * this->SpacingImg[2];
+
+ /// Update Slice text
+ if ( this->window->GetFlagDisplayText() )
+ {
+ int slice = (int)( (this->window->GetRendererProperties()->position[2] -
+ this->OriginImg[2]) /
+ this->SpacingImg[2] + 0.5f );
+ QString strSlice;
+ strSlice.sprintf("Slice: %d",slice);
+ this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
+ }
+
+ /// Update renderers
+ this->window->GetRendererProperties()->zIPW->SetSlicePosition(this->window->GetRendererProperties()->position[2]);
+ this->window->GetRendererProperties()->xyIPW->SetSlicePosition(this->window->GetRendererProperties()->position[2]);
+ this->window->GetRenderWindow()->Render();
+ this->window->GetXYRenderer()->ResetCameraClippingRange();
+ this->window->GetRenderWindowXY()->Render();
+ }
+
+ }
+
+ /// Update text display
+ this->window->UpdateCoords(pos);
+
+}
+
+
+void vtkMyInteractorStyleTrackballCameraOpenHeart::MoveForwardXYPlan()
+{
+
+ /// Get picker position
+ double pos[3];
+ this->GetPickerPosition(pos);
+
+ /// Go back to the initial coordinate system before reslicing
+ double posXYZ[3];
+ for (int i=0; i<3; i++)
+ posXYZ[i] = pos[i];
+ this->window->ComputePointBeforeRotation(posXYZ);
+
+ /// Update Slice image
+ if ( this->IsInside(posXYZ) )
+ {
+ /// Compute corresponding step
+ if ( (posXYZ[0] >= this->Limits[0] ) &&
+ (posXYZ[0] <= this->Limits[1] ) &&
+ (posXYZ[1] >= this->Limits[2] ) &&
+ (posXYZ[1] <= this->Limits[3] ) )
+ this->Step = 1;
+ else
+ this->Step = 5;
+
+ /// Compute new slice position
+ double limit = this->Bounds[5];
+ posXYZ[2] += this->Step * this->window->GetCurrentImageData()->GetSpacing()[2];
+ if ( posXYZ[2] <= limit )
+ this->window->GetRendererProperties()->position[2] += this->Step * this->window->GetCurrentImageData()->GetSpacing()[2];
+
+ /// Update Slice text
+ if ( this->window->GetFlagDisplayText() )
+ {
+ int slice = (int)( (this->window->GetRendererProperties()->position[2] -
+ this->window->GetCurrentImageData()->GetOrigin()[2]) /
+ this->window->GetCurrentImageData()->GetSpacing()[2] + 0.5f );
+ QString strSlice;
+ strSlice.sprintf("Slice: %d",slice);
+ this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
+ }
+
+ /// Update renderers
+ this->window->GetRendererProperties()->zIPW->SetSlicePosition(this->window->GetRendererProperties()->position[2]);
+ this->window->GetRendererProperties()->xyIPW->SetSlicePosition(this->window->GetRendererProperties()->position[2]);
+ this->window->GetRenderWindow()->Render();
+ this->window->GetXYRenderer()->ResetCameraClippingRange();
+ this->window->GetRenderWindowXY()->Render();
+
+ }
+
+}
+
+
+void vtkMyInteractorStyleTrackballCameraOpenHeart::MoveForwardXZPlan()
+{
+
+ /// Get picker position
+ double pos[3];
+ this->GetPickerPosition(pos);
+
+ /// Go back to the initial coordinate system before reslicing
+ double posXYZ[3];
+ for (int i=0; i<3; i++)
+ posXYZ[i] = pos[i];
+ this->window->ComputePointBeforeRotation(posXYZ);
+
+ /// Update Slice image
+ if ( this->IsInside(posXYZ) )
+ {
+ /// Compute corresponding step
+ if ( (posXYZ[0] >= this->Limits[0] ) &&
+ (posXYZ[0] <= this->Limits[1] ) &&
+ (posXYZ[2] >= this->Limits[4] ) &&
+ (posXYZ[2] <= this->Limits[5] ) )
+ this->Step = 1;
+ else
+ this->Step = 5;
+
+ /// Compute new slice position
+ double limit = this->Bounds[3];
+ posXYZ[1] += this->Step * this->window->GetCurrentImageData()->GetSpacing()[1];
+ if ( posXYZ[1] <= limit )
+ this->window->GetRendererProperties()->position[1] += this->Step * this->window->GetCurrentImageData()->GetSpacing()[1];
+
+ /// Update Slice text
+ if ( this->window->GetFlagDisplayText() )
+ {
+ int slice = (int)( (this->window->GetRendererProperties()->position[1] -
+ this->window->GetCurrentImageData()->GetOrigin()[1]) /
+ this->window->GetCurrentImageData()->GetSpacing()[1] + 0.5f );
+ QString strSlice;
+ strSlice.sprintf("Slice: %d",slice);
+ this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
+ }
+
+ /// Update renderers
+ this->window->GetRendererProperties()->yIPW->SetSlicePosition(this->window->GetRendererProperties()->position[1]);
+ this->window->GetRendererProperties()->xzIPW->SetSlicePosition(this->window->GetRendererProperties()->position[1]);
+ this->window->GetRenderWindow()->Render();
+ this->window->GetXZRenderer()->ResetCameraClippingRange();
+ this->window->GetRenderWindowXZ()->Render();
+
+ }
+
+}
+
+
+void vtkMyInteractorStyleTrackballCameraOpenHeart::MoveForwardYZPlan()
+{
+
+ /// Get picker position
+ double pos[3];
+ this->GetPickerPosition(pos);
+
+ /// Go back to the initial coordinate system before reslicing
+ double posXYZ[3];
+ for (int i=0; i<3; i++)
+ posXYZ[i] = pos[i];
+ this->window->ComputePointBeforeRotation(posXYZ);
+
+ /// Update Slice image
+ if ( this->IsInside(posXYZ) )
+ {
+ /// Compute corresponding step
+ if ( (posXYZ[1] >= this->Limits[2] ) &&
+ (posXYZ[1] <= this->Limits[3] ) &&
+ (posXYZ[2] >= this->Limits[4] ) &&
+ (posXYZ[2] <= this->Limits[5] ) )
+ this->Step = 1;
+ else
+ this->Step = 5;
+
+ /// Compute new slice position
+ double limit = this->Bounds[1];
+ posXYZ[0] += this->Step * this->window->GetCurrentImageData()->GetSpacing()[0];
+ if ( posXYZ[0] <= limit )
+ this->window->GetRendererProperties()->position[0] += this->Step * this->window->GetCurrentImageData()->GetSpacing()[0];
+
+ /// Update Slice text
+ if ( this->window->GetFlagDisplayText() )
+ {
+ int slice = (int)( (this->window->GetRendererProperties()->position[0] -
+ this->window->GetCurrentImageData()->GetOrigin()[0]) /
+ this->window->GetCurrentImageData()->GetSpacing()[0] + 0.5f );
+ QString strSlice;
+ strSlice.sprintf("Slice: %d",slice);
+ this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
+ }
+
+ /// Update renderers
+ this->window->GetRendererProperties()->xIPW->SetSlicePosition(this->window->GetRendererProperties()->position[0]);
+ this->window->GetRendererProperties()->yzIPW->SetSlicePosition(this->window->GetRendererProperties()->position[0]);
+ this->window->GetRenderWindow()->Render();
+ this->window->GetYZRenderer()->ResetCameraClippingRange();
+ this->window->GetRenderWindowYZ()->Render();
+
+ }
+
+}
+
+
+void vtkMyInteractorStyleTrackballCameraOpenHeart::MoveBackwardXYPlan()
+{
+
+ /// Get picker position
+ double pos[3];
+ this->GetPickerPosition(pos);
+
+ /// Go back to the initial coordinate system before reslicing
+ double posXYZ[3];
+ for (int i=0; i<3; i++)
+ posXYZ[i] = pos[i];
+ this->window->ComputePointBeforeRotation(posXYZ);
+
+ /// Update Slice image
+ if ( this->IsInside(posXYZ) )
+ {
+ /// Compute corresponding step
+ if ( (posXYZ[0] >= this->Limits[0] ) &&
+ (posXYZ[0] <= this->Limits[1] ) &&
+ (posXYZ[1] >= this->Limits[2] ) &&
+ (posXYZ[1] <= this->Limits[3] ) )
+ this->Step = 1;
+ else
+ this->Step = 5;
+
+ /// Compute new slice position
+ posXYZ[2] -= this->Step * this->window->GetCurrentImageData()->GetSpacing()[2];
+ if ( posXYZ[2] >= 0 )
+ this->window->GetRendererProperties()->position[2] -= this->Step * this->window->GetCurrentImageData()->GetSpacing()[2];
+
+ /// Update Slice text
+ if ( this->window->GetFlagDisplayText() )
+ {
+ int slice = (int)( (this->window->GetRendererProperties()->position[2] -
+ this->window->GetCurrentImageData()->GetOrigin()[2]) /
+ this->window->GetCurrentImageData()->GetSpacing()[2] + 0.5f );
+ QString strSlice;
+ strSlice.sprintf("Slice: %d",slice);
+ this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
+ }
+
+ /// Update renderers
+ this->window->GetRendererProperties()->zIPW->SetSlicePosition(this->window->GetRendererProperties()->position[2]);
+ this->window->GetRendererProperties()->xyIPW->SetSlicePosition(this->window->GetRendererProperties()->position[2]);
+ this->window->GetRenderWindow()->Render();
+ this->window->GetXYRenderer()->ResetCameraClippingRange();
+ this->window->GetRenderWindowXY()->Render();
+
+ }
+
+}
+
+
+void vtkMyInteractorStyleTrackballCameraOpenHeart::MoveBackwardXZPlan()
+{
+
+ /// Get picker position
+ double pos[3];
+ this->GetPickerPosition(pos);
+
+ /// Go back to the initial coordinate system before reslicing
+ double posXYZ[3];
+ for (int i=0; i<3; i++)
+ posXYZ[i] = pos[i];
+ this->window->ComputePointBeforeRotation(posXYZ);
+
+ /// Update Slice image
+ if ( this->IsInside(posXYZ) )
+ {
+ /// Compute corresponding step
+ if ( (posXYZ[0] >= this->Limits[0] ) &&
+ (posXYZ[0] <= this->Limits[1] ) &&
+ (posXYZ[2] >= this->Limits[4] ) &&
+ (posXYZ[2] <= this->Limits[5] ) )
+ this->Step = 1;
+ else
+ this->Step = 5;
+
+ /// Compute new slice position
+ posXYZ[1] -= this->Step * this->window->GetCurrentImageData()->GetSpacing()[1];
+ if ( posXYZ[1] >= 0 )
+ this->window->GetRendererProperties()->position[1] -= this->Step * this->window->GetCurrentImageData()->GetSpacing()[1];
+
+ /// Update Slice text
+ if ( this->window->GetFlagDisplayText() )
+ {
+ int slice = (int)( (this->window->GetRendererProperties()->position[1] -
+ this->window->GetCurrentImageData()->GetOrigin()[1]) /
+ this->window->GetCurrentImageData()->GetSpacing()[1] + 0.5f );
+ QString strSlice;
+ strSlice.sprintf("Slice: %d",slice);
+ this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
+ }
+
+ /// Update renderers
+ this->window->GetRendererProperties()->yIPW->SetSlicePosition(this->window->GetRendererProperties()->position[1]);
+ this->window->GetRendererProperties()->xzIPW->SetSlicePosition(this->window->GetRendererProperties()->position[1]);
+ this->window->GetRenderWindow()->Render();
+ this->window->GetXZRenderer()->ResetCameraClippingRange();
+ this->window->GetRenderWindowXZ()->Render();
+
+ }
+
+}
+
+
+void vtkMyInteractorStyleTrackballCameraOpenHeart::MoveBackwardYZPlan()
+{
+
+ /// Get picker position
+ double pos[3];
+ this->GetPickerPosition(pos);
+
+ /// Go back to the initial coordinate system before reslicing
+ double posXYZ[3];
+ for (int i=0; i<3; i++)
+ posXYZ[i] = pos[i];
+ this->window->ComputePointBeforeRotation(posXYZ);
+
+ /// Update Slice image
+ if ( this->IsInside(posXYZ) )
+ {
+ /// Compute corresponding step
+ if ( (posXYZ[1] >= this->Limits[2] ) &&
+ (posXYZ[1] <= this->Limits[3] ) &&
+ (posXYZ[2] >= this->Limits[4] ) &&
+ (posXYZ[2] <= this->Limits[5] ) )
+ this->Step = 1;
+ else
+ this->Step = 5;
+
+ /// Compute new slice position
+ posXYZ[0] -= this->Step * this->window->GetCurrentImageData()->GetSpacing()[0];
+ if ( posXYZ[0] >= 0 )
+ this->window->GetRendererProperties()->position[0] -= this->Step * this->window->GetCurrentImageData()->GetSpacing()[0];
+
+ /// Update Slice text
+ if ( this->window->GetFlagDisplayText() )
+ {
+ int slice = (int)( (this->window->GetRendererProperties()->position[0] -
+ this->window->GetCurrentImageData()->GetOrigin()[0]) /
+ this->window->GetCurrentImageData()->GetSpacing()[0] + 0.5f );
+ QString strSlice;
+ strSlice.sprintf("Slice: %d",slice);
+ this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
+ }
+
+ /// Update renderers
+ this->window->GetRendererProperties()->xIPW->SetSlicePosition(this->window->GetRendererProperties()->position[0]);
+ this->window->GetRendererProperties()->yzIPW->SetSlicePosition(this->window->GetRendererProperties()->position[0]);
+ this->window->GetRenderWindow()->Render();
+ this->window->GetYZRenderer()->ResetCameraClippingRange();
+ this->window->GetRenderWindowYZ()->Render();
+
+ }
+
+}
+
+
+void vtkMyInteractorStyleTrackballCameraOpenHeart::MoveBackward()
+{
+
+ /// Get picker position
+ double pos[3];
+ this->GetPickerPosition(pos);
+
+ /// Go back to the initial coordinate system before reslicing
+ double posXYZ[3];
+ for (int i=0; i<3; i++)
+ posXYZ[i] = pos[i];
+ this->window->ComputePointBeforeRotation(posXYZ);
+
+ /// Compute point of interest for checking which plan is selected
+ double RefX[3];
+ for (int i=0; i<3; i++)
+ RefX[i] = this->window->GetRendererProperties()->xIPW->GetCenter()[i];
+ this->window->ComputePointBeforeRotation(RefX);
+ double RefY[3];
+ for (int i=0; i<3; i++)
+ RefY[i] = this->window->GetRendererProperties()->yIPW->GetCenter()[i];
+ this->window->ComputePointBeforeRotation(RefY);
+ double RefZ[3];
+ for (int i=0; i<3; i++)
+ RefZ[i] = this->window->GetRendererProperties()->zIPW->GetCenter()[i];
+ this->window->ComputePointBeforeRotation(RefZ);
+
+ /// Update Slice image
+ if ( this->IsInside(posXYZ) )
+ {
+
+ if ( fabs(posXYZ[0]-RefX[0]) < this->PadSliceDetection[0] )
+ {
+
+ /// Compute corresponding step
+ if ( (posXYZ[1] >= this->Limits[2] ) &&
+ (posXYZ[1] <= this->Limits[3] ) &&
+ (posXYZ[2] >= this->Limits[4] ) &&
+ (posXYZ[2] <= this->Limits[5] ) )
+ this->Step = 1;
+ else
+ this->Step = 5;
+
+ /// Compute new slice position
+ posXYZ[0] -= this->Step * this->SpacingImg[0];
+ if ( posXYZ[0] >= 0 )
+ this->window->GetRendererProperties()->position[0] -= this->Step * this->SpacingImg[0];
+
+ /// Update Slice text
+ if ( this->window->GetFlagDisplayText() )
+ {
+ int slice = (int)( (this->window->GetRendererProperties()->position[0] -
+ this->OriginImg[0]) /
+ this->SpacingImg[0] + 0.5f );
+ QString strSlice;
+ strSlice.sprintf("Slice: %d",slice);
+ this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
+ }
+
+ /// Update renderers
+ this->window->GetRendererProperties()->xIPW->SetSlicePosition(this->window->GetRendererProperties()->position[0]);
+ this->window->GetRendererProperties()->yzIPW->SetSlicePosition(this->window->GetRendererProperties()->position[0]);
+ this->window->GetRenderWindow()->Render();
+ this->window->GetYZRenderer()->ResetCameraClippingRange();
+ this->window->GetRenderWindowYZ()->Render();
+ }
+
+ if ( fabs(posXYZ[1]-RefY[1]) < this->PadSliceDetection[1] )
+ {
+
+ /// Compute corresponding step
+ if ( (posXYZ[0] >= this->Limits[0] ) &&
+ (posXYZ[0] <= this->Limits[1] ) &&
+ (posXYZ[2] >= this->Limits[4] ) &&
+ (posXYZ[2] <= this->Limits[5] ) )
+ this->Step = 1;
+ else
+ this->Step = 5;
+
+ /// Compute new slice position
+ posXYZ[1] -= this->Step * this->SpacingImg[1];
+ if ( posXYZ[1] >= 0 )
+ this->window->GetRendererProperties()->position[1] -= this->Step * this->SpacingImg[1];
+
+ /// Update Slice text
+ if ( this->window->GetFlagDisplayText() )
+ {
+ int slice = (int)( (this->window->GetRendererProperties()->position[1] -
+ this->OriginImg[1]) /
+ this->SpacingImg[1] + 0.5f );
+ QString strSlice;
+ strSlice.sprintf("Slice: %d",slice);
+ this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
+ }
+
+ /// Update renderers
+ this->window->GetRendererProperties()->yIPW->SetSlicePosition(this->window->GetRendererProperties()->position[1]);
+ this->window->GetRendererProperties()->xzIPW->SetSlicePosition(this->window->GetRendererProperties()->position[1]);
+ this->window->GetRenderWindow()->Render();
+ this->window->GetXZRenderer()->ResetCameraClippingRange();
+ this->window->GetRenderWindowXZ()->Render();
+ }
+
+ if ( fabs(posXYZ[2]-RefZ[2]) < this->PadSliceDetection[2] )
+ {
+
+ /// Compute corresponding step
+ if ( (posXYZ[0] >= this->Limits[0] ) &&
+ (posXYZ[0] <= this->Limits[1] ) &&
+ (posXYZ[1] >= this->Limits[2] ) &&
+ (posXYZ[1] <= this->Limits[3] ) )
+ this->Step = 1;
+ else
+ this->Step = 5;
+
+ /// Compute new slice position
+ posXYZ[2] -= this->Step * this->SpacingImg[2];
+ if ( posXYZ[2] >= 0 )
+ this->window->GetRendererProperties()->position[2] -= this->Step * this->SpacingImg[2];
+
+ /// Update Slice text
+ if ( this->window->GetFlagDisplayText() )
+ {
+ int slice = (int)( (this->window->GetRendererProperties()->position[2] -
+ this->OriginImg[2]) /
+ this->SpacingImg[2] + 0.5f );
+ QString strSlice;
+ strSlice.sprintf("Slice: %d",slice);
+ this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
+ }
+
+ /// Update renderers
+ this->window->GetRendererProperties()->zIPW->SetSlicePosition(this->window->GetRendererProperties()->position[2]);
+ this->window->GetRendererProperties()->xyIPW->SetSlicePosition(this->window->GetRendererProperties()->position[2]);
+ this->window->GetRenderWindow()->Render();
+ this->window->GetXYRenderer()->ResetCameraClippingRange();
+ this->window->GetRenderWindowXY()->Render();
+ }
+
+ /// Update text display
+ this->window->UpdateCoords(this->window->GetRendererProperties()->position);
+
+ }
+
+}
+
+
+void vtkMyInteractorStyleTrackballCameraOpenHeart::OnEnter()
+{
+
+ if ( !this->FlagFirstTime )
+ {
+
+ /// Set flag to 1 to never enter again in this part of the code
+ this->FlagFirstTime = 1;
+ double extend[6];
+ this->window->GetCurrentImageData()->GetWholeBoundingBox(extend);
+
+ /// Save the boundary of the volume in world coordinates
+ this->Bounds[0] = this->window->GetCurrentImageData()->GetExtent()[0] * this->window->GetCurrentImageData()->GetSpacing()[0] +
+ this->window->GetCurrentImageData()->GetOrigin()[0];
+ this->Bounds[1] = this->window->GetCurrentImageData()->GetExtent()[1] * this->window->GetCurrentImageData()->GetSpacing()[0] +
+ this->window->GetCurrentImageData()->GetOrigin()[0];
+ this->Bounds[2] = this->window->GetCurrentImageData()->GetExtent()[2] * this->window->GetCurrentImageData()->GetSpacing()[1] +
+ this->window->GetCurrentImageData()->GetOrigin()[1];
+ this->Bounds[3] = this->window->GetCurrentImageData()->GetExtent()[3] * this->window->GetCurrentImageData()->GetSpacing()[1] +
+ this->window->GetCurrentImageData()->GetOrigin()[1];
+ this->Bounds[4] = this->window->GetCurrentImageData()->GetExtent()[4] * this->window->GetCurrentImageData()->GetSpacing()[2] +
+ this->window->GetCurrentImageData()->GetOrigin()[2];
+ this->Bounds[5] = this->window->GetCurrentImageData()->GetExtent()[5] * this->window->GetCurrentImageData()->GetSpacing()[2] +
+ this->window->GetCurrentImageData()->GetOrigin()[2];
+
+ /// Save the limit of the box to increase the scolling effect
+ this->Limits[0] = (this->Bounds[1] - this->Bounds[0]) * this->PadBound;
+ this->Limits[1] = this->Bounds[1] - (this->Bounds[1] - this->Bounds[0]) * this->PadBound;
+ this->Limits[2] = (this->Bounds[3] - this->Bounds[2]) * this->PadBound;
+ this->Limits[3] = this->Bounds[3] - (this->Bounds[3] - this->Bounds[2]) * this->PadBound;
+ this->Limits[4] = (this->Bounds[5] - this->Bounds[4]) * this->PadBound;
+ this->Limits[5] = this->Bounds[5] - (this->Bounds[5] - this->Bounds[4]) * this->PadBound;
+
+ /// Save usefull information
+ for ( int i=0; i<3; i++)
+ {
+ this->SpacingImg[i] = this->window->GetCurrentImageData()->GetSpacing()[i];
+ this->OriginImg[i] = this->window->GetCurrentImageData()->GetOrigin()[i];
+ this->LimitImg[i] = this->OriginImg[i] + (this->window->GetDimensions()[i]-1) *
+ this->SpacingImg[i];
+ this->PadSliceDetection[i] = 0.01 * this->SpacingImg[i];
+ }
+
+ }
+
+ vtkInteractorStyleTrackballCamera::OnEnter();
+
+}
+
+
+void vtkMyInteractorStyleTrackballCameraOpenHeart::OnLeave()
+{
+ this->Step = 1;
+ vtkInteractorStyleTrackballCamera::OnLeave();
+}
+
+
+void vtkMyInteractorStyleTrackballCameraOpenHeart::OnLeftButtonDown()
+{
+ this->FlagLeftClick = true;
+ if ( this->window->GetSelectedButton() == 0 )
+ {
+ this->window->GetMainRenderer()->AddActor(this->window->GetRendererProperties()->BoundingBoxActor);
+ this->window->GetRenderWindow()->Render();
+ }
+ vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
+}
+
+
+void vtkMyInteractorStyleTrackballCameraOpenHeart::OnLeftButtonUp()
+{
+ this->FlagLeftClick = false;
+ if ( this->window->GetSelectedButton() == 0 ) {
+ this->window->GetMainRenderer()->RemoveActor(this->window->GetRendererProperties()->BoundingBoxActor);
+ this->window->GetRenderWindow()->Render();
+ }
+ vtkInteractorStyleTrackballCamera::OnLeftButtonUp();
+}
+
+
+void vtkMyInteractorStyleTrackballCameraOpenHeart::GetPickerPosition(double *pos)
+{
+ int X = this->Interactor->GetEventPosition()[0];
+ int Y = this->Interactor->GetEventPosition()[1];
+ this->window->GetPicker()->Pick(X,Y,0.0,this->window->GetMainRenderer());
+ this->window->GetPicker()->GetPickPosition(pos);
+}
+
+
+bool vtkMyInteractorStyleTrackballCameraOpenHeart::IsInside(double *pos)
+{
+ if ( (pos[0]>=this->Bounds[0]) && (pos[0]<=this->Bounds[1]) &&
+ (pos[1]>=this->Bounds[2]) && (pos[1]<=this->Bounds[3]) &&
+ (pos[2]>=this->Bounds[4]) && (pos[2]<=this->Bounds[5]) )
+ return true;
+ else
+ return false;
+}
+
+