The following code is based on this question. The difference is that here I am trying to match a tuple element of double[3] rather than an element of type int. Is there a faster way of getting a specific tuple element in a vector of tuples, where one of its elements (a vector of doubles) matches some other value(s) (another vector of doubles)? In this case the first element of the matching tuple is what I am after. This code is embedded in a loop where it matches ~10k elements and is slow. I have not made use of the fact that there should always be one unique match, which could be used to reduce the number of subsequent searches.
In this question, one answer suggests sorting and then using the binary_search, lower_bound, or upper_bound algorithms speed things up. Would this be possible in this case, where a vector of double[3] would need to be sorted rather than a vector of ints?
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point3;
typedef Kernel::Vector_3 Vector;
typedef std::tuple<int, Point3, Vector> PointVectorTuple;
double eps = 1.0e-6;
double dvec[3];
// Populate points of type PointVectorTuple here
// Specify dvec[3] value here too
auto it = std::find_if(points.begin(), points.end(),
[=](const PointVectorTuple &e) {
return (std::abs(std::get<1>(e)[0] - dvec[0]) < eps and
std::abs(std::get<1>(e)[1] - dvec[0]) < eps and
std::abs(std::get<1>(e)[2] - dvec[0]) < eps);
});
if (it != points.end())
{
int index = get<0>(*it);
}
else
{
std::cout("Not match found!");
}
Aucun commentaire:
Enregistrer un commentaire