60: m_qListBemSurface(p_MNEBem.m_qListBemSurface)
73 throw std::runtime_error(
"Could not read the bem surfaces\n");
91 m_qListBemSurface.clear();
101 bool open_here =
false;
104 if (!p_pStream->device()->isOpen()) {
105 QString t_sFileName = p_pStream->streamName();
107 t_file.setFileName(t_sFileName);
109 if (!p_pStream->open()) {
121 QList<FiffDirNode::SPtr> bem = p_pStream->dirtree()->dir_tree_find(
FIFFB_BEM);
123 qCritical() <<
"No BEM block found!";
130 QList<FiffDirNode::SPtr> bemsurf = p_pStream->dirtree()->dir_tree_find(
FIFFB_BEM_SURF);
131 if (bemsurf.isEmpty()) {
132 qCritical() <<
"No BEM surfaces found!";
139 for (
int k = 0; k < bemsurf.size(); ++k) {
141 qInfo(
"\tReading a BEM surface...");
144 if (add_geom || p_BemSurface.
nn.rows() == 0) {
149 p_Bem.m_qListBemSurface.append(p_BemSurface);
153 qInfo(
"\t%lld bem surfaces read\n",
static_cast<long long>(bemsurf.size()));
165 p_BemSurface.
clear();
173 p_BemSurface.
id = *t_pTag->toInt();
180 p_BemSurface.
sigma = 1.0;
182 p_BemSurface.
sigma = *t_pTag->toFloat();
190 qWarning() <<
"np not found!";
193 p_BemSurface.
np = *t_pTag->toInt();
201 qWarning() <<
"ntri not found!";
204 p_BemSurface.
ntri = *t_pTag->toInt();
211 qWarning() <<
"FIFF_MNE_COORD_FRAME not found, trying FIFF_BEM_COORD_FRAME.";
214 throw std::runtime_error(
"Coordinate frame information not found.");
231 throw std::runtime_error(
"Vertex data not found.");
234 p_BemSurface.
rr = t_pTag->toFloatMatrix().transpose();
235 qint32 rows_rr = p_BemSurface.
rr.rows();
237 if (rows_rr != p_BemSurface.
np) {
239 throw std::runtime_error(
"Vertex information is incorrect.");
247 p_BemSurface.
nn = t_pTag->toFloatMatrix().transpose();
248 if (p_BemSurface.
nn.rows() != p_BemSurface.
np) {
250 throw std::runtime_error(
"Vertex normal information is incorrect.");
253 p_BemSurface.
nn.resize(0, 3);
259 if (p_BemSurface.
ntri > 0) {
263 throw std::runtime_error(
"Triangulation not found.");
265 p_BemSurface.
itris = t_pTag->toIntMatrix().transpose();
266 p_BemSurface.
itris -= MatrixXi::Constant(p_BemSurface.
itris.rows(), 3, 1);
269 p_BemSurface.
itris = t_pTag->toIntMatrix().transpose();
270 p_BemSurface.
itris -= MatrixXi::Constant(p_BemSurface.
itris.rows(), 3, 1);
273 if (p_BemSurface.
itris.rows() != p_BemSurface.
ntri) {
275 throw std::runtime_error(
"Triangulation information is incorrect.");
278 p_BemSurface.
itris.resize(0, 3);
292 qInfo(
"Write BEM surface in %s...\n", t_pStream->streamName().toUtf8().constData());
294 t_pStream->end_file();
303 for (qint32 h = 0; h < m_qListBemSurface.size(); ++h) {
304 qInfo(
"\tWrite a bem surface... ");
306 m_qListBemSurface[h].writeToStream(p_pStream);
310 qInfo(
"\t%lld bem surfaces written\n",
static_cast<long long>(m_qListBemSurface.size()));
324 if (m_qListBemSurface.isEmpty()) {
325 qWarning(
"Warning: No BEM surfaces available! Returning an empty surface.");
329 return defaultSurface;
332 if (idx < 0 || idx >= m_qListBemSurface.length()) {
333 qWarning(
"Warning: Required surface doesn't exist! Returning surface '0'.");
336 return m_qListBemSurface[idx];
347 if (m_qListBemSurface.isEmpty()) {
348 qWarning(
"Warning: No BEM surfaces available! Returning an empty surface.");
353 return defaultSurface;
356 if (idx < 0 || idx >= m_qListBemSurface.length()) {
357 qWarning(
"Warning: Required surface doesn't exist! Returning surface '0'.");
360 return m_qListBemSurface[idx];
367 this->m_qListBemSurface.append(surf);
375 this->m_qListBemSurface.append(*surf);
384 QList<MatrixXf> vertList;
385 for (
int i = 0; i < this->m_qListBemSurface.size(); i++) {
386 vertList.append(this->m_qListBemSurface[i].rr);
391 for (
int i = 0; i < this->m_qListBemSurface.size(); i++) {
392 this->m_qListBemSurface[i].rr = vertList.at(i);
402 for (
int i = 0; i < this->m_qListBemSurface.size(); i++) {
403 vert = this->m_qListBemSurface[i].rr;
405 this->m_qListBemSurface[i].rr = vert;
415 for (
int i = 0; i < this->m_qListBemSurface.size(); i++) {
416 vert = this->m_qListBemSurface[i].rr;
418 this->m_qListBemSurface[i].rr = vert;
#define FIFF_MNE_COORD_FRAME
#define FIFF_MNE_SOURCE_SPACE_NORMALS
#define FIFF_MNE_SOURCE_SPACE_TRIANGLES
#define FIFFV_BEM_SURF_ID_UNKNOWN
#define FIFF_BEM_SURF_NNODE
#define FIFF_BEM_SURF_NODES
#define FIFF_BEM_SURF_TRIANGLES
#define FIFF_BEM_COORD_FRAME
#define FIFF_BEM_SURF_NTRI
#define FIFF_BEM_SURF_NORMALS
Thin-plate-spline 3-D warp from landmark correspondences.
Reader and in-memory representation of a FreeSurfer/MNE surface label (.label).
Boundary element model bundle (inner skull, outer skull, outer skin) loaded from -bem....
Core MNE data structures (source spaces, source estimates, hemispheres).
FreeSurfer surface, annotation and parcellation I/O for mne-cpp.
FIFF file I/O, in-memory data structures and high-level readers/writers.
Shared utilities (I/O helpers, spectral analysis, layout management, warp algorithms).
Labelled 4x4 FIFF affine: source frame, destination frame, rotation, translation and cached inverse.
Eigen::MatrixX3f apply_inverse_trans(const Eigen::MatrixX3f &rr, bool do_move=true) const
Eigen::MatrixX3f apply_trans(const Eigen::MatrixX3f &rr, bool do_move=true) const
QSharedPointer< FiffDirNode > SPtr
FIFF tag-stream reader/writer: wraps a QIODevice and exposes typed read_* / write_* methods for every...
fiff_long_t start_block(fiff_int_t kind)
QSharedPointer< FiffStream > SPtr
static FiffStream::SPtr start_file(QIODevice &p_IODevice)
fiff_long_t end_block(fiff_int_t kind, fiff_int_t next=FIFFV_NEXT_SEQ)
std::unique_ptr< FiffTag > UPtr
Thin-plate-spline 3-D warp fitted from landmark correspondences.
Eigen::MatrixXf calculate(const Eigen::MatrixXf &sLm, const Eigen::MatrixXf &dLm, const Eigen::MatrixXf &sVert)
bool write(QIODevice &p_IODevice)
void invtransform(const FIFFLIB::FiffCoordTrans &trans)
void transform(const FIFFLIB::FiffCoordTrans &trans)
static bool readBemSurface(FIFFLIB::FiffStream::SPtr &p_pStream, const FIFFLIB::FiffDirNode::SPtr &p_Tree, MNEBemSurface &p_BemSurface)
void writeToStream(FIFFLIB::FiffStream *p_pStream)
void warp(const Eigen::MatrixXf &sLm, const Eigen::MatrixXf &dLm)
static bool readFromStream(FIFFLIB::FiffStream::SPtr &p_pStream, bool add_geom, MNEBem &p_Bem)
const MNEBemSurface & operator[](qint32 idx) const
MNEBem & operator<<(const MNEBemSurface &surf)
BEM surface provides geometry information.