forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkImageCroppingRegionsWidget.h
251 lines (212 loc) · 6.31 KB
/
vtkImageCroppingRegionsWidget.h
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/*=========================================================================
Program: Visualization Toolkit
Module: vtkImageCroppingRegionsWidget.h
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.
=========================================================================*/
/**
* @class vtkImageCroppingRegionsWidget
* @brief widget for cropping an image
*
* This widget displays a set of axis aligned lines that can be interactively
* manipulated to crop a volume. The region to be cropped away is displayed
* in a different highlight. Much like the vtkVolumeMapper, this widget
* supports 27 possible configurations of cropping planes. (See
* CroppingRegionFlags). If a volume mapper is set, the cropping planes
* are directly propagated to the volume mapper. The widget invokes a
* CroppingPlanesPositionChangedEvent when the position of any of the
* cropping planes is changed. The widget also invokes an InteractionEvent
* in response to user interaction.
*/
#ifndef vtkImageCroppingRegionsWidget_h
#define vtkImageCroppingRegionsWidget_h
#include "vtk3DWidget.h"
#include "vtkInteractionWidgetsModule.h" // For export macro
class vtkActor2D;
class vtkImageData;
class vtkLineSource;
class vtkVolumeMapper;
class vtkPolyData;
class VTKINTERACTIONWIDGETS_EXPORT vtkImageCroppingRegionsWidget : public vtk3DWidget
{
public:
///@{
/**
* Standard VTK methods.
*/
static vtkImageCroppingRegionsWidget* New();
vtkTypeMacro(vtkImageCroppingRegionsWidget, vtk3DWidget);
void PrintSelf(ostream& os, vtkIndent indent) override;
///@}
///@{
/**
* Place/Adjust widget within bounds
*/
using vtk3DWidget::PlaceWidget;
void PlaceWidget(double bounds[6]) override;
///@}
/**
* Enable/disable the widget
*/
void SetEnabled(int enabling) override;
///@{
/**
* Set/Get the plane positions that represent the cropped region.
*/
vtkGetVector6Macro(PlanePositions, double);
virtual void SetPlanePositions(double pos[6])
{
this->SetPlanePositions(pos[0], pos[1], pos[2], pos[3], pos[4], pos[5]);
}
virtual void SetPlanePositions(float pos[6])
{
this->SetPlanePositions(pos[0], pos[1], pos[2], pos[3], pos[4], pos[5]);
}
virtual void SetPlanePositions(
double xMin, double xMax, double yMin, double yMax, double zMin, double zMax);
///@}
///@{
/**
* Set/Get the cropping region flags
*/
virtual void SetCroppingRegionFlags(int flags);
vtkGetMacro(CroppingRegionFlags, int);
///@}
/**
* Set/get the slice orientation
*/
enum
{
SLICE_ORIENTATION_YZ = 0,
SLICE_ORIENTATION_XZ = 1,
SLICE_ORIENTATION_XY = 2
};
vtkGetMacro(SliceOrientation, int);
virtual void SetSliceOrientation(int orientation);
virtual void SetSliceOrientationToXY()
{
this->SetSliceOrientation(vtkImageCroppingRegionsWidget::SLICE_ORIENTATION_XY);
}
virtual void SetSliceOrientationToYZ()
{
this->SetSliceOrientation(vtkImageCroppingRegionsWidget::SLICE_ORIENTATION_YZ);
}
virtual void SetSliceOrientationToXZ()
{
this->SetSliceOrientation(vtkImageCroppingRegionsWidget::SLICE_ORIENTATION_XZ);
}
///@{
/**
* Set/Get the slice number
*/
virtual void SetSlice(int num);
vtkGetMacro(Slice, int);
///@}
///@{
/**
* Set/Get line 1 color
*/
virtual void SetLine1Color(double r, double g, double b);
virtual void SetLine1Color(double rgb[3]) { this->SetLine1Color(rgb[0], rgb[1], rgb[2]); }
virtual double* GetLine1Color();
virtual void GetLine1Color(double rgb[3]);
///@}
///@{
/**
* Set/Get line 2 color
*/
virtual void SetLine2Color(double r, double g, double b);
virtual void SetLine2Color(double rgb[3]) { this->SetLine2Color(rgb[0], rgb[1], rgb[2]); }
virtual double* GetLine2Color();
virtual void GetLine2Color(double rgb[3]);
///@}
///@{
/**
* Set/Get line 3 color
*/
virtual void SetLine3Color(double r, double g, double b);
virtual void SetLine3Color(double rgb[3]) { this->SetLine3Color(rgb[0], rgb[1], rgb[2]); }
virtual double* GetLine3Color();
virtual void GetLine3Color(double rgb[3]);
///@}
///@{
/**
* Set/Get line 4 color
*/
virtual void SetLine4Color(double r, double g, double b);
virtual void SetLine4Color(double rgb[3]) { this->SetLine4Color(rgb[0], rgb[1], rgb[2]); }
virtual double* GetLine4Color();
virtual void GetLine4Color(double rgb[3]);
///@}
///@{
/**
* Set/Get the input volume mapper
* Update the widget according to its mapper
*/
virtual void SetVolumeMapper(vtkVolumeMapper* mapper);
vtkGetObjectMacro(VolumeMapper, vtkVolumeMapper);
virtual void UpdateAccordingToInput();
///@}
///@{
/**
* Callbacks for user interaction.
*/
void MoveHorizontalLine();
void MoveVerticalLine();
void MoveIntersectingLines();
void UpdateCursorIcon();
void OnButtonPress();
void OnButtonRelease();
void OnMouseMove();
///@}
/**
* Events invoked by this widget
*/
enum WidgetEventIds
{
CroppingPlanesPositionChangedEvent = 10050
};
protected:
vtkImageCroppingRegionsWidget();
~vtkImageCroppingRegionsWidget() override;
vtkVolumeMapper* VolumeMapper;
vtkLineSource* LineSources[4];
vtkActor2D* LineActors[4];
vtkPolyData* RegionPolyData[9];
vtkActor2D* RegionActors[9];
double PlanePositions[6];
int SliceOrientation;
int Slice;
double GetSlicePosition();
int CroppingRegionFlags;
int MouseCursorState;
int Moving;
// Handles the events
static void ProcessEvents(
vtkObject* object, unsigned long event, void* clientdata, void* calldata);
void SetMouseCursor(int state);
enum WidgetStates
{
NoLine = 0,
MovingH1AndV1,
MovingH2AndV1,
MovingH1AndV2,
MovingH2AndV2,
MovingV1,
MovingV2,
MovingH1,
MovingH2
};
int ComputeWorldCoordinate(int x, int y, double* coord);
void UpdateOpacity();
void UpdateGeometry();
void ConstrainPlanePositions(double positions[6]);
private:
vtkImageCroppingRegionsWidget(const vtkImageCroppingRegionsWidget&) = delete;
void operator=(const vtkImageCroppingRegionsWidget&) = delete;
};
#endif