66 throw std::runtime_error(
"Could not read the bem surfaces\n");
84 m_qListBemSurface.clear();
94 bool open_here =
false;
97 if (!p_pStream->device()->isOpen()) {
98 QString t_sFileName = p_pStream->streamName();
100 t_file.setFileName(t_sFileName);
102 if (!p_pStream->open()) {
114 QList<FiffDirNode::SPtr> bem = p_pStream->dirtree()->dir_tree_find(
FIFFB_BEM);
116 qCritical() <<
"No BEM block found!";
123 QList<FiffDirNode::SPtr> bemsurf = p_pStream->dirtree()->dir_tree_find(
FIFFB_BEM_SURF);
124 if (bemsurf.isEmpty()) {
125 qCritical() <<
"No BEM surfaces found!";
132 QList<MNEBemSurface> surfaces;
133 for (
int k = 0; k < bemsurf.size(); ++k) {
135 qInfo(
"\tReading a BEM surface...");
143 if (add_geom || p_BemSurface.
nn.rows() == 0) {
148 surfaces.append(p_BemSurface);
150 p_Bem.m_qListBemSurface.append(surfaces);
152 qInfo(
"\t%lld bem surfaces read\n",
static_cast<long long>(bemsurf.size()));
164 p_BemSurface.
clear();
172 p_BemSurface.
id = *t_pTag->toInt();
179 p_BemSurface.
sigma = 1.0;
181 p_BemSurface.
sigma = *t_pTag->toFloat();
188 qWarning() <<
"np not found!";
191 p_BemSurface.
np = *t_pTag->toInt();
198 qWarning() <<
"ntri not found!";
201 p_BemSurface.
ntri = *t_pTag->toInt();
208 qWarning() <<
"FIFF_MNE_COORD_FRAME not found, trying FIFF_BEM_COORD_FRAME.";
210 qWarning() <<
"Coordinate frame information not found.";
227 qWarning() <<
"Vertex data not found.";
231 p_BemSurface.
rr = t_pTag->toFloatMatrix().transpose();
232 qint32 rows_rr = p_BemSurface.
rr.rows();
234 if (rows_rr != p_BemSurface.
np) {
235 qWarning() <<
"Vertex information is incorrect.";
244 p_BemSurface.
nn = t_pTag->toFloatMatrix().transpose();
245 if (p_BemSurface.
nn.rows() != p_BemSurface.
np) {
246 qWarning() <<
"Vertex normal information is incorrect.";
250 p_BemSurface.
nn.resize(0, 3);
256 if (p_BemSurface.
ntri > 0) {
259 qWarning() <<
"Triangulation not found.";
262 p_BemSurface.
itris = t_pTag->toIntMatrix().transpose();
263 p_BemSurface.
itris -= MatrixXi::Constant(p_BemSurface.
itris.rows(), 3, 1);
266 p_BemSurface.
itris = t_pTag->toIntMatrix().transpose();
267 p_BemSurface.
itris -= MatrixXi::Constant(p_BemSurface.
itris.rows(), 3, 1);
270 if (p_BemSurface.
itris.rows() != p_BemSurface.
ntri) {
271 qWarning() <<
"Triangulation information is incorrect.";
275 p_BemSurface.
itris.resize(0, 3);
289 qInfo(
"Write BEM surface in %s...\n", t_pStream->streamName().toUtf8().constData());
291 t_pStream->end_file();
300 for (qint32 h = 0; h < m_qListBemSurface.size(); ++h) {
301 qInfo(
"\tWrite a bem surface... ");
303 m_qListBemSurface[h].writeToStream(p_pStream);
307 qInfo(
"\t%lld bem surfaces written\n",
static_cast<long long>(m_qListBemSurface.size()));
321 if (m_qListBemSurface.isEmpty()) {
322 qWarning(
"Warning: No BEM surfaces available! Returning an empty surface.");
326 return defaultSurface;
329 if (idx < 0 || idx >= m_qListBemSurface.length()) {
330 qWarning(
"Warning: Required surface doesn't exist! Returning surface '0'.");
333 return m_qListBemSurface[idx];
344 if (m_qListBemSurface.isEmpty()) {
345 qWarning(
"Warning: No BEM surfaces available! Returning an empty surface.");
350 return defaultSurface;
353 if (idx < 0 || idx >= m_qListBemSurface.length()) {
354 qWarning(
"Warning: Required surface doesn't exist! Returning surface '0'.");
357 return m_qListBemSurface[idx];
364 this->m_qListBemSurface.append(surf);
372 this->m_qListBemSurface.append(*surf);
381 QList<MatrixXf> vertList;
382 for (
int i = 0; i < this->m_qListBemSurface.size(); i++) {
383 vertList.append(this->m_qListBemSurface[i].rr);
388 for (
int i = 0; i < this->m_qListBemSurface.size(); i++) {
389 this->m_qListBemSurface[i].rr = vertList.at(i);
399 for (
int i = 0; i < this->m_qListBemSurface.size(); i++) {
400 vert = this->m_qListBemSurface[i].rr;
402 this->m_qListBemSurface[i].rr = vert;
412 for (
int i = 0; i < this->m_qListBemSurface.size(); i++) {
413 vert = this->m_qListBemSurface[i].rr;
415 this->m_qListBemSurface[i].rr = vert;
constexpr auto FIFF_MNE_SOURCE_SPACE_NORMALS
constexpr auto FIFF_MNE_COORD_FRAME
constexpr auto FIFF_MNE_SOURCE_SPACE_TRIANGLES
constexpr auto FIFF_BEM_SURF_TRIANGLES
constexpr auto FIFFV_BEM_SURF_ID_UNKNOWN
constexpr auto FIFF_BEM_SURF_NNODE
constexpr auto FIFF_BEM_SURF_NORMALS
constexpr auto FIFF_BEM_SIGMA
constexpr auto FIFF_BEM_SURF_NODES
constexpr auto FIFF_BEM_SURF_ID
constexpr auto FIFFB_BEM_SURF
constexpr auto FIFF_BEM_SURF_NTRI
constexpr auto FIFF_BEM_COORD_FRAME
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.