24 geometry_msgs::Polygon poly;
25 for (
const auto& vertex : polygon)
27 geometry_msgs::Point32 p;
30 poly.points.push_back(p);
33 std::vector<geometry_msgs::Polygon> polygons = { poly };
45 std::vector<geometry_msgs::Polygon> subPolygonsRet;
49 for (
const auto& subPolygon : subPolygons)
51 geometry_msgs::Polygon poly;
52 for (
const auto& vertex : subPolygon)
54 geometry_msgs::Point32 pt;
57 poly.points.push_back(pt);
59 subPolygonsRet.push_back(poly);
62 return subPolygonsRet;
72 bool plan(cpp_uav::Torres16::Request& req, cpp_uav::Torres16::Response& res)
79 geometry_msgs::Point start;
81 std_msgs::Float64 footprintLength, footprintWidth, horizontalOverwrap, verticalOverwrap;
83 polygon = req.polygon;
86 footprintLength = req.footprint_length;
87 footprintWidth = req.footprint_width;
88 horizontalOverwrap = req.horizontal_overwrap;
89 verticalOverwrap = req.vertical_overwrap;
92 bool isOptimal =
computeConvexCoverage(polygon, footprintWidth.data, horizontalOverwrap.data, candidatePath);
94 if (isOptimal ==
true)
108 double pathLengthSum = 0;
112 for (
const auto& polygon : subPolygons)
122 bool existsSecondOptimalPath =
125 if (existsSecondOptimalPath ==
true)
137 res.path = secondOptimalPath;
143 else if(subPolygons.size() == 1)
147 res.path = secondOptimalPath;
152 else if (subPolygons.size() < 2)
156 ROS_ERROR(
"Unable to generate path.");
167 res.path = multipleCoveragePath;
173 int main(
int argc,
char** argv)
175 ros::init(argc, argv,
"torres_etal_2016");
178 ros::ServiceServer planner = nh.advertiseService(
"cpp_torres16",
plan);
179 ROS_INFO(
"Ready to plan.");
bool plan(cpp_uav::Torres16::Request &req, cpp_uav::Torres16::Response &res)
Plans coverage path.
Utility for computational geometry.
bool findSecondOptimalPath(const PointVector &polygon, double footprintWidth, double horizontalOverwrap, PointVector &path)
Find second optimal path.
int main(int argc, char **argv)
PointVector identifyOptimalAlternative(const PointVector &polygon, const PointVector &path, const geometry_msgs::Point &start, const geometry_msgs::Point &end)
Identify optimal path from 4 coverage alternatives.
PointVector computeMultiplePolygonCoverage(std::vector< PointVector > subPolygons, double footprintWidth, double horizontalOverwrap, int adjacencyCriteria=1)
Compute coverage path for multiple convex polygons.
std::vector< geometry_msgs::Polygon > generatePolygonVector(const PointVector &polygon)
Generate vector of polygon from PointVector.
std::vector< geometry_msgs::Point > PointVector
bool computeConvexCoverage(const PointVector &polygon, double footprintWidth, double horizontalOverwrap, const Direction &sweepDirection, PointVector &path)
Compute coverage path for convex polygon.
double calculatePathLength(const PointVector &path)
Calculates length of path.
std::vector< PointVector > decomposePolygon(const PointVector &polygon)
Decompose given polygon.