Hi,<br><br><br>I&#39;ve done a very simple MIP-visualizer with VTK 5.2 (Thanks to Aurélie for the help).<br><br>But I&#39;m a little disappointed because it&#39;s very slow. The refresh time of the window is very long.<br>
<br>I make tests with a DICOM Series (36 CT-slices).<br><br>Here&#39;s the program very simplified :<br><br><span style="font-family: courier new,monospace;">#include &quot;vtkDICOMImageReader.h&quot;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include &quot;vtkImageData.h&quot;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include &quot;vtkImageShiftScale.h&quot;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include &quot;vtkPiecewiseFunction.h&quot;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include &quot;vtkRenderer.h&quot;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include &quot;vtkRenderWindow.h&quot;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include &quot;vtkRenderWindowInteractor.h&quot;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include &quot;vtkVolume.h&quot;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include &quot;vtkVolumeProperty.h&quot;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include &quot;vtkVolumeRayCastMapper.h&quot;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include &quot;vtkVolumeRayCastMIPFunction.h&quot;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include &lt;sstream&gt;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">using namespace std;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">int main (int argc, char **argv)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">{</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">if( argc &lt; 2 )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">{</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">std::cerr &lt;&lt; argv[0] &lt;&lt; &quot; rep&quot;;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">return 1;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">else</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">{</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">string rep;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">rep = argv[1];</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">vtkDICOMImageReader * reader;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">reader = vtkDICOMImageReader::New();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">string dir(&quot;&quot;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">ostringstream oss(dir.c_str());</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">oss &lt;&lt; rep ;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">dir = oss.str();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">const char* adresse = dir.c_str();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">reader-&gt;SetDirectoryName(adresse);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">cout &lt;&lt; adresse &lt;&lt; endl;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">reader-&gt;Update();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">reader-&gt;SetDataScalarTypeToShort();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">reader-&gt;UpdateWholeExtent();&nbsp; &nbsp;&nbsp;&nbsp; </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">reader-&gt;GetOutput()-&gt;UpdateInformation();&nbsp;&nbsp;&nbsp; &nbsp; </span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">vtkRenderer* renderer = vtkRenderer::New();</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">vtkRenderWindow* renWin = vtkRenderWindow::New();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">renWin-&gt;AddRenderer(renderer);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">iren-&gt;SetRenderWindow(renWin);</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">double range[2];</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">reader-&gt;GetOutput()-&gt;GetScalarRange(range);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">double min = range[0];</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">double max = range[1];</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">double diff = max-min;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">double slope = 255.0/diff;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">double inter = -slope*min;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">double shift = inter/slope;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">vtkImageShiftScale *vtkImageCast = vtkImageShiftScale::New();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">vtkImageCast-&gt;SetInput(reader-&gt;GetOutput());</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">vtkImageCast-&gt;SetShift(shift);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">vtkImageCast-&gt;SetScale(slope);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">vtkImageCast-&gt;SetOutputScalarTypeToUnsignedShort();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">vtkImageCast-&gt;Update();&nbsp;&nbsp;&nbsp; </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">vtkImageCast-&gt;GetOutput()-&gt;GetScalarRange(range);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">double level = 0.5 * (range[1] + range[0]);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">double window = range[1] - range[0];</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">vtkPiecewiseFunction *opacityTransferFunction = vtkPiecewiseFunction::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">opacityTransferFunction-&gt;AddPoint( level - window/2&nbsp; , 0.0 );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">opacityTransferFunction-&gt;AddPoint( level + window/2 , 1.0 );</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">vtkPiecewiseFunction *grayTransferFunction = vtkPiecewiseFunction::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">grayTransferFunction-&gt;AddSegment( level - window/2, 0.0 , level + window/2, 1.0 );</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">vtkVolumeProperty *mipProperty;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">mipProperty = vtkVolumeProperty::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">mipProperty-&gt;SetScalarOpacity( opacityTransferFunction );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">mipProperty-&gt;SetColor( grayTransferFunction );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">mipProperty-&gt;SetInterpolationTypeToLinear();</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">vtkVolumeRayCastMIPFunction* mipFunction = vtkVolumeRayCastMIPFunction::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">mipFunction-&gt;SetMaximizeMethodToOpacity();</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">vtkVolumeRayCastMapper* volumeMapper = vtkVolumeRayCastMapper::New();</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">volumeMapper-&gt;SetVolumeRayCastFunction( mipFunction );&nbsp;&nbsp;&nbsp; </span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">volumeMapper-&gt;SetInput( vtkImageCast-&gt;GetOutput() );</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">vtkVolume* volume = vtkVolume::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">volume-&gt;SetMapper( volumeMapper );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">volume-&gt;SetProperty( mipProperty );</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">renderer-&gt;AddViewProp( volume );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">renderer-&gt;Render();</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">renWin-&gt;SetSize( 1000 , 700 );</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">iren-&gt;Initialize();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">iren-&gt;Start();</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">iren-&gt;Delete();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">renWin-&gt;Delete();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">renderer-&gt;Delete();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">return 0;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">}</span><br><br><br><font face="arial,helvetica,sans-serif">and here&#39;s the CMakeLists.txt :<br>
<br><br><span style="font-family: courier new,monospace;">PROJECT (Project)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">FIND_PACKAGE(VTK REQUIRED)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">IF(NOT VTK_USE_RENDERING)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; MESSAGE(FATAL_ERROR &quot;Example ${PROJECT_NAME} requires VTK_USE_RENDERING.&quot;)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">ENDIF(NOT VTK_USE_RENDERING)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">INCLUDE(${VTK_USE_FILE})</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">ADD_EXECUTABLE(MIP_TEST MIP_TEST.cxx)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">TARGET_LINK_LIBRARIES(MIP_TEST vtkVolumeRendering)</span><br>
<br><br>To test you just have to give as input a repertory of a DICOM Serie.<br><br><br><br>My porpose is </font><font face="arial,helvetica,sans-serif">obviously </font><font face="arial,helvetica,sans-serif">to create a program more &quot;complicated&quot; than this one, but it will be impossible if it&#39;s so slow.<br>
<br>Do you have any advice, remarks,...? to make it quicker ?<br><br><br>Thank you very much,<br><br>Regards,<br><br><br><br>Stéphane<br></font>