向量中的最大值<向量< Point3f> > [英] Highest values in vector< vector<Point3f> >
问题描述
我知道如何为 int
, float
,<$ c等数据类型找到最大值$ c> double 等。但是在这里,我正在使用 x
, y
, & z
通过使用 Point3f
进行坐标。因此,任何人都可以帮助找到 x
, y
或 z $的最大值c $ c>来自
std :: vector
的 std :: vector
?
I know the how to find the highest values for the data types like int
, float
, double
, etc. But here I am working with x
, y
, & z
coordinates by using Point3f
. So can anybody help to find the highest values of x
, y
or z
from a std::vector
of std::vector
?
std::vector< std::vector<Point3f> > cluster_points;
为简单起见,我只想查找 x <的最大值/ code>轴。
for simplicity lets say I want to find the highest values only for x
axis among all.
推荐答案
我不了解opencv,因此可以使用更简单的解决方案。
I don't know opencv, so can be simpler solutions but...
几个带有几个lambda函数的 std :: for_each()
怎么样?
What about a couple of std::for_each()
with a couple of lambda functions?
std::vector<std::vector<Point3f>> vvp { /* some data */ };
auto mx = vvp[0][0].x;
auto my = vvp[0][0].y;
auto mz = vvp[0][0].z;
std::for_each(vvp.cbegin(), vvp.cend(),
[&](std::vector<Point3f> const & vp)
{ std::for_each(vp.cbegin(), vp.cend(),
[&](Point3f const & p)
{ mx = std::max(mx, p.x);
my = std::max(my, p.y);
mz = std::max(mz, p.z); }); });
如果可以使用C ++ 14,那么带 auto
参数,双 std :: for_each()
部分可以简单地写为
If you can use C++14, so lambda functions with auto
arguments, the double std::for_each()
part can be simply written as
std::for_each(vvp.cbegin(), vvp.cend(), [&](auto const & vp)
{ std::for_each(vp.cbegin(), vp.cend(), [&](auto const & p)
{ mx = std::max(mx, p.x);
my = std::max(my, p.y);
mz = std::max(mz, p.z); }); });
因此无需显式显示 Poinf3f
并可由其他用户使用点3d类型。
so without expliciting Poinf3f
and usable by other point-3d like types.
这篇关于向量中的最大值<向量< Point3f> >的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!