VTK
vtkCellLinks.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkCellLinks.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 =========================================================================*/
27 #ifndef __vtkCellLinks_h
28 #define __vtkCellLinks_h
29 
30 #include "vtkObject.h"
31 class vtkDataSet;
32 class vtkCellArray;
33 
35 {
36 public:
37 
38  //BTX
39  class Link {
40  public:
41  unsigned short ncells;
43  };
44  //ETX
45 
46  static vtkCellLinks *New();
47  vtkTypeMacro(vtkCellLinks,vtkObject);
48  void PrintSelf(ostream& os, vtkIndent indent);
49 
52  void Allocate(vtkIdType numLinks, vtkIdType ext=1000);
53 
55  Link &GetLink(vtkIdType ptId) {return this->Array[ptId];};
56 
58  unsigned short GetNcells(vtkIdType ptId) { return this->Array[ptId].ncells;};
59 
61  void BuildLinks(vtkDataSet *data);
62 
64  void BuildLinks(vtkDataSet *data, vtkCellArray *Connectivity);
65 
67  vtkIdType *GetCells(vtkIdType ptId) {return this->Array[ptId].cells;};
68 
71  vtkIdType InsertNextPoint(int numLinks);
72 
76  void InsertNextCellReference(vtkIdType ptId, vtkIdType cellId);
77 
79  void DeletePoint(vtkIdType ptId);
80 
84  void RemoveCellReference(vtkIdType cellId, vtkIdType ptId);
85 
89  void AddCellReference(vtkIdType cellId, vtkIdType ptId);
90 
93  void ResizeCellList(vtkIdType ptId, int size);
94 
96  void Squeeze();
97 
99  void Reset();
100 
107  unsigned long GetActualMemorySize();
108 
111  void DeepCopy(vtkCellLinks *src);
112 
113 protected:
114  vtkCellLinks():Array(NULL),Size(0),MaxId(-1),Extend(1000) {};
115  ~vtkCellLinks();
116 
118  void IncrementLinkCount(vtkIdType ptId) { this->Array[ptId].ncells++;};
119 
120  void AllocateLinks(vtkIdType n);
121 
123 
124  void InsertCellReference(vtkIdType ptId, unsigned short pos,
125  vtkIdType cellId);
127 
128  Link *Array; // pointer to data
129  vtkIdType Size; // allocated size of data
130  vtkIdType MaxId; // maximum index inserted thus far
131  vtkIdType Extend; // grow array by this point
132  Link *Resize(vtkIdType sz); // function to resize data
133 private:
134  vtkCellLinks(const vtkCellLinks&); // Not implemented.
135  void operator=(const vtkCellLinks&); // Not implemented.
136 };
137 
138 //----------------------------------------------------------------------------
140  unsigned short pos,
141  vtkIdType cellId)
142 {
143  this->Array[ptId].cells[pos] = cellId;
144 }
145 
146 //----------------------------------------------------------------------------
148 {
149  this->Array[ptId].ncells = 0;
150  delete [] this->Array[ptId].cells;
151  this->Array[ptId].cells = NULL;
152 }
153 
154 //----------------------------------------------------------------------------
156  vtkIdType cellId)
157 {
158  this->Array[ptId].cells[this->Array[ptId].ncells++] = cellId;
159 }
160 
161 //----------------------------------------------------------------------------
163 {
164  vtkIdType *cells=this->Array[ptId].cells;
165  int ncells=this->Array[ptId].ncells;
166 
167  for (int i=0; i < ncells; i++)
168  {
169  if (cells[i] == cellId)
170  {
171  for (int j=i; j < (ncells-1); j++)
172  {
173  cells[j] = cells[j+1];
174  }
175  this->Array[ptId].ncells--;
176  break;
177  }
178  }
179 }
180 
181 //----------------------------------------------------------------------------
183 {
184  this->Array[ptId].cells[this->Array[ptId].ncells++] = cellId;
185 }
186 
187 //----------------------------------------------------------------------------
188 inline void vtkCellLinks::ResizeCellList(vtkIdType ptId, int size)
189 {
190  int newSize;
191  vtkIdType *cells;
192 
193  newSize = this->Array[ptId].ncells + size;
194  cells = new vtkIdType[newSize];
195  memcpy(cells, this->Array[ptId].cells,
196  this->Array[ptId].ncells*sizeof(vtkIdType));
197  delete [] this->Array[ptId].cells;
198  this->Array[ptId].cells = cells;
199 }
200 
201 #endif
202 
abstract base class for most VTK objects
Definition: vtkObject.h:60
#define VTK_FILTERING_EXPORT
abstract class to specify dataset behavior
Definition: vtkDataSet.h:58
int vtkIdType
Definition: vtkType.h:255
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:37
object to represent cell connectivity
Definition: vtkCellArray.h:48
static vtkObject * New()