From: dsarrut Date: Wed, 7 Jul 2010 07:10:16 +0000 (+0000) Subject: widget to load binary image X-Git-Tag: v1.2.0~551 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=558ee3aac5989966a5695cf1ab361317bccfcc4a;p=clitk.git widget to load binary image --- diff --git a/vv/vvLabelImageLoaderWidget.cxx b/vv/vvLabelImageLoaderWidget.cxx new file mode 100644 index 0000000..b10f00f --- /dev/null +++ b/vv/vvLabelImageLoaderWidget.cxx @@ -0,0 +1,129 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +======================================================================-====*/ +#ifndef VVTOOLINPUTSELECTORWIDGET_CXX +#define VVTOOLINPUTSELECTORWIDGET_CXX + +// vv +#include "vvLabelImageLoaderWidget.h" +#include "vvSlicerManager.h" +#include "vvImageReader.h" +#include "vvImageWriter.h" + +// vtk +#include + +// qt +#include +#include +#include + +//------------------------------------------------------------------------------ +vvLabelImageLoaderWidget::vvLabelImageLoaderWidget(QWidget * parent, Qt::WindowFlags f): + QWidget(parent, f) +{ + setupUi(this); + setEnabled(true); + connect(mOpenButton, SIGNAL(clicked()), this, SLOT(OpenImage())); +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +vvImage::Pointer vvLabelImageLoaderWidget::GetImage() +{ + return m_Output; +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +double vvLabelImageLoaderWidget::GetBackgroundValue() +{ + return mBackgroundValueSpinBox->value(); +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvLabelImageLoaderWidget::OpenImage() +{ + DD("OpenImage"); + + // Browse for file + QString Extensions = "Images files ( *.mhd *.hdr *.his)"; + Extensions += ";;All Files (*)"; + QString filename = + QFileDialog::getOpenFileName(this,tr("Open mask image"), + "",Extensions); //mMainWindow->GetInputPathName() + if (filename == "") return; // nothing to do + + // Open Image + vvImageReader * mReader = new vvImageReader; + mReader->SetInputFilename(filename.toStdString()); + mReader->Update(IMAGE); + if (mReader->GetLastError().size() != 0) { + std::cerr << "Error while reading " << filename.toStdString() << std::endl; + QString error = "Cannot open file \n"; + error += mReader->GetLastError().c_str(); + QMessageBox::information(this,tr("Reading problem"),error); + delete mReader; + return; + } + + // Create output pointer + m_Output = vvImage::New(); + + // Check type and convert if needed + vvImage::Pointer temp = mReader->GetOutput(); + + if (temp->GetNumberOfDimensions() != 3) { + std::cerr << "Error while reading " << filename.toStdString() << std::endl; + QString error; + error = QString("Cannot open file %1 because it is not 3D\n").arg(filename); + QMessageBox::information(this,tr("Reading problem"),error); + delete mReader; + return; + } + + DD(temp->GetScalarTypeAsITKString()); + if (temp->GetScalarTypeAsITKString() != "unsigned_char") { + DD("Cast"); + vtkImageData * p = vtkImageData::New(); + p->SetExtent(temp->GetFirstVTKImageData()->GetExtent ()); // Only first ! could not be 4D + p->SetScalarTypeToUnsignedChar(); + p->AllocateScalars (); + p->CopyAndCastFrom(temp->GetFirstVTKImageData(), temp->GetFirstVTKImageData()->GetExtent ()); + m_Output->AddImage(p); + vvImageWriter * writer = new vvImageWriter; + writer->SetOutputFileName("a.mhd"); + writer->SetInput(m_Output); + writer->Update(); + } + else { + m_Output = temp; + } + + // Set GUI + mLabelInputInfo->setText(vtksys::SystemTools::GetFilenameName(filename.toStdString()).c_str()); + emit accepted(); +} +//------------------------------------------------------------------------------ + + +#endif + diff --git a/vv/vvLabelImageLoaderWidget.h b/vv/vvLabelImageLoaderWidget.h new file mode 100644 index 0000000..1e0d25b --- /dev/null +++ b/vv/vvLabelImageLoaderWidget.h @@ -0,0 +1,56 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +======================================================================-====*/ +#ifndef VVLABELIMAGELOADERWIDGET_H +#define VVLABELIMAGELOADERWIDGET_H + +// vv +#include "vvImage.h" + +// qt +#include +#include +#include "ui_vvLabelImageLoaderWidget.h" + +class vvSlicerManager; + +//------------------------------------------------------------------------------ +class vvLabelImageLoaderWidget: public QWidget, private Ui::vvLabelImageLoaderWidget +{ + Q_OBJECT + public: + vvLabelImageLoaderWidget(QWidget * parent=0, Qt::WindowFlags f=0); + ~vvLabelImageLoaderWidget() {} + + vvImage::Pointer GetImage(); + double GetBackgroundValue(); + +signals: + void accepted(); + +protected: + Ui::vvLabelImageLoaderWidget ui; + vvImage::Pointer m_Output; + + protected slots: + void OpenImage(); + +}; // end class vvLabelImageLoaderWidget +//------------------------------------------------------------------------------ + +#endif +