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[]) VTK_SIZEHINT(pts, npts)
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
vtkCellArray::GetNumberOfConnectivityEntries
vtkIdType GetNumberOfConnectivityEntries()
Get the total number of entries (i.e., data values) in the connectivity array.
Definition: vtkCellArray.h:125
vtkCellArray::UpdateCellCount
void UpdateCellCount(int npts)
Used in conjunction with InsertNextCell(int npts) and InsertCellPoint() to update the number of point...
Definition: vtkCellArray.h:331
vtkCellArray::TraversalLocation
vtkIdType TraversalLocation
Definition: vtkCellArray.h:288
vtkAOSDataArrayTemplate::WritePointer
ValueType * WritePointer(vtkIdType valueIdx, vtkIdType numValues)
Get the address of a particular data index.
vtkCellArray::ReverseCell
void ReverseCell(vtkIdType loc)
Special method inverts ordering of current cell.
Definition: vtkCellArray.h:383
VTK_EXPECTS
#define VTK_EXPECTS(x)
Definition: vtkWrappingHints.h:41
vtkIdType
int vtkIdType
Definition: vtkType.h:347
vtkCellArray::InsertLocation
vtkIdType InsertLocation
Definition: vtkCellArray.h:287
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkCellArray::WritePointer
vtkIdType * WritePointer(const vtkIdType ncells, const vtkIdType size)
Get pointer to data array for purpose of direct writes of data.
Definition: vtkCellArray.h:409
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:53
vtkAOSDataArrayTemplate::GetPointer
ValueType * GetPointer(vtkIdType valueIdx)
Get the address of a particular data index.
vtkCellArray::GetData
vtkIdTypeArray * GetData()
Return the underlying data as a data array.
Definition: vtkCellArray.h:258
vtkCell.h
vtkCellArray::GetNextCell
int GetNextCell(vtkIdType &npts, vtkIdType *&pts)
A cell traversal methods that is more efficient than vtkDataSet traversal methods.
Definition: vtkCellArray.h:359
vtkCellArray::GetTraversalLocation
vtkIdType GetTraversalLocation(vtkIdType npts)
Computes the current traversal location within the internal array.
Definition: vtkCellArray.h:200
VTK_SIZEHINT
#define VTK_SIZEHINT(...)
Definition: vtkWrappingHints.h:42
vtkAbstractArray::GetMaxId
vtkIdType GetMaxId()
What is the maximum id currently in the array.
Definition: vtkAbstractArray.h:327
vtkCellArray::GetCell
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
vtkAbstractArray::Reset
void Reset()
Reset to an empty state, without freeing any memory.
Definition: vtkAbstractArray.h:311
vtkCellArray::Ia
vtkIdTypeArray * Ia
Definition: vtkCellArray.h:289
vtkCellArray::EstimateSize
vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell)
Utility routines help manage memory of cell array.
Definition: vtkCellArray.h:89
vtkAOSDataArrayTemplate::GetValue
ValueType GetValue(vtkIdType valueIdx) const
Get the value at valueIdx.
Definition: vtkAOSDataArrayTemplate.h:64
vtkCell
abstract class to specify cell behavior
Definition: vtkCell.h:56
vtkCellArray::Allocate
int Allocate(vtkIdType sz, vtkIdType ext=1000)
Allocate memory and set the size to extend by.
Definition: vtkCellArray.h:58
vtkCellArray::Squeeze
void Squeeze()
Reclaim any extra memory.
Definition: vtkCellArray.h:269
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkCellArray
object to represent cell connectivity
Definition: vtkCellArray.h:44
vtkCellArray::InsertCellPoint
void InsertCellPoint(vtkIdType id)
Used in conjunction with InsertNextCell(int npts) to add another point to the list of cells.
Definition: vtkCellArray.h:325
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:30
vtkX3D::size
Definition: vtkX3D.h:253
vtkObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkGenericDataArray::InsertValue
void InsertValue(vtkIdType valueIdx, ValueType value)
Insert data at a specified position in the array.
vtkCell::GetNumberOfPoints
vtkIdType GetNumberOfPoints()
Return the number of points in the cell.
Definition: vtkCell.h:137
vtkAOSDataArrayTemplate::SetValue
void SetValue(vtkIdType valueIdx, ValueType value)
Set the value at valueIdx to value.
Definition: vtkAOSDataArrayTemplate.h:73
vtkIdTypeArray.h
vtkObject.h
vtkIdTypeArray
dynamic, self-adjusting array of vtkIdType
Definition: vtkIdTypeArray.h:35
vtkCell::PointIds
vtkIdList * PointIds
Definition: vtkCell.h:363
vtkCellArray::GetSize
vtkIdType GetSize()
Get the size of the allocated connectivity array.
Definition: vtkCellArray.h:117
vtkCellArray::InitTraversal
void InitTraversal()
A cell traversal methods that is more efficient than vtkDataSet traversal methods.
Definition: vtkCellArray.h:96
vtkCellArray::InsertNextCell
vtkIdType InsertNextCell(vtkCell *cell)
Insert a cell object.
Definition: vtkCellArray.h:343
vtkIdList::GetPointer
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:108
vtkCellArray::ReplaceCell
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
vtkGenericDataArray::InsertNextValue
vtkIdType InsertNextValue(ValueType value)
Insert data at the end of the array.
vtkIdList::GetNumberOfIds
vtkIdType GetNumberOfIds()
Return the number of id's in the list.
Definition: vtkIdList.h:57
vtkCellArray::SetTraversalLocation
void SetTraversalLocation(vtkIdType loc)
Definition: vtkCellArray.h:193
vtkCellArray::GetTraversalLocation
vtkIdType GetTraversalLocation()
Get/Set the current traversal location.
Definition: vtkCellArray.h:191
vtkCellArray::NumberOfCells
vtkIdType NumberOfCells
Definition: vtkCellArray.h:286
vtkCellArray::Reset
void Reset()
Reuse list.
Definition: vtkCellArray.h:350