@@ -30,12 +30,6 @@ namespace
3030{
3131static const double EPSILON = 1e-6 ;
3232
33- struct RasterConstructData
34- {
35- std::vector<vtkSmartPointer<vtkPolyData>> raster_segments;
36- std::vector<double > segment_lengths;
37- };
38-
3933Eigen::Matrix3d computeRotation (const Eigen::Vector3d& vx, const Eigen::Vector3d& vy, const Eigen::Vector3d& vz)
4034{
4135 Eigen::Matrix3d m;
@@ -46,154 +40,14 @@ Eigen::Matrix3d computeRotation(const Eigen::Vector3d& vx, const Eigen::Vector3d
4640 return m;
4741}
4842
49- /* *
50- * @brief removes points that appear in multiple lists such that only one instance of that point
51- * index remains
52- * @param points_lists
53- */
54- void removeRedundant (std::vector<std::vector<vtkIdType>>& points_lists)
55- {
56- using IdList = std::vector<vtkIdType>;
57- if (points_lists.size () < 2 )
58- {
59- return ;
60- }
61-
62- std::vector<std::vector<vtkIdType>> new_points_lists;
63- new_points_lists.push_back (points_lists.front ());
64- for (std::size_t i = 1 ; i < points_lists.size (); i++)
65- {
66- IdList& current_list = points_lists[i];
67- IdList new_list;
68- IdList all_ids;
69-
70- // create list of all ids
71- for (auto & ref_list : new_points_lists)
72- {
73- all_ids.insert (all_ids.end (), ref_list.begin (), ref_list.end ());
74- }
75-
76- for (auto & id : current_list)
77- {
78- // add if not found in any of the previous lists
79- if (std::find (all_ids.begin (), all_ids.end (), id) == all_ids.end ())
80- {
81- new_list.push_back (id);
82- }
83- }
84-
85- // add if it has enough points
86- if (new_list.size () > 0 )
87- {
88- new_points_lists.push_back (new_list);
89- }
90- }
91-
92- points_lists.clear ();
93- points_lists.assign (new_points_lists.begin (), new_points_lists.end ());
94- }
95-
96- void mergeRasterSegments (const vtkSmartPointer<vtkPoints>& points,
97- double merge_dist,
98- std::vector<std::vector<vtkIdType>>& points_lists)
99- {
100- using namespace Eigen ;
101- using IdList = std::vector<vtkIdType>;
102- if (points_lists.size () < 2 )
103- {
104- return ;
105- }
106-
107- std::vector<IdList> new_points_lists;
108- IdList merged_list_ids;
109- IdList merged_list;
110-
111- auto do_merge =
112- [&points](const IdList& current_list, const IdList& next_list, double merge_dist, IdList& merged_list) {
113- Vector3d cl_point, nl_point;
114-
115- // checking front and back end points respectively
116- points->GetPoint (current_list.front (), cl_point.data ());
117- points->GetPoint (next_list.back (), nl_point.data ());
118- double d = (cl_point - nl_point).norm ();
119- if (d < merge_dist)
120- {
121- merged_list.assign (next_list.begin (), next_list.end ());
122- merged_list.insert (merged_list.end (), current_list.begin (), current_list.end ());
123- return true ;
124- }
125-
126- // checking back and front end points respectively
127- points->GetPoint (current_list.back (), cl_point.data ());
128- points->GetPoint (next_list.front (), nl_point.data ());
129- d = (cl_point - nl_point).norm ();
130- if (d < merge_dist)
131- {
132- merged_list.assign (current_list.begin (), current_list.end ());
133- merged_list.insert (merged_list.end (), next_list.begin (), next_list.end ());
134- return true ;
135- }
136- return false ;
137- };
138-
139- for (std::size_t i = 0 ; i < points_lists.size (); i++)
140- {
141- if (std::find (merged_list_ids.begin (), merged_list_ids.end (), i) != merged_list_ids.end ())
142- {
143- // already merged
144- continue ;
145- }
146-
147- IdList current_list = points_lists[i];
148- Vector3d cl_point, nl_point;
149- bool seek_adjacent = true ;
150- while (seek_adjacent)
151- {
152- seek_adjacent = false ;
153- for (std::size_t j = i + 1 ; j < points_lists.size (); j++)
154- {
155- if (std::find (merged_list_ids.begin (), merged_list_ids.end (), j) != merged_list_ids.end ())
156- {
157- // already merged
158- continue ;
159- }
160-
161- merged_list.clear ();
162- IdList next_list = points_lists[j];
163- if (do_merge (current_list, next_list, merge_dist, merged_list))
164- {
165- current_list = merged_list;
166- merged_list_ids.push_back (static_cast <vtkIdType>(j));
167- seek_adjacent = true ;
168- continue ;
169- }
170-
171- std::reverse (next_list.begin (), next_list.end ());
172- if (do_merge (current_list, next_list, merge_dist, merged_list))
173- {
174- current_list = merged_list;
175- merged_list_ids.push_back (static_cast <vtkIdType>(j));
176- seek_adjacent = true ;
177- continue ;
178- }
179- }
180- }
181- new_points_lists.push_back (current_list);
182- }
183- points_lists.clear ();
184- std::copy_if (new_points_lists.begin (), new_points_lists.end (), std::back_inserter (points_lists), [](const IdList& l) {
185- return l.size () > 1 ;
186- });
187- }
188-
189- noether::ToolPaths convertToPoses (const std::vector<RasterConstructData>& rasters_data)
43+ noether::ToolPaths convertToPoses (const std::vector<std::vector<vtkSmartPointer<vtkPolyData>>>& rasters_data)
19044{
19145 noether::ToolPaths rasters_array;
192- for (const RasterConstructData & rd : rasters_data)
46+ for (const std::vector<vtkSmartPointer<vtkPolyData>> & rd : rasters_data)
19347 {
19448 noether::ToolPath raster_path;
19549 std::vector<vtkSmartPointer<vtkPolyData>> raster_segments;
196- raster_segments.assign (rd.raster_segments . begin (), rd. raster_segments .end ());
50+ raster_segments.assign (rd.begin (), rd.end ());
19751
19852 for (const vtkSmartPointer<vtkPolyData>& polydata : raster_segments)
19953 {
@@ -383,7 +237,7 @@ ToolPaths PlaneSlicerRasterPlanner::planImpl(const pcl::PolygonMesh& mesh) const
383237
384238 cutter->SetCutFunction (plane);
385239 cutter->SetInputData (mesh_data_);
386- cutter->SetSortBy ( 1 );
240+ cutter->SetSortByToSortByCell ( );
387241 cutter->SetGenerateTriangles (false );
388242 cutter->Update ();
389243
@@ -406,69 +260,15 @@ ToolPaths PlaneSlicerRasterPlanner::planImpl(const pcl::PolygonMesh& mesh) const
406260 // collect rasters and set direction
407261 raster_data->Update ();
408262 vtkIdType num_slices = raster_data->GetTotalNumberOfInputConnections ();
409- std::vector<RasterConstructData> rasters_data_vec;
410- std::vector<std::vector<vtkIdType>> raster_ids;
263+ std::vector<std::vector<vtkSmartPointer<vtkPolyData>>> rasters_data_vec;
411264 for (std::size_t i = 0 ; i < num_slices; i++)
412265 {
413- RasterConstructData r;
414-
415- // collecting raster segments based on min hole size
416266 vtkSmartPointer<vtkPolyData> raster_lines = raster_data->GetInput (i);
417- #if VTK_MAJOR_VERSION > 7
418- const vtkIdType* indices;
419- #else
420- vtkIdType* indices;
421- #endif
422- vtkIdType num_points;
423- vtkIdType num_lines = raster_lines->GetNumberOfLines ();
424- vtkCellArray* cells = raster_lines->GetLines ();
425-
426- if (num_lines == 0 )
427- {
428- continue ;
429- }
430-
431- raster_ids.clear ();
432-
433- unsigned int lineCount = 0 ;
434- for (cells->InitTraversal (); cells->GetNextCell (num_points, indices); lineCount++)
435- {
436- std::vector<vtkIdType> point_ids;
437- for (vtkIdType i = 0 ; i < num_points; i++)
438- {
439- if (std::find (point_ids.begin (), point_ids.end (), indices[i]) != point_ids.end ())
440- {
441- continue ;
442- }
443- point_ids.push_back (indices[i]);
444- }
445- if (point_ids.empty ())
446- {
447- continue ;
448- }
449-
450- // removing duplicates
451- auto iter = std::unique (point_ids.begin (), point_ids.end ());
452- point_ids.erase (iter, point_ids.end ());
453-
454- // adding
455- raster_ids.push_back (point_ids);
456- }
457-
458- if (raster_ids.empty ())
459- {
267+ if (raster_lines->GetNumberOfLines () == 0 )
460268 continue ;
461- }
462-
463- // remove redundant indices
464- removeRedundant (raster_ids);
465-
466- // merging segments
467- mergeRasterSegments (raster_lines->GetPoints (), min_hole_size_, raster_ids);
468269
469270 // Save raster
470- r.raster_segments .push_back (raster_lines);
471- rasters_data_vec.push_back (r);
271+ rasters_data_vec.push_back ({raster_lines});
472272 }
473273
474274 // converting to poses msg now
0 commit comments