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, vtkIdType *pts);
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);
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);
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, vtkIdType *pts);
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, vtkIdType *pts);
396 
405  void ReplaceLinkedCell(vtkIdType cellId, int npts, vtkIdType *pts);
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 
539 protected:
540  vtkPolyData();
541  ~vtkPolyData() override;
542 
543  // constant cell objects returned by GetCell called.
553 
554  // points inherited
555  // point data (i.e., scalars, vectors, normals, tcoords) inherited
560 
561  // dummy static member below used as a trick to simplify traversal
562  static vtkPolyDataDummyContainter DummyContainer;
563 
564  // supporting structures for more complex topological operations
565  // built only when necessary
568 
569 private:
570  // Hide these from the user and the compiler.
571 
575  void GetCellNeighbors(vtkIdType cellId, vtkIdList& ptIds, vtkIdList& cellIds)
576  {this->GetCellNeighbors(cellId, &ptIds, &cellIds);}
577 
578  void Cleanup();
579 
580 private:
581  vtkPolyData(const vtkPolyData&) = delete;
582  void operator=(const vtkPolyData&) = delete;
583 };
584 
585 inline void vtkPolyData::GetPointCells(vtkIdType ptId, unsigned short& ncells,
586  vtkIdType* &cells)
587 {
588  ncells = this->Links->GetNcells(ptId);
589  cells = this->Links->GetCells(ptId);
590 }
591 
592 inline int vtkPolyData::IsTriangle(int v1, int v2, int v3)
593 {
594  unsigned short int n1;
595  int i, j, tVerts[3];
596  vtkIdType *cells, *tVerts2, n2;
597 
598  tVerts[0] = v1;
599  tVerts[1] = v2;
600  tVerts[2] = v3;
601 
602  for (i=0; i<3; i++)
603  {
604  this->GetPointCells(tVerts[i], n1, cells);
605  for (j=0; j<n1; j++)
606  {
607  this->GetCellPoints(cells[j], n2, tVerts2);
608  if ( (tVerts[0] == tVerts2[0] || tVerts[0] == tVerts2[1] ||
609  tVerts[0] == tVerts2[2]) &&
610  (tVerts[1] == tVerts2[0] || tVerts[1] == tVerts2[1] ||
611  tVerts[1] == tVerts2[2]) &&
612  (tVerts[2] == tVerts2[0] || tVerts[2] == tVerts2[1] ||
613  tVerts[2] == tVerts2[2]) )
614  {
615  return 1;
616  }
617  }
618  }
619  return 0;
620 }
621 
623 {
624  vtkIdType *pts, npts;
625 
626  this->GetCellPoints(cellId, npts, pts);
627  for (vtkIdType i=0; i < npts; i++)
628  {
629  if ( pts[i] == ptId )
630  {
631  return 1;
632  }
633  }
634 
635  return 0;
636 }
637 
639 {
640  this->Links->DeletePoint(ptId);
641 }
642 
644 {
645  this->Cells->DeleteCell(cellId);
646 }
647 
649 {
650  vtkIdType *pts, npts;
651 
652  this->GetCellPoints(cellId, npts, pts);
653  for (vtkIdType i=0; i<npts; i++)
654  {
655  this->Links->RemoveCellReference(cellId, pts[i]);
656  }
657 }
658 
660 {
661  vtkIdType *pts, npts;
662 
663  this->GetCellPoints(cellId, npts, pts);
664  for (vtkIdType i=0; i<npts; i++)
665  {
666  this->Links->AddCellReference(cellId, pts[i]);
667  }
668 }
669 
671 {
672  this->Links->ResizeCellList(ptId,size);
673 }
674 
676  vtkIdType newPtId)
677 {
678  int i;
679  vtkIdType *verts, nverts;
680 
681  this->GetCellPoints(cellId,nverts,verts);
682  for ( i=0; i < nverts; i++ )
683  {
684  if ( verts[i] == oldPtId )
685  {
686  verts[i] = newPtId; // this is very nasty! direct write!
687  return;
688  }
689  }
690 }
691 
692 inline unsigned char vtkPolyData::GetCellPoints(
693  vtkIdType cellId, vtkIdType& npts, vtkIdType* &pts)
694 {
695  unsigned char type = this->Cells->GetCellType(cellId);
696  vtkCellArray *cells;
697  switch (type)
698  {
699  case VTK_VERTEX: case VTK_POLY_VERTEX:
700  cells = this->Verts;
701  break;
702 
703  case VTK_LINE: case VTK_POLY_LINE:
704  cells = this->Lines;
705  break;
706 
707  case VTK_TRIANGLE: case VTK_QUAD: case VTK_POLYGON:
708  cells = this->Polys;
709  break;
710 
711  case VTK_TRIANGLE_STRIP:
712  cells = this->Strips;
713  break;
714 
715  default:
716  cells = nullptr;
717  npts = 0;
718  pts = nullptr;
719  return 0;
720  }
721  int loc = this->Cells->GetCellLocation(cellId);
722  cells->GetCell(loc, npts, pts);
723  return type;
724 }
725 
726 inline unsigned char vtkPolyData::GetCell(
727  vtkIdType cellId, vtkIdType* &cell)
728 {
729  unsigned char type = this->Cells->GetCellType(cellId);
730  vtkCellArray *cells;
731  switch (type)
732  {
733  case VTK_VERTEX: case VTK_POLY_VERTEX:
734  cells = this->Verts;
735  break;
736 
737  case VTK_LINE: case VTK_POLY_LINE:
738  cells = this->Lines;
739  break;
740 
741  case VTK_TRIANGLE: case VTK_QUAD: case VTK_POLYGON:
742  cells = this->Polys;
743  break;
744 
745  case VTK_TRIANGLE_STRIP:
746  cells = this->Strips;
747  break;
748 
749  default:
750  cells = nullptr;
751  cell = nullptr;
752  return 0;
753  }
754  int loc = this->Cells->GetCellLocation(cellId);
755  cell = cells->GetData()->GetPointer(loc);
756  return type;
757 }
758 
759 #endif
void ComputeBounds() override
Compute the (X, Y, Z) bounds of the data.
unsigned char GetCellType(vtkIdType cellId)
Return the type of cell.
Definition: vtkCellTypes.h:114
vtkCellTypes * Cells
Definition: vtkPolyData.h:566
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.
void DeleteCell(vtkIdType cellId)
Delete cell by setting to nullptr cell type.
Definition: vtkCellTypes.h:94
vtkCellArray * Strips
Definition: vtkPolyData.h:559
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:300
void ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId, vtkIdType newPtId)
Replace a point in the cell connectivity list with a different point.
Definition: vtkPolyData.h:675
vtkCellArray * Lines
Definition: vtkPolyData.h:557
abstract class to specify dataset behavior
Definition: vtkDataSet.h:62
a cell that represents a 3D point
Definition: vtkVertex.h:36
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:659
vtkPolyLine * PolyLine
Definition: vtkPolyData.h:547
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:345
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:648
void DeletePoint(vtkIdType ptId)
Mark a point/cell as deleted from this vtkPolyData.
Definition: vtkPolyData.h:638
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:545
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
vtkIdType GetCellLocation(vtkIdType cellId)
Return the location of the cell in the associated vtkCellArray.
Definition: vtkCellTypes.h:89
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's a triangle.
Definition: vtkPolyData.h:592
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:670
vtkLine * Line
Definition: vtkPolyData.h:546
virtual void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds, vtkIdList *cellIds)
Topological inquiry to get all cells using list of points exclusive of cell specified (e....
int IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId)
Determine whether a point is used by a particular cell.
Definition: vtkPolyData.h:622
vtkTriangle * Triangle
Definition: vtkPolyData.h:548
object to represent cell connectivity
Definition: vtkCellArray.h:50
vtkEmptyCell * EmptyCell
Definition: vtkPolyData.h:552
vtkCellArray * Polys
Definition: vtkPolyData.h:558
a cell that represents a triangle
Definition: vtkTriangle.h:41
vtkQuad * Quad
Definition: vtkPolyData.h:549
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:544
vtkCellLinks * Links
Definition: vtkPolyData.h:567
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:643
static vtkPolyDataDummyContainter DummyContainer
Definition: vtkPolyData.h:562
vtkCellArray * Verts
Definition: vtkPolyData.h:556
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:550
vtkTriangleStrip * TriangleStrip
Definition: vtkPolyData.h:551