forked from dgobbi/ToolCursor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvtkFiducialPointsTool.cxx
174 lines (143 loc) · 4.71 KB
/
vtkFiducialPointsTool.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*=========================================================================
Program: ToolCursor
Module: vtkFiducialPointsTool.cxx
Copyright (c) 2010 David Gobbi
All rights reserved.
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 "vtkFiducialPointsTool.h"
#include "vtkObjectFactory.h"
#include "vtkCommand.h"
#include "vtkGeometricCursorShapes.h"
#include "vtkToolCursor.h"
#include "vtkCamera.h"
#include "vtkRenderer.h"
#include "vtkTransform.h"
#include "vtkMath.h"
#include "vtkGlyph3D.h"
#include "vtkPolyData.h"
#include "vtkPointData.h"
#include "vtkActor.h"
#include "vtkDataSetMapper.h"
#include "vtkProperty.h"
#include "vtkActorCollection.h"
#include "vtkVolumePicker.h"
// A macro to assist VTK 5 backwards compatibility
#if VTK_MAJOR_VERSION >= 6
#define SET_INPUT_DATA SetInputData
#define SET_SOURCE_DATA SetSourceData
#else
#define SET_INPUT_DATA SetInput
#define SET_SOURCE_DATA SetSource
#endif
vtkStandardNewMacro(vtkFiducialPointsTool);
//----------------------------------------------------------------------------
vtkFiducialPointsTool::vtkFiducialPointsTool()
{
this->Transform = vtkTransform::New();
this->PointSet = vtkPolyData::New();
vtkGeometricCursorShapes *shapes = vtkGeometricCursorShapes::New();
this->Glyph3D = vtkGlyph3D::New();
this->Glyph3D->SetColorModeToColorByScalar();
this->Glyph3D->SetScaleFactor(0.7);
this->Glyph3D->SET_INPUT_DATA(this->PointSet);
this->Glyph3D->SET_SOURCE_DATA(vtkPolyData::SafeDownCast(
shapes->GetShapeData("Sphere")));
this->Mapper = vtkDataSetMapper::New();
this->Mapper->SetInputConnection(this->Glyph3D->GetOutputPort());
this->Actor = vtkActor::New();
this->Actor->PickableOff();
this->Actor->SetMapper(this->Mapper);
this->Actor->GetProperty()->SetColor(1,0,0);
shapes->Delete();
}
//----------------------------------------------------------------------------
vtkFiducialPointsTool::~vtkFiducialPointsTool()
{
this->Transform->Delete();
this->PointSet->Delete();
this->Glyph3D->Delete();
this->Actor->Delete();
this->Mapper->Delete();
}
//----------------------------------------------------------------------------
void vtkFiducialPointsTool::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
//----------------------------------------------------------------------------
void vtkFiducialPointsTool::SetPoints(vtkPoints *points)
{
if (1) //points != this->PointSet->GetPoints())
{
this->PointSet->SetPoints(points);
int n = points->GetNumberOfPoints();
vtkUnsignedCharArray *colors = vtkUnsignedCharArray::New();
colors->SetNumberOfComponents(3);
unsigned char red[3] = { 255, 0, 0 };
unsigned char yellow[3] = { 255, 255, 0 };
for (int i = 0; i < n; i++)
{
unsigned char *color = red;
if (i == n-1) { color = yellow; }
colors->InsertNextTupleValue(color);
}
//this->PointSet->GetPointData()->SetScalars(colors);
this->Glyph3D->Modified();
colors->Delete();
this->Modified();
}
}
//----------------------------------------------------------------------------
vtkPoints *vtkFiducialPointsTool::GetPoints()
{
return this->PointSet->GetPoints();
}
//----------------------------------------------------------------------------
void vtkFiducialPointsTool::SetMarker(vtkPolyData *data)
{
if (data != this->Glyph3D->GetSource())
{
this->Glyph3D->SET_SOURCE_DATA(data);
this->Modified();
}
}
//----------------------------------------------------------------------------
vtkPolyData *vtkFiducialPointsTool::GetMarker()
{
return this->Glyph3D->GetSource();
}
//----------------------------------------------------------------------------
void vtkFiducialPointsTool::StartAction()
{
this->Superclass::StartAction();
this->Transform->Identity();
}
//----------------------------------------------------------------------------
void vtkFiducialPointsTool::StopAction()
{
this->Superclass::StopAction();
this->InvokeEvent(vtkCommand::InteractionEvent);
}
//----------------------------------------------------------------------------
void vtkFiducialPointsTool::DoAction()
{
this->Superclass::DoAction();
// Get the initial point.
double p0[3];
this->GetStartPosition(p0);
// Get the depth.
double x, y, z;
this->WorldToDisplay(p0, x, y, z);
// Get the display position.
double p[3];
this->GetDisplayPosition(x, y);
this->DisplayToWorld(x, y, z, p);
// Get the vector.
double v[3];
v[0] = p[0] - p0[0];
v[1] = p[1] - p0[1];
v[2] = p[2] - p0[2];
}