28#include <QCoreApplication>
58#define ALLOC_ICMATRIX_41(x,y) mne_imatrix_41((x),(y))
60#define MALLOC_41(x,t) (t *)malloc((x)*sizeof(t))
61#define REALLOC_41(x,y,t) (t *)((x == Q_NULLPTR) ? malloc((y)*sizeof(t)) : realloc((x),(y)*sizeof(t)))
63#define FREE_41(x) if ((char *)(x) != Q_NULLPTR) free((char *)(x))
65#define VEC_COPY_41(to,from) {\
66 (to)[X_41] = (from)[X_41];\
67 (to)[Y_41] = (from)[Y_41];\
68 (to)[Z_41] = (from)[Z_41];\
71#define VEC_DOT_41(x,y) ((x)[X_41]*(y)[X_41] + (x)[Y_41]*(y)[Y_41] + (x)[Z_41]*(y)[Z_41])
73#define VEC_LEN_41(x) sqrt(VEC_DOT_41(x,x))
75#define ALLOC_CMATRIX_41(x,y) mne_cmatrix_41((x),(y))
76#define FREE_CMATRIX_41(m) mne_free_cmatrix_41((m))
77#define FREE_ICMATRIX_41(m) mne_free_icmatrix_41((m))
79static void matrix_error_41(
int kind,
int nr,
int nc)
83 printf(
"Failed to allocate memory pointers for a %d x %d matrix\n",nr,nc);
85 printf(
"Failed to allocate memory for a %d x %d matrix\n",nr,nc);
87 printf(
"Allocation error for a %d x %d matrix\n",nr,nc);
88 if (
sizeof(
void *) == 4) {
89 printf(
"This is probably because you seem to be using a computer with 32-bit architecture.\n");
90 printf(
"Please consider moving to a 64-bit platform.");
92 printf(
"Cannot continue. Sorry.\n");
104 if (!m) matrix_error_41(1,nr,nc);
106 if (!whole) matrix_error_41(2,nr,nc);
120 if (!m) matrix_error_41(1,nr,nc);
122 if (!whole) matrix_error_41(2,nr,nc);
150 if(!stream->open()) {
156 id->version = stream->id().version;
157 id->machid[0] = stream->id().machid[0];
158 id->machid[1] = stream->id().machid[1];
159 id->time = stream->id().time;
334 QList<FiffChInfo>& listMegCh,
336 QList<FiffChInfo>& listMegComp,
338 QList<FiffChInfo>& listEegCh,
343 int iNumCh = pFiffInfoBase->nchan;
344 for (
int k = 0; k < iNumCh; k++) {
346 listMegCh.append(pFiffInfoBase->chs[k]);
349 listMegComp.append(pFiffInfoBase->chs[k]);
351 }
else if (pFiffInfoBase->chs[k].kind ==
FIFFV_EEG_CH) {
352 listEegCh.append(pFiffInfoBase->chs[k]);
357 if(m_pSettings->meg_head_t.isEmpty()) {
358 transDevHead = pFiffInfoBase->dev_head_t;
360 transDevHead = m_pSettings->meg_head_t;
362 if(m_meg_head_t.isEmpty()) {
363 qCritical(
"MEG -> head coordinate transformation not found.");
366 id = pFiffInfoBase->meas_id;
380 for (k = 0; k < nch; k++) {
382 if (chs.at(k).chpos.r0.norm() < close) {
383 qCritical(
"Some EEG channels do not have locations assigned.");
402 srand ( time(Q_NULLPTR) );
403 double rand_1 = (double)(rand() % 100);rand_1 /= 100;
404 double rand_2 = (double)(rand() % 100);rand_2 /= 100;
407 seconds = time (Q_NULLPTR);
411 t_id->
machid[0] = 65536*rand_1;
412 t_id->
machid[1] = 65536*rand_2;
421 *t_pStream << (qint32)
kind;
423 *t_pStream << (qint32)datasize;
430 data[1] = t_id->
machid[0];
431 data[2] = t_id->
machid[1];
435 for(qint32 i = 0; i < 5; ++i)
436 *t_pStream << data[i];
455 *t_pStream << (qint32)datasize;
461 *t_pStream << (qint32)trans.
from;
462 *t_pStream << (qint32)trans.
to;
468 for (r = 0; r < 3; ++r)
469 for (c = 0; c < 3; ++c)
470 *t_pStream << (
float)trans.
rot()(r,c);
471 for (r = 0; r < 3; ++r)
472 *t_pStream << (
float)trans.
move()(r);
477 for (r = 0; r < 3; ++r)
478 for (c = 0; c < 3; ++c)
479 *t_pStream << (
float)trans.
invrot()(r,c);
480 for (r = 0; r < 3; ++r)
481 *t_pStream << (
float)trans.
invmove()(r);
491static int **make_file_triangle_list_41(
int **tris,
int ntri)
499 for (j = 0; j < ntri; j++)
500 for (k = 0; k < 3; k++)
501 res[j][k] = tris[j][k]+1;
554 MatrixXf mat(rows,cols);
556 for (
int i = 0; i < rows; ++i) {
557 for(
int j = 0; j < cols; ++j) {
558 mat(i,j) = data[i][j];
562 t_pStream->write_float_matrix(
kind, mat);
628 MatrixXi mat(rows,cols);
630 for (
int i = 0; i < rows; ++i) {
631 for(
int j = 0; j < cols; ++j) {
632 mat(i,j) = data[i][j];
636 t_pStream->write_int_matrix(
kind, mat);
701 int datasize,idxsize,ptrsize;
711 qCritical(
"Incomprehensible sparse matrix coding");
715 if (datasize <= 0 || idxsize <= 0 || ptrsize <= 0) {
716 qCritical(
"fiff_write_float_ccs_matrix: negative vector size(s) in sparse matrix!\n");
726 qCritical(
"Incomprehensible sparse matrix coding");
735 *t_pStream << (qint32)
kind;
736 *t_pStream << (qint32)type;
737 *t_pStream << (qint32)(datasize+idxsize+ptrsize+4*
sizeof(
fiff_int_t));
745 for(k = 0; k < mat->
nz; ++k)
746 *t_pStream << mat->
data[k];
766 for(k = 0; k < mat->
nz; ++k)
767 *t_pStream << mat->
inds[k];
786 for(k = 0; k < mat->
n+1; ++k)
787 *t_pStream << mat->
ptrs[k];
803 for(k = 0; k < mat->
m+1; ++k)
804 *t_pStream << mat->
ptrs[k];
821 *t_pStream << (qint32)mat->
nz;
826 *t_pStream << (qint32)mat->
m;
831 *t_pStream << (qint32)mat->
n;
836 *t_pStream << (qint32)two;
861 for (j = 0, nz = 0; j < nrow; j++)
865 qCritical(
"No nonzero elements specified.");
874 sparse->
data.resize(nz);
875 sparse->
data.setZero();
876 sparse->
inds.resize(nz);
877 sparse->
inds.setZero();
878 sparse->
ptrs.resize(nrow + 1);
879 sparse->
ptrs.setZero();
881 for (j = 0, nz = 0; j < nrow; j++) {
883 for (k = 0; k < nnz[j]; k++) {
886 ind = sparse->
inds[nz] = colindex[j][k];
887 if (ind < 0 || ind >= ncol) {
888 qCritical(
"Column index out of range in mne_create_sparse_rcs");
893 sparse->
data[nz] = vals[j][k];
895 sparse->
data[nz] = 0.0;
898 sparse->
ptrs[j] = ptr;
900 sparse->
ptrs[nrow] = nz;
901 for (j = nrow-1; j >= 0; j--)
902 if (sparse->
ptrs[j] < 0)
903 sparse->
ptrs[j] = sparse->
ptrs[j+1];
915 qCritical(
"The input matrix to mne_add_upper_triangle_rcs must be in RCS format");
918 if (mat->
m != mat->
n) {
919 qCritical(
"The input matrix to mne_pick_lower_triangle_rcs must be square");
925 std::vector<int> nnz(mat->
m);
926 std::vector<std::vector<int>> colindex(mat->
m);
927 std::vector<std::vector<float>> vals(mat->
m);
929 for (i = 0; i < mat->
m; i++) {
930 nnz[i] = mat->
ptrs[i+1] - mat->
ptrs[i];
932 colindex[i].resize(nnz[i]);
933 vals[i].resize(nnz[i]);
934 for (j = mat->
ptrs[i], k = 0; j < mat->ptrs[i+1]; j++) {
935 if (mat->
inds[j] <= i) {
936 vals[i][k] = mat->
data[j];
937 colindex[i][k] = mat->
inds[j];
947 std::vector<int*> ci_ptrs(mat->
m);
948 std::vector<float*> val_ptrs(mat->
m);
949 for (i = 0; i < mat->
m; i++) {
950 ci_ptrs[i] = colindex[i].empty() ? nullptr : colindex[i].data();
951 val_ptrs[i] = vals[i].empty() ? nullptr : vals[i].data();
957static int write_volume_space_info(
FiffStream::SPtr& t_pStream, MNESourceSpace* ss,
int selected_only)
963 int *nneighbors = Q_NULLPTR;
964 int *neighbors = Q_NULLPTR;
965 int *inuse_map = Q_NULLPTR;
976 for (k = 0,p = 0, ntot = 0; k < ss->
np; k++) {
990 for (k = 0, nvert = 0, ntot = 0; k < ss->
np; k++) {
994 nneighbors[nvert++] = nneigh;
995 for (p = 0; p < nneigh; p++)
996 neighbors[ntot++] = neigh[p] < 0 ? -1 : inuse_map[neigh[p]];
1001 for (k = 0, ntot = 0; k < ss->
np; k++)
1006 for (k = 0, ntot = 0; k < ss->
np; k++) {
1009 nneighbors[k] = nneigh;
1010 for (p = 0; p < nneigh; p++)
1011 neighbors[ntot++] = neigh[p];
1036 if (!selected_only) {
1069 qCritical(
"Cannot write the interpolator for selection yet");
1086 float **sel = Q_NULLPTR;
1087 int **tris = Q_NULLPTR;
1088 int *nearest = Q_NULLPTR;
1089 float *nearest_dist = Q_NULLPTR;
1093 qCritical(
"No points in the source space being saved");
1113 if (selected_only) {
1114 if (ss->
nuse == 0) {
1115 qCritical(
"No vertices in use. Cannot write active-only vertices from this source space");
1120 for (p = 0, pp = 0; p < ss->
np; p++) {
1130 for (p = 0, pp = 0; p < ss->
np; p++) {
1160 FREE_ICMATRIX(tris); tris = Q_NULLPTR;
1172 if (ss->
nuse > 0 && ss->
inuse.size() > 0) {
1189 Eigen::MatrixXi file_tris = ss->
itris.array() + 1;
1199 Eigen::MatrixXi file_use_tris = ss->
use_itris.array() + 1;
1211 for (p = 0; p < ss->
np; p++) {
1212 nearest[p] = ss->
nearest[p].nearest;
1213 nearest_dist[p] = ss->
nearest[p].dist;
1234 FREE_41(nearest); nearest = Q_NULLPTR;
1235 FREE_41(nearest_dist); nearest_dist = Q_NULLPTR;
1275 int nlist = list.size();
1277 if (nlist == 0 || list.isEmpty())
1280 for (
int k = 0; k < nlist-1; k++) {
1284 res += list[nlist-1];
1301 if (!mat->
rowlist.isEmpty()) {
1305 if (!mat->
collist.isEmpty()) {
1309 t_pStream->write_float_matrix(
kind, mat->
data);
1321 int nent = dir.size();
1326 for (k = 0; k < nent; k++) {
1331 if (!t_pStream->read_tag(t_pTag,dir[k]->pos)) {
1332 fprintf (stderr,
"Could not read FIFF_DIR_POINTER!\n");
1338 dirpos = *t_pTag->toInt();
1344 dirpos = (
fiff_int_t)t_pStream->write_dir_entries(dir);
1346 printf (
"Could not update directory!\n");
1348 t_pTag->setNum(dirpos);
1351 t_pStream->write_dir_pointer(dirpos, dir[k]->pos);
1368 printf (
"Could not find place for directory!\n");
1375 std::vector<std::unique_ptr<MNESourceSpace>>& spaces,
1376 const QString& mri_file,
1379 const QString& meas_file,
1382 QList<FiffChInfo> meg_chs,
1384 QList<FiffChInfo> eeg_chs,
1419 if (mri_id != Q_NULLPTR)
1430 QStringList file_bads;
1440 int nchan = nmeg+neeg;
1444 for (k = 0, p = 0; k < nmeg; k++) {
1445 meg_chs[k].scanNo = ++p;
1446 t_pStream->write_ch_info(meg_chs[k]);
1449 for (k = 0; k < neeg; k++) {
1450 eeg_chs[k].scanNo = ++p;
1451 if (k == 0) fprintf(stderr,
"[write_solution] EEG[0] scanNo=%d, p=%d, nmeg=%d, neeg=%d\n", eeg_chs[k].scanNo, p, nmeg, neeg);
1452 t_pStream->write_ch_info(eeg_chs[k]);
1454 fprintf(stderr,
"[write_solution] after loops: nmeg=%d, neeg=%d, p=%d, meg_chs.size=%lld, eeg_chs.size=%lld\n", nmeg, neeg, p, (
long long)meg_chs.size(), (
long long)eeg_chs.size());
1462 QFile fileBad(meas_file);
1464 if(!t_pStreamBads->open())
1466 file_bads = t_pStreamBads->read_bad_channels(t_pStreamBads->dirtree());
1479 for (k = 0, nvert = 0; k < static_cast<int>(spaces.size()); k++) {
1482 nvert += spaces[k]->nuse;
1545 t_pStream->end_file();
1557 t_pStreamIn->close();
1565 t_pStreamIn->close();
1580 QString cwd = QDir::currentPath();
1585 QFile fileInOut(
name);
1599 if (!fileInOut.exists()) {
1600 qCritical(
"File %s does not exist. Cannot attach env info.",
name.toUtf8().constData());
1615 for (insert = -1, b = 0; insert_blocks[b] >= 0; b++) {
1616 for (k = 0; k < t_pStreamInOut->nent(); k++) {
1618 if (!t_pStreamInOut->read_tag(t_pTag, t_pStreamInOut->dir()[k]->pos))
1620 if (*(t_pTag->toInt()) == insert_blocks[b]) {
1630 qCritical(
"Suitable place for environment insertion not found.");
1644 if (where < 0 || where >= t_pStreamInOut->nent()-1) {
1645 qCritical(
"illegal insertion point in fiff_insert_after!");
1650 QList<FiffDirEntry::SPtr> old_dir = t_pStreamInOut->dir();
1651 QList<FiffDirEntry::SPtr> this_ent = old_dir.mid(where);
1653 if (!t_pStreamInOut->read_tag(t_pTagNext, this_ent[0]->pos))
1658 qint64 next_tmp = t_pStreamInOut->device()->pos();
1662 t_pStreamInOut->device()->seek(fileInOut.size());
1667 QList<FiffDirEntry::SPtr> new_dir = old_dir.mid(0,where+1);
1672 qint64 old_end = t_pStreamInOut->device()->pos();
1683 new_this->size = 1 * 4;
1685 new_dir.append(new_this);
1690 new_this->size = 5 * 4;
1692 new_dir.append(new_this);
1697 new_this->size = cwd.size();
1699 new_dir.append(new_this);
1704 new_this->size = command.size();
1706 new_dir.append(new_this);
1711 new_this->size = 1 * 4;
1713 new_this->pos = t_pStreamInOut->end_block(
FIFFB_MNE_ENV,next_tmp);
1714 new_dir.append(new_this);
1719 new_dir.append(old_dir.mid(where+1));
1725 t_pTagNext->next = (qint32)old_end;
1726 t_pStreamInOut->write_tag(t_pTagNext,this_ent[0]->pos);
1731 t_pStreamInOut->dir() = new_dir;
1753 , m_pSettings(pSettings)
1773void ComputeFwd::initFwd()
1782 m_listMegChs = QList<FiffChInfo>();
1783 m_listEegChs = QList<FiffChInfo>();
1784 m_listCompChs = QList<FiffChInfo>();
1790 m_templates = Q_NULLPTR;
1791 m_megcoils = Q_NULLPTR;
1792 m_compcoils = Q_NULLPTR;
1793 m_eegels = Q_NULLPTR;
1794 m_eegModels = Q_NULLPTR;
1798 m_mri_id = Q_NULLPTR;
1802 QTextStream *filteredStream = Q_NULLPTR;
1804 m_eegModel = Q_NULLPTR;
1805 m_bemModel = Q_NULLPTR;
1812 printf(
"Source space : %s\n",m_pSettings->srcname.toUtf8().constData());
1813 if (!(m_pSettings->transname.isEmpty()) || !(m_pSettings->mriname.isEmpty())) {
1814 printf(
"MRI -> head transform source : %s\n",!(m_pSettings->mriname.isEmpty()) ? m_pSettings->mriname.toUtf8().constData() : m_pSettings->transname.toUtf8().constData());
1816 printf(
"MRI and head coordinates are assumed to be identical.\n");
1818 printf(
"Measurement data : %s\n",m_pSettings->measname.toUtf8().constData());
1819 if (!m_pSettings->bemname.isEmpty()) {
1820 printf(
"BEM model : %s\n",m_pSettings->bemname.toUtf8().constData());
1822 printf(
"Sphere model : origin at (% 7.2f % 7.2f % 7.2f) mm\n",
1823 1000.0f*m_pSettings->r0[
X_41],1000.0f*m_pSettings->r0[
Y_41],1000.0f*m_pSettings->r0[
Z_41]);
1824 if (m_pSettings->include_eeg) {
1827 if (m_pSettings->eeg_model_file.isEmpty()) {
1828 qCritical(
"!!!!!!!!!!TODO: default_eeg_model_file();");
1832 m_eegModels->fwd_list_eeg_sphere_models(stderr);
1834 if (m_pSettings->eeg_model_name.isEmpty()) {
1835 m_pSettings->eeg_model_name = QString(
"Default");
1837 if ((m_eegModel = m_eegModels->fwd_select_eeg_sphere_model(m_pSettings->eeg_model_name)) == Q_NULLPTR) {
1841 if (!m_eegModel->fwd_setup_eeg_sphere_model(m_pSettings->eeg_sphere_rad,m_pSettings->use_equiv_eeg,3)) {
1845 printf(
"Using EEG sphere model \"%s\" with scalp radius %7.1f mm\n",
1846 m_pSettings->eeg_model_name.toUtf8().constData(),1000*m_pSettings->eeg_sphere_rad);
1847 printf(
"%s the electrode locations to scalp\n",m_pSettings->scale_eeg_pos ?
"Scale" :
"Do not scale");
1849 m_eegModel->scale_pos = m_pSettings->scale_eeg_pos;
1855 printf(
"%s field computations\n",m_pSettings->accurate ?
"Accurate" :
"Standard");
1857 printf(
"%s source orientations\n",m_pSettings->fixed_ori ?
"Fixed" :
"Free");
1858 if (m_pSettings->compute_grad) {
1859 printf(
"Compute derivatives with respect to source location coordinates\n");
1861 printf(
"Destination for the solution : %s\n",m_pSettings->solname.toUtf8().constData());
1862 if (m_pSettings->do_all) {
1863 printf(
"Calculate solution for all source locations.\n");
1865 if (m_pSettings->nlabel > 0) {
1866 printf(
"Source space will be restricted to sources in %d labels\n",m_pSettings->nlabel);
1872 printf(
"Reading %s...\n",m_pSettings->srcname.toUtf8().constData());
1876 for (k = 0, m_iNSource = 0; k < static_cast<int>(m_spaces.size()); k++) {
1877 if (m_pSettings->do_all) {
1878 m_spaces[k]->enable_all_sources();
1880 m_iNSource += m_spaces[k]->nuse;
1882 if (m_iNSource == 0) {
1883 qCritical(
"No sources are active in these source spaces. --all option should be used.");
1886 printf(
"Read %d source spaces a total of %d active source locations\n",
static_cast<int>(m_spaces.size()),m_iNSource);
1893 if (!m_pSettings->mriname.isEmpty()) {
1895 if (m_mri_head_t.isEmpty()) {
1898 if ((m_mri_id =
get_file_id(m_pSettings->mriname)) == Q_NULLPTR) {
1899 qCritical(
"Couln't read MRI file id (How come?)");
1903 else if (!m_pSettings->transname.isEmpty()) {
1912 m_mri_head_t.print();
1917 if(!m_pSettings->pFiffInfo) {
1919 QFile measname(m_pSettings->measname);
1922 FIFFLIB::FiffInfo fiffInfo;
1923 if(!pStream->open()) {
1924 qCritical() <<
"Could not open Stream.";
1929 if(!pStream->read_meas_info(pStream->dirtree(), fiffInfo, DirNode)){
1930 qCritical() <<
"Could not find the channel information.";
1934 m_pInfoBase = QSharedPointer<FIFFLIB::FiffInfo>(
new FiffInfo(fiffInfo));
1936 m_pInfoBase = m_pSettings->pFiffInfo;
1939 qCritical (
"ComputeFwd::initFwd(): no FiffInfo");
1942 if (mne_read_meg_comp_eeg_ch_info_41(m_pInfoBase,
1954 m_iNChan = iNMeg + iNEeg;
1958 printf(
"Read %3d MEG channels from %s\n",iNMeg,m_pSettings->measname.toUtf8().constData());
1961 printf(
"Read %3d MEG compensation channels from %s\n",iNComp,m_pSettings->measname.toUtf8().constData());
1964 printf(
"Read %3d EEG channels from %s\n",iNEeg,m_pSettings->measname.toUtf8().constData());
1966 if (!m_pSettings->include_meg) {
1967 printf(
"MEG not requested. MEG channels omitted.\n");
1968 m_listMegChs.clear();
1969 m_listCompChs.clear();
1974 m_meg_head_t.print();
1975 if (!m_pSettings->include_eeg) {
1976 printf(
"EEG not requested. EEG channels omitted.\n");
1977 m_listEegChs.clear();
1987 if (m_pSettings->include_meg) {
1988 qPath = QString(QCoreApplication::applicationDirPath() +
"/../resources/general/coilDefinitions/coil_def.dat");
1990 if ( !QCoreApplication::startingUp() ) {
1991 qPath = QCoreApplication::applicationDirPath() + QString(
"/../resources/general/coilDefinitions/coil_def.dat");
1992 }
else if (!
file.exists()) {
1993 qPath =
"../resources/general/coilDefinitions/coil_def.dat";
2008 if (m_compData->ncomp > 0) {
2009 printf(
"%d compensation data sets in %s\n",m_compData->ncomp,m_pSettings->measname.toUtf8().constData());
2011 m_listCompChs.clear();
2018 FiffCoordTrans head_mri_t = m_mri_head_t.inverted();
2023 if ((m_megcoils = m_templates->create_meg_coils(m_listMegChs,
2026 meg_mri_t)) == Q_NULLPTR) {
2030 if ((m_compcoils = m_templates->create_meg_coils(m_listCompChs,
2033 meg_mri_t)) == Q_NULLPTR) {
2039 head_mri_t)) == Q_NULLPTR) {
2043 printf(
"MRI coordinate coil definitions created.\n");
2045 if ((m_megcoils = m_templates->create_meg_coils(m_listMegChs,
2048 m_meg_head_t)) == Q_NULLPTR) {
2053 if ((m_compcoils = m_templates->create_meg_coils(m_listCompChs,
2060 iNEeg)) == Q_NULLPTR) {
2063 printf(
"Head coordinate coil definitions created.\n");
2072 printf(
"Source spaces are now in %s coordinates.\n",
FiffCoordTrans::frame_name(m_pSettings->coord_frame).toUtf8().constData());
2076 if (!m_pSettings->bemname.isEmpty()) {
2079 m_pSettings->bemname = bemsolname;
2081 printf(
"\nSetting up the BEM model using %s...\n",m_pSettings->bemname.toUtf8().constData());
2082 printf(
"\nLoading surfaces...\n");
2086 printf(
"Three-layer model surfaces loaded.\n");
2093 printf(
"Homogeneous model surface loaded.\n");
2095 if (iNEeg > 0 && m_bemModel->nsurf == 1) {
2096 qCritical(
"Cannot use a homogeneous model in EEG calculations.");
2099 printf(
"\nLoading the solution matrix...\n");
2104 printf(
"Employing the head->MRI coordinate transform with the BEM model.\n");
2109 printf(
"BEM model %s is now set up\n",m_bemModel->sol_name.toUtf8().constData());
2111 printf(
"Using the sphere model.\n");
2117 if (m_pSettings->filter_spaces) {
2118 if (!m_pSettings->mindistoutname.isEmpty()) {
2119 filteredFile.setFileName(m_pSettings->mindistoutname);
2120 if (!filteredFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
2121 qCritical() << m_pSettings->mindistoutname;
2124 filteredStream =
new QTextStream(&filteredFile);
2125 printf(
"Omitted source space points will be output to : %s\n",m_pSettings->mindistoutname.toUtf8().constData());
2128 m_pSettings->bemname,
2131 filteredStream,m_pSettings->use_threads);
2132 delete filteredStream;
2133 filteredStream = Q_NULLPTR;
2145 iNMeg = m_megcoils->ncoil;
2148 iNEeg = m_eegels->ncoil;
2151 m_pSettings->use_threads =
false;
2167 m_pSettings->fixed_ori,
2170 m_pSettings->use_threads,
2173 m_pSettings->compute_grad)) ==
FAIL) {
2180 m_pSettings->fixed_ori,
2183 m_pSettings->use_threads,
2186 m_pSettings->compute_grad))==
FAIL) {
2190 if(iNMeg > 0 && iNEeg > 0) {
2192 qWarning() <<
"The MEG and EEG forward solutions do not match";
2201 }
else if (iNMeg > 0) {
2207 if(m_pSettings->compute_grad) {
2208 if(iNMeg > 0 && iNEeg > 0) {
2210 qWarning() <<
"The MEG and EEG forward solutions do not match";
2219 }
else if (iNMeg > 0) {
2234 iNMeg = m_megcoils->ncoil;
2239 iNComp = m_compcoils->ncoil;
2249 if ((m_megcoils = m_templates->create_meg_coils(m_listMegChs,
2252 meg_mri_t)) == Q_NULLPTR) {
2256 if ((m_compcoils = m_templates->create_meg_coils(m_listCompChs,
2259 meg_mri_t)) == Q_NULLPTR) {
2264 if ((m_megcoils = m_templates->create_meg_coils(m_listMegChs,
2267 transDevHead)) == Q_NULLPTR) {
2272 if ((m_compcoils = m_templates->create_meg_coils(m_listCompChs,
2292 m_pSettings->fixed_ori,
2295 m_pSettings->use_threads,
2298 m_pSettings->compute_grad)) ==
FAIL) {
2303 m_meg_head_t = transDevHead;
2306 if(m_pSettings->compute_grad) {
2323 int iNMeg = m_megcoils->ncoil;
2324 int iNEeg = m_eegels->ncoil;
2328 if(sSolName ==
"default") {
2329 sName = m_pSettings->solname;
2334 printf(
"\nwriting %s...",sSolName.toUtf8().constData());
2338 m_pSettings->mriname,m_mri_id,
2340 m_pSettings->measname,m_meas_id,
2346 m_pSettings->fixed_ori,
2347 m_pSettings->coord_frame,
2352 m_pSettings->compute_grad)) {
2356 if (!
mne_attach_env(m_pSettings->solname,m_pSettings->command)) {
2360 printf(
"\nFinished.\n");
FIFF class declaration, which provides static wrapper functions to stay consistent with mne matlab to...
#define FIFF_MNE_SOURCE_SPACE_ID
#define FIFF_MNE_SOURCE_SPACE_DIST_LIMIT
#define FIFF_MNE_SOURCE_SPACE_VOXEL_DIMS
#define FIFF_MNE_COORD_FRAME
#define FIFF_MNE_FORWARD_SOLUTION_GRAD
#define FIFF_MNE_SOURCE_ORIENTATION
#define FIFF_MNE_SOURCE_SPACE_TYPE
#define FIFFV_MNE_SURF_UNKNOWN
#define FIFF_MNE_SOURCE_SPACE_SELECTION
#define FIFFV_COORD_DEVICE
#define FIFF_MNE_SOURCE_SPACE_USE_TRIANGLES
#define FIFF_MNE_FORWARD_SOLUTION
#define FIFF_MNE_SOURCE_SPACE_NUSE_TRI
#define FIFF_MNE_SOURCE_SPACE_INTERPOLATOR
#define FIFF_MNE_SOURCE_SPACE_NORMALS
#define FIFF_MNE_ROW_NAMES
#define FIFF_MNE_SOURCE_SPACE_NEAREST_DIST
#define FIFF_MNE_SOURCE_SPACE_DIST
#define FIFF_MNE_SOURCE_SPACE_POINTS
#define FIFF_MNE_SOURCE_SPACE_NTRI
#define FIFF_MNE_SOURCE_SPACE_MRI_FILE
#define FIFF_MNE_COL_NAMES
#define FIFF_MNE_ENV_WORKING_DIR
#define FIFF_MNE_INCLUDED_METHODS
#define FIFF_MNE_ENV_COMMAND_LINE
#define FIFFB_MNE_SOURCE_SPACE
#define FIFF_MNE_SOURCE_SPACE_NPOINTS
#define FIFFV_MNE_SPACE_VOLUME
#define FIFFV_MNE_FIXED_ORI
#define FIFF_MNE_CH_NAME_LIST
#define FIFF_MNE_SOURCE_SPACE_TRIANGLES
#define FIFFB_MNE_FORWARD_SOLUTION
#define FIFFB_MNE_PARENT_MEAS_FILE
#define FIFFV_MNE_SPACE_UNKNOWN
#define FIFF_MNE_SOURCE_SPACE_NUSE
#define FIFFB_MNE_BAD_CHANNELS
#define FIFFB_MNE_NAMED_MATRIX
#define FIFF_MNE_FILE_NAME
#define FIFF_MNE_SOURCE_SPACE_NEAREST
#define FIFFB_MNE_PARENT_MRI_FILE
#define FIFFV_MNE_FREE_ORI
#define FIFF_PARENT_BLOCK_ID
#define FIFF_PARENT_FILE_ID
#define FIFFT_COORD_TRANS_STRUCT
Old fiff_type declarations - replace them.
FiffSparseMatrix class declaration.
FiffCoordTrans class declaration.
MNECTFCompDataSet class declaration.
MNEForwardSolution class declaration, which provides the forward solution including the source space ...
MNENamedMatrix class declaration.
MNENearest class declaration.
MNESourceSpace class declaration.
#define FIFF_MNE_SOURCE_SPACE_NEIGHBORS
#define FIFF_MNE_SOURCE_SPACE_NNEIGHBORS
FwdEegSphereModelSet class declaration.
FwdCompData class declaration.
Compute Forward Setting class declaration.
int mne_write_named_matrix(FiffStream::SPtr &t_pStream, int kind, MNENamedMatrix *mat)
void fiff_write_float_matrix_old(FiffStream::SPtr &t_pStream, int kind, fiff_float_t **data, int rows, int cols)
void write_id_old(FiffStream::SPtr &t_pStream, fiff_int_t kind, fiffId id)
void mne_write_bad_channel_list_new(FiffStream::SPtr &t_pStream, const QStringList &t_badList)
bool mne_attach_env(const QString &name, const QString &command)
int ** mne_imatrix_41(int nr, int nc)
QString mne_name_list_to_string_41(const QStringList &list)
#define FREE_ICMATRIX_41(m)
void fiff_write_int_matrix_old(FiffStream::SPtr &t_pStream, int kind, fiff_int_t **data, int rows, int cols)
int mne_write_one_source_space(FiffStream::SPtr &t_pStream, MNESourceSpace *ss, bool selected_only)
FiffSparseMatrix * mne_pick_lower_triangle_rcs(FiffSparseMatrix *mat)
void mne_free_cmatrix_41(float **m)
void write_coord_trans_old(FiffStream::SPtr &t_pStream, const FiffCoordTrans &trans)
int fiff_write_float_sparse_matrix_old(FiffStream::SPtr &t_pStream, int kind, FiffSparseMatrix *mat)
#define ALLOC_CMATRIX_41(x, y)
bool write_solution(const QString &name, std::vector< std::unique_ptr< MNESourceSpace > > &spaces, const QString &mri_file, fiffId mri_id, const FiffCoordTrans &mri_head_t, const QString &meas_file, FiffId meas_id, const FiffCoordTrans &meg_head_t, QList< FiffChInfo > meg_chs, int nmeg, QList< FiffChInfo > eeg_chs, int neeg, int fixed_ori, int coord_frame, FiffNamedMatrix &meg_solution, FiffNamedMatrix &eeg_solution, FiffNamedMatrix &meg_solution_grad, FiffNamedMatrix &eeg_solution_grad, bool bDoGrad)
int mne_check_chinfo(const QList< FiffChInfo > &chs, int nch)
bool fiff_put_dir(FiffStream::SPtr &t_pStream, const QList< FiffDirEntry::SPtr > &dir)
FiffSparseMatrix * mne_create_sparse_rcs(int nrow, int ncol, int *nnz, int **colindex, float **vals)
fiffId get_file_id(const QString &name)
#define VEC_COPY_41(to, from)
#define ALLOC_ICMATRIX_41(x, y)
void write_coord_trans(FiffStream::SPtr &t_pStream, const FiffCoordTrans &trans)
void mne_free_icmatrix_41(int **m)
#define FREE_CMATRIX_41(m)
float ** mne_cmatrix_41(int nr, int nc)
#define FWD_COIL_ACCURACY_ACCURATE
#define FWD_COIL_ACCURACY_NORMAL
FwdCoilSet class declaration.
FwdBemModel class declaration.
Core MNE data structures (source spaces, source estimates, hemispheres).
FIFF file I/O and data structures (raw, epochs, evoked, covariance, forward).
FiffId * fiffId
Backward-compatible pointer typedef for the old fiffId pointer.
FiffId fiffIdRec
Backward-compatible typedef for the old fiffIdRec struct.
Forward modelling (BEM, MEG/EEG lead fields).
Coordinate transformation description.
FiffCoordTrans inverted() const
Directory entry description.
QSharedPointer< FiffDirEntry > SPtr
QSharedPointer< FiffDirNode > SPtr
Universally unique identifier.
static FiffId new_file_id()
QSharedPointer< FiffInfoBase > SPtr
void transpose_named_matrix()
FIFF sparse matrix storage.
FIFFLIB::fiff_int_t coding
static FiffStream::SPtr start_file(QIODevice &p_IODevice)
static FiffStream::SPtr open_update(QIODevice &p_IODevice)
QSharedPointer< FiffStream > SPtr
QSharedPointer< FiffTag > SPtr
QSharedDataPointer< FIFFLIB::FiffNamedMatrix > m_eeg_forward
QSharedDataPointer< FIFFLIB::FiffNamedMatrix > sol
void storeFwd(const QString &sSolName="default")
QSharedDataPointer< FIFFLIB::FiffNamedMatrix > m_meg_forward_grad
QSharedDataPointer< FIFFLIB::FiffNamedMatrix > m_meg_forward
QSharedDataPointer< FIFFLIB::FiffNamedMatrix > sol_grad
QSharedDataPointer< FIFFLIB::FiffNamedMatrix > m_eeg_forward_grad
void updateHeadPos(const FIFFLIB::FiffCoordTrans &transDevHead)
ComputeFwd(ComputeFwdSettings::SPtr pSettings)
QSharedPointer< ComputeFwdSettings > SPtr
static int compute_forward_eeg(std::vector< std::unique_ptr< MNELIB::MNESourceSpace > > &spaces, FwdCoilSet *els, bool fixed_ori, FwdBemModel *bem_model, FwdEegSphereModel *m, bool use_threads, FIFFLIB::FiffNamedMatrix &resp, FIFFLIB::FiffNamedMatrix &resp_grad, bool bDoGrad)
static FwdBemModel * fwd_bem_load_homog_surface(const QString &name)
static int fwd_bem_set_head_mri_t(FwdBemModel *m, const FIFFLIB::FiffCoordTrans &t)
static QString fwd_bem_make_bem_sol_name(const QString &name)
static int fwd_bem_load_recompute_solution(const QString &name, int bem_method, int force_recompute, FwdBemModel *m)
static int compute_forward_meg(std::vector< std::unique_ptr< MNELIB::MNESourceSpace > > &spaces, FwdCoilSet *coils, FwdCoilSet *comp_coils, MNELIB::MNECTFCompDataSet *comp_data, bool fixed_ori, FwdBemModel *bem_model, Eigen::Vector3f *r0, bool use_threads, FIFFLIB::FiffNamedMatrix &resp, FIFFLIB::FiffNamedMatrix &resp_grad, bool bDoGRad)
static FwdBemModel * fwd_bem_load_three_layer_surfaces(const QString &name)
static FwdCoilSet * create_eeg_els(const QList< FIFFLIB::FiffChInfo > &chs, int nch, const FIFFLIB::FiffCoordTrans &t=FIFFLIB::FiffCoordTrans())
static FwdCoilSet * read_coil_defs(const QString &name)
static FwdEegSphereModelSet * fwd_load_eeg_sphere_models(const QString &p_sFileName, FwdEegSphereModelSet *now)
static std::unique_ptr< MNECTFCompDataSet > read(const QString &name)
A dense matrix with named rows and columns.
This is used in the patch definitions.
This defines a source space.
static int restrict_sources_to_labels(std::vector< std::unique_ptr< MNESourceSpace > > &spaces, const QStringList &labels, int nlabel)
static int filter_source_spaces(const MNESurface &surf, float limit, const FIFFLIB::FiffCoordTrans &mri_head_t, std::vector< std::unique_ptr< MNESourceSpace > > &spaces, QTextStream *filtered)
static int read_source_spaces(const QString &name, std::vector< std::unique_ptr< MNESourceSpace > > &spaces)
static int transform_source_spaces_to(int coord_frame, const FIFFLIB::FiffCoordTrans &t, std::vector< std::unique_ptr< MNESourceSpace > > &spaces)
std::vector< Eigen::VectorXi > neighbor_vert
std::optional< FIFFLIB::FiffCoordTrans > MRI_surf_RAS_RAS_t
FIFFLIB::FiffSparseMatrix dist
std::vector< MNENearest > nearest
Eigen::VectorXi nneighbor_vert
std::optional< FIFFLIB::FiffSparseMatrix > interpolator
std::optional< FIFFLIB::FiffCoordTrans > MRI_voxel_surf_RAS_t
std::optional< FIFFLIB::FiffCoordTrans > voxel_surf_RAS_t
static FiffCoordTrans combine(int from, int to, const FiffCoordTrans &t1, const FiffCoordTrans &t2)
static FiffCoordTrans identity(int from, int to)
static FiffCoordTrans readMriTransform(const QString &name)
static FiffCoordTrans readFShead2mriTransform(const QString &name)
static QString frame_name(int frame)