[vtkusers] How to create a color vtkImageData?

Jérôme jerome.velut at gmail.com
Sat Mar 20 11:26:31 EDT 2010


Hi,
it seems that you allocate correctly a 3 components array in ImageData, but
the one you fill in is not the former !
your 'scalars' is another float array, which you fill with InsertTupe1, i.e.
*one* component.
You have to specify the data type for your vtkImageData and use, for
instance, the SetScalarComponentFromFloat
function, that is member of vtkImageData.

I think you will find lots of example on the VTK wiki that do such a fill.

HTH
Jerome

2010/3/20 Андрей Глухов <realandron at gmail.com>

> If I set SetNumberOfScalarComponents (3) and fills the array with
> vtkMath.Random a color image is displayed,but if I substituted specific
> values, the image is displayed in grayscale. How to create an array?
> //code
>             vtkImageData vol = new vtkImageData();
>             vol.SetDimensions(512, 512, 1);
>             vol.SetSpacing(10, 10, 10);
>             vol.SetOrigin(0, 0, 0);
>             vol.AllocateScalars();
>             vol.SetNumberOfScalarComponents(3);
>
>             vtkFloatArray scalars = new vtkFloatArray();
>             for (int i = 0; i < 512; i++)
>             {
>                 for (int j = 0; j < 512; j++)
>                 {
>                         scalars.InsertTuple1(i * 512 + j,vtkMath.Random(0,
> 2000));//Why grayscale with my values??
>                 }
>             }
>
>             vol.GetPointData().SetScalars(scalars);
>             vol.Update();
>
>             vtkImageViewer viewer = new vtkImageViewer();
>             viewer.SetInput(vol);
>             viewer.SetSize(512, 512);
>             viewer.Render();
> --
> С Уважением,
> Андрей.
> Best regards, Andrew
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100320/8c315d1a/attachment.htm>


More information about the vtkusers mailing list