From: Romulo Pinho Date: Tue, 20 Dec 2011 17:24:36 +0000 (+0100) Subject: --focal_origin works again X-Git-Tag: v1.3.0~132 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=de73c67818eb9bb316269a5db3d5a32d91a92fa5;p=clitk.git --focal_origin works again --- diff --git a/tools/clitkDicom2Image.cxx b/tools/clitkDicom2Image.cxx index b13de42..0ad79ef 100644 --- a/tools/clitkDicom2Image.cxx +++ b/tools/clitkDicom2Image.cxx @@ -23,6 +23,7 @@ #include "vvImageReader.h" #include "vvImageWriter.h" #include +#include #if GDCM_MAJOR_VERSION == 2 #include #include @@ -51,6 +52,7 @@ int main(int argc, char * argv[]) //=========================================== /// Get slices locations ... + std::vector theorigin(3); std::vector sliceLocations; for(unsigned int i=0; i theorigin = gdcm::ImageHelper::GetOriginValue(hreader.GetFile()); + theorigin = gdcm::ImageHelper::GetOriginValue(hreader.GetFile()); sliceLocations.push_back(theorigin[2]); gdcm::Attribute<0x28, 0x100> pixel_size; gdcm::DataSet& ds = hreader.GetFile().GetDataSet(); @@ -74,7 +76,10 @@ int main(int argc, char * argv[]) header->SetFileName(input_files[i]); header->SetMaxSizeLoadEntry(16384); // required ? header->Load(); - sliceLocations.push_back(header->GetZOrigin()); + 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; @@ -143,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], theorigin[2]); + 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; }