[vtkusers] convert unsigned VTkimagedata to signed one

David Feng dfeng at cs.unc.edu
Tue Mar 9 08:54:34 EST 2010


This bit of code is strange:

> vtk.vtkImageData VoxelData = new vtk.vtkImageData();
> VoxelData = VIC.GetOutput();
> VoxelData.AllocateScalars();
>
> vtkImageActor imageActor = new vtkImageActor();
> imageActor.SetInput(VoxelData);

You're creating a new vtkImageData object, then overwriting that
reference with the output from VIC.  If you want a pointer to the
output of a filter, just grab it:

> vtk.vtkImageData VoxelData = VIC.GetOutput().

I'm not sure what calling AllocateScalars() does in this situation,
since you're potentially overwriting the output of a filter with new
scalars.  Replace the code above with something like this:

> vtkImageActor imageActor = new vtkImageActor();
> imageActor.SetInput(VIC.GetOutput());

If you still get casting errors, put the vtkImageShiftScale in between
VIC and the vtkImageActor and try again.

David



On Sun, Mar 7, 2010 at 3:33 PM, Ali Habib <ali.mahmoud.habib at gmail.com> wrote:
> Dear David,
> the proplem in vtkimageactor wich is complain, after applying your code the
> same error appear
> any suggesion please
>
> vtk.vtkDICOMImageReader VDR = new vtk.vtkDICOMImageReader();
>             VDR.SetDirectoryName(@"G:\Master
> Degree\DataSet\case2\DICOM\PA1\ST1\SE2");
>             VDR.SetDataOrigin(0, 0, 0);
>             VDR.Update();
>             vtkImageShiftScale ss = new vtkImageShiftScale();
>             ss.SetOutputScalarTypeToUnsignedChar();
>                  ss.SetInputConnection(VDR.GetOutputPort());
>                 ss.Update();
>             // decrease the dataset data for large data preprocessing
>             vtkImageShrink3D VIS = new vtkImageShrink3D();
>             VIS.SetShrinkFactors(2, 2, 2);
>             VIS.SetInputConnection(ss.GetOutputPort());
>             VIS.Update();
>             vtkImageThreshold VIT = new vtkImageThreshold();
>             VIT.ThresholdBetween(200, 2000);
>             VIT.SetInputConnection(VIS.GetOutputPort());
>             VIT.Update();
>             ///// Start the creation of volume rendering
>             //1. Gget the range of data
>             vtk.vtkImageChangeInformation VIC = new
> vtk.vtkImageChangeInformation();
>             VIC.SetInput(VDR.GetOutput());
>             VIC.CenterImageOn();
>             VIC.Update();
>             vtk.vtkImageData VoxelData = new vtk.vtkImageData();
>             VoxelData = VIC.GetOutput();
>             VoxelData.AllocateScalars();
>             vtkImageActor imageActor = new vtkImageActor();
>             imageActor.SetInput(VoxelData);
>
>  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>             // Create the RenderWindow, Renderer and both Actors
>             //
>             vtkRenderer ren1 = new vtkRenderer();
>             vtkRenderWindow renWin = new vtkRenderWindow();
>             renWin.AddRenderer(ren1);
>             vtkRenderWindowInteractor iren = new
> vtkRenderWindowInteractor();
>             iren.SetRenderWindow(renWin);
>             // Add the actors to the renderer, set the background and size
>             //
>             ren1.AddActor(imageActor);
>             ren1.SetBackground(.1, .2, .4);
>
>
>             ren1.ResetCamera();
>             ren1.ResetCameraClippingRange();
>             renWin.Render();
>
>
> On Sun, Mar 7, 2010 at 10:25 PM, David Feng <d.feng1 at gmail.com> wrote:
>>
>> I'm assuming it's the vtkImageShrink3D filter that's complaining.  I'm
>> surprised it only handles unsigned chars.  vtkImageShiftScale will
>> convert from one type to another:
>>
>> vtkImageShiftScale ss = vtk.vtkImageShiftScale()
>> ss.SetOutputScalarTypeToUnsignedChar()
>> ss.SetInputConnection(VDR.GetOutputPort())
>> ss.Update()
>>
>> vtkImageResample might be able to do the resampling you need without
>> the unsigned char restriction.  Not sure though.
>>
>> David
>>
>> On Sun, Mar 7, 2010 at 2:21 PM, Ali Habib <ali.mahmoud.habib at gmail.com>
>> wrote:
>> > Dear All,
>> > I read DICOm data to VTK image data and display it but it give error
>> > that
>> > "this filter requires unsigned char scalar " I want to convert the data
>> > to
>> > unsigned char
>> > the code use:
>> >             vtk.vtkDICOMImageReader VDR = new vtk.vtkDICOMImageReader();
>> >             VDR.SetDirectoryName(@"G:\Master
>> > Degree\DataSet\case2\DICOM\PA1\ST1\SE2");
>> >             VDR.SetDataOrigin(0, 0, 0);
>> >             VDR.Update();
>> >             // decrease the dataset data for large data preprocessing
>> >             vtkImageShrink3D VIS = new vtkImageShrink3D();
>> >             VIS.SetShrinkFactors(2, 2, 2);
>> >             VIS.SetInputConnection(VDR.GetOutputPort());
>> >             VIS.Update();
>> >             vtkImageThreshold VIT = new vtkImageThreshold();
>> >             VIT.ThresholdBetween(200, 2000);
>> >             VIT.SetInputConnection(VIS.GetOutputPort());
>> >             VIT.Update();
>> >             ///// Start the creation of volume rendering
>> >             //1. Gget the range of data
>> >             vtk.vtkImageChangeInformation VIC = new
>> > vtk.vtkImageChangeInformation();
>> >             VIC.SetInput(VDR.GetOutput());
>> >             VIC.CenterImageOn();
>> >             VIC.Update();
>> >             vtk.vtkImageData VoxelData = new vtk.vtkImageData();
>> >             VoxelData = VIC.GetOutput();
>> >             VoxelData.AllocateScalars();
>> >             vtkImageActor imageActor = new vtkImageActor();
>> >             imageActor.SetInput(VoxelData);
>> >
>> >
>> >  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>> >             // Create the RenderWindow, Renderer and both Actors
>> >             //
>> >             vtkRenderer ren1 = new vtkRenderer();
>> >             vtkRenderWindow renWin = new vtkRenderWindow();
>> >             renWin.AddRenderer(ren1);
>> >             vtkRenderWindowInteractor iren = new
>> > vtkRenderWindowInteractor();
>> >             iren.SetRenderWindow(renWin);
>> >             // Add the actors to the renderer, set the background and
>> > size
>> >             //
>> >             ren1.AddActor(imageActor);
>> >             ren1.SetBackground(.1, .2, .4);
>> >
>> >
>> >             ren1.ResetCamera();
>> >             ren1.ResetCameraClippingRange();
>> >             renWin.Render();
>> > Best regards
>> >
>> >
>> > _______________________________________________
>> > 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
>> >
>> >
>>
>>
>>
>> --
>> http://www.cs.unc.edu/~dfeng
>
>



-- 
http://www.cs.unc.edu/~dfeng



More information about the vtkusers mailing list