Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound 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 
00008 Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen 
00009 All rights reserved.
00010 
00011 Redistribution and use in source and binary forms, with or without
00012 modification, are permitted provided that the following conditions are met:
00013 
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016 
00017  * Redistributions in binary form must reproduce the above copyright notice,
00018    this list of conditions and the following disclaimer in the documentation
00019    and/or other materials provided with the distribution.
00020 
00021  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
00022    of any contributors may be used to endorse or promote products derived
00023    from this software without specific prior written permission.
00024 
00025  * Modified source versions must be plainly marked as such, and must not be
00026    misrepresented as being the original software.
00027 
00028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00029 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00030 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00031 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00032 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00033 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00034 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00035 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00036 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00037 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038 
00039 =========================================================================*/
00070 #ifndef __vtkPolyData_h
00071 #define __vtkPolyData_h
00072 
00073 #include "vtkPointSet.h"
00074 #include "vtkPoints.h"
00075 #include "vtkCellArray.h"
00076 #include "vtkCellTypes.h"
00077 #include "vtkCellLinks.h"
00078 
00079 class vtkVertex;
00080 class vtkPolyVertex;
00081 class vtkLine;
00082 class vtkPolyLine;
00083 class vtkTriangle;
00084 class vtkQuad;
00085 class vtkPolygon;
00086 class vtkTriangleStrip;
00087 class vtkEmptyCell;
00088 
00089 
00090 
00091 class VTK_COMMON_EXPORT vtkPolyData : public vtkPointSet 
00092 {
00093 public:
00094   static vtkPolyData *New();
00095 
00096   vtkTypeMacro(vtkPolyData,vtkPointSet);
00097   void PrintSelf(ostream& os, vtkIndent indent);
00098 
00100   vtkDataObject *MakeObject() {return vtkPolyData::New();};
00101 
00103   int GetDataObjectType() {return VTK_POLY_DATA;}
00104 
00107   void CopyStructure(vtkDataSet *ds);
00108 
00110 
00111   vtkIdType GetNumberOfCells();
00112   vtkCell *GetCell(vtkIdType cellId);
00113   void GetCell(vtkIdType cellId, vtkGenericCell *cell);
00114   int GetCellType(vtkIdType cellId);
00115   void GetCellBounds(vtkIdType cellId, float bounds[6]);
00116   void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds,
00117                         vtkIdList *cellIds);
00119   
00121 
00125   void CopyCells(vtkPolyData *pd, vtkIdList *idList,
00126                  vtkPointLocator *locator = NULL);
00128   
00130   void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds);
00131 
00134   void GetPointCells(vtkIdType ptId, vtkIdList *cellIds);
00135 
00137   void ComputeBounds();
00138   
00143   void Squeeze();
00144 
00146   int GetMaxCellSize();
00147 
00149   void SetVerts (vtkCellArray* v);
00150 
00153   vtkCellArray *GetVerts();
00154 
00156   void SetLines (vtkCellArray* l);
00157 
00160   vtkCellArray *GetLines();
00161 
00163   void SetPolys (vtkCellArray* p);
00164 
00167   vtkCellArray *GetPolys();
00168   
00170   void SetStrips (vtkCellArray* s);
00171 
00175   vtkCellArray *GetStrips();
00176 
00178 
00179   vtkIdType GetNumberOfVerts();
00180   vtkIdType GetNumberOfLines();
00181   vtkIdType GetNumberOfPolys();
00182   vtkIdType GetNumberOfStrips();
00184 
00189   void Allocate(vtkIdType numCells=1000, int extSize=1000);
00190 
00192 
00201   void Allocate(vtkPolyData *inPolyData, vtkIdType numCells=1000, 
00202                 int extSize=1000);
00204 
00211   int InsertNextCell(int type, int npts, vtkIdType *pts);
00212 
00219   int InsertNextCell(int type, vtkIdList *pts);
00220 
00223   void Reset();
00224 
00226   void BuildCells();
00227 
00230   void BuildLinks();
00231 
00235   void DeleteCells();
00236 
00238   void DeleteLinks();
00239   
00241 
00242   void GetPointCells(vtkIdType ptId, unsigned short& ncells,
00243                      vtkIdType* &cells);
00245 
00247 
00250   void GetCellEdgeNeighbors(vtkIdType cellId, vtkIdType p1, vtkIdType p2,
00251                             vtkIdList *cellIds);
00253 
00256   void GetCellPoints(vtkIdType cellId, vtkIdType& npts, vtkIdType* &pts);
00257 
00260   int IsTriangle(int v1, int v2, int v3);
00261 
00264   int IsEdge(int v1, int v2);
00265 
00268   int IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId);
00269 
00275   void ReplaceCell(vtkIdType cellId, int npts, vtkIdType *pts);
00276 
00278 
00279   void ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId,
00280                         vtkIdType newPtId);
00282   
00284   void ReverseCell(vtkIdType cellId);
00285 
00287 
00288   void DeletePoint(vtkIdType ptId);
00289   void DeleteCell(vtkIdType cellId);
00291 
00296   int InsertNextLinkedPoint(float x[3], int numLinks); 
00297   
00301   int InsertNextLinkedCell(int type, int npts, vtkIdType *pts); 
00302 
00309   void ReplaceLinkedCell(vtkIdType cellId, int npts, vtkIdType *pts);
00310 
00316   void RemoveCellReference(vtkIdType cellId);
00317 
00323   void AddCellReference(vtkIdType cellId);
00324 
00330   void RemoveReferenceToCell(vtkIdType ptId, vtkIdType cellId);
00331 
00336   void AddReferenceToCell(vtkIdType ptId, vtkIdType cellId);
00337 
00340   void ResizeCellList(vtkIdType ptId, int size);
00341 
00343   virtual void Initialize();
00344 
00346 
00349   void SetUpdateExtent(int piece, int numPieces, int ghostLevel);
00350   void SetUpdateExtent(int piece, int numPieces)
00351     {this->SetUpdateExtent(piece, numPieces, 0);}
00352   void GetUpdateExtent(int &piece, int &numPieces, int &ghostLevel);
00354 
00356 
00357   vtkGetVector6Macro( UpdateExtent, int );
00359 
00361 
00365   void SetUpdateExtent( int x1, int x2, int y1, int y2, int z1, int z2 )
00366     { this->vtkPointSet::SetUpdateExtent( x1, x2, y1, y2, z1, z2 ); };
00367   void SetUpdateExtent( int ext[6] )
00368     { this->vtkPointSet::SetUpdateExtent( ext ); };
00370 
00372 
00374   vtkGetMacro( Piece, int );
00375   vtkGetMacro( NumberOfPieces, int );
00377 
00379 
00380   vtkGetMacro( GhostLevel, int );
00382   
00388   unsigned long GetActualMemorySize();
00389   
00391 
00392   void ShallowCopy(vtkDataObject *src);  
00393   void DeepCopy(vtkDataObject *src);
00395 
00398   void RemoveGhostCells(int level);
00399 
00400 protected:
00401   vtkPolyData();
00402   ~vtkPolyData();
00403 
00404   // constant cell objects returned by GetCell called.
00405   vtkVertex *Vertex;
00406   vtkPolyVertex *PolyVertex;
00407   vtkLine *Line;
00408   vtkPolyLine *PolyLine;
00409   vtkTriangle *Triangle;
00410   vtkQuad *Quad;
00411   vtkPolygon *Polygon;
00412   vtkTriangleStrip *TriangleStrip;
00413   vtkEmptyCell *EmptyCell;
00414   
00415   // points inherited
00416   // point data (i.e., scalars, vectors, normals, tcoords) inherited
00417   vtkCellArray *Verts;
00418   vtkCellArray *Lines;
00419   vtkCellArray *Polys;
00420   vtkCellArray *Strips;
00421 
00422   // dummy static member below used as a trick to simplify traversal
00423   static vtkCellArray *Dummy;
00424 
00425   // supporting structures for more complex topological operations
00426   // built only when necessary
00427   vtkCellTypes *Cells;
00428   vtkCellLinks *Links;
00429 
00430   // This method is called during an update.  
00431   // If the CropFilter is set, the user reqquested a piece which the 
00432   // source cannot generate, then it will break up the
00433   // data set in order to satisfy the request.
00434   virtual void Crop();
00435 
00436 
00437 private:
00438   // Hide these from the user and the compiler.
00439   
00441 
00442   void GetCellNeighbors(vtkIdType cellId, vtkIdList& ptIds, vtkIdList& cellIds)
00443     {this->GetCellNeighbors(cellId, &ptIds, &cellIds);}
00445 
00446 private:
00447   vtkPolyData(const vtkPolyData&);  // Not implemented.
00448   void operator=(const vtkPolyData&);  // Not implemented.
00449 };
00450 
00451 inline void vtkPolyData::GetPointCells(vtkIdType ptId, unsigned short& ncells, 
00452                                        vtkIdType* &cells)
00453 {
00454   ncells = this->Links->GetNcells(ptId);
00455   cells = this->Links->GetCells(ptId);
00456 }
00457 
00458 inline int vtkPolyData::IsTriangle(int v1, int v2, int v3)
00459 {
00460   unsigned short int n1;
00461   int i, j, tVerts[3];
00462   vtkIdType *cells, *tVerts2, n2;
00463   
00464   tVerts[0] = v1;
00465   tVerts[1] = v2;
00466   tVerts[2] = v3;
00467 
00468   for (i=0; i<3; i++) 
00469     {
00470     this->GetPointCells(tVerts[i], n1, cells);
00471     for (j=0; j<n1; j++) 
00472       {
00473       this->GetCellPoints(cells[j], n2, tVerts2);
00474       if ( (tVerts[0] == tVerts2[0] || tVerts[0] == tVerts2[1] ||
00475             tVerts[0] == tVerts2[2]) &&
00476            (tVerts[1] == tVerts2[0] || tVerts[1] == tVerts2[1] ||
00477             tVerts[1] == tVerts2[2]) &&
00478            (tVerts[2] == tVerts2[0] || tVerts[2] == tVerts2[1] ||
00479             tVerts[2] == tVerts2[2]) )
00480         {
00481         return 1;
00482         }
00483       }
00484     }
00485   return 0;
00486 }
00487 
00488 inline int vtkPolyData::IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId)
00489 {
00490   vtkIdType *pts, npts;
00491   
00492   this->GetCellPoints(cellId, npts, pts);
00493   for (vtkIdType i=0; i < npts; i++)
00494     {
00495     if ( pts[i] == ptId )
00496       {
00497       return 1;
00498       }
00499     }
00500 
00501   return 0;
00502 }
00503 
00504 inline int vtkPolyData::IsEdge(int p1, int p2)
00505 {
00506   unsigned short int ncells;
00507   int i;
00508   vtkIdType *cells;
00509   
00510   this->GetPointCells(p1,ncells,cells);
00511   for (i=0; i < ncells; i++)
00512     {
00513     if ( this->IsPointUsedByCell(p2,cells[i]) )
00514       {
00515       return 1;
00516       }
00517     }
00518 
00519   return 0;
00520 }
00521 
00522 inline void vtkPolyData::DeletePoint(vtkIdType ptId)
00523 {
00524   this->Links->DeletePoint(ptId);
00525 }
00526 
00527 inline void vtkPolyData::DeleteCell(vtkIdType cellId)
00528 {
00529   this->Cells->DeleteCell(cellId);
00530 }
00531 
00532 inline void vtkPolyData::RemoveCellReference(vtkIdType cellId)
00533 {
00534   vtkIdType *pts, npts;
00535   
00536   this->GetCellPoints(cellId, npts, pts);
00537   for (vtkIdType i=0; i<npts; i++)
00538     {
00539     this->Links->RemoveCellReference(cellId, pts[i]);
00540     }
00541 }
00542 
00543 inline void vtkPolyData::AddCellReference(vtkIdType cellId)
00544 {
00545   vtkIdType *pts, npts;
00546   
00547   this->GetCellPoints(cellId, npts, pts);
00548   for (vtkIdType i=0; i<npts; i++)
00549     {
00550     this->Links->AddCellReference(cellId, pts[i]);
00551     }
00552 }
00553 
00554 inline void vtkPolyData::ResizeCellList(vtkIdType ptId, int size)
00555 {
00556   this->Links->ResizeCellList(ptId,size);
00557 }
00558 
00559 inline void vtkPolyData::ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId,
00560                                           vtkIdType newPtId)
00561 {
00562   int i;
00563   vtkIdType *verts, nverts;
00564   
00565   this->GetCellPoints(cellId,nverts,verts);
00566   for ( i=0; i < nverts; i++ )
00567     {
00568     if ( verts[i] == oldPtId ) 
00569       {
00570       verts[i] = newPtId; // this is very nasty! direct write!
00571       return;
00572       }
00573     }
00574 }
00575 
00576 #endif
00577 
00578 

Generated on Thu Mar 28 14:19:16 2002 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001