util.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /******************************************************************************
  2. * Copyright 2017 The Apollo Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *****************************************************************************/
  16. #ifndef MODULES_PERCEPTION_OBSTACLE_LIDAR_SEGMENTATION_CNNSEG_UTIL_H_
  17. #define MODULES_PERCEPTION_OBSTACLE_LIDAR_SEGMENTATION_CNNSEG_UTIL_H_
  18. #include <string>
  19. inline int F2I(float val, float ori, float scale) {
  20. return static_cast<int>(std::floor((ori - val) * scale));
  21. }
  22. inline int Pc2Pixel(float in_pc, float in_range, float out_size) {
  23. float inv_res = 0.5 * out_size / in_range;
  24. return static_cast<int>(std::floor((in_range - in_pc) * inv_res));
  25. }
  26. inline float Pixel2Pc(int in_pixel, float in_size, float out_range) {
  27. float res = 2.0 * out_range / in_size;
  28. return out_range - (static_cast<float>(in_pixel) + 0.5f) * res;
  29. }
  30. #endif // MODULES_PERCEPTION_OBSTACLE_LIDAR_SEGMENTATION_CNNSEG_UTIL_H_