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 
63 #include <vector> // STL Header; Required for vector
64 
67 class vtkPointPlacer;
68 class vtkPolyData;
69 class vtkIdList;
70 
71 //----------------------------------------------------------------------
72 //BTX
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 //ETX
117 
119 {
120  //BTX
121  friend class vtkContourWidget;
122  //ETX
123 public:
125 
127  void PrintSelf(ostream& os, vtkIndent indent);
129 
131 
133  virtual int AddNodeAtWorldPosition( double x, double y, double z);
134  virtual int AddNodeAtWorldPosition( double worldPos[3] );
135  virtual int AddNodeAtWorldPosition( double worldPos[3],
136  double worldOrient[9] );
138 
140 
143  virtual int AddNodeAtDisplayPosition( double displayPos[2] );
144  virtual int AddNodeAtDisplayPosition( int displayPos[2] );
145  virtual int AddNodeAtDisplayPosition( int X, int Y );
147 
149 
152  virtual int ActivateNode( double displayPos[2] );
153  virtual int ActivateNode( int displayPos[2] );
154  virtual int ActivateNode( int X, int Y );
156 
157  // Descirption:
158  // Move the active node to a specified world position.
159  // Will return 0 if there is no active node or the node
160  // could not be moved to that position. 1 will be returned
161  // on success.
162  virtual int SetActiveNodeToWorldPosition( double pos[3] );
163  virtual int SetActiveNodeToWorldPosition( double pos[3],
164  double orient[9] );
165 
167 
171  virtual int SetActiveNodeToDisplayPosition( double pos[2] );
172  virtual int SetActiveNodeToDisplayPosition( int pos[2] );
173  virtual int SetActiveNodeToDisplayPosition( int X, int Y );
175 
177 
178  virtual int ToggleActiveNodeSelected();
179  virtual int GetActiveNodeSelected();
180  virtual int GetNthNodeSelected(int);
181  virtual int SetNthNodeSelected(int);
183 
186  virtual int GetActiveNodeWorldPosition( double pos[3] );
187 
190  virtual int GetActiveNodeWorldOrientation( double orient[9] );
191 
194  virtual int GetActiveNodeDisplayPosition( double pos[2] );
195 
197  virtual int GetNumberOfNodes();
198 
201  virtual int GetNthNodeDisplayPosition( int n, double pos[2] );
202 
205  virtual int GetNthNodeWorldPosition( int n, double pos[3] );
206 
207  //BTX
209 
210  virtual vtkContourRepresentationNode *GetNthNode(int n);
211  //ETX
213 
216  virtual int GetNthNodeWorldOrientation( int n, double orient[9] );
217 
219 
224  virtual int SetNthNodeDisplayPosition( int n, int X, int Y );
225  virtual int SetNthNodeDisplayPosition( int n, int pos[2] );
226  virtual int SetNthNodeDisplayPosition( int n, double pos[2] );
228 
230 
233  virtual int SetNthNodeWorldPosition( int n, double pos[3] );
234  virtual int SetNthNodeWorldPosition( int n, double pos[3],
235  double orient[9] );
237 
240  virtual int GetNthNodeSlope( int idx, double slope[3] );
241 
242  // Descirption:
243  // For a given node n, get the number of intermediate
244  // points between this node and the node at
245  // (n+1). If n is the last node and the loop is
246  // closed, this is the number of intermediate points
247  // between node n and node 0. 0 is returned if n is
248  // out of range.
249  virtual int GetNumberOfIntermediatePoints( int n );
250 
252 
255  virtual int GetIntermediatePointWorldPosition( int n,
256  int idx, double point[3] );
258 
260 
263  virtual int AddIntermediatePointWorldPosition( int n,
264  double point[3] );
266 
268 
271  virtual int AddIntermediatePointWorldPosition( int n,
272  double point[3], vtkIdType ptId );
274 
277  virtual int DeleteLastNode();
278 
281  virtual int DeleteActiveNode();
282 
284  virtual int DeleteNthNode( int n );
285 
287  virtual void ClearAllNodes();
288 
291  virtual int AddNodeOnContour( int X, int Y );
292 
294 
296  vtkSetClampMacro(PixelTolerance,int,1,100);
297  vtkGetMacro(PixelTolerance,int);
299 
301 
303  vtkSetClampMacro(WorldTolerance, double, 0.0, VTK_DOUBLE_MAX);
304  vtkGetMacro(WorldTolerance, double);
306 
307 //BTX -- used to communicate about the state of the representation
308  enum {
309  Outside=0,
310  Nearby
311  };
312 
313  enum {
314  Inactive = 0,
317  Scale
318  };
319 //ETX
320 
322 
324  vtkGetMacro( CurrentOperation, int );
325  vtkSetClampMacro( CurrentOperation, int,
328  void SetCurrentOperationToInactive()
329  { this->SetCurrentOperation( vtkContourRepresentation::Inactive ); }
330  void SetCurrentOperationToTranslate()
331  { this->SetCurrentOperation( vtkContourRepresentation::Translate ); }
332  void SetCurrentOperationToShift()
333  {this->SetCurrentOperation( vtkContourRepresentation::Shift ); }
334  void SetCurrentOperationToScale()
335  {this->SetCurrentOperation( vtkContourRepresentation::Scale ); }
337 
338  // Descirption:
339  // Set / get the Point Placer. The point placer is
340  // responsible for converting display coordinates into
341  // world coordinates according to some constraints, and
342  // for validating world positions.
343  void SetPointPlacer( vtkPointPlacer * );
344  vtkGetObjectMacro( PointPlacer, vtkPointPlacer );
345 
347 
349  void SetLineInterpolator( vtkContourLineInterpolator *);
350  vtkGetObjectMacro( LineInterpolator, vtkContourLineInterpolator );
352 
354 
355  virtual void BuildRepresentation()=0;
356  virtual int ComputeInteractionState(int X, int Y, int modified=0)=0;
357  virtual void StartWidgetInteraction(double e[2])=0;
358  virtual void WidgetInteraction(double e[2])=0;
360 
362 
363  virtual void ReleaseGraphicsResources(vtkWindow *w)=0;
364  virtual int RenderOverlay(vtkViewport *viewport)=0;
365  virtual int RenderOpaqueGeometry(vtkViewport *viewport)=0;
366  virtual int RenderTranslucentPolygonalGeometry(vtkViewport *viewport)=0;
367  virtual int HasTranslucentPolygonalGeometry()=0;
369 
371 
373  void SetClosedLoop( int val );
374  vtkGetMacro( ClosedLoop, int );
375  vtkBooleanMacro( ClosedLoop, int );
377 
379 
381  virtual void SetShowSelectedNodes(int);
382  vtkGetMacro( ShowSelectedNodes, int );
383  vtkBooleanMacro( ShowSelectedNodes, int );
385 
386 //BTX
388 
389  virtual vtkPolyData* GetContourRepresentationAsPolyData() = 0;
390 //ETX
392 
395  void GetNodePolyData( vtkPolyData* poly );
396 
397  vtkSetMacro(RebuildLocator,bool);
398 
399 protected:
402 
403  // Selection tolerance for the handles
406 
409 
411 
414 
415  // A flag to indicate whether to show the Selected nodes
417 
419 
420  void AddNodeAtPositionInternal( double worldPos[3],
421  double worldOrient[9], int displayPos[2] );
422  void AddNodeAtPositionInternal( double worldPos[3],
423  double worldOrient[9], double displayPos[2] );
424  void SetNthNodeWorldPositionInternal( int n, double worldPos[3],
425  double worldOrient[9] );
426 
428 
430  void GetRendererComputedDisplayPositionFromWorldPosition( double worldPos[3],
431  double worldOrient[9], int displayPos[2] );
432  void GetRendererComputedDisplayPositionFromWorldPosition( double worldPos[3],
433  double worldOrient[9], double displayPos[2] );
435 
436  virtual void UpdateLines( int index );
437  void UpdateLine( int idx1, int idx2 );
438 
439  virtual int FindClosestPointOnContour( int X, int Y,
440  double worldPos[3],
441  int *idx );
442 
443  virtual void BuildLines()=0;
444 
445  // This method is called when something changes in the point
446  // placer. It will cause all points to
447  // be updates, and all lines to be regenerated.
448  // Should be extended to detect changes in the line interpolator
449  // too.
450  virtual int UpdateContour();
452 
453  void ComputeMidpoint( double p1[3], double p2[3], double mid[3] )
454  {
455  mid[0] = (p1[0] + p2[0])/2;
456  mid[1] = (p1[1] + p2[1])/2;
457  mid[2] = (p1[2] + p2[2])/2;
458  }
459 
469  void Initialize( vtkPolyData *, vtkIdList *);
470 
473  virtual void Initialize( vtkPolyData *);
474 
478 
481  void ResetLocator();
482 
483  void BuildLocator();
484 
486 
487 
488 private:
489  vtkContourRepresentation(const vtkContourRepresentation&); //Not implemented
490  void operator=(const vtkContourRepresentation&); //Not implemented
491 };
492 
493 #endif
494