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 printf(
"\tCompleting triangulation info...");
193 for (qint32 i = 0; i <
ntri; ++i)
195 for ( qint32 j = 0; j < 3; ++j)
210 a = r.row(1) - r.row(0 );
211 b = r.row(2) - r.row(0);
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 printf(
"\tCompleting selection triangulation info...");
236 for (qint32 i = 0; i <
nuse_tri; ++i)
238 for ( qint32 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 printf(
"\tCompleting triangle and vertex neighboring info...");
287 printf(
"\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<qint32> t_vfirsti;
302 t_vfirsti.push_back(current);
303 std::vector<qint32> t_vlasti;
305 for(quint32 i = 0; i < 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(quint32 k = 0; k < t_vfirsti.size(); ++k)
319 std::vector<int> t_vIndex;
321 for(
int l = t_vfirsti[k]; l <= t_vlasti[k]; ++l)
322 t_vIndex.push_back(t_vIndn[l].first);
324 std::sort(t_vIndex.begin(),t_vIndex.end());
326 int* t_pV = &t_vIndex[0];
327 Eigen::Map<Eigen::VectorXi> t_vPInfo(t_pV, t_vIndex.size());
329 pinfo.append(t_vPInfo);
333 std::vector<qint32> patch_verts;
334 patch_verts.reserve(t_vlasti.size());
335 for(quint32 i = 0; i < t_vlasti.size(); ++i)
336 patch_verts.push_back(nearest_sorted[t_vlasti[i]]);
339 std::vector<qint32>::iterator it;
340 for(qint32 i = 0; i <
vertno.size(); ++i)
342 it = std::find(patch_verts.begin(), patch_verts.end(),
vertno[i]);
358 std::vector<std::vector<int>> temp_ntri(this->
itris.rows());
359 for (p = 0; p < this->
itris.rows(); p++) {
360 for (k = 0; k < 3; k++) {
361 temp_ntri[this->
itris(p,k)].push_back(p);
365 for (k = 0; k < static_cast<int>(temp_ntri.size()); k++) {
366 neighbor_tri[k] = Eigen::Map<Eigen::VectorXi>(temp_ntri[k].data(), temp_ntri[k].size());
372 std::vector<std::vector<int>> temp_nvert(this->
np);
373 for (k = 0; k < this->
np; k++) {
376 for (c = 0; c < 3; c++) {
382 for (q = 0; q < static_cast<int>(temp_nvert[k].size()); q++) {
383 if (temp_nvert[k][q] == vert) {
390 temp_nvert[k].push_back(vert);
397 for (k = 0; k < this->np; k++) {
398 neighbor_vert[k] = Eigen::Map<Eigen::VectorXi>(temp_nvert[k].data(), temp_nvert[k].size());
415 rr = PointsT::Zero(0,3);
416 nn = NormalsT::Zero(0,3);
418 inuse = VectorXi::Zero(0);
419 vertno = VectorXi::Zero(0);
426 itris = TrianglesT::Zero(0,3);
435 tri_nn = MatrixX3d::Zero(0,3);
443 m_TriCoords = MatrixXf();
450 if(m_TriCoords.size() == 0)
452 m_TriCoords = MatrixXf(3,3*
itris.rows());
453 for(qint32 i = 0; i <
itris.rows(); ++i)
455 m_TriCoords.col(i*3) =
rr.row(
itris(i,0) ).transpose().cast<
float>();
456 m_TriCoords.col(i*3+1) =
rr.row(
itris(i,1) ).transpose().cast<
float>();
457 m_TriCoords.col(i*3+2) =
rr.row(
itris(i,2) ).transpose().cast<
float>();
461 m_TriCoords *= p_fScaling;
478 if (trans.
to == this->coord_frame && trans.
from == dest)
480 else if(trans.
from != this->coord_frame || trans.
to != dest)
482 printf(
"Cannot transform the source space using this coordinate transformation");
486 MatrixXf t = trans.
trans.block(0,0,3,4);
489 MatrixXf t_rr = MatrixXf::Ones(this->
np, 4);
490 t_rr.block(0, 0, this->
np, 3) = this->
rr;
491 MatrixXf t_nn = MatrixXf::Zero(this->
np, 4);
492 t_nn.block(0, 0, this->
np, 3) = this->
nn;
494 this->
rr = (t*t_rr.transpose()).transpose();
495 this->
nn = (t*t_nn.transpose()).transpose();
504 if(this->
type == 1 || this->
type == 2)
507 printf(
"Unknown source space type (%d)\n", this->
type);
517 qDebug() <<
"ToDo: Write Volume not implemented yet!!!!!!!!";
563 Eigen::VectorXf nearestDistF = this->
nearestDistVec().cast<
float>();
569 if (!this->
dist.is_empty())
572 Eigen::SparseMatrix<double> eigenDist = this->
dist.toEigenSparse();
573 typedef Eigen::Triplet<float> T;
574 std::vector<T> tripletList;
575 tripletList.reserve(eigenDist.nonZeros());
576 for (
int k=0; k < eigenDist.outerSize(); ++k)
577 for (Eigen::SparseMatrix<double>::InnerIterator it(eigenDist,k); it; ++it)
578 if(it.col() >= it.row())
579 tripletList.push_back(T(it.row(), it.col(), (
float)it.value()));
580 Eigen::SparseMatrix<float> dists(eigenDist.rows(), eigenDist.cols());
581 dists.setFromTriplets(tripletList.begin(), tripletList.end());
#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
MNEMath class declaration.
MNEHemisphere class declaration.
MNENearest 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.
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)
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
static bool compareIdxValuePairSmallerThan(const std::pair< int, T > &lhs, const std::pair< int, T > &rhs)