15 : m_origin(origin), m_halfDimension(halfDimension) {
16 min.
x = origin.
x - halfDimension.
x;
17 min.
y = origin.
y - halfDimension.
y;
18 min.
z = origin.
z - halfDimension.
z;
19 max.
x = origin.
x + halfDimension.
x;
20 max.
y = origin.
y + halfDimension.
y;
21 max.
z = origin.
z + halfDimension.
z;
24 for (
int i = 0; i < 8; ++i) children[i] =
nullptr;
29 for (
int i = 0; i < 8; ++i)
delete children[i];
33bool TetrahedralTree::DoesBoxOverlap(
const Vec3& b_min,
34 const Vec3& b_max)
const {
35 if (max.
x < b_min.
x)
return false;
36 if (max.
y < b_min.
y)
return false;
37 if (max.
z < b_min.
z)
return false;
38 if (min.
x > b_max.
x)
return false;
39 if (min.
y > b_max.
y)
return false;
40 if (min.
z > b_max.
z)
return false;
46int TetrahedralTree::GetOctantContainingPoint(
const Vec3& point)
const {
48 if (point.x >= m_origin.
x) oct |= 4;
49 if (point.y >= m_origin.
y) oct |= 2;
50 if (point.z >= m_origin.
z) oct |= 1;
54bool TetrahedralTree::IsFull()
const {
59bool TetrahedralTree::IsEmpty()
const {
return iBlockElems.size() == 0; }
61bool TetrahedralTree::IsLeafNode()
const {
64 return children[0] ==
nullptr;
71 if (!this->IsFull()) {
72 iBlockElems.push_back(OctreeBlockElem(point, nodeIndex));
77 for (
int i = 0; i < 8; ++i) {
79 Vec3 newOrigin = m_origin;
80 newOrigin.
x += m_halfDimension.
x * (i & 4 ? .5f : -.5f);
81 newOrigin.
y += m_halfDimension.
y * (i & 2 ? .5f : -.5f);
82 newOrigin.
z += m_halfDimension.
z * (i & 1 ? .5f : -.5f);
88 while (!this->IsEmpty()) {
89 OctreeBlockElem bElem = iBlockElems.back();
90 iBlockElems.pop_back();
91 int octant = GetOctantContainingPoint(bElem.point);
102 int octant = GetOctantContainingPoint(point);
108 const int elemIndex) {
111 tetList.push_back(elemIndex);
114 for (
int i = 0; i < 8; i++) {
115 Vec3 elem_min(elemBoundingBox[0], elemBoundingBox[1], elemBoundingBox[2]);
116 Vec3 elem_max(elemBoundingBox[3], elemBoundingBox[4], elemBoundingBox[5]);
118 if (children[i]->DoesBoxOverlap(elem_min, elem_max))
131 return octreeNode->tetList;
134 return std::vector<int>();
143 if (!(m_origin.
x - m_halfDimension.
x <= point.
x &&
144 point.
x <= m_origin.
x + m_halfDimension.
x &&
145 m_origin.
y - m_halfDimension.
y <= point.
y &&
146 point.
y <= m_origin.
y + m_halfDimension.
y &&
147 m_origin.
z - m_halfDimension.
z <= point.
z &&
148 point.
z <= m_origin.
z + m_halfDimension.
z))
151 return GetBlockFromPointHelper(point);
154const TetrahedralTree* TetrahedralTree::GetBlockFromPointHelper(
157 if (IsLeafNode())
return this;
160 int octant = GetOctantContainingPoint(point);
161 return children[octant]->GetBlockFromPointHelper(point);
Helper class for searches in field maps.
std::vector< int > GetTetListInBlock(const Vec3 &point)
void InsertTetrahedron(const double elemBoundingBox[6], const int elemIndex)
TetrahedralTree(const Vec3 &origin, const Vec3 &halfDimension)
void InsertMeshNode(Vec3 point, const int nodeIndex)