29 source_cloud_(source_cloud),
30 target_cloud_(target_cloud),
45 PointCloudRGB::Ptr source_cloud = context<StateMachine>().getSourceCloud();
46 PointCloudRGB::Ptr target_cloud = context<StateMachine>().getTargetCloud();
49 double part_max_size = 4;
52 double floor_height = 0.35;
55 const double INF = std::numeric_limits<double>::infinity();
56 Eigen::Vector3f part_center(INF, INF, INF);
61 double leaf_size_factor = 10;
65 double leaf_size = leaf_size_factor * std::max(target_res, source_res);
67 bool using_cad =
false;
73 PointCloudRGB::Ptr source_cloud_downsampled(
new PointCloudRGB);
74 PointCloudRGB::Ptr target_cloud_downsampled(
new PointCloudRGB);
76 Filter source_cloud_filter(leaf_size, part_max_size, floor_height);
77 if(part_center[0]!=INF && part_center[1]!=INF && part_center[2]!=INF)
78 source_cloud_filter.setCloudCenter(part_center);
79 source_cloud_filter.run(source_cloud, source_cloud_filtered);
80 source_cloud_filter.downsampleCloud(source_cloud_filtered, source_cloud_downsampled);
84 source_cloud_filter.run(target_cloud, target_cloud_filtered);
85 source_cloud_filter.downsampleCloud(target_cloud_filtered, target_cloud_downsampled);
89 Filter target_cloud_filter(leaf_size);
90 target_cloud_filter.run(target_cloud, target_cloud_filtered);
91 target_cloud_filter.downsampleCloud(target_cloud, target_cloud_downsampled);
95 context<StateMachine>().setTargetCloudFiltered(target_cloud_filtered);
96 context<StateMachine>().setSourceCloudFiltered(source_cloud_filtered);
99 post_event(
ValidEvent(source_cloud_downsampled, target_cloud_downsampled));
108 PointCloudRGB::Ptr source_cloud = context<StateMachine>().getSourceCloud();
109 PointCloudRGB::Ptr target_cloud = context<StateMachine>().getTargetCloud();
112 double radius_factor = 1.4;
115 int align_method = 1;
124 initial_alignment.
run();
128 context<StateMachine>().setCloudTransform(initial_alignment.
getRigidTransform());
129 ROS_INFO(
"Transform result from pre-alignment");
142 PointCloudRGB::Ptr source_cloud = context<StateMachine>().getSourceCloud();
143 PointCloudRGB::Ptr target_cloud = context<StateMachine>().getTargetCloud();
146 bool compute_cov =
false;
149 GICPAlignment gicp_alignment(target_cloud, source_cloud, compute_cov);
150 gicp_alignment.
run();
162 Eigen::Matrix4f final_transform = gicp_alignment.
getFineTransform() * context<StateMachine>().getCloudTransform();
164 context<StateMachine>().setCloudTransform(final_transform);
175 PointCloudRGB::Ptr source_cloud = context<StateMachine>().getSourceCloudFiltered();
176 PointCloudRGB::Ptr target_cloud = context<StateMachine>().getTargetCloudFiltered();
180 Eigen::Matrix4f final_transform = context<StateMachine>().getCloudTransform();
182 pcl::transformPointCloud(*source_cloud, *source_cloud, final_transform);
184 double voxelize_factor = 3;
186 ROS_INFO(
"Received from launch voxelize factor: %f", voxelize_factor);
188 double th = 4e-3 * voxelize_factor;
189 Filter::removeFromCloud(source_cloud, target_cloud, th, substracted_cloud);
191 double min_fod_points = 3;
195 std::vector<PointCloudRGB::Ptr> fods_cloud_array;
200 double cluster_tolerance = th * 100;
201 FODDetector fod_detector(substracted_cloud, cluster_tolerance, min_fod_points);
210 ROS_INFO(
"No difference between source and target cloud");
211 substracted_cloud =
nullptr;
212 fods_cloud_array.push_back(substracted_cloud);
214 ROS_INFO(
"Detected %d fods", num_of_fods);
221 sensor_msgs::PointCloud2 target_cloud_msg, source_cloud_msg;
223 PointCloudRGB::Ptr source_cloud = context<StateMachine>().getSourceCloudFiltered();
224 PointCloudRGB::Ptr target_cloud = context<StateMachine>().getTargetCloudFiltered();
231 context<StateMachine>().target_pub_.publish(target_cloud_msg);
232 context<StateMachine>().source_pub_.publish(source_cloud_msg);
235 int n_fods = context<StateMachine>().getNFODs();
238 std_msgs::Int16 n_fods_msg;
241 std::vector<PointCloudRGB::Ptr> fods_cloud_array = context<StateMachine>().getFODCloudArray();
242 for(
int i=0; i<n_fods; i++)
247 *fods_cloud += *fods_cloud_array[i];
249 sensor_msgs::PointCloud2 cloud_msg;
251 context<StateMachine>().fods_pub_.publish(cloud_msg);
253 n_fods_msg.data = n_fods;
254 context<StateMachine>().n_fods_pub_.publish(n_fods_msg);
static void printTransform(const Eigen::Matrix4f &transform)
Print on console transform values with matrix format.
pcl::PointCloud< pcl::PointXYZRGB > PointCloudRGB
static bool isValidTransform(Eigen::Matrix4f transform)
Check whether transform contains valid data and is not NaN.
int fodIndicesToPointCloud(std::vector< PointCloudRGB::Ptr > &cloud_array)
Save each cluster (possible FOD) in a pcl::PointCloudRGB. Give back an array of all generated clouds...
PublishState(my_context ctx)
void run()
Perform GICP alignment.
AlignmentMethod
Define possible Alignment methods.
void getAlignedCloud(PointCloudRGB::Ptr aligned_cloud)
Get the aligned cloud object.
Perform a fine alignment from source to target cloud with Generalized Iterative Closest Point...
ros::Publisher target_pub_
pcl::PointCloud< pcl::PointXYZRGB > PointCloudRGB
AlignState(my_context ctx)
static bool isValidCloud(PointCloudXYZ::Ptr cloud)
Check whether cloud contains data and is not empty.
FODDetectionState(my_context ctx)
GICPState(my_context ctx)
ros::Publisher source_pub_
Eigen::Matrix4f cloud_transform_
void run()
Perform initial alignment.
ROSCPP_DECL bool get(const std::string &key, std::string &s)
Eigen::Matrix4f getRigidTransform()
Get the rigid transform object.
static void cloudToROSMsg(PointCloudRGB::Ptr cloud, sensor_msgs::PointCloud2 &cloud_msg, const std::string &frameid="world")
Convert XYZRGB cloud to PointCloud2.
void clusterPossibleFODs()
Extract cluster indices from input cloud with resolution set. Each cluster is a possible FOD...
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void getAlignedCloud(PointCloudRGB::Ptr aligned_cloud)
Get the aligned cloud object.
static double computeCloudResolution(PointCloudXYZ::Ptr cloud)
Obtain the resolution of the cloud.
ros::Publisher n_fods_pub_
Eigen::Matrix4f getFineTransform()
Get the fine transform object.
void setMethod(AlignmentMethod method)
Set the AlignmentMethod object.
void setRadiusFactor(double align_factor)
Set the Radius Factor object.
StateMachine(PointCloudRGB::Ptr source_cloud, PointCloudRGB::Ptr target_cloud, ros::NodeHandle nh)
FilterState(my_context ctx)