VTK
|
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 "vtkCommonDataModelModule.h" // For export macro 00067 #include "vtkPointSet.h" 00068 00069 #include "vtkCellTypes.h" // Needed for inline methods 00070 #include "vtkCellLinks.h" // Needed for inline methods 00071 00072 class vtkVertex; 00073 class vtkPolyVertex; 00074 class vtkLine; 00075 class vtkPolyLine; 00076 class vtkTriangle; 00077 class vtkQuad; 00078 class vtkPolygon; 00079 class vtkTriangleStrip; 00080 class vtkEmptyCell; 00081 00082 class VTKCOMMONDATAMODEL_EXPORT vtkPolyData : public vtkPointSet 00083 { 00084 public: 00085 static vtkPolyData *New(); 00086 00087 vtkTypeMacro(vtkPolyData,vtkPointSet); 00088 void PrintSelf(ostream& os, vtkIndent indent); 00089 00091 int GetDataObjectType() {return VTK_POLY_DATA;} 00092 00095 void CopyStructure(vtkDataSet *ds); 00096 00098 00099 vtkIdType GetNumberOfCells(); 00100 vtkCell *GetCell(vtkIdType cellId); 00101 void GetCell(vtkIdType cellId, vtkGenericCell *cell); 00102 int GetCellType(vtkIdType cellId); 00103 void GetCellBounds(vtkIdType cellId, double bounds[6]); 00104 void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds, 00105 vtkIdList *cellIds); 00107 00109 00113 void CopyCells(vtkPolyData *pd, vtkIdList *idList, 00114 vtkPointLocator *locator = NULL); 00116 00118 void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds); 00119 00122 void GetPointCells(vtkIdType ptId, vtkIdList *cellIds); 00123 00125 void ComputeBounds(); 00126 00131 void Squeeze(); 00132 00134 int GetMaxCellSize(); 00135 00137 void SetVerts (vtkCellArray* v); 00138 00141 vtkCellArray *GetVerts(); 00142 00144 void SetLines (vtkCellArray* l); 00145 00148 vtkCellArray *GetLines(); 00149 00151 void SetPolys (vtkCellArray* p); 00152 00155 vtkCellArray *GetPolys(); 00156 00158 void SetStrips (vtkCellArray* s); 00159 00163 vtkCellArray *GetStrips(); 00164 00166 00167 vtkIdType GetNumberOfVerts(); 00168 vtkIdType GetNumberOfLines(); 00169 vtkIdType GetNumberOfPolys(); 00170 vtkIdType GetNumberOfStrips(); 00172 00179 void Allocate(vtkIdType numCells=1000, int extSize=1000); 00180 00182 00191 void Allocate(vtkPolyData *inPolyData, vtkIdType numCells=1000, 00192 int extSize=1000); 00194 00201 int InsertNextCell(int type, int npts, vtkIdType *pts); 00202 00209 int InsertNextCell(int type, vtkIdList *pts); 00210 00213 void Reset(); 00214 00216 void BuildCells(); 00217 00223 void BuildLinks(int initialSize=0); 00224 00228 void DeleteCells(); 00229 00231 void DeleteLinks(); 00232 00234 00235 void GetPointCells(vtkIdType ptId, unsigned short& ncells, 00236 vtkIdType* &cells); 00238 00240 00243 void GetCellEdgeNeighbors(vtkIdType cellId, vtkIdType p1, vtkIdType p2, 00244 vtkIdList *cellIds); 00246 00249 void GetCellPoints(vtkIdType cellId, vtkIdType& npts, vtkIdType* &pts); 00250 00253 int IsTriangle(int v1, int v2, int v3); 00254 00260 int IsEdge(vtkIdType p1, vtkIdType p2); 00261 00264 int IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId); 00265 00271 void ReplaceCell(vtkIdType cellId, int npts, vtkIdType *pts); 00272 00274 00275 void ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId, 00276 vtkIdType newPtId); 00278 00280 void ReverseCell(vtkIdType cellId); 00281 00283 00284 void DeletePoint(vtkIdType ptId); 00285 void DeleteCell(vtkIdType cellId); 00287 00293 void RemoveDeletedCells(); 00294 00296 00302 int InsertNextLinkedPoint(int numLinks); 00303 int InsertNextLinkedPoint(double x[3], int numLinks); 00305 00309 int InsertNextLinkedCell(int type, int npts, vtkIdType *pts); 00310 00317 void ReplaceLinkedCell(vtkIdType cellId, int npts, vtkIdType *pts); 00318 00324 void RemoveCellReference(vtkIdType cellId); 00325 00331 void AddCellReference(vtkIdType cellId); 00332 00338 void RemoveReferenceToCell(vtkIdType ptId, vtkIdType cellId); 00339 00344 void AddReferenceToCell(vtkIdType ptId, vtkIdType cellId); 00345 00348 void ResizeCellList(vtkIdType ptId, int size); 00349 00351 virtual void Initialize(); 00352 00354 00355 virtual int GetPiece(); 00356 virtual int GetNumberOfPieces(); 00358 00360 virtual int GetGhostLevel(); 00361 00367 unsigned long GetActualMemorySize(); 00368 00370 00371 void ShallowCopy(vtkDataObject *src); 00372 void DeepCopy(vtkDataObject *src); 00374 00377 void RemoveGhostCells(int level); 00378 00379 //BTX 00381 00382 static vtkPolyData* GetData(vtkInformation* info); 00383 static vtkPolyData* GetData(vtkInformationVector* v, int i=0); 00384 //ETX 00386 00387 //BTX 00389 00403 enum 00404 { 00405 ERR_NO_SUCH_FIELD = -4, 00406 ERR_INCORRECT_FIELD = -3, 00407 ERR_NON_MANIFOLD_STAR = -2, 00408 REGULAR_POINT = -1, 00409 MINIMUM = 0, 00410 SADDLE = 1, 00411 MAXIMUM = 2 00412 }; 00413 //ETX 00414 int GetScalarFieldCriticalIndex (vtkIdType pointId, 00415 vtkDataArray *scalarField); 00416 int GetScalarFieldCriticalIndex (vtkIdType pointId, int fieldId); 00417 int GetScalarFieldCriticalIndex (vtkIdType pointId, const char* fieldName); 00419 00420 protected: 00421 vtkPolyData(); 00422 ~vtkPolyData(); 00423 00424 // constant cell objects returned by GetCell called. 00425 vtkVertex *Vertex; 00426 vtkPolyVertex *PolyVertex; 00427 vtkLine *Line; 00428 vtkPolyLine *PolyLine; 00429 vtkTriangle *Triangle; 00430 vtkQuad *Quad; 00431 vtkPolygon *Polygon; 00432 vtkTriangleStrip *TriangleStrip; 00433 vtkEmptyCell *EmptyCell; 00434 00435 // points inherited 00436 // point data (i.e., scalars, vectors, normals, tcoords) inherited 00437 vtkCellArray *Verts; 00438 vtkCellArray *Lines; 00439 vtkCellArray *Polys; 00440 vtkCellArray *Strips; 00441 00442 // dummy static member below used as a trick to simplify traversal 00443 static vtkCellArray *Dummy; 00444 00445 // supporting structures for more complex topological operations 00446 // built only when necessary 00447 vtkCellTypes *Cells; 00448 vtkCellLinks *Links; 00449 00450 private: 00451 // Hide these from the user and the compiler. 00452 00454 00455 void GetCellNeighbors(vtkIdType cellId, vtkIdList& ptIds, vtkIdList& cellIds) 00456 {this->GetCellNeighbors(cellId, &ptIds, &cellIds);} 00458 00459 void Cleanup(); 00460 00461 private: 00462 vtkPolyData(const vtkPolyData&); // Not implemented. 00463 void operator=(const vtkPolyData&); // Not implemented. 00464 }; 00465 00466 inline void vtkPolyData::GetPointCells(vtkIdType ptId, unsigned short& ncells, 00467 vtkIdType* &cells) 00468 { 00469 ncells = this->Links->GetNcells(ptId); 00470 cells = this->Links->GetCells(ptId); 00471 } 00472 00473 inline int vtkPolyData::IsTriangle(int v1, int v2, int v3) 00474 { 00475 unsigned short int n1; 00476 int i, j, tVerts[3]; 00477 vtkIdType *cells, *tVerts2, n2; 00478 00479 tVerts[0] = v1; 00480 tVerts[1] = v2; 00481 tVerts[2] = v3; 00482 00483 for (i=0; i<3; i++) 00484 { 00485 this->GetPointCells(tVerts[i], n1, cells); 00486 for (j=0; j<n1; j++) 00487 { 00488 this->GetCellPoints(cells[j], n2, tVerts2); 00489 if ( (tVerts[0] == tVerts2[0] || tVerts[0] == tVerts2[1] || 00490 tVerts[0] == tVerts2[2]) && 00491 (tVerts[1] == tVerts2[0] || tVerts[1] == tVerts2[1] || 00492 tVerts[1] == tVerts2[2]) && 00493 (tVerts[2] == tVerts2[0] || tVerts[2] == tVerts2[1] || 00494 tVerts[2] == tVerts2[2]) ) 00495 { 00496 return 1; 00497 } 00498 } 00499 } 00500 return 0; 00501 } 00502 00503 inline int vtkPolyData::IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId) 00504 { 00505 vtkIdType *pts, npts; 00506 00507 this->GetCellPoints(cellId, npts, pts); 00508 for (vtkIdType i=0; i < npts; i++) 00509 { 00510 if ( pts[i] == ptId ) 00511 { 00512 return 1; 00513 } 00514 } 00515 00516 return 0; 00517 } 00518 00519 inline void vtkPolyData::DeletePoint(vtkIdType ptId) 00520 { 00521 this->Links->DeletePoint(ptId); 00522 } 00523 00524 inline void vtkPolyData::DeleteCell(vtkIdType cellId) 00525 { 00526 this->Cells->DeleteCell(cellId); 00527 } 00528 00529 inline void vtkPolyData::RemoveCellReference(vtkIdType cellId) 00530 { 00531 vtkIdType *pts, npts; 00532 00533 this->GetCellPoints(cellId, npts, pts); 00534 for (vtkIdType i=0; i<npts; i++) 00535 { 00536 this->Links->RemoveCellReference(cellId, pts[i]); 00537 } 00538 } 00539 00540 inline void vtkPolyData::AddCellReference(vtkIdType cellId) 00541 { 00542 vtkIdType *pts, npts; 00543 00544 this->GetCellPoints(cellId, npts, pts); 00545 for (vtkIdType i=0; i<npts; i++) 00546 { 00547 this->Links->AddCellReference(cellId, pts[i]); 00548 } 00549 } 00550 00551 inline void vtkPolyData::ResizeCellList(vtkIdType ptId, int size) 00552 { 00553 this->Links->ResizeCellList(ptId,size); 00554 } 00555 00556 inline void vtkPolyData::ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId, 00557 vtkIdType newPtId) 00558 { 00559 int i; 00560 vtkIdType *verts, nverts; 00561 00562 this->GetCellPoints(cellId,nverts,verts); 00563 for ( i=0; i < nverts; i++ ) 00564 { 00565 if ( verts[i] == oldPtId ) 00566 { 00567 verts[i] = newPtId; // this is very nasty! direct write! 00568 return; 00569 } 00570 } 00571 } 00572 00573 #endif 00574 00575