X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FmaracasVisuLib%2Fsrc%2Finterface%2FwxWindows%2Fwidgets%2Finclude%2FvtkInteractorStyleCutter.cxx;fp=lib%2FmaracasVisuLib%2Fsrc%2Finterface%2FwxWindows%2Fwidgets%2Finclude%2FvtkInteractorStyleCutter.cxx;h=01d92b24eeb44abcd3f9eb454b7e2ebbe046d7a9;hb=a4ee3758aa0477f677fb981e2c4d6e29995e8db8;hp=0000000000000000000000000000000000000000;hpb=cc20770ee090848c31a8f18c277d89f2b904e087;p=creaMaracasVisu.git diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/include/vtkInteractorStyleCutter.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/include/vtkInteractorStyleCutter.cxx new file mode 100644 index 0000000..01d92b2 --- /dev/null +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/include/vtkInteractorStyleCutter.cxx @@ -0,0 +1,192 @@ +/*========================================================================= + + Program: Visualization Toolkit + Module: $RCSfile: vtkInteractorStyleCutter.cxx,v $ + Language: C++ + Date: $Date: 2009/05/14 13:54:57 $ + Version: $Revision: 1.1 $ + + Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen + All rights reserved. + See Copyright.txt or http://www.kitware.com/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notice for more information. + +=========================================================================*/ +#include "vtkInteractorStyleCutter.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +vtkCxxRevisionMacro(vtkInteractorStyleCutter, "$Revision: 1.1 $"); +vtkStandardNewMacro(vtkInteractorStyleCutter); + +//---------------------------------------------------------------------------- +vtkInteractorStyleCutter::vtkInteractorStyleCutter() +{ + this->CurrentPosition[0] = this->CurrentPosition[1] = 0; + this->Direction[0] = this->Direction[1] = this->Direction[2] = 0.; + this->Moving = 0; + + this->Points = vtkPoints::New(); + this->Lines = vtkCellArray::New(); + this->LoopPoints = vtkPoints::New(); + + vtkPolyData *pd = vtkPolyData::New(); + pd->SetPoints( Points ); + pd->SetLines( Lines ); + + vtkPolyDataMapper2D *bboxMapper = vtkPolyDataMapper2D::New(); + bboxMapper->SetInput( pd ); + + this->BboxActor = vtkActor2D::New(); + this->BboxActor->SetMapper( bboxMapper ); + this->BboxActor->GetProperty()->SetColor(1, 0, 0); + this->BboxActor->VisibilityOff(); + + //thanks + pd->Delete(); + bboxMapper->Delete(); +} + +//---------------------------------------------------------------------------- +vtkInteractorStyleCutter::~vtkInteractorStyleCutter() +{ + this->Points->Delete(); + this->BboxActor->Delete(); + this->Lines->Delete(); + this->LoopPoints->Delete(); +} + +//---------------------------------------------------------------------------- +void vtkInteractorStyleCutter::OnMouseMove() +{ + if (!this->Interactor || !this->Moving) + { + return; + } + + this->CurrentPosition[0] = this->Interactor->GetEventPosition()[0]; + this->CurrentPosition[1] = this->Interactor->GetEventPosition()[1]; + + //mouse move event + this->Points->SetPoint(this->PointID, this->CurrentPosition[0], + this->CurrentPosition[1], 0); + + this->Interactor->Render(); +} + +//---------------------------------------------------------------------------- +void vtkInteractorStyleCutter::OnLeftButtonDown() +{ + if (!this->Interactor) + { + return; + } + + this->CurrentPosition[0] = this->Interactor->GetEventPosition()[0]; + this->CurrentPosition[1] = this->Interactor->GetEventPosition()[1]; + + if(!this->Moving) + { + this->Initialize(); + + //Call this before accessing CurrentRenderer + this->FindPokedRenderer(this->CurrentPosition[0], this->CurrentPosition[1]); + this->CurrentRenderer->AddProp( BboxActor ); + } + + this->Moving = 1; + + this->Points->SetPoint(this->PointID, this->CurrentPosition[0], + this->CurrentPosition[1], 0); + this->PointID = this->Points->InsertNextPoint( this->CurrentPosition[0], + this->CurrentPosition[1], 0); + + this->Lines->InsertCellPoint( this->PointID ); + this->Lines->UpdateCellCount( this->PointID + 1 ); + this->BboxActor->VisibilityOn(); + + this->Interactor->Render(); +} + +//---------------------------------------------------------------------------- +void vtkInteractorStyleCutter::OnRightButtonDown() +{ + if (!this->Interactor || !this->Moving) + { + return; + } + + double xyz[3]; + this->Points->GetPoint( 0, xyz ); + this->Points->SetPoint(this->PointID, xyz); + + //Save current state + this->EndLoop(); + + this->Interactor->Render(); + this->Moving = 0; +} + +//---------------------------------------------------------------------------- +void vtkInteractorStyleCutter::Initialize() +{ + this->Points->Reset(); + this->Lines->Reset(); + + this->PointID = this->Points->InsertNextPoint( 0, 0, 0); + this->Lines->InsertNextCell( 1 ); + this->Lines->InsertCellPoint( 0 ); +} +//---------------------------------------------------------------------------- +void vtkInteractorStyleCutter::EndLoop() +{ + double pi[3],fpi[4]; + int numPts = this->Points->GetNumberOfPoints()-1; + this->LoopPoints->SetNumberOfPoints( numPts ); + vtkCamera *camera = this->CurrentRenderer->GetActiveCamera(); + int state = camera->GetParallelProjection (); + camera->ParallelProjectionOn(); + + for (int i=0; i < numPts; i++) + { + this->Points->GetPoint(i, pi); + this->CurrentRenderer->SetDisplayPoint(pi[0], pi[1], 0); + this->CurrentRenderer->DisplayToWorld(); + + this->CurrentRenderer->GetWorldPoint( fpi ); + if ( fpi[3] ) + { + fpi[0] /= fpi[3]; + fpi[1] /= fpi[3]; + fpi[2] /= fpi[3]; + } + this->LoopPoints->SetPoint( i, fpi[0], fpi[1], fpi[2] ); + } + + //Set direction of extrusion, should save this state before camera moves + camera->GetDirectionOfProjection( this->Direction ); + //camera->SetParallelProjection( state ); +} +//---------------------------------------------------------------------------- +//Just a quick hack: +void vtkInteractorStyleCutter::VisibilityOff() +{ + this->BboxActor->VisibilityOff(); +} +//---------------------------------------------------------------------------- +void vtkInteractorStyleCutter::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os, indent); +}