Commit c1d1287e authored by Tom Fischer's avatar Tom Fischer
Browse files

[GL/AABB] Use Eigen::Vector3d instead of MathLib::Point3d.

parent c7ebb6be
......@@ -142,7 +142,7 @@ void MeshElementRemovalDialog::accept()
(aabb_edits[4]) ? this->zMinEdit->text().toDouble() : (minAABB[2]);
maxAABB[2] =
(aabb_edits[5]) ? this->zMaxEdit->text().toDouble() : (maxAABB[2]);
std::vector<MathLib::Point3d> extent;
std::vector<Eigen::Vector3d> extent;
extent.push_back(minAABB);
extent.push_back(maxAABB);
const GeoLib::AABB updated_aabb(extent.begin(), extent.end());
......
......@@ -68,8 +68,8 @@ int main(int argc, char* argv[])
std::vector<MeshLib::Node*> const& nodes_vec(mesh->getNodes());
GeoLib::AABB const bounding_box(nodes_vec.begin(), nodes_vec.end());
MathLib::Point3d const& min(bounding_box.getMinPoint());
MathLib::Point3d const& max(bounding_box.getMaxPoint());
auto const& min(bounding_box.getMinPoint());
auto const& max(bounding_box.getMaxPoint());
auto const n_cols =
static_cast<std::size_t>(std::ceil((max[0] - min[0]) / cellsize));
auto const n_rows =
......
......@@ -110,7 +110,7 @@ void markFaults(MeshLib::Mesh& mesh, MeshLib::Mesh const& fault,
min_pnt[i] -= half_cell_size[i];
max_pnt[i] += half_cell_size[i];
}
std::array<MathLib::Point3d, 2> const fault_extent{{min_pnt, max_pnt}};
std::array<Eigen::Vector3d, 2> const fault_extent{{min_pnt, max_pnt}};
GeoLib::AABB const fault_aabb_ext(fault_extent.cbegin(),
fault_extent.cend());
......
......@@ -171,14 +171,14 @@ public:
* for the given point set
* @return a point
*/
MathLib::Point3d const& getMinPoint() const { return _min_pnt; }
Eigen::Vector3d const& getMinPoint() const { return _min_pnt; }
/**
* returns a point that coordinates are maximal for each dimension
* within the given point set
* @return a point
*/
MathLib::Point3d const& getMaxPoint() const { return _max_pnt; }
Eigen::Vector3d const& getMaxPoint() const { return _max_pnt; }
/**
* Method checks if the given AABB object is contained within the
......@@ -194,13 +194,12 @@ public:
}
private:
MathLib::Point3d _min_pnt = MathLib::Point3d{std::array<double, 3>{
{std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
std::numeric_limits<double>::max()}}};
MathLib::Point3d _max_pnt = MathLib::Point3d{
std::array<double, 3>{std::numeric_limits<double>::lowest(),
std::numeric_limits<double>::lowest(),
std::numeric_limits<double>::lowest()}};
Eigen::Vector3d _min_pnt{std::numeric_limits<double>::max(),
std::numeric_limits<double>::max(),
std::numeric_limits<double>::max()};
Eigen::Vector3d _max_pnt{std::numeric_limits<double>::lowest(),
std::numeric_limits<double>::lowest(),
std::numeric_limits<double>::lowest()};
private:
/// Enlarge the bounding box the smallest possible amount (modifying the
......
......@@ -97,8 +97,8 @@ public:
double half_len) const;
void getPntVecsOfGridCellsIntersectingCuboid(
MathLib::Point3d const& min_pnt,
MathLib::Point3d const& max_pnt,
Eigen::Vector3d const& min_pnt,
Eigen::Vector3d const& max_pnt,
std::vector<std::vector<POINT*> const*>& pnts) const;
#ifndef NDEBUG
......@@ -286,8 +286,8 @@ Grid<POINT>::getPntVecsOfGridCellsIntersectingCube(P const& center,
template <typename POINT>
void Grid<POINT>::getPntVecsOfGridCellsIntersectingCuboid(
MathLib::Point3d const& min_pnt,
MathLib::Point3d const& max_pnt,
Eigen::Vector3d const& min_pnt,
Eigen::Vector3d const& max_pnt,
std::vector<std::vector<POINT*> const*>& pnts) const
{
std::array<std::size_t, 3> min_coords(getGridCoords(min_pnt));
......@@ -479,7 +479,7 @@ POINT* Grid<POINT>::getNearestPoint(P const& pnt) const
auto const& min_point{getMinPoint()};
auto const& max_point{getMaxPoint()};
double sqr_min_dist(MathLib::sqrDist(min_point, max_point));
double sqr_min_dist = (max_point - min_point).squaredNorm();
POINT* nearest_pnt(nullptr);
std::array<double, 6> dists(getPointCellBorderDistances(pnt, coords));
......
......@@ -21,14 +21,6 @@
namespace GeoLib
{
namespace details
{
Eigen::Vector3d convertToEigen(MathLib::Point3d point3d)
{
return Eigen::Vector3d{point3d[0], point3d[1], point3d[2]};
}
} // namespace details
PointVec::PointVec(
const std::string& name, std::unique_ptr<std::vector<Point*>> points,
std::unique_ptr<std::map<std::string, std::size_t>> name_id_map,
......@@ -36,11 +28,9 @@ PointVec::PointVec(
: TemplateVec<Point>(name, std::move(points), std::move(name_id_map)),
_type(type),
_aabb(_data_vec->begin(), _data_vec->end()),
_rel_eps(rel_eps * std::sqrt(MathLib::sqrDist(_aabb.getMinPoint(),
_aabb.getMaxPoint()))),
_rel_eps(rel_eps * (_aabb.getMaxPoint() - _aabb.getMinPoint()).norm()),
_oct_tree(OctTree<GeoLib::Point, 16>::createOctTree(
details::convertToEigen(_aabb.getMinPoint()),
details::convertToEigen(_aabb.getMaxPoint()), _rel_eps))
_aabb.getMinPoint(), _aabb.getMaxPoint(), _rel_eps))
{
assert(_data_vec);
std::size_t const number_of_all_input_pnts(_data_vec->size());
......@@ -189,8 +179,7 @@ std::size_t PointVec::uniqueInsert(Point* pnt)
_aabb.update(*pnt);
// recreate the (enlarged) OctTree
_oct_tree.reset(GeoLib::OctTree<GeoLib::Point, 16>::createOctTree(
details::convertToEigen(_aabb.getMinPoint()),
details::convertToEigen(_aabb.getMaxPoint()), _rel_eps));
_aabb.getMinPoint(), _aabb.getMaxPoint(), _rel_eps));
// add all points that are already in the _data_vec
for (std::size_t k(0); k < _data_vec->size(); ++k)
{
......@@ -267,18 +256,16 @@ void PointVec::setNameForElement(std::size_t id, std::string const& name)
void PointVec::resetInternalDataStructures()
{
MathLib::Point3d const& min(_aabb.getMinPoint());
MathLib::Point3d const& max(_aabb.getMaxPoint());
double const rel_eps(_rel_eps / std::sqrt(MathLib::sqrDist(min, max)));
auto const& min(_aabb.getMinPoint());
auto const& max(_aabb.getMaxPoint());
double const rel_eps(_rel_eps / (max-min).norm());
_aabb = GeoLib::AABB(_data_vec->begin(), _data_vec->end());
_rel_eps = rel_eps * std::sqrt(MathLib::sqrDist(_aabb.getMinPoint(),
_aabb.getMaxPoint()));
_rel_eps = rel_eps * (_aabb.getMaxPoint() - _aabb.getMinPoint()).norm();
_oct_tree.reset(OctTree<GeoLib::Point, 16>::createOctTree(
details::convertToEigen(_aabb.getMinPoint()),
details::convertToEigen(_aabb.getMaxPoint()), _rel_eps));
_aabb.getMinPoint(), _aabb.getMaxPoint(), _rel_eps));
GeoLib::Point* ret_pnt(nullptr);
for (auto const p : *_data_vec)
......
......@@ -70,8 +70,8 @@ bool Polygon::initialise()
bool Polygon::isPntInPolygon(GeoLib::Point const& pnt) const
{
MathLib::Point3d const& min_aabb_pnt(_aabb.getMinPoint());
MathLib::Point3d const& max_aabb_pnt(_aabb.getMaxPoint());
auto const& min_aabb_pnt(_aabb.getMinPoint());
auto const& max_aabb_pnt(_aabb.getMaxPoint());
if (pnt[0] < min_aabb_pnt[0] || max_aabb_pnt[0] < pnt[0] ||
pnt[1] < min_aabb_pnt[1] || max_aabb_pnt[1] < pnt[1])
......
......@@ -479,8 +479,14 @@ getCandidateElementsForLineSegmentIntersection(
{seg_deep_copy.getBeginPoint(), seg_deep_copy.getEndPoint()}};
GeoLib::AABB aabb(pnts.cbegin(), pnts.cend());
auto candidate_elements = mesh_element_grid.getElementsInVolume(
aabb.getMinPoint(), aabb.getMaxPoint());
// TODO TF: remove after getElementsInVolume interface change
auto convert_to_Point3d = [](Eigen::Vector3d const& v) {
return MathLib::Point3d{std::array{v[0], v[1], v[2]}};
};
auto const min = convert_to_Point3d(aabb.getMinPoint());
auto const max = convert_to_Point3d(aabb.getMaxPoint());
auto candidate_elements = mesh_element_grid.getElementsInVolume(min, max);
// make candidate elements unique
BaseLib::makeVectorUnique(candidate_elements);
......
......@@ -45,10 +45,8 @@ unsigned char CoordinateSystem::getCoordinateSystem(
{
unsigned char coords = 0;
auto const bbox_min =
Eigen::Map<Eigen::Vector3d const>(bbox.getMinPoint().getCoords());
auto const bbox_max =
Eigen::Map<Eigen::Vector3d const>(bbox.getMaxPoint().getCoords());
auto const& bbox_min = bbox.getMinPoint();
auto const& bbox_max = bbox.getMaxPoint();
Eigen::Vector3d const pt_diff = bbox_max - bbox_min;
// The axis aligned bounding box is a from the right half-open interval.
......
......@@ -26,8 +26,8 @@ MeshElementGrid::MeshElementGrid(MeshLib::Mesh const& mesh)
: _aabb{mesh.getNodes().cbegin(), mesh.getNodes().cend()},
_n_steps({{1, 1, 1}})
{
auto getDimensions = [](MathLib::Point3d const& min,
MathLib::Point3d const& max) {
auto getDimensions = [](auto const& min, auto const& max)
{
std::bitset<3> dim; // all bits are set to zero.
for (std::size_t k(0); k < 3; ++k)
{
......@@ -42,8 +42,8 @@ MeshElementGrid::MeshElementGrid(MeshLib::Mesh const& mesh)
return dim;
};
MathLib::Point3d const& min_pnt(_aabb.getMinPoint());
MathLib::Point3d const& max_pnt(_aabb.getMaxPoint());
auto const& min_pnt(_aabb.getMinPoint());
auto const& max_pnt(_aabb.getMaxPoint());
auto const dim = getDimensions(min_pnt, max_pnt);
std::array<double, 3> delta{{max_pnt[0] - min_pnt[0],
......@@ -119,12 +119,12 @@ MeshElementGrid::MeshElementGrid(MeshLib::Mesh const& mesh)
sortElementsInGridCells(mesh);
}
MathLib::Point3d const& MeshElementGrid::getMinPoint() const
Eigen::Vector3d const& MeshElementGrid::getMinPoint() const
{
return _aabb.getMinPoint();
}
MathLib::Point3d const& MeshElementGrid::getMaxPoint() const
Eigen::Vector3d const& MeshElementGrid::getMaxPoint() const
{
return _aabb.getMaxPoint();
}
......
......@@ -69,10 +69,10 @@ public:
/// Returns the min point of the internal AABB. The method is a wrapper for
/// GeoLib::AABB::getMinPoint().
MathLib::Point3d const& getMinPoint() const;
Eigen::Vector3d const& getMinPoint() const;
/// Returns the max point of the internal AABB. The method is a wrapper for
/// AABB::getMaxPoint().
MathLib::Point3d const& getMaxPoint() const;
Eigen::Vector3d const& getMaxPoint() const;
private:
void sortElementsInGridCells(MeshLib::Mesh const& mesh);
......
......@@ -45,8 +45,8 @@ TEST(GeoLibAABB, RandomNumberOfPointersToRandomPoints)
// construct from list points a axis aligned bounding box
GeoLib::AABB aabb(pnts_list.begin(), pnts_list.end());
MathLib::Point3d const& min_pnt(aabb.getMinPoint());
MathLib::Point3d const& max_pnt(aabb.getMaxPoint());
auto const& min_pnt(aabb.getMinPoint());
auto const& max_pnt(aabb.getMaxPoint());
ASSERT_LE(minus_half_box_size, min_pnt[0])
<< "coordinate 0 of min_pnt is smaller than " << minus_half_box_size;
......@@ -92,8 +92,8 @@ TEST(GeoLibAABB, RandomNumberOfPointsRandomPointInAList)
// construct from list points a axis aligned bounding box
GeoLib::AABB aabb(pnts_list.begin(), pnts_list.end());
MathLib::Point3d const& min_pnt(aabb.getMinPoint());
MathLib::Point3d const& max_pnt(aabb.getMaxPoint());
auto const& min_pnt(aabb.getMinPoint());
auto const& max_pnt(aabb.getMaxPoint());
ASSERT_LE(minus_half_box_size, min_pnt[0])
<< "coordinate 0 of min_pnt is smaller than " << minus_half_box_size;
......@@ -134,8 +134,8 @@ TEST(GeoLibAABB, RandomNumberOfPointersToRandomPointsInAVector)
// construct from list points a axis aligned bounding box
GeoLib::AABB aabb(pnts.begin(), pnts.end());
MathLib::Point3d const& min_pnt(aabb.getMinPoint());
MathLib::Point3d const& max_pnt(aabb.getMaxPoint());
auto const& min_pnt(aabb.getMinPoint());
auto const& max_pnt(aabb.getMaxPoint());
ASSERT_LE(minus_half_box_size, min_pnt[0])
<< "coordinate 0 of min_pnt is smaller than " << minus_half_box_size;
......@@ -181,8 +181,8 @@ TEST(GeoLibAABB, RandomNumberOfPointsRandomPointInAVector)
// construct from list points a axis aligned bounding box
GeoLib::AABB aabb(pnts.begin(), pnts.end());
MathLib::Point3d const& min_pnt(aabb.getMinPoint());
MathLib::Point3d const& max_pnt(aabb.getMaxPoint());
auto const& min_pnt(aabb.getMinPoint());
auto const& max_pnt(aabb.getMaxPoint());
ASSERT_LE(minus_half_box_size, min_pnt[0])
<< "coordinate 0 of min_pnt is smaller than " << minus_half_box_size;
......@@ -229,8 +229,8 @@ TEST(GeoLibAABB, RandomNumberOfPointsRandomBox)
// construct from list points a axis aligned bounding box
GeoLib::AABB aabb(pnts.begin(), pnts.end());
MathLib::Point3d const& min_pnt(aabb.getMinPoint());
MathLib::Point3d const& max_pnt(aabb.getMaxPoint());
auto const& min_pnt(aabb.getMinPoint());
auto const& max_pnt(aabb.getMaxPoint());
ASSERT_LE(minus_half_box_size_x, min_pnt[0])
<< "coordinate 0 of min_pnt is smaller than " << minus_half_box_size_x;
......@@ -265,7 +265,7 @@ TEST(GeoLib, AABBAllPointsWithNegativeCoordinatesI)
ids.push_back(1);
GeoLib::AABB aabb(pnts, ids);
MathLib::Point3d const& max_pnt(aabb.getMaxPoint());
auto const& max_pnt(aabb.getMaxPoint());
ASSERT_NEAR(-1.0, max_pnt[0], std::numeric_limits<double>::epsilon());
ASSERT_NEAR(-1.0, max_pnt[1], std::numeric_limits<double>::epsilon());
......@@ -287,7 +287,7 @@ TEST(GeoLib, AABBAllPointsWithNegativeCoordinatesII)
// construct from points of the vector a axis aligned bounding box
GeoLib::AABB aabb(pnts.begin(), pnts.end());
MathLib::Point3d const& max_pnt(aabb.getMaxPoint());
auto const& max_pnt(aabb.getMaxPoint());
ASSERT_NEAR(-1.0, max_pnt[0], std::numeric_limits<double>::epsilon());
ASSERT_NEAR(-1.0, max_pnt[1], std::numeric_limits<double>::epsilon());
......
......@@ -286,8 +286,8 @@ TEST_F(GeoLibOctTree, TestWithAlternatingPoints3d)
ps_ptr.push_back(new GeoLib::Point(5 * small_displacement, 1, 0, 6));
GeoLib::AABB const aabb(ps_ptr.cbegin(), ps_ptr.cend());
auto const min(convertToEigen(aabb.getMinPoint()));
auto const max(convertToEigen(aabb.getMaxPoint()));
auto const& min(aabb.getMinPoint());
auto const& max(aabb.getMaxPoint());
std::unique_ptr<GeoLib::OctTree<GeoLib::Point, 8>> oct_tree(
GeoLib::OctTree<GeoLib::Point, 8>::createOctTree(min, max, eps));
......@@ -341,8 +341,8 @@ TEST_F(GeoLibOctTree, TestSmallDistanceDifferentLeaves)
// create OctTree
GeoLib::AABB const aabb(ps_ptr.cbegin(), ps_ptr.cend());
auto const min(convertToEigen(aabb.getMinPoint()));
auto const max(convertToEigen(aabb.getMaxPoint()));
auto const& min(aabb.getMinPoint());
auto const& max(aabb.getMaxPoint());
std::unique_ptr<GeoLib::OctTree<GeoLib::Point, 2>> oct_tree(
GeoLib::OctTree<GeoLib::Point, 2>::createOctTree(min, max, eps));
......@@ -373,8 +373,8 @@ TEST_F(GeoLibOctTree, TestOctTreeWithTwoEqualPoints)
double const eps(0.0);
GeoLib::AABB aabb(ps_ptr.begin(), ps_ptr.end());
auto const min(convertToEigen(aabb.getMinPoint()));
auto const max(convertToEigen(aabb.getMaxPoint()));
auto const& min(aabb.getMinPoint());
auto const& max(aabb.getMaxPoint());
std::unique_ptr<GeoLib::OctTree<GeoLib::Point, 2>> oct_tree(
GeoLib::OctTree<GeoLib::Point, 2>::createOctTree(min, max, eps));
......@@ -392,8 +392,8 @@ TEST_F(GeoLibOctTree, TestOctTreeWithTwoEqualPointsOne)
double const eps(0.0);
GeoLib::AABB aabb(ps_ptr.begin(), ps_ptr.end());
auto const min(convertToEigen(aabb.getMinPoint()));
auto const max(convertToEigen(aabb.getMaxPoint()));
auto const& min(aabb.getMinPoint());
auto const& max(aabb.getMaxPoint());
std::unique_ptr<GeoLib::OctTree<GeoLib::Point, 2>> oct_tree(
GeoLib::OctTree<GeoLib::Point, 2>::createOctTree(min, max, eps));
......@@ -411,8 +411,8 @@ TEST_F(GeoLibOctTree, TestOctTreeOnCubicDomain)
double const eps(0.0);
GeoLib::AABB aabb(ps_ptr.begin(), ps_ptr.end());
auto const min(convertToEigen(aabb.getMinPoint()));
auto const max(convertToEigen(aabb.getMaxPoint()));
auto const& min(aabb.getMinPoint());
auto const& max(aabb.getMaxPoint());
std::unique_ptr<GeoLib::OctTree<GeoLib::Point, 2>> oct_tree(
GeoLib::OctTree<GeoLib::Point, 2>::createOctTree(min, max, eps));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment