Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkSimpSamp.h
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 #ifndef _SIMPSAMP
18 #define _SIMPSAMP
19 
20 #include <MitkFiberTrackingExports.h>
21 #include <mitkParticle.h>
22 #include <stdlib.h>
23 
24 using namespace std;
25 
26 namespace mitk
27 {
28 
32 class MITKFIBERTRACKING_EXPORT SimpSamp
33 {
34 
35  float *P;
36  int cnt;
37 
38 public:
40 
41 
43  {
44  P = (float*) malloc(sizeof(float)*1000);
45  objs = (EndPoint*) malloc(sizeof(EndPoint)*1000);
46  }
48  {
49  free(P);
50  free(objs);
51  }
52 
53  inline void clear()
54  {
55  cnt = 1;
56  P[0] = 0;
57  }
58 
59  inline void add(float p, EndPoint obj)
60  {
61  P[cnt] = P[cnt-1] + p;
62  objs[cnt-1] = obj;
63  cnt++;
64  }
65 
66  inline int draw(float prob)
67  {
68  float r = prob*P[cnt-1];
69  int j;
70  int rl = 1;
71  int rh = cnt-1;
72  while(rh != rl)
73  {
74  j = rl + (rh-rl)/2;
75  if (r < P[j])
76  {
77  rh = j;
78  continue;
79  }
80  if (r > P[j])
81  {
82  rl = j+1;
83  continue;
84  }
85  break;
86  }
87  return rh-1;
88  }
89 
90  inline EndPoint drawObj(float prob)
91  {
92  return objs[draw(prob)];
93  }
94 
95  inline bool isempty()
96  {
97  if (cnt == 1)
98  return true;
99  else
100  return false;
101  }
102 
103 
104  float probFor(int idx)
105  {
106  return (P[idx+1]-P[idx])/P[cnt-1];
107  }
108 
109  float probFor(EndPoint& t)
110  {
111  for (int i = 1; i< cnt;i++)
112  {
113  if (t == objs[i-1])
114  return probFor(i-1);
115  }
116  return 0;
117  }
118 };
119 
120 }
121 
122 #endif
123 
124 
void add(float p, EndPoint obj)
Definition: mitkSimpSamp.h:59
float probFor(int idx)
Definition: mitkSimpSamp.h:104
STL namespace.
DataCollection - Class to facilitate loading/accessing structured data.
EndPoint * objs
Definition: mitkSimpSamp.h:39
int draw(float prob)
Definition: mitkSimpSamp.h:66
Samples new tract from surrounding fiber segments.
Definition: mitkSimpSamp.h:32
EndPoint drawObj(float prob)
Definition: mitkSimpSamp.h:90
float probFor(EndPoint &t)
Definition: mitkSimpSamp.h:109