--- /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 "vtkMyInteractorStyleTrackballCameraOpenHeartYZ.h"
+
+
+using namespace std;
+
+
+void vtkMyInteractorStyleTrackballCameraOpenHeartYZ::OnMouseWheelForward()
+{
+
+ /// 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[0] ) &&
+ (posXYZ[1] <= this->Limits[1] ) &&
+ (posXYZ[2] >= this->Limits[2] ) &&
+ (posXYZ[2] <= this->Limits[3] ) )
+ 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 vtkMyInteractorStyleTrackballCameraOpenHeartYZ::OnMouseWheelBackward()
+{
+
+ /// 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[0] ) &&
+ (posXYZ[1] <= this->Limits[1] ) &&
+ (posXYZ[2] >= this->Limits[2] ) &&
+ (posXYZ[2] <= this->Limits[3] ) )
+ 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 vtkMyInteractorStyleTrackballCameraOpenHeartYZ::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[3] - this->Bounds[2]) * this->PadBound;
+ this->Limits[1] = this->Bounds[3] - (this->Bounds[3] - this->Bounds[2]) * this->PadBound;
+ this->Limits[2] = (this->Bounds[5] - this->Bounds[4]) * this->PadBound;
+ this->Limits[3] = this->Bounds[5] - (this->Bounds[5] - this->Bounds[4]) * this->PadBound;
+
+ }
+
+ vtkInteractorStyleTrackballCamera::OnEnter();
+
+}
+
+
+void vtkMyInteractorStyleTrackballCameraOpenHeartYZ::OnLeave()
+{
+ this->Step = 1;
+ vtkInteractorStyleTrackballCamera::OnLeave();
+}
+
+
+void vtkMyInteractorStyleTrackballCameraOpenHeartYZ::GetPickerPosition(double *pos)
+{
+ int X = this->Interactor->GetEventPosition()[0];
+ int Y = this->Interactor->GetEventPosition()[1];
+ this->window->GetPickerYZ()->Pick(X,Y,0.0,this->window->GetYZRenderer());
+ this->window->GetPickerYZ()->GetPickPosition(pos);
+}
+
+
+bool vtkMyInteractorStyleTrackballCameraOpenHeartYZ::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;
+}