VTK  9.7.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 "vtkWrappingHints.h" // For VTK_MARSHALAUTO
56 #include <vector> // STL Header; Required for vector
57 
58 VTK_ABI_NAMESPACE_BEGIN
61 class vtkPointPlacer;
62 class vtkPolyData;
63 class vtkIdList;
64 
65 //----------------------------------------------------------------------
67 {
68 public:
69  double WorldPosition[3];
71 
72  // The point id. This is blank except in the case of
73  // vtkPolygonalSurfaceContourLineInterpolator
75 };
76 
78 {
79 public:
80  double WorldPosition[3];
81  double WorldOrientation[9];
83  int Selected;
84  std::vector<vtkContourRepresentationPoint*> Points;
85 
86  // The point id. This is blank except in the case of
87  // vtkPolygonalSurfaceContourLineInterpolator
89 };
90 
92 {
93 public:
94  std::vector<vtkContourRepresentationNode*> Nodes;
95  void ClearNodes()
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 
110 class VTKINTERACTIONWIDGETS_EXPORT VTK_MARSHALAUTO vtkContourRepresentation
111  : public vtkWidgetRepresentation
112 {
113  friend class vtkContourWidget;
114 
115 public:
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 
183  virtual int ToggleActiveNodeSelected();
184  virtual int GetActiveNodeSelected();
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 
229  virtual vtkContourRepresentationNode* GetNthNode(int n);
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.
278  virtual int GetNumberOfIntermediatePoints(int n);
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  {
353  Outside = 0,
354  Nearby
355  };
356 
357  enum
358  {
359  Inactive = 0,
362  Scale
363  };
364 
366 
370  vtkGetMacro(CurrentOperation, int);
371  vtkSetClampMacro(
374  {
375  this->SetCurrentOperation(vtkContourRepresentation::Inactive);
376  }
378  {
379  this->SetCurrentOperation(vtkContourRepresentation::Translate);
380  }
381  void SetCurrentOperationToShift() { this->SetCurrentOperation(vtkContourRepresentation::Shift); }
382  void SetCurrentOperationToScale() { this->SetCurrentOperation(vtkContourRepresentation::Scale); }
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.
390  void SetPointPlacer(vtkPointPlacer*);
391  vtkGetObjectMacro(PointPlacer, vtkPointPlacer);
392 
394 
399  void SetLineInterpolator(vtkContourLineInterpolator*);
400  vtkGetObjectMacro(LineInterpolator, vtkContourLineInterpolator);
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;
420  int RenderTranslucentPolygonalGeometry(vtkViewport* viewport) override = 0;
423 
425 
429  void SetClosedLoop(vtkTypeBool val);
430  vtkGetMacro(ClosedLoop, vtkTypeBool);
431  vtkBooleanMacro(ClosedLoop, vtkTypeBool);
433 
435 
439  virtual void SetShowSelectedNodes(vtkTypeBool);
440  vtkGetMacro(ShowSelectedNodes, vtkTypeBool);
441  vtkBooleanMacro(ShowSelectedNodes, vtkTypeBool);
443 
447  virtual vtkPolyData* GetContourRepresentationAsPolyData() = 0;
448 
453  void GetNodePolyData(vtkPolyData* poly);
454 
455  vtkSetMacro(RebuildLocator, bool);
456 
457 protected:
459  ~vtkContourRepresentation() override;
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 
487  void GetRendererComputedDisplayPositionFromWorldPosition(
488  double worldPos[3], double worldOrient[9], int displayPos[2]);
489  void GetRendererComputedDisplayPositionFromWorldPosition(
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 
524  virtual void Initialize(vtkPolyData*, vtkIdList*);
525 
530  virtual void Initialize(vtkPolyData*);
531 
536  virtual void InitializeContour(vtkPolyData*, vtkIdList*);
537 
543 
548  void ResetLocator();
549 
550  void BuildLocator();
551 
553 
554 private:
556  void operator=(const vtkContourRepresentation&) = delete;
557 };
558 
559 VTK_ABI_NAMESPACE_END
560 #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:202
abstract specification for Viewports
Definition: vtkViewport.h:46
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:363
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:71
int RenderOpaqueGeometry(vtkViewport *viewport) override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THESE METHODS OUTSIDE OF THE RENDE...
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.
int RenderTranslucentPolygonalGeometry(vtkViewport *viewport) override
void SetCurrentOperationToShift()
Set / get the current operation.
int vtkTypeBool
Definition: vtkABI.h:64
window superclass for vtkRenderWindow
Definition: vtkWindow.h:41
a simple class to control print indentation
Definition: vtkIndent.h:28
void ComputeMidpoint(double p1[3], double p2[3], double mid[3])
int RenderOverlay(vtkViewport *viewport) override
list of point or cell ids
Definition: vtkIdList.h:25
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])
Defines API for interpolating/modifying nodes from a vtkContourRepresentation.
void SetCurrentOperationToScale()
Set / get the current operation.
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
#define VTK_MARSHALAUTO
virtual void Initialize()
Incremental octree in support of both point location and point insertion.