VTK
vtkCellArray.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkCellArray.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 =========================================================================*/
41 #ifndef vtkCellArray_h
42 #define vtkCellArray_h
43 
44 #include "vtkCommonDataModelModule.h" // For export macro
45 #include "vtkObject.h"
46 
47 #include "vtkIdTypeArray.h" // Needed for inline methods
48 #include "vtkCell.h" // Needed for inline methods
49 
50 class VTKCOMMONDATAMODEL_EXPORT vtkCellArray : public vtkObject
51 {
52 public:
53  vtkTypeMacro(vtkCellArray,vtkObject);
54  void PrintSelf(ostream& os, vtkIndent indent) override;
55 
59  static vtkCellArray *New();
60 
65  {return this->Ia->Allocate(sz,ext);}
66 
70  void Initialize();
71 
73 
76  vtkGetMacro(NumberOfCells, vtkIdType);
78 
80 
84  vtkSetMacro(NumberOfCells, vtkIdType);
86 
95  vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell)
96  {return numCells*(1+maxPtsPerCell);}
97 
102  void InitTraversal() {this->TraversalLocation=0;};
103 
110  int GetNextCell(vtkIdType& npts, vtkIdType* &pts)
111  VTK_SIZEHINT(pts, npts);
112 
118  int GetNextCell(vtkIdList *pts);
119 
124  {return this->Ia->GetSize();}
125 
132  {return this->Ia->GetMaxId()+1;}
133 
138  void GetCell(vtkIdType loc, vtkIdType &npts, vtkIdType* &pts)
139  VTK_EXPECTS(0 <= loc && loc < GetSize())
140  VTK_SIZEHINT(pts, npts);
141 
146  void GetCell(vtkIdType loc, vtkIdList* pts)
147  VTK_EXPECTS(0 <= loc && loc < GetSize());
148 
152  vtkIdType InsertNextCell(vtkCell *cell);
153 
158  vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType pts[])
159  VTK_SIZEHINT(pts, npts);
160 
165  vtkIdType InsertNextCell(vtkIdList *pts);
166 
173  vtkIdType InsertNextCell(int npts);
174 
179  void InsertCellPoint(vtkIdType id);
180 
185  void UpdateCellCount(int npts);
186 
192  {return (this->InsertLocation - npts - 1);};
193 
198  {return this->TraversalLocation;}
200  {this->TraversalLocation = loc;}
201 
207  {return(this->TraversalLocation-npts-1);}
208 
213  void ReverseCell(vtkIdType loc)
214  VTK_EXPECTS(0 <= loc && loc < GetSize());
215 
222  void ReplaceCell(vtkIdType loc, int npts, const vtkIdType pts[])
223  VTK_EXPECTS(0 <= loc && loc < GetSize())
224  VTK_SIZEHINT(pts, npts);
225 
230  int GetMaxCellSize();
231 
236  {return this->Ia->GetPointer(0);}
237 
243  vtkIdType *WritePointer(const vtkIdType ncells, const vtkIdType size);
244 
254  void SetCells(vtkIdType ncells, vtkIdTypeArray *cells);
255 
259  void DeepCopy(vtkCellArray *ca);
260 
265  {return this->Ia;}
266 
270  void Reset();
271 
275  void Squeeze()
276  {this->Ia->Squeeze();}
277 
286  unsigned long GetActualMemorySize();
287 
288 protected:
289  vtkCellArray();
290  ~vtkCellArray() override;
291 
293  vtkIdType InsertLocation; //keep track of current insertion point
294  vtkIdType TraversalLocation; //keep track of traversal position
296 
297 private:
298  vtkCellArray(const vtkCellArray&) = delete;
299  void operator=(const vtkCellArray&) = delete;
300 };
301 
302 
303 //----------------------------------------------------------------------------
305  const vtkIdType pts[]) VTK_SIZEHINT(pts, npts)
306 {
307  vtkIdType i = this->Ia->GetMaxId() + 1;
308  vtkIdType *ptr = this->Ia->WritePointer(i, npts+1);
309 
310  for ( *ptr++ = npts, i = 0; i < npts; i++)
311  {
312  *ptr++ = *pts++;
313  }
314 
315  this->NumberOfCells++;
316  this->InsertLocation += npts + 1;
317 
318  return this->NumberOfCells - 1;
319 }
320 
321 //----------------------------------------------------------------------------
323 {
324  this->InsertLocation = this->Ia->InsertNextValue(npts) + 1;
325  this->NumberOfCells++;
326 
327  return this->NumberOfCells - 1;
328 }
329 
330 //----------------------------------------------------------------------------
332 {
333  this->Ia->InsertValue(this->InsertLocation++, id);
334 }
335 
336 //----------------------------------------------------------------------------
337 inline void vtkCellArray::UpdateCellCount(int npts)
338 {
339  this->Ia->SetValue(this->InsertLocation-npts-1, npts);
340 }
341 
342 //----------------------------------------------------------------------------
344 {
345  return this->InsertNextCell(pts->GetNumberOfIds(), pts->GetPointer(0));
346 }
347 
348 //----------------------------------------------------------------------------
350 {
351  return this->InsertNextCell(cell->GetNumberOfPoints(),
352  cell->PointIds->GetPointer(0));
353 }
354 
355 //----------------------------------------------------------------------------
356 inline void vtkCellArray::Reset()
357 {
358  this->NumberOfCells = 0;
359  this->InsertLocation = 0;
360  this->TraversalLocation = 0;
361  this->Ia->Reset();
362 }
363 
364 //----------------------------------------------------------------------------
366 {
367  if ( this->Ia->GetMaxId() >= 0 &&
368  this->TraversalLocation <= this->Ia->GetMaxId() )
369  {
370  npts = this->Ia->GetValue(this->TraversalLocation++);
371  pts = this->Ia->GetPointer(this->TraversalLocation);
372  this->TraversalLocation += npts;
373  return 1;
374  }
375  npts=0;
376  pts=nullptr;
377  return 0;
378 }
379 
380 //----------------------------------------------------------------------------
382  vtkIdType* &pts)
383 {
384  npts = this->Ia->GetValue(loc++);
385  pts = this->Ia->GetPointer(loc);
386 }
387 
388 //----------------------------------------------------------------------------
390 {
391  int i;
392  vtkIdType tmp;
393  vtkIdType npts=this->Ia->GetValue(loc);
394  vtkIdType *pts=this->Ia->GetPointer(loc+1);
395  for (i=0; i < (npts/2); i++)
396  {
397  tmp = pts[i];
398  pts[i] = pts[npts-i-1];
399  pts[npts-i-1] = tmp;
400  }
401 }
402 
403 //----------------------------------------------------------------------------
404 inline void vtkCellArray::ReplaceCell(vtkIdType loc, int npts,
405  const vtkIdType pts[])
406 {
407  vtkIdType *oldPts=this->Ia->GetPointer(loc+1);
408  for (int i=0; i < npts; i++)
409  {
410  oldPts[i] = pts[i];
411  }
412 }
413 
414 //----------------------------------------------------------------------------
416  const vtkIdType size)
417 {
418  this->NumberOfCells = ncells;
419  this->InsertLocation = size;
420  this->TraversalLocation = 0;
421  return this->Ia->WritePointer(0,size);
422 }
423 
424 #endif
vtkIdType * GetPointer()
Get pointer to array of cell data.
Definition: vtkCellArray.h:235
vtkIdList * PointIds
Definition: vtkCell.h:366
vtkIdType GetNumberOfPoints()
Return the number of points in the cell.
Definition: vtkCell.h:140
vtkIdType GetInsertLocation(int npts)
Computes the current insertion location within the internal array.
Definition: vtkCellArray.h:191
abstract base class for most VTK objects
Definition: vtkObject.h:59
vtkIdType NumberOfCells
Definition: vtkCellArray.h:292
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void InsertCellPoint(vtkIdType id)
Used in conjunction with InsertNextCell(int npts) to add another point to the list of cells...
Definition: vtkCellArray.h:331
vtkIdType GetNumberOfIds()
Return the number of id&#39;s in the list.
Definition: vtkIdList.h:63
void InitTraversal()
A cell traversal methods that is more efficient than vtkDataSet traversal methods.
Definition: vtkCellArray.h:102
vtkIdType InsertLocation
Definition: vtkCellArray.h:293
vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext=1000)
Allocate memory and set the size to extend by.
Definition: vtkCellArray.h:64
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:347
void ReplaceCell(vtkIdType loc, int npts, const vtkIdType pts[])
Replace the point ids of the cell with a different list of point ids.
Definition: vtkCellArray.h:404
vtkIdTypeArray * Ia
Definition: vtkCellArray.h:295
int vtkTypeBool
Definition: vtkABI.h:69
void Squeeze()
Reclaim any extra memory.
Definition: vtkCellArray.h:275
abstract class to specify cell behavior
Definition: vtkCell.h:59
void Reset()
Reuse list.
Definition: vtkCellArray.h:356
void SetTraversalLocation(vtkIdType loc)
Definition: vtkCellArray.h:199
vtkIdType GetTraversalLocation(vtkIdType npts)
Computes the current traversal location within the internal array.
Definition: vtkCellArray.h:206
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkIdType GetNumberOfConnectivityEntries()
Get the total number of entries (i.e., data values) in the connectivity array.
Definition: vtkCellArray.h:131
list of point or cell ids
Definition: vtkIdList.h:36
vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell)
Utility routines help manage memory of cell array.
Definition: vtkCellArray.h:95
void ReverseCell(vtkIdType loc)
Special method inverts ordering of current cell.
Definition: vtkCellArray.h:389
#define VTK_SIZEHINT(...)
void UpdateCellCount(int npts)
Used in conjunction with InsertNextCell(int npts) and InsertCellPoint() to update the number of point...
Definition: vtkCellArray.h:337
vtkIdType TraversalLocation
Definition: vtkCellArray.h:294
vtkIdType InsertNextCell(vtkCell *cell)
Insert a cell object.
Definition: vtkCellArray.h:349
vtkIdType * WritePointer(const vtkIdType ncells, const vtkIdType size)
Get pointer to data array for purpose of direct writes of data.
Definition: vtkCellArray.h:415
object to represent cell connectivity
Definition: vtkCellArray.h:50
vtkIdTypeArray * GetData()
Return the underlying data as a data array.
Definition: vtkCellArray.h:264
vtkIdType GetSize()
Get the size of the allocated connectivity array.
Definition: vtkCellArray.h:123
int GetNextCell(vtkIdType &npts, vtkIdType *&pts)
A cell traversal methods that is more efficient than vtkDataSet traversal methods.
Definition: vtkCellArray.h:365
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
vtkIdType GetTraversalLocation()
Get/Set the current traversal location.
Definition: vtkCellArray.h:197
#define VTK_EXPECTS(x)
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:114
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