VTK  9.1.0
vtkContourRepresentation.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkContourRepresentation.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
68#ifndef vtkContourRepresentation_h
69#define vtkContourRepresentation_h
70
71#include "vtkInteractionWidgetsModule.h" // For export macro
73#include <vector> // STL Header; Required for vector
74
77class vtkPointPlacer;
78class vtkPolyData;
79class vtkIdList;
80
81//----------------------------------------------------------------------
83{
84public:
85 double WorldPosition[3];
87
88 // The point id. This is blank except in the case of
89 // vtkPolygonalSurfaceContourLineInterpolator
91};
92
94{
95public:
96 double WorldPosition[3];
100 std::vector<vtkContourRepresentationPoint*> Points;
101
102 // The point id. This is blank except in the case of
103 // vtkPolygonalSurfaceContourLineInterpolator
105};
106
108{
109public:
110 std::vector<vtkContourRepresentationNode*> Nodes;
112 {
113 for (unsigned int i = 0; i < this->Nodes.size(); i++)
114 {
115 for (unsigned int j = 0; j < this->Nodes[i]->Points.size(); j++)
116 {
117 delete this->Nodes[i]->Points[j];
118 }
119 this->Nodes[i]->Points.clear();
120 delete this->Nodes[i];
121 }
122 this->Nodes.clear();
123 }
124};
125
126class VTKINTERACTIONWIDGETS_EXPORT vtkContourRepresentation : public vtkWidgetRepresentation
127{
128 friend class vtkContourWidget;
129
130public:
132
136 void PrintSelf(ostream& os, vtkIndent indent) override;
138
140
144 virtual int AddNodeAtWorldPosition(double x, double y, double z);
145 virtual int AddNodeAtWorldPosition(double worldPos[3]);
146 virtual int AddNodeAtWorldPosition(double worldPos[3], double worldOrient[9]);
148
150
156 virtual int AddNodeAtDisplayPosition(double displayPos[2]);
157 virtual int AddNodeAtDisplayPosition(int displayPos[2]);
158 virtual int AddNodeAtDisplayPosition(int X, int Y);
160
162
168 virtual int ActivateNode(double displayPos[2]);
169 virtual int ActivateNode(int displayPos[2]);
170 virtual int ActivateNode(int X, int Y);
172
173 // Description:
174 // Move the active node to a specified world position.
175 // Will return 0 if there is no active node or the node
176 // could not be moved to that position. 1 will be returned
177 // on success.
178 virtual int SetActiveNodeToWorldPosition(double pos[3]);
179 virtual int SetActiveNodeToWorldPosition(double pos[3], double orient[9]);
180
182
189 virtual int SetActiveNodeToDisplayPosition(double pos[2]);
190 virtual int SetActiveNodeToDisplayPosition(int pos[2]);
191 virtual int SetActiveNodeToDisplayPosition(int X, int Y);
193
195
200 virtual int GetNthNodeSelected(int);
201 virtual int SetNthNodeSelected(int);
203
208 virtual int GetActiveNodeWorldPosition(double pos[3]);
209
214 virtual int GetActiveNodeWorldOrientation(double orient[9]);
215
220 virtual int GetActiveNodeDisplayPosition(double pos[2]);
221
225 virtual int GetNumberOfNodes();
226
232 virtual int GetNthNodeDisplayPosition(int n, double pos[2]);
233
239 virtual int GetNthNodeWorldPosition(int n, double pos[3]);
240
245
251 virtual int GetNthNodeWorldOrientation(int n, double orient[9]);
252
254
262 virtual int SetNthNodeDisplayPosition(int n, int X, int Y);
263 virtual int SetNthNodeDisplayPosition(int n, int pos[2]);
264 virtual int SetNthNodeDisplayPosition(int n, double pos[2]);
266
268
275 virtual int SetNthNodeWorldPosition(int n, double pos[3]);
276 virtual int SetNthNodeWorldPosition(int n, double pos[3], double orient[9]);
278
284 virtual int GetNthNodeSlope(int idx, double slope[3]);
285
286 // Description:
287 // For a given node n, get the number of intermediate
288 // points between this node and the node at
289 // (n+1). If n is the last node and the loop is
290 // closed, this is the number of intermediate points
291 // between node n and node 0. 0 is returned if n is
292 // out of range.
294
301 virtual int GetIntermediatePointWorldPosition(int n, int idx, double point[3]);
302
308 virtual int AddIntermediatePointWorldPosition(int n, double point[3]);
309
316 virtual int AddIntermediatePointWorldPosition(int n, double point[3], vtkIdType ptId);
317
322 virtual int DeleteLastNode();
323
328 virtual int DeleteActiveNode();
329
334 virtual int DeleteNthNode(int n);
335
339 virtual void ClearAllNodes();
340
345 virtual int AddNodeOnContour(int X, int Y);
346
348
352 vtkSetClampMacro(PixelTolerance, int, 1, 100);
353 vtkGetMacro(PixelTolerance, int);
355
357
361 vtkSetClampMacro(WorldTolerance, double, 0.0, VTK_DOUBLE_MAX);
362 vtkGetMacro(WorldTolerance, double);
364
365 // Used to communicate about the state of the representation
366 enum
367 {
368 Outside = 0,
369 Nearby
370 };
371
372 enum
373 {
374 Inactive = 0,
377 Scale
378 };
379
381
385 vtkGetMacro(CurrentOperation, int);
386 vtkSetClampMacro(
389 {
390 this->SetCurrentOperation(vtkContourRepresentation::Inactive);
391 }
393 {
394 this->SetCurrentOperation(vtkContourRepresentation::Translate);
395 }
396 void SetCurrentOperationToShift() { this->SetCurrentOperation(vtkContourRepresentation::Shift); }
397 void SetCurrentOperationToScale() { this->SetCurrentOperation(vtkContourRepresentation::Scale); }
399
400 // Description:
401 // Set / get the Point Placer. The point placer is
402 // responsible for converting display coordinates into
403 // world coordinates according to some constraints, and
404 // for validating world positions.
406 vtkGetObjectMacro(PointPlacer, vtkPointPlacer);
407
409
415 vtkGetObjectMacro(LineInterpolator, vtkContourLineInterpolator);
417
419
422 void BuildRepresentation() override = 0;
423 int ComputeInteractionState(int X, int Y, int modified = 0) override = 0;
424 void StartWidgetInteraction(double e[2]) override = 0;
425 void WidgetInteraction(double e[2]) override = 0;
427
429
432 void ReleaseGraphicsResources(vtkWindow* w) override = 0;
433 int RenderOverlay(vtkViewport* viewport) override = 0;
434 int RenderOpaqueGeometry(vtkViewport* viewport) override = 0;
438
440
445 vtkGetMacro(ClosedLoop, vtkTypeBool);
446 vtkBooleanMacro(ClosedLoop, vtkTypeBool);
448
450
455 vtkGetMacro(ShowSelectedNodes, vtkTypeBool);
456 vtkBooleanMacro(ShowSelectedNodes, vtkTypeBool);
458
463
469
470 vtkSetMacro(RebuildLocator, bool);
471
472protected:
475
476 // Selection tolerance for the handles
479
482
484
487
488 // A flag to indicate whether to show the Selected nodes
490
492
493 void AddNodeAtPositionInternal(double worldPos[3], double worldOrient[9], int displayPos[2]);
494 void AddNodeAtPositionInternal(double worldPos[3], double worldOrient[9], double displayPos[2]);
495 void SetNthNodeWorldPositionInternal(int n, double worldPos[3], double worldOrient[9]);
496
498
503 double worldPos[3], double worldOrient[9], int displayPos[2]);
505 double worldPos[3], double worldOrient[9], double displayPos[2]);
507
508 virtual void UpdateLines(int index);
509 void UpdateLine(int idx1, int idx2);
510
511 virtual int FindClosestPointOnContour(int X, int Y, double worldPos[3], int* idx);
512
513 virtual void BuildLines() = 0;
514
515 // This method is called when something changes in the point placer.
516 // It will cause all points to be updated, and all lines to be regenerated.
517 // It should be extended to detect changes in the line interpolator too.
518 virtual int UpdateContour();
520
521 void ComputeMidpoint(double p1[3], double p2[3], double mid[3])
522 {
523 mid[0] = (p1[0] + p2[0]) / 2;
524 mid[1] = (p1[1] + p2[1]) / 2;
525 mid[2] = (p1[2] + p2[2]) / 2;
526 }
527
540
545 virtual void Initialize(vtkPolyData*);
546
552
558
564
566
568
569private:
571 void operator=(const vtkContourRepresentation&) = delete;
572};
573
574#endif
Defines API for interpolating/modifying nodes from a vtkContourRepresentation.
std::vector< vtkContourRepresentationNode * > Nodes
std::vector< vtkContourRepresentationPoint * > Points
represent the vtkContourWidget
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 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.
create a contour with a set of points
list of point or cell ids
Definition: vtkIdList.h:40
Incremental octree in support of both point location and point insertion.
a simple class to control print indentation
Definition: vtkIndent.h:43
Abstract interface to translate 2D display positions to world coordinates.
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:95
record modification and/or execution time
Definition: vtkTimeStamp.h:42
abstract specification for Viewports
Definition: vtkViewport.h:56
abstract class defines interface between the widget and widget representation classes
window superclass for vtkRenderWindow
Definition: vtkWindow.h:45
@ point
Definition: vtkX3D.h:242
@ index
Definition: vtkX3D.h:252
int vtkTypeBool
Definition: vtkABI.h:69
int vtkIdType
Definition: vtkType.h:332
#define VTK_DOUBLE_MAX
Definition: vtkType.h:165