使用以下方法读取原始 3d(256x256x256 单元格)纹理(8 位):
f = fopen(file, "rb");
if (f == NULL) return;
int size = width * height * depth;
data = new unsigned char[size*3];
fread(data, 3, size, f);
image = reinterpret_cast<rgb *>(data);
fclose(f);
图像rgba在哪里
typedef unsigned char byte;
typedef struct {
byte r;
byte g;
byte b;
} rgb;
我现在想在某个垂直方向“切片”立方体并显示数据:
glTexImage2D()
捕获这些切片的聪明方法是什么?我试图了解如何使用循环获取数据,但我不确定数据是如何组织的,而且我不认为这个循环是微不足道的。
我能否将数据映射成更简单的格式,以便使用直观的切片语法?
最佳答案
它只是一个 3D 数组。选择两个轴以标准 2D 访问模式扫描并改变第三个轴以更改切片:
for( unsigned int slice = 0; i < numSlices; ++i )
{
for( unsigned int x = 0; x < xSize; ++x )
{
for( unsigned int y = 0; y < ySize; ++y )
{
// XY slice
output[x][y] = array[x][y][slice];
// XZ slice
output[x][y] = array[x][slice][y];
// YZ slice
output[x][y] = array[slice][x][y];
}
}
}
您可以使用 Boost.MultiArray
变得更漂亮.
关于c++ - 读取原始 3D 纹理和切片立方体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7827316/