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[0] + p * this_tri->
r12[0] + q * this_tri->
r13[0],
266 this_tri->
r1[1] + p * this_tri->
r12[1] + q * this_tri->
r13[1],
267 this_tri->
r1[2] + p * this_tri->
r12[2] + q * this_tri->
r13[2]
292 for (best = -1, k = 0; k <
ntri; k++) {
294 if (best < 0 || std::fabs(
dist) < std::fabs(dist0)) {
309 Eigen::VectorXi& nearest_tri,
310 Eigen::VectorXf&
dist,
int nstep)
const
315 printf(
"%s for %d points %d steps...", nearest_tri[0] < 0 ?
"Closest" :
"Approx closest", np_points, nstep);
317 for (k = 0; k < np_points; k++) {
318 was = nearest_tri[k];
319 Eigen::Vector3f pt = Eigen::Map<const Eigen::Vector3f>(r.row(k).data());
322 if (nearest_tri[k] < 0) {
338 const Eigen::Vector3f& r)
const
341 float diff[3], dist_val, mindist;
344 for (k = 0; k <
ntri; k++)
347 if (approx_best < 0) {
350 for (k = 0; k <
np; k++) {
363 minvert = this_tri->
vert[0];
367 if (dist_val < mindist) {
369 minvert = this_tri->
vert[1];
373 if (dist_val < mindist) {
375 minvert = this_tri->
vert[2];
424 QList<FiffDirNode::SPtr> surfs;
425 QList<FiffDirNode::SPtr> bems;
430 int nnode, ntri_count;
433 MatrixXf tmp_node_normals;
437 MatrixXi tmp_triangles;
442 bems = stream->dirtree()->dir_tree_find(
FIFFB_BEM);
443 if (bems.size() > 0) {
450 if (surfs.size() == 0) {
451 printf(
"No BEM surfaces found in %s", name.toUtf8().constData());
455 for (k = 0; k < surfs.size(); ++k) {
458 id = *t_pTag->toInt();
464 printf(
"Desired surface not found in %s", name.toUtf8().constData());
473 nnode = *t_pTag->toInt();
477 ntri_count = *t_pTag->toInt();
481 tmp_nodes = t_pTag->toFloatMatrix().transpose();
484 tmp_node_normals = t_pTag->toFloatMatrix().transpose();
489 tmp_triangles = t_pTag->toIntMatrix().transpose();
498 sigma = *t_pTag->toFloat();
504 tmp_triangles.array() -= 1;
505 s->
itris = tmp_triangles;
510 s->
nn = tmp_node_normals;
511 s->
ntri = ntri_count;
519 s->
cm[0] = s->
cm[1] = s->
cm[2] = 0.0;
522 if (check_too_many_neighbors) {
531 else if (s->
nn.rows() == 0) {
539 s->
inuse = Eigen::VectorXi::Ones(s->
np);
540 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
QSharedPointer< FiffTag > SPtr
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.