#include "vtkInteractorStyleEsqui.h" #include "vtkObjectFactory.h" #include "vtkRenderer.h" #include "vtkRendererCollection.h" #include "vtkCamera.h" #include "vtkToolCollection.h" #include "vtkTool.h" #include "vtkRenderWindowInteractor.h" #include "vtkRenderWindow.h" #include "vtkAssembly.h" vtkCxxRevisionMacro(vtkInteractorStyleEsqui, "$Revision: 0.1 $"); vtkStandardNewMacro(vtkInteractorStyleEsqui); vtkInteractorStyleEsqui::vtkInteractorStyleEsqui() { this->ActiveCamera = 1; this->ActiveTool = 0; this->RightButton = 0; this->LeftButton = 0; this->Tools = NULL; } void vtkInteractorStyleEsqui::SetToolCollection(vtkToolCollection *Tools) { this->Tools = Tools; } vtkToolCollection* vtkInteractorStyleEsqui::GetToolCollection() { return this->Tools; } void vtkInteractorStyleEsqui::OnLeftButtonDown() { this->LeftButton = 1; } void vtkInteractorStyleEsqui::OnLeftButtonUp() { this->LeftButton = 0; } void vtkInteractorStyleEsqui::OnRightButtonDown() { this->RightButton = 1; } void vtkInteractorStyleEsqui::OnRightButtonUp() { this->RightButton = 0; } void vtkInteractorStyleEsqui::OnKeyPress() { char letra = *this->Interactor->GetKeySym(); switch (letra) { case ('c'): if(!this->ActiveCamera) { this->ActiveCamera = 1; } else { this->ActiveCamera = 0; } break; case ('d'): this->ActiveTool = 0; break; case ('i'): this->ActiveTool = 1; break; case ('a'): this->Tools->GetToolOnPosition(this->ActiveTool)->Abrir(); break; case ('s'): this->Tools->GetToolOnPosition(this->ActiveTool)->Cerrar(); break; case ('z'): this->Tools->GetToolOnPosition(this->ActiveTool)->Rotar(1); break; case ('x'): this->Tools->GetToolOnPosition(this->ActiveTool)->Rotar(-1); break; case ('C'): this->ActiveCamera = 1; break; case ('D'): this->ActiveTool = 0; break; case ('I'): this->ActiveTool = 1; break; case ('A'): this->Tools->GetToolOnPosition(this->ActiveTool)->Abrir(); break; case ('S'): this->Tools->GetToolOnPosition(this->ActiveTool)->Cerrar(); break; case ('Z'): this->Tools->GetToolOnPosition(this->ActiveTool)->Rotar(1); break; case ('X'): this->Tools->GetToolOnPosition(this->ActiveTool)->Rotar(-1); break; } } void vtkInteractorStyleEsqui::OnMouseMove() { int *LastPosition = this->Interactor->GetLastEventPosition(); int *CurrentPosition = this->Interactor->GetEventPosition(); if (this->RightButton || this->LeftButton) { if (this->ActiveCamera) { this->MueveCamara(LastPosition, CurrentPosition); } else { vtkTool *Tool = this->Tools->GetToolOnPosition(this->ActiveTool); this->MueveHerramienta(LastPosition,CurrentPosition,Tool); } this->Interactor->GetRenderWindow()->Render(); } } void vtkInteractorStyleEsqui::MueveCamara(int* LastPosition, int *CurrentPosition) { if (this->RightButton) { if (LastPosition[1] - CurrentPosition[1] < 0) { static_cast (this->Interactor->GetRenderWindow()-> GetRenderers()->GetItemAsObject(0)) ->GetActiveCamera()->Dolly(0.995); } else { static_cast (this->Interactor->GetRenderWindow()-> GetRenderers()->GetItemAsObject(0)) ->GetActiveCamera()->Dolly(1.005); } } else if (this->LeftButton) { static_cast (this->Interactor->GetRenderWindow()-> GetRenderers()->GetItemAsObject(0)) ->GetActiveCamera()->Yaw((LastPosition[0] - CurrentPosition[0])*0.01); static_cast (this->Interactor->GetRenderWindow()-> GetRenderers()->GetItemAsObject(0)) ->GetActiveCamera()->Pitch((LastPosition[1] - CurrentPosition[1])*0.01); } this->Interactor->GetRenderWindow()->Render(); } void vtkInteractorStyleEsqui::MueveHerramienta(int *LastPosition, int *CurrentPosition, vtkTool *Tool) { if (this->RightButton) { vtkTransform *Transform = vtkTransform::New(); if (LastPosition[1]-CurrentPosition[1]>0) { Transform->Translate(0,0,0.5); } else { Transform->Translate(0,0,0.5); } Tool->GetHerramientaCompleta()->SetUserTransform(Transform); Transform->Delete(); } else if (this->LeftButton) { vtkMatrix4x4 *Matrix = vtkMatrix4x4::New(); Matrix->Identity(); Tool->GetHerramientaCompleta()->SetUserMatrix(Matrix); Matrix->Delete(); } } void vtkInteractorStyleEsqui::PrintSelf(ostream& os, vtkIndent indent) { os << indent << "Left Button: " << this->LeftButton << endl; os << indent << "Right Button: " << this->RightButton << endl; os << indent << "Active Camera: " << this->ActiveCamera << endl; os << indent << "Active Tool: " << this->ActiveTool << endl; this->Superclass::PrintSelf(os,indent); }