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 //----------------------------------------------------------------------
73 //BTX
75 {
76 public:
77  double WorldPosition[3];
79 
80  // The point id. This is blank except in the case of
81  // vtkPolygonalSurfaceContourLineInterpolator
83 };
84 
86 {
87 public:
88  double WorldPosition[3];
89  double WorldOrientation[9];
91  int Selected;
92  std::vector<vtkContourRepresentationPoint*> Points;
93 
94  // The point id. This is blank except in the case of
95  // vtkPolygonalSurfaceContourLineInterpolator
97 };
98 
100 {
101 public:
102  std::vector<vtkContourRepresentationNode*> Nodes;
103  void ClearNodes()
104  {
105  for(unsigned int i=0;i<this->Nodes.size();i++)
106  {
107  for (unsigned int j=0;j<this->Nodes[i]->Points.size();j++)
108  {
109  delete this->Nodes[i]->Points[j];
110  }
111  this->Nodes[i]->Points.clear();
112  delete this->Nodes[i];
113  }
114  this->Nodes.clear();
115  }
116 };
117 //ETX
118 
120 {
121  //BTX
122  friend class vtkContourWidget;
123  //ETX
124 public:
126 
128  void PrintSelf(ostream& os, vtkIndent indent);
130 
132 
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 
144  virtual int AddNodeAtDisplayPosition( double displayPos[2] );
145  virtual int AddNodeAtDisplayPosition( int displayPos[2] );
146  virtual int AddNodeAtDisplayPosition( int X, int Y );
148 
150 
153  virtual int ActivateNode( double displayPos[2] );
154  virtual int ActivateNode( int displayPos[2] );
155  virtual int ActivateNode( int X, int Y );
157 
158  // Descirption:
159  // Move the active node to a specified world position.
160  // Will return 0 if there is no active node or the node
161  // could not be moved to that position. 1 will be returned
162  // on success.
163  virtual int SetActiveNodeToWorldPosition( double pos[3] );
164  virtual int SetActiveNodeToWorldPosition( double pos[3],
165  double orient[9] );
166 
168 
172  virtual int SetActiveNodeToDisplayPosition( double pos[2] );
173  virtual int SetActiveNodeToDisplayPosition( int pos[2] );
174  virtual int SetActiveNodeToDisplayPosition( int X, int Y );
176 
178 
179  virtual int ToggleActiveNodeSelected();
180  virtual int GetActiveNodeSelected();
181  virtual int GetNthNodeSelected(int);
182  virtual int SetNthNodeSelected(int);
184 
187  virtual int GetActiveNodeWorldPosition( double pos[3] );
188 
191  virtual int GetActiveNodeWorldOrientation( double orient[9] );
192 
195  virtual int GetActiveNodeDisplayPosition( double pos[2] );
196 
198  virtual int GetNumberOfNodes();
199 
202  virtual int GetNthNodeDisplayPosition( int n, double pos[2] );
203 
206  virtual int GetNthNodeWorldPosition( int n, double pos[3] );
207 
208  //BTX
210 
211  virtual vtkContourRepresentationNode *GetNthNode(int n);
212  //ETX
214 
217  virtual int GetNthNodeWorldOrientation( int n, double orient[9] );
218 
220 
225  virtual int SetNthNodeDisplayPosition( int n, int X, int Y );
226  virtual int SetNthNodeDisplayPosition( int n, int pos[2] );
227  virtual int SetNthNodeDisplayPosition( int n, double pos[2] );
229 
231 
234  virtual int SetNthNodeWorldPosition( int n, double pos[3] );
235  virtual int SetNthNodeWorldPosition( int n, double pos[3],
236  double orient[9] );
238 
241  virtual int GetNthNodeSlope( int idx, double slope[3] );
242 
243  // Descirption:
244  // For a given node n, get the number of intermediate
245  // points between this node and the node at
246  // (n+1). If n is the last node and the loop is
247  // closed, this is the number of intermediate points
248  // between node n and node 0. 0 is returned if n is
249  // out of range.
250  virtual int GetNumberOfIntermediatePoints( int n );
251 
253 
256  virtual int GetIntermediatePointWorldPosition( int n,
257  int idx, double point[3] );
259 
261 
264  virtual int AddIntermediatePointWorldPosition( int n,
265  double point[3] );
267 
269 
272  virtual int AddIntermediatePointWorldPosition( int n,
273  double point[3], vtkIdType ptId );
275 
278  virtual int DeleteLastNode();
279 
282  virtual int DeleteActiveNode();
283 
285  virtual int DeleteNthNode( int n );
286 
288  virtual void ClearAllNodes();
289 
292  virtual int AddNodeOnContour( int X, int Y );
293 
295 
297  vtkSetClampMacro(PixelTolerance,int,1,100);
298  vtkGetMacro(PixelTolerance,int);
300 
302 
304  vtkSetClampMacro(WorldTolerance, double, 0.0, VTK_DOUBLE_MAX);
305  vtkGetMacro(WorldTolerance, double);
307 
308 //BTX -- used to communicate about the state of the representation
309  enum {
310  Outside=0,
311  Nearby
312  };
313 
314  enum {
315  Inactive = 0,
318  Scale
319  };
320 //ETX
321 
323 
325  vtkGetMacro( CurrentOperation, int );
326  vtkSetClampMacro( CurrentOperation, int,
330  { this->SetCurrentOperation( vtkContourRepresentation::Inactive ); }
332  { this->SetCurrentOperation( vtkContourRepresentation::Translate ); }
334  {this->SetCurrentOperation( vtkContourRepresentation::Shift ); }
336  {this->SetCurrentOperation( vtkContourRepresentation::Scale ); }
338 
339  // Descirption:
340  // Set / get the Point Placer. The point placer is
341  // responsible for converting display coordinates into
342  // world coordinates according to some constraints, and
343  // for validating world positions.
344  void SetPointPlacer( vtkPointPlacer * );
345  vtkGetObjectMacro( PointPlacer, vtkPointPlacer );
346 
348 
350  void SetLineInterpolator( vtkContourLineInterpolator *);
351  vtkGetObjectMacro( LineInterpolator, vtkContourLineInterpolator );
353 
355 
356  virtual void BuildRepresentation()=0;
357  virtual int ComputeInteractionState(int X, int Y, int modified=0)=0;
358  virtual void StartWidgetInteraction(double e[2])=0;
359  virtual void WidgetInteraction(double e[2])=0;
361 
363 
364  virtual void ReleaseGraphicsResources(vtkWindow *w)=0;
365  virtual int RenderOverlay(vtkViewport *viewport)=0;
366  virtual int RenderOpaqueGeometry(vtkViewport *viewport)=0;
367  virtual int RenderTranslucentPolygonalGeometry(vtkViewport *viewport)=0;
368  virtual int HasTranslucentPolygonalGeometry()=0;
370 
372 
374  void SetClosedLoop( int val );
375  vtkGetMacro( ClosedLoop, int );
376  vtkBooleanMacro( ClosedLoop, int );
378 
380 
382  virtual void SetShowSelectedNodes(int);
383  vtkGetMacro( ShowSelectedNodes, int );
384  vtkBooleanMacro( ShowSelectedNodes, int );
386 
387 //BTX
389 
390  virtual vtkPolyData* GetContourRepresentationAsPolyData() = 0;
391 //ETX
393 
396  void GetNodePolyData( vtkPolyData* poly );
397 
398  vtkSetMacro(RebuildLocator,bool);
399 
400 protected:
403 
404  // Selection tolerance for the handles
407 
410 
412 
415 
416  // A flag to indicate whether to show the Selected nodes
418 
420 
421  void AddNodeAtPositionInternal( double worldPos[3],
422  double worldOrient[9], int displayPos[2] );
423  void AddNodeAtPositionInternal( double worldPos[3],
424  double worldOrient[9], double displayPos[2] );
425  void SetNthNodeWorldPositionInternal( int n, double worldPos[3],
426  double worldOrient[9] );
427 
429 
431  void GetRendererComputedDisplayPositionFromWorldPosition( double worldPos[3],
432  double worldOrient[9], int displayPos[2] );
433  void GetRendererComputedDisplayPositionFromWorldPosition( double worldPos[3],
434  double worldOrient[9], double displayPos[2] );
436 
437  virtual void UpdateLines( int index );
438  void UpdateLine( int idx1, int idx2 );
439 
440  virtual int FindClosestPointOnContour( int X, int Y,
441  double worldPos[3],
442  int *idx );
443 
444  virtual void BuildLines()=0;
445 
446  // This method is called when something changes in the point
447  // placer. It will cause all points to
448  // be updates, and all lines to be regenerated.
449  // Should be extended to detect changes in the line interpolator
450  // too.
451  virtual int UpdateContour();
453 
454  void ComputeMidpoint( double p1[3], double p2[3], double mid[3] )
455  {
456  mid[0] = (p1[0] + p2[0])/2;
457  mid[1] = (p1[1] + p2[1])/2;
458  mid[2] = (p1[2] + p2[2])/2;
459  }
460 
470  virtual void Initialize( vtkPolyData *, vtkIdList *);
471 
474  virtual void Initialize( vtkPolyData *);
475 
479  virtual void InitializeContour( vtkPolyData *, vtkIdList * );
480 
484 
487  void ResetLocator();
488 
489  void BuildLocator();
490 
492 
493 
494 private:
495  vtkContourRepresentation(const vtkContourRepresentation&); //Not implemented
496  void operator=(const vtkContourRepresentation&); //Not implemented
497 };
498 
499 #endif
500 
std::vector< vtkContourRepresentationNode * > Nodes
virtual int RenderOverlay(vtkViewport *vtkNotUsed(viewport))
std::vector< vtkContourRepresentationPoint * > Points
virtual int ComputeInteractionState(int X, int Y, int modify=0)
#define VTK_DOUBLE_MAX
Definition: vtkType.h:142
abstract specification for Viewports
Definition: vtkViewport.h:46
virtual void StartWidgetInteraction(double eventPos[2])
record modification and/or execution time
Definition: vtkTimeStamp.h:34
int vtkIdType
Definition: vtkType.h:275
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:83
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:36
#define VTKINTERACTIONWIDGETS_EXPORT
virtual int HasTranslucentPolygonalGeometry()
a simple class to control print indentation
Definition: vtkIndent.h:38
void ComputeMidpoint(double p1[3], double p2[3], double mid[3])
list of point or cell ids
Definition: vtkIdList.h:35
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.
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.