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 =========================================================================*/
56 #ifndef __vtkContourRepresentation_h
57 #define __vtkContourRepresentation_h
58 
60 #include <vtkstd/vector> // STL Header; Required for vector
61 
64 class vtkPointPlacer;
65 class vtkPolyData;
66 
67 //----------------------------------------------------------------------
68 //BTX
70 {
71 public:
72  double WorldPosition[3];
74 };
75 
77 {
78 public:
79  double WorldPosition[3];
80  double WorldOrientation[9];
82  int Selected;
83  vtkstd::vector<vtkContourRepresentationPoint*> Points;
84 };
85 
87 {
88 public:
89  vtkstd::vector<vtkContourRepresentationNode*> Nodes;
90  void ClearNodes()
91  {
92  for(unsigned int i=0;i<this->Nodes.size();i++)
93  {
94  for (unsigned int j=0;j<this->Nodes[i]->Points.size();j++)
95  {
96  delete this->Nodes[i]->Points[j];
97  }
98  this->Nodes[i]->Points.clear();
99  delete this->Nodes[i];
100  }
101  this->Nodes.clear();
102  }
103 };
104 //ETX
105 
107 {
108  //BTX
109  friend class vtkContourWidget;
110  //ETX
111 public:
113 
115  void PrintSelf(ostream& os, vtkIndent indent);
117 
119 
121  virtual int AddNodeAtWorldPosition( double x, double y, double z);
122  virtual int AddNodeAtWorldPosition( double worldPos[3] );
123  virtual int AddNodeAtWorldPosition( double worldPos[3],
124  double worldOrient[9] );
126 
128 
131  virtual int AddNodeAtDisplayPosition( double displayPos[2] );
132  virtual int AddNodeAtDisplayPosition( int displayPos[2] );
133  virtual int AddNodeAtDisplayPosition( int X, int Y );
135 
137 
140  virtual int ActivateNode( double displayPos[2] );
141  virtual int ActivateNode( int displayPos[2] );
142  virtual int ActivateNode( int X, int Y );
144 
145  // Descirption:
146  // Move the active node to a specified world position.
147  // Will return 0 if there is no active node or the node
148  // could not be moved to that position. 1 will be returned
149  // on success.
150  virtual int SetActiveNodeToWorldPosition( double pos[3] );
151  virtual int SetActiveNodeToWorldPosition( double pos[3],
152  double orient[9] );
153 
155 
159  virtual int SetActiveNodeToDisplayPosition( double pos[2] );
160  virtual int SetActiveNodeToDisplayPosition( int pos[2] );
161  virtual int SetActiveNodeToDisplayPosition( int X, int Y );
163 
165 
166  virtual int ToggleActiveNodeSelected();
167  virtual int GetActiveNodeSelected();
168  virtual int GetNthNodeSelected(int);
169  virtual int SetNthNodeSelected(int);
171 
174  virtual int GetActiveNodeWorldPosition( double pos[3] );
175 
178  virtual int GetActiveNodeWorldOrientation( double orient[9] );
179 
182  virtual int GetActiveNodeDisplayPosition( double pos[2] );
183 
185  virtual int GetNumberOfNodes();
186 
189  virtual int GetNthNodeDisplayPosition( int n, double pos[2] );
190 
193  virtual int GetNthNodeWorldPosition( int n, double pos[3] );
194 
197  virtual int GetNthNodeWorldOrientation( int n, double orient[9] );
198 
200 
205  virtual int SetNthNodeDisplayPosition( int n, int X, int Y );
206  virtual int SetNthNodeDisplayPosition( int n, int pos[2] );
207  virtual int SetNthNodeDisplayPosition( int n, double pos[2] );
209 
211 
214  virtual int SetNthNodeWorldPosition( int n, double pos[3] );
215  virtual int SetNthNodeWorldPosition( int n, double pos[3],
216  double orient[9] );
218 
221  virtual int GetNthNodeSlope( int idx, double slope[3] );
222 
223  // Descirption:
224  // For a given node n, get the number of intermediate
225  // points between this node and the node at
226  // (n+1). If n is the last node and the loop is
227  // closed, this is the number of intermediate points
228  // between node n and node 0. 0 is returned if n is
229  // out of range.
230  virtual int GetNumberOfIntermediatePoints( int n );
231 
233 
236  virtual int GetIntermediatePointWorldPosition( int n,
237  int idx, double point[3] );
239 
241 
244  virtual int AddIntermediatePointWorldPosition( int n,
245  double point[3] );
247 
250  virtual int DeleteLastNode();
251 
254  virtual int DeleteActiveNode();
255 
257  virtual int DeleteNthNode( int n );
258 
260  virtual void ClearAllNodes();
261 
264  virtual int AddNodeOnContour( int X, int Y );
265 
267 
269  vtkSetClampMacro(PixelTolerance,int,1,100);
270  vtkGetMacro(PixelTolerance,int);
272 
274 
276  vtkSetClampMacro(WorldTolerance, double, 0.0, VTK_DOUBLE_MAX);
277  vtkGetMacro(WorldTolerance, double);
279 
280 //BTX -- used to communicate about the state of the representation
281  enum {
282  Outside=0,
283  Nearby
284  };
285 
286  enum {
287  Inactive = 0,
290  Scale
291  };
292 //ETX
293 
295 
297  vtkGetMacro( CurrentOperation, int );
298  vtkSetClampMacro( CurrentOperation, int,
302  { this->SetCurrentOperation( vtkContourRepresentation::Inactive ); }
304  { this->SetCurrentOperation( vtkContourRepresentation::Translate ); }
306  {this->SetCurrentOperation( vtkContourRepresentation::Shift ); }
308  {this->SetCurrentOperation( vtkContourRepresentation::Scale ); }
310 
311  // Descirption:
312  // Set / get the Point Placer. The point placer is
313  // responsible for converting display coordinates into
314  // world coordinates according to some constraints, and
315  // for validating world positions.
316  void SetPointPlacer( vtkPointPlacer * );
317  vtkGetObjectMacro( PointPlacer, vtkPointPlacer );
318 
320 
322  void SetLineInterpolator( vtkContourLineInterpolator *);
323  vtkGetObjectMacro( LineInterpolator, vtkContourLineInterpolator );
325 
327 
328  virtual void BuildRepresentation()=0;
329  virtual int ComputeInteractionState(int X, int Y, int modified=0)=0;
330  virtual void StartWidgetInteraction(double e[2])=0;
331  virtual void WidgetInteraction(double e[2])=0;
333 
335 
336  virtual void ReleaseGraphicsResources(vtkWindow *w)=0;
337  virtual int RenderOverlay(vtkViewport *viewport)=0;
338  virtual int RenderOpaqueGeometry(vtkViewport *viewport)=0;
339  virtual int RenderTranslucentPolygonalGeometry(vtkViewport *viewport)=0;
340  virtual int HasTranslucentPolygonalGeometry()=0;
342 
344 
346  void SetClosedLoop( int val );
347  vtkGetMacro( ClosedLoop, int );
348  vtkBooleanMacro( ClosedLoop, int );
350 
352 
354  virtual void SetShowSelectedNodes(int);
355  vtkGetMacro( ShowSelectedNodes, int );
356  vtkBooleanMacro( ShowSelectedNodes, int );
358 
359 //BTX
361 
362  virtual vtkPolyData* GetContourRepresentationAsPolyData() = 0;
363 //ETX
365 
368  void GetNodePolyData( vtkPolyData* poly );
369 
370  vtkSetMacro(RebuildLocator,bool);
371 
372 protected:
375 
376  // Selection tolerance for the handles
379 
382 
384 
387 
388  // A flag to indicate whether to show the Selected nodes
390 
392 
393  void AddNodeAtPositionInternal( double worldPos[3],
394  double worldOrient[9], int displayPos[2] );
395  void AddNodeAtPositionInternal( double worldPos[3],
396  double worldOrient[9], double displayPos[2] );
397  void SetNthNodeWorldPositionInternal( int n, double worldPos[3],
398  double worldOrient[9] );
399 
401 
403  void GetRendererComputedDisplayPositionFromWorldPosition( double worldPos[3],
404  double worldOrient[9], int displayPos[2] );
405  void GetRendererComputedDisplayPositionFromWorldPosition( double worldPos[3],
406  double worldOrient[9], double displayPos[2] );
408 
409  virtual void UpdateLines( int index );
410  void UpdateLine( int idx1, int idx2 );
411 
412  virtual int FindClosestPointOnContour( int X, int Y,
413  double worldPos[3],
414  int *idx );
415 
416  virtual void BuildLines()=0;
417 
418  // This method is called when something changes in the point
419  // placer. It will cause all points to
420  // be updates, and all lines to be regenerated.
421  // Should be extended to detect changes in the line interpolator
422  // too.
423  virtual int UpdateContour();
425 
426  void ComputeMidpoint( double p1[3], double p2[3], double mid[3] )
427  {
428  mid[0] = (p1[0] + p2[0])/2;
429  mid[1] = (p1[1] + p2[1])/2;
430  mid[2] = (p1[2] + p2[2])/2;
431  }
432 
439  virtual void Initialize( vtkPolyData * );
440 
444 
447  void ResetLocator();
448 
449  void BuildLocator();
450 
452 
453 
454 private:
455  vtkContourRepresentation(const vtkContourRepresentation&); //Not implemented
456  void operator=(const vtkContourRepresentation&); //Not implemented
457 };
458 
459 #endif
460 
virtual int RenderOverlay(vtkViewport *vtkNotUsed(viewport))
vtkstd::vector< vtkContourRepresentationPoint * > Points
vtkstd::vector< vtkContourRepresentationNode * > Nodes
virtual int ComputeInteractionState(int X, int Y, int modify=0)
#define VTK_DOUBLE_MAX
Definition: vtkType.h:133
abstract specification for Viewports
Definition: vtkViewport.h:45
virtual void StartWidgetInteraction(double eventPos[2])
record modification and/or execution time
Definition: vtkTimeStamp.h:33
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:81
vtkIncrementalOctreePointLocator * Locator
represent the vtkContourWidget
virtual void ReleaseGraphicsResources(vtkWindow *)
abstract class defines interface between the widget and widget representation classes ...
virtual void BuildRepresentation()=0
window superclass for vtkRenderWindow
Definition: vtkWindow.h:35
virtual int HasTranslucentPolygonalGeometry()
a simple class to control print indentation
Definition: vtkIndent.h:37
void ComputeMidpoint(double p1[3], double p2[3], double mid[3])
Abstract interface to translate 2D display positions to world coordinates.
vtkContourRepresentationInternals * Internal
virtual void WidgetInteraction(double newEventPos[2])
#define VTK_WIDGETS_EXPORT
Defines API for interpolating/modifying nodes from a vtkContourRepresentation.
virtual int RenderOpaqueGeometry(vtkViewport *vtkNotUsed(viewport))
create a contour with a set of points
vtkContourLineInterpolator * LineInterpolator
void PrintSelf(ostream &os, vtkIndent indent)
virtual void Initialize()
virtual int RenderTranslucentPolygonalGeometry(vtkViewport *vtkNotUsed(viewport))
Incremental octree in support of both point location and point insertion.