]> Creatis software - openheart.git/blobdiff - Applications/vtkMyInteractorStyleTrackballCameraOpenHeartXZ.cxx
commit all the files for the first time
[openheart.git] / Applications / vtkMyInteractorStyleTrackballCameraOpenHeartXZ.cxx
diff --git a/Applications/vtkMyInteractorStyleTrackballCameraOpenHeartXZ.cxx b/Applications/vtkMyInteractorStyleTrackballCameraOpenHeartXZ.cxx
new file mode 100644 (file)
index 0000000..03148ac
--- /dev/null
@@ -0,0 +1,185 @@
+/**
+* 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 "vtkMyInteractorStyleTrackballCameraOpenHeartXZ.h"
+
+
+using namespace std;
+
+
+void vtkMyInteractorStyleTrackballCameraOpenHeartXZ::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[0] >= this->Limits[0] ) &&
+             (posXYZ[0] <= 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[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 vtkMyInteractorStyleTrackballCameraOpenHeartXZ::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[0] >= this->Limits[0] ) &&
+             (posXYZ[0] <= 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[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 vtkMyInteractorStyleTrackballCameraOpenHeartXZ::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[5] - this->Bounds[4]) * this->PadBound;
+        this->Limits[3] = this->Bounds[5] - (this->Bounds[5] - this->Bounds[4]) * this->PadBound;
+
+    }
+
+    vtkInteractorStyleTrackballCamera::OnEnter();
+
+}
+
+
+void vtkMyInteractorStyleTrackballCameraOpenHeartXZ::OnLeave()
+{
+    this->Step = 1;
+    vtkInteractorStyleTrackballCamera::OnLeave();
+}
+
+
+void vtkMyInteractorStyleTrackballCameraOpenHeartXZ::GetPickerPosition(double *pos)
+{
+    int X = this->Interactor->GetEventPosition()[0];
+    int Y = this->Interactor->GetEventPosition()[1];
+    this->window->GetPickerXZ()->Pick(X,Y,0.0,this->window->GetXZRenderer());
+    this->window->GetPickerXZ()->GetPickPosition(pos);
+}
+
+
+bool vtkMyInteractorStyleTrackballCameraOpenHeartXZ::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;
+}
+