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 "vtkCommonDataModelModule.h" // For export macro
44 #include "vtkObject.h"
45 
46 #include "vtkIdTypeArray.h" // Needed for inline methods
47 #include "vtkCell.h" // Needed for inline methods
48 
50 {
51 public:
52  vtkTypeMacro(vtkCellArray,vtkObject);
53  void PrintSelf(ostream& os, vtkIndent indent);
54 
56  static vtkCellArray *New();
57 
59 
60  int Allocate(const vtkIdType sz, const int ext=1000)
61  {return this->Ia->Allocate(sz,ext);}
63 
65  void Initialize();
66 
68 
69  vtkGetMacro(NumberOfCells, vtkIdType);
71 
73 
75  vtkSetMacro(NumberOfCells, vtkIdType);
77 
79 
85  vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell)
86  {return numCells*(1+maxPtsPerCell);}
88 
92  void InitTraversal() {this->TraversalLocation=0;};
93 
98  int GetNextCell(vtkIdType& npts, vtkIdType* &pts);
99 
103  int GetNextCell(vtkIdList *pts);
104 
106 
108  {return this->Ia->GetSize();}
110 
112 
116  {return this->Ia->GetMaxId()+1;}
118 
121  void GetCell(vtkIdType loc, vtkIdType &npts, vtkIdType* &pts);
122 
125  void GetCell(vtkIdType loc, vtkIdList* pts);
126 
128  vtkIdType InsertNextCell(vtkCell *cell);
129 
132  vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType* pts);
133 
136  vtkIdType InsertNextCell(vtkIdList *pts);
137 
142  vtkIdType InsertNextCell(int npts);
143 
146  void InsertCellPoint(vtkIdType id);
147 
150  void UpdateCellCount(int npts);
151 
153 
156  {return (this->InsertLocation - npts - 1);};
158 
160 
162  {return this->TraversalLocation;}
164  {this->TraversalLocation = loc;}
166 
168 
171  {return(this->TraversalLocation-npts-1);}
173 
176  void ReverseCell(vtkIdType loc);
177 
179  void ReplaceCell(vtkIdType loc, int npts, const vtkIdType *pts);
180 
183  int GetMaxCellSize();
184 
186 
188  {return this->Ia->GetPointer(0);}
190 
194  vtkIdType *WritePointer(const vtkIdType ncells, const vtkIdType size);
195 
203  void SetCells(vtkIdType ncells, vtkIdTypeArray *cells);
204 
206  void DeepCopy(vtkCellArray *ca);
207 
209 
211  {return this->Ia;}
213 
215  void Reset();
216 
218 
219  void Squeeze()
220  {this->Ia->Squeeze();}
222 
229  unsigned long GetActualMemorySize();
230 
231 protected:
232  vtkCellArray();
233  ~vtkCellArray();
234 
236  vtkIdType InsertLocation; //keep track of current insertion point
237  vtkIdType TraversalLocation; //keep track of traversal position
239 
240 private:
241  vtkCellArray(const vtkCellArray&); // Not implemented.
242  void operator=(const vtkCellArray&); // Not implemented.
243 };
244 
245 
246 //----------------------------------------------------------------------------
248  const vtkIdType* pts)
249 {
250  vtkIdType i = this->Ia->GetMaxId() + 1;
251  vtkIdType *ptr = this->Ia->WritePointer(i, npts+1);
252 
253  for ( *ptr++ = npts, i = 0; i < npts; i++)
254  {
255  *ptr++ = *pts++;
256  }
257 
258  this->NumberOfCells++;
259  this->InsertLocation += npts + 1;
260 
261  return this->NumberOfCells - 1;
262 }
263 
264 //----------------------------------------------------------------------------
266 {
267  this->InsertLocation = this->Ia->InsertNextValue(npts) + 1;
268  this->NumberOfCells++;
269 
270  return this->NumberOfCells - 1;
271 }
272 
273 //----------------------------------------------------------------------------
275 {
276  this->Ia->InsertValue(this->InsertLocation++, id);
277 }
278 
279 //----------------------------------------------------------------------------
280 inline void vtkCellArray::UpdateCellCount(int npts)
281 {
282  this->Ia->SetValue(this->InsertLocation-npts-1, npts);
283 }
284 
285 //----------------------------------------------------------------------------
287 {
288  return this->InsertNextCell(pts->GetNumberOfIds(), pts->GetPointer(0));
289 }
290 
291 //----------------------------------------------------------------------------
293 {
294  return this->InsertNextCell(cell->GetNumberOfPoints(),
295  cell->PointIds->GetPointer(0));
296 }
297 
298 //----------------------------------------------------------------------------
299 inline void vtkCellArray::Reset()
300 {
301  this->NumberOfCells = 0;
302  this->InsertLocation = 0;
303  this->TraversalLocation = 0;
304  this->Ia->Reset();
305 }
306 
307 //----------------------------------------------------------------------------
309 {
310  if ( this->Ia->GetMaxId() >= 0 &&
311  this->TraversalLocation <= this->Ia->GetMaxId() )
312  {
313  npts = this->Ia->GetValue(this->TraversalLocation++);
314  pts = this->Ia->GetPointer(this->TraversalLocation);
315  this->TraversalLocation += npts;
316  return 1;
317  }
318  npts=0;
319  pts=0;
320  return 0;
321 }
322 
323 //----------------------------------------------------------------------------
325  vtkIdType* &pts)
326 {
327  npts = this->Ia->GetValue(loc++);
328  pts = this->Ia->GetPointer(loc);
329 }
330 
331 //----------------------------------------------------------------------------
333 {
334  int i;
335  vtkIdType tmp;
336  vtkIdType npts=this->Ia->GetValue(loc);
337  vtkIdType *pts=this->Ia->GetPointer(loc+1);
338  for (i=0; i < (npts/2); i++)
339  {
340  tmp = pts[i];
341  pts[i] = pts[npts-i-1];
342  pts[npts-i-1] = tmp;
343  }
344 }
345 
346 //----------------------------------------------------------------------------
347 inline void vtkCellArray::ReplaceCell(vtkIdType loc, int npts,
348  const vtkIdType *pts)
349 {
350  vtkIdType *oldPts=this->Ia->GetPointer(loc+1);
351  for (int i=0; i < npts; i++)
352  {
353  oldPts[i] = pts[i];
354  }
355 }
356 
357 //----------------------------------------------------------------------------
359  const vtkIdType size)
360 {
361  this->NumberOfCells = ncells;
362  this->InsertLocation = 0;
363  this->TraversalLocation = 0;
364  return this->Ia->WritePointer(0,size);
365 }
366 
367 #endif
vtkIdType GetMaxId()
vtkIdType * GetPointer()
Definition: vtkCellArray.h:187
vtkIdList * PointIds
Definition: vtkCell.h:316
vtkIdType GetNumberOfPoints()
Definition: vtkCell.h:117
vtkIdType GetInsertLocation(int npts)
Definition: vtkCellArray.h:155
abstract base class for most VTK objects
Definition: vtkObject.h:61
vtkIdType NumberOfCells
Definition: vtkCellArray.h:235
void InsertCellPoint(vtkIdType id)
Definition: vtkCellArray.h:274
vtkIdType GetNumberOfIds()
Definition: vtkIdList.h:50
void DeepCopy(vtkPistonReference *self, vtkPistonReference *other)
void InitTraversal()
Definition: vtkCellArray.h:92
vtkIdType InsertLocation
Definition: vtkCellArray.h:236
void ReplaceCell(vtkIdType loc, int npts, const vtkIdType *pts)
Definition: vtkCellArray.h:347
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:275
vtkIdTypeArray * Ia
Definition: vtkCellArray.h:238
void Squeeze()
Definition: vtkCellArray.h:219
abstract class to specify cell behavior
Definition: vtkCell.h:61
virtual void PrintSelf(ostream &os, vtkIndent indent)
void SetTraversalLocation(vtkIdType loc)
Definition: vtkCellArray.h:163
vtkIdType GetTraversalLocation(vtkIdType npts)
Definition: vtkCellArray.h:170
a simple class to control print indentation
Definition: vtkIndent.h:38
vtkIdType GetNumberOfConnectivityEntries()
Definition: vtkCellArray.h:115
list of point or cell ids
Definition: vtkIdList.h:35
vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell)
Definition: vtkCellArray.h:85
void ReverseCell(vtkIdType loc)
Definition: vtkCellArray.h:332
void UpdateCellCount(int npts)
Definition: vtkCellArray.h:280
vtkIdType TraversalLocation
Definition: vtkCellArray.h:237
vtkIdType InsertNextCell(vtkCell *cell)
Definition: vtkCellArray.h:292
vtkIdType * WritePointer(const vtkIdType ncells, const vtkIdType size)
Definition: vtkCellArray.h:358
object to represent cell connectivity
Definition: vtkCellArray.h:49
vtkIdTypeArray * GetData()
Definition: vtkCellArray.h:210
vtkIdType GetSize()
Definition: vtkCellArray.h:107
int GetNextCell(vtkIdType &npts, vtkIdType *&pts)
Definition: vtkCellArray.h:308
static vtkObject * New()
vtkIdType GetTraversalLocation()
Definition: vtkCellArray.h:161
#define VTKCOMMONDATAMODEL_EXPORT
vtkIdType * GetPointer(const vtkIdType i)
Definition: vtkIdList.h:77
int Allocate(const vtkIdType sz, const int ext=1000)
Definition: vtkCellArray.h:60
void GetCell(vtkIdType loc, vtkIdType &npts, vtkIdType *&pts)
Definition: vtkCellArray.h:324