11 #ifndef __itkMeshFromFiberTractsFilter_hxx 12 #define __itkMeshFromFiberTractsFilter_hxx 16 #include <vtkPoints.h> 17 #include <vtkFloatArray.h> 18 #include <vtkDoubleArray.h> 19 #include <vtkPointData.h> 20 #include <vtkTubeFilter.h> 21 #include <vtkCellArray.h> 30 typename LightObject::Pointer
34 typename LightObject::Pointer loPtr = Superclass::InternalClone();
39 itkExceptionMacro(<<
"downcast to type " << this->GetNameOfClass()<<
" failed.");
42 rval->m_FiberTracts = m_FiberTracts;
43 rval->m_ColorScheme = m_ColorScheme;
44 rval->m_ShapeMode = m_ShapeMode;
45 rval->m_TubeRadius = m_TubeRadius;
46 rval->m_Mesh = m_Mesh;
47 rval->m_Flip = m_Flip;
49 for (
int i = 0; i < 3; ++i )
50 rval->m_Color[i] = m_Color[i];
59 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
60 vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
62 vtkSmartPointer<vtkUnsignedCharArray> scalars = vtkSmartPointer<vtkUnsignedCharArray>::New();
63 scalars->SetNumberOfComponents(3);
64 scalars->SetName(
"rgb_color");
68 int numFibers = m_FiberTracts->GetNumberOfFibers();
74 for (
int n = 0; n < numFibers; ++n )
76 auto fiber = m_FiberTracts->GetFiber(n);
77 int numPoints = fiber->GetNumberOfPoints();
85 lines->InsertNextCell(numPoints);
87 if (m_ColorScheme==COLOR_BY_MEAN_DIRECTION)
90 for (
int i = 0; i < numPoints; ++i )
92 auto vertex = fiber->GetPoint(i);
94 points->InsertPoint(count, vertex[0], vertex[1], vertex[2]);
95 lines->InsertCellPoint(count);
97 if (m_ColorScheme==COLOR_FIXED)
99 scalars->InsertTuple(count, m_Color);
101 else if (m_ColorScheme==COLOR_BY_POINT_DIRECTION)
103 auto diff = fiber->GetDirection(i);
110 for (
int d = 0; d < 3; ++d )
111 rgb[d] = std::fabs(dir[d])*255.0;
112 scalars->InsertTuple(count, rgb);
114 else if (m_ColorScheme==COLOR_BY_MEAN_DIRECTION)
116 auto diff = fiber->GetDirection(i);
124 else if (m_ColorScheme==COLOR_BY_IMAGE)
129 else if (m_ColorScheme==COLOR_BY_SCALARS)
134 else if (m_ColorScheme==COLOR_BY_PROPERTY)
143 if (m_ColorScheme==COLOR_BY_MEAN_DIRECTION)
145 double dirNorm = dirMean.GetTwoNorm();
148 for (
int d = 0; d < 3; ++d )
149 rgb[d] = std::fabs(dirMean[d])*255.0;
150 for (
int i = 0; i < numPoints; ++i )
151 scalars->InsertTuple(count-i, rgb);
153 else if (m_ColorScheme==COLOR_BY_ENDPOINTS_DIRECTION)
162 for (
int d = 0; d < 3; ++d )
163 rgb[d] = std::fabs(dir[d])*255.0;
164 for (
int i = 0; i < numPoints; ++i )
165 scalars->InsertTuple(count-i, rgb);
172 m_Mesh->SetPoints( points );
173 m_Mesh->SetLines( lines );
175 if (m_ColorScheme!=COLOR_NONE)
176 (m_Mesh->GetPointData())->SetScalars(scalars);
180 if (m_TubeRadius>0 && m_ShapeMode==GLYPH_TUBE)
182 vtkSmartPointer<vtkTubeFilter> tubeFilter = vtkTubeFilter::New();
183 tubeFilter->SetInputData(this->m_Mesh);
184 tubeFilter->SetRadius(m_TubeRadius);
185 tubeFilter->SetNumberOfSides(6);
186 tubeFilter->Update();
187 this->m_Mesh = tubeFilter->GetOutput();
NDArray<T,1> is a vector class which uses blas mkl.
void VectorToVector(const T1 &v1, T2 &v2, const int N)
double GetTwoNorm() const
void FlipVector(T1 &vec, const T2 &flip, const int N)
FiberType::VertexType VertexType
#define utlGlobalException(cond, expout)
#define utlPrintVar(cond,...)
LightObject::Pointer InternalClone() const ITK_OVERRIDE
Compute mesh from fibers.
SmartPointer< Self > Pointer