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