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, vtkIdType *pts);
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);
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);
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, vtkIdType *pts);
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, vtkIdType *pts);
390 
399  void ReplaceLinkedCell(vtkIdType cellId, int npts, vtkIdType *pts);
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 
533 protected:
534  vtkPolyData();
535  ~vtkPolyData() override;
536 
537  // constant cell objects returned by GetCell called.
547 
548  // points inherited
549  // point data (i.e., scalars, vectors, normals, tcoords) inherited
554 
555  // dummy static member below used as a trick to simplify traversal
556  static vtkPolyDataDummyContainter DummyContainer;
557 
558  // supporting structures for more complex topological operations
559  // built only when necessary
562 
563 private:
564  // Hide these from the user and the compiler.
565 
569  void GetCellNeighbors(vtkIdType cellId, vtkIdList& ptIds, vtkIdList& cellIds)
570  {this->GetCellNeighbors(cellId, &ptIds, &cellIds);}
571 
572  void Cleanup();
573 
574 private:
575  vtkPolyData(const vtkPolyData&) = delete;
576  void operator=(const vtkPolyData&) = delete;
577 };
578 
579 inline void vtkPolyData::GetPointCells(vtkIdType ptId, unsigned short& ncells,
580  vtkIdType* &cells)
581 {
582  ncells = this->Links->GetNcells(ptId);
583  cells = this->Links->GetCells(ptId);
584 }
585 
586 inline int vtkPolyData::IsTriangle(int v1, int v2, int v3)
587 {
588  unsigned short int n1;
589  int i, j, tVerts[3];
590  vtkIdType *cells, *tVerts2, n2;
591 
592  tVerts[0] = v1;
593  tVerts[1] = v2;
594  tVerts[2] = v3;
595 
596  for (i=0; i<3; i++)
597  {
598  this->GetPointCells(tVerts[i], n1, cells);
599  for (j=0; j<n1; j++)
600  {
601  this->GetCellPoints(cells[j], n2, tVerts2);
602  if ( (tVerts[0] == tVerts2[0] || tVerts[0] == tVerts2[1] ||
603  tVerts[0] == tVerts2[2]) &&
604  (tVerts[1] == tVerts2[0] || tVerts[1] == tVerts2[1] ||
605  tVerts[1] == tVerts2[2]) &&
606  (tVerts[2] == tVerts2[0] || tVerts[2] == tVerts2[1] ||
607  tVerts[2] == tVerts2[2]) )
608  {
609  return 1;
610  }
611  }
612  }
613  return 0;
614 }
615 
617 {
618  vtkIdType *pts, npts;
619 
620  this->GetCellPoints(cellId, npts, pts);
621  for (vtkIdType i=0; i < npts; i++)
622  {
623  if ( pts[i] == ptId )
624  {
625  return 1;
626  }
627  }
628 
629  return 0;
630 }
631 
633 {
634  this->Links->DeletePoint(ptId);
635 }
636 
638 {
639  this->Cells->DeleteCell(cellId);
640 }
641 
643 {
644  vtkIdType *pts, npts;
645 
646  this->GetCellPoints(cellId, npts, pts);
647  for (vtkIdType i=0; i<npts; i++)
648  {
649  this->Links->RemoveCellReference(cellId, pts[i]);
650  }
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->AddCellReference(cellId, pts[i]);
661  }
662 }
663 
665 {
666  this->Links->ResizeCellList(ptId,size);
667 }
668 
670  vtkIdType newPtId)
671 {
672  int i;
673  vtkIdType *verts, nverts;
674 
675  this->GetCellPoints(cellId,nverts,verts);
676  for ( i=0; i < nverts; i++ )
677  {
678  if ( verts[i] == oldPtId )
679  {
680  verts[i] = newPtId; // this is very nasty! direct write!
681  return;
682  }
683  }
684 }
685 
686 inline unsigned char vtkPolyData::GetCellPoints(
687  vtkIdType cellId, vtkIdType& npts, vtkIdType* &pts)
688 {
689  unsigned char type = this->Cells->GetCellType(cellId);
690  vtkCellArray *cells;
691  switch (type)
692  {
693  case VTK_VERTEX: case VTK_POLY_VERTEX:
694  cells = this->Verts;
695  break;
696 
697  case VTK_LINE: case VTK_POLY_LINE:
698  cells = this->Lines;
699  break;
700 
701  case VTK_TRIANGLE: case VTK_QUAD: case VTK_POLYGON:
702  cells = this->Polys;
703  break;
704 
705  case VTK_TRIANGLE_STRIP:
706  cells = this->Strips;
707  break;
708 
709  default:
710  cells = nullptr;
711  npts = 0;
712  pts = nullptr;
713  return 0;
714  }
715  int loc = this->Cells->GetCellLocation(cellId);
716  cells->GetCell(loc, npts, pts);
717  return type;
718 }
719 
720 inline unsigned char vtkPolyData::GetCell(
721  vtkIdType cellId, vtkIdType* &cell)
722 {
723  unsigned char type = this->Cells->GetCellType(cellId);
724  vtkCellArray *cells;
725  switch (type)
726  {
727  case VTK_VERTEX: case VTK_POLY_VERTEX:
728  cells = this->Verts;
729  break;
730 
731  case VTK_LINE: case VTK_POLY_LINE:
732  cells = this->Lines;
733  break;
734 
735  case VTK_TRIANGLE: case VTK_QUAD: case VTK_POLYGON:
736  cells = this->Polys;
737  break;
738 
739  case VTK_TRIANGLE_STRIP:
740  cells = this->Strips;
741  break;
742 
743  default:
744  cells = nullptr;
745  cell = nullptr;
746  return 0;
747  }
748  int loc = this->Cells->GetCellLocation(cellId);
749  cell = cells->GetData()->GetPointer(loc);
750  return type;
751 }
752 
753 #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:108
vtkCellTypes * Cells
Definition: vtkPolyData.h:560
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:88
vtkCellArray * Strips
Definition: vtkPolyData.h:553
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:669
vtkCellArray * Lines
Definition: vtkPolyData.h:551
abstract class to specify dataset behavior
Definition: vtkDataSet.h:56
a cell that represents a 3D point
Definition: vtkVertex.h:30
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:653
vtkPolyLine * PolyLine
Definition: vtkPolyData.h:541
a cell that represents a 2D quadrilateral
Definition: vtkQuad.h:35
abstract class for specifying dataset behavior
Definition: vtkPointSet.h:39
an empty cell used as a place-holder during processing
Definition: vtkEmptyCell.h:29
int vtkIdType
Definition: vtkType.h:345
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
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:642
void DeletePoint(vtkIdType ptId)
Mark a point/cell as deleted from this vtkPolyData.
Definition: vtkPolyData.h:632
provides thread-safe access to cells
int GetDataObjectType() override
Return what type of dataset this is.
Definition: vtkPolyData.h:90
vtkPolyVertex * PolyVertex
Definition: vtkPolyData.h:539
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.
vtkCell * GetCell(vtkIdType cellId) override
Standard vtkDataSet interface.
bool NeedToBuildCells()
Check if BuildCells is needed.
Definition: vtkPolyData.h:262
vtkIdType GetCellLocation(vtkIdType cellId)
Return the location of the cell in the associated vtkCellArray.
Definition: vtkCellTypes.h:83
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: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:586
list of point or cell ids
Definition: vtkIdList.h:30
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:48
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:664
vtkLine * Line
Definition: vtkPolyData.h:540
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:616
vtkTriangle * Triangle
Definition: vtkPolyData.h:542
object to represent cell connectivity
Definition: vtkCellArray.h:44
vtkEmptyCell * EmptyCell
Definition: vtkPolyData.h:546
vtkCellArray * Polys
Definition: vtkPolyData.h:552
a cell that represents a triangle
Definition: vtkTriangle.h:35
vtkQuad * Quad
Definition: vtkPolyData.h:543
vtkIdTypeArray * GetData()
Return the underlying data as a data array.
Definition: vtkCellArray.h:258
Store zero or more vtkInformation instances.
vtkVertex * Vertex
Definition: vtkPolyData.h:538
vtkCellLinks * Links
Definition: vtkPolyData.h:561
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:637
static vtkPolyDataDummyContainter DummyContainer
Definition: vtkPolyData.h:556
vtkCellArray * Verts
Definition: vtkPolyData.h:550
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:58
object provides direct access to cells in vtkCellArray and type information
Definition: vtkCellTypes.h:47
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:375
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.
vtkPolygon * Polygon
Definition: vtkPolyData.h:544
vtkTriangleStrip * TriangleStrip
Definition: vtkPolyData.h:545