fixed edge display for volume cells
[engrid-github.git] / src / libengrid / tricoord.cpp
blobff08a5a88e0fcb443a158f6d82fba423fc82040c
1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 // + +
3 // + This file is part of enGrid. +
4 // + +
5 // + Copyright 2008-2014 enGits GmbH +
6 // + +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
11 // + +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
16 // + +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
19 // + +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #include "tricoord.h"
23 TriCoord::TriCoord(vtkUnstructuredGrid* surf_grid, vtkIdType id_tri, vec3_t x)
25 m_SurfGrid = surf_grid;
26 setPosition(x);
29 void TriCoord::setPosition(vec3_t x)
32 bool intersects_face = GeometryTools::intersectEdgeAndTriangle(T.a, T.b, T.c, x1, x2, xi, ri);
33 if (!intersects_face) {
34 double kab = GeometryTools::intersection(T.a, T.b - T.a, xp, T.b - T.a);
35 double kac = GeometryTools::intersection(T.a, T.c - T.a, xp, T.c - T.a);
36 double kbc = GeometryTools::intersection(T.b, T.c - T.b, xp, T.c - T.b);
37 double dab = (T.a + kab*(T.b-T.a) - xp).abs();
38 double dac = (T.a + kac*(T.c-T.a) - xp).abs();
39 double dbc = (T.b + kbc*(T.c-T.b) - xp).abs();
40 bool set = false;
41 if ((kab >= 0) && (kab <= 1)) {
42 if (dab < d) {
43 xi = T.a + kab*(T.b-T.a);
44 d = dab;
45 set = true;
48 if ((kac >= 0) && (kac <= 1)) {
49 if (dac < d) {
50 xi = T.a + kac*(T.c-T.a);
51 d = dac;
52 set = true;
55 if ((kbc >= 0) && (kbc <= 1)) {
56 if (dbc < d) {
57 xi = T.b + kbc*(T.c-T.b);
58 d = dbc;
59 set = true;
62 double da = (T.a - xp).abs();
63 double db = (T.b - xp).abs();
64 double dc = (T.c - xp).abs();
65 if (da < d) {
66 xi = T.a;
67 d = da;
68 set = true;
70 if (db < d) {
71 xi = T.b;
72 d = db;
74 if (dc < d) {
75 xi = T.c;
76 d = dc;
77 set = true;
79 if (!set) {
80 EG_BUG;