VTK  9.7.1
vtkPolyData.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
56 #ifndef vtkPolyData_h
57 #define vtkPolyData_h
58 
59 #include "vtkCommonDataModelModule.h" // For export macro
60 #include "vtkPointSet.h"
61 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
62 
63 #include "vtkCellArray.h" // Needed for inline methods
64 #include "vtkCellLinks.h" // Needed for inline methods
65 #include "vtkPolyDataInternals.h" // Needed for inline methods
66 
67 VTK_ABI_NAMESPACE_BEGIN
68 struct vtkPolyDataDummyContainter;
70 
71 class VTKCOMMONDATAMODEL_EXPORT VTK_MARSHALAUTO vtkPolyData : public vtkPointSet
72 {
73 public:
74  static vtkPolyData* New();
75  static vtkPolyData* ExtendedNew();
76 
77  vtkTypeMacro(vtkPolyData, vtkPointSet);
78  void PrintSelf(ostream& os, vtkIndent indent) override;
79 
83  int GetDataObjectType() VTK_FUTURE_CONST override { return VTK_POLY_DATA; }
84 
88  void CopyStructure(vtkDataSet* ds) override;
89 
91 
94  inline vtkIdType GetNumberOfCells() override;
95  using vtkDataSet::GetCell;
96  vtkCell* GetCell(vtkIdType cellId) override;
97  void GetCell(vtkIdType cellId, vtkGenericCell* cell) override;
98  int GetCellType(vtkIdType cellId) override;
99  vtkIdType GetCellSize(vtkIdType cellId) override;
100  void GetCellBounds(vtkIdType cellId, double bounds[6]) override;
101  void GetCellNeighbors(vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds) override;
103 
111  void CopyCells(vtkPolyData* pd, vtkIdList* idList, vtkIncrementalPointLocator* locator = nullptr);
112 
116  void GetCellPoints(vtkIdType cellId, vtkIdList* ptIds) override;
117 
122  void GetPointCells(vtkIdType ptId, vtkIdList* cellIds) override;
123 
142  void ComputeCellsBounds();
143 
149  void GetCellsBounds(double bounds[6]);
150 
157  void Squeeze() override;
158 
162  int GetMaxCellSize() override;
163 
165 
169  int GetMaxSpatialDimension() override;
170  int GetMinSpatialDimension() override;
172 
178  vtkIdType GetCellIdRelativeToCellArray(vtkIdType cellId);
179 
183  void SetVerts(vtkCellArray* v);
184 
189  vtkCellArray* GetVerts();
190 
194  void SetLines(vtkCellArray* l);
195 
200  vtkCellArray* GetLines();
201 
205  void SetPolys(vtkCellArray* p);
206 
211  vtkCellArray* GetPolys();
212 
216  void SetStrips(vtkCellArray* s);
217 
223  vtkCellArray* GetStrips();
224 
226 
229  vtkIdType GetNumberOfVerts() { return (this->Verts ? this->Verts->GetNumberOfCells() : 0); }
230  vtkIdType GetNumberOfLines() { return (this->Lines ? this->Lines->GetNumberOfCells() : 0); }
231  vtkIdType GetNumberOfPolys() { return (this->Polys ? this->Polys->GetNumberOfCells() : 0); }
232  vtkIdType GetNumberOfStrips() { return (this->Strips ? this->Strips->GetNumberOfCells() : 0); }
234 
244  bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize);
245 
255  bool AllocateEstimate(vtkIdType numVerts, vtkIdType maxVertSize, vtkIdType numLines,
256  vtkIdType maxLineSize, vtkIdType numPolys, vtkIdType maxPolySize, vtkIdType numStrips,
257  vtkIdType maxStripSize);
258 
268  bool AllocateExact(vtkIdType numCells, vtkIdType connectivitySize);
269 
280  bool AllocateExact(vtkIdType numVerts, vtkIdType vertConnSize, vtkIdType numLines,
281  vtkIdType lineConnSize, vtkIdType numPolys, vtkIdType polyConnSize, vtkIdType numStrips,
282  vtkIdType stripConnSize);
283 
292  bool AllocateCopy(vtkPolyData* pd);
293 
303  bool AllocateProportional(vtkPolyData* pd, double ratio);
304 
311  void Allocate(vtkIdType numCells = 1000, int vtkNotUsed(extSize) = 1000)
312  {
313  this->AllocateExact(numCells, numCells);
314  }
315 
326  void Allocate(vtkPolyData* inPolyData, vtkIdType numCells = 1000, int vtkNotUsed(extSize) = 1000)
327  {
328  this->AllocateProportional(
329  inPolyData, static_cast<double>(numCells) / inPolyData->GetNumberOfCells());
330  }
331 
339  vtkIdType InsertNextCell(int type, int npts, const vtkIdType pts[]) VTK_SIZEHINT(pts, npts);
340 
348  vtkIdType InsertNextCell(int type, vtkIdList* pts);
349 
354  void Reset();
355 
363  void BuildCells();
364 
368  bool NeedToBuildCells() { return this->Cells == nullptr; }
369 
376  void BuildLinks(int initialSize = 0);
377 
379 
382  vtkSetSmartPointerMacro(Links, vtkAbstractCellLinks);
383  vtkGetSmartPointerMacro(Links, vtkAbstractCellLinks);
385 
391  void DeleteCells();
392 
396  void DeleteLinks();
397 
399 
403  void GetPointCells(vtkIdType ptId, vtkIdType& ncells, vtkIdType*& cells)
404  VTK_SIZEHINT(cells, ncells);
406 
412  void GetCellEdgeNeighbors(vtkIdType cellId, vtkIdType p1, vtkIdType p2, vtkIdList* cellIds);
413 
425  inline unsigned char GetCellPoints(vtkIdType cellId, vtkIdType& npts, vtkIdType const*& pts)
426  VTK_SIZEHINT(pts, npts);
427 
442  inline void GetCellPoints(vtkIdType cellId, vtkIdType& npts, vtkIdType const*& pts,
443  vtkIdList* ptIds) VTK_SIZEHINT(pts, npts) override;
444 
449  int IsTriangle(int v1, int v2, int v3);
450 
458  int IsEdge(vtkIdType p1, vtkIdType p2);
459 
464  int IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId);
465 
474  void ReplaceCell(vtkIdType cellId, vtkIdList* ids);
475  void ReplaceCell(vtkIdType cellId, int npts, const vtkIdType pts[]) VTK_SIZEHINT(pts, npts);
478 
488  inline void ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId, vtkIdType newPtId);
489  inline void ReplaceCellPoint(
490  vtkIdType cellId, vtkIdType oldPtId, vtkIdType newPtId, vtkIdList* cellPointIds);
492 
497  void ReverseCell(vtkIdType cellId);
498 
500 
504  void DeletePoint(vtkIdType ptId);
505  void DeleteCell(vtkIdType cellId);
507 
516  void RemoveDeletedCells();
517 
519 
527  vtkIdType InsertNextLinkedPoint(int numLinks);
528  vtkIdType InsertNextLinkedPoint(double x[3], int numLinks);
530 
537  vtkIdType InsertNextLinkedCell(int type, int npts, const vtkIdType pts[]) VTK_SIZEHINT(pts, npts);
538 
548  void ReplaceLinkedCell(vtkIdType cellId, int npts, const vtkIdType pts[]) VTK_SIZEHINT(pts, npts);
549 
557  void RemoveCellReference(vtkIdType cellId);
558 
566  void AddCellReference(vtkIdType cellId);
567 
575  void RemoveReferenceToCell(vtkIdType ptId, vtkIdType cellId);
576 
584  void AddReferenceToCell(vtkIdType ptId, vtkIdType cellId);
585 
591  void ResizeCellList(vtkIdType ptId, int size);
592 
596  void Initialize() override;
597 
599 
602  virtual int GetPiece();
603  virtual int GetNumberOfPieces();
605 
609  virtual int GetGhostLevel();
610 
619  unsigned long GetActualMemorySize() override;
620 
622 
625  void ShallowCopy(vtkDataObject* src) override;
626  void DeepCopy(vtkDataObject* src) override;
628 
635  void RemoveGhostCells();
636 
638 
642  static vtkPolyData* GetData(vtkInformationVector* v, int i = 0);
644 
663  enum
664  {
665  ERR_NO_SUCH_FIELD = -4,
666  ERR_INCORRECT_FIELD = -3,
667  ERR_NON_MANIFOLD_STAR = -2,
668  REGULAR_POINT = -1,
669  MINIMUM = 0,
670  SADDLE = 1,
671  MAXIMUM = 2
672  };
673 
674  int GetScalarFieldCriticalIndex(vtkIdType pointId, vtkDataArray* scalarField);
675  int GetScalarFieldCriticalIndex(vtkIdType pointId, int fieldId);
676  int GetScalarFieldCriticalIndex(vtkIdType pointId, const char* fieldName);
677 
685  vtkMTimeType GetMeshMTime() override;
686 
690  vtkMTimeType GetMTime() override;
691 
701  unsigned char GetCell(vtkIdType cellId, const vtkIdType*& pts);
702 
703 protected:
704  vtkPolyData();
705  ~vtkPolyData() override;
706 
707  void ReportReferences(vtkGarbageCollector*) override;
708 
711 
712  vtkCellArray* GetCellArrayInternal(TaggedCellId tag);
713 
714  // points inherited
715  // point data (i.e., scalars, vectors, normals, tcoords) inherited
720 
721  // supporting structures for more complex topological operations
722  // built only when necessary
725 
727 
728  // dummy static member below used as a trick to simplify traversal
729  static vtkPolyDataDummyContainter DummyContainer;
730 
731  // Take into account only points that belong to at least one cell.
732  double CellsBounds[6];
733 
735 
736 private:
737  void Cleanup();
738 
739  vtkPolyData(const vtkPolyData&) = delete;
740  void operator=(const vtkPolyData&) = delete;
741 };
742 
743 //------------------------------------------------------------------------------
745 {
746  return (this->GetNumberOfVerts() + this->GetNumberOfLines() + this->GetNumberOfPolys() +
747  this->GetNumberOfStrips());
748 }
749 
750 //------------------------------------------------------------------------------
752 {
753  if (!this->Cells)
754  {
755  this->BuildCells();
756  }
757  return static_cast<int>(this->Cells->GetTag(cellId).GetCellType());
758 }
759 
760 //------------------------------------------------------------------------------
762 {
763  if (!this->Cells)
764  {
765  this->BuildCells();
766  }
767  switch (this->GetCellType(cellId))
768  {
769  case VTK_EMPTY_CELL:
770  return 0;
771  case VTK_VERTEX:
772  return 1;
773  case VTK_LINE:
774  return 2;
775  case VTK_TRIANGLE:
776  return 3;
777  case VTK_QUAD:
778  return 4;
779  case VTK_POLY_VERTEX:
780  return this->Verts ? this->Verts->GetCellSize(this->GetCellIdRelativeToCellArray(cellId)) : 0;
781  case VTK_POLY_LINE:
782  return this->Lines ? this->Lines->GetCellSize(this->GetCellIdRelativeToCellArray(cellId)) : 0;
783  case VTK_POLYGON:
784  return this->Polys ? this->Polys->GetCellSize(this->GetCellIdRelativeToCellArray(cellId)) : 0;
785  case VTK_TRIANGLE_STRIP:
786  return this->Strips ? this->Strips->GetCellSize(this->GetCellIdRelativeToCellArray(cellId))
787  : 0;
788  }
789  vtkWarningMacro(<< "Cell type not supported.");
790  return 0;
791 }
792 
793 //------------------------------------------------------------------------------
795 {
796  vtkIdType npts;
797  const vtkIdType* pts;
798 
799  this->GetCellPoints(cellId, npts, pts);
800  for (vtkIdType i = 0; i < npts; i++)
801  {
802  if (pts[i] == ptId)
803  {
804  return 1;
805  }
806  }
807 
808  return 0;
809 }
810 
811 //------------------------------------------------------------------------------
813 {
814  static_cast<vtkCellLinks*>(this->Links.Get())->DeletePoint(ptId);
815 }
816 
817 //------------------------------------------------------------------------------
819 {
820  this->Cells->GetTag(cellId).MarkDeleted();
821 }
822 
823 //------------------------------------------------------------------------------
825 {
826  const vtkIdType* pts;
827  vtkIdType npts;
828 
829  this->GetCellPoints(cellId, npts, pts);
830  auto links = static_cast<vtkCellLinks*>(this->Links.Get());
831  for (vtkIdType i = 0; i < npts; i++)
832  {
833  links->RemoveCellReference(cellId, pts[i]);
834  }
835 }
836 
837 //------------------------------------------------------------------------------
839 {
840  const vtkIdType* pts;
841  vtkIdType npts;
842 
843  this->GetCellPoints(cellId, npts, pts);
844  auto links = static_cast<vtkCellLinks*>(this->Links.Get());
845  for (vtkIdType i = 0; i < npts; i++)
846  {
847  links->AddCellReference(cellId, pts[i]);
848  }
849 }
850 
851 //------------------------------------------------------------------------------
853 {
854  static_cast<vtkCellLinks*>(this->Links.Get())->ResizeCellList(ptId, size);
855 }
856 
857 //------------------------------------------------------------------------------
859 {
860  switch (tag.GetTarget())
861  {
863  return this->Verts;
865  return this->Lines;
867  return this->Polys;
869  return this->Strips;
870  }
871  return nullptr; // unreachable
872 }
873 
874 //------------------------------------------------------------------------------
876 {
877  vtkNew<vtkIdList> ids;
878  this->ReplaceCellPoint(cellId, oldPtId, newPtId, ids);
879 }
880 
881 //------------------------------------------------------------------------------
883  vtkIdType cellId, vtkIdType oldPtId, vtkIdType newPtId, vtkIdList* cellPointIds)
884 {
885  if (!this->Cells)
886  {
887  this->BuildCells();
888  }
889  vtkIdType npts;
890  const vtkIdType* pts;
891  this->GetCellPoints(cellId, npts, pts, cellPointIds);
892  for (vtkIdType i = 0; i < npts; i++)
893  {
894  if (pts[i] == oldPtId)
895  {
896  const TaggedCellId tag = this->Cells->GetTag(cellId);
897  vtkCellArray* cells = this->GetCellArrayInternal(tag);
898  cells->ReplaceCellPointAtId(tag.GetCellId(), i, newPtId);
899  break;
900  }
901  }
902 }
903 
904 //------------------------------------------------------------------------------
905 unsigned char vtkPolyData::GetCellPoints(vtkIdType cellId, vtkIdType& npts, vtkIdType const*& pts)
906 {
907  if (!this->Cells)
908  {
909  this->BuildCells();
910  }
911 
912  const TaggedCellId tag = this->Cells->GetTag(cellId);
913  if (tag.IsDeleted())
914  {
915  npts = 0;
916  pts = nullptr;
917  return VTK_EMPTY_CELL;
918  }
919 
920  vtkCellArray* cells = this->GetCellArrayInternal(tag);
921  cells->GetCellAtId(tag.GetCellId(), npts, pts);
922  return tag.GetCellType();
923 }
924 
925 //------------------------------------------------------------------------------
927  vtkIdType cellId, vtkIdType& npts, vtkIdType const*& pts, vtkIdList* ptIds)
928 {
929  if (!this->Cells)
930  {
931  this->BuildCells();
932  }
933 
934  const TaggedCellId tag = this->Cells->GetTag(cellId);
935  if (tag.IsDeleted())
936  {
937  npts = 0;
938  pts = nullptr;
939  }
940  else
941  {
942  vtkCellArray* cells = this->GetCellArrayInternal(tag);
943  cells->GetCellAtId(tag.GetCellId(), npts, pts, ptIds);
944  }
945 }
946 
947 VTK_ABI_NAMESPACE_END
948 #endif
void ReplaceCellPointAtId(vtkIdType cellId, vtkIdType cellPointIndex, vtkIdType newPointId)
Replaces the pointId at cellPointIndex of a cell with newPointId.
vtkIdType GetCellSize(vtkIdType cellId) override
Standard vtkDataSet interface.
Definition: vtkPolyData.h:761
vtkSmartPointer< vtkAbstractCellLinks > Links
Definition: vtkPolyData.h:724
vtkIdType GetCellSize(vtkIdType) override
This method always returns 1, as all cells are point in a pure vtkPointSet.
Definition: vtkPointSet.h:156
vtkSmartPointer< vtkCellArray > Verts
Definition: vtkPolyData.h:716
int GetCellType(vtkIdType cellId) override
Standard vtkDataSet interface.
Definition: vtkPolyData.h:751
void GetCellAtId(vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints, vtkIdList *ptIds) override
Return the point ids for the cell at cellId.
void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds) override
Copy a cells point ids into list provided.
Store vtkAlgorithm input/output information.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:318
void ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId, vtkIdType newPtId)
Replace a point in the cell connectivity list with a different point.
Definition: vtkPolyData.h:875
abstract class to specify dataset behavior
Definition: vtkDataSet.h:56
unsigned char GetCellType() const noexcept
vtkTimeStamp CellsBoundsTime
Definition: vtkPolyData.h:734
record modification and/or execution time
Definition: vtkTimeStamp.h:24
vtkIdType GetCellIdRelativeToCellArray(vtkIdType cellId)
Maps the cell at position cellId inside the vtkPolyData to its location in the corresponding cell arr...
Abstract class in support of both point location and point insertion.
vtkIdType GetCellSize(vtkIdType cellId) const override
Return the size of the cell at cellId.
vtkCellArray * GetCellArrayInternal(TaggedCellId tag)
Definition: vtkPolyData.h:858
void GetCellPoints(vtkIdType, vtkIdList *idList) override
Topological inquiry to get points defining cell.
Definition: vtkPointSet.h:137
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:838
concrete class for storing a set of points
Definition: vtkPointSet.h:58
vtkIdType GetNumberOfPolys()
Return the number of primitives of a particular type held.
Definition: vtkPolyData.h:231
vtkIdType GetNumberOfCells() override
This method always returns 0, as there are no cells in a vtkPointSet.
Definition: vtkPointSet.h:121
virtual int GetMaxSpatialDimension()
Get the maximum/minimum spatial dimensionality of the data which is the maximum/minimum dimension of ...
virtual vtkMTimeType GetMeshMTime()
Abstract method which return the mesh (geometry/topology) modification time.
int vtkIdType
Definition: vtkType.h:363
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:71
void Squeeze() override
Reclaim any unused memory.
void RemoveCellReference(vtkIdType cellId)
Remove all references to cell in cell structure.
Definition: vtkPolyData.h:824
void DeletePoint(vtkIdType ptId)
Mark a point/cell as deleted from this vtkPolyData.
Definition: vtkPolyData.h:812
int GetCellType(vtkIdType) override
This method always returns VTK_EMPTY_CELL, as there is no cell in a vtkPointSet.
Definition: vtkPointSet.h:150
vtkSmartPointer< vtkCellArray > Polys
Definition: vtkPolyData.h:718
Detect and break reference loops.
provides thread-safe access to cells
abstract class to specify cell behavior
Definition: vtkCell.h:50
void DeepCopy(vtkDataObject *src) override
Shallow and Deep copy.
T * Get() const noexcept
Get the contained pointer.
bool NeedToBuildCells()
Check if BuildCells is needed.
Definition: vtkPolyData.h:368
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for type information and printing.
a simple class to control print indentation
Definition: vtkIndent.h:28
static vtkPointSet * New()
Standard instantiation method.
vtkSmartPointer< vtkCellArray > Lines
Definition: vtkPolyData.h:717
list of point or cell ids
Definition: vtkIdList.h:25
vtkIdType GetNumberOfVerts()
Return the number of primitives of a particular type held.
Definition: vtkPolyData.h:229
void Initialize() override
Reset to an empty state and free any memory.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
vtkSmartPointer< CellMap > Cells
Definition: vtkPolyData.h:723
vtkIdType GetNumberOfCells() override
Standard vtkDataSet interface.
Definition: vtkPolyData.h:744
void ResizeCellList(vtkIdType ptId, int size)
Resize the list of cells using a particular point.
Definition: vtkPolyData.h:852
virtual int GetMinSpatialDimension()
Get the maximum/minimum spatial dimensionality of the data which is the maximum/minimum dimension of ...
vtkIdType GetNumberOfLines()
Return the number of primitives of a particular type held.
Definition: vtkPolyData.h:230
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.
A cell specified by degrees of freedom held in arrays.
int GetMaxCellSize() override
This method always returns 0, as there are no cells in a vtkPointSet.
Definition: vtkPointSet.h:122
static vtkPointSet * ExtendedNew()
int IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId)
Determine whether a point is used by a particular cell.
Definition: vtkPolyData.h:794
int GetDataObjectType() VTK_FUTURE_CONST override
Return what type of dataset this is.
Definition: vtkPolyData.h:83
object to represent cell connectivity
Definition: vtkCellArray.h:177
void GetPointCells(vtkIdType, vtkIdList *idList) override
Topological inquiry to get cells using point.
Definition: vtkPointSet.h:138
void BuildCells()
Create data structure that allows random access of cells.
Store zero or more vtkInformation instances.
#define VTK_MARSHALAUTO
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:818
static vtkPolyDataDummyContainter DummyContainer
Definition: vtkPolyData.h:729
vtkCell * GetCell(vtkIdType) override
This method always return a vtkEmptyCell, as there is no cell in a vtkPointSet.
vtkIdType GetCellId() const noexcept
void Allocate(vtkIdType numCells=1000, int extSize=1000)
Method allocates initial storage for vertex, line, polygon, and triangle strip arrays.
Definition: vtkPolyData.h:311
void CopyStructure(vtkDataSet *pd) override
Copy the geometric structure of an input point set object.
general representation of visualization data
Definition: vtkDataObject.h:55
void ReportReferences(vtkGarbageCollector *) override
vtkNew< vtkIdList > LegacyBuffer
Definition: vtkPolyData.h:726
virtual vtkCell * GetCell(vtkIdType cellId)=0
Get cell with cellId such that: 0 <= cellId < NumberOfCells.
vtkSmartPointer< vtkCellArray > Strips
Definition: vtkPolyData.h:719
virtual void GetCellBounds(vtkIdType cellId, double bounds[6])
Get the bounds of the cell with cellId such that: 0 <= cellId < NumberOfCells.
void Allocate(vtkPolyData *inPolyData, vtkIdType numCells=1000, int extSize=1000)
Similar to the method above, this method allocates initial storage for vertex, line, polygon, and triangle strip arrays.
Definition: vtkPolyData.h:326
vtkIdType GetNumberOfStrips()
Return the number of primitives of a particular type held.
Definition: vtkPolyData.h:232