VTK
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 public:
122 
126  void PrintSelf(ostream& os, vtkIndent indent) override;
128 
130 
134  virtual int AddNodeAtWorldPosition( double x, double y, double z);
135  virtual int AddNodeAtWorldPosition( double worldPos[3] );
136  virtual int AddNodeAtWorldPosition( double worldPos[3],
137  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],
171  double orient[9] );
172 
174 
181  virtual int SetActiveNodeToDisplayPosition( double pos[2] );
182  virtual int SetActiveNodeToDisplayPosition( int pos[2] );
183  virtual int SetActiveNodeToDisplayPosition( int X, int Y );
185 
187 
190  virtual int ToggleActiveNodeSelected();
191  virtual int GetActiveNodeSelected();
192  virtual int GetNthNodeSelected(int);
193  virtual int SetNthNodeSelected(int);
195 
200  virtual int GetActiveNodeWorldPosition( double pos[3] );
201 
206  virtual int GetActiveNodeWorldOrientation( double orient[9] );
207 
212  virtual int GetActiveNodeDisplayPosition( double pos[2] );
213 
217  virtual int GetNumberOfNodes();
218 
224  virtual int GetNthNodeDisplayPosition( int n, double pos[2] );
225 
231  virtual int GetNthNodeWorldPosition( int n, double pos[3] );
232 
236  virtual vtkContourRepresentationNode *GetNthNode(int n);
237 
243  virtual int GetNthNodeWorldOrientation( int n, double orient[9] );
244 
246 
254  virtual int SetNthNodeDisplayPosition( int n, int X, int Y );
255  virtual int SetNthNodeDisplayPosition( int n, int pos[2] );
256  virtual int SetNthNodeDisplayPosition( int n, double pos[2] );
258 
260 
267  virtual int SetNthNodeWorldPosition( int n, double pos[3] );
268  virtual int SetNthNodeWorldPosition( int n, double pos[3],
269  double orient[9] );
271 
277  virtual int GetNthNodeSlope( int idx, double slope[3] );
278 
279  // Description:
280  // For a given node n, get the number of intermediate
281  // points between this node and the node at
282  // (n+1). If n is the last node and the loop is
283  // closed, this is the number of intermediate points
284  // between node n and node 0. 0 is returned if n is
285  // out of range.
286  virtual int GetNumberOfIntermediatePoints( int n );
287 
294  virtual int GetIntermediatePointWorldPosition( int n,
295  int idx, double point[3] );
296 
302  virtual int AddIntermediatePointWorldPosition( int n,
303  double point[3] );
304 
311  virtual int AddIntermediatePointWorldPosition( int n,
312  double point[3], vtkIdType ptId );
313 
318  virtual int DeleteLastNode();
319 
324  virtual int DeleteActiveNode();
325 
330  virtual int DeleteNthNode( int n );
331 
335  virtual void ClearAllNodes();
336 
341  virtual int AddNodeOnContour( int X, int Y );
342 
344 
348  vtkSetClampMacro(PixelTolerance,int,1,100);
349  vtkGetMacro(PixelTolerance,int);
351 
353 
357  vtkSetClampMacro(WorldTolerance, double, 0.0, VTK_DOUBLE_MAX);
358  vtkGetMacro(WorldTolerance, double);
360 
361  // Used to communicate about the state of the representation
362  enum {
363  Outside=0,
364  Nearby
365  };
366 
367  enum {
368  Inactive = 0,
371  Scale
372  };
373 
375 
379  vtkGetMacro( CurrentOperation, int );
380  vtkSetClampMacro( CurrentOperation, int,
384  { this->SetCurrentOperation( vtkContourRepresentation::Inactive ); }
386  { this->SetCurrentOperation( vtkContourRepresentation::Translate ); }
388  {this->SetCurrentOperation( vtkContourRepresentation::Shift ); }
390  {this->SetCurrentOperation( vtkContourRepresentation::Scale ); }
392 
393  // Description:
394  // Set / get the Point Placer. The point placer is
395  // responsible for converting display coordinates into
396  // world coordinates according to some constraints, and
397  // for validating world positions.
398  void SetPointPlacer( vtkPointPlacer * );
399  vtkGetObjectMacro( PointPlacer, vtkPointPlacer );
400 
402 
407  void SetLineInterpolator( vtkContourLineInterpolator *);
408  vtkGetObjectMacro( LineInterpolator, vtkContourLineInterpolator );
410 
412 
415  void BuildRepresentation() override =0;
416  int ComputeInteractionState(int X, int Y, int modified=0) override =0;
417  void StartWidgetInteraction(double e[2]) override =0;
418  void WidgetInteraction(double e[2]) override =0;
420 
422 
425  void ReleaseGraphicsResources(vtkWindow *w) override =0;
426  int RenderOverlay(vtkViewport *viewport) override =0;
427  int RenderOpaqueGeometry(vtkViewport *viewport) override =0;
428  int RenderTranslucentPolygonalGeometry(vtkViewport *viewport) override =0;
429  int HasTranslucentPolygonalGeometry() override =0;
431 
433 
437  void SetClosedLoop( vtkTypeBool val );
438  vtkGetMacro( ClosedLoop, vtkTypeBool );
439  vtkBooleanMacro( ClosedLoop, vtkTypeBool );
441 
443 
447  virtual void SetShowSelectedNodes(vtkTypeBool);
448  vtkGetMacro( ShowSelectedNodes, vtkTypeBool );
449  vtkBooleanMacro( ShowSelectedNodes, vtkTypeBool );
451 
455  virtual vtkPolyData* GetContourRepresentationAsPolyData() = 0;
456 
461  void GetNodePolyData( vtkPolyData* poly );
462 
463  vtkSetMacro(RebuildLocator,bool);
464 
465 protected:
467  ~vtkContourRepresentation() override;
468 
469  // Selection tolerance for the handles
472 
475 
477 
480 
481  // A flag to indicate whether to show the Selected nodes
483 
485 
486  void AddNodeAtPositionInternal( double worldPos[3],
487  double worldOrient[9], int displayPos[2] );
488  void AddNodeAtPositionInternal( double worldPos[3],
489  double worldOrient[9], double displayPos[2] );
490  void SetNthNodeWorldPositionInternal( int n, double worldPos[3],
491  double worldOrient[9] );
492 
494 
498  void GetRendererComputedDisplayPositionFromWorldPosition( double worldPos[3],
499  double worldOrient[9], int displayPos[2] );
500  void GetRendererComputedDisplayPositionFromWorldPosition( double worldPos[3],
501  double worldOrient[9], double displayPos[2] );
503 
504  virtual void UpdateLines( int index );
505  void UpdateLine( int idx1, int idx2 );
506 
507  virtual int FindClosestPointOnContour( int X, int Y,
508  double worldPos[3],
509  int *idx );
510 
511  virtual void BuildLines()=0;
512 
513  // This method is called when something changes in the point placer.
514  // It will cause all points to be updated, and all lines to be regenerated.
515  // It should be extended to detect changes in the line interpolator too.
516  virtual int UpdateContour();
518 
519  void ComputeMidpoint( double p1[3], double p2[3], double mid[3] )
520  {
521  mid[0] = (p1[0] + p2[0])/2;
522  mid[1] = (p1[1] + p2[1])/2;
523  mid[2] = (p1[2] + p2[2])/2;
524  }
525 
537  virtual void Initialize( vtkPolyData *, vtkIdList *);
538 
543  virtual void Initialize( vtkPolyData *);
544 
549  virtual void InitializeContour( vtkPolyData *, vtkIdList * );
550 
556 
561  void ResetLocator();
562 
563  void BuildLocator();
564 
566 
567 
568 private:
570  void operator=(const vtkContourRepresentation&) = delete;
571 };
572 
573 #endif
574 
vtkContourRepresentation::SetCurrentOperationToInactive
void SetCurrentOperationToInactive()
Definition: vtkContourRepresentation.h:383
vtkWidgetRepresentation::StartWidgetInteraction
virtual void StartWidgetInteraction(double eventPos[2])
Definition: vtkWidgetRepresentation.h:136
vtkWidgetRepresentation.h
vtkContourRepresentation::ClosedLoop
vtkTypeBool ClosedLoop
Definition: vtkContourRepresentation.h:479
vtkContourRepresentationNode::NormalizedDisplayPosition
double NormalizedDisplayPosition[2]
Definition: vtkContourRepresentation.h:89
vtkPointPlacer
Abstract interface to translate 2D display positions to world coordinates.
Definition: vtkPointPlacer.h:49
vtkIdType
int vtkIdType
Definition: vtkType.h:347
vtkContourRepresentationInternals::ClearNodes
void ClearNodes()
Definition: vtkContourRepresentation.h:102
vtkContourLineInterpolator
Defines API for interpolating/modifying nodes from a vtkContourRepresentation.
Definition: vtkContourLineInterpolator.h:42
vtkContourRepresentationInternals
Definition: vtkContourRepresentation.h:98
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:32
vtkContourRepresentationNode::WorldPosition
double WorldPosition[3]
Definition: vtkContourRepresentation.h:87
vtkContourRepresentation
represent the vtkContourWidget
Definition: vtkContourRepresentation.h:117
vtkWidgetRepresentation
abstract class defines interface between the widget and widget representation classes
Definition: vtkWidgetRepresentation.h:60
vtkContourWidget
create a contour with a set of points
Definition: vtkContourWidget.h:133
vtkContourRepresentation::SetCurrentOperationToShift
void SetCurrentOperationToShift()
Definition: vtkContourRepresentation.h:387
vtkContourRepresentation::ComputeMidpoint
void ComputeMidpoint(double p1[3], double p2[3], double mid[3])
Definition: vtkContourRepresentation.h:519
vtkWidgetRepresentation::BuildRepresentation
virtual void BuildRepresentation()=0
vtkContourRepresentation::ContourBuildTime
vtkTimeStamp ContourBuildTime
Definition: vtkContourRepresentation.h:517
vtkContourWidget::Initialize
virtual void Initialize()
Definition: vtkContourWidget.h:242
vtkWindow
window superclass for vtkRenderWindow
Definition: vtkWindow.h:34
vtkContourRepresentationInternals::Nodes
std::vector< vtkContourRepresentationNode * > Nodes
Definition: vtkContourRepresentation.h:101
vtkWidgetRepresentation::RenderTranslucentPolygonalGeometry
int RenderTranslucentPolygonalGeometry(vtkViewport *vtkNotUsed(viewport)) override
Definition: vtkWidgetRepresentation.h:223
vtkWidgetRepresentation::ReleaseGraphicsResources
void ReleaseGraphicsResources(vtkWindow *) override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE Release any graphics resources that are being...
Definition: vtkWidgetRepresentation.h:220
vtkContourRepresentationNode::PointId
vtkIdType PointId
Definition: vtkContourRepresentation.h:95
vtkX3D::point
Definition: vtkX3D.h:236
vtkWidgetRepresentation::WidgetInteraction
virtual void WidgetInteraction(double newEventPos[2])
Definition: vtkWidgetRepresentation.h:137
vtkContourRepresentationNode::Points
std::vector< vtkContourRepresentationPoint * > Points
Definition: vtkContourRepresentation.h:91
vtkWidgetRepresentation::HasTranslucentPolygonalGeometry
int HasTranslucentPolygonalGeometry() override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THESE METHODS OUTSIDE OF THE RENDE...
Definition: vtkWidgetRepresentation.h:225
vtkIncrementalOctreePointLocator
Incremental octree in support of both point location and point insertion.
Definition: vtkIncrementalOctreePointLocator.h:60
vtkContourRepresentation::SetCurrentOperationToTranslate
void SetCurrentOperationToTranslate()
Definition: vtkContourRepresentation.h:385
vtkContourRepresentation::Shift
Definition: vtkContourRepresentation.h:370
vtkContourRepresentation::Locator
vtkIncrementalOctreePointLocator * Locator
Adding a point locator to the representation to speed up lookup of the active node when dealing with ...
Definition: vtkContourRepresentation.h:555
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkContourRepresentation::PixelTolerance
int PixelTolerance
Definition: vtkContourRepresentation.h:470
vtkContourRepresentation::PointPlacer
vtkPointPlacer * PointPlacer
Definition: vtkContourRepresentation.h:473
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:30
vtkContourRepresentationNode::Selected
int Selected
Definition: vtkContourRepresentation.h:90
vtkContourRepresentation::CurrentOperation
int CurrentOperation
Definition: vtkContourRepresentation.h:478
vtkViewport
abstract specification for Viewports
Definition: vtkViewport.h:44
vtkContourRepresentation::RebuildLocator
bool RebuildLocator
Definition: vtkContourRepresentation.h:565
vtkContourRepresentationNode::WorldOrientation
double WorldOrientation[9]
Definition: vtkContourRepresentation.h:88
vtkContourRepresentation::Internal
vtkContourRepresentationInternals * Internal
Definition: vtkContourRepresentation.h:484
vtkContourRepresentation::ShowSelectedNodes
vtkTypeBool ShowSelectedNodes
Definition: vtkContourRepresentation.h:482
vtkContourRepresentationPoint::PointId
vtkIdType PointId
Definition: vtkContourRepresentation.h:81
vtkContourRepresentation::WorldTolerance
double WorldTolerance
Definition: vtkContourRepresentation.h:471
vtkWidgetRepresentation::RenderOverlay
int RenderOverlay(vtkViewport *vtkNotUsed(viewport)) override
Definition: vtkWidgetRepresentation.h:221
vtkWidgetRepresentation::RenderOpaqueGeometry
int RenderOpaqueGeometry(vtkViewport *vtkNotUsed(viewport)) override
Definition: vtkWidgetRepresentation.h:222
vtkContourRepresentation::Scale
Definition: vtkContourRepresentation.h:371
vtkPolyData
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
vtkContourRepresentation::ActiveNode
int ActiveNode
Definition: vtkContourRepresentation.h:476
vtkContourRepresentationNode
Definition: vtkContourRepresentation.h:84
vtkContourRepresentation::Translate
Definition: vtkContourRepresentation.h:369
vtkContourRepresentation::LineInterpolator
vtkContourLineInterpolator * LineInterpolator
Definition: vtkContourRepresentation.h:474
vtkContourRepresentation::SetCurrentOperationToScale
void SetCurrentOperationToScale()
Definition: vtkContourRepresentation.h:389
vtkContourRepresentation::Inactive
Definition: vtkContourRepresentation.h:368
vtkContourRepresentationPoint
Definition: vtkContourRepresentation.h:73
vtkX3D::index
Definition: vtkX3D.h:246
vtkContourRepresentationPoint::WorldPosition
double WorldPosition[3]
Definition: vtkContourRepresentation.h:76
VTK_DOUBLE_MAX
#define VTK_DOUBLE_MAX
Definition: vtkType.h:169
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkWidgetRepresentation::ComputeInteractionState
virtual int ComputeInteractionState(int X, int Y, int modify=0)
vtkContourRepresentationPoint::NormalizedDisplayPosition
double NormalizedDisplayPosition[2]
Definition: vtkContourRepresentation.h:77
vtkWidgetRepresentation::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.