VTK
dox/Filtering/vtkPolyData.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkPolyData.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 =========================================================================*/
00063 #ifndef __vtkPolyData_h
00064 #define __vtkPolyData_h
00065 
00066 #include "vtkPointSet.h"
00067 
00068 #include "vtkCellTypes.h" // Needed for inline methods
00069 #include "vtkCellLinks.h" // Needed for inline methods
00070 
00071 class vtkVertex;
00072 class vtkPolyVertex;
00073 class vtkLine;
00074 class vtkPolyLine;
00075 class vtkTriangle;
00076 class vtkQuad;
00077 class vtkPolygon;
00078 class vtkTriangleStrip;
00079 class vtkEmptyCell;
00080 
00081 class VTK_FILTERING_EXPORT vtkPolyData : public vtkPointSet
00082 {
00083 public:
00084   static vtkPolyData *New();
00085 
00086   vtkTypeMacro(vtkPolyData,vtkPointSet);
00087   void PrintSelf(ostream& os, vtkIndent indent);
00088 
00090   int GetDataObjectType() {return VTK_POLY_DATA;}
00091 
00094   void CopyStructure(vtkDataSet *ds);
00095 
00097 
00098   vtkIdType GetNumberOfCells();
00099   vtkCell *GetCell(vtkIdType cellId);
00100   void GetCell(vtkIdType cellId, vtkGenericCell *cell);
00101   int GetCellType(vtkIdType cellId);
00102   void GetCellBounds(vtkIdType cellId, double bounds[6]);
00103   void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds,
00104                         vtkIdList *cellIds);
00106 
00108 
00112   void CopyCells(vtkPolyData *pd, vtkIdList *idList,
00113                  vtkPointLocator *locator = NULL);
00115   
00117   void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds);
00118 
00121   void GetPointCells(vtkIdType ptId, vtkIdList *cellIds);
00122 
00124   void ComputeBounds();
00125   
00130   void Squeeze();
00131 
00133   int GetMaxCellSize();
00134 
00136   void SetVerts (vtkCellArray* v);
00137 
00140   vtkCellArray *GetVerts();
00141 
00143   void SetLines (vtkCellArray* l);
00144 
00147   vtkCellArray *GetLines();
00148 
00150   void SetPolys (vtkCellArray* p);
00151 
00154   vtkCellArray *GetPolys();
00155   
00157   void SetStrips (vtkCellArray* s);
00158 
00162   vtkCellArray *GetStrips();
00163 
00165 
00166   vtkIdType GetNumberOfVerts();
00167   vtkIdType GetNumberOfLines();
00168   vtkIdType GetNumberOfPolys();
00169   vtkIdType GetNumberOfStrips();
00171 
00176   void Allocate(vtkIdType numCells=1000, int extSize=1000);
00177 
00179 
00188   void Allocate(vtkPolyData *inPolyData, vtkIdType numCells=1000, 
00189                 int extSize=1000);
00191 
00198   int InsertNextCell(int type, int npts, vtkIdType *pts);
00199 
00206   int InsertNextCell(int type, vtkIdList *pts);
00207 
00210   void Reset();
00211 
00213   void BuildCells();
00214 
00220   void BuildLinks(int initialSize=0);
00221 
00225   void DeleteCells();
00226 
00228   void DeleteLinks();
00229   
00231 
00232   void GetPointCells(vtkIdType ptId, unsigned short& ncells,
00233                      vtkIdType* &cells);
00235 
00237 
00240   void GetCellEdgeNeighbors(vtkIdType cellId, vtkIdType p1, vtkIdType p2,
00241                             vtkIdList *cellIds);
00243 
00246   void GetCellPoints(vtkIdType cellId, vtkIdType& npts, vtkIdType* &pts);
00247 
00250   int IsTriangle(int v1, int v2, int v3);
00251 
00257   int IsEdge(vtkIdType p1, vtkIdType p2);
00258 
00261   int IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId);
00262 
00268   void ReplaceCell(vtkIdType cellId, int npts, vtkIdType *pts);
00269 
00271 
00272   void ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId,
00273                         vtkIdType newPtId);
00275   
00277   void ReverseCell(vtkIdType cellId);
00278 
00280 
00281   void DeletePoint(vtkIdType ptId);
00282   void DeleteCell(vtkIdType cellId);
00284 
00291   void RemoveDeletedCells();
00292 
00294 
00300   int InsertNextLinkedPoint(int numLinks); 
00301   int InsertNextLinkedPoint(double x[3], int numLinks); 
00303   
00307   int InsertNextLinkedCell(int type, int npts, vtkIdType *pts); 
00308 
00315   void ReplaceLinkedCell(vtkIdType cellId, int npts, vtkIdType *pts);
00316 
00322   void RemoveCellReference(vtkIdType cellId);
00323 
00329   void AddCellReference(vtkIdType cellId);
00330 
00336   void RemoveReferenceToCell(vtkIdType ptId, vtkIdType cellId);
00337 
00342   void AddReferenceToCell(vtkIdType ptId, vtkIdType cellId);
00343 
00346   void ResizeCellList(vtkIdType ptId, int size);
00347 
00349   virtual void Initialize();
00350 
00354   void GetUpdateExtent(int &piece, int &numPieces, int &ghostLevel);
00355 
00357 
00358   virtual int* GetUpdateExtent();
00359   virtual void GetUpdateExtent(int& x0, int& x1, int& y0, int& y1,
00360                                int& z0, int& z1);
00361   virtual void GetUpdateExtent(int extent[6]);
00363 
00365 
00366   virtual int GetPiece();
00367   virtual int GetNumberOfPieces();
00369 
00371   virtual int GetGhostLevel();
00372   
00378   unsigned long GetActualMemorySize();
00379   
00381 
00382   void ShallowCopy(vtkDataObject *src);  
00383   void DeepCopy(vtkDataObject *src);
00385 
00388   void RemoveGhostCells(int level);
00389 
00390   //BTX
00392 
00393   static vtkPolyData* GetData(vtkInformation* info);
00394   static vtkPolyData* GetData(vtkInformationVector* v, int i=0);
00395   //ETX
00397 
00399 
00413   enum
00414     {
00415     ERR_NO_SUCH_FIELD = -4,
00416     ERR_INCORRECT_FIELD = -3,
00417     ERR_NON_MANIFOLD_STAR = -2,
00418     REGULAR_POINT = -1,
00419     MINIMUM = 0,
00420     SADDLE = 1,
00421     MAXIMUM = 2
00422     };
00423   //ETX
00424   int GetScalarFieldCriticalIndex (vtkIdType pointId, 
00425                                    vtkDataArray *scalarField);
00426   int GetScalarFieldCriticalIndex (vtkIdType pointId, int fieldId);
00427   int GetScalarFieldCriticalIndex (vtkIdType pointId, const char* fieldName);
00429 
00430 protected:
00431   vtkPolyData();
00432   ~vtkPolyData();
00433 
00434   // constant cell objects returned by GetCell called.
00435   vtkVertex *Vertex;
00436   vtkPolyVertex *PolyVertex;
00437   vtkLine *Line;
00438   vtkPolyLine *PolyLine;
00439   vtkTriangle *Triangle;
00440   vtkQuad *Quad;
00441   vtkPolygon *Polygon;
00442   vtkTriangleStrip *TriangleStrip;
00443   vtkEmptyCell *EmptyCell;
00444   
00445   // points inherited
00446   // point data (i.e., scalars, vectors, normals, tcoords) inherited
00447   vtkCellArray *Verts;
00448   vtkCellArray *Lines;
00449   vtkCellArray *Polys;
00450   vtkCellArray *Strips;
00451 
00452   // dummy static member below used as a trick to simplify traversal
00453   static vtkCellArray *Dummy;
00454 
00455   // supporting structures for more complex topological operations
00456   // built only when necessary
00457   vtkCellTypes *Cells;
00458   vtkCellLinks *Links;
00459 
00460   // This method is called during an update.  
00461   // If the CropFilter is set, the user reqquested a piece which the 
00462   // source cannot generate, then it will break up the
00463   // data set in order to satisfy the request.
00464   virtual void Crop();
00465 
00466 
00467 private:
00468   // Hide these from the user and the compiler.
00469   
00471 
00472   void GetCellNeighbors(vtkIdType cellId, vtkIdList& ptIds, vtkIdList& cellIds)
00473     {this->GetCellNeighbors(cellId, &ptIds, &cellIds);}
00475 
00476   void Cleanup();
00477 
00478 private:
00479   vtkPolyData(const vtkPolyData&);  // Not implemented.
00480   void operator=(const vtkPolyData&);  // Not implemented.
00481 };
00482 
00483 inline void vtkPolyData::GetPointCells(vtkIdType ptId, unsigned short& ncells, 
00484                                        vtkIdType* &cells)
00485 {
00486   ncells = this->Links->GetNcells(ptId);
00487   cells = this->Links->GetCells(ptId);
00488 }
00489 
00490 inline int vtkPolyData::IsTriangle(int v1, int v2, int v3)
00491 {
00492   unsigned short int n1;
00493   int i, j, tVerts[3];
00494   vtkIdType *cells, *tVerts2, n2;
00495   
00496   tVerts[0] = v1;
00497   tVerts[1] = v2;
00498   tVerts[2] = v3;
00499 
00500   for (i=0; i<3; i++) 
00501     {
00502     this->GetPointCells(tVerts[i], n1, cells);
00503     for (j=0; j<n1; j++) 
00504       {
00505       this->GetCellPoints(cells[j], n2, tVerts2);
00506       if ( (tVerts[0] == tVerts2[0] || tVerts[0] == tVerts2[1] ||
00507             tVerts[0] == tVerts2[2]) &&
00508            (tVerts[1] == tVerts2[0] || tVerts[1] == tVerts2[1] ||
00509             tVerts[1] == tVerts2[2]) &&
00510            (tVerts[2] == tVerts2[0] || tVerts[2] == tVerts2[1] ||
00511             tVerts[2] == tVerts2[2]) )
00512         {
00513         return 1;
00514         }
00515       }
00516     }
00517   return 0;
00518 }
00519 
00520 inline int vtkPolyData::IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId)
00521 {
00522   vtkIdType *pts, npts;
00523   
00524   this->GetCellPoints(cellId, npts, pts);
00525   for (vtkIdType i=0; i < npts; i++)
00526     {
00527     if ( pts[i] == ptId )
00528       {
00529       return 1;
00530       }
00531     }
00532 
00533   return 0;
00534 }
00535 
00536 inline void vtkPolyData::DeletePoint(vtkIdType ptId)
00537 {
00538   this->Links->DeletePoint(ptId);
00539 }
00540 
00541 inline void vtkPolyData::DeleteCell(vtkIdType cellId)
00542 {
00543   this->Cells->DeleteCell(cellId);
00544 }
00545 
00546 inline void vtkPolyData::RemoveCellReference(vtkIdType cellId)
00547 {
00548   vtkIdType *pts, npts;
00549   
00550   this->GetCellPoints(cellId, npts, pts);
00551   for (vtkIdType i=0; i<npts; i++)
00552     {
00553     this->Links->RemoveCellReference(cellId, pts[i]);
00554     }
00555 }
00556 
00557 inline void vtkPolyData::AddCellReference(vtkIdType cellId)
00558 {
00559   vtkIdType *pts, npts;
00560   
00561   this->GetCellPoints(cellId, npts, pts);
00562   for (vtkIdType i=0; i<npts; i++)
00563     {
00564     this->Links->AddCellReference(cellId, pts[i]);
00565     }
00566 }
00567 
00568 inline void vtkPolyData::ResizeCellList(vtkIdType ptId, int size)
00569 {
00570   this->Links->ResizeCellList(ptId,size);
00571 }
00572 
00573 inline void vtkPolyData::ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId,
00574                                           vtkIdType newPtId)
00575 {
00576   int i;
00577   vtkIdType *verts, nverts;
00578   
00579   this->GetCellPoints(cellId,nverts,verts);
00580   for ( i=0; i < nverts; i++ )
00581     {
00582     if ( verts[i] == oldPtId ) 
00583       {
00584       verts[i] = newPtId; // this is very nasty! direct write!
00585       return;
00586       }
00587     }
00588 }
00589 
00590 #endif
00591 
00592