48,
tri_nn(MatrixX3d::Zero(0, 3))
81 this->
id = p_MNEHemisphere.
id;
82 this->
np = p_MNEHemisphere.
np;
85 this->
rr = p_MNEHemisphere.
rr;
86 this->
nn = p_MNEHemisphere.
nn;
104 if (
this != &other) {
153 return std::make_shared<MNEHemisphere>(*
this);
163 qInfo(
"\tCompleting triangulation info...");
172 for (
int i = 0; i <
ntri; ++i) {
173 for (
int j = 0; j < 3; ++j) {
187 a = (r.row(1) - r.row(0)).transpose();
188 b = (r.row(2) - r.row(0)).transpose();
189 tri_nn(i, 0) = a(1) * b(2) - a(2) * b(1);
190 tri_nn(i, 1) = a(2) * b(0) - a(0) * b(2);
191 tri_nn(i, 2) = a(0) * b(1) - a(1) * b(0);
195 size = std::pow(size, 0.5f);
205 qInfo(
"\tCompleting selection triangulation info...");
211 for (
int i = 0; i <
nuse_tri; ++i) {
212 for (
int j = 0; j < 3; ++j) {
226 a = r.row(1) - r.row(0);
227 b = r.row(2) - r.row(0);
234 size = std::pow(size, 0.5f);
241 qInfo(
"\tCompleting triangle and vertex neighboring info...");
258 qInfo(
"\tComputing patch statistics...");
260 std::vector<std::pair<int, int>> t_vIndn;
262 for (
size_t i = 0; i <
nearest.size(); ++i) {
263 std::pair<int, int> t_pair(
static_cast<int>(i),
nearest[i].
nearest);
264 t_vIndn.push_back(t_pair);
268 VectorXi nearest_sorted(t_vIndn.size());
271 std::vector<int> t_vfirsti;
272 t_vfirsti.push_back(current);
273 std::vector<int> t_vlasti;
275 for (
int i = 0; i < static_cast<int>(t_vIndn.size()); ++i) {
276 nearest_sorted[i] = t_vIndn[i].second;
277 if (t_vIndn[current].second != t_vIndn[i].second) {
279 t_vlasti.push_back(i - 1);
280 t_vfirsti.push_back(current);
283 t_vlasti.push_back(
static_cast<int>(t_vIndn.size() - 1));
285 for (
int k = 0; k < static_cast<int>(t_vfirsti.size()); ++k) {
286 Eigen::VectorXi t_vIndex(t_vlasti[k] - t_vfirsti[k] + 1);
288 for (
int l = t_vfirsti[k]; l <= t_vlasti[k]; ++l)
289 t_vIndex[l - t_vfirsti[k]] = t_vIndn[l].first;
291 std::sort(t_vIndex.data(), t_vIndex.data() + t_vIndex.size());
293 pinfo.append(t_vIndex);
297 Eigen::VectorXi patch_verts(t_vlasti.size());
298 for (
int i = 0; i < static_cast<int>(t_vlasti.size()); ++i)
299 patch_verts[i] = nearest_sorted[t_vlasti[i]];
302 for (
int i = 0; i <
vertno.size(); ++i) {
303 const int* ptr = std::find(patch_verts.data(), patch_verts.data() + patch_verts.size(),
vertno[i]);
304 patch_inds[i] =
static_cast<int>(ptr - patch_verts.data());
319 std::vector<std::vector<int>> temp_ntri(this->
itris.rows());
320 for (p = 0; p < this->
itris.rows(); p++) {
321 for (k = 0; k < 3; k++) {
322 temp_ntri[this->
itris(p, k)].push_back(p);
326 for (k = 0; k < static_cast<int>(temp_ntri.size()); k++) {
327 neighbor_tri[k] = Eigen::Map<Eigen::VectorXi>(temp_ntri[k].data(), temp_ntri[k].size());
333 std::vector<std::vector<int>> temp_nvert(this->
np);
334 for (k = 0; k < this->
np; k++) {
337 for (c = 0; c < 3; c++) {
343 for (q = 0; q < static_cast<int>(temp_nvert[k].size()); q++) {
344 if (temp_nvert[k][q] == vert) {
351 temp_nvert[k].push_back(vert);
358 for (k = 0; k < this->np; k++) {
359 neighbor_vert[k] = Eigen::Map<Eigen::VectorXi>(temp_nvert[k].data(), temp_nvert[k].size());
376 rr = PointsT::Zero(0, 3);
377 nn = NormalsT::Zero(0, 3);
379 inuse = VectorXi::Zero(0);
380 vertno = VectorXi::Zero(0);
387 itris = TrianglesT::Zero(0, 3);
396 tri_nn = MatrixX3d::Zero(0, 3);
416 if (trans.
to == this->coord_frame && trans.
from == dest)
418 else if (trans.
from != this->coord_frame || trans.
to != dest) {
419 qWarning(
"Cannot transform the source space using this coordinate transformation");
423 MatrixXf t = trans.
trans.block(0, 0, 3, 4);
426 MatrixXf t_rr = MatrixXf::Ones(this->
np, 4);
427 t_rr.block(0, 0, this->
np, 3) = this->
rr;
428 MatrixXf t_nn = MatrixXf::Zero(this->
np, 4);
429 t_nn.block(0, 0, this->
np, 3) = this->
nn;
431 this->
rr = (t * t_rr.transpose()).transpose();
432 this->
nn = (t * t_nn.transpose()).transpose();
441 if (this->
type == 1 || this->
type == 2)
444 qWarning(
"Unknown source space type (%d)", this->
type);
454 qDebug() <<
"ToDo: Write Volume not implemented yet!!!!!!!!";
498 Eigen::VectorXf nearestDistF = this->
nearestDistVec().cast<
float>();
504 if (!this->
dist.is_empty()) {
506 const Eigen::SparseMatrix<float>& eigenDist = this->
dist.eigen();
507 typedef Eigen::Triplet<float> T;
508 std::vector<T> tripletList;
509 tripletList.reserve(eigenDist.nonZeros());
510 for (
int k = 0; k < eigenDist.outerSize(); ++k)
511 for (Eigen::SparseMatrix<float>::InnerIterator it(eigenDist, k); it; ++it)
512 if (it.col() >= it.row())
513 tripletList.push_back(T(it.row(), it.col(), it.value()));
514 Eigen::SparseMatrix<float> dists(eigenDist.rows(), eigenDist.cols());
515 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
Static linear-algebra helpers: SVD-based conditioning, block-diagonal assembly, sorted index pairs.
Per-hemisphere cortical surface bundle with decimation, patch info and rendering buffers.
Per-source-space-vertex nearest-cortex-vertex mapping.
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
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