与 3D 矢量的'operator ='不匹配

no match for 'operator =' for 3d vector

本文关键字:operator 不匹配 3D      更新时间:2023-10-16

我正在尝试将坐标std::vector surface的向量转换为3D数组,将surface中包含的3D数组的所有条目设置为0;然而,我得到一个不匹配的操作符数组。我查找了几次错误,但没有找到我的案例....

std::vector<coordinates>曲面是全局的。坐标看起来就像

struct coords{
    int xvalue;
    int yvalue;
    int zvalue;
    coords(int x1, int y1, int z1) : xvalue(x1),yvalue(y1),zvalue(z1){}
    ~coords(){}
};
typedef struct coords coordinates;

我的方法是:

(doubleBox是3D双向量的类型定义)

doubleBox levelset::putIntoBox( vector<coordinates> surface){
    int xMaxs, yMaxs,zMaxs;
    for (vector<coordinates>::iterator it = surface.begin() ; it != surface.end(); ++it){
        if (it->xvalue > xMaxs)
            xMaxs = it->xvalue;
        if (it->yvalue > yMaxs)
            yMaxs = it->yvalue;
        if (it->zvalue > zMaxs)
            zMaxs = it->zvalue;
        //check invalid surface
        if (it->xvalue < 0 || it->yvalue <0 || it->zvalue<0)
            cout << "invalid surface with point coordinates below 0 !" << endl;
    }
    doubleBox surfaceBox[xMaxs+1][yMaxs+1][zMaxs+1];
    int max = std::ceil(sqrt(xMaxs*xMaxs + yMaxs*yMaxs + zMaxs*zMaxs));
    std::fill(&surfaceBox[0][0][0],&surfaceBox[0][0][0] + sizeof(surfaceBox)*sizeof(surfaceBox[0])/ sizeof(surfaceBox[0][0]) / sizeof(surfaceBox[0][0]), max);
    for (vector<coordinates>::iterator it = surface.begin() ; it != surface.end(); it++){
        surfaceBox[it->xvalue][it->yvalue][it->zvalue] = 0.0;
    }
    return surfaceBox;
}

输出为(声明错误位于第二个for循环中)

c:mingwlibgccmingw324.8.1includec++bitsvector.tcc:160:5: note: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = std::vector<std::vector<double> >; _Alloc = std::allocator<std::vector<std::vector<double> > >]
     vector<_Tp, _Alloc>::
     ^
c:mingwlibgccmingw324.8.1includec++bitsvector.tcc:160:5: note:   no known conversion for argument 1 from 'const int' to 'const std::vector<std::vector<std::vector<double> > >&'
..srcLevelset.cpp: In member function 'doubleBox levelset::putIntoBox(std::vector<coords>)':
..srcLevelset.cpp:295:1: warning: control reaches end of non-void function [-Wreturn-type]

可能这个问题是由于std::fill使用不当引起的??

既然doubleBox定义为std::vector<std::vector<std::vector<double>,为什么要这样定义doubleBox surfaceBox[xMaxs+1][yMaxs+1][zMaxs+1]; ?

你定义的是一个元素类型为doubleBox的三维数组,这意味着每个元素的类型都是std::vector<std::vector<std::vector<double>,这不是你想要的。

您可能需要doubleBox surfaceBox(xMaxs + 1, std::vector<std::vector<double>>(yMaxs + 1, std::vector<double>(zMaxs + 1)));