VTK
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 #include "vtkCellArray.h" // Needed for inline methods
72 
73 class vtkVertex;
74 class vtkPolyVertex;
75 class vtkLine;
76 class vtkPolyLine;
77 class vtkTriangle;
78 class vtkQuad;
79 class vtkPolygon;
80 class vtkTriangleStrip;
81 class vtkEmptyCell;
82 struct vtkPolyDataDummyContainter;
83 
85 {
86 public:
87  static vtkPolyData *New();
88 
89  vtkTypeMacro(vtkPolyData,vtkPointSet);
90  void PrintSelf(ostream& os, vtkIndent indent);
91 
94 
97  void CopyStructure(vtkDataSet *ds);
98 
100 
102  vtkCell *GetCell(vtkIdType cellId);
103  void GetCell(vtkIdType cellId, vtkGenericCell *cell);
104  int GetCellType(vtkIdType cellId);
105  void GetCellBounds(vtkIdType cellId, double bounds[6]);
106  void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds,
107  vtkIdList *cellIds);
109 
111 
115  void CopyCells(vtkPolyData *pd, vtkIdList *idList,
116  vtkPointLocator *locator = NULL);
118 
120  void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds);
121 
124  void GetPointCells(vtkIdType ptId, vtkIdList *cellIds);
125 
127  void ComputeBounds();
128 
133  void Squeeze();
134 
136  int GetMaxCellSize();
137 
139  void SetVerts (vtkCellArray* v);
140 
143  vtkCellArray *GetVerts();
144 
146  void SetLines (vtkCellArray* l);
147 
150  vtkCellArray *GetLines();
151 
153  void SetPolys (vtkCellArray* p);
154 
157  vtkCellArray *GetPolys();
158 
160  void SetStrips (vtkCellArray* s);
161 
165  vtkCellArray *GetStrips();
166 
168 
169  vtkIdType GetNumberOfVerts();
170  vtkIdType GetNumberOfLines();
171  vtkIdType GetNumberOfPolys();
172  vtkIdType GetNumberOfStrips();
174 
181  void Allocate(vtkIdType numCells=1000, int extSize=1000);
182 
184 
193  void Allocate(vtkPolyData *inPolyData, vtkIdType numCells=1000,
194  int extSize=1000);
196 
203  vtkIdType InsertNextCell(int type, int npts, vtkIdType *pts);
204 
211  vtkIdType InsertNextCell(int type, vtkIdList *pts);
212 
215  void Reset();
216 
223  void BuildCells();
224 
226  bool NeedToBuildCells() { return this->Cells == 0; }
227 
233  void BuildLinks(int initialSize=0);
234 
238  void DeleteCells();
239 
241  void DeleteLinks();
242 
244 
245  void GetPointCells(vtkIdType ptId, unsigned short& ncells,
246  vtkIdType* &cells);
248 
250 
253  void GetCellEdgeNeighbors(vtkIdType cellId, vtkIdType p1, vtkIdType p2,
254  vtkIdList *cellIds);
256 
258 
262  unsigned char GetCellPoints(vtkIdType cellId,
263  vtkIdType& npts, vtkIdType* &pts);
265 
270  unsigned char GetCell(vtkIdType cellId, vtkIdType* &pts);
271 
274  int IsTriangle(int v1, int v2, int v3);
275 
281  int IsEdge(vtkIdType p1, vtkIdType p2);
282 
285  int IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId);
286 
292  void ReplaceCell(vtkIdType cellId, int npts, vtkIdType *pts);
293 
295 
296  void ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId,
297  vtkIdType newPtId);
299 
301  void ReverseCell(vtkIdType cellId);
302 
304 
305  void DeletePoint(vtkIdType ptId);
306  void DeleteCell(vtkIdType cellId);
308 
314  void RemoveDeletedCells();
315 
317 
323  vtkIdType InsertNextLinkedPoint(int numLinks);
324  vtkIdType InsertNextLinkedPoint(double x[3], int numLinks);
326 
330  vtkIdType InsertNextLinkedCell(int type, int npts, vtkIdType *pts);
331 
338  void ReplaceLinkedCell(vtkIdType cellId, int npts, vtkIdType *pts);
339 
345  void RemoveCellReference(vtkIdType cellId);
346 
352  void AddCellReference(vtkIdType cellId);
353 
359  void RemoveReferenceToCell(vtkIdType ptId, vtkIdType cellId);
360 
365  void AddReferenceToCell(vtkIdType ptId, vtkIdType cellId);
366 
369  void ResizeCellList(vtkIdType ptId, int size);
370 
372  virtual void Initialize();
373 
375 
376  virtual int GetPiece();
377  virtual int GetNumberOfPieces();
379 
381  virtual int GetGhostLevel();
382 
388  unsigned long GetActualMemorySize();
389 
391 
392  void ShallowCopy(vtkDataObject *src);
393  void DeepCopy(vtkDataObject *src);
395 
399  void RemoveGhostCells();
400 
401  //BTX
403 
405  static vtkPolyData* GetData(vtkInformationVector* v, int i=0);
406  //ETX
408 
409 //BTX
411 
425  enum
426  {
427  ERR_NO_SUCH_FIELD = -4,
428  ERR_INCORRECT_FIELD = -3,
429  ERR_NON_MANIFOLD_STAR = -2,
430  REGULAR_POINT = -1,
431  MINIMUM = 0,
432  SADDLE = 1,
433  MAXIMUM = 2
434  };
435 //ETX
436  int GetScalarFieldCriticalIndex (vtkIdType pointId,
437  vtkDataArray *scalarField);
438  int GetScalarFieldCriticalIndex (vtkIdType pointId, int fieldId);
439  int GetScalarFieldCriticalIndex (vtkIdType pointId, const char* fieldName);
441 
442 protected:
443  vtkPolyData();
444  ~vtkPolyData();
445 
446  // constant cell objects returned by GetCell called.
456 
457  // points inherited
458  // point data (i.e., scalars, vectors, normals, tcoords) inherited
463 
464  // dummy static member below used as a trick to simplify traversal
465  static vtkPolyDataDummyContainter DummyContainer;
466 
467  // supporting structures for more complex topological operations
468  // built only when necessary
471 
472 private:
473  // Hide these from the user and the compiler.
474 
476 
477  void GetCellNeighbors(vtkIdType cellId, vtkIdList& ptIds, vtkIdList& cellIds)
478  {this->GetCellNeighbors(cellId, &ptIds, &cellIds);}
480 
481  void Cleanup();
482 
483 private:
484  vtkPolyData(const vtkPolyData&); // Not implemented.
485  void operator=(const vtkPolyData&); // Not implemented.
486 };
487 
488 inline void vtkPolyData::GetPointCells(vtkIdType ptId, unsigned short& ncells,
489  vtkIdType* &cells)
490 {
491  ncells = this->Links->GetNcells(ptId);
492  cells = this->Links->GetCells(ptId);
493 }
494 
495 inline int vtkPolyData::IsTriangle(int v1, int v2, int v3)
496 {
497  unsigned short int n1;
498  int i, j, tVerts[3];
499  vtkIdType *cells, *tVerts2, n2;
500 
501  tVerts[0] = v1;
502  tVerts[1] = v2;
503  tVerts[2] = v3;
504 
505  for (i=0; i<3; i++)
506  {
507  this->GetPointCells(tVerts[i], n1, cells);
508  for (j=0; j<n1; j++)
509  {
510  this->GetCellPoints(cells[j], n2, tVerts2);
511  if ( (tVerts[0] == tVerts2[0] || tVerts[0] == tVerts2[1] ||
512  tVerts[0] == tVerts2[2]) &&
513  (tVerts[1] == tVerts2[0] || tVerts[1] == tVerts2[1] ||
514  tVerts[1] == tVerts2[2]) &&
515  (tVerts[2] == tVerts2[0] || tVerts[2] == tVerts2[1] ||
516  tVerts[2] == tVerts2[2]) )
517  {
518  return 1;
519  }
520  }
521  }
522  return 0;
523 }
524 
526 {
527  vtkIdType *pts, npts;
528 
529  this->GetCellPoints(cellId, npts, pts);
530  for (vtkIdType i=0; i < npts; i++)
531  {
532  if ( pts[i] == ptId )
533  {
534  return 1;
535  }
536  }
537 
538  return 0;
539 }
540 
542 {
543  this->Links->DeletePoint(ptId);
544 }
545 
547 {
548  this->Cells->DeleteCell(cellId);
549 }
550 
552 {
553  vtkIdType *pts, npts;
554 
555  this->GetCellPoints(cellId, npts, pts);
556  for (vtkIdType i=0; i<npts; i++)
557  {
558  this->Links->RemoveCellReference(cellId, pts[i]);
559  }
560 }
561 
563 {
564  vtkIdType *pts, npts;
565 
566  this->GetCellPoints(cellId, npts, pts);
567  for (vtkIdType i=0; i<npts; i++)
568  {
569  this->Links->AddCellReference(cellId, pts[i]);
570  }
571 }
572 
574 {
575  this->Links->ResizeCellList(ptId,size);
576 }
577 
579  vtkIdType newPtId)
580 {
581  int i;
582  vtkIdType *verts, nverts;
583 
584  this->GetCellPoints(cellId,nverts,verts);
585  for ( i=0; i < nverts; i++ )
586  {
587  if ( verts[i] == oldPtId )
588  {
589  verts[i] = newPtId; // this is very nasty! direct write!
590  return;
591  }
592  }
593 }
594 
595 inline unsigned char vtkPolyData::GetCellPoints(
596  vtkIdType cellId, vtkIdType& npts, vtkIdType* &pts)
597 {
598  unsigned char type = this->Cells->GetCellType(cellId);
599  vtkCellArray *cells;
600  switch (type)
601  {
602  case VTK_VERTEX: case VTK_POLY_VERTEX:
603  cells = this->Verts;
604  break;
605 
606  case VTK_LINE: case VTK_POLY_LINE:
607  cells = this->Lines;
608  break;
609 
610  case VTK_TRIANGLE: case VTK_QUAD: case VTK_POLYGON:
611  cells = this->Polys;
612  break;
613 
614  case VTK_TRIANGLE_STRIP:
615  cells = this->Strips;
616  break;
617 
618  default:
619  cells = NULL;
620  npts = 0;
621  pts = NULL;
622  return 0;
623  }
624  int loc = this->Cells->GetCellLocation(cellId);
625  cells->GetCell(loc, npts, pts);
626  return type;
627 }
628 
629 inline unsigned char vtkPolyData::GetCell(
630  vtkIdType cellId, vtkIdType* &cell)
631 {
632  unsigned char type = this->Cells->GetCellType(cellId);
633  vtkCellArray *cells;
634  switch (type)
635  {
636  case VTK_VERTEX: case VTK_POLY_VERTEX:
637  cells = this->Verts;
638  break;
639 
640  case VTK_LINE: case VTK_POLY_LINE:
641  cells = this->Lines;
642  break;
643 
644  case VTK_TRIANGLE: case VTK_QUAD: case VTK_POLYGON:
645  cells = this->Polys;
646  break;
647 
648  case VTK_TRIANGLE_STRIP:
649  cells = this->Strips;
650  break;
651 
652  default:
653  cells = NULL;
654  cell = NULL;
655  return 0;
656  }
657  int loc = this->Cells->GetCellLocation(cellId);
658  cell = cells->GetData()->GetPointer(loc);
659  return type;
660 }
661 
662 #endif
int GetDataObjectType()
Definition: vtkPolyData.h:93
vtkCellTypes * Cells
Definition: vtkPolyData.h:469
void ComputeBounds()
virtual vtkIdType GetNumberOfCells()=0
virtual void GetPointCells(vtkIdType ptId, vtkIdList *cellIds)=0
static vtkDataObject * New()
quickly locate points in 3-space
Store vtkAlgorithm input/output information.
void DeleteCell(vtkIdType cellId)
Definition: vtkCellTypes.h:74
vtkCellArray * Strips
Definition: vtkPolyData.h:462
void ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId, vtkIdType newPtId)
Definition: vtkPolyData.h:578
vtkCellArray * Lines
Definition: vtkPolyData.h:460
abstract class to specify dataset behavior
Definition: vtkDataSet.h:61
a cell that represents a 3D point
Definition: vtkVertex.h:35
void GetPointCells(vtkIdType ptId, vtkIdList *cellIds)
vtkIdType GetCellLocation(int cellId)
Definition: vtkCellTypes.h:71
static vtkPointSet * GetData(vtkInformation *info)
void AddCellReference(vtkIdType cellId)
Definition: vtkPolyData.h:562
void CopyStructure(vtkDataSet *pd)
vtkPolyLine * PolyLine
Definition: vtkPolyData.h:450
a cell that represents a 2D quadrilateral
Definition: vtkQuad.h:40
abstract class for specifying dataset behavior
Definition: vtkPointSet.h:41
void Initialize()
unsigned long GetActualMemorySize()
an empty cell used as a place-holder during processing
Definition: vtkEmptyCell.h:31
int vtkIdType
Definition: vtkType.h:247
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:84
cell represents a set of 0D vertices
Definition: vtkPolyVertex.h:37
void Squeeze()
void RemoveCellReference(vtkIdType cellId)
Definition: vtkPolyData.h:551
void DeletePoint(vtkIdType ptId)
Definition: vtkPolyData.h:541
provides thread-safe access to cells
vtkPolyVertex * PolyVertex
Definition: vtkPolyData.h:448
a cell that represents a triangle strip
cell represents a 1D line
Definition: vtkLine.h:34
abstract class to specify cell behavior
Definition: vtkCell.h:58
bool NeedToBuildCells()
Definition: vtkPolyData.h:226
a simple class to control print indentation
Definition: vtkIndent.h:38
virtual int GetMaxCellSize()=0
int IsTriangle(int v1, int v2, int v3)
Definition: vtkPolyData.h:495
list of point or cell ids
Definition: vtkIdList.h:35
virtual void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds)=0
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
a cell that represents an n-sided polygon
Definition: vtkPolygon.h:44
void ResizeCellList(vtkIdType ptId, int size)
Definition: vtkPolyData.h:573
vtkLine * Line
Definition: vtkPolyData.h:449
virtual void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds, vtkIdList *cellIds)
void PrintSelf(ostream &os, vtkIndent indent)
int IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId)
Definition: vtkPolyData.h:525
vtkTriangle * Triangle
Definition: vtkPolyData.h:451
object to represent cell connectivity
Definition: vtkCellArray.h:49
vtkEmptyCell * EmptyCell
Definition: vtkPolyData.h:455
void DeepCopy(vtkDataObject *src)
vtkCellArray * Polys
Definition: vtkPolyData.h:461
a cell that represents a triangle
Definition: vtkTriangle.h:40
void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds)
vtkQuad * Quad
Definition: vtkPolyData.h:452
unsigned char GetCellType(int cellId)
Definition: vtkCellTypes.h:87
vtkIdTypeArray * GetData()
Definition: vtkCellArray.h:210
Store zero or more vtkInformation instances.
vtkVertex * Vertex
Definition: vtkPolyData.h:447
vtkCellLinks * Links
Definition: vtkPolyData.h:470
void DeleteCell(vtkIdType cellId)
Definition: vtkPolyData.h:546
static vtkPolyDataDummyContainter DummyContainer
Definition: vtkPolyData.h:465
vtkCellArray * Verts
Definition: vtkPolyData.h:459
#define VTK_POLY_DATA
Definition: vtkType.h:64
void ShallowCopy(vtkDataObject *src)
general representation of visualization data
Definition: vtkDataObject.h:64
object provides direct access to cells in vtkCellArray and type information
Definition: vtkCellTypes.h:51
vtkCell * GetCell(vtkIdType cellId)
#define VTKCOMMONDATAMODEL_EXPORT
virtual vtkCell * GetCell(vtkIdType cellId)=0
virtual void GetCellBounds(vtkIdType cellId, double bounds[6])
void GetCell(vtkIdType loc, vtkIdType &npts, vtkIdType *&pts)
Definition: vtkCellArray.h:324
cell represents a set of 1D lines
Definition: vtkPolyLine.h:41
virtual int GetCellType(vtkIdType cellId)=0
vtkPolygon * Polygon
Definition: vtkPolyData.h:453
vtkTriangleStrip * TriangleStrip
Definition: vtkPolyData.h:454