v2.0.0
Loading...
Searching...
No Matches
fwd_thread_arg.cpp
Go to the documentation of this file.
1//=============================================================================================================
37
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//=============================================================================================================
49// USED NAMESPACES
50//=============================================================================================================
51
52using namespace Eigen;
53using namespace FWDLIB;
54using namespace MNELIB;
55
56//=============================================================================================================
57// DEFINE MEMBER METHODS
58//=============================================================================================================
59
61:res (nullptr)
62,res_grad (nullptr)
63,off (0)
64,field_pot (nullptr)
65,vec_field_pot (nullptr)
66,field_pot_grad(nullptr)
67,coils_els (nullptr)
68,client (nullptr)
69,s (nullptr)
70,fixed_ori (false)
71,stat (-1)
72,comp (-1)
73{
74}
75
76//=============================================================================================================
77
83
84//=============================================================================================================
85
87{
88 auto res = std::make_unique<FwdThreadArg>();
89
90 *res = one;
91 res->client_free = nullptr; /* Don't copy the source's deleter */
92 if (bem_model) {
93 auto bem = std::make_shared<FwdBemModel>();
94 *bem = *static_cast<FwdBemModel*>(res->client);
95 bem->v0.resize(0);
96 res->client = bem.get();
97 res->client_free = [bem]() {}; /* shared_ptr releases FwdBemModel on destruction */
98 }
99 return res;
100}
101
102//=============================================================================================================
103
105{
106 auto res = std::make_unique<FwdThreadArg>();
107 FwdCompData* orig = static_cast<FwdCompData*>(one.client);
108
109 *res = one;
110 res->client_free = nullptr; /* Don't copy the source's deleter */
111
112 auto comp = std::make_shared<FwdCompData>();
113 *comp = *orig;
114 comp->comp_coils = nullptr; /* Non-owning: shared with original, prevent ~FwdCompData from deleting */
115 comp->set = nullptr; /* Will be replaced below; prevent dtor from deleting orig's copy */
116 comp->work.resize(0);
117 comp->vec_work.resize(0, 0);
118
119 std::shared_ptr<MNECTFCompDataSet> set_guard(
120 orig->set ? new MNECTFCompDataSet(*(orig->set)) : nullptr);
121 comp->set = set_guard.get();
122
123 res->client = comp.get();
124
125 if (bem_model) {
126 auto bem = std::make_shared<FwdBemModel>();
127 *bem = *static_cast<FwdBemModel*>(comp->client);
128 bem->v0.resize(0);
129 comp->client = bem.get();
130 /* shared_ptrs release their objects when client_free is destroyed */
131 res->client_free = [comp, set_guard, bem]() {
132 comp->set = nullptr; /* Prevent ~FwdCompData double-free; set_guard owns it */
133 };
134 }
135 else {
136 res->client_free = [comp, set_guard]() {
137 comp->set = nullptr; /* Prevent ~FwdCompData double-free; set_guard owns it */
138 };
139 }
140 return res;
141}
MNESourceSpace class declaration.
FwdCompData class declaration.
FwdCoilSet class declaration.
FwdThreadArg class declaration.
FwdBemModel class declaration.
Core MNE data structures (source spaces, source estimates, hemispheres).
Forward modelling (BEM, MEG/EEG lead fields).
Definition compute_fwd.h:91
BEM (Boundary Element Method) model definition.
Eigen::VectorXf v0
This structure is used in the compensated field calculations.
MNELIB::MNECTFCompDataSet * set
fwdFieldGradFunc field_pot_grad
std::unique_ptr< FwdThreadArg > UPtr
static FwdThreadArg::UPtr create_eeg_multi_thread_duplicate(FwdThreadArg &one, bool bem_model)
std::function< void()> client_free
Eigen::MatrixXf * res_grad
Eigen::MatrixXf * res
fwdVecFieldFunc vec_field_pot
static FwdThreadArg::UPtr create_meg_multi_thread_duplicate(FwdThreadArg &one, bool bem_model)
MNELIB::MNESourceSpace * s
Collection of CTF third-order gradient compensation operators.