0

我有一个包含 (x,y,z) 值的向量_pts,即 3D 中的一个点。从 _pts[0] 开始,我想选择那些先前选择的点之间的距离大于sampleRadius的点。

这是我的代码,但显然出了点问题,因为选择了很多点而不是只选择了几个点。谁能看到我做错了什么?可能您需要更多代码来查看可能遗漏的内容,但我也很感激有关如何实现这一点的任何想法。

float distance;
bool distanceIsOk;

//PICK A POINT IN VECTOR _pts
for (int cPIdx = 0; cPIdx < _pts.size(); cPIdx++) {
    distanceIsOk = true;
    //CHECK DISTANCE AGAINST PREVIOUSLY PICKED POINTS
    for (int dPIdx = 0; dPIdx < indeces.size(); dPIdx++) {
        distance = sqrt(
                        (_pts[cPIdx].v[0] - _pts[dPIdx].v[0])*(_pts[cPIdx].v[0] - _pts[dPIdx].v[0]) +
                        (_pts[cPIdx].v[1] - _pts[dPIdx].v[1])*(_pts[cPIdx].v[1] - _pts[dPIdx].v[1]) +
                        (_pts[cPIdx].v[2] - _pts[dPIdx].v[2])*(_pts[cPIdx].v[2] - _pts[dPIdx].v[2])
                        );
        //IF DISTANCE IS <= SUBSAMPLERADIUS FOR AT LEAST ONE PREVIOUSLY SELECTED POINT
        if (distance <= subsampleRadius) {
            //DISCARD THE POINT
            distanceIsOk = false;
            dPIdx += indeces.size();
        }
    }
    //OTHERWISE INCLUDE THAT POINT
    if (distanceIsOk == true) {
        indeces.push_back(cPIdx);
    }
}
4

1 回答 1

0

发现错误。代替

        distance = sqrt(
                        (_pts[cPIdx].v[0] - _pts[dPIdx].v[0])*(_pts[cPIdx].v[0] - _pts[dPIdx].v[0]) +
                        (_pts[cPIdx].v[1] - _pts[dPIdx].v[1])*(_pts[cPIdx].v[1] - _pts[dPIdx].v[1]) +
                        (_pts[cPIdx].v[2] - _pts[dPIdx].v[2])*(_pts[cPIdx].v[2] - _pts[dPIdx].v[2])

它应该是

        distance = sqrt(
                        (_pts[cPIdx].v[0] - _pts[indeces[dPIdx]].v[0])*(_pts[cPIdx].v[0] - _pts[indeces[dPIdx]].v[0]) +
                        (_pts[cPIdx].v[1] - _pts[indeces[dPIdx]].v[1])*(_pts[cPIdx].v[1] - _pts[indeces[dPIdx]].v[1]) +
                        (_pts[cPIdx].v[2] - _pts[indeces[dPIdx]].v[2])*(_pts[cPIdx].v[2] - _pts[indeces[dPIdx]].v[2])
于 2013-03-12T15:11:07.680 回答