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 
118 {
119  friend class vtkContourWidget;
120 public:
122 
124  void PrintSelf(ostream& os, vtkIndent indent);
126 
128 
130  virtual int AddNodeAtWorldPosition( double x, double y, double z);
131  virtual int AddNodeAtWorldPosition( double worldPos[3] );
132  virtual int AddNodeAtWorldPosition( double worldPos[3],
133  double worldOrient[9] );
135 
137 
140  virtual int AddNodeAtDisplayPosition( double displayPos[2] );
141  virtual int AddNodeAtDisplayPosition( int displayPos[2] );
142  virtual int AddNodeAtDisplayPosition( int X, int Y );
144 
146 
149  virtual int ActivateNode( double displayPos[2] );
150  virtual int ActivateNode( int displayPos[2] );
151  virtual int ActivateNode( int X, int Y );
153 
154  // Descirption:
155  // Move the active node to a specified world position.
156  // Will return 0 if there is no active node or the node
157  // could not be moved to that position. 1 will be returned
158  // on success.
159  virtual int SetActiveNodeToWorldPosition( double pos[3] );
160  virtual int SetActiveNodeToWorldPosition( double pos[3],
161  double orient[9] );
162 
164 
168  virtual int SetActiveNodeToDisplayPosition( double pos[2] );
169  virtual int SetActiveNodeToDisplayPosition( int pos[2] );
170  virtual int SetActiveNodeToDisplayPosition( int X, int Y );
172 
174 
175  virtual int ToggleActiveNodeSelected();
176  virtual int GetActiveNodeSelected();
177  virtual int GetNthNodeSelected(int);
178  virtual int SetNthNodeSelected(int);
180 
183  virtual int GetActiveNodeWorldPosition( double pos[3] );
184 
187  virtual int GetActiveNodeWorldOrientation( double orient[9] );
188 
191  virtual int GetActiveNodeDisplayPosition( double pos[2] );
192 
194  virtual int GetNumberOfNodes();
195 
198  virtual int GetNthNodeDisplayPosition( int n, double pos[2] );
199 
202  virtual int GetNthNodeWorldPosition( int n, double pos[3] );
203 
205  virtual vtkContourRepresentationNode *GetNthNode(int n);
206 
209  virtual int GetNthNodeWorldOrientation( int n, double orient[9] );
210 
212 
217  virtual int SetNthNodeDisplayPosition( int n, int X, int Y );
218  virtual int SetNthNodeDisplayPosition( int n, int pos[2] );
219  virtual int SetNthNodeDisplayPosition( int n, double pos[2] );
221 
223 
226  virtual int SetNthNodeWorldPosition( int n, double pos[3] );
227  virtual int SetNthNodeWorldPosition( int n, double pos[3],
228  double orient[9] );
230 
233  virtual int GetNthNodeSlope( int idx, double slope[3] );
234 
235  // Descirption:
236  // For a given node n, get the number of intermediate
237  // points between this node and the node at
238  // (n+1). If n is the last node and the loop is
239  // closed, this is the number of intermediate points
240  // between node n and node 0. 0 is returned if n is
241  // out of range.
242  virtual int GetNumberOfIntermediatePoints( int n );
243 
245 
248  virtual int GetIntermediatePointWorldPosition( int n,
249  int idx, double point[3] );
251 
253 
256  virtual int AddIntermediatePointWorldPosition( int n,
257  double point[3] );
259 
261 
264  virtual int AddIntermediatePointWorldPosition( int n,
265  double point[3], vtkIdType ptId );
267 
270  virtual int DeleteLastNode();
271 
274  virtual int DeleteActiveNode();
275 
277  virtual int DeleteNthNode( int n );
278 
280  virtual void ClearAllNodes();
281 
284  virtual int AddNodeOnContour( int X, int Y );
285 
287 
289  vtkSetClampMacro(PixelTolerance,int,1,100);
290  vtkGetMacro(PixelTolerance,int);
292 
294 
296  vtkSetClampMacro(WorldTolerance, double, 0.0, VTK_DOUBLE_MAX);
297  vtkGetMacro(WorldTolerance, double);
299 
300  // Used to communicate about the state of the representation
301  enum {
302  Outside=0,
303  Nearby
304  };
305 
306  enum {
307  Inactive = 0,
310  Scale
311  };
312 
314 
316  vtkGetMacro( CurrentOperation, int );
317  vtkSetClampMacro( CurrentOperation, int,
321  { this->SetCurrentOperation( vtkContourRepresentation::Inactive ); }
323  { this->SetCurrentOperation( vtkContourRepresentation::Translate ); }
325  {this->SetCurrentOperation( vtkContourRepresentation::Shift ); }
327  {this->SetCurrentOperation( vtkContourRepresentation::Scale ); }
329 
330  // Descirption:
331  // Set / get the Point Placer. The point placer is
332  // responsible for converting display coordinates into
333  // world coordinates according to some constraints, and
334  // for validating world positions.
335  void SetPointPlacer( vtkPointPlacer * );
336  vtkGetObjectMacro( PointPlacer, vtkPointPlacer );
337 
339 
341  void SetLineInterpolator( vtkContourLineInterpolator *);
342  vtkGetObjectMacro( LineInterpolator, vtkContourLineInterpolator );
344 
346 
347  virtual void BuildRepresentation()=0;
348  virtual int ComputeInteractionState(int X, int Y, int modified=0)=0;
349  virtual void StartWidgetInteraction(double e[2])=0;
350  virtual void WidgetInteraction(double e[2])=0;
352 
354 
355  virtual void ReleaseGraphicsResources(vtkWindow *w)=0;
356  virtual int RenderOverlay(vtkViewport *viewport)=0;
357  virtual int RenderOpaqueGeometry(vtkViewport *viewport)=0;
358  virtual int RenderTranslucentPolygonalGeometry(vtkViewport *viewport)=0;
359  virtual int HasTranslucentPolygonalGeometry()=0;
361 
363 
365  void SetClosedLoop( int val );
366  vtkGetMacro( ClosedLoop, int );
367  vtkBooleanMacro( ClosedLoop, int );
369 
371 
373  virtual void SetShowSelectedNodes(int);
374  vtkGetMacro( ShowSelectedNodes, int );
375  vtkBooleanMacro( ShowSelectedNodes, int );
377 
379  virtual vtkPolyData* GetContourRepresentationAsPolyData() = 0;
380 
383  void GetNodePolyData( vtkPolyData* poly );
384 
385  vtkSetMacro(RebuildLocator,bool);
386 
387 protected:
390 
391  // Selection tolerance for the handles
394 
397 
399 
402 
403  // A flag to indicate whether to show the Selected nodes
405 
407 
408  void AddNodeAtPositionInternal( double worldPos[3],
409  double worldOrient[9], int displayPos[2] );
410  void AddNodeAtPositionInternal( double worldPos[3],
411  double worldOrient[9], double displayPos[2] );
412  void SetNthNodeWorldPositionInternal( int n, double worldPos[3],
413  double worldOrient[9] );
414 
416 
418  void GetRendererComputedDisplayPositionFromWorldPosition( double worldPos[3],
419  double worldOrient[9], int displayPos[2] );
420  void GetRendererComputedDisplayPositionFromWorldPosition( double worldPos[3],
421  double worldOrient[9], double displayPos[2] );
423 
424  virtual void UpdateLines( int index );
425  void UpdateLine( int idx1, int idx2 );
426 
427  virtual int FindClosestPointOnContour( int X, int Y,
428  double worldPos[3],
429  int *idx );
430 
431  virtual void BuildLines()=0;
432 
433  // This method is called when something changes in the point
434  // placer. It will cause all points to
435  // be updates, and all lines to be regenerated.
436  // Should be extended to detect changes in the line interpolator
437  // too.
438  virtual int UpdateContour();
440 
441  void ComputeMidpoint( double p1[3], double p2[3], double mid[3] )
442  {
443  mid[0] = (p1[0] + p2[0])/2;
444  mid[1] = (p1[1] + p2[1])/2;
445  mid[2] = (p1[2] + p2[2])/2;
446  }
447 
457  virtual void Initialize( vtkPolyData *, vtkIdList *);
458 
461  virtual void Initialize( vtkPolyData *);
462 
466  virtual void InitializeContour( vtkPolyData *, vtkIdList * );
467 
471 
474  void ResetLocator();
475 
476  void BuildLocator();
477 
479 
480 
481 private:
482  vtkContourRepresentation(const vtkContourRepresentation&); //Not implemented
483  void operator=(const vtkContourRepresentation&); //Not implemented
484 };
485 
486 #endif
487 
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:140
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:247
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:84
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.