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) VTK_OVERRIDE;
86 
90  int GetDataObjectType() VTK_OVERRIDE {return VTK_POLY_DATA;}
91 
95  void CopyStructure(vtkDataSet *ds) VTK_OVERRIDE;
96 
98 
101  vtkIdType GetNumberOfCells() VTK_OVERRIDE;
102  using vtkDataSet::GetCell;
103  vtkCell *GetCell(vtkIdType cellId) VTK_OVERRIDE;
104  void GetCell(vtkIdType cellId, vtkGenericCell *cell) VTK_OVERRIDE;
105  int GetCellType(vtkIdType cellId) VTK_OVERRIDE;
106  void GetCellBounds(vtkIdType cellId, double bounds[6]) VTK_OVERRIDE;
107  void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds,
108  vtkIdList *cellIds) VTK_OVERRIDE;
110 
117  void CopyCells(vtkPolyData *pd, vtkIdList *idList,
118  vtkPointLocator *locator = NULL);
119 
123  void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds) VTK_OVERRIDE;
124 
129  void GetPointCells(vtkIdType ptId, vtkIdList *cellIds) VTK_OVERRIDE;
130 
134  void ComputeBounds() VTK_OVERRIDE;
135 
142  void Squeeze() VTK_OVERRIDE;
143 
147  int GetMaxCellSize() VTK_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 == 0; }
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() VTK_OVERRIDE;
443 
445 
448  virtual int GetPiece();
449  virtual int GetNumberOfPieces();
451 
455  virtual int GetGhostLevel();
456 
465  unsigned long GetActualMemorySize() VTK_OVERRIDE;
466 
468 
471  void ShallowCopy(vtkDataObject *src) VTK_OVERRIDE;
472  void DeepCopy(vtkDataObject *src) VTK_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 
524 protected:
525  vtkPolyData();
526  ~vtkPolyData() VTK_OVERRIDE;
527 
528  // constant cell objects returned by GetCell called.
529  vtkVertex *Vertex;
530  vtkPolyVertex *PolyVertex;
531  vtkLine *Line;
532  vtkPolyLine *PolyLine;
533  vtkTriangle *Triangle;
534  vtkQuad *Quad;
535  vtkPolygon *Polygon;
536  vtkTriangleStrip *TriangleStrip;
537  vtkEmptyCell *EmptyCell;
538 
539  // points inherited
540  // point data (i.e., scalars, vectors, normals, tcoords) inherited
541  vtkCellArray *Verts;
542  vtkCellArray *Lines;
543  vtkCellArray *Polys;
544  vtkCellArray *Strips;
545 
546  // dummy static member below used as a trick to simplify traversal
547  static vtkPolyDataDummyContainter DummyContainer;
548 
549  // supporting structures for more complex topological operations
550  // built only when necessary
551  vtkCellTypes *Cells;
552  vtkCellLinks *Links;
553 
554 private:
555  // Hide these from the user and the compiler.
556 
560  void GetCellNeighbors(vtkIdType cellId, vtkIdList& ptIds, vtkIdList& cellIds)
561  {this->GetCellNeighbors(cellId, &ptIds, &cellIds);}
562 
563  void Cleanup();
564 
565 private:
566  vtkPolyData(const vtkPolyData&) VTK_DELETE_FUNCTION;
567  void operator=(const vtkPolyData&) VTK_DELETE_FUNCTION;
568 };
569 
570 inline void vtkPolyData::GetPointCells(vtkIdType ptId, unsigned short& ncells,
571  vtkIdType* &cells)
572 {
573  ncells = this->Links->GetNcells(ptId);
574  cells = this->Links->GetCells(ptId);
575 }
576 
577 inline int vtkPolyData::IsTriangle(int v1, int v2, int v3)
578 {
579  unsigned short int n1;
580  int i, j, tVerts[3];
581  vtkIdType *cells, *tVerts2, n2;
582 
583  tVerts[0] = v1;
584  tVerts[1] = v2;
585  tVerts[2] = v3;
586 
587  for (i=0; i<3; i++)
588  {
589  this->GetPointCells(tVerts[i], n1, cells);
590  for (j=0; j<n1; j++)
591  {
592  this->GetCellPoints(cells[j], n2, tVerts2);
593  if ( (tVerts[0] == tVerts2[0] || tVerts[0] == tVerts2[1] ||
594  tVerts[0] == tVerts2[2]) &&
595  (tVerts[1] == tVerts2[0] || tVerts[1] == tVerts2[1] ||
596  tVerts[1] == tVerts2[2]) &&
597  (tVerts[2] == tVerts2[0] || tVerts[2] == tVerts2[1] ||
598  tVerts[2] == tVerts2[2]) )
599  {
600  return 1;
601  }
602  }
603  }
604  return 0;
605 }
606 
608 {
609  vtkIdType *pts, npts;
610 
611  this->GetCellPoints(cellId, npts, pts);
612  for (vtkIdType i=0; i < npts; i++)
613  {
614  if ( pts[i] == ptId )
615  {
616  return 1;
617  }
618  }
619 
620  return 0;
621 }
622 
624 {
625  this->Links->DeletePoint(ptId);
626 }
627 
629 {
630  this->Cells->DeleteCell(cellId);
631 }
632 
634 {
635  vtkIdType *pts, npts;
636 
637  this->GetCellPoints(cellId, npts, pts);
638  for (vtkIdType i=0; i<npts; i++)
639  {
640  this->Links->RemoveCellReference(cellId, pts[i]);
641  }
642 }
643 
645 {
646  vtkIdType *pts, npts;
647 
648  this->GetCellPoints(cellId, npts, pts);
649  for (vtkIdType i=0; i<npts; i++)
650  {
651  this->Links->AddCellReference(cellId, pts[i]);
652  }
653 }
654 
656 {
657  this->Links->ResizeCellList(ptId,size);
658 }
659 
661  vtkIdType newPtId)
662 {
663  int i;
664  vtkIdType *verts, nverts;
665 
666  this->GetCellPoints(cellId,nverts,verts);
667  for ( i=0; i < nverts; i++ )
668  {
669  if ( verts[i] == oldPtId )
670  {
671  verts[i] = newPtId; // this is very nasty! direct write!
672  return;
673  }
674  }
675 }
676 
677 inline unsigned char vtkPolyData::GetCellPoints(
678  vtkIdType cellId, vtkIdType& npts, vtkIdType* &pts)
679 {
680  unsigned char type = this->Cells->GetCellType(cellId);
681  vtkCellArray *cells;
682  switch (type)
683  {
684  case VTK_VERTEX: case VTK_POLY_VERTEX:
685  cells = this->Verts;
686  break;
687 
688  case VTK_LINE: case VTK_POLY_LINE:
689  cells = this->Lines;
690  break;
691 
692  case VTK_TRIANGLE: case VTK_QUAD: case VTK_POLYGON:
693  cells = this->Polys;
694  break;
695 
696  case VTK_TRIANGLE_STRIP:
697  cells = this->Strips;
698  break;
699 
700  default:
701  cells = NULL;
702  npts = 0;
703  pts = NULL;
704  return 0;
705  }
706  int loc = this->Cells->GetCellLocation(cellId);
707  cells->GetCell(loc, npts, pts);
708  return type;
709 }
710 
711 inline unsigned char vtkPolyData::GetCell(
712  vtkIdType cellId, vtkIdType* &cell)
713 {
714  unsigned char type = this->Cells->GetCellType(cellId);
715  vtkCellArray *cells;
716  switch (type)
717  {
718  case VTK_VERTEX: case VTK_POLY_VERTEX:
719  cells = this->Verts;
720  break;
721 
722  case VTK_LINE: case VTK_POLY_LINE:
723  cells = this->Lines;
724  break;
725 
726  case VTK_TRIANGLE: case VTK_QUAD: case VTK_POLYGON:
727  cells = this->Polys;
728  break;
729 
730  case VTK_TRIANGLE_STRIP:
731  cells = this->Strips;
732  break;
733 
734  default:
735  cells = NULL;
736  cell = NULL;
737  return 0;
738  }
739  int loc = this->Cells->GetCellLocation(cellId);
740  cell = cells->GetData()->GetPointer(loc);
741  return type;
742 }
743 
744 #endif
void ComputeBounds() override
Compute the (X, Y, Z) bounds of the data.
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 ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId, vtkIdType newPtId)
Replace a point in the cell connectivity list with a different point.
Definition: vtkPolyData.h:660
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:644
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:633
void DeletePoint(vtkIdType ptId)
Mark a point/cell as deleted from this vtkPolyData.
Definition: vtkPolyData.h:623
provides thread-safe access to cells
int GetDataObjectType() override
Return what type of dataset this is.
Definition: vtkPolyData.h:90
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
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:577
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:655
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:607
object to represent cell connectivity
Definition: vtkCellArray.h:44
a cell that represents a triangle
Definition: vtkTriangle.h:35
vtkIdTypeArray * GetData()
Return the underlying data as a data array.
Definition: vtkCellArray.h:250
Store zero or more vtkInformation instances.
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:628
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:46
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:367
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.