VTK学习笔记(十二)vtkImageData打印内容
std::cout << __FUNCTION__ << std::endl << std::flush;
volumeData->Print(std::cout);
slicer 默认加载的nii.gz
数据类型是int类型,即 int32_t。
slicer 默认加载的.mhd
数据类型是short类型,即 int16_t。
另外在加载数据时也可以指定加载数据类型。
1、获取数据
之前一直使用 int16_t获取数据,也没有觉得哪里不对,后来一次测试发现,可能获取的数据有误。原因后面,之后我弄明白了会细说。
vtkImageData* volumeData;
int16_t* d_p = (int16_t*)volumeData->GetScalarPointer();
使用int16_t获取的数据,可以看到,中间多了一些“-1”。
下面是python下simpleITK获取的数据。
所以使用int32_t才获取到正确的数据。先说一下用int16_t获取到的数据错在哪里,错在了
vtkImageData* volumeData;
int32_t* d_p = (int32_t*)volumeData->GetScalarPointer();
2、使用前获取数据类型
vtkImageData* volumeData;
int inputDataType = volumeData->GetScalarType();
VTK数据类型
/*--------------------------------------------------------------------------*/
/* Define a unique integer identifier for each native scalar type. */
/* These types are returned by GetDataType to indicate pixel type. */
#define VTK_VOID 0
#define VTK_BIT 1
#define VTK_CHAR 2
#define VTK_SIGNED_CHAR 15
#define VTK_UNSIGNED_CHAR 3
#define VTK_SHORT 4
#define VTK_UNSIGNED_SHORT 5
#define VTK_INT 6
#define VTK_UNSIGNED_INT 7
#define VTK_LONG 8
#define VTK_UNSIGNED_LONG 9
#define VTK_FLOAT 10
#define VTK_DOUBLE 11
#define VTK_ID_TYPE 12
VC的stdint.h中数据类型定义
#include <vcruntime.h>
#if _VCRT_COMPILER_PREPROCESSOR
#pragma warning(push)
#pragma warning(disable: _VCRUNTIME_DISABLED_WARNINGS)
typedef signed char int8_t;
typedef short int16_t;
typedef int int32_t;
typedef long long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
typedef signed char int_least8_t;
typedef short int_least16_t;
typedef int int_least32_t;
typedef long long int_least64_t;
typedef unsigned char uint_least8_t;
typedef unsigned short uint_least16_t;
typedef unsigned int uint_least32_t;
typedef unsigned long long uint_least64_t;
typedef signed char int_fast8_t;
typedef int int_fast16_t;
typedef int int_fast32_t;
typedef long long int_fast64_t;
typedef unsigned char uint_fast8_t;
typedef unsigned int uint_fast16_t;
typedef unsigned int uint_fast32_t;
typedef unsigned long long uint_fast64_t;
typedef long long intmax_t;
typedef unsigned long long uintmax_t;