VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: $RCSfile: vtkContourRepresentation.h,v $ 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00056 #ifndef __vtkContourRepresentation_h 00057 #define __vtkContourRepresentation_h 00058 00059 #include "vtkWidgetRepresentation.h" 00060 #include <vtkstd/vector> // Required for vector 00061 00062 class vtkContourLineInterpolator; 00063 class vtkPointPlacer; 00064 class vtkPolyData; 00065 00066 //---------------------------------------------------------------------- 00067 //BTX 00068 class vtkContourRepresentationPoint 00069 { 00070 public: 00071 double WorldPosition[3]; 00072 double NormalizedDisplayPosition[2]; 00073 }; 00074 00075 class vtkContourRepresentationNode 00076 { 00077 public: 00078 double WorldPosition[3]; 00079 double WorldOrientation[9]; 00080 double NormalizedDisplayPosition[2]; 00081 vtkstd::vector<vtkContourRepresentationPoint*> Points; 00082 }; 00083 00084 class vtkContourRepresentationInternals 00085 { 00086 public: 00087 vtkstd::vector<vtkContourRepresentationNode*> Nodes; 00088 }; 00089 //ETX 00090 00091 class VTK_WIDGETS_EXPORT vtkContourRepresentation : public vtkWidgetRepresentation 00092 { 00093 //BTX 00094 friend class vtkContourWidget; 00095 //ETX 00096 public: 00098 00099 vtkTypeRevisionMacro(vtkContourRepresentation,vtkWidgetRepresentation); 00100 void PrintSelf(ostream& os, vtkIndent indent); 00102 00104 00106 virtual int AddNodeAtWorldPosition( double worldPos[3] ); 00107 virtual int AddNodeAtWorldPosition( double worldPos[3], 00108 double worldOrient[9] ); 00110 00112 00115 virtual int AddNodeAtDisplayPosition( double displayPos[2] ); 00116 virtual int AddNodeAtDisplayPosition( int displayPos[2] ); 00117 virtual int AddNodeAtDisplayPosition( int X, int Y ); 00119 00121 00124 virtual int ActivateNode( double displayPos[2] ); 00125 virtual int ActivateNode( int displayPos[2] ); 00126 virtual int ActivateNode( int X, int Y ); 00128 00129 // Descirption: 00130 // Move the active node to a specified world position. 00131 // Will return 0 if there is no active node or the node 00132 // could not be moved to that position. 1 will be returned 00133 // on success. 00134 virtual int SetActiveNodeToWorldPosition( double pos[3] ); 00135 virtual int SetActiveNodeToWorldPosition( double pos[3], 00136 double orient[9] ); 00137 00139 00143 virtual int SetActiveNodeToDisplayPosition( double pos[2] ); 00144 virtual int SetActiveNodeToDisplayPosition( int pos[2] ); 00145 virtual int SetActiveNodeToDisplayPosition( int X, int Y ); 00147 00150 virtual int GetActiveNodeWorldPosition( double pos[3] ); 00151 00154 virtual int GetActiveNodeWorldOrientation( double orient[9] ); 00155 00158 virtual int GetActiveNodeDisplayPosition( double pos[2] ); 00159 00161 virtual int GetNumberOfNodes(); 00162 00165 virtual int GetNthNodeDisplayPosition( int n, double pos[2] ); 00166 00169 virtual int GetNthNodeWorldPosition( int n, double pos[3] ); 00170 00173 virtual int GetNthNodeWorldOrientation( int n, double orient[9] ); 00174 00176 00181 virtual int SetNthNodeDisplayPosition( int n, int X, int Y ); 00182 virtual int SetNthNodeDisplayPosition( int n, int pos[2] ); 00183 virtual int SetNthNodeDisplayPosition( int n, double pos[2] ); 00185 00187 00190 virtual int SetNthNodeWorldPosition( int n, double pos[3] ); 00191 virtual int SetNthNodeWorldPosition( int n, double pos[3], 00192 double orient[9] ); 00194 00197 virtual int GetNthNodeSlope( int idx, double slope[3] ); 00198 00199 // Descirption: 00200 // For a given node n, get the number of intermediate 00201 // points between this node and the node at 00202 // (n+1). If n is the last node and the loop is 00203 // closed, this is the number of intermediate points 00204 // between node n and node 0. 0 is returned if n is 00205 // out of range. 00206 virtual int GetNumberOfIntermediatePoints( int n ); 00207 00209 00212 virtual int GetIntermediatePointWorldPosition( int n, 00213 int idx, double point[3] ); 00215 00217 00220 virtual int AddIntermediatePointWorldPosition( int n, 00221 double point[3] ); 00223 00226 virtual int DeleteLastNode(); 00227 00230 virtual int DeleteActiveNode(); 00231 00233 virtual int DeleteNthNode( int n ); 00234 00237 virtual int AddNodeOnContour( int X, int Y ); 00238 00240 00242 vtkSetClampMacro(PixelTolerance,int,1,100); 00243 vtkGetMacro(PixelTolerance,int); 00245 00247 00249 vtkSetClampMacro(WorldTolerance, double, 0.0, VTK_DOUBLE_MAX); 00250 vtkGetMacro(WorldTolerance, double); 00252 00253 //BTX -- used to communicate about the state of the representation 00254 enum { 00255 Outside=0, 00256 Nearby 00257 }; 00258 00259 enum { 00260 Inactive = 0, 00261 Translate, 00262 Shift, 00263 Scale 00264 }; 00265 //ETX 00266 00268 00270 vtkGetMacro( CurrentOperation, int ); 00271 vtkSetClampMacro( CurrentOperation, int, 00272 vtkContourRepresentation::Inactive, 00273 vtkContourRepresentation::Scale ); 00274 void SetCurrentOperationToInactive() 00275 { this->SetCurrentOperation( vtkContourRepresentation::Inactive ); } 00276 void SetCurrentOperationToTranslate() 00277 { this->SetCurrentOperation( vtkContourRepresentation::Translate ); } 00278 void SetCurrentOperationToShift() 00279 {this->SetCurrentOperation( vtkContourRepresentation::Shift ); } 00280 void SetCurrentOperationToScale() 00281 {this->SetCurrentOperation( vtkContourRepresentation::Scale ); } 00283 00284 // Descirption: 00285 // Set / get the Point Placer. The point placer is 00286 // responsible for converting display coordinates into 00287 // world coordinates according to some constraints, and 00288 // for validating world positions. 00289 void SetPointPlacer( vtkPointPlacer * ); 00290 vtkGetObjectMacro( PointPlacer, vtkPointPlacer ); 00291 00293 00295 void SetLineInterpolator( vtkContourLineInterpolator *); 00296 vtkGetObjectMacro( LineInterpolator, vtkContourLineInterpolator ); 00298 00300 00301 virtual void BuildRepresentation()=0; 00302 virtual int ComputeInteractionState(int X, int Y, int modified=0)=0; 00303 virtual void StartWidgetInteraction(double e[2])=0; 00304 virtual void WidgetInteraction(double e[2])=0; 00306 00308 00309 virtual void ReleaseGraphicsResources(vtkWindow *w)=0; 00310 virtual int RenderOverlay(vtkViewport *viewport)=0; 00311 virtual int RenderOpaqueGeometry(vtkViewport *viewport)=0; 00312 virtual int RenderTranslucentPolygonalGeometry(vtkViewport *viewport)=0; 00313 virtual int HasTranslucentPolygonalGeometry()=0; 00315 00317 00319 void SetClosedLoop( int val ); 00320 vtkGetMacro( ClosedLoop, int ); 00321 vtkBooleanMacro( ClosedLoop, int ); 00323 00325 00326 virtual vtkPolyData* GetContourRepresentationAsPolyData() = 0; 00327 //ETX 00329 00332 void GetNodePolyData( vtkPolyData* poly ); 00333 00334 protected: 00335 vtkContourRepresentation(); 00336 ~vtkContourRepresentation(); 00337 00338 // Selection tolerance for the handles 00339 int PixelTolerance; 00340 double WorldTolerance; 00341 00342 vtkPointPlacer *PointPlacer; 00343 vtkContourLineInterpolator *LineInterpolator; 00344 00345 int ActiveNode; 00346 00347 int CurrentOperation; 00348 int ClosedLoop; 00349 00350 vtkContourRepresentationInternals *Internal; 00351 00352 void AddNodeAtPositionInternal( double worldPos[3], 00353 double worldOrient[9], int displayPos[2] ); 00354 void AddNodeAtPositionInternal( double worldPos[3], 00355 double worldOrient[9], double displayPos[2] ); 00356 void SetNthNodeWorldPositionInternal( int n, double worldPos[3], 00357 double worldOrient[9] ); 00358 00360 00362 void GetRendererComputedDisplayPositionFromWorldPosition( double worldPos[3], 00363 double worldOrient[9], int displayPos[2] ); 00364 void GetRendererComputedDisplayPositionFromWorldPosition( double worldPos[3], 00365 double worldOrient[9], double displayPos[2] ); 00367 00368 void UpdateLines( int index ); 00369 void UpdateLine( int idx1, int idx2 ); 00370 00371 virtual int FindClosestPointOnContour( int X, int Y, 00372 double worldPos[3], 00373 int *idx ); 00374 00375 virtual void BuildLines()=0; 00376 00377 // This method is called when something changes in the point 00378 // placer. It will cause all points to 00379 // be updates, and all lines to be regenerated. 00380 // Should be extended to detect changes in the line interpolator 00381 // too. 00382 virtual int UpdateContour(); 00383 vtkTimeStamp ContourBuildTime; 00384 00385 void ComputeMidpoint( double p1[3], double p2[3], double mid[3] ) 00386 { 00387 mid[0] = (p1[0] + p2[0])/2; 00388 mid[1] = (p1[1] + p2[1])/2; 00389 mid[2] = (p1[2] + p2[2])/2; 00390 } 00391 00398 virtual void Initialize( vtkPolyData * ); 00399 00400 private: 00401 vtkContourRepresentation(const vtkContourRepresentation&); //Not implemented 00402 void operator=(const vtkContourRepresentation&); //Not implemented 00403 }; 00404 00405 #endif 00406