forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkAngleRepresentation.cxx
226 lines (197 loc) · 6.45 KB
/
vtkAngleRepresentation.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*=========================================================================
Program: Visualization Toolkit
Module: vtkAngleRepresentation.cxx
Copyright (c) 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 "vtkAngleRepresentation.h"
#include "vtkHandleRepresentation.h"
#include "vtkActor2D.h"
#include "vtkPolyDataMapper2D.h"
#include "vtkProperty2D.h"
#include "vtkCoordinate.h"
#include "vtkRenderer.h"
#include "vtkObjectFactory.h"
#include "vtkInteractorObserver.h"
#include "vtkMath.h"
#include "vtkTextProperty.h"
#include "vtkWindow.h"
vtkCxxSetObjectMacro(vtkAngleRepresentation,HandleRepresentation,vtkHandleRepresentation);
//----------------------------------------------------------------------
vtkAngleRepresentation::vtkAngleRepresentation()
{
this->HandleRepresentation = NULL;
this->Point1Representation = NULL;
this->CenterRepresentation = NULL;
this->Point2Representation = NULL;
this->Tolerance = 5;
this->Placed = 0;
this->Ray1Visibility = 1;
this->Ray2Visibility = 1;
this->ArcVisibility = 1;
this->LabelFormat = new char[8];
sprintf(this->LabelFormat,"%s","%-#6.3g");
}
//----------------------------------------------------------------------
vtkAngleRepresentation::~vtkAngleRepresentation()
{
if ( this->HandleRepresentation )
{
this->HandleRepresentation->Delete();
}
if ( this->Point1Representation )
{
this->Point1Representation->Delete();
}
if ( this->CenterRepresentation )
{
this->CenterRepresentation->Delete();
}
if ( this->Point2Representation )
{
this->Point2Representation->Delete();
}
delete [] this->LabelFormat;
this->LabelFormat = NULL;
}
//----------------------------------------------------------------------
void vtkAngleRepresentation::InstantiateHandleRepresentation()
{
if ( ! this->Point1Representation )
{
this->Point1Representation = this->HandleRepresentation->NewInstance();
this->Point1Representation->ShallowCopy(this->HandleRepresentation);
}
if ( ! this->CenterRepresentation )
{
this->CenterRepresentation = this->HandleRepresentation->NewInstance();
this->CenterRepresentation->ShallowCopy(this->HandleRepresentation);
}
if ( ! this->Point2Representation )
{
this->Point2Representation = this->HandleRepresentation->NewInstance();
this->Point2Representation->ShallowCopy(this->HandleRepresentation);
}
}
//----------------------------------------------------------------------
int vtkAngleRepresentation::
ComputeInteractionState(int vtkNotUsed(X), int vtkNotUsed(Y), int vtkNotUsed(modify))
{
if (this->Point1Representation == NULL ||
this->CenterRepresentation == NULL ||
this->Point2Representation == NULL )
{
this->InteractionState = vtkAngleRepresentation::Outside;
return this->InteractionState;
}
int p1State = this->Point1Representation->GetInteractionState();
int cState = this->CenterRepresentation->GetInteractionState();
int p2State = this->Point2Representation->GetInteractionState();
if ( p1State == vtkHandleRepresentation::Nearby )
{
this->InteractionState = vtkAngleRepresentation::NearP1;
}
else if ( cState == vtkHandleRepresentation::Nearby )
{
this->InteractionState = vtkAngleRepresentation::NearCenter;
}
else if ( p2State == vtkHandleRepresentation::Nearby )
{
this->InteractionState = vtkAngleRepresentation::NearP2;
}
else
{
this->InteractionState = vtkAngleRepresentation::Outside;
}
return this->InteractionState;
}
//----------------------------------------------------------------------
void vtkAngleRepresentation::StartWidgetInteraction(double e[2])
{
double pos[3];
pos[0] = e[0];
pos[1] = e[1];
pos[2] = 0.0;
this->SetPoint1DisplayPosition(pos);
this->SetCenterDisplayPosition(pos);
this->SetPoint2DisplayPosition(pos);
}
//----------------------------------------------------------------------
void vtkAngleRepresentation::CenterWidgetInteraction(double e[2])
{
double pos[3];
pos[0] = e[0];
pos[1] = e[1];
pos[2] = 0.0;
this->SetCenterDisplayPosition(pos);
this->SetPoint2DisplayPosition(pos);
}
//----------------------------------------------------------------------
void vtkAngleRepresentation::WidgetInteraction(double e[2])
{
double pos[3];
pos[0] = e[0];
pos[1] = e[1];
pos[2] = 0.0;
this->SetPoint2DisplayPosition(pos);
}
//----------------------------------------------------------------------
void vtkAngleRepresentation::BuildRepresentation()
{
// Make sure that tolerance is consistent between handles and this representation
this->Point1Representation->SetTolerance(this->Tolerance);
this->CenterRepresentation->SetTolerance(this->Tolerance);
this->Point2Representation->SetTolerance(this->Tolerance);
}
//----------------------------------------------------------------------
void vtkAngleRepresentation::PrintSelf(ostream& os, vtkIndent indent)
{
//Superclass typedef defined in vtkTypeMacro() found in vtkSetGet.h
this->Superclass::PrintSelf(os,indent);
os << indent << "Angle: " << this->GetAngle() << "\n";
os << indent << "Tolerance: " << this->Tolerance <<"\n";
os << indent << "Ray1 Visibility: " << (this->Ray1Visibility ? "On\n" : "Off\n");
os << indent << "Ray2 Visibility: " << (this->Ray2Visibility ? "On\n" : "Off\n");
os << indent << "Arc Visibility: " << (this->ArcVisibility ? "On\n" : "Off\n");
os << indent << "Handle Representation: " << this->HandleRepresentation << "\n";
os << indent << "Label Format: ";
if ( this->LabelFormat )
{
os << this->LabelFormat << "\n";
}
else
{
os << "(none)\n";
}
os << indent << "Point1 Representation: ";
if ( this->Point1Representation )
{
this->Point1Representation->PrintSelf(os,indent.GetNextIndent());
}
else
{
os << "(none)\n";
}
os << indent << "Center Representation: ";
if ( this->CenterRepresentation )
{
this->CenterRepresentation->PrintSelf(os,indent.GetNextIndent());
}
else
{
os << "(none)\n";
}
os << indent << "Point2 Representation: ";
if ( this->Point2Representation )
{
this->Point2Representation->PrintSelf(os,indent.GetNextIndent());
}
else
{
os << "(none)\n";
}
}