diff --git a/MeshLib/MeshSearch/MeshElementGrid.cpp b/MeshLib/MeshSearch/MeshElementGrid.cpp index 87fc85d98b78bfe3721285b03de3aa3e8593ea5b..358ea28d18499ba1ea15ac37ab2e8cf6604d2e6a 100644 --- a/MeshLib/MeshSearch/MeshElementGrid.cpp +++ b/MeshLib/MeshSearch/MeshElementGrid.cpp @@ -100,6 +100,16 @@ MeshElementGrid::MeshElementGrid(MeshLib::Mesh const& sfc_mesh) : sortElementsInGridCells(sfc_mesh); } +MathLib::Point3d const& MeshElementGrid::getMinPoint() const +{ + return _aabb.getMinPoint(); +} + +MathLib::Point3d const& MeshElementGrid::getMaxPoint() const +{ + return _aabb.getMaxPoint(); +} + void MeshElementGrid::sortElementsInGridCells(MeshLib::Mesh const& sfc_mesh) { for (auto const element : sfc_mesh.getElements()) { @@ -142,6 +152,13 @@ bool MeshElementGrid::sortElementInGridCells(MeshLib::Element const& element) const std::size_t n_plane(_n_steps[0]*_n_steps[1]); + // If a node of an element is almost equal to the upper right point of the + // AABB the grid cell coordinates computed by getGridCellCoordintes() could + // be to large (due to numerical errors). The following lines ensure that + // the grid cell coordinates are in the valid range. + for (std::size_t k(0); k<3; ++k) + max[k] = std::min(_n_steps[k]-1, max[k]); + // insert the element into the grid cells for (std::size_t i(min[0]); i<=max[0]; i++) { for (std::size_t j(min[1]); j<=max[1]; j++) { diff --git a/MeshLib/MeshSearch/MeshElementGrid.h b/MeshLib/MeshSearch/MeshElementGrid.h index 3cc0f96f5e26b97f90b913ad82e71843f8effe4b..06105270082ea8f4fe069d4be4d0826c9c426cc3 100644 --- a/MeshLib/MeshSearch/MeshElementGrid.h +++ b/MeshLib/MeshSearch/MeshElementGrid.h @@ -56,24 +56,6 @@ public: auto const min_coords(getGridCellCoordinates(min)); auto const max_coords(getGridCellCoordinates(max)); - if (!min_coords.first) { - WARN( - "MeshElementGrid::getElementsInVolume: Min point (%f,%f,%f) " - "outside of MeshElementGrid [%f,%f) x [%f,%f) x [%f,%f).", - min[0], min[1], min[2], _aabb.getMinPoint()[0], - _aabb.getMaxPoint()[0], _aabb.getMinPoint()[1], - _aabb.getMaxPoint()[1], _aabb.getMinPoint()[2], - _aabb.getMaxPoint()[2]); - } - if (!max_coords.first) { - WARN( - "MeshElementGrid::getElementsInVolume: Max point (%f,%f,%f) " - "outside of MeshElementGrid [%f,%f) x [%f,%f) x [%f,%f).", - max[0], max[1], max[2], _aabb.getMinPoint()[0], - _aabb.getMaxPoint()[0], _aabb.getMinPoint()[1], - _aabb.getMaxPoint()[1], _aabb.getMinPoint()[2], - _aabb.getMaxPoint()[2]); - } std::vector<MeshLib::Element const*> elements_vec; const std::size_t n_plane(_n_steps[0]*_n_steps[1]); @@ -90,6 +72,13 @@ public: return elements_vec; } + /// Returns the min point of the internal AABB. The method is a wrapper for + /// GeoLib::AABB::getMinPoint(). + MathLib::Point3d const& getMinPoint() const; + /// Returns the max point of the internal AABB. The method is a wrapper for + /// AABB::getMaxPoint(). + MathLib::Point3d const& getMaxPoint() const; + private: void sortElementsInGridCells(MeshLib::Mesh const& sfc_mesh); bool sortElementInGridCells(MeshLib::Element const& element);