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 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31 class PointFinder
: public EgVtkObject
35 QVector
<vec3_t
> m_Points
;
39 QVector
<QList
<int> > m_Buckets
;
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
);
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
);
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]);
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]);
98 Dx2
= vec3_t(Dx2
[2], Dx2
[2], Dx2
[2]);
101 if (Dx2
.abs() > Dx1
.abs()) {
106 m_Octree
.setBounds(x1
, x2
);
107 m_MinSize
= 0.0001*Dx
[0];
110 for (int i_points
= 0; i_points
< points
.size(); ++i_points
) {
111 m_Buckets
[0].append(i_points
);
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