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 =========================================================================*/ 00059 #ifndef __vtkContourRepresentation_h 00060 #define __vtkContourRepresentation_h 00061 00062 #include "vtkWidgetRepresentation.h" 00063 #include <vector> // STL Header; Required for vector 00064 00065 class vtkContourLineInterpolator; 00066 class vtkIncrementalOctreePointLocator; 00067 class vtkPointPlacer; 00068 class vtkPolyData; 00069 class vtkIdList; 00070 00071 //---------------------------------------------------------------------- 00072 //BTX 00073 class vtkContourRepresentationPoint 00074 { 00075 public: 00076 double WorldPosition[3]; 00077 double NormalizedDisplayPosition[2]; 00078 00079 // The point id. This is blank except in the case of 00080 // vtkPolygonalSurfaceContourLineInterpolator 00081 vtkIdType PointId; 00082 }; 00083 00084 class vtkContourRepresentationNode 00085 { 00086 public: 00087 double WorldPosition[3]; 00088 double WorldOrientation[9]; 00089 double NormalizedDisplayPosition[2]; 00090 int Selected; 00091 std::vector<vtkContourRepresentationPoint*> Points; 00092 00093 // The point id. This is blank except in the case of 00094 // vtkPolygonalSurfaceContourLineInterpolator 00095 vtkIdType PointId; 00096 }; 00097 00098 class vtkContourRepresentationInternals 00099 { 00100 public: 00101 std::vector<vtkContourRepresentationNode*> Nodes; 00102 void ClearNodes() 00103 { 00104 for(unsigned int i=0;i<this->Nodes.size();i++) 00105 { 00106 for (unsigned int j=0;j<this->Nodes[i]->Points.size();j++) 00107 { 00108 delete this->Nodes[i]->Points[j]; 00109 } 00110 this->Nodes[i]->Points.clear(); 00111 delete this->Nodes[i]; 00112 } 00113 this->Nodes.clear(); 00114 } 00115 }; 00116 //ETX 00117 00118 class VTK_WIDGETS_EXPORT vtkContourRepresentation : public vtkWidgetRepresentation 00119 { 00120 //BTX 00121 friend class vtkContourWidget; 00122 //ETX 00123 public: 00125 00126 vtkTypeMacro(vtkContourRepresentation,vtkWidgetRepresentation); 00127 void PrintSelf(ostream& os, vtkIndent indent); 00129 00131 00133 virtual int AddNodeAtWorldPosition( double x, double y, double z); 00134 virtual int AddNodeAtWorldPosition( double worldPos[3] ); 00135 virtual int AddNodeAtWorldPosition( double worldPos[3], 00136 double worldOrient[9] ); 00138 00140 00143 virtual int AddNodeAtDisplayPosition( double displayPos[2] ); 00144 virtual int AddNodeAtDisplayPosition( int displayPos[2] ); 00145 virtual int AddNodeAtDisplayPosition( int X, int Y ); 00147 00149 00152 virtual int ActivateNode( double displayPos[2] ); 00153 virtual int ActivateNode( int displayPos[2] ); 00154 virtual int ActivateNode( int X, int Y ); 00156 00157 // Descirption: 00158 // Move the active node to a specified world position. 00159 // Will return 0 if there is no active node or the node 00160 // could not be moved to that position. 1 will be returned 00161 // on success. 00162 virtual int SetActiveNodeToWorldPosition( double pos[3] ); 00163 virtual int SetActiveNodeToWorldPosition( double pos[3], 00164 double orient[9] ); 00165 00167 00171 virtual int SetActiveNodeToDisplayPosition( double pos[2] ); 00172 virtual int SetActiveNodeToDisplayPosition( int pos[2] ); 00173 virtual int SetActiveNodeToDisplayPosition( int X, int Y ); 00175 00177 00178 virtual int ToggleActiveNodeSelected(); 00179 virtual int GetActiveNodeSelected(); 00180 virtual int GetNthNodeSelected(int); 00181 virtual int SetNthNodeSelected(int); 00183 00186 virtual int GetActiveNodeWorldPosition( double pos[3] ); 00187 00190 virtual int GetActiveNodeWorldOrientation( double orient[9] ); 00191 00194 virtual int GetActiveNodeDisplayPosition( double pos[2] ); 00195 00197 virtual int GetNumberOfNodes(); 00198 00201 virtual int GetNthNodeDisplayPosition( int n, double pos[2] ); 00202 00205 virtual int GetNthNodeWorldPosition( int n, double pos[3] ); 00206 00207 //BTX 00209 00210 virtual vtkContourRepresentationNode *GetNthNode(int n); 00211 //ETX 00213 00216 virtual int GetNthNodeWorldOrientation( int n, double orient[9] ); 00217 00219 00224 virtual int SetNthNodeDisplayPosition( int n, int X, int Y ); 00225 virtual int SetNthNodeDisplayPosition( int n, int pos[2] ); 00226 virtual int SetNthNodeDisplayPosition( int n, double pos[2] ); 00228 00230 00233 virtual int SetNthNodeWorldPosition( int n, double pos[3] ); 00234 virtual int SetNthNodeWorldPosition( int n, double pos[3], 00235 double orient[9] ); 00237 00240 virtual int GetNthNodeSlope( int idx, double slope[3] ); 00241 00242 // Descirption: 00243 // For a given node n, get the number of intermediate 00244 // points between this node and the node at 00245 // (n+1). If n is the last node and the loop is 00246 // closed, this is the number of intermediate points 00247 // between node n and node 0. 0 is returned if n is 00248 // out of range. 00249 virtual int GetNumberOfIntermediatePoints( int n ); 00250 00252 00255 virtual int GetIntermediatePointWorldPosition( int n, 00256 int idx, double point[3] ); 00258 00260 00263 virtual int AddIntermediatePointWorldPosition( int n, 00264 double point[3] ); 00266 00268 00271 virtual int AddIntermediatePointWorldPosition( int n, 00272 double point[3], vtkIdType ptId ); 00274 00277 virtual int DeleteLastNode(); 00278 00281 virtual int DeleteActiveNode(); 00282 00284 virtual int DeleteNthNode( int n ); 00285 00287 virtual void ClearAllNodes(); 00288 00291 virtual int AddNodeOnContour( int X, int Y ); 00292 00294 00296 vtkSetClampMacro(PixelTolerance,int,1,100); 00297 vtkGetMacro(PixelTolerance,int); 00299 00301 00303 vtkSetClampMacro(WorldTolerance, double, 0.0, VTK_DOUBLE_MAX); 00304 vtkGetMacro(WorldTolerance, double); 00306 00307 //BTX -- used to communicate about the state of the representation 00308 enum { 00309 Outside=0, 00310 Nearby 00311 }; 00312 00313 enum { 00314 Inactive = 0, 00315 Translate, 00316 Shift, 00317 Scale 00318 }; 00319 //ETX 00320 00322 00324 vtkGetMacro( CurrentOperation, int ); 00325 vtkSetClampMacro( CurrentOperation, int, 00326 vtkContourRepresentation::Inactive, 00327 vtkContourRepresentation::Scale ); 00328 void SetCurrentOperationToInactive() 00329 { this->SetCurrentOperation( vtkContourRepresentation::Inactive ); } 00330 void SetCurrentOperationToTranslate() 00331 { this->SetCurrentOperation( vtkContourRepresentation::Translate ); } 00332 void SetCurrentOperationToShift() 00333 {this->SetCurrentOperation( vtkContourRepresentation::Shift ); } 00334 void SetCurrentOperationToScale() 00335 {this->SetCurrentOperation( vtkContourRepresentation::Scale ); } 00337 00338 // Descirption: 00339 // Set / get the Point Placer. The point placer is 00340 // responsible for converting display coordinates into 00341 // world coordinates according to some constraints, and 00342 // for validating world positions. 00343 void SetPointPlacer( vtkPointPlacer * ); 00344 vtkGetObjectMacro( PointPlacer, vtkPointPlacer ); 00345 00347 00349 void SetLineInterpolator( vtkContourLineInterpolator *); 00350 vtkGetObjectMacro( LineInterpolator, vtkContourLineInterpolator ); 00352 00354 00355 virtual void BuildRepresentation()=0; 00356 virtual int ComputeInteractionState(int X, int Y, int modified=0)=0; 00357 virtual void StartWidgetInteraction(double e[2])=0; 00358 virtual void WidgetInteraction(double e[2])=0; 00360 00362 00363 virtual void ReleaseGraphicsResources(vtkWindow *w)=0; 00364 virtual int RenderOverlay(vtkViewport *viewport)=0; 00365 virtual int RenderOpaqueGeometry(vtkViewport *viewport)=0; 00366 virtual int RenderTranslucentPolygonalGeometry(vtkViewport *viewport)=0; 00367 virtual int HasTranslucentPolygonalGeometry()=0; 00369 00371 00373 void SetClosedLoop( int val ); 00374 vtkGetMacro( ClosedLoop, int ); 00375 vtkBooleanMacro( ClosedLoop, int ); 00377 00379 00381 virtual void SetShowSelectedNodes(int); 00382 vtkGetMacro( ShowSelectedNodes, int ); 00383 vtkBooleanMacro( ShowSelectedNodes, int ); 00385 00386 //BTX 00388 00389 virtual vtkPolyData* GetContourRepresentationAsPolyData() = 0; 00390 //ETX 00392 00395 void GetNodePolyData( vtkPolyData* poly ); 00396 00397 vtkSetMacro(RebuildLocator,bool); 00398 00399 protected: 00400 vtkContourRepresentation(); 00401 ~vtkContourRepresentation(); 00402 00403 // Selection tolerance for the handles 00404 int PixelTolerance; 00405 double WorldTolerance; 00406 00407 vtkPointPlacer *PointPlacer; 00408 vtkContourLineInterpolator *LineInterpolator; 00409 00410 int ActiveNode; 00411 00412 int CurrentOperation; 00413 int ClosedLoop; 00414 00415 // A flag to indicate whether to show the Selected nodes 00416 int ShowSelectedNodes; 00417 00418 vtkContourRepresentationInternals *Internal; 00419 00420 void AddNodeAtPositionInternal( double worldPos[3], 00421 double worldOrient[9], int displayPos[2] ); 00422 void AddNodeAtPositionInternal( double worldPos[3], 00423 double worldOrient[9], double displayPos[2] ); 00424 void SetNthNodeWorldPositionInternal( int n, double worldPos[3], 00425 double worldOrient[9] ); 00426 00428 00430 void GetRendererComputedDisplayPositionFromWorldPosition( double worldPos[3], 00431 double worldOrient[9], int displayPos[2] ); 00432 void GetRendererComputedDisplayPositionFromWorldPosition( double worldPos[3], 00433 double worldOrient[9], double displayPos[2] ); 00435 00436 virtual void UpdateLines( int index ); 00437 void UpdateLine( int idx1, int idx2 ); 00438 00439 virtual int FindClosestPointOnContour( int X, int Y, 00440 double worldPos[3], 00441 int *idx ); 00442 00443 virtual void BuildLines()=0; 00444 00445 // This method is called when something changes in the point 00446 // placer. It will cause all points to 00447 // be updates, and all lines to be regenerated. 00448 // Should be extended to detect changes in the line interpolator 00449 // too. 00450 virtual int UpdateContour(); 00451 vtkTimeStamp ContourBuildTime; 00452 00453 void ComputeMidpoint( double p1[3], double p2[3], double mid[3] ) 00454 { 00455 mid[0] = (p1[0] + p2[0])/2; 00456 mid[1] = (p1[1] + p2[1])/2; 00457 mid[2] = (p1[2] + p2[2])/2; 00458 } 00459 00469 void Initialize( vtkPolyData *, vtkIdList *); 00470 00473 virtual void Initialize( vtkPolyData *); 00474 00477 vtkIncrementalOctreePointLocator *Locator; 00478 00481 void ResetLocator(); 00482 00483 void BuildLocator(); 00484 00485 bool RebuildLocator; 00486 00487 00488 private: 00489 vtkContourRepresentation(const vtkContourRepresentation&); //Not implemented 00490 void operator=(const vtkContourRepresentation&); //Not implemented 00491 }; 00492 00493 #endif 00494