1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
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. +
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. +
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/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #include "pointfinder.h"
23 PointFinder::PointFinder()
29 void PointFinder::setGrid(vtkUnstructuredGrid
*grid
)
31 QVector
<vec3_t
> points(grid
->GetNumberOfPoints());
32 for (vtkIdType id_node
= 0; id_node
< grid
->GetNumberOfPoints(); ++id_node
) {
33 grid
->GetPoint(id_node
, points
[id_node
].data());
38 int PointFinder::refine()
40 int N
= m_Octree
.getNumCells();
41 m_Octree
.setSmoothTransitionOff();
43 m_Octree
.resetRefineMarks();
44 for (int cell
= 0; cell
< m_Octree
.getNumCells(); ++cell
) {
45 double dx
= m_Octree
.getDx(cell
);
46 if (!m_Octree
.hasChildren(cell
) && m_Buckets
[cell
].size() > m_MaxPoints
&& dx
> 2*m_MinSize
) {
47 m_Octree
.markToRefine(cell
);
52 for (int cell
= 0; cell
< m_Octree
.getNumCells(); ++cell
) {
53 if (m_Octree
.markedForRefine(cell
)) {
59 if (m_Octree
.getNumCells() != N
+ N_new
) {
62 m_Buckets
.insert(N
, N_new
, QList
<int>());
63 for (int cell
= N
; cell
< m_Octree
.getNumCells(); ++cell
) {
64 m_Timer
<< " " << m_Octree
.getNumCells() << " octree cells" << Timer::endl
;
65 if (m_Octree
.getNumCells() != N
+ N_new
) {
68 int parent
= m_Octree
.getParent(cell
);
72 foreach (int i_points
, m_Buckets
[parent
]) {
73 vec3_t xcell
= m_Octree
.getCellCentre(cell
);
74 vec3_t x
= m_Points
[i_points
];
77 double Dx
= m_Octree
.getDx(cell
);
78 double Dy
= m_Octree
.getDy(cell
);
79 double Dz
= m_Octree
.getDz(cell
);
80 if (x
[0] < xcell
[0] - 1.5*Dx
|| x
[0] > xcell
[0] + 1.5*Dx
) append
= false;
81 else if (x
[1] < xcell
[1] - 1.5*Dy
|| x
[1] > xcell
[1] + 1.5*Dy
) append
= false;
82 else if (x
[2] < xcell
[2] - 1.5*Dz
|| x
[2] > xcell
[2] + 1.5*Dz
) append
= false;
85 m_Buckets
[cell
].append(i_points
);
92 void PointFinder::getClosePoints(vec3_t x
, QVector
<int> &points
, double dist
)
94 if (m_Octree
.isInsideBounds(x
)) {
95 int cell
= m_Octree
.findCell(x
);
99 if (m_Octree
.hasChildren(cell
)) {
102 while ((m_Buckets
[cell
].size() == 0 || dist
> m_Octree
.getDx(cell
)) && m_Octree
.getParent(cell
) >= 0) {
103 cell
= m_Octree
.getParent(cell
);
105 points
.resize(m_Buckets
[cell
].size());
106 qCopy(m_Buckets
[cell
].begin(), m_Buckets
[cell
].end(), points
.begin());
108 points
.resize(m_Points
.size());
109 for (int i
= 0; i
< points
.size(); ++i
) {
115 void PointFinder::writeOctreeMesh(QString file_name
)
117 EG_VTKSP(vtkUnstructuredGrid
, otg
);
118 m_Octree
.toVtkGridHangingNodes(otg
);
119 writeGrid(otg
, file_name
);