VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkContourRepresentation.h 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> // STL Header; 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 int Selected; 00082 vtkstd::vector<vtkContourRepresentationPoint*> Points; 00083 }; 00084 00085 class vtkContourRepresentationInternals 00086 { 00087 public: 00088 vtkstd::vector<vtkContourRepresentationNode*> Nodes; 00089 void ClearNodes() 00090 { 00091 for(unsigned int i=0;i<this->Nodes.size();i++) 00092 { 00093 for (unsigned int j=0;j<this->Nodes[i]->Points.size();j++) 00094 { 00095 delete this->Nodes[i]->Points[j]; 00096 } 00097 this->Nodes[i]->Points.clear(); 00098 delete this->Nodes[i]; 00099 } 00100 this->Nodes.clear(); 00101 } 00102 }; 00103 //ETX 00104 00105 class VTK_WIDGETS_EXPORT vtkContourRepresentation : public vtkWidgetRepresentation 00106 { 00107 //BTX 00108 friend class vtkContourWidget; 00109 //ETX 00110 public: 00112 00113 vtkTypeMacro(vtkContourRepresentation,vtkWidgetRepresentation); 00114 void PrintSelf(ostream& os, vtkIndent indent); 00116 00118 00120 virtual int AddNodeAtWorldPosition( double x, double y, double z); 00121 virtual int AddNodeAtWorldPosition( double worldPos[3] ); 00122 virtual int AddNodeAtWorldPosition( double worldPos[3], 00123 double worldOrient[9] ); 00125 00127 00130 virtual int AddNodeAtDisplayPosition( double displayPos[2] ); 00131 virtual int AddNodeAtDisplayPosition( int displayPos[2] ); 00132 virtual int AddNodeAtDisplayPosition( int X, int Y ); 00134 00136 00139 virtual int ActivateNode( double displayPos[2] ); 00140 virtual int ActivateNode( int displayPos[2] ); 00141 virtual int ActivateNode( int X, int Y ); 00143 00144 // Descirption: 00145 // Move the active node to a specified world position. 00146 // Will return 0 if there is no active node or the node 00147 // could not be moved to that position. 1 will be returned 00148 // on success. 00149 virtual int SetActiveNodeToWorldPosition( double pos[3] ); 00150 virtual int SetActiveNodeToWorldPosition( double pos[3], 00151 double orient[9] ); 00152 00154 00158 virtual int SetActiveNodeToDisplayPosition( double pos[2] ); 00159 virtual int SetActiveNodeToDisplayPosition( int pos[2] ); 00160 virtual int SetActiveNodeToDisplayPosition( int X, int Y ); 00162 00164 00165 virtual int ToggleActiveNodeSelected(); 00166 virtual int GetActiveNodeSelected(); 00167 virtual int GetNthNodeSelected(int); 00168 virtual int SetNthNodeSelected(int); 00170 00173 virtual int GetActiveNodeWorldPosition( double pos[3] ); 00174 00177 virtual int GetActiveNodeWorldOrientation( double orient[9] ); 00178 00181 virtual int GetActiveNodeDisplayPosition( double pos[2] ); 00182 00184 virtual int GetNumberOfNodes(); 00185 00188 virtual int GetNthNodeDisplayPosition( int n, double pos[2] ); 00189 00192 virtual int GetNthNodeWorldPosition( int n, double pos[3] ); 00193 00196 virtual int GetNthNodeWorldOrientation( int n, double orient[9] ); 00197 00199 00204 virtual int SetNthNodeDisplayPosition( int n, int X, int Y ); 00205 virtual int SetNthNodeDisplayPosition( int n, int pos[2] ); 00206 virtual int SetNthNodeDisplayPosition( int n, double pos[2] ); 00208 00210 00213 virtual int SetNthNodeWorldPosition( int n, double pos[3] ); 00214 virtual int SetNthNodeWorldPosition( int n, double pos[3], 00215 double orient[9] ); 00217 00220 virtual int GetNthNodeSlope( int idx, double slope[3] ); 00221 00222 // Descirption: 00223 // For a given node n, get the number of intermediate 00224 // points between this node and the node at 00225 // (n+1). If n is the last node and the loop is 00226 // closed, this is the number of intermediate points 00227 // between node n and node 0. 0 is returned if n is 00228 // out of range. 00229 virtual int GetNumberOfIntermediatePoints( int n ); 00230 00232 00235 virtual int GetIntermediatePointWorldPosition( int n, 00236 int idx, double point[3] ); 00238 00240 00243 virtual int AddIntermediatePointWorldPosition( int n, 00244 double point[3] ); 00246 00249 virtual int DeleteLastNode(); 00250 00253 virtual int DeleteActiveNode(); 00254 00256 virtual int DeleteNthNode( int n ); 00257 00259 virtual void ClearAllNodes(); 00260 00263 virtual int AddNodeOnContour( int X, int Y ); 00264 00266 00268 vtkSetClampMacro(PixelTolerance,int,1,100); 00269 vtkGetMacro(PixelTolerance,int); 00271 00273 00275 vtkSetClampMacro(WorldTolerance, double, 0.0, VTK_DOUBLE_MAX); 00276 vtkGetMacro(WorldTolerance, double); 00278 00279 //BTX -- used to communicate about the state of the representation 00280 enum { 00281 Outside=0, 00282 Nearby 00283 }; 00284 00285 enum { 00286 Inactive = 0, 00287 Translate, 00288 Shift, 00289 Scale 00290 }; 00291 //ETX 00292 00294 00296 vtkGetMacro( CurrentOperation, int ); 00297 vtkSetClampMacro( CurrentOperation, int, 00298 vtkContourRepresentation::Inactive, 00299 vtkContourRepresentation::Scale ); 00300 void SetCurrentOperationToInactive() 00301 { this->SetCurrentOperation( vtkContourRepresentation::Inactive ); } 00302 void SetCurrentOperationToTranslate() 00303 { this->SetCurrentOperation( vtkContourRepresentation::Translate ); } 00304 void SetCurrentOperationToShift() 00305 {this->SetCurrentOperation( vtkContourRepresentation::Shift ); } 00306 void SetCurrentOperationToScale() 00307 {this->SetCurrentOperation( vtkContourRepresentation::Scale ); } 00309 00310 // Descirption: 00311 // Set / get the Point Placer. The point placer is 00312 // responsible for converting display coordinates into 00313 // world coordinates according to some constraints, and 00314 // for validating world positions. 00315 void SetPointPlacer( vtkPointPlacer * ); 00316 vtkGetObjectMacro( PointPlacer, vtkPointPlacer ); 00317 00319 00321 void SetLineInterpolator( vtkContourLineInterpolator *); 00322 vtkGetObjectMacro( LineInterpolator, vtkContourLineInterpolator ); 00324 00326 00327 virtual void BuildRepresentation()=0; 00328 virtual int ComputeInteractionState(int X, int Y, int modified=0)=0; 00329 virtual void StartWidgetInteraction(double e[2])=0; 00330 virtual void WidgetInteraction(double e[2])=0; 00332 00334 00335 virtual void ReleaseGraphicsResources(vtkWindow *w)=0; 00336 virtual int RenderOverlay(vtkViewport *viewport)=0; 00337 virtual int RenderOpaqueGeometry(vtkViewport *viewport)=0; 00338 virtual int RenderTranslucentPolygonalGeometry(vtkViewport *viewport)=0; 00339 virtual int HasTranslucentPolygonalGeometry()=0; 00341 00343 00345 void SetClosedLoop( int val ); 00346 vtkGetMacro( ClosedLoop, int ); 00347 vtkBooleanMacro( ClosedLoop, int ); 00349 00351 00353 virtual void SetShowSelectedNodes(int); 00354 vtkGetMacro( ShowSelectedNodes, int ); 00355 vtkBooleanMacro( ShowSelectedNodes, int ); 00357 00359 00360 virtual vtkPolyData* GetContourRepresentationAsPolyData() = 0; 00361 //ETX 00363 00366 void GetNodePolyData( vtkPolyData* poly ); 00367 00368 00369 protected: 00370 vtkContourRepresentation(); 00371 ~vtkContourRepresentation(); 00372 00373 // Selection tolerance for the handles 00374 int PixelTolerance; 00375 double WorldTolerance; 00376 00377 vtkPointPlacer *PointPlacer; 00378 vtkContourLineInterpolator *LineInterpolator; 00379 00380 int ActiveNode; 00381 00382 int CurrentOperation; 00383 int ClosedLoop; 00384 00385 // A flag to indicate whether to show the Selected nodes 00386 int ShowSelectedNodes; 00387 00388 vtkContourRepresentationInternals *Internal; 00389 00390 void AddNodeAtPositionInternal( double worldPos[3], 00391 double worldOrient[9], int displayPos[2] ); 00392 void AddNodeAtPositionInternal( double worldPos[3], 00393 double worldOrient[9], double displayPos[2] ); 00394 void SetNthNodeWorldPositionInternal( int n, double worldPos[3], 00395 double worldOrient[9] ); 00396 00398 00400 void GetRendererComputedDisplayPositionFromWorldPosition( double worldPos[3], 00401 double worldOrient[9], int displayPos[2] ); 00402 void GetRendererComputedDisplayPositionFromWorldPosition( double worldPos[3], 00403 double worldOrient[9], double displayPos[2] ); 00405 00406 void UpdateLines( int index ); 00407 void UpdateLine( int idx1, int idx2 ); 00408 00409 virtual int FindClosestPointOnContour( int X, int Y, 00410 double worldPos[3], 00411 int *idx ); 00412 00413 virtual void BuildLines()=0; 00414 00415 // This method is called when something changes in the point 00416 // placer. It will cause all points to 00417 // be updates, and all lines to be regenerated. 00418 // Should be extended to detect changes in the line interpolator 00419 // too. 00420 virtual int UpdateContour(); 00421 vtkTimeStamp ContourBuildTime; 00422 00423 void ComputeMidpoint( double p1[3], double p2[3], double mid[3] ) 00424 { 00425 mid[0] = (p1[0] + p2[0])/2; 00426 mid[1] = (p1[1] + p2[1])/2; 00427 mid[2] = (p1[2] + p2[2])/2; 00428 } 00429 00436 virtual void Initialize( vtkPolyData * ); 00437 00438 private: 00439 vtkContourRepresentation(const vtkContourRepresentation&); //Not implemented 00440 void operator=(const vtkContourRepresentation&); //Not implemented 00441 }; 00442 00443 #endif 00444