40 std::string config_file =
44 range_ = config.
range();
51 const size_t KPolygonMaxNum = 100;
52 polygons_world_.reserve(KPolygonMaxNum);
53 polygons_local_.reserve(KPolygonMaxNum);
56 Eigen::Vector2d min_range(-range_, -range_);
57 Eigen::Vector2d max_range(range_, range_);
58 Eigen::Vector2d cell_size(cell_size_, cell_size_);
59 bitmap_.
Init(min_range, max_range, cell_size);
62 AINFO <<
" HDMap Roi Filter Parameters: "
63 <<
" range: " << range_ <<
" cell_size: " << cell_size_
64 <<
" extend_dist: " << extend_dist_
65 <<
" no_edge_table: " << no_edge_table_
66 <<
" set_roi_service: " << set_roi_service_;
74 AERROR <<
" Input frame data error !";
79 auto& road_polygons = frame->
hdmap_struct->road_polygons;
80 auto& junction_polygons = frame->
hdmap_struct->junction_polygons;
81 size_t polygons_world_size = road_polygons.size() + junction_polygons.size();
82 if (0 == polygons_world_size) {
83 AINFO <<
" Polygon Empty.";
87 polygons_world_.clear();
88 polygons_world_.resize(polygons_world_size,
nullptr);
90 for (
auto& polygon : road_polygons) {
91 polygons_world_[i++] = &polygon;
93 for (
auto& polygon : junction_polygons) {
94 polygons_world_[i++] = &polygon;
100 &polygons_local_, &cloud_local);
102 bool ret = FilterWithPolygonMask(cloud_local, polygons_local_,
108 frame->
cloud->mutable_points_label()->at(index) =
110 frame->
world_cloud->mutable_points_label()->at(index) =
116 if (set_roi_service_) {
118 if (roi_service !=
nullptr) {
119 roi_service_content_.
range_ = range_;
127 std::fill(roi_service_content_.
bitmap_.begin(),
128 roi_service_content_.
bitmap_.end(), -1);
130 roi_service->UpdateServiceContent(roi_service_content_);
132 AINFO <<
"Failed to find roi service and cannot update.";
138bool HdmapROIFilter::FilterWithPolygonMask(
140 const EigenVector<PolygonDType>& map_polygons,
142 std::vector<Polygon<double>> raw_polygons;
144 raw_polygons.resize(map_polygons.size());
145 double min_x = range_;
146 double max_x = -min_x;
147 double min_y = min_x;
148 double max_y = max_x;
150 for (
size_t i = 0; i < map_polygons.size(); ++i) {
151 auto& raw_polygon = raw_polygons[i];
152 const auto& map_polygon = map_polygons[i];
153 raw_polygon.resize(map_polygon.size());
154 for (
size_t j = 0; j < map_polygon.size(); ++j) {
155 raw_polygon[j].x() = map_polygon[j].x;
156 raw_polygon[j].y() = map_polygon[j].y;
157 min_x = std::min(raw_polygon[j].x(), min_x);
158 max_x = std::max(raw_polygon[j].x(), max_x);
159 min_y = std::min(raw_polygon[j].y(), min_y);
160 max_y = std::max(raw_polygon[j].y(), max_y);
163 min_x = std::max(min_x, -range_);
164 max_x = std::min(max_x, range_);
165 min_y = std::max(min_y, -range_);
166 max_y = std::min(max_y, range_);
169 if ((max_y - min_y) < (max_x - min_x)) {
170 major_dir = DirectionMajor::YMAJOR;
172 bitmap_.
SetUp(major_dir);
174 return DrawPolygonsMask<double>(raw_polygons, &bitmap_, extend_dist_,
176 Bitmap2dFilter(cloud, bitmap_, roi_indices);
179void HdmapROIFilter::TransformFrame(
181 const EigenVector<PolygonDType*>& polygons_world,
182 EigenVector<PolygonDType>* polygons_local,
184 Eigen::Vector3d vel_location = vel_pose.translation();
185 Eigen::Matrix3d vel_rot = vel_pose.linear();
186 Eigen::Vector3d x_axis = vel_rot.row(0);
187 Eigen::Vector3d y_axis = vel_rot.row(1);
190 polygons_local->clear();
191 polygons_local->resize(polygons_world.size());
192 for (
size_t i = 0; i < polygons_local->size(); ++i) {
193 const auto& polygon_world = *(polygons_world[i]);
194 auto& polygon_local = (*polygons_local)[i];
195 polygon_local.resize(polygon_world.size());
196 for (
size_t j = 0; j < polygon_local.size(); ++j) {
197 polygon_local[j].x = polygon_world[j].x - vel_location.x();
198 polygon_local[j].y = polygon_world[j].y - vel_location.y();
203 (*cloud_local)->clear();
204 (*cloud_local)->resize(cloud->size());
205 for (
size_t i = 0; i < (*cloud_local)->size(); ++i) {
206 const auto& pt = cloud->at(i);
207 auto& local_pt = (*cloud_local)->at(i);
208 Eigen::Vector3d e_pt(pt.x, pt.y, pt.z);
209 local_pt.x =
static_cast<float>(x_axis.dot(e_pt));
210 local_pt.y =
static_cast<float>(y_axis.dot(e_pt));
215 const Bitmap2D& bitmap,
216 base::PointIndices* roi_indices) {
217 if (!bitmap.Check(Eigen::Vector2d(0.0, 0.0))) {
218 AWARN <<
" Car is not in roi!!.";
221 roi_indices->indices.clear();
222 roi_indices->indices.reserve(in_cloud->size());
223 for (
size_t i = 0; i < in_cloud->size(); ++i) {
224 const auto& pt = in_cloud->at(i);
225 Eigen::Vector2d e_pt(pt.x, pt.y);
226 if (!bitmap.IsExists(e_pt)) {
229 if (bitmap.Check(e_pt)) {
230 roi_indices->indices.push_back(
static_cast<int>(i));
int dir_major() const
Return the dir_major_
void SetUp(const DirectionMajor dir_major)
Set the dir_major_ and op_dir_major_
const std::vector< uint64_t > & bitmap() const
Return the bitmap_
void Init(const Eigen::Vector2d &min_range, const Eigen::Vector2d &max_range, const Eigen::Vector2d &cell_size)
Init of Bitmap 2D object
const Vec2ui & map_size() const
Return the map_size_
bool Filter(const ROIFilterOptions &options, LidarFrame *frame) override
filter point cloud outside of hdmap roi
bool Init(const ROIFilterInitOptions &options) override
Init of Hdmap ROI Filter object
std::vector< Point, Eigen::aligned_allocator< Point > > Polygon
Eigen::Vector3d transform_
DirectionMajor major_dir_
std::vector< uint64_t > bitmap_
SceneServicePtr Service(const std::string &name)
static SceneManager & Instance()
std::vector< EigenType, Eigen::aligned_allocator< EigenType > > EigenVector
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
std::shared_ptr< PointFCloud > PointFCloudPtr
typename PolygonScanCvter< T >::Polygon Polygon
Bitmap2D::DirectionMajor DirectionMajor
std::string GetConfigFile(const std::string &config_path, const std::string &config_file)
std::vector< int > indices
optional double cell_size
optional bool set_roi_service
optional bool no_edge_table
optional double extend_dist
base::PointIndices roi_indices
Eigen::Affine3d lidar2world_pose
std::shared_ptr< base::AttributePointCloud< base::PointD > > world_cloud
std::shared_ptr< base::HdmapStruct > hdmap_struct
std::shared_ptr< base::AttributePointCloud< base::PointF > > cloud