1#ifndef __VOLUME_SPACE_H__
2#define __VOLUME_SPACE_H__
31#include "Common/Vector3D.h"
33#include "Common/XmlAdapter.h"
44 std::vector<std::vector<float> > m_sform, m_inverse;
45 void computeInverse();
51 POSTERIOR_TO_ANTERIOR = 1,
52 ANTERIOR_TO_POSTERIOR = 5,
53 INFERIOR_TO_SUPERIOR = 2,
54 SUPERIOR_TO_INFERIOR = 6
57 VolumeSpace(
const int64_t dims[3],
const std::vector<std::vector<float> >& sform);
58 VolumeSpace(
const int64_t dims[3],
const float sform[12]);
59 void setSpace(
const int64_t dims[3],
const std::vector<std::vector<float> >& sform);
60 void setSpace(
const int64_t dims[3],
const float sform[12]);
61 const int64_t* getDims()
const {
return m_dims; }
62 const std::vector<std::vector<float> >& getSform()
const {
return m_sform; }
64 bool matchesVolumeSpace(
const VolumeSpace& right)
const;
66 bool operator!=(
const VolumeSpace& right)
const {
return !(*
this == right); }
80 { indexToSpace<T>(indexIn[0], indexIn[1], indexIn[2], coordOut[0], coordOut[1], coordOut[2]); }
84 inline void indexToSpace(
const T& indexIn1,
const T& indexIn2,
const T& indexIn3,
float* coordOut)
const
85 { indexToSpace<T>(indexIn1, indexIn2, indexIn3, coordOut[0], coordOut[1], coordOut[2]); }
89 inline void indexToSpace(
const T* indexIn,
float& coordOut1,
float& coordOut2,
float& coordOut3)
const
90 { indexToSpace<T>(indexIn[0], indexIn[1], indexIn[2], coordOut1, coordOut2, coordOut3); }
94 void indexToSpace(
const T& indexIn1,
const T& indexIn2,
const T& indexIn3,
float& coordOut1,
float& coordOut2,
float& coordOut3)
const;
97 inline void spaceToIndex(
const float* coordIn,
float* indexOut)
const {
spaceToIndex(coordIn[0], coordIn[1], coordIn[2], indexOut[0], indexOut[1], indexOut[2]); }
99 inline void spaceToIndex(
const float& coordIn1,
const float& coordIn2,
const float& coordIn3,
float* indexOut)
const {
spaceToIndex(coordIn1, coordIn2, coordIn3, indexOut[0], indexOut[1], indexOut[2]); }
101 inline void spaceToIndex(
const float* coordIn,
float& indexOut1,
float& indexOut2,
float& indexOut3)
const {
spaceToIndex(coordIn[0], coordIn[1], coordIn[2], indexOut1, indexOut2, indexOut3); }
103 void spaceToIndex(
const float& coordIn1,
const float& coordIn2,
const float& coordIn3,
float& indexOut1,
float& indexOut2,
float& indexOut3)
const;
106 inline void enclosingVoxel(
const float* coordIn, int64_t* indexOut)
const {
enclosingVoxel(coordIn[0], coordIn[1], coordIn[2], indexOut[0], indexOut[1], indexOut[2]); }
108 inline void enclosingVoxel(
const float& coordIn1,
const float& coordIn2,
const float& coordIn3, int64_t* indexOut)
const {
enclosingVoxel(coordIn1, coordIn2, coordIn3, indexOut[0], indexOut[1], indexOut[2]); }
110 inline void enclosingVoxel(
const float* coordIn, int64_t& indexOut1, int64_t& indexOut2, int64_t& indexOut3)
const {
enclosingVoxel(coordIn[0], coordIn[1], coordIn[2], indexOut1, indexOut2, indexOut3); }
112 void enclosingVoxel(
const float& coordIn1,
const float& coordIn2,
const float& coordIn3, int64_t& indexOut1, int64_t& indexOut2, int64_t& indexOut3)
const;
114 template <
typename T>
115 inline bool indexValid(
const T* indexIn)
const
117 return indexValid(indexIn[0], indexIn[1], indexIn[2]);
121 inline bool indexValid(
const int64_t& indexIn1,
const int64_t& indexIn2,
const int64_t& indexIn3)
const
123 if (indexIn1 < 0 || indexIn1 >= m_dims[0])
return false;
124 if (indexIn2 < 0 || indexIn2 >= m_dims[1])
return false;
125 if (indexIn3 < 0 || indexIn3 >= m_dims[2])
return false;
129 inline int64_t getIndex(
const int64_t& indexIn1,
const int64_t& indexIn2,
const int64_t& indexIn3)
const
131 return indexIn1 + m_dims[0] * (indexIn2 + m_dims[1] * indexIn3);
134 template <
typename T>
135 inline int64_t getIndex(
const T* indexIn)
const
137 return getIndex(indexIn[0], indexIn[1], indexIn[2]);
140 void readCiftiXML1(XmlReader& xml);
141 void readCiftiXML2(XmlReader& xml);
142 void writeCiftiXML1(XmlWriter& xml)
const;
143 void writeCiftiXML2(XmlWriter& xml)
const;
146 template <
typename T>
147 void VolumeSpace::indexToSpace(
const T& indexIn1,
const T& indexIn2,
const T& indexIn3,
float& coordOut1,
float& coordOut2,
float& coordOut3)
const
149 coordOut1 = indexIn1 * m_sform[0][0] + indexIn2 * m_sform[0][1] + indexIn3 * m_sform[0][2] + m_sform[0][3];
150 coordOut2 = indexIn1 * m_sform[1][0] + indexIn2 * m_sform[1][1] + indexIn3 * m_sform[1][2] + m_sform[1][3];
151 coordOut3 = indexIn1 * m_sform[2][0] + indexIn2 * m_sform[2][1] + indexIn3 * m_sform[2][2] + m_sform[2][3];
Definition: Vector3D.h:37
Definition: VolumeSpace.h:42
bool isPlumb() const
returns true if volume space is not skew, and each axis and index is separate
Definition: VolumeSpace.cxx:291
void indexToSpace(const T *indexIn, float &coordOut1, float &coordOut2, float &coordOut3) const
returns three coordinates of an index triplet
Definition: VolumeSpace.h:89
void enclosingVoxel(const float *coordIn, int64_t &indexOut1, int64_t &indexOut2, int64_t &indexOut3) const
returns integer indexes of voxel whose center is closest to the coordinate triplet
Definition: VolumeSpace.h:110
void spaceToIndex(const float *coordIn, float &indexOut1, float &indexOut2, float &indexOut3) const
returns three floating point indexes of a given coordinate triplet
Definition: VolumeSpace.h:101
void enclosingVoxel(const float &coordIn1, const float &coordIn2, const float &coordIn3, int64_t *indexOut) const
returns integer index triplet of voxel whose center is closest to the three coordinates
Definition: VolumeSpace.h:108
void getOrientAndSpacingForPlumb(OrientTypes *orientOut, float *spacingOut, float *originOut) const
returns orientation, spacing, and center (spacing/center can be negative, spacing/center is LPI rearr...
Definition: VolumeSpace.cxx:187
void getOrientation(OrientTypes orientOut[3]) const
get just orientation, even for non-plumb volumes
Definition: VolumeSpace.cxx:226
bool indexValid(const int64_t &indexIn1, const int64_t &indexIn2, const int64_t &indexIn3) const
checks if an index is within array dimensions
Definition: VolumeSpace.h:121
void enclosingVoxel(const float *coordIn, int64_t *indexOut) const
returns integer index triplet of voxel whose center is closest to the coordinate triplet
Definition: VolumeSpace.h:106
void spaceToIndex(const float *coordIn, float *indexOut) const
returns floating point index triplet of a given coordinate triplet
Definition: VolumeSpace.h:97
void indexToSpace(const T *indexIn, float *coordOut) const
returns coordinate triplet of an index triplet
Definition: VolumeSpace.h:79
void spaceToIndex(const float &coordIn1, const float &coordIn2, const float &coordIn3, float *indexOut) const
returns floating point index triplet of three given coordinates
Definition: VolumeSpace.h:99
void indexToSpace(const T &indexIn1, const T &indexIn2, const T &indexIn3, float *coordOut) const
returns coordinate triplet of three indices
Definition: VolumeSpace.h:84
namespace for all CiftiLib functionality
Definition: CiftiBrainModelsMap.h:42