2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008,2009 Oliver Gloth +
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. +
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. +
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/>. +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28 #include "egvtkobject.h"
30 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41 vec3_t
& getPosition() { return m_Position
; }
42 void setPosition(const vec3_t
& x
) { m_Position
= x
; }
46 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
63 int getNode (int i
) { return m_Node
[i
]; }
64 int getNeighbour(int i
) { return m_Neighbour
[i
]; }
65 bool hasChildren () { return m_Child
[0] != -1; }
67 int getEdgeNode(Octree
* octree
, int n1
, int n2
, int f
);
68 void getFaceNodes(int i
, Octree
* octree
, QVector
<int>& face_nodes
, bool reverse
= false);
69 void getFaceNodes(int i
, Octree
* octree
, QVector
<QVector
<int> >& face_nodes
, bool reverse
= false);
74 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
76 class Octree
: public EgVtkObject
79 friend class OctreeCell
;
81 private: // attributes
83 vec3_t m_Origin
; ///< origin of internal coordinate system
84 mat3_t m_Base
; ///< base vectors of internal coordinate system
85 mat3_t m_InvBase
; ///< inverted base of internal coordiante system
86 vec3_t m_Corner1
; ///< first corner of extend box of the whole domain (in internal coordinates)
87 vec3_t m_Corner2
; ///< second corner of extend box of the whole domain (in internal coordinates)
88 double m_Dx
; ///< extend in x direction
89 double m_Dy
; ///< extend in y direction
90 double m_Dz
; ///< extend in z direction
92 bool m_SmoothTransition
;
94 QVector
<OctreeNode
> m_Nodes
;
95 QVector
<OctreeCell
> m_Cells
;
96 QVector
<bool> m_ToRefine
;
97 QVector
<int> m_SameNodes
;
102 void mergeNodes_identifyDuplicates();
103 void mergeNodes_compactNodes();
104 void mergeNodes_updateCells();
106 void checkNeighbours();
108 int opposingFace(int i
);
110 void toVtkGrid_HangingNodes(vtkUnstructuredGrid
*grid
, bool create_fields
);
111 void toVtkGrid_Conforming(vtkUnstructuredGrid
*grid
, bool create_fields
);
118 void setOrigin(vec3_t x0
);
119 void setBase(vec3_t g1
, vec3_t g2
, vec3_t g3
);
120 void setBounds(vec3_t corner1
, vec3_t corner2
);
122 //int getNeighbour(int cell, int neigh) { return m_Cells[cell].m_Neighbour[neigh]; }
124 void markToRefine(int cell
) { m_ToRefine
[cell
] = true; }
125 bool markedForRefine(int cell
) { return m_ToRefine
[cell
]; }
127 void resetRefineMarks();
128 void setSmoothTransitionOn() { m_SmoothTransition
= true; }
129 void setSmoothTransitionOff() { m_SmoothTransition
= false; }
131 vec3_t
getCellCentre(int cell
);
132 vec3_t
getFaceCentre(int i_cells
, int i_faces
);
133 vec3_t
getNodePosition(int cell
, int node
) { return m_Nodes
[m_Cells
[cell
].m_Node
[node
]].m_Position
; }
134 vec3_t
getNodePosition(int node
) { return m_Nodes
[node
].m_Position
; }
135 int getNode(int cell
, int node
) { return m_Cells
[cell
].m_Node
[node
]; }
136 int getNumCells() { return m_Cells
.size(); }
137 int getNumNodes() { return m_Nodes
.size(); }
138 void getEdges(int cell
, QVector
<SortedPair
<int> >& edges
);
139 int getLevel(int cell
) { return m_Cells
[cell
].m_Level
; }
140 double getDx(int cell
);
141 double getDy(int cell
);
142 double getDz(int cell
);
143 double getDx(const OctreeCell
& cell
);
144 double getDy(const OctreeCell
& cell
);
145 double getDz(const OctreeCell
& cell
);
146 bool hasChildren(int i_cells
) { return m_Cells
[i_cells
].m_Child
[0] != -1; }
147 int findCell(vec3_t x
);
148 bool intersectsFace(int cell
, int face
, vec3_t x1
, vec3_t x2
, double &k
, double tol
= 1e-4);
149 void setMaxCells(int n
) { m_MaxCells
= n
; }
151 void toVtkGrid(vtkUnstructuredGrid
*grid
, bool hanging_nodes
= true, bool create_fields
= false);
156 inline double Octree::getDx(int cell
)
159 for (int i
= 0; i
< m_Cells
[cell
].m_Level
; ++i
) {
165 inline double Octree::getDx(const OctreeCell
& cell
)
168 for (int i
= 0; i
< cell
.m_Level
; ++i
) {
174 inline double Octree::getDy(int cell
)
177 for (int i
= 0; i
< m_Cells
[cell
].m_Level
; ++i
) {
183 inline double Octree::getDy(const OctreeCell
& cell
)
186 for (int i
= 0; i
< cell
.m_Level
; ++i
) {
192 inline double Octree::getDz(int cell
)
195 for (int i
= 0; i
< m_Cells
[cell
].m_Level
; ++i
) {
201 inline double Octree::getDz(const OctreeCell
& cell
)
204 for (int i
= 0; i
< cell
.m_Level
; ++i
) {