MNE-CPP 0.1.9
A Framework for Electrophysiology
Loading...
Searching...
No Matches
mne_triangle.cpp
Go to the documentation of this file.
1//=============================================================================================================
37//=============================================================================================================
38// INCLUDES
39//=============================================================================================================
40
41#include "mne_triangle.h"
42
43#define X_50 0
44#define Y_50 1
45#define Z_50 2
46
47#define VEC_DOT_50(x,y) ((x)[X_50]*(y)[X_50] + (x)[Y_50]*(y)[Y_50] + (x)[Z_50]*(y)[Z_50])
48#define VEC_LEN_50(x) sqrt(VEC_DOT_50(x,x))
49
50#define VEC_DIFF_50(from,to,diff) {\
51 (diff)[X_50] = (to)[X_50] - (from)[X_50];\
52 (diff)[Y_50] = (to)[Y_50] - (from)[Y_50];\
53 (diff)[Z_50] = (to)[Z_50] - (from)[Z_50];\
54 }
55
56#define CROSS_PRODUCT_50(x,y,xy) {\
57 (xy)[X_50] = (x)[Y_50]*(y)[Z_50]-(y)[Y_50]*(x)[Z_50];\
58 (xy)[Y_50] = -((x)[X_50]*(y)[Z_50]-(y)[X_50]*(x)[Z_50]);\
59 (xy)[Z_50] = (x)[X_50]*(y)[Y_50]-(y)[X_50]*(x)[Y_50];\
60 }
61
62//=============================================================================================================
63// USED NAMESPACES
64//=============================================================================================================
65
66using namespace Eigen;
67using namespace MNELIB;
68
69//=============================================================================================================
70// DEFINE MEMBER METHODS
71//=============================================================================================================
72
76
77//=============================================================================================================
78
82
83//=============================================================================================================
84
85void MneTriangle::add_triangle_data(MneTriangle *tri)
86/*
87 * Normal vector of a triangle and other stuff
88 */
89{
90 float size,sizey;
91 int c;
92 VEC_DIFF_50 (tri->r1,tri->r2,tri->r12);
93 VEC_DIFF_50 (tri->r1,tri->r3,tri->r13);
94 CROSS_PRODUCT_50 (tri->r12,tri->r13,tri->nn);
95 size = VEC_LEN_50(tri->nn);
96 /*
97 * Possibly zero area triangles
98 */
99 if (size > 0) {
100 tri->nn[X_50] = tri->nn[X_50]/size;
101 tri->nn[Y_50] = tri->nn[Y_50]/size;
102 tri->nn[Z_50] = tri->nn[Z_50]/size;
103 }
104 tri->area = size/2.0;
105 sizey = VEC_LEN_50(tri->r13);
106 if (sizey <= 0)
107 sizey = 1.0;
108
109 for (c = 0; c < 3; c++) {
110 tri->ey[c] = tri->r13[c]/sizey;
111 tri->cent[c] = (tri->r1[c]+tri->r2[c]+tri->r3[c])/3.0;
112 }
113 CROSS_PRODUCT_50(tri->ey,tri->nn,tri->ex);
114
115 return;
116}
MneTriangle class declaration.
Triangle data.