[Insight-users] Problem showing Dicom Image : where is the error?
charfeddine amir
charfeddine_amir at yahoo.fr
Wed Jan 18 09:56:40 EST 2006
hi All
I'm developping an application that reads the first serie of
Dicom images from a directory, show each image and save it
in bmp format.
the problem is that image series is well readed, and image
are well saved in bmp format, but image are not well showed
in the vtkrenderwindow used ( i get a black window with two
white line on it and not the image readed).
this code in the main file :
this function is for reading first series from a given
directory and showing it's first dicom image(invoked by
pushing the Read Directory button in the GUI)
void
migAppBase
::ReadImage()
{
// Can only read an image once
if(m_InputImage.IsNotNull())
return;
char* chooserName = fl_dir_chooser("select a dicom directory", 0, 0);
// Store the filename
strcpy( m_InputImageDirectoryname, chooserName );
reader = ReaderType::New();
dicomIO = ImageIOType::New();
nameGenerator = NamesGeneratorType::New();
reader->SetImageIO( dicomIO );
nameGenerator->SetUseSeriesDetails( true );
nameGenerator->SetDirectory( m_InputImageDirectoryname );
seriesUID = nameGenerator->GetSeriesUIDs();
seriesIdentifier = seriesUID.begin()->c_str();
fileNames = nameGenerator->GetFileNames( seriesIdentifier );
FileNamesItr = fileNames.begin ();
FileNamesEnd = fileNames.end();
rescaler = RescaleFilterType::New();
rescaler->SetOutputMinimum( 0 );
rescaler->SetOutputMaximum( 255 );
reader->SetFileName( FileNamesItr->c_str() );
try
{
rescaler->SetInput( reader->GetOutput() );
reader->Update();
m_InputImage = reader->GetOutput();
m_InputImage->SetRequestedRegionToLargestPossibleRegion();
// Create the input image VTK pipeline
this->CreateInputImageWindow();
}
catch (itk::ExceptionObject &ex)
{
}
FileNamesItr++;
}
this function is for reading the next image in the serie
(invoked by pushing the Read Next button in the GUI)
void
migAppBase
::ReadNext()
{
if ( FileNamesItr != FileNamesEnd )
{
reader->SetFileName( FileNamesItr->c_str() );
try
{
rescaler->SetInput( reader->GetOutput() );
m_InputImage = reader->GetOutput();
m_InputImage->SetRequestedRegionToLargestPossibleRegion();
reader->Update();
// Create the input image VTK pipeline
this->CreateInputImageWindow();
}
catch (itk::ExceptionObject &ex)
{
}
FileNamesItr++;
}
}
this function is for saving the actual image (that should
be showed in the vtk window) in bmp format (invoked by
pushing the save Image in the GUI)
void
migAppBase
::SaveImage()
{
Writer2Type::Pointer writer2 = Writer2Type::New();
std::string OutputFilename1 = FileNamesItr->c_str() + std::string(".bmp");
writer2->SetFileName( OutputFilename1.c_str() );
writer2->SetInput( rescaler->GetOutput() );
try
{
writer2->Update();
}
catch (itk::ExceptionObject & e)
{
}
}
this is the fuction for showing the actual image
void
migAppBase
::CreateInputImageWindow()
{
// If this is the first time we've hit Image Suivante there's other stuff
// that needs to happen
if(m_IsFirstUpdate)
{
// Display the output image
CreateWindowWithRWI(m_InputInteractor, m_InputWindow, "Input Image");
// these two steps are VERY IMPORTANT, you have to show() the fltk window
// containing the vtkFlRenderWindowInteractor, and then the
// vtkFlRenderWindowInteractor itself
m_InputWindow->show();
m_InputInteractor->show();
// now we get to setup our VTK rendering pipeline
CreateInputImageVTKPipeline(m_InputInteractor);
// No longer the first update
m_IsFirstUpdate = false;
}
else
{
// Refresh the output window if not the first update
// NB: doing this on the first update on Windows causes a new
// renderwindow to spawn (not sure why)
m_InputRenderWindow->Render();
}
}
function(s) for fltk and vtk interaction( creation of the
vtkrenderwindow and integrating it to the fltk window)
void
migAppBase
::CreateWindowWithRWI(vtkFlRenderWindowInteractor *&flrwi, Fl_Window *&flw, char *title)
{
// set up main FLTK window
flw = new Fl_Window(300,330,title);
// and instantiate vtkFlRenderWindowInteractor (here it acts like a
// FLTK window, i.e. you could also instantiate it as child of a
// Fl_Group in a window)
flrwi = new vtkFlRenderWindowInteractor(5,5,290,260,NULL);
// this will result in a little message under the rendering
Fl_Box* box = new Fl_Box(5,261,290,34,
"3 = stereo, j = joystick, t = trackball, "
"w = wireframe, s = surface, p = pick; "
"you can also resize the window");
box->labelsize(10);
box->align(FL_ALIGN_WRAP);
// we're done populating the flw
flw->end();
// if the main window gets resized, the vtk window should resize with it
flw->resizable(flrwi);
}
void
migAppBase
::CreateInputImageVTKPipeline(vtkFlRenderWindowInteractor *flrwi)
{
// Abort if the user is being stupid
if(m_InputImage.IsNull())
return;
// create a rendering window and renderer
m_InputRenderer = vtkRenderer::New();
m_InputRenderer->SetBackground(0.0, 0.0, 0.0);
m_InputRenderWindow = vtkRenderWindow::New();
m_InputRenderWindow->AddRenderer(m_InputRenderer);
// NB: here we treat the vtkFlRenderWindowInteractor just like any other
// old vtkRenderWindowInteractor
flrwi->SetRenderWindow(m_InputRenderWindow);
// Hook the VTK pipeline up to the ITK pipeline
m_InputImageITKtoVTKexporter = itk::VTKImageExport<InputImageType>::New();
m_InputImageVTKimporter = vtkImageImport::New();
m_InputImageITKtoVTKexporter->SetInput( m_InputImage );
ConnectPipelines(m_InputImageITKtoVTKexporter, m_InputImageVTKimporter);
// Need to update prior to creating the cutting planes
m_InputImageITKtoVTKexporter->Update();
m_InputImageVTKimporter->Update();
// Create the image cutting planes
m_InputImagePlaneX = vtkImagePlaneWidget::New();
m_InputImagePlaneX->RestrictPlaneToVolumeOn();
m_InputImagePlaneX->SetResliceInterpolateToCubic();
m_InputImagePlaneX->SetInput( (vtkDataSet*) m_InputImageVTKimporter->GetOutput() );
m_InputImagePlaneX->SetPlaneOrientationToXAxes();
m_InputImagePlaneX->SetSliceIndex( 0 );
m_InputImagePlaneY = vtkImagePlaneWidget::New();
m_InputImagePlaneY->RestrictPlaneToVolumeOn();
m_InputImagePlaneY->SetResliceInterpolateToCubic();
m_InputImagePlaneY->SetInput( (vtkDataSet*) m_InputImageVTKimporter->GetOutput() );
m_InputImagePlaneY->SetPlaneOrientationToYAxes();
m_InputImagePlaneY->SetSliceIndex( 0 );
// Set the position of the image planes to the center of the volume
this->ResetInputImagePlaneWidgets();
// Link the image planes to the interactor
m_InputImagePlaneX->SetInteractor( flrwi );
m_InputImagePlaneY->SetInteractor( flrwi );
// Turn on the image plane so they display
m_InputImagePlaneX->On();
m_InputImagePlaneY->On();
// just like with any other vtkRenderWindowInteractor(), you HAVE to call
// Initialize() before the interactor will function. See the docs in
// vtkRenderWindowInteractor.h
// This must occur AFTER the image planes have been added to the interactor
flrwi->Initialize();
// Clean up memory allocation (NB: not actually deleted until program returns)
m_InputRenderer->Delete();
m_InputRenderWindow->Delete();
}
thx for help
any comment is welcome
Amir
---------------------------------
Nouveau : téléphonez moins cher avec Yahoo! Messenger ! Découvez les tarifs exceptionnels pour appeler la France et l'international.Téléchargez la version beta.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20060118/1cc8cbe5/attachment-0001.htm
More information about the Insight-users
mailing list