From d6819bb51fcfa132af7e5d4253470ccf79db035e Mon Sep 17 00:00:00 2001 From: David Sarrut Date: Thu, 12 Jul 2012 09:59:46 +0200 Subject: [PATCH] First version of dicom-rt reader in the roi tool. --- common/clitkDicomRTStruct2ImageFilter.cxx | 41 +++++++++++++++++ common/clitkDicomRTStruct2ImageFilter.h | 2 + tools/clitkDicomRTStruct2Image.cxx | 2 +- vv/vvToolROIManager.cxx | 56 +++++++++++++++++++++-- 4 files changed, 96 insertions(+), 5 deletions(-) diff --git a/common/clitkDicomRTStruct2ImageFilter.cxx b/common/clitkDicomRTStruct2ImageFilter.cxx index 1541cb2..fa66cfb 100644 --- a/common/clitkDicomRTStruct2ImageFilter.cxx +++ b/common/clitkDicomRTStruct2ImageFilter.cxx @@ -49,10 +49,22 @@ clitk::DicomRTStruct2ImageFilter::~DicomRTStruct2ImageFilter() } //-------------------------------------------------------------------- + +//-------------------------------------------------------------------- bool clitk::DicomRTStruct2ImageFilter::ImageInfoIsSet() const { return mSize.size() && mSpacing.size() && mOrigin.size(); } +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +void clitk::DicomRTStruct2ImageFilter::SetWriteOutputFlag(bool b) +{ + mWriteOutput = b; +} +//-------------------------------------------------------------------- + //-------------------------------------------------------------------- void clitk::DicomRTStruct2ImageFilter::SetROI(clitk::DicomRT_ROI * roi) @@ -79,6 +91,25 @@ void clitk::DicomRTStruct2ImageFilter::SetOutputImageFilename(std::string s) //-------------------------------------------------------------------- +//-------------------------------------------------------------------- +void clitk::DicomRTStruct2ImageFilter::SetImage(vvImage::Pointer image) +{ + if (image->GetNumberOfDimensions() != 3) { + std::cerr << "Error. Please provide a 3D image." << std::endl; + exit(0); + } + mSpacing.resize(3); + mOrigin.resize(3); + mSize.resize(3); + for(unsigned int i=0; i<3; i++) { + mSpacing[i] = image->GetSpacing()[i]; + mOrigin[i] = image->GetOrigin()[i]; + mSize[i] = image->GetSize()[i]; + } +} +//-------------------------------------------------------------------- + + //-------------------------------------------------------------------- void clitk::DicomRTStruct2ImageFilter::SetImageFilename(std::string f) { @@ -101,20 +132,30 @@ void clitk::DicomRTStruct2ImageFilter::SetImageFilename(std::string f) } //-------------------------------------------------------------------- + +//-------------------------------------------------------------------- void clitk::DicomRTStruct2ImageFilter::SetOutputOrigin(const double* origin) { std::copy(origin,origin+3,std::back_inserter(mOrigin)); } +//-------------------------------------------------------------------- + + //-------------------------------------------------------------------- void clitk::DicomRTStruct2ImageFilter::SetOutputSpacing(const double* spacing) { std::copy(spacing,spacing+3,std::back_inserter(mSpacing)); } +//-------------------------------------------------------------------- + + //-------------------------------------------------------------------- void clitk::DicomRTStruct2ImageFilter::SetOutputSize(const unsigned long* size) { std::copy(size,size+3,std::back_inserter(mSize)); } +//-------------------------------------------------------------------- + //-------------------------------------------------------------------- void clitk::DicomRTStruct2ImageFilter::Update() diff --git a/common/clitkDicomRTStruct2ImageFilter.h b/common/clitkDicomRTStruct2ImageFilter.h index 1add60e..8f6045a 100644 --- a/common/clitkDicomRTStruct2ImageFilter.h +++ b/common/clitkDicomRTStruct2ImageFilter.h @@ -37,6 +37,7 @@ namespace clitk { void SetROI(clitk::DicomRT_ROI * roi); ///This is used to create a mask with the same characteristics as an input image + void SetImage(vvImage::Pointer image); void SetImageFilename(std::string s); void SetOutputOrigin(const double* origin); void SetOutputSpacing(const double* spacing); @@ -46,6 +47,7 @@ namespace clitk { vtkImageData * GetOutput(); template typename itk::Image::ConstPointer GetITKOutput(); void SetCropMaskEnabled(bool b); + void SetWriteOutputFlag(bool b); protected: bool ImageInfoIsSet() const; diff --git a/tools/clitkDicomRTStruct2Image.cxx b/tools/clitkDicomRTStruct2Image.cxx index cc23126..88d480d 100644 --- a/tools/clitkDicomRTStruct2Image.cxx +++ b/tools/clitkDicomRTStruct2Image.cxx @@ -41,7 +41,7 @@ int main(int argc, char * argv[]) { if (args_info.roi_arg != -1) { filter.SetROI(s->GetROIFromROINumber(args_info.roi_arg)); filter.SetOutputImageFilename(args_info.output_arg); - filter.Update(); + filter.Update(); } else { clitk::DicomRT_StructureSet::ROIConstIteratorType iter; diff --git a/vv/vvToolROIManager.cxx b/vv/vvToolROIManager.cxx index 7382746..809a3c5 100644 --- a/vv/vvToolROIManager.cxx +++ b/vv/vvToolROIManager.cxx @@ -19,6 +19,7 @@ // vv #include "vvToolROIManager.h" #include "vvImageReader.h" +#include "vvImageWriter.h" #include "vvROIActor.h" #include "vvSlicer.h" #include "vvROIActor.h" @@ -26,6 +27,10 @@ #include "vvStructSelector.h" #include "vvToolManager.h" +// clitk +#include "clitkDicomRTStruct2ImageFilter.h" +#include "clitkDicomRT_StructureSet.h" + // Qt #include #include @@ -63,7 +68,7 @@ vvToolROIManager::vvToolROIManager(vvMainWindowBase * parent, Qt::WindowFlags f) mGroupBoxROI->setEnabled(false); // Temporary disable "Load dicom" button - frame_4->hide(); + // frame_4->hide(); // Set default LUT mDefaultLUTColor = vtkSmartPointer::New(); @@ -290,12 +295,14 @@ void vvToolROIManager::SelectedImageHasChanged(vvSlicerManager * m) { void vvToolROIManager::OpenBinaryImage() { // Open images - QString Extensions = "Images files ( *.mha *.mhd *.hdr *.his)"; + QString Extensions = "Images or Dicom-Struct files ( *.mha *.mhd *.hdr *.his *.dcm RS*)"; Extensions += ";;All Files (*)"; QStringList filename = QFileDialog::getOpenFileNames(this,tr("Open binary image"), mMainWindowBase->GetInputPathName(),Extensions); - OpenBinaryImage(filename); + if (filename.size() > 1) OpenBinaryImage(filename); + if (filename.size() == 0) return; + } //------------------------------------------------------------------------------ @@ -361,7 +368,48 @@ void vvToolROIManager::OpenDicomImage() QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); reader.SetSelectedItems(selector.getSelectedItems()); reader.SetImage(mCurrentSlicerManager->GetImage()); - reader.Update(); + // reader.Update(); + + // Read and display information + clitk::DicomRT_StructureSet::Pointer s = clitk::DicomRT_StructureSet::New(); + s->Read(file.toStdString()); + s->Print(std::cout); + + // FIXME -> selection + + DD("here"); + clitk::DicomRTStruct2ImageFilter filter; + filter.SetCropMaskEnabled(true); // FIXME + filter.SetImage(mCurrentImage); // Used FIXME -> change to set IMAGE + filter.SetROI(s->GetROIFromROINumber(1)); // FIXME selection + filter.SetWriteOutputFlag(false); + filter.Update(); + + DD("debug"); + typedef itk::Image ImageType; + typedef itk::VTKImageToImageFilter ConnectorType; + ConnectorType::Pointer connector = ConnectorType::New(); + connector->SetInput(filter.GetOutput()); + connector->Update(); + clitk::writeImage(connector->GetOutput(), "toto.mha"); + + // Get image + DD("filter done"); + vvImage::Pointer binaryImage = vvImage::New(); + binaryImage->AddVtkImage(filter.GetOutput()); + + // DEBUG write image + DD("write debug"); + vvImageWriter::Pointer writer = vvImageWriter::New(); + writer->SetOutputFileName("bidon.mha"); + writer->SetInput(binaryImage); + writer->Update(); + + // Add to gui + DD("gui"); + AddImage(binaryImage, file.toStdString(), mBackgroundValueSpinBox->value(), + (!mBGModeCheckBox->isChecked())); + mOpenedBinaryImageFilenames.push_back(file); // std::vector contours=reader.GetOutput(); // for (std::vector::iterator i=contours.begin(); -- 2.47.1