Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkTransferFunctionInitializer.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 
18 
19 static const char *presetNames[] = {"choose an internal transferfunction preset",
20  "CT Generic",
21  "CT Black & White",
22  "CT Thorax large",
23  "CT Thorax small",
24  "CT Bone",
25  "CT Bone (with Gradient)",
26  "CT Cardiac",
27  "MR Generic"};
28 
29 static int numPresetNames = sizeof(presetNames) / sizeof(char *);
30 
31 namespace mitk
32 {
34  {
35  if (transferFunction.IsNotNull())
36  {
37  m_transferFunction = transferFunction;
38  }
39  }
40 
42  void TransferFunctionInitializer::GetPresetNames(std::vector<std::string> &names)
43  {
44  for (int i = 0; i < numPresetNames; ++i)
45  {
46  names.push_back(presetNames[i]);
47  }
48  }
49 
51  {
52  m_transferFunction = transferFunction;
53  }
54 
56  {
57  if (m_transferFunction)
58  {
59  m_Mode = mode;
61  }
62  }
63 
64  void TransferFunctionInitializer::RemoveAllPoints()
65  {
66  m_transferFunction->GetScalarOpacityFunction()->RemoveAllPoints();
67  m_transferFunction->GetColorTransferFunction()->RemoveAllPoints();
68  m_transferFunction->GetGradientOpacityFunction()->RemoveAllPoints();
69  }
70 
71  void TransferFunctionInitializer::SetModified()
72  {
73  m_transferFunction->GetScalarOpacityFunction()->Modified();
74  m_transferFunction->GetColorTransferFunction()->Modified();
75  m_transferFunction->GetGradientOpacityFunction()->Modified();
76  }
77 
79  {
80  if (m_transferFunction)
81  {
82  this->RemoveAllPoints();
83  switch (this->m_Mode)
84  {
85  case TF_CT_DEFAULT:
86  this->SetCtDefaultMode();
87  break;
88 
89  case TF_CT_BLACK_WHITE:
90  this->SetCtBlackWhiteMode();
91  break;
92 
93  case TF_CT_THORAX_LARGE:
94  this->SetCtThoraxLargeMode();
95  break;
96 
97  case TF_CT_THORAX_SMALL:
98  this->SetCtThoraxSmallMode();
99  break;
100 
101  case TF_CT_BONE:
102  this->SetCtBoneMode();
103  break;
104 
105  case TF_CT_BONE_GRADIENT:
106  this->SetCtBoneGradientMode();
107  break;
108 
109  case TF_CT_CARDIAC:
110  this->SetCtCardiacMode();
111  break;
112 
113  case TF_MR_GENERIC:
114  this->SetMrGenericMode();
115  break;
116 
117  default:
118  itkExceptionMacro(<< "No Mode set!");
119  break;
120  }
121 
122  this->SetModified();
123  }
124  else
125  {
126  itkExceptionMacro(<< "No Transferfunction set!");
127  }
128  }
129 
130  void TransferFunctionInitializer::SetCtDefaultMode()
131  {
132  // grayvalue->opacity
133  m_transferFunction->GetScalarOpacityFunction()->AddPoint(132.108911, 0.000000);
134  m_transferFunction->GetScalarOpacityFunction()->AddPoint(197.063492, 0.041333);
135  m_transferFunction->GetScalarOpacityFunction()->AddPoint(1087.917989, 0.700000);
136 
137  // gradient at grayvalue->opacity
138  m_transferFunction->GetGradientOpacityFunction()->AddPoint(560.695000, 1.000000);
139 
140  // grayvalue->color
141  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(176.881890, 0.650980, 0.000000, 0.000000);
142  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(239.427822, 0.933333, 0.000000, 0.000000);
143  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(301.973753, 1.000000, 0.800000, 0.062745);
144  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(495.866142, 1.000000, 0.905882, 0.666667);
145  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(677.249344, 1.000000, 0.882353, 0.215686);
146  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(808.595801, 1.000000, 1.000000, 1.000000);
147  }
148 
149  void TransferFunctionInitializer::SetCtBlackWhiteMode()
150  {
151  // Set Opacity
152  m_transferFunction->GetScalarOpacityFunction()->AddPoint(135.063521, 0.0);
153  m_transferFunction->GetScalarOpacityFunction()->AddPoint(948.137931, 1.0);
154 
155  // Set Color
156  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(122.088929, 0.352941, 0.352941, 0.352941);
157  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(372.931034, 1.000000, 1.000000, 1.000000);
158 
159  // Set Gradient
160  m_transferFunction->GetGradientOpacityFunction()->Initialize();
161  m_transferFunction->GetGradientOpacityFunction()->AddPoint(560.695000, 1);
162  }
163 
164  void TransferFunctionInitializer::SetCtThoraxLargeMode()
165  {
166  // grayvalue->opacity
167 
168  m_transferFunction->GetScalarOpacityFunction()->AddPoint(76.721239, 0.000000);
169  m_transferFunction->GetScalarOpacityFunction()->AddPoint(139.524336, 0.000000);
170  m_transferFunction->GetScalarOpacityFunction()->AddPoint(274.458333, 0.228650);
171  m_transferFunction->GetScalarOpacityFunction()->AddPoint(638.420139, 0.721763);
172 
173  // gradient at grayvalue->opacity
174  m_transferFunction->GetGradientOpacityFunction()->AddPoint(560.695000, 1.000000);
175 
176  // grayvalue->color
177  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(85.382743, 0.478431, 0.000000, 0.000000);
178  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(198.201327, 0.933333, 0.000000, 0.000000);
179  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(254.610619, 1.000000, 0.800000, 0.062745);
180  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(336.0907085, 1.000000, 0.905882, 0.666667);
181  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(630.672566, 1.000000, 1.000000, 1.000000);
182  }
183 
184  void TransferFunctionInitializer::SetCtThoraxSmallMode()
185  {
186  // grayvalue->opacity
187  m_transferFunction->GetScalarOpacityFunction()->AddPoint(147.216912, 0.000000);
188  m_transferFunction->GetScalarOpacityFunction()->AddPoint(274.458333, 0.228650);
189  m_transferFunction->GetScalarOpacityFunction()->AddPoint(430.330882, 0.675532);
190 
191  // gradient at grayvalue->opacity
192  m_transferFunction->GetGradientOpacityFunction()->AddPoint(560.695000, 1.000000);
193 
194  // grayvalue->color
195  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(129.607774, 0.478431, 0.000000, 0.000000);
196  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(213.812721, 0.933333, 0.000000, 0.000000);
197  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(348.540636, 1.000000, 0.800000, 0.062745);
198  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(500.419118, 1.000000, 0.898039, 0.776471);
199  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(579.268382, 1.000000, 1.000000, 1.000000);
200  }
201 
202  void TransferFunctionInitializer::SetCtBoneMode()
203  {
204  // grayvalue->opacity
205  m_transferFunction->GetScalarOpacityFunction()->AddPoint(126.413793, 0.000000);
206  m_transferFunction->GetScalarOpacityFunction()->AddPoint(178.312160, 0.014663);
207  m_transferFunction->GetScalarOpacityFunction()->AddPoint(247.509982, 0.000000);
208  m_transferFunction->GetScalarOpacityFunction()->AddPoint(1013.010889, 1.000000);
209 
210  // gradient at grayvalue->opacity
211  m_transferFunction->GetGradientOpacityFunction()->AddPoint(485.377495, 1.000000);
212 
213  // grayvalue->color
214  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(312.382940, 1.000000, 0.564706, 0.274510);
215  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(455.103448, 1.000000, 0.945098, 0.768627);
216  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(623.773140, 1.000000, 0.800000, 0.333333);
217  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(796.767695, 1.000000, 0.901961, 0.815686);
218  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(930.838475, 1.000000, 1.000000, 1.000000);
219  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(1073.558984, 1.000000, 0.839216, 0.423529);
220  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(1220.604356, 1.000000, 0.772549, 0.490196);
221  }
222 
223  void TransferFunctionInitializer::SetCtBoneGradientMode()
224  {
225  // grayvalue->opacity
226  m_transferFunction->GetScalarOpacityFunction()->AddPoint(126.413793, 0.000000);
227  m_transferFunction->GetScalarOpacityFunction()->AddPoint(186.961887, 0.146628);
228  m_transferFunction->GetScalarOpacityFunction()->AddPoint(247.509982, 0.000000);
229  m_transferFunction->GetScalarOpacityFunction()->AddPoint(1013.010889, 1.000000);
230 
231  // gradient at grayvalue->opacity
232  m_transferFunction->GetGradientOpacityFunction()->AddPoint(22.617060, 0.000000);
233  m_transferFunction->GetGradientOpacityFunction()->AddPoint(65.865699, 1.000000);
234 
235  // grayvalue->color
236  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(312.382940, 1.000000, 0.564706, 0.274510);
237  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(455.103448, 1.000000, 0.945098, 0.768627);
238  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(623.773140, 1.000000, 0.800000, 0.333333);
239  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(796.767695, 1.000000, 0.901961, 0.815686);
240  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(930.838475, 1.000000, 1.000000, 1.000000);
241  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(1073.558984, 1.000000, 0.839216, 0.423529);
242  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(1220.604356, 1.000000, 0.772549, 0.490196);
243  }
244 
245  void TransferFunctionInitializer::SetCtCardiacMode()
246  {
247  // Set Opacity
248  m_transferFunction->GetScalarOpacityFunction()->AddPoint(150.246824, 0.000000);
249  m_transferFunction->GetScalarOpacityFunction()->AddPoint(179.974592, 0.202346);
250  m_transferFunction->GetScalarOpacityFunction()->AddPoint(276.589837, 0.000000);
251  m_transferFunction->GetScalarOpacityFunction()->AddPoint(781.961887, 1.000000);
252 
253  // Set Color
254  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(395.500907, 1.000000, 0.000000, 0.000000);
255  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(410.364791, 1.000000, 0.749020, 0.000000);
256  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(484.684211, 1.000000, 0.878431, 0.662745);
257  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(588.731397, 1.000000, 0.784314, 0.482353);
258 
259  // Set Gradient
260  m_transferFunction->GetGradientOpacityFunction()->AddPoint(246.862069, 0.215827);
261  }
262 
263  void TransferFunctionInitializer::SetMrGenericMode()
264  {
265  // Set Opacity
266  m_transferFunction->GetScalarOpacityFunction()->AddPoint(0, 0);
267  m_transferFunction->GetScalarOpacityFunction()->AddPoint(20, 0);
268  m_transferFunction->GetScalarOpacityFunction()->AddPoint(40, 0.15);
269  m_transferFunction->GetScalarOpacityFunction()->AddPoint(120, 0.3);
270  m_transferFunction->GetScalarOpacityFunction()->AddPoint(220, 0.375);
271  m_transferFunction->GetScalarOpacityFunction()->AddPoint(1024, 0.5);
272 
273  // Set Color
274  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(0, 0, 0, 0);
275  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(20, 0.168627, 0, 0);
276  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(40, 0.403922, 0.145098, 0.0784314);
277  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(120, 0.780392, 0.607843, 0.380392);
278  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(220, 0.847059, 0.835294, 0.788235);
279  m_transferFunction->GetColorTransferFunction()->AddRGBPoint(1024, 1, 1, 1);
280 
281  // Set Gradient
282  m_transferFunction->GetGradientOpacityFunction()->AddPoint(0, 1);
283  m_transferFunction->GetGradientOpacityFunction()->AddPoint(255, 1);
284  }
285 
287 } // namespace
static void GetPresetNames(std::vector< std::string > &presetNames)
TransferFunctionInitializer(TransferFunction::Pointer transferFunction=nullptr)
static const char * presetNames[]
DataCollection - Class to facilitate loading/accessing structured data.
void SetTransferFunction(TransferFunction::Pointer transferFunction)
mitk::TransferFunction::Pointer GetTransferFunction()
static int numPresetNames