roi_service_filter_test.cc 4.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/******************************************************************************
 * Copyright 2018 The Apollo Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *****************************************************************************/
16 17
#include "modules/perception/lidar/lib/roi_filter/roi_service_filter/roi_service_filter.h"

18 19
#include <fstream>
#include <sstream>
20 21 22

#include "gtest/gtest.h"

23 24
#include "modules/perception/base/hdmap_struct.h"
#include "modules/perception/common/io/io_util.h"
25
#include "modules/perception/common/perception_gflags.h"
26 27 28 29
#include "modules/perception/lib/config_manager/config_manager.h"
#include "modules/perception/lidar/common/pcl_util.h"
#include "modules/perception/lidar/lib/roi_filter/hdmap_roi_filter/hdmap_roi_filter.h"
#include "modules/perception/lidar/lib/scene_manager/scene_manager.h"
30
#include "modules/perception/map/hdmap/hdmap_input.h"
31 32 33 34 35 36 37 38 39 40 41 42 43 44

namespace apollo {
namespace perception {

namespace lib {
DECLARE_string(config_manager_path);
DECLARE_string(work_root);
}  // namespace lib

namespace lidar {

class LidarLibROIServiceFilterTest : public testing::Test {
 protected:
  void SetUp() {
G
GoLancer 已提交
45 46
    char cyber_path[100] = "CYBER_PATH=";
    putenv(cyber_path);
47
    char module_path[100] = "MODULE_PATH=";
48
    putenv(module_path);
49 50
    FLAGS_work_root = "/apollo/modules/perception/testdata/"
        "lidar/lib/roi_filter/roi_service_filter";
51
    FLAGS_config_manager_path = "./conf";
52
    lib::ConfigManager::Instance()->Reset();
53 54 55 56 57 58 59 60 61 62 63

    map::HDMapInput* hdmap_input =
        lib::Singleton<map::HDMapInput>::get_instance();
    hdmap_input->Reset();
  }

  void TearDown() {}
};

void MockData(LidarFrame* frame) {
  std::string pcd =
64
      "/apollo/modules/perception/testdata/lidar/lib/roi_filter/"
65 66
      "roi_service_filter/data/pcd/1532063882.176900.pcd";
  std::string pose =
67
      "/apollo/modules/perception/testdata/lidar/lib/roi_filter/"
68
      "roi_service_filter/data/pose/1532063882.176900.pose";
69

70 71 72
  // a. load pcd
  frame->cloud = base::PointFCloudPool::Instance().Get();
  EXPECT_TRUE(LoadPCLPCD(pcd, frame->cloud.get()));
73

74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
  // b. load pose
  int idt = 0;
  double timestamp = 0.0;
  EXPECT_TRUE(
      common::ReadPoseFile(pose, &frame->lidar2world_pose, &idt, &timestamp));

  // c.update hdmap struct;
  map::HDMapInput* hdmap_input =
      lib::Singleton<map::HDMapInput>::get_instance();
  base::PointD point;
  point.x = frame->lidar2world_pose.translation()(0);
  point.y = frame->lidar2world_pose.translation()(1);
  point.z = frame->lidar2world_pose.translation()(2);
  frame->hdmap_struct.reset(new base::HdmapStruct);
  CHECK(hdmap_input->GetRoiHDMapStruct(point, 120.0, frame->hdmap_struct));

  // d. trans points
  frame->world_cloud = base::PointDCloudPool::Instance().Get();
92 93
  // auto translation = frame->lidar2world_pose.translation();
  for (size_t i = 0; i < frame->cloud->size(); ++i) {
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
    auto& local_pt = frame->cloud->at(i);
    Eigen::Vector3d trans_pt(local_pt.x, local_pt.y, local_pt.z);
    trans_pt = frame->lidar2world_pose * trans_pt;
    base::PointD world_pt;
    world_pt.x = trans_pt(0);
    world_pt.y = trans_pt(1);
    world_pt.z = trans_pt(2);
    frame->world_cloud->push_back(world_pt);
  }
}

TEST_F(LidarLibROIServiceFilterTest, lidar_lib_roi_service_filter_test) {
  ROIServiceFilter roi_service_filter;
  EXPECT_EQ(roi_service_filter.Name(), "ROIServiceFilter");
  EXPECT_FALSE(roi_service_filter.Init(ROIFilterInitOptions()));

  EXPECT_TRUE(SceneManager::Instance().Init());
  EXPECT_TRUE(roi_service_filter.Init(ROIFilterInitOptions()));
Z
zhuangli1987 已提交
112
  EXPECT_FALSE(roi_service_filter.Filter(ROIFilterOptions(), nullptr));
113 114 115 116 117 118 119
  LidarFrame frame;
  EXPECT_FALSE(roi_service_filter.Filter(ROIFilterOptions(), &frame));
  MockData(&frame);
  EXPECT_FALSE(roi_service_filter.Filter(ROIFilterOptions(), &frame));

  HdmapROIFilter roi_filter;
  CHECK(roi_filter.Init(ROIFilterInitOptions()));
120 121
  // TODO(All): Add back tests when data is ready.
  /*
122 123 124 125 126 127
  CHECK(roi_filter.Filter(ROIFilterOptions(), &frame));

  base::PointIndices filter_indices = frame.roi_indices;

  EXPECT_TRUE(roi_service_filter.Filter(ROIFilterOptions(), &frame));
  EXPECT_EQ(filter_indices.indices.size(), frame.roi_indices.indices.size());
128
  for (size_t i = 0; i < filter_indices.indices.size(); ++i) {
129 130
    EXPECT_EQ(filter_indices.indices[i], frame.roi_indices.indices[i]);
  }
131
  */
132 133 134 135 136
}

}  // namespace lidar
}  // namespace perception
}  // namespace apollo