1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkPolygonalHandleRepresentation3D.cxx
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14 =========================================================================*/
15 #include "vtkPolygonalHandleRepresentation3D.h"
16 #include "vtkActor.h"
17 #include "vtkCamera.h"
18 #include "vtkCellPicker.h"
19 #include "vtkCoordinate.h"
20 #include "vtkMatrix4x4.h"
21 #include "vtkObjectFactory.h"
22 #include "vtkPointPlacer.h"
23 #include "vtkPolyDataMapper.h"
24 #include "vtkProperty.h"
25 #include "vtkRenderWindow.h"
26 #include "vtkRenderer.h"
27
28 vtkStandardNewMacro(vtkPolygonalHandleRepresentation3D);
29
30 //------------------------------------------------------------------------------
vtkPolygonalHandleRepresentation3D()31 vtkPolygonalHandleRepresentation3D::vtkPolygonalHandleRepresentation3D()
32 {
33 this->Offset[0] = this->Offset[1] = this->Offset[2] = 0.0;
34
35 this->Actor = vtkActor::New();
36 this->Actor->SetMapper(this->Mapper);
37 this->Actor->SetProperty(this->Property);
38 this->HandlePicker->AddPickList(this->Actor);
39 }
40
41 //------------------------------------------------------------------------------
SetWorldPosition(double p[3])42 void vtkPolygonalHandleRepresentation3D::SetWorldPosition(double p[3])
43 {
44 if (!this->Renderer || !this->PointPlacer || this->PointPlacer->ValidateWorldPosition(p))
45 {
46 this->HandleTransformMatrix->SetElement(0, 3, p[0] - this->Offset[0]);
47 this->HandleTransformMatrix->SetElement(1, 3, p[1] - this->Offset[1]);
48 this->HandleTransformMatrix->SetElement(2, 3, p[2] - this->Offset[2]);
49
50 this->WorldPosition->SetValue(this->HandleTransformMatrix->GetElement(0, 3),
51 this->HandleTransformMatrix->GetElement(1, 3), this->HandleTransformMatrix->GetElement(2, 3));
52
53 this->WorldPositionTime.Modified();
54 }
55 }
56
57 //------------------------------------------------------------------------------
PrintSelf(ostream & os,vtkIndent indent)58 void vtkPolygonalHandleRepresentation3D::PrintSelf(ostream& os, vtkIndent indent)
59 {
60 this->Superclass::PrintSelf(os, indent);
61
62 os << indent << "Offset: (" << this->Offset[0] << "," << this->Offset[1] << ")\n";
63 }
64