51#define _USE_MATH_DEFINES
86#define VEC_DOT_17(x,y) ((x)[X_17]*(y)[X_17] + (x)[Y_17]*(y)[Y_17] + (x)[Z_17]*(y)[Z_17])
87#define VEC_LEN_17(x) sqrt(VEC_DOT_17(x,x))
88#define VEC_DIFF_17(from,to,diff) {\
89 (diff)[X_17] = (to)[X_17] - (from)[X_17];\
90 (diff)[Y_17] = (to)[Y_17] - (from)[Y_17];\
91 (diff)[Z_17] = (to)[Z_17] - (from)[Z_17];\
93#define VEC_COPY_17(to,from) {\
94 (to)[X_17] = (from)[X_17];\
95 (to)[Y_17] = (from)[Y_17];\
96 (to)[Z_17] = (from)[Z_17];\
120 double tot_angle, angle;
121 for (k = 0, tot_angle = 0.0; k <
ntri; k++) {
133 double a, b, c, v1, v2, det;
136 this_tri = &
tris[tri];
150 x = (b * v1 - c * v2) / det;
151 y = (a * v2 - c * v1) / det;
158 double p, q, p0, q0, t0;
160 double a, b, c, v1, v2, det;
161 double best,
dist, dist0;
165 this_tri = &
tris[tri];
187 p = (b * v1 - c * v2) / det;
188 q = (a * v2 - c * v1) / det;
190 if (p >= 0.0 && p <= 1.0 &&
191 q >= 0.0 && q <= 1.0 &&
201 p0 = p + 0.5 * (q * c) / a;
202 if (p0 < 0.0) p0 = 0.0;
203 else if (p0 > 1.0) p0 = 1.0;
205 dist0 = sqrt((p - p0) * (p - p0) * a +
206 (q - q0) * (q - q0) * b +
207 (p - p0) * (q - q0) * c +
216 t0 = 0.5 * ((2.0 * a - c) * (1.0 - p) + (2.0 * b - c) * q) / (a + b - c);
217 if (t0 < 0.0) t0 = 0.0;
218 else if (t0 > 1.0) t0 = 1.0;
221 dist0 = sqrt((p - p0) * (p - p0) * a +
222 (q - q0) * (q - q0) * b +
223 (p - p0) * (q - q0) * c +
235 q0 = q + 0.5 * (p * c) / b;
236 if (q0 < 0.0) q0 = 0.0;
237 else if (q0 > 1.0) q0 = 1.0;
238 dist0 = sqrt((p - p0) * (p - p0) * a +
239 (q - q0) * (q - q0) * b +
240 (p - p0) * (q - q0) * c +
264 return Eigen::Vector3f(
265 this_tri->
r1 + p * this_tri->
r12 + q * this_tri->
r13
290 for (best = -1, k = 0; k <
ntri; k++) {
292 if (best < 0 || std::fabs(
dist) < std::fabs(dist0)) {
307 Eigen::VectorXi& nearest_tri,
308 Eigen::VectorXf&
dist,
int nstep)
const
313 printf(
"%s for %d points %d steps...", nearest_tri[0] < 0 ?
"Closest" :
"Approx closest", np_points, nstep);
315 for (k = 0; k < np_points; k++) {
316 was = nearest_tri[k];
317 Eigen::Vector3f pt = Eigen::Map<const Eigen::Vector3f>(r.row(k).data());
320 if (nearest_tri[k] < 0) {
336 const Eigen::Vector3f& r)
const
339 float diff[3], dist_val, mindist;
342 for (k = 0; k <
ntri; k++)
345 if (approx_best < 0) {
348 for (k = 0; k <
np; k++) {
361 minvert = this_tri->
vert[0];
365 if (dist_val < mindist) {
367 minvert = this_tri->
vert[1];
371 if (dist_val < mindist) {
373 minvert = this_tri->
vert[2];
422 QList<FiffDirNode::SPtr> surfs;
423 QList<FiffDirNode::SPtr> bems;
428 int nnode, ntri_count;
431 MatrixXf tmp_node_normals;
435 MatrixXi tmp_triangles;
440 bems = stream->dirtree()->dir_tree_find(
FIFFB_BEM);
441 if (bems.size() > 0) {
448 if (surfs.size() == 0) {
449 printf(
"No BEM surfaces found in %s", name.toUtf8().constData());
453 for (k = 0; k < surfs.size(); ++k) {
456 id = *t_pTag->toInt();
462 printf(
"Desired surface not found in %s", name.toUtf8().constData());
471 nnode = *t_pTag->toInt();
475 ntri_count = *t_pTag->toInt();
479 tmp_nodes = t_pTag->toFloatMatrix().transpose();
482 tmp_node_normals = t_pTag->toFloatMatrix().transpose();
487 tmp_triangles = t_pTag->toIntMatrix().transpose();
496 sigma = *t_pTag->toFloat();
502 tmp_triangles.array() -= 1;
503 s->
itris = tmp_triangles;
508 s->
nn = tmp_node_normals;
509 s->
ntri = ntri_count;
517 s->
cm[0] = s->
cm[1] = s->
cm[2] = 0.0;
520 if (check_too_many_neighbors) {
529 else if (s->
nn.rows() == 0) {
537 s->
inuse = Eigen::VectorXi::Ones(s->
np);
538 s->
vertno = Eigen::VectorXi::LinSpaced(s->
np, 0, s->
np - 1);
#define FIFF_MNE_COORD_FRAME
#define FIFFV_MNE_SPACE_SURFACE
FiffStream class declaration.
#define FIFF_BEM_SURF_NNODE
#define FIFF_BEM_SURF_NODES
#define FIFF_BEM_SURF_TRIANGLES
#define FIFF_BEM_COORD_FRAME
#define FIFF_BEM_SURF_NTRI
#define FIFF_BEM_SURF_NORMALS
FiffCoordTrans class declaration.
MNETriangle class declaration.
MNESurface class declaration.
#define VEC_DIFF_17(from, to, diff)
MNEProjData class declaration.
MNESourceSpace class declaration.
Core MNE data structures (source spaces, source estimates, hemispheres).
FIFF file I/O and data structures (raw, epochs, evoked, covariance, forward).
QSharedPointer< FiffDirNode > SPtr
QSharedPointer< FiffStream > SPtr
std::unique_ptr< FiffTag > UPtr
Auxiliary projection data computed from MNEProjOp for efficient repeated application.
double sum_solids(const Eigen::Vector3f &from) const
void find_closest_on_surface_approx(const PointsT &r, int np, Eigen::VectorXi &nearest_tri, Eigen::VectorXf &dist, int nstep) const
static MNESurface * read_bem_surface2(const QString &name, int which, int add_geometry, float *sigmap)
Eigen::Vector3f project_to_triangle(int tri, float p, float q) const
void triangle_coords(const Eigen::Vector3f &r, int tri, float &x, float &y, float &z) const
int project_to_surface(const MNEProjData *proj_data, const Eigen::Vector3f &r, float &distp) const
void decide_search_restriction(MNEProjData &p, int approx_best, int nstep, const Eigen::Vector3f &r) const
static MNESurface * read_bem_surface(const QString &name, int which, int add_geometry, float *sigmap)
int nearest_triangle_point(const Eigen::Vector3f &r, const MNEProjData *user, int tri, float &x, float &y, float &z) const
void activate_neighbors(int start, Eigen::VectorXi &act, int nstep) const
std::vector< Eigen::VectorXi > neighbor_tri
int add_geometry_info(int do_normals, int check_too_many_neighbors)
std::vector< Eigen::VectorXi > neighbor_vert
FIFFLIB::FiffSparseMatrix dist
Eigen::VectorXi nneighbor_vert
Eigen::VectorXi nneighbor_tri
static double solid_angle(const Eigen::Vector3f &from, const MNELIB::MNETriangle &tri)
std::vector< MNETriangle > tris
Eigen::Matrix< float, Eigen::Dynamic, 3, Eigen::RowMajor > PointsT
int add_geometry_info2(int do_normals)
Per-triangle geometric data for a cortical or BEM surface.