VTK  9.2.5
vtkCellTypes.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkCellTypes.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 =========================================================================*/
131 #ifndef vtkCellTypes_h
132 #define vtkCellTypes_h
133 
134 #include "vtkCommonDataModelModule.h" // For export macro
135 #include "vtkObject.h"
136 
137 #include "vtkCellType.h" // Needed for inline methods
138 #include "vtkDeprecation.h" // Needed for deprecation
139 #include "vtkIdTypeArray.h" // Needed for inline methods
140 #include "vtkSmartPointer.h" // Needed for internals
141 #include "vtkUnsignedCharArray.h" // Needed for inline methods
142 
143 class vtkIntArray;
144 
145 class VTKCOMMONDATAMODEL_EXPORT vtkCellTypes : public vtkObject
146 {
147 public:
148  static vtkCellTypes* New();
149  vtkTypeMacro(vtkCellTypes, vtkObject);
150  void PrintSelf(ostream& os, vtkIndent indent) override;
151 
155  int Allocate(vtkIdType sz = 512, vtkIdType ext = 1000);
156 
160  void InsertCell(vtkIdType id, unsigned char type, vtkIdType loc);
161 
165  vtkIdType InsertNextCell(unsigned char type, vtkIdType loc);
166 
172  VTK_DEPRECATED_IN_9_2_0("Please use version without cellLocations.")
173  void SetCellTypes(
174  vtkIdType ncells, vtkUnsignedCharArray* cellTypes, vtkIdTypeArray* cellLocations);
175 
179  void SetCellTypes(vtkIdType ncells, vtkUnsignedCharArray* cellTypes);
180 
181  VTK_DEPRECATED_IN_9_2_0("Please use version without cellLocations.")
182  void SetCellTypes(vtkIdType ncells, vtkUnsignedCharArray* cellTypes, vtkIntArray* cellLocations);
183 
190  VTK_DEPRECATED_IN_9_2_0("The Location API will disappear.")
191  vtkIdType GetCellLocation(vtkIdType cellId) { return this->LocationArray->GetValue(cellId); }
192 
196  void DeleteCell(vtkIdType cellId) { this->TypeArray->SetValue(cellId, VTK_EMPTY_CELL); }
197 
201  vtkIdType GetNumberOfTypes() { return (this->MaxId + 1); }
202 
206  int IsType(unsigned char type);
207 
211  vtkIdType InsertNextType(unsigned char type) { return this->InsertNextCell(type, -1); }
212 
216  unsigned char GetCellType(vtkIdType cellId) { return this->TypeArray->GetValue(cellId); }
217 
221  void Squeeze();
222 
226  void Reset();
227 
236  unsigned long GetActualMemorySize();
237 
242  void DeepCopy(vtkCellTypes* src);
243 
248  static const char* GetClassNameFromTypeId(int typeId);
249 
254  static int GetTypeIdFromClassName(const char* classname);
255 
262  static int IsLinear(unsigned char type);
263 
267  static int GetDimension(unsigned char type);
268 
270 
273  vtkUnsignedCharArray* GetCellTypesArray() { return this->TypeArray; }
274  vtkIdTypeArray* GetCellLocationsArray() { return this->LocationArray; }
276 
277 protected:
279  ~vtkCellTypes() override = default;
280 
282 
283  // DEPRECATION_IN_9_2_0 Note for whoever is in deprecation duties:
284  // The attribute LocationArray needs to be deleted, and any code in this class that would fail
285  // compiling because of its removal deleted as well.
286  vtkSmartPointer<vtkIdTypeArray> LocationArray; // pointer to array of offsets
287 
288  vtkIdType MaxId; // maximum index inserted thus far
289 
290 private:
291  vtkCellTypes(const vtkCellTypes&) = delete;
292  void operator=(const vtkCellTypes&) = delete;
293 };
294 
295 //----------------------------------------------------------------------------
296 inline int vtkCellTypes::IsType(unsigned char type)
297 {
298  vtkIdType numTypes = this->GetNumberOfTypes();
299 
300  for (vtkIdType i = 0; i < numTypes; i++)
301  {
302  if (type == this->GetCellType(i))
303  {
304  return 1;
305  }
306  }
307  return 0;
308 }
309 
310 //-----------------------------------------------------------------------------
311 inline int vtkCellTypes::IsLinear(unsigned char type)
312 {
313  return ((type <= 20) || (type == VTK_CONVEX_POINT_SET) || (type == VTK_POLYHEDRON));
314 }
315 
316 #endif
object provides direct access to cells in vtkCellArray and type information
Definition: vtkCellTypes.h:146
vtkIdType InsertNextCell(unsigned char type, vtkIdType loc)
Add a cell to the object in the next available slot.
static const char * GetClassNameFromTypeId(int typeId)
Given an int (as defined in vtkCellType.h) identifier for a class return it's classname.
int Allocate(vtkIdType sz=512, vtkIdType ext=1000)
Allocate memory for this array.
void InsertCell(vtkIdType id, unsigned char type, vtkIdType loc)
Add a cell at specified id.
vtkIdType MaxId
Definition: vtkCellTypes.h:288
vtkUnsignedCharArray * GetCellTypesArray()
Methods for obtaining the arrays representing types and locations.
Definition: vtkCellTypes.h:273
void Squeeze()
Reclaim any extra memory.
void Reset()
Initialize object without releasing memory.
vtkIdType InsertNextType(unsigned char type)
Add the type specified to the end of the list.
Definition: vtkCellTypes.h:211
~vtkCellTypes() override=default
vtkSmartPointer< vtkIdTypeArray > LocationArray
Definition: vtkCellTypes.h:286
static int IsLinear(unsigned char type)
This convenience method is a fast check to determine if a cell type represents a linear or nonlinear ...
Definition: vtkCellTypes.h:311
unsigned long GetActualMemorySize()
Return the memory in kibibytes (1024 bytes) consumed by this cell type array.
static vtkCellTypes * New()
vtkIdType GetNumberOfTypes()
Return the number of types in the list.
Definition: vtkCellTypes.h:201
vtkSmartPointer< vtkUnsignedCharArray > TypeArray
Definition: vtkCellTypes.h:281
void DeleteCell(vtkIdType cellId)
Delete cell by setting to nullptr cell type.
Definition: vtkCellTypes.h:196
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkIdTypeArray * GetCellLocationsArray()
Methods for obtaining the arrays representing types and locations.
Definition: vtkCellTypes.h:274
static int GetDimension(unsigned char type)
Get the dimension of a cell.
int IsType(unsigned char type)
Return 1 if type specified is contained in list; 0 otherwise.
Definition: vtkCellTypes.h:296
unsigned char GetCellType(vtkIdType cellId)
Return the type of cell.
Definition: vtkCellTypes.h:216
void DeepCopy(vtkCellTypes *src)
Standard DeepCopy method.
static int GetTypeIdFromClassName(const char *classname)
Given a data object classname, return it's int identified (as defined in vtkCellType....
dynamic, self-adjusting array of vtkIdType
a simple class to control print indentation
Definition: vtkIndent.h:119
dynamic, self-adjusting array of int
Definition: vtkIntArray.h:155
abstract base class for most VTK objects
Definition: vtkObject.h:82
dynamic, self-adjusting array of unsigned char
@ type
Definition: vtkX3D.h:522
@ version
Definition: vtkX3D.h:532
@ VTK_EMPTY_CELL
Definition: vtkCellType.h:85
@ VTK_POLYHEDRON
Definition: vtkCellType.h:128
@ VTK_CONVEX_POINT_SET
Definition: vtkCellType.h:125
#define VTK_DEPRECATED_IN_9_2_0(reason)
int vtkIdType
Definition: vtkType.h:332