12 #ifndef __itkSHCoefficientsPowerImageFilter_h 13 #define __itkSHCoefficientsPowerImageFilter_h 15 #include "itkUnaryFunctorImageFilter.h" 38 template <
class TInput,
class TOutput>
60 return !( *
this == other );
70 if (utl::IsSame<double>(
m_Power, 1))
72 else if (utl::IsSame<double>(
m_Power, 2))
74 int shInputDim = shCoef.GetSize();
77 TOutput out(shOutputDim);
79 if (shCoef.GetSquaredNorm()>0)
82 for (
int k = 0; k < shOutputDim; k += 1 )
85 for (
int i = 0; i < shInputDim; i += 1 )
88 for (
int j = 0; j < shInputDim; j += 1 )
91 out[k] += shCoef[i]*shCoef[j]* (*utl::SH3IntegralTable)(index);
101 TOutput out(shOutputDim);
103 if (shCoef.GetSquaredNorm()>0)
105 VectorType shInput(shCoef.GetSize());
106 shInput.SetData(const_cast<double* const>(shCoef.GetDataPointer()), shCoef.GetSize());
107 VectorType sf = (*m_SHBasisMatrix) * shInput;
134 template <
class TInputImage,
class TOutputImage=itk::Image<
double,3> >
137 UnaryFunctorImageFilter<TInputImage, TOutputImage,
138 Functor::SHCoefficientsPower<
139 typename TInputImage::PixelType,
140 typename TOutputImage::PixelType> >
145 typedef UnaryFunctorImageFilter<
146 TInputImage, TOutputImage,
148 typename TInputImage::PixelType,
typename TOutputImage::PixelType>
180 typename TInputImage::Pointer inputSH =
const_cast<TInputImage *
>(this->GetInput());
182 if (utl::IsSame<double>(this->GetPower(), 2))
186 else if (!utl::IsSame<double>(this->GetPower(), 1))
188 utlGlobalException(this->GetSHRank()<=0,
"need to set SHRank to fit the SH coefficients when power is not 1 or 2");
193 this->GetFunctor().SetSHBasisMatrix(shMatrixInput);
197 this->GetFunctor().SetSHBasisMatrixInverse(shMatrixOutputInverse);
203 Superclass::GenerateOutputInformation();
204 typename TOutputImage::Pointer outputPtr = this->GetOutput();
205 typename TInputImage::Pointer inputSH =
const_cast<TInputImage *
>(this->GetInput());
207 int numberOfComponentsPerPixel=0;
208 int dimInput = inputSH->GetNumberOfComponentsPerPixel();
209 if (this->GetPower()==1)
210 numberOfComponentsPerPixel = dimInput;
211 else if (this->GetPower()==2)
215 utlGlobalException(this->GetSHRank()<=0,
"need to set shRank when power is not 1 or 2");
218 outputPtr->SetNumberOfComponentsPerPixel(numberOfComponentsPerPixel);
224 void operator=(
const Self &);
NDArray is a N-Dimensional array class (row-major, c version)
Functor::SHCoefficientsPower< typename TInputImage::PixelType, typename TOutputImage::PixelType > FunctorType
MatrixPointer m_SHBasisMatrix
bool operator==(const SHCoefficientsPower &other) const
FunctorType::MatrixType MatrixType
void InitializeSHTripleIntegrationTable(const int rank0=-1, const int rank1=-1, const int rank2=-1, const bool useExactSize=false)
SHCoefficientsPowerImageFilter Self
void GenerateOutputInformation() ITK_OVERRIDE
helper functions specifically used in dmritool
void VectorToVector(const T1 &v1, T2 &v2, const int N)
virtual ~SHCoefficientsPowerImageFilter()
UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::SHCoefficientsPower< typename TInputImage::PixelType, typename TOutputImage::PixelType > > Superclass
void BeforeThreadedGenerateData() ITK_OVERRIDE
int DimToRankSH(const int dimm)
void PowerVector(IteratorType v1, IteratorType v2, const double poww)
std::shared_ptr< NDArray< T, 2 > > ComputeSHMatrix(const unsigned int rank, const NDArray< T, 2 > &grad, const int mode)
#define itkFunctorSetGetMacro(name, type)
#define utlGlobalException(cond, expout)
utl::NDArray< double, 2 > MatrixType
FunctorType::MatrixPointer MatrixPointer
utl_shared_ptr< MatrixType > MatrixPointer
NDArray< T, 2 > PInverseMatrix(const NDArray< T, 2 > &mat, const double eps=1e-10)
SmartPointer< Self > Pointer
int RankToDimSH(const int shRank)
SmartPointer< const Self > ConstPointer
utl::NDArray< double, 1 > VectorType
TOutput operator()(const TInput &shCoef)
utlSetGetMacro(Power, double)
SHCoefficientsPowerImageFilter()
In each vxoel, the input VectorImage is a SH coefficient vector which represents a spherical function...
bool operator!=(const SHCoefficientsPower &other) const
MatrixPointer m_SHBasisMatrixInverse