]> Creatis software - clitk.git/commitdiff
First version of dicom-rt reader in the roi tool.
authorDavid Sarrut <david.sarrut@gmail.com>
Thu, 12 Jul 2012 07:59:46 +0000 (09:59 +0200)
committerDavid Sarrut <david.sarrut@gmail.com>
Thu, 12 Jul 2012 07:59:46 +0000 (09:59 +0200)
common/clitkDicomRTStruct2ImageFilter.cxx
common/clitkDicomRTStruct2ImageFilter.h
tools/clitkDicomRTStruct2Image.cxx
vv/vvToolROIManager.cxx

index 1541cb28f46f794e1ad274e12cb8c94c33bf9313..fa66cfb31361de6d96bea75d01676c0295901b67 100644 (file)
@@ -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()
index 1add60e469c5ccab31a9221cb732d87f00348389..8f6045ae1e2b7100524464a6ee85c1faccde2a94 100644 (file)
@@ -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 <int Dimension> typename itk::Image<unsigned char,Dimension>::ConstPointer GetITKOutput();
     void SetCropMaskEnabled(bool b);
+    void SetWriteOutputFlag(bool b);
 
   protected:
     bool ImageInfoIsSet() const;
index cc231260f29c57287738efb1b3fee641884f0afe..88d480d1f625d9016beff80ec72e256191a22efd 100644 (file)
@@ -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;
index 738274667a43126eec48d244b2e51114b952ebd1..809a3c54512ac9a3b3da8cb49e15c31e7f3bd451 100644 (file)
@@ -19,6 +19,7 @@
 // vv
 #include "vvToolROIManager.h"
 #include "vvImageReader.h"
+#include "vvImageWriter.h"
 #include "vvROIActor.h"
 #include "vvSlicer.h"
 #include "vvROIActor.h"
 #include "vvStructSelector.h"
 #include "vvToolManager.h"
 
+// clitk
+#include "clitkDicomRTStruct2ImageFilter.h"
+#include "clitkDicomRT_StructureSet.h"
+
 // Qt
 #include <QFileDialog>
 #include <QMessageBox>
@@ -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<vtkLookupTable>::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<unsigned char, 3> ImageType;
+    typedef itk::VTKImageToImageFilter<ImageType> ConnectorType;
+    ConnectorType::Pointer connector = ConnectorType::New();
+    connector->SetInput(filter.GetOutput());
+    connector->Update();
+    clitk::writeImage<ImageType>(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<vvMesh::Pointer> contours=reader.GetOutput();
     // for (std::vector<vvMesh::Pointer>::iterator i=contours.begin();