vtkInteractorStyleCutter.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkInteractorStyleCutter.cxx,v $
00005   Language:  C++
00006   Date:      $Date: 2010/02/24 14:00:46 $
00007   Version:   $Revision: 1.1 $
00008 
00009   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
00010   All rights reserved.
00011   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00012 
00013      This software is distributed WITHOUT ANY WARRANTY; without even 
00014      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00015      PURPOSE.  See the above copyright notice for more information.
00016 
00017 =========================================================================*/
00018 #include "vtkInteractorStyleCutter.h"
00019 
00020 #include <vtkPoints.h>
00021 #include <vtkActor2D.h>
00022 #include <vtkObjectFactory.h>
00023 #include <vtkRenderer.h>
00024 #include <vtkRenderWindowInteractor.h>
00025 #include <vtkCellArray.h>
00026 #include <vtkPolyData.h>
00027 #include <vtkPolyDataMapper2D.h>
00028 #include <vtkProperty2D.h>
00029 #include <vtkCamera.h>
00030 
00031 vtkCxxRevisionMacro(vtkInteractorStyleCutter, "$Revision: 1.1 $");
00032 vtkStandardNewMacro(vtkInteractorStyleCutter);
00033 
00034 //----------------------------------------------------------------------------
00035 vtkInteractorStyleCutter::vtkInteractorStyleCutter()
00036 {
00037   this->CurrentPosition[0] = this->CurrentPosition[1] = 0;
00038   this->Direction[0] = this->Direction[1] = this->Direction[2] = 0.;
00039   this->Moving = 0;
00040 
00041   this->Points = vtkPoints::New();
00042   this->Lines = vtkCellArray::New();
00043   this->LoopPoints = vtkPoints::New();
00044 
00045   vtkPolyData *pd = vtkPolyData::New();
00046   pd->SetPoints( Points );
00047   pd->SetLines( Lines );
00048    
00049   vtkPolyDataMapper2D *bboxMapper = vtkPolyDataMapper2D::New();
00050   bboxMapper->SetInput( pd );
00051    
00052   this->BboxActor = vtkActor2D::New();
00053   this->BboxActor->SetMapper( bboxMapper );
00054   this->BboxActor->GetProperty()->SetColor(1, 0, 0);
00055   this->BboxActor->VisibilityOff();
00056 
00057   finished = false;
00058 
00059   //thanks
00060   pd->Delete();
00061   bboxMapper->Delete();
00062 }
00063 
00064 //----------------------------------------------------------------------------
00065 vtkInteractorStyleCutter::~vtkInteractorStyleCutter()
00066 {
00067   this->Points->Delete();
00068   this->BboxActor->Delete();
00069   this->Lines->Delete();
00070   this->LoopPoints->Delete();
00071 }
00072 
00073 //----------------------------------------------------------------------------
00074 void vtkInteractorStyleCutter::OnMouseMove()
00075 {
00076   if (!this->Interactor || !this->Moving)
00077     {
00078     return;
00079     }
00080   
00081   this->CurrentPosition[0] = this->Interactor->GetEventPosition()[0];
00082   this->CurrentPosition[1] = this->Interactor->GetEventPosition()[1];  
00083   
00084   //mouse move event
00085   this->Points->SetPoint(this->PointID, this->CurrentPosition[0], 
00086     this->CurrentPosition[1], 0);
00087 
00088   this->Interactor->Render();
00089 }
00090 
00091 //----------------------------------------------------------------------------
00092 void vtkInteractorStyleCutter::OnLeftButtonDown()
00093 {
00094   if (!this->Interactor)
00095     {
00096     return;
00097     }
00098 
00099         finished = false;
00100   
00101   this->CurrentPosition[0] = this->Interactor->GetEventPosition()[0];
00102   this->CurrentPosition[1] = this->Interactor->GetEventPosition()[1];  
00103 
00104   if(!this->Moving)
00105     {
00106     this->Initialize();
00107 
00108     //Call this before accessing CurrentRenderer
00109     this->FindPokedRenderer(this->CurrentPosition[0], this->CurrentPosition[1]);
00110         this->CurrentRenderer->AddViewProp(BboxActor);
00111     }
00112 
00113   this->Moving = 1;
00114 
00115   this->Points->SetPoint(this->PointID, this->CurrentPosition[0],
00116     this->CurrentPosition[1], 0);
00117   this->PointID = this->Points->InsertNextPoint( this->CurrentPosition[0], 
00118     this->CurrentPosition[1], 0);
00119 
00120   this->Lines->InsertCellPoint( this->PointID );
00121   this->Lines->UpdateCellCount( this->PointID + 1 );
00122   this->BboxActor->VisibilityOn();
00123 
00124   this->Interactor->Render();
00125 }
00126 
00127 //----------------------------------------------------------------------------
00128 bool vtkInteractorStyleCutter::Finished()
00129 {
00130     return finished;
00131 }
00132 
00133 //----------------------------------------------------------------------------
00134 void vtkInteractorStyleCutter::OnRightButtonDown()
00135 {
00136   if (!this->Interactor || !this->Moving)
00137     {
00138     return;
00139     }
00140   
00141   double xyz[3];
00142   this->Points->GetPoint( 0, xyz );
00143   this->Points->SetPoint(this->PointID, xyz);
00144 
00145   //Save current state
00146   this->EndLoop();
00147 
00148   this->Interactor->Render();
00149   this->Moving = 0;
00150   finished = true;
00151 }
00152 
00153 //----------------------------------------------------------------------------
00154 void vtkInteractorStyleCutter::Initialize()
00155 {
00156   this->Points->Reset();
00157   this->Lines->Reset();
00158 
00159   this->PointID = this->Points->InsertNextPoint( 0, 0, 0);
00160   this->Lines->InsertNextCell( 1 );
00161   this->Lines->InsertCellPoint( 0 );
00162 }
00163 //----------------------------------------------------------------------------
00164 void vtkInteractorStyleCutter::EndLoop()
00165 {
00166   double pi[3],fpi[4];
00167   int numPts = this->Points->GetNumberOfPoints()-1;
00168   this->LoopPoints->SetNumberOfPoints( numPts );
00169   vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
00170   //int state = camera->GetParallelProjection ();
00171   camera->ParallelProjectionOn();
00172 
00173   for (int i=0; i < numPts; i++)
00174   {
00175     this->Points->GetPoint(i, pi);
00176     this->CurrentRenderer->SetDisplayPoint(pi[0], pi[1], 0);
00177     this->CurrentRenderer->DisplayToWorld();
00178 
00179     this->CurrentRenderer->GetWorldPoint( fpi );
00180     if ( fpi[3] )
00181     {
00182       fpi[0] /= fpi[3];
00183       fpi[1] /= fpi[3];
00184       fpi[2] /= fpi[3];
00185     }
00186     this->LoopPoints->SetPoint( i, fpi[0], fpi[1], fpi[2] );
00187   }
00188 
00189   //Set direction of extrusion, should save this state before camera moves
00190   camera->GetDirectionOfProjection( this->Direction );
00191   //camera->SetParallelProjection( state );
00192 }
00193 //----------------------------------------------------------------------------
00194 //Just a quick hack:
00195 void vtkInteractorStyleCutter::VisibilityOff()
00196 {
00197   this->BboxActor->VisibilityOff();
00198 }
00199 //----------------------------------------------------------------------------
00200 void vtkInteractorStyleCutter::PrintSelf(ostream& os, vtkIndent indent)
00201 {
00202   this->Superclass::PrintSelf(os, indent);
00203 }
00204 
00205 

Generated on 20 Oct 2010 for creaMaracasVisu_lib by  doxygen 1.6.1