Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

Common/vtkPolyData.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkPolyData.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 =========================================================================*/
00042 #ifndef __vtkPolyData_h
00043 #define __vtkPolyData_h
00044 
00045 #include "vtkPointSet.h"
00046 
00047 #include "vtkCellTypes.h" // Needed for inline methods
00048 #include "vtkCellLinks.h" // Needed for inline methods
00049 
00050 class vtkVertex;
00051 class vtkPolyVertex;
00052 class vtkLine;
00053 class vtkPolyLine;
00054 class vtkTriangle;
00055 class vtkQuad;
00056 class vtkPolygon;
00057 class vtkTriangleStrip;
00058 class vtkEmptyCell;
00059 
00060 class VTK_COMMON_EXPORT vtkPolyData : public vtkPointSet 
00061 {
00062 public:
00063   static vtkPolyData *New();
00064 
00065   vtkTypeRevisionMacro(vtkPolyData,vtkPointSet);
00066   void PrintSelf(ostream& os, vtkIndent indent);
00067 
00069   int GetDataObjectType() {return VTK_POLY_DATA;}
00070 
00073   void CopyStructure(vtkDataSet *ds);
00074 
00076 
00077   vtkIdType GetNumberOfCells();
00078   vtkCell *GetCell(vtkIdType cellId);
00079   void GetCell(vtkIdType cellId, vtkGenericCell *cell);
00080   int GetCellType(vtkIdType cellId);
00081   void GetCellBounds(vtkIdType cellId, double bounds[6]);
00082   void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds,
00083                         vtkIdList *cellIds);
00085   
00087 
00091   void CopyCells(vtkPolyData *pd, vtkIdList *idList,
00092                  vtkPointLocator *locator = NULL);
00094   
00096   void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds);
00097 
00100   void GetPointCells(vtkIdType ptId, vtkIdList *cellIds);
00101 
00103   void ComputeBounds();
00104   
00109   void Squeeze();
00110 
00112   int GetMaxCellSize();
00113 
00115   void SetVerts (vtkCellArray* v);
00116 
00119   vtkCellArray *GetVerts();
00120 
00122   void SetLines (vtkCellArray* l);
00123 
00126   vtkCellArray *GetLines();
00127 
00129   void SetPolys (vtkCellArray* p);
00130 
00133   vtkCellArray *GetPolys();
00134   
00136   void SetStrips (vtkCellArray* s);
00137 
00141   vtkCellArray *GetStrips();
00142 
00144 
00145   vtkIdType GetNumberOfVerts();
00146   vtkIdType GetNumberOfLines();
00147   vtkIdType GetNumberOfPolys();
00148   vtkIdType GetNumberOfStrips();
00150 
00155   void Allocate(vtkIdType numCells=1000, int extSize=1000);
00156 
00158 
00167   void Allocate(vtkPolyData *inPolyData, vtkIdType numCells=1000, 
00168                 int extSize=1000);
00170 
00177   int InsertNextCell(int type, int npts, vtkIdType *pts);
00178 
00185   int InsertNextCell(int type, vtkIdList *pts);
00186 
00189   void Reset();
00190 
00192   void BuildCells();
00193 
00199   void BuildLinks(int initialSize=0);
00200 
00204   void DeleteCells();
00205 
00207   void DeleteLinks();
00208   
00210 
00211   void GetPointCells(vtkIdType ptId, unsigned short& ncells,
00212                      vtkIdType* &cells);
00214 
00216 
00219   void GetCellEdgeNeighbors(vtkIdType cellId, vtkIdType p1, vtkIdType p2,
00220                             vtkIdList *cellIds);
00222 
00225   void GetCellPoints(vtkIdType cellId, vtkIdType& npts, vtkIdType* &pts);
00226 
00229   int IsTriangle(int v1, int v2, int v3);
00230 
00236   int IsEdge(vtkIdType p1, vtkIdType p2);
00237 
00240   int IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId);
00241 
00247   void ReplaceCell(vtkIdType cellId, int npts, vtkIdType *pts);
00248 
00250 
00251   void ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId,
00252                         vtkIdType newPtId);
00254   
00256   void ReverseCell(vtkIdType cellId);
00257 
00259 
00260   void DeletePoint(vtkIdType ptId);
00261   void DeleteCell(vtkIdType cellId);
00263 
00265 
00271   int InsertNextLinkedPoint(int numLinks); 
00272   int InsertNextLinkedPoint(double x[3], int numLinks); 
00274   
00278   int InsertNextLinkedCell(int type, int npts, vtkIdType *pts); 
00279 
00286   void ReplaceLinkedCell(vtkIdType cellId, int npts, vtkIdType *pts);
00287 
00293   void RemoveCellReference(vtkIdType cellId);
00294 
00300   void AddCellReference(vtkIdType cellId);
00301 
00307   void RemoveReferenceToCell(vtkIdType ptId, vtkIdType cellId);
00308 
00313   void AddReferenceToCell(vtkIdType ptId, vtkIdType cellId);
00314 
00317   void ResizeCellList(vtkIdType ptId, int size);
00318 
00320   virtual void Initialize();
00321 
00323 
00326   void SetUpdateExtent(int piece, int numPieces, int ghostLevel);
00327   void SetUpdateExtent(int piece, int numPieces)
00328     {this->SetUpdateExtent(piece, numPieces, 0);}
00329   void GetUpdateExtent(int &piece, int &numPieces, int &ghostLevel);
00331 
00333 
00334   vtkGetVector6Macro( UpdateExtent, int );
00336 
00338 
00342   void SetUpdateExtent( int x1, int x2, int y1, int y2, int z1, int z2 )
00343     { this->vtkPointSet::SetUpdateExtent( x1, x2, y1, y2, z1, z2 ); };
00344   void SetUpdateExtent( int ext[6] )
00345     { this->vtkPointSet::SetUpdateExtent( ext ); };
00347 
00349 
00351   vtkGetMacro( Piece, int );
00352   vtkGetMacro( NumberOfPieces, int );
00354 
00356 
00357   vtkGetMacro( GhostLevel, int );
00359   
00365   unsigned long GetActualMemorySize();
00366   
00368 
00369   void ShallowCopy(vtkDataObject *src);  
00370   void DeepCopy(vtkDataObject *src);
00372 
00375   void RemoveGhostCells(int level);
00376 
00377 protected:
00378   vtkPolyData();
00379   ~vtkPolyData();
00380 
00381   // constant cell objects returned by GetCell called.
00382   vtkVertex *Vertex;
00383   vtkPolyVertex *PolyVertex;
00384   vtkLine *Line;
00385   vtkPolyLine *PolyLine;
00386   vtkTriangle *Triangle;
00387   vtkQuad *Quad;
00388   vtkPolygon *Polygon;
00389   vtkTriangleStrip *TriangleStrip;
00390   vtkEmptyCell *EmptyCell;
00391   
00392   // points inherited
00393   // point data (i.e., scalars, vectors, normals, tcoords) inherited
00394   vtkCellArray *Verts;
00395   vtkCellArray *Lines;
00396   vtkCellArray *Polys;
00397   vtkCellArray *Strips;
00398 
00399   // dummy static member below used as a trick to simplify traversal
00400   static vtkCellArray *Dummy;
00401 
00402   // supporting structures for more complex topological operations
00403   // built only when necessary
00404   vtkCellTypes *Cells;
00405   vtkCellLinks *Links;
00406 
00407   // This method is called during an update.  
00408   // If the CropFilter is set, the user reqquested a piece which the 
00409   // source cannot generate, then it will break up the
00410   // data set in order to satisfy the request.
00411   virtual void Crop();
00412 
00413 
00414 private:
00415   // Hide these from the user and the compiler.
00416   
00418 
00419   void GetCellNeighbors(vtkIdType cellId, vtkIdList& ptIds, vtkIdList& cellIds)
00420     {this->GetCellNeighbors(cellId, &ptIds, &cellIds);}
00422 
00423 private:
00424   vtkPolyData(const vtkPolyData&);  // Not implemented.
00425   void operator=(const vtkPolyData&);  // Not implemented.
00426 };
00427 
00428 inline void vtkPolyData::GetPointCells(vtkIdType ptId, unsigned short& ncells, 
00429                                        vtkIdType* &cells)
00430 {
00431   ncells = this->Links->GetNcells(ptId);
00432   cells = this->Links->GetCells(ptId);
00433 }
00434 
00435 inline int vtkPolyData::IsTriangle(int v1, int v2, int v3)
00436 {
00437   unsigned short int n1;
00438   int i, j, tVerts[3];
00439   vtkIdType *cells, *tVerts2, n2;
00440   
00441   tVerts[0] = v1;
00442   tVerts[1] = v2;
00443   tVerts[2] = v3;
00444 
00445   for (i=0; i<3; i++) 
00446     {
00447     this->GetPointCells(tVerts[i], n1, cells);
00448     for (j=0; j<n1; j++) 
00449       {
00450       this->GetCellPoints(cells[j], n2, tVerts2);
00451       if ( (tVerts[0] == tVerts2[0] || tVerts[0] == tVerts2[1] ||
00452             tVerts[0] == tVerts2[2]) &&
00453            (tVerts[1] == tVerts2[0] || tVerts[1] == tVerts2[1] ||
00454             tVerts[1] == tVerts2[2]) &&
00455            (tVerts[2] == tVerts2[0] || tVerts[2] == tVerts2[1] ||
00456             tVerts[2] == tVerts2[2]) )
00457         {
00458         return 1;
00459         }
00460       }
00461     }
00462   return 0;
00463 }
00464 
00465 inline int vtkPolyData::IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId)
00466 {
00467   vtkIdType *pts, npts;
00468   
00469   this->GetCellPoints(cellId, npts, pts);
00470   for (vtkIdType i=0; i < npts; i++)
00471     {
00472     if ( pts[i] == ptId )
00473       {
00474       return 1;
00475       }
00476     }
00477 
00478   return 0;
00479 }
00480 
00481 inline void vtkPolyData::DeletePoint(vtkIdType ptId)
00482 {
00483   this->Links->DeletePoint(ptId);
00484 }
00485 
00486 inline void vtkPolyData::DeleteCell(vtkIdType cellId)
00487 {
00488   this->Cells->DeleteCell(cellId);
00489 }
00490 
00491 inline void vtkPolyData::RemoveCellReference(vtkIdType cellId)
00492 {
00493   vtkIdType *pts, npts;
00494   
00495   this->GetCellPoints(cellId, npts, pts);
00496   for (vtkIdType i=0; i<npts; i++)
00497     {
00498     this->Links->RemoveCellReference(cellId, pts[i]);
00499     }
00500 }
00501 
00502 inline void vtkPolyData::AddCellReference(vtkIdType cellId)
00503 {
00504   vtkIdType *pts, npts;
00505   
00506   this->GetCellPoints(cellId, npts, pts);
00507   for (vtkIdType i=0; i<npts; i++)
00508     {
00509     this->Links->AddCellReference(cellId, pts[i]);
00510     }
00511 }
00512 
00513 inline void vtkPolyData::ResizeCellList(vtkIdType ptId, int size)
00514 {
00515   this->Links->ResizeCellList(ptId,size);
00516 }
00517 
00518 inline void vtkPolyData::ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId,
00519                                           vtkIdType newPtId)
00520 {
00521   int i;
00522   vtkIdType *verts, nverts;
00523   
00524   this->GetCellPoints(cellId,nverts,verts);
00525   for ( i=0; i < nverts; i++ )
00526     {
00527     if ( verts[i] == oldPtId ) 
00528       {
00529       verts[i] = newPtId; // this is very nasty! direct write!
00530       return;
00531       }
00532     }
00533 }
00534 
00535 #endif
00536 
00537