Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkSphereInterpolator.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkSphereInterpolator.h"
18 
19 #include <usGetModuleContext.h>
20 #include <usModuleContext.h>
21 #include <usModule.h>
22 #include <usModuleResource.h>
23 #include <usModuleResourceStream.h>
24 
25 #include <mitkQBallImage.h>
26 
27 #include <fstream>
28 #include <exception>
29 
30 static const std::string BaryCoordsFileName = "FiberTrackingLUTBaryCoords.bin";
31 static const std::string IndicesFileName = "FiberTrackingLUTIndices.bin";
32 
34 {
35  m_ValidState = true;
36  if (lutPath.length()==0)
37  {
38  if (!LoadLookuptables())
39  {
40  m_ValidState = false;
41  return;
42  }
43  }
44  else
45  {
46  if (!LoadLookuptables(lutPath))
47  {
48  m_ValidState = false;
49  return;
50  }
51  }
52 
53  size = 301;
54  sN = (size-1)/2;
56  beta = 0.5;
57 
58  inva = (sqrt(1+beta)-sqrt(beta));
59  b = 1/(1-sqrt(1/beta + 1));
60 }
61 
63 {
64 
65 }
66 
67 bool SphereInterpolator::LoadLookuptables(const string& lutPath)
68 {
69  MITK_INFO << "SphereInterpolator: loading lookuptables from custom path: " << lutPath;
70 
71  string path = lutPath; path.append(BaryCoordsFileName);
72  std::ifstream BaryCoordsStream;
73  BaryCoordsStream.open(path.c_str(), ios::in | ios::binary);
74  MITK_INFO << "SphereInterpolator: 1 " << path;
75  if (!BaryCoordsStream.is_open())
76  {
77  MITK_INFO << "SphereInterpolator: could not load FiberTrackingLUTBaryCoords.bin from " << path;
78  return false;
79  }
80 
81  ifstream IndicesStream;
82  path = lutPath; path.append("FiberTrackingLUTIndices.bin");
83  IndicesStream.open(path.c_str(), ios::in | ios::binary);
84  MITK_INFO << "SphereInterpolator: 1 " << path;
85  if (!IndicesStream.is_open())
86  {
87  MITK_INFO << "SphereInterpolator: could not load FiberTrackingLUTIndices.bin from " << path;
88  return false;
89  }
90 
91  if (LoadLookuptables(BaryCoordsStream, IndicesStream))
92  {
93  MITK_INFO << "SphereInterpolator: first and second lut loaded successfully";
94  return true;
95  }
96 
97  return false;
98 }
99 
101 {
102  MITK_INFO << "SphereInterpolator: loading lookuptables";
103 
105  us::ModuleResource BaryCoordsRes = module->GetResource(BaryCoordsFileName);
106  if (!BaryCoordsRes.IsValid())
107  {
108  MITK_INFO << "Could not retrieve resource " << BaryCoordsFileName;
109  return false;
110  }
111 
112  us::ModuleResource IndicesRes = module->GetResource(IndicesFileName);
113  if (!IndicesRes)
114  {
115  MITK_INFO << "Could not retrieve resource " << IndicesFileName;
116  return false;
117  }
118 
119  us::ModuleResourceStream BaryCoordsStream(BaryCoordsRes, std::ios_base::binary);
120  us::ModuleResourceStream IndicesStream(IndicesRes, std::ios_base::binary);
121  return LoadLookuptables(BaryCoordsStream, IndicesStream);
122 }
123 
124 bool SphereInterpolator::LoadLookuptables(std::istream& BaryCoordsStream, std::istream& IndicesStream)
125 {
126  if (BaryCoordsStream)
127  {
128  try
129  {
130  float tmp;
131  BaryCoordsStream.seekg (0, ios::beg);
132  while (!BaryCoordsStream.eof())
133  {
134  BaryCoordsStream.read((char *)&tmp, sizeof(tmp));
135  barycoords.push_back(tmp);
136  }
137  }
138  catch (const std::exception& e)
139  {
140  MITK_INFO << e.what();
141  }
142  }
143  else
144  {
145  MITK_INFO << "SphereInterpolator: could not load FiberTrackingLUTBaryCoords.bin";
146  return false;
147  }
148 
149  if (IndicesStream)
150  {
151  try
152  {
153  int tmp;
154  IndicesStream.seekg (0, ios::beg);
155  while (!IndicesStream.eof())
156  {
157  IndicesStream.read((char *)&tmp, sizeof(tmp));
158  indices.push_back(tmp);
159  }
160  }
161  catch (const std::exception& e)
162  {
163  MITK_INFO << e.what();
164  }
165  }
166  else
167  {
168  MITK_INFO << "SphereInterpolator: could not load FiberTrackingLUTIndices.bin";
169  return false;
170  }
171 
172  return true;
173 }
#define MITK_INFO
Definition: mitkLogMacros.h:22
vector< float > barycoords
SphereInterpolator(const string &lutPath)
Module * GetModule() const
static const std::string BaryCoordsFileName
#define QBALL_ODFSIZE
static const std::string IndicesFileName
static bool in(Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4)
Definition: jsoncpp.cpp:244
ModuleResource GetResource(const std::string &path) const
Definition: usModule.cpp:267
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.