DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkMeshFromSphericalFunctionTessellatedSamplesImageFilter.h
Go to the documentation of this file.
1 
18 #ifndef __itkMeshFromSphericalFunctionTessellatedSamplesImageFilter_h
19 #define __itkMeshFromSphericalFunctionTessellatedSamplesImageFilter_h
20 
22 
23 namespace itk
24 {
25 
34 template < class TInputImage, class TOutputMesh=vtkPolyData>
36  : public MeshFromContinuousSphericalFunctionImageFilter<TInputImage, TOutputMesh>
37 {
38 public:
42  typedef SmartPointer<Self> Pointer;
43  typedef SmartPointer<const Self> ConstPointer;
44 
46  itkNewMacro(Self);
47 
50 
51  //** Convenient typedefs */
52  typedef TInputImage InputImageType;
53  typedef typename InputImageType::Pointer InputImagePointer;
54  typedef typename InputImageType::ConstPointer InputImageConstPointer;
55  typedef typename InputImageType::IndexType InputImageIndexType;
56  typedef typename InputImageType::SizeType InputImageSizeType;
57  typedef typename InputImageType::SizeValueType InputImageSizeValueType;
58  typedef typename InputImageType::SpacingType InputImageSpacingType;
59  typedef typename InputImageType::PixelType InputImagePixelType;
60  typedef typename InputImageType::RegionType InputImageRegionType;
61  typedef typename InputImageType::PointType InputImagePointType;
62 
63  typedef TOutputMesh OutputMeshPolyDataType;
64 
70 
71 
76 
77 
85 
86  itkSetMacro(DataOrientations, MatrixPointer);
87  itkGetMacro(DataOrientations, MatrixPointer);
88 
90  {
91  utlShowPosition(this->GetDebug());
92 
93  InputImageConstPointer inputPtr = this->GetInput();
94  int numberOfSamples = this->m_Orientations->Rows();
95  int inputDimension = inputPtr->GetNumberOfComponentsPerPixel();
96 
97  utlSAGlobalException(m_DataOrientations->Rows()!=inputDimension)
98  (m_DataOrientations->Rows())(inputDimension).msg("inconsistent size between input orientations and input image with spherical samples (whole sphere or hemisphere).");
99  utlSAGlobalException(numberOfSamples!=inputDimension && numberOfSamples!=2*inputDimension)
100  (numberOfSamples)(inputDimension).msg("inconsistent size between tessellation and input image with spherical samples (whole sphere or hemisphere).");
101 
102  auto orientationsFliped = utl::FlipOrientations(*m_DataOrientations, this->m_Flip);
103  *this->m_BasisMatrix = (*this->m_Orientations) * orientationsFliped.GetTranspose();
104  // utl::PrintUtlMatrix(*this->m_Orientations, "m_Orientations");
105  // utl::PrintUtlMatrix(*this->m_DataOrientations, "m_DataOrientations");
106  // utl::PrintUtlMatrix(*this->m_BasisMatrix, "m_BasisMatrix");
107  for ( int j = 0; j < this->m_BasisMatrix->Columns(); j += 1 )
108  {
109  int num = 0;
110  for ( int i = 0; i < this->m_BasisMatrix->Rows(); i += 1 )
111  {
112  if ( std::fabs((*this->m_BasisMatrix)(i,j)-1.0) < 1e-8 || std::fabs((*this->m_BasisMatrix)(i,j)+1.0)<1e-8 )
113  {
114  (*this->m_BasisMatrix)(i,j) = 1.0;
115  num++;
116  }
117  else
118  (*this->m_BasisMatrix)(i,j) = 0;
119  }
120  utlGlobalException(inputDimension==numberOfSamples && num!=1, "input orientation is different from the stored one.");
121  utlGlobalException(inputDimension==2*numberOfSamples && num!=2, "input orientation is different from the stored one.");
122  }
123 
124  return this->m_BasisMatrix;
125  }
126 
127  VectorType NormalizeUnitIntegral(const VectorType& x) const ITK_OVERRIDE
128  {
129  VectorType result(x);
130  if (x.GetTwoNorm()>0)
131  {
132  double normFactor = 4.0*M_PI/x.Size() * x.GetSum();
133  if (normFactor!=0)
134  result /= normFactor;
135  }
136  return result;
137  }
138 
139 
140 protected:
142  m_DataOrientations (new MatrixType())
143  {
144  }
146  {};
147 
148  void PrintSelf(std::ostream& os, Indent indent) const ITK_OVERRIDE
149  {
150  Superclass::PrintSelf(os, indent);
151  utl::PrintUtlMatrix(*this->m_DataOrientations, "m_DataOrientations", " ", os<<indent);
152  }
153 
155  MatrixPointer m_DataOrientations;
156 
157 private:
158  MeshFromSphericalFunctionTessellatedSamplesImageFilter(const Self&); //purposely not implemented
159  void operator=(const Self&);//purposely not implemented
160 
161 
162 };
163 
164 } // end namespace itk
165 
166 
167 #endif
Compute mesh from spherical samples in the pre-stored tessellated vertices.
void PrintUtlMatrix(const NDArray< T, 2 > &mat, const std::string &str="", const char *separate=" ", std::ostream &os=std::cout)
#define utlSAGlobalException(expr)
Definition: utlCoreMacro.h:362
MeshFromContinuousSphericalFunctionImageFilter< TInputImage, TOutputMesh > Superclass
NDArray< T, 2 > FlipOrientations(const NDArray< T, 2 > &in, const std::vector< int > &flip)
#define ITK_OVERRIDE
Definition: utlITKMacro.h:46
#define M_PI
Definition: utlCoreMacro.h:57
#define utlGlobalException(cond, expout)
Definition: utlCoreMacro.h:372
Superclass::OutputMeshPolyDataPointer OutputMeshPolyDataPointer
Compute mesh from continuous spherical function linearly represented by a set of bases.
#define utlShowPosition(cond)
Definition: utlCoreMacro.h:554
SmartPointer< Self > Pointer
Tesselates a sphere via subdivision of tetrahedron, octahedron, or icosahedron.