<div dir="ltr">As far as I know, you can't simply set the output of file reader to vtkActor. It should be mapped through a vtkLookupTable and mapper.<br><br>it should be something like below<br><br><font size="4"><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">Create</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">a</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">greyscale</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">lookup</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">table</span>
</font><pre style="margin: 0px; text-indent: 0px;"><font size="4"><span style="color: rgb(192, 192, 192);"> </span>vtkSmartPointer<span style="color: rgb(0, 0, 0);"><</span>vtkLookupTable<span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(192, 192, 192);"> </span>table<span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 0, 0);">=</span></font></pre>
<font size="4">
</font><pre style="margin: 0px; text-indent: 0px;"><font size="4"><span style="color: rgb(192, 192, 192);"> </span>vtkSmartPointer<span style="color: rgb(0, 0, 0);"><</span>vtkLookupTable<span style="color: rgb(0, 0, 0);">>::</span>New<span style="color: rgb(0, 0, 0);">();</span></font></pre>
<font size="4">
</font><pre style="margin: 0px; text-indent: 0px;"><font size="4"><span style="color: rgb(192, 192, 192);"> </span>table<span style="color: rgb(0, 0, 0);">-></span>SetRange<span style="color: rgb(0, 0, 0);">(-</span><span style="color: rgb(0, 0, 128);">600</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 128);">900</span><span style="color: rgb(0, 0, 0);">);</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">image</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">intensity</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">range</span></font></pre>
<font size="4">
</font><pre style="margin: 0px; text-indent: 0px;"><font size="4"><span style="color: rgb(192, 192, 192);"> </span>table<span style="color: rgb(0, 0, 0);">-></span>SetValueRange<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 128);">0.0</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 0, 128);">1.0</span><span style="color: rgb(0, 0, 0);">);</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">from</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">black</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">to</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">white</span></font></pre>
<font size="4">
</font><pre style="margin: 0px; text-indent: 0px;"><font size="4"><span style="color: rgb(192, 192, 192);"> </span>table<span style="color: rgb(0, 0, 0);">-></span>SetSaturationRange<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 128);">0.0</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 0, 128);">0.0</span><span style="color: rgb(0, 0, 0);">);</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">no</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">color</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">saturation</span></font></pre>
<font size="4">
</font><pre style="margin: 0px; text-indent: 0px;"><font size="4"><span style="color: rgb(192, 192, 192);"> </span>table<span style="color: rgb(0, 0, 0);">-></span>SetRampToLinear<span style="color: rgb(0, 0, 0);">();</span></font></pre>
<font size="4">
</font><pre style="margin: 0px; text-indent: 0px;"><font size="4"><span style="color: rgb(192, 192, 192);"> </span>table<span style="color: rgb(0, 0, 0);">-></span>Build<span style="color: rgb(0, 0, 0);">();</span></font></pre>
<font size="4">
</font>
<pre style="margin: 0px; text-indent: 0px;"><font size="4"><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">Map</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">the</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">image</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">through</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">the</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">lookup</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">table</span></font></pre>
<font size="4">
</font><pre style="margin: 0px; text-indent: 0px;"><font size="4"><span style="color: rgb(192, 192, 192);"> </span>vtkSmartPointer<span style="color: rgb(0, 0, 0);"><</span>vtkImageMapToColors<span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(192, 192, 192);"> </span>color<span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 0, 0);">=</span></font></pre>
<font size="4">
</font><pre style="margin: 0px; text-indent: 0px;"><font size="4"><span style="color: rgb(192, 192, 192);"> </span>vtkSmartPointer<span style="color: rgb(0, 0, 0);"><</span>vtkImageMapToColors<span style="color: rgb(0, 0, 0);">>::</span>New<span style="color: rgb(0, 0, 0);">();</span></font></pre>
<font size="4">
</font><pre style="margin: 0px; text-indent: 0px;"><font size="4"><span style="color: rgb(192, 192, 192);"> </span>color<span style="color: rgb(0, 0, 0);">-></span>SetLookupTable<span style="color: rgb(0, 0, 0);">(</span>table<span style="color: rgb(0, 0, 0);">);</span></font></pre>
<font size="4">
</font><pre style="margin: 0px; text-indent: 0px;"><font size="4"><span style="color: rgb(192, 192, 192);"> </span>color<span style="color: rgb(0, 0, 0);">-></span>SetInputConnection<span style="color: rgb(0, 0, 0);">(</span>reader->GetOutput()<span style="color: rgb(0, 0, 0);">);</span></font></pre>
<font size="4">
</font>
<pre style="margin: 0px; text-indent: 0px;"><font size="4"><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">Set</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">the</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);">image</span></font></pre>
<font size="4">
</font><pre style="margin: 0px; text-indent: 0px;"><font size="4"><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(128, 128, 0);">this</span><span style="color: rgb(0, 0, 0);">-></span>axialSlice<span style="color: rgb(0, 0, 0);">-></span>SetInput<span style="color: rgb(0, 0, 0);">(</span>color<span style="color: rgb(0, 0, 0);">-></span>GetOutput<span style="color: rgb(0, 0, 0);">());</span></font></pre>
<br>Since this this mainly vtk related , you should post it to vtk list too. (I have added a cc)<br><br>HTH<br><br>Jothy<br><br><div class="gmail_quote">On Mon, Jul 18, 2011 at 3:25 AM, soheilghafurian <span dir="ltr"><<a href="mailto:soheilghafurian@yahoo.com">soheilghafurian@yahoo.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">My problem is I load a dicom file and I try to show it through vtk by<br>
ImageToVTKImageFilter. But the result is kind of distorted. I think the<br>
problem is because the pixeltype is not good, but when I use another type, I<br>
get this message when the program is running:<br>
<br>
ERROR: In ..\..\Rendering\vtkImageActor.cxx, line 267<br>
vtkOpenGLImageActor (058C5340): This filter requires unsigned char scalars<br>
as input<br>
<br>
Could anyone help me on how I should solve this problem? here is the code:<br>
<br>
int main()<br>
{<br>
char *fName = fl_file_chooser("Pick the fixed dicom Image", "*.dcm", ".");<br>
if(fName == NULL) return 0;<br>
<br>
typedef itk::Image< unsigned char, 2> ImageType;<br>
typedef itk::ImageFileReader<ImageType> ReaderType;<br>
typedef itk::ImageToVTKImageFilter<ImageType> ConnectorType;<br>
<br>
ReaderType::Pointer reader = ReaderType::New();<br>
ConnectorType::Pointer connector = ConnectorType::New();<br>
<br>
reader->SetFileName(fName);<br>
reader->Update();<br>
connector->SetInput(reader->GetOutput());<br>
<br>
<br>
<br>
vtkSmartPointer<vtkImageActor> actor =<br>
vtkSmartPointer<vtkImageActor>::New();<br>
// actor->SetInput(connector->GetOutput());<br>
actor->SetInput(connector->GetOutput());<br>
<br>
vtkSmartPointer<vtkRenderer> renderer =<br>
vtkSmartPointer<vtkRenderer>::New();<br>
renderer->AddActor(actor);<br>
renderer->ResetCamera();<br>
<br>
vtkSmartPointer<vtkRenderWindow> renderWindow =<br>
vtkSmartPointer<vtkRenderWindow>::New();<br>
renderWindow->AddRenderer(renderer);<br>
<br>
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =<br>
vtkSmartPointer<vtkRenderWindowInteractor>::New();<br>
vtkSmartPointer<vtkInteractorStyleImage> style =<br>
vtkSmartPointer<vtkInteractorStyleImage>::New();<br>
<br>
renderWindowInteractor->SetInteractorStyle(style);<br>
<br>
renderWindowInteractor->SetRenderWindow(renderWindow);<br>
renderWindowInteractor->Initialize();<br>
<br>
renderWindowInteractor->Start();<br>
<br>
return EXIT_SUCCESS;<br>
}<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://itk-insight-users.2283740.n2.nabble.com/How-to-show-dicoms-with-vtk-ImageToVTKImageFilter-tp6593222p6593222.html" target="_blank">http://itk-insight-users.2283740.n2.nabble.com/How-to-show-dicoms-with-vtk-ImageToVTKImageFilter-tp6593222p6593222.html</a><br>
Sent from the ITK Insight Users mailing list archive at Nabble.com.<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>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
</blockquote></div><br></div>