VTK  9.0.3
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 =========================================================================*/
59 #ifndef vtkContourRepresentation_h
60 #define vtkContourRepresentation_h
61 
62 #include "vtkInteractionWidgetsModule.h" // For export macro
64 #include <vector> // STL Header; Required for vector
65 
68 class vtkPointPlacer;
69 class vtkPolyData;
70 class vtkIdList;
71 
72 //----------------------------------------------------------------------
74 {
75 public:
76  double WorldPosition[3];
78 
79  // The point id. This is blank except in the case of
80  // vtkPolygonalSurfaceContourLineInterpolator
82 };
83 
85 {
86 public:
87  double WorldPosition[3];
88  double WorldOrientation[9];
90  int Selected;
91  std::vector<vtkContourRepresentationPoint*> Points;
92 
93  // The point id. This is blank except in the case of
94  // vtkPolygonalSurfaceContourLineInterpolator
96 };
97 
99 {
100 public:
101  std::vector<vtkContourRepresentationNode*> Nodes;
102  void ClearNodes()
103  {
104  for (unsigned int i = 0; i < this->Nodes.size(); i++)
105  {
106  for (unsigned int j = 0; j < this->Nodes[i]->Points.size(); j++)
107  {
108  delete this->Nodes[i]->Points[j];
109  }
110  this->Nodes[i]->Points.clear();
111  delete this->Nodes[i];
112  }
113  this->Nodes.clear();
114  }
115 };
116 
117 class VTKINTERACTIONWIDGETS_EXPORT vtkContourRepresentation : public vtkWidgetRepresentation
118 {
119  friend class vtkContourWidget;
120 
121 public:
123 
127  void PrintSelf(ostream& os, vtkIndent indent) override;
129 
131 
135  virtual int AddNodeAtWorldPosition(double x, double y, double z);
136  virtual int AddNodeAtWorldPosition(double worldPos[3]);
137  virtual int AddNodeAtWorldPosition(double worldPos[3], double worldOrient[9]);
139 
141 
147  virtual int AddNodeAtDisplayPosition(double displayPos[2]);
148  virtual int AddNodeAtDisplayPosition(int displayPos[2]);
149  virtual int AddNodeAtDisplayPosition(int X, int Y);
151 
153 
159  virtual int ActivateNode(double displayPos[2]);
160  virtual int ActivateNode(int displayPos[2]);
161  virtual int ActivateNode(int X, int Y);
163 
164  // Description:
165  // Move the active node to a specified world position.
166  // Will return 0 if there is no active node or the node
167  // could not be moved to that position. 1 will be returned
168  // on success.
169  virtual int SetActiveNodeToWorldPosition(double pos[3]);
170  virtual int SetActiveNodeToWorldPosition(double pos[3], double orient[9]);
171 
173 
180  virtual int SetActiveNodeToDisplayPosition(double pos[2]);
181  virtual int SetActiveNodeToDisplayPosition(int pos[2]);
182  virtual int SetActiveNodeToDisplayPosition(int X, int Y);
184 
186 
190  virtual int GetActiveNodeSelected();
191  virtual int GetNthNodeSelected(int);
192  virtual int SetNthNodeSelected(int);
194 
199  virtual int GetActiveNodeWorldPosition(double pos[3]);
200 
205  virtual int GetActiveNodeWorldOrientation(double orient[9]);
206 
211  virtual int GetActiveNodeDisplayPosition(double pos[2]);
212 
216  virtual int GetNumberOfNodes();
217 
223  virtual int GetNthNodeDisplayPosition(int n, double pos[2]);
224 
230  virtual int GetNthNodeWorldPosition(int n, double pos[3]);
231 
236 
242  virtual int GetNthNodeWorldOrientation(int n, double orient[9]);
243 
245 
253  virtual int SetNthNodeDisplayPosition(int n, int X, int Y);
254  virtual int SetNthNodeDisplayPosition(int n, int pos[2]);
255  virtual int SetNthNodeDisplayPosition(int n, double pos[2]);
257 
259 
266  virtual int SetNthNodeWorldPosition(int n, double pos[3]);
267  virtual int SetNthNodeWorldPosition(int n, double pos[3], double orient[9]);
269 
275  virtual int GetNthNodeSlope(int idx, double slope[3]);
276 
277  // Description:
278  // For a given node n, get the number of intermediate
279  // points between this node and the node at
280  // (n+1). If n is the last node and the loop is
281  // closed, this is the number of intermediate points
282  // between node n and node 0. 0 is returned if n is
283  // out of range.
284  virtual int GetNumberOfIntermediatePoints(int n);
285 
292  virtual int GetIntermediatePointWorldPosition(int n, int idx, double point[3]);
293 
299  virtual int AddIntermediatePointWorldPosition(int n, double point[3]);
300 
307  virtual int AddIntermediatePointWorldPosition(int n, double point[3], vtkIdType ptId);
308 
313  virtual int DeleteLastNode();
314 
319  virtual int DeleteActiveNode();
320 
325  virtual int DeleteNthNode(int n);
326 
330  virtual void ClearAllNodes();
331 
336  virtual int AddNodeOnContour(int X, int Y);
337 
339 
343  vtkSetClampMacro(PixelTolerance, int, 1, 100);
344  vtkGetMacro(PixelTolerance, int);
346 
348 
352  vtkSetClampMacro(WorldTolerance, double, 0.0, VTK_DOUBLE_MAX);
353  vtkGetMacro(WorldTolerance, double);
355 
356  // Used to communicate about the state of the representation
357  enum
358  {
359  Outside = 0,
360  Nearby
361  };
362 
363  enum
364  {
365  Inactive = 0,
368  Scale
369  };
370 
372 
376  vtkGetMacro(CurrentOperation, int);
377  vtkSetClampMacro(
380  {
381  this->SetCurrentOperation(vtkContourRepresentation::Inactive);
382  }
384  {
385  this->SetCurrentOperation(vtkContourRepresentation::Translate);
386  }
387  void SetCurrentOperationToShift() { this->SetCurrentOperation(vtkContourRepresentation::Shift); }
388  void SetCurrentOperationToScale() { this->SetCurrentOperation(vtkContourRepresentation::Scale); }
390 
391  // Description:
392  // Set / get the Point Placer. The point placer is
393  // responsible for converting display coordinates into
394  // world coordinates according to some constraints, and
395  // for validating world positions.
397  vtkGetObjectMacro(PointPlacer, vtkPointPlacer);
398 
400 
406  vtkGetObjectMacro(LineInterpolator, vtkContourLineInterpolator);
408 
410 
413  void BuildRepresentation() override = 0;
414  int ComputeInteractionState(int X, int Y, int modified = 0) override = 0;
415  void StartWidgetInteraction(double e[2]) override = 0;
416  void WidgetInteraction(double e[2]) override = 0;
418 
420 
423  void ReleaseGraphicsResources(vtkWindow* w) override = 0;
424  int RenderOverlay(vtkViewport* viewport) override = 0;
425  int RenderOpaqueGeometry(vtkViewport* viewport) override = 0;
426  int RenderTranslucentPolygonalGeometry(vtkViewport* viewport) override = 0;
429 
431 
436  vtkGetMacro(ClosedLoop, vtkTypeBool);
437  vtkBooleanMacro(ClosedLoop, vtkTypeBool);
439 
441 
446  vtkGetMacro(ShowSelectedNodes, vtkTypeBool);
447  vtkBooleanMacro(ShowSelectedNodes, vtkTypeBool);
449 
454 
460 
461  vtkSetMacro(RebuildLocator, bool);
462 
463 protected:
466 
467  // Selection tolerance for the handles
470 
473 
475 
478 
479  // A flag to indicate whether to show the Selected nodes
481 
483 
484  void AddNodeAtPositionInternal(double worldPos[3], double worldOrient[9], int displayPos[2]);
485  void AddNodeAtPositionInternal(double worldPos[3], double worldOrient[9], double displayPos[2]);
486  void SetNthNodeWorldPositionInternal(int n, double worldPos[3], double worldOrient[9]);
487 
489 
494  double worldPos[3], double worldOrient[9], int displayPos[2]);
496  double worldPos[3], double worldOrient[9], double displayPos[2]);
498 
499  virtual void UpdateLines(int index);
500  void UpdateLine(int idx1, int idx2);
501 
502  virtual int FindClosestPointOnContour(int X, int Y, double worldPos[3], int* idx);
503 
504  virtual void BuildLines() = 0;
505 
506  // This method is called when something changes in the point placer.
507  // It will cause all points to be updated, and all lines to be regenerated.
508  // It should be extended to detect changes in the line interpolator too.
509  virtual int UpdateContour();
511 
512  void ComputeMidpoint(double p1[3], double p2[3], double mid[3])
513  {
514  mid[0] = (p1[0] + p2[0]) / 2;
515  mid[1] = (p1[1] + p2[1]) / 2;
516  mid[2] = (p1[2] + p2[2]) / 2;
517  }
518 
530  virtual void Initialize(vtkPolyData*, vtkIdList*);
531 
536  virtual void Initialize(vtkPolyData*);
537 
543 
549 
554  void ResetLocator();
555 
556  void BuildLocator();
557 
559 
560 private:
562  void operator=(const vtkContourRepresentation&) = delete;
563 };
564 
565 #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)
void StartWidgetInteraction(double e[2]) override=0
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
Methods invoked by print to print information about the object including superclasses.
void AddNodeAtPositionInternal(double worldPos[3], double worldOrient[9], double displayPos[2])
void WidgetInteraction(double e[2]) override=0
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])
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)
vtkIncrementalOctreePointLocator * Locator
Adding a point locator to the representation to speed up lookup of the active node when dealing with ...
virtual int GetActiveNodeSelected()
void SetNthNodeWorldPositionInternal(int n, double worldPos[3], double worldOrient[9])
virtual vtkContourRepresentationNode * GetNthNode(int n)
Get the nth node.
virtual int SetActiveNodeToWorldPosition(double pos[3])
virtual int SetActiveNodeToDisplayPosition(int X, int Y)
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.
virtual vtkPolyData * GetContourRepresentationAsPolyData()=0
Get the points in this contour as a vtkPolyData.
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)
int RenderOverlay(vtkViewport *viewport) override=0
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
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THESE METHODS OUTSIDE OF THE RENDE...
int ComputeInteractionState(int X, int Y, int modified=0) override=0
virtual int AddNodeAtWorldPosition(double worldPos[3])
void AddNodeAtPositionInternal(double worldPos[3], double worldOrient[9], int displayPos[2])
int RenderTranslucentPolygonalGeometry(vtkViewport *viewport) override=0
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])
virtual int GetNthNodeWorldOrientation(int n, double orient[9])
Get the nth node's world orientation.
virtual int ActivateNode(int displayPos[2])
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.
void GetRendererComputedDisplayPositionFromWorldPosition(double worldPos[3], double worldOrient[9], double displayPos[2])
virtual int ActivateNode(int X, int Y)
int RenderOpaqueGeometry(vtkViewport *viewport) override=0
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THESE METHODS OUTSIDE OF THE RENDE...
virtual int SetNthNodeDisplayPosition(int n, double pos[2])
virtual int GetNumberOfNodes()
Get the number of nodes.
virtual int SetActiveNodeToDisplayPosition(int pos[2])
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])
virtual void Initialize(vtkPolyData *, vtkIdList *)
Build a contour representation from externally supplied PolyData.
virtual int GetNthNodeSelected(int)
vtkContourLineInterpolator * LineInterpolator
virtual int SetActiveNodeToWorldPosition(double pos[3], double orient[9])
virtual int AddNodeAtWorldPosition(double worldPos[3], double worldOrient[9])
create a contour with a set of points
list of point or cell ids
Definition: vtkIdList.h:31
Incremental octree in support of both point location and point insertion.
a simple class to control print indentation
Definition: vtkIndent.h:34
Abstract interface to translate 2D display positions to world coordinates.
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:85
record modification and/or execution time
Definition: vtkTimeStamp.h:33
abstract specification for Viewports
Definition: vtkViewport.h:45
abstract class defines interface between the widget and widget representation classes
window superclass for vtkRenderWindow
Definition: vtkWindow.h:38
@ point
Definition: vtkX3D.h:242
@ index
Definition: vtkX3D.h:252
int vtkTypeBool
Definition: vtkABI.h:69
int vtkIdType
Definition: vtkType.h:338
#define VTK_DOUBLE_MAX
Definition: vtkType.h:165