VTK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vtkPolyData.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkPolyData.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
63 #ifndef __vtkPolyData_h
64 #define __vtkPolyData_h
65 
66 #include "vtkCommonDataModelModule.h" // For export macro
67 #include "vtkPointSet.h"
68 
69 #include "vtkCellTypes.h" // Needed for inline methods
70 #include "vtkCellLinks.h" // Needed for inline methods
71 
72 class vtkVertex;
73 class vtkPolyVertex;
74 class vtkLine;
75 class vtkPolyLine;
76 class vtkTriangle;
77 class vtkQuad;
78 class vtkPolygon;
79 class vtkTriangleStrip;
80 class vtkEmptyCell;
81 
82 class VTKCOMMONDATAMODEL_EXPORT vtkPolyData : public vtkPointSet
83 {
84 public:
85  static vtkPolyData *New();
86 
87  vtkTypeMacro(vtkPolyData,vtkPointSet);
88  void PrintSelf(ostream& os, vtkIndent indent);
89 
91  int GetDataObjectType() {return VTK_POLY_DATA;}
92 
95  void CopyStructure(vtkDataSet *ds);
96 
98 
99  vtkIdType GetNumberOfCells();
100  vtkCell *GetCell(vtkIdType cellId);
101  void GetCell(vtkIdType cellId, vtkGenericCell *cell);
102  int GetCellType(vtkIdType cellId);
103  void GetCellBounds(vtkIdType cellId, double bounds[6]);
104  void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds,
105  vtkIdList *cellIds);
107 
109 
113  void CopyCells(vtkPolyData *pd, vtkIdList *idList,
114  vtkPointLocator *locator = NULL);
116 
118  void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds);
119 
122  void GetPointCells(vtkIdType ptId, vtkIdList *cellIds);
123 
125  void ComputeBounds();
126 
131  void Squeeze();
132 
134  int GetMaxCellSize();
135 
137  void SetVerts (vtkCellArray* v);
138 
141  vtkCellArray *GetVerts();
142 
144  void SetLines (vtkCellArray* l);
145 
148  vtkCellArray *GetLines();
149 
151  void SetPolys (vtkCellArray* p);
152 
155  vtkCellArray *GetPolys();
156 
158  void SetStrips (vtkCellArray* s);
159 
163  vtkCellArray *GetStrips();
164 
166 
167  vtkIdType GetNumberOfVerts();
168  vtkIdType GetNumberOfLines();
169  vtkIdType GetNumberOfPolys();
170  vtkIdType GetNumberOfStrips();
172 
179  void Allocate(vtkIdType numCells=1000, int extSize=1000);
180 
182 
191  void Allocate(vtkPolyData *inPolyData, vtkIdType numCells=1000,
192  int extSize=1000);
194 
201  int InsertNextCell(int type, int npts, vtkIdType *pts);
202 
209  int InsertNextCell(int type, vtkIdList *pts);
210 
213  void Reset();
214 
216  void BuildCells();
217 
223  void BuildLinks(int initialSize=0);
224 
228  void DeleteCells();
229 
231  void DeleteLinks();
232 
234 
235  void GetPointCells(vtkIdType ptId, unsigned short& ncells,
236  vtkIdType* &cells);
238 
240 
243  void GetCellEdgeNeighbors(vtkIdType cellId, vtkIdType p1, vtkIdType p2,
244  vtkIdList *cellIds);
246 
249  void GetCellPoints(vtkIdType cellId, vtkIdType& npts, vtkIdType* &pts);
250 
253  int IsTriangle(int v1, int v2, int v3);
254 
260  int IsEdge(vtkIdType p1, vtkIdType p2);
261 
264  int IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId);
265 
271  void ReplaceCell(vtkIdType cellId, int npts, vtkIdType *pts);
272 
274 
275  void ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId,
276  vtkIdType newPtId);
278 
280  void ReverseCell(vtkIdType cellId);
281 
283 
284  void DeletePoint(vtkIdType ptId);
285  void DeleteCell(vtkIdType cellId);
287 
293  void RemoveDeletedCells();
294 
296 
302  int InsertNextLinkedPoint(int numLinks);
303  int InsertNextLinkedPoint(double x[3], int numLinks);
305 
309  int InsertNextLinkedCell(int type, int npts, vtkIdType *pts);
310 
317  void ReplaceLinkedCell(vtkIdType cellId, int npts, vtkIdType *pts);
318 
324  void RemoveCellReference(vtkIdType cellId);
325 
331  void AddCellReference(vtkIdType cellId);
332 
338  void RemoveReferenceToCell(vtkIdType ptId, vtkIdType cellId);
339 
344  void AddReferenceToCell(vtkIdType ptId, vtkIdType cellId);
345 
348  void ResizeCellList(vtkIdType ptId, int size);
349 
351  virtual void Initialize();
352 
354 
355  virtual int GetPiece();
356  virtual int GetNumberOfPieces();
358 
360  virtual int GetGhostLevel();
361 
367  unsigned long GetActualMemorySize();
368 
370 
371  void ShallowCopy(vtkDataObject *src);
372  void DeepCopy(vtkDataObject *src);
374 
377  void RemoveGhostCells(int level);
378 
379  //BTX
381 
382  static vtkPolyData* GetData(vtkInformation* info);
383  static vtkPolyData* GetData(vtkInformationVector* v, int i=0);
384  //ETX
386 
387 //BTX
389 
403  enum
404  {
405  ERR_NO_SUCH_FIELD = -4,
406  ERR_INCORRECT_FIELD = -3,
407  ERR_NON_MANIFOLD_STAR = -2,
408  REGULAR_POINT = -1,
409  MINIMUM = 0,
410  SADDLE = 1,
411  MAXIMUM = 2
412  };
413 //ETX
414  int GetScalarFieldCriticalIndex (vtkIdType pointId,
415  vtkDataArray *scalarField);
416  int GetScalarFieldCriticalIndex (vtkIdType pointId, int fieldId);
417  int GetScalarFieldCriticalIndex (vtkIdType pointId, const char* fieldName);
419 
420 protected:
421  vtkPolyData();
422  ~vtkPolyData();
423 
424  // constant cell objects returned by GetCell called.
426  vtkPolyVertex *PolyVertex;
427  vtkLine *Line;
430  vtkQuad *Quad;
431  vtkPolygon *Polygon;
432  vtkTriangleStrip *TriangleStrip;
434 
435  // points inherited
436  // point data (i.e., scalars, vectors, normals, tcoords) inherited
441 
442  // dummy static member below used as a trick to simplify traversal
444 
445  // supporting structures for more complex topological operations
446  // built only when necessary
447  vtkCellTypes *Cells;
449 
450 private:
451  // Hide these from the user and the compiler.
452 
454 
455  void GetCellNeighbors(vtkIdType cellId, vtkIdList& ptIds, vtkIdList& cellIds)
456  {this->GetCellNeighbors(cellId, &ptIds, &cellIds);}
458 
459  void Cleanup();
460 
461 private:
462  vtkPolyData(const vtkPolyData&); // Not implemented.
463  void operator=(const vtkPolyData&); // Not implemented.
464 };
465 
466 inline void vtkPolyData::GetPointCells(vtkIdType ptId, unsigned short& ncells,
467  vtkIdType* &cells)
468 {
469  ncells = this->Links->GetNcells(ptId);
470  cells = this->Links->GetCells(ptId);
471 }
472 
473 inline int vtkPolyData::IsTriangle(int v1, int v2, int v3)
474 {
475  unsigned short int n1;
476  int i, j, tVerts[3];
477  vtkIdType *cells, *tVerts2, n2;
478 
479  tVerts[0] = v1;
480  tVerts[1] = v2;
481  tVerts[2] = v3;
482 
483  for (i=0; i<3; i++)
484  {
485  this->GetPointCells(tVerts[i], n1, cells);
486  for (j=0; j<n1; j++)
487  {
488  this->GetCellPoints(cells[j], n2, tVerts2);
489  if ( (tVerts[0] == tVerts2[0] || tVerts[0] == tVerts2[1] ||
490  tVerts[0] == tVerts2[2]) &&
491  (tVerts[1] == tVerts2[0] || tVerts[1] == tVerts2[1] ||
492  tVerts[1] == tVerts2[2]) &&
493  (tVerts[2] == tVerts2[0] || tVerts[2] == tVerts2[1] ||
494  tVerts[2] == tVerts2[2]) )
495  {
496  return 1;
497  }
498  }
499  }
500  return 0;
501 }
502 
503 inline int vtkPolyData::IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId)
504 {
505  vtkIdType *pts, npts;
506 
507  this->GetCellPoints(cellId, npts, pts);
508  for (vtkIdType i=0; i < npts; i++)
509  {
510  if ( pts[i] == ptId )
511  {
512  return 1;
513  }
514  }
515 
516  return 0;
517 }
518 
519 inline void vtkPolyData::DeletePoint(vtkIdType ptId)
520 {
521  this->Links->DeletePoint(ptId);
522 }
523 
524 inline void vtkPolyData::DeleteCell(vtkIdType cellId)
525 {
526  this->Cells->DeleteCell(cellId);
527 }
528 
529 inline void vtkPolyData::RemoveCellReference(vtkIdType cellId)
530 {
531  vtkIdType *pts, npts;
532 
533  this->GetCellPoints(cellId, npts, pts);
534  for (vtkIdType i=0; i<npts; i++)
535  {
536  this->Links->RemoveCellReference(cellId, pts[i]);
537  }
538 }
539 
540 inline void vtkPolyData::AddCellReference(vtkIdType cellId)
541 {
542  vtkIdType *pts, npts;
543 
544  this->GetCellPoints(cellId, npts, pts);
545  for (vtkIdType i=0; i<npts; i++)
546  {
547  this->Links->AddCellReference(cellId, pts[i]);
548  }
549 }
550 
551 inline void vtkPolyData::ResizeCellList(vtkIdType ptId, int size)
552 {
553  this->Links->ResizeCellList(ptId,size);
554 }
555 
556 inline void vtkPolyData::ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId,
557  vtkIdType newPtId)
558 {
559  int i;
560  vtkIdType *verts, nverts;
561 
562  this->GetCellPoints(cellId,nverts,verts);
563  for ( i=0; i < nverts; i++ )
564  {
565  if ( verts[i] == oldPtId )
566  {
567  verts[i] = newPtId; // this is very nasty! direct write!
568  return;
569  }
570  }
571 }
572 
573 #endif
574 
575 
static vtkCellArray * Dummy
Definition: vtkPolyData.h:443
int GetDataObjectType()
Definition: vtkPolyData.h:91
vtkCellTypes * Cells
Definition: vtkPolyData.h:447
vtkCellArray * Strips
Definition: vtkPolyData.h:440
void ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId, vtkIdType newPtId)
Definition: vtkPolyData.h:556
vtkCellArray * Lines
Definition: vtkPolyData.h:438
a cell that represents a 3D point
Definition: vtkVertex.h:35
void GetPointCells(vtkIdType ptId, vtkIdList *cellIds)
void AddCellReference(vtkIdType cellId)
Definition: vtkPolyData.h:540
vtkPolyLine * PolyLine
Definition: vtkPolyData.h:428
an empty cell used as a place-holder during processing
Definition: vtkEmptyCell.h:31
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:82
void RemoveCellReference(vtkIdType cellId)
Definition: vtkPolyData.h:529
void DeletePoint(vtkIdType ptId)
Definition: vtkPolyData.h:519
provides thread-safe access to cells
vtkPolyVertex * PolyVertex
Definition: vtkPolyData.h:426
int IsTriangle(int v1, int v2, int v3)
Definition: vtkPolyData.h:473
void ResizeCellList(vtkIdType ptId, int size)
Definition: vtkPolyData.h:551
vtkLine * Line
Definition: vtkPolyData.h:427
int IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId)
Definition: vtkPolyData.h:503
vtkTriangle * Triangle
Definition: vtkPolyData.h:429
object to represent cell connectivity
Definition: vtkCellArray.h:49
vtkEmptyCell * EmptyCell
Definition: vtkPolyData.h:433
vtkCellArray * Polys
Definition: vtkPolyData.h:439
a cell that represents a triangle
Definition: vtkTriangle.h:40
void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds)
vtkQuad * Quad
Definition: vtkPolyData.h:430
vtkVertex * Vertex
Definition: vtkPolyData.h:425
vtkCellLinks * Links
Definition: vtkPolyData.h:448
void DeleteCell(vtkIdType cellId)
Definition: vtkPolyData.h:524
vtkCellArray * Verts
Definition: vtkPolyData.h:437
general representation of visualization data
Definition: vtkDataObject.h:64
cell represents a set of 1D lines
Definition: vtkPolyLine.h:41
vtkPolygon * Polygon
Definition: vtkPolyData.h:431
vtkTriangleStrip * TriangleStrip
Definition: vtkPolyData.h:432