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 =========================================================================*/
58 #ifndef vtkPolyData_h
59 #define vtkPolyData_h
60 
61 #include "vtkCommonDataModelModule.h" // For export macro
62 #include "vtkPointSet.h"
63 
64 #include "vtkCellTypes.h" // Needed for inline methods
65 #include "vtkCellLinks.h" // Needed for inline methods
66 #include "vtkCellArray.h" // Needed for inline methods
67 
68 class vtkVertex;
69 class vtkPolyVertex;
70 class vtkLine;
71 class vtkPolyLine;
72 class vtkTriangle;
73 class vtkQuad;
74 class vtkPolygon;
75 class vtkTriangleStrip;
76 class vtkEmptyCell;
77 struct vtkPolyDataDummyContainter;
78 
79 class VTKCOMMONDATAMODEL_EXPORT vtkPolyData : public vtkPointSet
80 {
81 public:
82  static vtkPolyData *New();
83 
84  vtkTypeMacro(vtkPolyData,vtkPointSet);
85  void PrintSelf(ostream& os, vtkIndent indent) override;
86 
90  int GetDataObjectType() override {return VTK_POLY_DATA;}
91 
95  void CopyStructure(vtkDataSet *ds) override;
96 
98 
101  vtkIdType GetNumberOfCells() override;
102  using vtkDataSet::GetCell;
103  vtkCell *GetCell(vtkIdType cellId) override;
104  void GetCell(vtkIdType cellId, vtkGenericCell *cell) override;
105  int GetCellType(vtkIdType cellId) override;
106  void GetCellBounds(vtkIdType cellId, double bounds[6]) override;
107  void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds,
108  vtkIdList *cellIds) override;
110 
117  void CopyCells(vtkPolyData *pd, vtkIdList *idList,
118  vtkPointLocator *locator = nullptr);
119 
123  void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds) override;
124 
129  void GetPointCells(vtkIdType ptId, vtkIdList *cellIds) override;
130 
134  void ComputeBounds() override;
135 
142  void Squeeze() override;
143 
147  int GetMaxCellSize() override;
148 
152  void SetVerts (vtkCellArray* v);
153 
158  vtkCellArray *GetVerts();
159 
163  void SetLines (vtkCellArray* l);
164 
169  vtkCellArray *GetLines();
170 
174  void SetPolys (vtkCellArray* p);
175 
180  vtkCellArray *GetPolys();
181 
185  void SetStrips (vtkCellArray* s);
186 
192  vtkCellArray *GetStrips();
193 
195 
198  vtkIdType GetNumberOfVerts();
199  vtkIdType GetNumberOfLines();
200  vtkIdType GetNumberOfPolys();
201  vtkIdType GetNumberOfStrips();
203 
211  void Allocate(vtkIdType numCells=1000, int extSize=1000);
212 
223  void Allocate(vtkPolyData *inPolyData, vtkIdType numCells=1000,
224  int extSize=1000);
225 
233  vtkIdType InsertNextCell(int type, int npts, const vtkIdType pts[]) VTK_SIZEHINT(pts, npts);
234 
242  vtkIdType InsertNextCell(int type, vtkIdList *pts);
243 
248  void Reset();
249 
257  void BuildCells();
258 
262  bool NeedToBuildCells() { return this->Cells == nullptr; }
263 
270  void BuildLinks(int initialSize=0);
271 
277  void DeleteCells();
278 
282  void DeleteLinks();
283 
287  void GetPointCells(vtkIdType ptId, unsigned short& ncells,
288  vtkIdType* &cells) VTK_SIZEHINT(cells, ncells);
289 
295  void GetCellEdgeNeighbors(vtkIdType cellId, vtkIdType p1, vtkIdType p2,
296  vtkIdList *cellIds);
297 
304  unsigned char GetCellPoints(vtkIdType cellId,
305  vtkIdType& npts, vtkIdType* &pts) VTK_SIZEHINT(pts, npts);
306 
313  unsigned char GetCell(vtkIdType cellId, vtkIdType* &pts);
314 
319  int IsTriangle(int v1, int v2, int v3);
320 
328  int IsEdge(vtkIdType p1, vtkIdType p2);
329 
334  int IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId);
335 
342  void ReplaceCell(vtkIdType cellId, int npts, const vtkIdType pts[]) VTK_SIZEHINT(pts, npts);
343 
347  void ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId,
348  vtkIdType newPtId);
349 
353  void ReverseCell(vtkIdType cellId);
354 
356 
359  void DeletePoint(vtkIdType ptId);
360  void DeleteCell(vtkIdType cellId);
362 
370  void RemoveDeletedCells();
371 
373 
380  vtkIdType InsertNextLinkedPoint(int numLinks);
381  vtkIdType InsertNextLinkedPoint(double x[3], int numLinks);
383 
389  vtkIdType InsertNextLinkedCell(int type, int npts, const vtkIdType pts[]) VTK_SIZEHINT(pts, npts);
390 
399  void ReplaceLinkedCell(vtkIdType cellId, int npts, const vtkIdType pts[]) VTK_SIZEHINT(pts, npts);
400 
407  void RemoveCellReference(vtkIdType cellId);
408 
415  void AddCellReference(vtkIdType cellId);
416 
423  void RemoveReferenceToCell(vtkIdType ptId, vtkIdType cellId);
424 
431  void AddReferenceToCell(vtkIdType ptId, vtkIdType cellId);
432 
437  void ResizeCellList(vtkIdType ptId, int size);
438 
442  void Initialize() override;
443 
445 
448  virtual int GetPiece();
449  virtual int GetNumberOfPieces();
451 
455  virtual int GetGhostLevel();
456 
465  unsigned long GetActualMemorySize() override;
466 
468 
471  void ShallowCopy(vtkDataObject *src) override;
472  void DeepCopy(vtkDataObject *src) override;
474 
480  void RemoveGhostCells();
481 
483 
487  static vtkPolyData* GetData(vtkInformationVector* v, int i=0);
489 
508  enum
509  {
510  ERR_NO_SUCH_FIELD = -4,
511  ERR_INCORRECT_FIELD = -3,
512  ERR_NON_MANIFOLD_STAR = -2,
513  REGULAR_POINT = -1,
514  MINIMUM = 0,
515  SADDLE = 1,
516  MAXIMUM = 2
517  };
518 
519  int GetScalarFieldCriticalIndex (vtkIdType pointId,
520  vtkDataArray *scalarField);
521  int GetScalarFieldCriticalIndex (vtkIdType pointId, int fieldId);
522  int GetScalarFieldCriticalIndex (vtkIdType pointId, const char* fieldName);
523 
531  virtual vtkMTimeType GetMeshMTime();
532 
536  vtkMTimeType GetMTime() override;
537 
538 protected:
539  vtkPolyData();
540  ~vtkPolyData() override;
541 
542  // constant cell objects returned by GetCell called.
552 
553  // points inherited
554  // point data (i.e., scalars, vectors, normals, tcoords) inherited
559 
560  // dummy static member below used as a trick to simplify traversal
561  static vtkPolyDataDummyContainter DummyContainer;
562 
563  // supporting structures for more complex topological operations
564  // built only when necessary
567 
568 private:
569  // Hide these from the user and the compiler.
570 
574  void GetCellNeighbors(vtkIdType cellId, vtkIdList& ptIds, vtkIdList& cellIds)
575  {this->GetCellNeighbors(cellId, &ptIds, &cellIds);}
576 
577  void Cleanup();
578 
579 private:
580  vtkPolyData(const vtkPolyData&) = delete;
581  void operator=(const vtkPolyData&) = delete;
582 };
583 
584 inline void vtkPolyData::GetPointCells(vtkIdType ptId, unsigned short& ncells,
585  vtkIdType* &cells)
586 {
587  ncells = this->Links->GetNcells(ptId);
588  cells = this->Links->GetCells(ptId);
589 }
590 
591 inline int vtkPolyData::IsTriangle(int v1, int v2, int v3)
592 {
593  unsigned short int n1;
594  int i, j, tVerts[3];
595  vtkIdType *cells, *tVerts2, n2;
596 
597  tVerts[0] = v1;
598  tVerts[1] = v2;
599  tVerts[2] = v3;
600 
601  for (i=0; i<3; i++)
602  {
603  this->GetPointCells(tVerts[i], n1, cells);
604  for (j=0; j<n1; j++)
605  {
606  this->GetCellPoints(cells[j], n2, tVerts2);
607  if ( (tVerts[0] == tVerts2[0] || tVerts[0] == tVerts2[1] ||
608  tVerts[0] == tVerts2[2]) &&
609  (tVerts[1] == tVerts2[0] || tVerts[1] == tVerts2[1] ||
610  tVerts[1] == tVerts2[2]) &&
611  (tVerts[2] == tVerts2[0] || tVerts[2] == tVerts2[1] ||
612  tVerts[2] == tVerts2[2]) )
613  {
614  return 1;
615  }
616  }
617  }
618  return 0;
619 }
620 
622 {
623  vtkIdType *pts, npts;
624 
625  this->GetCellPoints(cellId, npts, pts);
626  for (vtkIdType i=0; i < npts; i++)
627  {
628  if ( pts[i] == ptId )
629  {
630  return 1;
631  }
632  }
633 
634  return 0;
635 }
636 
638 {
639  this->Links->DeletePoint(ptId);
640 }
641 
643 {
644  this->Cells->DeleteCell(cellId);
645 }
646 
648 {
649  vtkIdType *pts, npts;
650 
651  this->GetCellPoints(cellId, npts, pts);
652  for (vtkIdType i=0; i<npts; i++)
653  {
654  this->Links->RemoveCellReference(cellId, pts[i]);
655  }
656 }
657 
659 {
660  vtkIdType *pts, npts;
661 
662  this->GetCellPoints(cellId, npts, pts);
663  for (vtkIdType i=0; i<npts; i++)
664  {
665  this->Links->AddCellReference(cellId, pts[i]);
666  }
667 }
668 
670 {
671  this->Links->ResizeCellList(ptId,size);
672 }
673 
675  vtkIdType newPtId)
676 {
677  int i;
678  vtkIdType *verts, nverts;
679 
680  this->GetCellPoints(cellId,nverts,verts);
681  for ( i=0; i < nverts; i++ )
682  {
683  if ( verts[i] == oldPtId )
684  {
685  verts[i] = newPtId; // this is very nasty! direct write!
686  return;
687  }
688  }
689 }
690 
691 inline unsigned char vtkPolyData::GetCellPoints(
692  vtkIdType cellId, vtkIdType& npts, vtkIdType* &pts)
693 {
694  unsigned char type = this->Cells->GetCellType(cellId);
695  vtkCellArray *cells;
696  switch (type)
697  {
698  case VTK_VERTEX: case VTK_POLY_VERTEX:
699  cells = this->Verts;
700  break;
701 
702  case VTK_LINE: case VTK_POLY_LINE:
703  cells = this->Lines;
704  break;
705 
706  case VTK_TRIANGLE: case VTK_QUAD: case VTK_POLYGON:
707  cells = this->Polys;
708  break;
709 
710  case VTK_TRIANGLE_STRIP:
711  cells = this->Strips;
712  break;
713 
714  default:
715  cells = nullptr;
716  npts = 0;
717  pts = nullptr;
718  return 0;
719  }
720  int loc = this->Cells->GetCellLocation(cellId);
721  cells->GetCell(loc, npts, pts);
722  return type;
723 }
724 
725 inline unsigned char vtkPolyData::GetCell(
726  vtkIdType cellId, vtkIdType* &cell)
727 {
728  unsigned char type = this->Cells->GetCellType(cellId);
729  vtkCellArray *cells;
730  switch (type)
731  {
732  case VTK_VERTEX: case VTK_POLY_VERTEX:
733  cells = this->Verts;
734  break;
735 
736  case VTK_LINE: case VTK_POLY_LINE:
737  cells = this->Lines;
738  break;
739 
740  case VTK_TRIANGLE: case VTK_QUAD: case VTK_POLYGON:
741  cells = this->Polys;
742  break;
743 
744  case VTK_TRIANGLE_STRIP:
745  cells = this->Strips;
746  break;
747 
748  default:
749  cells = nullptr;
750  cell = nullptr;
751  return 0;
752  }
753  int loc = this->Cells->GetCellLocation(cellId);
754  cell = cells->GetData()->GetPointer(loc);
755  return type;
756 }
757 
758 #endif
VTK_TRIANGLE_STRIP
Definition: vtkCellType.h:51
vtkCellTypes
object provides direct access to cells in vtkCellArray and type information
Definition: vtkCellTypes.h:47
vtkPolyData::GetPointCells
void GetPointCells(vtkIdType ptId, vtkIdList *cellIds) override
Efficient method to obtain cells using a particular point.
vtkPolyData::ReplaceCellPoint
void ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId, vtkIdType newPtId)
Replace a point in the cell connectivity list with a different point.
Definition: vtkPolyData.h:674
vtkPointSet.h
vtkX3D::type
Definition: vtkX3D.h:516
vtkIdType
int vtkIdType
Definition: vtkType.h:347
vtkCellTypes.h
VTK_LINE
Definition: vtkCellType.h:48
vtkPolygon
a cell that represents an n-sided polygon
Definition: vtkPolygon.h:39
vtkInformationVector
Store zero or more vtkInformation instances.
Definition: vtkInformationVector.h:35
vtkPointLocator
quickly locate points in 3-space
Definition: vtkPointLocator.h:50
vtkEmptyCell
an empty cell used as a place-holder during processing
Definition: vtkEmptyCell.h:29
vtkPolyData::Strips
vtkCellArray * Strips
Definition: vtkPolyData.h:558
vtkCellArray.h
vtkPolyData::PolyVertex
vtkPolyVertex * PolyVertex
Definition: vtkPolyData.h:544
vtkPointSet::Squeeze
void Squeeze() override
Reclaim any unused memory.
vtkPolyData::RemoveCellReference
void RemoveCellReference(vtkIdType cellId)
Remove all references to cell in cell structure.
Definition: vtkPolyData.h:647
vtkAOSDataArrayTemplate::GetPointer
ValueType * GetPointer(vtkIdType valueIdx)
Get the address of a particular data index.
vtkCellArray::GetData
vtkIdTypeArray * GetData()
Return the underlying data as a data array.
Definition: vtkCellArray.h:258
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:48
vtkPolyData::Lines
vtkCellArray * Lines
Definition: vtkPolyData.h:556
vtkPointSet::GetData
static vtkPointSet * GetData(vtkInformation *info)
Retrieve an instance of this class from an information object.
vtkVertex
a cell that represents a 3D point
Definition: vtkVertex.h:30
vtkPolyData::NeedToBuildCells
bool NeedToBuildCells()
Check if BuildCells is needed.
Definition: vtkPolyData.h:262
vtkLine
cell represents a 1D line
Definition: vtkLine.h:29
VTK_POLY_LINE
Definition: vtkCellType.h:49
vtkPolyData::DeletePoint
void DeletePoint(vtkIdType ptId)
Mark a point/cell as deleted from this vtkPolyData.
Definition: vtkPolyData.h:637
VTK_QUAD
Definition: vtkCellType.h:54
vtkPolyData::GetCell
vtkCell * GetCell(vtkIdType cellId) override
Get cell with cellId such that: 0 <= cellId < NumberOfCells.
vtkPolyData::GetDataObjectType
int GetDataObjectType() override
Return what type of dataset this is.
Definition: vtkPolyData.h:90
vtkPolyData::AddCellReference
void AddCellReference(vtkIdType cellId)
Add references to cell in cell structure.
Definition: vtkPolyData.h:658
vtkPolyData::PolyLine
vtkPolyLine * PolyLine
Definition: vtkPolyData.h:546
vtkPointSet::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
VTK_SIZEHINT
#define VTK_SIZEHINT(...)
Definition: vtkWrappingHints.h:42
vtkPolyLine
cell represents a set of 1D lines
Definition: vtkPolyLine.h:36
vtkCellTypes::GetCellType
unsigned char GetCellType(vtkIdType cellId)
Return the type of cell.
Definition: vtkCellTypes.h:108
vtkCellArray::GetCell
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:375
vtkPointSet::DeepCopy
void DeepCopy(vtkDataObject *src) override
vtkDataSet::GetCellNeighbors
virtual void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds, vtkIdList *cellIds)
Topological inquiry to get all cells using list of points exclusive of cell specified (e....
vtkCell
abstract class to specify cell behavior
Definition: vtkCell.h:56
vtkDataSet::GetPointCells
virtual void GetPointCells(vtkIdType ptId, vtkIdList *cellIds)=0
Topological inquiry to get cells using point.
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkCellTypes::GetCellLocation
vtkIdType GetCellLocation(vtkIdType cellId)
Return the location of the cell in the associated vtkCellArray.
Definition: vtkCellTypes.h:83
vtkCellArray
object to represent cell connectivity
Definition: vtkCellArray.h:44
vtkPolyData::IsTriangle
int IsTriangle(int v1, int v2, int v3)
Given three vertices, determine whether it's a triangle.
Definition: vtkPolyData.h:591
vtkPolyData::Line
vtkLine * Line
Definition: vtkPolyData.h:545
vtkPolyData::EmptyCell
vtkEmptyCell * EmptyCell
Definition: vtkPolyData.h:551
VTK_POLY_VERTEX
Definition: vtkCellType.h:47
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:30
vtkPointSet::Initialize
void Initialize() override
Reset to an empty state and free any memory.
vtkPointSet::GetMTime
vtkMTimeType GetMTime() override
Get MTime which also considers its vtkPoints MTime.
vtkX3D::size
Definition: vtkX3D.h:253
vtkTriangle
a cell that represents a triangle
Definition: vtkTriangle.h:35
vtkPolyData::Vertex
vtkVertex * Vertex
Definition: vtkPolyData.h:543
vtkDataSet
abstract class to specify dataset behavior
Definition: vtkDataSet.h:56
vtkInformation
Store vtkAlgorithm input/output information.
Definition: vtkInformation.h:80
vtkDataSet::GetCellPoints
virtual void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds)=0
Topological inquiry to get points defining cell.
vtkX3D::info
Definition: vtkX3D.h:376
vtkCellTypes::DeleteCell
void DeleteCell(vtkIdType cellId)
Delete cell by setting to nullptr cell type.
Definition: vtkCellTypes.h:88
vtkPolyData::Quad
vtkQuad * Quad
Definition: vtkPolyData.h:548
vtkPolyData::IsPointUsedByCell
int IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId)
Determine whether a point is used by a particular cell.
Definition: vtkPolyData.h:621
vtkPolyData::ResizeCellList
void ResizeCellList(vtkIdType ptId, int size)
Resize the list of cells using a particular point.
Definition: vtkPolyData.h:669
vtkPointSet
abstract class for specifying dataset behavior
Definition: vtkPointSet.h:39
VTK_POLYGON
Definition: vtkCellType.h:52
vtkPolyData::Polys
vtkCellArray * Polys
Definition: vtkPolyData.h:557
vtkPolyData
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
vtkPolyData::DummyContainer
static vtkPolyDataDummyContainter DummyContainer
Definition: vtkPolyData.h:561
vtkPointSet::ShallowCopy
void ShallowCopy(vtkDataObject *src) override
Shallow and Deep copy.
vtkGenericCell
provides thread-safe access to cells
Definition: vtkGenericCell.h:36
vtkPolyData::Triangle
vtkTriangle * Triangle
Definition: vtkPolyData.h:547
vtkDataSet::GetNumberOfCells
virtual vtkIdType GetNumberOfCells()=0
Determine the number of cells composing the dataset.
vtkPolyData::Links
vtkCellLinks * Links
Definition: vtkPolyData.h:566
vtkDataObject
general representation of visualization data
Definition: vtkDataObject.h:58
vtkDataSet::GetCellType
virtual int GetCellType(vtkIdType cellId)=0
Get type of cell with cellId such that: 0 <= cellId < NumberOfCells.
vtkPointSet::GetActualMemorySize
unsigned long GetActualMemorySize() override
Return the actual size of the data in kibibytes (1024 bytes).
vtkPolyData::DeleteCell
void DeleteCell(vtkIdType cellId)
Definition: vtkPolyData.h:642
vtkPolyData::Verts
vtkCellArray * Verts
Definition: vtkPolyData.h:555
VTK_VERTEX
Definition: vtkCellType.h:46
VTK_TRIANGLE
Definition: vtkCellType.h:50
vtkDataSet::GetCellBounds
virtual void GetCellBounds(vtkIdType cellId, double bounds[6])
Get the bounds of the cell with cellId such that: 0 <= cellId < NumberOfCells.
vtkPolyData::Polygon
vtkPolygon * Polygon
Definition: vtkPolyData.h:549
VTK_POLY_DATA
#define VTK_POLY_DATA
Definition: vtkType.h:91
vtkPointSet::CopyStructure
void CopyStructure(vtkDataSet *pd) override
Copy the geometric structure of an input point set object.
vtkPolyData::TriangleStrip
vtkTriangleStrip * TriangleStrip
Definition: vtkPolyData.h:550
vtkDataSet::GetMaxCellSize
virtual int GetMaxCellSize()=0
Convenience method returns largest cell size in dataset.
vtkTriangleStrip
a cell that represents a triangle strip
Definition: vtkTriangleStrip.h:37
vtkPolyData::GetCellPoints
void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds) override
Copy a cells point ids into list provided.
vtkQuad
a cell that represents a 2D quadrilateral
Definition: vtkQuad.h:35
vtkPointSet::ComputeBounds
void ComputeBounds() override
Compute the (X, Y, Z) bounds of the data.
vtkDataObject::New
static vtkDataObject * New()
vtkDataSet::GetCell
virtual vtkCell * GetCell(vtkIdType cellId)=0
Get cell with cellId such that: 0 <= cellId < NumberOfCells.
vtkMTimeType
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:302
vtkPolyData::Cells
vtkCellTypes * Cells
Definition: vtkPolyData.h:565
vtkPolyVertex
cell represents a set of 0D vertices
Definition: vtkPolyVertex.h:32