--- /dev/null
+/*=========================================================================
+
+ 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 <vtkPoints.h>
+#include <vtkActor2D.h>
+#include <vtkObjectFactory.h>
+#include <vtkRenderer.h>
+#include <vtkRenderWindowInteractor.h>
+#include <vtkCellArray.h>
+#include <vtkPolyData.h>
+#include <vtkPolyDataMapper2D.h>
+#include <vtkProperty2D.h>
+#include <vtkCamera.h>
+
+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);
+}