(#415) Used AABB tree to search for elements

to find close elements to the wellpath for Geom Well Log extraction
This commit is contained in:
Jacob Støren 2015-09-07 16:47:40 +02:00
parent 3468160d8f
commit 1b9977239d
4 changed files with 45 additions and 46 deletions

View File

@ -21,6 +21,7 @@
#include "RigFemPartGrid.h"
#include "cvfBoundingBox.h"
#include "cvfBoundingBoxTree.h"
//--------------------------------------------------------------------------------------------------
///
@ -338,3 +339,38 @@ cvf::BoundingBox RigFemPart::boundingBox()
return m_boundingBox;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigFemPart::findIntersectingCells(const cvf::BoundingBox& inputBB, std::vector<size_t>* elementIndices) const
{
if (m_elementSearchTree.isNull())
{
// build tree
size_t elmCount = elementCount();
std::vector<cvf::BoundingBox> cellBoundingBoxes;
cellBoundingBoxes.resize(elmCount);
for (size_t elmIdx = 0; elmIdx < elmCount; ++elmIdx)
{
const int* cellIndices = connectivities(elmIdx);
cvf::BoundingBox& cellBB = cellBoundingBoxes[elmIdx];
cellBB.add(m_nodes.coordinates[cellIndices[0]]);
cellBB.add(m_nodes.coordinates[cellIndices[1]]);
cellBB.add(m_nodes.coordinates[cellIndices[2]]);
cellBB.add(m_nodes.coordinates[cellIndices[3]]);
cellBB.add(m_nodes.coordinates[cellIndices[4]]);
cellBB.add(m_nodes.coordinates[cellIndices[5]]);
cellBB.add(m_nodes.coordinates[cellIndices[6]]);
cellBB.add(m_nodes.coordinates[cellIndices[7]]);
}
m_elementSearchTree = new cvf::BoundingBoxTree;
m_elementSearchTree->buildTreeFromBoundingBoxes(cellBoundingBoxes, NULL);
}
m_elementSearchTree->findIntersections(inputBB, elementIndices);
}

View File

@ -30,6 +30,11 @@
class RigFemPartGrid;
namespace cvf
{
class BoundingBoxTree;
}
class RigFemPartNodes
{
public:
@ -74,6 +79,7 @@ public:
cvf::BoundingBox boundingBox();
float characteristicElementSize();
const std::vector<int>& possibleGridCornerElements() const { return m_possibleGridCornerElements; }
void findIntersectingCells(const cvf::BoundingBox& inputBB, std::vector<size_t>* elementIndices) const;
cvf::Vec3f faceNormal(int elmentIndex, int faceIndex);
@ -102,4 +108,6 @@ private:
float m_characteristicElementSize;
cvf::BoundingBox m_boundingBox;
mutable cvf::ref<cvf::BoundingBoxTree> m_elementSearchTree;
};

View File

@ -138,32 +138,6 @@ std::vector<size_t> RigEclipseWellLogExtractor::findCloseCells(const cvf::Boundi
{
std::vector<size_t> closeCells;
m_caseData->mainGrid()->findIntersectingCells(bb, &closeCells);
#if 0
const std::vector<RigCell>& cells = m_caseData->mainGrid()->cells();
const std::vector<cvf::Vec3d>& nodeCoords = m_caseData->mainGrid()->nodes();
size_t cellCount = cells.size();
for (size_t cIdx = 0; cIdx < cellCount; ++cIdx)
{
const caf::SizeTArray8& cellIndices = cells[cIdx].cornerIndices();
cvf::BoundingBox cellBB;
cellBB.add(nodeCoords[cellIndices[0]]);
cellBB.add(nodeCoords[cellIndices[1]]);
cellBB.add(nodeCoords[cellIndices[2]]);
cellBB.add(nodeCoords[cellIndices[3]]);
cellBB.add(nodeCoords[cellIndices[4]]);
cellBB.add(nodeCoords[cellIndices[5]]);
cellBB.add(nodeCoords[cellIndices[6]]);
cellBB.add(nodeCoords[cellIndices[7]]);
if (bb.intersects(cellBB))
{
closeCells.push_back(cIdx);
}
}
#endif
return closeCells;
}

View File

@ -191,26 +191,7 @@ std::vector<size_t> RigGeoMechWellLogExtractor::findCloseCells(const cvf::Boundi
if (m_caseData->femParts()->partCount())
{
const RigFemPart* femPart = m_caseData->femParts()->part(0);
const std::vector<cvf::Vec3f>& nodeCoords = femPart->nodes().coordinates;
size_t elmCount = femPart->elementCount();
for (size_t elmIdx = 0; elmIdx < elmCount; ++elmIdx)
{
const int* elmNodeIndices = femPart->connectivities(elmIdx);
int elmNodeCount = RigFemTypes::elmentNodeCount(femPart->elementType(elmIdx));
cvf::BoundingBox cellBB;
for (int enIdx = 0; enIdx < elmNodeCount; ++enIdx)
{
cellBB.add(cvf::Vec3d(nodeCoords[elmNodeIndices[enIdx]]));
}
if (bb.intersects(cellBB))
{
closeCells.push_back(elmIdx);
}
}
m_caseData->femParts()->part(0)->findIntersectingCells(bb, &closeCells);
}
return closeCells;
}