DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkFiberTractsReader.hxx
Go to the documentation of this file.
1 
11 #ifndef __itkFiberTractsReader_hxx
12 #define __itkFiberTractsReader_hxx
13 
14 #include "itkFiberTractsReader.h"
15 #include "utlDMRI.h"
16 
17 namespace itk
18 {
19 
21 {
24  if (format==TRACTS_TRK)
25  ReadTractsTRK();
26  else if (format==TRACTS_TCK)
27  ReadTractsTCK();
28  else if (format==TRACTS_VTK)
29  ReadTractsVTK();
30  else
31  {
32  utlGlobalException(true, "un-supported tract format");
33  }
34 }
35 
37 {
38  auto header = m_FiberTracts->GetHeader();
39  auto fibers = m_FiberTracts->GetFibers();
40 
42 
43  // int n_p = header->n_properties;
44  // int n_s = header->n_scalars;
45  int dim_p = itk::GetDimensionOfProperties(*header);
46  int dim_s = itk::GetDimensionOfScalars(*header);
47 
48  FILE* file;
49  file = fopen(m_FileName.c_str(), "rb");
50  fseek (file, 0, SEEK_END);
51  long fsize = ftell(file);
52  long offset=1000;
53  int numPoints;
54  float val[3+dim_s], val2[dim_p];
55  VertexType vertex;
56  while (offset<fsize)
57  {
58  fseek (file, offset, SEEK_SET);
59 
60  fread((char*)&numPoints, sizeof(int), 1, file);
61 
62  FiberPointer fiber = FiberType::New();
63  auto tract = fiber->GetTract();
64  auto properties = fiber->GetProperties();
65  auto scalars = fiber->GetScalars();
66  for ( int i = 0; i < numPoints; ++i )
67  {
68  fread((char*)&val, sizeof(float)*(3+dim_s), 1, file);
69  vertex[0]=val[0];
70  vertex[1]=val[1];
71  vertex[2]=val[2];
72  tract->AddVertex(vertex);
73  STDVectorType vec;
74  for ( int j = 0; j < dim_s; ++j )
75  vec.push_back(val[3+j]);
76  scalars->push_back(vec);
77  }
78 
79  fread((char*)&val2, sizeof(float)*dim_p, 1, file);
80  for ( int j = 0; j < dim_p; ++j )
81  properties->push_back(val[j]);
82 
83  fibers->InsertElement( fibers->Size(), fiber);
84 
85  offset += 4+ numPoints*(3+dim_s)*4 + dim_p*4;
86  }
87 
88  fclose (file);
89 }
90 
92 {
93  utlGlobalException(true, "TODO: read tracts in tck format");
94 }
95 
97 {
98  utlGlobalException(true, "TODO: read tracts in vtk format");
99 }
100 
101 }
102 
103 
104 #endif
105 
106 
static Pointer New()
FiberTractsType::FiberPointer FiberPointer
bool IsFileExist(const std::string &file)
Definition: utlCore.h:529
Created "08-23-2017.
FiberTractsPointer m_FiberTracts
int GetFiberTractsFormat(const std::string &filename)
Definition: utlDMRI.h:537
#define utlGlobalException(cond, expout)
Definition: utlCoreMacro.h:372
FiberType::VertexType VertexType
int GetDimensionOfScalars(const TrackVisHeaderType &header)
void ReadTrackVisHeader(const std::string &filename, TrackVisHeaderType &header)
FiberType::STDVectorType STDVectorType
int GetDimensionOfProperties(const TrackVisHeaderType &header)