3d - > 1D数组索引 [英] 3d -> 1D array indexing

查看:122
本文介绍了3d - > 1D数组索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++中,一个W * H * D大小的3D数组的索引值是多少?



对于一个特定的i,j,k,这是正确的索引:



i * W * H + j * W + k

解决方案

你写的是等价于这样做的指针运算:

  T x [D] [H] W]。 

x [i] [j] [k]; //指针运算在这里

显然,根据你如何订购 D H W (或 i j k ),计算将不同。


in C++, what is the indexing value for a W * H * D sized 3D array?

for a particular i, j, k is this the correct indexing:

i*W*H+j*W+k

解决方案

What you have written is equivalent to the pointer arithmetic that this would do:

T x[D][H][W];

x[i][j][k];  // Pointer arithmetic done here

Obviously, depending on how you order D, H and W (or i, j, k), the calculation will differ.

这篇关于3d - > 1D数组索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆