forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkPointCloudRepresentation.h
264 lines (232 loc) · 8.97 KB
/
vtkPointCloudRepresentation.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
252
253
254
255
256
257
258
259
260
261
262
263
264
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPointCloudRepresentation.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 vtkPointCloudRepresentation
* @brief represent the vtkPointCloudWidget
*
* This class provides support for interactively querying and selecting
* points from a point cloud. It is a representation for the
* vtkPointCloudWidget.
*
* @sa
* vtkPointCloudWidget vtkHardwareSelection vtkPointPicker
*/
#ifndef vtkPointCloudRepresentation_h
#define vtkPointCloudRepresentation_h
#include "vtkInteractionWidgetsModule.h" // For export macro
#include "vtkWidgetRepresentation.h"
class vtkActor;
class vtkPolyDataMapper;
class vtkOutlineFilter;
class vtkActor2D;
class vtkCoordinate;
class vtkPolyDataMapper2D;
class vtkProperty2D;
class vtkPolyData;
class vtkPicker;
class vtkPointPicker;
class vtkPointSet;
class vtkGlyphSource2D;
struct vtkPointCloudPicker;
class VTKINTERACTIONWIDGETS_EXPORT vtkPointCloudRepresentation : public vtkWidgetRepresentation
{
friend struct vtkPointCloudPicker;
public:
/**
* Instantiate this class.
*/
static vtkPointCloudRepresentation* New();
///@{
/**
* Standard VTK class methods for obtaining type information and printing.
*/
vtkTypeMacro(vtkPointCloudRepresentation, vtkWidgetRepresentation);
void PrintSelf(ostream& os, vtkIndent indent) override;
///@}
///@{
/**
* Specify and place either an actor (vtkActor) or a point set
* (vtkPointSet) that represents the point cloud. If placing with an
* actor, then the actor must refer to a mapper which in turn refers to a
* vtkPointSet, with the actor being used to render the point cloud. If
* placing with a vtkPointSet, then an internal vtkActor (and associated
* vtkPointGaussianMapper) is created to render the point cloud.
*/
void PlacePointCloud(vtkActor* a);
void PlacePointCloud(vtkPointSet* ps);
///@}
///@{
/**
* Retrieve the associated actor and mapper used to render the point cloud.
*/
vtkGetObjectMacro(PointCloudActor, vtkActor);
vtkGetObjectMacro(PointCloudMapper, vtkPolyDataMapper);
///@}
/**
* Retrieve the point id from the selected point. Note that this can
* be invalid (<0) if nothing was picked.
*/
vtkIdType GetPointId() { return this->PointId; }
///@{
/**
* Retrieve the point coordinates of the selected point. Note that if the
* point id is invalid (<0) then the coordinates are undefined.
*/
const double* GetPointCoordinates() { return this->PointCoordinates; }
void GetPointCoordinates(double x[3])
{
x[0] = this->PointCoordinates[0];
x[1] = this->PointCoordinates[1];
x[2] = this->PointCoordinates[2];
}
///@}
///@{
/**
* Flag controls whether highlighting of points occurs as the mouse
* moves over them. This can cause extra rendering operations.
*/
vtkSetMacro(Highlighting, bool);
vtkGetMacro(Highlighting, bool);
vtkBooleanMacro(Highlighting, bool);
///@}
// Enums define the state of the representation relative to the mouse pointer
// position. Used by ComputeInteractionState() to communicate with the
// widget.
enum _InteractionState
{
Outside = 0, // no points nor outline selected
OverOutline, // mouse is over the bounding box of the point cloud
Over, // mouse is over a point
Selecting // user has selected the point
};
///@{
/**
* The interaction state may be set from a widget (e.g., PointCloudWidget)
* or other object. This controls how the interaction with the widget
* proceeds. Normally this method is used as part of a handshaking process
* with the widget: First ComputeInteractionState() is invoked that returns
* a state based on geometric considerations (i.e., cursor near a widget
* feature), then based on events, the widget may modify this further.
*/
vtkSetClampMacro(InteractionState, int, Outside, Selecting);
///@}
///@{
/**
* Some methods required to satisfy the vtkWidgetRepresentation API.
*/
double* GetBounds() VTK_SIZEHINT(6) override;
void BuildRepresentation() override {}
int ComputeInteractionState(int X, int Y, int modify = 0) override;
///@}
///@{
/**
* These methods are necessary to make this representation behave as
* a vtkProp (i.e., support rendering).
*/
void GetActors2D(vtkPropCollection* pc) override;
int RenderOpaqueGeometry(vtkViewport* viewport) override;
int RenderTranslucentPolygonalGeometry(vtkViewport* viewport) override;
vtkTypeBool HasTranslucentPolygonalGeometry() override;
void ReleaseGraphicsResources(vtkWindow*) override;
int RenderOverlay(vtkViewport*) override;
///@}
///@{
/**
* Because point clouds can be very large, alternative point picking
* approaches can be used to select points: either hardware picking (via
* rendering) or software rendering (via CPU ray cast). In summary,
* hardware picking (via vtkHardwareSelector) is preferred, with an
* optional software picker (via vtkPointPicker) available. Each approach
* has potential advantages and disadvantages - mainly, vtkHardwareSelector
* is faster but only selects opaque geometry and what is visible on the
* screen, does not work with anti-aliasing, cannot handle assemblies, and
* may not work on some systems. vtkPointPicker avoids extra renders, and
* can handle translucent geometry, can select points "behind" other
* objects, will work on all systems, but is scalable to only a few tens of
* thousands of points. (See vtkHardwareSelector and vtkPointPicker for
* further information.) The choice of picker also has implications on the
* type of tolerancing used (as described in the following documentation).
* (Note also that the pickers may return slighty different results, this
* is expected due to the different way tolerancing works.)
*/
enum _Picking_Mode
{
HARDWARE_PICKING = 0,
SOFTWARE_PICKING
};
vtkSetClampMacro(PickingMode, int, HARDWARE_PICKING, SOFTWARE_PICKING);
vtkGetMacro(PickingMode, int);
void SetPickingModeToHardware() { this->SetPickingMode(HARDWARE_PICKING); }
void SetPickingModeToSoftware() { this->SetPickingMode(SOFTWARE_PICKING); }
///@}
///@{
/**
* The tolerance representing the distance to a point expressed in pixels.
* A tolerance of 0 selects from the pixel precisely under the cursor. A
* tolerance of 1 results in a 3x3 pixel square under the cursor (padded
* out by 1 in each direction); a tolerance of N results in a (2N+1)**2
* selection rectangle. The point in the selection rectangle which is
* closest in z-buffer to the pick position is selected. Note that this can
* sometimes return points further away from the cursor (which can be
* unexpected - use the tolerance carefully).
*/
vtkSetMacro(HardwarePickingTolerance, unsigned int);
vtkGetMacro(HardwarePickingTolerance, unsigned int);
///@}
///@{
/**
* The tolerance representing the distance to a point (as a fraction of the
* bounding box of the point cloud). This specifies when the cursor is
* considered near enough to the point to highlight it. Note that this is
* a sensitive parameter - too small and it's hard to pick anything; too
* large and points close to the eye can be picked in preference to points
* further away which are closer to the pick ray.
*/
vtkSetClampMacro(SoftwarePickingTolerance, double, 0.0, 100.0);
vtkGetMacro(SoftwarePickingTolerance, double);
///@}
/*
* Register internal Pickers within PickingManager
*/
void RegisterPickers() override;
protected:
vtkPointCloudRepresentation();
~vtkPointCloudRepresentation() override;
// The point cloud that is being operated on
vtkActor* PointCloudActor;
vtkPolyDataMapper* PointCloudMapper;
vtkPointSet* PointCloud;
// The selected point id and coordinates
vtkIdType PointId;
double PointCoordinates[3];
// Data members to manage state
bool Highlighting;
int PickingMode;
unsigned int HardwarePickingTolerance;
double SoftwarePickingTolerance;
vtkPicker* OutlinePicker;
vtkPointCloudPicker* PointCloudPicker;
// Draw an outline around the point cloud
vtkActor* OutlineActor;
vtkPolyDataMapper* OutlineMapper;
vtkOutlineFilter* OutlineFilter;
// Highlight the selected point
vtkActor2D* SelectionActor;
vtkCoordinate* SelectionCoordinate;
vtkPolyDataMapper2D* SelectionMapper;
vtkGlyphSource2D* SelectionShape;
vtkProperty2D* SelectionProperty;
void CreateDefaultProperties();
private:
vtkPointCloudRepresentation(const vtkPointCloudRepresentation&) = delete;
void operator=(const vtkPointCloudRepresentation&) = delete;
};
#endif