VTK  9.0.1
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 =========================================================================*/
62 #ifndef vtkPolyData_h
63 #define vtkPolyData_h
64 
65 #include "vtkCommonDataModelModule.h" // For export macro
66 #include "vtkPointSet.h"
67 
68 #include "vtkCellArray.h" // Needed for inline methods
69 #include "vtkCellLinks.h" // Needed for inline methods
70 #include "vtkPolyDataInternals.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 struct vtkPolyDataDummyContainter;
83 
84 class VTKCOMMONDATAMODEL_EXPORT vtkPolyData : public vtkPointSet
85 {
86 public:
87  static vtkPolyData* New();
88 
89  vtkTypeMacro(vtkPolyData, vtkPointSet);
90  void PrintSelf(ostream& os, vtkIndent indent) override;
91 
95  int GetDataObjectType() override { return VTK_POLY_DATA; }
96 
100  void CopyStructure(vtkDataSet* ds) override;
101 
103 
106  vtkIdType GetNumberOfCells() override;
107  using vtkDataSet::GetCell;
108  vtkCell* GetCell(vtkIdType cellId) override;
109  void GetCell(vtkIdType cellId, vtkGenericCell* cell) override;
110  int GetCellType(vtkIdType cellId) override;
111  void GetCellBounds(vtkIdType cellId, double bounds[6]) override;
112  void GetCellNeighbors(vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds) override;
114 
122  void CopyCells(vtkPolyData* pd, vtkIdList* idList, vtkIncrementalPointLocator* locator = nullptr);
123 
127  void GetCellPoints(vtkIdType cellId, vtkIdList* ptIds) override;
128 
133  void GetPointCells(vtkIdType ptId, vtkIdList* cellIds) override;
134 
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() { return (this->Verts ? this->Verts->GetNumberOfCells() : 0); }
205  vtkIdType GetNumberOfLines() { return (this->Lines ? this->Lines->GetNumberOfCells() : 0); }
206  vtkIdType GetNumberOfPolys() { return (this->Polys ? this->Polys->GetNumberOfCells() : 0); }
207  vtkIdType GetNumberOfStrips() { return (this->Strips ? this->Strips->GetNumberOfCells() : 0); }
209 
219  bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize);
220 
230  bool AllocateEstimate(vtkIdType numVerts, vtkIdType maxVertSize, vtkIdType numLines,
231  vtkIdType maxLineSize, vtkIdType numPolys, vtkIdType maxPolySize, vtkIdType numStrips,
232  vtkIdType maxStripSize);
233 
243  bool AllocateExact(vtkIdType numCells, vtkIdType connectivitySize);
244 
255  bool AllocateExact(vtkIdType numVerts, vtkIdType vertConnSize, vtkIdType numLines,
256  vtkIdType lineConnSize, vtkIdType numPolys, vtkIdType polyConnSize, vtkIdType numStrips,
257  vtkIdType stripConnSize);
258 
267  bool AllocateCopy(vtkPolyData* pd);
268 
278  bool AllocateProportional(vtkPolyData* pd, double ratio);
279 
286  void Allocate(vtkIdType numCells = 1000, int vtkNotUsed(extSize) = 1000)
287  {
288  this->AllocateExact(numCells, numCells);
289  }
290 
301  void Allocate(vtkPolyData* inPolyData, vtkIdType numCells = 1000, int vtkNotUsed(extSize) = 1000)
302  {
303  this->AllocateProportional(
304  inPolyData, static_cast<double>(numCells) / inPolyData->GetNumberOfCells());
305  }
306 
314  vtkIdType InsertNextCell(int type, int npts, const vtkIdType pts[]) VTK_SIZEHINT(pts, npts);
315 
323  vtkIdType InsertNextCell(int type, vtkIdList* pts);
324 
329  void Reset();
330 
338  void BuildCells();
339 
343  bool NeedToBuildCells() { return this->Cells == nullptr; }
344 
351  void BuildLinks(int initialSize = 0);
352 
358  void DeleteCells();
359 
363  void DeleteLinks();
364 
366 
370  void GetPointCells(vtkIdType ptId, vtkIdType& ncells, vtkIdType*& cells)
371  VTK_SIZEHINT(cells, ncells);
372 #ifndef VTK_LEGACY_REMOVE
373  VTK_LEGACY(void GetPointCells(vtkIdType ptId, unsigned short& ncells, vtkIdType*& cells))
374  VTK_SIZEHINT(cells, ncells);
375 #endif
376 
377 
383  void GetCellEdgeNeighbors(vtkIdType cellId, vtkIdType p1, vtkIdType p2, vtkIdList* cellIds);
384 
394  unsigned char GetCellPoints(vtkIdType cellId, vtkIdType& npts, vtkIdType const*& pts)
395  VTK_SIZEHINT(pts, npts);
396 
401  int IsTriangle(int v1, int v2, int v3);
402 
410  int IsEdge(vtkIdType p1, vtkIdType p2);
411 
416  int IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId);
417 
426  void ReplaceCell(vtkIdType cellId, vtkIdList* ids);
427  void ReplaceCell(vtkIdType cellId, int npts, const vtkIdType pts[]) VTK_SIZEHINT(pts, npts);
434  void ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId, vtkIdType newPtId);
435 
440  void ReverseCell(vtkIdType cellId);
441 
443 
447  void DeletePoint(vtkIdType ptId);
448  void DeleteCell(vtkIdType cellId);
450 
459  void RemoveDeletedCells();
460 
462 
470  vtkIdType InsertNextLinkedPoint(int numLinks);
471  vtkIdType InsertNextLinkedPoint(double x[3], int numLinks);
473 
480  vtkIdType InsertNextLinkedCell(int type, int npts, const vtkIdType pts[]) VTK_SIZEHINT(pts, npts);
481 
491  void ReplaceLinkedCell(vtkIdType cellId, int npts, const vtkIdType pts[]) VTK_SIZEHINT(pts, npts);
492 
500  void RemoveCellReference(vtkIdType cellId);
501 
509  void AddCellReference(vtkIdType cellId);
510 
518  void RemoveReferenceToCell(vtkIdType ptId, vtkIdType cellId);
519 
527  void AddReferenceToCell(vtkIdType ptId, vtkIdType cellId);
528 
534  void ResizeCellList(vtkIdType ptId, int size);
535 
539  void Initialize() override;
540 
542 
545  virtual int GetPiece();
546  virtual int GetNumberOfPieces();
548 
552  virtual int GetGhostLevel();
553 
562  unsigned long GetActualMemorySize() override;
563 
565 
568  void ShallowCopy(vtkDataObject* src) override;
569  void DeepCopy(vtkDataObject* src) override;
571 
577  void RemoveGhostCells();
578 
580 
584  static vtkPolyData* GetData(vtkInformationVector* v, int i = 0);
586 
605  enum
606  {
607  ERR_NO_SUCH_FIELD = -4,
608  ERR_INCORRECT_FIELD = -3,
609  ERR_NON_MANIFOLD_STAR = -2,
610  REGULAR_POINT = -1,
611  MINIMUM = 0,
612  SADDLE = 1,
613  MAXIMUM = 2
614  };
615 
616  int GetScalarFieldCriticalIndex(vtkIdType pointId, vtkDataArray* scalarField);
617  int GetScalarFieldCriticalIndex(vtkIdType pointId, int fieldId);
618  int GetScalarFieldCriticalIndex(vtkIdType pointId, const char* fieldName);
619 
627  virtual vtkMTimeType GetMeshMTime();
628 
632  vtkMTimeType GetMTime() override;
633 
643  unsigned char GetCell(vtkIdType cellId, const vtkIdType*& pts);
644 
645 protected:
646  vtkPolyData();
647  ~vtkPolyData() override;
648 
651 
652  vtkCellArray* GetCellArrayInternal(TaggedCellId tag);
653 
654  // constant cell objects returned by GetCell called.
664 
665  // points inherited
666  // point data (i.e., scalars, vectors, normals, tcoords) inherited
671 
672  // supporting structures for more complex topological operations
673  // built only when necessary
676 
678 
679  // dummy static member below used as a trick to simplify traversal
680  static vtkPolyDataDummyContainter DummyContainer;
681 
682 private:
683  // Hide these from the user and the compiler.
684 
688  void GetCellNeighbors(vtkIdType cellId, vtkIdList& ptIds, vtkIdList& cellIds)
689  {
690  this->GetCellNeighbors(cellId, &ptIds, &cellIds);
691  }
692 
693  void Cleanup();
694 
695 private:
696  vtkPolyData(const vtkPolyData&) = delete;
697  void operator=(const vtkPolyData&) = delete;
698 };
699 
700 //------------------------------------------------------------------------------
701 inline void vtkPolyData::GetPointCells(vtkIdType ptId, vtkIdType& ncells, vtkIdType*& cells)
702 {
703  ncells = this->Links->GetNcells(ptId);
704  cells = this->Links->GetCells(ptId);
705 }
706 
707 #ifndef VTK_LEGACY_REMOVE
708 inline void vtkPolyData::GetPointCells(vtkIdType ptId, unsigned short& ncells, vtkIdType*& cells)
709 {
710  VTK_LEGACY_BODY(vtkPolyData::GetPointCells, "VTK 9.0");
711  ncells = static_cast<unsigned short>(this->Links->GetNcells(ptId));
712  cells = this->Links->GetCells(ptId);
713 }
714 #endif
715 
716 //------------------------------------------------------------------------------
718 {
719  return (this->GetNumberOfVerts() + this->GetNumberOfLines() + this->GetNumberOfPolys() +
720  this->GetNumberOfStrips());
721 }
722 
723 //------------------------------------------------------------------------------
725 {
726  if (!this->Cells)
727  {
728  this->BuildCells();
729  }
730  return static_cast<int>(this->Cells->GetTag(cellId).GetCellType());
731 }
732 
733 //------------------------------------------------------------------------------
734 inline int vtkPolyData::IsTriangle(int v1, int v2, int v3)
735 {
736  vtkIdType n1;
737  int i, j, tVerts[3];
738  vtkIdType* cells;
739  const vtkIdType* tVerts2;
740  vtkIdType n2;
741 
742  tVerts[0] = v1;
743  tVerts[1] = v2;
744  tVerts[2] = v3;
745 
746  for (i = 0; i < 3; i++)
747  {
748  this->GetPointCells(tVerts[i], n1, cells);
749  for (j = 0; j < n1; j++)
750  {
751  this->GetCellPoints(cells[j], n2, tVerts2);
752  if ((tVerts[0] == tVerts2[0] || tVerts[0] == tVerts2[1] || tVerts[0] == tVerts2[2]) &&
753  (tVerts[1] == tVerts2[0] || tVerts[1] == tVerts2[1] || tVerts[1] == tVerts2[2]) &&
754  (tVerts[2] == tVerts2[0] || tVerts[2] == tVerts2[1] || tVerts[2] == tVerts2[2]))
755  {
756  return 1;
757  }
758  }
759  }
760  return 0;
761 }
762 
763 //------------------------------------------------------------------------------
765 {
766  vtkIdType npts;
767  const vtkIdType* pts;
768 
769  this->GetCellPoints(cellId, npts, pts);
770  for (vtkIdType i = 0; i < npts; i++)
771  {
772  if (pts[i] == ptId)
773  {
774  return 1;
775  }
776  }
777 
778  return 0;
779 }
780 
781 //------------------------------------------------------------------------------
783 {
784  this->Links->DeletePoint(ptId);
785 }
786 
787 //------------------------------------------------------------------------------
789 {
790  this->Cells->GetTag(cellId).MarkDeleted();
791 }
792 
793 //------------------------------------------------------------------------------
795 {
796  const vtkIdType* pts;
797  vtkIdType npts;
798 
799  this->GetCellPoints(cellId, npts, pts);
800  for (vtkIdType i = 0; i < npts; i++)
801  {
802  this->Links->RemoveCellReference(cellId, pts[i]);
803  }
804 }
805 
806 //------------------------------------------------------------------------------
808 {
809  const vtkIdType* pts;
810  vtkIdType npts;
811 
812  this->GetCellPoints(cellId, npts, pts);
813  for (vtkIdType i = 0; i < npts; i++)
814  {
815  this->Links->AddCellReference(cellId, pts[i]);
816  }
817 }
818 
819 //------------------------------------------------------------------------------
821 {
822  this->Links->ResizeCellList(ptId, size);
823 }
824 
825 //------------------------------------------------------------------------------
827 {
828  switch (tag.GetTarget())
829  {
831  return this->Verts;
833  return this->Lines;
835  return this->Polys;
837  return this->Strips;
838  }
839  return nullptr; // unreachable
840 }
841 
842 //------------------------------------------------------------------------------
843 inline void vtkPolyData::ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId, vtkIdType newPtId)
844 {
845  vtkNew<vtkIdList> ids;
846  this->GetCellPoints(cellId, ids);
847  for (vtkIdType i = 0; i < ids->GetNumberOfIds(); i++)
848  {
849  if (ids->GetId(i) == oldPtId)
850  {
851  ids->SetId(i, newPtId);
852  break;
853  }
854  }
855  this->ReplaceCell(cellId, static_cast<int>(ids->GetNumberOfIds()), ids->GetPointer(0));
856 }
857 
858 //------------------------------------------------------------------------------
859 inline unsigned char vtkPolyData::GetCellPoints(
860  vtkIdType cellId, vtkIdType& npts, vtkIdType const*& pts)
861 {
862  if (!this->Cells)
863  {
864  this->BuildCells();
865  }
866 
867  const TaggedCellId tag = this->Cells->GetTag(cellId);
868  if (tag.IsDeleted())
869  {
870  npts = 0;
871  pts = nullptr;
872  return VTK_EMPTY_CELL;
873  }
874 
875  vtkCellArray* cells = this->GetCellArrayInternal(tag);
876  cells->GetCellAtId(tag.GetCellId(), npts, pts);
877  return tag.GetCellType();
878 }
879 
880 #endif
void ComputeBounds() override
Compute the (X, Y, Z) bounds of the data.
vtkSmartPointer< vtkCellArray > Verts
Definition: vtkPolyData.h:667
vtkSmartPointer< vtkEmptyCell > EmptyCell
Definition: vtkPolyData.h:663
int GetCellType(vtkIdType cellId) override
Standard vtkDataSet interface.
Definition: vtkPolyData.h:724
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.
unsigned char GetCellType() const noexcept
vtkSmartPointer< vtkPolygon > Polygon
Definition: vtkPolyData.h:661
void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds) override
Copy a cells point ids into list provided.
static vtkDataObject * New()
Store vtkAlgorithm input/output information.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:293
void ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId, vtkIdType newPtId)
Replace a point in the cell connectivity list with a different point.
Definition: vtkPolyData.h:843
abstract class to specify dataset behavior
Definition: vtkDataSet.h:56
a cell that represents a 3D point
Definition: vtkVertex.h:30
void SetId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:89
vtkSmartPointer< vtkPolyLine > PolyLine
Definition: vtkPolyData.h:658
vtkIdType GetCellId() const noexcept
Abstract class in support of both point location and point insertion.
void ReplaceCell(vtkIdType cellId, vtkIdList *ids)
Replace the points defining cell "cellId" with a new set of points.
vtkCellArray * GetCellArrayInternal(TaggedCellId tag)
Definition: vtkPolyData.h:826
vtkIdType GetNumberOfIds()
Return the number of id&#39;s in the list.
Definition: vtkIdList.h:57
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:807
a cell that represents a 2D quadrilateral
Definition: vtkQuad.h:35
abstract class for specifying dataset behavior
Definition: vtkPointSet.h:62
vtkIdType GetNumberOfPolys()
Return the number of primitives of a particular type held.
Definition: vtkPolyData.h:206
vtkSmartPointer< vtkCellLinks > Links
Definition: vtkPolyData.h:675
an empty cell used as a place-holder during processing
Definition: vtkEmptyCell.h:29
int vtkIdType
Definition: vtkType.h:338
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:84
cell represents a set of 0D vertices
Definition: vtkPolyVertex.h:32
void Squeeze() override
Reclaim any unused memory.
void RemoveCellReference(vtkIdType cellId)
Remove all references to cell in cell structure.
Definition: vtkPolyData.h:794
void DeletePoint(vtkIdType ptId)
Mark a point/cell as deleted from this vtkPolyData.
Definition: vtkPolyData.h:782
vtkSmartPointer< vtkCellArray > Polys
Definition: vtkPolyData.h:669
provides thread-safe access to cells
int GetDataObjectType() override
Return what type of dataset this is.
Definition: vtkPolyData.h:95
vtkSmartPointer< vtkPolyVertex > PolyVertex
Definition: vtkPolyData.h:656
a cell that represents a triangle strip
cell represents a 1D line
Definition: vtkLine.h:29
abstract class to specify cell behavior
Definition: vtkCell.h:56
void DeepCopy(vtkDataObject *src) override
Shallow and Deep copy.
vtkSmartPointer< vtkTriangle > Triangle
Definition: vtkPolyData.h:659
bool NeedToBuildCells()
Check if BuildCells is needed.
Definition: vtkPolyData.h:343
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methdos for type information and printing.
a simple class to control print indentation
Definition: vtkIndent.h:33
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:734
vtkSmartPointer< vtkCellArray > Lines
Definition: vtkPolyData.h:668
list of point or cell ids
Definition: vtkIdList.h:30
vtkIdType GetNumberOfVerts()
Return the number of primitives of a particular type held.
Definition: vtkPolyData.h:204
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:49
vtkSmartPointer< CellMap > Cells
Definition: vtkPolyData.h:674
vtkIdType GetNumberOfCells() override
Standard vtkDataSet interface.
Definition: vtkPolyData.h:717
a cell that represents an n-sided polygon
Definition: vtkPolygon.h:39
void ResizeCellList(vtkIdType ptId, int size)
Resize the list of cells using a particular point.
Definition: vtkPolyData.h:820
vtkSmartPointer< vtkQuad > Quad
Definition: vtkPolyData.h:660
vtkIdType GetNumberOfLines()
Return the number of primitives of a particular type held.
Definition: vtkPolyData.h:205
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:764
vtkIdType GetId(const vtkIdType i)
Return the id at location i.
Definition: vtkIdList.h:62
vtkSmartPointer< vtkLine > Line
Definition: vtkPolyData.h:657
object to represent cell connectivity
Definition: vtkCellArray.h:179
void Allocate(vtkPolyData *inPolyData, vtkIdType numCells=1000, int vtkNotUsed(extSize)=1000)
Similar to the method above, this method allocates initial storage for vertex, line, polygon, and triangle strip arrays.
Definition: vtkPolyData.h:301
vtkSmartPointer< vtkTriangleStrip > TriangleStrip
Definition: vtkPolyData.h:662
a cell that represents a triangle
Definition: vtkTriangle.h:35
void BuildCells()
Create data structure that allows random access of cells.
Store zero or more vtkInformation instances.
void Allocate(vtkIdType numCells=1000, int vtkNotUsed(extSize)=1000)
Method allocates initial storage for vertex, line, polygon, and triangle strip arrays.
Definition: vtkPolyData.h:286
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:788
static vtkPolyDataDummyContainter DummyContainer
Definition: vtkPolyData.h:680
void GetCellAtId(vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints)
Return the point ids for the cell at cellId.
void CopyStructure(vtkDataSet *pd) override
Copy the geometric structure of an input point set object.
#define VTK_POLY_DATA
Definition: vtkType.h:85
general representation of visualization data
Definition: vtkDataObject.h:59
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:120
vtkNew< vtkIdList > LegacyBuffer
Definition: vtkPolyData.h:677
virtual vtkCell * GetCell(vtkIdType cellId)=0
Get cell with cellId such that: 0 <= cellId < NumberOfCells.
vtkSmartPointer< vtkCellArray > Strips
Definition: vtkPolyData.h:670
virtual void GetCellBounds(vtkIdType cellId, double bounds[6])
Get the bounds of the cell with cellId such that: 0 <= cellId < NumberOfCells.
vtkSmartPointer< vtkVertex > Vertex
Definition: vtkPolyData.h:655
cell represents a set of 1D lines
Definition: vtkPolyLine.h:36
virtual int GetCellType(vtkIdType cellId)=0
Get type of cell with cellId such that: 0 <= cellId < NumberOfCells.
vtkIdType GetNumberOfStrips()
Return the number of primitives of a particular type held.
Definition: vtkPolyData.h:207