VTK  9.3.1
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
50 #ifndef vtkContourRepresentation_h
51 #define vtkContourRepresentation_h
52 
53 #include "vtkInteractionWidgetsModule.h" // For export macro
55 #include <vector> // STL Header; Required for vector
56 
57 VTK_ABI_NAMESPACE_BEGIN
60 class vtkPointPlacer;
61 class vtkPolyData;
62 class vtkIdList;
63 
64 //----------------------------------------------------------------------
66 {
67 public:
68  double WorldPosition[3];
70 
71  // The point id. This is blank except in the case of
72  // vtkPolygonalSurfaceContourLineInterpolator
74 };
75 
77 {
78 public:
79  double WorldPosition[3];
80  double WorldOrientation[9];
82  int Selected;
83  std::vector<vtkContourRepresentationPoint*> Points;
84 
85  // The point id. This is blank except in the case of
86  // vtkPolygonalSurfaceContourLineInterpolator
88 };
89 
91 {
92 public:
93  std::vector<vtkContourRepresentationNode*> Nodes;
94  void ClearNodes()
95  {
96  for (unsigned int i = 0; i < this->Nodes.size(); i++)
97  {
98  for (unsigned int j = 0; j < this->Nodes[i]->Points.size(); j++)
99  {
100  delete this->Nodes[i]->Points[j];
101  }
102  this->Nodes[i]->Points.clear();
103  delete this->Nodes[i];
104  }
105  this->Nodes.clear();
106  }
107 };
108 
109 class VTKINTERACTIONWIDGETS_EXPORT vtkContourRepresentation : public vtkWidgetRepresentation
110 {
111  friend class vtkContourWidget;
112 
113 public:
115 
119  void PrintSelf(ostream& os, vtkIndent indent) override;
121 
123 
127  virtual int AddNodeAtWorldPosition(double x, double y, double z);
128  virtual int AddNodeAtWorldPosition(double worldPos[3]);
129  virtual int AddNodeAtWorldPosition(double worldPos[3], double worldOrient[9]);
131 
133 
139  virtual int AddNodeAtDisplayPosition(double displayPos[2]);
140  virtual int AddNodeAtDisplayPosition(int displayPos[2]);
141  virtual int AddNodeAtDisplayPosition(int X, int Y);
143 
145 
151  virtual int ActivateNode(double displayPos[2]);
152  virtual int ActivateNode(int displayPos[2]);
153  virtual int ActivateNode(int X, int Y);
155 
156  // Description:
157  // Move the active node to a specified world position.
158  // Will return 0 if there is no active node or the node
159  // could not be moved to that position. 1 will be returned
160  // on success.
161  virtual int SetActiveNodeToWorldPosition(double pos[3]);
162  virtual int SetActiveNodeToWorldPosition(double pos[3], double orient[9]);
163 
165 
172  virtual int SetActiveNodeToDisplayPosition(double pos[2]);
173  virtual int SetActiveNodeToDisplayPosition(int pos[2]);
174  virtual int SetActiveNodeToDisplayPosition(int X, int Y);
176 
178 
181  virtual int ToggleActiveNodeSelected();
182  virtual int GetActiveNodeSelected();
183  virtual int GetNthNodeSelected(int);
184  virtual int SetNthNodeSelected(int);
186 
191  virtual int GetActiveNodeWorldPosition(double pos[3]);
192 
197  virtual int GetActiveNodeWorldOrientation(double orient[9]);
198 
203  virtual int GetActiveNodeDisplayPosition(double pos[2]);
204 
208  virtual int GetNumberOfNodes();
209 
215  virtual int GetNthNodeDisplayPosition(int n, double pos[2]);
216 
222  virtual int GetNthNodeWorldPosition(int n, double pos[3]);
223 
227  virtual vtkContourRepresentationNode* GetNthNode(int n);
228 
234  virtual int GetNthNodeWorldOrientation(int n, double orient[9]);
235 
237 
245  virtual int SetNthNodeDisplayPosition(int n, int X, int Y);
246  virtual int SetNthNodeDisplayPosition(int n, int pos[2]);
247  virtual int SetNthNodeDisplayPosition(int n, double pos[2]);
249 
251 
258  virtual int SetNthNodeWorldPosition(int n, double pos[3]);
259  virtual int SetNthNodeWorldPosition(int n, double pos[3], double orient[9]);
261 
267  virtual int GetNthNodeSlope(int idx, double slope[3]);
268 
269  // Description:
270  // For a given node n, get the number of intermediate
271  // points between this node and the node at
272  // (n+1). If n is the last node and the loop is
273  // closed, this is the number of intermediate points
274  // between node n and node 0. 0 is returned if n is
275  // out of range.
276  virtual int GetNumberOfIntermediatePoints(int n);
277 
284  virtual int GetIntermediatePointWorldPosition(int n, int idx, double point[3]);
285 
291  virtual int AddIntermediatePointWorldPosition(int n, double point[3]);
292 
299  virtual int AddIntermediatePointWorldPosition(int n, double point[3], vtkIdType ptId);
300 
305  virtual int DeleteLastNode();
306 
311  virtual int DeleteActiveNode();
312 
317  virtual int DeleteNthNode(int n);
318 
322  virtual void ClearAllNodes();
323 
328  virtual int AddNodeOnContour(int X, int Y);
329 
331 
335  vtkSetClampMacro(PixelTolerance, int, 1, 100);
336  vtkGetMacro(PixelTolerance, int);
338 
340 
344  vtkSetClampMacro(WorldTolerance, double, 0.0, VTK_DOUBLE_MAX);
345  vtkGetMacro(WorldTolerance, double);
347 
348  // Used to communicate about the state of the representation
349  enum
350  {
351  Outside = 0,
352  Nearby
353  };
354 
355  enum
356  {
357  Inactive = 0,
360  Scale
361  };
362 
364 
368  vtkGetMacro(CurrentOperation, int);
369  vtkSetClampMacro(
372  {
373  this->SetCurrentOperation(vtkContourRepresentation::Inactive);
374  }
376  {
377  this->SetCurrentOperation(vtkContourRepresentation::Translate);
378  }
379  void SetCurrentOperationToShift() { this->SetCurrentOperation(vtkContourRepresentation::Shift); }
380  void SetCurrentOperationToScale() { this->SetCurrentOperation(vtkContourRepresentation::Scale); }
382 
383  // Description:
384  // Set / get the Point Placer. The point placer is
385  // responsible for converting display coordinates into
386  // world coordinates according to some constraints, and
387  // for validating world positions.
388  void SetPointPlacer(vtkPointPlacer*);
389  vtkGetObjectMacro(PointPlacer, vtkPointPlacer);
390 
392 
397  void SetLineInterpolator(vtkContourLineInterpolator*);
398  vtkGetObjectMacro(LineInterpolator, vtkContourLineInterpolator);
400 
402 
405  void BuildRepresentation() override = 0;
406  int ComputeInteractionState(int X, int Y, int modified = 0) override = 0;
407  void StartWidgetInteraction(double e[2]) override = 0;
408  void WidgetInteraction(double e[2]) override = 0;
410 
412 
415  void ReleaseGraphicsResources(vtkWindow* w) override = 0;
416  int RenderOverlay(vtkViewport* viewport) override = 0;
417  int RenderOpaqueGeometry(vtkViewport* viewport) override = 0;
418  int RenderTranslucentPolygonalGeometry(vtkViewport* viewport) override = 0;
421 
423 
427  void SetClosedLoop(vtkTypeBool val);
428  vtkGetMacro(ClosedLoop, vtkTypeBool);
429  vtkBooleanMacro(ClosedLoop, vtkTypeBool);
431 
433 
437  virtual void SetShowSelectedNodes(vtkTypeBool);
438  vtkGetMacro(ShowSelectedNodes, vtkTypeBool);
439  vtkBooleanMacro(ShowSelectedNodes, vtkTypeBool);
441 
445  virtual vtkPolyData* GetContourRepresentationAsPolyData() = 0;
446 
451  void GetNodePolyData(vtkPolyData* poly);
452 
453  vtkSetMacro(RebuildLocator, bool);
454 
455 protected:
457  ~vtkContourRepresentation() override;
458 
459  // Selection tolerance for the handles
462 
465 
467 
470 
471  // A flag to indicate whether to show the Selected nodes
473 
475 
476  void AddNodeAtPositionInternal(double worldPos[3], double worldOrient[9], int displayPos[2]);
477  void AddNodeAtPositionInternal(double worldPos[3], double worldOrient[9], double displayPos[2]);
478  void SetNthNodeWorldPositionInternal(int n, double worldPos[3], double worldOrient[9]);
479 
481 
485  void GetRendererComputedDisplayPositionFromWorldPosition(
486  double worldPos[3], double worldOrient[9], int displayPos[2]);
487  void GetRendererComputedDisplayPositionFromWorldPosition(
488  double worldPos[3], double worldOrient[9], double displayPos[2]);
490 
491  virtual void UpdateLines(int index);
492  void UpdateLine(int idx1, int idx2);
493 
494  virtual int FindClosestPointOnContour(int X, int Y, double worldPos[3], int* idx);
495 
496  virtual void BuildLines() = 0;
497 
498  // This method is called when something changes in the point placer.
499  // It will cause all points to be updated, and all lines to be regenerated.
500  // It should be extended to detect changes in the line interpolator too.
501  virtual int UpdateContour();
503 
504  void ComputeMidpoint(double p1[3], double p2[3], double mid[3])
505  {
506  mid[0] = (p1[0] + p2[0]) / 2;
507  mid[1] = (p1[1] + p2[1]) / 2;
508  mid[2] = (p1[2] + p2[2]) / 2;
509  }
510 
522  virtual void Initialize(vtkPolyData*, vtkIdList*);
523 
528  virtual void Initialize(vtkPolyData*);
529 
534  virtual void InitializeContour(vtkPolyData*, vtkIdList*);
535 
541 
546  void ResetLocator();
547 
548  void BuildLocator();
549 
551 
552 private:
554  void operator=(const vtkContourRepresentation&) = delete;
555 };
556 
557 VTK_ABI_NAMESPACE_END
558 #endif
std::vector< vtkContourRepresentationNode * > Nodes
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instances of this class.
std::vector< vtkContourRepresentationPoint * > Points
void SetCurrentOperationToInactive()
Set / get the current operation.
virtual int ComputeInteractionState(int X, int Y, int modify=0)
#define VTK_DOUBLE_MAX
Definition: vtkType.h:154
abstract specification for Viewports
Definition: vtkViewport.h:44
virtual void StartWidgetInteraction(double eventPos[2])
record modification and/or execution time
Definition: vtkTimeStamp.h:24
void SetCurrentOperationToTranslate()
Set / get the current operation.
int vtkIdType
Definition: vtkType.h:315
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
vtkIncrementalOctreePointLocator * Locator
Adding a point locator to the representation to speed up lookup of the active node when dealing with ...
represent the vtkContourWidget
abstract class defines interface between the widget and widget representation classes ...
virtual void BuildRepresentation()=0
Subclasses of vtkWidgetRepresentation must implement these methods.
void SetCurrentOperationToShift()
Set / get the current operation.
int vtkTypeBool
Definition: vtkABI.h:64
window superclass for vtkRenderWindow
Definition: vtkWindow.h:27
int RenderTranslucentPolygonalGeometry(vtkViewport *vtkNotUsed(viewport)) override
a simple class to control print indentation
Definition: vtkIndent.h:28
void ComputeMidpoint(double p1[3], double p2[3], double mid[3])
list of point or cell ids
Definition: vtkIdList.h:22
void ReleaseGraphicsResources(vtkWindow *) override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE Release any graphics resources that are being...
Abstract interface to translate 2D display positions to world coordinates.
vtkContourRepresentationInternals * Internal
virtual void WidgetInteraction(double newEventPos[2])
int RenderOpaqueGeometry(vtkViewport *vtkNotUsed(viewport)) override
Defines API for interpolating/modifying nodes from a vtkContourRepresentation.
void SetCurrentOperationToScale()
Set / get the current operation.
int RenderOverlay(vtkViewport *vtkNotUsed(viewport)) override
create a contour with a set of points
vtkTypeBool HasTranslucentPolygonalGeometry() override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THESE METHODS OUTSIDE OF THE RENDE...
vtkContourLineInterpolator * LineInterpolator
virtual void Initialize()
Incremental octree in support of both point location and point insertion.