VTK  9.0.1
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 =========================================================================*/
36 #ifndef vtkCellLinks_h
37 #define vtkCellLinks_h
38 
39 #include "vtkAbstractCellLinks.h"
40 #include "vtkCommonDataModelModule.h" // For export macro
41 
42 class vtkDataSet;
43 class vtkCellArray;
44 
45 class VTKCOMMONDATAMODEL_EXPORT vtkCellLinks : public vtkAbstractCellLinks
46 {
47 public:
48  class Link
49  {
50  public:
53  };
54 
56 
59  static vtkCellLinks* New();
61  void PrintSelf(ostream& os, vtkIndent indent) override;
63 
68  void BuildLinks(vtkDataSet* data) override;
69 
74  void Allocate(vtkIdType numLinks, vtkIdType ext = 1000);
75 
79  void Initialize() override;
80 
84  Link& GetLink(vtkIdType ptId) { return this->Array[ptId]; }
85 
89  vtkIdType GetNcells(vtkIdType ptId) { return this->Array[ptId].ncells; }
90 
94  vtkIdType* GetCells(vtkIdType ptId) { return this->Array[ptId].cells; }
95 
100  vtkIdType InsertNextPoint(int numLinks);
101 
107  void InsertNextCellReference(vtkIdType ptId, vtkIdType cellId);
108 
112  void DeletePoint(vtkIdType ptId);
113 
119  void RemoveCellReference(vtkIdType cellId, vtkIdType ptId);
120 
126  void AddCellReference(vtkIdType cellId, vtkIdType ptId);
127 
132  void ResizeCellList(vtkIdType ptId, int size);
133 
137  void Squeeze() override;
138 
142  void Reset() override;
143 
152  unsigned long GetActualMemorySize() override;
153 
158  void DeepCopy(vtkAbstractCellLinks* src) override;
159 
160 protected:
162  : Array(nullptr)
163  , Size(0)
164  , MaxId(-1)
165  , Extend(1000)
166  {
167  }
168  ~vtkCellLinks() override;
169 
173  void IncrementLinkCount(vtkIdType ptId) { this->Array[ptId].ncells++; }
174 
175  void AllocateLinks(vtkIdType n);
176 
180  void InsertCellReference(vtkIdType ptId, vtkIdType pos, vtkIdType cellId);
181 
182  Link* Array; // pointer to data
183  vtkIdType Size; // allocated size of data
184  vtkIdType MaxId; // maximum index inserted thus far
185  vtkIdType Extend; // grow array by this point
186  Link* Resize(vtkIdType sz); // function to resize data
187 
188 private:
189  vtkCellLinks(const vtkCellLinks&) = delete;
190  void operator=(const vtkCellLinks&) = delete;
191 };
192 
193 //----------------------------------------------------------------------------
195 {
196  this->Array[ptId].cells[pos] = cellId;
197 }
198 
199 //----------------------------------------------------------------------------
201 {
202  this->Array[ptId].ncells = 0;
203  delete[] this->Array[ptId].cells;
204  this->Array[ptId].cells = nullptr;
205 }
206 
207 //----------------------------------------------------------------------------
209 {
210  this->Array[ptId].cells[this->Array[ptId].ncells++] = cellId;
211 }
212 
213 //----------------------------------------------------------------------------
215 {
216  vtkIdType* cells = this->Array[ptId].cells;
217  vtkIdType ncells = this->Array[ptId].ncells;
218 
219  for (vtkIdType i = 0; i < ncells; i++)
220  {
221  if (cells[i] == cellId)
222  {
223  for (vtkIdType j = i; j < (ncells - 1); j++)
224  {
225  cells[j] = cells[j + 1];
226  }
227  this->Array[ptId].ncells--;
228  break;
229  }
230  }
231 }
232 
233 //----------------------------------------------------------------------------
235 {
236  this->Array[ptId].cells[this->Array[ptId].ncells++] = cellId;
237 }
238 
239 //----------------------------------------------------------------------------
241 {
242  vtkIdType newSize = this->Array[ptId].ncells + size;
243  vtkIdType* cells = new vtkIdType[newSize];
244  memcpy(cells, this->Array[ptId].cells,
245  static_cast<size_t>(this->Array[ptId].ncells) * sizeof(vtkIdType));
246  delete[] this->Array[ptId].cells;
247  this->Array[ptId].cells = cells;
248 }
249 
250 #endif
abstract class to specify dataset behavior
Definition: vtkDataSet.h:56
int vtkIdType
Definition: vtkType.h:338
a simple class to control print indentation
Definition: vtkIndent.h:33
object to represent cell connectivity
Definition: vtkCellArray.h:179
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...