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) VTK_OVERRIDE;
49 
53  static vtkCellArray *New();
54 
58  int Allocate(const vtkIdType sz, const int 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 
111  int GetNextCell(vtkIdList *pts);
112 
117  {return this->Ia->GetSize();}
118 
125  {return this->Ia->GetMaxId()+1;}
126 
131  void GetCell(vtkIdType loc, vtkIdType &npts, vtkIdType* &pts);
132 
137  void GetCell(vtkIdType loc, vtkIdList* pts);
138 
142  vtkIdType InsertNextCell(vtkCell *cell);
143 
148  vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType* pts);
149 
154  vtkIdType InsertNextCell(vtkIdList *pts);
155 
162  vtkIdType InsertNextCell(int npts);
163 
168  void InsertCellPoint(vtkIdType id);
169 
174  void UpdateCellCount(int npts);
175 
181  {return (this->InsertLocation - npts - 1);};
182 
187  {return this->TraversalLocation;}
189  {this->TraversalLocation = loc;}
190 
196  {return(this->TraversalLocation-npts-1);}
197 
202  void ReverseCell(vtkIdType loc);
203 
210  void ReplaceCell(vtkIdType loc, int npts, const vtkIdType *pts);
211 
216  int GetMaxCellSize();
217 
222  {return this->Ia->GetPointer(0);}
223 
229  vtkIdType *WritePointer(const vtkIdType ncells, const vtkIdType size);
230 
240  void SetCells(vtkIdType ncells, vtkIdTypeArray *cells);
241 
245  void DeepCopy(vtkCellArray *ca);
246 
251  {return this->Ia;}
252 
256  void Reset();
257 
261  void Squeeze()
262  {this->Ia->Squeeze();}
263 
272  unsigned long GetActualMemorySize();
273 
274 protected:
275  vtkCellArray();
276  ~vtkCellArray() VTK_OVERRIDE;
277 
279  vtkIdType InsertLocation; //keep track of current insertion point
280  vtkIdType TraversalLocation; //keep track of traversal position
282 
283 private:
284  vtkCellArray(const vtkCellArray&) VTK_DELETE_FUNCTION;
285  void operator=(const vtkCellArray&) VTK_DELETE_FUNCTION;
286 };
287 
288 
289 //----------------------------------------------------------------------------
291  const vtkIdType* pts)
292 {
293  vtkIdType i = this->Ia->GetMaxId() + 1;
294  vtkIdType *ptr = this->Ia->WritePointer(i, npts+1);
295 
296  for ( *ptr++ = npts, i = 0; i < npts; i++)
297  {
298  *ptr++ = *pts++;
299  }
300 
301  this->NumberOfCells++;
302  this->InsertLocation += npts + 1;
303 
304  return this->NumberOfCells - 1;
305 }
306 
307 //----------------------------------------------------------------------------
309 {
310  this->InsertLocation = this->Ia->InsertNextValue(npts) + 1;
311  this->NumberOfCells++;
312 
313  return this->NumberOfCells - 1;
314 }
315 
316 //----------------------------------------------------------------------------
318 {
319  this->Ia->InsertValue(this->InsertLocation++, id);
320 }
321 
322 //----------------------------------------------------------------------------
323 inline void vtkCellArray::UpdateCellCount(int npts)
324 {
325  this->Ia->SetValue(this->InsertLocation-npts-1, npts);
326 }
327 
328 //----------------------------------------------------------------------------
330 {
331  return this->InsertNextCell(pts->GetNumberOfIds(), pts->GetPointer(0));
332 }
333 
334 //----------------------------------------------------------------------------
336 {
337  return this->InsertNextCell(cell->GetNumberOfPoints(),
338  cell->PointIds->GetPointer(0));
339 }
340 
341 //----------------------------------------------------------------------------
342 inline void vtkCellArray::Reset()
343 {
344  this->NumberOfCells = 0;
345  this->InsertLocation = 0;
346  this->TraversalLocation = 0;
347  this->Ia->Reset();
348 }
349 
350 //----------------------------------------------------------------------------
352 {
353  if ( this->Ia->GetMaxId() >= 0 &&
354  this->TraversalLocation <= this->Ia->GetMaxId() )
355  {
356  npts = this->Ia->GetValue(this->TraversalLocation++);
357  pts = this->Ia->GetPointer(this->TraversalLocation);
358  this->TraversalLocation += npts;
359  return 1;
360  }
361  npts=0;
362  pts=0;
363  return 0;
364 }
365 
366 //----------------------------------------------------------------------------
368  vtkIdType* &pts)
369 {
370  npts = this->Ia->GetValue(loc++);
371  pts = this->Ia->GetPointer(loc);
372 }
373 
374 //----------------------------------------------------------------------------
376 {
377  int i;
378  vtkIdType tmp;
379  vtkIdType npts=this->Ia->GetValue(loc);
380  vtkIdType *pts=this->Ia->GetPointer(loc+1);
381  for (i=0; i < (npts/2); i++)
382  {
383  tmp = pts[i];
384  pts[i] = pts[npts-i-1];
385  pts[npts-i-1] = tmp;
386  }
387 }
388 
389 //----------------------------------------------------------------------------
390 inline void vtkCellArray::ReplaceCell(vtkIdType loc, int npts,
391  const vtkIdType *pts)
392 {
393  vtkIdType *oldPts=this->Ia->GetPointer(loc+1);
394  for (int i=0; i < npts; i++)
395  {
396  oldPts[i] = pts[i];
397  }
398 }
399 
400 //----------------------------------------------------------------------------
402  const vtkIdType size)
403 {
404  this->NumberOfCells = ncells;
405  this->InsertLocation = 0;
406  this->TraversalLocation = 0;
407  return this->Ia->WritePointer(0,size);
408 }
409 
410 #endif
vtkIdType * GetPointer()
Get pointer to array of cell data.
Definition: vtkCellArray.h:221
vtkIdList * PointIds
Definition: vtkCell.h:361
vtkIdType GetNumberOfPoints()
Return the number of points in the cell.
Definition: vtkCell.h:137
vtkIdType GetInsertLocation(int npts)
Computes the current insertion location within the internal array.
Definition: vtkCellArray.h:180
abstract base class for most VTK objects
Definition: vtkObject.h:53
vtkIdType NumberOfCells
Definition: vtkCellArray.h:278
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:317
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:279
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:390
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:345
vtkIdTypeArray * Ia
Definition: vtkCellArray.h:281
void Squeeze()
Reclaim any extra memory.
Definition: vtkCellArray.h:261
abstract class to specify cell behavior
Definition: vtkCell.h:56
void Reset()
Reuse list.
Definition: vtkCellArray.h:342
void SetTraversalLocation(vtkIdType loc)
Definition: vtkCellArray.h:188
vtkIdType GetTraversalLocation(vtkIdType npts)
Computes the current traversal location within the internal array.
Definition: vtkCellArray.h:195
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:124
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:375
void UpdateCellCount(int npts)
Used in conjunction with InsertNextCell(int npts) and InsertCellPoint() to update the number of point...
Definition: vtkCellArray.h:323
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
vtkIdType TraversalLocation
Definition: vtkCellArray.h:280
vtkIdType InsertNextCell(vtkCell *cell)
Insert a cell object.
Definition: vtkCellArray.h:335
vtkIdType * WritePointer(const vtkIdType ncells, const vtkIdType size)
Get pointer to data array for purpose of direct writes of data.
Definition: vtkCellArray.h:401
object to represent cell connectivity
Definition: vtkCellArray.h:44
vtkIdTypeArray * GetData()
Return the underlying data as a data array.
Definition: vtkCellArray.h:250
vtkIdType GetSize()
Get the size of the allocated connectivity array.
Definition: vtkCellArray.h:116
int GetNextCell(vtkIdType &npts, vtkIdType *&pts)
A cell traversal methods that is more efficient than vtkDataSet traversal methods.
Definition: vtkCellArray.h:351
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:186
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:90
int Allocate(const vtkIdType sz, const int ext=1000)
Allocate memory and set the size to extend by.
Definition: vtkCellArray.h:58
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:367