DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkFiber.hxx
Go to the documentation of this file.
1 
12 #ifndef __itkFiber_hxx
13 #define __itkFiber_hxx
14 
15 #include "itkFiber.h"
16 #include "utlDMRI.h"
17 
18 namespace itk
19 {
20 
21 template< class TValue >
22 typename LightObject::Pointer
25 {
26  typename LightObject::Pointer loPtr = Superclass::InternalClone();
27 
28  typename Self::Pointer rval = dynamic_cast<Self *>(loPtr.GetPointer());
29  if(rval.IsNull())
30  {
31  itkExceptionMacro(<< "downcast to type " << this->GetNameOfClass()<< " failed.");
32  }
33 
34  rval->m_Tract = m_Tract;
35  rval->m_Properties = m_Properties;
36  rval->m_Scalars = m_Scalars;
37  return loPtr;
38 }
39 
40 template< class TValue >
43 ::DeepClone() const
44 {
45  Pointer out = Self::New();
46  *out->m_Scalars = *m_Scalars;
47  *out->m_Properties = *m_Properties;
48 
49  auto tract = out->GetTract();
50  auto vertexList = m_Tract->GetVertexList();
51  int numPoints = GetNumberOfPoints();
52  VertexType vertex;
53  for ( int i = 0; i < numPoints; ++i )
54  {
55  vertex = (*vertexList)[i];
56  tract->AddVertex(vertex);
57  }
58 
59  return out;
60 }
61 
62 template< class TValue >
63 double
65 ::DistanceToPoint(double x, double y, double z) const
66 {
67  VertexType vertex;
68  double d2=0, d2Min=std::numeric_limits<double>::max();
69  double dx, dy, dz;
70  for ( int i = 0; i < GetNumberOfPoints(); ++i )
71  {
72  vertex = GetPoint(i);
73  dx = x-vertex[0];
74  dy = y-vertex[1];
75  dz = z-vertex[2];
76  d2 = dx*dx+dy*dy+dz*dz;
77  if (d2 < d2Min)
78  d2Min = d2;
79  }
80  return std::sqrt(d2Min);
81 }
82 
83 template< class TValue >
84 std::vector<double>
87 {
88  std::vector<double> distVec;
89  VertexType p0, p1;
90  for ( int i = 1; i < GetNumberOfPoints(); ++i )
91  {
92  p0 = GetPoint(i-1);
93  p1 = GetPoint(i);
94  distVec.push_back(p0.EuclideanDistanceTo(p1));
95  }
96  return utl::GetContainerStats(distVec.begin(), distVec.end());
97 }
98 
99 template< class TValue >
100 void
102 ::RemoveScalarsByName(const std::string& name, const std::vector<std::string>& nameVec)
103 {
104  int numPoints = GetNumberOfPoints();
105  for ( int i = 0; i < numPoints; ++i )
106  {
107  utl::RemoveScalarsByName((*m_Scalars)[i], nameVec, name);
108  }
109 }
110 
111 template< class TValue >
112 void
114 ::RemovePropertiesByName(const std::string& name, const std::vector<std::string>& nameVec)
115 {
116  utl::RemoveScalarsByName(*m_Properties, nameVec, name);
117 }
118 
119 template< class TValue >
120 void
122 ::PrintSelf(std::ostream & os, Indent indent) const
123 {
124  // Superclass::PrintSelf(os, indent);
125 
126  int dim_s = GetDimensionOfScalarsPerPoint();
127  int dim_p = GetDimensionOfProperties();
128  PrintVar(true, os<<indent, dim_s, dim_p);
129 
130  // m_Tract->Print(os, indent);
131  auto points = m_Tract->GetVertexList();
132  os << indent << "points (" << (points) << "): (numberOfPoints: "<< points->size() << ") [";
133  for ( int i = 0; i < points->Size(); ++i )
134  {
135  os << points->GetElement(i);
136  os << ((i==points->Size()-1) ? "]\n" : ", ");
137  }
138 
139  if (dim_p>0)
140  utl::PrintVector(*m_Properties, "m_Properties", " ", os <<indent);
141  if (dim_s>0)
142  {
143  os << indent << "m_Scalars : [";
144  for ( int i = 0; i < m_Scalars->size(); ++i )
145  {
146  os << (*m_Scalars)[i];
147  os << ((i==m_Scalars->size()-1) ? "]\n" : ", ");
148  }
149  }
150 }
151 
152 }
153 
154 
155 #endif
156 
double DistanceToPoint(double x, double y, double z) const
Definition: itkFiber.hxx:65
LightObject::Pointer InternalClone() const ITK_OVERRIDE
Definition: itkFiber.hxx:24
TractType::VertexType VertexType
Definition: itkFiber.h:44
std::vector< double > GetContainerStats(IteratorType v1, IteratorType v2)
Definition: utlCore.h:921
void RemoveScalarsByName(std::vector< T > &vec, const std::vector< std::string > &nameVec, const std::string &name)
Definition: utlDMRI.h:153
Created "07-24-2017.
const T & max(const T &a, const T &b)
Return the maximum between a and b.
Definition: utlCore.h:263
std::vector< double > GetPointDistanceStats() const
Definition: itkFiber.hxx:86
void RemoveScalarsByName(const std::string &name, const std::vector< std::string > &nameVec)
Definition: itkFiber.hxx:102
void RemovePropertiesByName(const std::string &name, const std::vector< std::string > &nameVec)
Definition: itkFiber.hxx:114
SmartPointer< Self > Pointer
Definition: itkFiber.h:33
#define PrintVar(cond, os,...)
Definition: utlCoreMacro.h:242
void PrintVector(const std::vector< T > &vec, const std::string &str="", const char *separate=" ", std::ostream &os=std::cout, bool showStats=true)
Definition: utlCore.h:1002
virtual void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
Definition: itkFiber.hxx:122
int GetDimensionOfProperties(const TrackVisHeaderType &header)
Fiber< TValue >::Pointer DeepClone() const
Definition: itkFiber.hxx:43