Skip to content

Commit

Permalink
move MultiDimIterator into Common folder, include from CiftiFile and …
Browse files Browse the repository at this point in the history
…NiftiIO, add convenience iterator construction method from CiftiFile
  • Loading branch information
coalsont committed Jul 29, 2016
1 parent 8d2150a commit 452cdea
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 4 deletions.
3 changes: 1 addition & 2 deletions example/rewrite.cxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "CiftiFile.h"
#include "CiftiMultiDimIterator.h"

#include <iostream>
#include <vector>
Expand Down Expand Up @@ -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<int64_t>& dims = inputFile.getDimensions();
vector<float> scratchRow(dims[0]);//read/write a row at a time
for (MultiDimIterator<int64_t> iter(vector<int64_t>(dims.begin() + 1, dims.end())); !iter.atEnd(); ++iter)
for (MultiDimIterator<int64_t> 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);
Expand Down
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ PROJECT(src)
SET(HEADERS
CiftiFile.h
NiftiIO.h
CiftiMultiDimIterator.h
)

SET(SOURCES
Expand Down
1 change: 0 additions & 1 deletion src/CiftiFile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

#include "Common/CiftiAssert.h"
#include "Common/MultiDimArray.h"
#include "CiftiMultiDimIterator.h"
#include "NiftiIO.h"

#ifdef CIFTILIB_USE_QT
Expand Down
7 changes: 7 additions & 0 deletions src/CiftiFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -76,6 +77,12 @@ namespace cifti
void getRow(float* dataOut, const std::vector<int64_t>& indexSelect, const bool& tolerateShortRead = false) const;
const std::vector<int64_t>& getDimensions() const { return m_dims; }

///convenience function for iterating over arbitrary numbers of dimensions
MultiDimIterator<int64_t> getIteratorOverRows() const
{
return MultiDimIterator<int64_t>(std::vector<int64_t>(getDimensions().begin() + 1, getDimensions().end()));
}

///for 2D only, will be slow if on disk!
void getColumn(float* dataOut, const int64_t& index) const;

Expand Down
1 change: 1 addition & 0 deletions src/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ FloatMatrix.h
MatrixFunctions.h
MathFunctions.h
MultiDimArray.h
MultiDimIterator.h
Vector3D.h
VoxelIJK.h
XmlAdapter.h
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions src/NiftiIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cmath>
#include <limits>
#include <vector>
Expand Down

0 comments on commit 452cdea

Please sign in to comment.