[vtkusers] Plotting every point of a ImageData 3D grid

Daniel Coelho 1danielcoelho at gmail.com
Sun Sep 14 13:27:54 EDT 2014


Hello!

I'm trying to create a 3D plot with a structured, rectangular grid of
isolated points. It should look like the attached image (URL
http://docs.luxology.com/modo/701/help/images/layout/ArraySample.png),
except that instead of plotting every point as yellow, each point should
have a different color based on a scalar that they hold.

I've managed to plot the data with the correct color so far. The remaining
problem is that only the very outer layer of points, all around the cube,
gets rendered! None of the interior points get rendered at all, even though
the dataArray that holds the scalars has 1000 points, and all the
dimensions are set properly.

See below for my code:

//Create a vtkImageData
vtkSmartPointer<vtkImageData> imageData =
vtkSmartPointer<vtkImageData>::New();

//Configures the vtkImageData
imageData->SetOrigin(0, 0, 0);
imageData->SetSpacing(1, 1, 1);
imageData->SetDimensions(10, 10, 10);
imageData->SetExtent(0, 9, 0, 9, 0, 9);
imageData->AllocateScalars(VTK_UNSIGNED_CHAR, 1);

//Creates the vtkDataArray that imageData will hold
vtkSmartPointer<vtkTypeUInt8Array> dataArray = vtkTypeUInt8Array::New();

//Copy data from a vector into the data array
//vec is a 1D uint8_t vector holding the entire data
dataArray->SetVoidArray(&(vec[0]), vec.size(), 1);

//Adds the dataArray into the imageData
imageData->GetPointData()->AddArray(dataArray);

//Creates a vtkDataSetMapper
vtkSmartPointer<vtkDataSetMapper> imageDataMapper =
vtkSmartPointer<vtkDataSetMapper>::New();

//Configures the vtkDataSetMapper, adding imageData and making the mapper
plot the scalars of every point
imageDataMapper->SetInputDataObject(imageData);
imageDataMapper->ScalarVisibilityOn();

//Creates a vtkActor
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();

//Configures the actor
actor->GetProperty()->SetInterpolation(0);
actor->GetProperty()->SetPointSize(5);
actor->GetProperty()->SetOpacity(0.5);
actor->GetProperty()->SetRepresentationToPoints();
actor->SetMapper(imageDataMapper);

//Renders the image
renderer->ResetCamera();
renderer->Render();

I really appreciate any help!

Thanks,

Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20140914/d75d683a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 3DGrid.png
Type: image/png
Size: 83069 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20140914/d75d683a/attachment.png>


More information about the vtkusers mailing list