38 #ifndef PCL_FILTERS_IMPL_FRUSTUM_CULLING_HPP_
39 #define PCL_FILTERS_IMPL_FRUSTUM_CULLING_HPP_
41 #include <pcl/filters/frustum_culling.h>
45 template <
typename Po
intT>
void
48 bool is_far_plane_infinite = (fp_dist_ == std::numeric_limits<float>::max());
49 if(is_far_plane_infinite) {
50 fp_dist_ = np_dist_ + 1.0f;
60 Eigen::Vector3f view = camera_pose_.block<3, 1> (0, 0);
61 Eigen::Vector3f up = camera_pose_.block<3, 1> (0, 1);
62 Eigen::Vector3f right = camera_pose_.block<3, 1> (0, 2);
63 Eigen::Vector3f T = camera_pose_.block<3, 1> (0, 3);
66 float fov_lower_bound_rad =
static_cast<float>(fov_lower_bound_ *
M_PI / 180);
67 float fov_upper_bound_rad =
static_cast<float>(fov_upper_bound_ *
M_PI / 180);
68 float fov_left_bound_rad =
static_cast<float>(fov_left_bound_ *
M_PI / 180);
69 float fov_right_bound_rad =
static_cast<float>(fov_right_bound_ *
M_PI / 180);
71 float roi_xmax = roi_x_ + (roi_w_ / 2);
72 float roi_xmin = roi_x_ - (roi_w_ / 2);
73 float roi_ymax = roi_y_ + (roi_h_ / 2);
74 float roi_ymin = roi_y_ - (roi_h_ / 2);
76 float np_h_u =
static_cast<float>(2 * std::tan(fov_lower_bound_rad) * np_dist_ * (roi_ymin - 0.5));
77 float np_h_d =
static_cast<float>(2 * std::tan(fov_upper_bound_rad) * np_dist_ * (roi_ymax - 0.5));
78 float np_w_l =
static_cast<float>(2 * std::tan(fov_left_bound_rad) * np_dist_ * (roi_xmin - 0.5));
79 float np_w_r =
static_cast<float>(2 * std::tan(fov_right_bound_rad) * np_dist_ * (roi_xmax - 0.5));
81 float fp_h_u =
static_cast<float>(2 * std::tan(fov_lower_bound_rad) * fp_dist_ * (roi_ymin - 0.5));
82 float fp_h_d =
static_cast<float>(2 * std::tan(fov_upper_bound_rad) * fp_dist_ * (roi_ymax - 0.5));
83 float fp_w_l =
static_cast<float>(2 * std::tan(fov_left_bound_rad) * fp_dist_ * (roi_xmin - 0.5));
84 float fp_w_r =
static_cast<float>(2 * std::tan(fov_right_bound_rad) * fp_dist_ * (roi_xmax - 0.5));
86 Eigen::Vector3f fp_c (T + view * fp_dist_);
87 Eigen::Vector3f fp_tl (fp_c + (up * fp_h_u) - (right * fp_w_l));
88 Eigen::Vector3f fp_tr (fp_c + (up * fp_h_u) + (right * fp_w_r));
89 Eigen::Vector3f fp_bl (fp_c - (up * fp_h_d) - (right * fp_w_l));
90 Eigen::Vector3f fp_br (fp_c - (up * fp_h_d) + (right * fp_w_r));
92 Eigen::Vector3f np_c (T + view * np_dist_);
94 Eigen::Vector3f np_tr (np_c + (up * np_h_u) + (right * np_w_r));
95 Eigen::Vector3f np_bl (np_c - (up * np_h_d) - (right * np_w_l));
96 Eigen::Vector3f np_br (np_c - (up * np_h_d) + (right * np_w_r));
98 pl_f.head<3> () = (fp_bl - fp_br).cross (fp_tr - fp_br);
99 pl_f (3) = -fp_c.dot (pl_f.head<3> ());
101 if(is_far_plane_infinite) {
103 fp_dist_ = std::numeric_limits<float>::max();
106 pl_n.head<3> () = (np_tr - np_br).cross (np_bl - np_br);
107 pl_n (3) = -np_c.dot (pl_n.head<3> ());
109 Eigen::Vector3f a (fp_bl - T);
110 Eigen::Vector3f b (fp_br - T);
111 Eigen::Vector3f c (fp_tr - T);
112 Eigen::Vector3f d (fp_tl - T);
127 pl_r.head<3> () = b.cross (c);
128 pl_l.head<3> () = d.cross (a);
129 pl_t.head<3> () = c.cross (d);
130 pl_b.head<3> () = a.cross (b);
132 pl_r (3) = -T.dot (pl_r.head<3> ());
133 pl_l (3) = -T.dot (pl_l.head<3> ());
134 pl_t (3) = -T.dot (pl_t.head<3> ());
135 pl_b (3) = -T.dot (pl_b.head<3> ());
137 if (extract_removed_indices_)
139 removed_indices_->resize (indices_->size ());
141 indices.resize (indices_->size ());
142 std::size_t indices_ctr = 0;
143 std::size_t removed_ctr = 0;
144 for (std::size_t i = 0; i < indices_->size (); i++)
146 int idx = indices_->at (i);
147 Eigen::Vector4f pt ((*input_)[idx].x,
151 bool is_in_fov = (pt.dot (pl_l) <= 0) &&
152 (pt.dot (pl_r) <= 0) &&
153 (pt.dot (pl_t) <= 0) &&
154 (pt.dot (pl_b) <= 0) &&
155 (pt.dot (pl_f) <= 0) &&
156 (pt.dot (pl_n) <= 0);
157 if (is_in_fov ^ negative_)
159 indices[indices_ctr++] = idx;
161 else if (extract_removed_indices_)
163 (*removed_indices_)[removed_ctr++] = idx;
166 indices.resize (indices_ctr);
167 removed_indices_->resize (removed_ctr);
170 #define PCL_INSTANTIATE_FrustumCulling(T) template class PCL_EXPORTS pcl::FrustumCulling<T>;
void applyFilter(Indices &indices) override
Sample of point indices.
IndicesAllocator<> Indices
Type used for indices in PCL.