X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=tools%2FclitkDicom2Image.cxx;h=6410714293c69e769b12eceae618f9c26a5abf94;hb=bec6f659babc742382ca007b53800e7305fa298f;hp=421d456b945ab4b990b0f79c556828048f73d363;hpb=3651402ef8b7936f79264cba79c284343c704aa2;p=clitk.git diff --git a/tools/clitkDicom2Image.cxx b/tools/clitkDicom2Image.cxx index 421d456..6410714 100644 --- a/tools/clitkDicom2Image.cxx +++ b/tools/clitkDicom2Image.cxx @@ -3,7 +3,7 @@ Authors belong to: - University of LYON http://www.universite-lyon.fr/ - - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - Léon Bérard cancer center http://www.centreleonberard.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr This software is distributed WITHOUT ANY WARRANTY; without even @@ -14,7 +14,7 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html -======================================================================-====*/ +===========================================================================**/ // clitk includes #include "clitkDicom2Image_ggo.h" @@ -22,6 +22,13 @@ #include "clitkImageCommon.h" #include "vvImageReader.h" #include "vvImageWriter.h" +#include +#include +#if GDCM_MAJOR_VERSION == 2 + #include + #include + #include +#endif //==================================================================== int main(int argc, char * argv[]) @@ -45,16 +52,40 @@ int main(int argc, char * argv[]) //=========================================== /// Get slices locations ... + std::vector theorigin(3); std::vector sliceLocations; for(unsigned int i=0; iGetZOrigin()); - if (header->GetPixelSize() != 2) { +#if GDCM_MAJOR_VERSION == 2 + gdcm::Reader hreader; + hreader.SetFileName(input_files[i].c_str()); + hreader.Read(); + theorigin = gdcm::ImageHelper::GetOriginValue(hreader.GetFile()); + sliceLocations.push_back(theorigin[2]); + gdcm::Attribute<0x28, 0x100> pixel_size; + gdcm::DataSet& ds = hreader.GetFile().GetDataSet(); + pixel_size.SetFromDataSet(ds); + if (pixel_size.GetValue() != 16) + { std::cerr << "Pixel type 2 bytes ! " << std::endl; std::cerr << "In file " << input_files[i] << std::endl; exit(0); } +#else + gdcm::File *header = new gdcm::File(); + header->SetFileName(input_files[i]); + header->SetMaxSizeLoadEntry(16384); // required ? + header->Load(); + theorigin[0] = header->GetXOrigin(); + theorigin[1] = header->GetYOrigin(); + theorigin[2] = header->GetZOrigin(); + sliceLocations.push_back(theorigin[2]); + if (header->GetPixelSize() != 2) { + std::cerr << "Pixel type 2 bytes ! " << std::endl; + std::cerr << "In file " << input_files[i] << std::endl; + exit(0); + } +#endif } //=========================================== @@ -117,11 +148,29 @@ int main(int argc, char * argv[]) std::cerr << reader->GetLastError() << std::endl; return 1; } + + vvImage::Pointer image = reader->GetOutput(); + vtkImageData* vtk_image = image->GetFirstVTKImageData(); + vtkImageChangeInformation* modifier = vtkImageChangeInformation::New(); + if (args_info.focal_origin_given) { + std::vector spacing = image->GetSpacing(); + std::vector size = image->GetSize(); + theorigin[0] = -spacing[0]*size[0]/2.0; + theorigin[1] = -spacing[1]*size[1]/2.0; + modifier->SetInput(vtk_image); + modifier->SetOutputOrigin(theorigin[0], theorigin[1], sliceLocations[sliceIndex[0]]); + modifier->Update(); + vvImage::Pointer focal_image = vvImage::New(); + focal_image->AddVtkImage(modifier->GetOutput()); + image = focal_image; + } vvImageWriter::Pointer writer = vvImageWriter::New(); - writer->SetInput(reader->GetOutput()); + writer->SetInput(image); writer->SetOutputFileName(args_info.output_arg); writer->Update(); + modifier->Delete(); + return 0; }