I have a volume of size NX x NY x NZ x NC
, where NC = 3
is the number of channels, i.e., the colors of the voxels.
The volume should be visualized using VTK in C++. However, I don't know how to initialize the volume in VTK if the data is already stored in memory without performing a deep copy using a 4D nested loop.
The following code should be considered as pseudocode to get an idea of the desired outcome.
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
// ...
}