MNE-CPP  0.1.9
A Framework for Electrophysiology
fwd_thread_arg.cpp
Go to the documentation of this file.
1 //=============================================================================================================
38 //=============================================================================================================
39 // INCLUDES
40 //=============================================================================================================
41 
42 #include "fwd_thread_arg.h"
44 #include "fwd_coil_set.h"
45 #include "fwd_bem_model.h"
46 #include "fwd_comp_data.h"
47 
48 #ifndef TRUE
49 #define TRUE 1
50 #endif
51 
52 #ifndef FALSE
53 #define FALSE 0
54 #endif
55 
56 #ifndef FAIL
57 #define FAIL -1
58 #endif
59 
60 #ifndef OK
61 #define OK 0
62 #endif
63 
64 #define FREE_80(x) if ((char *)(x) != NULL) free((char *)(x))
65 
66 #define FREE_CMATRIX_80(m) mne_free_cmatrix_80((m))
67 
68 void mne_free_cmatrix_80 (float **m)
69 {
70  if (m) {
71  FREE_80(*m);
72  FREE_80(m);
73  }
74 }
75 
76 //=============================================================================================================
77 // USED NAMESPACES
78 //=============================================================================================================
79 
80 using namespace Eigen;
81 using namespace FWDLIB;
82 using namespace MNELIB;
83 
84 //=============================================================================================================
85 // DEFINE MEMBER METHODS
86 //=============================================================================================================
87 
88 FwdThreadArg::FwdThreadArg()
89 :res (NULL)
90 ,res_grad (NULL)
91 ,off (0)
92 ,field_pot (NULL)
93 ,vec_field_pot (NULL)
94 ,field_pot_grad(NULL)
95 ,coils_els (NULL)
96 ,client (NULL)
97 ,s (NULL)
98 ,fixed_ori (FALSE)
99 ,stat (FAIL)
100 ,comp (-1)
101 {
102 }
103 
104 //=============================================================================================================
105 
107 {
108 }
109 
110 //=============================================================================================================
111 
112 FwdThreadArg *FwdThreadArg::create_eeg_multi_thread_duplicate(FwdThreadArg *one, bool bem_model)
113 /*
114  * Create a duplicate to make the data structure thread safe
115  * Do not duplicate read-only parts of the relevant structures
116  */
117 {
118  FwdThreadArg* res = new FwdThreadArg;
119 
120  *res = *one;
121  if (bem_model) {
122  FwdBemModel* new_bem = new FwdBemModel;
123  FwdBemModel* orig_bem = (FwdBemModel*)res->client;
124 
125  *new_bem = *orig_bem;
126  new_bem->v0 = NULL;
127  res->client = new_bem;
128  }
129  return res;
130 }
131 
132 //=============================================================================================================
133 
134 void FwdThreadArg::free_eeg_multi_thread_duplicate(FwdThreadArg *one, bool bem_model)
135 {
136  if (!one){
137  qDebug("Pointer passed is null. Returning early.");
138  return;
139  }
140  if (bem_model) {
141  FwdBemModel* bem = (FwdBemModel*) one->client;
142  FREE_80(bem->v0);
143  FREE_80(bem);
144  }
145  one->client = NULL;
146  if(one)
147  delete one;
148 }
149 
150 //=============================================================================================================
151 
152 FwdThreadArg *FwdThreadArg::create_meg_multi_thread_duplicate(FwdThreadArg* one, bool bem_model)
153 /*
154  * Create a duplicate to make the data structure thread safe
155  * Do not duplicate read-only parts of the relevant structures
156  */
157 {
158  FwdThreadArg* res = new FwdThreadArg;
159  FwdCompData* orig = (FwdCompData*)one->client;
160  FwdCompData* comp = NULL;
161 
162  *res = *one;
163  res->client = comp = new FwdCompData;
164  *comp = *orig;
165  comp->work = NULL;
166  comp->vec_work = NULL;
167  comp->set = orig->set ? new MneCTFCompDataSet(*(orig->set)) : NULL;
168 
169  if (bem_model) {
170  FwdBemModel* new_bem = new FwdBemModel();
171  FwdBemModel* orig_bem = (FwdBemModel*)comp->client;
172 
173  *new_bem = *orig_bem;
174  new_bem->v0 = NULL;
175  comp->client = new_bem;
176  }
177  return res;
178 }
179 
180 //=============================================================================================================
181 
182 void FwdThreadArg::free_meg_multi_thread_duplicate(FwdThreadArg *one, bool bem_model)
183 
184 {
185  if (!one){
186  qDebug("Pointer passed is null. Returning early.");
187  return;
188  }
189 
190  FwdCompData* comp = (FwdCompData*)one->client;
191 
192  FREE_80(comp->work);
193  FREE_CMATRIX_80(comp->vec_work);
194  if(comp->set)
195  delete comp->set;
196 
197  if (bem_model) {
198  FwdBemModel* bem = (FwdBemModel*)comp->client;
199  FREE_80(bem->v0);
200  FREE_80(bem);
201  }
202  FREE_80(comp);
203  one->client = NULL;
204  if(one)
205  delete one;
206 }
Fwd Thread Argument (FwdThreadArg) class declaration.
Filter Thread Argument Description.
Holds the BEM model definition.
FwdBemModel class declaration.
FwdCompData class declaration.
One MNE CTF Compensation Data Set description.
FwdCoilSet class declaration.
This structure is used in the compensated field calculations.
Definition: fwd_comp_data.h:87
MneSourceSpaceOld class declaration.