vtkInteractorStyleCutter.cxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
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
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
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
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
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
00190 camera->GetDirectionOfProjection( this->Direction );
00191
00192 }
00193
00194
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