From 49c07b7152335b7cc8a054629783e9f5ef337a85 Mon Sep 17 00:00:00 2001 From: David Sarrut Date: Mon, 3 Jun 2013 13:55:25 +0200 Subject: [PATCH] First version of clitkImage2DicomRTStruct --- tests_dav/clitkImage2DicomRTStruct.cxx | 173 ++++++++++++++++++++++++- tests_dav/clitkImage2DicomRTStruct.ggo | 7 +- 2 files changed, 174 insertions(+), 6 deletions(-) diff --git a/tests_dav/clitkImage2DicomRTStruct.cxx b/tests_dav/clitkImage2DicomRTStruct.cxx index d71491b..b5916cf 100644 --- a/tests_dav/clitkImage2DicomRTStruct.cxx +++ b/tests_dav/clitkImage2DicomRTStruct.cxx @@ -21,25 +21,192 @@ #include "clitkDicomRT_StructureSet.h" #include "clitkImage2DicomRTStruct_ggo.h" +#include +#include +#include +#include +#include +#include + //-------------------------------------------------------------------- int main(int argc, char * argv[]) { // Init command line GGO(clitkImage2DicomRTStruct, args_info); + // // Read + // DD("read"); + // vtkSmartPointer reader = vtkGDCMPolyDataReader::New(); + // reader->SetFileName(args_info.rtstruct_arg); + // reader->Update(); + // DD("reader done"); + + // //====================================== + // // access to properties + // vtkRTStructSetProperties * p = reader->GetRTStructSetProperties(); + // DD(p->GetNumberOfStructureSetROIs()); + // DD(p->GetStructureSetROIName(0)); + // DD(p->GetStructureSetROINumber(0)); + + + // //====================================== + // // Test read binary image, convert to polydata + // typedef float PixelType; + // typedef itk::Image ImageType; + // ImageType::Pointer input_itk = clitk::readImage(args_info.input_arg, true); + // vvImage::Pointer input_vv = vvImageFromITK<3, PixelType>(input_itk); + // vtkImageData * input_vtk = input_vv->GetVTKImages()[0]; + + // vtkSmartPointer clipper = vtkSmartPointer::New(); + // clipper->SetInput(input_vtk); + // int* extent = input_vtk->GetExtent(); + // DDV(extent, 6); + // clipper->Delete(); + + // uint n = input_vtk->GetDimensions()[2]; + // DD(n); + // std::vector > contours; + // for(uint i=0; i squares = vtkSmartPointer::New(); + // squares->SetInput(input_vtk); + // squares->SetImageRange(extent[0], extent[1], extent[2], extent[3], i, i); + // squares->SetValue(1, 1.0); + // squares->Update(); + // // DD(squares->GetNumberOfContours()); + + // vtkSmartPointer m = squares->GetOutput(); + // contours.push_back(m); + // } + // DD("done"); + + // vtkSmartPointer append = vtkSmartPointer::New(); + // for(unsigned int i=0; iAddInput(contours[i]); + // } + // append->Update(); + + // vtkSmartPointer mMesh = vtkSmartPointer::New(); + // mMesh->DeepCopy(append->GetOutput()); + + // // Write vtk + // vtkPolyDataWriter * w = vtkPolyDataWriter::New(); + // w->SetInput(mMesh); + // w->SetFileName("toto.vtk"); + // w->Write(); + // //====================================== + + + // // Set polydata + // vtkPolyData * c = reader->GetOutput(1); // second one (Oso, not Aorta) + // DD(c->GetNumberOfVerts()); + // DD(c->GetNumberOfLines()); + // DD(c->GetNumberOfPolys()); + // DD(c->GetNumberOfStrips()); + + + // //====================================== + + // DD(p->GetNumberOfContourReferencedFrameOfReferences()); + // DD(p->GetNumberOfReferencedFrameOfReferences ()); + // DD(p->GetNumberOfStructureSetROIs ()); + + // // Write + // vtkSmartPointer writer = vtkGDCMPolyDataWriter::New(); + // DD(reader->GetNumberOfOutputPorts() ); + // int numMasks = reader->GetNumberOfOutputPorts()+1; + // DD(numMasks); + + // writer->SetNumberOfInputPorts( numMasks ); // Add one + // // // vtkRTStructSetProperties * p = reader->GetRTStructSetProperties(); + // // std::string ref = p->GetReferenceFrameOfReferenceUID(); + // // const char * algogen = p->GetStructureSetROIGenerationAlgorithm(0); + // // DD(ref); + // // DD(algogen); + // // vtkIdType id = p->GetNumberOfContourReferencedFrameOfReferences(); + // // p->AddStructureSetROI(id, ref.c_str(), "BIDON", algogen); + // // // int n = p->GetNumberOfContourReferencedFrameOfReferences(); + // // const char * classuid = p->GetContourReferencedFrameOfReferenceClassUID(0, 0); + // // const char *instanceuid = p->GetContourReferencedFrameOfReferenceInstanceUID(0, 0); + // // DD(classuid); + // // DD(instanceuid); + // // p->AddContourReferencedFrameOfReference(id, classuid, instanceuid); + // // p->AddContourReferencedFrameOfReference(id+1, classuid, instanceuid); + + // // DD(p->GetNumberOfContourReferencedFrameOfReferences()); + // // DD(p->GetNumberOfReferencedFrameOfReferences ()); + // // DD(p->GetNumberOfStructureSetROIs ()); + + // writer->SetFileName("./bidon.dcm"); + // writer->SetMedicalImageProperties(reader->GetMedicalImageProperties()); + + // vtkStringArray* roiNames = vtkStringArray::New(); + // vtkStringArray* roiAlgorithms = vtkStringArray::New(); + // vtkStringArray* roiTypes = vtkStringArray::New(); + // roiNames->SetNumberOfValues(numMasks); + // roiAlgorithms->SetNumberOfValues(numMasks); + // roiTypes->SetNumberOfValues(numMasks); + + // // Add one + // int num = reader->GetNumberOfOutputPorts(); + // DD(num); + // // writer->SetInput(0, mMesh); // FIXME first one + // vtkPolyData* blank = vtkPolyData::New(); + // writer->SetInput(0, blank); + // roiNames->InsertValue(0, "blank"); + // roiAlgorithms->InsertValue(0, "blank"); + // roiTypes->InsertValue(0, "ORGAN"); + + // for (int i = 1; i < numMasks; ++i) { + // DD(i); + // writer->SetInput(i, reader->GetOutput(i-1) ); + // std::string theString = reader->GetRTStructSetProperties()->GetStructureSetROIName(i-1); + // roiNames->InsertValue(i, theString); + // DD(theString); + // theString = reader->GetRTStructSetProperties()->GetStructureSetROIGenerationAlgorithm(i-1); + // roiAlgorithms->InsertValue(i, theString); + // theString = reader->GetRTStructSetProperties()->GetStructureSetRTROIInterpretedType(i-1); + // roiTypes->InsertValue(i, theString); + // } + + // vtkRTStructSetProperties* theProperties = vtkRTStructSetProperties::New(); + // // writer->SetRTStructSetProperties(reader->GetRTStructSetProperties()); + // writer->SetRTStructSetProperties(theProperties); + // writer->InitializeRTStructSet("./", + // reader->GetRTStructSetProperties()->GetStructureSetLabel(), + // reader->GetRTStructSetProperties()->GetStructureSetName(), + // roiNames, roiAlgorithms, roiTypes); + // writer->SetRTStructSetProperties(theProperties); + + // writer->Write(); + // DD("write done"); + + // DD("end"); + // writer->Delete(); + // reader->Delete(); + // exit(0); // FIXME stop here (test) + // Read initial 3D image typedef float PixelType; typedef itk::Image ImageType; ImageType::Pointer input = clitk::readImage(args_info.input_arg, true); + // // Read initial RT Struct + // clitk::DicomRT_StructureSet::Pointer structset = clitk::DicomRT_StructureSet::New(); + // structset->Read(args_info.rtstruct_arg); + // Create a filter to convert image into dicomRTStruct clitk::Image2DicomRTStructFilter filter; filter.SetInput(input); + filter.SetDicomFolder(args_info.dicom_arg); + filter.SetStructureSetFilename(args_info.rtstruct_arg); + filter.SetOutputFilename(args_info.output_arg); filter.Update(); - // Write result - clitk::DicomRT_StructureSet::Pointer s = filter.GetDicomRTStruct(); - // s->Write(args_info.output_arg); + // // Write result + // clitk::DicomRT_StructureSet::Pointer s = filter.GetDicomRTStruct(); + // s->Write(args_info.output_arg); // This is the end my friend return 0; diff --git a/tests_dav/clitkImage2DicomRTStruct.ggo b/tests_dav/clitkImage2DicomRTStruct.ggo index 68334b1..3499543 100644 --- a/tests_dav/clitkImage2DicomRTStruct.ggo +++ b/tests_dav/clitkImage2DicomRTStruct.ggo @@ -5,9 +5,10 @@ version "Convert (binary) image to 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" string yes -option "output" o "Output DicomRT filename" string yes - +option "input" i "Input image file (binary image) to be converted into contours" string 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 "image" j "Used to read image info (spacing, origin)" string yes # option "roi" r "ROI to binarize (if -1 = all roi)" int no default="-1" -- 2.47.1