【发布时间】:2021-12-11 20:25:19
【问题描述】:
我有一个大小为NX x NY x NZ x NC 的体积,其中NC = 3 是通道数,即体素的颜色。
应使用 C++ 中的 VTK 可视化卷。但是,如果数据已经存储在内存中而没有使用 4D 嵌套循环执行深度复制,我不知道如何在 VTK 中初始化卷。
应将以下代码视为伪代码,以了解所需的结果。
unsigned int NX = 100, NY = 100, NZ = 100, NC = 3;
float *volPtr = (float *)malloc(sizeof(float) * NX * NY * NZ * NC); // pointer to raw data
vtkNew<vtkVolume> vol; // or vtkNew<vtkStructuredGrid> vol;
// vol.setPointer(volPtr); // <- I need to find a way to do this
// EDIT: This makes arr point to volPtr without copying it.
// Maybe the vtkFloatArray can be converted to a volume.
vtkNew<vtkFloatArray> arr;
arr->SetArray(volPtr, NX * NY * NZ * NC, 1);
while (true) {
generate_data(volPtr); // dummy function to generate new data and write it to vol
// The VTK object 'vol' should now contain the new data as it points to volPtr
// Visualize the volume
// ...
}
【问题讨论】:
-
对于未来的参考,类似的问题here