48,
tri_nn(MatrixX3d::Zero(0,3))
80, m_TriCoords(p_MNEHemisphere.m_TriCoords)
84 this->
id = p_MNEHemisphere.
id;
85 this->
np = p_MNEHemisphere.
np;
88 this->
rr = p_MNEHemisphere.
rr;
89 this->
nn = p_MNEHemisphere.
nn;
107 if (
this != &other) {
142 this->m_TriCoords = other.m_TriCoords;
157 return std::make_shared<MNEHemisphere>(*
this);
167 qInfo(
"\tCompleting triangulation info...");
176 for (
int i = 0; i <
ntri; ++i)
178 for (
int j = 0; j < 3; ++j)
193 a = (r.row(1) - r.row(0 )).transpose();
194 b = (r.row(2) - r.row(0)).transpose();
195 tri_nn(i,0) = a(1)*b(2)-a(2)*b(1);
196 tri_nn(i,1) = a(2)*b(0)-a(0)*b(2);
197 tri_nn(i,2) = a(0)*b(1)-a(1)*b(0);
201 size = std::pow(size, 0.5f );
212 qInfo(
"\tCompleting selection triangulation info...");
221 for (
int j = 0; j < 3; ++j)
236 a = r.row(1) - r.row(0 );
237 b = r.row(2) - r.row(0);
244 size = std::pow(size, 0.5f );
252 qInfo(
"\tCompleting triangle and vertex neighboring info...");
270 qInfo(
"\tComputing patch statistics...");
272 std::vector< std::pair<int,int> > t_vIndn;
274 for(
size_t i = 0; i <
nearest.size(); ++i)
276 std::pair<int,int> t_pair(
static_cast<int>(i),
nearest[i].
nearest);
277 t_vIndn.push_back(t_pair);
281 VectorXi nearest_sorted(t_vIndn.size());
284 std::vector<int> t_vfirsti;
285 t_vfirsti.push_back(current);
286 std::vector<int> t_vlasti;
288 for(
int i = 0; i < static_cast<int>(t_vIndn.size()); ++i)
290 nearest_sorted[i] = t_vIndn[i].second;
291 if (t_vIndn[current].second != t_vIndn[i].second)
294 t_vlasti.push_back(i-1);
295 t_vfirsti.push_back(current);
298 t_vlasti.push_back(
static_cast<int>(t_vIndn.size()-1));
300 for(
int k = 0; k < static_cast<int>(t_vfirsti.size()); ++k)
302 Eigen::VectorXi t_vIndex(t_vlasti[k] - t_vfirsti[k] + 1);
304 for(
int l = t_vfirsti[k]; l <= t_vlasti[k]; ++l)
305 t_vIndex[l - t_vfirsti[k]] = t_vIndn[l].first;
307 std::sort(t_vIndex.data(), t_vIndex.data() + t_vIndex.size());
309 pinfo.append(t_vIndex);
313 Eigen::VectorXi patch_verts(t_vlasti.size());
314 for(
int i = 0; i < static_cast<int>(t_vlasti.size()); ++i)
315 patch_verts[i] = nearest_sorted[t_vlasti[i]];
318 for(
int i = 0; i <
vertno.size(); ++i)
320 const int* ptr = std::find(patch_verts.data(), patch_verts.data() + patch_verts.size(),
vertno[i]);
321 patch_inds[i] =
static_cast<int>(ptr - patch_verts.data());
336 std::vector<std::vector<int>> temp_ntri(this->
itris.rows());
337 for (p = 0; p < this->
itris.rows(); p++) {
338 for (k = 0; k < 3; k++) {
339 temp_ntri[this->
itris(p,k)].push_back(p);
343 for (k = 0; k < static_cast<int>(temp_ntri.size()); k++) {
344 neighbor_tri[k] = Eigen::Map<Eigen::VectorXi>(temp_ntri[k].data(), temp_ntri[k].size());
350 std::vector<std::vector<int>> temp_nvert(this->
np);
351 for (k = 0; k < this->
np; k++) {
354 for (c = 0; c < 3; c++) {
360 for (q = 0; q < static_cast<int>(temp_nvert[k].size()); q++) {
361 if (temp_nvert[k][q] == vert) {
368 temp_nvert[k].push_back(vert);
375 for (k = 0; k < this->np; k++) {
376 neighbor_vert[k] = Eigen::Map<Eigen::VectorXi>(temp_nvert[k].data(), temp_nvert[k].size());
393 rr = PointsT::Zero(0,3);
394 nn = NormalsT::Zero(0,3);
396 inuse = VectorXi::Zero(0);
397 vertno = VectorXi::Zero(0);
404 itris = TrianglesT::Zero(0,3);
413 tri_nn = MatrixX3d::Zero(0,3);
421 m_TriCoords = MatrixXf();
428 if(m_TriCoords.size() == 0)
430 m_TriCoords = MatrixXf(3,3*
itris.rows());
431 for(
int i = 0; i <
itris.rows(); ++i)
433 m_TriCoords.col(i*3) =
rr.row(
itris(i,0) ).transpose().cast<
float>();
434 m_TriCoords.col(i*3+1) =
rr.row(
itris(i,1) ).transpose().cast<
float>();
435 m_TriCoords.col(i*3+2) =
rr.row(
itris(i,2) ).transpose().cast<
float>();
439 m_TriCoords *= p_fScaling;
456 if (trans.
to == this->coord_frame && trans.
from == dest)
458 else if(trans.
from != this->coord_frame || trans.
to != dest)
460 qWarning(
"Cannot transform the source space using this coordinate transformation");
464 MatrixXf t = trans.
trans.block(0,0,3,4);
467 MatrixXf t_rr = MatrixXf::Ones(this->
np, 4);
468 t_rr.block(0, 0, this->
np, 3) = this->
rr;
469 MatrixXf t_nn = MatrixXf::Zero(this->
np, 4);
470 t_nn.block(0, 0, this->
np, 3) = this->
nn;
472 this->
rr = (t*t_rr.transpose()).transpose();
473 this->
nn = (t*t_nn.transpose()).transpose();
482 if(this->
type == 1 || this->
type == 2)
485 qWarning(
"Unknown source space type (%d)", this->
type);
495 qDebug() <<
"ToDo: Write Volume not implemented yet!!!!!!!!";
541 Eigen::VectorXf nearestDistF = this->
nearestDistVec().cast<
float>();
547 if (!this->
dist.is_empty())
550 const Eigen::SparseMatrix<float>& eigenDist = this->
dist.eigen();
551 typedef Eigen::Triplet<float> T;
552 std::vector<T> tripletList;
553 tripletList.reserve(eigenDist.nonZeros());
554 for (
int k=0; k < eigenDist.outerSize(); ++k)
555 for (Eigen::SparseMatrix<float>::InnerIterator it(eigenDist,k); it; ++it)
556 if(it.col() >= it.row())
557 tripletList.push_back(T(it.row(), it.col(), it.value()));
558 Eigen::SparseMatrix<float> dists(eigenDist.rows(), eigenDist.cols());
559 dists.setFromTriplets(tripletList.begin(), tripletList.end());
Per-hemisphere cortical surface bundle with decimation, patch info and rendering buffers.
Per-source-space-vertex nearest-cortex-vertex mapping.
#define FIFF_MNE_SOURCE_SPACE_ID
#define FIFF_MNE_SOURCE_SPACE_DIST_LIMIT
#define FIFF_MNE_COORD_FRAME
#define FIFF_MNE_SOURCE_SPACE_TYPE
#define FIFF_MNE_SOURCE_SPACE_SELECTION
#define FIFF_MNE_SOURCE_SPACE_USE_TRIANGLES
#define FIFF_MNE_SOURCE_SPACE_NUSE_TRI
#define FIFF_MNE_SOURCE_SPACE_NORMALS
#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_NPOINTS
#define FIFF_MNE_SOURCE_SPACE_TRIANGLES
#define FIFF_MNE_SOURCE_SPACE_NUSE
#define FIFF_MNE_SOURCE_SPACE_NEAREST
#define FIFFB_MNE_PARENT_MRI_FILE
Static linear-algebra helpers: SVD-based conditioning, block-diagonal assembly, sorted index pairs.
Core MNE data structures (source spaces, source estimates, hemispheres).
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::Matrix< float, 4, 4, Eigen::DontAlign > trans
Sparse FIFF matrix: CCS or RCS storage with the value / index / pointer triple as written by FiffStre...
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)
fiff_long_t write_float_matrix(fiff_int_t kind, const Eigen::MatrixXf &mat)
fiff_long_t write_int_matrix(fiff_int_t kind, const Eigen::MatrixXi &mat)
fiff_long_t write_int(fiff_int_t kind, const fiff_int_t *data, fiff_int_t nel=1, fiff_int_t next=FIFFV_NEXT_SEQ)
fiff_long_t write_float(fiff_int_t kind, const float *data, fiff_int_t nel=1)
fiff_long_t write_float_sparse_rcs(fiff_int_t kind, const Eigen::SparseMatrix< float > &mat)
fiff_long_t end_block(fiff_int_t kind, fiff_int_t next=FIFFV_NEXT_SEQ)
static bool compareIdxValuePairSmallerThan(const std::pair< int, T > &lhs, const std::pair< int, T > &rhs)
void writeToStream(FIFFLIB::FiffStream *p_pStream)
Eigen::MatrixX3d tri_cent
bool complete_source_space_info()
Eigen::VectorXd use_tri_area
Eigen::MatrixX3d use_tri_cent
Eigen::MatrixXf & getTriCoords(float p_fScaling=1.0f)
MNEHemisphere & operator=(const MNEHemisphere &other)
bool compute_patch_info()
MNESourceSpace::SPtr clone() const override
bool transform_hemisphere_to(FIFFLIB::fiff_int_t dest, const FIFFLIB::FiffCoordTrans &p_Trans)
MNEClusterInfo cluster_info
Eigen::MatrixX3d use_tri_nn
QList< Eigen::VectorXi > pinfo
~MNEHemisphere() override
Eigen::VectorXi patch_inds
std::shared_ptr< MNESourceSpace > SPtr
std::vector< Eigen::VectorXi > neighbor_tri
std::vector< Eigen::VectorXi > neighbor_vert
Eigen::VectorXd nearestDistVec() const
FIFFLIB::FiffSparseMatrix dist
std::vector< MNENearest > nearest
Eigen::VectorXi nearestVertIdx() const