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
50class VTKCOMMONDATAMODEL_EXPORT vtkCellArray : public vtkObject
51{
52public:
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
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
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
252
257 {return this->Ia;}
258
262 void Reset();
263
267 void Squeeze()
268 {this->Ia->Squeeze();}
269
278 unsigned long GetActualMemorySize();
279
280protected:
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
289private:
290 vtkCellArray(const vtkCellArray&) VTK_DELETE_FUNCTION;
291 void operator=(const vtkCellArray&) VTK_DELETE_FUNCTION;
292};
293
294
295//----------------------------------------------------------------------------
296inline 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//----------------------------------------------------------------------------
329inline 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//----------------------------------------------------------------------------
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//----------------------------------------------------------------------------
396inline 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
vtkIdType GetMaxId()
What is the maximum id currently in the array.
object to represent cell connectivity
Definition: vtkCellArray.h:51
vtkIdTypeArray * GetData()
Return the underlying data as a data array.
Definition: vtkCellArray.h:256
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
vtkIdType GetNumberOfConnectivityEntries()
Get the total number of entries (i.e., data values) in the connectivity array.
Definition: vtkCellArray.h:130
int GetNextCell(vtkIdList *pts)
A cell traversal methods that is more efficient than vtkDataSet traversal methods.
void Reset()
Reuse list.
Definition: vtkCellArray.h:348
vtkIdType GetTraversalLocation()
Get/Set the current traversal location.
Definition: vtkCellArray.h:192
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:381
int GetNextCell(vtkIdType &npts, vtkIdType *&pts)
A cell traversal methods that is more efficient than vtkDataSet traversal methods.
Definition: vtkCellArray.h:357
void InitTraversal()
A cell traversal methods that is more efficient than vtkDataSet traversal methods.
Definition: vtkCellArray.h:102
void InsertCellPoint(vtkIdType id)
Used in conjunction with InsertNextCell(int npts) to add another point to the list of cells.
Definition: vtkCellArray.h:323
~vtkCellArray() override
void SetTraversalLocation(vtkIdType loc)
Definition: vtkCellArray.h:194
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
void Squeeze()
Reclaim any extra memory.
Definition: vtkCellArray.h:267
int GetMaxCellSize()
Returns the size of the largest cell.
vtkIdType * GetPointer()
Get pointer to array of cell data.
Definition: vtkCellArray.h:227
void Initialize()
Free any memory and reset to an empty state.
void DeepCopy(vtkCellArray *ca)
Perform a deep copy (no reference counting) of the given cell array.
vtkIdType InsertNextCell(vtkCell *cell)
Insert a cell object.
Definition: vtkCellArray.h:341
int Allocate(const vtkIdType sz, const int ext=1000)
Allocate memory and set the size to extend by.
Definition: vtkCellArray.h:64
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkIdType GetInsertLocation(int npts)
Computes the current insertion location within the internal array.
Definition: vtkCellArray.h:186
void UpdateCellCount(int npts)
Used in conjunction with InsertNextCell(int npts) and InsertCellPoint() to update the number of point...
Definition: vtkCellArray.h:329
void SetCells(vtkIdType ncells, vtkIdTypeArray *cells)
Define multiple cells by providing a connectivity list.
static vtkCellArray * New()
Instantiate cell array (connectivity list).
unsigned long GetActualMemorySize()
Return the memory in kibibytes (1024 bytes) consumed by this cell array.
vtkIdType GetTraversalLocation(vtkIdType npts)
Computes the current traversal location within the internal array.
Definition: vtkCellArray.h:201
vtkIdType * WritePointer(const vtkIdType ncells, const vtkIdType size)
Get pointer to data array for purpose of direct writes of data.
Definition: vtkCellArray.h:407
vtkIdType GetSize()
Get the size of the allocated connectivity array.
Definition: vtkCellArray.h:122
void GetCell(vtkIdType loc, vtkIdList *pts)
Internal method used to retrieve a cell given an offset into the internal array.
abstract class to specify cell behavior
Definition: vtkCell.h:60
vtkIdType GetNumberOfPoints()
Return the number of points in the cell.
Definition: vtkCell.h:132
vtkIdList * PointIds
Definition: vtkCell.h:356
list of point or cell ids
Definition: vtkIdList.h:37
vtkIdType GetNumberOfIds()
Return the number of id's in the list.
Definition: vtkIdList.h:56
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:96
dynamic, self-adjusting array of vtkIdType
a simple class to control print indentation
Definition: vtkIndent.h:40
abstract base class for most VTK objects
Definition: vtkObject.h:60
@ size
Definition: vtkX3D.h:253
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
int vtkIdType
Definition: vtkType.h:287