15 : m_origin(origin), m_halfDimension(halfDimension) {
17 min.
x = origin.
x - halfDimension.
x;
18 min.
y = origin.
y - halfDimension.
y;
19 min.
z = origin.
z - halfDimension.
z;
20 max.
x = origin.
x + halfDimension.
x;
21 max.
y = origin.
y + halfDimension.
y;
22 max.
z = origin.
z + halfDimension.
z;
25 for (
int i = 0; i < 8; ++i) children[i] = NULL;
30 for (
int i = 0; i < 8; ++i)
delete children[i];
34bool TetrahedralTree::DoesBoxOverlap(
const Vec3& b_min,
35 const Vec3& b_max)
const {
36 if (max.
x < b_min.
x)
return false;
37 if (max.
y < b_min.
y)
return false;
38 if (max.
z < b_min.
z)
return false;
39 if (min.
x > b_max.
x)
return false;
40 if (min.
y > b_max.
y)
return false;
41 if (min.
z > b_max.
z)
return false;
47int TetrahedralTree::GetOctantContainingPoint(
const Vec3& point)
const {
49 if (point.x >= m_origin.
x) oct |= 4;
50 if (point.y >= m_origin.
y) oct |= 2;
51 if (point.z >= m_origin.
z) oct |= 1;
55bool TetrahedralTree::IsFull()
const {
60bool TetrahedralTree::IsEmpty()
const {
return iBlockElems.size() == 0; }
62bool TetrahedralTree::IsLeafNode()
const {
65 return children[0] == NULL;
72 if (!this->IsFull()) {
73 iBlockElems.push_back(OctreeBlockElem(point, nodeIndex));
78 for (
int i = 0; i < 8; ++i) {
80 Vec3 newOrigin = m_origin;
81 newOrigin.
x += m_halfDimension.
x * (i & 4 ? .5f : -.5f);
82 newOrigin.
y += m_halfDimension.
y * (i & 2 ? .5f : -.5f);
83 newOrigin.
z += m_halfDimension.
z * (i & 1 ? .5f : -.5f);
89 while (!this->IsEmpty()) {
90 OctreeBlockElem bElem = iBlockElems.back();
91 iBlockElems.pop_back();
92 int octant = GetOctantContainingPoint(bElem.point);
97 children[GetOctantContainingPoint(point)]
103 int octant = GetOctantContainingPoint(point);
109 const int elemIndex) {
113 tetList.push_back(elemIndex);
116 for (
int i = 0; i < 8; i++) {
117 Vec3 elem_min(elemBoundingBox[0], elemBoundingBox[1], elemBoundingBox[2]);
118 Vec3 elem_max(elemBoundingBox[3], elemBoundingBox[4], elemBoundingBox[5]);
120 if (children[i]->DoesBoxOverlap(elem_min, elem_max))
134 return octreeNode->tetList;
137 return std::vector<int>();
146 if (!(m_origin.
x - m_halfDimension.
x <= point.
x &&
147 point.
x <= m_origin.
x + m_halfDimension.
x &&
148 m_origin.
y - m_halfDimension.
y <= point.
y &&
149 point.
y <= m_origin.
y + m_halfDimension.
y &&
150 m_origin.
z - m_halfDimension.
z <= point.
z &&
151 point.
z <= m_origin.
z + m_halfDimension.
z))
154 return GetBlockFromPointHelper(point);
157const TetrahedralTree* TetrahedralTree::GetBlockFromPointHelper(
160 if (IsLeafNode())
return this;
163 int octant = GetOctantContainingPoint(point);
164 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)