X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=common%2FclitkImage2DicomRTStructFilter.txx;h=77c5e07044f1684b502021b8196c13ec15c5c975;hb=5c75da348b0f9d26a5d93ca563ae51761c2fffb8;hp=051211b6d0d325fa882875b86fc02f861035f8b3;hpb=93b8df062a36ca152f3cb20d08ea9b9ce9c1e45f;p=clitk.git diff --git a/common/clitkImage2DicomRTStructFilter.txx b/common/clitkImage2DicomRTStructFilter.txx index 051211b..77c5e07 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 @@ -61,6 +62,7 @@ clitk::Image2DicomRTStructFilter::Image2DicomRTStructFilter() m_DicomFolder = ""; m_OutputFilename = "default-output.dcm"; m_ThresholdValue = 0.5; + m_SkipInitialStructuresFlag = false; } //-------------------------------------------------------------------- @@ -76,9 +78,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; } //-------------------------------------------------------------------- @@ -88,10 +89,22 @@ clitk::Image2DicomRTStructFilter::SetROIName(std::string name, std::s template void clitk::Image2DicomRTStructFilter::Update() { + // Check this is a RT-Struct + gdcm::Reader gdcm_reader; + gdcm_reader.SetFileName(m_StructureSetFilename.c_str()); + if (!gdcm_reader.Read()) { + clitkExceptionMacro("Error could not open the file '" << m_StructureSetFilename << std::endl); + } + gdcm::MediaStorage ms; + ms.SetFromFile(gdcm_reader.GetFile()); + if (ms != gdcm::MediaStorage::RTStructureSetStorage) { + clitkExceptionMacro("File '" << m_StructureSetFilename << "' is not a DICOM-RT-Struct file." << std::endl); + } + // Read rt struct vtkSmartPointer reader = vtkGDCMPolyDataReader::New(); reader->SetFileName(m_StructureSetFilename.c_str()); - reader->Update(); + reader->Update(); // Get properties vtkRTStructSetProperties * p = reader->GetRTStructSetProperties(); @@ -100,9 +113,18 @@ 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; + + if (m_SkipInitialStructuresFlag) { + numMasks = m; + } + writer->SetNumberOfInputPorts(numMasks); writer->SetFileName(m_OutputFilename.c_str()); writer->SetMedicalImageProperties(reader->GetMedicalImageProperties()); @@ -116,18 +138,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); @@ -137,13 +187,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();