[英]How to get max/min element from a boost multiarray
I'm wondering a simple way to find the maximum/minimum element of a boost multiarray, an object of 3 indices as the following:我想知道一个简单的方法来找到一个 boost 多数组的最大/最小元素,一个包含 3 个索引的对象,如下所示:
int iDepth=10,iWidth=10,iHeight=10;
boost::multi_array<GLfloat, 3> image(boost::extents[iDepth][iWidth][iHeight]);
这应该工作:
std::max_element( image.origin(), image.origin() + image.num_elements());
Using member data()
is more correct because:使用成员
data()
更正确,因为:
image
is actually a contiguous (compact array).image
实际上是一个连续的(紧凑数组)。[0][0]...
.[0][0]...
。 ( origin()
means the address of [0][0]...
even if the array "starts" at a different point, eg [1][1]...
. origin()
表示[0][0]...
的地址,即使数组在不同的点“开始”,例如[1][1]...
。std::max_element( image.data(), image.data() + image.num_elements());
你尝试过这样的事情:
std::max_element( image.begin(), image.end());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.