% lokalni reprezentace reseni
N_p = ((N + 3) * (N + 2) * (N + 1)) / 6;
N_fp = ((N + 2) * (N + 1)) / 2;
N_faces = 4;
NODETOL = 1e-9;

N_v = size(P,2); % pocet uzlu v siti
K = size(E,2); % pocet elementu v siti

x_opt_eq = load(sprintf('x_opt_eq_Hesthaven_N=%d.txt',N));
y_opt_eq = load(sprintf('y_opt_eq_Hesthaven_N=%d.txt',N));
z_opt_eq = load(sprintf('z_opt_eq_Hesthaven_N=%d.txt',N));
[r,s,t] = xyztorst(x_opt_eq,y_opt_eq,z_opt_eq);

v_1 = E(1,:); v_2 = E(2,:); v_3 = E(3,:); v_4 = E(4,:);
x = 0.5 * (-(r + s + t + 1)' * P(1,v_1) + (r + 1)' * P(1,v_2) + (s + 1)' * P(1,v_3) + (t + 1)' * P(1,v_4));
y = 0.5 * (-(r + s + t + 1)' * P(2,v_1) + (r + 1)' * P(2,v_2) + (s + 1)' * P(2,v_3) + (t + 1)' * P(2,v_4));
z = 0.5 * (-(r + s + t + 1)' * P(3,v_1) + (r + 1)' * P(3,v_2) + (s + 1)' * P(3,v_3) + (t + 1)' * P(3,v_4));

fmask1 = find(abs(t + 1) < NODETOL);
fmask2 = find(abs(s + 1) < NODETOL);
fmask3 = find(abs(r + s + t + 1) < NODETOL);
fmask4 = find(abs(r + 1) < NODETOL);
Fmask = [fmask1; fmask2; fmask3; fmask4]';
Fx = x(Fmask(:),:); Fy = y(Fmask(:),:); Fz = z(Fmask(:),:);

[EtoE,EtoF] = Connectivity3D();

[mapM, vmapM, mapP, vmapP, mapB, vmapB] = BuildMaps3D();