X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Applications%2FvtkMyInteractorStyleTrackballCameraOpenHeartYZ.cxx;fp=Applications%2FvtkMyInteractorStyleTrackballCameraOpenHeartYZ.cxx;h=d2f7a6229846fa6f2a260352c4d3c0cb03638050;hb=e989157c905531306964b1f4d2d70991029aaca2;hp=0000000000000000000000000000000000000000;hpb=a29e955d81fcaf6b37db4a5cb168549f96f1fff3;p=openheart.git diff --git a/Applications/vtkMyInteractorStyleTrackballCameraOpenHeartYZ.cxx b/Applications/vtkMyInteractorStyleTrackballCameraOpenHeartYZ.cxx new file mode 100644 index 0000000..d2f7a62 --- /dev/null +++ b/Applications/vtkMyInteractorStyleTrackballCameraOpenHeartYZ.cxx @@ -0,0 +1,184 @@ +/** +* 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 +#include +#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; +}