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 =========================================================================*/
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 public:
125 
129  void PrintSelf(ostream& os, vtkIndent indent);
131 
133 
137  virtual int AddNodeAtWorldPosition( double x, double y, double z);
138  virtual int AddNodeAtWorldPosition( double worldPos[3] );
139  virtual int AddNodeAtWorldPosition( double worldPos[3],
140  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  // Descirption:
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],
174  double orient[9] );
175 
177 
184  virtual int SetActiveNodeToDisplayPosition( double pos[2] );
185  virtual int SetActiveNodeToDisplayPosition( int pos[2] );
186  virtual int SetActiveNodeToDisplayPosition( int X, int Y );
188 
190 
193  virtual int ToggleActiveNodeSelected();
194  virtual int GetActiveNodeSelected();
195  virtual int GetNthNodeSelected(int);
196  virtual int SetNthNodeSelected(int);
198 
203  virtual int GetActiveNodeWorldPosition( double pos[3] );
204 
209  virtual int GetActiveNodeWorldOrientation( double orient[9] );
210 
215  virtual int GetActiveNodeDisplayPosition( double pos[2] );
216 
220  virtual int GetNumberOfNodes();
221 
227  virtual int GetNthNodeDisplayPosition( int n, double pos[2] );
228 
234  virtual int GetNthNodeWorldPosition( int n, double pos[3] );
235 
239  virtual vtkContourRepresentationNode *GetNthNode(int n);
240 
246  virtual int GetNthNodeWorldOrientation( int n, double orient[9] );
247 
249 
257  virtual int SetNthNodeDisplayPosition( int n, int X, int Y );
258  virtual int SetNthNodeDisplayPosition( int n, int pos[2] );
259  virtual int SetNthNodeDisplayPosition( int n, double pos[2] );
261 
263 
270  virtual int SetNthNodeWorldPosition( int n, double pos[3] );
271  virtual int SetNthNodeWorldPosition( int n, double pos[3],
272  double orient[9] );
274 
280  virtual int GetNthNodeSlope( int idx, double slope[3] );
281 
282  // Descirption:
283  // For a given node n, get the number of intermediate
284  // points between this node and the node at
285  // (n+1). If n is the last node and the loop is
286  // closed, this is the number of intermediate points
287  // between node n and node 0. 0 is returned if n is
288  // out of range.
289  virtual int GetNumberOfIntermediatePoints( int n );
290 
297  virtual int GetIntermediatePointWorldPosition( int n,
298  int idx, double point[3] );
299 
305  virtual int AddIntermediatePointWorldPosition( int n,
306  double point[3] );
307 
314  virtual int AddIntermediatePointWorldPosition( int n,
315  double point[3], vtkIdType ptId );
316 
321  virtual int DeleteLastNode();
322 
327  virtual int DeleteActiveNode();
328 
333  virtual int DeleteNthNode( int n );
334 
338  virtual void ClearAllNodes();
339 
344  virtual int AddNodeOnContour( int X, int Y );
345 
347 
351  vtkSetClampMacro(PixelTolerance,int,1,100);
352  vtkGetMacro(PixelTolerance,int);
354 
356 
360  vtkSetClampMacro(WorldTolerance, double, 0.0, VTK_DOUBLE_MAX);
361  vtkGetMacro(WorldTolerance, double);
363 
364  // Used to communicate about the state of the representation
365  enum {
366  Outside=0,
367  Nearby
368  };
369 
370  enum {
371  Inactive = 0,
374  Scale
375  };
376 
378 
382  vtkGetMacro( CurrentOperation, int );
383  vtkSetClampMacro( CurrentOperation, int,
387  { this->SetCurrentOperation( vtkContourRepresentation::Inactive ); }
389  { this->SetCurrentOperation( vtkContourRepresentation::Translate ); }
391  {this->SetCurrentOperation( vtkContourRepresentation::Shift ); }
393  {this->SetCurrentOperation( vtkContourRepresentation::Scale ); }
395 
396  // Descirption:
397  // Set / get the Point Placer. The point placer is
398  // responsible for converting display coordinates into
399  // world coordinates according to some constraints, and
400  // for validating world positions.
401  void SetPointPlacer( vtkPointPlacer * );
402  vtkGetObjectMacro( PointPlacer, vtkPointPlacer );
403 
405 
410  void SetLineInterpolator( vtkContourLineInterpolator *);
411  vtkGetObjectMacro( LineInterpolator, vtkContourLineInterpolator );
413 
415 
418  virtual void BuildRepresentation()=0;
419  virtual int ComputeInteractionState(int X, int Y, int modified=0)=0;
420  virtual void StartWidgetInteraction(double e[2])=0;
421  virtual void WidgetInteraction(double e[2])=0;
423 
425 
428  virtual void ReleaseGraphicsResources(vtkWindow *w)=0;
429  virtual int RenderOverlay(vtkViewport *viewport)=0;
430  virtual int RenderOpaqueGeometry(vtkViewport *viewport)=0;
431  virtual int RenderTranslucentPolygonalGeometry(vtkViewport *viewport)=0;
432  virtual int HasTranslucentPolygonalGeometry()=0;
434 
436 
440  void SetClosedLoop( int val );
441  vtkGetMacro( ClosedLoop, int );
442  vtkBooleanMacro( ClosedLoop, int );
444 
446 
450  virtual void SetShowSelectedNodes(int);
451  vtkGetMacro( ShowSelectedNodes, int );
452  vtkBooleanMacro( ShowSelectedNodes, int );
454 
458  virtual vtkPolyData* GetContourRepresentationAsPolyData() = 0;
459 
464  void GetNodePolyData( vtkPolyData* poly );
465 
466  vtkSetMacro(RebuildLocator,bool);
467 
468 protected:
471 
472  // Selection tolerance for the handles
475 
478 
480 
483 
484  // A flag to indicate whether to show the Selected nodes
486 
488 
489  void AddNodeAtPositionInternal( double worldPos[3],
490  double worldOrient[9], int displayPos[2] );
491  void AddNodeAtPositionInternal( double worldPos[3],
492  double worldOrient[9], double displayPos[2] );
493  void SetNthNodeWorldPositionInternal( int n, double worldPos[3],
494  double worldOrient[9] );
495 
497 
501  void GetRendererComputedDisplayPositionFromWorldPosition( double worldPos[3],
502  double worldOrient[9], int displayPos[2] );
503  void GetRendererComputedDisplayPositionFromWorldPosition( double worldPos[3],
504  double worldOrient[9], double displayPos[2] );
506 
507  virtual void UpdateLines( int index );
508  void UpdateLine( int idx1, int idx2 );
509 
510  virtual int FindClosestPointOnContour( int X, int Y,
511  double worldPos[3],
512  int *idx );
513 
514  virtual void BuildLines()=0;
515 
516  // This method is called when something changes in the point placer.
517  // It will cause all points to be updated, and all lines to be regenerated.
518  // It should be extended to detect changes in the line interpolator too.
519  virtual int UpdateContour();
521 
522  void ComputeMidpoint( double p1[3], double p2[3], double mid[3] )
523  {
524  mid[0] = (p1[0] + p2[0])/2;
525  mid[1] = (p1[1] + p2[1])/2;
526  mid[2] = (p1[2] + p2[2])/2;
527  }
528 
540  virtual void Initialize( vtkPolyData *, vtkIdList *);
541 
546  virtual void Initialize( vtkPolyData *);
547 
552  virtual void InitializeContour( vtkPolyData *, vtkIdList * );
553 
559 
564  void ResetLocator();
565 
566  void BuildLocator();
567 
569 
570 
571 private:
572  vtkContourRepresentation(const vtkContourRepresentation&) VTK_DELETE_FUNCTION;
573  void operator=(const vtkContourRepresentation&) VTK_DELETE_FUNCTION;
574 };
575 
576 #endif
577 
std::vector< vtkContourRepresentationNode * > Nodes
virtual int RenderOverlay(vtkViewport *vtkNotUsed(viewport))
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:163
abstract specification for Viewports
Definition: vtkViewport.h:47
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:287
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:85
vtkIncrementalOctreePointLocator * Locator
Adding a point locator to the representation to speed up lookup of the active node when dealing with ...
represent the vtkContourWidget
virtual void ReleaseGraphicsResources(vtkWindow *)
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE Release any graphics resources that are being...
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.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
virtual int HasTranslucentPolygonalGeometry()
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THESE METHODS OUTSIDE OF THE RENDE...
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:36
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.
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
virtual int RenderOpaqueGeometry(vtkViewport *vtkNotUsed(viewport))
create a contour with a set of points
vtkContourLineInterpolator * LineInterpolator
void PrintSelf(ostream &os, vtkIndent indent)
Standard methods for instances of this class.
vtkBooleanMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
virtual void Initialize()
virtual int RenderTranslucentPolygonalGeometry(vtkViewport *vtkNotUsed(viewport))
Incremental octree in support of both point location and point insertion.