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 =========================================================================*/
64 #ifndef vtkPolyData_h
65 #define vtkPolyData_h
66 
67 #include "vtkCommonDataModelModule.h" // For export macro
68 #include "vtkPointSet.h"
69 
70 #include "vtkCellTypes.h" // Needed for inline methods
71 #include "vtkCellLinks.h" // Needed for inline methods
72 #include "vtkCellArray.h" // Needed for inline methods
73 
74 class vtkVertex;
75 class vtkPolyVertex;
76 class vtkLine;
77 class vtkPolyLine;
78 class vtkTriangle;
79 class vtkQuad;
80 class vtkPolygon;
81 class vtkTriangleStrip;
82 class vtkEmptyCell;
83 struct vtkPolyDataDummyContainter;
84 
85 class VTKCOMMONDATAMODEL_EXPORT vtkPolyData : public vtkPointSet
86 {
87 public:
88  static vtkPolyData *New();
89 
90  vtkTypeMacro(vtkPolyData,vtkPointSet);
91  void PrintSelf(ostream& os, vtkIndent indent) override;
92 
96  int GetDataObjectType() override {return VTK_POLY_DATA;}
97 
101  void CopyStructure(vtkDataSet *ds) override;
102 
104 
107  vtkIdType GetNumberOfCells() override;
108  using vtkDataSet::GetCell;
109  vtkCell *GetCell(vtkIdType cellId) override;
110  void GetCell(vtkIdType cellId, vtkGenericCell *cell) override;
111  int GetCellType(vtkIdType cellId) override;
112  void GetCellBounds(vtkIdType cellId, double bounds[6]) override;
113  void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds,
114  vtkIdList *cellIds) override;
116 
123  void CopyCells(vtkPolyData *pd, vtkIdList *idList,
124  vtkPointLocator *locator = nullptr);
125 
129  void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds) override;
130 
135  void GetPointCells(vtkIdType ptId, vtkIdList *cellIds) override;
136 
140  void ComputeBounds() override;
141 
148  void Squeeze() override;
149 
153  int GetMaxCellSize() override;
154 
158  void SetVerts (vtkCellArray* v);
159 
164  vtkCellArray *GetVerts();
165 
169  void SetLines (vtkCellArray* l);
170 
175  vtkCellArray *GetLines();
176 
180  void SetPolys (vtkCellArray* p);
181 
186  vtkCellArray *GetPolys();
187 
191  void SetStrips (vtkCellArray* s);
192 
198  vtkCellArray *GetStrips();
199 
201 
204  vtkIdType GetNumberOfVerts();
205  vtkIdType GetNumberOfLines();
206  vtkIdType GetNumberOfPolys();
207  vtkIdType GetNumberOfStrips();
209 
217  void Allocate(vtkIdType numCells=1000, int extSize=1000);
218 
229  void Allocate(vtkPolyData *inPolyData, vtkIdType numCells=1000,
230  int extSize=1000);
231 
239  vtkIdType InsertNextCell(int type, int npts, const vtkIdType pts[]) VTK_SIZEHINT(pts, npts);
240 
248  vtkIdType InsertNextCell(int type, vtkIdList *pts);
249 
254  void Reset();
255 
263  void BuildCells();
264 
268  bool NeedToBuildCells() { return this->Cells == nullptr; }
269 
276  void BuildLinks(int initialSize=0);
277 
283  void DeleteCells();
284 
288  void DeleteLinks();
289 
293  void GetPointCells(vtkIdType ptId, unsigned short& ncells,
294  vtkIdType* &cells) VTK_SIZEHINT(cells, ncells);
295 
301  void GetCellEdgeNeighbors(vtkIdType cellId, vtkIdType p1, vtkIdType p2,
302  vtkIdList *cellIds);
303 
310  unsigned char GetCellPoints(vtkIdType cellId,
311  vtkIdType& npts, vtkIdType* &pts) VTK_SIZEHINT(pts, npts);
312 
319  unsigned char GetCell(vtkIdType cellId, vtkIdType* &pts);
320 
325  int IsTriangle(int v1, int v2, int v3);
326 
334  int IsEdge(vtkIdType p1, vtkIdType p2);
335 
340  int IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId);
341 
348  void ReplaceCell(vtkIdType cellId, int npts, const vtkIdType pts[]) VTK_SIZEHINT(pts, npts);
349 
353  void ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId,
354  vtkIdType newPtId);
355 
359  void ReverseCell(vtkIdType cellId);
360 
362 
365  void DeletePoint(vtkIdType ptId);
366  void DeleteCell(vtkIdType cellId);
368 
376  void RemoveDeletedCells();
377 
379 
386  vtkIdType InsertNextLinkedPoint(int numLinks);
387  vtkIdType InsertNextLinkedPoint(double x[3], int numLinks);
389 
395  vtkIdType InsertNextLinkedCell(int type, int npts, const vtkIdType pts[]) VTK_SIZEHINT(pts, npts);
396 
405  void ReplaceLinkedCell(vtkIdType cellId, int npts, const vtkIdType pts[]) VTK_SIZEHINT(pts, npts);
406 
413  void RemoveCellReference(vtkIdType cellId);
414 
421  void AddCellReference(vtkIdType cellId);
422 
429  void RemoveReferenceToCell(vtkIdType ptId, vtkIdType cellId);
430 
437  void AddReferenceToCell(vtkIdType ptId, vtkIdType cellId);
438 
443  void ResizeCellList(vtkIdType ptId, int size);
444 
448  void Initialize() override;
449 
451 
454  virtual int GetPiece();
455  virtual int GetNumberOfPieces();
457 
461  virtual int GetGhostLevel();
462 
471  unsigned long GetActualMemorySize() override;
472 
474 
477  void ShallowCopy(vtkDataObject *src) override;
478  void DeepCopy(vtkDataObject *src) override;
480 
486  void RemoveGhostCells();
487 
489 
493  static vtkPolyData* GetData(vtkInformationVector* v, int i=0);
495 
514  enum
515  {
516  ERR_NO_SUCH_FIELD = -4,
517  ERR_INCORRECT_FIELD = -3,
518  ERR_NON_MANIFOLD_STAR = -2,
519  REGULAR_POINT = -1,
520  MINIMUM = 0,
521  SADDLE = 1,
522  MAXIMUM = 2
523  };
524 
525  int GetScalarFieldCriticalIndex (vtkIdType pointId,
526  vtkDataArray *scalarField);
527  int GetScalarFieldCriticalIndex (vtkIdType pointId, int fieldId);
528  int GetScalarFieldCriticalIndex (vtkIdType pointId, const char* fieldName);
529 
537  virtual vtkMTimeType GetMeshMTime();
538 
542  vtkMTimeType GetMTime() override;
543 
544 protected:
545  vtkPolyData();
546  ~vtkPolyData() override;
547 
548  // constant cell objects returned by GetCell called.
558 
559  // points inherited
560  // point data (i.e., scalars, vectors, normals, tcoords) inherited
565 
566  // dummy static member below used as a trick to simplify traversal
567  static vtkPolyDataDummyContainter DummyContainer;
568 
569  // supporting structures for more complex topological operations
570  // built only when necessary
573 
574 private:
575  // Hide these from the user and the compiler.
576 
580  void GetCellNeighbors(vtkIdType cellId, vtkIdList& ptIds, vtkIdList& cellIds)
581  {this->GetCellNeighbors(cellId, &ptIds, &cellIds);}
582 
583  void Cleanup();
584 
585 private:
586  vtkPolyData(const vtkPolyData&) = delete;
587  void operator=(const vtkPolyData&) = delete;
588 };
589 
590 inline void vtkPolyData::GetPointCells(vtkIdType ptId, unsigned short& ncells,
591  vtkIdType* &cells)
592 {
593  ncells = this->Links->GetNcells(ptId);
594  cells = this->Links->GetCells(ptId);
595 }
596 
597 inline int vtkPolyData::IsTriangle(int v1, int v2, int v3)
598 {
599  unsigned short int n1;
600  int i, j, tVerts[3];
601  vtkIdType *cells, *tVerts2, n2;
602 
603  tVerts[0] = v1;
604  tVerts[1] = v2;
605  tVerts[2] = v3;
606 
607  for (i=0; i<3; i++)
608  {
609  this->GetPointCells(tVerts[i], n1, cells);
610  for (j=0; j<n1; j++)
611  {
612  this->GetCellPoints(cells[j], n2, tVerts2);
613  if ( (tVerts[0] == tVerts2[0] || tVerts[0] == tVerts2[1] ||
614  tVerts[0] == tVerts2[2]) &&
615  (tVerts[1] == tVerts2[0] || tVerts[1] == tVerts2[1] ||
616  tVerts[1] == tVerts2[2]) &&
617  (tVerts[2] == tVerts2[0] || tVerts[2] == tVerts2[1] ||
618  tVerts[2] == tVerts2[2]) )
619  {
620  return 1;
621  }
622  }
623  }
624  return 0;
625 }
626 
628 {
629  vtkIdType *pts, npts;
630 
631  this->GetCellPoints(cellId, npts, pts);
632  for (vtkIdType i=0; i < npts; i++)
633  {
634  if ( pts[i] == ptId )
635  {
636  return 1;
637  }
638  }
639 
640  return 0;
641 }
642 
644 {
645  this->Links->DeletePoint(ptId);
646 }
647 
649 {
650  this->Cells->DeleteCell(cellId);
651 }
652 
654 {
655  vtkIdType *pts, npts;
656 
657  this->GetCellPoints(cellId, npts, pts);
658  for (vtkIdType i=0; i<npts; i++)
659  {
660  this->Links->RemoveCellReference(cellId, pts[i]);
661  }
662 }
663 
665 {
666  vtkIdType *pts, npts;
667 
668  this->GetCellPoints(cellId, npts, pts);
669  for (vtkIdType i=0; i<npts; i++)
670  {
671  this->Links->AddCellReference(cellId, pts[i]);
672  }
673 }
674 
676 {
677  this->Links->ResizeCellList(ptId,size);
678 }
679 
681  vtkIdType newPtId)
682 {
683  int i;
684  vtkIdType *verts, nverts;
685 
686  this->GetCellPoints(cellId,nverts,verts);
687  for ( i=0; i < nverts; i++ )
688  {
689  if ( verts[i] == oldPtId )
690  {
691  verts[i] = newPtId; // this is very nasty! direct write!
692  return;
693  }
694  }
695 }
696 
697 inline unsigned char vtkPolyData::GetCellPoints(
698  vtkIdType cellId, vtkIdType& npts, vtkIdType* &pts)
699 {
700  unsigned char type = this->Cells->GetCellType(cellId);
701  vtkCellArray *cells;
702  switch (type)
703  {
704  case VTK_VERTEX: case VTK_POLY_VERTEX:
705  cells = this->Verts;
706  break;
707 
708  case VTK_LINE: case VTK_POLY_LINE:
709  cells = this->Lines;
710  break;
711 
712  case VTK_TRIANGLE: case VTK_QUAD: case VTK_POLYGON:
713  cells = this->Polys;
714  break;
715 
716  case VTK_TRIANGLE_STRIP:
717  cells = this->Strips;
718  break;
719 
720  default:
721  cells = nullptr;
722  npts = 0;
723  pts = nullptr;
724  return 0;
725  }
726  int loc = this->Cells->GetCellLocation(cellId);
727  cells->GetCell(loc, npts, pts);
728  return type;
729 }
730 
731 inline unsigned char vtkPolyData::GetCell(
732  vtkIdType cellId, vtkIdType* &cell)
733 {
734  unsigned char type = this->Cells->GetCellType(cellId);
735  vtkCellArray *cells;
736  switch (type)
737  {
738  case VTK_VERTEX: case VTK_POLY_VERTEX:
739  cells = this->Verts;
740  break;
741 
742  case VTK_LINE: case VTK_POLY_LINE:
743  cells = this->Lines;
744  break;
745 
746  case VTK_TRIANGLE: case VTK_QUAD: case VTK_POLYGON:
747  cells = this->Polys;
748  break;
749 
750  case VTK_TRIANGLE_STRIP:
751  cells = this->Strips;
752  break;
753 
754  default:
755  cells = nullptr;
756  cell = nullptr;
757  return 0;
758  }
759  int loc = this->Cells->GetCellLocation(cellId);
760  cell = cells->GetData()->GetPointer(loc);
761  return type;
762 }
763 
764 #endif
void ComputeBounds() override
Compute the (X, Y, Z) bounds of the data.
vtkCellTypes * Cells
Definition: vtkPolyData.h:571
virtual vtkIdType GetNumberOfCells()=0
Determine the number of cells composing the dataset.
virtual void GetPointCells(vtkIdType ptId, vtkIdList *cellIds)=0
Topological inquiry to get cells using point.
void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds) override
Copy a cells point ids into list provided.
static vtkDataObject * New()
quickly locate points in 3-space
Store vtkAlgorithm input/output information.
vtkCellArray * Strips
Definition: vtkPolyData.h:564
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:302
void ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId, vtkIdType newPtId)
Replace a point in the cell connectivity list with a different point.
Definition: vtkPolyData.h:680
vtkCellArray * Lines
Definition: vtkPolyData.h:562
abstract class to specify dataset behavior
Definition: vtkDataSet.h:62
a cell that represents a 3D point
Definition: vtkVertex.h:36
ValueType * GetPointer(vtkIdType valueIdx)
Get the address of a particular data index.
void GetPointCells(vtkIdType ptId, vtkIdList *cellIds) override
Efficient method to obtain cells using a particular point.
static vtkPointSet * GetData(vtkInformation *info)
Retrieve an instance of this class from an information object.
void AddCellReference(vtkIdType cellId)
Add references to cell in cell structure.
Definition: vtkPolyData.h:664
vtkPolyLine * PolyLine
Definition: vtkPolyData.h:552
a cell that represents a 2D quadrilateral
Definition: vtkQuad.h:41
abstract class for specifying dataset behavior
Definition: vtkPointSet.h:42
an empty cell used as a place-holder during processing
Definition: vtkEmptyCell.h:32
int vtkIdType
Definition: vtkType.h:347
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:85
cell represents a set of 0D vertices
Definition: vtkPolyVertex.h:38
void Squeeze() override
Reclaim any unused memory.
void RemoveCellReference(vtkIdType cellId)
Remove all references to cell in cell structure.
Definition: vtkPolyData.h:653
void DeletePoint(vtkIdType ptId)
Mark a point/cell as deleted from this vtkPolyData.
Definition: vtkPolyData.h:643
provides thread-safe access to cells
int GetDataObjectType() override
Return what type of dataset this is.
Definition: vtkPolyData.h:96
vtkPolyVertex * PolyVertex
Definition: vtkPolyData.h:550
a cell that represents a triangle strip
cell represents a 1D line
Definition: vtkLine.h:35
abstract class to specify cell behavior
Definition: vtkCell.h:59
void DeepCopy(vtkDataObject *src) override
Shallow and Deep copy.
vtkCell * GetCell(vtkIdType cellId) override
Standard vtkDataSet interface.
bool NeedToBuildCells()
Check if BuildCells is needed.
Definition: vtkPolyData.h:268
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
a simple class to control print indentation
Definition: vtkIndent.h:39
virtual int GetMaxCellSize()=0
Convenience method returns largest cell size in dataset.
int IsTriangle(int v1, int v2, int v3)
Given three vertices, determine whether it&#39;s a triangle.
Definition: vtkPolyData.h:597
list of point or cell ids
Definition: vtkIdList.h:36
void Initialize() override
Reset to an empty state and free any memory.
virtual void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds)=0
Topological inquiry to get points defining cell.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
a cell that represents an n-sided polygon
Definition: vtkPolygon.h:45
void ResizeCellList(vtkIdType ptId, int size)
Resize the list of cells using a particular point.
Definition: vtkPolyData.h:675
vtkLine * Line
Definition: vtkPolyData.h:551
virtual void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds, vtkIdList *cellIds)
Topological inquiry to get all cells using list of points exclusive of cell specified (e...
#define VTK_SIZEHINT(...)
vtkMTimeType GetMTime() override
Get MTime which also considers its vtkPoints MTime.
int IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId)
Determine whether a point is used by a particular cell.
Definition: vtkPolyData.h:627
vtkTriangle * Triangle
Definition: vtkPolyData.h:553
object to represent cell connectivity
Definition: vtkCellArray.h:50
vtkEmptyCell * EmptyCell
Definition: vtkPolyData.h:557
vtkCellArray * Polys
Definition: vtkPolyData.h:563
a cell that represents a triangle
Definition: vtkTriangle.h:41
vtkQuad * Quad
Definition: vtkPolyData.h:554
vtkIdTypeArray * GetData()
Return the underlying data as a data array.
Definition: vtkCellArray.h:264
Store zero or more vtkInformation instances.
vtkVertex * Vertex
Definition: vtkPolyData.h:549
vtkCellLinks * Links
Definition: vtkPolyData.h:572
unsigned long GetActualMemorySize() override
Return the actual size of the data in kibibytes (1024 bytes).
void ShallowCopy(vtkDataObject *src) override
Shallow and Deep copy.
void DeleteCell(vtkIdType cellId)
Mark a point/cell as deleted from this vtkPolyData.
Definition: vtkPolyData.h:648
static vtkPolyDataDummyContainter DummyContainer
Definition: vtkPolyData.h:567
vtkCellArray * Verts
Definition: vtkPolyData.h:561
void CopyStructure(vtkDataSet *pd) override
Copy the geometric structure of an input point set object.
#define VTK_POLY_DATA
Definition: vtkType.h:91
general representation of visualization data
Definition: vtkDataObject.h:64
object provides direct access to cells in vtkCellArray and type information
Definition: vtkCellTypes.h:53
virtual vtkCell * GetCell(vtkIdType cellId)=0
Get cell with cellId such that: 0 <= cellId < NumberOfCells.
virtual void GetCellBounds(vtkIdType cellId, double bounds[6])
Get the bounds of the cell with cellId such that: 0 <= cellId < NumberOfCells.
void GetCell(vtkIdType loc, vtkIdType &npts, vtkIdType *&pts)
Internal method used to retrieve a cell given an offset into the internal array.
Definition: vtkCellArray.h:381
cell represents a set of 1D lines
Definition: vtkPolyLine.h:42
virtual int GetCellType(vtkIdType cellId)=0
Get type of cell with cellId such that: 0 <= cellId < NumberOfCells.
vtkPolygon * Polygon
Definition: vtkPolyData.h:555
vtkTriangleStrip * TriangleStrip
Definition: vtkPolyData.h:556