ANIMA  4.0
animaBaseCompartment.cxx
Go to the documentation of this file.
1 #include <animaBaseCompartment.h>
2 
5 
6 namespace anima
7 {
8 
9 double BaseCompartment::GetPredictedSignal(double smallDelta, double bigDelta, double gradientStrength, const Vector3DType &gradient)
10 {
11  double ftDiffusionProfile = GetFourierTransformedDiffusionProfile(smallDelta,bigDelta, gradientStrength, gradient);
12 
13  return std::abs(ftDiffusionProfile);
14 }
15 
16 bool BaseCompartment::IsEqual(Self *rhs, double tolerance, double absoluteTolerance)
17 {
18  if (this->GetTensorCompatible() && rhs->GetTensorCompatible())
19  {
20  // Compare tensor representations, easier and probably faster
21  Matrix3DType lhsTensor = this->GetDiffusionTensor();
22  Matrix3DType rhsTensor = rhs->GetDiffusionTensor();
23 
24  for (unsigned int i = 0;i < Matrix3DType::RowDimensions;++i)
25  {
26  for (unsigned int j = i;j < Matrix3DType::ColumnDimensions;++j)
27  {
28  double diffValue = std::abs(lhsTensor(i,j) - rhsTensor(i,j));
29  double denom = std::max(std::abs(lhsTensor(i,j)),std::abs(rhsTensor(i,j)));
30  if (denom == 0)
31  continue;
32  if ((diffValue / denom > tolerance) && (diffValue > absoluteTolerance))
33  return false;
34  }
35  }
36 
37  return true;
38  }
39 
40  double denomValue = std::max(this->GetAxialDiffusivity(),rhs->GetAxialDiffusivity());
41  double diffValue = std::abs(this->GetAxialDiffusivity() - rhs->GetAxialDiffusivity());
42  if ((diffValue / denomValue > tolerance) && (diffValue > absoluteTolerance))
43  return false;
44 
45  Vector3DType orientationLHS(0.0);
47  Vector3DType orientationRHS(0.0);
49 
50  if (std::abs(std::abs(anima::ComputeScalarProduct(orientationLHS,orientationRHS)) - 1.0) > tolerance)
51  return false;
52 
53  denomValue = std::max(this->GetPerpendicularAngle(),rhs->GetPerpendicularAngle());
54  diffValue = std::abs(this->GetPerpendicularAngle() - rhs->GetPerpendicularAngle());
55  if ((diffValue / denomValue > tolerance) && (diffValue > absoluteTolerance))
56  return false;
57 
58  denomValue = std::max(this->GetRadialDiffusivity1(),rhs->GetRadialDiffusivity1());
59  diffValue = std::abs(this->GetRadialDiffusivity1() - rhs->GetRadialDiffusivity1());
60  if ((diffValue / denomValue > tolerance) && (diffValue > absoluteTolerance))
61  return false;
62 
63  denomValue = std::max(this->GetRadialDiffusivity2(),rhs->GetRadialDiffusivity2());
64  diffValue = std::abs(this->GetRadialDiffusivity2() - rhs->GetRadialDiffusivity2());
65  if ((diffValue / denomValue > tolerance) && (diffValue > absoluteTolerance))
66  return false;
67 
68  denomValue = std::max(this->GetOrientationConcentration(),rhs->GetOrientationConcentration());
69  diffValue = std::abs(this->GetOrientationConcentration() - rhs->GetOrientationConcentration());
70  if ((diffValue / denomValue > tolerance) && (diffValue > absoluteTolerance))
71  return false;
72 
73  denomValue = std::max(this->GetExtraAxonalFraction(),rhs->GetExtraAxonalFraction());
74  diffValue = std::abs(this->GetExtraAxonalFraction() - rhs->GetExtraAxonalFraction());
75  if ((diffValue / denomValue > tolerance) && (diffValue > absoluteTolerance))
76  return false;
77 
78  denomValue = std::max(this->GetTissueRadius(),rhs->GetTissueRadius());
79  diffValue = std::abs(this->GetTissueRadius() - rhs->GetTissueRadius());
80  if ((diffValue / denomValue > tolerance) && (diffValue > absoluteTolerance))
81  return false;
82 
83  return true;
84 }
85 
87 {
96  this->SetTissueRadius(rhs->GetTissueRadius());
97 }
98 
99 void BaseCompartment::Reorient(vnl_matrix <double> &orientationMatrix, bool affineTransform)
100 {
101  Vector3DType tmpDir;
102  Vector3DType tmpRotatedDir;
103 
105 
106  unsigned int imageDimension = tmpDir.size();
107  for (unsigned int k = 0;k < imageDimension;++k)
108  {
109  tmpRotatedDir[k] = 0;
110 
111  for (unsigned int l = 0;l < imageDimension;++l)
112  tmpRotatedDir[k] += orientationMatrix(l,k) * tmpDir[l];
113  }
114 
115  anima::TransformCartesianToSphericalCoordinates(tmpRotatedDir,tmpRotatedDir);
116  this->SetOrientationTheta(tmpRotatedDir[0]);
117  this->SetOrientationPhi(tmpRotatedDir[1]);
118 }
119 
121 {
122  throw itk::ExceptionObject(__FILE__,__LINE__,"This compartment type does not support diffusion tensor export",ITK_LOCATION);
123 }
124 
126 {
127  throw itk::ExceptionObject(__FILE__,__LINE__,"This compartment type does not support apparent fractional anisotropy computation",ITK_LOCATION);
128 }
129 
131 {
132  throw itk::ExceptionObject(__FILE__,__LINE__,"This compartment type does not support apparent mean diffusivity computation",ITK_LOCATION);
133 }
134 
136 {
137  throw itk::ExceptionObject(__FILE__,__LINE__,"This compartment type does not support apparent parallel diffusivity computation",ITK_LOCATION);
138 }
139 
141 {
142  throw itk::ExceptionObject(__FILE__,__LINE__,"This compartment type does not support apparent perpendicular diffusivity computation",ITK_LOCATION);
143 }
144 
145 } // end namespace anima
virtual bool GetTensorCompatible()
virtual double GetApparentFractionalAnisotropy()
void TransformSphericalToCartesianCoordinates(const VectorType &v, VectorType &resVec)
virtual void SetAxialDiffusivity(double num)
virtual void SetRadialDiffusivity2(double num)
virtual void SetTissueRadius(double num)
virtual bool IsEqual(Self *rhs, double tolerance=1.0e-2, double absoluteTolerance=1.0e-8)
Tests equality to another compartment up to a constant (relative and absolute tolerances) ...
virtual double GetOrientationPhi()
virtual void SetRadialDiffusivity1(double num)
itk::Matrix< double, 3, 3 > Matrix3DType
virtual double GetApparentMeanDiffusivity()
vnl_vector_fixed< double, 3 > Vector3DType
virtual void SetPerpendicularAngle(double num)
virtual double GetAxialDiffusivity()
virtual double GetApparentPerpendicularDiffusivity()
Get approximation to perpendicular diffusivity of the compartment (may be different from radial diffu...
virtual double GetPerpendicularAngle()
virtual double GetOrientationTheta()
virtual void SetOrientationConcentration(double num)
virtual void SetExtraAxonalFraction(double num)
virtual double GetExtraAxonalFraction()
virtual void SetOrientationTheta(double num)
virtual const Matrix3DType & GetDiffusionTensor()
Get compartment as a 3D tensor (default behavior: throw exception if not supported by the compartment...
virtual double GetFourierTransformedDiffusionProfile(double smallDelta, double bigDelta, double gradientStrength, const Vector3DType &gradient)=0
virtual double GetRadialDiffusivity2()
virtual void CopyFromOther(Self *rhs)
Copy internal parameters from another compartment, faster than a set/get compartment vector...
virtual double GetRadialDiffusivity1()
double ComputeScalarProduct(const VectorType &v1, const VectorType &v2, const unsigned int NDimension)
virtual void SetOrientationPhi(double num)
virtual double GetTissueRadius()
virtual double GetApparentParallelDiffusivity()
Get approximation to parallel diffusivity of the compartment (may be different from axial diffusivity...
double GetPredictedSignal(double smallDelta, double bigDelta, double gradientStrength, const Vector3DType &gradient)
virtual void Reorient(vnl_matrix< double > &orientationMatrix, bool affineTransform)
Reorient the fascicle compartment using a matrix, the flag specifies if the transform is affine or ri...
void TransformCartesianToSphericalCoordinates(const VectorType &v, VectorType &resVec)
virtual double GetOrientationConcentration()