Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tree 四叉树搜索不会返回到根目录_Tree_This_Quadtree - Fatal编程技术网

Tree 四叉树搜索不会返回到根目录

Tree 四叉树搜索不会返回到根目录,tree,this,quadtree,Tree,This,Quadtree,第一次来这里,希望你们能帮忙 所以我做了一个四叉树函数,给定I=1:4坐标localmaplon[I],localmaplat[I] 它搜索并返回4个四叉树节点,以便我可以看到localmap所在的四叉树 我遇到的问题是,在第一个解决方案之后,它将四叉树节点设置为它搜索的四叉树,而不是根节点: 我的电脑看起来像这样: i: 1 //good. i: 10 //good. i: 11 //good. i: 12 //good. i: 13 //good. index returned: 13 //

第一次来这里,希望你们能帮忙

所以我做了一个四叉树函数,给定I=1:4坐标localmaplon[I],localmaplat[I] 它搜索并返回4个四叉树节点,以便我可以看到localmap所在的四叉树

我遇到的问题是,在第一个解决方案之后,它将四叉树节点设置为它搜索的四叉树,而不是根节点:

我的电脑看起来像这样:

i: 1 //good.
i: 10 //good.
i: 11 //good.
i: 12 //good.
i: 13 //good.
index returned: 13 //good.
index returned: 13 //good.
index returned: 13 //good.
index returned: 13 //good.
index returned: 13 //good.
0 index: 13 //good.
index: 13 <-- returns index 13! //good.
i: 13 <--Starts the next getQuadTree on index 13. Desired effect is 1 like above code.
index returned: 13 //bad
0 index: 13 //bad
index: 13 //bad
i: 13 //bad
index returned: 13 //bad
0 index: 13 //bad
index: 13 //bad
i: 13 //bad
index returned: 13 //bad
0 index: 13 //bad
index: 13 //bad
你们能帮我找出我做错了什么吗! 下面是两个函数。 这是SolveLocalBucket函数:

//Solve for local buckets in a local map using the quadtree    
QuadTree QuadTree::solveLocalBuckets(Robot* Bot) {
float *ptrLat;
float *ptrLon;
ptrLat=&Bot->localmaplat[0];
ptrLon=&Bot->localmaplon[0];

MatrixXf bucketMatrix(1, Bot->localmapsize);
vector <QuadTree> vecQt;
vecQt.push_back(*this);

for (int i=0; i<Tad->localmapsize; i++) {
    vecQt.push_back(vecQt[0].getQuadTree((ptrLat+i), (ptrLon+i)));
    cout << "0 index: " << vecQt[0].index << endl;
    cout << "index: " << vecQt[i+1].index << endl;
}

return vecQt[0];
}
这是getQuadTree函数

//Gets a quadtree given a latitude and longitude from a quadtree.
QuadTree QuadTree::getQuadTree(float* tlat, float* tlon) {

cout << "i: " << this->index << endl;

if (hasChild) {
    if (*tlon >= centerLon) {
        if (*tlat >= centerLat) {
            //Qaudrant 1
            if (NE->hasChild) {
                *this = NE->getQuadTree(tlat, tlon);
            } else {
                cout << "index returned: " << this->index << endl;
                return *NE;
            }
        } else if (*tlat < centerLat) {
            //Qaudrant 4
            if (SE->hasChild) {
                *this = SE->getQuadTree(tlat, tlon);
            } else {
                cout << "index returned: " << this->index << endl;
                return *SE;
            }
        } else {
            ROS_INFO("Robot latitidue data corrupt.");
        }
    } else if (*tlon < centerLon) {
        if (*tlat >= centerLat) {
            //Quadrant 2
            if (NW->hasChild) {
                *this = NW->getQuadTree(tlat, tlon);
            } else {
                cout << "index returned: " << this->index << endl;
                return *NW;
            }
        } else if (*tlat < centerLat) {
            //Quadrant 3
            if (SW->hasChild) {
                *this = SW->getQuadTree(tlat, tlon);
            } else {
                cout << "index returned: " << this->index << endl;
                return *SW;
            }
        } else {
            ROS_INFO("Robot latitidue data corrupt.");
        }

    } else {
        ROS_INFO("Robot longitutde data corrupt.");
    }
}
cout << "index returned: " << this->index << endl;
return *this;
}