C++ Boost图形库-将向量推入边属性
我想知道是否可以通过输入值来设置边的属性。下面是一个例子C++ Boost图形库-将向量推入边属性,c++,boost,C++,Boost,我想知道是否可以通过输入值来设置边的属性。下面是一个例子 struct Edge { //boundary length int length = 0; //boundary coordinates vector<cv::Point> boundary; //pointer to heap boost::heap::fibonacci_heap<rnn, boost::heap::compare<compare_nn&
struct Edge {
//boundary length
int length = 0;
//boundary coordinates
vector<cv::Point> boundary;
//pointer to heap
boost::heap::fibonacci_heap<rnn, boost::heap::compare<compare_nn>>::handle_type heap_pointer;
Edge(float length = 0) : length (length ) {}
};
//i'd like to push in point into vector<cv::Point> boundary
boost::put(&Edge::boundary, g, boost::edge(0, 1, g), cv::Point(2,2));
struct-Edge{
//边界长度
整数长度=0;
//边界坐标
矢量边界;
//指向堆的指针
boost::heap::fibonacci\u heap::handle\u类型堆\u指针;
边(浮动长度=0):长度(长度){}
};
//我想把点推入向量边界
boost::put(&Edge::boundary,g,boost::Edge(0,1,g),cv::Point(2,2));
我可以得到向量属性,在我把它放回边缘之前推一个点,但它似乎效率很高。我希望有人能给我一个建议。我不知道我是否正确理解你的问题,但这里似乎有一个有用的简单结构方法:
struct Edge {
// your stuff here
void push(cv::Point& point) {
boundary.push_back(point);
}
};
更简单的是:
auto& boundary = boost::get(&Edge::boundary, g, boost::edge(0, 1, g));
boundary.emplace_back(2,2);
关键是引用向量,而不是复制它
当然,如果您的标准库还不支持emplace\u back
,您可以将其拼写为push\u back(cv::Point(2,2))