contours_imp.hpp
Go to the documentation of this file.
1 #ifndef RAM_PATH_PLANNING_CONTOURS_IMP_HPP
2 #define RAM_PATH_PLANNING_CONTOURS_IMP_HPP
3 
4 namespace ram_path_planning
5 {
6 template<class ActionSpec>
8  DonghongDingBase<ActionSpec>("Contours", "Generate layers contours",
9  "ram/path_planning/generate_trajectory/contours")
10 
11  {
12  this->deposited_material_width_ = 0.002; // 2 millimeters
13  }
14 
15 template<class ActionSpec>
17  const Polygon poly_data,
18  Layer &layer,
19  const double deposited_material_width,
20  const std::array<double, 3> normal_vector,
21  const bool use_gui)
22  {
23  if (!poly_data)
24  return "generateOneLayerTrajectory: polydata is not initialized";
25 
26  if (poly_data->GetNumberOfPoints() == 0)
27  return "generateOneLayerTrajectory: polydata is empty";
28 
29  this->normal_vector_[0] = normal_vector[0];
30  this->normal_vector_[1] = normal_vector[1];
31  this->normal_vector_[2] = normal_vector[2];
32 
33  vtkMath::Normalize(this->normal_vector_);
34 
35  if (normal_vector[0] == 0 && normal_vector[1] == 0 && normal_vector[2] == 0)
36  {
37  this->normal_vector_[0] = 0;
38  this->normal_vector_[1] = 0;
39  this->normal_vector_[2] = 1;
40  }
41 
42  this->deposited_material_width_ = deposited_material_width;
43 
44  if (!this->removeDuplicatePoints(poly_data, this->deposited_material_width_ / 2)) // tolerance default
45  return "Failed to remove duplicate points";
46 
47  if (!this->mergeColinearEdges(poly_data))
48  return "Failed to merge colinear edges";
49 
50  if (this->intersectionBetweenContours(poly_data))
51  return "Contours intersects";
52 
53  std::vector<int> level;
54  std::vector<int> father;
55  this->identifyRelationships(poly_data, level, father);
56 
57  for (auto i : level)
58  if (i != 0)
59  return "Cannot generate a contour in a figure with holes";
60 
61  if (!this->organizePolygonContoursInLayer(poly_data, level, father, layer))
62  return "Failed to organize polygon contours in layer";
63 
64  // Action feedback
65  if (!this->publishStatusDone("Contours are ready to generate the trajectory", gh))
66  return "GoalHandle is not active";
67 
68  for (auto polygons : layer)
69  for (auto polydata : polygons)
70  {
71  if (!this->offsetPolygonContour(polydata, this->deposited_material_width_ / 2.0))
72  return "Error in deposited material width";
73 
74  // Action feedback
75  if (!this->publishStatusDone("Trajectory has been generate", gh))
76  return "GoalHandle is not active";
77  }
78 
79  if (use_gui)
80  {
81  std::string s;
82  ROS_INFO_STREAM("Path generated on one layer");
83  std::getline(std::cin, s);
84  }
85  return "";
86  }
87 
88 template<class ActionSpec>
90  const std::string yaml_file,
91  Layer &layer,
92  const double deposited_material_width,
93  const bool use_gui)
94  {
95  // Prepare contours
96  const Polygon poly_data = Polygon::New();
97  std::vector<unsigned> layer_count;
98  if (!ram_utils::yamlFileToPolydata2(yaml_file, poly_data, layer_count))
99  if (!ram_utils::yamlFileToPolydata(yaml_file, poly_data))
100  return "Could not parse the YAML file";
101 
102  std::array<double, 3> normal_vector = {0, 0, 1};
103  layer.clear();
104  return generateOneLayerTrajectory(gh, poly_data, layer, deposited_material_width, normal_vector, use_gui);
105  }
106 
107 }
108 
109 #endif
void identifyRelationships(const Polygon poly_data, std::vector< int > &level, std::vector< int > &father)
bool mergeColinearEdges(const Polygon poly_data, const double tolerance=1e-6)
bool yamlFileToPolydata(const std::string yaml_file, Polygon poly_data)
XmlRpcServer s
bool publishStatusDone(const std::string progress_msg, actionlib::ServerGoalHandle< ActionSpec > &gh)
std::string generateOneLayerTrajectory(actionlib::ServerGoalHandle< ActionSpec > &gh, const Polygon poly_data, Layer &layer, const double deposited_material_width, const std::array< double, 3 > normal_vector={0, 0, 1}, const bool use_gui=false)
bool organizePolygonContoursInLayer(const Polygon poly_data, const std::vector< int > level, const std::vector< int > father, Layer &layer)
bool removeDuplicatePoints(const Polygon poly_data, const double tolerance=1e-6)
bool yamlFileToPolydata2(const std::string yaml_file, Polygon poly_data, std::vector< unsigned > &layer_count)
vtkSmartPointer< vtkPolyData > Polygon
Definition: contours.hpp:13
#define ROS_INFO_STREAM(args)
bool intersectionBetweenContours(const Polygon poly_data)
bool offsetPolygonContour(const Polygon poly_data, const double deposited_material_width)
bool use_gui
std::vector< PolygonVector > Layer
Definition: contours.hpp:15


ram_path_planning
Author(s): Andres Campos - Institut Maupertuis
autogenerated on Mon Jun 10 2019 14:50:03