corrected normal direction
[engrid.git] / src / libengrid / brlcadprojection.cpp
blob427149e31f4df6561e2440dd28f3952257edb65d
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008-2012 enGits GmbH +
7 // + +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
12 // + +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
17 // + +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // + +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24 #include "brlcadprojection.h"
26 BrlCadProjection::BrlCadProjection(QString file_name, QString object_name)
28 setupBrlCad(file_name, object_name);
29 m_ForceRay = false;
30 m_Failed = false;
33 BrlCadProjection::~BrlCadProjection()
38 vec3_t BrlCadProjection::project(vec3_t x, vtkIdType id_node, bool, vec3_t v)
40 vec3_t n = v;
41 if (n.abs() < 1e-3) {
42 if (id_node == -1) {
43 EG_BUG;
45 n = m_FPart.globalNormal(id_node);
47 if (!checkVector(x)) {
48 EG_BUG;
50 if (!checkVector(n)) {
51 cout << "vector defect (id_node=" << id_node << ")" << endl;
52 return x;
53 EG_BUG;
56 vec3_t x_proj = x;
57 m_LastNormal = n;
58 m_LastRadius = 1e10;
60 vec3_t x_hit1, n_hit1, x_hit2, n_hit2;
61 double r_hit1, r_hit2;
62 HitType hit_type1, hit_type2;
64 hit_type1 = shootRay(x, n, x_hit1, n_hit1, r_hit1);
65 if (hit_type1 == Miss) {
66 n *= -1;
67 hit_type1 = shootRay(x, n, x_hit1, n_hit1, r_hit1);
69 if (hit_type1 == Miss) {
70 m_Failed = true;
71 return x;
73 m_Failed = false;
74 n *= -1;
75 hit_type2 = shootRay(x_hit1, n, x_hit2, n_hit2, r_hit2);
76 x_proj = x_hit1;
77 m_LastNormal = (-1)*n_hit1;
78 m_LastRadius = r_hit1;
79 if (hit_type2 != Miss) {
80 if ((x - x_hit2).abs() < (x - x_hit1).abs()) {
81 x_proj = x_hit2;
82 m_LastNormal = (-1)*n_hit2;
83 m_LastRadius = r_hit2;
86 return x_proj;
89 double BrlCadProjection::getRadius(vtkIdType id_node)
91 vec3_t x;
92 m_FGrid->GetPoint(id_node, x.data());
93 m_ForceRay = true;
94 project(x, id_node);
95 m_ForceRay = false;
96 return m_LastRadius;