VTK  9.2.6
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 =========================================================================*/
62 #ifndef vtkContourRepresentation_h
63 #define vtkContourRepresentation_h
64 
65 #include "vtkInteractionWidgetsModule.h" // For export macro
67 #include <vector> // STL Header; Required for vector
68 
71 class vtkPointPlacer;
72 class vtkPolyData;
73 class vtkIdList;
74 
75 //----------------------------------------------------------------------
77 {
78 public:
79  double WorldPosition[3];
81 
82  // The point id. This is blank except in the case of
83  // vtkPolygonalSurfaceContourLineInterpolator
85 };
86 
88 {
89 public:
90  double WorldPosition[3];
91  double WorldOrientation[9];
93  int Selected;
94  std::vector<vtkContourRepresentationPoint*> Points;
95 
96  // The point id. This is blank except in the case of
97  // vtkPolygonalSurfaceContourLineInterpolator
99 };
100 
102 {
103 public:
104  std::vector<vtkContourRepresentationNode*> Nodes;
105  void ClearNodes()
106  {
107  for (unsigned int i = 0; i < this->Nodes.size(); i++)
108  {
109  for (unsigned int j = 0; j < this->Nodes[i]->Points.size(); j++)
110  {
111  delete this->Nodes[i]->Points[j];
112  }
113  this->Nodes[i]->Points.clear();
114  delete this->Nodes[i];
115  }
116  this->Nodes.clear();
117  }
118 };
119 
120 class VTKINTERACTIONWIDGETS_EXPORT vtkContourRepresentation : public vtkWidgetRepresentation
121 {
122  friend class vtkContourWidget;
123 
124 public:
126 
130  void PrintSelf(ostream& os, vtkIndent indent) override;
132 
134 
138  virtual int AddNodeAtWorldPosition(double x, double y, double z);
139  virtual int AddNodeAtWorldPosition(double worldPos[3]);
140  virtual int AddNodeAtWorldPosition(double worldPos[3], double worldOrient[9]);
142 
144 
150  virtual int AddNodeAtDisplayPosition(double displayPos[2]);
151  virtual int AddNodeAtDisplayPosition(int displayPos[2]);
152  virtual int AddNodeAtDisplayPosition(int X, int Y);
154 
156 
162  virtual int ActivateNode(double displayPos[2]);
163  virtual int ActivateNode(int displayPos[2]);
164  virtual int ActivateNode(int X, int Y);
166 
167  // Description:
168  // Move the active node to a specified world position.
169  // Will return 0 if there is no active node or the node
170  // could not be moved to that position. 1 will be returned
171  // on success.
172  virtual int SetActiveNodeToWorldPosition(double pos[3]);
173  virtual int SetActiveNodeToWorldPosition(double pos[3], double orient[9]);
174 
176 
183  virtual int SetActiveNodeToDisplayPosition(double pos[2]);
184  virtual int SetActiveNodeToDisplayPosition(int pos[2]);
185  virtual int SetActiveNodeToDisplayPosition(int X, int Y);
187 
189 
192  virtual int ToggleActiveNodeSelected();
193  virtual int GetActiveNodeSelected();
194  virtual int GetNthNodeSelected(int);
195  virtual int SetNthNodeSelected(int);
197 
202  virtual int GetActiveNodeWorldPosition(double pos[3]);
203 
208  virtual int GetActiveNodeWorldOrientation(double orient[9]);
209 
214  virtual int GetActiveNodeDisplayPosition(double pos[2]);
215 
219  virtual int GetNumberOfNodes();
220 
226  virtual int GetNthNodeDisplayPosition(int n, double pos[2]);
227 
233  virtual int GetNthNodeWorldPosition(int n, double pos[3]);
234 
238  virtual vtkContourRepresentationNode* GetNthNode(int n);
239 
245  virtual int GetNthNodeWorldOrientation(int n, double orient[9]);
246 
248 
256  virtual int SetNthNodeDisplayPosition(int n, int X, int Y);
257  virtual int SetNthNodeDisplayPosition(int n, int pos[2]);
258  virtual int SetNthNodeDisplayPosition(int n, double pos[2]);
260 
262 
269  virtual int SetNthNodeWorldPosition(int n, double pos[3]);
270  virtual int SetNthNodeWorldPosition(int n, double pos[3], double orient[9]);
272 
278  virtual int GetNthNodeSlope(int idx, double slope[3]);
279 
280  // Description:
281  // For a given node n, get the number of intermediate
282  // points between this node and the node at
283  // (n+1). If n is the last node and the loop is
284  // closed, this is the number of intermediate points
285  // between node n and node 0. 0 is returned if n is
286  // out of range.
287  virtual int GetNumberOfIntermediatePoints(int n);
288 
295  virtual int GetIntermediatePointWorldPosition(int n, int idx, double point[3]);
296 
302  virtual int AddIntermediatePointWorldPosition(int n, double point[3]);
303 
310  virtual int AddIntermediatePointWorldPosition(int n, double point[3], vtkIdType ptId);
311 
316  virtual int DeleteLastNode();
317 
322  virtual int DeleteActiveNode();
323 
328  virtual int DeleteNthNode(int n);
329 
333  virtual void ClearAllNodes();
334 
339  virtual int AddNodeOnContour(int X, int Y);
340 
342 
346  vtkSetClampMacro(PixelTolerance, int, 1, 100);
347  vtkGetMacro(PixelTolerance, int);
349 
351 
355  vtkSetClampMacro(WorldTolerance, double, 0.0, VTK_DOUBLE_MAX);
356  vtkGetMacro(WorldTolerance, double);
358 
359  // Used to communicate about the state of the representation
360  enum
361  {
362  Outside = 0,
363  Nearby
364  };
365 
366  enum
367  {
368  Inactive = 0,
371  Scale
372  };
373 
375 
379  vtkGetMacro(CurrentOperation, int);
380  vtkSetClampMacro(
383  {
384  this->SetCurrentOperation(vtkContourRepresentation::Inactive);
385  }
387  {
388  this->SetCurrentOperation(vtkContourRepresentation::Translate);
389  }
390  void SetCurrentOperationToShift() { this->SetCurrentOperation(vtkContourRepresentation::Shift); }
391  void SetCurrentOperationToScale() { this->SetCurrentOperation(vtkContourRepresentation::Scale); }
393 
394  // Description:
395  // Set / get the Point Placer. The point placer is
396  // responsible for converting display coordinates into
397  // world coordinates according to some constraints, and
398  // for validating world positions.
399  void SetPointPlacer(vtkPointPlacer*);
400  vtkGetObjectMacro(PointPlacer, vtkPointPlacer);
401 
403 
408  void SetLineInterpolator(vtkContourLineInterpolator*);
409  vtkGetObjectMacro(LineInterpolator, vtkContourLineInterpolator);
411 
413 
416  void BuildRepresentation() override = 0;
417  int ComputeInteractionState(int X, int Y, int modified = 0) override = 0;
418  void StartWidgetInteraction(double e[2]) override = 0;
419  void WidgetInteraction(double e[2]) override = 0;
421 
423 
426  void ReleaseGraphicsResources(vtkWindow* w) override = 0;
427  int RenderOverlay(vtkViewport* viewport) override = 0;
428  int RenderOpaqueGeometry(vtkViewport* viewport) override = 0;
429  int RenderTranslucentPolygonalGeometry(vtkViewport* viewport) override = 0;
432 
434 
438  void SetClosedLoop(vtkTypeBool val);
439  vtkGetMacro(ClosedLoop, vtkTypeBool);
440  vtkBooleanMacro(ClosedLoop, vtkTypeBool);
442 
444 
448  virtual void SetShowSelectedNodes(vtkTypeBool);
449  vtkGetMacro(ShowSelectedNodes, vtkTypeBool);
450  vtkBooleanMacro(ShowSelectedNodes, vtkTypeBool);
452 
456  virtual vtkPolyData* GetContourRepresentationAsPolyData() = 0;
457 
462  void GetNodePolyData(vtkPolyData* poly);
463 
464  vtkSetMacro(RebuildLocator, bool);
465 
466 protected:
468  ~vtkContourRepresentation() override;
469 
470  // Selection tolerance for the handles
473 
476 
478 
481 
482  // A flag to indicate whether to show the Selected nodes
484 
486 
487  void AddNodeAtPositionInternal(double worldPos[3], double worldOrient[9], int displayPos[2]);
488  void AddNodeAtPositionInternal(double worldPos[3], double worldOrient[9], double displayPos[2]);
489  void SetNthNodeWorldPositionInternal(int n, double worldPos[3], double worldOrient[9]);
490 
492 
496  void GetRendererComputedDisplayPositionFromWorldPosition(
497  double worldPos[3], double worldOrient[9], int displayPos[2]);
498  void GetRendererComputedDisplayPositionFromWorldPosition(
499  double worldPos[3], double worldOrient[9], double displayPos[2]);
501 
502  virtual void UpdateLines(int index);
503  void UpdateLine(int idx1, int idx2);
504 
505  virtual int FindClosestPointOnContour(int X, int Y, double worldPos[3], int* idx);
506 
507  virtual void BuildLines() = 0;
508 
509  // This method is called when something changes in the point placer.
510  // It will cause all points to be updated, and all lines to be regenerated.
511  // It should be extended to detect changes in the line interpolator too.
512  virtual int UpdateContour();
514 
515  void ComputeMidpoint(double p1[3], double p2[3], double mid[3])
516  {
517  mid[0] = (p1[0] + p2[0]) / 2;
518  mid[1] = (p1[1] + p2[1]) / 2;
519  mid[2] = (p1[2] + p2[2]) / 2;
520  }
521 
533  virtual void Initialize(vtkPolyData*, vtkIdList*);
534 
539  virtual void Initialize(vtkPolyData*);
540 
545  virtual void InitializeContour(vtkPolyData*, vtkIdList*);
546 
552 
557  void ResetLocator();
558 
559  void BuildLocator();
560 
562 
563 private:
565  void operator=(const vtkContourRepresentation&) = delete;
566 };
567 
568 #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:165
abstract specification for Viewports
Definition: vtkViewport.h:55
virtual void StartWidgetInteraction(double eventPos[2])
record modification and/or execution time
Definition: vtkTimeStamp.h:35
void SetCurrentOperationToTranslate()
Set / get the current operation.
int vtkIdType
Definition: vtkType.h:332
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:90
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:69
window superclass for vtkRenderWindow
Definition: vtkWindow.h:38
int RenderTranslucentPolygonalGeometry(vtkViewport *vtkNotUsed(viewport)) override
a simple class to control print indentation
Definition: vtkIndent.h:39
void ComputeMidpoint(double p1[3], double p2[3], double mid[3])
list of point or cell ids
Definition: vtkIdList.h:33
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.