C ,如何制作动态3D矩阵
C++, how can I make a dynamic 3D matrix?
in c ,CodeBlocks环境,我声明:
int m[120][120][120];
我知道,从m[0][0][0]
到m[119][119][119]
,我都有变量。
我可以让计算机从位置宣布内存m[45][45][45]
?
我希望我清楚自己:)
如果您只需要45..119,只需使矩阵45在每个维度中较小并转换值
// Very simple example to explain what I meant.
class MyMatrix
{
public:
SetValue(int x, int y, int z, float value) { mMatrix[x-45][y-45][z-45] = value; }
private
float mMatrix[120-45][120-45][120-45];
}
您所说的是基本上是在开始时要保留/分配一些内存,如果以后您需要更多内存,则希望将其扩展。
如果是这种情况,则最好使用std::vector
,然后将45
作为初始容量。通常45
太小,但是如果您想设置它,则可以通过std::vector.reserve(n)
方法进行操作。会这样:
matrix = vector<vector<vector<float> > >();
matrix.reserve(45);
for (int i = 0; i < 45; i++)
{
matrix[i] = vector<vector<float> >()
matrix[i].reserve(45);
for (int j = 0; j < 45; j++)
{
matrix[i][j] = vector<float>();
matrix[i][j].reserve(45);
}
}
您也可以使用 fill 构造函数来实现相同的东西。
相关文章:
- 从 C++ 中的 3D 矩阵中提取 2D 矩阵
- 如何使用OpenCV从已知的3D点云(在没有I的情况下构建)估计新图像I的相机姿态矩阵
- 使用 OpenCV 在 3D 矩阵中导入 2D 矩阵
- 给定的3D旋转矩阵和3D方向矢量发现角差
- C 矩阵乘法 - 从深度图像中恢复3D坐标
- 变换从三焦点张量计算的投影矩阵以估计3D点
- 特征:将矩阵3d旋转转换为四元数
- 如何将3D矩阵存储在文本文件中,以便将其导入MATLAB
- C ,如何制作动态3D矩阵
- 使用 gsl_vector C++中的 3D 矩阵
- openCV 创建不同大小的 3D 矩阵
- c++3D矩阵使用矢量性能较差
- 使用引用C++ 3D 矩阵
- opencv 中从 2D 到 3D 的转换矩阵
- 如何在 3D 矩阵中选择 Inrest 区域
- 如何使用opencv库将3D矩阵的元素归零
- 2D 坐标到 3D 坐标分辨率和相机矩阵
- 无法将一个 3D 矩阵转换为另一个 3D 矩阵
- 使用特征矩阵构建3D结构的最有效选项
- 如何使用c++中的Eigen库创建一个高效的3D矩阵