2 #include <nav_msgs/OccupancyGrid.h> 7 #include <tuw_multi_robot_msgs/Graph.h> 14 int main(
int argc,
char **argv)
17 ros::init(argc, argv,
"voronoi_graph_node");
65 if (graphCachePath_.back() !=
'/'){
66 graphCachePath_ +=
"/";
70 if (customGraphPath_.back() !=
'/' && customGraphPath_.size() != 0){
71 customGraphPath_ +=
"/";
84 std::vector<signed char> map = _map->data;
86 Eigen::Vector2d origin;
87 origin[0] = _map->info.origin.position.x;
88 origin[1] = _map->info.origin.position.y;
90 size_t new_hash =
getHash(map, origin, _map->info.resolution);
98 ROS_INFO(
"Graph generator: Graph not found! Generating new one!");
103 ROS_INFO(
"Graph generator: Graph loaded from memory");
123 std::vector<signed char> map = _map->data;
128 ROS_INFO(
"Graph generator: Computing distance field ...");
129 origin_[0] = _map->info.origin.position.x;
130 origin_[1] = _map->info.origin.position.y;
133 cv::Mat m(_map->info.height, _map->info.width, CV_8SC1, map.data());
137 ROS_INFO(
"Graph generator: Computing voronoi graph ...");
140 ROS_INFO(
"Graph generator: Generating graph ...");
141 potential.reset(
new float[m.cols * m.rows]);
147 ROS_INFO(
"Graph generator: Created new Graph %lu", _map_hash);
171 tuw_multi_robot_msgs::Graph graph;
172 graph.header.frame_id =
"map";
173 graph.header.seq = 0;
178 graph.origin.position.x =
origin_[0];
179 graph.origin.position.y =
origin_[1];
183 tuw_multi_robot_msgs::Vertex seg;
185 seg.id = (*it).getId();
186 seg.weight = (*it).getLength();
187 seg.width = (*it).getMinPathSpace();
189 std::vector<Eigen::Vector2d> path = (*it).getPath();
191 for (uint32_t i = 0; i < path.size(); i++)
193 geometry_msgs::Point pos;
198 seg.path.push_back(pos);
202 std::vector<uint32_t> predecessors = (*it).getPredecessors();
204 for (uint32_t i = 0; i < predecessors.size(); i++)
206 seg.predecessors.push_back(predecessors[i]);
209 std::vector<uint32_t> successors = (*it).getSuccessors();
211 for (uint32_t i = 0; i < successors.size(); i++)
213 seg.successors.push_back(successors[i]);
216 graph.vertices.push_back(seg);
224 nav_msgs::OccupancyGrid grid;
226 grid.header.frame_id =
"map";
233 grid.info.width = nx;
234 grid.info.height = ny;
238 grid.info.origin.position.x =
origin_[0];
239 grid.info.origin.position.y =
origin_[1];
240 grid.info.origin.position.z = 0.0;
241 grid.info.origin.orientation.w = 1.0;
243 grid.data.resize(nx * ny);
245 for (
unsigned int i = 0; i < grid.data.size(); i++)
247 grid.data[i] = (
map_.data[i]);
void createGraph(const nav_msgs::OccupancyGrid::ConstPtr &_map, size_t _map_hash)
void publish(const boost::shared_ptr< M > &message) const
void globalMapCallback(const nav_msgs::OccupancyGrid::ConstPtr &_map)
bool loadGraph(size_t _hash)
ros::Publisher pubSegments_
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
std::unique_ptr< float[]> potential
static void resetId()
resets the id counter (which is used to generate uinique ids)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
float endSegmentOptimization_
bool load(const std::string &_mapPath, std::vector< Segment > &_segs, Eigen::Vector2d &_origin, float &_resolution)
loads a graph from memory which is saved in plain text
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
std::string topicGlobalMap_
std::string topicVoronoiMap_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
std::string graphCachePath_
std::string topicSegments_
std::vector< Segment > segments_
VoronoiGeneratorNode(ros::NodeHandle &n)
void save(const std::string &_mapPath, const std::vector< Segment > &_segs, const Eigen::Vector2d &_origin, const float &_resolution)
saves the graph to a specific path in xml format
void publishTf(std::string mapName)
std::string customGraphPath_
size_t getHash(const std::vector< signed char > &_map, Eigen::Vector2d _origin, float _resolution)
generate a hash from a _map
float crossingOptimization_
bool loadCustomGraph(std::string _path)
ROSCPP_DECL void spinOnce()
int main(int argc, char **argv)
void computeVoronoiMap(const cv::Mat &_distField, cv::Mat &_voronoiMap)
computes the voronoi _map
void computeDistanceField(const cv::Mat &_map, cv::Mat &_distField)
computes the distance field of a map
std::vector< Segment > calcSegments(cv::Mat &_map, cv::Mat &_distField, cv::Mat &_voronoiPath, float *potential, float _path_length, float _optimizeCrossingPixels, float _optimizeEndSegmentsPixel)
calculates the search graph
void prepareMap(const cv::Mat &_map, cv::Mat &_smoothedMap, int _blurSize)
prepares the map by smoothing it