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) VTK_OVERRIDE;
55 
59  static vtkCellArray *New();
60 
64  int Allocate(const vtkIdType sz, const int ext=1000)
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 
117  int GetNextCell(vtkIdList *pts);
118 
123  {return this->Ia->GetSize();}
124 
131  {return this->Ia->GetMaxId()+1;}
132 
137  void GetCell(vtkIdType loc, vtkIdType &npts, vtkIdType* &pts);
138 
143  void GetCell(vtkIdType loc, vtkIdList* pts);
144 
148  vtkIdType InsertNextCell(vtkCell *cell);
149 
154  vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType* pts);
155 
160  vtkIdType InsertNextCell(vtkIdList *pts);
161 
168  vtkIdType InsertNextCell(int npts);
169 
174  void InsertCellPoint(vtkIdType id);
175 
180  void UpdateCellCount(int npts);
181 
187  {return (this->InsertLocation - npts - 1);};
188 
193  {return this->TraversalLocation;}
195  {this->TraversalLocation = loc;}
196 
202  {return(this->TraversalLocation-npts-1);}
203 
208  void ReverseCell(vtkIdType loc);
209 
216  void ReplaceCell(vtkIdType loc, int npts, const vtkIdType *pts);
217 
222  int GetMaxCellSize();
223 
228  {return this->Ia->GetPointer(0);}
229 
235  vtkIdType *WritePointer(const vtkIdType ncells, const vtkIdType size);
236 
246  void SetCells(vtkIdType ncells, vtkIdTypeArray *cells);
247 
251  void DeepCopy(vtkCellArray *ca);
252 
257  {return this->Ia;}
258 
262  void Reset();
263 
267  void Squeeze()
268  {this->Ia->Squeeze();}
269 
278  unsigned long GetActualMemorySize();
279 
280 protected:
281  vtkCellArray();
282  ~vtkCellArray() VTK_OVERRIDE;
283 
284  vtkIdType NumberOfCells;
285  vtkIdType InsertLocation; //keep track of current insertion point
286  vtkIdType TraversalLocation; //keep track of traversal position
288 
289 private:
290  vtkCellArray(const vtkCellArray&) VTK_DELETE_FUNCTION;
291  void operator=(const vtkCellArray&) VTK_DELETE_FUNCTION;
292 };
293 
294 
295 //----------------------------------------------------------------------------
296 inline vtkIdType vtkCellArray::InsertNextCell(vtkIdType npts,
297  const vtkIdType* pts)
298 {
299  vtkIdType i = this->Ia->GetMaxId() + 1;
300  vtkIdType *ptr = this->Ia->WritePointer(i, npts+1);
301 
302  for ( *ptr++ = npts, i = 0; i < npts; i++)
303  {
304  *ptr++ = *pts++;
305  }
306 
307  this->NumberOfCells++;
308  this->InsertLocation += npts + 1;
309 
310  return this->NumberOfCells - 1;
311 }
312 
313 //----------------------------------------------------------------------------
315 {
316  this->InsertLocation = this->Ia->InsertNextValue(npts) + 1;
317  this->NumberOfCells++;
318 
319  return this->NumberOfCells - 1;
320 }
321 
322 //----------------------------------------------------------------------------
324 {
325  this->Ia->InsertValue(this->InsertLocation++, id);
326 }
327 
328 //----------------------------------------------------------------------------
329 inline void vtkCellArray::UpdateCellCount(int npts)
330 {
331  this->Ia->SetValue(this->InsertLocation-npts-1, npts);
332 }
333 
334 //----------------------------------------------------------------------------
336 {
337  return this->InsertNextCell(pts->GetNumberOfIds(), pts->GetPointer(0));
338 }
339 
340 //----------------------------------------------------------------------------
342 {
343  return this->InsertNextCell(cell->GetNumberOfPoints(),
344  cell->PointIds->GetPointer(0));
345 }
346 
347 //----------------------------------------------------------------------------
348 inline void vtkCellArray::Reset()
349 {
350  this->NumberOfCells = 0;
351  this->InsertLocation = 0;
352  this->TraversalLocation = 0;
353  this->Ia->Reset();
354 }
355 
356 //----------------------------------------------------------------------------
358 {
359  if ( this->Ia->GetMaxId() >= 0 &&
360  this->TraversalLocation <= this->Ia->GetMaxId() )
361  {
362  npts = this->Ia->GetValue(this->TraversalLocation++);
363  pts = this->Ia->GetPointer(this->TraversalLocation);
364  this->TraversalLocation += npts;
365  return 1;
366  }
367  npts=0;
368  pts=0;
369  return 0;
370 }
371 
372 //----------------------------------------------------------------------------
374  vtkIdType* &pts)
375 {
376  npts = this->Ia->GetValue(loc++);
377  pts = this->Ia->GetPointer(loc);
378 }
379 
380 //----------------------------------------------------------------------------
382 {
383  int i;
384  vtkIdType tmp;
385  vtkIdType npts=this->Ia->GetValue(loc);
386  vtkIdType *pts=this->Ia->GetPointer(loc+1);
387  for (i=0; i < (npts/2); i++)
388  {
389  tmp = pts[i];
390  pts[i] = pts[npts-i-1];
391  pts[npts-i-1] = tmp;
392  }
393 }
394 
395 //----------------------------------------------------------------------------
396 inline void vtkCellArray::ReplaceCell(vtkIdType loc, int npts,
397  const vtkIdType *pts)
398 {
399  vtkIdType *oldPts=this->Ia->GetPointer(loc+1);
400  for (int i=0; i < npts; i++)
401  {
402  oldPts[i] = pts[i];
403  }
404 }
405 
406 //----------------------------------------------------------------------------
408  const vtkIdType size)
409 {
410  this->NumberOfCells = ncells;
411  this->InsertLocation = 0;
412  this->TraversalLocation = 0;
413  return this->Ia->WritePointer(0,size);
414 }
415 
416 #endif
vtkpiston::DeepCopy
void DeepCopy(vtkPistonReference *self, vtkPistonReference *other)
vtkCellArray::GetNumberOfConnectivityEntries
vtkIdType GetNumberOfConnectivityEntries()
Get the total number of entries (i.e., data values) in the connectivity array.
Definition: vtkCellArray.h:130
vtkCellArray::Allocate
int Allocate(const vtkIdType sz, const int ext=1000)
Allocate memory and set the size to extend by.
Definition: vtkCellArray.h:64
vtkCellArray::UpdateCellCount
void UpdateCellCount(int npts)
Used in conjunction with InsertNextCell(int npts) and InsertCellPoint() to update the number of point...
Definition: vtkCellArray.h:329
vtkCellArray::ReverseCell
void ReverseCell(vtkIdType loc)
Special method inverts ordering of current cell.
Definition: vtkCellArray.h:381
vtkIdType
int vtkIdType
Definition: vtkType.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:407
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:59
vtkCellArray::GetData
vtkIdTypeArray * GetData()
Return the underlying data as a data array.
Definition: vtkCellArray.h:256
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:357
vtkCellArray::GetTraversalLocation
vtkIdType GetTraversalLocation(vtkIdType npts)
Computes the current traversal location within the internal array.
Definition: vtkCellArray.h:201
vtkAbstractArray::GetMaxId
vtkIdType GetMaxId()
What is the maximum id currently in the array.
Definition: vtkAbstractArray.h:330
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:373
vtkCellArray::EstimateSize
vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell)
Utility routines help manage memory of cell array.
Definition: vtkCellArray.h:95
vtkCell
abstract class to specify cell behavior
Definition: vtkCell.h:59
vtkCellArray::Squeeze
void Squeeze()
Reclaim any extra memory.
Definition: vtkCellArray.h:267
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkCellArray::GetPointer
vtkIdType * GetPointer()
Get pointer to array of cell data.
Definition: vtkCellArray.h:227
vtkCellArray
object to represent cell connectivity
Definition: vtkCellArray.h:50
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:323
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:36
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.
vtkCell::GetNumberOfPoints
vtkIdType GetNumberOfPoints()
Return the number of points in the cell.
Definition: vtkCell.h:132
vtkIdTypeArray.h
vtkObject.h
vtkSetMacro
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
vtkIdTypeArray
dynamic, self-adjusting array of vtkIdType
Definition: vtkIdTypeArray.h:41
vtkCell::PointIds
vtkIdList * PointIds
Definition: vtkCell.h:356
vtkCellArray::GetSize
vtkIdType GetSize()
Get the size of the allocated connectivity array.
Definition: vtkCellArray.h:122
vtkCellArray::InitTraversal
void InitTraversal()
A cell traversal methods that is more efficient than vtkDataSet traversal methods.
Definition: vtkCellArray.h:102
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:396
vtkCellArray::InsertNextCell
vtkIdType InsertNextCell(vtkCell *cell)
Insert a cell object.
Definition: vtkCellArray.h:341
vtkIdList::GetPointer
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:96
vtkIdList::GetNumberOfIds
vtkIdType GetNumberOfIds()
Return the number of id's in the list.
Definition: vtkIdList.h:56
vtkCellArray::SetTraversalLocation
void SetTraversalLocation(vtkIdType loc)
Definition: vtkCellArray.h:194
vtkCellArray::GetInsertLocation
vtkIdType GetInsertLocation(int npts)
Computes the current insertion location within the internal array.
Definition: vtkCellArray.h:186
vtkCellArray::GetTraversalLocation
vtkIdType GetTraversalLocation()
Get/Set the current traversal location.
Definition: vtkCellArray.h:192
vtkCellArray::Reset
void Reset()
Reuse list.
Definition: vtkCellArray.h:348