[Insight-users] pipeline:ITK to VTK

Beck y_h_young at hotmail.com
Thu, 18 Mar 2004 11:24:40 +0800


This is a multi-part message in MIME format.

------=_NextPart_000_003B_01C40CDB.9AA80410
Content-Type: text/plain;
	charset="big5"
Content-Transfer-Encoding: quoted-printable

Dear all:
    I try the example "SegmenterViewer2" (attached below).It can compile =
and link  ,but it will fail at run time.

    (I replace'VXLNumerics.lib' with 'ITKNumerics.lib' because I can't =
find VXLNumerics.lib  in IVK directory.)

    I can't find what happen in it,hope somebody can help,thank you very =
much.


    Best regards

    Beck

//-----------  SegmenterViewer2 .cxx  ------------------------
#include "itkImageFileReader.h"
#include "itkImageToVTKImageFilter.h"
#include "itkImage.h"

#include "itkCastImageFilter.h"
#include "itkConfidenceConnectedImageFilter.h"
#include "itkCurvatureFlowImageFilter.h"

#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkContourFilter.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkProperty.h"

int main( int argc, char ** argv )
{

  if( argc < 6 )
    {
    std::cerr << "Usage: viewer1 imagefilename  xseed yseed zseed =
neighborhoodsize" << std::endl;
    return -1;
    }

  typedef signed short    InputPixelType;
  typedef float           InternalPixelType;
  typedef unsigned char   SegmentedPixelType;

  typedef itk::Image< InputPixelType, 3 >          InputImageType;
  typedef itk::Image< InternalPixelType, 3 >       InternalImageType;
  typedef itk::Image< SegmentedPixelType, 3 >      SegmentedImageType;

  typedef itk::ImageFileReader< InputImageType >   ReaderType;

  typedef   itk::CastImageFilter<=20
                 InputImageType,=20
                 InternalImageType >     CastImageFilterType;

  typedef   itk::CurvatureFlowImageFilter<=20
                 InternalImageType,=20
                 InternalImageType >     CurvatureFlowImageFilterType;

  typedef   itk::ConfidenceConnectedImageFilter<=20
                         InternalImageType,=20
                         SegmentedImageType >     =
ConfidenceConnectedImageFilterType;

  typedef itk::ImageToVTKImageFilter< SegmentedImageType >  =
ConnectorFilterType;


  //----------------------------------
  //           ITK Pipeline
  //----------------------------------

  ReaderType::Pointer  reader =3D ReaderType::New();

  CastImageFilterType::Pointer cast =3D CastImageFilterType::New();

  CurvatureFlowImageFilterType::Pointer smoothing =3D =
CurvatureFlowImageFilterType::New();

  ConfidenceConnectedImageFilterType::Pointer confidence =3D =
ConfidenceConnectedImageFilterType::New();

  ConnectorFilterType::Pointer connector =3D ConnectorFilterType::New();

  reader->SetFileName( argv[1] );

  cast->SetInput(       reader->GetOutput() );
  smoothing->SetInput(  cast->GetOutput() );
  confidence->SetInput( smoothing->GetOutput() );

  smoothing->SetTimeStep( 0.125 );
  smoothing->SetNumberOfIterations( 2 );
   =20
  confidence->SetMultiplier( 5.0 );
  confidence->SetNumberOfIterations( 2 );
  confidence->SetReplaceValue( 250 );
 =20
  typedef ConfidenceConnectedImageFilterType::IndexType IndexType;
  IndexType seed;
  seed[0] =3D atoi( argv[2] );
  seed[1] =3D atoi( argv[3] );
  seed[2] =3D atoi( argv[4] );

  std::cout << "Using seed =3D " << seed << std::endl;
  confidence->SetSeed( seed );

  confidence->SetInitialNeighborhoodRadius( atoi( argv[5] ) );

  connector->SetInput( confidence->GetOutput() );
  connector->GetImporter()->SetDataScalarTypeToUnsignedChar();

  //----------------------------------
  //           VTK Pipeline
  //----------------------------------

  vtkRenderer               * renderer               =3D =
vtkRenderer::New();
  vtkRenderWindow           * renderWindow           =3D =
vtkRenderWindow::New();
  vtkRenderWindowInteractor * renderWindowInteractor =3D =
vtkRenderWindowInteractor::New();

  renderWindow->AddRenderer( renderer );
  renderWindow->SetInteractor( renderWindowInteractor );

  vtkContourFilter * contour =3D vtkContourFilter::New();
 =20
  contour->SetInput( connector->GetOutput() );
  contour->SetValue( 0, 127.0 );

  vtkPolyDataMapper * polyDataMapper =3D vtkPolyDataMapper::New();

  polyDataMapper->SetInput( contour->GetOutput() );
  polyDataMapper->SetScalarRange( 0.0, 250.0 );

  vtkActor * actor =3D vtkActor::New();
  actor->SetMapper( polyDataMapper );
  actor->GetProperty()->SetColor( 0.8, 0.8, 1.0 );
 =20
  renderer->AddActor( actor );
  renderer->SetBackground( 0.1, 0.2, 0.4 );

  renderWindow->Render();
  renderWindowInteractor->Start();
 =20
  return 0;

}
//------   CMakeLists.txt   --------------------------
PROJECT( SegmenterViewer2 )

INCLUDE (${CMAKE_ROOT}/Modules/FindITK.cmake)
IF (USE_ITK_FILE)
  INCLUDE (${USE_ITK_FILE})
ENDIF (USE_ITK_FILE)

INCLUDE (${CMAKE_ROOT}/Modules/FindVTK.cmake)
IF (USE_VTK_FILE)
  INCLUDE (${USE_VTK_FILE})
ENDIF (USE_VTK_FILE)


ADD_EXECUTABLE( SegmenterViewer2 SegmenterViewer2.cxx )

TARGET_LINK_LIBRARIES( SegmenterViewer2
    ITKIO ITKCommon ITKBasicFilters ITKNumerics ITKNumerics
    vtkCommon vtkGraphics vtkRendering vtkImaging vtkIO vtkHybrid )


------=_NextPart_000_003B_01C40CDB.9AA80410
Content-Type: text/html;
	charset="big5"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dbig5">
<META content=3D"MSHTML 6.00.2800.1226" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>
<DIV><FONT size=3D4>Dear all:</FONT></DIV>
<DIV><FONT size=3D4>&nbsp;&nbsp;&nbsp; I try the example =
"SegmenterViewer2"=20
(attached below).It can compile and link&nbsp; ,but it will fail at run=20
time.</FONT></DIV>
<DIV><FONT size=3D4></FONT>&nbsp;</DIV>
<DIV><FONT size=3D4>&nbsp;&nbsp;&nbsp; (I replace'VXLNumerics.lib' with=20
'ITKNumerics.lib' because I can't find VXLNumerics.lib&nbsp; in IVK=20
directory.)</FONT></DIV>
<DIV><FONT size=3D4></FONT>&nbsp;</DIV>
<DIV><FONT size=3D4>&nbsp;&nbsp;&nbsp; I can't find what happen in =
it,hope=20
somebody can help,thank you very much.</FONT></DIV>
<DIV><FONT size=3D4></FONT>&nbsp;</DIV>
<DIV><FONT size=3D4></FONT>&nbsp;</DIV>
<DIV><FONT size=3D4>&nbsp;&nbsp;&nbsp; Best regards</FONT></DIV>
<DIV><FONT size=3D4></FONT>&nbsp;</DIV>
<DIV><FONT size=3D4>&nbsp;&nbsp;&nbsp; Beck</FONT></DIV>
<DIV><FONT size=3D4></FONT>&nbsp;</DIV>
<DIV><FONT size=3D4>//-----------&nbsp; SegmenterViewer2&nbsp;.cxx&nbsp; =

------------------------</FONT></DIV>
<DIV><FONT size=3D2>#include "itkImageFileReader.h"<BR>#include=20
"itkImageToVTKImageFilter.h"<BR>#include "itkImage.h"</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>#include "itkCastImageFilter.h"<BR>#include=20
"itkConfidenceConnectedImageFilter.h"<BR>#include=20
"itkCurvatureFlowImageFilter.h"</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>#include "vtkRenderer.h"<BR>#include=20
"vtkRenderWindow.h"<BR>#include =
"vtkRenderWindowInteractor.h"<BR>#include=20
"vtkContourFilter.h"<BR>#include "vtkPolyDataMapper.h"<BR>#include=20
"vtkActor.h"<BR>#include "vtkProperty.h"</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>int main( int argc, char ** argv )<BR>{</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>&nbsp; if( argc &lt; 6 )<BR>&nbsp;&nbsp;&nbsp;=20
{<BR>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; "Usage: viewer1 =
imagefilename&nbsp;=20
xseed yseed zseed neighborhoodsize" &lt;&lt; =
std::endl;<BR>&nbsp;&nbsp;&nbsp;=20
return -1;<BR>&nbsp;&nbsp;&nbsp; }</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>&nbsp; typedef signed short&nbsp;&nbsp;&nbsp;=20
InputPixelType;<BR>&nbsp; typedef=20
float&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
InternalPixelType;<BR>&nbsp; typedef unsigned char&nbsp;&nbsp;=20
SegmentedPixelType;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>&nbsp; typedef itk::Image&lt; InputPixelType, 3=20
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
InputImageType;<BR>&nbsp; typedef itk::Image&lt; InternalPixelType, 3=20
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InternalImageType;<BR>&nbsp; =
typedef=20
itk::Image&lt; SegmentedPixelType, 3 &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
SegmentedImageType;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>&nbsp; typedef itk::ImageFileReader&lt; =
InputImageType=20
&gt;&nbsp;&nbsp; ReaderType;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>&nbsp; typedef&nbsp;&nbsp; itk::CastImageFilter&lt;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;=20
InputImageType,=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;=20
InternalImageType &gt;&nbsp;&nbsp;&nbsp;&nbsp; =
CastImageFilterType;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>&nbsp; typedef&nbsp;&nbsp; =
itk::CurvatureFlowImageFilter&lt;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;=20
InternalImageType,=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;=20
InternalImageType &gt;&nbsp;&nbsp;&nbsp;&nbsp;=20
CurvatureFlowImageFilterType;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>&nbsp; typedef&nbsp;&nbsp;=20
itk::ConfidenceConnectedImageFilter&lt;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;=20
InternalImageType,=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;=20
SegmentedImageType &gt;&nbsp;&nbsp;&nbsp;&nbsp;=20
ConfidenceConnectedImageFilterType;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>&nbsp; typedef itk::ImageToVTKImageFilter&lt;=20
SegmentedImageType &gt;&nbsp; ConnectorFilterType;</FONT></DIV>
<DIV>&nbsp;</DIV><FONT size=3D2>
<DIV><BR>&nbsp; //----------------------------------<BR>&nbsp;=20
//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ITK=20
Pipeline<BR>&nbsp; //----------------------------------</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; ReaderType::Pointer&nbsp; reader =3D =
ReaderType::New();</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; CastImageFilterType::Pointer cast =3D=20
CastImageFilterType::New();</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; CurvatureFlowImageFilterType::Pointer smoothing =3D=20
CurvatureFlowImageFilterType::New();</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; ConfidenceConnectedImageFilterType::Pointer confidence =3D=20
ConfidenceConnectedImageFilterType::New();</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; ConnectorFilterType::Pointer connector =3D=20
ConnectorFilterType::New();</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; reader-&gt;SetFileName( argv[1] );</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; cast-&gt;SetInput(&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
reader-&gt;GetOutput() );<BR>&nbsp; smoothing-&gt;SetInput(&nbsp;=20
cast-&gt;GetOutput() );<BR>&nbsp; confidence-&gt;SetInput(=20
smoothing-&gt;GetOutput() );</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; smoothing-&gt;SetTimeStep( 0.125 );<BR>&nbsp;=20
smoothing-&gt;SetNumberOfIterations( 2 );<BR>&nbsp;&nbsp;&nbsp; =
<BR>&nbsp;=20
confidence-&gt;SetMultiplier( 5.0 );<BR>&nbsp;=20
confidence-&gt;SetNumberOfIterations( 2 );<BR>&nbsp;=20
confidence-&gt;SetReplaceValue( 250 );<BR>&nbsp; <BR>&nbsp; typedef=20
ConfidenceConnectedImageFilterType::IndexType IndexType;<BR>&nbsp; =
IndexType=20
seed;<BR>&nbsp; seed[0] =3D atoi( argv[2] );<BR>&nbsp; seed[1] =3D atoi( =
argv[3]=20
);<BR>&nbsp; seed[2] =3D atoi( argv[4] );</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; std::cout &lt;&lt; "Using seed =3D " &lt;&lt; seed &lt;&lt;=20
std::endl;<BR>&nbsp; confidence-&gt;SetSeed( seed );</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; confidence-&gt;SetInitialNeighborhoodRadius( atoi( argv[5] ) =

);</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; connector-&gt;SetInput( confidence-&gt;GetOutput() =
);<BR>&nbsp;=20
connector-&gt;GetImporter()-&gt;SetDataScalarTypeToUnsignedChar();</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; //----------------------------------<BR>&nbsp;=20
//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VTK=20
Pipeline<BR>&nbsp; //----------------------------------</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;=20
vtkRenderer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;=20
*=20
renderer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;=20
=3D vtkRenderer::New();<BR>&nbsp;=20
vtkRenderWindow&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; *=20
renderWindow&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
=3D=20
vtkRenderWindow::New();<BR>&nbsp; vtkRenderWindowInteractor *=20
renderWindowInteractor =3D vtkRenderWindowInteractor::New();</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; renderWindow-&gt;AddRenderer( renderer );<BR>&nbsp;=20
renderWindow-&gt;SetInteractor( renderWindowInteractor );</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; vtkContourFilter * contour =3D =
vtkContourFilter::New();<BR>&nbsp;=20
<BR>&nbsp; contour-&gt;SetInput( connector-&gt;GetOutput() );<BR>&nbsp;=20
contour-&gt;SetValue( 0, 127.0 );</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; vtkPolyDataMapper * polyDataMapper =3D =
vtkPolyDataMapper::New();</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; polyDataMapper-&gt;SetInput( contour-&gt;GetOutput() =
);<BR>&nbsp;=20
polyDataMapper-&gt;SetScalarRange( 0.0, 250.0 );</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; vtkActor * actor =3D vtkActor::New();<BR>&nbsp; =
actor-&gt;SetMapper(=20
polyDataMapper );<BR>&nbsp; actor-&gt;GetProperty()-&gt;SetColor( 0.8, =
0.8, 1.0=20
);<BR>&nbsp; <BR>&nbsp; renderer-&gt;AddActor( actor );<BR>&nbsp;=20
renderer-&gt;SetBackground( 0.1, 0.2, 0.4 );</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; renderWindow-&gt;Render();<BR>&nbsp;=20
renderWindowInteractor-&gt;Start();<BR>&nbsp; <BR>&nbsp; return 0;</DIV>
<DIV>&nbsp;</DIV>
<DIV>}<BR></FONT><FONT size=3D4>//------&nbsp;&nbsp; =
CMakeLists.txt&nbsp;&nbsp;=20
--------------------------</FONT></DIV>
<DIV><FONT size=3D2>PROJECT( SegmenterViewer2 )</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>INCLUDE (${CMAKE_ROOT}/Modules/FindITK.cmake)<BR>IF=20
(USE_ITK_FILE)<BR>&nbsp; INCLUDE (${USE_ITK_FILE})<BR>ENDIF=20
(USE_ITK_FILE)</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>INCLUDE (${CMAKE_ROOT}/Modules/FindVTK.cmake)<BR>IF=20
(USE_VTK_FILE)<BR>&nbsp; INCLUDE (${USE_VTK_FILE})<BR>ENDIF=20
(USE_VTK_FILE)</FONT></DIV>
<DIV>&nbsp;</DIV><FONT size=3D2>
<DIV><BR>ADD_EXECUTABLE( SegmenterViewer2 SegmenterViewer2.cxx )</DIV>
<DIV>&nbsp;</DIV>
<DIV>TARGET_LINK_LIBRARIES( SegmenterViewer2<BR>&nbsp;&nbsp;&nbsp; ITKIO =

ITKCommon ITKBasicFilters ITKNumerics ITKNumerics<BR>&nbsp;&nbsp;&nbsp;=20
vtkCommon vtkGraphics vtkRendering vtkImaging vtkIO vtkHybrid )</DIV>
<DIV>&nbsp;</DIV>
<DIV></FONT>&nbsp;</DIV></FONT></DIV></BODY></HTML>

------=_NextPart_000_003B_01C40CDB.9AA80410--