1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
19 #ifndef VVTOOLINPUTSELECTORWIDGET_CXX
20 #define VVTOOLINPUTSELECTORWIDGET_CXX
23 #include <clitkImageCommon.h>
26 #include "vvLabelImageLoaderWidget.h"
27 #include "vvSlicerManager.h"
28 #include "vvImageReader.h"
29 #include "vvImageWriter.h"
32 #include <vtkImageData.h>
35 #include <QAbstractButton>
36 #include <QFileDialog>
37 #include <QMessageBox>
39 //------------------------------------------------------------------------------
40 vvLabelImageLoaderWidget::vvLabelImageLoaderWidget(QWidget * parent, Qt::WindowFlags f):
45 connect(mOpenButton, SIGNAL(clicked()), this, SLOT(OpenImage()));
47 //------------------------------------------------------------------------------
50 //------------------------------------------------------------------------------
51 vvImage::Pointer vvLabelImageLoaderWidget::GetImage()
55 //------------------------------------------------------------------------------
58 //------------------------------------------------------------------------------
59 double vvLabelImageLoaderWidget::GetBackgroundValue()
61 return mBackgroundValueSpinBox->value();
63 //------------------------------------------------------------------------------
66 //------------------------------------------------------------------------------
67 void vvLabelImageLoaderWidget::SetText(QString t)
69 mOpenLabel->setText(t);
71 //------------------------------------------------------------------------------
74 //------------------------------------------------------------------------------
75 void vvLabelImageLoaderWidget::OpenImage()
78 QString Extensions = "Images files ( *.mhd *.hdr *.his)";
79 Extensions += ";;All Files (*)";
81 QFileDialog::getOpenFileName(this,tr("Open mask image"),
82 "",Extensions); //mMainWindow->GetInputPathName()
83 if (filename == "") return; // nothing to do
85 itk::ImageIOBase::Pointer header = clitk::readImageHeader(filename.toStdString());
88 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
90 std::cerr << "Error while reading " << filename.toStdString() << std::endl;
91 QString error = QString("Cannot open file %1\n").arg(filename);
92 QMessageBox::information(this,tr("Reading problem"),error);
96 // Create output pointer
97 if (header->GetNumberOfDimensions() != 3) {
98 std::cerr << "Error while reading " << filename.toStdString() << std::endl;
100 error = QString("Cannot open file %1 because it is not 3D\n").arg(filename);
101 QMessageBox::information(this,tr("Reading problem"),error);
105 // Convert to unsigned char while reading (if not already)
106 typedef itk::ImageFileReader< itk::Image< unsigned char, 3 > > ReaderType;
107 ReaderType::Pointer reader = ReaderType::New();
108 reader->SetFileName(filename.toStdString());
112 m_Output = vvImage::New();
114 m_Output->AddItkImage( reader->GetOutput() );
116 catch ( itk::ExceptionObject & err ) {
117 std::cerr << "Error while reading " << filename.toStdString() << std::endl
118 << "The error is " << err << std::endl;
120 error = QString("Cannot open file %1\n").arg(filename);
121 QMessageBox::information(this,tr("Reading problem"),error);
126 mLabelInputInfo->setText(vtksys::SystemTools::GetFilenameName(filename.toStdString()).c_str());
127 QApplication::restoreOverrideCursor();
130 //------------------------------------------------------------------------------