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 struct vtkPolyDataDummyContainter; 00082 00083 class VTKCOMMONDATAMODEL_EXPORT vtkPolyData : public vtkPointSet 00084 { 00085 public: 00086 static vtkPolyData *New(); 00087 00088 vtkTypeMacro(vtkPolyData,vtkPointSet); 00089 void PrintSelf(ostream& os, vtkIndent indent); 00090 00092 int GetDataObjectType() {return VTK_POLY_DATA;} 00093 00096 void CopyStructure(vtkDataSet *ds); 00097 00099 00100 vtkIdType GetNumberOfCells(); 00101 vtkCell *GetCell(vtkIdType cellId); 00102 void GetCell(vtkIdType cellId, vtkGenericCell *cell); 00103 int GetCellType(vtkIdType cellId); 00104 void GetCellBounds(vtkIdType cellId, double bounds[6]); 00105 void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds, 00106 vtkIdList *cellIds); 00108 00110 00114 void CopyCells(vtkPolyData *pd, vtkIdList *idList, 00115 vtkPointLocator *locator = NULL); 00117 00119 void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds); 00120 00123 void GetPointCells(vtkIdType ptId, vtkIdList *cellIds); 00124 00126 void ComputeBounds(); 00127 00132 void Squeeze(); 00133 00135 int GetMaxCellSize(); 00136 00138 void SetVerts (vtkCellArray* v); 00139 00142 vtkCellArray *GetVerts(); 00143 00145 void SetLines (vtkCellArray* l); 00146 00149 vtkCellArray *GetLines(); 00150 00152 void SetPolys (vtkCellArray* p); 00153 00156 vtkCellArray *GetPolys(); 00157 00159 void SetStrips (vtkCellArray* s); 00160 00164 vtkCellArray *GetStrips(); 00165 00167 00168 vtkIdType GetNumberOfVerts(); 00169 vtkIdType GetNumberOfLines(); 00170 vtkIdType GetNumberOfPolys(); 00171 vtkIdType GetNumberOfStrips(); 00173 00180 void Allocate(vtkIdType numCells=1000, int extSize=1000); 00181 00183 00192 void Allocate(vtkPolyData *inPolyData, vtkIdType numCells=1000, 00193 int extSize=1000); 00195 00202 vtkIdType InsertNextCell(int type, int npts, vtkIdType *pts); 00203 00210 vtkIdType InsertNextCell(int type, vtkIdList *pts); 00211 00214 void Reset(); 00215 00217 void BuildCells(); 00218 00224 void BuildLinks(int initialSize=0); 00225 00229 void DeleteCells(); 00230 00232 void DeleteLinks(); 00233 00235 00236 void GetPointCells(vtkIdType ptId, unsigned short& ncells, 00237 vtkIdType* &cells); 00239 00241 00244 void GetCellEdgeNeighbors(vtkIdType cellId, vtkIdType p1, vtkIdType p2, 00245 vtkIdList *cellIds); 00247 00250 void GetCellPoints(vtkIdType cellId, vtkIdType& npts, vtkIdType* &pts); 00251 00254 int IsTriangle(int v1, int v2, int v3); 00255 00261 int IsEdge(vtkIdType p1, vtkIdType p2); 00262 00265 int IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId); 00266 00272 void ReplaceCell(vtkIdType cellId, int npts, vtkIdType *pts); 00273 00275 00276 void ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId, 00277 vtkIdType newPtId); 00279 00281 void ReverseCell(vtkIdType cellId); 00282 00284 00285 void DeletePoint(vtkIdType ptId); 00286 void DeleteCell(vtkIdType cellId); 00288 00294 void RemoveDeletedCells(); 00295 00297 00303 vtkIdType InsertNextLinkedPoint(int numLinks); 00304 vtkIdType InsertNextLinkedPoint(double x[3], int numLinks); 00306 00310 vtkIdType InsertNextLinkedCell(int type, int npts, vtkIdType *pts); 00311 00318 void ReplaceLinkedCell(vtkIdType cellId, int npts, vtkIdType *pts); 00319 00325 void RemoveCellReference(vtkIdType cellId); 00326 00332 void AddCellReference(vtkIdType cellId); 00333 00339 void RemoveReferenceToCell(vtkIdType ptId, vtkIdType cellId); 00340 00345 void AddReferenceToCell(vtkIdType ptId, vtkIdType cellId); 00346 00349 void ResizeCellList(vtkIdType ptId, int size); 00350 00352 virtual void Initialize(); 00353 00355 00356 virtual int GetPiece(); 00357 virtual int GetNumberOfPieces(); 00359 00361 virtual int GetGhostLevel(); 00362 00368 unsigned long GetActualMemorySize(); 00369 00371 00372 void ShallowCopy(vtkDataObject *src); 00373 void DeepCopy(vtkDataObject *src); 00375 00378 void RemoveGhostCells(int level); 00379 00380 //BTX 00382 00383 static vtkPolyData* GetData(vtkInformation* info); 00384 static vtkPolyData* GetData(vtkInformationVector* v, int i=0); 00385 //ETX 00387 00388 //BTX 00390 00404 enum 00405 { 00406 ERR_NO_SUCH_FIELD = -4, 00407 ERR_INCORRECT_FIELD = -3, 00408 ERR_NON_MANIFOLD_STAR = -2, 00409 REGULAR_POINT = -1, 00410 MINIMUM = 0, 00411 SADDLE = 1, 00412 MAXIMUM = 2 00413 }; 00414 //ETX 00415 int GetScalarFieldCriticalIndex (vtkIdType pointId, 00416 vtkDataArray *scalarField); 00417 int GetScalarFieldCriticalIndex (vtkIdType pointId, int fieldId); 00418 int GetScalarFieldCriticalIndex (vtkIdType pointId, const char* fieldName); 00420 00421 protected: 00422 vtkPolyData(); 00423 ~vtkPolyData(); 00424 00425 // constant cell objects returned by GetCell called. 00426 vtkVertex *Vertex; 00427 vtkPolyVertex *PolyVertex; 00428 vtkLine *Line; 00429 vtkPolyLine *PolyLine; 00430 vtkTriangle *Triangle; 00431 vtkQuad *Quad; 00432 vtkPolygon *Polygon; 00433 vtkTriangleStrip *TriangleStrip; 00434 vtkEmptyCell *EmptyCell; 00435 00436 // points inherited 00437 // point data (i.e., scalars, vectors, normals, tcoords) inherited 00438 vtkCellArray *Verts; 00439 vtkCellArray *Lines; 00440 vtkCellArray *Polys; 00441 vtkCellArray *Strips; 00442 00443 // dummy static member below used as a trick to simplify traversal 00444 static vtkPolyDataDummyContainter DummyContainer; 00445 00446 // supporting structures for more complex topological operations 00447 // built only when necessary 00448 vtkCellTypes *Cells; 00449 vtkCellLinks *Links; 00450 00451 private: 00452 // Hide these from the user and the compiler. 00453 00455 00456 void GetCellNeighbors(vtkIdType cellId, vtkIdList& ptIds, vtkIdList& cellIds) 00457 {this->GetCellNeighbors(cellId, &ptIds, &cellIds);} 00459 00460 void Cleanup(); 00461 00462 private: 00463 vtkPolyData(const vtkPolyData&); // Not implemented. 00464 void operator=(const vtkPolyData&); // Not implemented. 00465 }; 00466 00467 inline void vtkPolyData::GetPointCells(vtkIdType ptId, unsigned short& ncells, 00468 vtkIdType* &cells) 00469 { 00470 ncells = this->Links->GetNcells(ptId); 00471 cells = this->Links->GetCells(ptId); 00472 } 00473 00474 inline int vtkPolyData::IsTriangle(int v1, int v2, int v3) 00475 { 00476 unsigned short int n1; 00477 int i, j, tVerts[3]; 00478 vtkIdType *cells, *tVerts2, n2; 00479 00480 tVerts[0] = v1; 00481 tVerts[1] = v2; 00482 tVerts[2] = v3; 00483 00484 for (i=0; i<3; i++) 00485 { 00486 this->GetPointCells(tVerts[i], n1, cells); 00487 for (j=0; j<n1; j++) 00488 { 00489 this->GetCellPoints(cells[j], n2, tVerts2); 00490 if ( (tVerts[0] == tVerts2[0] || tVerts[0] == tVerts2[1] || 00491 tVerts[0] == tVerts2[2]) && 00492 (tVerts[1] == tVerts2[0] || tVerts[1] == tVerts2[1] || 00493 tVerts[1] == tVerts2[2]) && 00494 (tVerts[2] == tVerts2[0] || tVerts[2] == tVerts2[1] || 00495 tVerts[2] == tVerts2[2]) ) 00496 { 00497 return 1; 00498 } 00499 } 00500 } 00501 return 0; 00502 } 00503 00504 inline int vtkPolyData::IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId) 00505 { 00506 vtkIdType *pts, npts; 00507 00508 this->GetCellPoints(cellId, npts, pts); 00509 for (vtkIdType i=0; i < npts; i++) 00510 { 00511 if ( pts[i] == ptId ) 00512 { 00513 return 1; 00514 } 00515 } 00516 00517 return 0; 00518 } 00519 00520 inline void vtkPolyData::DeletePoint(vtkIdType ptId) 00521 { 00522 this->Links->DeletePoint(ptId); 00523 } 00524 00525 inline void vtkPolyData::DeleteCell(vtkIdType cellId) 00526 { 00527 this->Cells->DeleteCell(cellId); 00528 } 00529 00530 inline void vtkPolyData::RemoveCellReference(vtkIdType cellId) 00531 { 00532 vtkIdType *pts, npts; 00533 00534 this->GetCellPoints(cellId, npts, pts); 00535 for (vtkIdType i=0; i<npts; i++) 00536 { 00537 this->Links->RemoveCellReference(cellId, pts[i]); 00538 } 00539 } 00540 00541 inline void vtkPolyData::AddCellReference(vtkIdType cellId) 00542 { 00543 vtkIdType *pts, npts; 00544 00545 this->GetCellPoints(cellId, npts, pts); 00546 for (vtkIdType i=0; i<npts; i++) 00547 { 00548 this->Links->AddCellReference(cellId, pts[i]); 00549 } 00550 } 00551 00552 inline void vtkPolyData::ResizeCellList(vtkIdType ptId, int size) 00553 { 00554 this->Links->ResizeCellList(ptId,size); 00555 } 00556 00557 inline void vtkPolyData::ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId, 00558 vtkIdType newPtId) 00559 { 00560 int i; 00561 vtkIdType *verts, nverts; 00562 00563 this->GetCellPoints(cellId,nverts,verts); 00564 for ( i=0; i < nverts; i++ ) 00565 { 00566 if ( verts[i] == oldPtId ) 00567 { 00568 verts[i] = newPtId; // this is very nasty! direct write! 00569 return; 00570 } 00571 } 00572 } 00573 00574 #endif