limited volume meshing to boundary layer only
[engrid-github.git] / src / libengrid / pointfinder.h
blob6b66869c62212408ecef476546a5d64c2dffdfa9
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 POINTFINDER_H
22 #define POINTFINDER_H
24 #include "octree.h"
25 #include "triangle.h"
26 #include "timer.h"
28 #include <QVector>
29 #include <QList>
31 class PointFinder : public EgVtkObject
34 Octree m_Octree;
35 QVector<vec3_t> m_Points;
36 double m_MinSize;
37 int m_MaxPoints;
38 Timer m_Timer;
39 QVector<QList<int> > m_Buckets;
40 int m_MinBucketSize;
41 int m_MaxBucketSize;
44 private: // methods
46 int refine();
49 public: // methods
51 PointFinder();
53 template <typename C>
54 void setPoints(const C &points);
56 void setGrid(vtkUnstructuredGrid *grid);
57 void setMaxNumPoints(int N) { m_MaxPoints = N; }
58 void getClosePoints(vec3_t x, QVector<int> &points, double dist = 0);
59 int minBucketSize() { return m_MinBucketSize; }
60 int maxBucketSize() { return m_MaxBucketSize; }
61 void writeOctreeMesh(QString file_name);
67 template <typename C>
68 void PointFinder::setPoints(const C &points)
70 m_Points.resize(points.size());
71 qCopy(points.begin(), points.end(), m_Points.begin());
73 vec3_t x1(1e99, 1e99, 1e99);
74 vec3_t x2(-1e99, -1e99, -1e99);
75 foreach (vec3_t x, m_Points) {
76 x1[0] = min(x[0], x1[0]);
77 x1[1] = min(x[1], x1[1]);
78 x1[2] = min(x[2], x1[2]);
79 x2[0] = max(x[0], x2[0]);
80 x2[1] = max(x[1], x2[1]);
81 x2[2] = max(x[2], x2[2]);
83 vec3_t xc = 0.5*(x1 + x2);
84 vec3_t Dx1 = xc - x1;
85 vec3_t Dx2 = x2 - xc;
86 if (fabs(Dx1[0]) >= fabs(Dx1[1]) && fabs(Dx1[0]) >= fabs(Dx1[2])) {
87 Dx1 = vec3_t(Dx1[0], Dx1[0], Dx1[0]);
88 } else if (fabs(Dx1[1]) >= fabs(Dx1[0]) && fabs(Dx1[1]) >= fabs(Dx1[2])) {
89 Dx1 = vec3_t(Dx1[1], Dx1[1], Dx1[1]);
90 } else {
91 Dx1 = vec3_t(Dx1[2], Dx1[2], Dx1[2]);
93 if (fabs(Dx2[0]) >= fabs(Dx2[1]) && fabs(Dx2[0]) >= fabs(Dx2[2])) {
94 Dx2 = vec3_t(Dx2[0], Dx2[0], Dx2[0]);
95 } else if (fabs(Dx2[1]) >= fabs(Dx2[0]) && fabs(Dx2[1]) >= fabs(Dx2[2])) {
96 Dx2 = vec3_t(Dx2[1], Dx2[1], Dx2[1]);
97 } else {
98 Dx2 = vec3_t(Dx2[2], Dx2[2], Dx2[2]);
100 vec3_t Dx = Dx1;
101 if (Dx2.abs() > Dx1.abs()) {
102 Dx = Dx2;
104 x1 = xc - 2*Dx;
105 x2 = xc + 2*Dx;
106 m_Octree.setBounds(x1, x2);
107 m_MinSize = 0.0001*Dx[0];
109 m_Buckets.resize(1);
110 for (int i_points = 0; i_points < points.size(); ++i_points) {
111 m_Buckets[0].append(i_points);
113 int N;
114 do {
115 N = refine();
116 } while (N > 0);
117 m_MaxBucketSize = 0;
118 m_MinBucketSize = points.size();
119 for (int i = 0; i < m_Buckets.size(); ++i) {
120 m_MinBucketSize = min(m_MinBucketSize, m_Buckets[i].size());
121 m_MaxBucketSize = max(m_MaxBucketSize, m_Buckets[i].size());
127 #endif // POINTFINDER_H