关于vector存储结构体的问题
本帖最后由 闪亮的马路 于 2022-3-24 09:41 编辑结构体定义如下:
struct GridNode
{
int id;
Eigen::Vector3d coord;
Eigen::Vector3i dir; // direction of expanding
Eigen::Vector3i index;
double gScore, fScore;
GridNodePtr cameFrom;
std::multimap<double, GridNodePtr>::iterator nodeMapIt;
GridNode(Eigen::Vector3i _index, Eigen::Vector3d _coord){
id = 0;
index = _index;
coord = _coord;
dir = Eigen::Vector3i::Zero();
gScore = inf;
fScore = inf;
cameFrom = NULL;
}
GridNode(const GridNode& g);
GridNode(){};
~GridNode(){};
};
存储函数部分如下:
inline void AstarPathFinder::AstarGetSucc(GridNodePtr currentPtr, vector<GridNodePtr> & neighborPtrSets, vector<double> & edgeCostSets)
{
neighborPtrSets.clear();
edgeCostSets.clear();
Vector3iinit_index(0,0,0);
Vector3dinit_coord(0,0,0);
GridNodePtrneighborPtrSet = new GridNode(init_index, init_coord);
if (heuristic_type =="Manhattan")
{
//x-1
if(isFree(currentPtr->index-1,currentPtr->index,currentPtr->index) &&
!isOccupied(currentPtr->index-1,currentPtr->index,currentPtr->index))
{
neighborPtrSet->id = 0;
neighborPtrSet->index = currentPtr->index;
neighborPtrSet->index = currentPtr->index-1;
neighborPtrSet->coord = gridIndex2coord( neighborPtrSet->index);
neighborPtrSet->dir = currentPtr->dir;
neighborPtrSets.push_back(neighborPtrSet);
edgeCostSets.push_back(1);
}
//x+1
if(isFree(currentPtr->index+1,currentPtr->index,currentPtr->index) &&
!isOccupied(currentPtr->index+1,currentPtr->index,currentPtr->index))
{
neighborPtrSet->id = 0;
neighborPtrSet->index = currentPtr->index;
neighborPtrSet->index = currentPtr->index+1;
neighborPtrSet->coord = gridIndex2coord( neighborPtrSet->index);
neighborPtrSet->dir = currentPtr->dir;
neighborPtrSets.push_back(neighborPtrSet);
edgeCostSets.push_back(1);
}
仿真发现neighborPtrSets存储的两个结构体共用了一个地址,数据也一样,该怎么修改呢?
页:
[1]