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 =========================================================================*/
40 #ifndef __vtkCellArray_h
41 #define __vtkCellArray_h
42 
43 #include "vtkObject.h"
44 
45 #include "vtkIdTypeArray.h" // Needed for inline methods
46 #include "vtkCell.h" // Needed for inline methods
47 
49 {
50 public:
51  vtkTypeMacro(vtkCellArray,vtkObject);
52  void PrintSelf(ostream& os, vtkIndent indent);
53 
55  static vtkCellArray *New();
56 
58 
59  int Allocate(const vtkIdType sz, const int ext=1000)
60  {return this->Ia->Allocate(sz,ext);}
62 
64  void Initialize();
65 
67 
68  vtkGetMacro(NumberOfCells, vtkIdType);
70 
72 
74  vtkSetMacro(NumberOfCells, vtkIdType);
76 
78 
84  vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell)
85  {return numCells*(1+maxPtsPerCell);}
87 
91  void InitTraversal() {this->TraversalLocation=0;};
92 
96  int GetNextCell(vtkIdType& npts, vtkIdType* &pts);
97 
101  int GetNextCell(vtkIdList *pts);
102 
104 
106  {return this->Ia->GetSize();}
108 
110 
114  {return this->Ia->GetMaxId()+1;}
116 
119  void GetCell(vtkIdType loc, vtkIdType &npts, vtkIdType* &pts);
120 
123  void GetCell(vtkIdType loc, vtkIdList* pts);
124 
126  vtkIdType InsertNextCell(vtkCell *cell);
127 
130  vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType* pts);
131 
134  vtkIdType InsertNextCell(vtkIdList *pts);
135 
140  vtkIdType InsertNextCell(int npts);
141 
144  void InsertCellPoint(vtkIdType id);
145 
148  void UpdateCellCount(int npts);
149 
151 
154  {return (this->InsertLocation - npts - 1);};
156 
158 
160  {return this->TraversalLocation;}
162  {this->TraversalLocation = loc;}
164 
166 
169  {return(this->TraversalLocation-npts-1);}
171 
174  void ReverseCell(vtkIdType loc);
175 
177  void ReplaceCell(vtkIdType loc, int npts, const vtkIdType *pts);
178 
181  int GetMaxCellSize();
182 
184 
186  {return this->Ia->GetPointer(0);}
188 
192  vtkIdType *WritePointer(const vtkIdType ncells, const vtkIdType size);
193 
201  void SetCells(vtkIdType ncells, vtkIdTypeArray *cells);
202 
204  void DeepCopy(vtkCellArray *ca);
205 
207 
209  {return this->Ia;}
211 
213  void Reset();
214 
216 
217  void Squeeze()
218  {this->Ia->Squeeze();}
220 
227  unsigned long GetActualMemorySize();
228 
229 protected:
230  vtkCellArray();
231  ~vtkCellArray();
232 
234  vtkIdType InsertLocation; //keep track of current insertion point
235  vtkIdType TraversalLocation; //keep track of traversal position
237 
238 private:
239  vtkCellArray(const vtkCellArray&); // Not implemented.
240  void operator=(const vtkCellArray&); // Not implemented.
241 };
242 
243 
244 //----------------------------------------------------------------------------
246  const vtkIdType* pts)
247 {
248  vtkIdType i = this->Ia->GetMaxId() + 1;
249  vtkIdType *ptr = this->Ia->WritePointer(i, npts+1);
250 
251  for ( *ptr++ = npts, i = 0; i < npts; i++)
252  {
253  *ptr++ = *pts++;
254  }
255 
256  this->NumberOfCells++;
257  this->InsertLocation += npts + 1;
258 
259  return this->NumberOfCells - 1;
260 }
261 
262 //----------------------------------------------------------------------------
264 {
265  this->InsertLocation = this->Ia->InsertNextValue(npts) + 1;
266  this->NumberOfCells++;
267 
268  return this->NumberOfCells - 1;
269 }
270 
271 //----------------------------------------------------------------------------
273 {
274  this->Ia->InsertValue(this->InsertLocation++, id);
275 }
276 
277 //----------------------------------------------------------------------------
278 inline void vtkCellArray::UpdateCellCount(int npts)
279 {
280  this->Ia->SetValue(this->InsertLocation-npts-1, npts);
281 }
282 
283 //----------------------------------------------------------------------------
285 {
286  return this->InsertNextCell(pts->GetNumberOfIds(), pts->GetPointer(0));
287 }
288 
289 //----------------------------------------------------------------------------
291 {
292  return this->InsertNextCell(cell->GetNumberOfPoints(),
293  cell->PointIds->GetPointer(0));
294 }
295 
296 //----------------------------------------------------------------------------
297 inline void vtkCellArray::Reset()
298 {
299  this->NumberOfCells = 0;
300  this->InsertLocation = 0;
301  this->TraversalLocation = 0;
302  this->Ia->Reset();
303 }
304 
305 //----------------------------------------------------------------------------
307 {
308  if ( this->Ia->GetMaxId() >= 0 &&
309  this->TraversalLocation <= this->Ia->GetMaxId() )
310  {
311  npts = this->Ia->GetValue(this->TraversalLocation++);
312  pts = this->Ia->GetPointer(this->TraversalLocation);
313  this->TraversalLocation += npts;
314  return 1;
315  }
316  npts=0;
317  pts=0;
318  return 0;
319 }
320 
321 //----------------------------------------------------------------------------
323  vtkIdType* &pts)
324 {
325  npts = this->Ia->GetValue(loc++);
326  pts = this->Ia->GetPointer(loc);
327 }
328 
329 //----------------------------------------------------------------------------
331 {
332  int i;
333  vtkIdType tmp;
334  vtkIdType npts=this->Ia->GetValue(loc);
335  vtkIdType *pts=this->Ia->GetPointer(loc+1);
336  for (i=0; i < (npts/2); i++)
337  {
338  tmp = pts[i];
339  pts[i] = pts[npts-i-1];
340  pts[npts-i-1] = tmp;
341  }
342 }
343 
344 //----------------------------------------------------------------------------
345 inline void vtkCellArray::ReplaceCell(vtkIdType loc, int npts,
346  const vtkIdType *pts)
347 {
348  vtkIdType *oldPts=this->Ia->GetPointer(loc+1);
349  for (int i=0; i < npts; i++)
350  {
351  oldPts[i] = pts[i];
352  }
353 }
354 
355 //----------------------------------------------------------------------------
357  const vtkIdType size)
358 {
359  this->NumberOfCells = ncells;
360  this->InsertLocation = 0;
361  this->TraversalLocation = 0;
362  return this->Ia->WritePointer(0,size);
363 }
364 
365 #endif
vtkIdType GetMaxId()
vtkIdType * GetPointer()
Definition: vtkCellArray.h:185
vtkIdType GetInsertLocation(int npts)
Definition: vtkCellArray.h:153
abstract base class for most VTK objects
Definition: vtkObject.h:60
vtkIdType NumberOfCells
Definition: vtkCellArray.h:233
void InsertCellPoint(vtkIdType id)
Definition: vtkCellArray.h:272
#define VTK_FILTERING_EXPORT
vtkIdType InsertNextValue(vtkIdType f)
vtkIdType GetNumberOfIds()
Definition: vtkIdList.h:45
void InitTraversal()
Definition: vtkCellArray.h:91
vtkIdType GetValue(vtkIdType id)
vtkIdType InsertLocation
Definition: vtkCellArray.h:234
void ReplaceCell(vtkIdType loc, int npts, const vtkIdType *pts)
Definition: vtkCellArray.h:345
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:255
void InsertValue(vtkIdType id, vtkIdType f)
vtkIdTypeArray * Ia
Definition: vtkCellArray.h:236
void Squeeze()
Definition: vtkCellArray.h:217
virtual void PrintSelf(ostream &os, vtkIndent indent)
void SetTraversalLocation(vtkIdType loc)
Definition: vtkCellArray.h:161
vtkIdType GetTraversalLocation(vtkIdType npts)
Definition: vtkCellArray.h:168
a simple class to control print indentation
Definition: vtkIndent.h:37
vtkIdType GetNumberOfConnectivityEntries()
Definition: vtkCellArray.h:113
list of point or cell ids
Definition: vtkIdList.h:34
void SetValue(vtkIdType id, vtkIdType value)
vtkIdType * GetPointer(vtkIdType id)
vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell)
Definition: vtkCellArray.h:84
void ReverseCell(vtkIdType loc)
Definition: vtkCellArray.h:330
void UpdateCellCount(int npts)
Definition: vtkCellArray.h:278
vtkIdType TraversalLocation
Definition: vtkCellArray.h:235
vtkIdType InsertNextCell(vtkCell *cell)
Definition: vtkCellArray.h:290
vtkIdType * WritePointer(const vtkIdType ncells, const vtkIdType size)
Definition: vtkCellArray.h:356
object to represent cell connectivity
Definition: vtkCellArray.h:48
vtkIdType * WritePointer(vtkIdType id, vtkIdType number)
vtkIdTypeArray * GetData()
Definition: vtkCellArray.h:208
vtkIdType GetSize()
Definition: vtkCellArray.h:105
int GetNextCell(vtkIdType &npts, vtkIdType *&pts)
Definition: vtkCellArray.h:306
static vtkObject * New()
vtkIdType GetTraversalLocation()
Definition: vtkCellArray.h:159
vtkIdType * GetPointer(const vtkIdType i)
Definition: vtkIdList.h:72
int Allocate(const vtkIdType sz, const int ext=1000)
Definition: vtkCellArray.h:59
void GetCell(vtkIdType loc, vtkIdType &npts, vtkIdType *&pts)
Definition: vtkCellArray.h:322