Skip to content

Commit

Permalink
When reorienting a vector-valued image, the data also needs to be man…
Browse files Browse the repository at this point in the history
…ipulated to reflect the transform
  • Loading branch information
jonclayden committed Dec 17, 2019
1 parent ccad293 commit 9389598
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions inst/include/RNifti/NiftiImage_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,22 @@ inline NiftiImage & NiftiImage::reorient (const int icode, const int jcode, cons
volStart += volSize;
}

// Vector data needs to be reoriented to match the xform
if (image->intent_code == NIFTI_INTENT_VECTOR && image->dim[5] == 3)
{
internal::vec3 oldVec;
const size_t supervolSize = volSize * image->nt;
NiftiImageData::Iterator it = newData.begin();
for (size_t i=0; i<supervolSize; i++, ++it)
{
for (int j=0; j<3; j++)
oldVec.v[j] = double(*(it + j*supervolSize));
const internal::vec3 newVec = internal::matrixVectorProduct(transform, oldVec);
for (int j=0; j<3; j++)
*(it + j*supervolSize) = newVec.v[j];
}
}

// Replace the existing data in the image
this->replaceData(newData);
}
Expand Down

0 comments on commit 9389598

Please sign in to comment.