65,
tri_nn(MatrixX3d::Zero(0,3))
97, m_TriCoords(p_MNEHemisphere.m_TriCoords)
101 this->
id = p_MNEHemisphere.
id;
102 this->
np = p_MNEHemisphere.
np;
105 this->
rr = p_MNEHemisphere.
rr;
106 this->
nn = p_MNEHemisphere.
nn;
124 if (
this != &other) {
159 this->m_TriCoords = other.m_TriCoords;
174 return std::make_shared<MNEHemisphere>(*
this);
184 qInfo(
"\tCompleting triangulation info...");
193 for (
int i = 0; i <
ntri; ++i)
195 for (
int j = 0; j < 3; ++j)
210 a = (r.row(1) - r.row(0 )).transpose();
211 b = (r.row(2) - r.row(0)).transpose();
212 tri_nn(i,0) = a(1)*b(2)-a(2)*b(1);
213 tri_nn(i,1) = a(2)*b(0)-a(0)*b(2);
214 tri_nn(i,2) = a(0)*b(1)-a(1)*b(0);
218 size = std::pow(size, 0.5f );
229 qInfo(
"\tCompleting selection triangulation info...");
238 for (
int j = 0; j < 3; ++j)
253 a = r.row(1) - r.row(0 );
254 b = r.row(2) - r.row(0);
261 size = std::pow(size, 0.5f );
269 qInfo(
"\tCompleting triangle and vertex neighboring info...");
287 qInfo(
"\tComputing patch statistics...");
289 std::vector< std::pair<int,int> > t_vIndn;
291 for(
size_t i = 0; i <
nearest.size(); ++i)
293 std::pair<int,int> t_pair(
static_cast<int>(i),
nearest[i].
nearest);
294 t_vIndn.push_back(t_pair);
298 VectorXi nearest_sorted(t_vIndn.size());
301 std::vector<int> t_vfirsti;
302 t_vfirsti.push_back(current);
303 std::vector<int> t_vlasti;
305 for(
int i = 0; i < static_cast<int>(t_vIndn.size()); ++i)
307 nearest_sorted[i] = t_vIndn[i].second;
308 if (t_vIndn[current].second != t_vIndn[i].second)
311 t_vlasti.push_back(i-1);
312 t_vfirsti.push_back(current);
315 t_vlasti.push_back(
static_cast<int>(t_vIndn.size()-1));
317 for(
int k = 0; k < static_cast<int>(t_vfirsti.size()); ++k)
319 Eigen::VectorXi t_vIndex(t_vlasti[k] - t_vfirsti[k] + 1);
321 for(
int l = t_vfirsti[k]; l <= t_vlasti[k]; ++l)
322 t_vIndex[l - t_vfirsti[k]] = t_vIndn[l].first;
324 std::sort(t_vIndex.data(), t_vIndex.data() + t_vIndex.size());
326 pinfo.append(t_vIndex);
330 Eigen::VectorXi patch_verts(t_vlasti.size());
331 for(
int i = 0; i < static_cast<int>(t_vlasti.size()); ++i)
332 patch_verts[i] = nearest_sorted[t_vlasti[i]];
335 for(
int i = 0; i <
vertno.size(); ++i)
337 const int* ptr = std::find(patch_verts.data(), patch_verts.data() + patch_verts.size(),
vertno[i]);
338 patch_inds[i] =
static_cast<int>(ptr - patch_verts.data());
353 std::vector<std::vector<int>> temp_ntri(this->
itris.rows());
354 for (p = 0; p < this->
itris.rows(); p++) {
355 for (k = 0; k < 3; k++) {
356 temp_ntri[this->
itris(p,k)].push_back(p);
360 for (k = 0; k < static_cast<int>(temp_ntri.size()); k++) {
361 neighbor_tri[k] = Eigen::Map<Eigen::VectorXi>(temp_ntri[k].data(), temp_ntri[k].size());
367 std::vector<std::vector<int>> temp_nvert(this->
np);
368 for (k = 0; k < this->
np; k++) {
371 for (c = 0; c < 3; c++) {
377 for (q = 0; q < static_cast<int>(temp_nvert[k].size()); q++) {
378 if (temp_nvert[k][q] == vert) {
385 temp_nvert[k].push_back(vert);
392 for (k = 0; k < this->np; k++) {
393 neighbor_vert[k] = Eigen::Map<Eigen::VectorXi>(temp_nvert[k].data(), temp_nvert[k].size());
410 rr = PointsT::Zero(0,3);
411 nn = NormalsT::Zero(0,3);
413 inuse = VectorXi::Zero(0);
414 vertno = VectorXi::Zero(0);
421 itris = TrianglesT::Zero(0,3);
430 tri_nn = MatrixX3d::Zero(0,3);
438 m_TriCoords = MatrixXf();
445 if(m_TriCoords.size() == 0)
447 m_TriCoords = MatrixXf(3,3*
itris.rows());
448 for(
int i = 0; i <
itris.rows(); ++i)
450 m_TriCoords.col(i*3) =
rr.row(
itris(i,0) ).transpose().cast<
float>();
451 m_TriCoords.col(i*3+1) =
rr.row(
itris(i,1) ).transpose().cast<
float>();
452 m_TriCoords.col(i*3+2) =
rr.row(
itris(i,2) ).transpose().cast<
float>();
456 m_TriCoords *= p_fScaling;
473 if (trans.
to == this->coord_frame && trans.
from == dest)
475 else if(trans.
from != this->coord_frame || trans.
to != dest)
477 qWarning(
"Cannot transform the source space using this coordinate transformation");
481 MatrixXf t = trans.
trans.block(0,0,3,4);
484 MatrixXf t_rr = MatrixXf::Ones(this->
np, 4);
485 t_rr.block(0, 0, this->
np, 3) = this->
rr;
486 MatrixXf t_nn = MatrixXf::Zero(this->
np, 4);
487 t_nn.block(0, 0, this->
np, 3) = this->
nn;
489 this->
rr = (t*t_rr.transpose()).transpose();
490 this->
nn = (t*t_nn.transpose()).transpose();
499 if(this->
type == 1 || this->
type == 2)
502 qWarning(
"Unknown source space type (%d)", this->
type);
512 qDebug() <<
"ToDo: Write Volume not implemented yet!!!!!!!!";
558 Eigen::VectorXf nearestDistF = this->
nearestDistVec().cast<
float>();
564 if (!this->
dist.is_empty())
567 const Eigen::SparseMatrix<float>& eigenDist = this->
dist.eigen();
568 typedef Eigen::Triplet<float> T;
569 std::vector<T> tripletList;
570 tripletList.reserve(eigenDist.nonZeros());
571 for (
int k=0; k < eigenDist.outerSize(); ++k)
572 for (Eigen::SparseMatrix<float>::InnerIterator it(eigenDist,k); it; ++it)
573 if(it.col() >= it.row())
574 tripletList.push_back(T(it.row(), it.col(), it.value()));
575 Eigen::SparseMatrix<float> dists(eigenDist.rows(), eigenDist.cols());
576 dists.setFromTriplets(tripletList.begin(), tripletList.end());
Linalg class declaration.
#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
MNENearest class declaration.
MNEHemisphere class declaration.
Core MNE data structures (source spaces, source estimates, hemispheres).
FIFF file I/O and data structures (raw, epochs, evoked, covariance, forward).
Shared utilities (I/O helpers, spectral analysis, layout management, warp algorithms).
Coordinate transformation description.
Eigen::Matrix< float, 4, 4, Eigen::DontAlign > trans
FIFF sparse matrix storage backed by Eigen.
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