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   Language:  C++
00006 
00007   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
00008   All rights reserved.
00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00010 
00011      This software is distributed WITHOUT ANY WARRANTY; without even 
00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00013      PURPOSE.  See the above copyright notice for more information.
00014 
00015 =========================================================================*/
00060 #ifndef __vtkPolyData_h
00061 #define __vtkPolyData_h
00062 
00063 #include "vtkPointSet.h"
00064 
00065 #include "vtkCellTypes.h" // Needed for inline methods
00066 #include "vtkCellLinks.h" // Needed for inline methods
00067 
00068 class vtkVertex;
00069 class vtkPolyVertex;
00070 class vtkLine;
00071 class vtkPolyLine;
00072 class vtkTriangle;
00073 class vtkQuad;
00074 class vtkPolygon;
00075 class vtkTriangleStrip;
00076 class vtkEmptyCell;
00077 
00078 class VTK_COMMON_EXPORT vtkPolyData : public vtkPointSet 
00079 {
00080 public:
00081   static vtkPolyData *New();
00082 
00083   vtkTypeRevisionMacro(vtkPolyData,vtkPointSet);
00084   void PrintSelf(ostream& os, vtkIndent indent);
00085 
00087   int GetDataObjectType() {return VTK_POLY_DATA;}
00088 
00091   void CopyStructure(vtkDataSet *ds);
00092 
00094 
00095   vtkIdType GetNumberOfCells();
00096   vtkCell *GetCell(vtkIdType cellId);
00097   void GetCell(vtkIdType cellId, vtkGenericCell *cell);
00098   int GetCellType(vtkIdType cellId);
00099   void GetCellBounds(vtkIdType cellId, float bounds[6]);
00100   void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds,
00101                         vtkIdList *cellIds);
00103   
00105 
00109   void CopyCells(vtkPolyData *pd, vtkIdList *idList,
00110                  vtkPointLocator *locator = NULL);
00112   
00114   void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds);
00115 
00118   void GetPointCells(vtkIdType ptId, vtkIdList *cellIds);
00119 
00121   void ComputeBounds();
00122   
00127   void Squeeze();
00128 
00130   int GetMaxCellSize();
00131 
00133   void SetVerts (vtkCellArray* v);
00134 
00137   vtkCellArray *GetVerts();
00138 
00140   void SetLines (vtkCellArray* l);
00141 
00144   vtkCellArray *GetLines();
00145 
00147   void SetPolys (vtkCellArray* p);
00148 
00151   vtkCellArray *GetPolys();
00152   
00154   void SetStrips (vtkCellArray* s);
00155 
00159   vtkCellArray *GetStrips();
00160 
00162 
00163   vtkIdType GetNumberOfVerts();
00164   vtkIdType GetNumberOfLines();
00165   vtkIdType GetNumberOfPolys();
00166   vtkIdType GetNumberOfStrips();
00168 
00173   void Allocate(vtkIdType numCells=1000, int extSize=1000);
00174 
00176 
00185   void Allocate(vtkPolyData *inPolyData, vtkIdType numCells=1000, 
00186                 int extSize=1000);
00188 
00195   int InsertNextCell(int type, int npts, vtkIdType *pts);
00196 
00203   int InsertNextCell(int type, vtkIdList *pts);
00204 
00207   void Reset();
00208 
00210   void BuildCells();
00211 
00217   void BuildLinks(int initialSize=0);
00218 
00222   void DeleteCells();
00223 
00225   void DeleteLinks();
00226   
00228 
00229   void GetPointCells(vtkIdType ptId, unsigned short& ncells,
00230                      vtkIdType* &cells);
00232 
00234 
00237   void GetCellEdgeNeighbors(vtkIdType cellId, vtkIdType p1, vtkIdType p2,
00238                             vtkIdList *cellIds);
00240 
00243   void GetCellPoints(vtkIdType cellId, vtkIdType& npts, vtkIdType* &pts);
00244 
00247   int IsTriangle(int v1, int v2, int v3);
00248 
00251   int IsEdge(int v1, int v2);
00252 
00255   int IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId);
00256 
00262   void ReplaceCell(vtkIdType cellId, int npts, vtkIdType *pts);
00263 
00265 
00266   void ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId,
00267                         vtkIdType newPtId);
00269   
00271   void ReverseCell(vtkIdType cellId);
00272 
00274 
00275   void DeletePoint(vtkIdType ptId);
00276   void DeleteCell(vtkIdType cellId);
00278 
00280 
00286   int InsertNextLinkedPoint(int numLinks); 
00287   int InsertNextLinkedPoint(float x[3], int numLinks); 
00289   
00293   int InsertNextLinkedCell(int type, int npts, vtkIdType *pts); 
00294 
00301   void ReplaceLinkedCell(vtkIdType cellId, int npts, vtkIdType *pts);
00302 
00308   void RemoveCellReference(vtkIdType cellId);
00309 
00315   void AddCellReference(vtkIdType cellId);
00316 
00322   void RemoveReferenceToCell(vtkIdType ptId, vtkIdType cellId);
00323 
00328   void AddReferenceToCell(vtkIdType ptId, vtkIdType cellId);
00329 
00332   void ResizeCellList(vtkIdType ptId, int size);
00333 
00335   virtual void Initialize();
00336 
00338 
00341   void SetUpdateExtent(int piece, int numPieces, int ghostLevel);
00342   void SetUpdateExtent(int piece, int numPieces)
00343     {this->SetUpdateExtent(piece, numPieces, 0);}
00344   void GetUpdateExtent(int &piece, int &numPieces, int &ghostLevel);
00346 
00348 
00349   vtkGetVector6Macro( UpdateExtent, int );
00351 
00353 
00357   void SetUpdateExtent( int x1, int x2, int y1, int y2, int z1, int z2 )
00358     { this->vtkPointSet::SetUpdateExtent( x1, x2, y1, y2, z1, z2 ); };
00359   void SetUpdateExtent( int ext[6] )
00360     { this->vtkPointSet::SetUpdateExtent( ext ); };
00362 
00364 
00366   vtkGetMacro( Piece, int );
00367   vtkGetMacro( NumberOfPieces, int );
00369 
00371 
00372   vtkGetMacro( GhostLevel, int );
00374   
00380   unsigned long GetActualMemorySize();
00381   
00383 
00384   void ShallowCopy(vtkDataObject *src);  
00385   void DeepCopy(vtkDataObject *src);
00387 
00390   void RemoveGhostCells(int level);
00391 
00392 protected:
00393   vtkPolyData();
00394   ~vtkPolyData();
00395 
00396   // constant cell objects returned by GetCell called.
00397   vtkVertex *Vertex;
00398   vtkPolyVertex *PolyVertex;
00399   vtkLine *Line;
00400   vtkPolyLine *PolyLine;
00401   vtkTriangle *Triangle;
00402   vtkQuad *Quad;
00403   vtkPolygon *Polygon;
00404   vtkTriangleStrip *TriangleStrip;
00405   vtkEmptyCell *EmptyCell;
00406   
00407   // points inherited
00408   // point data (i.e., scalars, vectors, normals, tcoords) inherited
00409   vtkCellArray *Verts;
00410   vtkCellArray *Lines;
00411   vtkCellArray *Polys;
00412   vtkCellArray *Strips;
00413 
00414   // dummy static member below used as a trick to simplify traversal
00415   static vtkCellArray *Dummy;
00416 
00417   // supporting structures for more complex topological operations
00418   // built only when necessary
00419   vtkCellTypes *Cells;
00420   vtkCellLinks *Links;
00421 
00422   // This method is called during an update.  
00423   // If the CropFilter is set, the user reqquested a piece which the 
00424   // source cannot generate, then it will break up the
00425   // data set in order to satisfy the request.
00426   virtual void Crop();
00427 
00428 
00429 private:
00430   // Hide these from the user and the compiler.
00431   
00433 
00434   void GetCellNeighbors(vtkIdType cellId, vtkIdList& ptIds, vtkIdList& cellIds)
00435     {this->GetCellNeighbors(cellId, &ptIds, &cellIds);}
00437 
00438 private:
00439   vtkPolyData(const vtkPolyData&);  // Not implemented.
00440   void operator=(const vtkPolyData&);  // Not implemented.
00441 };
00442 
00443 inline void vtkPolyData::GetPointCells(vtkIdType ptId, unsigned short& ncells, 
00444                                        vtkIdType* &cells)
00445 {
00446   ncells = this->Links->GetNcells(ptId);
00447   cells = this->Links->GetCells(ptId);
00448 }
00449 
00450 inline int vtkPolyData::IsTriangle(int v1, int v2, int v3)
00451 {
00452   unsigned short int n1;
00453   int i, j, tVerts[3];
00454   vtkIdType *cells, *tVerts2, n2;
00455   
00456   tVerts[0] = v1;
00457   tVerts[1] = v2;
00458   tVerts[2] = v3;
00459 
00460   for (i=0; i<3; i++) 
00461     {
00462     this->GetPointCells(tVerts[i], n1, cells);
00463     for (j=0; j<n1; j++) 
00464       {
00465       this->GetCellPoints(cells[j], n2, tVerts2);
00466       if ( (tVerts[0] == tVerts2[0] || tVerts[0] == tVerts2[1] ||
00467             tVerts[0] == tVerts2[2]) &&
00468            (tVerts[1] == tVerts2[0] || tVerts[1] == tVerts2[1] ||
00469             tVerts[1] == tVerts2[2]) &&
00470            (tVerts[2] == tVerts2[0] || tVerts[2] == tVerts2[1] ||
00471             tVerts[2] == tVerts2[2]) )
00472         {
00473         return 1;
00474         }
00475       }
00476     }
00477   return 0;
00478 }
00479 
00480 inline int vtkPolyData::IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId)
00481 {
00482   vtkIdType *pts, npts;
00483   
00484   this->GetCellPoints(cellId, npts, pts);
00485   for (vtkIdType i=0; i < npts; i++)
00486     {
00487     if ( pts[i] == ptId )
00488       {
00489       return 1;
00490       }
00491     }
00492 
00493   return 0;
00494 }
00495 
00496 inline int vtkPolyData::IsEdge(int p1, int p2)
00497 {
00498   unsigned short int ncells;
00499   int i;
00500   vtkIdType *cells;
00501   
00502   this->GetPointCells(p1,ncells,cells);
00503   for (i=0; i < ncells; i++)
00504     {
00505     if ( this->IsPointUsedByCell(p2,cells[i]) )
00506       {
00507       return 1;
00508       }
00509     }
00510 
00511   return 0;
00512 }
00513 
00514 inline void vtkPolyData::DeletePoint(vtkIdType ptId)
00515 {
00516   this->Links->DeletePoint(ptId);
00517 }
00518 
00519 inline void vtkPolyData::DeleteCell(vtkIdType cellId)
00520 {
00521   this->Cells->DeleteCell(cellId);
00522 }
00523 
00524 inline void vtkPolyData::RemoveCellReference(vtkIdType cellId)
00525 {
00526   vtkIdType *pts, npts;
00527   
00528   this->GetCellPoints(cellId, npts, pts);
00529   for (vtkIdType i=0; i<npts; i++)
00530     {
00531     this->Links->RemoveCellReference(cellId, pts[i]);
00532     }
00533 }
00534 
00535 inline void vtkPolyData::AddCellReference(vtkIdType cellId)
00536 {
00537   vtkIdType *pts, npts;
00538   
00539   this->GetCellPoints(cellId, npts, pts);
00540   for (vtkIdType i=0; i<npts; i++)
00541     {
00542     this->Links->AddCellReference(cellId, pts[i]);
00543     }
00544 }
00545 
00546 inline void vtkPolyData::ResizeCellList(vtkIdType ptId, int size)
00547 {
00548   this->Links->ResizeCellList(ptId,size);
00549 }
00550 
00551 inline void vtkPolyData::ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId,
00552                                           vtkIdType newPtId)
00553 {
00554   int i;
00555   vtkIdType *verts, nverts;
00556   
00557   this->GetCellPoints(cellId,nverts,verts);
00558   for ( i=0; i < nverts; i++ )
00559     {
00560     if ( verts[i] == oldPtId ) 
00561       {
00562       verts[i] = newPtId; // this is very nasty! direct write!
00563       return;
00564       }
00565     }
00566 }
00567 
00568 #endif
00569 
00570