Skip to content

Commit f30d772

Browse files
committed
Add Axis-Aligned Bounding Box option to Plane-Slicer Planner
1 parent 9c97ac4 commit f30d772

File tree

5 files changed

+72
-12
lines changed

5 files changed

+72
-12
lines changed
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
float64 raster_spacing # Offset between two rasters
22
float64 point_spacing # Required spacing between path points
3-
float64 raster_rot_offset # Specifies the direction of the raster path in radians
3+
float64 raster_rot_offset # Specifies the direction of the raster path in radians. Rotates about short dimension of bounding box.
44
float64 min_segment_size # The minimum segment size to allow when finding intersections; small segments will be discarded
55
float64 min_hole_size # A path may pass over holes smaller than this, but must be broken when larger holes are encounterd.
66
float64 tool_offset # How far off the surface the tool needs to be
7+
8+
# When set to TRUE: initial cuts are determined using an axis-aligned bounding box. (global axes)
9+
# When set to FALSE: initial cuts are determined using an object-oriented bounding box and the
10+
# principal axes of the part. (Note that ROS sets message fields to 0/False by default.)
11+
bool raster_wrt_global_axes
12+
13+
# Normal of the cutting planes. Points from the first raster to the second raster, not the
14+
# direction from the first point in one raster to the second point of the same raster. X is the
15+
# longest direction of the bounding box, Z is the shortest, Y is middle, following right hand rule.
16+
# If left as 0 (magnitude < 0.000001), defaults to [0,1,0], the mid direction of the bounding box.
17+
geometry_msgs/Vector3 raster_direction

tool_path_planner/include/tool_path_planner/plane_slicer_raster_generator.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <vtkSmartPointer.h>
2727
#include <vtkPolyData.h>
2828
#include <boost/optional.hpp>
29+
#include <Eigen/Dense>
2930
#include <pcl/PolygonMesh.h>
3031
#include <shape_msgs/Mesh.h>
3132
#include <vtkCellLocator.h>
@@ -45,6 +46,7 @@ class PlaneSlicerRasterGenerator : public PathGenerator
4546
static constexpr double DEFAULT_MIN_SEGMENT_SIZE = 0.01;
4647
static constexpr double DEFAULT_SEARCH_RADIUS = 0.01;
4748
static constexpr double DEFAULT_MIN_HOLE_SIZE = 1e-2;
49+
static constexpr bool DEFAULT_RASTER_WRT_GLOBAL_AXES = false;
4850

4951
public:
5052

@@ -56,6 +58,8 @@ class PlaneSlicerRasterGenerator : public PathGenerator
5658
double min_segment_size {DEFAULT_MIN_SEGMENT_SIZE};
5759
double search_radius {DEFAULT_SEARCH_RADIUS};
5860
double min_hole_size {DEFAULT_MIN_HOLE_SIZE};
61+
bool raster_wrt_global_axes {DEFAULT_RASTER_WRT_GLOBAL_AXES};
62+
Eigen::Vector3d raster_direction {Eigen::Vector3d::UnitY()};
5963

6064
Json::Value toJson() const
6165
{

tool_path_planner/include/tool_path_planner/utilities.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,4 @@ namespace tool_path_planner
124124

125125
}
126126

127-
128-
129127
#endif /* INCLUDE_TOOL_PATH_PLANNER_UTILITIES_H_ */

tool_path_planner/src/plane_slicer_raster_generator.cpp

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,40 @@ boost::optional<ToolPaths> PlaneSlicerRasterGenerator::generate()
458458
{
459459
CONSOLE_BRIDGE_logDebug("%s No mesh data has been provided",getName().c_str());
460460
}
461-
// computing mayor axis using oob
462-
vtkSmartPointer<vtkOBBTree> oob = vtkSmartPointer<vtkOBBTree>::New();
463-
Vector3d corner, x_dir, y_dir, z_dir, sizes;// x is longest, y is mid and z is smallest
464-
oob->ComputeOBB(mesh_data_,corner.data(), x_dir.data(), y_dir.data(), z_dir.data(), sizes.data());
461+
// Assign the longest axis of the bounding box to x, middle to y, and shortest to z.
462+
Vector3d corner, x_dir, y_dir, z_dir, sizes;
463+
if (config_.raster_wrt_global_axes)
464+
{
465+
// Determine extent of mesh along axes of current coordinate frame
466+
VectorXd bounds(6);
467+
std::vector<Vector3d> extents;
468+
mesh_data_->GetBounds(bounds.data());
469+
extents.push_back(Vector3d::UnitX() * (bounds[1] - bounds[0])); // Extent in x-direction of supplied mesh coordinate frame
470+
extents.push_back(Vector3d::UnitY() * (bounds[3] - bounds[2])); // Extent in y-direction of supplied mesh coordinate frame
471+
extents.push_back(Vector3d::UnitZ() * (bounds[5] - bounds[4])); // Extent in z-direction of supplied mesh coordinate frame
472+
473+
// find min and max magnitude.
474+
int max = 0;
475+
int min = 0;
476+
for (std::size_t i = 1; i < extents.size(); ++i)
477+
{
478+
if (extents[max].squaredNorm() < extents[i].squaredNorm())
479+
max = i;
480+
else if (extents[min].squaredNorm() > extents[i].squaredNorm())
481+
min = i;
482+
}
483+
484+
// Assign the axes in order. Computing y saves comparisons and guarantees right-handedness.
485+
x_dir = extents[max].normalized();
486+
z_dir = extents[min].normalized();
487+
y_dir = z_dir.cross(x_dir).normalized();
488+
}
489+
else
490+
{
491+
// computing major axes using oob and assign to x_dir, y_dir, z_dir
492+
vtkSmartPointer<vtkOBBTree> oob = vtkSmartPointer<vtkOBBTree>::New();
493+
oob->ComputeOBB(mesh_data_,corner.data(), x_dir.data(), y_dir.data(), z_dir.data(), sizes.data());
494+
}
465495

466496
// Compute the center of mass
467497
Vector3d origin;
@@ -498,10 +528,11 @@ boost::optional<ToolPaths> PlaneSlicerRasterGenerator::generate()
498528
half_ext = sizes / 2.0;
499529
center = Eigen::Vector3d(bounds[0], bounds[2], bounds[3]) + half_ext;
500530

501-
// now cutting the mesh with planes along the y axis
502-
// @todo This should be calculated instead of being fixed along the y-axis
531+
// Apply the rotation offset about the short direction (new Z axis) of the bounding box
503532
Isometry3d rotation_offset = Isometry3d::Identity() * AngleAxisd(config_.raster_rot_offset, Vector3d::UnitZ());
504-
Vector3d raster_dir = (rotation_offset * Vector3d::UnitY()).normalized();
533+
534+
// Calculate direction of raster strokes, rotated by the above-specified amount
535+
Vector3d raster_dir = (rotation_offset * config_.raster_direction).normalized();
505536

506537
// Calculate all 8 corners projected onto the raster direction vector
507538
Eigen::VectorXd dist(8);

tool_path_planner/src/utilities.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,14 @@ bool toPlaneSlicerConfigMsg(noether_msgs::PlaneSlicerRasterGeneratorConfig &conf
165165
{
166166
config_msg.point_spacing = config.point_spacing;
167167
config_msg.raster_spacing = config.raster_spacing;
168-
// config_msg.tool_offset = config.tool_offset;
169168
config_msg.min_hole_size = config.min_hole_size;
170169
config_msg.min_segment_size = config.min_segment_size;
171170
config_msg.raster_rot_offset = config.raster_rot_offset;
171+
config_msg.raster_wrt_global_axes = config.raster_wrt_global_axes;
172+
173+
config_msg.raster_direction.x = config.raster_direction.x();
174+
config_msg.raster_direction.y = config.raster_direction.y();
175+
config_msg.raster_direction.z = config.raster_direction.z();
172176

173177
return true;
174178
}
@@ -220,10 +224,22 @@ bool toPlaneSlicerConfig(PlaneSlicerRasterGenerator::Config& config,
220224
{
221225
config.point_spacing = config_msg.point_spacing;
222226
config.raster_spacing = config_msg.raster_spacing;
223-
// config.tool_offset = config_msg.tool_offset;
224227
config.min_hole_size = config_msg.min_hole_size;
225228
config.min_segment_size = config_msg.min_segment_size;
226229
config.raster_rot_offset = config_msg.raster_rot_offset;
230+
config.raster_wrt_global_axes = config_msg.raster_wrt_global_axes;
231+
232+
// Check that the raster direction was set; we are not interested in direction [0,0,0]
233+
double norm_squared =
234+
config_msg.raster_direction.x * config_msg.raster_direction.x +
235+
config_msg.raster_direction.y * config_msg.raster_direction.y +
236+
config_msg.raster_direction.z * config_msg.raster_direction.z;
237+
if (norm_squared > 0.000001)
238+
{
239+
config.raster_direction.x() = config_msg.raster_direction.x;
240+
config.raster_direction.y() = config_msg.raster_direction.y;
241+
config.raster_direction.z() = config_msg.raster_direction.z;
242+
}
227243

228244
return true;
229245
}

0 commit comments

Comments
 (0)