<div dir="ltr">You are not setting the opaccity/color transfer function properly<br><br>try this , my scalar values range from 0-100.<br><br># The following class is used to store transparencyv-values for later retrival. In our case, we want the value 0 to be<br>
# completly opaque whereas the three different cubes are given different transperancy-values to show how it works.<br> alphaChannelFunc = vtk.vtkPiecewiseFunction()<br> alphaChannelFunc.AddPoint(0, 0.0)<br> alphaChannelFunc.AddPoint(10, 0.005)<br>
alphaChannelFunc.AddPoint(50, 0.1)<br> alphaChannelFunc.AddPoint(100, 0.15)<br><br> # This class stores color data and can create color tables from a few color points. For this demo, we want the three cubes<br> # to be of the colors red green and blue.<br>
colorFunc = vtk.vtkColorTransferFunction()<br> colorFunc.AddRGBPoint(0, 1.0, 0.0, 0.0)<br> colorFunc.AddRGBPoint(50, 0.0, 1.0, 0.0)<br> colorFunc.AddRGBPoint(100, 0.0, 0.0, 1.0)<br><br>Jothy<br><br><br><br><div class="gmail_quote">
On Wed, Jul 14, 2010 at 5:22 PM, Chris Turner <span dir="ltr"><<a href="mailto:cturnercomplex@googlemail.com" target="_blank">cturnercomplex@googlemail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">So I tried to volume render the VOI but I only saw a black rectangle<br>
and as soon as i try to click into the window it disappeared.<br>
<br>
Thats the code I added:<br>
# create a rendering window and renderer<br>
renderer = vtk.vtkRenderer()<br>
window = vtk.vtkRenderWindow()<br>
window.AddRenderer(renderer)<br>
<br>
iren = vtk.vtkRenderWindowInteractor()<br>
iren.SetRenderWindow(window)<br>
<br>
# enable user interface interactor<br>
window.SetSize(500,500)<br>
renderer.SetBackground(1,1,1)<br>
caster = vtk.vtkImageCast()<br>
<br>
caster.SetInput(voi.GetOutput())<br>
<br>
caster.SetOutputScalarTypeToUnsignedShort()<br>
<br>
<br>
<br>
rayCastFunction = vtk.vtkVolumeRayCastMIPFunction()<br>
volumeMapper = vtk.vtkVolumeRayCastMapper()<br>
<br>
volumeMapper.SetInput(caster.GetOutput())<br>
<br>
volumeMapper.SetVolumeRayCastFunction(rayCastFunction)<br>
<br>
volumeProperty = vtk.vtkVolumeProperty() #slicer.vtkVolumeProperty()<br>
<br>
colorTransferFunction = vtk.vtkColorTransferFunction()<br>
<br>
colorTransferFunction.AddRGBPoint( 100.0, 1,1,1)<br>
<br>
<br>
<br>
opacityTransferFunction = vtk.vtkPiecewiseFunction()<br>
opacityTransferFunction.AddPoint( 100, 1.0);<br>
<br>
<br>
volumeProperty.SetColor(colorTransferFunction)<br>
<br>
volumeProperty.SetScalarOpacity(opacityTransferFunction)<br>
<br>
volumeProperty.SetInterpolationTypeToLinear()<br>
<br>
volumeProperty.ShadeOn()<br>
<br>
<br>
<br>
Volume = vtk.vtkVolume()<br>
<br>
Volume.SetMapper(volumeMapper)<br>
<br>
Volume.SetProperty(volumeProperty)<br>
renderer.AddViewProp(Volume)<br>
<br>
iren.Start()<br>
<br>
Also when I use "print str(image)" I get the following output:<br>
<br>
vtkImageData (0x1bc4ef0)<br>
Debug: Off<br>
Modified Time: 404<br>
Reference Count: 3<br>
Registered Events: (none)<br>
Source: (none)<br>
Information: 0x1bc5060<br>
Data Released: False<br>
Global Release Data: Off<br>
UpdateTime: 0<br>
Release Data: Off<br>
UpdateExtent: Not Initialized<br>
WholeExtent: 0, 0, 0, 0, 0, 0<br>
RequestExactExtent: Off<br>
Field Data:<br>
Debug: Off<br>
Modified Time: 402<br>
Reference Count: 1<br>
Registered Events: (none)<br>
Number Of Arrays: 0<br>
Number Of Components: 0<br>
Number Of Tuples: 0<br>
Number Of Points: 1<br>
Number Of Cells: 1<br>
Cell Data:<br>
Debug: Off<br>
Modified Time: 392<br>
Reference Count: 1<br>
Registered Events: (none)<br>
Number Of Arrays: 0<br>
Number Of Components: 0<br>
Number Of Tuples: 0<br>
Copy Tuple Flags: ( 1 1 1 1 1 0 1 )<br>
Interpolate Flags: ( 1 1 1 1 1 0 0 )<br>
Pass Through Flags: ( 1 1 1 1 1 1 1 )<br>
Scalars: (none)<br>
Vectors: (none)<br>
Normals: (none)<br>
TCoords: (none)<br>
Tensors: (none)<br>
GlobalIds: (none)<br>
PedigreeIds: (none)<br>
Point Data:<br>
Debug: Off<br>
Modified Time: 398<br>
Reference Count: 1<br>
Registered Events: (none)<br>
Number Of Arrays: 1<br>
Array 0 name = ImageFile<br>
Number Of Components: 1<br>
Number Of Tuples: 1<br>
Copy Tuple Flags: ( 1 1 1 1 1 0 1 )<br>
Interpolate Flags: ( 1 1 1 1 1 0 0 )<br>
Pass Through Flags: ( 1 1 1 1 1 1 1 )<br>
Scalars:<br>
Debug: Off<br>
Modified Time: 397<br>
Reference Count: 1<br>
Registered Events: (none)<br>
Name: ImageFile<br>
Data type: short<br>
Size: 1<br>
MaxId: 0<br>
NumberOfComponents: 1<br>
Information: 0<br>
Name: ImageFile<br>
Number Of Components: 1<br>
Number Of Tuples: 1<br>
Size: 1<br>
MaxId: 0<br>
LookupTable: (none)<br>
Array: 0x1bc9a10<br>
Vectors: (none)<br>
Normals: (none)<br>
TCoords: (none)<br>
Tensors: (none)<br>
GlobalIds: (none)<br>
PedigreeIds: (none)<br>
Bounds:<br>
Xmin,Xmax: (0, 0)<br>
Ymin,Ymax: (0, 0)<br>
Zmin,Zmax: (0, 0)<br>
Compute Time: 0<br>
ScalarType: 4<br>
NumberOfScalarComponents: 1<br>
Spacing: (1, 1, 1)<br>
Origin: (0, 0, 0)<br>
Dimensions: (1, 1, 1)<br>
Increments: (1, 1, 1)<br>
Extent: (0, 0, 0, 0, 0, 0)<br>
<br>
But when I load it in ParaView the image has the correct parameters.<br>
<br>
I'm confused.<br>
<font color="#888888"><br>
Chris<br>
</font><div><div></div><div><br>
On Wed, Jul 14, 2010 at 11:55 AM, Jothy <<a href="mailto:jothybasu@gmail.com" target="_blank">jothybasu@gmail.com</a>> wrote:<br>
> Are you able to render this atleast, before trying to save?<br>
><br>
> Jothy<br>
><br>
> On Wed, Jul 14, 2010 at 4:27 PM, Chris Turner<br>
> <<a href="mailto:cturnercomplex@googlemail.com" target="_blank">cturnercomplex@googlemail.com</a>> wrote:<br>
>><br>
>> bounds are (-69.3 ,323 ,332 ,9.68,468,448)<br>
>> extents are (0,0,0,79,145,116)<br>
>><br>
>> I changed the SetVOI to (-69,323,332,-68,468,448) but same result.<br>
>><br>
>><br>
>> On Wed, Jul 14, 2010 at 11:01 AM, Jothy <<a href="mailto:jothybasu@gmail.com" target="_blank">jothybasu@gmail.com</a>> wrote:<br>
>> > Have you checked that your setVOi is with the bounds of the Image. What<br>
>> > are<br>
>> > your bounds?<br>
>> ><br>
>> > Jothy<br>
>> ><br>
>> > On Wed, Jul 14, 2010 at 3:58 PM, Chris Turner<br>
>> > <<a href="mailto:cturnercomplex@googlemail.com" target="_blank">cturnercomplex@googlemail.com</a>> wrote:<br>
>> >><br>
>> >> No didn't do the trick either.<br>
>> >><br>
>> >> No file, no error/warning message.<br>
>> >><br>
>> >> Thanks though!<br>
>> >><br>
>> >> On Wed, Jul 14, 2010 at 10:54 AM, Jothy <<a href="mailto:jothybasu@gmail.com" target="_blank">jothybasu@gmail.com</a>> wrote:<br>
>> >> > Try SetVOI(0,0,0,79,1,146)<br>
>> >> ><br>
>> >> > Jothy<br>
>> >> ><br>
>> >> > On Wed, Jul 14, 2010 at 3:44 PM, Chris Turner<br>
>> >> > <<a href="mailto:cturnercomplex@googlemail.com" target="_blank">cturnercomplex@googlemail.com</a>> wrote:<br>
>> >> >><br>
>> >> >> Hi David & Bill,<br>
>> >> >><br>
>> >> >> thanks for your patience and your help I appreciate it a lot! So<br>
>> >> >> this<br>
>> >> >> is the code with David's suggestion:<br>
>> >> >><br>
>> >> >> import os<br>
>> >> >> import vtk<br>
>> >> >> import sys<br>
>> >> >><br>
>> >> >><br>
>> >> >> reader=vtk.vtkImageReader()<br>
>> >> >> reader.SetFileName("/tmp/lungROI.vtk")<br>
>> >> >> reader.Update()<br>
>> >> >><br>
>> >> >> lut=vtk.vtkLookupTable()<br>
>> >> >> lut.SetRange(-1024, +4095)<br>
>> >> >><br>
>> >> >> map=vtk.vtkImageMapToColors()<br>
>> >> >> map.SetInput(reader.GetOutput())<br>
>> >> >> map.SetLookupTable(lut)<br>
>> >> >><br>
>> >> >><br>
>> >> >> voi=vtk.vtkExtractVOI()<br>
>> >> >> voi.SetInput(map.GetOutput())<br>
>> >> >> voi.SetVOI(0,0,0,79,146,1)<br>
>> >> >> voi.Update()<br>
>> >> >><br>
>> >> >> writerp=vtk.vtkPNGWriter()<br>
>> >> >> writerp.SetInput(voi.GetOutput())<br>
>> >> >> writerp.SetFileName("/tmp/out.png")<br>
>> >> >> writerp.Write()<br>
>> >> >><br>
>> >> >> print "done"<br>
>> >> >><br>
>> >> >><br>
>> >> >> .... but still no output nor an error message. You can take a look<br>
>> >> >> at<br>
>> >> >> the Image here:<br>
>> >> >><br>
>> >> >> <a href="http://www.load.to/t8MWurwasf/lungROI.vtk" target="_blank">http://www.load.to/t8MWurwasf/lungROI.vtk</a> (~10mb)<br>
>> >> >><br>
>> >> >> Thanks Again,<br>
>> >> >> Chris<br>
>> >> >><br>
>> >> >><br>
>> >> >> On Tue, Jul 13, 2010 at 4:38 PM, David Gobbi <<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>><br>
>> >> >> wrote:<br>
>> >> >> > Hi Chris,<br>
>> >> >> ><br>
>> >> >> > This could be an instance of trying to write 16-bit data to a JPEG<br>
>> >> >> > file. Try adding vtkImageMapToColors with a suitable<br>
>> >> >> > vtkLookupTable.<br>
>> >> >> > The Range of the lookup table will have to be set to something<br>
>> >> >> > reasonable for the image, a range of (-1024, +4095) is a good<br>
>> >> >> > place<br>
>> >> >> > to<br>
>> >> >> > start and then you can increase or decrease the range in order to<br>
>> >> >> > get<br>
>> >> >> > the contrast right.<br>
>> >> >> ><br>
>> >> >> > David<br>
>> >> >> ><br>
>> >> >> ><br>
>> >> >> > On Tue, Jul 13, 2010 at 2:15 PM, Bill Lorensen<br>
>> >> >> > <<a href="mailto:bill.lorensen@gmail.com" target="_blank">bill.lorensen@gmail.com</a>><br>
>> >> >> > wrote:<br>
>> >> >> >> Post you entire example. And, if you can post a link to your<br>
>> >> >> >> data...<br>
>> >> >> >><br>
>> >> >> >> On Tue, Jul 13, 2010 at 3:57 PM, Chris Turner<br>
>> >> >> >> <<a href="mailto:cturnercomplex@googlemail.com" target="_blank">cturnercomplex@googlemail.com</a>> wrote:<br>
>> >> >> >>> Hi Bill,<br>
>> >> >> >>><br>
>> >> >> >>> thanks for your answer! But didn't do the trick.<br>
>> >> >> >>> So strange I thought this was a standard question and procedure.<br>
>> >> >> >>> And<br>
>> >> >> >>> that there has to be a easy way to do that.<br>
>> >> >> >>><br>
>> >> >> >>> And why don't I even get a error message or something. Even when<br>
>> >> >> >>> I<br>
>> >> >> >>> turn on the debug mode there is nothing suspicious.<br>
>> >> >> >>><br>
>> >> >> >>> Anybody has another approach?<br>
>> >> >> >>><br>
>> >> >> >>> Thanks<br>
>> >> >> >>> Chris<br>
>> >> >> >>><br>
>> >> >> >>> On Mon, Jul 12, 2010 at 10:16 AM, Bill Lorensen<br>
>> >> >> >>> <<a href="mailto:bill.lorensen@gmail.com" target="_blank">bill.lorensen@gmail.com</a>> wrote:<br>
>> >> >> >>>> Try,<br>
>> >> >> >>>> voi.SetVOI(0,0,0,511,511,0)<br>
>> >> >> >>>><br>
>> >> >> >>>> On Mon, Jul 12, 2010 at 10:07 AM, Chris Turner<br>
>> >> >> >>>> <<a href="mailto:cturnercomplex@googlemail.com" target="_blank">cturnercomplex@googlemail.com</a>> wrote:<br>
>> >> >> >>>>> Really? Am I the only one with that problem?<br>
>> >> >> >>>>><br>
>> >> >> >>>>> On Fri, Jul 9, 2010 at 5:02 PM, Chris Turner<br>
>> >> >> >>>>> <<a href="mailto:cturnercomplex@googlemail.com" target="_blank">cturnercomplex@googlemail.com</a>> wrote:<br>
>> >> >> >>>>>> Hi Everyone!<br>
>> >> >> >>>>>><br>
>> >> >> >>>>>> I'm trying to extract a slice from a vtkImageData object and<br>
>> >> >> >>>>>> save<br>
>> >> >> >>>>>> it as picture.<br>
>> >> >> >>>>>><br>
>> >> >> >>>>>> That's how I do it:<br>
>> >> >> >>>>>><br>
>> >> >> >>>>>> voi=vtkExtractVOI()<br>
>> >> >> >>>>>> voi.SetInput(imageData)<br>
>> >> >> >>>>>> voi.SetVOI(0,0,0,512,512,1)<br>
>> >> >> >>>>>> voi.Update()<br>
>> >> >> >>>>>><br>
>> >> >> >>>>>> writer=vtkJPEGWriter()<br>
>> >> >> >>>>>> writer.SetInput(voi.GetOutput())<br>
>> >> >> >>>>>> writer.SetFileName("slice.jpg")<br>
>> >> >> >>>>>> writer.Write()<br>
>> >> >> >>>>>><br>
>> >> >> >>>>>> ImageData is 512x512x40 spacing 1,1,1<br>
>> >> >> >>>>>><br>
>> >> >> >>>>>> The strange thing is I don't get an output nor an error<br>
>> >> >> >>>>>> message.<br>
>> >> >> >>>>>> So<br>
>> >> >> >>>>>> I<br>
>> >> >> >>>>>> think I'm missing something here.... but it can't figure out<br>
>> >> >> >>>>>> what.<br>
>> >> >> >>>>>><br>
>> >> >> >>>>>> So does anybody have an idea or a better solution?<br>
>> >> >> >>>>>><br>
>> >> >> >>>>>> Thanks<br>
>> >> >> >>>>>> Chris<br>
>> >> >> >>>>>><br>
>> >> >> >>>>> _______________________________________________<br>
>> >> >> >>>>> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
>> >> >> >>>>><br>
>> >> >> >>>>> Visit other Kitware open-source projects at<br>
>> >> >> >>>>> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
>> >> >> >>>>><br>
>> >> >> >>>>> Please keep messages on-topic and check the VTK FAQ at:<br>
>> >> >> >>>>> <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
>> >> >> >>>>><br>
>> >> >> >>>>> Follow this link to subscribe/unsubscribe:<br>
>> >> >> >>>>> <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
>> >> >> >>>>><br>
>> >> >> >>>><br>
>> >> >> >>><br>
>> >> >> >> _______________________________________________<br>
>> >> >> >> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
>> >> >> >><br>
>> >> >> >> Visit other Kitware open-source projects at<br>
>> >> >> >> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
>> >> >> >><br>
>> >> >> >> Please keep messages on-topic and check the VTK FAQ at:<br>
>> >> >> >> <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
>> >> >> >><br>
>> >> >> >> Follow this link to subscribe/unsubscribe:<br>
>> >> >> >> <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
>> >> >> >><br>
>> >> >> ><br>
>> >> >> _______________________________________________<br>
>> >> >> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
>> >> >><br>
>> >> >> Visit other Kitware open-source projects at<br>
>> >> >> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
>> >> >><br>
>> >> >> Please keep messages on-topic and check the VTK FAQ at:<br>
>> >> >> <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
>> >> >><br>
>> >> >> Follow this link to subscribe/unsubscribe:<br>
>> >> >> <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
>> >> ><br>
>> >> ><br>
>> >> _______________________________________________<br>
>> >> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
>> >><br>
>> >> Visit other Kitware open-source projects at<br>
>> >> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
>> >><br>
>> >> Please keep messages on-topic and check the VTK FAQ at:<br>
>> >> <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
>> >><br>
>> >> Follow this link to subscribe/unsubscribe:<br>
>> >> <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
>> ><br>
>> ><br>
>> _______________________________________________<br>
>> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
>><br>
>> Visit other Kitware open-source projects at<br>
>> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
>><br>
>> Please keep messages on-topic and check the VTK FAQ at:<br>
>> <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
>><br>
>> Follow this link to subscribe/unsubscribe:<br>
>> <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
><br>
><br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
</div></div></blockquote></div><br></div>