fixed edge display for volume cells
[engrid-github.git] / src / libengrid / triangle.h
blob4974ecfe0f8bf5325dd87c5605bcf3d765790c5e
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 #ifndef TRIANGLE_H
22 #define TRIANGLE_H
24 #include <QVector>
26 #include "vtkIdList.h"
27 #include "vtkUnstructuredGrid.h"
28 #include "math/mathvector.h"
29 #include "math/smallsquarematrix.h"
30 #include "egvtkobject.h"
32 class Triangle : public EgVtkObject
35 protected:
37 vtkIdType m_IdA;
38 vtkIdType m_IdB;
39 vtkIdType m_IdC;
41 vec3_t m_Xa, m_Xb, m_Xc;
42 vec3_t m_G1, m_G2, m_G3;
43 mat3_t m_G, m_GI;
44 double m_A;
45 double m_SmallestLength;
46 double m_LongestLength;
47 double m_SmallestHeight;
48 bool m_Valid;
49 vec3_t m_NormalA, m_NormalB, m_NormalC;
50 vec3_t m_RNormalA, m_RNormalB, m_RNormalC;
51 QVector <bool> m_HasNeighbour; ///< True if edge i has a neighbour in the grid
53 public:
55 Triangle();
56 Triangle(vec3_t a, vec3_t b, vec3_t c);
57 Triangle(vtkUnstructuredGrid* grid, vtkIdType id_a, vtkIdType id_b, vtkIdType id_c);
58 Triangle(vtkUnstructuredGrid* grid, vtkIdType id_cell);
59 void setupTriangle();
60 void setDefaults();
62 /**
63 * Calculates the closest (NOT the projection!) point (xi,ri) of point xp on the triangle.
64 * @param xp Point to "project"
65 * @param xi Global 3D coordinates of the closest point on the triangle.
66 * @param ri Local 3D triangle coordinates of the closest point on the triangle. (0<=ri[0]<=1 and 0<=ri[1]<=1 and ri[2]=0)
67 * @param d Distance of xp to (xi,ri)
68 * @return True if (xi,ri) is the result of a direct projection on the triangle, else false.
70 bool snapOntoTriangle(vec3_t xp, vec3_t &xi, vec3_t &ri, double &d, int& side, bool restrict_to_triangle);
72 vec3_t local3DToGlobal3D(vec3_t l_M);
73 vec3_t global3DToLocal3D(vec3_t g_M);
74 vec3_t local2DToGlobal3D(vec2_t l_M);
75 vec2_t global3DToLocal2D(vec3_t g_M);
77 void saveTriangle(QString filename);
79 bool hasNeighbour(int i) { return m_HasNeighbour[i]; }
80 void setNeighbourTrue(int i) { m_HasNeighbour[i] = true; }
81 void setNeighbourFalse(int i) { m_HasNeighbour[i] = false; }
82 vtkIdType idA() { return m_IdA; }
83 vtkIdType idB() { return m_IdB; }
84 vtkIdType idC() { return m_IdC; }
85 vec3_t g1() { return m_G1; }
86 vec3_t g2() { return m_G2; }
87 vec3_t g3() { return m_G3; }
88 vec3_t a() { return m_Xa; }
89 vec3_t b() { return m_Xb; }
90 vec3_t c() { return m_Xc; }
91 vec3_t nA() { return m_NormalA; }
92 vec3_t nB() { return m_NormalB; }
93 vec3_t nC() { return m_NormalC; }
94 vec3_t rNa() { return m_RNormalA; }
95 vec3_t rNb() { return m_RNormalB; }
96 vec3_t rNc() { return m_RNormalC; }
97 double smallestLength() { return m_SmallestLength; }
98 double longestLength() { return m_LongestLength; }
99 double smallestHeight() { return m_SmallestHeight; }
100 void setNormals(vec3_t na, vec3_t nb, vec3_t nc);
105 #endif