X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=common%2FclitkDicomRTStruct2ImageFilter.cxx;fp=common%2FclitkDicomRTStruct2ImageFilter.cxx;h=bf515a423b460ec958a6dd624bea7587103212c2;hb=a365564201d98b704f43e1f52124f55f5e110d2e;hp=fcc9e2be26da9c02cfdcb1a94f10e5ff67874745;hpb=8a3497690d4e39e99b6d5e50cb324449041ea08d;p=clitk.git diff --git a/common/clitkDicomRTStruct2ImageFilter.cxx b/common/clitkDicomRTStruct2ImageFilter.cxx index fcc9e2b..bf515a4 100644 --- a/common/clitkDicomRTStruct2ImageFilter.cxx +++ b/common/clitkDicomRTStruct2ImageFilter.cxx @@ -102,10 +102,14 @@ void clitk::DicomRTStruct2ImageFilter::SetImage(vvImage::Pointer image) mSpacing.resize(3); mOrigin.resize(3); mSize.resize(3); + mDirection.resize(3); for(unsigned int i=0; i<3; i++) { mSpacing[i] = image->GetSpacing()[i]; mOrigin[i] = image->GetOrigin()[i]; mSize[i] = image->GetSize()[i]; + mDirection[i].resize(3); + for(unsigned int j=0; j<3; j++) + mDirection[i][j] = image->GetDirection()[i][j]; } } //-------------------------------------------------------------------- @@ -125,10 +129,14 @@ void clitk::DicomRTStruct2ImageFilter::SetImageFilename(std::string f) mSpacing.resize(3); mOrigin.resize(3); mSize.resize(3); + mDirection.resize(3); for(unsigned int i=0; i<3; i++) { mSpacing[i] = header->GetSpacing(i); mOrigin[i] = header->GetOrigin(i); mSize[i] = header->GetDimensions(i); + mDirection[i].resize(3); + for(unsigned int j=0; j<3; j++) + mDirection[i][j] = header->GetDirection(i)[j]; } } //-------------------------------------------------------------------- @@ -176,6 +184,38 @@ void clitk::DicomRTStruct2ImageFilter::Update() // Get bounds double *bounds=mesh->GetBounds(); + //Change mOrigin, mSize and mSpacing with respect to the directions + // Spacing is influenced by input direction + std::vector tempSpacing; + tempSpacing.resize(3); + for(int i=0; i<3; i++) { + tempSpacing[i] = 0.0; + for(int j=0; j<3; j++) { + tempSpacing[i] += mDirection[i][j] * mSpacing[j]; + } + } + for(int i=0; i<3; i++) + mSpacing[i] = tempSpacing[i]; + + // Size is influenced by affine transform matrix and input direction + // Size is converted to double, transformed and converted back to size type. + std::vector tempSize; + tempSize.resize(3); + for(int i=0; i<3; i++) { + tempSize[i] = 0.0; + for(int j=0; j<3; j++) { + tempSize[i] += mDirection[i][j] * mSize[j]; + } + } + for(int i=0; i<3; i++) { + if (tempSize[i] < 0.0) { + tempSize[i] *= -1; + mOrigin[i] += mSpacing[i]*(tempSize[i] -1); + mSpacing[i] *= -1; + } + mSize[i] = lrint(tempSize[i]); + } + // Compute origin std::vector origin; origin.resize(3);