VTK  9.5.2
vtkContourRepresentation.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
49
50#ifndef vtkContourRepresentation_h
51#define vtkContourRepresentation_h
52
53#include "vtkInteractionWidgetsModule.h" // For export macro
55#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
56#include <vector> // STL Header; Required for vector
57
58VTK_ABI_NAMESPACE_BEGIN
61class vtkPointPlacer;
62class vtkPolyData;
63class vtkIdList;
64
65//----------------------------------------------------------------------
67{
68public:
69 double WorldPosition[3];
71
72 // The point id. This is blank except in the case of
73 // vtkPolygonalSurfaceContourLineInterpolator
75};
76
78{
79public:
80 double WorldPosition[3];
84 std::vector<vtkContourRepresentationPoint*> Points;
85
86 // The point id. This is blank except in the case of
87 // vtkPolygonalSurfaceContourLineInterpolator
89};
90
92{
93public:
94 std::vector<vtkContourRepresentationNode*> Nodes;
96 {
97 for (unsigned int i = 0; i < this->Nodes.size(); i++)
98 {
99 for (unsigned int j = 0; j < this->Nodes[i]->Points.size(); j++)
100 {
101 delete this->Nodes[i]->Points[j];
102 }
103 this->Nodes[i]->Points.clear();
104 delete this->Nodes[i];
105 }
106 this->Nodes.clear();
107 }
108};
109
110class VTKINTERACTIONWIDGETS_EXPORT VTK_MARSHALAUTO vtkContourRepresentation
112{
113 friend class vtkContourWidget;
114
115public:
117
121 void PrintSelf(ostream& os, vtkIndent indent) override;
123
125
129 virtual int AddNodeAtWorldPosition(double x, double y, double z);
130 virtual int AddNodeAtWorldPosition(double worldPos[3]);
131 virtual int AddNodeAtWorldPosition(double worldPos[3], double worldOrient[9]);
133
135
141 virtual int AddNodeAtDisplayPosition(double displayPos[2]);
142 virtual int AddNodeAtDisplayPosition(int displayPos[2]);
143 virtual int AddNodeAtDisplayPosition(int X, int Y);
145
147
153 virtual int ActivateNode(double displayPos[2]);
154 virtual int ActivateNode(int displayPos[2]);
155 virtual int ActivateNode(int X, int Y);
157
158 // Description:
159 // Move the active node to a specified world position.
160 // Will return 0 if there is no active node or the node
161 // could not be moved to that position. 1 will be returned
162 // on success.
163 virtual int SetActiveNodeToWorldPosition(double pos[3]);
164 virtual int SetActiveNodeToWorldPosition(double pos[3], double orient[9]);
165
167
174 virtual int SetActiveNodeToDisplayPosition(double pos[2]);
175 virtual int SetActiveNodeToDisplayPosition(int pos[2]);
176 virtual int SetActiveNodeToDisplayPosition(int X, int Y);
178
180
185 virtual int GetNthNodeSelected(int);
186 virtual int SetNthNodeSelected(int);
188
193 virtual int GetActiveNodeWorldPosition(double pos[3]);
194
199 virtual int GetActiveNodeWorldOrientation(double orient[9]);
200
205 virtual int GetActiveNodeDisplayPosition(double pos[2]);
206
210 virtual int GetNumberOfNodes();
211
217 virtual int GetNthNodeDisplayPosition(int n, double pos[2]);
218
224 virtual int GetNthNodeWorldPosition(int n, double pos[3]);
225
230
236 virtual int GetNthNodeWorldOrientation(int n, double orient[9]);
237
239
247 virtual int SetNthNodeDisplayPosition(int n, int X, int Y);
248 virtual int SetNthNodeDisplayPosition(int n, int pos[2]);
249 virtual int SetNthNodeDisplayPosition(int n, double pos[2]);
251
253
260 virtual int SetNthNodeWorldPosition(int n, double pos[3]);
261 virtual int SetNthNodeWorldPosition(int n, double pos[3], double orient[9]);
263
269 virtual int GetNthNodeSlope(int idx, double slope[3]);
270
271 // Description:
272 // For a given node n, get the number of intermediate
273 // points between this node and the node at
274 // (n+1). If n is the last node and the loop is
275 // closed, this is the number of intermediate points
276 // between node n and node 0. 0 is returned if n is
277 // out of range.
279
286 virtual int GetIntermediatePointWorldPosition(int n, int idx, double point[3]);
287
293 virtual int AddIntermediatePointWorldPosition(int n, double point[3]);
294
301 virtual int AddIntermediatePointWorldPosition(int n, double point[3], vtkIdType ptId);
302
307 virtual int DeleteLastNode();
308
313 virtual int DeleteActiveNode();
314
319 virtual int DeleteNthNode(int n);
320
324 virtual void ClearAllNodes();
325
330 virtual int AddNodeOnContour(int X, int Y);
331
333
337 vtkSetClampMacro(PixelTolerance, int, 1, 100);
338 vtkGetMacro(PixelTolerance, int);
340
342
346 vtkSetClampMacro(WorldTolerance, double, 0.0, VTK_DOUBLE_MAX);
347 vtkGetMacro(WorldTolerance, double);
349
350 // Used to communicate about the state of the representation
351 enum
352 {
355 };
356
357 enum
358 {
363 };
364
366
370 vtkGetMacro(CurrentOperation, int);
371 vtkSetClampMacro(
384
385 // Description:
386 // Set / get the Point Placer. The point placer is
387 // responsible for converting display coordinates into
388 // world coordinates according to some constraints, and
389 // for validating world positions.
391 vtkGetObjectMacro(PointPlacer, vtkPointPlacer);
392
394
402
404
407 void BuildRepresentation() override = 0;
408 int ComputeInteractionState(int X, int Y, int modified = 0) override = 0;
409 void StartWidgetInteraction(double e[2]) override = 0;
410 void WidgetInteraction(double e[2]) override = 0;
412
414
417 void ReleaseGraphicsResources(vtkWindow* w) override = 0;
418 int RenderOverlay(vtkViewport* viewport) override = 0;
419 int RenderOpaqueGeometry(vtkViewport* viewport) override = 0;
423
425
430 vtkGetMacro(ClosedLoop, vtkTypeBool);
431 vtkBooleanMacro(ClosedLoop, vtkTypeBool);
433
435
443
448
454
455 vtkSetMacro(RebuildLocator, bool);
456
457protected:
460
461 // Selection tolerance for the handles
464
467
469
472
473 // A flag to indicate whether to show the Selected nodes
475
477
478 void AddNodeAtPositionInternal(double worldPos[3], double worldOrient[9], int displayPos[2]);
479 void AddNodeAtPositionInternal(double worldPos[3], double worldOrient[9], double displayPos[2]);
480 void SetNthNodeWorldPositionInternal(int n, double worldPos[3], double worldOrient[9]);
481
483
488 double worldPos[3], double worldOrient[9], int displayPos[2]);
490 double worldPos[3], double worldOrient[9], double displayPos[2]);
492
493 virtual void UpdateLines(int index);
494 void UpdateLine(int idx1, int idx2);
495
496 virtual int FindClosestPointOnContour(int X, int Y, double worldPos[3], int* idx);
497
498 virtual void BuildLines() = 0;
499
500 // This method is called when something changes in the point placer.
501 // It will cause all points to be updated, and all lines to be regenerated.
502 // It should be extended to detect changes in the line interpolator too.
503 virtual int UpdateContour();
505
506 void ComputeMidpoint(double p1[3], double p2[3], double mid[3])
507 {
508 mid[0] = (p1[0] + p2[0]) / 2;
509 mid[1] = (p1[1] + p2[1]) / 2;
510 mid[2] = (p1[2] + p2[2]) / 2;
511 }
512
525
530 virtual void Initialize(vtkPolyData*);
531
537
543
549
551
553
554private:
556 void operator=(const vtkContourRepresentation&) = delete;
557};
558
559VTK_ABI_NAMESPACE_END
560#endif
Defines API for interpolating/modifying nodes from a vtkContourRepresentation.
std::vector< vtkContourRepresentationNode * > Nodes
std::vector< vtkContourRepresentationPoint * > Points
virtual int AddNodeAtDisplayPosition(int X, int Y)
Add a node at a specific display position.
void StartWidgetInteraction(double e[2]) override=0
These are methods that satisfy vtkWidgetRepresentation's API.
virtual int AddNodeAtDisplayPosition(double displayPos[2])
Add a node at a specific display position.
void SetClosedLoop(vtkTypeBool val)
Set / Get the ClosedLoop value.
vtkContourRepresentationInternals * Internal
void PrintSelf(ostream &os, vtkIndent indent) override
Standard VTK methods.
void AddNodeAtPositionInternal(double worldPos[3], double worldOrient[9], double displayPos[2])
void WidgetInteraction(double e[2]) override=0
These are methods that satisfy vtkWidgetRepresentation's API.
void SetCurrentOperationToTranslate()
Set / get the current operation.
void SetCurrentOperationToInactive()
Set / get the current operation.
virtual vtkContourRepresentationNode * GetNthNode(int n)
Get the nth node.
virtual int AddNodeOnContour(int X, int Y)
Given a specific X, Y pixel location, add a new node on the contour at this location.
virtual int SetNthNodeWorldPosition(int n, double pos[3], double orient[9])
Set the nth node's world position.
virtual int GetNthNodeSlope(int idx, double slope[3])
Get the nth node's slope.
void GetNodePolyData(vtkPolyData *poly)
Get the nodes and not the intermediate points in this contour as a vtkPolyData.
virtual int UpdateContour()
virtual int GetNumberOfIntermediatePoints(int n)
void SetCurrentOperationToScale()
Set / get the current operation.
vtkIncrementalOctreePointLocator * Locator
Adding a point locator to the representation to speed up lookup of the active node when dealing with ...
virtual int GetActiveNodeSelected()
Set/Get whether the active or nth node is selected.
void SetNthNodeWorldPositionInternal(int n, double worldPos[3], double worldOrient[9])
virtual int SetActiveNodeToWorldPosition(double pos[3])
virtual int SetActiveNodeToDisplayPosition(int X, int Y)
Move the active node based on a specified display position.
void ReleaseGraphicsResources(vtkWindow *w) override=0
Methods required by vtkProp superclass.
void GetRendererComputedDisplayPositionFromWorldPosition(double worldPos[3], double worldOrient[9], int displayPos[2])
Given a world position and orientation, this computes the display position using the renderer of this...
virtual int DeleteNthNode(int n)
Delete the nth node.
virtual int DeleteLastNode()
Delete the last node.
virtual int FindClosestPointOnContour(int X, int Y, double worldPos[3], int *idx)
void BuildRepresentation() override=0
These are methods that satisfy vtkWidgetRepresentation's API.
void UpdateLine(int idx1, int idx2)
void SetPointPlacer(vtkPointPlacer *)
virtual int GetIntermediatePointWorldPosition(int n, int idx, double point[3])
Get the world position of the intermediate point at index idx between nodes n and (n+1) (or n and 0 i...
virtual void Initialize(vtkPolyData *)
Overloaded initialize method, that is called when the vtkIdList is nullptr to maintain backwards comp...
void SetLineInterpolator(vtkContourLineInterpolator *)
Set / Get the Line Interpolator.
virtual int SetNthNodeSelected(int)
Set/Get whether the active or nth node is selected.
int RenderOverlay(vtkViewport *viewport) override=0
Methods required by vtkProp superclass.
virtual int DeleteActiveNode()
Delete the active node.
virtual void InitializeContour(vtkPolyData *, vtkIdList *)
Internal implementation, delegated to another method, so that users who override the method Initializ...
virtual int GetActiveNodeWorldOrientation(double orient[9])
Get the world orientation of the active node.
virtual void UpdateLines(int index)
vtkTypeBool HasTranslucentPolygonalGeometry() override=0
Methods required by vtkProp superclass.
int ComputeInteractionState(int X, int Y, int modified=0) override=0
These are methods that satisfy vtkWidgetRepresentation's API.
virtual int AddNodeAtWorldPosition(double worldPos[3])
Add a node at a specific world position.
void SetCurrentOperationToShift()
Set / get the current operation.
void AddNodeAtPositionInternal(double worldPos[3], double worldOrient[9], int displayPos[2])
int RenderTranslucentPolygonalGeometry(vtkViewport *viewport) override=0
Methods required by vtkProp superclass.
virtual int SetNthNodeDisplayPosition(int n, int X, int Y)
Set the nth node's display position.
virtual int SetNthNodeWorldPosition(int n, double pos[3])
Set the nth node's world position.
virtual int SetNthNodeDisplayPosition(int n, int pos[2])
Set the nth node's display position.
virtual int GetNthNodeWorldOrientation(int n, double orient[9])
Get the nth node's world orientation.
virtual int ActivateNode(int displayPos[2])
Given a display position, activate a node.
virtual int AddNodeAtWorldPosition(double x, double y, double z)
Add a node at a specific world position.
virtual int ToggleActiveNodeSelected()
Set/Get whether the active or nth node is selected.
~vtkContourRepresentation() override
virtual int GetActiveNodeWorldPosition(double pos[3])
Get the world position of the active node.
virtual int GetActiveNodeDisplayPosition(double pos[2])
Get the display position of the active node.
virtual int GetNthNodeWorldPosition(int n, double pos[3])
Get the nth node's world position.
virtual void SetShowSelectedNodes(vtkTypeBool)
A flag to indicate whether to show the Selected nodes Default is to set it to false.
virtual int AddIntermediatePointWorldPosition(int n, double point[3])
Add an intermediate point between node n and n+1 (or n and 0 if n is the last node and the loop is cl...
virtual int ActivateNode(double displayPos[2])
Given a display position, activate a node.
virtual vtkPolyData * GetContourRepresentationAsPolyData()=0
Get the points in this contour as a vtkPolyData.
void GetRendererComputedDisplayPositionFromWorldPosition(double worldPos[3], double worldOrient[9], double displayPos[2])
Given a world position and orientation, this computes the display position using the renderer of this...
virtual int ActivateNode(int X, int Y)
Given a display position, activate a node.
int RenderOpaqueGeometry(vtkViewport *viewport) override=0
Methods required by vtkProp superclass.
virtual int SetNthNodeDisplayPosition(int n, double pos[2])
Set the nth node's display position.
virtual int GetNumberOfNodes()
Get the number of nodes.
virtual int SetActiveNodeToDisplayPosition(int pos[2])
Move the active node based on a specified display position.
virtual void ClearAllNodes()
Delete all nodes.
void ComputeMidpoint(double p1[3], double p2[3], double mid[3])
virtual void BuildLines()=0
void ResetLocator()
Deletes the previous locator if it exists and creates a new locator.
virtual int AddIntermediatePointWorldPosition(int n, double point[3], vtkIdType ptId)
Add an intermediate point between node n and n+1 (or n and 0 if n is the last node and the loop is cl...
virtual int GetNthNodeDisplayPosition(int n, double pos[2])
Get the nth node's display position.
virtual int SetActiveNodeToDisplayPosition(double pos[2])
Move the active node based on a specified display position.
virtual int AddNodeAtDisplayPosition(int displayPos[2])
Add a node at a specific display position.
virtual void SetCurrentOperation(int)
Set / get the current operation.
virtual void Initialize(vtkPolyData *, vtkIdList *)
Build a contour representation from externally supplied PolyData.
virtual int GetNthNodeSelected(int)
Set/Get whether the active or nth node is selected.
vtkContourLineInterpolator * LineInterpolator
virtual int SetActiveNodeToWorldPosition(double pos[3], double orient[9])
virtual int AddNodeAtWorldPosition(double worldPos[3], double worldOrient[9])
Add a node at a specific world position.
list of point or cell ids
Definition vtkIdList.h:24
Incremental octree in support of both point location and point insertion.
a simple class to control print indentation
Definition vtkIndent.h:29
Abstract interface to translate 2D display positions to world coordinates.
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition vtkPolyData.h:72
record modification and/or execution time
abstract specification for Viewports
Definition vtkViewport.h:47
window superclass for vtkRenderWindow
Definition vtkWindow.h:26
int vtkTypeBool
Definition vtkABI.h:64
int vtkIdType
Definition vtkType.h:332
#define VTK_DOUBLE_MAX
Definition vtkType.h:171
#define VTK_MARSHALAUTO