7 #include <itkImageToVTKImageFilter.h>
8 #include <itkImageFileReader.h>
10 #include <vtkCellArray.h>
11 #include <vtkFloatArray.h>
12 #include <vtkPointData.h>
13 #include <vtkPoints.h>
14 #include <vtkPolyData.h>
15 #include <vtkSmartPointer.h>
17 #include <fpa/VTK/ImageMPR.h>
19 // -------------------------------------------------------------------------
20 const unsigned int Dimension = 3;
23 typedef itk::Image< TPixel, Dimension > TImage;
25 // -------------------------------------------------------------------------
26 int main( int argc, char* argv[] )
31 << "Usage: " << argv[ 0 ]
32 << " input_image input_seeds"
37 std::string input_image_fn = argv[ 1 ];
38 std::string input_seeds_fn = argv[ 2 ];
41 itk::ImageFileReader< TImage >::Pointer input_image_reader =
42 itk::ImageFileReader< TImage >::New( );
43 input_image_reader->SetFileName( input_image_fn );
46 input_image_reader->Update( );
48 catch( itk::ExceptionObject& err )
50 std::cerr << "Error caugth: " << err << std::endl;
54 TImage::ConstPointer input_image = input_image_reader->GetOutput( );
55 itk::ImageToVTKImageFilter< TImage >::Pointer input_image_vtk =
56 itk::ImageToVTKImageFilter< TImage >::New( );
57 input_image_vtk->SetInput( input_image );
58 input_image_vtk->Update( );
61 std::ifstream input_seeds_fs( input_seeds_fn.c_str( ) );
65 << "Error opening file \"" << input_seeds_fn << "\"" << std::endl;
72 unsigned int number_of_points;
73 input_seeds_fs >> str_val >> number_of_points;
74 input_seeds_fs >> str_val; // X
75 input_seeds_fs >> str_val; // Y
76 input_seeds_fs >> str_val; // Z
77 input_seeds_fs >> str_val; // value
78 input_seeds_fs >> str_val; // Label
80 vtkSmartPointer< vtkPoints > input_seeds_points =
81 vtkSmartPointer< vtkPoints >::New( );
82 vtkSmartPointer< vtkCellArray > input_seeds_cells =
83 vtkSmartPointer< vtkCellArray >::New( );
84 vtkSmartPointer< vtkFloatArray > input_seeds_ids =
85 vtkSmartPointer< vtkFloatArray >::New( );
87 input_seeds_ids->SetNumberOfComponents( 1 );
88 input_seeds_ids->SetNumberOfTuples( number_of_points );
90 double min_value = std::numeric_limits< double >::max( );
91 double max_value = double( 0 );
92 for( unsigned int i = 0; i < number_of_points; ++i )
96 input_seeds_fs >> x >> y >> z >> value >> str_val;
98 min_value = ( value < min_value )? value: min_value;
99 max_value = ( value > max_value )? value: max_value;
101 TImage::IndexType idx;
105 TImage::PointType pnt;
106 input_image->TransformIndexToPhysicalPoint( idx, pnt );
108 input_seeds_points->InsertNextPoint( pnt[ 0 ], pnt[ 1 ], pnt[ 2 ] );
109 input_seeds_cells->InsertNextCell( 1 );
110 input_seeds_cells->InsertCellPoint( i );
111 input_seeds_ids->SetTuple1(
112 i, double( i ) / double( number_of_points - 1 )
117 input_seeds_fs.close( );
119 vtkSmartPointer< vtkPolyData > input_seeds =
120 vtkSmartPointer< vtkPolyData >::New( );
121 input_seeds->SetPoints( input_seeds_points );
122 input_seeds->SetVerts( input_seeds_cells );
123 input_seeds->GetPointData( )->SetScalars( input_seeds_ids );
125 // Show input image and let some interaction
126 fpa::VTK::ImageMPR view;
127 view.SetBackground( 0.3, 0.2, 0.8 );
128 view.SetSize( 600, 600 );
129 view.SetImage( input_image_vtk->GetOutput( ) );
131 max_value - min_value,
132 ( min_value + max_value ) / double( 2 )
134 view.AddPolyData( input_seeds );