VTK  9.4.20241108
vtkCellLinks.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
24#ifndef vtkCellLinks_h
25#define vtkCellLinks_h
26
28#include "vtkCommonDataModelModule.h" // For export macro
29
30#include <memory> // For shared_ptr
31
32VTK_ABI_NAMESPACE_BEGIN
33class vtkDataSet;
34class vtkCellArray;
35
36class VTKCOMMONDATAMODEL_EXPORT vtkCellLinks : public vtkAbstractCellLinks
37{
38public:
39 class Link
40 {
41 public:
43 : ncells(0)
44 , cells(nullptr)
45 {
46 }
47 ~Link() = default;
50 };
51
53
56 static vtkCellLinks* New();
58 void PrintSelf(ostream& os, vtkIndent indent) override;
60
64 void BuildLinks() override;
65
70 void Allocate(vtkIdType numLinks, vtkIdType ext = 1000);
71
75 void Initialize() override;
76
80 Link& GetLink(vtkIdType ptId) { return this->Array[ptId]; }
81
85 vtkIdType GetNcells(vtkIdType ptId) { return this->Array[ptId].ncells; }
86
90 vtkIdType* GetCells(vtkIdType ptId) { return this->Array[ptId].cells; }
91
93
100 void SelectCells(vtkIdType minMaxDegree[2], unsigned char* cellSelection) override;
102
108
114 void InsertNextCellReference(vtkIdType ptId, vtkIdType cellId);
115
119 void DeletePoint(vtkIdType ptId);
120
126 void RemoveCellReference(vtkIdType cellId, vtkIdType ptId);
127
133 void AddCellReference(vtkIdType cellId, vtkIdType ptId);
134
139 void ResizeCellList(vtkIdType ptId, int size);
140
144 void Squeeze() override;
145
149 void Reset() override;
150
159 unsigned long GetActualMemorySize() override;
160
166 void DeepCopy(vtkAbstractCellLinks* src) override;
167
174
175protected:
177 ~vtkCellLinks() override;
178
182 void IncrementLinkCount(vtkIdType ptId) { this->Array[ptId].ncells++; }
183
185
189 void InsertCellReference(vtkIdType ptId, vtkIdType pos, vtkIdType cellId);
190
191 std::shared_ptr<Link> ArraySharedPtr; // Shared Ptr to Array
192 Link* Array; // pointer to data
193 vtkIdType Size; // allocated size of data
194 vtkIdType MaxId; // maximum index inserted thus far
195 vtkIdType Extend; // grow array by this point
196 Link* Resize(vtkIdType sz); // function to resize data
197
198 // Some information recorded at build time
201
202private:
203 vtkCellLinks(const vtkCellLinks&) = delete;
204 void operator=(const vtkCellLinks&) = delete;
205};
206
207//----------------------------------------------------------------------------
209{
210 this->Array[ptId].cells[pos] = cellId;
211}
212
213//----------------------------------------------------------------------------
215{
216 this->Array[ptId].ncells = 0;
217 delete[] this->Array[ptId].cells;
218 this->Array[ptId].cells = nullptr;
219}
220
221//----------------------------------------------------------------------------
223{
224 this->Array[ptId].cells[this->Array[ptId].ncells++] = cellId;
225}
226
227//----------------------------------------------------------------------------
229{
230 vtkIdType* cells = this->Array[ptId].cells;
231 vtkIdType ncells = this->Array[ptId].ncells;
232
233 for (vtkIdType i = 0; i < ncells; i++)
234 {
235 if (cells[i] == cellId)
236 {
237 for (vtkIdType j = i; j < (ncells - 1); j++)
238 {
239 cells[j] = cells[j + 1];
240 }
241 this->Array[ptId].ncells--;
242 break;
243 }
244 }
245}
246
247//----------------------------------------------------------------------------
249{
250 this->Array[ptId].cells[this->Array[ptId].ncells++] = cellId;
251}
252
253//----------------------------------------------------------------------------
254inline void vtkCellLinks::ResizeCellList(vtkIdType ptId, int size)
255{
256 vtkIdType newSize = this->Array[ptId].ncells + size;
257 vtkIdType* cells = new vtkIdType[newSize];
258 memcpy(cells, this->Array[ptId].cells,
259 static_cast<size_t>(this->Array[ptId].ncells) * sizeof(vtkIdType));
260 delete[] this->Array[ptId].cells;
261 this->Array[ptId].cells = cells;
262}
263
264VTK_ABI_NAMESPACE_END
265#endif
object to represent cell connectivity
abstract class to specify dataset behavior
Definition vtkDataSet.h:166
a simple class to control print indentation
Definition vtkIndent.h:108
int vtkIdType
Definition vtkType.h:315