From 794be53b8efec2ddb9c3097efd559c514fb4a813 Mon Sep 17 00:00:00 2001 From: David Sarrut Date: Wed, 12 Jun 2013 16:56:33 +0200 Subject: [PATCH] Allow to insert several images/contours at one time --- common/clitkImage2DicomRTStructFilter.h | 8 +-- common/clitkImage2DicomRTStructFilter.txx | 73 ++++++++++++++++------- tools/clitkImage2DicomRTStruct.cxx | 13 ++-- tools/clitkImage2DicomRTStruct.ggo | 3 +- 4 files changed, 64 insertions(+), 33 deletions(-) diff --git a/common/clitkImage2DicomRTStructFilter.h b/common/clitkImage2DicomRTStructFilter.h index 924bcc0..d570934 100644 --- a/common/clitkImage2DicomRTStructFilter.h +++ b/common/clitkImage2DicomRTStructFilter.h @@ -41,25 +41,23 @@ namespace clitk { typedef typename clitk::DicomRT_StructureSet::Pointer DicomRTStructPointer; // Set inputs - itkSetMacro(Input, ImagePointer); - itkGetConstMacro(Input, ImagePointer); + itkSetMacro(InputFilenames, std::vector ); itkSetMacro(StructureSetFilename, std::string); itkSetMacro(DicomFolder, std::string); itkSetMacro(OutputFilename, std::string); - void SetROIName(std::string name, std::string type); + void SetROIType(std::string type); itkSetMacro(ThresholdValue, PixelType); // Run filter void Update(); protected: - ImagePointer m_Input; std::string m_StructureSetFilename; std::string m_DicomFolder; std::string m_OutputFilename; - std::string m_ROIName; std::string m_ROIType; PixelType m_ThresholdValue; + std::vector m_InputFilenames; }; //-------------------------------------------------------------------- diff --git a/common/clitkImage2DicomRTStructFilter.txx b/common/clitkImage2DicomRTStructFilter.txx index 1b241a9..248451d 100644 --- a/common/clitkImage2DicomRTStructFilter.txx +++ b/common/clitkImage2DicomRTStructFilter.txx @@ -45,6 +45,7 @@ #include "vtkCamera.h" #include "vtkProperty.h" #include "vtkProperty2D.h" +#include // itk #include @@ -76,9 +77,8 @@ clitk::Image2DicomRTStructFilter::~Image2DicomRTStructFilter() //-------------------------------------------------------------------- template void -clitk::Image2DicomRTStructFilter::SetROIName(std::string name, std::string type) +clitk::Image2DicomRTStructFilter::SetROIType(std::string type) { - m_ROIName = name; m_ROIType = type; } //-------------------------------------------------------------------- @@ -112,9 +112,13 @@ void clitk::Image2DicomRTStructFilter::Update() << p->GetNumberOfStructureSetROIs() << std::endl; } + + // number of additional contours + int m = m_InputFilenames.size(); + // Init writer vtkGDCMPolyDataWriter * writer = vtkGDCMPolyDataWriter::New(); - int numMasks = reader->GetNumberOfOutputPorts() + 1;//add one more + int numMasks = reader->GetNumberOfOutputPorts() + m; writer->SetNumberOfInputPorts(numMasks); writer->SetFileName(m_OutputFilename.c_str()); writer->SetMedicalImageProperties(reader->GetMedicalImageProperties()); @@ -128,18 +132,46 @@ void clitk::Image2DicomRTStructFilter::Update() roiTypes->SetNumberOfValues(numMasks); // Convert the image into a mesh - typedef clitk::BinaryImageToMeshFilter BinaryImageToMeshFilterType; - typename BinaryImageToMeshFilterType::Pointer convert = BinaryImageToMeshFilterType::New(); - convert->SetThresholdValue(m_ThresholdValue); - convert->SetInput(m_Input); - convert->Update(); - vtkPolyData* mesh = convert->GetOutputMesh(); - if (GetVerboseFlag()) { - std::cout << "Mesh has " << mesh->GetNumberOfLines() << " lines." << std::endl; + std::vector > meshes; + std::vector m_ROINames; + meshes.resize(m); + m_ROINames.resize(m); + for(unsigned int i=0; i ImageType; + ImagePointer input = clitk::readImage(m_InputFilenames[i], false); + + std::ostringstream oss; + oss << vtksys::SystemTools:: + GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(m_InputFilenames[i])); + std::string name = oss.str(); + m_ROINames[i] = name; + + // convert to mesh + typedef clitk::BinaryImageToMeshFilter BinaryImageToMeshFilterType; + typename BinaryImageToMeshFilterType::Pointer convert = BinaryImageToMeshFilterType::New(); + convert->SetThresholdValue(m_ThresholdValue); + convert->SetInput(input); + convert->Update(); + meshes[i] = convert->GetOutputMesh(); + if (GetVerboseFlag()) { + std::cout << "Mesh has " << meshes[i]->GetNumberOfLines() << " lines." << std::endl; + } + + /* + // debug mesh write FIXME + vtkSmartPointer wr = vtkSmartPointer::New(); + wr->SetInputConnection(convert->GetOutputPort()); //psurface->GetOutputPort() + wr->SetFileName("bidon.obj"); + wr->Update(); + wr->Write(); + */ } - + // Copy previous contours - for (unsigned int i = 0; i < numMasks-1; ++i) { + for (unsigned int i = 0; i < numMasks-m; ++i) { writer->SetInput(i, reader->GetOutput(i)); std::string theString = reader->GetRTStructSetProperties()->GetStructureSetROIName(i); roiNames->InsertValue(i, theString); @@ -149,13 +181,14 @@ void clitk::Image2DicomRTStructFilter::Update() roiTypes->InsertValue(i, theString); } - // Add new one - int last = numMasks-1; - writer->SetInput(last, mesh); - roiNames->InsertValue(last, m_ROIName); - roiAlgorithms->InsertValue(last, "CLITK_CREATED"); - roiTypes->InsertValue(last, m_ROIType); - + // Add new ones + for (unsigned int i = numMasks-m; i < numMasks; ++i) { + writer->SetInput(i, meshes[i-numMasks+m]); + roiNames->InsertValue(i, m_ROINames[i-numMasks+m]); + roiAlgorithms->InsertValue(i, "CLITK_CREATED"); + roiTypes->InsertValue(i, m_ROIType); + } + /* // Visu DEBUG vtkPolyDataMapper *cubeMapper = vtkPolyDataMapper::New(); diff --git a/tools/clitkImage2DicomRTStruct.cxx b/tools/clitkImage2DicomRTStruct.cxx index 264eb05..a82b0ec 100644 --- a/tools/clitkImage2DicomRTStruct.cxx +++ b/tools/clitkImage2DicomRTStruct.cxx @@ -27,19 +27,20 @@ int main(int argc, char * argv[]) { // Init command line GGO(clitkImage2DicomRTStruct, args_info); - // Read initial 3D image - typedef float PixelType; - typedef itk::Image ImageType; - ImageType::Pointer input = clitk::readImage(args_info.input_arg, args_info.verbose_flag); + // Set initial 3D image filenames + std::vector filenames; + for(unsigned int i=0; i< args_info.input_given; i++) + filenames.push_back(args_info.input_arg[i]); // Create a filter to convert image into dicomRTStruct and write to disk + typedef float PixelType; clitk::Image2DicomRTStructFilter filter; filter.SetVerboseFlag(args_info.verbose_flag); - filter.SetInput(input); + filter.SetInputFilenames(filenames); filter.SetDicomFolder(args_info.dicom_arg); filter.SetStructureSetFilename(args_info.rtstruct_arg); filter.SetOutputFilename(args_info.output_arg); - filter.SetROIName(args_info.roiname_arg, args_info.roitype_arg); + filter.SetROIType(args_info.roitype_arg); filter.SetThresholdValue(args_info.threshold_arg); filter.Update(); diff --git a/tools/clitkImage2DicomRTStruct.ggo b/tools/clitkImage2DicomRTStruct.ggo index 928d11b..70f85b2 100644 --- a/tools/clitkImage2DicomRTStruct.ggo +++ b/tools/clitkImage2DicomRTStruct.ggo @@ -5,12 +5,11 @@ version "Add a (binary) image inside a DICOM RT Structure Set (contours)" option "config" - "Config file" string no option "verbose" v "Verbose" flag off -option "input" i "Input image file (binary image) to be converted into contours" string yes +option "input" i "Input image file (binary image) to be converted into contours" string multiple yes option "rtstruct" r "Input rt struct" string yes option "dicom" d "Input folder where the initial dicom ct is" string yes option "output" o "Output DicomRT filename" string yes option "threshold" t "Threshold for binary image" float no default = "0.5" -option "roiname" - "Name of the roi added into the rt-struct" string yes option "roitype" - "Name of the type of roi added into the rt-struct" string no default = "ORGAN" -- 2.47.1