From 452cdeaaadbbd60cbf5f621987dff57728ee78a5 Mon Sep 17 00:00:00 2001 From: Tim Coalson Date: Fri, 29 Jul 2016 17:05:29 -0500 Subject: [PATCH] move MultiDimIterator into Common folder, include from CiftiFile and NiftiIO, add convenience iterator construction method from CiftiFile --- example/rewrite.cxx | 3 +-- src/CMakeLists.txt | 1 - src/CiftiFile.cxx | 1 - src/CiftiFile.h | 7 +++++++ src/Common/CMakeLists.txt | 1 + src/{CiftiMultiDimIterator.h => Common/MultiDimIterator.h} | 0 src/NiftiIO.h | 3 +++ 7 files changed, 12 insertions(+), 4 deletions(-) rename src/{CiftiMultiDimIterator.h => Common/MultiDimIterator.h} (100%) diff --git a/example/rewrite.cxx b/example/rewrite.cxx index 30e121b..0bfbd6d 100644 --- a/example/rewrite.cxx +++ b/example/rewrite.cxx @@ -1,5 +1,4 @@ #include "CiftiFile.h" -#include "CiftiMultiDimIterator.h" #include #include @@ -46,7 +45,7 @@ int main(int argc, char** argv) outputFile.setCiftiXML(inputFile.getCiftiXML());//the CiftiXML is how you access all the mapping information const vector& dims = inputFile.getDimensions(); vector scratchRow(dims[0]);//read/write a row at a time - for (MultiDimIterator iter(vector(dims.begin() + 1, dims.end())); !iter.atEnd(); ++iter) + for (MultiDimIterator iter = inputFile.getIteratorOverRows(); !iter.atEnd(); ++iter) {//helper class to iterate over 2D and 3D cifti with the same code - the "+ 1" is to drop the first dimension (row length) inputFile.getRow(scratchRow.data(), *iter); outputFile.setRow(scratchRow.data(), *iter); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9cb6cca..bfd94fd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,7 +3,6 @@ PROJECT(src) SET(HEADERS CiftiFile.h NiftiIO.h -CiftiMultiDimIterator.h ) SET(SOURCES diff --git a/src/CiftiFile.cxx b/src/CiftiFile.cxx index 9a565c6..99dd512 100644 --- a/src/CiftiFile.cxx +++ b/src/CiftiFile.cxx @@ -29,7 +29,6 @@ #include "Common/CiftiAssert.h" #include "Common/MultiDimArray.h" -#include "CiftiMultiDimIterator.h" #include "NiftiIO.h" #ifdef CIFTILIB_USE_QT diff --git a/src/CiftiFile.h b/src/CiftiFile.h index d22d62a..ccd761a 100644 --- a/src/CiftiFile.h +++ b/src/CiftiFile.h @@ -30,6 +30,7 @@ #include "Common/AString.h" #include "Common/CiftiException.h" +#include "Common/MultiDimIterator.h" #include "Cifti/CiftiXML.h" #include "boost/shared_ptr.hpp" @@ -76,6 +77,12 @@ namespace cifti void getRow(float* dataOut, const std::vector& indexSelect, const bool& tolerateShortRead = false) const; const std::vector& getDimensions() const { return m_dims; } + ///convenience function for iterating over arbitrary numbers of dimensions + MultiDimIterator getIteratorOverRows() const + { + return MultiDimIterator(std::vector(getDimensions().begin() + 1, getDimensions().end())); + } + ///for 2D only, will be slow if on disk! void getColumn(float* dataOut, const int64_t& index) const; diff --git a/src/Common/CMakeLists.txt b/src/Common/CMakeLists.txt index 52b77a7..40255e2 100644 --- a/src/Common/CMakeLists.txt +++ b/src/Common/CMakeLists.txt @@ -13,6 +13,7 @@ FloatMatrix.h MatrixFunctions.h MathFunctions.h MultiDimArray.h +MultiDimIterator.h Vector3D.h VoxelIJK.h XmlAdapter.h diff --git a/src/CiftiMultiDimIterator.h b/src/Common/MultiDimIterator.h similarity index 100% rename from src/CiftiMultiDimIterator.h rename to src/Common/MultiDimIterator.h diff --git a/src/NiftiIO.h b/src/NiftiIO.h index 490cada..cdf3c1a 100644 --- a/src/NiftiIO.h +++ b/src/NiftiIO.h @@ -35,6 +35,9 @@ #include "Common/CiftiException.h" #include "Nifti/NiftiHeader.h" +//include MultiDimIterator from a private include directory, in case people want to use it with NiftiIO +#include "Common/MultiDimIterator.h" + #include #include #include