X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=tools%2FclitkImageConvertGenericFilter.cxx;h=51a43a029a60fa239ebd0840465751af3198cd63;hb=d98418e7948315cd8c6ae9a2d5452ef0b52f9827;hp=a1b28c22014d14606902cd338ceb908170edd331;hpb=85e5c2db06fc4689445dab0adbd41441eca15eaf;p=clitk.git diff --git a/tools/clitkImageConvertGenericFilter.cxx b/tools/clitkImageConvertGenericFilter.cxx index a1b28c2..51a43a0 100644 --- a/tools/clitkImageConvertGenericFilter.cxx +++ b/tools/clitkImageConvertGenericFilter.cxx @@ -24,6 +24,7 @@ #include "vvImageWriter.h" #include "itkFlipImageFilter.h" #include "itkGDCMImageIO.h" +#include #include "gdcmReader.h" #include "gdcmAttribute.h" @@ -147,6 +148,10 @@ void clitk::ImageConvertGenericFilter::UpdateWithInputImageType() // Read the attribute Image Position (Patient) gdcm::Tag DetectorInformationSequenceTag(0x0054,0x0022); const gdcm::DataElement & DIS = ds.GetDataElement(DetectorInformationSequenceTag); + if (!DIS.GetByteValue()) { + std::cout << "Error: could not find 0x0054,0x0022 tag. Abort." << std::endl; + exit(0); + } gdcm::SmartPointer sqf = DIS.GetValueAsSQ(); gdcm::Item & item = sqf->GetItem(1); gdcm::DataSet & ds_position = item.GetNestedDataSet(); @@ -172,8 +177,26 @@ void clitk::ImageConvertGenericFilter::UpdateWithInputImageType() itk::MetaDataDictionary dict;// = new itk::MetaDataDictionary; input->SetMetaDataDictionary(dict); } - this->SetNextOutput(input); + typedef itk::ChangeInformationImageFilter CIType; + typename CIType::Pointer changeInfo = CIType::New(); + if(mNoNiiMeta) { + changeInfo->SetInput(input); + typename CIType::PointType o = input->GetOrigin(); + o[0] *= -1.; + o[1] *= -1.; + typename CIType::DirectionType d = input->GetDirection(); + d[0][0] *= -1.; + d[1][1] *= -1.; + changeInfo->ChangeDirectionOn(); + changeInfo->ChangeOriginOn(); + changeInfo->SetOutputOrigin(o); + changeInfo->SetOutputDirection(d); + changeInfo->Update(); + input = changeInfo->GetOutput(); + } + + this->SetNextOutput(input); } else { // "trick" to call independent versions of update according to the