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 =========================================================================*/
35 #ifndef vtkCellArray_h
36 #define vtkCellArray_h
37 
38 #include "vtkCommonDataModelModule.h" // For export macro
39 #include "vtkObject.h"
40 
41 #include "vtkIdTypeArray.h" // Needed for inline methods
42 #include "vtkCell.h" // Needed for inline methods
43 
44 class VTKCOMMONDATAMODEL_EXPORT vtkCellArray : public vtkObject
45 {
46 public:
47  vtkTypeMacro(vtkCellArray,vtkObject);
48  void PrintSelf(ostream& os, vtkIndent indent) override;
49 
53  static vtkCellArray *New();
54 
58  int Allocate(vtkIdType sz, vtkIdType ext=1000)
59  {return this->Ia->Allocate(sz,ext);}
60 
64  void Initialize();
65 
67 
70  vtkGetMacro(NumberOfCells, vtkIdType);
72 
74 
78  vtkSetMacro(NumberOfCells, vtkIdType);
80 
89  vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell)
90  {return numCells*(1+maxPtsPerCell);}
91 
96  void InitTraversal() {this->TraversalLocation=0;};
97 
104  int GetNextCell(vtkIdType& npts, vtkIdType* &pts)
105  VTK_SIZEHINT(pts, npts);
106 
112  int GetNextCell(vtkIdList *pts);
113 
118  {return this->Ia->GetSize();}
119 
126  {return this->Ia->GetMaxId()+1;}
127 
132  void GetCell(vtkIdType loc, vtkIdType &npts, vtkIdType* &pts)
133  VTK_EXPECTS(0 <= loc && loc < GetSize())
134  VTK_SIZEHINT(pts, npts);
135 
140  void GetCell(vtkIdType loc, vtkIdList* pts)
141  VTK_EXPECTS(0 <= loc && loc < GetSize());
142 
146  vtkIdType InsertNextCell(vtkCell *cell);
147 
152  vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType* pts)
153  VTK_SIZEHINT(pts, npts);
154 
159  vtkIdType InsertNextCell(vtkIdList *pts);
160 
167  vtkIdType InsertNextCell(int npts);
168 
173  void InsertCellPoint(vtkIdType id);
174 
179  void UpdateCellCount(int npts);
180 
185  vtkIdType GetInsertLocation(int npts)
186  {return (this->InsertLocation - npts - 1);};
187 
192  {return this->TraversalLocation;}
194  {this->TraversalLocation = loc;}
195 
201  {return(this->TraversalLocation-npts-1);}
202 
207  void ReverseCell(vtkIdType loc)
208  VTK_EXPECTS(0 <= loc && loc < GetSize());
209 
216  void ReplaceCell(vtkIdType loc, int npts, const vtkIdType *pts)
217  VTK_EXPECTS(0 <= loc && loc < GetSize())
218  VTK_SIZEHINT(pts, npts);
219 
224  int GetMaxCellSize();
225 
229  vtkIdType *GetPointer()
230  {return this->Ia->GetPointer(0);}
231 
237  vtkIdType *WritePointer(const vtkIdType ncells, const vtkIdType size);
238 
248  void SetCells(vtkIdType ncells, vtkIdTypeArray *cells);
249 
253  void DeepCopy(vtkCellArray *ca);
254 
259  {return this->Ia;}
260 
264  void Reset();
265 
269  void Squeeze()
270  {this->Ia->Squeeze();}
271 
280  unsigned long GetActualMemorySize();
281 
282 protected:
283  vtkCellArray();
284  ~vtkCellArray() override;
285 
287  vtkIdType InsertLocation; //keep track of current insertion point
288  vtkIdType TraversalLocation; //keep track of traversal position
290 
291 private:
292  vtkCellArray(const vtkCellArray&) = delete;
293  void operator=(const vtkCellArray&) = delete;
294 };
295 
296 
297 //----------------------------------------------------------------------------
299  const vtkIdType* pts)
300 {
301  vtkIdType i = this->Ia->GetMaxId() + 1;
302  vtkIdType *ptr = this->Ia->WritePointer(i, npts+1);
303 
304  for ( *ptr++ = npts, i = 0; i < npts; i++)
305  {
306  *ptr++ = *pts++;
307  }
308 
309  this->NumberOfCells++;
310  this->InsertLocation += npts + 1;
311 
312  return this->NumberOfCells - 1;
313 }
314 
315 //----------------------------------------------------------------------------
317 {
318  this->InsertLocation = this->Ia->InsertNextValue(npts) + 1;
319  this->NumberOfCells++;
320 
321  return this->NumberOfCells - 1;
322 }
323 
324 //----------------------------------------------------------------------------
326 {
327  this->Ia->InsertValue(this->InsertLocation++, id);
328 }
329 
330 //----------------------------------------------------------------------------
331 inline void vtkCellArray::UpdateCellCount(int npts)
332 {
333  this->Ia->SetValue(this->InsertLocation-npts-1, npts);
334 }
335 
336 //----------------------------------------------------------------------------
338 {
339  return this->InsertNextCell(pts->GetNumberOfIds(), pts->GetPointer(0));
340 }
341 
342 //----------------------------------------------------------------------------
344 {
345  return this->InsertNextCell(cell->GetNumberOfPoints(),
346  cell->PointIds->GetPointer(0));
347 }
348 
349 //----------------------------------------------------------------------------
350 inline void vtkCellArray::Reset()
351 {
352  this->NumberOfCells = 0;
353  this->InsertLocation = 0;
354  this->TraversalLocation = 0;
355  this->Ia->Reset();
356 }
357 
358 //----------------------------------------------------------------------------
360 {
361  if ( this->Ia->GetMaxId() >= 0 &&
362  this->TraversalLocation <= this->Ia->GetMaxId() )
363  {
364  npts = this->Ia->GetValue(this->TraversalLocation++);
365  pts = this->Ia->GetPointer(this->TraversalLocation);
366  this->TraversalLocation += npts;
367  return 1;
368  }
369  npts=0;
370  pts=nullptr;
371  return 0;
372 }
373 
374 //----------------------------------------------------------------------------
376  vtkIdType* &pts)
377 {
378  npts = this->Ia->GetValue(loc++);
379  pts = this->Ia->GetPointer(loc);
380 }
381 
382 //----------------------------------------------------------------------------
384 {
385  int i;
386  vtkIdType tmp;
387  vtkIdType npts=this->Ia->GetValue(loc);
388  vtkIdType *pts=this->Ia->GetPointer(loc+1);
389  for (i=0; i < (npts/2); i++)
390  {
391  tmp = pts[i];
392  pts[i] = pts[npts-i-1];
393  pts[npts-i-1] = tmp;
394  }
395 }
396 
397 //----------------------------------------------------------------------------
398 inline void vtkCellArray::ReplaceCell(vtkIdType loc, int npts,
399  const vtkIdType *pts)
400 {
401  vtkIdType *oldPts=this->Ia->GetPointer(loc+1);
402  for (int i=0; i < npts; i++)
403  {
404  oldPts[i] = pts[i];
405  }
406 }
407 
408 //----------------------------------------------------------------------------
410  const vtkIdType size)
411 {
412  this->NumberOfCells = ncells;
413  this->InsertLocation = size;
414  this->TraversalLocation = 0;
415  return this->Ia->WritePointer(0,size);
416 }
417 
418 #endif
vtkIdType GetMaxId()
What is the maximum id currently in the array.
vtkIdList * PointIds
Definition: vtkCell.h:363
vtkIdType GetNumberOfPoints()
Return the number of points in the cell.
Definition: vtkCell.h:137
abstract base class for most VTK objects
Definition: vtkObject.h:53
vtkIdType NumberOfCells
Definition: vtkCellArray.h:286
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:325
vtkIdType GetNumberOfIds()
Return the number of id&#39;s in the list.
Definition: vtkIdList.h:50
void InitTraversal()
A cell traversal methods that is more efficient than vtkDataSet traversal methods.
Definition: vtkCellArray.h:96
vtkIdType InsertLocation
Definition: vtkCellArray.h:287
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:398
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:345
vtkIdTypeArray * Ia
Definition: vtkCellArray.h:289
void Squeeze()
Reclaim any extra memory.
Definition: vtkCellArray.h:269
abstract class to specify cell behavior
Definition: vtkCell.h:56
void Reset()
Reuse list.
Definition: vtkCellArray.h:350
void SetTraversalLocation(vtkIdType loc)
Definition: vtkCellArray.h:193
vtkIdType GetTraversalLocation(vtkIdType npts)
Computes the current traversal location within the internal array.
Definition: vtkCellArray.h:200
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkIdType GetNumberOfConnectivityEntries()
Get the total number of entries (i.e., data values) in the connectivity array.
Definition: vtkCellArray.h:125
list of point or cell ids
Definition: vtkIdList.h:30
vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell)
Utility routines help manage memory of cell array.
Definition: vtkCellArray.h:89
void ReverseCell(vtkIdType loc)
Special method inverts ordering of current cell.
Definition: vtkCellArray.h:383
#define VTK_SIZEHINT(...)
void Reset()
Reset to an empty state, without freeing any memory.
void UpdateCellCount(int npts)
Used in conjunction with InsertNextCell(int npts) and InsertCellPoint() to update the number of point...
Definition: vtkCellArray.h:331
vtkIdType TraversalLocation
Definition: vtkCellArray.h:288
vtkIdType InsertNextCell(vtkCell *cell)
Insert a cell object.
Definition: vtkCellArray.h:343
vtkIdType * WritePointer(const vtkIdType ncells, const vtkIdType size)
Get pointer to data array for purpose of direct writes of data.
Definition: vtkCellArray.h:409
object to represent cell connectivity
Definition: vtkCellArray.h:44
vtkIdTypeArray * GetData()
Return the underlying data as a data array.
Definition: vtkCellArray.h:258
vtkIdType GetSize()
Get the size of the allocated connectivity array.
Definition: vtkCellArray.h:117
int GetNextCell(vtkIdType &npts, vtkIdType *&pts)
A cell traversal methods that is more efficient than vtkDataSet traversal methods.
Definition: vtkCellArray.h:359
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:191
#define VTK_EXPECTS(x)
int Allocate(vtkIdType sz, vtkIdType ext=1000)
Allocate memory and set the size to extend by.
Definition: vtkCellArray.h:58
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:95
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