VTK  9.3.20240521
vtkType.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
3#ifndef vtkType_h
4#define vtkType_h
5
6#include "vtkABINamespace.h"
7#include "vtkCompiler.h" // for VTK_USE_EXTERN_TEMPLATE
8#include "vtkOptions.h" // for VTK_USE_64BIT_IDS, VTK_USE_64BIT_TIMESTAMPS, VTK_USE_FUTURE_BOOL
9#include "vtk_kwiml.h"
10
11#define VTK_SIZEOF_CHAR KWIML_ABI_SIZEOF_CHAR
12#define VTK_SIZEOF_SHORT KWIML_ABI_SIZEOF_SHORT
13#define VTK_SIZEOF_INT KWIML_ABI_SIZEOF_INT
14#define VTK_SIZEOF_LONG KWIML_ABI_SIZEOF_LONG
15#define VTK_SIZEOF_LONG_LONG KWIML_ABI_SIZEOF_LONG_LONG
16#define VTK_SIZEOF_FLOAT KWIML_ABI_SIZEOF_FLOAT
17#define VTK_SIZEOF_DOUBLE KWIML_ABI_SIZEOF_DOUBLE
18#define VTK_SIZEOF_VOID_P KWIML_ABI_SIZEOF_DATA_PTR
19
20/* Whether type "char" is signed (it may be signed or unsigned). */
21#if defined(KWIML_ABI_CHAR_IS_SIGNED)
22#define VTK_TYPE_CHAR_IS_SIGNED 1
23#else
24#define VTK_TYPE_CHAR_IS_SIGNED 0
25#endif
26
27/*--------------------------------------------------------------------------*/
28/* Define a unique integer identifier for each native scalar type. */
29
30/* These types are returned by GetDataType to indicate pixel type. */
31#define VTK_VOID 0
32#define VTK_BIT 1
33#define VTK_CHAR 2
34#define VTK_SIGNED_CHAR 15
35#define VTK_UNSIGNED_CHAR 3
36#define VTK_SHORT 4
37#define VTK_UNSIGNED_SHORT 5
38#define VTK_INT 6
39#define VTK_UNSIGNED_INT 7
40#define VTK_LONG 8
41#define VTK_UNSIGNED_LONG 9
42#define VTK_FLOAT 10
43#define VTK_DOUBLE 11
44#define VTK_ID_TYPE 12
45
46/* These types are not currently supported by GetDataType, but are for
47 completeness. */
48#define VTK_STRING 13
49#define VTK_OPAQUE 14
50
51#define VTK_LONG_LONG 16
52#define VTK_UNSIGNED_LONG_LONG 17
53
54/* These types are required by vtkVariant and vtkVariantArray */
55#define VTK_VARIANT 20
56#define VTK_OBJECT 21
57
58// deleted value
59// #define VTK_UNICODE_STRING 22 <==== do not use
60
61/*--------------------------------------------------------------------------*/
62/* Define a unique integer identifier for each vtkDataObject type. */
63/* When adding a new data type here, make sure to update */
64/* vtkDataObjectTypes as well. */
65#define VTK_POLY_DATA 0
66#define VTK_STRUCTURED_POINTS 1
67#define VTK_STRUCTURED_GRID 2
68#define VTK_RECTILINEAR_GRID 3
69#define VTK_UNSTRUCTURED_GRID 4
70#define VTK_PIECEWISE_FUNCTION 5
71#define VTK_IMAGE_DATA 6
72#define VTK_DATA_OBJECT 7
73#define VTK_DATA_SET 8
74#define VTK_POINT_SET 9
75#define VTK_UNIFORM_GRID 10
76#define VTK_COMPOSITE_DATA_SET 11
77#define VTK_MULTIGROUP_DATA_SET 12
78#define VTK_MULTIBLOCK_DATA_SET 13
79#define VTK_HIERARCHICAL_DATA_SET 14
80#define VTK_HIERARCHICAL_BOX_DATA_SET 15
81#define VTK_GENERIC_DATA_SET 16
82#define VTK_HYPER_OCTREE 17
83#define VTK_TEMPORAL_DATA_SET 18
84#define VTK_TABLE 19
85#define VTK_GRAPH 20
86#define VTK_TREE 21
87#define VTK_SELECTION 22
88#define VTK_DIRECTED_GRAPH 23
89#define VTK_UNDIRECTED_GRAPH 24
90#define VTK_MULTIPIECE_DATA_SET 25
91#define VTK_DIRECTED_ACYCLIC_GRAPH 26
92#define VTK_ARRAY_DATA 27
93#define VTK_REEB_GRAPH 28
94#define VTK_UNIFORM_GRID_AMR 29
95#define VTK_NON_OVERLAPPING_AMR 30
96#define VTK_OVERLAPPING_AMR 31
97#define VTK_HYPER_TREE_GRID 32
98#define VTK_MOLECULE 33
99#define VTK_PISTON_DATA_OBJECT 34
100#define VTK_PATH 35
101#define VTK_UNSTRUCTURED_GRID_BASE 36
102#define VTK_PARTITIONED_DATA_SET 37
103#define VTK_PARTITIONED_DATA_SET_COLLECTION 38
104#define VTK_UNIFORM_HYPER_TREE_GRID 39
105#define VTK_EXPLICIT_STRUCTURED_GRID 40
106#define VTK_DATA_OBJECT_TREE 41
107#define VTK_ABSTRACT_ELECTRONIC_DATA 42
108#define VTK_OPEN_QUBE_ELECTRONIC_DATA 43
109#define VTK_ANNOTATION 44
110#define VTK_ANNOTATION_LAYERS 45
111#define VTK_BSP_CUTS 46
112#define VTK_GEO_JSON_FEATURE 47
113#define VTK_IMAGE_STENCIL_DATA 48
114#define VTK_CELL_GRID 49
115
116/*--------------------------------------------------------------------------*/
117/* Define a casting macro for use by the constants below. */
118#if defined(__cplusplus)
119#define VTK_TYPE_CAST(T, V) static_cast<T>(V)
120#else
121#define VTK_TYPE_CAST(T, V) ((T)(V))
122#endif
123
124/*--------------------------------------------------------------------------*/
125/* Define min/max constants for each type. */
126#define VTK_BIT_MIN 0
127#define VTK_BIT_MAX 1
128#if VTK_TYPE_CHAR_IS_SIGNED
129#define VTK_CHAR_MIN VTK_TYPE_CAST(char, 0x80)
130#define VTK_CHAR_MAX VTK_TYPE_CAST(char, 0x7f)
131#else
132#define VTK_CHAR_MIN VTK_TYPE_CAST(char, 0u)
133#define VTK_CHAR_MAX VTK_TYPE_CAST(char, 0xffu)
134#endif
135#define VTK_SIGNED_CHAR_MIN VTK_TYPE_CAST(signed char, 0x80)
136#define VTK_SIGNED_CHAR_MAX VTK_TYPE_CAST(signed char, 0x7f)
137#define VTK_UNSIGNED_CHAR_MIN VTK_TYPE_CAST(unsigned char, 0u)
138#define VTK_UNSIGNED_CHAR_MAX VTK_TYPE_CAST(unsigned char, 0xffu)
139#define VTK_SHORT_MIN VTK_TYPE_CAST(short, 0x8000)
140#define VTK_SHORT_MAX VTK_TYPE_CAST(short, 0x7fff)
141#define VTK_UNSIGNED_SHORT_MIN VTK_TYPE_CAST(unsigned short, 0u)
142#define VTK_UNSIGNED_SHORT_MAX VTK_TYPE_CAST(unsigned short, 0xffffu)
143#define VTK_INT_MIN VTK_TYPE_CAST(int, ~(~0u >> 1))
144#define VTK_INT_MAX VTK_TYPE_CAST(int, ~0u >> 1)
145#define VTK_UNSIGNED_INT_MIN VTK_TYPE_CAST(unsigned int, 0)
146#define VTK_UNSIGNED_INT_MAX VTK_TYPE_CAST(unsigned int, ~0u)
147#define VTK_LONG_MIN VTK_TYPE_CAST(long, ~(~0ul >> 1))
148#define VTK_LONG_MAX VTK_TYPE_CAST(long, ~0ul >> 1)
149#define VTK_UNSIGNED_LONG_MIN VTK_TYPE_CAST(unsigned long, 0ul)
150#define VTK_UNSIGNED_LONG_MAX VTK_TYPE_CAST(unsigned long, ~0ul)
151#define VTK_FLOAT_MIN VTK_TYPE_CAST(float, -1.0e+38f)
152#define VTK_FLOAT_MAX VTK_TYPE_CAST(float, 1.0e+38f)
153#define VTK_DOUBLE_MIN VTK_TYPE_CAST(double, -1.0e+299)
154#define VTK_DOUBLE_MAX VTK_TYPE_CAST(double, 1.0e+299)
155#define VTK_LONG_LONG_MIN VTK_TYPE_CAST(long long, ~(~0ull >> 1))
156#define VTK_LONG_LONG_MAX VTK_TYPE_CAST(long long, ~0ull >> 1)
157#define VTK_UNSIGNED_LONG_LONG_MIN VTK_TYPE_CAST(unsigned long long, 0ull)
158#define VTK_UNSIGNED_LONG_LONG_MAX VTK_TYPE_CAST(unsigned long long, ~0ull)
159
160/*--------------------------------------------------------------------------*/
161/* Define named types and constants corresponding to specific integer
162 and floating-point sizes and signedness. */
163
164/* Select an 8-bit integer type. */
165#if VTK_SIZEOF_CHAR == 1
166typedef unsigned char vtkTypeUInt8;
167typedef signed char vtkTypeInt8;
168#define VTK_TYPE_UINT8 VTK_UNSIGNED_CHAR
169#define VTK_TYPE_UINT8_MIN VTK_UNSIGNED_CHAR_MIN
170#define VTK_TYPE_UINT8_MAX VTK_UNSIGNED_CHAR_MAX
171#define VTK_TYPE_INT8 VTK_SIGNED_CHAR
172#define VTK_TYPE_INT8_MIN VTK_SIGNED_CHAR_MIN
173#define VTK_TYPE_INT8_MAX VTK_SIGNED_CHAR_MAX
174#else
175#error "No native data type can represent an 8-bit integer."
176#endif
177
178/* Select a 16-bit integer type. */
179#if VTK_SIZEOF_SHORT == 2
180typedef unsigned short vtkTypeUInt16;
181typedef signed short vtkTypeInt16;
182#define VTK_TYPE_UINT16 VTK_UNSIGNED_SHORT
183#define VTK_TYPE_UINT16_MIN VTK_UNSIGNED_SHORT_MIN
184#define VTK_TYPE_UINT16_MAX VTK_UNSIGNED_SHORT_MAX
185#define VTK_TYPE_INT16 VTK_SHORT
186#define VTK_TYPE_INT16_MIN VTK_SHORT_MIN
187#define VTK_TYPE_INT16_MAX VTK_SHORT_MAX
188#elif VTK_SIZEOF_INT == 2
189typedef unsigned int vtkTypeUInt16;
190typedef signed int vtkTypeInt16;
191#define VTK_TYPE_UINT16 VTK_UNSIGNED_INT
192#define VTK_TYPE_UINT16_MIN VTK_UNSIGNED_INT_MIN
193#define VTK_TYPE_UINT16_MAX VTK_UNSIGNED_INT_MAX
194#define VTK_TYPE_INT16 VTK_INT
195#define VTK_TYPE_INT16_MIN VTK_INT_MIN
196#define VTK_TYPE_INT16_MAX VTK_INT_MAX
197#else
198#error "No native data type can represent a 16-bit integer."
199#endif
200
201/* Select a 32-bit integer type. */
202#if VTK_SIZEOF_INT == 4
203typedef unsigned int vtkTypeUInt32;
204typedef signed int vtkTypeInt32;
205#define VTK_TYPE_UINT32 VTK_UNSIGNED_INT
206#define VTK_TYPE_UINT32_MIN VTK_UNSIGNED_INT_MIN
207#define VTK_TYPE_UINT32_MAX VTK_UNSIGNED_INT_MAX
208#define VTK_TYPE_INT32 VTK_INT
209#define VTK_TYPE_INT32_MIN VTK_INT_MIN
210#define VTK_TYPE_INT32_MAX VTK_INT_MAX
211#elif VTK_SIZEOF_LONG == 4
212typedef unsigned long vtkTypeUInt32;
213typedef signed long vtkTypeInt32;
214#define VTK_TYPE_UINT32 VTK_UNSIGNED_LONG
215#define VTK_TYPE_UINT32_MIN VTK_UNSIGNED_LONG_MIN
216#define VTK_TYPE_UINT32_MAX VTK_UNSIGNED_LONG_MAX
217#define VTK_TYPE_INT32 VTK_LONG
218#define VTK_TYPE_INT32_MIN VTK_LONG_MIN
219#define VTK_TYPE_INT32_MAX VTK_LONG_MAX
220#else
221#error "No native data type can represent a 32-bit integer."
222#endif
223
224/* Select a 64-bit integer type. */
225#if VTK_SIZEOF_LONG_LONG == 8
226typedef unsigned long long vtkTypeUInt64;
227typedef signed long long vtkTypeInt64;
228#define VTK_TYPE_UINT64 VTK_UNSIGNED_LONG_LONG
229#define VTK_TYPE_UINT64_MIN VTK_UNSIGNED_LONG_LONG_MIN
230#define VTK_TYPE_UINT64_MAX VTK_UNSIGNED_LONG_LONG_MAX
231#define VTK_TYPE_INT64 VTK_LONG_LONG
232#define VTK_TYPE_INT64_MIN VTK_LONG_LONG_MIN
233#define VTK_TYPE_INT64_MAX VTK_LONG_LONG_MAX
234#elif VTK_SIZEOF_LONG == 8
235typedef unsigned long vtkTypeUInt64;
236typedef signed long vtkTypeInt64;
237#define VTK_TYPE_UINT64 VTK_UNSIGNED_LONG
238#define VTK_TYPE_UINT64_MIN VTK_UNSIGNED_LONG_MIN
239#define VTK_TYPE_UINT64_MAX VTK_UNSIGNED_LONG_MAX
240#define VTK_TYPE_INT64 VTK_LONG
241#define VTK_TYPE_INT64_MIN VTK_LONG_MIN
242#define VTK_TYPE_INT64_MAX VTK_LONG_MAX
243#else
244#error "No native data type can represent a 64-bit integer."
245#endif
246
247// If this is a 64-bit platform, or the user has indicated that 64-bit
248// timestamps should be used, select an unsigned 64-bit integer type
249// for use in MTime values. If possible, use 'unsigned long' as we have
250// historically.
251#if defined(VTK_USE_64BIT_TIMESTAMPS) || VTK_SIZEOF_VOID_P == 8
252#if VTK_SIZEOF_LONG == 8
253typedef unsigned long vtkMTimeType;
254#define VTK_MTIME_TYPE_IMPL VTK_UNSIGNED_LONG
255#define VTK_MTIME_MIN VTK_UNSIGNED_LONG_MIN
256#define VTK_MTIME_MAX VTK_UNSIGNED_LONG_MAX
257#else
258typedef vtkTypeUInt64 vtkMTimeType;
259#define VTK_MTIME_TYPE_IMPL VTK_TYPE_UINT64
260#define VTK_MTIME_MIN VTK_TYPE_UINT64_MIN
261#define VTK_MTIME_MAX VTK_TYPE_UINT64_MAX
262#endif
263#else
264#if VTK_SIZEOF_LONG == 4
265typedef unsigned long vtkMTimeType;
266#define VTK_MTIME_TYPE_IMPL VTK_UNSIGNED_LONG
267#define VTK_MTIME_MIN VTK_UNSIGNED_LONG_MIN
268#define VTK_MTIME_MAX VTK_UNSIGNED_LONG_MAX
269#else
270typedef vtkTypeUInt32 vtkMTimeType;
271#define VTK_MTIME_TYPE_IMPL VTK_TYPE_UINT32
272#define VTK_MTIME_MIN VTK_TYPE_UINT32_MIN
273#define VTK_MTIME_MAX VTK_TYPE_UINT32_MAX
274#endif
275#endif
276
277/* Select a 32-bit floating point type. */
278#if VTK_SIZEOF_FLOAT == 4
279typedef float vtkTypeFloat32;
280#define VTK_TYPE_FLOAT32 VTK_FLOAT
281#else
282#error "No native data type can represent a 32-bit floating point value."
283#endif
284
285/* Select a 64-bit floating point type. */
286#if VTK_SIZEOF_DOUBLE == 8
287typedef double vtkTypeFloat64;
288#define VTK_TYPE_FLOAT64 VTK_DOUBLE
289#else
290#error "No native data type can represent a 64-bit floating point value."
291#endif
292
293/*--------------------------------------------------------------------------*/
294/* Choose an implementation for vtkIdType. */
295#define VTK_HAS_ID_TYPE
296#ifdef VTK_USE_64BIT_IDS
297#if VTK_SIZEOF_LONG_LONG == 8
298typedef long long vtkIdType;
299#define VTK_ID_TYPE_IMPL VTK_LONG_LONG
300#define VTK_SIZEOF_ID_TYPE VTK_SIZEOF_LONG_LONG
301#define VTK_ID_MIN VTK_LONG_LONG_MIN
302#define VTK_ID_MAX VTK_LONG_LONG_MAX
303#define VTK_ID_TYPE_PRId "lld"
304#elif VTK_SIZEOF_LONG == 8
305typedef long vtkIdType;
306#define VTK_ID_TYPE_IMPL VTK_LONG
307#define VTK_SIZEOF_ID_TYPE VTK_SIZEOF_LONG
308#define VTK_ID_MIN VTK_LONG_MIN
309#define VTK_ID_MAX VTK_LONG_MAX
310#define VTK_ID_TYPE_PRId "ld"
311#else
312#error "VTK_USE_64BIT_IDS is ON but no 64-bit integer type is available."
313#endif
314#else
315typedef int vtkIdType;
316#define VTK_ID_TYPE_IMPL VTK_INT
317#define VTK_SIZEOF_ID_TYPE VTK_SIZEOF_INT
318#define VTK_ID_MIN VTK_INT_MIN
319#define VTK_ID_MAX VTK_INT_MAX
320#define VTK_ID_TYPE_PRId "d"
321#endif
322
323#ifndef __cplusplus
324// Make sure that when VTK headers are used by the C compiler we make
325// sure to define the bool type. This is possible when using IO features
326// like vtkXMLWriterC.h
327#include "stdbool.h"
328#endif
329
330/*--------------------------------------------------------------------------*/
331/* If not already defined, define vtkTypeBool. When VTK was started, some */
332/* compilers did not yet support the bool type, and so VTK often used int, */
333/* or more rarely unsigned int, where it should have used bool. */
334/* Eventually vtkTypeBool will switch to real bool. */
335#ifndef VTK_TYPE_BOOL_TYPEDEFED
336#define VTK_TYPE_BOOL_TYPEDEFED
337#if VTK_USE_FUTURE_BOOL
338typedef bool vtkTypeBool;
339typedef bool vtkTypeUBool;
340#else
341typedef int vtkTypeBool;
342typedef unsigned int vtkTypeUBool;
343#endif
344#endif
345
346#if defined(__cplusplus)
347/* Description:
348 * Returns true if data type tags a and b point to the same data type. This
349 * is intended to handle vtkIdType, which does not have the same tag as its
350 * underlying data type.
351 * @note This method is only available when included from a C++ source file. */
352VTK_ABI_NAMESPACE_BEGIN
353inline vtkTypeBool vtkDataTypesCompare(int a, int b)
354{
355 return (a == b ||
356 ((a == VTK_ID_TYPE || a == VTK_ID_TYPE_IMPL) && (b == VTK_ID_TYPE || b == VTK_ID_TYPE_IMPL)));
357}
358VTK_ABI_NAMESPACE_END
359#endif
360
361/*--------------------------------------------------------------------------*/
363#define vtkInstantiateTemplateMacro(decl) \
364 decl<float>; \
365 decl<double>; \
366 decl<char>; \
367 decl<signed char>; \
368 decl<unsigned char>; \
369 decl<short>; \
370 decl<unsigned short>; \
371 decl<int>; \
372 decl<unsigned int>; \
373 decl<long>; \
374 decl<unsigned long>; \
375 decl<long long>; \
376 decl<unsigned long long>
377
378#define vtkInstantiateSecondOrderTemplateMacro(decl0, decl1) \
379 decl0<decl1<float>>; \
380 decl0<decl1<double>>; \
381 decl0<decl1<char>>; \
382 decl0<decl1<signed char>>; \
383 decl0<decl1<unsigned char>>; \
384 decl0<decl1<short>>; \
385 decl0<decl1<unsigned short>>; \
386 decl0<decl1<int>>; \
387 decl0<decl1<unsigned int>>; \
388 decl0<decl1<long>>; \
389 decl0<decl1<unsigned long>>; \
390 decl0<decl1<long long>>; \
391 decl0<decl1<unsigned long long>>
392
393#define vtkInstantiateStdFunctionTemplateMacro(decl0, decl1, delc2) \
394 decl0<decl1<float(delc2)>>; \
395 decl0<decl1<double(delc2)>>; \
396 decl0<decl1<char(delc2)>>; \
397 decl0<decl1<signed char(delc2)>>; \
398 decl0<decl1<unsigned char(delc2)>>; \
399 decl0<decl1<short(delc2)>>; \
400 decl0<decl1<unsigned short(delc2)>>; \
401 decl0<decl1<int(delc2)>>; \
402 decl0<decl1<unsigned int(delc2)>>; \
403 decl0<decl1<long(delc2)>>; \
404 decl0<decl1<unsigned long(delc2)>>; \
405 decl0<decl1<long long(delc2)>>; \
406 decl0<decl1<unsigned long long(delc2)>>
407
409#ifdef VTK_USE_EXTERN_TEMPLATE
410#define vtkExternTemplateMacro(decl) vtkInstantiateTemplateMacro(decl)
411#define vtkExternSecondOrderTemplateMacro(decl0, decl1) \
412 vtkInstantiateSecondOrderTemplateMacro(decl0, decl1)
413#define vtkExternStdFunctionTemplateMacro(decl0, decl1, decl2) \
414 vtkInstantiateStdFunctionTemplateMacro(decl0, decl1, decl2)
415#else
416#define vtkExternTemplateMacro(decl)
417#define vtkExternSecondOrderTemplateMacro(decl0, decl1)
418#define vtkExternStdFunctionTemplateMacro(decl0, decl1, decl2)
419#endif
420
421#endif
422// VTK-HeaderTest-Exclude: vtkType.h
int vtkTypeBool
Definition vtkABI.h:64
int vtkIdType
Definition vtkType.h:315
#define VTK_ID_TYPE_IMPL
Definition vtkType.h:316
unsigned int vtkTypeUBool
Definition vtkType.h:342
int vtkTypeBool
Definition vtkType.h:341
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:270
#define VTK_ID_TYPE
Definition vtkType.h:44