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 "vvLabelImageLoaderWidget.h"
24 #include "vvSlicerManager.h"
25 #include "vvImageReader.h"
26 #include "vvImageWriter.h"
29 #include <vtkImageData.h>
32 #include <QAbstractButton>
33 #include <QFileDialog>
34 #include <QMessageBox>
36 //------------------------------------------------------------------------------
37 vvLabelImageLoaderWidget::vvLabelImageLoaderWidget(QWidget * parent, Qt::WindowFlags f):
42 connect(mOpenButton, SIGNAL(clicked()), this, SLOT(OpenImage()));
44 //------------------------------------------------------------------------------
47 //------------------------------------------------------------------------------
48 vvImage::Pointer vvLabelImageLoaderWidget::GetImage()
52 //------------------------------------------------------------------------------
55 //------------------------------------------------------------------------------
56 double vvLabelImageLoaderWidget::GetBackgroundValue()
58 return mBackgroundValueSpinBox->value();
60 //------------------------------------------------------------------------------
63 //------------------------------------------------------------------------------
64 void vvLabelImageLoaderWidget::SetText(QString t)
66 mOpenLabel->setText(t);
68 //------------------------------------------------------------------------------
71 //------------------------------------------------------------------------------
72 void vvLabelImageLoaderWidget::OpenImage()
75 QString Extensions = "Images files ( *.mhd *.hdr *.his)";
76 Extensions += ";;All Files (*)";
78 QFileDialog::getOpenFileName(this,tr("Open mask image"),
79 "",Extensions); //mMainWindow->GetInputPathName()
80 if (filename == "") return; // nothing to do
83 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
84 vvImageReader * mReader = new vvImageReader;
85 mReader->SetInputFilename(filename.toStdString());
86 mReader->Update(IMAGE);
87 if (mReader->GetLastError().size() != 0) {
88 std::cerr << "Error while reading " << filename.toStdString() << std::endl;
89 QString error = "Cannot open file \n";
90 error += mReader->GetLastError().c_str();
91 QMessageBox::information(this,tr("Reading problem"),error);
96 // Create output pointer
97 m_Output = vvImage::New();
99 // Check type and convert if needed
100 vvImage::Pointer temp = mReader->GetOutput();
102 if (temp->GetNumberOfDimensions() != 3) {
103 std::cerr << "Error while reading " << filename.toStdString() << std::endl;
105 error = QString("Cannot open file %1 because it is not 3D\n").arg(filename);
106 QMessageBox::information(this,tr("Reading problem"),error);
111 if (temp->GetScalarTypeAsITKString() != "unsigned_char") {
112 vtkImageData * p = vtkImageData::New();
113 p->SetExtent(temp->GetFirstVTKImageData()->GetExtent ()); // Only first ! could not be 4D
114 p->SetScalarTypeToUnsignedChar();
115 p->AllocateScalars ();
116 p->CopyAndCastFrom(temp->GetFirstVTKImageData(), temp->GetFirstVTKImageData()->GetExtent ());
117 m_Output->AddImage(p);
118 vvImageWriter * writer = new vvImageWriter;
119 writer->SetOutputFileName("a.mhd");
120 writer->SetInput(m_Output);
128 mLabelInputInfo->setText(vtksys::SystemTools::GetFilenameName(filename.toStdString()).c_str());
129 QApplication::restoreOverrideCursor();
132 //------------------------------------------------------------------------------