/** * 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 #include #include #include #include #include #include #include "vtkMyInteractorStyleTrackballCameraOpenHeartXY.h" using namespace std; void vtkMyInteractorStyleTrackballCameraOpenHeartXY::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[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 vtkMyInteractorStyleTrackballCameraOpenHeartXY::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[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 vtkMyInteractorStyleTrackballCameraOpenHeartXY::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; } vtkInteractorStyleTrackballCamera::OnEnter(); } void vtkMyInteractorStyleTrackballCameraOpenHeartXY::OnLeave() { this->Step = 1; vtkInteractorStyleTrackballCamera::OnLeave(); } void vtkMyInteractorStyleTrackballCameraOpenHeartXY::GetPickerPosition(double *pos) { int X = this->Interactor->GetEventPosition()[0]; int Y = this->Interactor->GetEventPosition()[1]; this->window->GetPickerXY()->Pick(X,Y,0.0,this->window->GetXYRenderer()); this->window->GetPickerXY()->GetPickPosition(pos); } bool vtkMyInteractorStyleTrackballCameraOpenHeartXY::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; }