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  vtkCell *GetCell(vtkIdType cellId) VTK_OVERRIDE;
109  void GetCell(vtkIdType cellId, vtkGenericCell *cell) VTK_OVERRIDE;
110  int GetCellType(vtkIdType cellId) VTK_OVERRIDE;
111  void GetCellBounds(vtkIdType cellId, double bounds[6]) VTK_OVERRIDE;
112  void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds,
113  vtkIdList *cellIds) VTK_OVERRIDE;
115 
122  void CopyCells(vtkPolyData *pd, vtkIdList *idList,
123  vtkPointLocator *locator = NULL);
124 
128  void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds) VTK_OVERRIDE;
129 
134  void GetPointCells(vtkIdType ptId, vtkIdList *cellIds) VTK_OVERRIDE;
135 
139  void ComputeBounds() VTK_OVERRIDE;
140 
147  void Squeeze() VTK_OVERRIDE;
148 
152  int GetMaxCellSize() VTK_OVERRIDE;
153 
157  void SetVerts (vtkCellArray* v);
158 
163  vtkCellArray *GetVerts();
164 
168  void SetLines (vtkCellArray* l);
169 
174  vtkCellArray *GetLines();
175 
179  void SetPolys (vtkCellArray* p);
180 
185  vtkCellArray *GetPolys();
186 
190  void SetStrips (vtkCellArray* s);
191 
197  vtkCellArray *GetStrips();
198 
200 
203  vtkIdType GetNumberOfVerts();
204  vtkIdType GetNumberOfLines();
205  vtkIdType GetNumberOfPolys();
206  vtkIdType GetNumberOfStrips();
208 
216  void Allocate(vtkIdType numCells=1000, int extSize=1000);
217 
228  void Allocate(vtkPolyData *inPolyData, vtkIdType numCells=1000,
229  int extSize=1000);
230 
238  vtkIdType InsertNextCell(int type, int npts, vtkIdType *pts);
239 
247  vtkIdType InsertNextCell(int type, vtkIdList *pts);
248 
253  void Reset();
254 
262  void BuildCells();
263 
267  bool NeedToBuildCells() { return this->Cells == 0; }
268 
275  void BuildLinks(int initialSize=0);
276 
282  void DeleteCells();
283 
287  void DeleteLinks();
288 
292  void GetPointCells(vtkIdType ptId, unsigned short& ncells,
293  vtkIdType* &cells);
294 
300  void GetCellEdgeNeighbors(vtkIdType cellId, vtkIdType p1, vtkIdType p2,
301  vtkIdList *cellIds);
302 
309  unsigned char GetCellPoints(vtkIdType cellId,
310  vtkIdType& npts, vtkIdType* &pts);
311 
318  unsigned char GetCell(vtkIdType cellId, vtkIdType* &pts);
319 
324  int IsTriangle(int v1, int v2, int v3);
325 
333  int IsEdge(vtkIdType p1, vtkIdType p2);
334 
339  int IsPointUsedByCell(vtkIdType ptId, vtkIdType cellId);
340 
347  void ReplaceCell(vtkIdType cellId, int npts, vtkIdType *pts);
348 
352  void ReplaceCellPoint(vtkIdType cellId, vtkIdType oldPtId,
353  vtkIdType newPtId);
354 
358  void ReverseCell(vtkIdType cellId);
359 
361 
364  void DeletePoint(vtkIdType ptId);
365  void DeleteCell(vtkIdType cellId);
367 
375  void RemoveDeletedCells();
376 
378 
385  vtkIdType InsertNextLinkedPoint(int numLinks);
386  vtkIdType InsertNextLinkedPoint(double x[3], int numLinks);
388 
394  vtkIdType InsertNextLinkedCell(int type, int npts, vtkIdType *pts);
395 
404  void ReplaceLinkedCell(vtkIdType cellId, int npts, vtkIdType *pts);
405 
412  void RemoveCellReference(vtkIdType cellId);
413 
420  void AddCellReference(vtkIdType cellId);
421 
428  void RemoveReferenceToCell(vtkIdType ptId, vtkIdType cellId);
429 
436  void AddReferenceToCell(vtkIdType ptId, vtkIdType cellId);
437 
442  void ResizeCellList(vtkIdType ptId, int size);
443 
447  void Initialize() VTK_OVERRIDE;
448 
450 
453  virtual int GetPiece();
454  virtual int GetNumberOfPieces();
456 
460  virtual int GetGhostLevel();
461 
470  unsigned long GetActualMemorySize() VTK_OVERRIDE;
471 
473 
476  void ShallowCopy(vtkDataObject *src) VTK_OVERRIDE;
477  void DeepCopy(vtkDataObject *src) VTK_OVERRIDE;
479 
485  void RemoveGhostCells();
486 
488 
491  static vtkPolyData* GetData(vtkInformation* info);
492  static vtkPolyData* GetData(vtkInformationVector* v, int i=0);
494 
513  enum
514  {
515  ERR_NO_SUCH_FIELD = -4,
516  ERR_INCORRECT_FIELD = -3,
517  ERR_NON_MANIFOLD_STAR = -2,
518  REGULAR_POINT = -1,
519  MINIMUM = 0,
520  SADDLE = 1,
521  MAXIMUM = 2
522  };
523 
524  int GetScalarFieldCriticalIndex (vtkIdType pointId,
525  vtkDataArray *scalarField);
526  int GetScalarFieldCriticalIndex (vtkIdType pointId, int fieldId);
527  int GetScalarFieldCriticalIndex (vtkIdType pointId, const char* fieldName);
528 
529 protected:
530  vtkPolyData();
531  ~vtkPolyData() VTK_OVERRIDE;
532 
533  // constant cell objects returned by GetCell called.
534  vtkVertex *Vertex;
535  vtkPolyVertex *PolyVertex;
536  vtkLine *Line;
537  vtkPolyLine *PolyLine;
538  vtkTriangle *Triangle;
539  vtkQuad *Quad;
540  vtkPolygon *Polygon;
541  vtkTriangleStrip *TriangleStrip;
542  vtkEmptyCell *EmptyCell;
543 
544  // points inherited
545  // point data (i.e., scalars, vectors, normals, tcoords) inherited
546  vtkCellArray *Verts;
547  vtkCellArray *Lines;
548  vtkCellArray *Polys;
549  vtkCellArray *Strips;
550 
551  // dummy static member below used as a trick to simplify traversal
552  static vtkPolyDataDummyContainter DummyContainer;
553 
554  // supporting structures for more complex topological operations
555  // built only when necessary
556  vtkCellTypes *Cells;
557  vtkCellLinks *Links;
558 
559 private:
560  // Hide these from the user and the compiler.
561 
565  void GetCellNeighbors(vtkIdType cellId, vtkIdList& ptIds, vtkIdList& cellIds)
566  {this->GetCellNeighbors(cellId, &ptIds, &cellIds);}
567 
568  void Cleanup();
569 
570 private:
571  vtkPolyData(const vtkPolyData&) VTK_DELETE_FUNCTION;
572  void operator=(const vtkPolyData&) VTK_DELETE_FUNCTION;
573 };
574 
575 inline void vtkPolyData::GetPointCells(vtkIdType ptId, unsigned short& ncells,
576  vtkIdType* &cells)
577 {
578  ncells = this->Links->GetNcells(ptId);
579  cells = this->Links->GetCells(ptId);
580 }
581 
582 inline int vtkPolyData::IsTriangle(int v1, int v2, int v3)
583 {
584  unsigned short int n1;
585  int i, j, tVerts[3];
586  vtkIdType *cells, *tVerts2, n2;
587 
588  tVerts[0] = v1;
589  tVerts[1] = v2;
590  tVerts[2] = v3;
591 
592  for (i=0; i<3; i++)
593  {
594  this->GetPointCells(tVerts[i], n1, cells);
595  for (j=0; j<n1; j++)
596  {
597  this->GetCellPoints(cells[j], n2, tVerts2);
598  if ( (tVerts[0] == tVerts2[0] || tVerts[0] == tVerts2[1] ||
599  tVerts[0] == tVerts2[2]) &&
600  (tVerts[1] == tVerts2[0] || tVerts[1] == tVerts2[1] ||
601  tVerts[1] == tVerts2[2]) &&
602  (tVerts[2] == tVerts2[0] || tVerts[2] == tVerts2[1] ||
603  tVerts[2] == tVerts2[2]) )
604  {
605  return 1;
606  }
607  }
608  }
609  return 0;
610 }
611 
613 {
614  vtkIdType *pts, npts;
615 
616  this->GetCellPoints(cellId, npts, pts);
617  for (vtkIdType i=0; i < npts; i++)
618  {
619  if ( pts[i] == ptId )
620  {
621  return 1;
622  }
623  }
624 
625  return 0;
626 }
627 
629 {
630  this->Links->DeletePoint(ptId);
631 }
632 
634 {
635  this->Cells->DeleteCell(cellId);
636 }
637 
639 {
640  vtkIdType *pts, npts;
641 
642  this->GetCellPoints(cellId, npts, pts);
643  for (vtkIdType i=0; i<npts; i++)
644  {
645  this->Links->RemoveCellReference(cellId, pts[i]);
646  }
647 }
648 
650 {
651  vtkIdType *pts, npts;
652 
653  this->GetCellPoints(cellId, npts, pts);
654  for (vtkIdType i=0; i<npts; i++)
655  {
656  this->Links->AddCellReference(cellId, pts[i]);
657  }
658 }
659 
661 {
662  this->Links->ResizeCellList(ptId,size);
663 }
664 
666  vtkIdType newPtId)
667 {
668  int i;
669  vtkIdType *verts, nverts;
670 
671  this->GetCellPoints(cellId,nverts,verts);
672  for ( i=0; i < nverts; i++ )
673  {
674  if ( verts[i] == oldPtId )
675  {
676  verts[i] = newPtId; // this is very nasty! direct write!
677  return;
678  }
679  }
680 }
681 
682 inline unsigned char vtkPolyData::GetCellPoints(
683  vtkIdType cellId, vtkIdType& npts, vtkIdType* &pts)
684 {
685  unsigned char type = this->Cells->GetCellType(cellId);
686  vtkCellArray *cells;
687  switch (type)
688  {
689  case VTK_VERTEX: case VTK_POLY_VERTEX:
690  cells = this->Verts;
691  break;
692 
693  case VTK_LINE: case VTK_POLY_LINE:
694  cells = this->Lines;
695  break;
696 
697  case VTK_TRIANGLE: case VTK_QUAD: case VTK_POLYGON:
698  cells = this->Polys;
699  break;
700 
701  case VTK_TRIANGLE_STRIP:
702  cells = this->Strips;
703  break;
704 
705  default:
706  cells = NULL;
707  npts = 0;
708  pts = NULL;
709  return 0;
710  }
711  int loc = this->Cells->GetCellLocation(cellId);
712  cells->GetCell(loc, npts, pts);
713  return type;
714 }
715 
716 inline unsigned char vtkPolyData::GetCell(
717  vtkIdType cellId, vtkIdType* &cell)
718 {
719  unsigned char type = this->Cells->GetCellType(cellId);
720  vtkCellArray *cells;
721  switch (type)
722  {
723  case VTK_VERTEX: case VTK_POLY_VERTEX:
724  cells = this->Verts;
725  break;
726 
727  case VTK_LINE: case VTK_POLY_LINE:
728  cells = this->Lines;
729  break;
730 
731  case VTK_TRIANGLE: case VTK_QUAD: case VTK_POLYGON:
732  cells = this->Polys;
733  break;
734 
735  case VTK_TRIANGLE_STRIP:
736  cells = this->Strips;
737  break;
738 
739  default:
740  cells = NULL;
741  cell = NULL;
742  return 0;
743  }
744  int loc = this->Cells->GetCellLocation(cellId);
745  cell = cells->GetData()->GetPointer(loc);
746  return type;
747 }
748 
749 #endif
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:665
abstract class to specify dataset behavior
Definition: vtkDataSet.h:62
a cell that represents a 3D point
Definition: vtkVertex.h:36
void DeepCopy(vtkPistonReference *self, vtkPistonReference *other)
void AddCellReference(vtkIdType cellId)
Add references to cell in cell structure.
Definition: vtkPolyData.h:649
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:287
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 RemoveCellReference(vtkIdType cellId)
Remove all references to cell in cell structure.
Definition: vtkPolyData.h:638
void DeletePoint(vtkIdType ptId)
Mark a point/cell as deleted from this vtkPolyData.
Definition: vtkPolyData.h:628
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
vtkCell * GetCell(vtkIdType cellId) override
Standard vtkDataSet interface.
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
int IsTriangle(int v1, int v2, int v3)
Given three vertices, determine whether it's a triangle.
Definition: vtkPolyData.h:582
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:660
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:612
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.
void DeleteCell(vtkIdType cellId)
Mark a point/cell as deleted from this vtkPolyData.
Definition: vtkPolyData.h:633
void CopyStructure(vtkDataSet *pd) override
Copy the geometric structure of an input point set object.
#define VTK_POLY_DATA
Definition: vtkType.h:87
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.
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