Bläddra i källkod

Merge branch 'jeely_xingyueL' of http://111.33.136.149:3000/adc_pilot/modularization into jeely_xingyueL

sunjiacheng 2 år sedan
förälder
incheckning
29e990d035
100 ändrade filer med 7768 tillägg och 9526 borttagningar
  1. 1 0
      sh/envInstall.sh
  2. 2 1
      src/controller/controller_Geely_xingyueL/controller_Geely_xingyueL.pro
  3. 9 10
      src/controller/controller_Geely_xingyueL/include/car_control.h
  4. 56 0
      src/controller/controller_Geely_xingyueL/include/kx_11_can_frame/asdm_sim_canfd_data_type.h
  5. 22 43
      src/controller/controller_Geely_xingyueL/include/kx_11_can_frame/asdm_sim_canfd_frame.h
  6. 8 0
      src/controller/controller_Geely_xingyueL/include/kx_11_can_frame/can_canfd_common.h
  7. 0 107
      src/controller/controller_Geely_xingyueL/include/kx_11_can_frame/chassis_can1_frame.h
  8. 2 2
      src/controller/controller_Geely_xingyueL/include/socket_can_interface/socket_can_interface.h
  9. 5 2
      src/controller/controller_Geely_xingyueL/include/socket_udp/socket_udp.h
  10. 295 3
      src/controller/controller_Geely_xingyueL/main.cpp
  11. 2 2
      src/decition/common/common/car_status.h
  12. 28 4
      src/decition/decition_brain_sf_Jeely_xingyueL/decition/adc_adapter/jeely_xingyueL_adapter.cpp
  13. 1 1
      src/decition/decition_brain_sf_Jeely_xingyueL/decition/adc_planner/spline_planner.cpp
  14. 1 1
      src/decition/decition_brain_sf_Jeely_xingyueL/decition/adc_tools/transfer.cpp
  15. 1 1
      src/decition/decition_brain_sf_Jeely_xingyueL/decition/brain.cpp
  16. 88 40
      src/decition/decition_brain_sf_Jeely_xingyueL/decition/decide_gps_00.cpp
  17. 2 2
      src/decition/decition_brain_sf_Jeely_xingyueL/decition/decide_gps_00.h
  18. 0 73
      src/detection/detection_lidar_PointPillars_MultiHead/.gitignore
  19. 0 0
      src/detection/detection_lidar_PointPillars_MultiHead/Tracker/Ctracker.cpp
  20. 0 0
      src/detection/detection_lidar_PointPillars_MultiHead/Tracker/Ctracker.h
  21. 0 0
      src/detection/detection_lidar_PointPillars_MultiHead/Tracker/HungarianAlg.cpp
  22. 0 0
      src/detection/detection_lidar_PointPillars_MultiHead/Tracker/HungarianAlg.h
  23. 0 0
      src/detection/detection_lidar_PointPillars_MultiHead/Tracker/Kalman.cpp
  24. 0 0
      src/detection/detection_lidar_PointPillars_MultiHead/Tracker/Kalman.h
  25. 0 0
      src/detection/detection_lidar_PointPillars_MultiHead/Tracker/ShortPathCalculator.h
  26. 0 0
      src/detection/detection_lidar_PointPillars_MultiHead/Tracker/Tracking.hpp
  27. 0 0
      src/detection/detection_lidar_PointPillars_MultiHead/Tracker/defines.h
  28. 0 0
      src/detection/detection_lidar_PointPillars_MultiHead/Tracker/track.cpp
  29. 0 0
      src/detection/detection_lidar_PointPillars_MultiHead/Tracker/track.h
  30. 25 75
      src/detection/detection_lidar_PointPillars_MultiHead/cfgs/cbgs_pp_multihead.yaml
  31. 26 8
      src/detection/detection_lidar_PointPillars_MultiHead/detection_lidar_PointPillars_MultiHead.pro
  32. 461 67
      src/detection/detection_lidar_PointPillars_MultiHead/main.cpp
  33. 36 82
      src/detection/detection_lidar_PointPillars_MultiHead/pointpillars.cc
  34. 1 5
      src/detection/detection_lidar_PointPillars_MultiHead/pointpillars.h
  35. 176 45
      src/detection/detection_lidar_PointPillars_MultiHead/postprocess.cu
  36. 25 0
      src/detection/detection_lidar_PointPillars_MultiHead/roiaware_pool3d.h
  37. 361 0
      src/detection/detection_lidar_PointPillars_MultiHead/roiaware_pool3d_kernel.cu
  38. 0 246
      src/detection/detection_lidar_PointPillars_MultiHead_1025/cfgs/cbgs_pp_multihead.yaml
  39. 0 141
      src/detection/detection_lidar_PointPillars_MultiHead_1025/common.h
  40. 0 181
      src/detection/detection_lidar_PointPillars_MultiHead_1025/detection_lidar_PointPillars_MultiHead.pro
  41. 0 376
      src/detection/detection_lidar_PointPillars_MultiHead_1025/main.cpp
  42. 0 422
      src/detection/detection_lidar_PointPillars_MultiHead_1025/nms.cu
  43. 0 64
      src/detection/detection_lidar_PointPillars_MultiHead_1025/nms.h
  44. 0 507
      src/detection/detection_lidar_PointPillars_MultiHead_1025/pointpillars.cc
  45. 0 287
      src/detection/detection_lidar_PointPillars_MultiHead_1025/pointpillars.h
  46. 0 383
      src/detection/detection_lidar_PointPillars_MultiHead_1025/postprocess.cu
  47. 0 125
      src/detection/detection_lidar_PointPillars_MultiHead_1025/postprocess.h
  48. 0 410
      src/detection/detection_lidar_PointPillars_MultiHead_1025/preprocess.cu
  49. 0 138
      src/detection/detection_lidar_PointPillars_MultiHead_1025/preprocess.h
  50. 0 73
      src/detection/detection_lidar_PointPillars_MultiHead_1025/scatter.cu
  51. 0 77
      src/detection/detection_lidar_PointPillars_MultiHead_1025/scatter.h
  52. 6 3
      src/detection/detection_lidar_ukf_pda/detection_lidar_ukf_pda.pro
  53. 100 0
      src/detection/detection_lidar_ukf_pda/imm_ukf_pda.h
  54. 36 0
      src/detection/detection_yolov4_shigong_monocular/include/Hungarian.h
  55. 90 0
      src/detection/detection_yolov4_shigong_monocular/include/KalmanTracker.h
  56. 54 0
      src/detection/detection_yolov4_shigong_monocular/include/detect_obstacle.h
  57. 82 0
      src/detection/detection_yolov4_shigong_monocular/include/imageBuffer.h
  58. 353 0
      src/detection/detection_yolov4_shigong_monocular/main.cpp
  59. 406 0
      src/detection/detection_yolov4_shigong_monocular/main_multibatch.cpp
  60. 28 0
      src/detection/detection_yolov4_shigong_monocular/proto/obstacles.proto
  61. 1 0
      src/detection/detection_yolov4_shigong_monocular/proto/protomake.sh
  62. 16 0
      src/detection/detection_yolov4_shigong_monocular/proto/rawpic.proto
  63. 398 0
      src/detection/detection_yolov4_shigong_monocular/src/Hungarian.cpp
  64. 101 0
      src/detection/detection_yolov4_shigong_monocular/src/KalmanTracker.cpp
  65. 309 0
      src/detection/detection_yolov4_shigong_monocular/src/detect_obstacle.cpp
  66. 94 0
      src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/include/Utils.h
  67. 503 0
      src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/include/logging.h
  68. 106 0
      src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/include/mish.h
  69. 70 0
      src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/include/trt_utils.h
  70. 167 0
      src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/include/yolo.h
  71. 56 0
      src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/include/yolodetect.h
  72. 126 0
      src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/include/yololayer.h
  73. 270 0
      src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/src/main.cpp
  74. 196 0
      src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/src/mish.cu
  75. 473 0
      src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/src/trt_utils.cpp
  76. 510 0
      src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/src/yolo.cpp
  77. 274 0
      src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/src/yolodetect.cpp
  78. 129 0
      src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/src/yololayer.cpp
  79. 271 0
      src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/src/yololayer.cu
  80. 1 1
      src/driver/driver_lidar_rs16/main.cpp
  81. 67 36
      src/driver/driver_lidar_rs32/driver_lidar_rs32.pro
  82. 1 1
      src/driver/driver_lidar_rs32/lidar_driver_rs32.h
  83. 7 7
      src/fusion/lidar_radar_fusion_cnn/Tracker/Ctracker.cpp
  84. 6 4
      src/fusion/lidar_radar_fusion_cnn/Tracker/defines.h
  85. 1 1
      src/fusion/lidar_radar_fusion_cnn/fusion_probabilities.cpp
  86. 14 14
      src/fusion/lidar_radar_fusion_cnn/main.cpp
  87. 1 1
      src/fusion/lidar_radar_fusion_cnn/perceptionoutput.cpp
  88. 5 5
      src/tool/data_serials/mainwindow.cpp
  89. 402 0
      src/tool/picview/moc_predefs.h
  90. 402 0
      src/tool/view_message/moc_predefs.h
  91. 2 2
      src/ui/ui_ads_hmi/ADCIntelligentVehicle.cpp
  92. 0 2939
      thirdpartylib/FastRTPS/include/fastcdr/Cdr.h
  93. 0 312
      thirdpartylib/FastRTPS/include/fastcdr/FastBuffer.h
  94. 0 1756
      thirdpartylib/FastRTPS/include/fastcdr/FastCdr.h
  95. 0 53
      thirdpartylib/FastRTPS/include/fastcdr/config.h
  96. 0 53
      thirdpartylib/FastRTPS/include/fastcdr/config.h.in
  97. 0 66
      thirdpartylib/FastRTPS/include/fastcdr/eProsima_auto_link.h
  98. 0 85
      thirdpartylib/FastRTPS/include/fastcdr/exceptions/BadParamException.h
  99. 0 98
      thirdpartylib/FastRTPS/include/fastcdr/exceptions/Exception.h
  100. 0 85
      thirdpartylib/FastRTPS/include/fastcdr/exceptions/NotEnoughMemoryException.h

+ 1 - 0
sh/envInstall.sh

@@ -1,3 +1,4 @@
+echo "nvidia" | sudo -S apt update
 echo "nvidia" | sudo -S  apt install -y vim gedit terminator net-tools
 # ADC develop ENV required
 echo "nvidia" | sudo -S apt install patchelf -y

+ 2 - 1
src/controller/controller_Geely_xingyueL/controller_Geely_xingyueL.pro

@@ -39,7 +39,7 @@ HEADERS += \
     include/kx_11_can_frame/asdm_sim_canfd_data_type.h \
     include/kx_11_can_frame/asdm_sim_canfd_frame.h \
     include/kx_11_can_frame/can_canfd_common.h \
-    include/kx_11_can_frame/chassis_can1_frame.h \
+#    include/kx_11_can_frame/chassis_can1_frame.h \
     include/socket_can_interface/socket_can_interface.h \
     include/socket_udp/socket_udp.h \
     include/basic_types.h \
@@ -48,4 +48,5 @@ HEADERS += \
 
 LIBS += $$PWD/lib/libcar_control.a
 
+unix|win32: LIBS += -lglog
 

+ 9 - 10
src/controller/controller_Geely_xingyueL/include/car_control.h

@@ -1,17 +1,9 @@
 #ifndef CAR_CONTROL_H
 #define CAR_CONTROL_H
 
-#include "kx_11_can_frame/chassis_can1_frame.h"
 #include "kx_11_can_frame/asdm_sim_canfd_frame.h"
 #include <thread>
 
-enum class AppCtrlSm   //cxw,20220622
-{
-  kStandby = 0,
-  kStartup = 1,
-  kActive = 2,
-  kShutDown = 3
-};
 
 enum class StsMach
 {
@@ -73,9 +65,9 @@ private:
   void chassis_handshake_off();
   void apa_startup_action();
   void hwa_pre_active();
+  bool is_car_vin_matched();
 private:
-  ChassisCAN1_Process *chassis_obj_ptr_{nullptr};
-  ASDM_Sim_Process *asdm_obj_ptr_{nullptr};
+  std::unique_ptr<ASDM_Sim_Process>  asdm_obj_ptr_{nullptr};
   StsMach sm_{StsMach::kStandby};
   std::unique_ptr<std::thread> thread_sm_task_{nullptr};
   bool is_chassis_handshake_timeout{false};
@@ -90,11 +82,13 @@ private:
   uint16_t timeout_apa_shutdown = 0;
   uint16_t timeout_hwa_startup = 0;
   uint16_t timeout_hwa_shutdown = 0;
+  uint32_t time_vin_check = 0;
   const uint16_t kMaxStartupDlyTime = (3000 / 20); // uinit:ms
   const uint16_t kMaxApaStartupTime = (3000 / 20); // uinit:ms
   const uint16_t kMaxApaShutdownTime = (10000 / 20); // uinit:ms
   const uint16_t kMaxHwaStartupTime = (5000 / 20); // uinit:ms
   const uint16_t kMaxHwaShutdownTime = (10000 / 20); // uinit:ms
+  const uint32_t kMaxVinCheckTime = (5 * 60 * 1000 / 20); // uinit:ms,  5minites
   float32_t kSpeedForCtrlModSwitch = CONVERT_KPH_2_MPS(6);   // the APA longitude speed uppper limit is 10km/h
   const float32_t kSteerDiffMax = 90;
   const float32_t kSteerDiffMin = -90;
@@ -103,6 +97,11 @@ private:
   const float32_t kApaShutDownDecel = -1.28; //uinit: m/s^2, apa max deceleration.
   const float32_t kHwaShutDownDecel = -5; //uinit: m/s^2, hwa shutdown deceleration value.
 
+  const float32_t kApaAccelerationMax = 1.27; //uinit: m/s^2
+  const float32_t kApaAccelerationMin = -1.27; //uinit: m/s^2
+  const float32_t kHwaAccelerationMax = 11; //uinit: m/s^2
+  const float32_t kHwaAccelerationMin = -11; //uinit: m/s^2
+
   // debug parameter:
   bool debug_enable_{false};
   uint16_t print_period_ms_{20};

+ 56 - 0
src/controller/controller_Geely_xingyueL/include/kx_11_can_frame/asdm_sim_canfd_data_type.h

@@ -321,4 +321,60 @@ struct VddmFeedback
   CfmdLgtCtrlMod lgt_ctrl_mod_feedback{CfmdLgtCtrlMod::kNoReq};
 };
 
+
+// Chassis CAN date type 
+enum class SteerStsToParkAssis
+{
+  kNormOper = 0,
+  kAbortBySpdHi = 1,
+  kCtrlDifHi = 2,
+  kCtrlIntErr = 3,
+  kAbortByDrvIntv = 4,
+  kSteerTqHi = 5,
+  kSpare1 = 6,
+  kSpare2 = 7
+};
+
+enum class DrvrWheelHoldSts
+{
+  kNoInfo = 0,
+  kOffDetected = 1,
+  kNotOnOrOffDetected = 2,
+  kOnDetected = 3
+};
+
+struct AccFuncPinionCtrReq
+{
+  float32_t torque_upper_limit{0};
+  float32_t torque_lower_limit{0};
+  float32_t pinion_ang_req_in_deg{0};
+};
+
+struct ChassisCanCtrlReq
+{
+    // input parameters
+  float32_t pas_pinion_ang_req_in_deg{0};
+  bool is_pas_func_active{false};
+  struct AccFuncPinionCtrReq acc_func_pinion_ctrl_req;
+};
+
+
+struct ChassisCanFeedback
+{
+  // output parameters
+  SteerStsToParkAssis steer_sts{SteerStsToParkAssis::kNormOper};
+  DrvrWheelHoldSts driver_wheel_hold_sts{DrvrWheelHoldSts::kNoInfo};
+  bool driver_steering_is_active{false};
+  bool is_steer_servious_sts{false};
+  float32_t cur_pinion_steer_ag1_in_deg{0};
+  
+  bool pinion_steer_ag1_valid{false};
+  float32_t pinion_steerAgSpd1_deg_in_per_sec{0};
+  bool pinion_steer_ag_spd1_valid{false};
+  float32_t steer_wheel_torque{0};
+  bool steer_wheel_torque_valid{false};
+  bool vfc_info_enable{false};
+};
+
+
 #endif

+ 22 - 43
src/controller/controller_Geely_xingyueL/include/kx_11_can_frame/asdm_sim_canfd_frame.h

@@ -18,60 +18,39 @@ public:
   ~ASDM_Sim_Process();
 
 public:
-
-  ReceiveFrameCanfd vddm_fr03_;
-  ReceiveFrameCanfd bcm_fr00_;
-  ReceiveFrameCanfd bcm_fr03_;
-  ReceiveFrameCanfd bcm_fr06_;
+  ChassisCanCtrlReq chassis_can_request;
+  ChassisCanFeedback chassis_can_feedback;
 
   AsdmControlRequest asdm_control_request;
   VddmFeedback vddm_feedback;
 private:
   void receive_process(canfd_frame receive_frame);
-  static void* tx_rx_polling(void* arg);
-  static void* rx_5ms(void* arg);
-  static void* tx_5ms(void* arg);
+  void tx_rx_polling();
+  void rx_2ms();
+  void tx_3ms();
   void set_filters();
-  void vddm_fr03_decode(void);
-  void bcm_fr00_decode(void);
-  void bcm_fr03_decode(void);
-  void bcm_fr06_decode(void);
+  void vddm_fr03_decode();
+  void bcm_fr00_decode();
+  void bcm_fr03_decode();
+  void bcm_fr06_decode();
+  void cem_fr08_decode();
+  void chassis_can_feedback_fr_decode();
 
-  void asdm_sim_fr03_frame_send(void);
-  void asdm_sim_fr02_frame_send(void);
-  void asdm_sim_fr04_frame_send(void);
-  void asdm_sim_fr11_frame_send(void);
-  void asdm_sim_fr30_frame_send(void);
-  void asdm_sim_nm_frame_send(void);
-  void asdm_sim_fr20_frame_send(void);
-  void asdm_sim_fr10_frame_send(void);
-  void asdm_sim_fr13_frame_send(void);
+  void asdm_sim_total_signals_frame_send();
 
 private:
-  SendFrameCanfd asdm_sim_fr02_;
-  SendFrameCanfd asdm_sim_fr03_;
-  SendFrameCanfd asdm_sim_fr04_;
-  SendFrameCanfd asdm_sim_fr11_;
-  SendFrameCanfd asdm_sim_fr30_;
-  SendFrameCanfd asdm_sim_nm_fr_;
-  SendFrameCanfd asdm_sim_fr20_;
-  SendFrameCanfd asdm_sim_fr10_;
-  SendFrameCanfd asdm_sim_fr13_;
+  std::unique_ptr<std::thread> thread_poll_{nullptr};
+  std::unique_ptr<std::thread> thread_rx_5ms_{nullptr};
+  std::unique_ptr<std::thread> thread_tx_5ms_{nullptr};
 
-  pthread_mutex_t mtx_asdm_sim_fr02_;
-  pthread_mutex_t mtx_asdm_sim_fr03_;
-  pthread_mutex_t mtx_asdm_sim_fr04_;
-  pthread_mutex_t mtx_asdm_sim_fr11_;
-  pthread_mutex_t mtx_asdm_sim_fr30_;
-  pthread_mutex_t mtx_asdm_sim_nm_fr_;
-  pthread_mutex_t mtx_asdm_sim_fr20_;
-  pthread_mutex_t mtx_asdm_sim_fr10_;
-  pthread_mutex_t mtx_asdm_sim_fr13_;
+  SendFrameCanfd asdm_sim_total_fr_;
 
-  pthread_mutex_t mtx_vddm_fr03_;
-  pthread_mutex_t mtx_bcm_fr00_;
-  pthread_mutex_t mtx_bcm_fr03_;
-  pthread_mutex_t mtx_bcm_fr06_;
+  ReceiveFrameCanfd vddm_fr03_;
+  ReceiveFrameCanfd bcm_fr00_;
+  ReceiveFrameCanfd bcm_fr03_;
+  ReceiveFrameCanfd bcm_fr06_;
+  ReceiveFrameCanfd cem_fr08_;
+  ReceiveFrameCanfd chassis_feedback_fr_;
 };
 
 #endif

+ 8 - 0
src/controller/controller_Geely_xingyueL/include/kx_11_can_frame/can_canfd_common.h

@@ -2,7 +2,10 @@
 #define CAN_CANFD_COMMON_H
 
 #include <pthread.h>
+#include <thread>
+#include <mutex>
 #include "./include/socket_can_interface/socket_can_interface.h"
+#include "./include/glog_config.h"
 
 
 #define DOMAIN_ECU_PASSWORD "nvidia"
@@ -16,12 +19,14 @@
 #define CONVERT_KPH_2_MPS(kph)  ((float32_t)kph / 3.6)
 #define CONVERT_MPS_2_KPH(ms)   ((float32_t)ms * 3.6)
 
+using mlock = std::unique_lock<std::mutex>;
 
 typedef struct
 {
   /* data */
   can_frame fr{0, 0, 0, 0, 0, {0}};       // can frame 
   bool is_updated{false}; // if receive a new frame , it's updated , so need be processed
+  std::mutex mtx;
 } ReceiveFrame;
 
 typedef struct
@@ -29,6 +34,7 @@ typedef struct
   /* data */
   can_frame fr{0, 0, 0, 0, 0, {0}};       // can frame 
   bool need_send{false};  // if need send can frame to can bus ,set this to true
+  std::mutex mtx;
 } SendFrame;
 
 typedef struct
@@ -36,6 +42,7 @@ typedef struct
   /* data */
   canfd_frame fr{0, 0, 0, 0, 0, {0}};       // can fd frame 
   bool is_updated{false}; // if receive a new frame , it's updated , so need be processed
+  std::mutex mtx;
 } ReceiveFrameCanfd;
 
 typedef struct
@@ -43,6 +50,7 @@ typedef struct
   /* data */
   canfd_frame fr{0, 0, 0, 0, 0, {0}};       // can fd frame 
   bool need_send{false};  // if need send can frame to can bus ,set this to true
+  std::mutex mtx;
 } SendFrameCanfd;
 
 enum class GenQf1

+ 0 - 107
src/controller/controller_Geely_xingyueL/include/kx_11_can_frame/chassis_can1_frame.h

@@ -1,107 +0,0 @@
-#ifndef CHASSIS_CAN1_FRAME_H
-#define CHASSIS_CAN1_FRAME_H
-
-#include "./include/socket_can_interface/socket_can_interface.h"
-#include "can_canfd_common.h"
-
-
-#define CHASSIS_CAN1_BITRATE (500000)
-
-enum class SteerStsToParkAssis
-{
-  kNormOper = 0,
-  kAbortBySpdHi = 1,
-  kCtrlDifHi = 2,
-  kCtrlIntErr = 3,
-  kAbortByDrvIntv = 4,
-  kSteerTqHi = 5,
-  kSpare1 = 6,
-  kSpare2 = 7
-};
-
-enum class DrvrWheelHoldSts
-{
-  kNoInfo = 0,
-  kOffDetected = 1,
-  kNotOnOrOffDetected = 2,
-  kOnDetected = 3
-};
-
-struct AccFuncPinionCtrReq
-{
-  float32_t torque_upper_limit{0};
-  float32_t torque_lower_limit{0};
-  float32_t pinion_ang_req_in_deg{0};
-};
-
-
-
-class ChassisCAN1_Process : public SocketCanInterface
-{
-public:
-  ChassisCAN1_Process();
-  ~ChassisCAN1_Process();
-  void set_filters();
-public:
-  // output parameters
-  SteerStsToParkAssis steer_sts{SteerStsToParkAssis::kNormOper};
-  DrvrWheelHoldSts driver_wheel_hold_sts{DrvrWheelHoldSts::kNoInfo};
-  bool driver_steering_is_active{false};
-  bool is_steer_servious_sts{false};
-  float32_t cur_pinion_steer_ag1_in_deg{0};
-  
-  bool pinion_steer_ag1_valid{false};
-  float32_t pinion_steerAgSpd1_deg_in_per_sec{0};
-  bool pinion_steer_ag_spd1_valid{false};
-  float32_t steer_wheel_torque{0};
-  bool steer_wheel_torque_valid{false};
-  bool vfc_info_enable{false};
-
-  // input parameters
-  float32_t pas_pinion_ang_req_in_deg{0};
-  bool is_pas_func_active{false};
-  struct AccFuncPinionCtrReq acc_func_pinion_ctrl_req;
-
-private:
-  static void* chassis_tx_rx_polling(void* arg);
-  static void* chassis_rx_5ms(void* arg);
-  static void* chassis_tx_15ms(void* arg);
-  static void* chassis_asdm_tx(void* arg);
-  void receive_process(can_frame receive_frame);
-  void pscm_fr03_decode(void);
-  void pscm_fr07_decode(void);
-  void vddm_fr21_decode(void);
-  void pscm_fr01_decode(void);
-  void pscm_fr02_decode(void);
-
-  void pas_fr02_frame_send(void);
-  void pas_fr04_frame_send(void);
-  void pas_nm_frame_send(void);
-  void asdm_fr01_frame_send(void);
-  void asdm_fr03_frame_send(void);
-
-private:
-  ReceiveFrame pscm_chas1_fr03_;
-  ReceiveFrame pscm_chas1_fr07_;
-  ReceiveFrame pscm_chas1_fr01_;
-  ReceiveFrame pscm_chas1_fr02_;
-  ReceiveFrame vddm_chas1_fr21_;
-
-  SendFrame pas_chas1_fr02_;
-  SendFrame pas_chas1_fr04_;
-  SendFrame pas_chas1_nmfr_;
-  SendFrame asdm_chas1_fr01_;
-  SendFrame asdm_chas1_fr03_;
-
-  pthread_mutex_t mtx_pscm_chas1_fr03_;
-  pthread_mutex_t mtx_pscm_chas1_fr07_;
-  pthread_mutex_t mtx_pscm_chas1_fr01_;
-  pthread_mutex_t mtx_pscm_chas1_fr02_;
-  pthread_mutex_t mtx_vddm_chas1_fr21_;
-
-  pthread_mutex_t mtx_pas_chas1_fr02_;
-  pthread_mutex_t mtx_asdm_chas1_fr01_;
-  pthread_mutex_t mtx_asdm_chas1_fr03_;
-};
-
-#endif

+ 2 - 2
src/controller/controller_Geely_xingyueL/include/socket_can_interface/socket_can_interface.h

@@ -42,7 +42,7 @@ public:
     SocketCanInterface() = default;
     ~SocketCanInterface() = default;
 
-    bool Init(const std::string &canDevice, const std::uint32_t &bitRate, const std::string &passWord,  const std::uint32_t &dbitRate = 0); // data bit rate default 0 : mean the can is CAN, set the dbitrate mean CANFD!
+    bool Init(const std::string &canDevice, bool canfd_on);
     bool SetRecvTimeout(const struct timeval &tv) const;
     bool SetCanFiLter(const struct can_filter &filter) const;
     bool SetCanFilters(const std::vector<can_filter> &filters) const;
@@ -66,7 +66,7 @@ public:
     void SetSignedSignalRawData(can_frame &send_can_frame, const SignalAttribute &sig_attr, const int32_t signal_raw);
     void SetSignedSignalRawData(canfd_frame &send_canfd_frame, const SignalAttribute &sig_attr, const int32_t signal_raw);
 
-    void SetUnsignedSignalPhyData(canfd_frame &send_canfd_frame, const SignalAttribute &sig_attr, const float32_t signal_phy);
+    void SetUnsignedSignalPhyData(canfd_frame &send_canfd_frame, const SignalAttribute &sig_attr, const float64_t signal_phy);
     void SetUnsignedSignalPhyData(can_frame &send_can_frame, const SignalAttribute &sig_attr, const float64_t signal_phy);
     void cntr_inc(uint32_t &cntr);
 private:

+ 5 - 2
src/controller/controller_Geely_xingyueL/include/socket_udp/socket_udp.h

@@ -11,6 +11,7 @@
 #include <string.h>
 #include <sys/socket.h>
 #include <unistd.h>
+#include <thread>
 
 // define the socket UDP communication IP and Ports
 #define UDP_SEND_TARGET_IP_STRING "192.168.4.132"
@@ -88,11 +89,13 @@ class RemoteUdpCommunication
 
   private:
   int socket_udp_init();
-  static void* socket_send(void* arg);
-  static void* socket_receive(void* arg);
+  void socket_send();
+  void socket_receive();
   void close_socket_udp();
   void setnonblocking(int sock);
   private:
+  std::unique_ptr<std::thread> thread_socket_send_;
+  std::unique_ptr<std::thread> thread_socket_receive_;
   struct sockaddr_in socksend_addr_;
   struct sockaddr_in sockrcv_addr_;
   int send_fd_ = -1;

+ 295 - 3
src/controller/controller_Geely_xingyueL/main.cpp

@@ -1,3 +1,4 @@
+#if 1
 #include <QCoreApplication>
 
 #include <QTime>
@@ -14,12 +15,23 @@
 #include <fstream>
 #include "include/car_control.h"
 
+
+enum class AppCtrlSm   //cxw,20220622
+{
+  kStandby = 0,
+  kStartup = 1,
+  kActive = 2,
+  kShutDown = 3
+};
+
 CarControl car_control_module;
 AppCtrlSm app_ctrl_car_sm_ = AppCtrlSm::kStandby;
 
 using namespace std;
 
 
+
+
 void * gpadecition;
 
 iv::brain::decition gdecition_def;
@@ -74,7 +86,7 @@ static void ShareChassis(void * pa,iv::chassis  * pchassis)
 
 void executeDecition(const iv::brain::decition decition)
 {
-//    std::cout<<"Command: Acc is "<<decition.accelerator()<<" Angle is "<<decition.wheelangle()<<" DangWei is "<<decition.gear()<<std::endl;
+    std::cout<<"Command: Acc is "<<decition.accelerator()<<" Angle is "<<decition.wheelangle()<<" DangWei is "<<decition.gear()<<std::endl;
 
     GearPrkgAssistReq gearSetVal= GearPrkgAssistReq::kNoRequest;
     double speedSetVal = 0;
@@ -235,6 +247,7 @@ void sendthread()
             communicate_cnt=gCommunctionNum+1;
         }
 
+#if 1
         switch (app_ctrl_car_sm_)
         {
             case AppCtrlSm::kStandby://ctrl_car节点有消息输入,否则退出与汽车的控制
@@ -307,7 +320,7 @@ void sendthread()
                 break;
         }
 
-
+#endif
 
 
 
@@ -315,7 +328,8 @@ void sendthread()
 
 
 //        bool bstatus = car_control_module.is_lat_lgt_ctrl_active();
-
+                    std::cout<<" lat lgt req. status: "<<(int)car_control_module.get_chassis_err_state()
+                            <<"  machine state: "<<(int)car_control_module.get_chassis_statemachine_sts()<< std::endl;
 //        if(bstatus == true)
 //        {
 //            //            std::cout<<"di pan ke kong "<<std::endl;
@@ -329,6 +343,9 @@ void sendthread()
 //        }
 
 
+
+
+#if 0
                        string filename="log.txt";
                        ofstream outfile;
                        outfile.open(filename, ostream::app);
@@ -350,6 +367,278 @@ void sendthread()
 //                              <<"OBS_Distance"<< ","<<obsDistance<< ","                            
                               <<endl;
                        outfile.close();
+#endif
+//        car_control_module.sm_task_20ms();  // 线控状态机函数
+        std::this_thread::sleep_for(std::chrono::milliseconds(20));
+    }
+}
+
+void * gpa;
+
+void recvthread()
+{
+    iv::chassis xchassis;
+    int tmp1[10] = {0,1,2,3,4,5,6,7,8,9};
+    while(1)
+    {
+        gstatus = car_control_module.is_lat_lgt_ctrl_active();
+        ggearSetVal = car_control_module.get_setted_tar_gear();
+        ggearRealVal = car_control_module.get_cur_disp_gear();
+        gchassErr = car_control_module.get_chassis_err_state();
+        gstsMach = car_control_module.get_chassis_statemachine_sts();
+        gspeed = car_control_module.get_current_vehicle_spd_in_ms();
+        gsteerDeg = car_control_module.get_current_steer_ang_in_deg();
+
+        std::cout<<"FeedBack: current_vehicle_spd_in_ms is "<<gspeed<<"err code :"<<(int)gchassErr<<std::endl;
+
+
+        xchassis.set_angle_feedback(gsteerDeg);
+
+        ShareChassis(gpa,&xchassis);
+        std::this_thread::sleep_for(std::chrono::milliseconds(20));
+        /*
+            bool is_lat_lgt_ctrl_active();        // 底盘控制状态反馈, true: 底盘可线控, false: 底盘不可控
+            ChassisErrCode get_chassis_err_state();// 底盘错误状态码
+            StsMach get_chassis_statemachine_sts(); // 内部状态机运行状态
+            float32_t get_current_steer_ang_in_deg();// 当前方向盘实际角度
+            float32_t get_current_vehicle_spd_in_ms();// 当前车辆实际车速,单位m/s
+            GearPrkgAssistReq get_setted_tar_gear(); // 获取当前设定目标档位值
+            GearLevelIndicate get_cur_disp_gear(); // 当前实际显示档位状态
+        */
+    }
+}
+
+int main(int argc, char *argv[])
+{
+    auto ret = google_glog_config("/home/nvidia/log1/.");
+
+    RegisterIVBackTrace();
+    showversion("controller_Geely_xingyueL");
+    QCoreApplication a(argc, argv);
+
+    QString strpath = QCoreApplication::applicationDirPath();
+
+    if(argc < 2)
+        strpath = strpath + "/controller_Geely_xingyueL.xml";
+    else
+        strpath = argv[1];
+    std::cout<<strpath.toStdString()<<std::endl;
+
+    //    car_control_module.set_lat_lgt_ctrl_req(true);
+    //    car_control_module.sm_task_20ms();  // 线控状态机函数
+
+    //car_control_module.set_target_gear(GearPrkgAssistReq::kTargetGearP);
+
+    iv::xmlparam::Xmlparam xp(strpath.toStdString());
+    std::string gstrmemdecition = xp.GetParam("dection","deciton");
+    std::string strchassismsgname = xp.GetParam("chassismsgname","chassis");
+
+    gpa = iv::modulecomm::RegisterSend(strchassismsgname.data(),1000,1);
+    gpadecition = iv::modulecomm::RegisterRecv(gstrmemdecition.data(),ListenDeciton);
+
+    std::thread xthread(sendthread);
+//    std::thread myxthread(recvthread);
+
+    return a.exec();
+}
+
+#else
+
+#include <QCoreApplication>
+
+#include <QTime>
+#include <QMutex>
+#include <QTimer>
+#include "xmlparam.h"
+#include "modulecomm.h"
+#include "ivbacktrace.h"
+#include "ivversion.h"
+#include "decition.pb.h"
+#include "chassis.pb.h"
+#include <thread>
+#include "include/car_control.h"
+
+CarControl car_control_module;
+
+void * gpadecition;
+
+iv::brain::decition gdecition_def;
+iv::brain::decition gdecition;
+
+int gnDecitionNum = 0; //when is zero,send default;
+const int gnDecitionNumMax = 100;
+
+static QMutex gMutex;
+
+bool gstatus;
+GearPrkgAssistReq ggearSetVal;
+GearLevelIndicate ggearRealVal;
+ChassisErrCode gchassErr;
+StsMach gstsMach;
+float gsteerDeg, gspeed;
+double lastspeedSetVal = 0;
+double lastEpsSetVal = 0;
+
+GearPrkgAssistReq lastgearSetVal= GearPrkgAssistReq::kNoRequest;
+
+static void ShareChassis(void * pa,iv::chassis  * pchassis)
+{
+    char * str;
+    int ndatasize = pchassis->ByteSize();
+    str = new char[ndatasize];
+    std::shared_ptr<char> pstr;
+    pstr.reset(str);
+    if(!pchassis->SerializeToArray(str,ndatasize))
+    {
+        std::cout<<"ShareChassis Error."<<std::endl;
+        return;
+    }
+    iv::modulecomm::ModuleSendMsg(pa,str,ndatasize);
+
+}
+
+void executeDecition(const iv::brain::decition decition)
+{
+    std::cout<<"Command: Acc is "<<decition.accelerator()<<" Angle is "<<decition.wheelangle()<<" DangWei is "<<decition.gear()<<std::endl;
+
+    GearPrkgAssistReq gearSetVal= GearPrkgAssistReq::kNoRequest;
+    double speedSetVal = 0;
+    double EpsSetVal = 0;
+
+    if(decition.has_gear()){
+        switch (decition.gear()) {
+        case 1:
+            //car_control_module.set_target_gear(GearPrkgAssistReq::kTargetGearP);
+            gearSetVal=GearPrkgAssistReq::kTargetGearP;
+            break;
+        case 2:
+            //car_control_module.set_target_gear(GearPrkgAssistReq::kTargetGearR);
+            gearSetVal=GearPrkgAssistReq::kTargetGearR;
+            break;
+        case 3:
+            //car_control_module.set_target_gear(GearPrkgAssistReq::kTargetGearD);
+            gearSetVal=GearPrkgAssistReq::kTargetGearD;
+            break;
+        default:
+            //car_control_module.set_target_gear(GearPrkgAssistReq::kNoRequest);
+            gearSetVal=GearPrkgAssistReq::kNoRequest;;
+            break;
+        }
+        lastgearSetVal=gearSetVal;
+    }
+    else
+    {
+        gearSetVal=lastgearSetVal;
+    }
+
+    if(decition.has_accelerator()){
+        speedSetVal=decition.accelerator();
+        lastspeedSetVal=speedSetVal;
+        //speedSetVal=0.1;
+       // car_control_module.set_target_acc_mps2(decition.accelerator());
+//        car_control_module.set_target_acc_mps2(0.1);
+    }
+    else
+    {
+        speedSetVal=lastspeedSetVal;
+    }
+
+    if(decition.has_wheelangle())
+    {
+       // car_control_module.set_target_pinion_ag_in_deg(0.0);
+        EpsSetVal=decition.wheelangle();
+        lastEpsSetVal=EpsSetVal;
+       // EpsSetVal=0.0;//
+  // car_control_module.set_target_pinion_ag_in_deg(decition.wheelangle());
+    }
+    else
+    {
+        EpsSetVal=lastEpsSetVal;
+    }
+    // gearSetVal=GearPrkgAssistReq::kTargetGearD;
+    car_control_module.set_target_gear(gearSetVal);
+    car_control_module.set_target_acc_mps2(speedSetVal);
+    car_control_module.set_target_pinion_ag_in_deg(EpsSetVal);
+
+    if(decition.has_leftlamp() && decition.leftlamp()==true)
+        car_control_module.set_turn_light_status(TurnLightIndicReq::kLeft);
+    else if(decition.has_rightlamp() && decition.rightlamp()==true)
+        car_control_module.set_turn_light_status(TurnLightIndicReq::kRight);
+    else
+        car_control_module.set_turn_light_status(TurnLightIndicReq::kOff);
+
+    /*
+    void set_lat_lgt_ctrl_req(bool req);  // 握手请求, true:请求握手, false:退出握手
+    void set_target_gear(GearPrkgAssistReq tar);  // 目标档位请求
+    bool is_lat_lgt_ctrl_active();        // 底盘控制状态反馈, true: 底盘可线控, false: 底盘不可控
+    void set_target_pinion_ag_in_deg(float32_t ang_req);// 设置目标方向盘角度请求, -450°至+450°(车辆实测范围值),方向盘左正,右负。
+    void set_target_acc_mps2(float32_t tar_acc);// 目标加减速度值。
+    void set_turn_light_status(TurnLightIndicReq req);// 转向灯控制请求
+*/
+}
+
+
+
+
+void ListenDeciton(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
+{
+    qint64 oldtime;
+    iv::brain::decition xdecition;
+
+    if(!xdecition.ParseFromArray(strdata,nSize))
+    {
+        std::cout<<"ListenDecition parse error."<<std::endl;
+        return;
+    }
+
+    if(xdecition.gear() != 3)
+    {
+        qDebug("not D");
+    }
+    if((oldtime - QDateTime::currentMSecsSinceEpoch())<-100)
+        // qDebug("dection time is %ld diff is %ld ",QDateTime::currentMSecsSinceEpoch(),oldtime - QDateTime::currentMSecsSinceEpoch());
+        oldtime = QDateTime::currentMSecsSinceEpoch();
+    gMutex.lock();
+    gdecition.CopyFrom(xdecition);
+    gMutex.unlock();
+    gnDecitionNum = gnDecitionNumMax;
+    std::cout<<"update decision. "<<std::endl;
+}
+
+
+void sendthread()
+{
+    iv::brain::decition xdecition;
+//    car_control_module.set_target_gear(GearPrkgAssistReq::kTargetGearD);
+//    car_control_module.sm_task_20ms();  // 线控状态机函数
+
+    while(1)
+    {
+        if(gnDecitionNum <= 0)
+        {
+            xdecition.CopyFrom(gdecition_def);
+        }
+        else
+        {
+            gMutex.lock();
+            xdecition.CopyFrom(gdecition);
+            gMutex.unlock();
+            gnDecitionNum--;
+        }
+
+        bool bstatus = car_control_module.is_lat_lgt_ctrl_active();
+
+        if(bstatus == true)
+        {
+            //            std::cout<<"di pan ke kong "<<std::endl;
+            executeDecition(xdecition);
+        }
+        else
+        {
+            std::cout<<" lat lgt req. status: "<<(int)car_control_module.get_chassis_err_state()
+                    <<"  machine state: "<<(int)car_control_module.get_chassis_statemachine_sts()<< std::endl;
+            car_control_module.set_lat_lgt_ctrl_req(true);
+        }
 
 //        car_control_module.sm_task_20ms();  // 线控状态机函数
         std::this_thread::sleep_for(std::chrono::milliseconds(20));
@@ -393,6 +682,7 @@ void recvthread()
 
 int main(int argc, char *argv[])
 {
+    auto ret = google_glog_config("/home/nvidia/log1/.");
     RegisterIVBackTrace();
     showversion("controller_Geely_xingyueL");
     QCoreApplication a(argc, argv);
@@ -422,3 +712,5 @@ int main(int argc, char *argv[])
 
     return a.exec();
 }
+
+#endif

+ 2 - 2
src/decition/common/common/car_status.h

@@ -163,8 +163,8 @@ namespace iv {
         iv::roadmode_vel mroadmode_vel;
         int vehGroupId;
         double mfEPSOff = 0.0;
-        float socfDis=15;   //停障触发距离
-        float aocfDis=25;   //避障触发距离//20
+        float socfDis=10;   //停障触发距离
+        float aocfDis=42;   //避障触发距离//20
         float aocfTimes=3; //避障触发次数
         float aobzDis=5;   //避障保障距离
         /// traffice light : 0x90

+ 28 - 4
src/decition/decition_brain_sf_Jeely_xingyueL/decition/adc_adapter/jeely_xingyueL_adapter.cpp

@@ -84,23 +84,47 @@ iv::decition::Decition iv::decition::Jeely_xingyueL_adapter::getAdapterDeciton(G
     }
 
     //0227 10m nei xianzhi shache
-    if(obsDistance<10 &&obsDistance>0){
-        controlSpeed=min(controlSpeed,-0.8f);
+    if(obsDistance<5 &&obsDistance>0){
+        controlSpeed=min(controlSpeed,-0.9f);
+      //  controlSpeed=max(controlSpeed,-0.4f);
     }
+//    if(controlSpeed<-0.2)//debug ,lianxu,zhangaiwu buwen
+//    {
+//        controlSpeed=-0.1;
+//    }
 
 
     if(DecideGps00::minDecelerate<0){
-        controlSpeed = min(DecideGps00::minDecelerate, controlSpeed);
+        controlSpeed = min(DecideGps00::minDecelerate, controlSpeed);//-1 from here apollo_fu 20220704
     }
+
+
+//        if(controlSpeed<-0.5)//debug,zhandianqiting
+//        {
+//            controlSpeed=-0.5;
+//        }
+
     controlSpeed = limitSpeed(realSpeed, controlBrake, dSpeed, controlSpeed);
 
+
+
     if(realSpeed<6.0)//xw
     {
-        controlSpeed=min(controlSpeed,0.1f);
+//        if(controlSpeed>0.0)
+//        {
+//            controlSpeed=0.5;
+
+//        }
+//        else
+//        {
+//           controlSpeed=max(controlSpeed,-0.5f);
+//        }
+        controlSpeed=min(controlSpeed,0.5f);
     }
 
     //controlSpeed=0.1;
 
+      (*decition)->mode=1;
     (*decition)->accelerator=controlSpeed;
 
     if((*decition)->leftlamp){

+ 1 - 1
src/decition/decition_brain_sf_Jeely_xingyueL/decition/adc_planner/spline_planner.cpp

@@ -36,7 +36,7 @@ std::vector<iv::Point2D> iv::decition::SplinePlanner::chooseRoadBySpline(GPS_INS
         if(fabs(obsSpline[j].d - nowX)<= 1.0e-6){
                     s_obs_current_relative=obsSpline[j].s;
                     if(s_obs_current_relative>40)
-                        s_obs_current_relative=40;
+                        s_obs_current_relative=40;//40gaicheng20
         }
     }
     iv::Point2D now_s_d=cartesian_to_frenet1D(gpsMapLine,now_gps_ins.gps_x, now_gps_ins.gps_y);

+ 1 - 1
src/decition/decition_brain_sf_Jeely_xingyueL/decition/adc_tools/transfer.cpp

@@ -228,7 +228,7 @@ iv::Point2D iv::decition::frenet_to_cartesian1D(std::vector<GPSData> gpsMap,doub
     int s_index=(int)(s_condition-(*gpsMap[index]).frenet_s)*10+index;
     int start_index=max(0,s_index-500);
     int map_size=gpsMap.size();
-    int end_index=min(s_index+500,map_size);
+    int end_index=min(s_index+500,map_size-1);
 
     int map_max=(*gpsMap[map_size-1]).frenet_s;
     double s_index_min=(*gpsMap[start_index]).frenet_s;

+ 1 - 1
src/decition/decition_brain_sf_Jeely_xingyueL/decition/brain.cpp

@@ -1558,7 +1558,7 @@ void iv::decition::BrainDecition::UpdateFusion(std::shared_ptr<iv::fusion::fusio
                 fusion_ptr_[dx*(iv::gry) + dy].type = xobs.type();
                 fusion_ptr_[dx*(iv::gry) + dy].high = xobs.dimensions().z();
                 fusion_ptr_[dx*(iv::gry) + dy].speed_x = xobs.vel_relative().x();
-                fusion_ptr_[dx*(iv::gry) + dy].speed_y = xobs.vel_relative().y();
+                fusion_ptr_[dx*(iv::gry) + dy].speed_y = xobs.velocity_linear_x();
                 fusion_ptr_[dx*(iv::gry) + dy].yaw = xobs.yaw();
                 fusion_ptr_[dx*(iv::gry) + dy].pointcount = 5;
                 fusion_ptr_[dx*(iv::gry) + dy].ob = 2;

+ 88 - 40
src/decition/decition_brain_sf_Jeely_xingyueL/decition/decide_gps_00.cpp

@@ -1170,7 +1170,7 @@ iv::decition::Decition iv::decition::DecideGps00::getDecideFromGPS(GPS_INS now_g
         if((now_s_d.s+20>(gpsTraceAvoidXY[gpsTraceAvoidXY.size()-1].s))&&((gpsTraceAvoidXY[gpsTraceAvoidXY.size()-1].s)<((*gpsMapLine[gpsMapLine.size()-1]).frenet_s))){
             double sPathFinal=gpsTraceAvoidXY[gpsTraceAvoidXY.size()-1].s;
             if(sPathFinal+20<=(*gpsMapLine[gpsMapLine.size()-1]).frenet_s){
-                sPathFinal=sPathFinal+20;
+                sPathFinal=sPathFinal+20;//20gaicheng 6
             }else{
                 sPathFinal=(*gpsMapLine[gpsMapLine.size()-1]).frenet_s;
             }
@@ -1183,13 +1183,13 @@ iv::decition::Decition iv::decition::DecideGps00::getDecideFromGPS(GPS_INS now_g
 
     if((vehState == avoiding || vehState == backOri)&&(gpsTraceAvoidXY.size()>0)&&(obstacle_avoid_flag==1))
     {
+       // gpsTraceOri.clear();//20220811,cxw,add
         gpsTraceOri=getGpsTraceAvoid(now_gps_ins, gpsTraceAvoidXY, lastGpsIndex,circleMode);
     }
 
     if(gpsTraceOri.empty()){
         gps_decition->wheel_angle = 0;
         gps_decition->speed = dSpeed;
-
         gps_decition->accelerator = -0.5;
         gps_decition->brake=10;
         return gps_decition;
@@ -1347,18 +1347,18 @@ iv::decition::Decition iv::decition::DecideGps00::getDecideFromGPS(GPS_INS now_g
     }
 
     //2020-0106
-    if(ServiceCarStatus.msysparam.mvehtype !="zhongche"){
+//    if(ServiceCarStatus.msysparam.mvehtype !="zhongche"){
 
-        if(vehState==avoiding){
-            ServiceCarStatus.msysparam.vehWidth=2.4;
-            controlAng=max(-150.0,controlAng);//35  zj-150
-            controlAng=min(150.0,controlAng);//35   zj-150
-        }
-        if(vehState==backOri){
-            controlAng=max(-150.0,controlAng);//35   zj-150
-            controlAng=min(150.0,controlAng);//35     zj-150
-        }
-    }
+//        if(vehState==avoiding){
+//            ServiceCarStatus.msysparam.vehWidth=2.4;
+//            controlAng=max(-150.0,controlAng);//35  zj-150
+//            controlAng=min(150.0,controlAng);//35   zj-150
+//        }
+//        if(vehState==backOri){
+//            controlAng=max(-150.0,controlAng);//35   zj-150
+//            controlAng=min(150.0,controlAng);//35     zj-150
+//        }
+//    }
 
 //    givlog->debug("brain_decition","vehState: %d,controlAng: %f",
 //            vehState,controlAng);
@@ -1599,7 +1599,7 @@ iv::decition::Decition iv::decition::DecideGps00::getDecideFromGPS(GPS_INS now_g
     static double obs_speed_for_avoid=-1,obs_filter_speed_memory=0;   //obs_speed_for_avoid: obstacle actual speed in km/h
     if(!ServiceCarStatus.daocheMode){
         //computeObsOnRoad(lidarGridPtr, gpsTraceNow, roadNow,gpsMapLine,lidar_per);
-        computeObsOnRoadXY(lidarGridPtr, gpsTraceNow,gpsTraceNowLeft,gpsTraceNowRight,roadNow,gpsMapLine,lidar_per);
+        computeObsOnRoadXY(now_gps_ins,lidarGridPtr, gpsTraceNow,gpsTraceNowLeft,gpsTraceNowRight,roadNow,gpsMapLine,lidar_per);
 
 
         if(obs_filter_flag==0)
@@ -1647,6 +1647,8 @@ iv::decition::Decition iv::decition::DecideGps00::getDecideFromGPS(GPS_INS now_g
 
 
         obs_speed_for_avoid=(secSpeed+obsSpeed)*3.6;
+//        obsSpeed=0-secSpeed;
+//        obs_speed_for_avoid=0;
 
 
     }else{
@@ -1714,7 +1716,7 @@ iv::decition::Decition iv::decition::DecideGps00::getDecideFromGPS(GPS_INS now_g
 //            gps_decition->rightlamp = false;
 //        }
 
-        dSpeed = min(6.0,dSpeed);
+        dSpeed = min(10.0,dSpeed); //6gaicheng 10,20220818
         if (turnLampFlag>0)
         {
             gps_decition->leftlamp = false;
@@ -1876,7 +1878,7 @@ iv::decition::Decition iv::decition::DecideGps00::getDecideFromGPS(GPS_INS now_g
     if(PathPoint+400<gpsMapLine.size()){
         int road_permit_sum=0;
         for(int k=PathPoint;k<PathPoint+400;k++){
-                if((gpsMapLine[k]->mbnoavoid==false)&&(gpsMapLine[k]->roadSum>1))
+                if((gpsMapLine[k]->mbnoavoid==false))//&&(gpsMapLine[k]->roadSum>1))
                                  road_permit_sum++;
         }
         if(road_permit_sum>=400)
@@ -1884,7 +1886,7 @@ iv::decition::Decition iv::decition::DecideGps00::getDecideFromGPS(GPS_INS now_g
     }
 
     //shiyanbizhang 0929
-    if(obsDistance>0&& (obsDistance<ServiceCarStatus.aocfDis)&&(obs_speed_for_avoid>-8.0)&&(obs_speed_for_avoid<3.0)&&(realspeed>1)//&& (avoid_speed_flag==true)        //
+    if(obsDistance>0&& (obsDistance<ServiceCarStatus.aocfDis)&&(obs_speed_for_avoid>-8.0)&&(obs_speed_for_avoid<3.0)&&(realspeed>0.1)//&& (avoid_speed_flag==true)//sudugaiwei0.1        //
             &&(vehState==normalRun||vehState==backOri || vehState==avoiding) //&&(ObsTimeStart==-1)
             && (gpsMapLine[PathPoint]->runMode==1)&& (road_permit_avoid==true)&&(gpsMapLine[PathPoint]->mode2!=3000)&&(gpsMapLine[PathPoint+300]->mode2!=3000)&&(gpsMapLine[PathPoint+100]->mode2!=3000)&&(gpsMapLine[PathPoint+300]->mode2!=23)){
 //        ObsTimeStart=GetTickCount();
@@ -1913,7 +1915,7 @@ iv::decition::Decition iv::decition::DecideGps00::getDecideFromGPS(GPS_INS now_g
     if (vehState == avoidObs   || vehState==waitAvoid ) {
         if (obsDistance <ServiceCarStatus.aocfDis && obsDistance >0)
         {
-            dSpeed = min(6.0,dSpeed);
+            dSpeed = min(10.0,dSpeed);//6gaiwei10 ,20220818
             avoidTimes++;
             //          if (avoidTimes>=6)
             if (avoidTimes>=ServiceCarStatus.aocfTimes)
@@ -1925,7 +1927,7 @@ iv::decition::Decition iv::decition::DecideGps00::getDecideFromGPS(GPS_INS now_g
         }
         else if (obsDistance < 40 && obsDistance >0 && dSpeed>15)
         {
-            dSpeed =  min(15.0,dSpeed);
+            dSpeed =  min(10.0,dSpeed);//15gaiceng10,20220816
             avoidTimes = 0;
         }
         else
@@ -1996,15 +1998,18 @@ iv::decition::Decition iv::decition::DecideGps00::getDecideFromGPS(GPS_INS now_g
 
 
 
-    if((vehState == preAvoid)||(avoidXNew!=0))
+    if((vehState == preAvoid)||((avoidXNew!=0)))
+//    if((vehState == preAvoid)||(avoidXNew!=0))
     {
+        dSpeed = min(10.0,dSpeed);//6gaiwei 10
+        static int count_avoidx_0=0;
         int avoidLeft_value=0;
         int avoidRight_value=0;
         int* avoidLeft_p=&avoidLeft_value;
         int* avoidRight_p=&avoidRight_value;
         computeAvoidBoundary(roadOri,roadSum,gpsMapLine[PathPoint]->mfLaneWidth,ServiceCarStatus.msysparam.vehWidth,avoidLeft_p,avoidRight_p);
         avoidXNewPre=computeAvoidXDistance(lidarGridPtr,now_gps_ins, gpsMapLine,lidar_per,avoidLeft_value,avoidRight_value,avoidXNewLast);
-        if(avoidXNewPreVector.size()<5){
+        if(avoidXNewPreVector.size()<20){
             avoidXNewPreVector.push_back(avoidXNewPre);
         }else{
             if(avoidXNewPreVector[0]!=avoidXNewLast){
@@ -2028,12 +2033,29 @@ iv::decition::Decition iv::decition::DecideGps00::getDecideFromGPS(GPS_INS now_g
             else
                 turnLampFlag=0;
 
-           gpsTraceNow.clear();
+//           gpsTraceNow.clear();
            gpsTraceAvoidXY.clear();
            givlog->debug("decition_brain","avoidXNew: %d,avoidXNewLast: %d",
                            avoidXNew,avoidXNewLast);
            //gpsTraceAvoidXY = getGpsTraceOffsetAvoid(gpsTraceOri, avoidXNew,now_gps_ins);
-           gpsTraceAvoidXY = splinePlanner->chooseRoadBySpline(now_gps_ins,gpsMapLine,PathPoint,obsSpline,avoidXNew,avoidXNewLast);
+//           gpsTraceAvoidXY = splinePlanner->chooseRoadBySpline(now_gps_ins,gpsMapLine,PathPoint,obsSpline,avoidXNew,avoidXNewLast);
+           if(vehState == preAvoid)
+           {
+               gpsTraceAvoidXY = splinePlanner->chooseRoadBySpline(now_gps_ins,gpsMapLine,PathPoint,obsSpline,avoidXNew,avoidXNewLast);
+           }
+           else if(avoidXNew==0)
+           {
+               count_avoidx_0++;
+               if(count_avoidx_0>60)
+               {
+                  gpsTraceAvoidXY = splinePlanner->chooseRoadBySpline(now_gps_ins,gpsMapLine,PathPoint,obsSpline,avoidXNew,avoidXNewLast);
+
+               }
+            }
+           if(avoidXNew!=0)
+           {
+               count_avoidx_0=0;
+           }
            vehState = avoiding;
            startAvoidGpsIns = now_gps_ins;
            obstacle_avoid_flag=1;
@@ -2042,7 +2064,16 @@ iv::decition::Decition iv::decition::DecideGps00::getDecideFromGPS(GPS_INS now_g
            avoidXNewPreFilter=avoidXNew;
         }
     }
-
+if (vehState == preAvoid)
+{
+    //dSpeed = min(6.0,dSpeed);
+    iv::Point2D now_s_d=cartesian_to_frenet1D(gpsMapLine,now_gps_ins.gps_x, now_gps_ins.gps_y);
+            if ((obsDistance>ServiceCarStatus.aocfDis)&&(fabs(now_s_d.d)<0.05))
+            {
+                // vehState = avoidObs; 0929
+                vehState=normalRun;
+            }
+}
 
 
 //    if (vehState == preAvoid)
@@ -2390,7 +2421,7 @@ iv::decition::Decition iv::decition::DecideGps00::getDecideFromGPS(GPS_INS now_g
         if(obsDistance>0 && obsDistance<8){
                 dSpeed=0;
             }
-    }else if(obsDistance>0 && obsDistance<15){
+    }else if(obsDistance>0 && obsDistance<10){
         dSpeed=0;
     }
 
@@ -2601,17 +2632,19 @@ iv::decition::Decition iv::decition::DecideGps00::getDecideFromGPS(GPS_INS now_g
                                <<"Decide_ACC"  << ","  <<setprecision(2)<<gps_decition->torque<< ","
                                <<"Decide_Brake"<< ","  <<gps_decition->brake<< ","
                                <<"Vehicle_RealSpd"<< ","  <<setprecision(2)<<now_gps_ins.speed<< ","
-//                               <<"zuo_ultra"<< ","<<ServiceCarStatus.mbUltraDis[3]<< ","
-//                               <<"you_ultra"<< ","<<ServiceCarStatus.mbUltraDis[1]<< ","
-    //                          <<"OBS_Distance"<< ","<<obsDistance_log<< ","
-    //                           <<"OBS_Speed"<< ","<<obs_speed_for_avoid<< ","
-    //                           <<"Vehicle_state"<< ","<<vehState<< ","
-    //                           <<"avoid_flag"<<","<<obstacle_avoid_flag<<","
-    //                           <<"avoidXNew"<<","<<avoidXNew<<","
-    //                           <<"avoidXNewPre"<<","<<avoidXNewPre<<","
-    //                           <<"avoidXPre"<<","<<avoidXPre<<","
-    //                           <<"ObsTimeEnd"<<","<<ObsTimeEnd<<","
-    //                           <<"avoidXY_size"<<","<<gpsTraceAvoidXY.size()<<","
+//                            <<"readyParkMode"<< ","<<readyParkMode<< ","
+//                              <<"readyZhucheMode"<< ","<<readyZhucheMode<< ","
+                              <<"OBS_Distance"<< ","<<obsDistance_log<< ","
+                               <<"OBS_Speed"<< ","<<obs_speed_for_avoid<< ","
+                              <<"obsSpeed_fusion"<<","<<obsSpeed<<","
+                              <<"SecSpeed"<<","<<secSpeed<<","
+                               <<"Vehicle_state"<< ","<<vehState<< ","
+                              <<"avoid_flag"<<","<<obstacle_avoid_flag<<","
+                               <<"avoidXNew"<<","<<avoidXNew<<","
+                               <<"avoidXNewPre"<<","<<avoidXNewPre<<","
+                               //<<"avoidXPre"<<","<<avoidXPre<<","
+                               <<"ObsTimeEnd"<<","<<ObsTimeEnd<<","
+                               <<"avoidXY_size"<<","<<gpsTraceAvoidXY.size()<<","
                                <<"Min_Decelation"","<<minDecelerate<< ","
     //                           <<"Decide_Angle"<< ","  << setprecision(2)<<gps_decition->wheel_angle<< ","
     //                           <<"Vehicle_GPS_heading"<< ","<< setprecision(10)<<now_gps_ins.ins_heading_angle<< ","
@@ -2619,7 +2652,7 @@ iv::decition::Decition iv::decition::DecideGps00::getDecideFromGPS(GPS_INS now_g
     //                           <<"Vehicle_GPS_Y"<< ","<< setprecision(10)<<now_gps_ins.gps_lng<< ","
     //                           <<"Trace_Point"<< ","<<PathPoint<< ","
     //                           <<"OBS_Speed"<< ","<<obsSpeed<< ","
-    //                           <<"OBS_Distance"<< ","<<obsDistance<< ","
+                               <<"gpsTraceOri"<< ","<<gpsTraceOri.size()<< ","
     //                           <<"TTC"<< ","<<ttc<< ","
 //                               <<"Decide_torque"  << ","  <<setprecision(2)<<gps_decition->torque<< ","
 //                               <<"Decide_Brake"<< ","  <<gps_decition->brake<< ","
@@ -2632,7 +2665,7 @@ iv::decition::Decition iv::decition::DecideGps00::getDecideFromGPS(GPS_INS now_g
 //                               <<"avoidXNewPre"<<","<<avoidXNewPre<<","
 ////                               <<"avoidXPre"<<","<<avoidXPre<<","
 //                               <<"ObsTimeEnd"<<","<<ObsTimeEnd<<","
-//                               <<"avoidXY_size"<<","<<gpsTraceAvoidXY.size()<<","
+                             <<"avoidXY_size"<<","<<gpsTraceAvoidXY.size()<<","
 //                               <<"Min_Decelation"","<<minDecelerate<< ","
                                <<"Decide_Angle"<< ","  << setprecision(2)<<gps_decition->wheel_angle<< ","
                               // <<"Vehicle_GPS_heading"<< ","<< setprecision(10)<<now_gps_ins.ins_heading_angle<< ","
@@ -3583,13 +3616,20 @@ void iv::decition::DecideGps00::computeObsOnRoad(iv::LidarGridPtr lidarGridPtr,
 
 }
 
-void iv::decition::DecideGps00::computeObsOnRoadXY(iv::LidarGridPtr lidarGridPtr, std::vector<Point2D> gpsTrace,std::vector<Point2D> gpsTraceLeft,std::vector<Point2D> gpsTraceRight,int roadNum,
+//void iv::decition::DecideGps00::computeObsOnRoadXY(iv::LidarGridPtr lidarGridPtr, std::vector<Point2D> gpsTrace,std::vector<Point2D> gpsTraceLeft,std::vector<Point2D> gpsTraceRight,int roadNum,
+//                                                 const std::vector<GPSData> gpsMapLine, std::vector<iv::Perception::PerceptionOutput> lidar_per) {
+void iv::decition::DecideGps00::computeObsOnRoadXY( iv::GPS_INS now_gps_ins,iv::LidarGridPtr lidarGridPtr, std::vector<Point2D> gpsTrace,std::vector<Point2D> gpsTraceLeft,std::vector<Point2D> gpsTraceRight,int roadNum,
                                                  const std::vector<GPSData> gpsMapLine, std::vector<iv::Perception::PerceptionOutput> lidar_per) {
 
+
     //    QTime xTime;
     //   xTime.start();
     //    qDebug("time 0 is %d ",xTime.elapsed());
     double obs,obsSd;
+    double obsCarCoordinateX,obsCarCoordinateY;
+    GPS_INS obsGeodetic;
+    Point2D obsFrenet,obsFrenetMid;
+    double obsCarCoordinateDistance=-1;
 
     if (lidarGridPtr == NULL)
     {
@@ -3604,7 +3644,15 @@ void iv::decition::DecideGps00::computeObsOnRoadXY(iv::LidarGridPtr lidarGridPtr
         if(!ServiceCarStatus.useMobileEye){
             lidarXiuZheng=0-ServiceCarStatus.msysparam.frontGpsXiuzheng;
         }
-        lidarDistance = obsPoint.y + lidarXiuZheng;   //激光距离推到车头  gjw20191110 lidar
+
+        obsCarCoordinateX=obsPoint.x;
+        obsCarCoordinateY=obsPoint.y;
+        obsGeodetic = Coordinate_UnTransfer(obsCarCoordinateX, obsCarCoordinateY, now_gps_ins);   //车体转大地
+        obsFrenetMid=cartesian_to_frenet1D(gpsMapLine,obsGeodetic.gps_x,obsGeodetic.gps_y);          //大地转frenet
+        iv::Point2D now_s_d=cartesian_to_frenet1D(gpsMapLine,now_gps_ins.gps_x,now_gps_ins.gps_y);
+        givlog->debug("decition_brain","road_num: %d,obsFrenetMid_s: %f,now_s: %f",roadNum,obsFrenetMid.s,now_s_d.s);
+        obsFrenet.s=obsFrenetMid.s-now_s_d.s;
+        lidarDistance = obsFrenet.s;//obsPoint.y + lidarXiuZheng;   //激光距离推到车头  gjw20191110 lidar
         //    lidarDistance=-1;
         if (lidarDistance<0)
         {

+ 2 - 2
src/decition/decition_brain_sf_Jeely_xingyueL/decition/decide_gps_00.h

@@ -201,7 +201,7 @@ public:
     bool checkReturnEnable(double avoidX, iv::LidarGridPtr lidarGridPtr, int roadNum);
 
     void computeObsOnRoad(iv::LidarGridPtr lidarGridPtr, std::vector<Point2D> gpsTrace, int roadNum,const std::vector<GPSData> gpsMapLine, std::vector<iv::Perception::PerceptionOutput> lidar_per);
-    void computeObsOnRoadXY(iv::LidarGridPtr lidarGridPtr, std::vector<Point2D> gpsTrace,std::vector<Point2D> gpsTraceLeft,std::vector<Point2D> gpsTraceRight,int roadNum,const std::vector<GPSData> gpsMapLine, std::vector<iv::Perception::PerceptionOutput> lidar_per);
+    void computeObsOnRoadXY(iv::GPS_INS now_gps_ins,iv::LidarGridPtr lidarGridPtr, std::vector<Point2D> gpsTrace,std::vector<Point2D> gpsTraceLeft,std::vector<Point2D> gpsTraceRight,int roadNum,const std::vector<GPSData> gpsMapLine, std::vector<iv::Perception::PerceptionOutput> lidar_per);
     static void getEsrObsDistanceByFrenet(const std::vector<Point2D>& gpsTrace, iv::decition::FrenetPoint car_now_frenet_point,iv::decition::FrenetPoint &esrObs_F_Point, const std::vector<iv::GPSData>& gpsMap,int pathpoint,GPS_INS nowGps);
 
     void computeRearObsOnRoad(iv::LidarGridPtr lidarGridPtr, std::vector<Point2D> gpsTrace, int roadNum,const std::vector<GPSData> gpsMapLine);
@@ -271,7 +271,7 @@ public:
     float  ObsTimeSpan=-1;
     double ObsTimeStart=-1;
     double ObsTimeEnd=-1;
-    float ObsTimeWidth=70.0;   //500   zj-30
+    float ObsTimeWidth=40;//70.0;   //500   zj-30
     std::vector<iv::TracePoint> planTrace;
 
     bool roadNowStart=true;

+ 0 - 73
src/detection/detection_lidar_PointPillars_MultiHead/.gitignore

@@ -1,73 +0,0 @@
-# This file is used to ignore files which are generated
-# ----------------------------------------------------------------------------
-
-*~
-*.autosave
-*.a
-*.core
-*.moc
-*.o
-*.obj
-*.orig
-*.rej
-*.so
-*.so.*
-*_pch.h.cpp
-*_resource.rc
-*.qm
-.#*
-*.*#
-core
-!core/
-tags
-.DS_Store
-.directory
-*.debug
-Makefile*
-*.prl
-*.app
-moc_*.cpp
-ui_*.h
-qrc_*.cpp
-Thumbs.db
-*.res
-*.rc
-/.qmake.cache
-/.qmake.stash
-
-# qtcreator generated files
-*.pro.user*
-
-# xemacs temporary files
-*.flc
-
-# Vim temporary files
-.*.swp
-
-# Visual Studio generated files
-*.ib_pdb_index
-*.idb
-*.ilk
-*.pdb
-*.sln
-*.suo
-*.vcproj
-*vcproj.*.*.user
-*.ncb
-*.sdf
-*.opensdf
-*.vcxproj
-*vcxproj.*
-
-# MinGW generated files
-*.Debug
-*.Release
-
-# Python byte code
-*.pyc
-
-# Binaries
-# --------
-*.dll
-*.exe
-

+ 0 - 0
src/detection/detection_lidar_PointPillars_MultiHead_1025/Tracker/Ctracker.cpp → src/detection/detection_lidar_PointPillars_MultiHead/Tracker/Ctracker.cpp


+ 0 - 0
src/detection/detection_lidar_PointPillars_MultiHead_1025/Tracker/Ctracker.h → src/detection/detection_lidar_PointPillars_MultiHead/Tracker/Ctracker.h


+ 0 - 0
src/detection/detection_lidar_PointPillars_MultiHead_1025/Tracker/HungarianAlg.cpp → src/detection/detection_lidar_PointPillars_MultiHead/Tracker/HungarianAlg.cpp


+ 0 - 0
src/detection/detection_lidar_PointPillars_MultiHead_1025/Tracker/HungarianAlg.h → src/detection/detection_lidar_PointPillars_MultiHead/Tracker/HungarianAlg.h


+ 0 - 0
src/detection/detection_lidar_PointPillars_MultiHead_1025/Tracker/Kalman.cpp → src/detection/detection_lidar_PointPillars_MultiHead/Tracker/Kalman.cpp


+ 0 - 0
src/detection/detection_lidar_PointPillars_MultiHead_1025/Tracker/Kalman.h → src/detection/detection_lidar_PointPillars_MultiHead/Tracker/Kalman.h


+ 0 - 0
src/detection/detection_lidar_PointPillars_MultiHead_1025/Tracker/ShortPathCalculator.h → src/detection/detection_lidar_PointPillars_MultiHead/Tracker/ShortPathCalculator.h


+ 0 - 0
src/detection/detection_lidar_PointPillars_MultiHead_1025/Tracker/Tracking.hpp → src/detection/detection_lidar_PointPillars_MultiHead/Tracker/Tracking.hpp


+ 0 - 0
src/detection/detection_lidar_PointPillars_MultiHead_1025/Tracker/defines.h → src/detection/detection_lidar_PointPillars_MultiHead/Tracker/defines.h


+ 0 - 0
src/detection/detection_lidar_PointPillars_MultiHead_1025/Tracker/track.cpp → src/detection/detection_lidar_PointPillars_MultiHead/Tracker/track.cpp


+ 0 - 0
src/detection/detection_lidar_PointPillars_MultiHead_1025/Tracker/track.h → src/detection/detection_lidar_PointPillars_MultiHead/Tracker/track.h


+ 25 - 75
src/detection/detection_lidar_PointPillars_MultiHead/cfgs/cbgs_pp_multihead.yaml

@@ -1,9 +1,11 @@
-CLASS_NAMES: ['car','truck', 'construction_vehicle', 'bus', 'trailer',
-              'barrier', 'motorcycle', 'bicycle', 'pedestrian', 'traffic_cone']
+#CLASS_NAMES: ['轿车', '卡车', '施工车辆', '公交车', '拖车/挂车',
+#              '路碍', '摩托车', '自行车', '行人', '锥形筒']
 
+CLASS_NAMES: ['car', 'truck', 'bus', 'barrier', 'bicycle', 'pedestrian', 'traffic_cone']
 DATA_CONFIG:
-    _BASE_CONFIG_: cfgs/dataset_configs/nuscenes_dataset.yaml
+    _BASE_CONFIG_: /home/a/tian/OpenPCDet/tools/cfgs/dataset_configs/nuscenes_dataset_new.yaml
 
+    #POINT_CLOUD_RANGE: [-38.4, -38.4, -5.0, 38.4, 38.4, 3.0]
     POINT_CLOUD_RANGE: [-51.2, -51.2, -5.0, 51.2, 51.2, 3.0]
     DATA_PROCESSOR:
         -   NAME: mask_points_and_boxes_outside_range
@@ -58,9 +60,9 @@ MODEL:
         ANCHOR_GENERATOR_CONFIG: [
             {
                 'class_name': car,
-                'anchor_sizes': [[4.63, 1.97, 1.74]],
+                'anchor_sizes': [[4.62, 1.95, 1.73]],
                 'anchor_rotations': [0, 1.57],
-                'anchor_bottom_heights': [-0.95],
+                'anchor_bottom_heights': [-0.85],
                 'align_center': False,
                 'feature_map_stride': 4,
                 'matched_threshold': 0.6,
@@ -68,79 +70,49 @@ MODEL:
             },
             {
                 'class_name': truck,
-                'anchor_sizes': [[6.93, 2.51, 2.84]],
+                'anchor_sizes': [[6.85, 2.56, 2.89]],
                 'anchor_rotations': [0, 1.57],
-                'anchor_bottom_heights': [-0.6],
+                'anchor_bottom_heights': [-0.23],
                 'align_center': False,
                 'feature_map_stride': 4,
-                'matched_threshold': 0.55,
-                'unmatched_threshold': 0.4
-            },
-            {
-                'class_name': construction_vehicle,
-                'anchor_sizes': [[6.37, 2.85, 3.19]],
-                'anchor_rotations': [0, 1.57],
-                'anchor_bottom_heights': [-0.225],
-                'align_center': False,
-                'feature_map_stride': 4,
-                'matched_threshold': 0.5,
-                'unmatched_threshold': 0.35
+                'matched_threshold': 0.525,
+                'unmatched_threshold': 0.375
             },
             {
                 'class_name': bus,
-                'anchor_sizes': [[10.5, 2.94, 3.47]],
-                'anchor_rotations': [0, 1.57],
-                'anchor_bottom_heights': [-0.085],
-                'align_center': False,
-                'feature_map_stride': 4,
-                'matched_threshold': 0.55,
-                'unmatched_threshold': 0.4
-            },
-            {
-                'class_name': trailer,
-                'anchor_sizes': [[12.29, 2.90, 3.87]],
+                'anchor_sizes': [[11.81, 2.91, 3.71]],
                 'anchor_rotations': [0, 1.57],
-                'anchor_bottom_heights': [0.115],
+                'anchor_bottom_heights': [0.24],
                 'align_center': False,
                 'feature_map_stride': 4,
-                'matched_threshold': 0.5,
-                'unmatched_threshold': 0.35
+                'matched_threshold': 0.525,
+                'unmatched_threshold': 0.375
             },
             {
                 'class_name': barrier,
                 'anchor_sizes': [[0.50, 2.53, 0.98]],
                 'anchor_rotations': [0, 1.57],
-                'anchor_bottom_heights': [-1.33],
+                'anchor_bottom_heights': [-1.18],
                 'align_center': False,
                 'feature_map_stride': 4,
                 'matched_threshold': 0.55,
                 'unmatched_threshold': 0.4
             },
-            {
-                'class_name': motorcycle,
-                'anchor_sizes': [[2.11, 0.77, 1.47]],
-                'anchor_rotations': [0, 1.57],
-                'anchor_bottom_heights': [-1.085],
-                'align_center': False,
-                'feature_map_stride': 4,
-                'matched_threshold': 0.5,
-                'unmatched_threshold': 0.3
-            },
             {
                 'class_name': bicycle,
-                'anchor_sizes': [[1.70, 0.60, 1.28]],
+                'anchor_sizes': [[1.91, 0.69, 1.38]],
                 'anchor_rotations': [0, 1.57],
-                'anchor_bottom_heights': [-1.18],
+                'anchor_bottom_heights': [-0.96],
                 'align_center': False,
                 'feature_map_stride': 4,
                 'matched_threshold': 0.5,
-                'unmatched_threshold': 0.35
+                'unmatched_threshold': 0.325
             },
             {
                 'class_name': pedestrian,
-                'anchor_sizes': [[0.73, 0.67, 1.77]],
+                'anchor_sizes': [[0.72, 0.67, 1.77]],
                 'anchor_rotations': [0, 1.57],
-                'anchor_bottom_heights': [-0.935],
+                'anchor_bottom_heights': [-0.67],
                 'align_center': False,
                 'feature_map_stride': 4,
                 'matched_threshold': 0.6,
@@ -150,36 +122,13 @@ MODEL:
                 'class_name': traffic_cone,
                 'anchor_sizes': [[0.41, 0.41, 1.07]],
                 'anchor_rotations': [0, 1.57],
-                'anchor_bottom_heights': [-1.285],
+                'anchor_bottom_heights': [-1.23],
                 'align_center': False,
                 'feature_map_stride': 4,
                 'matched_threshold': 0.6,
                 'unmatched_threshold': 0.4
             },
         ]
-
-        SHARED_CONV_NUM_FILTER: 64
-
-        RPN_HEAD_CFGS: [
-            {
-                'HEAD_CLS_NAME': ['car'],
-            },
-            {
-                'HEAD_CLS_NAME': ['truck', 'construction_vehicle'],
-            },
-            {
-                'HEAD_CLS_NAME': ['bus', 'trailer'],
-            },
-            {
-                'HEAD_CLS_NAME': ['barrier'],
-            },
-            {
-                'HEAD_CLS_NAME': ['motorcycle', 'bicycle'],
-            },
-            {
-                'HEAD_CLS_NAME': ['pedestrian', 'traffic_cone'],
-            },
-        ]
         SEPARATE_REG_CONFIG: 
             NUM_MIDDLE_CONV: 1
             NUM_MIDDLE_FILTER: 64
@@ -226,7 +175,7 @@ MODEL:
 
 OPTIMIZATION:
     BATCH_SIZE_PER_GPU: 4
-    NUM_EPOCHS: 20
+    NUM_EPOCHS: 30
 
     OPTIMIZER: adam_onecycle
     LR: 0.001
@@ -235,7 +184,7 @@ OPTIMIZATION:
 
     MOMS: [0.95, 0.85]
     PCT_START: 0.4
-    DIV_FACTOR: 10
+    DIV_FACTOR: 20
     DECAY_STEP_LIST: [35, 45]
     LR_DECAY: 0.1
     LR_CLIP: 0.0000001
@@ -244,3 +193,4 @@ OPTIMIZATION:
     WARMUP_EPOCH: 1
 
     GRAD_NORM_CLIP: 10
+

+ 26 - 8
src/detection/detection_lidar_PointPillars_MultiHead/detection_lidar_PointPillars_MultiHead.pro

@@ -1,6 +1,6 @@
 QT -= gui
 
-CONFIG += c++11 console
+CONFIG += c++14 console
 CONFIG -= app_bundle
 
 QMAKE_CXXFLAGS += -std=gnu++17
@@ -11,7 +11,7 @@ QMAKE_LFLAGS += -no-pie  -Wl,--no-as-needed
 # depend on your compiler). Please consult the documentation of the
 # deprecated API in order to know how to port your code away from it.
 DEFINES += QT_DEPRECATED_WARNINGS
-
+#DEFINES += DEBUG_SHOW
 # You can also make your code fail to compile if you use deprecated APIs.
 # In order to do so, uncomment the following line.
 # You can also select to disable deprecated APIs only up to a certain version of Qt.
@@ -20,13 +20,18 @@ DEFINES += QT_DEPRECATED_WARNINGS
 SOURCES += main.cpp \
     pointpillars.cc \
     ../../include/msgtype/object.pb.cc \
-    ../../include/msgtype/objectarray.pb.cc
+    ../../include/msgtype/objectarray.pb.cc \
+    Tracker/Ctracker.cpp \
+    Tracker/HungarianAlg.cpp \
+    Tracker/Kalman.cpp \
+    Tracker/track.cpp
 
 DISTFILES += \
     nms.cu \
     postprocess.cu \
     preprocess.cu \
-    scatter.cu
+    scatter.cu \
+    roiaware_pool3d_kernel.cu
 
 HEADERS += \
     common.h \
@@ -36,14 +41,24 @@ HEADERS += \
     preprocess.h \
     scatter.h \
     ../../include/msgtype/object.pb.h \
-    ../../include/msgtype/objectarray.pb.h
-
+    ../../include/msgtype/objectarray.pb.h \
+    Tracker/Ctracker.h \
+    Tracker/defines.h \
+    Tracker/HungarianAlg.h \
+    Tracker/Kalman.h \
+    Tracker/ShortPathCalculator.h \
+    Tracker/track.h \
+    Tracker/Tracking.hpp \
+    roiaware_pool3d.h
+
+INCLUDEPATH+=Tracker
 
 CUDA_SOURCES +=  \
     nms.cu \
     postprocess.cu \
     preprocess.cu \
-    scatter.cu
+    scatter.cu \
+    roiaware_pool3d_kernel.cu
 
 CUDA_SDK = "/usr/local/cuda/"   # cudaSDK路径
 
@@ -128,7 +143,7 @@ LIBS += -lcudart -lcufft -lyaml-cpp
 
 #LIBS += -L/home/adc/soft/cudnn-10.2-linux-x64-v7.6.5.32/cuda/lib64 -lcudnn
 
-LIBS +=  -lmyelin -lnvinfer -lnvonnxparser -lnvcaffe_parser
+LIBS +=  -L/usr/lib/aarch64-linux-gnu/ -lmyelin -lnvinfer -lnvonnxparser -lnvcaffe_parser
 
 #LIBS += -L/home/nvidia/git/libtorch_gpu-1.6.0-linux-aarch64/lib -ltorch_cuda  -ltorch -lc10 -ltorch_cpu
 
@@ -164,3 +179,6 @@ unix:LIBS +=  -lpcl_common\
         -lpcl_surface\
         -lpcl_tracking\
         -lpcl_visualization
+
+INCLUDEPATH += /usr/include/opencv4/
+LIBS += /usr/lib/aarch64-linux-gnu/libopencv*.so

+ 461 - 67
src/detection/detection_lidar_PointPillars_MultiHead/main.cpp

@@ -16,6 +16,10 @@
 #include <thread>
 #include "objectarray.pb.h"
 //#include "ivbacktrace.h"
+#include "Tracking.hpp"
+
+#include "roiaware_pool3d.h"
+#include "Eigen/Dense"
 
 iv::Ivfault *gfault = nullptr;
 iv::Ivlog *givlog = nullptr;
@@ -29,33 +33,310 @@ const int kNumPointFeature = 5;
 const int kOutputNumBoxFeature = 7;
 std::string gstrinput;
 std::string gstroutput;
+Eigen::Matrix3d rotation_matrix;
+Eigen::Vector3d trans_matrix;
+TrackerSettings settings;
+CTracker tracker(settings);
+bool m_isTrackerInitialized = false;
+
+
+#include <random>
+////////////////////用于nms////////////////////
+#include<opencv2/opencv.hpp>
+#define rad2Angle(rad) ((rad) * 180.0 / M_PI)
+
+const float smallinbig_threshold = 0.8;
+const float distance_threshold = 0.1;
+const float secondnms_threshold = 0.1;
+
+typedef struct {
+    cv::RotatedRect box;
+    std::vector<float> detection;
+    std::vector<float> bbox_pts;
+    int label;
+    float score;
+}BBOX3D;
+
+//将检测结果转为RotatedRect以便于nms计算
+bool GetRotatedRect(std::vector<float> &out_detections,std::vector<int> &out_labels,
+                    std::vector<float> &out_scores, std::vector<BBOX3D> &results)
+{
+    int obj_size = out_detections.size()/kOutputNumBoxFeature;
+    if(out_labels.size()==obj_size && out_scores.size()==obj_size)
+    {
+        for(int i=0;i<obj_size;i++)
+        {
+            BBOX3D result;
+            result.box = cv::RotatedRect(cv::Point2f(out_detections.at(i*7),out_detections.at(i*7+1)),
+                                         cv::Size2f(out_detections.at(i*7+3),out_detections.at(i*7+4)),
+                                         rad2Angle(out_detections.at(i*7+6)));
+            for(int j=0;j<kOutputNumBoxFeature;j++)
+                result.detection.push_back(out_detections.at(i*7+j));
+            result.label = out_labels.at(i);
+            result.score = out_scores.at(i);
+            results.push_back(result);
+        }
+        return true;
+    }
+    else
+    {
+        std::cout<<"the size of detections labels scores is not equal !!!"<<std::endl;
+        return false;
+    }
+
+}
+
+bool sort_score(BBOX3D box1,BBOX3D box2)
+{
+    return (box1.score > box2.score);
+}
+
+//计算两个旋转矩形的IOU
+float calcIOU(cv::RotatedRect rect1, cv::RotatedRect rect2)
+{
+    float areaRect1 = rect1.size.width * rect1.size.height;
+    float areaRect2 = rect2.size.width * rect2.size.height;
+    vector<cv::Point2f> vertices;
+    int intersectionType = cv::rotatedRectangleIntersection(rect1, rect2, vertices);
+    if (vertices.size()==0)
+        return 0.0;
+    else{
+        vector<cv::Point2f> order_pts;
+        cv::convexHull(cv::Mat(vertices), order_pts, true);
+        double area = cv::contourArea(order_pts);
+        float inner = (float) (area / (areaRect1 + areaRect2 - area + 0.0001));
+        //排除小框完全在大框里面的case
+        float areaMin = (areaRect1 < areaRect2)?areaRect1:areaRect2;
+        float innerMin = (float)(area / (areaMin + 0.0001));
+        if(innerMin > smallinbig_threshold)
+            inner = innerMin;
+        return inner;
+    }
+}
+//计算两个点的欧式距离
+float calcdistance(cv::Point2f center1, cv::Point2f center2)
+{
+    float distance = sqrt((center1.x-center2.x)*(center1.x-center2.x)+
+                          (center1.y-center2.y)*(center1.y-center2.y));
+    return distance;
+}
+
+
+//nms
+void nms(std::vector<BBOX3D> &vec_boxs,float threshold,std::vector<BBOX3D> &results)
+{
+    std::sort(vec_boxs.begin(),vec_boxs.end(),sort_score);
+    while(vec_boxs.size() > 0)
+    {
+        results.push_back(vec_boxs[0]);
+        vec_boxs.erase(vec_boxs.begin());
+        for (auto it = vec_boxs.begin(); it != vec_boxs.end();)
+        {
+            float iou_value =calcIOU(results.back().box,(*it).box);
+            float distance_value = calcdistance(results.back().box.center,(*it).box.center);
+            if ((iou_value > threshold) || (distance_value<distance_threshold))
+                it = vec_boxs.erase(it);
+            else it++;
+        }
+
+//        std::cout<<"results: "<<results.back().detection.at(0)<<" "<<results.back().detection.at(1)<<
+//                   " "<<results.back().detection.at(2)<<std::endl;
+
+    }
+}
+void GetLidarObj(std::vector<BBOX3D> &results,iv::lidar::objectarray & lidarobjvec)
+{
+    int i;
+    int obj_size = results.size();
+    //    givlog->verbose("OBJ","object size is %d",obj_size);;
+    for(i=0;i<obj_size;i++)
+    {
+        iv::lidar::lidarobject lidarobj;
+        if (results.at(i).score < 0.10) {
+            std::cout<<"///////: "<<results.at(i).score<<std::endl;
+            continue;
+        }
+
+
+        //if (results.at(i).label == 5) continue;
+
+        vector<float>out_detection = results.at(i).detection;
+        lidarobj.set_tyaw(out_detection.at(6));
+        iv::lidar::PointXYZ centroid;
+        iv::lidar::PointXYZ * _centroid;
+        centroid.set_x(out_detection.at(0));
+        centroid.set_y(out_detection.at(1));
+        centroid.set_z(out_detection.at(2));
+        _centroid = lidarobj.mutable_centroid();
+        _centroid->CopyFrom(centroid);
+
+        iv::lidar::PointXYZ min_point;
+        iv::lidar::PointXYZ * _min_point;
+        min_point.set_x(0);
+        min_point.set_y(0);
+        min_point.set_z(0);
+        _min_point = lidarobj.mutable_min_point();
+        _min_point->CopyFrom(min_point);
+
+        iv::lidar::PointXYZ max_point;
+        iv::lidar::PointXYZ * _max_point;
+        max_point.set_x(0);
+        max_point.set_y(0);
+        max_point.set_z(0);
+        _max_point = lidarobj.mutable_max_point();
+        _max_point->CopyFrom(max_point);
+        iv::lidar::PointXYZ position;
+        iv::lidar::PointXYZ * _position;
+        position.set_x(out_detection.at(0));
+        position.set_y(out_detection.at(1));
+        position.set_z(out_detection.at(2));
+        _position = lidarobj.mutable_position();
+        _position->CopyFrom(position);
+        lidarobj.set_mntype(results.at(i).label);
+        // label 2  8
+        if(results.at(i).label==2){
+            lidarobj.set_mntype(8);
+        }else if(results.at(i).label==8){
+            lidarobj.set_mntype(2);
+        }
+        lidarobj.set_score(results.at(i).score);
+        lidarobj.add_type_probs(results.at(i).score);
+        iv::lidar::PointXYZI point_cloud;
+        iv::lidar::PointXYZI * _point_cloud;
+        point_cloud.set_x(out_detection.at(0));
+        point_cloud.set_y(out_detection.at(1));
+        point_cloud.set_z(out_detection.at(2));
+        point_cloud.set_i(results.at(i).label);
+        _point_cloud = lidarobj.add_cloud();
+        _point_cloud->CopyFrom(point_cloud);
+        iv::lidar::Dimension ld;
+        iv::lidar::Dimension * pld;
+        ld.set_x(out_detection.at(3));
+        ld.set_y(out_detection.at(4));
+        ld.set_z(out_detection.at(5));
+        pld = lidarobj.mutable_dimensions();
+        pld->CopyFrom(ld);
+
+//        std::cout<<"x y z:  "<<out_detection.at(0)<<" "<<out_detection.at(1)<<" "<<
+//        out_detection.at(2)<<" "<<out_detection.at(3)<<" "<< out_detection.at(4)<<" "
+//        <<out_detection.at(5)<<" "<<out_detection.at(6)<<std::endl;
+
+        iv::lidar::lidarobject * po = lidarobjvec.add_obj();
+        po->CopyFrom(lidarobj);
+    }
+
+//   std::cout<<"the lidarobjvec: "<<lidarobjvec.obj_size()<<std::endl;
+}
+////////////////////用于nms////////////////////
+
+
+////////////////////用于获得3dbbox中点云个数////////////////////
+#if 0
+inline void lidar_to_local_coords_cpu(float shift_x, float shift_y, float rot_angle, float &local_x, float &local_y){
+    float cosa = cos(-rot_angle), sina = sin(-rot_angle);
+    local_x = shift_x * cosa + shift_y * (-sina);
+    local_y = shift_x * sina + shift_y * cosa;
+}
+
+
+inline int check_pt_in_box3d_cpu(const float *pt, std::vector<float> &box3d, float &local_x, float &local_y){
+    // param pt: (x, y, z)
+    // param box3d: [x, y, z, dx, dy, dz, heading], (x, y, z) is the box center
+    const float MARGIN = 1e-2;
+    float x = pt[0], y = pt[1], z = pt[2];
+    float cx = box3d[0], cy = box3d[1], cz = box3d[2];
+    float dx = box3d[3], dy = box3d[4], dz = box3d[5], rz = box3d[6];
+
+    if (fabsf(z - cz) > dz / 2.0) return 0;
+    lidar_to_local_coords_cpu(x - cx, y - cy, rz, local_x, local_y);
+    float in_flag = (fabs(local_x) < dx / 2.0 + MARGIN) & (fabs(local_y) < dy / 2.0 + MARGIN);
+    return in_flag;
+}
+
+int points_in_boxes_cpu(std::vector<BBOX3D>& boxes, float* pts_lidar,
+                        int pts_num, std::vector<std::vector<int>>& pts_indices){
+
+    std::vector<std::vector<float>> pts_bboxes;
+
+    int boxes_num = boxes.size();
+    float local_x = 0, local_y = 0;
+    for (int i = 0; i < boxes_num; i++){
+        std::vector<float>pts_bbox;
+        for (int j = 0; j < pts_num; j++){
+            int cur_in_flag = check_pt_in_box3d_cpu(pts_lidar + j * 5, boxes[i].detection, local_x, local_y);
+            pts_indices[i][j] = cur_in_flag;
+            if(cur_in_flag)
+            {
+                pts_bbox.push_back(pts_lidar[j*5+0]);
+                pts_bbox.push_back(pts_lidar[j*5+1]);
+                pts_bbox.push_back(pts_lidar[j*5+2]);
+                pts_bbox.push_back(pts_lidar[j*5+3]);
+                pts_bbox.push_back(pts_lidar[j*5+4]);
+            }
+
+        }
+        pts_bboxes.push_back(pts_bbox);
+
+        std::cout<<"the size of points: "<<i<<" : "<<pts_bbox.size() / 5 <<std::endl;
+
+        pts_bbox.clear();
+    }
+
+    return 1;
+}
+
+#endif
+////////////////////用于获得3dbbox中点云个数////////////////////
 
 
 void PclToArray(
-    const pcl::PointCloud<pcl::PointXYZI>::Ptr& in_pcl_pc_ptr,
-    float* out_points_array, const float normalizing_factor) {
-  for (size_t i = 0; i < in_pcl_pc_ptr->size(); ++i) {
-    pcl::PointXYZI point = in_pcl_pc_ptr->at(i);
-    out_points_array[i * 4 + 0] = point.x;
-    out_points_array[i * 4 + 1] = point.y;
-    out_points_array[i * 4 + 2] = point.z;
-    out_points_array[i * 4 + 3] =
-        static_cast<float>(point.intensity / normalizing_factor);
-  }
+        const pcl::PointCloud<pcl::PointXYZI>::Ptr& in_pcl_pc_ptr,
+        float* out_points_array, const float normalizing_factor) {
+    for (size_t i = 0; i < in_pcl_pc_ptr->size(); ++i) {
+        pcl::PointXYZI point = in_pcl_pc_ptr->at(i);
+        out_points_array[i * 4 + 0] = point.x;
+        out_points_array[i * 4 + 1] = point.y;
+        out_points_array[i * 4 + 2] = point.z;
+        out_points_array[i * 4 + 3] =
+                static_cast<float>(point.intensity / normalizing_factor);
+    }
 }
 
 void PclXYZITToArray(
-    const pcl::PointCloud<pcl::PointXYZI>::Ptr& in_pcl_pc_ptr,
-    float* out_points_array, const float normalizing_factor) {
-  for (size_t i = 0; i < in_pcl_pc_ptr->size(); ++i) {
-    pcl::PointXYZI point = in_pcl_pc_ptr->at(i);
-    out_points_array[i * 5 + 0] = point.x;
-    out_points_array[i * 5 + 1] = point.y;
-    out_points_array[i * 5 + 2] = point.z;
-    out_points_array[i * 5 + 3] =
-        static_cast<float>(point.intensity / normalizing_factor);
-    out_points_array[i * 5 + 4] = 0;
-  }
+        const pcl::PointCloud<pcl::PointXYZI>::Ptr& in_pcl_pc_ptr,
+        float* out_points_array, const float normalizing_factor) {
+
+    /////shuffle the index array/////
+    bool shuffle = true;
+    int point_num = in_pcl_pc_ptr->size();
+    std::vector<int>indices(point_num);
+    std::iota(indices.begin(),indices.end(),0);
+    if(shuffle)
+    {
+//        unsigned seed = 0;
+//        std::shuffle(indices.begin(),indices.end(),std::default_random_engine(seed));
+
+        std::random_device rd;
+        std::mt19937 g(rd());
+        std::shuffle(indices.begin(),indices.end(),g);
+
+    }
+    /////shuffle the index array/////
+
+    for (size_t i = 0; i < in_pcl_pc_ptr->size(); ++i) {
+        //pcl::PointXYZI point = in_pcl_pc_ptr->at(i);
+        int indice = indices[i];
+        pcl::PointXYZI point = in_pcl_pc_ptr->at(indice);
+        Eigen::Vector3d new_point, old_point;
+        old_point<<point.x, point.y, point.z;
+        new_point = rotation_matrix * (old_point) + trans_matrix;
+        out_points_array[i * 5 + 0] = new_point[0];
+        out_points_array[i * 5 + 1] = new_point[1];
+        out_points_array[i * 5 + 2] = new_point[2];
+        out_points_array[i * 5 + 3] =
+                static_cast<float>(point.intensity / normalizing_factor);
+        out_points_array[i * 5 + 4] = 0;
+    }
 }
 
 void GetLidarObj(std::vector<float> out_detections,std::vector<int> out_labels,
@@ -67,8 +348,7 @@ void GetLidarObj(std::vector<float> out_detections,std::vector<int> out_labels,
     for(i=0;i<obj_size;i++)
     {
         iv::lidar::lidarobject lidarobj;
-        if (out_scores.at(i) < 0.12) continue;
-        if (out_labels.at(i) == 5) continue;
+        if (out_scores.at(i) < 0.10) continue;
 
         lidarobj.set_tyaw(out_detections.at(i*7+6));
         iv::lidar::PointXYZ centroid;
@@ -117,16 +397,16 @@ void GetLidarObj(std::vector<float> out_detections,std::vector<int> out_labels,
         point_cloud.set_x(out_detections.at(i*7));
         point_cloud.set_y(out_detections.at(i*7+1));
         point_cloud.set_z(out_detections.at(i*7+2));
-        point_cloud.set_i(out_detections.at(out_labels.at(i)));
+        point_cloud.set_i(0);
 
         _point_cloud = lidarobj.add_cloud();
         _point_cloud->CopyFrom(point_cloud);
 
         iv::lidar::Dimension ld;
         iv::lidar::Dimension * pld;
-        ld.set_x(out_detections.at(i*7+3));
-        ld.set_y(out_detections.at(i*7+4));
-        ld.set_z(out_detections.at(i*7+5));
+        ld.set_x(out_detections.at(i*7+3));// w
+        ld.set_y(out_detections.at(i*7+4));// l
+        ld.set_z(out_detections.at(i*7+5));// h
         pld = lidarobj.mutable_dimensions();
         pld->CopyFrom(ld);
 
@@ -134,15 +414,16 @@ void GetLidarObj(std::vector<float> out_detections,std::vector<int> out_labels,
         iv::lidar::lidarobject * po = lidarobjvec.add_obj();
         po->CopyFrom(lidarobj);
     }
+
 }
 
 void DectectOnePCD(const pcl::PointCloud<pcl::PointXYZI>::Ptr &pc_ptr)
 {
     std::shared_ptr<float> points_array_ptr = std::shared_ptr<float>(new float[pc_ptr->size() * kNumPointFeature]);
- //   float* points_array = new float[pc_ptr->size() * kNumPointFeature];
+    //   float* points_array = new float[pc_ptr->size() * kNumPointFeature];
     PclXYZITToArray(pc_ptr, points_array_ptr.get(), 1.0);
 
-    int    in_num_points = pc_ptr->width;
+    int in_num_points = pc_ptr->width;
 
     std::vector<float> out_detections;
     std::vector<int> out_labels;
@@ -151,34 +432,146 @@ void DectectOnePCD(const pcl::PointCloud<pcl::PointXYZI>::Ptr &pc_ptr)
     QTime xTime;
 
     xTime.start();
-
+    auto startTime = std::chrono::high_resolution_clock::now();
     cudaDeviceSynchronize();
     pPillars->DoInference(points_array_ptr.get(), in_num_points, &out_detections, &out_labels , &out_scores);
     cudaDeviceSynchronize();
-    int BoxFeature = 7;
-    int num_objects = out_detections.size() / BoxFeature;
+    auto endTime = std::chrono::high_resolution_clock::now();
+    double inferenceDuration = std::chrono::duration_cast<std::chrono::nanoseconds>(endTime - startTime).count()/1000000.0;
+//    std::cout<< "inferenceDuration Time: " << inferenceDuration << " ms"<< std::endl;
 
+
+//    int BoxFeature = 7;
+//    int num_objects = out_detections.size() / BoxFeature;
 //    givlog->verbose("obj size is %d", num_objects);
 //    std::cout<<"obj size is "<<num_objects<<std::endl;
 
-//    std::vector<iv::lidar::lidarobject> lidarobjvec;
+
+//    iv::lidar::objectarray lidarobjvec;
+//    GetLidarObj(out_detections,out_labels,out_scores,lidarobjvec);
+
+    //////////nms//////////
+    //startTime = std::chrono::high_resolution_clock::now();
+    std::vector<BBOX3D>results_rect;
+    GetRotatedRect(out_detections,out_labels,out_scores,results_rect);
+//    std::cout<<"results_rect size: "<<results_rect.size()<<std::endl;
+
+    std::vector<BBOX3D>results_bbox;
+    nms(results_rect,secondnms_threshold,results_bbox);
+//    std::cout<<"results_bbox size: "<<results_bbox.size()<<std::endl;
+
+      //get lidar points in 3Dbbox in cpu
+//    startTime = std::chrono::high_resolution_clock::now();
+//    //get lidar points in 3Dbbox
+//    int boxes_num = results_bbox.size();
+//    std::vector<std::vector<int>>pts_indices(boxes_num, vector<int>(in_num_points, 0));
+//    points_in_boxes_cpu(results_bbox,points_array_ptr.get(),in_num_points,pts_indices);
+//    endTime = std::chrono::high_resolution_clock::now();
+//    double nmsDuration = std::chrono::duration_cast<std::chrono::nanoseconds>(endTime - startTime).count()/1000000.0;
+//    std::cout <<"3DBoxDuration Time : "<<nmsDuration<< endl;
+
+
+
+    //get lidar points in 3Dbbox in gpu
+    startTime = std::chrono::high_resolution_clock::now();
+    float* dev_points;
+    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&dev_points),
+                        in_num_points * 5 * sizeof(float))); // in_num_points , 5
+    GPU_CHECK(cudaMemset(dev_points, 0, in_num_points * 5 * sizeof(float)));
+    GPU_CHECK(cudaMemcpy(dev_points, points_array_ptr.get(),
+                        in_num_points * 5 * sizeof(float),
+                        cudaMemcpyHostToDevice));
+    int* box_idx_of_points_gpu;
+    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&box_idx_of_points_gpu),
+                        in_num_points * sizeof(int))); // in_num_points , 5
+    GPU_CHECK(cudaMemset(box_idx_of_points_gpu, -1, in_num_points * sizeof(float)));
+
+    int boxes_num = results_bbox.size();
+    float *boxes_cpu = new float[boxes_num*7];
+    for(int i=0;i<boxes_num;i++)
+    {
+        for(int j=0;j<7;j++)
+            *(boxes_cpu + (i*7+j)) = results_bbox[i].detection[j];
+    }
+    float *boxes_gpu;
+    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&boxes_gpu),
+                        boxes_num * 7 * sizeof(float))); // in_num_points , 5
+    GPU_CHECK(cudaMemset(boxes_gpu, 0, boxes_num * 7 * sizeof(float)));
+    GPU_CHECK(cudaMemcpy(boxes_gpu, boxes_cpu,boxes_num * 7 * sizeof(float),
+                        cudaMemcpyHostToDevice));
+    int batch_size = 1;
+    points_in_boxes_launcher(batch_size,boxes_num,in_num_points,boxes_gpu,dev_points,box_idx_of_points_gpu);
+    int* box_idx_of_points_cpu = new int[in_num_points]();
+    cudaMemcpy(box_idx_of_points_cpu, box_idx_of_points_gpu, in_num_points * sizeof(int), cudaMemcpyDeviceToHost);
+    //vector<int> box_idx_of_points(box_idx_of_points_cpu,box_idx_of_points_cpu+in_num_points);
+
+
+    //cv::Mat image=cv::Mat::zeros(1200,1200,CV_8UC3);
+    //存储bbox的点云
+    for(int i=0; i < in_num_points; i++)
+    {
+
+        for(int j=0; j<boxes_num; j++)
+        {
+            if (box_idx_of_points_cpu[i] == j)
+            {
+                for(int idx=0; idx<5; idx++)
+                    results_bbox[j].bbox_pts.push_back(points_array_ptr.get()[i*5+idx]);
+//                int x = int(points_array_ptr.get()[i*5]*10+600);
+//                int y = int(points_array_ptr.get()[i*5+1]*10+600);
+//                cv::circle(image,cv::Point(x,y),2,cv::Scalar(0,0,255));
+            }
+
+        }
+    }
+//    for(int j=0; j<boxes_num; j++)
+//    {
+
+//        std::cout<<"num points in bbox: "<<results_bbox[j].bbox_pts.size()/5<<std::endl;
+//    }
+
+
+    endTime = std::chrono::high_resolution_clock::now();
+    double gpuDuration = std::chrono::duration_cast<std::chrono::nanoseconds>(endTime - startTime).count()/1000000.0;
+//    std::cout <<"3DBoxDuration_gpu Time : "<<gpuDuration<< endl;
+
+
+    //endTime = std::chrono::high_resolution_clock::now();
+    //double nmsDuration = std::chrono::duration_cast<std::chrono::nanoseconds>(endTime - startTime).count()/1000000.0;
+    //std::cout <<"nmsDuration Time : "<<(double)(ends - start)/ CLOCKS_PER_SEC*1000 << endl;
+
     iv::lidar::objectarray lidarobjvec;
-    GetLidarObj(out_detections,out_labels,out_scores,lidarobjvec);
+    GetLidarObj(results_bbox,lidarobjvec);
+    //////////nms//////////
 
     double timex = pc_ptr->header.stamp;
     timex = timex/1000.0;
     lidarobjvec.set_timestamp(pc_ptr->header.stamp);
 
+    //---------------------------------------------  init tracker  -------------------------------------------------
+//    if (!m_isTrackerInitialized)
+//    {
+//        m_isTrackerInitialized = InitTracker(tracker);
+//        if (!m_isTrackerInitialized)
+//        {
+//            std::cerr << "Tracker initialize error!!!" << std::endl;
+//        }
+//    }
+//    iv::lidar::objectarray trackedobjvec = Tracking(lidarobjvec, tracker);
+
+    //--------------------------------------------  end tracking  --------------------------------------------------
+
     int ntlen;
     std::string out = lidarobjvec.SerializeAsString();
+
     iv::modulecomm::ModuleSendMsg(gpdetect,out.data(),out.length());
 
-//    givlog->verbose("lenth is %d",out.length());
+    //    givlog->verbose("lenth is %d",out.length());
 }
 
 void ListenPointCloud(const char *strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
 {
-//    std::cout<<" is  ok  ------------  "<<std::endl;
+    //    std::cout<<" is  ok  ------------  "<<std::endl;
     if(nSize <=16)return;
     unsigned int * pHeadSize = (unsigned int *)strdata;
     if(*pHeadSize > nSize)
@@ -210,9 +603,9 @@ void ListenPointCloud(const char *strdata,const unsigned int nSize,const unsigne
     {
         pcl::PointXYZI xp;
         memcpy(&xp,p,sizeof(pcl::PointXYZI));
-        xp.z = xp.z;
+        xp.z = xp.z;p++;
+        if (((abs(xp.x)<0.5)&&(xp.y<0.5 && xp.y > -1.0)) || xp.z > 3.0 ) continue;
         point_cloud->push_back(xp);
-        p++;
     }
 
     DectectOnePCD(point_cloud);
@@ -272,10 +665,7 @@ void exitfunc()
     iv::modulecomm::Unregister(gpdetect);
     std::cout<<"exit func complete"<<std::endl;
 }
-
-#include <QDir>
 #include <QFile>
-
 bool trtisexist(std::string strpfe,std::string strbackbone)
 {
     QFile xFile;
@@ -291,13 +681,12 @@ bool trtisexist(std::string strpfe,std::string strbackbone)
     }
     return true;
 }
-
 int main(int argc, char *argv[])
 {
     QCoreApplication a(argc, argv);
 
-//    RegisterIVBackTrace();
-
+    //    RegisterIVBackTrace();
+    tracker.setSettings(settings);
     gfault = new iv::Ivfault("lidar_pointpillar");
     givlog = new iv::Ivlog("lidar_pointpillar");
 
@@ -306,13 +695,11 @@ int main(int argc, char *argv[])
     char * strhome = getenv("HOME");
     std::string pfe_file = strhome;
     pfe_file += "/models/lidar/cbgs_pp_multihead_pfe.onnx";
-    std::string pfe_trt_file = strhome;
-    pfe_trt_file += "/models/lidar/cbgs_pp_multihead_pfe.trt";
+    std::string pfe_trt_file = pfe_file.substr(0, pfe_file.find(".")) + ".trt";
 
     std::string backbone_file = strhome;
     backbone_file += "/models/lidar/cbgs_pp_multihead_backbone.onnx";
-    std::string backbone_trt_file = strhome;
-    backbone_trt_file += "/models/lidar/cbgs_pp_multihead_backbone.trt";
+    std::string backbone_trt_file = backbone_file.substr(0, backbone_file.find(".")) + ".trt";
 
     bool btrtexist = trtisexist(pfe_trt_file,backbone_trt_file);
 
@@ -332,33 +719,40 @@ int main(int argc, char *argv[])
     backbone_file = xparam.GetParam("backbone_file",backbone_file.data());
     gstrinput = xparam.GetParam("input","lidar_pc");
     gstroutput = xparam.GetParam("output","lidar_pointpillar");
+
     if(btrtexist == false)
     {
 
-       std::cout<<"use onnx model."<<std::endl;
-    pPillars = new PointPillars(
-      0.15,
-      0.10,
-      true,
-      pfe_file,
-      backbone_file,
-      pp_config
-    );
+        std::cout<<"use onnx model."<<std::endl;
+        pPillars = new PointPillars(
+                    0.15,
+                    0.10,
+                    true,
+                    pfe_file,
+                    backbone_file,
+                    pp_config
+                    );
     }
     else
     {
-        std::cout<<"use engine mode."<<std::endl;
-    pPillars = new PointPillars(
-      0.15,
-      0.10,
-      false,
-      pfe_trt_file,
-      backbone_trt_file,
-      pp_config
-    );
+        std::cout<<"use trt model."<<std::endl;
+        pPillars = new PointPillars(
+                    0.15,
+                    0.10,
+                    false,
+                    pfe_trt_file,
+                    backbone_trt_file,
+                    pp_config
+                    );
     }
     std::cout<<"PointPillars Init OK."<<std::endl;
-
+    Eigen::AngleAxisd r_z ( 0.00654, Eigen::Vector3d ( 0,0,1 ) ); //沿 Z 轴旋转 yaw   +
+    Eigen::AngleAxisd r_y ( 0.13, Eigen::Vector3d ( 0,1,0 ) ); //沿 Y 轴旋转 roll  +
+    Eigen::AngleAxisd r_x ( -0.0377, Eigen::Vector3d ( 1,0,0 ) ); //沿 X 轴旋转 pitch -
+    Eigen::Quaterniond q_zyx = r_z*r_y*r_x; //ZYX旋转顺序(绕旋转后的轴接着旋转)
+    // 四元数-->>旋转矩阵
+    rotation_matrix = q_zyx.toRotationMatrix();
+    trans_matrix << 0, 1.1, 0.35;//x,y,z
     gpa = iv::modulecomm::RegisterRecv(gstrinput.data(),ListenPointCloud);
     gpdetect = iv::modulecomm::RegisterSend(gstroutput.data(), 10000000,1);
     gpthread = new std::thread(statethread);

+ 36 - 82
src/detection/detection_lidar_PointPillars_MultiHead/pointpillars.cc

@@ -224,13 +224,28 @@ void PointPillars::DeviceMemoryMalloc() {
 
     GPU_CHECK(cudaMalloc(&rpn_buffers_[0],  kRpnInputSize * sizeof(float)));
 
-    GPU_CHECK(cudaMalloc(&rpn_buffers_[1],  kNumAnchorPerCls  * sizeof(float)));  //classes
-    GPU_CHECK(cudaMalloc(&rpn_buffers_[2],  kNumAnchorPerCls  * 2 * 2 * sizeof(float)));
-    GPU_CHECK(cudaMalloc(&rpn_buffers_[3],  kNumAnchorPerCls  * 2 * 2 * sizeof(float)));
-    GPU_CHECK(cudaMalloc(&rpn_buffers_[4],  kNumAnchorPerCls  * sizeof(float)));
-    GPU_CHECK(cudaMalloc(&rpn_buffers_[5],  kNumAnchorPerCls  * 2 * 2 * sizeof(float)));
-    GPU_CHECK(cudaMalloc(&rpn_buffers_[6],  kNumAnchorPerCls  * 2 * 2 * sizeof(float)));
-    
+
+    if(kNumClass == 10)
+    {
+////class = 10
+        GPU_CHECK(cudaMalloc(&rpn_buffers_[1],  kNumAnchorPerCls  * sizeof(float)));  //classes
+        GPU_CHECK(cudaMalloc(&rpn_buffers_[2],  kNumAnchorPerCls  * 2 * 2 * sizeof(float)));
+        GPU_CHECK(cudaMalloc(&rpn_buffers_[3],  kNumAnchorPerCls  * 2 * 2 * sizeof(float)));
+        GPU_CHECK(cudaMalloc(&rpn_buffers_[4],  kNumAnchorPerCls  * sizeof(float)));
+        GPU_CHECK(cudaMalloc(&rpn_buffers_[5],  kNumAnchorPerCls  * 2 * 2 * sizeof(float)));
+        GPU_CHECK(cudaMalloc(&rpn_buffers_[6],  kNumAnchorPerCls  * 2 * 2 * sizeof(float)));
+    }
+    else
+    {
+////class = 7
+        GPU_CHECK(cudaMalloc(&rpn_buffers_[1],  kNumAnchorPerCls  * sizeof(float)));  //classes
+        GPU_CHECK(cudaMalloc(&rpn_buffers_[2],  kNumAnchorPerCls  * sizeof(float)));
+        GPU_CHECK(cudaMalloc(&rpn_buffers_[3],  kNumAnchorPerCls  * sizeof(float)));
+        GPU_CHECK(cudaMalloc(&rpn_buffers_[4],  kNumAnchorPerCls  * sizeof(float)));
+        GPU_CHECK(cudaMalloc(&rpn_buffers_[5],  kNumAnchorPerCls  * sizeof(float)));
+        GPU_CHECK(cudaMalloc(&rpn_buffers_[6],  kNumAnchorPerCls  * 2 * 2 * sizeof(float)));
+    }
+
     GPU_CHECK(cudaMalloc(&rpn_buffers_[7],  kNumAnchorPerCls * kNumClass * kNumOutputBoxFeature * sizeof(float))); //boxes
 
     // for scatter kernel
@@ -283,33 +298,13 @@ void PointPillars::SetDeviceMemoryToZero() {
     GPU_CHECK(cudaMemset(dev_filter_count_,     0, kNumClass * sizeof(int)));
 }
 
-
-#include <fstream>
-#include <iostream>
-#
-
-void PointPillars::SaveEngine(nvinfer1::ICudaEngine* pengine,std::string strpath)
-{
-    nvinfer1::IHostMemory* data = pengine->serialize();
-    std::ofstream file;
-    file.open(strpath,std::ios::binary | std::ios::out);
-    if(!file.is_open())
-    {
-        std::cout << "read create engine file" << strpath <<" failed" << std::endl;
-        return;
-    }
-
-    file.write((const char*)data->data(), data->size());
-    file.close();
-}
-
 void PointPillars::InitTRT(const bool use_onnx) {
   if (use_onnx_) {
     // create a TensorRT model from the onnx model and load it into an engine
     OnnxToTRTModel(pfe_file_, &pfe_engine_);
-    SaveEngine(pfe_engine_,"/home/nvidia/models/lidar/cbgs_pp_multihead_pfe.trt");
+    SaveEngine(pfe_engine_, pfe_file_.substr(0, pfe_file_.find(".")) + ".trt");
     OnnxToTRTModel(backbone_file_, &backbone_engine_);
-    SaveEngine(backbone_engine_,"/home/nvidia/models/lidar/cbgs_pp_multihead_backbone.trt");
+    SaveEngine(backbone_engine_, backbone_file_.substr(0, backbone_file_.find(".")) + ".trt");
   }else {
     EngineToTRTModel(pfe_file_, &pfe_engine_);
     EngineToTRTModel(backbone_file_, &backbone_engine_);
@@ -363,58 +358,19 @@ void PointPillars::OnnxToTRTModel(
     builder->destroy();
 }
 
-void PointPillars::LoadEngineModel(const string &engine_file, nvinfer1::ICudaEngine **engine_ptr)
+void PointPillars::SaveEngine(const nvinfer1::ICudaEngine* engine, const std::string& engine_filepath)
 {
-//    using namespace std;
-//    fstream file;
-
-//    file.open(engine_file,ios::binary | ios::in);
-//    if(!file.is_open())
-//    {
-//        cout << "read engine file" << engine_file <<" failed" << endl;
-//        return;
-//    }
-//    file.seekg(0, ios::end);
-//    int length = file.tellg();
-//    file.seekg(0, ios::beg);
-//    std::unique_ptr<char[]> data(new char[length]);
-//    file.read(data.get(), length);
-
-//    file.close();
-
-//    std::cout << "deserializing" << std::endl;
-//    mTrtRunTime = createInferRuntime(gLogger);
-//    assert(mTrtRunTime != nullptr);
-//    mTrtEngine= mTrtRunTime->deserializeCudaEngine(data.get(), length, &mTrtPluginFactory);
-//    assert(mTrtEngine != nullptr);
-
-//    nvinfer1::IRuntime* runtime = nvinfer1::createInferRuntime(g_logger_);
-
-//    if (runtime == nullptr) {
-//        std::string msg("failed to build runtime parser");
-//        g_logger_.log(nvinfer1::ILogger::Severity::kERROR, msg.c_str());
-//        exit(EXIT_FAILURE);
-//    }
-
-
-
-//    std::cout << "                                                                  "<< std::endl;
-//    std::cout << "------------------------------------------------------------------"<< std::endl;
-//    std::cout << ">>>>                                                          >>>>"<< std::endl;
-//    std::cout << "                                                                  "<< std::endl;
-//    std::cout << "Input filename:   " << engine_file << std::endl;
-//    std::cout << "                                                                  "<< std::endl;
-//    std::cout << ">>>>                                                          >>>>"<< std::endl;
-//    std::cout << "------------------------------------------------------------------"<< std::endl;
-//    std::cout << "                                                                  "<< std::endl;
-
-//    nvinfer1::ICudaEngine* engine = runtime->deserializeCudaEngine(modelMem, modelSize, NULL);
-//    if (engine == nullptr) {
-//        std::string msg("failed to build engine parser");
-//        g_logger_.log(nvinfer1::ILogger::Severity::kERROR, msg.c_str());
-//        exit(EXIT_FAILURE);
-//    }
-//    *engine_ptr = engine;
+    // serialize the engine, then close everything down
+    nvinfer1::IHostMemory& trtModelStream = *(engine->serialize());
+    std::ofstream file;
+    file.open(engine_filepath, std::ios::binary | std::ios::out);
+    if(!file.is_open())
+    {
+        std::cout << "read create engine file" << engine_filepath <<" failed" << std::endl;
+        return;
+    }
+    file.write((const char*)trtModelStream.data(), std::streamsize(trtModelStream.size()));
+    file.close();
 }
 
 void PointPillars::EngineToTRTModel(
@@ -561,8 +517,6 @@ void PointPillars::DoInference(const float* in_points_array,
 //        std::cout << setiosflags(ios::left) << setw(14) << Modules[i]  << setw(8)  << Times[i] * 1000 << " ms" << resetiosflags(ios::left) << std::endl;
 //    }
 //    std::cout << "------------------------------------" << std::endl;
-
-    GPU_CHECK(cudaFree(dev_points));
     cudaStreamDestroy(stream);
 
 }

+ 1 - 5
src/detection/detection_lidar_PointPillars_MultiHead/pointpillars.h

@@ -225,6 +225,7 @@ class PointPillars {
      * @details Called in the constructor
      */
     void InitTRT(const bool use_onnx);
+    void SaveEngine(const nvinfer1::ICudaEngine* engine, const std::string& engine_filepath);
     /**
      * @brief Convert ONNX to TensorRT model
      * @param[in] model_file ONNX model file path
@@ -243,9 +244,6 @@ class PointPillars {
     void EngineToTRTModel(const std::string &engine_file ,     
                         nvinfer1::ICudaEngine** engine_ptr) ;
 
-    void LoadEngineModel(const std::string &engine_file ,
-                         nvinfer1::ICudaEngine** engine_ptr) ;
-
     /**
      * @brief Preproces points
      * @param[in] in_points_array Point cloud array
@@ -272,8 +270,6 @@ class PointPillars {
                 const std::string pp_config);
     ~PointPillars();
 
-    void SaveEngine(nvinfer1::ICudaEngine* pengine,std::string strpath);
-
     /**
      * @brief Call PointPillars for the inference
      * @param[in] in_points_array Point cloud array

+ 176 - 45
src/detection/detection_lidar_PointPillars_MultiHead/postprocess.cu

@@ -143,6 +143,7 @@ __global__ void sigmoid_filter_kernel(
     if( cls_score[ threadIdx.x ] > score_threshold) 
     {
         int counter = atomicAdd(&filter_count[blockIdx.z], 1);
+        //printf("counter : %d \n" , counter);
         if ( blockIdx.z == 0) {
             box_decode_warp(0 ,box_pred_0 , tid , num_anchors_per_head , counter , filtered_box);
             filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
@@ -188,38 +189,139 @@ __global__ void sigmoid_filter_kernel(
     __syncthreads();  
     if( cls_score[ threadIdx.x + blockDim.x ] > score_threshold)  {     
             int counter = atomicAdd(&filter_count[blockIdx.z], 1);
-            // printf("counter : %d \n" , counter);
+            //printf("counter : %d \n" , counter);
             if (blockIdx.z == 1) {
                 box_decode_warp(0 ,box_pred_2 , tid , num_anchors_per_head , counter , filtered_box);
-                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
+                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x + blockDim.x];
             }else 
             if (blockIdx.z == 2) {
                 box_decode_warp(0 ,box_pred_2 , tid , num_anchors_per_head , counter , filtered_box);
-                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
+                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x + blockDim.x];
             }else 
             if (blockIdx.z == 3) {
                 box_decode_warp(0 ,box_pred_4 , tid , num_anchors_per_head , counter , filtered_box);
-                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
+                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x + blockDim.x];
             }else 
             if (blockIdx.z == 4) {
                 box_decode_warp(0 ,box_pred_4 , tid , num_anchors_per_head , counter , filtered_box);
-                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
+                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x + blockDim.x];
             }else 
             if (blockIdx.z == 6) {
                 box_decode_warp(0 ,box_pred_7 , tid , num_anchors_per_head , counter , filtered_box);
-                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
+                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x + blockDim.x];
             }else 
             if (blockIdx.z == 7) {
                 box_decode_warp(0 ,box_pred_7 , tid , num_anchors_per_head , counter , filtered_box);
-                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
+                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x + blockDim.x];
             }else 
             if (blockIdx.z == 8) {
                 box_decode_warp(0 ,box_pred_9 , tid , num_anchors_per_head , counter , filtered_box);
-                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
+                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x + blockDim.x];
             }else 
             if (blockIdx.z == 9) {
                 box_decode_warp(0 ,box_pred_9 , tid , num_anchors_per_head , counter , filtered_box);
-                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
+                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x + blockDim.x];
+            }
+    }
+}
+
+__global__ void sigmoid_filter_kernel(
+
+    float* cls_pred_0,
+    float* cls_pred_1,
+    float* cls_pred_2,
+    float* cls_pred_3,
+    float* cls_pred_4,
+    float* cls_pred_56,
+
+    const float* box_pred_0,
+
+    const float* box_pred_1,
+
+    const float* box_pred_2,
+
+    const float* box_pred_3,
+
+    const float* box_pred_4,
+
+    const float* box_pred_5,
+    const float* box_pred_6,
+
+
+    float* filtered_box,
+    float* filtered_score,
+    int* filter_count,
+
+    const float score_threshold) {
+
+    // cls_pred_34
+    // 32768*2 , 2
+
+    int num_anchors_per_head = gridDim.x * gridDim.y * blockDim.x;
+    // 16 * 4 * 512 = 32768
+    extern __shared__ float cls_score[];
+    cls_score[threadIdx.x + blockDim.x] = -1.0f;
+
+    int tid = blockIdx.x * gridDim.y * blockDim.x + blockIdx.y *  blockDim.x + threadIdx.x;
+
+
+    if ( blockIdx.z == 0) cls_score[ threadIdx.x ] = 1 / (1 + expf(-cls_pred_0[ tid ]));
+    if ( blockIdx.z == 1) cls_score[ threadIdx.x ] = 1 / (1 + expf(-cls_pred_1[ tid ]));
+    if ( blockIdx.z == 2) cls_score[ threadIdx.x ] = 1 / (1 + expf(-cls_pred_2[ tid ]));
+    if ( blockIdx.z == 3) cls_score[ threadIdx.x ] = 1 / (1 + expf(-cls_pred_3[ tid ]));
+    if ( blockIdx.z == 4) cls_score[ threadIdx.x ] = 1 / (1 + expf(-cls_pred_4[ tid ]));
+    if ( blockIdx.z == 5) {
+        cls_score[ threadIdx.x ] = 1 / (1 + expf(-cls_pred_56[ tid * 2 ]));
+        cls_score[ threadIdx.x + blockDim.x] = 1 / (1 + expf(-cls_pred_56[ (num_anchors_per_head + tid) * 2]));}
+    if ( blockIdx.z == 6) {
+        cls_score[ threadIdx.x ] = 1 / (1 + expf(-cls_pred_56[ tid * 2 + 1 ]));
+        cls_score[ threadIdx.x + blockDim.x] = 1 / (1 + expf(-cls_pred_56[ (num_anchors_per_head + tid) * 2 + 1]));}
+
+    __syncthreads();
+
+    if( cls_score[ threadIdx.x ] > score_threshold)
+    {
+        int counter = atomicAdd(&filter_count[blockIdx.z], 1);
+        if ( blockIdx.z == 0) {
+            box_decode_warp(0 ,box_pred_0 , tid , num_anchors_per_head , counter , filtered_box);
+            filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
+        }else
+        if ( blockIdx.z == 1) {
+            box_decode_warp(0 ,box_pred_1 , tid , num_anchors_per_head , counter , filtered_box);
+            filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
+        }else
+        if ( blockIdx.z == 2) {
+            box_decode_warp(0 ,box_pred_2 , tid , num_anchors_per_head , counter , filtered_box);
+            filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
+        }else
+        if ( blockIdx.z == 3) {
+            box_decode_warp(0 ,box_pred_3 , tid , num_anchors_per_head , counter , filtered_box);
+            filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
+        }else
+        if (blockIdx.z == 4) {
+            box_decode_warp(0 ,box_pred_4 , tid , num_anchors_per_head , counter , filtered_box);
+            filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
+        }else
+        if ( blockIdx.z == 5) {
+            box_decode_warp(0 ,box_pred_5 , tid , num_anchors_per_head , counter , filtered_box);
+            filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
+        }else
+        if ( blockIdx.z == 6) {
+            box_decode_warp(0 ,box_pred_5 , tid , num_anchors_per_head , counter , filtered_box);
+            filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
+        }
+    }
+    __syncthreads();
+    if( cls_score[ threadIdx.x + blockDim.x ] > score_threshold)  {
+            int counter = atomicAdd(&filter_count[blockIdx.z], 1);
+            // printf("counter : %d \n" , counter);
+            if (blockIdx.z == 5) {
+                box_decode_warp(0 ,box_pred_6 , tid , num_anchors_per_head , counter , filtered_box);
+                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x + blockDim.x];
+            }else
+            if (blockIdx.z == 6) {
+                box_decode_warp(0 ,box_pred_6 , tid , num_anchors_per_head , counter , filtered_box);
+                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x + blockDim.x];
             }
     }
 }
@@ -290,31 +392,62 @@ void PostprocessCuda::DoPostprocessCuda(
     std::vector<float>& out_detection, std::vector<int>& out_label , std::vector<float>& out_score) {
     // 在此之前,先进行rpn_box_output的concat. 
     // 128x128 的feature map, cls_pred 的shape为(32768,1),(32768,1),(32768,1),(65536,2),(32768,1)
-    dim3 gridsize(16, 4 , 10);  //16 *  4  * 512  = 32768 代表一个head的anchors
-    sigmoid_filter_kernel<<< gridsize, 512 , 512 * 2 * sizeof(float)>>>(
-        cls_pred_0,
-        cls_pred_12, 
-        cls_pred_34, 
-        cls_pred_5, 
-        cls_pred_67, 
-        cls_pred_89,
-
-        &box_preds[0 * 32768 * 9],
-        &box_preds[1 * 32768 * 9],
-        &box_preds[2 * 32768 * 9],
-        &box_preds[3 * 32768 * 9],
-        &box_preds[4 * 32768 * 9],
-        &box_preds[5 * 32768 * 9],
-        &box_preds[6 * 32768 * 9],
-        &box_preds[7 * 32768 * 9],
-        &box_preds[8 * 32768 * 9],
-        &box_preds[9 * 32768 * 9],
-
-        dev_filtered_box, 
-        dev_filtered_score,  
-        dev_filter_count, 
-    
-        score_threshold_);
+
+//////class = 10
+    if(num_class_ == 10)
+    {
+        dim3 gridsize(16, 4 , 10);  //16 *  4  * 512  = 32768 代表一个head的anchors
+        sigmoid_filter_kernel<<< gridsize, 512 , 512 * 2 * sizeof(float)>>>(
+            cls_pred_0,
+            cls_pred_12,
+            cls_pred_34,
+            cls_pred_5,
+            cls_pred_67,
+            cls_pred_89,
+
+            &box_preds[0 * 32768 * 9],
+            &box_preds[1 * 32768 * 9],
+            &box_preds[2 * 32768 * 9],
+            &box_preds[3 * 32768 * 9],
+            &box_preds[4 * 32768 * 9],
+            &box_preds[5 * 32768 * 9],
+            &box_preds[6 * 32768 * 9],
+            &box_preds[7 * 32768 * 9],
+            &box_preds[8 * 32768 * 9],
+            &box_preds[9 * 32768 * 9],
+
+            dev_filtered_box,
+            dev_filtered_score,
+            dev_filter_count,
+
+            score_threshold_);
+    }
+    else
+    {
+        ////class = 7
+            dim3 gridsize(16, 4 , 7);  //16 *  4  * 512  = 32768 代表一个head的anchors
+            sigmoid_filter_kernel<<< gridsize, 512 , 512 * 2 * sizeof(float)>>>(
+                 cls_pred_0,
+                 cls_pred_12,
+                 cls_pred_34,
+                 cls_pred_5,
+                 cls_pred_67,
+                 cls_pred_89,
+                 &box_preds[0 * 32768 * 9],
+                 &box_preds[1 * 32768 * 9],
+                 &box_preds[2 * 32768 * 9],
+                 &box_preds[3 * 32768 * 9],
+                 &box_preds[4 * 32768 * 9],
+                 &box_preds[5 * 32768 * 9],
+                 &box_preds[6 * 32768 * 9],
+
+                 dev_filtered_box,
+                 dev_filtered_score,
+                 dev_filter_count,
+
+                 score_threshold_);
+    }
+
     cudaDeviceSynchronize();
     
     int host_filter_count[num_class_] = {0};
@@ -362,17 +495,16 @@ void PostprocessCuda::DoPostprocessCuda(
 
         cudaMemcpy(host_filtered_box, dev_sorted_filtered_box, host_filter_count[i] * num_output_box_feature_ * sizeof(float), cudaMemcpyDeviceToHost);
         cudaMemcpy(host_filtered_scores, dev_sorted_filtered_scores, host_filter_count[i] * sizeof(float), cudaMemcpyDeviceToHost);
-        for (int i = 0; i < num_out; ++i)  {
-            out_detection.emplace_back(host_filtered_box[keep_inds[i] * num_output_box_feature_ + 0]);
-            out_detection.emplace_back(host_filtered_box[keep_inds[i] * num_output_box_feature_ + 1]);
-            out_detection.emplace_back(host_filtered_box[keep_inds[i] * num_output_box_feature_ + 2]);
-            out_detection.emplace_back(host_filtered_box[keep_inds[i] * num_output_box_feature_ + 3]);
-            out_detection.emplace_back(host_filtered_box[keep_inds[i] * num_output_box_feature_ + 4]);
-            out_detection.emplace_back(host_filtered_box[keep_inds[i] * num_output_box_feature_ + 5]);
-            out_detection.emplace_back(host_filtered_box[keep_inds[i] * num_output_box_feature_ + 6]);
-            out_score.emplace_back(host_filtered_scores[keep_inds[i]]);
+        for (int j = 0; j < num_out; ++j)  {
+            out_detection.emplace_back(host_filtered_box[keep_inds[j] * num_output_box_feature_ + 0]);
+            out_detection.emplace_back(host_filtered_box[keep_inds[j] * num_output_box_feature_ + 1]);
+            out_detection.emplace_back(host_filtered_box[keep_inds[j] * num_output_box_feature_ + 2]);
+            out_detection.emplace_back(host_filtered_box[keep_inds[j] * num_output_box_feature_ + 3]);
+            out_detection.emplace_back(host_filtered_box[keep_inds[j] * num_output_box_feature_ + 4]);
+            out_detection.emplace_back(host_filtered_box[keep_inds[j] * num_output_box_feature_ + 5]);
+            out_detection.emplace_back(host_filtered_box[keep_inds[j] * num_output_box_feature_ + 6]);
+            out_score.emplace_back(host_filtered_scores[keep_inds[j]]);
             out_label.emplace_back(i);
-
         }
         delete[] keep_inds;
         delete[] host_filtered_scores;
@@ -380,6 +512,5 @@ void PostprocessCuda::DoPostprocessCuda(
 
         GPU_CHECK(cudaFree(dev_indexes));
         GPU_CHECK(cudaFree(dev_sorted_filtered_box));
-        GPU_CHECK(cudaFree(dev_sorted_filtered_scores));
     }
 }

+ 25 - 0
src/detection/detection_lidar_PointPillars_MultiHead/roiaware_pool3d.h

@@ -0,0 +1,25 @@
+/*
+RoI-aware point cloud feature pooling
+Reference paper:  https://arxiv.org/abs/1907.03670
+Written by Shaoshuai Shi
+All Rights Reserved 2019-2020.
+*/
+
+
+#include <assert.h>
+
+
+//#define CHECK_CUDA(x) AT_CHECK(x.type().is_cuda(), #x, " must be a CUDAtensor ")
+//#define CHECK_CONTIGUOUS(x) AT_CHECK(x.is_contiguous(), #x, " must be contiguous ")
+//#define CHECK_INPUT(x) CHECK_CUDA(x);CHECK_CONTIGUOUS(x)
+
+
+void roiaware_pool3d_launcher(int boxes_num, int pts_num, int channels, int max_pts_each_voxel,
+    int out_x, int out_y, int out_z, const float *rois, const float *pts, const float *pts_feature,
+    int *argmax, int *pts_idx_of_voxels, float *pooled_features, int pool_method);
+
+void roiaware_pool3d_backward_launcher(int boxes_num, int out_x, int out_y, int out_z, int channels, int max_pts_each_voxel,
+    const int *pts_idx_of_voxels, const int *argmax, const float *grad_out, float *grad_in, int pool_method);
+
+void points_in_boxes_launcher(int batch_size, int boxes_num, int pts_num, const float *boxes,
+    const float *pts, int *box_idx_of_points);

+ 361 - 0
src/detection/detection_lidar_PointPillars_MultiHead/roiaware_pool3d_kernel.cu

@@ -0,0 +1,361 @@
+/*
+RoI-aware point cloud feature pooling
+Written by Shaoshuai Shi
+All Rights Reserved 2019-2020.
+*/
+
+
+#include <math.h>
+#include <stdio.h>
+
+#include "roiaware_pool3d.h"
+
+#define THREADS_PER_BLOCK 256
+#define DIVUP(m,n) ((m) / (n) + ((m) % (n) > 0))
+// #define DEBUG
+
+
+__device__ inline void lidar_to_local_coords(float shift_x, float shift_y, float rot_angle, float &local_x, float &local_y){
+    float cosa = cos(-rot_angle), sina = sin(-rot_angle);
+    local_x = shift_x * cosa + shift_y * (-sina);
+    local_y = shift_x * sina + shift_y * cosa;
+}
+
+
+__device__ inline int check_pt_in_box3d(const float *pt, const float *box3d, float &local_x, float &local_y){
+    // param pt: (x, y, z)
+    // param box3d: [x, y, z, dx, dy, dz, heading] (x, y, z) is the box center
+
+    const float MARGIN = 1e-5;
+    float x = pt[0], y = pt[1], z = pt[2];
+    float cx = box3d[0], cy = box3d[1], cz = box3d[2];
+    float dx = box3d[3], dy = box3d[4], dz = box3d[5], rz = box3d[6];
+
+    if (fabsf(z - cz) > dz / 2.0) return 0;
+    lidar_to_local_coords(x - cx, y - cy, rz, local_x, local_y);
+    float in_flag = (fabs(local_x) < dx / 2.0 + MARGIN) & (fabs(local_y) < dy / 2.0 + MARGIN);
+    return in_flag;
+}
+
+
+__global__ void generate_pts_mask_for_box3d(int boxes_num, int pts_num, int out_x, int out_y, int out_z,
+    const float *rois, const float *pts, int *pts_mask){
+    // params rois: [x, y, z, dx, dy, dz, heading] (x, y, z) is the box center
+    // params pts: (npoints, 3) [x, y, z]
+    // params pts_mask: (N, npoints): -1 means point doesnot in this box, otherwise: encode (x_idxs, y_idxs, z_idxs) by binary bit
+    int pt_idx = blockIdx.x * blockDim.x + threadIdx.x;
+    int box_idx = blockIdx.y;
+    if (pt_idx >= pts_num || box_idx >= boxes_num) return;
+
+    pts += pt_idx * 3;
+    rois += box_idx * 7;
+    pts_mask += box_idx * pts_num + pt_idx;
+
+    float local_x = 0, local_y = 0;
+    int cur_in_flag = check_pt_in_box3d(pts, rois, local_x, local_y);
+
+    pts_mask[0] = -1;
+    if (cur_in_flag > 0){
+        float local_z = pts[2] - rois[2];
+        float dx = rois[3], dy = rois[4], dz = rois[5];
+
+        float x_res = dx / out_x;
+        float y_res = dy / out_y;
+        float z_res = dz / out_z;
+
+        unsigned int x_idx = int((local_x + dx / 2) / x_res);
+        unsigned int y_idx = int((local_y + dy / 2) / y_res);
+        unsigned int z_idx = int((local_z + dz / 2) / z_res);
+
+        x_idx = min(max(x_idx, 0), out_x - 1);
+        y_idx = min(max(y_idx, 0), out_y - 1);
+        z_idx = min(max(z_idx, 0), out_z - 1);
+
+        unsigned int idx_encoding = (x_idx << 16) + (y_idx << 8) + z_idx;
+        pts_mask[0] = idx_encoding;
+    }
+}
+
+
+__global__ void collect_inside_pts_for_box3d(int boxes_num, int pts_num, int max_pts_each_voxel,
+    int out_x, int out_y, int out_z, const int *pts_mask, int *pts_idx_of_voxels){
+    // params pts_mask: (N, npoints)  0 or 1
+    // params pts_idx_of_voxels: (N, out_x, out_y, out_z, max_pts_each_voxel)
+
+    int box_idx = blockIdx.x * blockDim.x + threadIdx.x;
+    if (box_idx >= boxes_num) return;
+
+    int max_num_pts = max_pts_each_voxel - 1;  // index 0 is the counter
+    pts_idx_of_voxels += box_idx * out_x * out_y * out_z * max_pts_each_voxel;
+
+    for (int k = 0; k < pts_num; k++){
+        if (pts_mask[box_idx * pts_num + k] != -1){
+            unsigned int idx_encoding = pts_mask[box_idx * pts_num + k];
+            unsigned int x_idx = (idx_encoding >> 16) & 0xFF;
+            unsigned int y_idx = (idx_encoding >> 8) & 0xFF;
+            unsigned int z_idx = idx_encoding & 0xFF;
+            unsigned int base_offset = x_idx * out_y * out_z * max_pts_each_voxel + y_idx * out_z * max_pts_each_voxel + z_idx * max_pts_each_voxel;
+            unsigned int cnt = pts_idx_of_voxels[base_offset];
+            if (cnt < max_num_pts){
+                pts_idx_of_voxels[base_offset + cnt + 1] = k;
+                pts_idx_of_voxels[base_offset]++;
+            }
+#ifdef DEBUG
+        printf("collect: pts_%d, idx(%d, %d, %d), idx_encoding=%x\n",
+            k, x_idx, y_idx, z_idx, idx_encoding);
+#endif
+
+        }
+    }
+}
+
+
+__global__ void roiaware_maxpool3d(int boxes_num, int pts_num, int channels, int max_pts_each_voxel, int out_x,
+    int out_y, int out_z, const float *pts_feature, const int *pts_idx_of_voxels, float *pooled_features, int *argmax){
+    // params pts_feature: (npoints, C)
+    // params pts_idx_of_voxels: (N, out_x, out_y, out_z, max_pts_each_voxel), index 0 is the counter
+    // params pooled_features: (N, out_x, out_y, out_z, C)
+    // params argmax: (N, out_x, out_y, out_z, C)
+
+    int box_idx = blockIdx.z;
+    int channel_idx = blockIdx.y;
+    int voxel_idx_flat = blockIdx.x * blockDim.x + threadIdx.x;
+
+    int x_idx = voxel_idx_flat / (out_y * out_z);
+    int y_idx = (voxel_idx_flat - x_idx * (out_y * out_z)) / out_z;
+    int z_idx = voxel_idx_flat % out_z;
+    if (box_idx >= boxes_num || channel_idx >= channels|| x_idx >= out_x || y_idx >= out_y || z_idx >= out_z) return;
+
+#ifdef DEBUG
+    printf("src pts_idx_of_voxels: (%p, ), argmax: %p\n", pts_idx_of_voxels, argmax);
+#endif
+
+    int offset_base = x_idx * out_y * out_z + y_idx * out_z + z_idx;
+    pts_idx_of_voxels += box_idx * out_x * out_y * out_z * max_pts_each_voxel + offset_base * max_pts_each_voxel;
+    pooled_features += box_idx * out_x * out_y * out_z * channels + offset_base * channels + channel_idx;
+    argmax += box_idx * out_x * out_y * out_z * channels + offset_base * channels + channel_idx;
+
+    int argmax_idx = -1;
+    float max_val = -1e50;
+
+    int total_pts = pts_idx_of_voxels[0];
+
+    for (int k = 1; k <= total_pts; k++){
+        if (pts_feature[pts_idx_of_voxels[k] * channels + channel_idx] > max_val){
+            max_val = pts_feature[pts_idx_of_voxels[k] * channels + channel_idx];
+            argmax_idx = pts_idx_of_voxels[k];
+        }
+    }
+
+    if (argmax_idx != -1){
+        pooled_features[0] = max_val;
+    }
+    argmax[0] = argmax_idx;
+
+#ifdef DEBUG
+    printf("channel_%d idx(%d, %d, %d), argmax_idx=(%d, %.3f), total=%d, after pts_idx: %p, argmax: (%p, %d)\n",
+        channel_idx, x_idx, y_idx, z_idx, argmax_idx, max_val, total_pts, pts_idx_of_voxels, argmax, argmax_idx);
+#endif
+}
+
+
+__global__ void roiaware_avgpool3d(int boxes_num, int pts_num, int channels, int max_pts_each_voxel, int out_x,
+    int out_y, int out_z, const float *pts_feature, const int *pts_idx_of_voxels, float *pooled_features){
+    // params pts_feature: (npoints, C)
+    // params pts_idx_of_voxels: (N, out_x, out_y, out_z, max_pts_each_voxel), index 0 is the counter
+    // params pooled_features: (N, out_x, out_y, out_z, C)
+    // params argmax: (N, out_x, out_y, out_z, C)
+
+    int box_idx = blockIdx.z;
+    int channel_idx = blockIdx.y;
+    int voxel_idx_flat = blockIdx.x * blockDim.x + threadIdx.x;
+
+    int x_idx = voxel_idx_flat / (out_y * out_z);
+    int y_idx = (voxel_idx_flat - x_idx * (out_y * out_z)) / out_z;
+    int z_idx = voxel_idx_flat % out_z;
+    if (box_idx >= boxes_num || channel_idx >= channels|| x_idx >= out_x || y_idx >= out_y || z_idx >= out_z) return;
+
+    int offset_base = x_idx * out_y * out_z + y_idx * out_z + z_idx;
+    pts_idx_of_voxels += box_idx * out_x * out_y * out_z * max_pts_each_voxel + offset_base * max_pts_each_voxel;
+    pooled_features += box_idx * out_x * out_y * out_z * channels + offset_base * channels + channel_idx;
+
+    float sum_val = 0;
+    int total_pts = pts_idx_of_voxels[0];
+
+    for (int k = 1; k <= total_pts; k++){
+        sum_val += pts_feature[pts_idx_of_voxels[k] * channels + channel_idx];
+    }
+
+    if (total_pts > 0){
+        pooled_features[0] = sum_val / total_pts;
+    }
+}
+
+
+void roiaware_pool3d_launcher(int boxes_num, int pts_num, int channels, int max_pts_each_voxel, int out_x, int out_y, int out_z,
+    const float *rois, const float *pts, const float *pts_feature, int *argmax, int *pts_idx_of_voxels, float *pooled_features, int pool_method){
+    // params rois: (N, 7) [x, y, z, dx, dy, dz, heading] (x, y, z) is the box center
+    // params pts: (npoints, 3) [x, y, z]
+    // params pts_feature: (npoints, C)
+    // params argmax: (N, out_x, out_y, out_z, C)
+    // params pts_idx_of_voxels: (N, out_x, out_y, out_z, max_pts_each_voxel)
+    // params pooled_features: (N, out_x, out_y, out_z, C)
+    // params pool_method: 0: max_pool 1: avg_pool
+
+    int *pts_mask = NULL;
+    cudaMalloc(&pts_mask, boxes_num * pts_num * sizeof(int));  // (N, M)
+    cudaMemset(pts_mask, -1, boxes_num * pts_num * sizeof(int));
+
+    dim3 blocks_mask(DIVUP(pts_num, THREADS_PER_BLOCK), boxes_num);
+    dim3 threads(THREADS_PER_BLOCK);
+    generate_pts_mask_for_box3d<<<blocks_mask, threads>>>(boxes_num, pts_num, out_x, out_y, out_z, rois, pts, pts_mask);
+
+    // TODO: Merge the collect and pool functions, SS
+
+    dim3 blocks_collect(DIVUP(boxes_num, THREADS_PER_BLOCK));
+    collect_inside_pts_for_box3d<<<blocks_collect, threads>>>(boxes_num, pts_num, max_pts_each_voxel,
+        out_x, out_y, out_z, pts_mask, pts_idx_of_voxels);
+
+    dim3 blocks_pool(DIVUP(out_x * out_y * out_z, THREADS_PER_BLOCK), channels, boxes_num);
+    if (pool_method == 0){
+        roiaware_maxpool3d<<<blocks_pool, threads>>>(boxes_num, pts_num, channels, max_pts_each_voxel, out_x, out_y, out_z,
+            pts_feature, pts_idx_of_voxels, pooled_features, argmax);
+    }
+    else if (pool_method == 1){
+        roiaware_avgpool3d<<<blocks_pool, threads>>>(boxes_num, pts_num, channels, max_pts_each_voxel, out_x, out_y, out_z,
+            pts_feature, pts_idx_of_voxels, pooled_features);
+    }
+
+
+    cudaFree(pts_mask);
+
+#ifdef DEBUG
+    cudaDeviceSynchronize();  // for using printf in kernel function
+#endif
+}
+
+
+__global__ void roiaware_maxpool3d_backward(int boxes_num, int channels, int out_x, int out_y, int out_z,
+    const int *argmax, const float *grad_out, float *grad_in){
+    // params argmax: (N, out_x, out_y, out_z, C)
+    // params grad_out: (N, out_x, out_y, out_z, C)
+    // params grad_in: (npoints, C), return value
+
+    int box_idx = blockIdx.z;
+    int channel_idx = blockIdx.y;
+    int voxel_idx_flat = blockIdx.x * blockDim.x + threadIdx.x;
+
+    int x_idx = voxel_idx_flat / (out_y * out_z);
+    int y_idx = (voxel_idx_flat - x_idx * (out_y * out_z)) / out_z;
+    int z_idx = voxel_idx_flat % out_z;
+    if (box_idx >= boxes_num || channel_idx >= channels|| x_idx >= out_x || y_idx >= out_y || z_idx >= out_z) return;
+
+    int offset_base = x_idx * out_y * out_z + y_idx * out_z + z_idx;
+    argmax += box_idx * out_x * out_y * out_z * channels + offset_base * channels + channel_idx;
+    grad_out += box_idx * out_x * out_y * out_z * channels + offset_base * channels + channel_idx;
+
+    if (argmax[0] == -1) return;
+
+    atomicAdd(grad_in + argmax[0] * channels + channel_idx, grad_out[0] * 1);
+}
+
+
+__global__ void roiaware_avgpool3d_backward(int boxes_num, int channels, int out_x, int out_y, int out_z,
+    int max_pts_each_voxel, const int *pts_idx_of_voxels, const float *grad_out, float *grad_in){
+    // params pts_idx_of_voxels: (N, out_x, out_y, out_z, max_pts_each_voxel)
+    // params grad_out: (N, out_x, out_y, out_z, C)
+    // params grad_in: (npoints, C), return value
+
+    int box_idx = blockIdx.z;
+    int channel_idx = blockIdx.y;
+    int voxel_idx_flat = blockIdx.x * blockDim.x + threadIdx.x;
+
+    int x_idx = voxel_idx_flat / (out_y * out_z);
+    int y_idx = (voxel_idx_flat - x_idx * (out_y * out_z)) / out_z;
+    int z_idx = voxel_idx_flat % out_z;
+    if (box_idx >= boxes_num || channel_idx >= channels|| x_idx >= out_x || y_idx >= out_y || z_idx >= out_z) return;
+
+    int offset_base = x_idx * out_y * out_z + y_idx * out_z + z_idx;
+    pts_idx_of_voxels += box_idx * out_x * out_y * out_z * max_pts_each_voxel + offset_base * max_pts_each_voxel;
+    grad_out += box_idx * out_x * out_y * out_z * channels + offset_base * channels + channel_idx;
+
+
+    int total_pts = pts_idx_of_voxels[0];
+    float cur_grad = 1 / fmaxf(float(total_pts), 1.0);
+    for (int k = 1; k <= total_pts; k++){
+        atomicAdd(grad_in + pts_idx_of_voxels[k] * channels + channel_idx, grad_out[0] * cur_grad);
+    }
+}
+
+
+void roiaware_pool3d_backward_launcher(int boxes_num, int out_x, int out_y, int out_z, int channels, int max_pts_each_voxel,
+    const int *pts_idx_of_voxels, const int *argmax, const float *grad_out, float *grad_in, int pool_method){
+    // params pts_idx_of_voxels: (N, out_x, out_y, out_z, max_pts_each_voxel)
+    // params argmax: (N, out_x, out_y, out_z, C)
+    // params grad_out: (N, out_x, out_y, out_z, C)
+    // params grad_in: (npoints, C), return value
+    // params pool_method: 0: max_pool, 1: avg_pool
+
+    dim3 blocks(DIVUP(out_x * out_y * out_z, THREADS_PER_BLOCK), channels, boxes_num);
+    dim3 threads(THREADS_PER_BLOCK);
+    if (pool_method == 0){
+        roiaware_maxpool3d_backward<<<blocks, threads>>>(
+            boxes_num, channels, out_x, out_y, out_z, argmax, grad_out, grad_in
+        );
+    }
+    else if (pool_method == 1){
+        roiaware_avgpool3d_backward<<<blocks, threads>>>(
+            boxes_num, channels, out_x, out_y, out_z, max_pts_each_voxel, pts_idx_of_voxels, grad_out, grad_in
+        );
+    }
+
+}
+
+
+__global__ void points_in_boxes_kernel(int batch_size, int boxes_num, int pts_num, const float *boxes,
+    const float *pts, int *box_idx_of_points){
+    // params boxes: (B, N, 7) [x, y, z, dx, dy, dz, heading] (x, y, z) is the box center
+    // params pts: (B, npoints, 3) [x, y, z] in LiDAR coordinate
+    // params boxes_idx_of_points: (B, npoints), default -1
+
+    int bs_idx = blockIdx.y;
+    int pt_idx = blockIdx.x * blockDim.x + threadIdx.x;
+    if (bs_idx >= batch_size || pt_idx >= pts_num) return;
+
+    boxes += bs_idx * boxes_num * 7;
+    pts += bs_idx * pts_num * 5 + pt_idx * 5;
+    box_idx_of_points += bs_idx * pts_num + pt_idx;
+
+    float local_x = 0, local_y = 0;
+    int cur_in_flag = 0;
+    for (int k = 0; k < boxes_num; k++){
+        cur_in_flag = check_pt_in_box3d(pts, boxes + k * 7, local_x, local_y);
+        if (cur_in_flag){
+            box_idx_of_points[0] = k;
+            break;
+        }
+    }
+}
+
+
+void points_in_boxes_launcher(int batch_size, int boxes_num, int pts_num, const float *boxes,
+    const float *pts, int *box_idx_of_points){
+    // params boxes: (B, N, 7) [x, y, z, dx, dy, dz, heading] (x, y, z) is the box center
+    // params pts: (B, npoints, 3) [x, y, z]
+    // params boxes_idx_of_points: (B, npoints), default -1
+    cudaError_t err;
+
+    dim3 blocks(DIVUP(pts_num, THREADS_PER_BLOCK), batch_size);
+    dim3 threads(THREADS_PER_BLOCK);
+    points_in_boxes_kernel<<<blocks, threads>>>(batch_size, boxes_num, pts_num, boxes, pts, box_idx_of_points);
+
+    err = cudaGetLastError();
+    if (cudaSuccess != err) {
+        fprintf(stderr, "CUDA kernel failed : %s\n", cudaGetErrorString(err));
+        exit(-1);
+    }
+
+#ifdef DEBUG
+    cudaDeviceSynchronize();  // for using printf in kernel function
+#endif
+}

+ 0 - 246
src/detection/detection_lidar_PointPillars_MultiHead_1025/cfgs/cbgs_pp_multihead.yaml

@@ -1,246 +0,0 @@
-CLASS_NAMES: ['car','truck', 'construction_vehicle', 'bus', 'trailer',
-              'barrier', 'motorcycle', 'bicycle', 'pedestrian', 'traffic_cone']
-
-DATA_CONFIG:
-    _BASE_CONFIG_: cfgs/dataset_configs/nuscenes_dataset.yaml
-
-    POINT_CLOUD_RANGE: [-51.2, -51.2, -5.0, 51.2, 51.2, 3.0]
-    DATA_PROCESSOR:
-        -   NAME: mask_points_and_boxes_outside_range
-            REMOVE_OUTSIDE_BOXES: True
-
-        -   NAME: shuffle_points
-            SHUFFLE_ENABLED: {
-                'train': True,
-                'test': True
-            }
-
-        -   NAME: transform_points_to_voxels
-            VOXEL_SIZE: [0.2, 0.2, 8.0]
-            MAX_POINTS_PER_VOXEL: 20
-            MAX_NUMBER_OF_VOXELS: {
-                'train': 30000,
-                'test': 30000
-            }
-
-MODEL:
-    NAME: PointPillar
-
-    VFE:
-        NAME: PillarVFE
-        WITH_DISTANCE: False
-        USE_ABSLOTE_XYZ: True
-        USE_NORM: True
-        NUM_FILTERS: [64]
-
-    MAP_TO_BEV:
-        NAME: PointPillarScatter
-        NUM_BEV_FEATURES: 64
-
-    BACKBONE_2D:
-        NAME: BaseBEVBackbone
-        LAYER_NUMS: [3, 5, 5]
-        LAYER_STRIDES: [2, 2, 2]
-        NUM_FILTERS: [64, 128, 256]
-        UPSAMPLE_STRIDES: [0.5, 1, 2]
-        NUM_UPSAMPLE_FILTERS: [128, 128, 128]
-
-    DENSE_HEAD:
-        NAME: AnchorHeadMulti
-        CLASS_AGNOSTIC: False
-
-        DIR_OFFSET: 0.78539
-        DIR_LIMIT_OFFSET: 0.0
-        NUM_DIR_BINS: 2
-
-        USE_MULTIHEAD: True
-        SEPARATE_MULTIHEAD: True
-        ANCHOR_GENERATOR_CONFIG: [
-            {
-                'class_name': car,
-                'anchor_sizes': [[4.63, 1.97, 1.74]],
-                'anchor_rotations': [0, 1.57],
-                'anchor_bottom_heights': [-0.95],
-                'align_center': False,
-                'feature_map_stride': 4,
-                'matched_threshold': 0.6,
-                'unmatched_threshold': 0.45
-            },
-            {
-                'class_name': truck,
-                'anchor_sizes': [[6.93, 2.51, 2.84]],
-                'anchor_rotations': [0, 1.57],
-                'anchor_bottom_heights': [-0.6],
-                'align_center': False,
-                'feature_map_stride': 4,
-                'matched_threshold': 0.55,
-                'unmatched_threshold': 0.4
-            },
-            {
-                'class_name': construction_vehicle,
-                'anchor_sizes': [[6.37, 2.85, 3.19]],
-                'anchor_rotations': [0, 1.57],
-                'anchor_bottom_heights': [-0.225],
-                'align_center': False,
-                'feature_map_stride': 4,
-                'matched_threshold': 0.5,
-                'unmatched_threshold': 0.35
-            },
-            {
-                'class_name': bus,
-                'anchor_sizes': [[10.5, 2.94, 3.47]],
-                'anchor_rotations': [0, 1.57],
-                'anchor_bottom_heights': [-0.085],
-                'align_center': False,
-                'feature_map_stride': 4,
-                'matched_threshold': 0.55,
-                'unmatched_threshold': 0.4
-            },
-            {
-                'class_name': trailer,
-                'anchor_sizes': [[12.29, 2.90, 3.87]],
-                'anchor_rotations': [0, 1.57],
-                'anchor_bottom_heights': [0.115],
-                'align_center': False,
-                'feature_map_stride': 4,
-                'matched_threshold': 0.5,
-                'unmatched_threshold': 0.35
-            },
-            {
-                'class_name': barrier,
-                'anchor_sizes': [[0.50, 2.53, 0.98]],
-                'anchor_rotations': [0, 1.57],
-                'anchor_bottom_heights': [-1.33],
-                'align_center': False,
-                'feature_map_stride': 4,
-                'matched_threshold': 0.55,
-                'unmatched_threshold': 0.4
-            },
-            {
-                'class_name': motorcycle,
-                'anchor_sizes': [[2.11, 0.77, 1.47]],
-                'anchor_rotations': [0, 1.57],
-                'anchor_bottom_heights': [-1.085],
-                'align_center': False,
-                'feature_map_stride': 4,
-                'matched_threshold': 0.5,
-                'unmatched_threshold': 0.3
-            },
-            {
-                'class_name': bicycle,
-                'anchor_sizes': [[1.70, 0.60, 1.28]],
-                'anchor_rotations': [0, 1.57],
-                'anchor_bottom_heights': [-1.18],
-                'align_center': False,
-                'feature_map_stride': 4,
-                'matched_threshold': 0.5,
-                'unmatched_threshold': 0.35
-            },
-            {
-                'class_name': pedestrian,
-                'anchor_sizes': [[0.73, 0.67, 1.77]],
-                'anchor_rotations': [0, 1.57],
-                'anchor_bottom_heights': [-0.935],
-                'align_center': False,
-                'feature_map_stride': 4,
-                'matched_threshold': 0.6,
-                'unmatched_threshold': 0.4
-            },
-            {
-                'class_name': traffic_cone,
-                'anchor_sizes': [[0.41, 0.41, 1.07]],
-                'anchor_rotations': [0, 1.57],
-                'anchor_bottom_heights': [-1.285],
-                'align_center': False,
-                'feature_map_stride': 4,
-                'matched_threshold': 0.6,
-                'unmatched_threshold': 0.4
-            },
-        ]
-
-        SHARED_CONV_NUM_FILTER: 64
-
-        RPN_HEAD_CFGS: [
-            {
-                'HEAD_CLS_NAME': ['car'],
-            },
-            {
-                'HEAD_CLS_NAME': ['truck', 'construction_vehicle'],
-            },
-            {
-                'HEAD_CLS_NAME': ['bus', 'trailer'],
-            },
-            {
-                'HEAD_CLS_NAME': ['barrier'],
-            },
-            {
-                'HEAD_CLS_NAME': ['motorcycle', 'bicycle'],
-            },
-            {
-                'HEAD_CLS_NAME': ['pedestrian', 'traffic_cone'],
-            },
-        ]
-        SEPARATE_REG_CONFIG: 
-            NUM_MIDDLE_CONV: 1
-            NUM_MIDDLE_FILTER: 64
-            REG_LIST: ['reg:2', 'height:1', 'size:3', 'angle:2', 'velo:2']
-
-        TARGET_ASSIGNER_CONFIG:
-            NAME: AxisAlignedTargetAssigner
-            POS_FRACTION: -1.0
-            SAMPLE_SIZE: 512
-            NORM_BY_NUM_EXAMPLES: False
-            MATCH_HEIGHT: False
-            BOX_CODER: ResidualCoder
-            BOX_CODER_CONFIG: {
-                'code_size': 9,
-                'encode_angle_by_sincos': True
-            }
-
-
-        LOSS_CONFIG:
-            REG_LOSS_TYPE: WeightedL1Loss
-            LOSS_WEIGHTS: {
-                'pos_cls_weight': 1.0,
-                'neg_cls_weight': 2.0,
-                'cls_weight': 1.0,
-                'loc_weight': 0.25,
-                'dir_weight': 0.2,
-                'code_weights': [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.2, 0.2]
-            }
-
-    POST_PROCESSING:
-        RECALL_THRESH_LIST: [0.3, 0.5, 0.7]
-        SCORE_THRESH: 0.1
-        OUTPUT_RAW_SCORE: False
-
-        EVAL_METRIC: kitti
-
-        NMS_CONFIG:
-            MULTI_CLASSES_NMS: True
-            NMS_TYPE: nms_gpu
-            NMS_THRESH: 0.2
-            NMS_PRE_MAXSIZE: 1000
-            NMS_POST_MAXSIZE: 83
-
-
-OPTIMIZATION:
-    BATCH_SIZE_PER_GPU: 4
-    NUM_EPOCHS: 20
-
-    OPTIMIZER: adam_onecycle
-    LR: 0.001
-    WEIGHT_DECAY: 0.01
-    MOMENTUM: 0.9
-
-    MOMS: [0.95, 0.85]
-    PCT_START: 0.4
-    DIV_FACTOR: 10
-    DECAY_STEP_LIST: [35, 45]
-    LR_DECAY: 0.1
-    LR_CLIP: 0.0000001
-
-    LR_WARMUP: False
-    WARMUP_EPOCH: 1
-
-    GRAD_NORM_CLIP: 10

+ 0 - 141
src/detection/detection_lidar_PointPillars_MultiHead_1025/common.h

@@ -1,141 +0,0 @@
-/******************************************************************************
- * Copyright 2020 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.
- *****************************************************************************/
-
-/*
- * Copyright 2018-2019 Autoware Foundation. 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.
- */
-
-/**
- * @author Kosuke Murakami
- * @date 2019/02/26
- */
-
-/**
-* @author Yan haixu
-* Contact: just github.com/hova88
-* @date 2021/04/30
-*/
-
-
-
-#pragma once
-
-// headers in STL
-#include <stdio.h>
-#include <assert.h>
-#include <iostream>
-#include <fstream>
-#include <string>
-#include <vector>
-// headers in CUDA
-#include "cuda_runtime_api.h"
-
-using namespace std;
-// using MACRO to allocate memory inside CUDA kernel
-#define NUM_3D_BOX_CORNERS_MACRO 8
-
-#define NUM_2D_BOX_CORNERS_MACRO 4
-
-#define NUM_THREADS_MACRO 64
-
-// need to be changed when num_threads_ is changed
-
-#define DIVUP(m, n) ((m) / (n) + ((m) % (n) > 0))
-
-#define GPU_CHECK(ans)                    \
-  {                                       \
-    GPUAssert((ans), __FILE__, __LINE__); \
-  }
-inline void GPUAssert(cudaError_t code, const char *file, int line,
-                      bool abort = true)
-{
-  if (code != cudaSuccess)
-  {
-    fprintf(stderr, "GPUassert: %s %s %d\n", cudaGetErrorString(code), file,
-            line);
-    if (abort)
-      exit(code);
-  }
-};
-
-template <typename T>
-void HOST_SAVE(T *array, int size, string filename, string root = "../test/result", string postfix = ".txt")
-{
-  string filepath = root + "/" + filename + postfix;
-  if (postfix == ".bin")
-  {
-    fstream file(filepath, ios::out | ios::binary);
-    file.write(reinterpret_cast<char *>(array), sizeof(size * sizeof(T)));
-    file.close();
-    std::cout << "|>>>|  Data has been written in " << filepath << "  |<<<|" << std::endl;
-    return;
-  }
-  else if (postfix == ".txt")
-  {
-    ofstream file(filepath, ios::out);
-    for (int i = 0; i < size; ++i)
-      file << array[i] << " ";
-    file.close();
-    std::cout << "|>>>|  Data has been written in " << filepath << "  |<<<|" << std::endl;
-    return;
-  }
-};
-
-template <typename T>
-void DEVICE_SAVE(T *array, int size, string filename, string root = "../test/result", string postfix = ".txt")
-{
-  T *temp_ = new T[size];
-  cudaMemcpy(temp_, array, size * sizeof(T), cudaMemcpyDeviceToHost);
-  HOST_SAVE<T>(temp_, size, filename, root, postfix);
-  delete[] temp_;
-};
-
-
-// int TXTtoArrary( float* &points_array , string file_name , int num_feature = 4)
-// {
-//   ifstream InFile;
-//   InFile.open(file_name.data());
-//   assert(InFile.is_open());
-
-//   vector<float> temp_points;
-//   string c;
-
-//   while (!InFile.eof())
-//   {
-//       InFile >> c;
-
-//       temp_points.push_back(atof(c.c_str()));
-//   }
-//   points_array = new float[temp_points.size()];
-//   for (int i = 0 ; i < temp_points.size() ; ++i) {
-//     points_array[i] = temp_points[i];
-//   }
-
-//   InFile.close();  
-//   return temp_points.size() / num_feature;
-// };

+ 0 - 181
src/detection/detection_lidar_PointPillars_MultiHead_1025/detection_lidar_PointPillars_MultiHead.pro

@@ -1,181 +0,0 @@
-QT -= gui
-
-CONFIG += c++14 console
-CONFIG -= app_bundle
-
-QMAKE_CXXFLAGS += -std=gnu++17
-QMAKE_LFLAGS += -no-pie  -Wl,--no-as-needed
-
-# The following define makes your compiler emit warnings if you use
-# any feature of Qt which as been marked deprecated (the exact warnings
-# depend on your compiler). Please consult the documentation of the
-# deprecated API in order to know how to port your code away from it.
-DEFINES += QT_DEPRECATED_WARNINGS
-#DEFINES += DEBUG_SHOW
-# You can also make your code fail to compile if you use deprecated APIs.
-# In order to do so, uncomment the following line.
-# You can also select to disable deprecated APIs only up to a certain version of Qt.
-#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
-
-SOURCES += main.cpp \
-    pointpillars.cc \
-    ../../include/msgtype/object.pb.cc \
-    ../../include/msgtype/objectarray.pb.cc \
-    Tracker/Ctracker.cpp \
-    Tracker/HungarianAlg.cpp \
-    Tracker/Kalman.cpp \
-    Tracker/track.cpp
-
-DISTFILES += \
-    nms.cu \
-    postprocess.cu \
-    preprocess.cu \
-    scatter.cu
-
-HEADERS += \
-    common.h \
-    nms.h \
-    pointpillars.h \
-    postprocess.h \
-    preprocess.h \
-    scatter.h \
-    ../../include/msgtype/object.pb.h \
-    ../../include/msgtype/objectarray.pb.h \
-    Tracker/Ctracker.h \
-    Tracker/defines.h \
-    Tracker/HungarianAlg.h \
-    Tracker/Kalman.h \
-    Tracker/ShortPathCalculator.h \
-    Tracker/track.h \
-    Tracker/Tracking.hpp
-
-INCLUDEPATH+=Tracker
-
-CUDA_SOURCES +=  \
-    nms.cu \
-    postprocess.cu \
-    preprocess.cu \
-    scatter.cu
-
-CUDA_SDK = "/usr/local/cuda/"   # cudaSDK路径
-
-CUDA_DIR = "/usr/local/cuda/"            # CUDA tookit路径
-
-SYSTEM_NAME = linux         # 自己系统环境 'Win32', 'x64', or 'Win64'
-
-SYSTEM_TYPE = 64           #操作系统位数 '32' or '64',
-
-CUDA_ARCH = sm_72         # cuda架构, for example 'compute_10', 'compute_11', 'sm_10'
-
-NVCC_OPTIONS = --use_fast_math --compiler-options "-fPIC"
-
-
-# include paths
-
-INCLUDEPATH += $$CUDA_DIR/include
-#INCLUDEPATH += /usr/local/cuda-10.0/targets/aarch64-linux/include/crt
-
-# library directories
-
-QMAKE_LIBDIR += $$CUDA_DIR/lib/
-
-CUDA_OBJECTS_DIR = ./
-
-# The following library conflicts with something in Cuda
-
-#QMAKE_LFLAGS_RELEASE = /NODEFAULTLIB:msvcrt.lib
-
-#QMAKE_LFLAGS_DEBUG   = /NODEFAULTLIB:msvcrtd.lib
-
-# Add the necessary libraries
-
-CUDA_LIBS =  cudart cufft
-
-# The following makes sure all path names (which often include spaces) are put between quotation marks
-
-CUDA_INC = $$join(INCLUDEPATH,'" -I"','-I"','"')
-
-NVCC_LIBS = $$join(CUDA_LIBS,' -l','-l', '')
-
-#LIBS += $$join(CUDA_LIBS,'.so ', '', '.so')
-
-# Configuration of the Cuda compiler
-
-CONFIG(debug, debug|release) {
-
-    # Debug mode
-
-    cuda_d.input = CUDA_SOURCES
-
-    cuda_d.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.o
-
-    cuda_d.commands = $$CUDA_DIR/bin/nvcc -D_DEBUG $$NVCC_OPTIONS $$CUDA_INC $$NVCC_LIBS --machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
-
-    cuda_d.dependency_type = TYPE_C
-
-    QMAKE_EXTRA_COMPILERS += cuda_d
-
-}
-
-else {
-
-    # Release mode
-
-    cuda.input = CUDA_SOURCES
-
-    cuda.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.o
-
-    cuda.commands = $$CUDA_DIR/bin/nvcc $$NVCC_OPTIONS $$CUDA_INC $$NVCC_LIBS --machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH -O3 -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
-
-    cuda.dependency_type = TYPE_C
-
-    QMAKE_EXTRA_COMPILERS += cuda
-
-}
-
-
-LIBS += -L/usr/local/cuda-10.2/targets/aarch64-linux/lib
-
-LIBS += -lcudart -lcufft -lyaml-cpp
-
-#LIBS += -L/home/adc/soft/cudnn-10.2-linux-x64-v7.6.5.32/cuda/lib64 -lcudnn
-
-LIBS +=  -lmyelin -lnvinfer -lnvonnxparser -lnvcaffe_parser
-
-#LIBS += -L/home/nvidia/git/libtorch_gpu-1.6.0-linux-aarch64/lib -ltorch_cuda  -ltorch -lc10 -ltorch_cpu
-
-unix:INCLUDEPATH += /usr/include/eigen3
-unix:INCLUDEPATH += /usr/include/pcl-1.7
-unix:INCLUDEPATH += /usr/include/pcl-1.8
-
-!include(../../../include/common.pri ) {
-    error( "Couldn't find the common.pri file!" )
-}
-
-!include(../../../include/ivprotobuf.pri ) {
-    error( "Couldn't find the ivprotobuf.pri file!" )
-}
-
-LIBS += -lboost_system
-
-unix:LIBS +=  -lpcl_common\
-        -lpcl_features\
-        -lpcl_filters\
-        -lpcl_io\
-        -lpcl_io_ply\
-        -lpcl_kdtree\
-        -lpcl_keypoints\
-        -lpcl_octree\
-        -lpcl_outofcore\
-        -lpcl_people\
-        -lpcl_recognition\
-        -lpcl_registration\
-        -lpcl_sample_consensus\
-        -lpcl_search\
-        -lpcl_segmentation\
-        -lpcl_surface\
-        -lpcl_tracking\
-        -lpcl_visualization
-
-INCLUDEPATH += /usr/include/opencv4/
-LIBS += /usr/lib/aarch64-linux-gnu/libopencv*.so

+ 0 - 376
src/detection/detection_lidar_PointPillars_MultiHead_1025/main.cpp

@@ -1,376 +0,0 @@
-#include <QCoreApplication>
-#include <QDateTime>
-#include <iostream>
-#include "pointpillars.h"
-#include <iostream>
-#include <pcl/point_cloud.h>
-#include <pcl/point_types.h>
-#include <pcl/io/io.h>
-#include <pcl/io/pcd_io.h>
-#include "xmlparam.h"
-#include "modulecomm.h"
-#include "ivfault.h"
-#include "ivlog.h"
-#include "ivexit.h"
-#include "ivversion.h"
-#include <thread>
-#include "objectarray.pb.h"
-//#include "ivbacktrace.h"
-#include "Tracking.hpp"
-iv::Ivfault *gfault = nullptr;
-iv::Ivlog *givlog = nullptr;
-
-std::thread * gpthread;
-PointPillars * pPillars = nullptr ;
-void * gpa;
-void * gpdetect;
-int gnothavedatatime = 0;
-const int kNumPointFeature = 5;
-const int kOutputNumBoxFeature = 7;
-std::string gstrinput;
-std::string gstroutput;
-
-TrackerSettings settings;
-CTracker tracker(settings);
-bool m_isTrackerInitialized = false;
-
-void PclToArray(
-        const pcl::PointCloud<pcl::PointXYZI>::Ptr& in_pcl_pc_ptr,
-        float* out_points_array, const float normalizing_factor) {
-    for (size_t i = 0; i < in_pcl_pc_ptr->size(); ++i) {
-        pcl::PointXYZI point = in_pcl_pc_ptr->at(i);
-        out_points_array[i * 4 + 0] = point.x;
-        out_points_array[i * 4 + 1] = point.y;
-        out_points_array[i * 4 + 2] = point.z;
-        out_points_array[i * 4 + 3] =
-                static_cast<float>(point.intensity / normalizing_factor);
-    }
-}
-
-void PclXYZITToArray(
-        const pcl::PointCloud<pcl::PointXYZI>::Ptr& in_pcl_pc_ptr,
-        float* out_points_array, const float normalizing_factor) {
-    for (size_t i = 0; i < in_pcl_pc_ptr->size(); ++i) {
-        pcl::PointXYZI point = in_pcl_pc_ptr->at(i);
-        out_points_array[i * 5 + 0] = point.x;
-        out_points_array[i * 5 + 1] = point.y;
-        out_points_array[i * 5 + 2] = point.z;
-        out_points_array[i * 5 + 3] =
-                static_cast<float>(point.intensity / normalizing_factor);
-        out_points_array[i * 5 + 4] = 0;
-    }
-}
-
-void GetLidarObj(std::vector<float> out_detections,std::vector<int> out_labels,
-                 std::vector<float> out_scores,iv::lidar::objectarray & lidarobjvec)
-{
-    int i;
-    int obj_size = out_detections.size()/kOutputNumBoxFeature;
-    //    givlog->verbose("OBJ","object size is %d",obj_size);
-    for(i=0;i<obj_size;i++)
-    {
-        iv::lidar::lidarobject lidarobj;
-        if (out_scores.at(i) < 0.10) continue;
-
-        lidarobj.set_tyaw(out_detections.at(i*7+6));
-        iv::lidar::PointXYZ centroid;
-        iv::lidar::PointXYZ * _centroid;
-        centroid.set_x(out_detections.at(i*7));
-        centroid.set_y(out_detections.at(i*7+1));
-        centroid.set_z(out_detections.at(i*7+2));
-        _centroid = lidarobj.mutable_centroid();
-        _centroid->CopyFrom(centroid);
-
-        iv::lidar::PointXYZ min_point;
-        iv::lidar::PointXYZ * _min_point;
-        min_point.set_x(0);
-        min_point.set_y(0);
-        min_point.set_z(0);
-        _min_point = lidarobj.mutable_min_point();
-        _min_point->CopyFrom(min_point);
-
-        iv::lidar::PointXYZ max_point;
-        iv::lidar::PointXYZ * _max_point;
-        max_point.set_x(0);
-        max_point.set_y(0);
-        max_point.set_z(0);
-        _max_point = lidarobj.mutable_max_point();
-        _max_point->CopyFrom(max_point);
-
-        iv::lidar::PointXYZ position;
-        iv::lidar::PointXYZ * _position;
-        position.set_x(out_detections.at(i*7));
-        position.set_y(out_detections.at(i*7+1));
-        position.set_z(out_detections.at(i*7+2));
-        _position = lidarobj.mutable_position();
-        _position->CopyFrom(position);
-        lidarobj.set_mntype(out_labels.at(i));
-        // label 2  8
-        if(out_labels.at(i)==2){
-            lidarobj.set_mntype(8);
-        }else if(out_labels.at(i)==8){
-            lidarobj.set_mntype(2);
-        }
-        lidarobj.set_score(out_scores.at(i));
-        lidarobj.add_type_probs(out_scores.at(i));
-
-        iv::lidar::PointXYZI point_cloud;
-        iv::lidar::PointXYZI * _point_cloud;
-        point_cloud.set_x(out_detections.at(i*7));
-        point_cloud.set_y(out_detections.at(i*7+1));
-        point_cloud.set_z(out_detections.at(i*7+2));
-        point_cloud.set_i(0);
-
-        _point_cloud = lidarobj.add_cloud();
-        _point_cloud->CopyFrom(point_cloud);
-
-        iv::lidar::Dimension ld;
-        iv::lidar::Dimension * pld;
-        ld.set_x(out_detections.at(i*7+3));// w
-        ld.set_y(out_detections.at(i*7+4));// l
-        ld.set_z(out_detections.at(i*7+5));// h
-        pld = lidarobj.mutable_dimensions();
-        pld->CopyFrom(ld);
-
-        //        std::cout<<"x y z   :  "<<out_detections.at(i*7+3)<<"    "<< out_detections.at(i*7+4)<<"    "<<out_detections.at(i*7+5)<<std::endl;
-        iv::lidar::lidarobject * po = lidarobjvec.add_obj();
-        po->CopyFrom(lidarobj);
-    }
-
-}
-
-void DectectOnePCD(const pcl::PointCloud<pcl::PointXYZI>::Ptr &pc_ptr)
-{
-    std::shared_ptr<float> points_array_ptr = std::shared_ptr<float>(new float[pc_ptr->size() * kNumPointFeature]);
-    //   float* points_array = new float[pc_ptr->size() * kNumPointFeature];
-    PclXYZITToArray(pc_ptr, points_array_ptr.get(), 1.0);
-
-    int    in_num_points = pc_ptr->width;
-
-    std::vector<float> out_detections;
-    std::vector<int> out_labels;
-    std::vector<float> out_scores;
-
-    QTime xTime;
-
-    xTime.start();
-
-    cudaDeviceSynchronize();
-    pPillars->DoInference(points_array_ptr.get(), in_num_points, &out_detections, &out_labels , &out_scores);
-    cudaDeviceSynchronize();
-
-    //    givlog->verbose("obj size is %d", num_objects);
-    //    std::cout<<"obj size is "<<num_objects<<std::endl;
-
-    //    std::vector<iv::lidar::lidarobject> lidarobjvec;
-    iv::lidar::objectarray lidarobjvec;
-    GetLidarObj(out_detections,out_labels,out_scores,lidarobjvec);
-
-    double timex = pc_ptr->header.stamp;
-    timex = timex/1000.0;
-    lidarobjvec.set_timestamp(pc_ptr->header.stamp);
-    //---------------------------------------------  init tracker  -------------------------------------------------
-    if (!m_isTrackerInitialized)
-    {
-        m_isTrackerInitialized = InitTracker(tracker);
-        if (!m_isTrackerInitialized)
-        {
-            std::cerr << "Tracker initialize error!!!" << std::endl;
-        }
-    }
-    iv::lidar::objectarray trackedobjvec = Tracking(lidarobjvec, tracker);
-    //    std::<<"track    end"<<std::endl;
-
-    //    --------------------------------------------  end tracking  --------------------------------------------------
-    int ntlen;
-    std::string out = trackedobjvec.SerializeAsString();
-    iv::modulecomm::ModuleSendMsg(gpdetect,out.data(),out.length());
-
-    //    givlog->verbose("lenth is %d",out.length());
-}
-
-void ListenPointCloud(const char *strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
-{
-    //    std::cout<<" is  ok  ------------  "<<std::endl;
-    if(nSize <=16)return;
-    unsigned int * pHeadSize = (unsigned int *)strdata;
-    if(*pHeadSize > nSize)
-    {
-        givlog->verbose("ListenPointCloud data is small headsize = %d, data size is %d", *pHeadSize, nSize);
-        std::cout<<"ListenPointCloud data is small headsize ="<<*pHeadSize<<"  data size is"<<nSize<<std::endl;
-    }
-
-    gnothavedatatime = 0;
-    QTime xTime;
-    xTime.start();
-
-    pcl::PointCloud<pcl::PointXYZI>::Ptr point_cloud(
-                new pcl::PointCloud<pcl::PointXYZI>());
-    int nNameSize;
-    nNameSize = *pHeadSize - 4-4-8;
-    char * strName = new char[nNameSize+1];strName[nNameSize] = 0;
-    std::shared_ptr<char> str_ptr;
-    str_ptr.reset(strName);
-    memcpy(strName,(char *)((char *)strdata +4),nNameSize);
-    point_cloud->header.frame_id = strName;
-    memcpy(&point_cloud->header.seq,(char *)strdata+4+nNameSize,4);
-    memcpy(&point_cloud->header.stamp,(char *)strdata+4+nNameSize+4,8);
-    int nPCount = (nSize - *pHeadSize)/sizeof(pcl::PointXYZI);
-    int i;
-    pcl::PointXYZI * p;
-    p = (pcl::PointXYZI *)((char *)strdata + *pHeadSize);
-    for(i=0;i<nPCount;i++)
-    {
-        pcl::PointXYZI xp;
-        memcpy(&xp,p,sizeof(pcl::PointXYZI));
-        xp.z = xp.z;
-        point_cloud->push_back(xp);
-        p++;
-    }
-
-    DectectOnePCD(point_cloud);
-    std::cout<<"time is "<<(QDateTime::currentMSecsSinceEpoch() % 1000)<<" "<<xTime.elapsed()<<std::endl;
-    gfault->SetFaultState(0, 0, "ok");
-
-}
-
-bool gbstate = true;
-void statethread()
-{
-    int nstate = 0;
-    int nlaststate = 0;
-    while (gbstate)
-    {
-        std::this_thread::sleep_for(std::chrono::milliseconds(10));
-        if(gnothavedatatime < 100000) gnothavedatatime++;
-
-        if (gnothavedatatime  < 100){
-            nstate = 0;
-        }
-        if (gnothavedatatime > 1000)
-        {
-            nstate = 1;
-        }
-        if (gnothavedatatime > 6000)
-        {
-            nstate = 2;
-        }
-        if (nstate != nlaststate) {
-            switch (nstate) {
-            case 0:
-                givlog->info("detection_lidar_pointpillar is ok");
-                gfault->SetFaultState(0,0,"data is ok.");
-                break;
-            case 1:
-                givlog->info(" more than 10 seconds not have lidar pointcloud.");
-                gfault->SetFaultState(1,1,"more than 10 seconds not have lidar pointcloud.");
-                break;
-            case 2:
-                givlog->info(" more than 60 seconds not have lidar pointcloud.");
-                gfault->SetFaultState(2,2, "more than 60 seconds not have lidar pointcloud.");
-                break;
-            default:
-                break;
-            }
-        }
-    }
-}
-
-void exitfunc()
-{
-    gbstate = false;
-    gpthread->join();
-    std::cout<<" state thread closed."<<std::endl;
-    iv::modulecomm::Unregister(gpa);
-    iv::modulecomm::Unregister(gpdetect);
-    std::cout<<"exit func complete"<<std::endl;
-}
-#include <QFile>
-bool trtisexist(std::string strpfe,std::string strbackbone)
-{
-    QFile xFile;
-    xFile.setFileName(strpfe.data());
-    if(xFile.exists() == false)
-    {
-        return false;
-    }
-    xFile.setFileName(strbackbone.data());
-    if(xFile.exists() == false)
-    {
-        return false;
-    }
-    return true;
-}
-int main(int argc, char *argv[])
-{
-    QCoreApplication a(argc, argv);
-
-    //    RegisterIVBackTrace();
-    tracker.setSettings(settings);
-    gfault = new iv::Ivfault("lidar_pointpillar");
-    givlog = new iv::Ivlog("lidar_pointpillar");
-
-    gfault->SetFaultState(0,0,"pointpillar initialize. ");
-
-    char * strhome = getenv("HOME");
-    std::string pfe_file = strhome;
-    pfe_file += "/models/lidar/cbgs_pp_multihead_pfe.onnx";
-    std::string pfe_trt_file = pfe_file.substr(0, pfe_file.find(".")) + ".trt";
-
-    std::string backbone_file = strhome;
-    backbone_file += "/models/lidar/cbgs_pp_multihead_backbone.onnx";
-    std::string backbone_trt_file = backbone_file.substr(0, backbone_file.find(".")) + ".trt";
-
-    bool btrtexist = trtisexist(pfe_trt_file,backbone_trt_file);
-
-
-    QString strpath = QCoreApplication::applicationDirPath();
-    std::string pp_config = strpath.toStdString() ;
-    pp_config += "/cfgs/cbgs_pp_multihead.yaml";
-    if (argc < 2)
-        strpath = strpath + "/detection_lidar_pointpillar.xml";
-    else
-        strpath = argv[1];
-
-    std::cout<<pp_config<<std::endl;
-
-    iv::xmlparam::Xmlparam xparam(strpath.toStdString());
-    pfe_file = xparam.GetParam("pfe_file",pfe_file.data());
-    backbone_file = xparam.GetParam("backbone_file",backbone_file.data());
-    gstrinput = xparam.GetParam("input","lidar_pc");
-    gstroutput = xparam.GetParam("output","lidar_pointpillar");
-
-    if(btrtexist == false)
-    {
-
-        std::cout<<"use onnx model."<<std::endl;
-        pPillars = new PointPillars(
-                    0.4,
-                    0.2,
-                    true,
-                    pfe_file,
-                    backbone_file,
-                    pp_config
-                    );
-    }
-    else
-    {
-        std::cout<<"use trt model."<<std::endl;
-        pPillars = new PointPillars(
-                    0.1,
-                    0.2,
-                    false,
-                    pfe_trt_file,
-                    backbone_trt_file,
-                    pp_config
-                    );
-    }
-    std::cout<<"PointPillars Init OK."<<std::endl;
-
-    gpa = iv::modulecomm::RegisterRecv(gstrinput.data(),ListenPointCloud);
-    gpdetect = iv::modulecomm::RegisterSend(gstroutput.data(), 10000000,1);
-    gpthread = new std::thread(statethread);
-
-    iv::ivexit::RegIVExitCall(exitfunc);
-    return a.exec();
-}

+ 0 - 422
src/detection/detection_lidar_PointPillars_MultiHead_1025/nms.cu

@@ -1,422 +0,0 @@
-/*
-3D IoU Calculation and Rotated NMS(modified from 2D NMS written by others)
-Written by Shaoshuai Shi
-All Rights Reserved 2019-2020.
-*/
-
-/**
-* @author Yan haixu
-* Contact: just github.com/hova88
-* @date 2021/04/30
-*/
-
-#include <stdio.h>
-#include "nms.h"
-#include "common.h"
-#define THREADS_PER_BLOCK 16
-#define DIVUP(m, n) ((m) / (n) + ((m) % (n) > 0))
-
-// #define DEBUG
-const int THREADS_PER_BLOCK_NMS = sizeof(unsigned long long) * 8;
-const float EPS = 1e-8;
-struct Point {
-    float x, y;
-    __device__ Point() {}
-    __device__ Point(double _x, double _y){
-        x = _x, y = _y;
-    }
-
-    __device__ void set(float _x, float _y){
-        x = _x; y = _y;
-    }
-
-    __device__ Point operator +(const Point &b)const{
-        return Point(x + b.x, y + b.y);
-    }
-
-    __device__ Point operator -(const Point &b)const{
-        return Point(x - b.x, y - b.y);
-    }
-};
-
-__device__ inline float cross(const Point &a, const Point &b){
-    return a.x * b.y - a.y * b.x;
-}
-
-__device__ inline float cross(const Point &p1, const Point &p2, const Point &p0){
-    return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y);
-}
-
-__device__ int check_rect_cross(const Point &p1, const Point &p2, const Point &q1, const Point &q2){
-    int ret = min(p1.x,p2.x) <= max(q1.x,q2.x)  &&
-              min(q1.x,q2.x) <= max(p1.x,p2.x) &&
-              min(p1.y,p2.y) <= max(q1.y,q2.y) &&
-              min(q1.y,q2.y) <= max(p1.y,p2.y);
-    return ret;
-}
-
-__device__ inline int check_in_box2d(const float *box, const Point &p){
-    //params: (7) [x, y, z, dx, dy, dz, heading]
-    const float MARGIN = 1e-2;
-
-    float center_x = box[0], center_y = box[1];
-    float angle_cos = cos(-box[6]), angle_sin = sin(-box[6]);  // rotate the point in the opposite direction of box
-    float rot_x = (p.x - center_x) * angle_cos + (p.y - center_y) * (-angle_sin);
-    float rot_y = (p.x - center_x) * angle_sin + (p.y - center_y) * angle_cos;
-
-    return (fabs(rot_x) < box[3] / 2 + MARGIN && fabs(rot_y) < box[4] / 2 + MARGIN);
-}
-
-__device__ inline int intersection(const Point &p1, const Point &p0, const Point &q1, const Point &q0, Point &ans){
-    // fast exclusion
-    if (check_rect_cross(p0, p1, q0, q1) == 0) return 0;
-
-    // check cross standing
-    float s1 = cross(q0, p1, p0);
-    float s2 = cross(p1, q1, p0);
-    float s3 = cross(p0, q1, q0);
-    float s4 = cross(q1, p1, q0);
-
-    if (!(s1 * s2 > 0 && s3 * s4 > 0)) return 0;
-
-    // calculate intersection of two lines
-    float s5 = cross(q1, p1, p0);
-    if(fabs(s5 - s1) > EPS){
-        ans.x = (s5 * q0.x - s1 * q1.x) / (s5 - s1);
-        ans.y = (s5 * q0.y - s1 * q1.y) / (s5 - s1);
-
-    }
-    else{
-        float a0 = p0.y - p1.y, b0 = p1.x - p0.x, c0 = p0.x * p1.y - p1.x * p0.y;
-        float a1 = q0.y - q1.y, b1 = q1.x - q0.x, c1 = q0.x * q1.y - q1.x * q0.y;
-        float D = a0 * b1 - a1 * b0;
-
-        ans.x = (b0 * c1 - b1 * c0) / D;
-        ans.y = (a1 * c0 - a0 * c1) / D;
-    }
-
-    return 1;
-}
-
-__device__ inline void rotate_around_center(const Point &center, const float angle_cos, const float angle_sin, Point &p){
-    float new_x = (p.x - center.x) * angle_cos + (p.y - center.y) * (-angle_sin) + center.x;
-    float new_y = (p.x - center.x) * angle_sin + (p.y - center.y) * angle_cos + center.y;
-    p.set(new_x, new_y);
-}
-
-__device__ inline int point_cmp(const Point &a, const Point &b, const Point &center){
-    return atan2(a.y - center.y, a.x - center.x) > atan2(b.y - center.y, b.x - center.x);
-}
-
-__device__ inline float box_overlap(const float *box_a, const float *box_b){
-    // params box_a: [x, y, z, dx, dy, dz, heading]
-    // params box_b: [x, y, z, dx, dy, dz, heading]
-
-    float a_angle = box_a[6], b_angle = box_b[6];
-    float a_dx_half = box_a[3] / 2, b_dx_half = box_b[3] / 2, a_dy_half = box_a[4] / 2, b_dy_half = box_b[4] / 2;
-    float a_x1 = box_a[0] - a_dx_half, a_y1 = box_a[1] - a_dy_half;
-    float a_x2 = box_a[0] + a_dx_half, a_y2 = box_a[1] + a_dy_half;
-    float b_x1 = box_b[0] - b_dx_half, b_y1 = box_b[1] - b_dy_half;
-    float b_x2 = box_b[0] + b_dx_half, b_y2 = box_b[1] + b_dy_half;
-
-    Point center_a(box_a[0], box_a[1]);
-    Point center_b(box_b[0], box_b[1]);
-
-#ifdef DEBUG
-    printf("a: (%.3f, %.3f, %.3f, %.3f, %.3f), b: (%.3f, %.3f, %.3f, %.3f, %.3f)\n", a_x1, a_y1, a_x2, a_y2, a_angle,
-           b_x1, b_y1, b_x2, b_y2, b_angle);
-    printf("center a: (%.3f, %.3f), b: (%.3f, %.3f)\n", center_a.x, center_a.y, center_b.x, center_b.y);
-#endif
-
-    Point box_a_corners[5];
-    box_a_corners[0].set(a_x1, a_y1);
-    box_a_corners[1].set(a_x2, a_y1);
-    box_a_corners[2].set(a_x2, a_y2);
-    box_a_corners[3].set(a_x1, a_y2);
-
-    Point box_b_corners[5];
-    box_b_corners[0].set(b_x1, b_y1);
-    box_b_corners[1].set(b_x2, b_y1);
-    box_b_corners[2].set(b_x2, b_y2);
-    box_b_corners[3].set(b_x1, b_y2);
-
-    // get oriented corners
-    float a_angle_cos = cos(a_angle), a_angle_sin = sin(a_angle);
-    float b_angle_cos = cos(b_angle), b_angle_sin = sin(b_angle);
-
-    for (int k = 0; k < 4; k++){
-#ifdef DEBUG
-        printf("before corner %d: a(%.3f, %.3f), b(%.3f, %.3f) \n", k, box_a_corners[k].x, box_a_corners[k].y, box_b_corners[k].x, box_b_corners[k].y);
-#endif
-        rotate_around_center(center_a, a_angle_cos, a_angle_sin, box_a_corners[k]);
-        rotate_around_center(center_b, b_angle_cos, b_angle_sin, box_b_corners[k]);
-#ifdef DEBUG
-        printf("corner %d: a(%.3f, %.3f), b(%.3f, %.3f) \n", k, box_a_corners[k].x, box_a_corners[k].y, box_b_corners[k].x, box_b_corners[k].y);
-#endif
-    }
-
-    box_a_corners[4] = box_a_corners[0];
-    box_b_corners[4] = box_b_corners[0];
-
-    // get intersection of lines
-    Point cross_points[16];
-    Point poly_center;
-    int cnt = 0, flag = 0;
-
-    poly_center.set(0, 0);
-    for (int i = 0; i < 4; i++){
-        for (int j = 0; j < 4; j++){
-            flag = intersection(box_a_corners[i + 1], box_a_corners[i], box_b_corners[j + 1], box_b_corners[j], cross_points[cnt]);
-            if (flag){
-                poly_center = poly_center + cross_points[cnt];
-                cnt++;
-#ifdef DEBUG
-                printf("Cross points (%.3f, %.3f): a(%.3f, %.3f)->(%.3f, %.3f), b(%.3f, %.3f)->(%.3f, %.3f) \n",
-                    cross_points[cnt - 1].x, cross_points[cnt - 1].y,
-                    box_a_corners[i].x, box_a_corners[i].y, box_a_corners[i + 1].x, box_a_corners[i + 1].y,
-                    box_b_corners[i].x, box_b_corners[i].y, box_b_corners[i + 1].x, box_b_corners[i + 1].y);
-#endif
-            }
-        }
-    }
-
-    // check corners
-    for (int k = 0; k < 4; k++){
-        if (check_in_box2d(box_a, box_b_corners[k])){
-            poly_center = poly_center + box_b_corners[k];
-            cross_points[cnt] = box_b_corners[k];
-            cnt++;
-#ifdef DEBUG
-                printf("b corners in a: corner_b(%.3f, %.3f)", cross_points[cnt - 1].x, cross_points[cnt - 1].y);
-#endif
-        }
-        if (check_in_box2d(box_b, box_a_corners[k])){
-            poly_center = poly_center + box_a_corners[k];
-            cross_points[cnt] = box_a_corners[k];
-            cnt++;
-#ifdef DEBUG
-                printf("a corners in b: corner_a(%.3f, %.3f)", cross_points[cnt - 1].x, cross_points[cnt - 1].y);
-#endif
-        }
-    }
-
-    poly_center.x /= cnt;
-    poly_center.y /= cnt;
-
-    // sort the points of polygon
-    Point temp;
-    for (int j = 0; j < cnt - 1; j++){
-        for (int i = 0; i < cnt - j - 1; i++){
-            if (point_cmp(cross_points[i], cross_points[i + 1], poly_center)){
-                temp = cross_points[i];
-                cross_points[i] = cross_points[i + 1];
-                cross_points[i + 1] = temp;
-            }
-        }
-    }
-
-#ifdef DEBUG
-    printf("cnt=%d\n", cnt);
-    for (int i = 0; i < cnt; i++){
-        printf("All cross point %d: (%.3f, %.3f)\n", i, cross_points[i].x, cross_points[i].y);
-    }
-#endif
-
-    // get the overlap areas
-    float area = 0;
-    for (int k = 0; k < cnt - 1; k++){
-        area += cross(cross_points[k] - cross_points[0], cross_points[k + 1] - cross_points[0]);
-    }
-
-    return fabs(area) / 2.0;
-}
-
-__device__ inline float iou_bev(const float *box_a, const float *box_b){
-    // params box_a: [x, y, z, dx, dy, dz, heading]
-    // params box_b: [x, y, z, dx, dy, dz, heading]
-    float sa = box_a[3] * box_a[4];
-    float sb = box_b[3] * box_b[4];
-    float s_overlap = box_overlap(box_a, box_b);
-    return s_overlap / fmaxf(sa + sb - s_overlap, EPS);
-}
-
-__global__ void boxes_overlap_kernel(const int num_a, const float *boxes_a, const int num_b, const float *boxes_b, float *ans_overlap){
-    // params boxes_a: (N, 7) [x, y, z, dx, dy, dz, heading]
-    // params boxes_b: (M, 7) [x, y, z, dx, dy, dz, heading]
-    const int a_idx = blockIdx.y * THREADS_PER_BLOCK + threadIdx.y;
-    const int b_idx = blockIdx.x * THREADS_PER_BLOCK + threadIdx.x;
-
-    if (a_idx >= num_a || b_idx >= num_b){
-        return;
-    }
-    const float * cur_box_a = boxes_a + a_idx * 7;
-    const float * cur_box_b = boxes_b + b_idx * 7;
-    float s_overlap = box_overlap(cur_box_a, cur_box_b);
-    ans_overlap[a_idx * num_b + b_idx] = s_overlap;
-}
-
-__global__ void boxes_iou_bev_kernel(const int num_a, const float *boxes_a, const int num_b, const float *boxes_b, float *ans_iou){
-    // params boxes_a: (N, 7) [x, y, z, dx, dy, dz, heading]
-    // params boxes_b: (M, 7) [x, y, z, dx, dy, dz, heading]
-    const int a_idx = blockIdx.y * THREADS_PER_BLOCK + threadIdx.y;
-    const int b_idx = blockIdx.x * THREADS_PER_BLOCK + threadIdx.x;
-
-    if (a_idx >= num_a || b_idx >= num_b){
-        return;
-    }
-
-    const float * cur_box_a = boxes_a + a_idx * 7;
-    const float * cur_box_b = boxes_b + b_idx * 7;
-    float cur_iou_bev = iou_bev(cur_box_a, cur_box_b);
-    ans_iou[a_idx * num_b + b_idx] = cur_iou_bev;
-}
-
-__global__ void nms_kernel(const int boxes_num, const float nms_overlap_thresh,
-                           const float *boxes, unsigned long long *mask){
-    //params: boxes (N, 7) [x, y, z, dx, dy, dz, heading]
-    //params: mask (N, N/THREADS_PER_BLOCK_NMS)
-
-    const int row_start = blockIdx.y;
-    const int col_start = blockIdx.x;
-
-    // if (row_start > col_start) return;
-
-    const int row_size = fminf(boxes_num - row_start * THREADS_PER_BLOCK_NMS, THREADS_PER_BLOCK_NMS);
-    const int col_size = fminf(boxes_num - col_start * THREADS_PER_BLOCK_NMS, THREADS_PER_BLOCK_NMS);
-
-    __shared__ float block_boxes[THREADS_PER_BLOCK_NMS * 7];
-
-    if (threadIdx.x < col_size) {
-        block_boxes[threadIdx.x * 7 + 0] = boxes[(THREADS_PER_BLOCK_NMS * col_start + threadIdx.x) * 7 + 0];
-        block_boxes[threadIdx.x * 7 + 1] = boxes[(THREADS_PER_BLOCK_NMS * col_start + threadIdx.x) * 7 + 1];
-        block_boxes[threadIdx.x * 7 + 2] = boxes[(THREADS_PER_BLOCK_NMS * col_start + threadIdx.x) * 7 + 2];
-        block_boxes[threadIdx.x * 7 + 3] = boxes[(THREADS_PER_BLOCK_NMS * col_start + threadIdx.x) * 7 + 3];
-        block_boxes[threadIdx.x * 7 + 4] = boxes[(THREADS_PER_BLOCK_NMS * col_start + threadIdx.x) * 7 + 4];
-        block_boxes[threadIdx.x * 7 + 5] = boxes[(THREADS_PER_BLOCK_NMS * col_start + threadIdx.x) * 7 + 5];
-        block_boxes[threadIdx.x * 7 + 6] = boxes[(THREADS_PER_BLOCK_NMS * col_start + threadIdx.x) * 7 + 6];
-    }
-    __syncthreads();
-
-    if (threadIdx.x < row_size) {
-        const int cur_box_idx = THREADS_PER_BLOCK_NMS * row_start + threadIdx.x;
-        const float *cur_box = boxes + cur_box_idx * 7;
-
-        int i = 0;
-        unsigned long long t = 0;
-        int start = 0;
-        if (row_start == col_start) {
-          start = threadIdx.x + 1;
-        }
-        for (i = start; i < col_size; i++) {
-            if (iou_bev(cur_box, block_boxes + i * 7) > nms_overlap_thresh){
-                t |= 1ULL << i;
-            }
-        }
-        const int col_blocks = DIVUP(boxes_num, THREADS_PER_BLOCK_NMS);
-        mask[cur_box_idx * col_blocks + col_start] = t;
-    }
-}
-
-
-__device__ inline float iou_normal(float const * const a, float const * const b) {
-    //params: a: [x, y, z, dx, dy, dz, heading]
-    //params: b: [x, y, z, dx, dy, dz, heading]
-
-    float left = fmaxf(a[0] - a[3] / 2, b[0] - b[3] / 2), right = fminf(a[0] + a[3] / 2, b[0] + b[3] / 2);
-    float top = fmaxf(a[1] - a[4] / 2, b[1] - b[4] / 2), bottom = fminf(a[1] + a[4] / 2, b[1] + b[4] / 2);
-    float width = fmaxf(right - left, 0.f), height = fmaxf(bottom - top, 0.f);
-    float interS = width * height;
-    float Sa = a[3] * a[4];
-    float Sb = b[3] * b[4];
-    return interS / fmaxf(Sa + Sb - interS, EPS);
-}
-
-
-__global__ void nms_normal_kernel(const int boxes_num, const float nms_overlap_thresh,
-                           const float *boxes, unsigned long long *mask){
-    //params: boxes (N, 7) [x, y, z, dx, dy, dz, heading]
-    //params: mask (N, N/THREADS_PER_BLOCK_NMS)
-
-    const int row_start = blockIdx.y;
-    const int col_start = blockIdx.x;
-
-    // if (row_start > col_start) return;
-
-    const int row_size = fminf(boxes_num - row_start * THREADS_PER_BLOCK_NMS, THREADS_PER_BLOCK_NMS);
-    const int col_size = fminf(boxes_num - col_start * THREADS_PER_BLOCK_NMS, THREADS_PER_BLOCK_NMS);
-
-    __shared__ float block_boxes[THREADS_PER_BLOCK_NMS * 7];
-
-    if (threadIdx.x < col_size) {
-        block_boxes[threadIdx.x * 7 + 0] = boxes[(THREADS_PER_BLOCK_NMS * col_start + threadIdx.x) * 7 + 0];
-        block_boxes[threadIdx.x * 7 + 1] = boxes[(THREADS_PER_BLOCK_NMS * col_start + threadIdx.x) * 7 + 1];
-        block_boxes[threadIdx.x * 7 + 2] = boxes[(THREADS_PER_BLOCK_NMS * col_start + threadIdx.x) * 7 + 2];
-        block_boxes[threadIdx.x * 7 + 3] = boxes[(THREADS_PER_BLOCK_NMS * col_start + threadIdx.x) * 7 + 3];
-        block_boxes[threadIdx.x * 7 + 4] = boxes[(THREADS_PER_BLOCK_NMS * col_start + threadIdx.x) * 7 + 4];
-        block_boxes[threadIdx.x * 7 + 5] = boxes[(THREADS_PER_BLOCK_NMS * col_start + threadIdx.x) * 7 + 5];
-        block_boxes[threadIdx.x * 7 + 6] = boxes[(THREADS_PER_BLOCK_NMS * col_start + threadIdx.x) * 7 + 6];
-    }
-    __syncthreads();
-
-    if (threadIdx.x < row_size) {
-        const int cur_box_idx = THREADS_PER_BLOCK_NMS * row_start + threadIdx.x;
-        const float *cur_box = boxes + cur_box_idx * 7;
-
-        int i = 0;
-        unsigned long long t = 0;
-        int start = 0;
-        if (row_start == col_start) {
-          start = threadIdx.x + 1;
-        }
-        for (i = start; i < col_size; i++) {
-            if (iou_normal(cur_box, block_boxes + i * 7) > nms_overlap_thresh){
-                t |= 1ULL << i;
-            }
-        }
-        const int col_blocks = DIVUP(boxes_num, THREADS_PER_BLOCK_NMS);
-        mask[cur_box_idx * col_blocks + col_start] = t;
-    }
-}
-
-
-NmsCuda::NmsCuda(const int num_threads, const int num_box_corners,
-    const float nms_overlap_threshold)
-: num_threads_(num_threads),
-  num_box_corners_(num_box_corners),
-  nms_overlap_threshold_(nms_overlap_threshold) {}
-
-void NmsCuda::DoNmsCuda(const int host_filter_count,
-    float *dev_sorted_box_for_nms, long *out_keep_inds,
-    int *out_num_to_keep) {
-
-    const int col_blocks = DIVUP(host_filter_count, num_threads_);
-    unsigned long long *dev_mask = NULL;
-    GPU_CHECK(cudaMalloc(&dev_mask, host_filter_count * col_blocks * sizeof(unsigned long long)));    
-
-    dim3 blocks(DIVUP(host_filter_count, num_threads_),
-                DIVUP(host_filter_count, num_threads_));
-    dim3 threads(num_threads_);
-
-    nms_kernel<<<blocks, threads>>>(host_filter_count, nms_overlap_threshold_, dev_sorted_box_for_nms, dev_mask);
-    // postprocess for nms output
-    std::vector<unsigned long long> host_mask(host_filter_count * col_blocks);
-    GPU_CHECK(cudaMemcpy(&host_mask[0], dev_mask,
-            sizeof(unsigned long long) * host_filter_count * col_blocks,
-            cudaMemcpyDeviceToHost));
-    std::vector<unsigned long long> remv(col_blocks);
-    memset(&remv[0], 0, sizeof(unsigned long long) * col_blocks);
-
-    for (int i = 0; i < host_filter_count; ++i) {
-        int nblock = i / num_threads_;
-        int inblock = i % num_threads_;
-
-        if (!(remv[nblock] & (1ULL << inblock))) {
-            out_keep_inds[(*out_num_to_keep)++] = i;
-            unsigned long long *p = &host_mask[0] + i * col_blocks;
-            for (int j = nblock; j < col_blocks; ++j) {
-                remv[j] |= p[j];
-            }
-        }
-    }
-    GPU_CHECK(cudaFree(dev_mask));
-}

+ 0 - 64
src/detection/detection_lidar_PointPillars_MultiHead_1025/nms.h

@@ -1,64 +0,0 @@
-
-/*
-3D IoU Calculation and Rotated NMS(modified from 2D NMS written by others)
-Written by Shaoshuai Shi
-All Rights Reserved 2019-2020.
-*/
-
-/*
- * Copyright 2018-2019 Autoware Foundation. 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.
- */
-
-/**
- * @author Kosuke Murakami
- * @date 2019/02/26
- */
-
-/**
-* @author Yan haixu
-* Contact: just github.com/hova88
-* @date 2021/04/30
-*/
-
-
-class NmsCuda {
- private:
-  const int num_threads_;
-  const int num_box_corners_;
-  const float nms_overlap_threshold_;
-
- public:
-  /**
-   * @brief Constructor
-   * @param[in] num_threads Number of threads when launching cuda kernel
-   * @param[in] num_box_corners Number of corners for 2D box
-   * @param[in] nms_overlap_threshold IOU threshold for NMS
-   * @details Captital variables never change after the compile, Non-captital
-   * variables could be chaned through rosparam
-   */
-  NmsCuda(const int num_threads, const int num_box_corners,
-          const float nms_overlap_threshold);
-
-  /**
-   * @brief GPU Non-Maximum Suppresion for network output
-   * @param[in] host_filter_count Number of filtered output
-   * @param[in] dev_sorted_box_for_nms Bounding box output sorted by score
-   * @param[out] out_keep_inds Indexes of selected bounding box
-   * @param[out] out_num_to_keep Number of kept bounding boxes
-   * @details NMS in GPU and postprocessing for selecting box in CPU
-   */
-  void DoNmsCuda(const int host_filter_count, float* dev_sorted_box_for_nms,
-                 long* out_keep_inds, int* out_num_to_keep);
-};

+ 0 - 507
src/detection/detection_lidar_PointPillars_MultiHead_1025/pointpillars.cc

@@ -1,507 +0,0 @@
-/******************************************************************************
- * Copyright 2020 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.
- *****************************************************************************/
-
-/*
- * Copyright 2018-2019 Autoware Foundation. 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.
- */
-
-/**
- * @author Kosuke Murakami
- * @date 2019/02/26
- */
-
-/**
-* @author Yan haixu
-* Contact: just github.com/hova88
-* @date 2021/04/30
-*/
-
-
-
-
-#include "pointpillars.h"
-
-#include <chrono>
-#include <iostream>
-#include <iostream>
-
-PointPillars::PointPillars(const float score_threshold,
-                           const float nms_overlap_threshold,
-                           const bool use_onnx,
-                           const std::string pfe_file,
-                           const std::string backbone_file,
-                           const std::string pp_config)
-    : score_threshold_(score_threshold),
-      nms_overlap_threshold_(nms_overlap_threshold),
-      use_onnx_(use_onnx),
-      pfe_file_(pfe_file),
-      backbone_file_(backbone_file),
-      pp_config_(pp_config)
-{
-    InitParams();
-    InitTRT(use_onnx_);
-    DeviceMemoryMalloc();
-
-    preprocess_points_cuda_ptr_.reset(new PreprocessPointsCuda(
-        kNumThreads,
-        kMaxNumPillars,
-        kMaxNumPointsPerPillar,
-        kNumPointFeature,
-        kNumIndsForScan,
-        kGridXSize,kGridYSize, kGridZSize,
-        kPillarXSize,kPillarYSize, kPillarZSize,
-        kMinXRange, kMinYRange, kMinZRange));
-
-    scatter_cuda_ptr_.reset(new ScatterCuda(kNumThreads, kGridXSize, kGridYSize));
-
-    const float float_min = std::numeric_limits<float>::lowest();
-    const float float_max = std::numeric_limits<float>::max();
-    postprocess_cuda_ptr_.reset(
-      new PostprocessCuda(kNumThreads,
-                          float_min, float_max, 
-                          kNumClass,kNumAnchorPerCls,
-                          kMultiheadLabelMapping,
-                          score_threshold_, 
-                          nms_overlap_threshold_,
-                          kNmsPreMaxsize, 
-                          kNmsPostMaxsize,
-                          kNumBoxCorners, 
-                          kNumInputBoxFeature,
-                          7));  /*kNumOutputBoxFeature*/
-    
-}
-
-PointPillars::~PointPillars() {
-    // for pillars 
-    GPU_CHECK(cudaFree(dev_num_points_per_pillar_));
-    GPU_CHECK(cudaFree(dev_x_coors_));
-    GPU_CHECK(cudaFree(dev_y_coors_));
-    GPU_CHECK(cudaFree(dev_pillar_point_feature_));
-    GPU_CHECK(cudaFree(dev_pillar_coors_));
-    // for sparse map
-    GPU_CHECK(cudaFree(dev_sparse_pillar_map_));    
-    GPU_CHECK(cudaFree(dev_cumsum_along_x_));
-    GPU_CHECK(cudaFree(dev_cumsum_along_y_));
-    // for pfe forward
-    GPU_CHECK(cudaFree(dev_pfe_gather_feature_));
-      
-    GPU_CHECK(cudaFree(pfe_buffers_[0]));
-    GPU_CHECK(cudaFree(pfe_buffers_[1]));
-
-    GPU_CHECK(cudaFree(rpn_buffers_[0]));
-    GPU_CHECK(cudaFree(rpn_buffers_[1]));
-    GPU_CHECK(cudaFree(rpn_buffers_[2]));
-    GPU_CHECK(cudaFree(rpn_buffers_[3]));
-    GPU_CHECK(cudaFree(rpn_buffers_[4]));
-    GPU_CHECK(cudaFree(rpn_buffers_[5]));
-    GPU_CHECK(cudaFree(rpn_buffers_[6]));
-    GPU_CHECK(cudaFree(rpn_buffers_[7]));
-    pfe_context_->destroy();
-    backbone_context_->destroy();
-    pfe_engine_->destroy();
-    backbone_engine_->destroy();
-    // for post process
-    GPU_CHECK(cudaFree(dev_scattered_feature_));
-    GPU_CHECK(cudaFree(dev_filtered_box_));
-    GPU_CHECK(cudaFree(dev_filtered_score_));
-    GPU_CHECK(cudaFree(dev_filtered_label_));
-    GPU_CHECK(cudaFree(dev_filtered_dir_));
-    GPU_CHECK(cudaFree(dev_box_for_nms_));
-    GPU_CHECK(cudaFree(dev_filter_count_));
-
-
-}
-
-void PointPillars::InitParams()
-{
-    YAML::Node params = YAML::LoadFile(pp_config_);
-    kPillarXSize = params["DATA_CONFIG"]["DATA_PROCESSOR"][2]["VOXEL_SIZE"][0].as<float>();
-    kPillarYSize = params["DATA_CONFIG"]["DATA_PROCESSOR"][2]["VOXEL_SIZE"][1].as<float>();
-    kPillarZSize = params["DATA_CONFIG"]["DATA_PROCESSOR"][2]["VOXEL_SIZE"][2].as<float>();
-    kMinXRange = params["DATA_CONFIG"]["POINT_CLOUD_RANGE"][0].as<float>();
-    kMinYRange = params["DATA_CONFIG"]["POINT_CLOUD_RANGE"][1].as<float>();
-    kMinZRange = params["DATA_CONFIG"]["POINT_CLOUD_RANGE"][2].as<float>();
-    kMaxXRange = params["DATA_CONFIG"]["POINT_CLOUD_RANGE"][3].as<float>();
-    kMaxYRange = params["DATA_CONFIG"]["POINT_CLOUD_RANGE"][4].as<float>();
-    kMaxZRange = params["DATA_CONFIG"]["POINT_CLOUD_RANGE"][5].as<float>();
-    kNumClass = params["CLASS_NAMES"].size();
-    kMaxNumPillars = params["DATA_CONFIG"]["DATA_PROCESSOR"][2]["MAX_NUMBER_OF_VOXELS"]["test"].as<int>();
-    kMaxNumPointsPerPillar = params["DATA_CONFIG"]["DATA_PROCESSOR"][2]["MAX_POINTS_PER_VOXEL"].as<int>();
-    kNumPointFeature = 5; // [x, y, z, i,0]
-    kNumInputBoxFeature = 7;
-    kNumOutputBoxFeature = params["MODEL"]["DENSE_HEAD"]["TARGET_ASSIGNER_CONFIG"]["BOX_CODER_CONFIG"]["code_size"].as<int>();
-    kBatchSize = 1;
-    kNumIndsForScan = 1024;
-    kNumThreads = 64;
-    kNumBoxCorners = 8;
-    kAnchorStrides = 4;
-    kNmsPreMaxsize = params["MODEL"]["POST_PROCESSING"]["NMS_CONFIG"]["NMS_PRE_MAXSIZE"].as<int>();
-    kNmsPostMaxsize = params["MODEL"]["POST_PROCESSING"]["NMS_CONFIG"]["NMS_POST_MAXSIZE"].as<int>();
-    //params for initialize anchors
-    //Adapt to OpenPCDet
-    kAnchorNames = params["CLASS_NAMES"].as<std::vector<std::string>>();
-    for (int i = 0; i < kAnchorNames.size(); ++i)
-    {
-        kAnchorDxSizes.emplace_back(params["MODEL"]["DENSE_HEAD"]["ANCHOR_GENERATOR_CONFIG"][i]["anchor_sizes"][0][0].as<float>());
-        kAnchorDySizes.emplace_back(params["MODEL"]["DENSE_HEAD"]["ANCHOR_GENERATOR_CONFIG"][i]["anchor_sizes"][0][1].as<float>());
-        kAnchorDzSizes.emplace_back(params["MODEL"]["DENSE_HEAD"]["ANCHOR_GENERATOR_CONFIG"][i]["anchor_sizes"][0][2].as<float>());
-        kAnchorBottom.emplace_back(params["MODEL"]["DENSE_HEAD"]["ANCHOR_GENERATOR_CONFIG"][i]["anchor_bottom_heights"][0].as<float>());
-    }
-    for (int idx_head = 0; idx_head < params["MODEL"]["DENSE_HEAD"]["RPN_HEAD_CFGS"].size(); ++idx_head)
-    {
-        int num_cls_per_head = params["MODEL"]["DENSE_HEAD"]["RPN_HEAD_CFGS"][idx_head]["HEAD_CLS_NAME"].size();
-        std::vector<int> value;
-        for (int i = 0; i < num_cls_per_head; ++i)
-        {
-            value.emplace_back(idx_head + i);
-        }
-        kMultiheadLabelMapping.emplace_back(value);
-    }
-
-    // Generate secondary parameters based on above.
-    kGridXSize = static_cast<int>((kMaxXRange - kMinXRange) / kPillarXSize); //512
-    kGridYSize = static_cast<int>((kMaxYRange - kMinYRange) / kPillarYSize); //512
-    kGridZSize = static_cast<int>((kMaxZRange - kMinZRange) / kPillarZSize); //1
-    kRpnInputSize = 64 * kGridYSize * kGridXSize;
-
-    kNumAnchorXinds = static_cast<int>(kGridXSize / kAnchorStrides); //Width
-    kNumAnchorYinds = static_cast<int>(kGridYSize / kAnchorStrides); //Hight
-    kNumAnchor = kNumAnchorXinds * kNumAnchorYinds * 2 * kNumClass;  // H * W * Ro * N = 196608
-
-    kNumAnchorPerCls = kNumAnchorXinds * kNumAnchorYinds * 2; //H * W * Ro = 32768
-    kRpnBoxOutputSize = kNumAnchor * kNumOutputBoxFeature;
-    kRpnClsOutputSize = kNumAnchor * kNumClass;
-    kRpnDirOutputSize = kNumAnchor * 2;
-}
-
-void PointPillars::DeviceMemoryMalloc() {
-    // for pillars 
-    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&dev_num_points_per_pillar_), kMaxNumPillars * sizeof(float))); // M
-    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&dev_x_coors_), kMaxNumPillars * sizeof(int))); // M
-    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&dev_y_coors_), kMaxNumPillars * sizeof(int))); // M
-    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&dev_pillar_point_feature_), kMaxNumPillars * kMaxNumPointsPerPillar * kNumPointFeature * sizeof(float))); // [M , m , 4]
-    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&dev_pillar_coors_),  kMaxNumPillars * 4 * sizeof(float))); // [M , 4]
-    // for sparse map
-    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&dev_sparse_pillar_map_), kNumIndsForScan * kNumIndsForScan * sizeof(int))); // [1024 , 1024]
-    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&dev_cumsum_along_x_), kNumIndsForScan * kNumIndsForScan * sizeof(int))); // [1024 , 1024]
-    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&dev_cumsum_along_y_), kNumIndsForScan * kNumIndsForScan * sizeof(int)));// [1024 , 1024]
-
-    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&dev_pfe_gather_feature_),
-                        kMaxNumPillars * kMaxNumPointsPerPillar *
-                            kNumGatherPointFeature * sizeof(float)));
-    // for trt inference
-    // create GPU buffers and a stream
-
-    GPU_CHECK(
-        cudaMalloc(&pfe_buffers_[0], kMaxNumPillars * kMaxNumPointsPerPillar *
-                                        kNumGatherPointFeature * sizeof(float)));
-    GPU_CHECK(cudaMalloc(&pfe_buffers_[1], kMaxNumPillars * 64 * sizeof(float)));
-
-    GPU_CHECK(cudaMalloc(&rpn_buffers_[0],  kRpnInputSize * sizeof(float)));
-
-    GPU_CHECK(cudaMalloc(&rpn_buffers_[1],  kNumAnchorPerCls  * sizeof(float)));  //classes
-    GPU_CHECK(cudaMalloc(&rpn_buffers_[2],  kNumAnchorPerCls  * 2 * 2 * sizeof(float)));
-    GPU_CHECK(cudaMalloc(&rpn_buffers_[3],  kNumAnchorPerCls  * 2 * 2 * sizeof(float)));
-    GPU_CHECK(cudaMalloc(&rpn_buffers_[4],  kNumAnchorPerCls  * sizeof(float)));
-    GPU_CHECK(cudaMalloc(&rpn_buffers_[5],  kNumAnchorPerCls  * 2 * 2 * sizeof(float)));
-    GPU_CHECK(cudaMalloc(&rpn_buffers_[6],  kNumAnchorPerCls  * 2 * 2 * sizeof(float)));
-    
-    GPU_CHECK(cudaMalloc(&rpn_buffers_[7],  kNumAnchorPerCls * kNumClass * kNumOutputBoxFeature * sizeof(float))); //boxes
-
-    // for scatter kernel
-    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&dev_scattered_feature_),
-                        kNumThreads * kGridYSize * kGridXSize * sizeof(float)));
-    // for filter
-    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&dev_filtered_box_),
-                        kNumAnchor * kNumOutputBoxFeature * sizeof(float)));
-    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&dev_filtered_score_),
-                        kNumAnchor * sizeof(float)));
-    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&dev_filtered_label_),
-                        kNumAnchor * sizeof(int)));
-    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&dev_filtered_dir_),
-                        kNumAnchor * sizeof(int)));
-    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&dev_box_for_nms_),
-                        kNumAnchor * kNumBoxCorners * sizeof(float)));
-    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&dev_filter_count_), kNumClass * sizeof(int)));
-
-}
-
-void PointPillars::SetDeviceMemoryToZero() {
-
-    GPU_CHECK(cudaMemset(dev_num_points_per_pillar_, 0, kMaxNumPillars * sizeof(float)));
-    GPU_CHECK(cudaMemset(dev_x_coors_,               0, kMaxNumPillars * sizeof(int)));
-    GPU_CHECK(cudaMemset(dev_y_coors_,               0, kMaxNumPillars * sizeof(int)));
-    GPU_CHECK(cudaMemset(dev_pillar_point_feature_,  0, kMaxNumPillars * kMaxNumPointsPerPillar * kNumPointFeature * sizeof(float)));
-    GPU_CHECK(cudaMemset(dev_pillar_coors_,          0, kMaxNumPillars * 4 * sizeof(float)));
-    // GPU_CHECK(cudaMemset(dev_sparse_pillar_map_,     0, kNumIndsForScan * kNumIndsForScan * sizeof(int)));
-    GPU_CHECK(cudaMemset(dev_pfe_gather_feature_,    0, kMaxNumPillars * kMaxNumPointsPerPillar * kNumGatherPointFeature * sizeof(float)));
-    
-    // GPU_CHECK(cudaMemset(pfe_buffers_[0],       0, kMaxNumPillars * kMaxNumPointsPerPillar * kNumGatherPointFeature * sizeof(float)));
-    // GPU_CHECK(cudaMemset(pfe_buffers_[1],       0, kMaxNumPillars * 64 * sizeof(float)));
-
-    GPU_CHECK(cudaMemset(dev_scattered_feature_,    0, kNumThreads * kGridYSize * kGridXSize * sizeof(float)));
-    
-    // GPU_CHECK(cudaMemset(rpn_buffers_[0],    0, kRpnInputSize * sizeof(float)));
-    // GPU_CHECK(cudaMemset(rpn_buffers_[1],    0, kNumAnchorPerCls * kNumOutputBoxFeature * sizeof(float)));
-    // GPU_CHECK(cudaMemset(rpn_buffers_[2],    0, kNumAnchorPerCls     * sizeof(float)));
-    // GPU_CHECK(cudaMemset(rpn_buffers_[3],    0, kNumAnchorPerCls * 2 * kNumOutputBoxFeature * sizeof(float)));
-    // GPU_CHECK(cudaMemset(rpn_buffers_[4],    0, kNumAnchorPerCls * 4 * sizeof(float)));
-    // GPU_CHECK(cudaMemset(rpn_buffers_[5],    0, kNumAnchorPerCls * kNumOutputBoxFeature * sizeof(float)));
-    // GPU_CHECK(cudaMemset(rpn_buffers_[6],    0, kNumAnchorPerCls     * sizeof(float)));
-    // GPU_CHECK(cudaMemset(rpn_buffers_[7],    0, kNumAnchorPerCls * 2 * kNumOutputBoxFeature * sizeof(float)));
-    // GPU_CHECK(cudaMemset(rpn_buffers_[8],    0, kNumAnchorPerCls * 4 * sizeof(float)));
-    // GPU_CHECK(cudaMemset(rpn_buffers_[9],    0, kNumAnchorPerCls * kNumOutputBoxFeature * sizeof(float)));
-    // GPU_CHECK(cudaMemset(rpn_buffers_[10],   0, kNumAnchorPerCls     * sizeof(float)));
-
-    GPU_CHECK(cudaMemset(dev_filtered_box_,     0, kNumAnchor * kNumOutputBoxFeature * sizeof(float)));
-    GPU_CHECK(cudaMemset(dev_filtered_score_,   0, kNumAnchor * sizeof(float)));
-    GPU_CHECK(cudaMemset(dev_filter_count_,     0, kNumClass * sizeof(int)));
-}
-
-void PointPillars::InitTRT(const bool use_onnx) {
-  if (use_onnx_) {
-    // create a TensorRT model from the onnx model and load it into an engine
-    OnnxToTRTModel(pfe_file_, &pfe_engine_);
-    SaveEngine(pfe_engine_, pfe_file_.substr(0, pfe_file_.find(".")) + ".trt");
-    OnnxToTRTModel(backbone_file_, &backbone_engine_);
-    SaveEngine(backbone_engine_, backbone_file_.substr(0, backbone_file_.find(".")) + ".trt");
-  }else {
-    EngineToTRTModel(pfe_file_, &pfe_engine_);
-    EngineToTRTModel(backbone_file_, &backbone_engine_);
-  }
-    if (pfe_engine_ == nullptr || backbone_engine_ == nullptr) {
-        std::cerr << "Failed to load ONNX file.";
-    }
-
-    // create execution context from the engine
-    pfe_context_ = pfe_engine_->createExecutionContext();
-    backbone_context_ = backbone_engine_->createExecutionContext();
-    if (pfe_context_ == nullptr || backbone_context_ == nullptr) {
-        std::cerr << "Failed to create TensorRT Execution Context.";
-    }
-  
-}
-
-void PointPillars::OnnxToTRTModel(
-    const std::string& model_file,  // name of the onnx model
-    nvinfer1::ICudaEngine** engine_ptr) {
-    int verbosity = static_cast<int>(nvinfer1::ILogger::Severity::kWARNING);
-
-    // create the builder
-    const auto explicit_batch =
-        static_cast<uint32_t>(kBatchSize) << static_cast<uint32_t>(
-            nvinfer1::NetworkDefinitionCreationFlag::kEXPLICIT_BATCH);
-    nvinfer1::IBuilder* builder = nvinfer1::createInferBuilder(g_logger_);
-    nvinfer1::INetworkDefinition* network =
-        builder->createNetworkV2(explicit_batch);
-
-    // parse onnx model
-    auto parser = nvonnxparser::createParser(*network, g_logger_);
-    if (!parser->parseFromFile(model_file.c_str(), verbosity)) {
-        std::string msg("failed to parse onnx file");
-        g_logger_.log(nvinfer1::ILogger::Severity::kERROR, msg.c_str());
-        exit(EXIT_FAILURE);
-    }
-
-    // Build the engine
-    builder->setMaxBatchSize(kBatchSize);
-    builder->setHalf2Mode(true);
-    nvinfer1::IBuilderConfig* config = builder->createBuilderConfig();
-    config->setMaxWorkspaceSize(1 << 25);
-    nvinfer1::ICudaEngine* engine =
-        builder->buildEngineWithConfig(*network, *config);
-
-    *engine_ptr = engine;
-    parser->destroy();
-    network->destroy();
-    config->destroy();
-    builder->destroy();
-}
-
-void PointPillars::SaveEngine(const nvinfer1::ICudaEngine* engine, const std::string& engine_filepath)
-{
-    // serialize the engine, then close everything down
-    nvinfer1::IHostMemory& trtModelStream = *(engine->serialize());
-    std::ofstream file;
-    file.open(engine_filepath, std::ios::binary | std::ios::out);
-    if(!file.is_open())
-    {
-        std::cout << "read create engine file" << engine_filepath <<" failed" << std::endl;
-        return;
-    }
-    file.write((const char*)trtModelStream.data(), std::streamsize(trtModelStream.size()));
-    file.close();
-}
-
-void PointPillars::EngineToTRTModel(
-    const std::string &engine_file ,     
-    nvinfer1::ICudaEngine** engine_ptr)  {
-    int verbosity = static_cast<int>(nvinfer1::ILogger::Severity::kWARNING);
-    std::stringstream gieModelStream; 
-    gieModelStream.seekg(0, gieModelStream.beg); 
-
-    std::ifstream cache(engine_file); 
-    gieModelStream << cache.rdbuf();
-    cache.close(); 
-    nvinfer1::IRuntime* runtime = nvinfer1::createInferRuntime(g_logger_); 
-
-    if (runtime == nullptr) {
-        std::string msg("failed to build runtime parser");
-        g_logger_.log(nvinfer1::ILogger::Severity::kERROR, msg.c_str());
-        exit(EXIT_FAILURE);
-    }
-    gieModelStream.seekg(0, std::ios::end);
-    const int modelSize = gieModelStream.tellg(); 
-
-    gieModelStream.seekg(0, std::ios::beg);
-    void* modelMem = malloc(modelSize); 
-    gieModelStream.read((char*)modelMem, modelSize);
-
-    std::cout << "                                                                  "<< std::endl;
-    std::cout << "------------------------------------------------------------------"<< std::endl;
-    std::cout << ">>>>                                                          >>>>"<< std::endl;
-    std::cout << "                                                                  "<< std::endl;
-    std::cout << "Input filename:   " << engine_file << std::endl;
-    std::cout << "                                                                  "<< std::endl;
-    std::cout << ">>>>                                                          >>>>"<< std::endl;
-    std::cout << "------------------------------------------------------------------"<< std::endl;
-    std::cout << "                                                                  "<< std::endl;
-
-    nvinfer1::ICudaEngine* engine = runtime->deserializeCudaEngine(modelMem, modelSize, NULL); 
-    if (engine == nullptr) {
-        std::string msg("failed to build engine parser");
-        g_logger_.log(nvinfer1::ILogger::Severity::kERROR, msg.c_str());
-        exit(EXIT_FAILURE);
-    }
-    *engine_ptr = engine;
-
-}
-
-void PointPillars::DoInference(const float* in_points_array,
-                                const int in_num_points,
-                                std::vector<float>* out_detections,
-                                std::vector<int>* out_labels,
-                                std::vector<float>* out_scores) 
-{
-    SetDeviceMemoryToZero();
-    cudaDeviceSynchronize();
-    // [STEP 1] : load pointcloud
-    float* dev_points;
-    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&dev_points),
-                        in_num_points * kNumPointFeature * sizeof(float))); // in_num_points , 5
-    GPU_CHECK(cudaMemset(dev_points, 0, in_num_points * kNumPointFeature * sizeof(float)));
-    GPU_CHECK(cudaMemcpy(dev_points, in_points_array,
-                        in_num_points * kNumPointFeature * sizeof(float),
-                        cudaMemcpyHostToDevice));
-    
-    // [STEP 2] : preprocess
-    host_pillar_count_[0] = 0;
-    auto preprocess_start = std::chrono::high_resolution_clock::now();
-    preprocess_points_cuda_ptr_->DoPreprocessPointsCuda(
-          dev_points, in_num_points, dev_x_coors_, dev_y_coors_,
-          dev_num_points_per_pillar_, dev_pillar_point_feature_, dev_pillar_coors_,
-          dev_sparse_pillar_map_, host_pillar_count_ ,
-          dev_pfe_gather_feature_ );
-    cudaDeviceSynchronize();
-    auto preprocess_end = std::chrono::high_resolution_clock::now();
-    // DEVICE_SAVE<float>(dev_pfe_gather_feature_,  kMaxNumPillars * kMaxNumPointsPerPillar * kNumGatherPointFeature  , "0_Model_pfe_input_gather_feature");
-
-    // [STEP 3] : pfe forward
-    cudaStream_t stream;
-    GPU_CHECK(cudaStreamCreate(&stream));
-    auto pfe_start = std::chrono::high_resolution_clock::now();
-    GPU_CHECK(cudaMemcpyAsync(pfe_buffers_[0], dev_pfe_gather_feature_,
-                            kMaxNumPillars * kMaxNumPointsPerPillar * kNumGatherPointFeature * sizeof(float), ///kNumGatherPointFeature
-                            cudaMemcpyDeviceToDevice, stream));
-    pfe_context_->enqueueV2(pfe_buffers_, stream, nullptr);
-    cudaDeviceSynchronize();
-    auto pfe_end = std::chrono::high_resolution_clock::now();
-    // DEVICE_SAVE<float>(reinterpret_cast<float*>(pfe_buffers_[1]),  kMaxNumPillars * 64 , "1_Model_pfe_output_buffers_[1]");
-
-    // [STEP 4] : scatter pillar feature
-    auto scatter_start = std::chrono::high_resolution_clock::now();
-    scatter_cuda_ptr_->DoScatterCuda(
-        host_pillar_count_[0], dev_x_coors_, dev_y_coors_,
-        reinterpret_cast<float*>(pfe_buffers_[1]), dev_scattered_feature_);
-    cudaDeviceSynchronize();
-    auto scatter_end = std::chrono::high_resolution_clock::now();   
-    // DEVICE_SAVE<float>(dev_scattered_feature_ ,  kRpnInputSize,"2_Model_backbone_input_dev_scattered_feature");
-
-    // [STEP 5] : backbone forward
-    auto backbone_start = std::chrono::high_resolution_clock::now();
-    GPU_CHECK(cudaMemcpyAsync(rpn_buffers_[0], dev_scattered_feature_,
-                            kBatchSize * kRpnInputSize * sizeof(float),
-                            cudaMemcpyDeviceToDevice, stream));
-    backbone_context_->enqueueV2(rpn_buffers_, stream, nullptr);
-    cudaDeviceSynchronize();
-    auto backbone_end = std::chrono::high_resolution_clock::now();
-    // DEVICE_SAVE<float>(reinterpret_cast<float*>(rpn_buffers_[1]) ,  kNumAnchorPerCls    ,"3_rpn_buffers_[1]");
-    // DEVICE_SAVE<float>(reinterpret_cast<float*>(rpn_buffers_[2]) ,  kNumAnchorPerCls * 4,"3_rpn_buffers_[2]");
-    // DEVICE_SAVE<float>(reinterpret_cast<float*>(rpn_buffers_[3]) ,  kNumAnchorPerCls * 4,"3_rpn_buffers_[3]");
-    // DEVICE_SAVE<float>(reinterpret_cast<float*>(rpn_buffers_[4]) ,  kNumAnchorPerCls    ,"3_rpn_buffers_[4]");
-    // DEVICE_SAVE<float>(reinterpret_cast<float*>(rpn_buffers_[5]) ,  kNumAnchorPerCls * 4,"3_rpn_buffers_[5]");
-    // DEVICE_SAVE<float>(reinterpret_cast<float*>(rpn_buffers_[6]) ,  kNumAnchorPerCls * 4,"3_rpn_buffers_[6]");
-    // DEVICE_SAVE<float>(reinterpret_cast<float*>(rpn_buffers_[7]) ,  kNumAnchorPerCls * kNumClass * 9 ,"3_rpn_buffers_[7]");
-
-    // [STEP 6]: postprocess (multihead)
-    auto postprocess_start = std::chrono::high_resolution_clock::now();
-    GPU_CHECK(cudaMemset(dev_filter_count_, 0, kNumClass * sizeof(int)));
-    postprocess_cuda_ptr_->DoPostprocessCuda(
-        reinterpret_cast<float*>(rpn_buffers_[1]), // [cls]   kNumAnchorPerCls 
-        reinterpret_cast<float*>(rpn_buffers_[2]), // [cls]   kNumAnchorPerCls * 2 * 2
-        reinterpret_cast<float*>(rpn_buffers_[3]), // [cls]   kNumAnchorPerCls * 2 * 2
-        reinterpret_cast<float*>(rpn_buffers_[4]), // [cls]   kNumAnchorPerCls 
-        reinterpret_cast<float*>(rpn_buffers_[5]), // [cls]   kNumAnchorPerCls * 2 * 2
-        reinterpret_cast<float*>(rpn_buffers_[6]), // [cls]   kNumAnchorPerCls * 2 * 2
-        reinterpret_cast<float*>(rpn_buffers_[7]), // [boxes] kNumAnchorPerCls * kNumClass * kNumOutputBoxFeature
-        dev_filtered_box_, dev_filtered_score_, dev_filter_count_,
-        *out_detections, *out_labels , *out_scores);
-    cudaDeviceSynchronize();
-    auto postprocess_end = std::chrono::high_resolution_clock::now();
-
-    // release the stream and the buffers
-//    std::chrono::duration<double> preprocess_cost = preprocess_end - preprocess_start;
-//    std::chrono::duration<double> pfe_cost = pfe_end - pfe_start;
-//    std::chrono::duration<double> scatter_cost = scatter_end - scatter_start;
-//    std::chrono::duration<double> backbone_cost = backbone_end - backbone_start;
-//    std::chrono::duration<double> postprocess_cost = postprocess_end - postprocess_start;
-
-//    std::chrono::duration<double> pointpillars_cost = postprocess_end - preprocess_start;
-//    std::cout << "------------------------------------" << std::endl;
-//    std::cout << setiosflags(ios::left)  << setw(14) << "Module" << setw(12)  << "Time"  << resetiosflags(ios::left) << std::endl;
-//    std::cout << "------------------------------------" << std::endl;
-//    std::string Modules[] = {"Preprocess" , "Pfe" , "Scatter" , "Backbone" , "Postprocess" , "Summary"};
-//    double Times[] = {preprocess_cost.count() , pfe_cost.count() , scatter_cost.count() , backbone_cost.count() , postprocess_cost.count() , pointpillars_cost.count()};
-
-//    for (int i =0 ; i < 6 ; ++i) {
-//        std::cout << setiosflags(ios::left) << setw(14) << Modules[i]  << setw(8)  << Times[i] * 1000 << " ms" << resetiosflags(ios::left) << std::endl;
-//    }
-//    std::cout << "------------------------------------" << std::endl;
-    cudaStreamDestroy(stream);
-
-}

+ 0 - 287
src/detection/detection_lidar_PointPillars_MultiHead_1025/pointpillars.h

@@ -1,287 +0,0 @@
-/******************************************************************************
- * Copyright 2020 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.
- *****************************************************************************/
-
-/*
- * Copyright 2018-2019 Autoware Foundation. 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.
- */
-
-/**
- * @author Kosuke Murakami
- * @date 2019/02/26
- */
-
-/**
-* @author Yan haixu
-* Contact: just github.com/hova88
-* @date 2021/04/30
-*/
-
-
-#pragma once
-
-// headers in STL
-#include <algorithm>
-#include <cmath>
-#include <iomanip>
-#include <limits>
-#include <map>
-#include <memory>
-#include <string>
-#include <vector>
-#include <iostream>
-#include <sstream>
-#include <fstream>
-// headers in TensorRT
-#include "NvInfer.h"
-#include "NvOnnxParser.h"
-
-// headers in local files
-// #include "params.h"
-#include "common.h"
-#include <yaml-cpp/yaml.h>
-#include "preprocess.h"
-#include "scatter.h"
-#include "postprocess.h"
-
-using namespace std;
-
-// Logger for TensorRT info/warning/errors
-class Logger : public nvinfer1::ILogger {
- public:
-  explicit Logger(Severity severity = Severity::kWARNING)
-      : reportable_severity(severity) {}
-
-  void log(Severity severity, const char* msg) override {
-    // suppress messages with severity enum value greater than the reportable
-    if (severity > reportable_severity) return;
-
-    switch (severity) {
-      case Severity::kINTERNAL_ERROR:
-        std::cerr << "INTERNAL_ERROR: ";
-        break;
-      case Severity::kERROR:
-        std::cerr << "ERROR: ";
-        break;
-      case Severity::kWARNING:
-        std::cerr << "WARNING: ";
-        break;
-      case Severity::kINFO:
-        std::cerr << "INFO: ";
-        break;
-      default:
-        std::cerr << "UNKNOWN: ";
-        break;
-    }
-    std::cerr << msg << std::endl;
-  }
-
-  Severity reportable_severity;
-};
-
-
-
-class PointPillars {
- private:
-    // initialize in initializer list
-    const float score_threshold_;
-    const float nms_overlap_threshold_;
-    const bool use_onnx_;
-    const std::string pfe_file_;
-    const std::string backbone_file_;
-    const std::string pp_config_;
-    // end initializer list
-    // voxel size
-    float kPillarXSize;
-    float kPillarYSize;
-    float kPillarZSize;
-    // point cloud range
-    float kMinXRange;
-    float kMinYRange;
-    float kMinZRange;
-    float kMaxXRange;
-    float kMaxYRange;
-    float kMaxZRange;
-    // hyper parameters
-    int kNumClass;
-    int kMaxNumPillars;
-    int kMaxNumPointsPerPillar;
-    int kNumPointFeature;
-    int kNumGatherPointFeature = 11;
-    int kGridXSize;
-    int kGridYSize;
-    int kGridZSize;
-    int kNumAnchorXinds;
-    int kNumAnchorYinds;
-    int kRpnInputSize;
-    int kNumAnchor;
-    int kNumInputBoxFeature;
-    int kNumOutputBoxFeature;
-    int kRpnBoxOutputSize;
-    int kRpnClsOutputSize;
-    int kRpnDirOutputSize;
-    int kBatchSize;
-    int kNumIndsForScan;
-    int kNumThreads;
-    // if you change kNumThreads, need to modify NUM_THREADS_MACRO in
-    // common.h
-    int kNumBoxCorners;
-    int kNmsPreMaxsize;
-    int kNmsPostMaxsize;
-    //params for initialize anchors
-    //Adapt to OpenPCDet
-    int kAnchorStrides;
-    std::vector<string> kAnchorNames;
-    std::vector<float> kAnchorDxSizes;
-    std::vector<float> kAnchorDySizes;
-    std::vector<float> kAnchorDzSizes;
-    std::vector<float> kAnchorBottom;
-    std::vector<std::vector<int>> kMultiheadLabelMapping;
-    int kNumAnchorPerCls;
-    int host_pillar_count_[1];
-
-    int* dev_x_coors_;
-    int* dev_y_coors_;
-    float* dev_num_points_per_pillar_;
-    int* dev_sparse_pillar_map_;
-    int* dev_cumsum_along_x_;
-    int* dev_cumsum_along_y_;
-
-    float* dev_pillar_point_feature_;
-    float* dev_pillar_coors_;
-    float* dev_points_mean_;
-
-    float* dev_pfe_gather_feature_;
-    void* pfe_buffers_[2];
-    //variable for doPostprocessCudaMultiHead
-    void* rpn_buffers_[8];
-    
-    std::vector<float*> rpn_box_output_; 
-    std::vector<float*> rpn_cls_output_;
-
-    float* dev_scattered_feature_;
-
-    float* dev_filtered_box_;
-    float* dev_filtered_score_;
-    int*   dev_filtered_label_;
-    int*   dev_filtered_dir_;
-    float* dev_box_for_nms_;
-    int*   dev_filter_count_;
-
-    std::unique_ptr<PreprocessPointsCuda> preprocess_points_cuda_ptr_;
-    std::unique_ptr<ScatterCuda> scatter_cuda_ptr_;
-    std::unique_ptr<PostprocessCuda> postprocess_cuda_ptr_;
-
-    Logger g_logger_;
-    nvinfer1::ICudaEngine* pfe_engine_;
-    nvinfer1::ICudaEngine* backbone_engine_;
-    nvinfer1::IExecutionContext* pfe_context_;
-    nvinfer1::IExecutionContext* backbone_context_;
-
-    /**
-     * @brief Memory allocation for device memory
-     * @details Called in the constructor
-     */
-    void DeviceMemoryMalloc();
-
-    /**
-     * @brief Memory set to 0 for device memory
-     * @details Called in the DoInference
-     */
-    void SetDeviceMemoryToZero();
-
-    /**
-     * @brief Initializing paraments from pointpillars.yaml
-     * @details Called in the constructor
-     */
-    void InitParams();
-    /**
-     * @brief Initializing TensorRT instances
-     * @param[in] usr_onnx_ if true, parse ONNX 
-     * @details Called in the constructor
-     */
-    void InitTRT(const bool use_onnx);
-    void SaveEngine(const nvinfer1::ICudaEngine* engine, const std::string& engine_filepath);
-    /**
-     * @brief Convert ONNX to TensorRT model
-     * @param[in] model_file ONNX model file path
-     * @param[out] engine_ptr TensorRT model engine made out of ONNX model
-     * @details Load ONNX model, and convert it to TensorRT model
-     */
-    void OnnxToTRTModel(const std::string& model_file,
-                        nvinfer1::ICudaEngine** engine_ptr);
-
-    /**
-     * @brief Convert Engine to TensorRT model
-     * @param[in] model_file Engine(TensorRT) model file path
-     * @param[out] engine_ptr TensorRT model engine made 
-     * @details Load Engine model, and convert it to TensorRT model
-     */
-    void EngineToTRTModel(const std::string &engine_file ,     
-                        nvinfer1::ICudaEngine** engine_ptr) ;
-
-    /**
-     * @brief Preproces points
-     * @param[in] in_points_array Point cloud array
-     * @param[in] in_num_points Number of points
-     * @details Call CPU or GPU preprocess
-     */
-    void Preprocess(const float* in_points_array, const int in_num_points);
-
-    public:
-    /**
-     * @brief Constructor
-     * @param[in] score_threshold Score threshold for filtering output
-     * @param[in] nms_overlap_threshold IOU threshold for NMS
-     * @param[in] use_onnx if true,using onnx file ,else using engine file
-     * @param[in] pfe_file Pillar Feature Extractor ONNX file path
-     * @param[in] rpn_file Region Proposal Network ONNX file path
-     * @details Variables could be changed through point_pillars_detection
-     */
-    PointPillars(const float score_threshold,
-                const float nms_overlap_threshold,
-                const bool use_onnx,
-                const std::string pfe_file,
-                const std::string rpn_file,
-                const std::string pp_config);
-    ~PointPillars();
-
-    /**
-     * @brief Call PointPillars for the inference
-     * @param[in] in_points_array Point cloud array
-     * @param[in] in_num_points Number of points
-     * @param[out] out_detections Network output bounding box
-     * @param[out] out_labels Network output object's label
-     * @details This is an interface for the algorithm
-     */
-    void DoInference(const float* in_points_array,
-                    const int in_num_points,
-                    std::vector<float>* out_detections,
-                    std::vector<int>* out_labels,
-                    std::vector<float>* out_scores);
-};
-

+ 0 - 383
src/detection/detection_lidar_PointPillars_MultiHead_1025/postprocess.cu

@@ -1,383 +0,0 @@
-/******************************************************************************
- * Copyright 2020 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.
- *****************************************************************************/
-
-/*
- * Copyright 2018-2019 Autoware Foundation. 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.
- */
-
-/**
- * @author Kosuke Murakami
- * @date 2019/02/26
- */
-
-/**
-* @author Yan haixu
-* Contact: just github.com/hova88
-* @date 2021/04/30
-*/
-
-
-// headers in CUDA
-#include <thrust/sort.h>
-
-// headers in local files
-#include "common.h"
-#include "postprocess.h"
-#include <stdio.h>
-
-
-// sigmoid_filter_warp
-__device__ void box_decode_warp(int head_offset, const float* box_pred, 
-    int tid , int num_anchors_per_head , int counter, float* filtered_box) 
-{
-    filtered_box[blockIdx.z * num_anchors_per_head * 7  + counter * 7 + 0] = box_pred[ head_offset + tid * 9 + 0];
-    filtered_box[blockIdx.z * num_anchors_per_head * 7  + counter * 7 + 1] = box_pred[ head_offset + tid * 9 + 1];
-    filtered_box[blockIdx.z * num_anchors_per_head * 7  + counter * 7 + 2] = box_pred[ head_offset + tid * 9 + 2];
-    filtered_box[blockIdx.z * num_anchors_per_head * 7  + counter * 7 + 3] = box_pred[ head_offset + tid * 9 + 3];
-    filtered_box[blockIdx.z * num_anchors_per_head * 7  + counter * 7 + 4] = box_pred[ head_offset + tid * 9 + 4];
-    filtered_box[blockIdx.z * num_anchors_per_head * 7  + counter * 7 + 5] = box_pred[ head_offset + tid * 9 + 5];
-    filtered_box[blockIdx.z * num_anchors_per_head * 7  + counter * 7 + 6] = box_pred[ head_offset + tid * 9 + 6];
-}
-
-
-__global__ void sigmoid_filter_kernel(
-
-    float* cls_pred_0,
-    float* cls_pred_12,
-    float* cls_pred_34,
-    float* cls_pred_5,
-    float* cls_pred_67,
-    float* cls_pred_89,
-
-    const float* box_pred_0,
-
-    const float* box_pred_1,
-    const float* box_pred_2,
-
-    const float* box_pred_3,
-    const float* box_pred_4,
-
-    const float* box_pred_5,
-
-    const float* box_pred_6,
-    const float* box_pred_7,
-
-    const float* box_pred_8,
-    const float* box_pred_9,
-
-    float* filtered_box, 
-    float* filtered_score, 
-    int* filter_count,
-
-    const float score_threshold) {   
-
-    // cls_pred_34 
-    // 32768*2 , 2
-
-    int num_anchors_per_head = gridDim.x * gridDim.y * blockDim.x;
-    // 16 * 4 * 512 = 32768
-    extern __shared__ float cls_score[];
-    cls_score[threadIdx.x + blockDim.x] = -1.0f;
-
-    int tid = blockIdx.x * gridDim.y * blockDim.x + blockIdx.y *  blockDim.x + threadIdx.x; 
-
-
-    if ( blockIdx.z == 0) cls_score[ threadIdx.x ] = 1 / (1 + expf(-cls_pred_0[ tid ]));
-    if ( blockIdx.z == 1) {
-        cls_score[ threadIdx.x ] = 1 / (1 + expf(-cls_pred_12[ tid * 2 ]));
-        cls_score[ threadIdx.x + blockDim.x] = 1 / (1 + expf(-cls_pred_12[ (num_anchors_per_head + tid) * 2]));}
-    if ( blockIdx.z == 2) {
-        cls_score[ threadIdx.x ] = 1 / (1 + expf(-cls_pred_12[ tid * 2 + 1]));
-        cls_score[ threadIdx.x + blockDim.x] = 1 / (1 + expf(-cls_pred_12[ (num_anchors_per_head + tid) * 2 + 1]));}
-
-    if ( blockIdx.z == 3) {
-        cls_score[ threadIdx.x ] = 1 / (1 + expf(-cls_pred_34[ tid * 2 ]));
-        cls_score[ threadIdx.x + blockDim.x] = 1 / (1 + expf(-cls_pred_34[ (num_anchors_per_head + tid) * 2]));}
-    if ( blockIdx.z == 4) {
-        cls_score[ threadIdx.x ] = 1 / (1 + expf(-cls_pred_34[ tid * 2 + 1 ]));
-        cls_score[ threadIdx.x + blockDim.x] = 1 / (1 + expf(-cls_pred_34[ (num_anchors_per_head + tid) * 2 + 1]));}
-
-    if ( blockIdx.z == 5) cls_score[ threadIdx.x ] = 1 / (1 + expf(-cls_pred_5[ tid ]));
-
-    if ( blockIdx.z == 6) {
-        cls_score[ threadIdx.x ] = 1 / (1 + expf(-cls_pred_67[ tid * 2 ]));
-        cls_score[ threadIdx.x + blockDim.x] = 1 / (1 + expf(-cls_pred_67[ (num_anchors_per_head + tid) * 2]));}
-    if ( blockIdx.z == 7) {
-        cls_score[ threadIdx.x ] = 1 / (1 + expf(-cls_pred_67[ tid * 2 + 1 ]));
-        cls_score[ threadIdx.x + blockDim.x] = 1 / (1 + expf(-cls_pred_67[ (num_anchors_per_head + tid) * 2 + 1]));}
-
-    if ( blockIdx.z == 8) {
-        cls_score[ threadIdx.x ] = 1 / (1 + expf(-cls_pred_89[ tid * 2 ]));
-        cls_score[ threadIdx.x + blockDim.x] = 1 / (1 + expf(-cls_pred_89[ (num_anchors_per_head + tid) * 2]));}
-    if ( blockIdx.z == 9) {
-        cls_score[ threadIdx.x ] = 1 / (1 + expf(-cls_pred_89[ tid * 2 + 1 ]));
-        cls_score[ threadIdx.x + blockDim.x] = 1 / (1 + expf(-cls_pred_89[ (num_anchors_per_head + tid) * 2 + 1]));}
-    
-    __syncthreads();
-    
-    if( cls_score[ threadIdx.x ] > score_threshold) 
-    {
-        int counter = atomicAdd(&filter_count[blockIdx.z], 1);
-        if ( blockIdx.z == 0) {
-            box_decode_warp(0 ,box_pred_0 , tid , num_anchors_per_head , counter , filtered_box);
-            filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
-        }else
-        if ( blockIdx.z == 1) {
-            box_decode_warp(0 ,box_pred_1 , tid , num_anchors_per_head , counter , filtered_box);
-            filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
-        }else
-        if ( blockIdx.z == 2) {
-            box_decode_warp(0 ,box_pred_1 , tid , num_anchors_per_head , counter , filtered_box);
-            filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
-        }else
-        if ( blockIdx.z == 3) {
-            box_decode_warp(0 ,box_pred_3 , tid , num_anchors_per_head , counter , filtered_box);
-            filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
-        }else 
-        if (blockIdx.z == 4) {
-            box_decode_warp(0 ,box_pred_3 , tid , num_anchors_per_head , counter , filtered_box);
-            filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];            
-        }else
-        if ( blockIdx.z == 5) {
-            box_decode_warp(0 ,box_pred_5 , tid , num_anchors_per_head , counter , filtered_box);
-            filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
-        }else
-        if ( blockIdx.z == 6) {
-            box_decode_warp(0 ,box_pred_6 , tid , num_anchors_per_head , counter , filtered_box);
-            filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
-        }else
-        if ( blockIdx.z == 7) {
-            box_decode_warp(0 ,box_pred_6 , tid , num_anchors_per_head , counter , filtered_box);
-            filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
-        }else
-        if ( blockIdx.z == 8) {
-
-            box_decode_warp(0 ,box_pred_8 , tid , num_anchors_per_head , counter , filtered_box);
-            filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
-        }else
-        if ( blockIdx.z == 9) {
-            box_decode_warp(0 ,box_pred_8 , tid , num_anchors_per_head , counter , filtered_box);
-            filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
-        }
-    }
-    __syncthreads();  
-    if( cls_score[ threadIdx.x + blockDim.x ] > score_threshold)  {     
-            int counter = atomicAdd(&filter_count[blockIdx.z], 1);
-            // printf("counter : %d \n" , counter);
-            if (blockIdx.z == 1) {
-                box_decode_warp(0 ,box_pred_2 , tid , num_anchors_per_head , counter , filtered_box);
-                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
-            }else 
-            if (blockIdx.z == 2) {
-                box_decode_warp(0 ,box_pred_2 , tid , num_anchors_per_head , counter , filtered_box);
-                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
-            }else 
-            if (blockIdx.z == 3) {
-                box_decode_warp(0 ,box_pred_4 , tid , num_anchors_per_head , counter , filtered_box);
-                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
-            }else 
-            if (blockIdx.z == 4) {
-                box_decode_warp(0 ,box_pred_4 , tid , num_anchors_per_head , counter , filtered_box);
-                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
-            }else 
-            if (blockIdx.z == 6) {
-                box_decode_warp(0 ,box_pred_7 , tid , num_anchors_per_head , counter , filtered_box);
-                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
-            }else 
-            if (blockIdx.z == 7) {
-                box_decode_warp(0 ,box_pred_7 , tid , num_anchors_per_head , counter , filtered_box);
-                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
-            }else 
-            if (blockIdx.z == 8) {
-                box_decode_warp(0 ,box_pred_9 , tid , num_anchors_per_head , counter , filtered_box);
-                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
-            }else 
-            if (blockIdx.z == 9) {
-                box_decode_warp(0 ,box_pred_9 , tid , num_anchors_per_head , counter , filtered_box);
-                filtered_score[blockIdx.z * num_anchors_per_head + counter] = cls_score[ threadIdx.x ];
-            }
-    }
-}
-
-__global__ void sort_boxes_by_indexes_kernel(float* filtered_box, float* filtered_scores, int* indexes, int filter_count,
-    float* sorted_filtered_boxes, float* sorted_filtered_scores,
-    const int num_output_box_feature)
-{
-    int tid = threadIdx.x + blockIdx.x * blockDim.x;
-    if(tid < filter_count)  {
-
-        int sort_index = indexes[tid];
-        sorted_filtered_boxes[tid * num_output_box_feature + 0] = filtered_box[sort_index * num_output_box_feature + 0];
-        sorted_filtered_boxes[tid * num_output_box_feature + 1] = filtered_box[sort_index * num_output_box_feature + 1];
-        sorted_filtered_boxes[tid * num_output_box_feature + 2] = filtered_box[sort_index * num_output_box_feature + 2];
-        sorted_filtered_boxes[tid * num_output_box_feature + 3] = filtered_box[sort_index * num_output_box_feature + 3];
-        sorted_filtered_boxes[tid * num_output_box_feature + 4] = filtered_box[sort_index * num_output_box_feature + 4];
-        sorted_filtered_boxes[tid * num_output_box_feature + 5] = filtered_box[sort_index * num_output_box_feature + 5];
-        sorted_filtered_boxes[tid * num_output_box_feature + 6] = filtered_box[sort_index * num_output_box_feature + 6];
-
-        // sorted_filtered_dir[tid] = filtered_dir[sort_index];
-        sorted_filtered_scores[tid] = filtered_scores[sort_index];
-    }
-}
-
-
-
-PostprocessCuda::PostprocessCuda(const int num_threads, const float float_min, const float float_max,
-    const int num_class,const int num_anchor_per_cls,
-    const std::vector<std::vector<int>> multihead_label_mapping,
-    const float score_threshold,  const float nms_overlap_threshold, 
-    const int nms_pre_maxsize, const int nms_post_maxsize,
-    const int num_box_corners, 
-    const int num_input_box_feature,
-    const int num_output_box_feature)
-: num_threads_(num_threads),
-  float_min_(float_min),
-  float_max_(float_max),
-  num_class_(num_class),
-  num_anchor_per_cls_(num_anchor_per_cls),
-  multihead_label_mapping_(multihead_label_mapping),
-  score_threshold_(score_threshold),
-  nms_overlap_threshold_(nms_overlap_threshold),
-  nms_pre_maxsize_(nms_pre_maxsize),
-  nms_post_maxsize_(nms_post_maxsize),
-  num_box_corners_(num_box_corners),
-  num_input_box_feature_(num_input_box_feature),
-  num_output_box_feature_(num_output_box_feature) {
-    nms_cuda_ptr_.reset(
-    new NmsCuda(num_threads_, num_box_corners_, nms_overlap_threshold_));
-
-}
-
-
-void PostprocessCuda::DoPostprocessCuda(
-    float* cls_pred_0,
-    float* cls_pred_12,
-    float* cls_pred_34,
-    float* cls_pred_5,
-    float* cls_pred_67,
-    float* cls_pred_89,
-
-    const float* box_preds,
-   
-    float* dev_filtered_box, 
-    float* dev_filtered_score, 
-    int* dev_filter_count,
-    std::vector<float>& out_detection, std::vector<int>& out_label , std::vector<float>& out_score) {
-    // 在此之前,先进行rpn_box_output的concat. 
-    // 128x128 的feature map, cls_pred 的shape为(32768,1),(32768,1),(32768,1),(65536,2),(32768,1)
-    dim3 gridsize(16, 4 , 10);  //16 *  4  * 512  = 32768 代表一个head的anchors
-    sigmoid_filter_kernel<<< gridsize, 512 , 512 * 2 * sizeof(float)>>>(
-        cls_pred_0,
-        cls_pred_12, 
-        cls_pred_34, 
-        cls_pred_5, 
-        cls_pred_67, 
-        cls_pred_89,
-
-        &box_preds[0 * 32768 * 9],
-        &box_preds[1 * 32768 * 9],
-        &box_preds[2 * 32768 * 9],
-        &box_preds[3 * 32768 * 9],
-        &box_preds[4 * 32768 * 9],
-        &box_preds[5 * 32768 * 9],
-        &box_preds[6 * 32768 * 9],
-        &box_preds[7 * 32768 * 9],
-        &box_preds[8 * 32768 * 9],
-        &box_preds[9 * 32768 * 9],
-
-        dev_filtered_box, 
-        dev_filtered_score,  
-        dev_filter_count, 
-    
-        score_threshold_);
-    cudaDeviceSynchronize();
-    
-    int host_filter_count[num_class_] = {0};
-    GPU_CHECK(cudaMemcpy(host_filter_count, dev_filter_count, num_class_ * sizeof(int), cudaMemcpyDeviceToHost));
-    
-    for (int i = 0; i < num_class_; ++ i) {
-        if(host_filter_count[i] <= 0) continue;
-
-        int* dev_indexes;
-        float* dev_sorted_filtered_box;
-        float* dev_sorted_filtered_scores;
-        GPU_CHECK(cudaMalloc((void**)&dev_indexes, host_filter_count[i] * sizeof(int)));
-        GPU_CHECK(cudaMalloc((void**)&dev_sorted_filtered_box, host_filter_count[i] * num_output_box_feature_ * sizeof(float)));
-        GPU_CHECK(cudaMalloc((void**)&dev_sorted_filtered_scores, host_filter_count[i]*sizeof(float)));
-        // GPU_CHECK(cudaMalloc((void**)&dev_sorted_box_for_nms, NUM_BOX_CORNERS_*host_filter_count[i]*sizeof(float)));
-        thrust::sequence(thrust::device, dev_indexes, dev_indexes + host_filter_count[i]);
-        thrust::sort_by_key(thrust::device, 
-                            &dev_filtered_score[i * num_anchor_per_cls_], 
-                            &dev_filtered_score[i * num_anchor_per_cls_ + host_filter_count[i]],
-                            dev_indexes, 
-                            thrust::greater<float>());
-
-        const int num_blocks = DIVUP(host_filter_count[i], num_threads_);
-
-        sort_boxes_by_indexes_kernel<<<num_blocks, num_threads_>>>(
-            &dev_filtered_box[i * num_anchor_per_cls_ * num_output_box_feature_], 
-            &dev_filtered_score[i * num_anchor_per_cls_], 
-            dev_indexes, 
-            host_filter_count[i],
-            dev_sorted_filtered_box, 
-            dev_sorted_filtered_scores,
-            num_output_box_feature_);
-
-        int num_box_for_nms = min(nms_pre_maxsize_, host_filter_count[i]);
-        long* keep_inds = new long[num_box_for_nms];  // index of kept box
-        memset(keep_inds, 0, num_box_for_nms * sizeof(int));
-        int num_out = 0;
-        nms_cuda_ptr_->DoNmsCuda(num_box_for_nms, dev_sorted_filtered_box, keep_inds, &num_out);
-
-        num_out = min(num_out, nms_post_maxsize_);
-
-        float* host_filtered_box = new float[host_filter_count[i] * num_output_box_feature_]();
-        float* host_filtered_scores = new float[host_filter_count[i]]();
-
-
-        cudaMemcpy(host_filtered_box, dev_sorted_filtered_box, host_filter_count[i] * num_output_box_feature_ * sizeof(float), cudaMemcpyDeviceToHost);
-        cudaMemcpy(host_filtered_scores, dev_sorted_filtered_scores, host_filter_count[i] * sizeof(float), cudaMemcpyDeviceToHost);
-        for (int j = 0; j < num_out; ++j)  {
-            out_detection.emplace_back(host_filtered_box[keep_inds[j] * num_output_box_feature_ + 0]);
-            out_detection.emplace_back(host_filtered_box[keep_inds[j] * num_output_box_feature_ + 1]);
-            out_detection.emplace_back(host_filtered_box[keep_inds[j] * num_output_box_feature_ + 2]);
-            out_detection.emplace_back(host_filtered_box[keep_inds[j] * num_output_box_feature_ + 3]);
-            out_detection.emplace_back(host_filtered_box[keep_inds[j] * num_output_box_feature_ + 4]);
-            out_detection.emplace_back(host_filtered_box[keep_inds[j] * num_output_box_feature_ + 5]);
-            out_detection.emplace_back(host_filtered_box[keep_inds[j] * num_output_box_feature_ + 6]);
-            out_score.emplace_back(host_filtered_scores[keep_inds[j]]);
-            out_label.emplace_back(i);
-        }
-        delete[] keep_inds;
-        delete[] host_filtered_scores;
-        delete[] host_filtered_box;
-
-        GPU_CHECK(cudaFree(dev_indexes));
-        GPU_CHECK(cudaFree(dev_sorted_filtered_box));
-    }
-}

+ 0 - 125
src/detection/detection_lidar_PointPillars_MultiHead_1025/postprocess.h

@@ -1,125 +0,0 @@
-/******************************************************************************
- * Copyright 2020 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.
- *****************************************************************************/
-
-/*
- * Copyright 2018-2019 Autoware Foundation. 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.
- */
-
-/**
- * @author Kosuke Murakami
- * @date 2019/02/26
- */
-
-/**
-* @author Yan haixu
-* Contact: just github.com/hova88
-* @date 2021/04/30
-*/
-
-#pragma once
-#include <memory>
-#include <vector>
-#include "nms.h"
-
-class PostprocessCuda {
- private:
-    // initializer list
-
-    const int num_threads_;
-    const float float_min_;
-    const float float_max_;
-    const int num_class_;
-    const int num_anchor_per_cls_;
-    const float score_threshold_;
-    const float nms_overlap_threshold_;
-    const int nms_pre_maxsize_;
-    const int nms_post_maxsize_;
-    const int num_box_corners_;
-    const int num_input_box_feature_;
-    const int num_output_box_feature_;
-    const std::vector<std::vector<int>> multihead_label_mapping_;
-    // end initializer list
-
-    std::unique_ptr<NmsCuda> nms_cuda_ptr_;
-  public:
-  /**
-   * @brief Constructor
-   * @param[in] num_threads Number of threads when launching cuda kernel
-   * @param[in] float_min The lowest float value
-   * @param[in] float_max The maximum float value
-   * @param[in] num_class Number of classes 
-   * @param[in] num_anchor_per_cls Number anchor per category
-   * @param[in] multihead_label_mapping 
-   * @param[in] score_threshold Score threshold for filtering output
-   * @param[in] nms_overlap_threshold IOU threshold for NMS
-   * @param[in] nms_pre_maxsize Maximum number of boxes into NMS
-   * @param[in] nms_post_maxsize Maximum number of boxes after NMS
-   * @param[in] num_box_corners Number of box's corner
-   * @param[in] num_output_box_feature Number of output box's feature
-   * @details Captital variables never change after the compile, non-capital
-   * variables could be changed through rosparam
-   */
-  PostprocessCuda(const int num_threads, 
-                  const float float_min, const float float_max,
-                  const int num_class, const int num_anchor_per_cls, 
-                  const std::vector<std::vector<int>> multihead_label_mapping,
-                  const float score_threshold,  
-                  const float nms_overlap_threshold, 
-                  const int nms_pre_maxsize, 
-                  const int nms_post_maxsize,
-                  const int num_box_corners,
-                  const int num_input_box_feature, 
-                  const int num_output_box_feature);
-  ~PostprocessCuda(){}
-
-  /**
-   * @brief Postprocessing for the network output
-   * @param[in] rpn_box_output Box predictions from the network output
-   * @param[in] rpn_cls_output Class predictions from the network output
-   * @param[in] rpn_dir_output Direction predictions from the network output
-   * @param[in] dev_filtered_box Filtered box predictions
-   * @param[in] dev_filtered_score Filtered score predictions
-   * @param[in] dev_filter_count The number of filtered output
-   * @param[out] out_detection Output bounding boxes
-   * @param[out] out_label Output labels of objects
-   * @details dev_* represents device memory allocated variables
-   */
-  void DoPostprocessCuda(
-    float* cls_pred_0,
-    float* cls_pred_12,
-    float* cls_pred_34,
-    float* cls_pred_5,
-    float* cls_pred_67,
-    float* cls_pred_89,
-    
-    const float* box_preds,
-    float* dev_filtered_box, 
-    float* dev_filtered_score, 
-    int* dev_filter_count,
-    std::vector<float>& out_detection, std::vector<int>& out_label , std::vector<float>& out_score);
-};

+ 0 - 410
src/detection/detection_lidar_PointPillars_MultiHead_1025/preprocess.cu

@@ -1,410 +0,0 @@
-/******************************************************************************
- * Copyright 2020 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.
- *****************************************************************************/
-
-/*
- * Copyright 2018-2019 Autoware Foundation. 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.
- */
-
-/**
- * @author Kosuke Murakami
- * @date 2019/02/26
- */
-
-/**
-* @author Yan haixu
-* Contact: just github.com/hova88
-* @date 2021/04/30
-*/
-
-
-
-// headers in STL
-#include <stdio.h>
-
-// headers in local files
-#include "common.h"
-#include "preprocess.h"
-
-__global__ void make_pillar_histo_kernel(
-    const float* dev_points, float* dev_pillar_point_feature_in_coors,
-    int* pillar_count_histo, const int num_points,
-    const int max_points_per_pillar, const int grid_x_size,
-    const int grid_y_size, const int grid_z_size, const float min_x_range,
-    const float min_y_range, const float min_z_range, const float pillar_x_size,
-    const float pillar_y_size, const float pillar_z_size,
-    const int num_point_feature) {
-  int th_i = blockIdx.x * blockDim.x +  threadIdx.x ;
-  if (th_i >= num_points) {
-    return;
-  }
-  int x_coor = floor((dev_points[th_i * num_point_feature + 0] - min_x_range) / pillar_x_size);
-  int y_coor = floor((dev_points[th_i * num_point_feature + 1] - min_y_range) / pillar_y_size);
-  int z_coor = floor((dev_points[th_i * num_point_feature + 2] - min_z_range) / pillar_z_size);
-
-  if (x_coor >= 0 && x_coor < grid_x_size && y_coor >= 0 &&
-      y_coor < grid_y_size && z_coor >= 0 && z_coor < grid_z_size) {
-    int count =
-        atomicAdd(&pillar_count_histo[y_coor * grid_x_size + x_coor], 1);
-    if (count < max_points_per_pillar) {
-      int ind =
-          y_coor * grid_x_size * max_points_per_pillar * num_point_feature +
-          x_coor * max_points_per_pillar * num_point_feature +
-          count * num_point_feature;
- 
-      for (int i = 0; i < num_point_feature; ++i) {
-        dev_pillar_point_feature_in_coors[ind + i] =
-            dev_points[th_i * num_point_feature + i];
-      }
-    }
-  }
-}
-
-__global__ void make_pillar_index_kernel(
-    int* dev_pillar_count_histo, int* dev_counter, int* dev_pillar_count,
-    int* dev_x_coors, int* dev_y_coors, float* dev_num_points_per_pillar,
-    int* dev_sparse_pillar_map, const int max_pillars,
-    const int max_points_per_pillar, const int grid_x_size,
-    const int num_inds_for_scan) {
-  int x = blockIdx.x;
-  int y = threadIdx.x;
-  int num_points_at_this_pillar = dev_pillar_count_histo[y * grid_x_size + x];
-  if (num_points_at_this_pillar == 0) {
-    return;
-  }
-
-  int count = atomicAdd(dev_counter, 1);
-  if (count < max_pillars) {
-    atomicAdd(dev_pillar_count, 1);
-    if (num_points_at_this_pillar >= max_points_per_pillar) {
-      dev_num_points_per_pillar[count] = max_points_per_pillar;
-    } else {
-      dev_num_points_per_pillar[count] = num_points_at_this_pillar;
-    }
-    dev_x_coors[count] = x;
-    dev_y_coors[count] = y;
-    dev_sparse_pillar_map[y * num_inds_for_scan + x] = 1;
-  }
-}
-
-__global__ void make_pillar_feature_kernel(
-    float* dev_pillar_point_feature_in_coors, float* dev_pillar_point_feature,
-    float* dev_pillar_coors, int* dev_x_coors, int* dev_y_coors,
-    float* dev_num_points_per_pillar, const int max_points,
-    const int num_point_feature, const int grid_x_size) {
-  int ith_pillar = blockIdx.x;
-  int num_points_at_this_pillar = dev_num_points_per_pillar[ith_pillar];
-  int ith_point = threadIdx.x;
-  if (ith_point >= num_points_at_this_pillar) {
-    return;
-  }
-  int x_ind = dev_x_coors[ith_pillar];
-  int y_ind = dev_y_coors[ith_pillar];
-  int pillar_ind = ith_pillar * max_points * num_point_feature +
-                   ith_point * num_point_feature;
-  int coors_ind = y_ind * grid_x_size * max_points * num_point_feature +
-                  x_ind * max_points * num_point_feature +
-                  ith_point * num_point_feature;
-  #pragma unroll 
-  for (int i = 0; i < num_point_feature; ++i) {
-    dev_pillar_point_feature[pillar_ind + i] =
-        dev_pillar_point_feature_in_coors[coors_ind + i];
-  }
-
-  float coor_x = static_cast<float>(x_ind);
-  float coor_y = static_cast<float>(y_ind);
-  dev_pillar_coors[ith_pillar * 4 + 0] = 0;  // batch idx
-  dev_pillar_coors[ith_pillar * 4 + 1] = 0;  // z
-  dev_pillar_coors[ith_pillar * 4 + 2] = coor_y;
-  dev_pillar_coors[ith_pillar * 4 + 3] = coor_x;
-}
-
-
-
-__global__ void pillar_mean_kernel(
-  float* dev_points_mean, 
-  const int num_point_feature,
-  const float* dev_pillar_point_feature, 
-  const float* dev_num_points_per_pillar, 
-  int max_pillars , 
-  int max_points_per_pillar) {
-
-    extern __shared__ float temp[];
-    int ith_pillar = blockIdx.x; 
-    int ith_point  = threadIdx.x;
-    int axis = threadIdx.y;
-  
-    int reduce_size = max_points_per_pillar > 32 ? 64 : 32;
-    temp[threadIdx.x * 3 + axis] =  dev_pillar_point_feature[ith_pillar * max_points_per_pillar * num_point_feature + ith_point * num_point_feature + axis];  
-    if (threadIdx.x < reduce_size - max_points_per_pillar) {
-        temp[(threadIdx.x + max_points_per_pillar) * 3 + axis] = 0.0f; //--> dummy placeholds will set as 0
-    }
-    __syncthreads();
-    int num_points_at_this_pillar = dev_num_points_per_pillar[ith_pillar];
-
-    if (ith_point >= num_points_at_this_pillar) {
-          return;
-    }
-
-    for (unsigned int d = reduce_size >> 1 ; d > 0.6; d >>= 1) {
-        if (ith_point < d) {
-            temp[ith_point*3 +axis] += temp[(ith_point + d) * 3 + axis];
-        }
-        __syncthreads();
-    }
-
-    if (ith_point == 0) {
-        dev_points_mean[ith_pillar * 3 + axis] = temp[ith_point + axis] / num_points_at_this_pillar ;
-    }
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-__device__ void warpReduce(volatile float* sdata , int ith_point , int axis) {
-    sdata[ith_point * blockDim.y + axis] += sdata[(ith_point + 8) * blockDim.y + axis];
-    sdata[ith_point * blockDim.y + axis] += sdata[(ith_point + 4) * blockDim.y + axis];
-    sdata[ith_point * blockDim.y + axis] += sdata[(ith_point + 2) * blockDim.y + axis];
-    sdata[ith_point * blockDim.y + axis] += sdata[(ith_point + 1) * blockDim.y + axis];
-}
-
-
-
-
-
-__global__ void make_pillar_mean_kernel(
-  float* dev_points_mean, 
-  const int num_point_feature,
-  const float* dev_pillar_point_feature, 
-  const float* dev_num_points_per_pillar, 
-  int max_pillars , 
-  int max_points_pre_pillar) {
-    extern __shared__ float temp[];
-    unsigned int ith_pillar = blockIdx.x;  // { 0 , 1, 2, ... , 10000+}
-    unsigned int ith_point  = threadIdx.x; // { 0 , 1, 2, ...,9}
-    unsigned int axis = threadIdx.y; 
-    unsigned int idx_pre  = ith_pillar * max_points_pre_pillar * num_point_feature \
-                     + ith_point  * num_point_feature;
-    unsigned int idx_post = ith_pillar * max_points_pre_pillar * num_point_feature \
-                     + (ith_point + blockDim.x)  * num_point_feature;
-
-    temp[ith_point * blockDim.y + axis] = 0.0;
-    unsigned int num_points_at_this_pillar = dev_num_points_per_pillar[ith_pillar];
-
-    // if (ith_point < num_points_at_this_pillar / 2) {
-      temp[ith_point * blockDim.y + axis] = dev_pillar_point_feature[idx_pre  + axis] 
-                                          + dev_pillar_point_feature[idx_post + axis];
-    // }
-    __syncthreads();
-
-    // do reduction in shared mem
-    // Sequential addressing. This solves the bank conflicts as
-    // the threads now access shared memory with a stride of one
-    // 32-bit word (unsigned int) now, which does not cause bank 
-    // conflicts
-    warpReduce(temp , ith_point , axis);
-
-	// // write result for this block to global mem
-    if (ith_point == 0)
-    dev_points_mean[ith_pillar * blockDim.y + axis] = temp[ith_point * blockDim.y + axis] / num_points_at_this_pillar ;
-}
-
-
-__global__ void gather_point_feature_kernel(
-  const int max_num_pillars_,const int max_num_points_per_pillar,const int num_point_feature,
-  const float min_x_range, const float min_y_range, const float min_z_range, 
-  const float pillar_x_size,  const float pillar_y_size, const float pillar_z_size,
-  const float* dev_pillar_point_feature, const float* dev_num_points_per_pillar, 
-  const float* dev_pillar_coors,
-  float* dev_points_mean, 
-  float* dev_pfe_gather_feature_){
-
-  int ith_pillar = blockIdx.x; 
-  int ith_point = threadIdx.x;
-  // int kNumPointFeature = 5;
-  int num_gather_feature = 11;
-  int num_points_at_this_pillar = dev_num_points_per_pillar[ith_pillar];
-
-  if (ith_point >= num_points_at_this_pillar){
-        return;
-    }
-
-
-    dev_pfe_gather_feature_[ith_pillar * max_num_points_per_pillar * num_gather_feature + ith_point * num_gather_feature + 0] 
-    =  dev_pillar_point_feature[ith_pillar * max_num_points_per_pillar * num_point_feature + ith_point * num_point_feature + 0]; 
-  
-    dev_pfe_gather_feature_[ith_pillar * max_num_points_per_pillar * num_gather_feature + ith_point * num_gather_feature + 1]  
-    =  dev_pillar_point_feature[ith_pillar * max_num_points_per_pillar * num_point_feature + ith_point * num_point_feature + 1];
-  
-    dev_pfe_gather_feature_[ith_pillar * max_num_points_per_pillar * num_gather_feature + ith_point * num_gather_feature + 2]  
-    =  dev_pillar_point_feature[ith_pillar * max_num_points_per_pillar * num_point_feature + ith_point * num_point_feature + 2];
-  
-    dev_pfe_gather_feature_[ith_pillar * max_num_points_per_pillar * num_gather_feature + ith_point * num_gather_feature + 3]  
-    =  dev_pillar_point_feature[ith_pillar * max_num_points_per_pillar * num_point_feature + ith_point * num_point_feature + 3];
-
-    dev_pfe_gather_feature_[ith_pillar * max_num_points_per_pillar * num_gather_feature + ith_point * num_gather_feature + 4]  
-    =  dev_pillar_point_feature[ith_pillar * max_num_points_per_pillar * num_point_feature + ith_point * num_point_feature + 4];
-  
-    // dev_pfe_gather_feature_[ith_pillar * max_num_points_per_pillar * num_gather_feature + ith_point * num_gather_feature + 4]  =  0.0f;
-    //   f_cluster = voxel_features[:, :, :3] - points_mean
-    dev_pfe_gather_feature_[ith_pillar * max_num_points_per_pillar * num_gather_feature + ith_point * num_gather_feature + 5]  
-    =  dev_pillar_point_feature[ith_pillar * max_num_points_per_pillar * num_point_feature + ith_point * num_point_feature + 0] - dev_points_mean[ith_pillar * 3 + 0 ];
-
-    dev_pfe_gather_feature_[ith_pillar * max_num_points_per_pillar * num_gather_feature + ith_point * num_gather_feature + 6] 
-    =  dev_pillar_point_feature[ith_pillar * max_num_points_per_pillar * num_point_feature + ith_point * num_point_feature + 1] - dev_points_mean[ith_pillar * 3 + 1 ];
-  
-    dev_pfe_gather_feature_[ith_pillar * max_num_points_per_pillar * num_gather_feature + ith_point * num_gather_feature + 7]  
-    =  dev_pillar_point_feature[ith_pillar * max_num_points_per_pillar * num_point_feature + ith_point * num_point_feature + 2] - dev_points_mean[ith_pillar * 3 + 2 ];
-
-    // f_center[:, :, 0] = voxel_features[:, :, 0] - (coords[:, 3].to(voxel_features.dtype).unsqueeze(1) * self.voxel_x + self.x_offset)
-    dev_pfe_gather_feature_[ith_pillar * max_num_points_per_pillar * num_gather_feature + ith_point * num_gather_feature + 8]  
-    =  dev_pillar_point_feature[ith_pillar * max_num_points_per_pillar * num_point_feature + ith_point * num_point_feature + 0] - (dev_pillar_coors[ith_pillar * 4 + 3] * pillar_x_size + (pillar_x_size/2 + min_x_range));
-  
-    dev_pfe_gather_feature_[ith_pillar * max_num_points_per_pillar * num_gather_feature + ith_point * num_gather_feature + 9]  
-    =  dev_pillar_point_feature[ith_pillar * max_num_points_per_pillar * num_point_feature + ith_point * num_point_feature + 1] - (dev_pillar_coors[ith_pillar * 4 + 2] * pillar_y_size + (pillar_y_size/2 + min_y_range));
-  
-    dev_pfe_gather_feature_[ith_pillar * max_num_points_per_pillar * num_gather_feature + ith_point * num_gather_feature + 10] 
-    =  dev_pillar_point_feature[ith_pillar * max_num_points_per_pillar * num_point_feature + ith_point * num_point_feature + 2] - (dev_pillar_coors[ith_pillar * 4 + 1] * pillar_z_size + (pillar_z_size/2 + min_z_range));
-
-}
-
-
-
-
-PreprocessPointsCuda::PreprocessPointsCuda(
-    const int num_threads, const int max_num_pillars,
-    const int max_points_per_pillar, const int num_point_feature,
-    const int num_inds_for_scan, const int grid_x_size, const int grid_y_size,
-    const int grid_z_size, const float pillar_x_size, const float pillar_y_size,
-    const float pillar_z_size, const float min_x_range, const float min_y_range,
-    const float min_z_range)
-    : num_threads_(num_threads),
-      max_num_pillars_(max_num_pillars),
-      max_num_points_per_pillar_(max_points_per_pillar),
-      num_point_feature_(num_point_feature),
-      num_inds_for_scan_(num_inds_for_scan),
-      grid_x_size_(grid_x_size),
-      grid_y_size_(grid_y_size),
-      grid_z_size_(grid_z_size),
-      pillar_x_size_(pillar_x_size),
-      pillar_y_size_(pillar_y_size),
-      pillar_z_size_(pillar_z_size),
-      min_x_range_(min_x_range),
-      min_y_range_(min_y_range),
-      min_z_range_(min_z_range) {
-    
-    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&dev_pillar_point_feature_in_coors_),
-        grid_y_size_ * grid_x_size_ * max_num_points_per_pillar_ *  num_point_feature_ * sizeof(float)));
-    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&dev_pillar_count_histo_),
-        grid_y_size_ * grid_x_size_ * sizeof(int)));
-    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&dev_counter_), sizeof(int)));
-    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&dev_pillar_count_), sizeof(int)));    
-    GPU_CHECK(cudaMalloc(reinterpret_cast<void**>(&dev_points_mean_), max_num_pillars_ * 3 *sizeof(float)));  
-    }
-
-PreprocessPointsCuda::~PreprocessPointsCuda() {
-    GPU_CHECK(cudaFree(dev_pillar_point_feature_in_coors_));
-    GPU_CHECK(cudaFree(dev_pillar_count_histo_));
-    GPU_CHECK(cudaFree(dev_counter_));
-    GPU_CHECK(cudaFree(dev_pillar_count_));
-    GPU_CHECK(cudaFree(dev_points_mean_));
-  }
-
-
-void PreprocessPointsCuda::DoPreprocessPointsCuda(
-    const float* dev_points, const int in_num_points, 
-    int* dev_x_coors,int* dev_y_coors, 
-    float* dev_num_points_per_pillar,
-    float* dev_pillar_point_feature, float* dev_pillar_coors,
-    int* dev_sparse_pillar_map, int* host_pillar_count , float* dev_pfe_gather_feature) {
-    // initialize paraments
-    GPU_CHECK(cudaMemset(dev_pillar_point_feature_in_coors_, 0 , grid_y_size_ * grid_x_size_ * max_num_points_per_pillar_ *  num_point_feature_ * sizeof(float)));
-    GPU_CHECK(cudaMemset(dev_pillar_count_histo_, 0 , grid_y_size_ * grid_x_size_ * sizeof(int)));
-    GPU_CHECK(cudaMemset(dev_counter_, 0, sizeof(int)));
-    GPU_CHECK(cudaMemset(dev_pillar_count_, 0, sizeof(int)));
-    GPU_CHECK(cudaMemset(dev_points_mean_, 0,  max_num_pillars_ * 3 * sizeof(float)));
-    int num_block = DIVUP(in_num_points , num_threads_);
-    make_pillar_histo_kernel<<<num_block , num_threads_>>>(
-        dev_points, dev_pillar_point_feature_in_coors_, dev_pillar_count_histo_,
-        in_num_points, max_num_points_per_pillar_, grid_x_size_, grid_y_size_,
-        grid_z_size_, min_x_range_, min_y_range_, min_z_range_, pillar_x_size_,
-        pillar_y_size_, pillar_z_size_, num_point_feature_);
-    
-    make_pillar_index_kernel<<<grid_x_size_, grid_y_size_>>>(
-        dev_pillar_count_histo_, dev_counter_, dev_pillar_count_, dev_x_coors,
-        dev_y_coors, dev_num_points_per_pillar, dev_sparse_pillar_map,
-        max_num_pillars_, max_num_points_per_pillar_, grid_x_size_,
-        num_inds_for_scan_);  
-
-    GPU_CHECK(cudaMemcpy(host_pillar_count, dev_pillar_count_, 1 * sizeof(int),
-        cudaMemcpyDeviceToHost));
-    make_pillar_feature_kernel<<<host_pillar_count[0],max_num_points_per_pillar_>>>(
-        dev_pillar_point_feature_in_coors_, dev_pillar_point_feature,
-        dev_pillar_coors, dev_x_coors, dev_y_coors, dev_num_points_per_pillar,
-        max_num_points_per_pillar_, num_point_feature_, grid_x_size_);
-    
-
-    dim3 mean_block(max_num_points_per_pillar_,3); //(32,3)
-
-    pillar_mean_kernel<<<host_pillar_count[0],mean_block,64 * 3 *sizeof(float)>>>(
-      dev_points_mean_  ,num_point_feature_, dev_pillar_point_feature, dev_num_points_per_pillar, 
-        max_num_pillars_ , max_num_points_per_pillar_);
-
-    // dim3 mean_block(10,3); // Unrolling the Last Warp
-    // make_pillar_mean_kernel<<<host_pillar_count[0], mean_block , 32 * 3 *sizeof(float)>>>(
-    //       dev_points_mean_  ,num_point_feature_, dev_pillar_point_feature, dev_num_points_per_pillar, 
-    //       max_num_pillars_ , max_num_points_per_pillar_);
-
-    gather_point_feature_kernel<<<max_num_pillars_, max_num_points_per_pillar_>>>(
-      max_num_pillars_,max_num_points_per_pillar_,num_point_feature_,
-      min_x_range_, min_y_range_, min_z_range_,
-      pillar_x_size_, pillar_y_size_, pillar_z_size_, 
-      dev_pillar_point_feature, dev_num_points_per_pillar, dev_pillar_coors,
-      dev_points_mean_,
-      dev_pfe_gather_feature);
-
-    // DEVICE_SAVE<float>(dev_pillar_point_feature , \
-    //     max_num_pillars_ * max_num_points_per_pillar_ * num_point_feature_ , "dev_pillar_point_feature");
-    // DEVICE_SAVE<float>(dev_num_points_per_pillar , \
-    //   max_num_pillars_ , "dev_num_points_per_pillar");
-    // DEVICE_SAVE<float>(dev_pfe_gather_feature , \
-    //   max_num_pillars_ * 11, "dev_pfe_gather_feature");
-}
-
-

+ 0 - 138
src/detection/detection_lidar_PointPillars_MultiHead_1025/preprocess.h

@@ -1,138 +0,0 @@
-/******************************************************************************
- * Copyright 2020 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.
- *****************************************************************************/
-
-/*
- * Copyright 2018-2019 Autoware Foundation. 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.
- */
-
-/**
- * @file preprocess_points_cuda.h
- * @brief GPU version of preprocess points
- * @author Kosuke Murakami
- * @date 2019/02/26
- */
-
-/**
-* @author Yan haixu
-* Contact: just github.com/hova88
-* @date 2021/04/30
-*/
-
-
-#pragma once
-
-
-class PreprocessPointsCuda {
- private:
-    // initializer list
-    const int num_threads_;
-    const int max_num_pillars_;
-    const int max_num_points_per_pillar_;
-    const int num_point_feature_;
-    const int num_inds_for_scan_;
-    const int grid_x_size_;
-    const int grid_y_size_;
-    const int grid_z_size_;
-    const float pillar_x_size_;
-    const float pillar_y_size_;
-    const float pillar_z_size_;
-    const float min_x_range_;
-    const float min_y_range_;
-    const float min_z_range_;
-    // end initializer list
-
-    float* dev_pillar_point_feature_in_coors_;
-    int* dev_pillar_count_histo_;
-
-    int* dev_counter_;
-    int* dev_pillar_count_;
-    float* dev_points_mean_;
-
-
-
- public:
-  /**
-   * @brief Constructor
-   * @param[in] num_threads Number of threads when launching cuda kernel
-   * @param[in] num_point_feature Number of features in a point
-   * @param[in] num_inds_for_scan Number of indexes for scan(cumsum)
-   * 
-   * @param[in] max_num_pillars Maximum number of pillars
-   * @param[in] max_points_per_pillar Maximum number of points per pillar
-
-   * @param[in] grid_x_size Number of pillars in x-coordinate
-   * @param[in] grid_y_size Number of pillars in y-coordinate
-   * @param[in] grid_z_size Number of pillars in z-coordinate
-   * 
-   * @param[in] pillar_x_size Size of x-dimension for a pillar
-   * @param[in] pillar_y_size Size of y-dimension for a pillar
-   * @param[in] pillar_z_size Size of z-dimension for a pillar
-   * 
-   * @param[in] min_x_range Minimum x value for point cloud
-   * @param[in] min_y_range Minimum y value for point cloud
-   * @param[in] min_z_range Minimum z value for point cloud
-   * @details Captital variables never change after the compile
-   */
-  PreprocessPointsCuda(const int num_threads, const int num_point_feature, const int num_inds_for_scan,
-                       const int max_num_pillars, const int max_points_per_pillar,  
-                       const int grid_x_size, const int grid_y_size, const int grid_z_size,  // grid size
-                       const float pillar_x_size, const float pillar_y_size, const float pillar_z_size, //voxel size
-                       const float min_x_range, const float min_y_range, const float min_z_range); // point cloud range
-  ~PreprocessPointsCuda();
-
-  /**
-   * @brief CUDA preprocessing for input point cloud
-   * @param[in] dev_points Point cloud array
-   * @param[in] in_num_points The number of points
-   * @param[mid] dev_x_coors X-coordinate indexes for corresponding pillars
-   * @param[mid] dev_y_coors Y-coordinate indexes for corresponding pillars
-   * @param[mid] dev_num_points_per_pillar
-   *   Number of points in corresponding pillars
-   * @param[mid] pillar_point_feature
-   *   Values of point feature in each pillar
-   * @param[mid] pillar_coors Array for coors of pillars
-   * @param[mid] dev_points_mean Array for calculate the point center
-   * @param[out] dev_sparse_pillar_map
-   *   Grid map representation for pillar-occupancy
-   * @param[out] host_pillar_count
-   *   The number of valid pillars for an input point cloud
-   * @param[out] dev_pfe_gather_feature
-   *   11 dimensions feature for pfe input channel
-   * @details Convert point cloud to pillar representation
-   */
-  void DoPreprocessPointsCuda(const float* dev_points,
-                              const int in_num_points,
-                              int* dev_x_coors,
-                              int* dev_y_coors,
-                              float* dev_num_points_per_pillar,
-                              float* dev_pillar_point_feature,
-                              float* dev_pillar_coors,
-                              int* dev_sparse_pillar_map,
-                              int* host_pillar_count,
-                              float* dev_pfe_gather_feature);
-};

+ 0 - 73
src/detection/detection_lidar_PointPillars_MultiHead_1025/scatter.cu

@@ -1,73 +0,0 @@
-/******************************************************************************
- * Copyright 2020 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.
- *****************************************************************************/
-
-/*
- * Copyright 2018-2019 Autoware Foundation. 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.
- */
-
-/**
- * @author Kosuke Murakami
- * @date 2019/02/26
- */
-
-/**
-* @author Yan haixu
-* Contact: just github.com/hova88
-* @date 2021/04/30
-*/
-
-
-
-//headers in local files
-#include "scatter.h"
-
-__global__ void scatter_kernel(int *x_coors, int *y_coors, float *pfe_output,
-  float *scattered_feature, const int grid_x_size,
-  const int grid_y_size) {
-int i_pillar = blockIdx.x;
-int i_feature = threadIdx.x;
-int x_ind = x_coors[i_pillar];
-int y_ind = y_coors[i_pillar];
-float feature = pfe_output[i_pillar * 64 + i_feature];
-scattered_feature[i_feature * grid_y_size * grid_x_size +
-y_ind * grid_x_size + x_ind] = feature;
-}
-
-ScatterCuda::ScatterCuda(const int num_threads, const int grid_x_size,
-const int grid_y_size)
-: num_threads_(num_threads),
-grid_x_size_(grid_x_size),
-grid_y_size_(grid_y_size) {}
-
-void ScatterCuda::DoScatterCuda(const int pillar_count, int *x_coors,
-   int *y_coors, float *pfe_output,
-   float *scattered_feature) {
-scatter_kernel<<<pillar_count, num_threads_>>>(x_coors, y_coors, pfe_output,
-                    scattered_feature,
-                    grid_x_size_, grid_y_size_);
-}

+ 0 - 77
src/detection/detection_lidar_PointPillars_MultiHead_1025/scatter.h

@@ -1,77 +0,0 @@
-/******************************************************************************
- * Copyright 2020 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.
- *****************************************************************************/
-
-/*
- * Copyright 2018-2019 Autoware Foundation. 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.
- */
-
-/**
- * @author Kosuke Murakami
- * @date 2019/02/26
- */
-
-/**
-* @author Yan haixu
-* Contact: just github.com/hova88
-* @date 2021/04/30
-*/
-
-
-#pragma once
-
-class ScatterCuda {
- private:
-  const int num_threads_;
-  const int grid_x_size_;
-  const int grid_y_size_;
-
- public:
-  /**
-   * @brief Constructor
-   * @param[in] num_threads The number of threads to launch cuda kernel
-   * @param[in] grid_x_size Number of pillars in x-coordinate
-   * @param[in] grid_y_size Number of pillars in y-coordinate
-   * @details Captital variables never change after the compile
-   */
-  ScatterCuda(const int num_threads, const int grid_x_size,
-              const int grid_y_size);
-
-  /**
-   * @brief Call scatter cuda kernel
-   * @param[in] pillar_count The valid number of pillars
-   * @param[in] x_coors X-coordinate indexes for corresponding pillars
-   * @param[in] y_coors Y-coordinate indexes for corresponding pillars
-   * @param[in] pfe_output Output from Pillar Feature Extractor
-   * @param[out] scattered_feature Gridmap representation for pillars' feature
-   * @details Allocate pillars in gridmap based on index(coordinates)
-   * information
-   */
-  void DoScatterCuda(const int pillar_count, int* x_coors, int* y_coors,
-                     float* pfe_output, float* scattered_feature);
-};
-

+ 6 - 3
src/detection/detection_lidar_ukf_pda/detection_lidar_ukf_pda.pro

@@ -543,7 +543,8 @@ void ImmUkfPda::staticClassification()
   for (size_t i = 0; i < targets_.size(); i++)
   {
     // targets_[i].x_merge_(2) is referred for estimated velocity
-    double current_velocity = std::abs(targets_[i].x_merge_(2));
+//    double current_velocity = std::abs(targets_[i].x_merge_(2));
+    double current_velocity = targets_[i].x_merge_(2);
     targets_[i].vel_history_.push_back(current_velocity);
     if (targets_[i].tracking_num_ == TrackingState::Stable && targets_[i].lifetime_ > life_time_thres_)
     {
@@ -696,7 +697,7 @@ void ImmUkfPda::makeOutput(const iv::lidar::objectarray & input,
 
 //    }
 
-    std::cout<<"          v     tyaw :      "<<tv<<"  "   <<tyaw<<std::endl;
+//    std::cout<<"          v     tyaw :      "<<tv<<"  "   <<tyaw<<std::endl;
 
     while (tyaw > M_PI)
       tyaw -= 2. * M_PI;
@@ -711,6 +712,8 @@ void ImmUkfPda::makeOutput(const iv::lidar::objectarray & input,
     dd.set_id(targets_[i].ukf_id_);
 //    dd.id = targets_[i].ukf_id_;
     dd.set_velocity_linear_x(tv);
+//    std::cout<<" -------------------------------------------------------"<<std::endl;
+//    std::cout<<"   vel    linear    "<<tv<<std::endl;
    // dd.velocity_linear_x = tv;
     dd.set_acceleration_linear_y(tyaw_rate);
    // dd.acceleration_linear_y = tyaw_rate;
@@ -901,7 +904,7 @@ void ImmUkfPda::tracker(const iv::lidar::objectarray & input,
       for(j=0;j<detected_objects_output.obj_size();j++)
       {
       iv::lidar::lidarobject obj = detected_objects_output.obj(j);
-      std::cout<<"obj "<<j<< " vel is "<<obj.velocity_linear_x()<<" id is "<<obj.id()<<std::endl;
+//      std::cout<<"obj "<<j<< " vel is "<<obj.velocity_linear_x()<<" id is "<<obj.id()<<std::endl;
 
       }
   }

+ 100 - 0
src/detection/detection_lidar_ukf_pda/imm_ukf_pda.h

@@ -0,0 +1,100 @@
+QT -= gui
+
+CONFIG += c++11 console
+CONFIG -= app_bundle
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which as been marked deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if you use deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+# project's file
+
+
+INCLUDEPATH += yolov4Tensorrt/include \
+               include
+
+SOURCES += yolov4Tensorrt/src/trt_utils.cpp \
+           yolov4Tensorrt/src/yolo.cpp \
+           yolov4Tensorrt/src/yolodetect.cpp
+
+CUDA_SOURCES += yolov4Tensorrt/src/mish.cu \
+                yolov4Tensorrt/src/yololayer.cu
+
+DISTFILES += yolov4Tensorrt/src/mish.cu \
+             yolov4Tensorrt/src/yololayer.cu
+
+SOURCES += main_multibatch.cpp \
+           src/Hungarian.cpp \
+           src/KalmanTracker.cpp \
+           src/detect_obstacle.cpp
+
+
+INCLUDEPATH += proto
+SOURCES +=  \
+        proto/rawpic.pb.cc \
+        proto/obstacles.pb.cc
+
+#INCLUDEPATH += modulecomm
+#LIBS += $$PWD/modulecomm/libmodulecomm.so
+
+#LIBS += -L"/usr/local/lib" \
+#        -lprotobuf
+!include(../../../include/common.pri ) {
+    error( "Couldn't find the common.pri file!" )
+}
+
+!include(../../../include/ivprotobuf.pri ) {
+    error( "Couldn't find the ivprotobuf.pri file!" )
+}
+# opencv
+INCLUDEPATH += /usr/include/opencv4
+LIBS += /usr/lib/aarch64-linux-gnu/libopencv_*.so
+
+# tensorrt
+LIBS += /usr/lib/aarch64-linux-gnu/libnvinfer.so \
+        /usr/lib/aarch64-linux-gnu/libnvinfer_plugin.so
+# c++
+LIBS += -L/usr/lib/aarch64-linux-gnu -lstdc++fs
+# cuda
+CUDA_SDK = "/usr/local/cuda"   # Path to cuda SDK install
+CUDA_DIR = "/usr/local/cuda"            # Path to cuda toolkit install
+#####系统类型,计算能力###########
+SYSTEM_NAME = linux         # Depending on your system either 'Win32', 'x64', or 'Win64'
+SYSTEM_TYPE = 64            # '32' or '64', depending on your system
+CUDA_ARCH = sm_72           # Type of CUDA architecture, for example 'compute_10', 'compute_11', 'sm_10'
+NVCC_OPTIONS = --use_fast_math
+
+INCLUDEPATH += $$CUDA_DIR/include
+QMAKE_LIBDIR += $$CUDA_DIR/lib64/
+
+CUDA_OBJECTS_DIR = ./
+
+# Add the necessary libraries
+CUDA_LIBS = -lcuda -lcudart #-lcublas
+
+# The following makes sure all path names (which often include spaces) are put between quotation marks
+CUDA_INC = $$join(INCLUDEPATH,'" -I"','-I"','"')
+LIBS += $$CUDA_LIBS
+
+# Configuration of the Cuda compiler
+CONFIG(debug, debug|release) {
+    # Debug mode
+    cuda_d.input = CUDA_SOURCES
+    cuda_d.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}.o
+    cuda_d.commands = $$CUDA_DIR/bin/nvcc -D_DEBUG $$NVCC_OPTIONS $$CUDA_INC $$NVCC_LIBS --machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
+    cuda_d.dependency_type = TYPE_C
+    QMAKE_EXTRA_COMPILERS += cuda_d
+}
+else {
+    # Release mode
+    cuda.input = CUDA_SOURCES
+    cuda.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}.o
+    cuda.commands = $$CUDA_DIR/bin/nvcc $$NVCC_OPTIONS $$CUDA_INC $$NVCC_LIBS --machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
+    cuda.dependency_type = TYPE_C
+    QMAKE_EXTRA_COMPILERS += cuda
+}

+ 36 - 0
src/detection/detection_yolov4_shigong_monocular/include/Hungarian.h

@@ -0,0 +1,36 @@
+//
+// Created by lqx on 20-4-23.
+//
+
+#ifndef TRACK_SORT_HUNGARIAN_H_H
+#define TRACK_SORT_HUNGARIAN_H_H
+
+#include <iostream>
+#include <vector>
+
+using namespace std;
+
+class HungarianAlgorithm
+{
+public:
+    HungarianAlgorithm();
+    ~HungarianAlgorithm();
+    double Solve(vector<vector<double>>& DistMatrix, vector<int>& Assignment);
+
+private:
+    void assignmentoptimal(int *assignment, double *cost, double *distMatrix, int nOfRows, int nOfColumns);
+    void buildassignmentvector(int *assignment, bool *starMatrix, int nOfRows, int nOfColumns);
+    void computeassignmentcost(int *assignment, double *cost, double *distMatrix, int nOfRows);
+    void step2a(int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix,
+                bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim);
+    void step2b(int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix,
+                bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim);
+    void step3(int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix,
+               bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim);
+    void step4(int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix,
+               bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim, int row, int col);
+    void step5(int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix,
+               bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim);
+};
+
+#endif //TRACK_SORT_HUNGARIAN_H_H

+ 90 - 0
src/detection/detection_yolov4_shigong_monocular/include/KalmanTracker.h

@@ -0,0 +1,90 @@
+//
+// Created by lqx on 20-4-23.
+//
+
+#ifndef TRACK_SORT_KALMANTRACKER_H
+#define TRACK_SORT_KALMANTRACKER_H
+
+///////////////////////////////////////////////////////////////////////////////
+// KalmanTracker.h: KalmanTracker Class Declaration
+
+#include "opencv2/video/tracking.hpp"
+#include "opencv2/highgui/highgui.hpp"
+
+using namespace std;
+using namespace cv;
+
+#define StateType Rect_<float>
+
+
+// This class represents the internel state of individual tracked objects observed as bounding box.
+class KalmanTracker
+{
+public:
+    KalmanTracker()
+    {
+        init_kf(StateType());
+        m_time_since_update = 0;
+        m_hits = 0;
+        m_hit_streak = 0;
+        m_age = 0;
+        m_id = kf_count;
+        //kf_count++;
+    }
+    KalmanTracker(StateType initRect)
+    {
+        init_kf(initRect);
+        m_time_since_update = 0;
+        m_hits = 0;
+        m_hit_streak = 0;
+        m_age = 0;
+        m_id = kf_count;
+        //kf_count++;
+    }
+
+    KalmanTracker(StateType initRect, int classId,float prob)
+    {
+        init_kf(initRect);
+        m_time_since_update = 0;
+        m_hits = 0;
+        m_hit_streak = 0;
+        m_age = 0;
+        m_id = kf_count;
+        kf_count++;
+        m_class_id = classId;
+        m_prob = prob;
+    }
+
+    ~KalmanTracker()
+    {
+        m_history.clear();
+        m_class_history.clear();
+    }
+
+    StateType predict();
+    void update(StateType stateMat,int classId, float prob);
+
+    StateType get_state();
+    StateType get_rect_xysr(float cx, float cy, float s, float r);
+
+    static int kf_count;
+
+    int m_time_since_update;
+    int m_hits;
+    int m_hit_streak;
+    int m_age;
+    int m_id;
+    int m_class_id;
+    std::vector<int> m_class_history;
+    float m_prob;
+
+private:
+    void init_kf(StateType stateMat);
+
+    cv::KalmanFilter kf;
+    cv::Mat measurement;
+
+    std::vector<StateType> m_history;
+};
+
+#endif //TRACK_SORT_KALMANTRACKER_H

+ 54 - 0
src/detection/detection_yolov4_shigong_monocular/include/detect_obstacle.h

@@ -0,0 +1,54 @@
+#ifndef DETECT_TURNSTILE_H
+#define DETECT_TURNSTILE_H
+
+#include "Hungarian.h"
+#include "KalmanTracker.h"
+
+namespace od{
+
+const int COLOR_MAP[2][3]={{0, 0, 255},{255, 0, 0}};
+const int max_age = 3;
+const int min_hits = 3;
+const double iouThreshold = 0.5;
+
+struct bbox_t {
+    unsigned int x, y, w, h;       // (x,y) - top-left corner, (w, h) - width & height of bounded box
+    float prob;                    // confidence - probability that the object was found correctly
+    unsigned int obj_id;           // class of object - from range [0, classes-1]
+    unsigned int track_id;         // tracking id for video (0 - untracked, 1 - inf - tracked object)
+    unsigned int frames_counter;   // counter of frames on which the object was detected
+    float x_3d, y_3d, z_3d;        // center of object (in Meters) if ZED 3D Camera is used
+};
+
+typedef struct TrackingBox
+{
+    int frame;
+    int id;
+    int class_id;
+    float prob;
+    Rect_<float> box;
+    vector<int> class_history;
+}TrackingBox;
+
+//yolo data o DetectBox
+typedef struct DetectBox
+{
+    int class_id;
+    float prob;
+    Rect_<float> box;
+}DetectBox;
+
+//Computes IOU between two bounding boxes
+double GetIOU(Rect_<float> bb_test, Rect_<float> bb_gt);
+//画出检测框和相关信息
+void DrawBoxes(Mat &frame, vector<string> classes, int classId, int turnstileId,float conf, int left, int top, int right, int bottom);
+
+//画出检测结果,image
+void Drawer(Mat &frame, vector<bbox_t> outs, vector<string> classes);
+//画出检测结果,video
+void Drawer(Mat &frame, vector<od::TrackingBox> &track_result, vector<string> &classes);
+//tracking obstacle
+bool TrackObstacle(int frame_count,vector<KalmanTracker> &trackers,vector<bbox_t> &outs,vector<od::TrackingBox> &track_result);
+}
+
+#endif // DETECT_TURNSTILE_H

+ 82 - 0
src/detection/detection_yolov4_shigong_monocular/include/imageBuffer.h

@@ -0,0 +1,82 @@
+#ifndef IMAGEBUFFER_H
+#define IMAGEBUFFER_H
+
+#include <opencv2/opencv.hpp>
+#include <mutex>
+#include <condition_variable>
+#include <queue>
+template<typename T>
+class ConsumerProducerQueue
+{
+
+public:
+    ConsumerProducerQueue(int mxsz,bool dropFrame) :
+            maxSize(mxsz),dropFrame(dropFrame)
+    { }
+
+    bool add(T request)
+    {
+        std::unique_lock<std::mutex> lock(mutex);
+        if(dropFrame && isFull())
+        {
+            //lock.unlock();
+            //return false;
+            cpq.pop();
+            cpq.push(request);
+            cond.notify_all();
+            return true;
+        }
+        else {
+            cond.wait(lock, [this]() { return !isFull(); });
+            cpq.push(request);
+            //lock.unlock();
+            cond.notify_all();
+            return true;
+        }
+    }
+    void consume(T &request)
+    {
+        std::unique_lock<std::mutex> lock(mutex);
+        cond.wait(lock, [this]()
+        { return !isEmpty(); });
+        request = cpq.front();
+        cpq.pop();
+        //lock.unlock();
+        cond.notify_all();
+
+    }
+
+    bool isFull() const
+    {
+        return cpq.size() >= maxSize;
+    }
+
+    bool isEmpty() const
+    {
+        return cpq.size() == 0;
+    }
+
+    int length() const
+    {
+        return cpq.size();
+    }
+
+    void clear()
+    {
+        std::unique_lock<std::mutex> lock(mutex);
+        while (!isEmpty())
+        {
+            cpq.pop();
+        }
+        lock.unlock();
+        cond.notify_all();
+    }
+
+private:
+    std::condition_variable cond;  //条件变量允许通过通知进而实现线程同步
+    std::mutex mutex;     //提供了多种互斥操作,可以显式避免数据竞争
+    std::queue<T> cpq;    //容器适配器,它给予程序员队列的功能
+    int maxSize;
+    bool dropFrame;
+};
+#endif // IMAGEBUFFER_H

+ 353 - 0
src/detection/detection_yolov4_shigong_monocular/main.cpp

@@ -0,0 +1,353 @@
+#include <opencv2/opencv.hpp>
+#include <opencv2/imgproc.hpp>
+#include <opencv2/highgui.hpp>
+#include <vector>
+#include <fstream>
+#include <thread>
+#include <cmath>
+
+#include "imageBuffer.h"
+#include "modulecomm.h"
+#include "rawpic.pb.h"
+#include "obstacles.pb.h"
+#include "yolodetect.h"
+#include "detect_obstacle.h"
+
+using namespace std;
+using namespace cv;
+
+uint max_batch_size = 1;
+
+string yaml_path="./model/external.yaml";
+
+bool test_video = false;
+string video_path = "20201231144029.avi";
+
+void * g_obstacle;
+string obstacledata="obstacledata";
+
+void * mpa_camera;
+string cameradata="picleft";
+
+typedef struct frame_info
+{
+    cv::Mat  frame;
+    long long timestamp;
+}frame_info;
+typedef struct obstacle_info
+{
+    string category;
+    uint64 class_id;
+    Point3f bbox_3d;
+    Rect_<float> bbox;
+}obstacle_info;
+
+typedef struct obstacles_info
+{
+    vector<obstacle_info> bboxes;
+    uint64 time;
+}obstacles_info;
+
+
+int capture_width=1280,capture_height=720;
+cv::Mat cameraMatrix = (cv::Mat_<double>(3,3)<< 1.0538648949999999e+03, 0., 9.7134830299999999e+02, 0.,
+                        9.6887771299999997e+02, 5.5096488099999999e+02, 0., 0., 1.);
+cv::Mat distCoeffs = (cv::Mat_<double>(1,5)<<-2.9078999999999999e-01, 6.0994000000000000e-02,
+                      3.6489999999999999e-03, -2.0590000000000001e-03, 0.);
+cv::Mat cameraMatrix_inv = (cv::Mat_<double>(3,3)<<9.4888823486240150e-04, 0., -9.2170097667025908e-01, 0.,
+                            1.0321219970099572e-03, -5.6866297326007331e-01, 0., 0., 1.);
+cv::Mat rvecM_inv = (cv::Mat_<double>(3,3)<<9.9361999532145029e-01, 1.5481286202195165e-02,
+                     1.1171228524619221e-01, -1.1071480863577153e-01,
+                     -5.4789655210038264e-02, 9.9234083098031878e-01,
+                     2.1483390005894807e-02, -9.9837789611924532e-01,
+                     -5.2726089314150459e-02 );
+cv::Mat tvec = (cv::Mat_<double>(3,1)<<1.5367854556890524e+02, 1.5365463964586140e+03,
+                -1.2444937322334890e+03);
+
+ConsumerProducerQueue<frame_info> * imageBuffer =  new ConsumerProducerQueue<frame_info>(3,true);
+ConsumerProducerQueue<frame_info> * imageBuffer_30 =  new ConsumerProducerQueue<frame_info>(3,true);
+ConsumerProducerQueue<frame_info> * imageBuffer_90 =  new ConsumerProducerQueue<frame_info>(3,true);
+
+// 获取系统当前时间,从格林威治标准时间(1970-01-01 00:00:00.000)开始到指定时间的毫秒数。
+long long getCurrentSystemTime()
+{
+    auto now = std::chrono::system_clock::now();
+    long long millseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
+    /*
+    uint64_t dis_millseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count()
+            - std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count() * 1000;
+    auto tt = std::chrono::system_clock::to_time_t(now);
+    struct tm* ptm = localtime(&tt);
+    char date[60] = { 0 };
+    sprintf(date, "%d/%02d/%02d/%02d/%02d/%02d/%03d",
+            (int)ptm->tm_year + 1900, (int)ptm->tm_mon + 1, (int)ptm->tm_mday,
+            (int)ptm->tm_hour, (int)ptm->tm_min, (int)ptm->tm_sec, (int)dis_millseconds);
+    return std::string(date);
+    */
+    return millseconds;
+}
+//读取视频数据
+void ReadFunc(int n)
+{
+    cv::VideoCapture cap_30(video_path);
+    if(!cap_30.isOpened())
+    {
+        cout<<"camera failed to open"<<endl;
+    }
+    while(1)
+    {
+        frame_info frameInfo_30;
+        cv::Mat frame_30;
+        //读视频的时候加上,读摄像头去掉
+        if(imageBuffer_30->isFull())
+        {
+            continue;
+        }
+        if(cap_30.read(frame_30))
+        {
+            long long timestamp = getCurrentSystemTime();
+            frameInfo_30.frame = frame_30;
+            frameInfo_30.timestamp = timestamp;
+            imageBuffer_30->add(frameInfo_30);
+        }
+        else
+        {
+            std::this_thread::sleep_for(std::chrono::milliseconds(1));
+        }
+    }
+}
+//从共享内存中接收摄像头数据
+void Listencamera(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
+{
+    if(nSize<1000)return;
+    iv::vision::rawpic pic;
+    if(false == pic.ParseFromArray(strdata,nSize))
+    {
+        std::cout<<"picview Listenpic fail."<<std::endl;
+        return;
+    }
+    cv::Mat mat(pic.height(),pic.width(),pic.mattype());
+    if(pic.type() == 1)
+        memcpy(mat.data,pic.picdata().data(),mat.rows*mat.cols*mat.elemSize());
+    else
+    {
+        //     mat.release();
+        std::vector<unsigned char> buff(pic.picdata().data(),pic.picdata().data() + pic.picdata().size());
+        mat = cv::imdecode(buff,IMREAD_COLOR);
+    }
+
+    frame_info img_info;
+    img_info.frame = mat;
+    img_info.timestamp = pic.time();
+    imageBuffer->add(img_info);
+    mat.release();
+}
+//向共享内存中存入障碍物检测结果
+void SendDetectResult(obstacles_info &obstacles,void* g_name)
+{
+    iv::vision::ObstacleInfo detectResult;
+    detectResult.set_time(obstacles.time);
+    for(unsigned int i=0;i <obstacles.bboxes.size();i++)
+    {
+        iv::vision::Bbox3D obstacle;
+        obstacle.set_category(obstacles.bboxes[i].category);
+        obstacle.set_class_id(obstacles.bboxes[i].class_id);
+        obstacle.set_x_3d(obstacles.bboxes[i].bbox_3d.x);
+        obstacle.set_y_3d(obstacles.bboxes[i].bbox_3d.y);
+        obstacle.set_z_3d(obstacles.bboxes[i].bbox_3d.z);
+        obstacle.set_x(obstacles.bboxes[i].bbox.x);
+        obstacle.set_y(obstacles.bboxes[i].bbox.y);
+        obstacle.set_w(obstacles.bboxes[i].bbox.width);
+        obstacle.set_h(obstacles.bboxes[i].bbox.height);
+        iv::vision::Bbox3D * bb = detectResult.add_bbox_3d();
+        bb->CopyFrom(obstacle);
+    }
+    std::string out_result = detectResult.SerializeAsString();
+    iv::modulecomm::ModuleSendMsg(g_name,out_result.data(),out_result.length());
+}
+//像素坐标系转换到车体坐标系
+cv::Point3f CameraToWorld(cv::Point2f CameraInfo)
+{
+    cv::Mat imagePoint = cv::Mat::ones(3, 1, cv::DataType<double>::type);//u,v,1
+    cv::Mat tempMat, tempMat2;
+    //输入一个2D坐标点,便可以求出相应的s
+    imagePoint.at<double>(0,0)=double(CameraInfo.x);
+    imagePoint.at<double>(1,0)=double(CameraInfo.y);
+    double zConst = 0;//实际坐标系的距离
+    //计算参数s
+    double s;
+    tempMat = rvecM_inv * cameraMatrix_inv * imagePoint;
+    tempMat2 = rvecM_inv * tvec;
+    s = zConst + tempMat2.at<double>(2, 0);
+    s /= tempMat.at<double>(2, 0);
+    //cout<<"s : "<<s<<endl;
+    //////////////////////camera_coordinates////////////////
+    cv::Mat camera_cordinates=-rvecM_inv*tvec;
+    /////////////////////2D to 3D///////////////////////
+    cv::Mat wcPoint = rvecM_inv * (cameraMatrix_inv *s*imagePoint - tvec);
+    cv::Point3f worldPoint(wcPoint.at<double>(0, 0), wcPoint.at<double>(1, 0),
+                           wcPoint.at<double>(2, 0));
+    return worldPoint;
+}
+int main(int argc, char** argv )
+{
+
+    if(argc==3)
+    {
+        test_video = (strcmp(argv[1], "true") == 0)?true:false;
+        if(test_video)
+            video_path = argv[2];
+        else
+            cameradata = argv[2];
+    }
+    if(argc==2)
+        test_video = (strcmp(argv[1], "true") == 0)?true:false;
+
+    if(test_video)
+        std::thread * readthread = new std::thread(ReadFunc,1);
+    else
+        mpa_camera= iv::modulecomm::RegisterRecv(&cameradata[0],Listencamera);
+
+    g_obstacle = iv::modulecomm::RegisterSend(&obstacledata[0],1000000,1);
+
+    //导入相机内参和畸变系数矩阵
+    FileStorage file_storage(yaml_path, FileStorage::READ);
+    if( file_storage.isOpened())
+    {
+        file_storage["camera_matrix"] >> cameraMatrix;
+        file_storage["camera_matrix_inv"] >> cameraMatrix_inv;
+        file_storage["distortion_coefficients"] >> distCoeffs;
+        file_storage["RotationR_inv"] >> rvecM_inv;
+        file_storage["tvec"] >> tvec;
+        file_storage.release();
+    }
+    else{
+        cout << "Error: can not open the external parameters file"<<endl;
+        return 0;
+    }
+
+    NetworkInfo networkInfo;
+    networkInfo.networkType     = "yolov4";
+    networkInfo.configFilePath  = "model/yolov4-shigong.cfg";
+    networkInfo.wtsFilePath     = "model/yolov4-shigong_final";
+    networkInfo.deviceType      = "kGPU";
+    networkInfo.inputBlobName   = "data";
+    networkInfo.maxbatchSize    = max_batch_size;
+    std::string modelname = "model/yolov4_shigong.engine";
+    IExecutionContext* yolo_context{nullptr};
+    YoloDetect detector(networkInfo,modelname);
+
+    string classesFile = "model/coco.names";
+    //加载类别名
+    /*
+    vector<string> classes;
+    ifstream ifs(classesFile.c_str());
+    string line;
+    while (getline(ifs, line)) classes.push_back(line);
+    */
+    vector<string> classes = {"shigong"};
+    //加载网络模型,0是指定第一块GPU
+    cudaSetDevice(0);
+    if(!detector.loadModel(yolo_context))
+    {
+        cout<<"load yolo model failed"<<endl;
+        return -1;
+    }
+
+    //Size size(cap.get(CV_CAP_PROP_FRAME_WIDTH), cap.get(CV_CAP_PROP_FRAME_HEIGHT));
+    //VideoWriter writer("./data/result.avi", cv::VideoWriter::fourcc('M', 'J', 'P', 'G'), 25, size);
+
+    vector<KalmanTracker> trackers_30;
+    KalmanTracker::kf_count = 0; // tracking id relies on this, so we have to reset it in each seq.
+    int frame_count = 0;
+    frame_info frameInfo_30;
+    Mat frame_30;
+
+    long long millseconds; //时间戳
+    double waittime = (double)getTickCount();
+
+    while (1)
+    {
+        if(imageBuffer_30->isEmpty())
+        {
+            double waittotal = (double)getTickCount() - waittime;
+            if(waittotal/cv::getTickFrequency()>30.0)
+            {
+                cout<<"Cant't get frame and quit"<<endl;
+                break;
+            }
+            continue;
+        }
+
+        imageBuffer_30->consume(frameInfo_30);
+        frame_30 = frameInfo_30.frame;
+
+        obstacles_info detect_result_info;
+        detect_result_info.time = frameInfo_30.timestamp;
+        frame_count++;
+
+        double start = (double)getTickCount();
+        //前向预测
+        float ignore_thresh=0.4;
+        float nms_thresh = 0.4;
+
+        std::vector<Detection> result_30;
+        od::bbox_t bbox_t_30;
+        vector<od::bbox_t> outs_30;
+
+        if(detector.process(*yolo_context,frame_30,result_30,ignore_thresh,nms_thresh))
+        {
+            for (size_t i = 0; i < result_30.size(); i++) {
+                cv::Rect r = detector.get_rect(frame_30, result_30[i].bbox,detector.m_input_w,detector.m_input_h);
+                bbox_t_30.x = r.x;
+                bbox_t_30.y = r.y;
+                bbox_t_30.w = r.width;
+                bbox_t_30.h = r.height;
+                bbox_t_30.prob = result_30[i].det_confidence;
+                bbox_t_30.obj_id = result_30[i].class_id;
+                outs_30.push_back(bbox_t_30);
+            }
+        }
+
+//        double infertime = (double)getTickCount() - start;
+//        std::cout<< "Total Cost of infertime: "  <<infertime*1000.0/cv::getTickFrequency()<<" ms"<<std::endl;
+
+        vector<od::TrackingBox>track_result_30;
+        bool track_flag_30 = od::TrackObstacle(frame_count,trackers_30,outs_30,track_result_30);
+        if(track_flag_30)
+        {
+            vector<obstacle_info>obstacle_vector;
+            for(unsigned int i=0;i < track_result_30.size(); i++)
+            {
+                obstacle_info obstacle;
+                obstacle.category = classes[track_result_30[i].class_id];
+                obstacle.class_id = track_result_30[i].class_id;
+                //求bbox的接地点
+                Point2f bottom_center = Point2f(track_result_30[i].box.x+0.5*track_result_30[i].box.width,
+                                                track_result_30[i].box.y+track_result_30[i].box.height);
+                obstacle.bbox_3d = CameraToWorld(bottom_center);
+                obstacle.bbox = track_result_30[i].box;
+                obstacle_vector.push_back(obstacle);
+            }
+            detect_result_info.bboxes = obstacle_vector;
+            SendDetectResult(detect_result_info,g_obstacle);
+            od::Drawer(frame_30, track_result_30, classes);
+        }
+
+        double total = (double)getTickCount() - start;
+        std::cout<< "Total Cost of Detection: "  <<total*1000.0/cv::getTickFrequency()<<" ms"<<endl;
+
+        namedWindow("Result_30",WINDOW_NORMAL);
+        imshow("Result_30",frame_30);
+
+        if(waitKey(1) == 'q')
+            break;
+        if(waitKey(1) == 's')
+            waitKey(0);
+        waittime = (double)getTickCount();
+    }
+    destroyAllWindows();
+    trackers_30.clear();
+    yolo_context->destroy();
+    return 0;
+}

+ 406 - 0
src/detection/detection_yolov4_shigong_monocular/main_multibatch.cpp

@@ -0,0 +1,406 @@
+#include <opencv2/opencv.hpp>
+#include <opencv2/imgproc.hpp>
+#include <opencv2/highgui.hpp>
+#include <vector>
+#include <fstream>
+#include <thread>
+#include <cmath>
+
+#include "imageBuffer.h"
+#include "modulecomm.h"
+#include "rawpic.pb.h"
+#include "obstacles.pb.h"
+#include "yolodetect.h"
+#include "detect_obstacle.h"
+
+using namespace std;
+using namespace cv;
+
+uint max_batch_size = 2;
+
+string yaml_path="/home/nvidia/models/camera/external.yaml";
+
+bool test_video = true;
+string video_path = "20201231144029.avi";
+
+void * g_obstacle;
+string obstacledata="obstacledata";
+
+void * mpa_camera;
+string cameradata="picleft";
+
+typedef struct frame_info
+{
+    cv::Mat  frame;
+    long long timestamp;
+}frame_info;
+typedef struct obstacle_info
+{
+    string category;
+    uint64 class_id;
+    Point3f bbox_3d;
+    Rect_<float> bbox;
+}obstacle_info;
+
+typedef struct obstacles_info
+{
+    vector<obstacle_info> bboxes;
+    uint64 time;
+}obstacles_info;
+
+
+int capture_width=1280,capture_height=720;
+cv::Mat cameraMatrix = (cv::Mat_<double>(3,3)<< 1.0538648949999999e+03, 0., 9.7134830299999999e+02, 0.,
+                        9.6887771299999997e+02, 5.5096488099999999e+02, 0., 0., 1.);
+cv::Mat distCoeffs = (cv::Mat_<double>(1,5)<<-2.9078999999999999e-01, 6.0994000000000000e-02,
+                      3.6489999999999999e-03, -2.0590000000000001e-03, 0.);
+cv::Mat cameraMatrix_inv = (cv::Mat_<double>(3,3)<<9.4888823486240150e-04, 0., -9.2170097667025908e-01, 0.,
+                            1.0321219970099572e-03, -5.6866297326007331e-01, 0., 0., 1.);
+cv::Mat rvecM_inv = (cv::Mat_<double>(3,3)<<9.9361999532145029e-01, 1.5481286202195165e-02,
+                     1.1171228524619221e-01, -1.1071480863577153e-01,
+                     -5.4789655210038264e-02, 9.9234083098031878e-01,
+                     2.1483390005894807e-02, -9.9837789611924532e-01,
+                     -5.2726089314150459e-02 );
+cv::Mat tvec = (cv::Mat_<double>(3,1)<<1.5367854556890524e+02, 1.5365463964586140e+03,
+                -1.2444937322334890e+03);
+
+ConsumerProducerQueue<frame_info> * imageBuffer =  new ConsumerProducerQueue<frame_info>(3,true);
+ConsumerProducerQueue<frame_info> * imageBuffer_30 =  new ConsumerProducerQueue<frame_info>(3,true);
+ConsumerProducerQueue<frame_info> * imageBuffer_90 =  new ConsumerProducerQueue<frame_info>(3,true);
+
+// 获取系统当前时间,从格林威治标准时间(1970-01-01 00:00:00.000)开始到指定时间的毫秒数。
+long long getCurrentSystemTime()
+{
+    auto now = std::chrono::system_clock::now();
+    long long millseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
+    /*
+    uint64_t dis_millseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count()
+            - std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count() * 1000;
+    auto tt = std::chrono::system_clock::to_time_t(now);
+    struct tm* ptm = localtime(&tt);
+    char date[60] = { 0 };
+    sprintf(date, "%d/%02d/%02d/%02d/%02d/%02d/%03d",
+            (int)ptm->tm_year + 1900, (int)ptm->tm_mon + 1, (int)ptm->tm_mday,
+            (int)ptm->tm_hour, (int)ptm->tm_min, (int)ptm->tm_sec, (int)dis_millseconds);
+    return std::string(date);
+    */
+    return millseconds;
+}
+//读取视频数据
+void ReadFunc(int n)
+{
+    cv::VideoCapture cap_30(0);
+    cv::VideoCapture cap_90(1);
+    if(!cap_30.isOpened() | !cap_90.isOpened())
+    {
+        cout<<"camera failed to open"<<endl;
+    }
+    while(1)
+    {
+        frame_info frameInfo_30,frameInfo_90;
+        cv::Mat frame_30,frame_90;
+        //读视频的时候加上,读摄像头去掉
+        if(imageBuffer_30->isFull() | imageBuffer_90->isFull())
+        {
+            continue;
+        }
+        if(cap_30.read(frame_30) && cap_90.read(frame_90))
+        {
+            long long timestamp = getCurrentSystemTime();
+            frameInfo_30.frame = frame_30;
+            frameInfo_30.timestamp = timestamp;
+            imageBuffer_30->add(frameInfo_30);
+            frameInfo_90.frame = frame_90;
+            frameInfo_90.timestamp = timestamp;
+            imageBuffer_90->add(frameInfo_90);
+        }
+        else
+        {
+            std::this_thread::sleep_for(std::chrono::milliseconds(1));
+        }
+    }
+}
+//从共享内存中接收摄像头数据
+void Listencamera(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
+{
+    if(nSize<1000)return;
+    iv::vision::rawpic pic;
+    if(false == pic.ParseFromArray(strdata,nSize))
+    {
+        std::cout<<"picview Listenpic fail."<<std::endl;
+        return;
+    }
+    cv::Mat mat(pic.height(),pic.width(),pic.mattype());
+    if(pic.type() == 1)
+        memcpy(mat.data,pic.picdata().data(),mat.rows*mat.cols*mat.elemSize());
+    else
+    {
+        //     mat.release();
+        std::vector<unsigned char> buff(pic.picdata().data(),pic.picdata().data() + pic.picdata().size());
+        mat = cv::imdecode(buff,IMREAD_COLOR);
+    }
+
+    frame_info img_info;
+    img_info.frame = mat;
+    img_info.timestamp = pic.time();
+    imageBuffer->add(img_info);
+    mat.release();
+}
+//向共享内存中存入障碍物检测结果
+void SendDetectResult(obstacles_info &obstacles,void* g_name)
+{
+    iv::vision::ObstacleInfo detectResult;
+    detectResult.set_time(obstacles.time);
+    for(unsigned int i=0;i <obstacles.bboxes.size();i++)
+    {
+        iv::vision::Bbox3D obstacle;
+        obstacle.set_category(obstacles.bboxes[i].category);
+        obstacle.set_class_id(obstacles.bboxes[i].class_id);
+        obstacle.set_x_3d(obstacles.bboxes[i].bbox_3d.x);
+        obstacle.set_y_3d(obstacles.bboxes[i].bbox_3d.y);
+        obstacle.set_z_3d(obstacles.bboxes[i].bbox_3d.z);
+        obstacle.set_x(obstacles.bboxes[i].bbox.x);
+        obstacle.set_y(obstacles.bboxes[i].bbox.y);
+        obstacle.set_w(obstacles.bboxes[i].bbox.width);
+        obstacle.set_h(obstacles.bboxes[i].bbox.height);
+        iv::vision::Bbox3D * bb = detectResult.add_bbox_3d();
+        bb->CopyFrom(obstacle);
+    }
+    std::string out_result = detectResult.SerializeAsString();
+    iv::modulecomm::ModuleSendMsg(g_name,out_result.data(),out_result.length());
+}
+//像素坐标系转换到车体坐标系
+cv::Point3f CameraToWorld(cv::Point2f CameraInfo)
+{
+    cv::Mat imagePoint = cv::Mat::ones(3, 1, cv::DataType<double>::type);//u,v,1
+    cv::Mat tempMat, tempMat2;
+    //输入一个2D坐标点,便可以求出相应的s
+    imagePoint.at<double>(0,0)=double(CameraInfo.x);
+    imagePoint.at<double>(1,0)=double(CameraInfo.y);
+    double zConst = 0;//实际坐标系的距离
+    //计算参数s
+    double s;
+    tempMat = rvecM_inv * cameraMatrix_inv * imagePoint;
+    tempMat2 = rvecM_inv * tvec;
+    s = zConst + tempMat2.at<double>(2, 0);
+    s /= tempMat.at<double>(2, 0);
+    //cout<<"s : "<<s<<endl;
+    //////////////////////camera_coordinates////////////////
+    cv::Mat camera_cordinates=-rvecM_inv*tvec;
+    /////////////////////2D to 3D///////////////////////
+    cv::Mat wcPoint = rvecM_inv * (cameraMatrix_inv *s*imagePoint - tvec);
+    cv::Point3f worldPoint(wcPoint.at<double>(0, 0), wcPoint.at<double>(1, 0),
+                           wcPoint.at<double>(2, 0));
+    return worldPoint;
+}
+int main(int argc, char** argv )
+{
+
+    if(argc==3)
+    {
+        test_video = (strcmp(argv[1], "true") == 0)?true:false;
+        if(test_video)
+            video_path = argv[2];
+        else
+            cameradata = argv[2];
+    }
+    if(argc==2)
+        test_video = (strcmp(argv[1], "true") == 0)?true:false;
+
+    if(test_video)
+        std::thread * readthread = new std::thread(ReadFunc,1);
+    else
+        mpa_camera= iv::modulecomm::RegisterRecv(&cameradata[0],Listencamera);
+
+    g_obstacle = iv::modulecomm::RegisterSend(&obstacledata[0],1000000,1);
+
+    //导入相机内参和畸变系数矩阵
+    FileStorage file_storage(yaml_path, FileStorage::READ);
+    if( file_storage.isOpened())
+    {
+        file_storage["camera_matrix"] >> cameraMatrix;
+        file_storage["camera_matrix_inv"] >> cameraMatrix_inv;
+        file_storage["distortion_coefficients"] >> distCoeffs;
+        file_storage["RotationR_inv"] >> rvecM_inv;
+        file_storage["tvec"] >> tvec;
+        file_storage.release();
+    }
+    else{
+        cout << "Error: can not open the external parameters file"<<endl;
+        return 0;
+    }
+
+    NetworkInfo networkInfo;
+    networkInfo.networkType     = "yolov4";
+    networkInfo.configFilePath  = "/home/nvidia/models/camera/yolov4-shigong.cfg";
+    networkInfo.wtsFilePath     = "/home/nvidia/models/camera/yolov4-shigong_final.weights";
+    networkInfo.deviceType      = "kGPU";
+    networkInfo.inputBlobName   = "data";
+    networkInfo.maxbatchSize    = max_batch_size;
+    std::string modelname = "/home/nvidia/models/camera/yolov4_shigong.engine";
+    IExecutionContext* yolo_context{nullptr};
+    YoloDetect detector(networkInfo,modelname);
+
+    /*
+    string classesFile = "model/shigong.names";
+    //加载类别名
+    vector<string> classes;
+    ifstream ifs(classesFile.c_str());
+    string line;
+    while (getline(ifs, line)) classes.push_back(line);
+    */
+    vector<string> classes = {"shigong"};
+    //加载网络模型,0是指定第一块GPU
+    cudaSetDevice(0);
+    if(!detector.loadModel(yolo_context))
+    {
+        cout<<"load yolo model failed"<<endl;
+        return -1;
+    }
+
+    //Size size(cap.get(CV_CAP_PROP_FRAME_WIDTH), cap.get(CV_CAP_PROP_FRAME_HEIGHT));
+    //VideoWriter writer("./data/result.avi", cv::VideoWriter::fourcc('M', 'J', 'P', 'G'), 25, size);
+
+    vector<KalmanTracker> trackers_30,trackers_90;
+    KalmanTracker::kf_count = 0; // tracking id relies on this, so we have to reset it in each seq.
+    int frame_count = 0;
+    frame_info frameInfo_30,frameInfo_90;
+    Mat frame_30,frame_90;
+
+    long long millseconds; //时间戳
+    double waittime = (double)getTickCount();
+
+    while (1)
+    {
+        if(imageBuffer_30->isEmpty() | imageBuffer_90->isEmpty())
+        {
+            double waittotal = (double)getTickCount() - waittime;
+            if(waittotal/cv::getTickFrequency()>30.0)
+            {
+                cout<<"Can't get frame and quit"<<endl;
+                break;
+            }
+            continue;
+        }
+
+        imageBuffer_30->consume(frameInfo_30);
+        frame_30 = frameInfo_30.frame;
+        imageBuffer_90->consume(frameInfo_90);
+        frame_90 = frameInfo_90.frame;
+        vector<Mat> frame_vec;
+        frame_vec.push_back(frame_30);
+        frame_vec.push_back(frame_90);
+
+        obstacles_info detect_result_info;
+        detect_result_info.time = frameInfo_30.timestamp;
+        frame_count++;
+
+        double start = (double)getTickCount();
+        //前向预测
+        float ignore_thresh=0.4;
+        float nms_thresh = 0.4;
+
+        //两个摄像头30,90度
+        std::vector<std::vector<Detection>> detect_results_yolo;
+        std::vector<Detection> result_30,result_90;
+        detect_results_yolo.push_back(result_30);
+        detect_results_yolo.push_back(result_90);
+        bool flag_30 = false;
+        bool flag_90 = false;
+        od::bbox_t bbox_t_30;
+        od::bbox_t bbox_t_90;
+        vector<od::bbox_t> outs_30;
+        vector<od::bbox_t> outs_90;
+
+        if(detector.process(*yolo_context,max_batch_size,frame_vec,
+                            detect_results_yolo,ignore_thresh,nms_thresh))
+        {
+            for (size_t i = 0; i < detect_results_yolo[0].size(); i++) {
+                cv::Rect r = detector.get_rect(frame_30, detect_results_yolo[0][i].bbox,detector.m_input_w,detector.m_input_h);
+                bbox_t_30.x = r.x;
+                bbox_t_30.y = r.y;
+                bbox_t_30.w = r.width;
+                bbox_t_30.h = r.height;
+                bbox_t_30.prob = detect_results_yolo[0][i].det_confidence;
+                bbox_t_30.obj_id = detect_results_yolo[0][i].class_id;
+                outs_30.push_back(bbox_t_30);
+            }
+            for (size_t i = 0; i < detect_results_yolo[1].size(); i++) {
+                cv::Rect r = detector.get_rect(frame_90, detect_results_yolo[1][i].bbox,
+                                               detector.m_input_w,detector.m_input_h);
+                bbox_t_90.x = r.x;
+                bbox_t_90.y = r.y;
+                bbox_t_90.w = r.width;
+                bbox_t_90.h = r.height;
+                bbox_t_90.prob = detect_results_yolo[1][i].det_confidence;
+                bbox_t_90.obj_id = detect_results_yolo[1][i].class_id;
+                outs_90.push_back(bbox_t_90);
+                od::Drawer(frame_90, outs_90, classes);
+            }
+        }
+
+//        double infertime = (double)getTickCount() - start;
+//        std::cout<< "Total Cost of infertime: "  <<infertime*1000.0/cv::getTickFrequency()<<" ms"<<std::endl;
+
+        vector<od::TrackingBox>track_result_30,track_result_90;
+        bool track_flag_30 = od::TrackObstacle(frame_count,trackers_30,outs_30,track_result_30);
+        bool track_flag_90 = od::TrackObstacle(frame_count,trackers_90,outs_90,track_result_90);
+        if(track_flag_30)
+        {
+            vector<obstacle_info>obstacle_vector;
+            for(unsigned int i=0;i < track_result_30.size(); i++)
+            {
+                obstacle_info obstacle;
+                obstacle.category = classes[track_result_30[i].class_id];
+                obstacle.class_id = track_result_30[i].class_id;
+                //求bbox的接地点
+                Point2f bottom_center = Point2f(track_result_30[i].box.x+0.5*track_result_30[i].box.width,
+                                                track_result_30[i].box.y+track_result_30[i].box.height);
+                obstacle.bbox_3d = CameraToWorld(bottom_center);
+                obstacle.bbox = track_result_30[i].box;
+                obstacle_vector.push_back(obstacle);
+            }
+            detect_result_info.bboxes = obstacle_vector;
+            SendDetectResult(detect_result_info,g_obstacle);
+            od::Drawer(frame_30, track_result_30, classes);
+        }
+        else if(track_flag_90)
+        {
+            vector<obstacle_info>obstacle_vector;
+            for(unsigned int i=0;i < track_result_90.size(); i++)
+            {
+                obstacle_info obstacle;
+                obstacle.category = classes[track_result_90[i].class_id];
+                obstacle.class_id = track_result_90[i].class_id;
+                //求bbox的接地点
+                Point2f bottom_center = Point2f(track_result_90[i].box.x+0.5*track_result_90[i].box.width,
+                                                track_result_90[i].box.y+track_result_90[i].box.height);
+                obstacle.bbox_3d = CameraToWorld(bottom_center);
+                obstacle.bbox = track_result_90[i].box;
+                obstacle_vector.push_back(obstacle);
+            }
+            detect_result_info.bboxes = obstacle_vector;
+            SendDetectResult(detect_result_info,g_obstacle);
+            od::Drawer(frame_90, track_result_90, classes);
+        }
+        double total = (double)getTickCount() - start;
+        std::cout<< "Total Cost of Detection: "  <<total*1000.0/cv::getTickFrequency()<<" ms"<<endl;
+
+        namedWindow("Result_30",WINDOW_NORMAL);
+        imshow("Result_30",frame_30);
+
+        namedWindow("Result_90",WINDOW_NORMAL);
+        imshow("Result_90",frame_90);
+
+        if(waitKey(1) == 'q')
+            break;
+        if(waitKey(1) == 's')
+            waitKey(0);
+        waittime = (double)getTickCount();
+    }
+    destroyAllWindows();
+    trackers_30.clear();
+    trackers_90.clear();
+    yolo_context->destroy();
+    return 0;
+}

+ 28 - 0
src/detection/detection_yolov4_shigong_monocular/proto/obstacles.proto

@@ -0,0 +1,28 @@
+syntax = "proto2";
+package iv.vision;
+message Bbox3D
+{
+     optional string category = 1;
+     optional uint64 class_id = 2;
+     optional double x_3d = 3;
+     optional double y_3d = 4;
+     optional double z_3d = 5;
+     /*
+     `-------------->x
+      |
+      |
+      |
+      v
+      y
+     */
+     optional uint64 x = 6;
+     optional uint64 y = 7;
+     optional uint64 w = 8;
+     optional uint64 h = 9;
+}
+
+message ObstacleInfo
+{
+     repeated Bbox3D bbox_3d = 1;
+     optional uint64 time = 2;
+}

+ 1 - 0
src/detection/detection_yolov4_shigong_monocular/proto/protomake.sh

@@ -0,0 +1 @@
+protoc *.proto -I=./ --cpp_out=./

+ 16 - 0
src/detection/detection_yolov4_shigong_monocular/proto/rawpic.proto

@@ -0,0 +1,16 @@
+syntax = "proto2";
+
+package iv.vision;
+
+
+message rawpic
+{
+  optional int64 time = 1; // number of milliseconds since 1970-01-01T00:00:00 Universal Coordinated Time
+  optional int32 index = 2;
+  optional int32 type = 3; //类型, 1 mat 2 jpg
+  optional int32 width = 4;
+  optional int32 height = 5;
+  optional int32 elemsize = 6;
+  optional int32 mattype = 7;
+  optional bytes picdata = 8;
+};

+ 398 - 0
src/detection/detection_yolov4_shigong_monocular/src/Hungarian.cpp

@@ -0,0 +1,398 @@
+//
+// Created by lqx on 20-4-23.
+//
+///////////////////////////////////////////////////////////////////////////////
+// Hungarian.cpp: Implementation file for Class HungarianAlgorithm.
+//
+// This is a C++ wrapper with slight modification of a hungarian algorithm implementation by Markus Buehren.
+// The original implementation is a few mex-functions for use in MATLAB, found here:
+// http://www.mathworks.com/matlabcentral/fileexchange/6543-functions-for-the-rectangular-assignment-problem
+//
+// Both this code and the orignal code are published under the BSD license.
+// by Cong Ma, 2016
+//
+
+#include <math.h>
+#include <cfloat>
+#include "Hungarian.h"
+
+
+HungarianAlgorithm::HungarianAlgorithm(){}
+HungarianAlgorithm::~HungarianAlgorithm(){}
+
+
+//********************************************************//
+// A single function wrapper for solving assignment problem.
+//********************************************************//
+double HungarianAlgorithm::Solve(vector<vector<double>>& DistMatrix, vector<int>& Assignment)
+{
+    unsigned int nRows = DistMatrix.size();
+    unsigned int nCols = DistMatrix[0].size();
+
+    double *distMatrixIn = new double[nRows * nCols];
+    int *assignment = new int[nRows];
+    double cost = 0.0;
+
+    // Fill in the distMatrixIn. Mind the index is "i + nRows * j".
+    // Here the cost matrix of size MxN is defined as a double precision array of N*M elements.
+    // In the solving functions matrices are seen to be saved MATLAB-internally in row-order.
+    // (i.e. the matrix [1 2; 3 4] will be stored as a vector [1 3 2 4], NOT [1 2 3 4]).
+    for (unsigned int i = 0; i < nRows; i++)
+        for (unsigned int j = 0; j < nCols; j++)
+            distMatrixIn[i + nRows * j] = DistMatrix[i][j];
+
+    // call solving function
+    assignmentoptimal(assignment, &cost, distMatrixIn, nRows, nCols);
+
+    Assignment.clear();
+    for (unsigned int r = 0; r < nRows; r++)
+        Assignment.push_back(assignment[r]);
+
+    delete[] distMatrixIn;
+    delete[] assignment;
+    return cost;
+}
+
+
+//********************************************************//
+// Solve optimal solution for assignment problem using Munkres algorithm, also known as Hungarian Algorithm.
+//********************************************************//
+void HungarianAlgorithm::assignmentoptimal(int *assignment, double *cost, double *distMatrixIn, int nOfRows, int nOfColumns)
+{
+    double *distMatrix, *distMatrixTemp, *distMatrixEnd, *columnEnd, value, minValue;
+    bool *coveredColumns, *coveredRows, *starMatrix, *newStarMatrix, *primeMatrix;
+    int nOfElements, minDim, row, col;
+
+    /* initialization */
+    *cost = 0;
+    for (row = 0; row<nOfRows; row++)
+        assignment[row] = -1;
+
+    /* generate working copy of distance Matrix */
+    /* check if all matrix elements are positive */
+    nOfElements = nOfRows * nOfColumns;
+    distMatrix = (double *)malloc(nOfElements * sizeof(double));
+    distMatrixEnd = distMatrix + nOfElements;
+
+    for (row = 0; row<nOfElements; row++)
+    {
+        value = distMatrixIn[row];
+        if (value < 0)
+            cerr << "All matrix elements have to be non-negative." << endl;
+        distMatrix[row] = value;
+    }
+
+
+    /* memory allocation */
+    coveredColumns = (bool *)calloc(nOfColumns, sizeof(bool));
+    coveredRows = (bool *)calloc(nOfRows, sizeof(bool));
+    starMatrix = (bool *)calloc(nOfElements, sizeof(bool));
+    primeMatrix = (bool *)calloc(nOfElements, sizeof(bool));
+    newStarMatrix = (bool *)calloc(nOfElements, sizeof(bool)); /* used in step4 */
+
+    /* preliminary steps */
+    if (nOfRows <= nOfColumns)
+    {
+        minDim = nOfRows;
+
+        for (row = 0; row<nOfRows; row++)
+        {
+            /* find the smallest element in the row */
+            distMatrixTemp = distMatrix + row;
+            minValue = *distMatrixTemp;
+            distMatrixTemp += nOfRows;
+            while (distMatrixTemp < distMatrixEnd)
+            {
+                value = *distMatrixTemp;
+                if (value < minValue)
+                    minValue = value;
+                distMatrixTemp += nOfRows;
+            }
+
+            /* subtract the smallest element from each element of the row */
+            distMatrixTemp = distMatrix + row;
+            while (distMatrixTemp < distMatrixEnd)
+            {
+                *distMatrixTemp -= minValue;
+                distMatrixTemp += nOfRows;
+            }
+        }
+
+        /* Steps 1 and 2a */
+        for (row = 0; row<nOfRows; row++)
+            for (col = 0; col<nOfColumns; col++)
+                if (fabs(distMatrix[row + nOfRows*col]) < DBL_EPSILON)
+                    if (!coveredColumns[col])
+                    {
+                        starMatrix[row + nOfRows*col] = true;
+                        coveredColumns[col] = true;
+                        break;
+                    }
+    }
+    else /* if(nOfRows > nOfColumns) */
+    {
+        minDim = nOfColumns;
+
+        for (col = 0; col<nOfColumns; col++)
+        {
+            /* find the smallest element in the column */
+            distMatrixTemp = distMatrix + nOfRows*col;
+            columnEnd = distMatrixTemp + nOfRows;
+
+            minValue = *distMatrixTemp++;
+            while (distMatrixTemp < columnEnd)
+            {
+                value = *distMatrixTemp++;
+                if (value < minValue)
+                    minValue = value;
+            }
+
+            /* subtract the smallest element from each element of the column */
+            distMatrixTemp = distMatrix + nOfRows*col;
+            while (distMatrixTemp < columnEnd)
+                *distMatrixTemp++ -= minValue;
+        }
+
+        /* Steps 1 and 2a */
+        for (col = 0; col<nOfColumns; col++)
+            for (row = 0; row<nOfRows; row++)
+                if (fabs(distMatrix[row + nOfRows*col]) < DBL_EPSILON)
+                    if (!coveredRows[row])
+                    {
+                        starMatrix[row + nOfRows*col] = true;
+                        coveredColumns[col] = true;
+                        coveredRows[row] = true;
+                        break;
+                    }
+        for (row = 0; row<nOfRows; row++)
+            coveredRows[row] = false;
+
+    }
+
+    /* move to step 2b */
+    step2b(assignment, distMatrix, starMatrix, newStarMatrix, primeMatrix, coveredColumns, coveredRows, nOfRows, nOfColumns, minDim);
+
+    /* compute cost and remove invalid assignments */
+    computeassignmentcost(assignment, cost, distMatrixIn, nOfRows);
+
+    /* free allocated memory */
+    free(distMatrix);
+    free(coveredColumns);
+    free(coveredRows);
+    free(starMatrix);
+    free(primeMatrix);
+    free(newStarMatrix);
+
+    return;
+}
+
+/********************************************************/
+void HungarianAlgorithm::buildassignmentvector(int *assignment, bool *starMatrix, int nOfRows, int nOfColumns)
+{
+    int row, col;
+
+    for (row = 0; row<nOfRows; row++)
+        for (col = 0; col<nOfColumns; col++)
+            if (starMatrix[row + nOfRows*col])
+            {
+#ifdef ONE_INDEXING
+                assignment[row] = col + 1; /* MATLAB-Indexing */
+#else
+                assignment[row] = col;
+#endif
+                break;
+            }
+}
+
+/********************************************************/
+void HungarianAlgorithm::computeassignmentcost(int *assignment, double *cost, double *distMatrix, int nOfRows)
+{
+    int row, col;
+
+    for (row = 0; row<nOfRows; row++)
+    {
+        col = assignment[row];
+        if (col >= 0)
+            *cost += distMatrix[row + nOfRows*col];
+    }
+}
+
+/********************************************************/
+void HungarianAlgorithm::step2a(int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim)
+{
+    bool *starMatrixTemp, *columnEnd;
+    int col;
+
+    /* cover every column containing a starred zero */
+    for (col = 0; col<nOfColumns; col++)
+    {
+        starMatrixTemp = starMatrix + nOfRows*col;
+        columnEnd = starMatrixTemp + nOfRows;
+        while (starMatrixTemp < columnEnd){
+            if (*starMatrixTemp++)
+            {
+                coveredColumns[col] = true;
+                break;
+            }
+        }
+    }
+
+    /* move to step 3 */
+    step2b(assignment, distMatrix, starMatrix, newStarMatrix, primeMatrix, coveredColumns, coveredRows, nOfRows, nOfColumns, minDim);
+}
+
+/********************************************************/
+void HungarianAlgorithm::step2b(int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim)
+{
+    int col, nOfCoveredColumns;
+
+    /* count covered columns */
+    nOfCoveredColumns = 0;
+    for (col = 0; col<nOfColumns; col++)
+        if (coveredColumns[col])
+            nOfCoveredColumns++;
+
+    if (nOfCoveredColumns == minDim)
+    {
+        /* algorithm finished */
+        buildassignmentvector(assignment, starMatrix, nOfRows, nOfColumns);
+    }
+    else
+    {
+        /* move to step 3 */
+        step3(assignment, distMatrix, starMatrix, newStarMatrix, primeMatrix, coveredColumns, coveredRows, nOfRows, nOfColumns, minDim);
+    }
+
+}
+
+/********************************************************/
+void HungarianAlgorithm::step3(int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim)
+{
+    bool zerosFound;
+    int row, col, starCol;
+
+    zerosFound = true;
+    while (zerosFound)
+    {
+        zerosFound = false;
+        for (col = 0; col<nOfColumns; col++)
+            if (!coveredColumns[col])
+                for (row = 0; row<nOfRows; row++)
+                    if ((!coveredRows[row]) && (fabs(distMatrix[row + nOfRows*col]) < DBL_EPSILON))
+                    {
+                        /* prime zero */
+                        primeMatrix[row + nOfRows*col] = true;
+
+                        /* find starred zero in current row */
+                        for (starCol = 0; starCol<nOfColumns; starCol++)
+                            if (starMatrix[row + nOfRows*starCol])
+                                break;
+
+                        if (starCol == nOfColumns) /* no starred zero found */
+                        {
+                            /* move to step 4 */
+                            step4(assignment, distMatrix, starMatrix, newStarMatrix, primeMatrix, coveredColumns, coveredRows, nOfRows, nOfColumns, minDim, row, col);
+                            return;
+                        }
+                        else
+                        {
+                            coveredRows[row] = true;
+                            coveredColumns[starCol] = false;
+                            zerosFound = true;
+                            break;
+                        }
+                    }
+    }
+
+    /* move to step 5 */
+    step5(assignment, distMatrix, starMatrix, newStarMatrix, primeMatrix, coveredColumns, coveredRows, nOfRows, nOfColumns, minDim);
+}
+
+/********************************************************/
+void HungarianAlgorithm::step4(int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim, int row, int col)
+{
+    int n, starRow, starCol, primeRow, primeCol;
+    int nOfElements = nOfRows*nOfColumns;
+
+    /* generate temporary copy of starMatrix */
+    for (n = 0; n<nOfElements; n++)
+        newStarMatrix[n] = starMatrix[n];
+
+    /* star current zero */
+    newStarMatrix[row + nOfRows*col] = true;
+
+    /* find starred zero in current column */
+    starCol = col;
+    for (starRow = 0; starRow<nOfRows; starRow++)
+        if (starMatrix[starRow + nOfRows*starCol])
+            break;
+
+    while (starRow<nOfRows)
+    {
+        /* unstar the starred zero */
+        newStarMatrix[starRow + nOfRows*starCol] = false;
+
+        /* find primed zero in current row */
+        primeRow = starRow;
+        for (primeCol = 0; primeCol<nOfColumns; primeCol++)
+            if (primeMatrix[primeRow + nOfRows*primeCol])
+                break;
+
+        /* star the primed zero */
+        newStarMatrix[primeRow + nOfRows*primeCol] = true;
+
+        /* find starred zero in current column */
+        starCol = primeCol;
+        for (starRow = 0; starRow<nOfRows; starRow++)
+            if (starMatrix[starRow + nOfRows*starCol])
+                break;
+    }
+
+    /* use temporary copy as new starMatrix */
+    /* delete all primes, uncover all rows */
+    for (n = 0; n<nOfElements; n++)
+    {
+        primeMatrix[n] = false;
+        starMatrix[n] = newStarMatrix[n];
+    }
+    for (n = 0; n<nOfRows; n++)
+        coveredRows[n] = false;
+
+    /* move to step 2a */
+    step2a(assignment, distMatrix, starMatrix, newStarMatrix, primeMatrix, coveredColumns, coveredRows, nOfRows, nOfColumns, minDim);
+}
+
+/********************************************************/
+void HungarianAlgorithm::step5(int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim)
+{
+    double h, value;
+    int row, col;
+
+    /* find smallest uncovered element h */
+    h = DBL_MAX;
+    for (row = 0; row<nOfRows; row++)
+        if (!coveredRows[row])
+            for (col = 0; col<nOfColumns; col++)
+                if (!coveredColumns[col])
+                {
+                    value = distMatrix[row + nOfRows*col];
+                    if (value < h)
+                        h = value;
+                }
+
+    /* add h to each covered row */
+    for (row = 0; row<nOfRows; row++)
+        if (coveredRows[row])
+            for (col = 0; col<nOfColumns; col++)
+                distMatrix[row + nOfRows*col] += h;
+
+    /* subtract h from each uncovered column */
+    for (col = 0; col<nOfColumns; col++)
+        if (!coveredColumns[col])
+            for (row = 0; row<nOfRows; row++)
+                distMatrix[row + nOfRows*col] -= h;
+
+    /* move to step 3 */
+    step3(assignment, distMatrix, starMatrix, newStarMatrix, primeMatrix, coveredColumns, coveredRows, nOfRows, nOfColumns, minDim);
+}
+

+ 101 - 0
src/detection/detection_yolov4_shigong_monocular/src/KalmanTracker.cpp

@@ -0,0 +1,101 @@
+//
+// Created by lqx on 20-4-23.
+//
+
+///////////////////////////////////////////////////////////////////////////////
+// KalmanTracker.cpp: KalmanTracker Class Implementation Declaration
+
+#include "KalmanTracker.h"
+#include "detect_obstacle.h"
+#include <iostream>
+
+int KalmanTracker::kf_count = 0;
+
+// initialize Kalman filter
+void KalmanTracker::init_kf(StateType stateMat)
+{
+    int stateNum = 7;
+    int measureNum = 4;
+    kf = KalmanFilter(stateNum, measureNum, 0);
+
+    measurement = Mat::zeros(measureNum, 1, CV_32F);
+
+    kf.transitionMatrix = (Mat_<float>(stateNum, stateNum) <<
+                                                            1, 0, 0, 0, 1, 0, 0,
+            0, 1, 0, 0, 0, 1, 0,
+            0, 0, 1, 0, 0, 0, 1,
+            0, 0, 0, 1, 0, 0, 0,
+            0, 0, 0, 0, 1, 0, 0,
+            0, 0, 0, 0, 0, 1, 0,
+            0, 0, 0, 0, 0, 0, 1);
+
+    setIdentity(kf.measurementMatrix);
+    setIdentity(kf.processNoiseCov, Scalar::all(1e-2));
+    setIdentity(kf.measurementNoiseCov, Scalar::all(1e-1));
+    setIdentity(kf.errorCovPost, Scalar::all(1));
+
+    // initialize state vector with bounding box in [cx,cy,s,r] style
+    kf.statePost.at<float>(0, 0) = stateMat.x + stateMat.width / 2;
+    kf.statePost.at<float>(1, 0) = stateMat.y + stateMat.height / 2;
+    kf.statePost.at<float>(2, 0) = stateMat.area();
+    kf.statePost.at<float>(3, 0) = stateMat.width / stateMat.height;
+}
+
+// Predict the estimated bounding box.
+StateType KalmanTracker::predict()
+{
+    // predict
+    Mat p = kf.predict();
+    m_age += 1;
+
+    if (m_time_since_update > od::max_age)
+        m_hit_streak = 0;
+    m_time_since_update += 1;
+    StateType predictBox = get_rect_xysr(p.at<float>(0, 0), p.at<float>(1, 0), p.at<float>(2, 0), p.at<float>(3, 0));
+    m_history.push_back(predictBox);
+    return m_history.back();
+}
+
+// Update the state vector with observed bounding box.
+void KalmanTracker::update(StateType stateMat, int classId, float prob)
+{
+    m_time_since_update = 0;
+    m_history.clear();
+    m_hits += 1;
+    m_hit_streak += 1;
+    m_class_id = classId;
+    m_class_history.push_back(classId);
+    m_prob = prob;
+    // measurement
+    measurement.at<float>(0, 0) = stateMat.x + stateMat.width / 2;
+    measurement.at<float>(1, 0) = stateMat.y + stateMat.height / 2;
+    measurement.at<float>(2, 0) = stateMat.area();
+    measurement.at<float>(3, 0) = stateMat.width / stateMat.height;
+
+    // update
+    kf.correct(measurement);
+}
+
+// Return the current state vector
+StateType KalmanTracker::get_state()
+{
+    Mat s = kf.statePost;
+    return get_rect_xysr(s.at<float>(0, 0), s.at<float>(1, 0), s.at<float>(2, 0), s.at<float>(3, 0));
+}
+
+
+// Convert bounding box from [cx,cy,s,r] to [x,y,w,h] style.
+StateType KalmanTracker::get_rect_xysr(float cx, float cy, float s, float r)
+{
+    float w = sqrt(s * r);
+    float h = s / w;
+    float x = (cx - w / 2);
+    float y = (cy - h / 2);
+
+    if (x < 0 && cx > 0)
+        x = 0;
+    if (y < 0 && cy > 0)
+        y = 0;
+
+    return StateType(x, y, w, h);
+}

+ 309 - 0
src/detection/detection_yolov4_shigong_monocular/src/detect_obstacle.cpp

@@ -0,0 +1,309 @@
+
+#include <set>
+#include "detect_obstacle.h"
+
+namespace od{
+// Computes IOU between two bounding boxes
+double GetIOU(Rect_<float> bb_test, Rect_<float> bb_gt)
+{
+    float in = (bb_test & bb_gt).area();
+    float un = bb_test.area() + bb_gt.area() - in;
+
+    if (un < DBL_EPSILON)
+        return 0;
+
+    return (double)(in / un);
+}
+
+//画出检测框和相关信息
+void DrawBoxes(Mat &frame, vector<string> classes, int classId, int turnstileId, float conf, int left, int top, int right, int bottom)
+{
+    //画检测框
+    rectangle(frame, Point(left, top), Point(right, bottom), Scalar(od::COLOR_MAP[classId][0], od::COLOR_MAP[classId][1], od::COLOR_MAP[classId][2]), 2);
+    //该检测框对应的类别和置信度
+    //string label = format("%.2f", conf);
+    //string label = format("%d", turnstileId);
+
+    string label;
+    if (!classes.empty())
+    {
+        CV_Assert(classId < (int)classes.size());
+        //label = classes[classId] + ":" + label;
+        label = classes[classId];
+    }
+    //将标签显示在检测框顶部
+    int baseLine;
+    Size labelSize = getTextSize(label, FONT_HERSHEY_SIMPLEX, 0.5, 1, &baseLine);
+    //top = max(top, labelSize.height);
+    rectangle(frame, Point(left, top), Point(left + round(1.1*labelSize.width), top - labelSize.height),
+              Scalar(od::COLOR_MAP[classId][0], od::COLOR_MAP[classId][1], od::COLOR_MAP[classId][2]), FILLED);
+    putText(frame, label, Point(left, top-baseLine*0.5), FONT_HERSHEY_SIMPLEX, 0.5, Scalar(255, 255, 255), 1);
+}
+
+//画出检测结果
+void Drawer(Mat &frame, vector<bbox_t> outs, vector<string> classes)
+{
+    //获取所有最佳检测框信息
+    for (int i = 0; i < outs.size(); i++)
+    {
+        DrawBoxes(frame, classes, outs[i].obj_id, outs[i].track_id, outs[i].prob, outs[i].x, outs[i].y,
+                  outs[i].x + outs[i].w, outs[i].y + outs[i].h);
+    }
+}
+
+//画出检测结果
+void Drawer(Mat &frame, vector<od::TrackingBox> &track_result, vector<string> &classes)
+{
+
+    //获取所有最佳检测框信息
+    for (int i = 0; i < track_result.size(); i++)
+    {
+        DrawBoxes(frame, classes, track_result[i].class_id, track_result[i].id, track_result[i].prob,
+                  int(track_result[i].box.x),int(track_result[i].box.y),
+                  int(track_result[i].box.x + track_result[i].box.width),
+                  int(track_result[i].box.y + track_result[i].box.height));
+    }
+}
+
+//tracking obstacle
+bool TrackObstacle(int frame_count,vector<KalmanTracker> &trackers,vector<bbox_t> &outs,vector<od::TrackingBox> &track_result)
+{
+    // variables used in the for-loop
+    vector<Rect_<float>> predictedBoxes;
+    vector<vector<double>> iouMatrix;
+    vector<int> assignment;
+    set<int> unmatchedDetections;
+    set<int> unmatchedTrajectories;
+    set<int> allItems;
+    set<int> matchedItems;
+    vector<cv::Point> matchedPairs;
+    unsigned int trkNum = 0;
+    unsigned int detNum = 0;
+    vector<od::DetectBox> detect_outs;
+    //bbox_t to Detect_box
+    for(unsigned int i=0;i<outs.size();i++)
+    {
+        od::DetectBox detect_temp;
+        detect_temp.class_id = outs[i].obj_id;
+        detect_temp.prob = outs[i].prob;
+        float tpx = outs[i].x;
+        float tpy = outs[i].y;
+        float tpw = outs[i].w;
+        float tph = outs[i].h;
+        //detect_temp.box = Rect_<float>(Point_<float>(tpx, tpy),Point_<float>(tpx + tpw, tpy + tph));
+        detect_temp.box = Rect_<float>(tpx,tpy,tpw,tph);
+        detect_outs.push_back(detect_temp);
+    }
+    //tracking
+    if (trackers.size() == 0) // the first frame met
+    {
+        // initialize kalman trackers using first detections.
+        for (unsigned int i = 0; i < outs.size(); i++)
+        {
+            KalmanTracker trk = KalmanTracker(detect_outs[i].box,
+                                              detect_outs[i].class_id,
+                                              detect_outs[i].prob);
+            trackers.push_back(trk);
+        }
+        return false;
+    }
+    ///////////////////////////////////////
+    // 3.1. get predicted locations from existing trackers.
+    predictedBoxes.clear();
+
+    for (auto it = trackers.begin(); it != trackers.end();)
+    {
+        Rect_<float> pBox = (*it).predict();
+        if (pBox.x >= 0 && pBox.y >= 0)
+        {
+            predictedBoxes.push_back(pBox);
+            it++;
+        }
+        else
+        {
+
+            cerr << "Box invalid at frame: " << frame_count <<" id "<<(*it).m_id+1<<endl;
+            it = trackers.erase(it);
+
+        }
+    }
+
+    if (trackers.size() == 0) return false;
+
+    ///////////////////////////////////////
+    // 3.2. associate detections to tracked object (both represented as bounding boxes)
+    // dets : detFrameData[fi]
+    trkNum = predictedBoxes.size();
+    detNum = outs.size();
+
+    iouMatrix.clear();
+    iouMatrix.resize(trkNum, vector<double>(detNum, 0));
+
+    for (unsigned int i = 0; i < trkNum; i++) // compute iou matrix as a distance matrix
+    {
+        for (unsigned int j = 0; j < detNum; j++)
+        {
+            // use 1-iou because the hungarian algorithm computes a minimum-cost assignment.
+            iouMatrix[i][j] = 1 - GetIOU(predictedBoxes[i], detect_outs[j].box);
+        }
+    }
+    // solve the assignment problem using hungarian algorithm.
+    // the resulting assignment is [track(prediction) : detection], with len=preNum
+    HungarianAlgorithm HungAlgo;
+    assignment.clear();
+    HungAlgo.Solve(iouMatrix, assignment);
+
+    // find matches, unmatched_detections and unmatched_predictions
+    unmatchedTrajectories.clear();
+    unmatchedDetections.clear();
+    allItems.clear();
+    matchedItems.clear();
+    if (detNum > trkNum) //	there are unmatched detections
+    {
+        for (unsigned int n = 0; n < detNum; n++)
+            allItems.insert(n);
+
+        for (unsigned int i = 0; i < trkNum; ++i)
+            matchedItems.insert(assignment[i]);
+
+        set_difference(allItems.begin(), allItems.end(),
+                       matchedItems.begin(), matchedItems.end(),
+                       insert_iterator<set<int>>(unmatchedDetections, unmatchedDetections.begin()));
+    }
+    else if (detNum < trkNum) // there are unmatched trajectory/predictions
+    {
+        for (unsigned int i = 0; i < trkNum; ++i)
+            if (assignment[i] == -1) // unassigned label will be set as -1 in the assignment algorithm
+                unmatchedTrajectories.insert(i);
+    }
+    // filter out matched with low IOU
+    matchedPairs.clear();
+    for (unsigned int i = 0; i < trkNum; ++i)
+    {
+        if (assignment[i] == -1) // pass over invalid values
+            continue;
+        if (1 - iouMatrix[i][assignment[i]] < od::iouThreshold)
+        {
+            unmatchedTrajectories.insert(i);
+            unmatchedDetections.insert(assignment[i]);
+        }
+        else
+            matchedPairs.push_back(cv::Point(i, assignment[i]));
+    }
+    ///////////////////////////////////////
+    // 3.3. updating trackers
+    // update matched trackers with assigned detections.
+    // each prediction is corresponding to a tracker
+    int detIdx, trkIdx;
+    for (unsigned int i = 0; i < matchedPairs.size(); i++)
+    {
+        trkIdx = matchedPairs[i].x;
+        detIdx = matchedPairs[i].y;
+        trackers[trkIdx].update(detect_outs[detIdx].box,
+                                detect_outs[detIdx].class_id,
+                                detect_outs[detIdx].prob);
+    }
+    // create and initialise new trackers for unmatched detections
+    for (auto umd : unmatchedDetections)
+    {
+        KalmanTracker tracker = KalmanTracker(detect_outs[umd].box,
+                                              detect_outs[umd].class_id,
+                                              detect_outs[umd].prob);
+        trackers.push_back(tracker);
+    }
+
+#if 0
+    //get unique trackers,merg same trackers
+    unsigned int trackers_num = trackers.size();
+    iouMatrix.clear();
+    iouMatrix.resize(trackers_num, vector<double>(trackers_num, 0));
+    for (unsigned int i = 0; i < trackers_num; i++) // compute iou matrix as a distance matrix
+    {
+        for (unsigned int j = 0; j < trackers_num; j++)
+        {
+            // use 1-iou because the hungarian algorithm computes a minimum-cost assignment.
+            if(j==i)
+                iouMatrix[i][j] = 1;
+            else
+                iouMatrix[i][j] = 1 - GetIOU(trackers[i].get_state(), trackers[j].get_state());
+        }
+    }
+    // solve the assignment problem using hungarian algorithm.
+    // the resulting assignment is [track(prediction) : detection], with len=preNum
+    assignment.clear();
+    HungAlgo.Solve(iouMatrix, assignment);
+    // filter out matched with low IOU
+    matchedPairs.clear();
+    for (unsigned int i = 0; i < trackers_num; ++i)
+    {
+        if (assignment[i] == -1) // pass over invalid values
+            continue;
+        if (iouMatrix[i][assignment[i]] < od::iouThreshold)
+        {
+            matchedPairs.push_back(cv::Point(i, assignment[i]));
+        }
+    }
+    int index1,index2;
+    vector<int> delete_index;
+    for (unsigned int i = 0; i < matchedPairs.size(); i++)
+    {
+        index1 = matchedPairs[i].x;
+        index2 = matchedPairs[i].y;
+        if(index1 >= index2)
+            continue;
+        if((trackers[index1].m_id > trackers[index2].m_id) && (trackers[index1].m_class_history.size()>0))
+        {
+            trackers[index1].m_id = trackers[index2].m_id;
+            trackers[index1].m_class_history.insert(trackers[index1].m_class_history.begin(),
+                                                    trackers[index2].m_class_history.begin(),trackers[index2].m_class_history.end());
+            delete_index.push_back(index2);
+        }
+        else if((trackers[index2].m_id > trackers[index1].m_id) && (trackers[index2].m_class_history.size()>0))
+        {
+            trackers[index2].m_id = trackers[index1].m_id;
+            trackers[index2].m_class_history.insert(trackers[index2].m_class_history.begin(),
+                                                    trackers[index1].m_class_history.begin(),trackers[index1].m_class_history.end());
+            delete_index.push_back(index1);
+
+        }
+    }
+    for(unsigned int i = 0; i < delete_index.size(); i++)
+    {
+        int idx = delete_index[i] - i;
+        trackers.erase(trackers.begin() + idx);
+    }
+#endif
+
+    // get trackers' output
+    track_result.clear();
+    for (auto it = trackers.begin(); it != trackers.end();)
+    {
+        if (((*it).m_time_since_update <= od::max_age) &&
+                ((*it).m_hit_streak >= od::min_hits || frame_count <= od::min_hits))
+        {
+            od::TrackingBox res;
+            res.box = (*it).get_state();
+            res.id = (*it).m_id + 1;
+            res.frame = frame_count;
+            res.class_id = (*it).m_class_id;
+            res.prob = (*it).m_prob;
+            res.class_history = (*it).m_class_history;
+            track_result.push_back(res);
+            it++;
+        }
+        else
+            it ++;
+        //remove dead tracklet
+        if(it != trackers.end() && (*it).m_time_since_update > od::max_age)
+        {
+            it = trackers.erase(it);
+        }
+    }
+    if(track_result.size()>0)
+        return true;
+    else return false;
+}
+}
+
+
+

+ 94 - 0
src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/include/Utils.h

@@ -0,0 +1,94 @@
+#ifndef __TRT_UTILS_H_
+#define __TRT_UTILS_H_
+
+#include <iostream>
+#include <vector>
+#include <algorithm>
+#include <cudnn.h>
+
+#ifndef CUDA_CHECK
+
+#define CUDA_CHECK(callstr)                                                                    \
+    {                                                                                          \
+        cudaError_t error_code = callstr;                                                      \
+        if (error_code != cudaSuccess) {                                                       \
+            std::cerr << "CUDA error " << error_code << " at " << __FILE__ << ":" << __LINE__; \
+            assert(0);                                                                         \
+        }                                                                                      \
+    }
+
+#endif
+
+namespace Tn
+{
+    class Profiler : public nvinfer1::IProfiler
+    {
+    public:
+        void printLayerTimes(int itrationsTimes)
+        {
+            float totalTime = 0;
+            for (size_t i = 0; i < mProfile.size(); i++)
+            {
+                printf("%-40.40s %4.3fms\n", mProfile[i].first.c_str(), mProfile[i].second / itrationsTimes);
+                totalTime += mProfile[i].second;
+            }
+            printf("Time over all layers: %4.3f\n", totalTime / itrationsTimes);
+        }
+    private:
+        typedef std::pair<std::string, float> Record;
+        std::vector<Record> mProfile;
+
+        virtual void reportLayerTime(const char* layerName, float ms)
+        {
+            auto record = std::find_if(mProfile.begin(), mProfile.end(), [&](const Record& r){ return r.first == layerName; });
+            if (record == mProfile.end())
+                mProfile.push_back(std::make_pair(layerName, ms));
+            else
+                record->second += ms;
+        }
+    };
+
+    //Logger for TensorRT info/warning/errors
+    class Logger : public nvinfer1::ILogger
+    {
+    public:
+
+        Logger(): Logger(Severity::kWARNING) {}
+
+        Logger(Severity severity): reportableSeverity(severity) {}
+
+        void log(Severity severity, const char* msg) override
+        {
+            // suppress messages with severity enum value greater than the reportable
+            if (severity > reportableSeverity) return;
+
+            switch (severity)
+            {
+                case Severity::kINTERNAL_ERROR: std::cerr << "INTERNAL_ERROR: "; break;
+                case Severity::kERROR: std::cerr << "ERROR: "; break;
+                case Severity::kWARNING: std::cerr << "WARNING: "; break;
+                case Severity::kINFO: std::cerr << "INFO: "; break;
+                default: std::cerr << "UNKNOWN: "; break;
+            }
+            std::cerr << msg << std::endl;
+        }
+
+        Severity reportableSeverity{Severity::kWARNING};
+    };
+
+    template<typename T> 
+    void write(char*& buffer, const T& val)
+    {
+        *reinterpret_cast<T*>(buffer) = val;
+        buffer += sizeof(T);
+    }
+
+    template<typename T> 
+    void read(const char*& buffer, T& val)
+    {
+        val = *reinterpret_cast<const T*>(buffer);
+        buffer += sizeof(T);
+    }
+}
+
+#endif

+ 503 - 0
src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/include/logging.h

@@ -0,0 +1,503 @@
+/*
+ * Copyright (c) 2019, NVIDIA CORPORATION. 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.
+ */
+
+#ifndef TENSORRT_LOGGING_H
+#define TENSORRT_LOGGING_H
+
+#include "NvInferRuntimeCommon.h"
+#include <cassert>
+#include <ctime>
+#include <iomanip>
+#include <iostream>
+#include <ostream>
+#include <sstream>
+#include <string>
+
+using Severity = nvinfer1::ILogger::Severity;
+
+class LogStreamConsumerBuffer : public std::stringbuf
+{
+public:
+    LogStreamConsumerBuffer(std::ostream& stream, const std::string& prefix, bool shouldLog)
+        : mOutput(stream)
+        , mPrefix(prefix)
+        , mShouldLog(shouldLog)
+    {
+    }
+
+    LogStreamConsumerBuffer(LogStreamConsumerBuffer&& other)
+        : mOutput(other.mOutput)
+    {
+    }
+
+    ~LogStreamConsumerBuffer()
+    {
+        // std::streambuf::pbase() gives a pointer to the beginning of the buffered part of the output sequence
+        // std::streambuf::pptr() gives a pointer to the current position of the output sequence
+        // if the pointer to the beginning is not equal to the pointer to the current position,
+        // call putOutput() to log the output to the stream
+        if (pbase() != pptr())
+        {
+            putOutput();
+        }
+    }
+
+    // synchronizes the stream buffer and returns 0 on success
+    // synchronizing the stream buffer consists of inserting the buffer contents into the stream,
+    // resetting the buffer and flushing the stream
+    virtual int sync()
+    {
+        putOutput();
+        return 0;
+    }
+
+    void putOutput()
+    {
+        if (mShouldLog)
+        {
+            // prepend timestamp
+            std::time_t timestamp = std::time(nullptr);
+            tm* tm_local = std::localtime(&timestamp);
+            std::cout << "[";
+            std::cout << std::setw(2) << std::setfill('0') << 1 + tm_local->tm_mon << "/";
+            std::cout << std::setw(2) << std::setfill('0') << tm_local->tm_mday << "/";
+            std::cout << std::setw(4) << std::setfill('0') << 1900 + tm_local->tm_year << "-";
+            std::cout << std::setw(2) << std::setfill('0') << tm_local->tm_hour << ":";
+            std::cout << std::setw(2) << std::setfill('0') << tm_local->tm_min << ":";
+            std::cout << std::setw(2) << std::setfill('0') << tm_local->tm_sec << "] ";
+            // std::stringbuf::str() gets the string contents of the buffer
+            // insert the buffer contents pre-appended by the appropriate prefix into the stream
+            mOutput << mPrefix << str();
+            // set the buffer to empty
+            str("");
+            // flush the stream
+            mOutput.flush();
+        }
+    }
+
+    void setShouldLog(bool shouldLog)
+    {
+        mShouldLog = shouldLog;
+    }
+
+private:
+    std::ostream& mOutput;
+    std::string mPrefix;
+    bool mShouldLog;
+};
+
+//!
+//! \class LogStreamConsumerBase
+//! \brief Convenience object used to initialize LogStreamConsumerBuffer before std::ostream in LogStreamConsumer
+//!
+class LogStreamConsumerBase
+{
+public:
+    LogStreamConsumerBase(std::ostream& stream, const std::string& prefix, bool shouldLog)
+        : mBuffer(stream, prefix, shouldLog)
+    {
+    }
+
+protected:
+    LogStreamConsumerBuffer mBuffer;
+};
+
+//!
+//! \class LogStreamConsumer
+//! \brief Convenience object used to facilitate use of C++ stream syntax when logging messages.
+//!  Order of base classes is LogStreamConsumerBase and then std::ostream.
+//!  This is because the LogStreamConsumerBase class is used to initialize the LogStreamConsumerBuffer member field
+//!  in LogStreamConsumer and then the address of the buffer is passed to std::ostream.
+//!  This is necessary to prevent the address of an uninitialized buffer from being passed to std::ostream.
+//!  Please do not change the order of the parent classes.
+//!
+class LogStreamConsumer : protected LogStreamConsumerBase, public std::ostream
+{
+public:
+    //! \brief Creates a LogStreamConsumer which logs messages with level severity.
+    //!  Reportable severity determines if the messages are severe enough to be logged.
+    LogStreamConsumer(Severity reportableSeverity, Severity severity)
+        : LogStreamConsumerBase(severityOstream(severity), severityPrefix(severity), severity <= reportableSeverity)
+        , std::ostream(&mBuffer) // links the stream buffer with the stream
+        , mShouldLog(severity <= reportableSeverity)
+        , mSeverity(severity)
+    {
+    }
+
+    LogStreamConsumer(LogStreamConsumer&& other)
+        : LogStreamConsumerBase(severityOstream(other.mSeverity), severityPrefix(other.mSeverity), other.mShouldLog)
+        , std::ostream(&mBuffer) // links the stream buffer with the stream
+        , mShouldLog(other.mShouldLog)
+        , mSeverity(other.mSeverity)
+    {
+    }
+
+    void setReportableSeverity(Severity reportableSeverity)
+    {
+        mShouldLog = mSeverity <= reportableSeverity;
+        mBuffer.setShouldLog(mShouldLog);
+    }
+
+private:
+    static std::ostream& severityOstream(Severity severity)
+    {
+        return severity >= Severity::kINFO ? std::cout : std::cerr;
+    }
+
+    static std::string severityPrefix(Severity severity)
+    {
+        switch (severity)
+        {
+        case Severity::kINTERNAL_ERROR: return "[F] ";
+        case Severity::kERROR: return "[E] ";
+        case Severity::kWARNING: return "[W] ";
+        case Severity::kINFO: return "[I] ";
+        case Severity::kVERBOSE: return "[V] ";
+        default: assert(0); return "";
+        }
+    }
+
+    bool mShouldLog;
+    Severity mSeverity;
+};
+
+//! \class Logger
+//!
+//! \brief Class which manages logging of TensorRT tools and samples
+//!
+//! \details This class provides a common interface for TensorRT tools and samples to log information to the console,
+//! and supports logging two types of messages:
+//!
+//! - Debugging messages with an associated severity (info, warning, error, or internal error/fatal)
+//! - Test pass/fail messages
+//!
+//! The advantage of having all samples use this class for logging as opposed to emitting directly to stdout/stderr is
+//! that the logic for controlling the verbosity and formatting of sample output is centralized in one location.
+//!
+//! In the future, this class could be extended to support dumping test results to a file in some standard format
+//! (for example, JUnit XML), and providing additional metadata (e.g. timing the duration of a test run).
+//!
+//! TODO: For backwards compatibility with existing samples, this class inherits directly from the nvinfer1::ILogger
+//! interface, which is problematic since there isn't a clean separation between messages coming from the TensorRT
+//! library and messages coming from the sample.
+//!
+//! In the future (once all samples are updated to use Logger::getTRTLogger() to access the ILogger) we can refactor the
+//! class to eliminate the inheritance and instead make the nvinfer1::ILogger implementation a member of the Logger
+//! object.
+
+class Logger : public nvinfer1::ILogger
+{
+public:
+    Logger(Severity severity = Severity::kWARNING)
+        : mReportableSeverity(severity)
+    {
+    }
+
+    //!
+    //! \enum TestResult
+    //! \brief Represents the state of a given test
+    //!
+    enum class TestResult
+    {
+        kRUNNING, //!< The test is running
+        kPASSED,  //!< The test passed
+        kFAILED,  //!< The test failed
+        kWAIVED   //!< The test was waived
+    };
+
+    //!
+    //! \brief Forward-compatible method for retrieving the nvinfer::ILogger associated with this Logger
+    //! \return The nvinfer1::ILogger associated with this Logger
+    //!
+    //! TODO Once all samples are updated to use this method to register the logger with TensorRT,
+    //! we can eliminate the inheritance of Logger from ILogger
+    //!
+    nvinfer1::ILogger& getTRTLogger()
+    {
+        return *this;
+    }
+
+    //!
+    //! \brief Implementation of the nvinfer1::ILogger::log() virtual method
+    //!
+    //! Note samples should not be calling this function directly; it will eventually go away once we eliminate the
+    //! inheritance from nvinfer1::ILogger
+    //!
+    void log(Severity severity, const char* msg) override
+    {
+        LogStreamConsumer(mReportableSeverity, severity) << "[TRT] " << std::string(msg) << std::endl;
+    }
+
+    //!
+    //! \brief Method for controlling the verbosity of logging output
+    //!
+    //! \param severity The logger will only emit messages that have severity of this level or higher.
+    //!
+    void setReportableSeverity(Severity severity)
+    {
+        mReportableSeverity = severity;
+    }
+
+    //!
+    //! \brief Opaque handle that holds logging information for a particular test
+    //!
+    //! This object is an opaque handle to information used by the Logger to print test results.
+    //! The sample must call Logger::defineTest() in order to obtain a TestAtom that can be used
+    //! with Logger::reportTest{Start,End}().
+    //!
+    class TestAtom
+    {
+    public:
+        TestAtom(TestAtom&&) = default;
+
+    private:
+        friend class Logger;
+
+        TestAtom(bool started, const std::string& name, const std::string& cmdline)
+            : mStarted(started)
+            , mName(name)
+            , mCmdline(cmdline)
+        {
+        }
+
+        bool mStarted;
+        std::string mName;
+        std::string mCmdline;
+    };
+
+    //!
+    //! \brief Define a test for logging
+    //!
+    //! \param[in] name The name of the test.  This should be a string starting with
+    //!                  "TensorRT" and containing dot-separated strings containing
+    //!                  the characters [A-Za-z0-9_].
+    //!                  For example, "TensorRT.sample_googlenet"
+    //! \param[in] cmdline The command line used to reproduce the test
+    //
+    //! \return a TestAtom that can be used in Logger::reportTest{Start,End}().
+    //!
+    static TestAtom defineTest(const std::string& name, const std::string& cmdline)
+    {
+        return TestAtom(false, name, cmdline);
+    }
+
+    //!
+    //! \brief A convenience overloaded version of defineTest() that accepts an array of command-line arguments
+    //!        as input
+    //!
+    //! \param[in] name The name of the test
+    //! \param[in] argc The number of command-line arguments
+    //! \param[in] argv The array of command-line arguments (given as C strings)
+    //!
+    //! \return a TestAtom that can be used in Logger::reportTest{Start,End}().
+    static TestAtom defineTest(const std::string& name, int argc, char const* const* argv)
+    {
+        auto cmdline = genCmdlineString(argc, argv);
+        return defineTest(name, cmdline);
+    }
+
+    //!
+    //! \brief Report that a test has started.
+    //!
+    //! \pre reportTestStart() has not been called yet for the given testAtom
+    //!
+    //! \param[in] testAtom The handle to the test that has started
+    //!
+    static void reportTestStart(TestAtom& testAtom)
+    {
+        reportTestResult(testAtom, TestResult::kRUNNING);
+        assert(!testAtom.mStarted);
+        testAtom.mStarted = true;
+    }
+
+    //!
+    //! \brief Report that a test has ended.
+    //!
+    //! \pre reportTestStart() has been called for the given testAtom
+    //!
+    //! \param[in] testAtom The handle to the test that has ended
+    //! \param[in] result The result of the test. Should be one of TestResult::kPASSED,
+    //!                   TestResult::kFAILED, TestResult::kWAIVED
+    //!
+    static void reportTestEnd(const TestAtom& testAtom, TestResult result)
+    {
+        assert(result != TestResult::kRUNNING);
+        assert(testAtom.mStarted);
+        reportTestResult(testAtom, result);
+    }
+
+    static int reportPass(const TestAtom& testAtom)
+    {
+        reportTestEnd(testAtom, TestResult::kPASSED);
+        return EXIT_SUCCESS;
+    }
+
+    static int reportFail(const TestAtom& testAtom)
+    {
+        reportTestEnd(testAtom, TestResult::kFAILED);
+        return EXIT_FAILURE;
+    }
+
+    static int reportWaive(const TestAtom& testAtom)
+    {
+        reportTestEnd(testAtom, TestResult::kWAIVED);
+        return EXIT_SUCCESS;
+    }
+
+    static int reportTest(const TestAtom& testAtom, bool pass)
+    {
+        return pass ? reportPass(testAtom) : reportFail(testAtom);
+    }
+
+    Severity getReportableSeverity() const
+    {
+        return mReportableSeverity;
+    }
+
+private:
+    //!
+    //! \brief returns an appropriate string for prefixing a log message with the given severity
+    //!
+    static const char* severityPrefix(Severity severity)
+    {
+        switch (severity)
+        {
+        case Severity::kINTERNAL_ERROR: return "[F] ";
+        case Severity::kERROR: return "[E] ";
+        case Severity::kWARNING: return "[W] ";
+        case Severity::kINFO: return "[I] ";
+        case Severity::kVERBOSE: return "[V] ";
+        default: assert(0); return "";
+        }
+    }
+
+    //!
+    //! \brief returns an appropriate string for prefixing a test result message with the given result
+    //!
+    static const char* testResultString(TestResult result)
+    {
+        switch (result)
+        {
+        case TestResult::kRUNNING: return "RUNNING";
+        case TestResult::kPASSED: return "PASSED";
+        case TestResult::kFAILED: return "FAILED";
+        case TestResult::kWAIVED: return "WAIVED";
+        default: assert(0); return "";
+        }
+    }
+
+    //!
+    //! \brief returns an appropriate output stream (cout or cerr) to use with the given severity
+    //!
+    static std::ostream& severityOstream(Severity severity)
+    {
+        return severity >= Severity::kINFO ? std::cout : std::cerr;
+    }
+
+    //!
+    //! \brief method that implements logging test results
+    //!
+    static void reportTestResult(const TestAtom& testAtom, TestResult result)
+    {
+        severityOstream(Severity::kINFO) << "&&&& " << testResultString(result) << " " << testAtom.mName << " # "
+                                         << testAtom.mCmdline << std::endl;
+    }
+
+    //!
+    //! \brief generate a command line string from the given (argc, argv) values
+    //!
+    static std::string genCmdlineString(int argc, char const* const* argv)
+    {
+        std::stringstream ss;
+        for (int i = 0; i < argc; i++)
+        {
+            if (i > 0)
+                ss << " ";
+            ss << argv[i];
+        }
+        return ss.str();
+    }
+
+    Severity mReportableSeverity;
+};
+
+namespace
+{
+
+//!
+//! \brief produces a LogStreamConsumer object that can be used to log messages of severity kVERBOSE
+//!
+//! Example usage:
+//!
+//!     LOG_VERBOSE(logger) << "hello world" << std::endl;
+//!
+inline LogStreamConsumer LOG_VERBOSE(const Logger& logger)
+{
+    return LogStreamConsumer(logger.getReportableSeverity(), Severity::kVERBOSE);
+}
+
+//!
+//! \brief produces a LogStreamConsumer object that can be used to log messages of severity kINFO
+//!
+//! Example usage:
+//!
+//!     LOG_INFO(logger) << "hello world" << std::endl;
+//!
+inline LogStreamConsumer LOG_INFO(const Logger& logger)
+{
+    return LogStreamConsumer(logger.getReportableSeverity(), Severity::kINFO);
+}
+
+//!
+//! \brief produces a LogStreamConsumer object that can be used to log messages of severity kWARNING
+//!
+//! Example usage:
+//!
+//!     LOG_WARN(logger) << "hello world" << std::endl;
+//!
+inline LogStreamConsumer LOG_WARN(const Logger& logger)
+{
+    return LogStreamConsumer(logger.getReportableSeverity(), Severity::kWARNING);
+}
+
+//!
+//! \brief produces a LogStreamConsumer object that can be used to log messages of severity kERROR
+//!
+//! Example usage:
+//!
+//!     LOG_ERROR(logger) << "hello world" << std::endl;
+//!
+inline LogStreamConsumer LOG_ERROR(const Logger& logger)
+{
+    return LogStreamConsumer(logger.getReportableSeverity(), Severity::kERROR);
+}
+
+//!
+//! \brief produces a LogStreamConsumer object that can be used to log messages of severity kINTERNAL_ERROR
+//         ("fatal" severity)
+//!
+//! Example usage:
+//!
+//!     LOG_FATAL(logger) << "hello world" << std::endl;
+//!
+inline LogStreamConsumer LOG_FATAL(const Logger& logger)
+{
+    return LogStreamConsumer(logger.getReportableSeverity(), Severity::kINTERNAL_ERROR);
+}
+
+} // anonymous namespace
+
+#endif // TENSORRT_LOGGING_H

+ 106 - 0
src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/include/mish.h

@@ -0,0 +1,106 @@
+#ifndef _MISH_PLUGIN_H
+#define _MISH_PLUGIN_H
+
+#include <string>
+#include <vector>
+#include "NvInfer.h"
+
+namespace nvinfer1
+{
+    class MishPlugin: public IPluginV2IOExt
+    {
+        public:
+            explicit MishPlugin();
+            MishPlugin(const void* data, size_t length);
+
+            ~MishPlugin();
+
+            int getNbOutputs() const override
+            {
+                return 1;
+            }
+
+            Dims getOutputDimensions(int index, const Dims* inputs, int nbInputDims) override;
+
+            int initialize() override;
+
+            virtual void terminate() override {};
+
+            virtual size_t getWorkspaceSize(int maxBatchSize) const override { return 0;}
+
+            virtual int enqueue(int batchSize, const void*const * inputs, void** outputs, void* workspace, cudaStream_t stream) override;
+
+            virtual size_t getSerializationSize() const override;
+
+            virtual void serialize(void* buffer) const override;
+
+            bool supportsFormatCombination(int pos, const PluginTensorDesc* inOut, int nbInputs, int nbOutputs) const override {
+                return inOut[pos].format == TensorFormat::kLINEAR && inOut[pos].type == DataType::kFLOAT;
+            }
+
+            const char* getPluginType() const override;
+
+            const char* getPluginVersion() const override;
+
+            void destroy() override;
+
+            IPluginV2IOExt* clone() const override;
+
+            void setPluginNamespace(const char* pluginNamespace) override;
+
+            const char* getPluginNamespace() const override;
+
+            DataType getOutputDataType(int index, const nvinfer1::DataType* inputTypes, int nbInputs) const override;
+
+            bool isOutputBroadcastAcrossBatch(int outputIndex, const bool* inputIsBroadcasted, int nbInputs) const override;
+
+            bool canBroadcastInputAcrossBatch(int inputIndex) const override;
+
+            void attachToContext(
+                    cudnnContext* cudnnContext, cublasContext* cublasContext, IGpuAllocator* gpuAllocator) override;
+
+            void configurePlugin(const PluginTensorDesc* in, int nbInput, const PluginTensorDesc* out, int nbOutput) override;
+
+            void detachFromContext() override;
+
+            int input_size_;
+        private:
+            void forwardGpu(const float *const * inputs, float* output, cudaStream_t stream, int batchSize = 1);
+            int thread_count_ = 256;
+            const char* mPluginNamespace;
+    };
+
+    class MishPluginCreator : public IPluginCreator
+    {
+        public:
+            MishPluginCreator();
+
+            ~MishPluginCreator() override = default;
+
+            const char* getPluginName() const override;
+
+            const char* getPluginVersion() const override;
+
+            const PluginFieldCollection* getFieldNames() override;
+
+            IPluginV2IOExt* createPlugin(const char* name, const PluginFieldCollection* fc) override;
+
+            IPluginV2IOExt* deserializePlugin(const char* name, const void* serialData, size_t serialLength) override;
+
+            void setPluginNamespace(const char* libNamespace) override
+            {
+                mNamespace = libNamespace;
+            }
+
+            const char* getPluginNamespace() const override
+            {
+                return mNamespace.c_str();
+            }
+
+        private:
+            std::string mNamespace;
+            static PluginFieldCollection mFC;
+            static std::vector<PluginField> mPluginAttributes;
+    };
+};
+#endif 

+ 70 - 0
src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/include/trt_utils.h

@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+
+#ifndef __TRT_UTILS_H__
+#define __TRT_UTILS_H__
+
+#include <set>
+#include <map>
+#include <string>
+#include <vector>
+#include <cassert>
+#include <iostream>
+#include <fstream>
+
+#include "NvInfer.h"
+#include "NvInferPlugin.h"
+
+#define UNUSED(expr) (void)(expr)
+#define DIVUP(n, d) ((n) + (d)-1) / (d)
+
+std::string trim(std::string s);
+float clamp(const float val, const float minVal, const float maxVal);
+bool fileExists(const std::string fileName, bool verbose = true);
+std::vector<float> loadWeights(const std::string weightsFilePath, const std::string& networkType);
+std::string dimsToString(const nvinfer1::Dims d);
+void displayDimType(const nvinfer1::Dims d);
+int getNumChannels(nvinfer1::ITensor* t);
+uint64_t get3DTensorVolume(nvinfer1::Dims inputDims);
+
+// Helper functions to create yolo engine
+nvinfer1::ILayer* netAddMaxpool(int layerIdx, std::map<std::string, std::string>& block,
+                                nvinfer1::ITensor* input, nvinfer1::INetworkDefinition* network);
+nvinfer1::ILayer* netAddConvLinear(int layerIdx, std::map<std::string, std::string>& block,
+                                   std::vector<float>& weights,
+                                   std::vector<nvinfer1::Weights>& trtWeights, int& weightPtr,
+                                   int& inputChannels, nvinfer1::ITensor* input,
+                                   nvinfer1::INetworkDefinition* network);
+nvinfer1::ILayer* netAddConvBNActive(int layerIdx, std::map<std::string, std::string>& block,
+                                    std::vector<float>& weights,
+                                    std::vector<nvinfer1::Weights>& trtWeights, int& weightPtr,
+                                    int& inputChannels, nvinfer1::ITensor* input,
+                                    nvinfer1::INetworkDefinition* network);
+nvinfer1::ILayer* netAddUpsample(int layerIdx, std::map<std::string, std::string>& block,
+                                 std::vector<float>& weights,
+                                 std::vector<nvinfer1::Weights>& trtWeights, int& inputChannels,
+                                 nvinfer1::ITensor* input, nvinfer1::INetworkDefinition* network);
+void printLayerInfo(std::string layerIndex, std::string layerName, std::string layerInput,
+                    std::string layerOutput, std::string weightPtr);
+
+#endif

+ 167 - 0
src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/include/yolo.h

@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _YOLO_H_
+#define _YOLO_H_
+
+#include <stdint.h>
+#include <string>
+#include <vector>
+#include <memory>
+
+#include "NvInfer.h"
+#include "trt_utils.h"
+#include "yololayer.h"
+#include "mish.h"
+
+typedef enum {
+    /** NvDsInferContext operation succeeded. */
+    NVDSINFER_SUCCESS = 0,
+    /** Failed to configure the NvDsInferContext instance possibly due to an
+     *  erroneous initialization property. */
+    NVDSINFER_CONFIG_FAILED,
+    /** Custom Library interface implementation failed. */
+    NVDSINFER_CUSTOM_LIB_FAILED,
+    /** Invalid parameters were supplied. */
+    NVDSINFER_INVALID_PARAMS,
+    /** Output parsing failed. */
+    NVDSINFER_OUTPUT_PARSING_FAILED,
+    /** CUDA error was encountered. */
+    NVDSINFER_CUDA_ERROR,
+    /** TensorRT interface failed. */
+    NVDSINFER_TENSORRT_ERROR,
+    /** Resource error was encountered. */
+    NVDSINFER_RESOURCE_ERROR,
+    /** TRT-IS error was encountered. */
+    NVDSINFER_TRTIS_ERROR,
+    /** Unknown error was encountered. */
+    NVDSINFER_UNKNOWN_ERROR
+} NvDsInferStatus;
+
+class IModelParser
+{
+public:
+    IModelParser() = default;
+    /**
+     * Destructor, make sure all external resource would be released here. */
+    virtual ~IModelParser() = default;
+
+    /**
+     * Function interface for parsing custom model and building tensorrt
+     * network.
+     *
+     * @param[in, out] network NvDsInfer will create the @a network and
+     *                 implementation can setup this network layer by layer.
+     * @return NvDsInferStatus indicating if model parsing was sucessful.
+     */
+    virtual NvDsInferStatus parseModel(
+        nvinfer1::INetworkDefinition& network) = 0;
+
+    /**
+     * Function interface to check if parser can support full-dimensions.
+     */
+    virtual bool hasFullDimsSupported() const = 0;
+
+    /**
+     * Function interface to get the new model name which is to be used for
+     * constructing the serialized engine file path.
+     */
+    virtual const char* getModelName() const = 0;
+};
+
+
+/**
+ * Holds all the file paths required to build a network.
+ */
+struct NetworkInfo
+{
+    std::string networkType;
+    std::string configFilePath;
+    std::string wtsFilePath;
+    std::string deviceType;
+    std::string inputBlobName;
+    uint maxbatchSize;
+};
+
+/**
+ * Holds information about an output tensor of the yolo network.
+ */
+struct TensorInfo
+{
+    std::string blobName;
+    uint stride{0};
+    uint gridSize{0};
+    uint numClasses{0};
+    uint numBBoxes{0};
+    uint64_t volume{0};
+    std::vector<uint> masks;
+    std::vector<float> anchors;
+    int bindingIndex{-1};
+    float* hostBuffer{nullptr};
+};
+
+class Yolo : public IModelParser {
+public:
+    Yolo(const NetworkInfo& networkInfo);
+    ~Yolo() override;
+    bool hasFullDimsSupported() const override { return false; }
+    const char* getModelName() const override {
+        return m_ConfigFilePath.empty() ? m_NetworkType.c_str()
+                                        : m_ConfigFilePath.c_str();
+    }
+    NvDsInferStatus parseModel(nvinfer1::INetworkDefinition& network) override;
+
+    nvinfer1::ICudaEngine *createEngine (nvinfer1::IBuilder* builder);
+
+protected:
+    const std::string m_NetworkType;
+    const std::string m_ConfigFilePath;
+    const std::string m_WtsFilePath;
+    const std::string m_DeviceType;
+    const std::string m_InputBlobName;
+    const std::string m_OutputBlobName;
+    std::vector<TensorInfo> m_OutputTensors;
+    std::vector<std::map<std::string, std::string>> m_ConfigBlocks;
+    uint m_InputH;
+    uint m_InputW;
+    uint m_InputC;
+    uint64_t m_InputSize;
+
+    uint m_MaxBatchSize;
+
+    // TRT specific members
+    std::vector<nvinfer1::Weights> m_TrtWeights;
+    std::vector<nvinfer1::ITensor*> m_YoloTensor;
+
+    std::vector<YoloKernel> m_YoloKernel;
+
+
+private:
+    NvDsInferStatus buildYoloNetwork(
+        std::vector<float>& weights, nvinfer1::INetworkDefinition& network);
+    std::vector<std::map<std::string, std::string>> parseConfigFile(
+        const std::string cfgFilePath);
+    void parseConfigBlocks();
+    void destroyNetworkUtils();
+};
+
+#endif // _YOLO_H_

+ 56 - 0
src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/include/yolodetect.h

@@ -0,0 +1,56 @@
+#ifndef YOLODETECT_H
+#define YOLODETECT_H
+
+#include "opencv2/opencv.hpp"
+#include "NvInfer.h"
+#include "NvInferRuntime.h"
+#include "cuda_runtime_api.h"
+
+#include "logging.h"
+#include "yolo.h"
+#include "trt_utils.h"
+#include "yololayer.h"
+#include "mish.h"
+
+using namespace nvinfer1;
+REGISTER_TENSORRT_PLUGIN(MishPluginCreator);
+REGISTER_TENSORRT_PLUGIN(YoloPluginCreator);
+
+
+class YoloDetect
+{
+public:
+    YoloDetect(NetworkInfo &networkInfo, std::string &modelname):
+        m_networkInfo(networkInfo),m_modelname(modelname)
+    {
+
+    }
+    bool loadModel(IExecutionContext*& context);
+    void doInference(IExecutionContext& context,float* input, float* output, int batch_size);
+    bool process(IExecutionContext& context, cv::Mat &image, std::vector<Detection> &detect_result,float ignore_thresh=0.4,float nms_thresh = 0.4);
+    bool process(IExecutionContext& context, uint max_batch_size,
+                 std::vector<cv::Mat> &image_vec,
+                 std::vector<std::vector<Detection>> &detect_results,
+                 float ignore_thresh=0.4,float nms_thresh = 0.4);
+    cv::Rect get_rect(cv::Mat& img, float bbox[4],int input_w,int input_h);
+private:
+    bool saveEngine();
+    ICudaEngine* loadEngine(IRuntime& runtime);
+    cv::Mat preprocess_img(cv::Mat& img,int input_w,int input_h);
+    float iou(float lbox[4], float rbox[4]);
+    static bool cmp(Detection& a, Detection& b);
+    void nms(std::vector<Detection>& res, float *output, float ignore_thresh=0.4,float nms_thresh = 0.4);
+
+public:
+    int m_input_h;
+    int m_input_w;
+    int m_output_size;
+
+private:
+    NetworkInfo m_networkInfo;
+    std::string m_modelname;
+    Logger gLogger;
+
+};
+
+#endif // YOLODETECT_H

+ 126 - 0
src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/include/yololayer.h

@@ -0,0 +1,126 @@
+#ifndef _YOLO_LAYER_H
+#define _YOLO_LAYER_H
+
+#include <assert.h>
+#include <cmath>
+#include <string.h>
+#include <cublas_v2.h>
+#include "NvInfer.h"
+#include "Utils.h"
+#include <iostream>
+#include "NvInferPlugin.h"
+
+struct YoloKernel
+{
+    int width;
+    int height;
+    int everyYoloAnchors;
+    float anchors[10];   // 一组yolo输出层中 anchors的数据个数 等于 3*2, 可以设置的更大一点,这个无所谓
+};
+
+struct alignas(float) Detection{
+    //x y w h
+    float bbox[4];
+    float det_confidence;
+    float class_id;
+    float class_confidence;
+};
+
+namespace nvinfer1
+{
+    class YoloLayerPlugin: public IPluginV2IOExt
+    {
+        public:
+            YoloLayerPlugin(const PluginFieldCollection& fc);
+            YoloLayerPlugin(const void* data, size_t length);
+
+            ~YoloLayerPlugin();
+
+            int getNbOutputs() const override
+            {
+                return 1;
+            }
+
+            Dims getOutputDimensions(int index, const Dims* inputs, int nbInputDims) override;
+
+            int initialize() override;
+
+            virtual void terminate() override {};
+
+            virtual size_t getWorkspaceSize(int maxBatchSize) const override { return 0;}
+
+            virtual int enqueue(int batchSize, const void*const * inputs, void** outputs, void* workspace, cudaStream_t stream) override;
+
+            virtual size_t getSerializationSize() const override;
+
+            virtual void serialize(void* buffer) const override;
+
+            bool supportsFormatCombination(int pos, const PluginTensorDesc* inOut, int nbInputs, int nbOutputs) const override {
+                return inOut[pos].format == TensorFormat::kLINEAR && inOut[pos].type == DataType::kFLOAT;
+            }
+
+            const char* getPluginType() const override;
+
+            const char* getPluginVersion() const override;
+
+            void destroy() override;
+
+            IPluginV2IOExt* clone() const override;
+
+            void setPluginNamespace(const char* pluginNamespace) override;
+
+            const char* getPluginNamespace() const override;
+
+            DataType getOutputDataType(int index, const nvinfer1::DataType* inputTypes, int nbInputs) const override;
+
+            bool isOutputBroadcastAcrossBatch(int outputIndex, const bool* inputIsBroadcasted, int nbInputs) const override;
+
+            bool canBroadcastInputAcrossBatch(int inputIndex) const override;
+
+            void attachToContext(
+                    cudnnContext* cudnnContext, cublasContext* cublasContext, IGpuAllocator* gpuAllocator) override;
+
+            void configurePlugin(const PluginTensorDesc* in, int nbInput, const PluginTensorDesc* out, int nbOutput) override;
+
+            void detachFromContext() override;
+
+        private:
+            void forwardGpu(const float *const * inputs,float * output, cudaStream_t stream,int batchSize = 1);
+            int mClassCount;        // 检测的目标的类别,从cfg文件获取,在cfg 设置
+            int mInput_w;           // 图像输入的尺寸,从cfg获取
+            int mInput_h;           // 由于umsample层的原因,宽度和高度要想等,TODO 调整
+            int mNumYoloLayers;     // yolo输出层的数量,从cfg获取,无需设置
+            std::vector<YoloKernel> mYoloKernel;
+
+            float mIgnore_thresh = 0.4;     // 置信度阈值,可以调整
+            int max_output_box = 1000;      // 最大输出数量
+            int mThreadCount = 256;         // cuda 内核函数,每一block中线程数量
+            const char* mPluginNamespace;   // 该插件名称
+
+    };
+    // 继承与IPluginCreator,重写虚函数
+    class YoloPluginCreator : public IPluginCreator
+    {
+        public:
+            YoloPluginCreator();
+
+            ~YoloPluginCreator() override = default;
+            const char* getPluginName() const override;
+            const char* getPluginVersion() const override;
+            const PluginFieldCollection* getFieldNames() override;
+            // 生成插件,这个是在 build network时调用
+            IPluginV2IOExt* createPlugin(const char* name, const PluginFieldCollection* fc) override;
+            // 反序列化,在读取保存的trt模型engine时调用,负责解析插件
+            IPluginV2IOExt* deserializePlugin(const char* name, const void* serialData, size_t serialLength) override;
+            void setPluginNamespace(const char* libNamespace) override{
+                mNamespace = libNamespace;
+            }
+            const char* getPluginNamespace() const override{
+                return mNamespace.c_str();
+            }
+        private:
+            std::string mNamespace;
+    };
+};
+
+#endif 

+ 270 - 0
src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/src/main.cpp

@@ -0,0 +1,270 @@
+#include <fstream>
+#include <iostream>
+#include <map>
+#include <sstream>
+#include <vector>
+#include <chrono>
+#include <string>
+#include "NvInfer.h"
+#include "NvInferRuntime.h"
+#include "cuda_runtime_api.h"
+
+#include <cmath>
+
+#include "logging.h"
+#include "yolo.h"
+#include "trt_utils.h"
+#include "yololayer.h"
+#include "mish.h"
+
+#include "opencv2/opencv.hpp"
+
+using namespace nvinfer1;
+
+Logger gLogger;
+REGISTER_TENSORRT_PLUGIN(MishPluginCreator);
+REGISTER_TENSORRT_PLUGIN(YoloPluginCreator);
+
+cv::Mat preprocess_img(cv::Mat& img,int input_w,int input_h) {
+    int w, h, x, y;
+    float r_w = input_w / (img.cols*1.0);
+    float r_h = input_h / (img.rows*1.0);
+    if (r_h > r_w) {
+        w = input_w;
+        h = r_w * img.rows;
+        x = 0;
+        y = (input_h - h) / 2;
+    } else {
+        w = r_h* img.cols;
+        h = input_h;
+        x = (input_w - w) / 2;
+        y = 0;
+    }
+    cv::Mat re(h, w, CV_8UC3);
+    cv::resize(img, re, re.size(), 0, 0, cv::INTER_CUBIC);
+    cv::Mat out(input_h, input_w, CV_8UC3, cv::Scalar(128, 128, 128));
+    re.copyTo(out(cv::Rect(x, y, re.cols, re.rows)));
+    return out;
+}
+
+cv::Rect get_rect(cv::Mat& img, float bbox[4],int input_w,int input_h) {
+    int l, r, t, b;
+    float r_w = input_w / (img.cols * 1.0);
+    float r_h = input_h / (img.rows * 1.0);
+    if (r_h > r_w) {
+        l = bbox[0] - bbox[2]/2.f;
+        r = bbox[0] + bbox[2]/2.f;
+        t = bbox[1] - bbox[3]/2.f - (input_h - r_w * img.rows) / 2;
+        b = bbox[1] + bbox[3]/2.f - (input_h - r_w * img.rows) / 2;
+        l = l / r_w;
+        r = r / r_w;
+        t = t / r_w;
+        b = b / r_w;
+    } else {
+        l = bbox[0] - bbox[2]/2.f - (input_w - r_h * img.cols) / 2;
+        r = bbox[0] + bbox[2]/2.f - (input_w - r_h * img.cols) / 2;
+        t = bbox[1] - bbox[3]/2.f;
+        b = bbox[1] + bbox[3]/2.f;
+        l = l / r_h;
+        r = r / r_h;
+        t = t / r_h;
+        b = b / r_h;
+    }
+    return cv::Rect(l, t, r-l, b-t);
+}
+
+float iou(float lbox[4], float rbox[4]) {
+    float interBox[] = {
+        std::max(lbox[0] - lbox[2]/2.f , rbox[0] - rbox[2]/2.f), //left
+        std::min(lbox[0] + lbox[2]/2.f , rbox[0] + rbox[2]/2.f), //right
+        std::max(lbox[1] - lbox[3]/2.f , rbox[1] - rbox[3]/2.f), //top
+        std::min(lbox[1] + lbox[3]/2.f , rbox[1] + rbox[3]/2.f), //bottom
+    };
+
+    if(interBox[2] > interBox[3] || interBox[0] > interBox[1])
+        return 0.0f;
+
+    float interBoxS =(interBox[1]-interBox[0])*(interBox[3]-interBox[2]);
+    return interBoxS/(lbox[2]*lbox[3] + rbox[2]*rbox[3] -interBoxS);
+}
+
+bool cmp(Detection& a, Detection& b) {
+    return a.det_confidence > b.det_confidence;
+}
+
+void nms(std::vector<Detection>& res, float *output, float ignore_thresh=0.4,float nms_thresh = 0.4) {
+    std::map<float, std::vector<Detection>> m;
+//    std::cout << "output[0] "<< output[0]<<std::endl;
+    for (int i = 0; i < output[0] && i < 1000; i++) {
+        if (output[1 + 7 * i + 4] <= ignore_thresh) continue;
+        Detection det;
+        memcpy(&det, &output[1 + 7 * i], 7 * sizeof(float));
+        if (m.count(det.class_id) == 0) m.emplace(det.class_id, std::vector<Detection>());
+        m[det.class_id].push_back(det);
+    }
+    for (auto it = m.begin(); it != m.end(); it++) {
+        auto& dets = it->second;
+        std::sort(dets.begin(), dets.end(), cmp);
+        for (size_t m = 0; m < dets.size(); ++m) {
+            auto& item = dets[m];
+            res.push_back(item);
+            for (size_t n = m + 1; n < dets.size(); ++n) {
+                if (iou(item.bbox, dets[n].bbox) > nms_thresh) {
+                    dets.erase(dets.begin()+n);
+                    --n;
+                }
+            }
+        }
+    }
+}
+
+int main(int argc,char* argv[])
+{
+    cudaSetDevice(0);
+    char *trtModelStream{nullptr};
+    size_t size{0};
+
+    NetworkInfo networkInfo;
+
+    networkInfo.networkType     = "yolov4-turnstile";
+    networkInfo.configFilePath  = "../data/yolov4-turnstile.cfg";
+    networkInfo.wtsFilePath     = "../data/yolov4-turnstile.weights";
+    networkInfo.deviceType      = "kGPU";
+    networkInfo.inputBlobName   = "data";
+
+    std::string modelname = networkInfo.networkType + ".engine";
+
+    IBuilder* builder = createInferBuilder(gLogger);
+    if (argc == 2 && std::string(argv[1]) == "-s") {
+        IHostMemory* modelStream{nullptr};
+        Yolo yolo(networkInfo);
+        ICudaEngine *cudaEngine = yolo.createEngine (builder);
+        modelStream = cudaEngine->serialize();
+        assert(modelStream != nullptr);
+        std::ofstream p(modelname, std::ios::binary);
+        if (!p) {
+            std::cerr << "could not open plan output file" << std::endl;
+            return -1;
+        }
+        p.write(reinterpret_cast<const char*>(modelStream->data()), modelStream->size());
+        modelStream->destroy();
+        return 0;
+    } else if (argc == 2 && std::string(argv[1]) == "-d") {
+        std::ifstream file(modelname, std::ios::binary);
+        if (file.good()) {
+            file.seekg(0, file.end);
+            size = file.tellg();
+            file.seekg(0, file.beg);
+            trtModelStream = new char[size];
+            assert(trtModelStream);
+            file.read(trtModelStream, size);
+            file.close();
+        }
+    }else {
+        std::cerr << "arguments not right!" << std::endl;
+        std::cerr << "./yolov3 -s  // serialize model to plan file" << std::endl;
+        std::cerr << "./yolov3 -d  // deserialize plan file and run inference" << std::endl;
+        return -1;
+    }
+
+    IRuntime* runtime = createInferRuntime(gLogger);
+    assert(runtime != nullptr);
+    ICudaEngine* engine = runtime->deserializeCudaEngine(trtModelStream, size);
+    assert(engine != nullptr);
+    IExecutionContext* context = engine->createExecutionContext();
+    assert(context != nullptr);
+    delete[] trtModelStream;
+
+    int numbindings=engine->getNbBindings();
+    std::cout<< "getNbBindings: " << numbindings<<std::endl;
+
+    const char* layername = engine->getBindingName(1);
+    std::cout<< "getBindingName:1 " << layername<<std::endl;
+    Dims out = engine->getBindingDimensions(1);
+    std::cout<< "out dims: " << out.d[0]<<" "<<out.d[1]<<" "<<out.d[2]<<" "<<out.d[3]<<std::endl;
+
+    Dims in = engine->getBindingDimensions(0);
+    std::cout<< "out dims: " << in.d[0]<<" "<<in.d[1]<<" "<<in.d[2]<<" "<<in.d[3]<<std::endl;
+
+    int input_h =  in.d[1];
+    int input_w =  in.d[2];
+    int OUTPUT_SIZE = out.d[0];
+
+    void* buffers[2];
+    int batchSize = 1;
+
+    cudaMalloc(&buffers[0], batchSize * 3 * input_h * input_w * sizeof(float));
+    cudaMalloc(&buffers[1], batchSize * OUTPUT_SIZE * sizeof(float));
+
+    // Create stream
+    cudaStream_t stream;
+    cudaStreamCreate(&stream);
+
+    // DMA input batch data to device, infer on the batch asynchronously, and DMA output back to host
+    cv::VideoCapture cap("../20201231144029.avi");
+    cv::Mat img;
+    cv::Mat pr_img;
+
+    bool detect = false;
+
+    float data[3 * input_h * input_w];
+    float prob[OUTPUT_SIZE];
+
+    std::cout<<"start detect"<<std::endl;
+
+    while (true){
+        if(!detect){detect=true; continue;}
+        cap>>img;
+        cv::Mat pr_img = preprocess_img(img,input_w,input_h);
+        for (int i = 0; i < input_h * input_w; i++) {
+            data[i] = pr_img.at<cv::Vec3b>(i)[2] / 255.0;
+            data[i + input_h * input_w] = pr_img.at<cv::Vec3b>(i)[1] / 255.0;
+            data[i + 2 * input_h * input_w] = pr_img.at<cv::Vec3b>(i)[0] / 255.0;
+        }
+
+//        // Run inference
+        auto start = std::chrono::system_clock::now();
+
+        cudaMemcpyAsync(buffers[0], data, batchSize * 3 * input_w * input_h * sizeof(float), cudaMemcpyHostToDevice, stream);
+        context->enqueue(batchSize, buffers, stream, nullptr);
+        cudaMemcpyAsync(prob, buffers[1], batchSize * OUTPUT_SIZE * sizeof(float), cudaMemcpyDeviceToHost, stream);
+        cudaStreamSynchronize(stream);
+
+        auto end = std::chrono::system_clock::now();
+        std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;
+
+        std::vector<Detection> res;
+        nms(res, prob);
+
+        for (size_t j = 0; j < res.size(); j++) {
+            float *p = (float*)&res[j];
+            cv::Rect r = get_rect(img, res[j].bbox,input_w,input_h);
+            cv::rectangle(img, r, cv::Scalar(0x27, 0xC1, 0x36), 2);
+            //std::string text = std::to_string((int)res[j].class_id) + " "+
+                    //std::to_string((float)res[j].det_confidence)+" "+
+                    //std::to_string((float)res[j].class_confidence);
+
+            std::string text = std::to_string((int)res[j].class_id);
+            cv::putText(img, text, cv::Point(r.x, r.y - 1), cv::FONT_HERSHEY_PLAIN, 1.2, cv::Scalar(0xFF, 0xFF, 0xFF), 2);
+        }
+        cv::imshow("_", img);
+        if(cv::waitKey(1)==27){break;}
+    }
+
+    // Release stream and buffers
+    cudaStreamDestroy(stream);
+    cudaFree(buffers[0]);
+    cudaFree(buffers[1]);
+
+    // Destroy the engine
+    context->destroy();
+    engine->destroy();
+    runtime->destroy();
+}
+
+
+
+
+
+
+

+ 196 - 0
src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/src/mish.cu

@@ -0,0 +1,196 @@
+#include <cmath>
+#include <stdio.h>
+#include <cassert>
+#include <iostream>
+#include "mish.h"
+
+namespace nvinfer1
+{
+    MishPlugin::MishPlugin()
+    {
+    }
+
+    MishPlugin::~MishPlugin()
+    {
+    }
+
+    // create the plugin at runtime from a byte stream
+    MishPlugin::MishPlugin(const void* data, size_t length)
+    {
+        assert(length == sizeof(input_size_));
+        input_size_ = *reinterpret_cast<const int*>(data);
+    }
+
+    void MishPlugin::serialize(void* buffer) const
+    {
+        *reinterpret_cast<int*>(buffer) = input_size_;
+    }
+
+    size_t MishPlugin::getSerializationSize() const
+    {  
+        return sizeof(input_size_);
+    }
+
+    int MishPlugin::initialize()
+    { 
+        return 0;
+    }
+
+    Dims MishPlugin::getOutputDimensions(int index, const Dims* inputs, int nbInputDims)
+    {
+        assert(nbInputDims == 1);
+        assert(index == 0);
+        input_size_ = inputs[0].d[0] * inputs[0].d[1] * inputs[0].d[2];
+        // Output dimensions
+        return Dims3(inputs[0].d[0], inputs[0].d[1], inputs[0].d[2]);
+    }
+
+    // Set plugin namespace
+    void MishPlugin::setPluginNamespace(const char* pluginNamespace)
+    {
+        mPluginNamespace = pluginNamespace;
+    }
+
+    const char* MishPlugin::getPluginNamespace() const
+    {
+        return mPluginNamespace;
+    }
+
+    // Return the DataType of the plugin output at the requested index
+    DataType MishPlugin::getOutputDataType(int index, const nvinfer1::DataType* inputTypes, int nbInputs) const
+    {
+        return DataType::kFLOAT;
+    }
+
+    // Return true if output tensor is broadcast across a batch.
+    bool MishPlugin::isOutputBroadcastAcrossBatch(int outputIndex, const bool* inputIsBroadcasted, int nbInputs) const
+    {
+        return false;
+    }
+
+    // Return true if plugin can use input that is broadcast across batch without replication.
+    bool MishPlugin::canBroadcastInputAcrossBatch(int inputIndex) const
+    {
+        return false;
+    }
+
+    void MishPlugin::configurePlugin(const PluginTensorDesc* in, int nbInput, const PluginTensorDesc* out, int nbOutput)
+    {
+    }
+
+    // Attach the plugin object to an execution context and grant the plugin the access to some context resource.
+    void MishPlugin::attachToContext(cudnnContext* cudnnContext, cublasContext* cublasContext, IGpuAllocator* gpuAllocator)
+    {
+    }
+
+    // Detach the plugin object from its execution context.
+    void MishPlugin::detachFromContext() {}
+
+    const char* MishPlugin::getPluginType() const
+    {
+        return "Mish_TRT";
+    }
+
+    const char* MishPlugin::getPluginVersion() const
+    {
+        return "1";
+    }
+
+    void MishPlugin::destroy()
+    {
+        delete this;
+    }
+
+    // Clone the plugin
+    IPluginV2IOExt* MishPlugin::clone() const
+    {
+        MishPlugin *p = new MishPlugin();
+        p->input_size_ = input_size_;
+        p->setPluginNamespace(mPluginNamespace);
+        return p;
+    }
+
+    __device__ float tanh_activate_kernel(float x){return (2/(1 + expf(-2*x)) - 1);}
+
+    __device__ float softplus_kernel(float x, float threshold = 20) {
+        if (x > threshold) return x;                // too large
+        else if (x < -threshold) return expf(x);    // too small
+        return logf(expf(x) + 1);
+    }
+
+    __global__ void mish_kernel(const float *input, float *output, int num_elem) {
+
+        int idx = threadIdx.x + blockDim.x * blockIdx.x;
+        if (idx >= num_elem) return;
+
+        //float t = exp(input[idx]);
+        //if (input[idx] > 20.0) {
+        //    t *= t;
+        //    output[idx] = (t - 1.0) / (t + 1.0);
+        //} else {
+        //    float tt = t * t;
+        //    output[idx] = (tt + 2.0 * t) / (tt + 2.0 * t + 2.0);
+        //}
+        //output[idx] *= input[idx];
+        output[idx] = input[idx] * tanh_activate_kernel(softplus_kernel(input[idx]));
+    }
+
+    void MishPlugin::forwardGpu(const float *const * inputs, float* output, cudaStream_t stream, int batchSize) {
+        int block_size = thread_count_;
+        int grid_size = (input_size_ * batchSize + block_size - 1) / block_size;
+        mish_kernel<<<grid_size, block_size>>>(inputs[0], output, input_size_ * batchSize);
+    }
+
+    int MishPlugin::enqueue(int batchSize, const void*const * inputs, void** outputs, void* workspace, cudaStream_t stream)
+    {
+        //assert(batchSize == 1);
+        //GPU
+        //CUDA_CHECK(cudaStreamSynchronize(stream));
+        forwardGpu((const float *const *)inputs, (float*)outputs[0], stream, batchSize);
+        return 0;
+    }
+
+    PluginFieldCollection MishPluginCreator::mFC{};
+    std::vector<PluginField> MishPluginCreator::mPluginAttributes;
+
+    MishPluginCreator::MishPluginCreator()
+    {
+        mPluginAttributes.clear();
+
+        mFC.nbFields = mPluginAttributes.size();
+        mFC.fields = mPluginAttributes.data();
+    }
+
+    const char* MishPluginCreator::getPluginName() const
+    {
+            return "Mish_TRT";
+    }
+
+    const char* MishPluginCreator::getPluginVersion() const
+    {
+            return "1";
+    }
+
+    const PluginFieldCollection* MishPluginCreator::getFieldNames()
+    {
+            return &mFC;
+    }
+
+    IPluginV2IOExt* MishPluginCreator::createPlugin(const char* name, const PluginFieldCollection* fc)
+    {
+        MishPlugin* obj = new MishPlugin();
+        obj->setPluginNamespace(mNamespace.c_str());
+        return obj;
+    }
+
+    IPluginV2IOExt* MishPluginCreator::deserializePlugin(const char* name, const void* serialData, size_t serialLength)
+    {
+        // This object will be deleted when the network is destroyed, which will
+        // call MishPlugin::destroy()
+        MishPlugin* obj = new MishPlugin(serialData, serialLength);
+        obj->setPluginNamespace(mNamespace.c_str());
+        return obj;
+    }
+
+}
+

+ 473 - 0
src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/src/trt_utils.cpp

@@ -0,0 +1,473 @@
+/*
+ * Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "trt_utils.h"
+#include <experimental/filesystem>
+#include <fstream>
+#include <iomanip>
+#include <functional>
+#include <algorithm>
+#include <math.h>
+#include "NvInferPlugin.h"
+
+static void leftTrim(std::string& s)
+{
+    s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int ch) { return !isspace(ch); }));
+}
+
+static void rightTrim(std::string& s)
+{
+    s.erase(std::find_if(s.rbegin(), s.rend(), [](int ch) { return !isspace(ch); }).base(), s.end());
+}
+
+std::string trim(std::string s)
+{
+    leftTrim(s);
+    rightTrim(s);
+    return s;
+}
+
+float clamp(const float val, const float minVal, const float maxVal)
+{
+    assert(minVal <= maxVal);
+    return std::min(maxVal, std::max(minVal, val));
+}
+
+bool fileExists(const std::string fileName, bool verbose)
+{
+    if (!std::experimental::filesystem::exists(std::experimental::filesystem::path(fileName)))
+    {
+        if (verbose) std::cout << "File does not exist : " << fileName << std::endl;
+        return false;
+    }
+    return true;
+}
+
+std::vector<float> loadWeights(const std::string weightsFilePath, const std::string& networkType)
+{
+    assert(fileExists(weightsFilePath));
+    std::cout << "Loading pre-trained weights..." << std::endl;
+    std::ifstream file(weightsFilePath, std::ios_base::binary);
+    assert(file.good());
+    std::string line;
+
+    if (networkType == "yolov2")
+    {
+        // Remove 4 int32 bytes of data from the stream belonging to the header
+        file.ignore(4 * 4);
+    }
+    else if ((networkType == "yolov3") || (networkType == "yolov3-tiny")
+             || (networkType == "yolov4") || (networkType == "yolov4-tiny") || (networkType == "yolov4-turnstile"))
+    {
+        // Remove 5 int32 bytes of data from the stream belonging to the header
+        file.ignore(4 * 5);
+    }
+    else
+    {
+        std::cout << "Invalid network type" << std::endl;
+        assert(0);
+    }
+
+    std::vector<float> weights;
+    char floatWeight[4];
+    while (!file.eof())
+    {
+        file.read(floatWeight, 4);
+        assert(file.gcount() == 4);
+        weights.push_back(*reinterpret_cast<float*>(floatWeight));
+        if (file.peek() == std::istream::traits_type::eof()) break;
+    }
+    std::cout << "Loading weights of " << networkType << " complete!"
+              << std::endl;
+    std::cout << "Total Number of weights read : " << weights.size() << std::endl;
+    return weights;
+}
+
+std::string dimsToString(const nvinfer1::Dims d)
+{
+    std::stringstream s;
+    assert(d.nbDims >= 1);
+    for (int i = 0; i < d.nbDims - 1; ++i)
+    {
+        s << std::setw(4) << d.d[i] << " x";
+    }
+    s << std::setw(4) << d.d[d.nbDims - 1];
+
+    return s.str();
+}
+
+void displayDimType(const nvinfer1::Dims d)
+{
+    std::cout << "(" << d.nbDims << ") ";
+    for (int i = 0; i < d.nbDims; ++i)
+    {
+        switch (d.type[i])
+        {
+        case nvinfer1::DimensionType::kSPATIAL: std::cout << "kSPATIAL "; break;
+        case nvinfer1::DimensionType::kCHANNEL: std::cout << "kCHANNEL "; break;
+        case nvinfer1::DimensionType::kINDEX: std::cout << "kINDEX "; break;
+        case nvinfer1::DimensionType::kSEQUENCE: std::cout << "kSEQUENCE "; break;
+        }
+    }
+    std::cout << std::endl;
+}
+
+int getNumChannels(nvinfer1::ITensor* t)
+{
+    nvinfer1::Dims d = t->getDimensions();
+    assert(d.nbDims == 3);
+
+    return d.d[0];
+}
+
+uint64_t get3DTensorVolume(nvinfer1::Dims inputDims)
+{
+    assert(inputDims.nbDims == 3);
+    return inputDims.d[0] * inputDims.d[1] * inputDims.d[2];
+}
+
+nvinfer1::ILayer* netAddMaxpool(int layerIdx, std::map<std::string, std::string>& block,
+                                nvinfer1::ITensor* input, nvinfer1::INetworkDefinition* network)
+{
+    assert(block.at("type") == "maxpool");
+    assert(block.find("size") != block.end());
+    assert(block.find("stride") != block.end());
+
+    int size = std::stoi(block.at("size"));
+    int stride = std::stoi(block.at("stride"));
+
+    nvinfer1::IPoolingLayer* pool
+        = network->addPooling(*input, nvinfer1::PoolingType::kMAX, nvinfer1::DimsHW{size, size});
+    assert(pool);
+    std::string maxpoolLayerName = "maxpool_" + std::to_string(layerIdx);
+    pool->setStride(nvinfer1::DimsHW{stride, stride});
+    pool->setPaddingMode(nvinfer1::PaddingMode::kSAME_UPPER);
+    pool->setName(maxpoolLayerName.c_str());
+
+    return pool;
+}
+
+nvinfer1::ILayer* netAddConvLinear(int layerIdx, std::map<std::string, std::string>& block,
+                                   std::vector<float>& weights,
+                                   std::vector<nvinfer1::Weights>& trtWeights, int& weightPtr,
+                                   int& inputChannels, nvinfer1::ITensor* input,
+                                   nvinfer1::INetworkDefinition* network)
+{
+    assert(block.at("type") == "convolutional");
+    assert(block.find("batch_normalize") == block.end());
+    assert(block.at("activation") == "linear");
+    assert(block.find("filters") != block.end());
+    assert(block.find("pad") != block.end());
+    assert(block.find("size") != block.end());
+    assert(block.find("stride") != block.end());
+
+    int filters = std::stoi(block.at("filters"));
+    int padding = std::stoi(block.at("pad"));
+    int kernelSize = std::stoi(block.at("size"));
+    int stride = std::stoi(block.at("stride"));
+    int pad;
+    if (padding)
+        pad = (kernelSize - 1) / 2;
+    else
+        pad = 0;
+    // load the convolution layer bias
+    nvinfer1::Weights convBias{nvinfer1::DataType::kFLOAT, nullptr, filters};
+    float* val = new float[filters];
+    for (int i = 0; i < filters; ++i)
+    {
+        val[i] = weights[weightPtr];
+        weightPtr++;
+    }
+    convBias.values = val;
+    trtWeights.push_back(convBias);
+    // load the convolutional layer weights
+    int size = filters * inputChannels * kernelSize * kernelSize;
+    nvinfer1::Weights convWt{nvinfer1::DataType::kFLOAT, nullptr, size};
+    val = new float[size];
+    for (int i = 0; i < size; ++i)
+    {
+        val[i] = weights[weightPtr];
+        weightPtr++;
+    }
+    convWt.values = val;
+    trtWeights.push_back(convWt);
+    nvinfer1::IConvolutionLayer* conv = network->addConvolution(
+        *input, filters, nvinfer1::DimsHW{kernelSize, kernelSize}, convWt, convBias);
+    assert(conv != nullptr);
+    std::string convLayerName = "conv_" + std::to_string(layerIdx);
+    conv->setName(convLayerName.c_str());
+    conv->setStride(nvinfer1::DimsHW{stride, stride});
+    conv->setPadding(nvinfer1::DimsHW{pad, pad});
+
+    return conv;
+}
+
+nvinfer1::ILayer* netAddConvBNActive(int layerIdx, std::map<std::string, std::string>& block,
+                                    std::vector<float>& weights,
+                                    std::vector<nvinfer1::Weights>& trtWeights, int& weightPtr,
+                                    int& inputChannels, nvinfer1::ITensor* input,
+                                    nvinfer1::INetworkDefinition* network)
+{
+    assert(block.at("type") == "convolutional");
+    assert(block.find("batch_normalize") != block.end());
+    assert(block.at("batch_normalize") == "1");
+//    assert(block.at("activation") == "leaky");
+    assert(block.find("filters") != block.end());
+    assert(block.find("pad") != block.end());
+    assert(block.find("size") != block.end());
+    assert(block.find("stride") != block.end());
+
+    bool batchNormalize, bias;
+    if (block.find("batch_normalize") != block.end())
+    {
+        batchNormalize = (block.at("batch_normalize") == "1");
+        bias = false;
+    }
+    else
+    {
+        batchNormalize = false;
+        bias = true;
+    }
+    // all conv_bn_leaky layers assume bias is false
+    assert(batchNormalize == true && bias == false);
+    UNUSED(batchNormalize);
+    UNUSED(bias);
+
+    int filters = std::stoi(block.at("filters"));
+    int padding = std::stoi(block.at("pad"));
+    int kernelSize = std::stoi(block.at("size"));
+    int stride = std::stoi(block.at("stride"));
+    int pad;
+    if (padding)
+        pad = (kernelSize - 1) / 2;
+    else
+        pad = 0;
+
+    /***** CONVOLUTION LAYER *****/
+    /*****************************/
+    // batch norm weights are before the conv layer
+    // load BN biases (bn_biases)
+    std::vector<float> bnBiases;
+    for (int i = 0; i < filters; ++i)
+    {
+        bnBiases.push_back(weights[weightPtr]);
+        weightPtr++;
+    }
+    // load BN weights
+    std::vector<float> bnWeights;
+    for (int i = 0; i < filters; ++i)
+    {
+        bnWeights.push_back(weights[weightPtr]);
+        weightPtr++;
+    }
+    // load BN running_mean
+    std::vector<float> bnRunningMean;
+    for (int i = 0; i < filters; ++i)
+    {
+        bnRunningMean.push_back(weights[weightPtr]);
+        weightPtr++;
+    }
+    // load BN running_var
+    std::vector<float> bnRunningVar;
+    for (int i = 0; i < filters; ++i)
+    {
+        // 1e-05 for numerical stability
+        bnRunningVar.push_back(sqrt(weights[weightPtr] + 1.0e-5));
+        weightPtr++;
+    }
+    // load Conv layer weights (GKCRS)
+    int size = filters * inputChannels * kernelSize * kernelSize;
+    nvinfer1::Weights convWt{nvinfer1::DataType::kFLOAT, nullptr, size};
+    float* val = new float[size];
+    for (int i = 0; i < size; ++i)
+    {
+        val[i] = weights[weightPtr];
+        weightPtr++;
+    }
+    convWt.values = val;
+    trtWeights.push_back(convWt);
+    nvinfer1::Weights convBias{nvinfer1::DataType::kFLOAT, nullptr, 0};
+    trtWeights.push_back(convBias);
+    nvinfer1::IConvolutionLayer* conv = network->addConvolution(
+        *input, filters, nvinfer1::DimsHW{kernelSize, kernelSize}, convWt, convBias);
+    assert(conv != nullptr);
+    std::string convLayerName = "conv_" + std::to_string(layerIdx);
+    conv->setName(convLayerName.c_str());
+    conv->setStride(nvinfer1::DimsHW{stride, stride});
+    conv->setPadding(nvinfer1::DimsHW{pad, pad});
+
+    /***** BATCHNORM LAYER *****/
+    /***************************/
+    size = filters;
+    // create the weights
+    nvinfer1::Weights shift{nvinfer1::DataType::kFLOAT, nullptr, size};
+    nvinfer1::Weights scale{nvinfer1::DataType::kFLOAT, nullptr, size};
+    nvinfer1::Weights power{nvinfer1::DataType::kFLOAT, nullptr, size};
+    float* shiftWt = new float[size];
+    for (int i = 0; i < size; ++i)
+    {
+        shiftWt[i]
+            = bnBiases.at(i) - ((bnRunningMean.at(i) * bnWeights.at(i)) / bnRunningVar.at(i));
+    }
+    shift.values = shiftWt;
+    float* scaleWt = new float[size];
+    for (int i = 0; i < size; ++i)
+    {
+        scaleWt[i] = bnWeights.at(i) / bnRunningVar[i];
+    }
+    scale.values = scaleWt;
+    float* powerWt = new float[size];
+    for (int i = 0; i < size; ++i)
+    {
+        powerWt[i] = 1.0;
+    }
+    power.values = powerWt;
+    trtWeights.push_back(shift);
+    trtWeights.push_back(scale);
+    trtWeights.push_back(power);
+    // Add the batch norm layers
+    nvinfer1::IScaleLayer* bn = network->addScale(
+        *conv->getOutput(0), nvinfer1::ScaleMode::kCHANNEL, shift, scale, power);
+    assert(bn != nullptr);
+    std::string bnLayerName = "batch_norm_" + std::to_string(layerIdx);
+    bn->setName(bnLayerName.c_str());
+    /***** ACTIVATION LAYER *****/
+    /****************************/
+    if(block.at("activation") == "leaky"){
+        nvinfer1::ITensor* bnOutput = bn->getOutput(0);
+        nvinfer1::IActivationLayer* leaky = network->addActivation(
+                    *bnOutput, nvinfer1::ActivationType::kLEAKY_RELU);
+        leaky->setAlpha(0.1);
+        assert(leaky != nullptr);
+        std::string leakyLayerName = "leaky_" + std::to_string(layerIdx);
+        leaky->setName(leakyLayerName.c_str());
+        return leaky;
+    }else if(block.at("activation") == "mish")
+    {
+        auto creator = getPluginRegistry()->getPluginCreator("Mish_TRT", "1");
+        const nvinfer1::PluginFieldCollection* pluginData = creator->getFieldNames();
+        nvinfer1::IPluginV2 *pluginObj = creator->createPlugin(("mish" + std::to_string(layerIdx)).c_str(), pluginData);
+        nvinfer1::ITensor* inputTensors[] = {bn->getOutput(0)};
+        auto mish = network->addPluginV2(&inputTensors[0], 1, *pluginObj);
+        return mish;
+    }
+
+}
+
+nvinfer1::ILayer* netAddUpsample(int layerIdx, std::map<std::string, std::string>& block,
+                                 std::vector<float>& weights,
+                                 std::vector<nvinfer1::Weights>& trtWeights, int& inputChannels,
+                                 nvinfer1::ITensor* input, nvinfer1::INetworkDefinition* network)
+{
+    assert(block.at("type") == "upsample");
+    nvinfer1::Dims inpDims = input->getDimensions();
+    assert(inpDims.nbDims == 3);
+    assert(inpDims.d[1] == inpDims.d[2]);
+    int h = inpDims.d[1];
+    int w = inpDims.d[2];
+    int stride = std::stoi(block.at("stride"));
+    // add pre multiply matrix as a constant
+    nvinfer1::Dims preDims{3,
+                           {1, stride * h, w},
+                           {nvinfer1::DimensionType::kCHANNEL, nvinfer1::DimensionType::kSPATIAL,
+                            nvinfer1::DimensionType::kSPATIAL}};
+    int size = stride * h * w;
+    nvinfer1::Weights preMul{nvinfer1::DataType::kFLOAT, nullptr, size};
+    float* preWt = new float[size];
+    /* (2*h * w)
+    [ [1, 0, ..., 0],
+      [1, 0, ..., 0],
+      [0, 1, ..., 0],
+      [0, 1, ..., 0],
+      ...,
+      ...,
+      [0, 0, ..., 1],
+      [0, 0, ..., 1] ]
+    */
+    for (int i = 0, idx = 0; i < h; ++i)
+    {
+        for (int s = 0; s < stride; ++s)
+        {
+            for (int j = 0; j < w; ++j, ++idx)
+            {
+                preWt[idx] = (i == j) ? 1.0 : 0.0;
+            }
+        }
+    }
+    preMul.values = preWt;
+    trtWeights.push_back(preMul);
+    nvinfer1::IConstantLayer* preM = network->addConstant(preDims, preMul);
+    assert(preM != nullptr);
+    std::string preLayerName = "preMul_" + std::to_string(layerIdx);
+    preM->setName(preLayerName.c_str());
+    // add post multiply matrix as a constant
+    nvinfer1::Dims postDims{3,
+                            {1, h, stride * w},
+                            {nvinfer1::DimensionType::kCHANNEL, nvinfer1::DimensionType::kSPATIAL,
+                             nvinfer1::DimensionType::kSPATIAL}};
+    size = stride * h * w;
+    nvinfer1::Weights postMul{nvinfer1::DataType::kFLOAT, nullptr, size};
+    float* postWt = new float[size];
+    /* (h * 2*w)
+    [ [1, 1, 0, 0, ..., 0, 0],
+      [0, 0, 1, 1, ..., 0, 0],
+      ...,
+      ...,
+      [0, 0, 0, 0, ..., 1, 1] ]
+    */
+    for (int i = 0, idx = 0; i < h; ++i)
+    {
+        for (int j = 0; j < stride * w; ++j, ++idx)
+        {
+            postWt[idx] = (j / stride == i) ? 1.0 : 0.0;
+        }
+    }
+    postMul.values = postWt;
+    trtWeights.push_back(postMul);
+    nvinfer1::IConstantLayer* post_m = network->addConstant(postDims, postMul);
+    assert(post_m != nullptr);
+    std::string postLayerName = "postMul_" + std::to_string(layerIdx);
+    post_m->setName(postLayerName.c_str());
+    // add matrix multiply layers for upsampling
+    nvinfer1::IMatrixMultiplyLayer* mm1
+        = network->addMatrixMultiply(*preM->getOutput(0), nvinfer1::MatrixOperation::kNONE, *input,
+                                     nvinfer1::MatrixOperation::kNONE);
+    assert(mm1 != nullptr);
+    std::string mm1LayerName = "mm1_" + std::to_string(layerIdx);
+    mm1->setName(mm1LayerName.c_str());
+    nvinfer1::IMatrixMultiplyLayer* mm2
+        = network->addMatrixMultiply(*mm1->getOutput(0), nvinfer1::MatrixOperation::kNONE,
+                                     *post_m->getOutput(0), nvinfer1::MatrixOperation::kNONE);
+    assert(mm2 != nullptr);
+    std::string mm2LayerName = "mm2_" + std::to_string(layerIdx);
+    mm2->setName(mm2LayerName.c_str());
+    return mm2;
+}
+
+void printLayerInfo(std::string layerIndex, std::string layerName, std::string layerInput,
+                    std::string layerOutput, std::string weightPtr)
+{
+    std::cout << std::setw(6) << std::left << layerIndex << std::setw(15) << std::left << layerName;
+    std::cout << std::setw(20) << std::left << layerInput << std::setw(20) << std::left
+              << layerOutput;
+    std::cout << std::setw(6) << std::left << weightPtr << std::endl;
+}

+ 510 - 0
src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/src/yolo.cpp

@@ -0,0 +1,510 @@
+
+#include "yolo.h"
+
+#include <fstream>
+#include <iomanip>
+#include <iterator>
+
+using namespace nvinfer1;
+
+REGISTER_TENSORRT_PLUGIN(MishPluginCreator);
+REGISTER_TENSORRT_PLUGIN(YoloPluginCreator);
+
+Yolo::Yolo(const NetworkInfo& networkInfo)
+    : m_NetworkType(networkInfo.networkType),           // yolov3
+      m_ConfigFilePath(networkInfo.configFilePath),     // yolov3.cfg
+      m_WtsFilePath(networkInfo.wtsFilePath),           // yolov3.weights
+      m_DeviceType(networkInfo.deviceType),             // kDLA, kGPU
+      m_InputBlobName(networkInfo.inputBlobName),       // data
+      m_InputH(0),
+      m_InputW(0),
+      m_InputC(0),
+      m_InputSize(0),
+      m_MaxBatchSize(networkInfo.maxbatchSize)
+{}
+
+Yolo::~Yolo()
+{
+    destroyNetworkUtils();
+}
+
+nvinfer1::ICudaEngine *Yolo::createEngine (nvinfer1::IBuilder* builder)
+{
+    assert (builder);
+
+//    std::vector<float> weights = loadWeights(m_WtsFilePath, m_NetworkType);
+//    std::vector<nvinfer1::Weights> trtWeights;
+
+    nvinfer1::INetworkDefinition *network = builder->createNetwork();
+    if (parseModel(*network) != NVDSINFER_SUCCESS) {
+        network->destroy();
+        return nullptr;
+    }
+
+    // Build the engine
+    std::cout << "Building the TensorRT Engine..." << std::endl;
+
+    ///////////////////////////////////////
+    builder->setMaxBatchSize(m_MaxBatchSize);
+    ///////////////////////////////////////
+
+    builder->setFp16Mode(true);
+
+    nvinfer1::ICudaEngine * engine = builder->buildCudaEngine(*network);
+    if (engine) {
+        std::cout << "Building complete!" << std::endl;
+    } else {
+        std::cerr << "Building engine failed!" << std::endl;
+    }
+
+    // destroy
+    network->destroy();
+    return engine;
+}
+
+NvDsInferStatus Yolo::parseModel(nvinfer1::INetworkDefinition& network) {
+    destroyNetworkUtils();
+
+    m_ConfigBlocks = parseConfigFile(m_ConfigFilePath);
+    parseConfigBlocks();
+
+    std::vector<float> weights = loadWeights(m_WtsFilePath, m_NetworkType);
+    // build yolo network
+    std::cout << "Building Yolo network..." << std::endl;
+    NvDsInferStatus status = buildYoloNetwork(weights, network);
+
+    if (status == NVDSINFER_SUCCESS) {
+        std::cout << "Building yolo network complete!" << std::endl;
+    } else {
+        std::cerr << "Building yolo network failed!" << std::endl;
+    }
+
+    return status;
+}
+
+NvDsInferStatus Yolo::buildYoloNetwork(
+    std::vector<float>& weights, nvinfer1::INetworkDefinition& network) {
+
+    // 清理yolo层
+    m_YoloKernel.clear();
+
+    int weightPtr = 0;
+    int channels = m_InputC;
+
+    nvinfer1::ITensor* data =
+        network.addInput(m_InputBlobName.c_str(), nvinfer1::DataType::kFLOAT,
+            nvinfer1::DimsCHW{static_cast<int>(m_InputC),
+                static_cast<int>(m_InputH), static_cast<int>(m_InputW)});
+    assert(data != nullptr && data->getDimensions().nbDims > 0);
+
+    nvinfer1::ITensor* previous = data;
+    std::vector<nvinfer1::ITensor*> tensorOutputs;
+    uint outputTensorCount = 0;
+
+    // build the network using the network API
+    for (uint i = 0; i < m_ConfigBlocks.size(); ++i) {
+        // check if num. of channels is correct
+        assert(getNumChannels(previous) == channels);
+        std::string layerIndex = "(" + std::to_string(tensorOutputs.size()) + ")";
+
+        if (m_ConfigBlocks.at(i).at("type") == "net") {
+            printLayerInfo("", "layer", "     inp_size", "     out_size", "weightPtr");
+        } else if (m_ConfigBlocks.at(i).at("type") == "convolutional") {
+            std::string inputVol = dimsToString(previous->getDimensions());
+            nvinfer1::ILayer* out;
+            std::string layerType;
+            // check if batch_norm enabled
+            if (m_ConfigBlocks.at(i).find("batch_normalize") != m_ConfigBlocks.at(i).end()) {
+
+                out = netAddConvBNActive(i, m_ConfigBlocks.at(i), weights,
+                                         m_TrtWeights, weightPtr, channels, previous, &network);
+                layerType = "conv-bn-Active";
+            }else{
+                out = netAddConvLinear(i, m_ConfigBlocks.at(i), weights,
+                    m_TrtWeights, weightPtr, channels, previous, &network);
+                layerType = "conv-linear";
+            }
+            previous = out->getOutput(0);
+            assert(previous != nullptr);
+            channels = getNumChannels(previous);
+            std::string outputVol = dimsToString(previous->getDimensions());
+            tensorOutputs.push_back(out->getOutput(0));
+            printLayerInfo(layerIndex, layerType, inputVol, outputVol, std::to_string(weightPtr));
+        } else if (m_ConfigBlocks.at(i).at("type") == "shortcut") {
+            assert(m_ConfigBlocks.at(i).at("activation") == "linear");
+            assert(m_ConfigBlocks.at(i).find("from") !=
+                   m_ConfigBlocks.at(i).end());
+            int from = stoi(m_ConfigBlocks.at(i).at("from"));
+
+            std::string inputVol = dimsToString(previous->getDimensions());
+            // check if indexes are correct
+            assert((i - 2 >= 0) && (i - 2 < tensorOutputs.size()));
+            assert((i + from - 1 >= 0) && (i + from - 1 < tensorOutputs.size()));
+            assert(i + from - 1 < i - 2);
+            nvinfer1::IElementWiseLayer* ew = network.addElementWise(
+                *tensorOutputs[i - 2], *tensorOutputs[i + from - 1],
+                nvinfer1::ElementWiseOperation::kSUM);
+            assert(ew != nullptr);
+            std::string ewLayerName = "shortcut_" + std::to_string(i);
+            ew->setName(ewLayerName.c_str());
+            previous = ew->getOutput(0);
+            assert(previous != nullptr);
+            std::string outputVol = dimsToString(previous->getDimensions());
+            tensorOutputs.push_back(ew->getOutput(0));
+            printLayerInfo(layerIndex, "skip", inputVol, outputVol, "    -");
+        } else if (m_ConfigBlocks.at(i).at("type") == "yolo") {
+            nvinfer1::Dims prevTensorDims = previous->getDimensions();
+            assert(prevTensorDims.d[1] == prevTensorDims.d[2]);
+            TensorInfo& curYoloTensor = m_OutputTensors.at(outputTensorCount);
+            curYoloTensor.gridSize = prevTensorDims.d[1];
+            curYoloTensor.stride = m_InputW / curYoloTensor.gridSize;
+            m_OutputTensors.at(outputTensorCount).volume = curYoloTensor.gridSize
+                * curYoloTensor.gridSize
+                * (curYoloTensor.numBBoxes * (5 + curYoloTensor.numClasses));
+            std::string layerName = "yolo_" + std::to_string(i);
+            curYoloTensor.blobName = layerName;
+
+            // 添加yolo层
+            m_YoloTensor.push_back(previous);
+            tensorOutputs.push_back(previous);
+
+            // 调整 yolo层的信息
+            Dims inputdims = previous->getDimensions();
+            YoloKernel tmpYolokernel;
+            tmpYolokernel.height= inputdims.d[1];
+            tmpYolokernel.width= inputdims.d[2];
+            // 添加yolo anchors
+            int masksize = m_OutputTensors.at(outputTensorCount).masks.size();
+            tmpYolokernel.everyYoloAnchors = masksize;
+
+            for(int i=0;i<masksize;i++)
+            {
+                int index = (int)m_OutputTensors.at(outputTensorCount).masks[i] * 2;
+                tmpYolokernel.anchors[2*i] = m_OutputTensors.at(outputTensorCount).anchors[index];
+                tmpYolokernel.anchors[2*i+1] = m_OutputTensors.at(outputTensorCount).anchors[index+1];
+            }
+
+            // 全局
+            m_YoloKernel.push_back(tmpYolokernel);
+
+            std::string inputVol = dimsToString(inputdims);
+            printLayerInfo(layerIndex, "yolo", inputVol, inputVol, std::to_string(weightPtr));
+
+            ++outputTensorCount;
+        } else if (m_ConfigBlocks.at(i).at("type") == "region") {
+            nvinfer1::Dims prevTensorDims = previous->getDimensions();
+            assert(prevTensorDims.d[1] == prevTensorDims.d[2]);
+            TensorInfo& curRegionTensor = m_OutputTensors.at(outputTensorCount);
+            curRegionTensor.gridSize = prevTensorDims.d[1];
+            curRegionTensor.stride = m_InputW / curRegionTensor.gridSize;
+            m_OutputTensors.at(outputTensorCount).volume = curRegionTensor.gridSize
+                * curRegionTensor.gridSize
+                * (curRegionTensor.numBBoxes * (5 + curRegionTensor.numClasses));
+            std::string layerName = "region_" + std::to_string(i);
+            curRegionTensor.blobName = layerName;
+            nvinfer1::plugin::RegionParameters RegionParameters{
+                static_cast<int>(curRegionTensor.numBBoxes), 4,
+                static_cast<int>(curRegionTensor.numClasses), nullptr};
+            std::string inputVol = dimsToString(previous->getDimensions());
+            nvinfer1::IPluginV2* regionPlugin
+                = createRegionPlugin(RegionParameters);
+            assert(regionPlugin != nullptr);
+            nvinfer1::IPluginV2Layer* region =
+                network.addPluginV2(&previous, 1, *regionPlugin);
+            assert(region != nullptr);
+            region->setName(layerName.c_str());
+            previous = region->getOutput(0);
+            assert(previous != nullptr);
+            previous->setName(layerName.c_str());
+            std::string outputVol = dimsToString(previous->getDimensions());
+            network.markOutput(*previous);
+            channels = getNumChannels(previous);
+            tensorOutputs.push_back(region->getOutput(0));
+            printLayerInfo(layerIndex, "region", inputVol, outputVol, std::to_string(weightPtr));
+            std::cout << "Anchors are being converted to network input resolution i.e. Anchors x "
+                      << curRegionTensor.stride << " (stride)" << std::endl;
+            for (auto& anchor : curRegionTensor.anchors) anchor *= curRegionTensor.stride;
+            ++outputTensorCount;
+        } else if (m_ConfigBlocks.at(i).at("type") == "reorg") {
+            std::string inputVol = dimsToString(previous->getDimensions());
+            nvinfer1::IPluginV2* reorgPlugin = createReorgPlugin(2);
+            assert(reorgPlugin != nullptr);
+            nvinfer1::IPluginV2Layer* reorg =
+                network.addPluginV2(&previous, 1, *reorgPlugin);
+            assert(reorg != nullptr);
+
+            std::string layerName = "reorg_" + std::to_string(i);
+            reorg->setName(layerName.c_str());
+            previous = reorg->getOutput(0);
+            assert(previous != nullptr);
+            std::string outputVol = dimsToString(previous->getDimensions());
+            channels = getNumChannels(previous);
+            tensorOutputs.push_back(reorg->getOutput(0));
+            printLayerInfo(layerIndex, "reorg", inputVol, outputVol, std::to_string(weightPtr));
+        }
+        // route layers (single or concat)
+        else if (m_ConfigBlocks.at(i).at("type") == "route") {
+            std::string strLayers = m_ConfigBlocks.at(i).at("layers");
+            std::vector<int> idxLayers;
+            size_t lastPos = 0, pos = 0;
+            while ((pos = strLayers.find(',', lastPos)) != std::string::npos) {
+                int vL = std::stoi(trim(strLayers.substr(lastPos, pos - lastPos)));
+                idxLayers.push_back (vL);
+                lastPos = pos + 1;
+            }
+            if (lastPos < strLayers.length()) {
+                std::string lastV = trim(strLayers.substr(lastPos));
+                if (!lastV.empty()) {
+                    idxLayers.push_back (std::stoi(lastV));
+                }
+            }
+            assert (!idxLayers.empty());
+            std::vector<nvinfer1::ITensor*> concatInputs;
+            for (int idxLayer : idxLayers) {
+                if (idxLayer < 0) {
+                    idxLayer = tensorOutputs.size() + idxLayer;
+                }
+                assert (idxLayer >= 0 && idxLayer < (int)tensorOutputs.size());
+                concatInputs.push_back (tensorOutputs[idxLayer]);
+            }
+            nvinfer1::IConcatenationLayer* concat;
+            if(m_ConfigBlocks.at(i).find("groups") != m_ConfigBlocks.at(i).end())
+            {
+                assert(m_ConfigBlocks.at(i).find("group_id") != m_ConfigBlocks.at(i).end());
+                int gorups =  std::stoi(m_ConfigBlocks.at(i).at("groups"));
+                int group_id = std::stoi(m_ConfigBlocks.at(i).at("group_id"));
+                std::vector<nvinfer1::ITensor*> group_concatInputs;
+                for(auto concatInput : concatInputs)
+                {
+                    Dims out_shape = concatInput->getDimensions();
+                    ISliceLayer* tmp= network.addSlice(*concatInput,Dims3{out_shape.d[0]/2,0,0},Dims3{out_shape.d[0]/2,out_shape.d[1],out_shape.d[2]},Dims3{1,1,1});
+                    group_concatInputs.push_back(tmp->getOutput(0));
+                }
+                concat=network.addConcatenation(group_concatInputs.data(), group_concatInputs.size());
+            }else {
+                concat=network.addConcatenation(concatInputs.data(), concatInputs.size());
+            }
+
+            assert(concat != nullptr);
+            std::string concatLayerName = "route_" + std::to_string(i - 1);
+            concat->setName(concatLayerName.c_str());
+            // concatenate along the channel dimension
+            concat->setAxis(0);
+            previous = concat->getOutput(0);
+            assert(previous != nullptr);
+            std::string outputVol = dimsToString(previous->getDimensions());
+            // set the output volume depth
+            channels
+                = getNumChannels(previous);
+            tensorOutputs.push_back(concat->getOutput(0));
+            printLayerInfo(layerIndex, "route", "        -", outputVol,
+                           std::to_string(weightPtr));
+        } else if (m_ConfigBlocks.at(i).at("type") == "upsample") {
+            std::string inputVol = dimsToString(previous->getDimensions());
+            nvinfer1::ILayer* out = netAddUpsample(i - 1, m_ConfigBlocks[i],
+                weights, m_TrtWeights, channels, previous, &network);
+            previous = out->getOutput(0);
+            std::string outputVol = dimsToString(previous->getDimensions());
+            tensorOutputs.push_back(out->getOutput(0));
+            printLayerInfo(layerIndex, "upsample", inputVol, outputVol, "    -");
+        } else if (m_ConfigBlocks.at(i).at("type") == "maxpool") {
+            std::string inputVol = dimsToString(previous->getDimensions());
+            nvinfer1::ILayer* out =
+                netAddMaxpool(i, m_ConfigBlocks.at(i), previous, &network);
+            previous = out->getOutput(0);
+            assert(previous != nullptr);
+            std::string outputVol = dimsToString(previous->getDimensions());
+            tensorOutputs.push_back(out->getOutput(0));
+            printLayerInfo(layerIndex, "maxpool", inputVol, outputVol, std::to_string(weightPtr));
+        }
+        else
+        {
+            std::cout << "Unsupported layer type --> \""
+                      << m_ConfigBlocks.at(i).at("type") << "\"" << std::endl;
+            assert(0);
+        }
+    }
+
+    auto creator = getPluginRegistry()->getPluginCreator("YoloLayer_TRT", "1");
+    assert(m_YoloKernel.size() == outputTensorCount);
+
+    // plugin filed 数量
+    int numyololayers = m_YoloKernel.size();
+
+    // 假定每个yolo输出层class相等
+    int numclass = m_OutputTensors[0].numClasses;
+    int input_w = m_InputW;
+    int input_h = m_InputH;
+
+    std::vector<PluginField> mPluginAttributes1 = {
+        PluginField("numclass", &numclass, PluginFieldType::kINT32, 1),
+        PluginField("input_w", &input_w, PluginFieldType::kINT32, 1),
+        PluginField("input_h", &input_h, PluginFieldType::kINT32, 1),
+        PluginField("numyololayers", &numyololayers, PluginFieldType::kINT32, 1),
+        PluginField("m_YoloKernel", &m_YoloKernel, PluginFieldType::kUNKNOWN, numyololayers),
+    };
+    PluginFieldCollection mFC1;
+    mFC1.nbFields = mPluginAttributes1.size();
+    mFC1.fields = mPluginAttributes1.data();
+    IPluginV2 * yoloplugin = creator->createPlugin(creator->getPluginName(), &mFC1);
+
+    ITensor** inputTensors_yolo = new ITensor*;
+    for (int i = 0; i<m_YoloTensor.size();i++)
+    {
+        inputTensors_yolo[i] = m_YoloTensor[i];
+    }
+
+    auto yolo = network.addPluginV2(inputTensors_yolo, 3, *yoloplugin);
+
+    previous = yolo->getOutput(0);
+    assert(previous != nullptr);
+    previous->setName("prob");
+    std::string outputVol = dimsToString(previous->getDimensions());
+    network.markOutput(*previous);
+
+    if ((int)weights.size() != weightPtr)
+    {
+        std::cout << "Number of unused weights left : " << (int)weights.size() - weightPtr << std::endl;
+        assert(0);
+    }
+
+    std::cout << "Output yolo blob names :" << std::endl;
+    for (auto& tensor : m_OutputTensors) {
+        std::cout << tensor.blobName << std::endl;
+    }
+
+    int nbLayers = network.getNbLayers();
+    std::cout << "Total number of yolo layers: " << nbLayers << std::endl;
+
+    return NVDSINFER_SUCCESS;
+}
+
+std::vector<std::map<std::string, std::string>>
+Yolo::parseConfigFile (const std::string cfgFilePath)
+{
+    assert(fileExists(cfgFilePath));
+    std::ifstream file(cfgFilePath);
+    assert(file.good());
+    std::string line;
+    std::vector<std::map<std::string, std::string>> blocks;
+    std::map<std::string, std::string> block;
+
+    while (getline(file, line))
+    {
+        if (line.size() == 0) continue;
+        if (line.front() == '#') continue;
+        line = trim(line);
+        if (line.front() == '[')
+        {
+            if (block.size() > 0)
+            {
+                blocks.push_back(block);
+                block.clear();
+            }
+            std::string key = "type";
+            std::string value = trim(line.substr(1, line.size() - 2));
+            block.insert(std::pair<std::string, std::string>(key, value));
+        }
+        else
+        {
+            int cpos = line.find('=');
+            std::string key = trim(line.substr(0, cpos));
+            std::string value = trim(line.substr(cpos + 1));
+            block.insert(std::pair<std::string, std::string>(key, value));
+        }
+    }
+    blocks.push_back(block);
+    return blocks;
+}
+
+void Yolo::parseConfigBlocks()
+{
+    for (auto block : m_ConfigBlocks) {
+        if (block.at("type") == "net")
+        {
+            assert((block.find("height") != block.end())
+                   && "Missing 'height' param in network cfg");
+            assert((block.find("width") != block.end()) && "Missing 'width' param in network cfg");
+            assert((block.find("channels") != block.end())
+                   && "Missing 'channels' param in network cfg");
+
+            m_InputH = std::stoul(block.at("height"));
+            m_InputW = std::stoul(block.at("width"));
+            m_InputC = std::stoul(block.at("channels"));
+//            assert(m_InputW == m_InputH);
+            m_InputSize = m_InputC * m_InputH * m_InputW;
+        }
+        else if ((block.at("type") == "region") || (block.at("type") == "yolo"))
+        {
+            assert((block.find("num") != block.end())
+                   && std::string("Missing 'num' param in " + block.at("type") + " layer").c_str());
+            assert((block.find("classes") != block.end())
+                   && std::string("Missing 'classes' param in " + block.at("type") + " layer")
+                          .c_str());
+            assert((block.find("anchors") != block.end())
+                   && std::string("Missing 'anchors' param in " + block.at("type") + " layer")
+                          .c_str());
+
+            TensorInfo outputTensor;
+            std::string anchorString = block.at("anchors");
+            while (!anchorString.empty())
+            {
+                int npos = anchorString.find_first_of(',');
+                if (npos != -1)
+                {
+                    float anchor = std::stof(trim(anchorString.substr(0, npos)));
+                    outputTensor.anchors.push_back(anchor);
+                    anchorString.erase(0, npos + 1);
+                }
+                else
+                {
+                    float anchor = std::stof(trim(anchorString));
+                    outputTensor.anchors.push_back(anchor);
+                    break;
+                }
+            }
+
+            if ((m_NetworkType == "yolov3") || (m_NetworkType == "yolov3-tiny") || (m_NetworkType == "yolov4-tiny") ||
+                    (m_NetworkType == "yolov4") || (m_NetworkType == "yolov4-turnstile"))
+            {
+                assert((block.find("mask") != block.end())
+                       && std::string("Missing 'mask' param in " + block.at("type") + " layer")
+                              .c_str());
+
+                std::string maskString = block.at("mask");
+                while (!maskString.empty())
+                {
+                    int npos = maskString.find_first_of(',');
+                    if (npos != -1)
+                    {
+                        uint mask = std::stoul(trim(maskString.substr(0, npos)));
+                        outputTensor.masks.push_back(mask);
+                        maskString.erase(0, npos + 1);
+                    }
+                    else
+                    {
+                        uint mask = std::stoul(trim(maskString));
+                        outputTensor.masks.push_back(mask);
+                        break;
+                    }
+                }
+            }
+
+            outputTensor.numBBoxes = outputTensor.masks.size() > 0
+                ? outputTensor.masks.size()
+                : std::stoul(trim(block.at("num")));
+            outputTensor.numClasses = std::stoul(block.at("classes"));
+            m_OutputTensors.push_back(outputTensor);
+        }
+    }
+}
+
+void Yolo::destroyNetworkUtils() {
+    // deallocate the weights
+    for (uint i = 0; i < m_TrtWeights.size(); ++i) {
+        if (m_TrtWeights[i].count > 0)
+            free(const_cast<void*>(m_TrtWeights[i].values));
+    }
+    m_TrtWeights.clear();
+}
+

+ 274 - 0
src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/src/yolodetect.cpp

@@ -0,0 +1,274 @@
+
+#include <fstream>
+#include <iostream>
+#include <map>
+#include <sstream>
+#include <vector>
+#include <chrono>
+#include <string>
+#include <cmath>
+
+#include "yolodetect.h"
+
+//yolo.weights-->yolo.engine
+bool YoloDetect::saveEngine()
+{
+    IBuilder* builder = createInferBuilder(gLogger);
+    IHostMemory* modelStream{nullptr};
+    Yolo yolo(m_networkInfo);
+    ICudaEngine *cudaEngine = yolo.createEngine (builder);
+    modelStream = cudaEngine->serialize();
+    assert(modelStream != nullptr);
+    std::ofstream p(m_modelname, std::ios::binary);
+    if (!p) {
+        std::cerr << "could not open plan output file" << std::endl;
+        return false;
+    }
+    p.write(reinterpret_cast<const char*>(modelStream->data()), modelStream->size());
+    modelStream->destroy();
+    return true;
+}
+
+//deserializeCudaEngine
+ICudaEngine* YoloDetect::loadEngine(IRuntime& runtime)
+{
+    char *trtModelStream{nullptr};
+    size_t size{0};
+    std::ifstream file(m_modelname, std::ios::binary);
+    if (file.good()) {
+        file.seekg(0, file.end);
+        size = file.tellg();
+        file.seekg(0, file.beg);
+        trtModelStream = new char[size];
+        assert(trtModelStream);
+        file.read(trtModelStream, size);
+        file.close();
+    }
+    else{
+        std::cout<<m_modelname<<" not found!"<<std::endl;
+        return nullptr;
+    }
+    ICudaEngine* engine = runtime.deserializeCudaEngine(trtModelStream, size);
+    delete[] trtModelStream;
+    return engine;
+}
+
+//load engine
+bool YoloDetect::loadModel(IExecutionContext*& context)
+{
+    std::cout<<"[API] Load engine from "<< m_modelname <<std::endl;
+    IRuntime* runtime = createInferRuntime(gLogger);
+    assert(runtime != nullptr);
+    ICudaEngine* engine = loadEngine(*runtime);
+    if(engine == nullptr)
+    {
+        std::cout<<"[API] Build engine to "<< m_modelname <<std::endl;
+        saveEngine();
+        std::cout << "[API] Build engine done!"<<std::endl;
+        std::cout<<"[API] Reload engine from "<< m_modelname <<std::endl;
+        engine = loadEngine(*runtime);
+    }
+    runtime->destroy();
+    context = engine->createExecutionContext();
+    if(context == nullptr)
+        return false;
+    std::cout << "[API] Load engine done!"<<std::endl;
+
+    int numbindings=engine->getNbBindings();
+    std::cout<< "getNbBindings: " << numbindings<<std::endl;
+
+    const char* layername = engine->getBindingName(1);
+    std::cout<< "getBindingName:1 " << layername<<std::endl;
+
+    Dims in = engine->getBindingDimensions(0);
+    std::cout<< "in dims: " << in.d[0]<<" "<<in.d[1]<<" "<<in.d[2]<<" "<<in.d[3]<<std::endl;
+    Dims out = engine->getBindingDimensions(1);
+    std::cout<< "out dims: " << out.d[0]<<" "<<out.d[1]<<" "<<out.d[2]<<" "<<out.d[3]<<std::endl;
+
+    m_input_h =  in.d[1];
+    m_input_w =  in.d[2];
+    m_output_size = out.d[0];
+    return true;
+}
+
+void YoloDetect::doInference(IExecutionContext& context,float* input, float* output, int batch_size)
+{
+    void* buffers[2];
+    cudaMalloc(&buffers[0], batch_size * 3 * m_input_h * m_input_w * sizeof(float));
+    cudaMalloc(&buffers[1], batch_size * m_output_size * sizeof(float));
+    // Create stream
+    cudaStream_t stream;
+    cudaStreamCreate(&stream);
+    cudaMemcpyAsync(buffers[0], input, batch_size * 3 * m_input_w * m_input_h * sizeof(float), cudaMemcpyHostToDevice, stream);
+    context.enqueue(batch_size, buffers, stream, nullptr);
+    cudaMemcpyAsync(output, buffers[1], batch_size * m_output_size * sizeof(float), cudaMemcpyDeviceToHost, stream);
+    cudaStreamSynchronize(stream);
+    // Release stream and buffers
+    cudaStreamDestroy(stream);
+    cudaFree(buffers[0]);
+    cudaFree(buffers[1]);
+}
+cv::Mat YoloDetect::preprocess_img(cv::Mat& img,int input_w,int input_h) {
+    //    int w, h, x, y;
+    //    float r_w = input_w / (img.cols*1.0);
+    //    float r_h = input_h / (img.rows*1.0);
+    //    if (r_h > r_w) {
+    //        w = input_w;
+    //        h = r_w * img.rows;
+    //        x = 0;
+    //        y = (input_h - h) / 2;
+    //    } else {
+    //        w = r_h* img.cols;
+    //        h = input_h;
+    //        x = (input_w - w) / 2;
+    //        y = 0;
+    //    }
+    //    cv::Mat re(h, w, CV_8UC3);
+    //    cv::resize(img, re, re.size(), 0, 0, cv::INTER_CUBIC);
+    //    cv::Mat out(input_h, input_w, CV_8UC3, cv::Scalar(128, 128, 128));
+    //    re.copyTo(out(cv::Rect(x, y, re.cols, re.rows)));
+
+    //直接将图片resize
+    cv::Mat out;
+    cv::resize(img,out,cv::Size(input_w,input_h),0,0,cv::INTER_CUBIC);
+
+    return out;
+}
+
+cv::Rect YoloDetect::get_rect(cv::Mat& img, float bbox[4],int input_w,int input_h) {
+    int l, r, t, b;
+    float r_w = input_w / (img.cols * 1.0);
+    float r_h = input_h / (img.rows * 1.0);
+
+    //    if (r_h > r_w) {
+    //        l = bbox[0] - bbox[2]/2.f;
+    //        r = bbox[0] + bbox[2]/2.f;
+    //        t = bbox[1] - bbox[3]/2.f - (input_h - r_w * img.rows) / 2;
+    //        b = bbox[1] + bbox[3]/2.f - (input_h - r_w * img.rows) / 2;
+    //        l = l / r_w;
+    //        r = r / r_w;
+    //        t = t / r_w;
+    //        b = b / r_w;
+    //    } else {
+    //        l = bbox[0] - bbox[2]/2.f - (input_w - r_h * img.cols) / 2;
+    //        r = bbox[0] + bbox[2]/2.f - (input_w - r_h * img.cols) / 2;
+    //        t = bbox[1] - bbox[3]/2.f;
+    //        b = bbox[1] + bbox[3]/2.f;
+    //        l = l / r_h;
+    //        r = r / r_h;
+    //        t = t / r_h;
+    //        b = b / r_h;
+    //    }
+
+
+    //直接将图片resize解码部分
+    l = bbox[0] - bbox[2]/2.f;
+    r = bbox[0] + bbox[2]/2.f;
+    t = bbox[1] - bbox[3]/2.f;
+    b = bbox[1] + bbox[3]/2.f;
+    l = l / r_w;
+    r = r / r_w;
+    t = t / r_h;
+    b = b / r_h;
+
+    return cv::Rect(l, t, r-l, b-t);
+}
+
+float YoloDetect::iou(float lbox[4], float rbox[4]) {
+    float interBox[] = {
+        std::max(lbox[0] - lbox[2]/2.f , rbox[0] - rbox[2]/2.f), //left
+        std::min(lbox[0] + lbox[2]/2.f , rbox[0] + rbox[2]/2.f), //right
+        std::max(lbox[1] - lbox[3]/2.f , rbox[1] - rbox[3]/2.f), //top
+        std::min(lbox[1] + lbox[3]/2.f , rbox[1] + rbox[3]/2.f), //bottom
+    };
+
+    if(interBox[2] > interBox[3] || interBox[0] > interBox[1])
+        return 0.0f;
+
+    float interBoxS =(interBox[1]-interBox[0])*(interBox[3]-interBox[2]);
+    return interBoxS/(lbox[2]*lbox[3] + rbox[2]*rbox[3] -interBoxS);
+}
+
+bool YoloDetect::cmp(Detection& a, Detection& b) {
+    return a.det_confidence > b.det_confidence;
+}
+
+void YoloDetect::nms(std::vector<Detection>& res, float *output, float ignore_thresh,float nms_thresh) {
+    std::map<float, std::vector<Detection>> m;
+
+    //std::cout << "output[0] "<<output[0]<<std::endl;
+
+    for (int i = 0; i < output[0] && i < 1000; i++) {
+        if (output[1 + 7 * i + 4] <= ignore_thresh) continue;
+        Detection det;
+        memcpy(&det, &output[1 + 7 * i], 7 * sizeof(float));
+        if (m.count(det.class_id) == 0) m.emplace(det.class_id, std::vector<Detection>());
+        m[det.class_id].push_back(det);
+    }
+    for (auto it = m.begin(); it != m.end(); it++) {
+        auto& dets = it->second;
+        std::sort(dets.begin(), dets.end(), cmp);
+        for (size_t m = 0; m < dets.size(); ++m) {
+            auto& item = dets[m];
+            res.push_back(item);
+            for (size_t n = m + 1; n < dets.size(); ++n) {
+                if (iou(item.bbox, dets[n].bbox) > nms_thresh) {
+                    dets.erase(dets.begin()+n);
+                    --n;
+                }
+            }
+        }
+    }
+}
+bool YoloDetect::process(IExecutionContext& context, cv::Mat &image, std::vector<Detection> &detect_results,
+                         float ignore_thresh,float nms_thresh)
+{
+    float data[3 * m_input_h * m_input_w];
+    float prob[m_output_size];
+    cv::Mat pr_img = preprocess_img(image,m_input_w,m_input_h);
+    for (int i = 0; i < m_input_h * m_input_w; i++) {
+        data[i] = pr_img.at<cv::Vec3b>(i)[2] / 255.0;
+        data[i + m_input_h * m_input_w] = pr_img.at<cv::Vec3b>(i)[1] / 255.0;
+        data[i + 2 * m_input_h * m_input_w] = pr_img.at<cv::Vec3b>(i)[0] / 255.0;
+    }
+    int batch_size = 1;
+    doInference(context,data,prob,batch_size);
+    nms(detect_results, prob,ignore_thresh,nms_thresh);
+    if(detect_results.size()>0)
+        return true;
+    else
+        return false;
+}
+
+//batchsize=2
+bool YoloDetect::process(IExecutionContext& context, uint max_batch_size,
+                         std::vector<cv::Mat> &image_vec,
+                         std::vector<std::vector<Detection>> &detect_results,
+                         float ignore_thresh,float nms_thresh)
+{
+    float data[max_batch_size * 3 * m_input_h * m_input_w];
+    float prob[max_batch_size * m_output_size];
+    for(uint idx=0;idx<max_batch_size;idx++)
+    {
+        cv::Mat pr_img =  preprocess_img(image_vec[idx],m_input_w,m_input_h);
+        for (int i = 0; i < m_input_h * m_input_w; i++) {
+            data[i + (idx * 3 + 0) * m_input_h * m_input_w] = pr_img.at<cv::Vec3b>(i)[2] / 255.0;
+            data[i + (idx * 3 + 1) * m_input_h * m_input_w] = pr_img.at<cv::Vec3b>(i)[1] / 255.0;
+            data[i + (idx * 3 + 2) * m_input_h * m_input_w] = pr_img.at<cv::Vec3b>(i)[0] / 255.0;
+        }
+
+    }
+    doInference(context,data,prob,max_batch_size);
+    bool flag = false;
+    for(uint idx=0;idx<max_batch_size;idx++)
+    {
+        nms(detect_results[idx],(prob+idx*m_output_size),ignore_thresh,nms_thresh);
+        if(detect_results[idx].size()>0) flag = true;
+    }
+    return flag;
+}
+
+
+
+
+

+ 129 - 0
src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/src/yololayer.cpp

@@ -0,0 +1,129 @@
+#include "yololayer.h"
+#include <cuda.h>
+#include <cuda_runtime.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+using namespace YoloLayer;
+using namespace nvinfer1;
+
+YoloLayerPlugin::YoloLayerPlugin()
+{
+    mClassCount = CLASS_NUM;
+    mYoloKernel.clear();
+    mYoloKernel.push_back(yolo1);
+    mYoloKernel.push_back(yolo2);
+    mYoloKernel.push_back(yolo3);
+
+    mKernelCount = mYoloKernel.size();
+}
+
+YoloLayerPlugin::~YoloLayerPlugin()
+{
+}
+
+// create the plugin at runtime from a byte stream
+YoloLayerPlugin::YoloLayerPlugin(const void* data, size_t length)
+{
+
+    const char *d = reinterpret_cast<const char *>(data), *a = d;
+    read(d, mClassCount);
+    read(d, mThreadCount);
+    read(d, mKernelCount);
+    mYoloKernel.resize(mKernelCount);
+    auto kernelSize = mKernelCount*sizeof(YoloKernel);
+    memcpy(mYoloKernel.data(),d,kernelSize);
+    d += kernelSize;
+
+    assert(d == a + length);
+}
+
+void YoloLayerPlugin::serialize(void* buffer) const
+{
+    std::cout<<"start getSerializationSize"<<std::endl;
+    char* d = static_cast<char*>(buffer), *a = d;
+    write(d, mClassCount);
+    write(d, mThreadCount);
+    write(d, mKernelCount);
+    auto kernelSize = mKernelCount*sizeof(YoloKernel);
+    memcpy(d,mYoloKernel.data(),kernelSize);
+    d += kernelSize;
+
+    assert(d == a + getSerializationSize());
+}
+
+size_t YoloLayerPlugin::getSerializationSize() const
+{
+    std::cout<<"start getSerializationSize"<<std::endl;
+    return sizeof(mClassCount) + sizeof(mThreadCount) + sizeof(mKernelCount)  + sizeof(YoloLayer::YoloKernel) * mYoloKernel.size();
+}
+
+int YoloLayerPlugin::initialize()
+{
+    return 0;
+}
+
+Dims YoloLayerPlugin::getOutputDimensions(int index, const Dims* inputs, int nbInputDims)
+{
+    //output the result to channel
+    int totalsize = MAX_OUTPUT_BBOX_COUNT * sizeof(Detection) / sizeof(float);
+
+    return Dims3(totalsize + 1, 1, 1);
+}
+
+// Set plugin namespace
+void YoloLayerPlugin::setPluginNamespace(const char* pluginNamespace)
+{
+    mPluginNamespace = pluginNamespace;
+}
+
+const char* YoloLayerPlugin::getPluginNamespace() const
+{
+    return mPluginNamespace;
+}
+
+bool YoloLayerPlugin::supportsFormat (
+    nvinfer1::DataType type, nvinfer1::PluginFormat format) const {
+    return (type == nvinfer1::DataType::kFLOAT &&
+            format == nvinfer1::PluginFormat::kNCHW);
+}
+
+void YoloLayerPlugin::configureWithFormat (
+    const nvinfer1::Dims* inputDims, int nbInputs,
+    const nvinfer1::Dims* outputDims, int nbOutputs,
+    nvinfer1::DataType type, nvinfer1::PluginFormat format, int maxBatchSize)
+{
+    assert(nbInputs == 3);
+    assert (format == nvinfer1::PluginFormat::kNCHW);
+    assert(inputDims != nullptr);
+}
+
+const char* YoloLayerPlugin::getPluginType() const
+{
+    return "YoloLayer_TRT";
+}
+
+const char* YoloLayerPlugin::getPluginVersion() const
+{
+    return "1";
+}
+
+void YoloLayerPlugin::destroy()
+{
+    delete this;
+}
+
+// Clone the plugin
+IPluginV2* YoloLayerPlugin::clone() const
+{
+    return new YoloLayerPlugin();
+}
+
+int YoloLayerPlugin::enqueue(int batchSize, const void*const * inputs, void** outputs, void* workspace, cudaStream_t stream)
+{
+    forwardGpu((const float *const *)inputs, (float*)outputs[0], stream, batchSize, mYoloKernel, mThreadCount);
+    return 0;
+}
+
+REGISTER_TENSORRT_PLUGIN(YoloPluginCreator);

+ 271 - 0
src/detection/detection_yolov4_shigong_monocular/yolov4Tensorrt/src/yololayer.cu

@@ -0,0 +1,271 @@
+#include "yololayer.h"
+
+namespace nvinfer1
+{
+    // build network 阶段,创建模型阶段,调用的接口
+    YoloLayerPlugin::YoloLayerPlugin(const PluginFieldCollection& fc)
+    {
+        void* tmpvoid;
+        const PluginField* fields = fc.fields;
+        for (int i = 0; i < fc.nbFields; ++i)
+        {
+            const char* attrName = fields[i].name;
+            if (!strcmp(attrName, "numclass")){
+                mClassCount = *(static_cast<const int*>(fields[i].data));
+            }
+            else if (!strcmp(attrName, "input_w")){
+                mInput_w= *(static_cast<const int*>(fields[i].data));
+            }else if(!strcmp(attrName, "input_h")){
+                mInput_h = *(static_cast<const int*>(fields[i].data));
+            }else if(!strcmp(attrName, "numyololayers")){
+                mNumYoloLayers = *(static_cast<const int*>(fields[i].data));
+            }else if(!strcmp(attrName, "m_YoloKernel")){
+                assert(fields[i].type == PluginFieldType::kUNKNOWN);
+                tmpvoid = const_cast<void*>(fields[i].data);
+            }
+        }
+        // 解析 yolo层
+        mYoloKernel = *(std::vector<YoloKernel> *)tmpvoid;
+        std::cout<<"mYoloKernel.size()"<<mYoloKernel.size()<<std::endl;
+    }
+    
+    YoloLayerPlugin::~YoloLayerPlugin()
+    {}
+    // create the plugin at runtime from a byte stream,反序列化,调用的接口,生成模型
+    YoloLayerPlugin::YoloLayerPlugin(const void* data, size_t length)
+    {
+        using namespace Tn;
+        const char *d = reinterpret_cast<const char *>(data), *a = d;
+        read(d, mClassCount);
+        read(d, mThreadCount);
+        read(d, mNumYoloLayers);
+        read(d, mInput_h);
+        read(d, mInput_w);
+        mYoloKernel.resize(mNumYoloLayers);
+        auto kernelSize = mNumYoloLayers*sizeof(YoloKernel);
+        memcpy(mYoloKernel.data(),d,kernelSize);
+        d += kernelSize;
+        assert(d == a + length);
+    }
+    // 序列化模型,即保存模型,将插件内用到的参数保存到模型中
+    void YoloLayerPlugin::serialize(void* buffer) const
+    {
+        using namespace Tn;
+        char* d = static_cast<char*>(buffer), *a = d;
+        write(d, mClassCount);
+        write(d, mThreadCount);
+        write(d, mNumYoloLayers);
+        write(d, mInput_h);
+        write(d, mInput_w);
+        auto kernelSize = mNumYoloLayers*sizeof(YoloKernel);
+        memcpy(d,mYoloKernel.data(),kernelSize);
+        d += kernelSize;
+        assert(d == a + getSerializationSize());
+    }
+    // 保存模型,序列化阶段,计算插件需要保存的数据长度
+    size_t YoloLayerPlugin::getSerializationSize() const
+    {  
+        int size  = sizeof(mInput_w) +sizeof(mInput_h)+
+                sizeof(mClassCount) + sizeof(mThreadCount) +
+                sizeof(mNumYoloLayers)  + sizeof(YoloKernel) * mYoloKernel.size();
+        return size;
+    }
+
+    int YoloLayerPlugin::initialize()
+    { 
+        return 0;
+    }
+    
+    Dims YoloLayerPlugin::getOutputDimensions(int index, const Dims* inputs, int nbInputDims)
+    {
+        //output the result to channel
+        int totalsize = max_output_box * sizeof(Detection) / sizeof(float);
+        return Dims3(totalsize + 1, 1, 1);
+    }
+
+    // Set plugin namespace
+    void YoloLayerPlugin::setPluginNamespace(const char* pluginNamespace)
+    {
+        mPluginNamespace = pluginNamespace;
+    }
+
+    const char* YoloLayerPlugin::getPluginNamespace() const
+    {
+        return mPluginNamespace;
+    }
+
+    // Return the DataType of the plugin output at the requested index
+    DataType YoloLayerPlugin::getOutputDataType(int index, const nvinfer1::DataType* inputTypes, int nbInputs) const
+    {
+        return DataType::kFLOAT;
+    }
+
+    // Return true if output tensor is broadcast across a batch.
+    bool YoloLayerPlugin::isOutputBroadcastAcrossBatch(int outputIndex, const bool* inputIsBroadcasted, int nbInputs) const
+    {
+        return false;
+    }
+
+    // Return true if plugin can use input that is broadcast across batch without replication.
+    bool YoloLayerPlugin::canBroadcastInputAcrossBatch(int inputIndex) const
+    {
+        return false;
+    }
+
+    void YoloLayerPlugin::configurePlugin(const PluginTensorDesc* in, int nbInput, const PluginTensorDesc* out, int nbOutput)
+    {
+    }
+
+    // Attach the plugin object to an execution context and grant the plugin the access to some context resource.
+    void YoloLayerPlugin::attachToContext(cudnnContext* cudnnContext, cublasContext* cublasContext, IGpuAllocator* gpuAllocator)
+    {
+    }
+
+    // Detach the plugin object from its execution context.
+    void YoloLayerPlugin::detachFromContext() {}
+
+    const char* YoloLayerPlugin::getPluginType() const
+    {
+        return "YoloLayer_TRT";
+    }
+
+    const char* YoloLayerPlugin::getPluginVersion() const
+    {
+        return "1";
+    }
+
+    void YoloLayerPlugin::destroy()
+    {
+        delete this;
+    }
+
+    // Clone the plugin
+    IPluginV2IOExt* YoloLayerPlugin::clone() const
+    {
+
+        YoloLayerPlugin *p = new YoloLayerPlugin(*this);
+        p->setPluginNamespace(mPluginNamespace);
+        return p;
+    }
+    // 核函数 sigmoid
+    __device__ float Logist(float data){ return 1.0f / (1.0f + __expf(-data)); };
+    // cuda 调用接口
+    __global__ void CalDetection(const float *input, float *output,int noElements, 
+            int yoloWidth,int yoloHeight,const float* anchors,int classes,
+                                 int outputElem,int input_w,int input_h,
+                                 float ignore_thresh,int every_yolo_anchors,int max_out_put_bbox_count) {
+ 
+        int idx = threadIdx.x + blockDim.x * blockIdx.x;
+        if (idx >= noElements) return;
+
+        int total_grid = yoloWidth * yoloHeight;
+        int bnIdx = idx / total_grid;
+        idx = idx - total_grid*bnIdx;
+        int info_len_i = 5 + classes;
+        const float* curInput = input + bnIdx * (info_len_i * total_grid * every_yolo_anchors);
+
+        for (int k = 0; k < 3; ++k) {
+            int class_id = 0;
+            float max_cls_prob = 0.0;
+            for (int i = 5; i < info_len_i; ++i) {
+                float p = Logist(curInput[idx + k * info_len_i * total_grid + i * total_grid]);
+                if (p > max_cls_prob) {
+                    max_cls_prob = p;
+                    class_id = i - 5;
+                }
+            }
+            float box_prob = Logist(curInput[idx + k * info_len_i * total_grid + 4 * total_grid]);
+            if (max_cls_prob*box_prob < ignore_thresh) continue;
+
+            float *res_count = output + bnIdx*outputElem;
+            int count = (int)atomicAdd(res_count, 1);
+            if (count >= max_out_put_bbox_count) return;
+            char* data = (char * )res_count + sizeof(float) + count*sizeof(Detection);
+            Detection* det =  (Detection*)(data);
+
+            int row = idx / yoloWidth;
+            int col = idx % yoloWidth;
+
+            //Location
+            det->bbox[0] = (col + Logist(curInput[idx + k * info_len_i * total_grid + 0 * total_grid]))* input_w/ yoloWidth;
+            det->bbox[1] = (row + Logist(curInput[idx + k * info_len_i * total_grid + 1 * total_grid]))* input_h/ yoloHeight;
+            det->bbox[2] = __expf(curInput[idx + k * info_len_i * total_grid + 2 * total_grid]) * anchors[2*k];
+            det->bbox[3] = __expf(curInput[idx + k * info_len_i * total_grid + 3 * total_grid]) * anchors[2*k + 1];
+            det->det_confidence = box_prob;
+            det->class_id = class_id;
+            det->class_confidence = max_cls_prob;
+        }
+    }
+
+    void YoloLayerPlugin::forwardGpu(const float *const * inputs, float* output, cudaStream_t stream, int batchSize)
+    {
+        // 每一层的输出大小长度,
+        int outputElem = 1 + max_output_box * sizeof(Detection) / sizeof(float);
+        // 根据batchsize调整输出的output 内存大小,初始化为0, 以最小内存单位字节为长度
+        for(int idx = 0 ; idx < batchSize; ++idx) {
+            CUDA_CHECK(cudaMemset(output + idx*outputElem, 0, sizeof(float)));
+        }
+        int numElem = 0;
+        void* devAnchor;
+        for (unsigned int i = 0;i< mYoloKernel.size();++i)
+        {
+            // yolo 每一层的参数
+            const auto& yolo = mYoloKernel[i];
+            numElem = yolo.width*yolo.height*batchSize;
+            if (numElem < mThreadCount)
+                mThreadCount = numElem;
+            int every_yolo_anchor_num = yolo.everyYoloAnchors;
+            size_t AnchorLen = sizeof(float)* yolo.everyYoloAnchors*2;
+            CUDA_CHECK(cudaMalloc(&devAnchor,AnchorLen));
+            CUDA_CHECK(cudaMemcpy(devAnchor, yolo.anchors, AnchorLen, cudaMemcpyHostToDevice));
+            CUDA_CHECK(cudaFree(devAnchor));
+            // 调用cuda接口,<调用的block数量,每一个block中的thread数量>
+            CalDetection<<< (yolo.width*yolo.height*batchSize + mThreadCount - 1) / mThreadCount, mThreadCount>>>
+                (inputs[i],output, numElem, yolo.width, yolo.height,
+                 (float *)devAnchor, mClassCount ,outputElem,mInput_w, mInput_w,
+                 mIgnore_thresh,every_yolo_anchor_num,max_output_box);
+        }
+    }
+
+    // 插件标准调用接口,enqueue
+    int YoloLayerPlugin::enqueue(int batchSize, const void*const * inputs, void** outputs, void* workspace, cudaStream_t stream)
+    {
+        forwardGpu((const float *const *)inputs, (float*)outputs[0], stream, batchSize);
+        return 0;
+    }
+
+    YoloPluginCreator::YoloPluginCreator()
+    {
+    }
+
+    const char* YoloPluginCreator::getPluginName() const
+    {
+            return "YoloLayer_TRT";
+    }
+
+    const char* YoloPluginCreator::getPluginVersion() const
+    {
+            return "1";
+    }
+
+    const PluginFieldCollection* YoloPluginCreator::getFieldNames()
+    {
+            return 0;
+    }
+
+    IPluginV2IOExt* YoloPluginCreator::createPlugin(const char* name, const PluginFieldCollection* fc)
+    {
+        YoloLayerPlugin* obj = new YoloLayerPlugin(*fc);
+        obj->setPluginNamespace(mNamespace.c_str());
+        return obj;
+    }
+
+    IPluginV2IOExt* YoloPluginCreator::deserializePlugin(const char* name, const void* serialData, size_t serialLength)
+    {
+        // This object will be deleted when the network is destroyed
+        YoloLayerPlugin* obj = new YoloLayerPlugin(serialData, serialLength);
+        obj->setPluginNamespace(mNamespace.c_str());
+        return obj;
+    }
+
+}

+ 1 - 1
src/driver/driver_lidar_rs16/main.cpp

@@ -185,7 +185,7 @@ int main(int argc, char *argv[])
     snprintf(gstr_inclinationang_yaxis,255,"0");
     snprintf(gstr_hostip,255,"0.0.0.0");
     snprintf(gstr_port,255,"6699");//默认端口号
-    snprintf(gstr_yaml,255,"");
+    snprintf(gstr_yaml,255,argv[1]);
 
     int nRtn = GetOptLong(argc,argv);
     if(nRtn == 1)  //show help,so exit.

+ 67 - 36
src/driver/driver_lidar_rs32/driver_lidar_rs32.pro

@@ -11,6 +11,7 @@
 //#include <pcl/conversions.h>
 #include <pcl/point_cloud.h>
 #include <pcl/point_types.h>
+#include <Eigen/Dense>
 
 #include "modulecomm.h"
 
@@ -23,13 +24,15 @@
 int vv7;
 #endif
 
+Eigen::Matrix3d rotation_matrix;
+Eigen::Vector3d trans_matrix;
+
 
 
 #define Lidar_Pi 3.1415926535897932384626433832795
 #define Lidar32 (unsigned long)3405883584//192.168.1.203
 #define Lidar_roll_ang (90)*Lidar_Pi/180.0
 
-
 std::thread * g_prs32Thread;
 std::thread * g_prs32ProcThread;
 
@@ -97,8 +100,6 @@ public:
     }
 };
 
-
-
 rs32_Buf  * g_rs32_Buf;
 char * g_RawData_Buf;
 int gnRawPos = 0;
@@ -237,8 +238,13 @@ void process_rs32obs(char * strdata,int nLen)
     pcl::PointCloud<pcl::PointXYZI>::Ptr point_cloud(
                 new pcl::PointCloud<pcl::PointXYZI>());
 
-
-
+    Eigen::AngleAxisd r_z ( 0, Eigen::Vector3d ( 0,0,1 ) ); //沿 Z 轴旋转 yaw   +
+    Eigen::AngleAxisd r_y ( 0, Eigen::Vector3d ( 0,1,0 ) ); //沿 Y 轴旋转 roll  +
+    Eigen::AngleAxisd r_x ( 0, Eigen::Vector3d ( 1,0,0 ) ); //沿 X 轴旋转 pitch -
+    Eigen::Quaterniond q_zyx = r_z*r_y*r_x; //ZYX旋转顺序(绕旋转后的轴接着旋转)
+    // 四元数-->>旋转矩阵
+    rotation_matrix = q_zyx.toRotationMatrix();
+    trans_matrix << 0, 0, 0;
 
 //    point_cloud->header.stamp =
 //            pcl_conversions::toPCL(sweep_data->header).stamp;
@@ -266,21 +272,41 @@ void process_rs32obs(char * strdata,int nLen)
 //    float lidar_32_ydistance = -2.3;			//32线激光雷达Y轴补偿
 
 
+//    float H_BETA[32] = {
+//        -8,-8,-8,-8,-8,-2.672,2.672,8,
+//        -8,-2.672,2.672,8,-8,-2.672,2.672,8,
+//        8,8,8,-8,8,-8,8,-8,
+//        -8,-2.672,2.672,8,-8,-2.672,2.672,8
+//    };
+
+//    float H_BETA[32] = {
+//        -4.11,3.67,-4.07,3.64,-4.03,3.62,-4.02,3.61,
+//                                   -4.01,3.61,-4.01,3.61,-4.02,3.62,-4.03,3.63,
+//                                  -4.06,3.71,-4.09,3.75,-4.23,3.92,-4.30,4.01,
+//                                  -4.56,4.18,-4.80,4.42,-5.07,4.66,-5.36,4.84
+//    };
+
     float H_BETA[32] = {
-        -8,-8,-8,-8,-8,-2.672,2.672,8,
-        -8,-2.672,2.672,8,-8,-2.672,2.672,8,
-        8,8,8,-8,8,-8,8,-8,
-        -8,-2.672,2.672,8,-8,-2.672,2.672,8
+        6.94,-3.54,6.88,-3.51,6.84,-3.49,6.83,-3.48,
+                                   6.84,-3.48,6.88,-3.49,6.94,-3.51,7.02,-3.54,
+                                  2.89,-7.72,2.87,-7.63,2.86,-7.56,2.85,-7.53,
+                                  2.85,-7.52,2.86,-7.54,2.88,-7.59,2.90,-7.67
     };
 
 //    float V_theta[16] = {-15,-13,-11,-9,-7,-5,-3,-1,15,13,11,9,7,5,3,1};
-    float V_theta[32] = {-25,-14.638,-7.91,-5.407,-3.667,-4,-4.333,-4.667,-2.333,-2.667,-3,-3.333,-1,-1.333,-1.667,-2,
-                        -10.281,-6.424,2.333,3.333,4.667,7,10.333,15,0.333,0,-0.333,-0.667,1.667,1.333,1.0,0.667};
-//    float V_theta[16] =  {-15,1,-13,3,-11,5,-9,7,-7,9,-5,11,-3,13,-1,15};
-//    float T[32] = {    0,  3.125,  1.5625,   4.6875,  6.25,  9.375,  7.8125,  10.9375,
-//                    12.5,  15.625, 14.0625, 17.1875, 18.75, 21.875,  20.3125, 23.4375,
-//                      25,  28.125, 26.5625, 29.6875, 31.25, 34.375, 32.8125,  35.9375,
-//                    37.5,  40.625, 39.0625, 42.1875, 43.75, 46.875, 45.3125,  48.4375};
+//    float V_theta[32] = {-25,-14.638,-7.91,-5.407,-3.667,-4,-4.333,-4.667,-2.333,-2.667,-3,-3.333,-1,-1.333,-1.667,-2,
+//                        -10.281,-6.424,2.333,3.333,4.667,7,10.333,15,0.333,0,-0.333,-0.667,1.667,1.333,1.0,0.667};
+//    float V_theta[32] = {14.94,13.03,10.92,8.9,6.96,5.46,
+//                         3.98,2.67,1.33,0,-1.33,-2.67,-3.96,
+//                         -5.23,-6.63,-8.01,-9.94,-15.97,-12.90,
+//                         -18.98,-21.92,-27.87,-24.96,-30.95,-33.89,
+//                         -37.09,-39.95,-43.11,-46.10,-49.13,-51.90,-53.70};
+    float V_theta[32] = {11.99,13.98,8.00,9.99,3.99,6.00,
+                         0,2.00,-3.99,-2.01,-7.98,-5.98,-12.01,
+                         -10.00,-15.99,-13.99,12.98,14.98,8.98,
+                         10.99,5.00,6.99,1.00,3.00,-3.01,
+                         -1.00,-6.99,-4.99,-10.98,-9.01,-14.99,-12.98};
+
 
 
         int buf1len = nLen/1206;
@@ -310,44 +336,49 @@ void process_rs32obs(char * strdata,int nLen)
                         Ang = (0 - wt-H_BETA[pointi]) / 180.0 * Lidar_Pi;
                         Range = ((pstr[bag*1206 + Group * 100 + 4 + 3 * pointi] << 8) + pstr[bag*1206+Group * 100 + 5 + 3 * pointi]);
                         unsigned char intensity = pstr[bag*1206 + Group * 100 + 6 + 3 * pointi];
-                        Range=Range* 5.0/1000.0;
+                        Range=Range* 5.0/2000.0;
 
                         if(Range<150)
                         {
-                            pcl::PointXYZI point;
-                            point.x  = Range*cos(V_theta[pointi] / 180 * Lidar_Pi)*cos(Ang + frollang);
-                            point.y  = Range*cos(V_theta[pointi] / 180 * Lidar_Pi)*sin(Ang + frollang);
-                            point.z  = Range*sin(V_theta[pointi] / 180 * Lidar_Pi);
+                            pcl::PointXYZI point,point_temp;
+                            point_temp.x  = Range*cos(V_theta[pointi] / 180 * Lidar_Pi)*cos(Ang + frollang);
+                            point_temp.y  = Range*cos(V_theta[pointi] / 180 * Lidar_Pi)*sin(Ang + frollang);
+                            point_temp.z  = Range*sin(V_theta[pointi] / 180 * Lidar_Pi);
+//                            if(point.z>1.5) continue;
                             if(binclix)
                             {
                                 double y,z;
-                                y = point.y;
-                                z = point.z;
-                                point.y = y*cos_finclinationang_xaxis +z*sin_finclinationang_xaxis;
-                                point.z = z*cos_finclinationang_xaxis - y*sin_finclinationang_xaxis;
+                                y = point_temp.y;
+                                z = point_temp.z;
+
+                                point_temp.y = y*cos_finclinationang_xaxis +z*sin_finclinationang_xaxis;
+                                point_temp.z = z*cos_finclinationang_xaxis - y*sin_finclinationang_xaxis;
                             }
                             if(bincliy)
                             {
                                 double z,x;
-                                z = point.z;
-                                x = point.x;
-                                point.z = z*cos_finclinationang_yaxis + x*sin_finclinationang_yaxis;
-                                point.x = x*cos_finclinationang_yaxis - z*sin_finclinationang_yaxis;
+                                z = point_temp.z;
+                                x = point_temp.x;
+                                point_temp.z = z*cos_finclinationang_yaxis + x*sin_finclinationang_yaxis;
+                                point_temp.x = x*cos_finclinationang_yaxis - z*sin_finclinationang_yaxis;
                             }
+                            point.x = -point_temp.y;
+                            point.y = point_temp.x;
+                            point.z = point_temp.z;
+                            Eigen::Vector3d new_point, old_point;
+                            old_point<<point.x, point.y, point.z;
+                            new_point = rotation_matrix * (old_point) + trans_matrix;
+                            point.x = new_point[0];
+                            point.y = new_point[1];
+                            point.z = new_point[2];
+
                             point.intensity = intensity;
                             point_cloud->points.push_back(point);
 
-
                             ++point_cloud->width;
                         }
                     }
 
-
-
-
-
-
-
                 }
             }
 

+ 1 - 1
src/driver/driver_lidar_rs32/lidar_driver_rs32.h

@@ -176,7 +176,7 @@ int main(int argc, char *argv[])
     QCoreApplication a(argc, argv);
 
     snprintf(gstr_memname,255,"lidar_pc");
-    snprintf(gstr_rollang,255,"-9.0");
+    snprintf(gstr_rollang,255,"0.0");
     snprintf(gstr_inclinationang_xaxis,255,"0.0");
     snprintf(gstr_inclinationang_yaxis,255,"0");
     snprintf(gstr_hostip,255,"0.0.0.0");

+ 7 - 7
src/fusion/lidar_radar_fusion_cnn/Tracker/Ctracker.cpp

@@ -22,7 +22,7 @@ bool InitTracker(CTracker& tracker)
     settings.m_accelNoiseMag = 0.5f; // 卡尔曼的噪声放大器
     settings.m_distThres = 30.f; // 匹配算法中的距离阈值
     settings.m_minAreaRadiusPix = -1.f;//frame.rows / 20.f; // 目标的最小面积半径(像素)
-    settings.m_maximumAllowedSkippedFrames = 2; // 被跟踪目标允许未匹配到的最大次数,当超过这一数值,该目标的跟踪器将被移除
+    settings.m_maximumAllowedSkippedFrames = 3; // 被跟踪目标允许未匹配到的最大次数,当超过这一数值,该目标的跟踪器将被移除
     settings.m_maxTraceLength = 5; // 最大跟踪长度,即历史轨迹保留的最大长度
 
     tracker.setSettings(settings);
@@ -58,9 +58,9 @@ iv::fusion::fusionobjectarray Tracking(iv::fusion::fusionobjectarray& fusionobjv
         CRegion region = CRegion(rect,fusionobjvec.obj(i).type(),fusionobjvec.obj(i).prob());
         regions.push_back(region);
 #ifdef DEBUG_SHOW
-        std::cout<<"old id:"<<i<<std::endl;
-        std::cout<<"old type:"<<fusionobjvec.obj(i).type()<<std::endl;
-        std::cout<<"old x,y,z,w,h,l,yaw:"<<rect.center.x<<","<<rect.center.y<<","<<rect.center.z<<"  "<<rect.size.width<<","<<rect.size.height<<","<<rect.size.length<<"  "<<rect.yaw<<std::endl;
+//        std::cout<<"old id:"<<i<<std::endl;
+//        std::cout<<"old type:"<<fusionobjvec.obj(i).type()<<std::endl;
+//        std::cout<<"old x,y,z,w,h,l,yaw:"<<rect.center.x<<","<<rect.center.y<<","<<rect.center.z<<"  "<<rect.size.width<<","<<rect.size.height<<","<<rect.size.length<<"  "<<rect.yaw<<std::endl;
 #endif
     }
     tracker.Update(regions, cv::UMat(), 30);
@@ -159,9 +159,9 @@ iv::fusion::fusionobjectarray Tracking(iv::fusion::fusionobjectarray& fusionobjv
             pe->CopyFrom(fusion_object);
         }
 #ifdef DEBUG_SHOW
-        std::cout<<"id:"<<fusion_object.id()<<"  "<<obj_id<<std::endl;
-        std::cout<<"type:"<<fusion_object.type()<<std::endl;
-        std::cout<<"update x,y,z,w,h,l,yaw,vx,vy:"<<fusion_object.centroid().x()<<","<<fusion_object.centroid().y()<<","<<fusion_object.centroid().z()<<"  "<<fusion_object.dimensions().x()<<","<<fusion_object.dimensions().y()<<","<<fusion_object.dimensions().z()<<"  "<<fusion_object.yaw()<<"  "<<fusion_object.vel_relative().x()<<","<<fusion_object.vel_relative().y()<<std::endl;
+//        std::cout<<"id:"<<fusion_object.id()<<"  "<<obj_id<<std::endl;
+//        std::cout<<"type:"<<fusion_object.type()<<std::endl;
+//        std::cout<<"update x,y,z,w,h,l,yaw,vx,vy:"<<fusion_object.centroid().x()<<","<<fusion_object.centroid().y()<<","<<fusion_object.centroid().z()<<"  "<<fusion_object.dimensions().x()<<","<<fusion_object.dimensions().y()<<","<<fusion_object.dimensions().z()<<"  "<<fusion_object.yaw()<<"  "<<fusion_object.vel_relative().x()<<","<<fusion_object.vel_relative().y()<<std::endl;
 #endif
     }
 #ifdef DEBUG_SHOW

+ 6 - 4
src/fusion/lidar_radar_fusion_cnn/Tracker/defines.h

@@ -102,6 +102,7 @@ void RLfusion(iv::lidar::objectarray& lidar_object_arr,iv::radar::radarobjectarr
         fusion_object.set_sensor_type(0);
         fusion_object.set_type(lidar_object_arr.obj(match_idx[i].nlidar).mntype());
         fusion_object.set_prob(lidar_object_arr.obj(match_idx[i].nlidar).score());
+        fusion_object.set_velocity_linear_x(-lidar_object_arr.obj(match_idx[i].nlidar).velocity_linear_x());
 
         if(match_idx.at(i).nradar == -1000)
         {
@@ -128,8 +129,9 @@ void RLfusion(iv::lidar::objectarray& lidar_object_arr,iv::radar::radarobjectarr
             centroid.set_z(lidar_object_arr.obj(match_idx[i].nlidar).centroid().z());
             centroid_ = fusion_object.mutable_centroid();
             centroid_->CopyFrom(centroid);
+#ifdef DEBUG_SHOW
             std::cout<<"lidar: "<<centroid.x()<<","<<centroid.y()<<","<<centroid.z()<<std::endl;
-
+#endif
         }else {
 //             std::cout<<"   fusion    is    ok  "<<std::endl;
             fusion_object.set_yaw(radar_object_array.obj(match_idx.at(i).nradar).angle());
@@ -171,7 +173,7 @@ void RLfusion(iv::lidar::objectarray& lidar_object_arr,iv::radar::radarobjectarr
         dimension_ = fusion_object.mutable_dimensions();
         dimension_->CopyFrom(dimension);
 
-        std::cout<<" x     y    z:   "<<lidar_object_arr.obj(match_idx[i].nlidar).dimensions().x()<<"     "<<lidar_object_arr.obj(match_idx[i].nlidar).dimensions().y()<<std::endl;
+//        std::cout<<" x     y    z:   "<<lidar_object_arr.obj(match_idx[i].nlidar).dimensions().x()<<"     "<<lidar_object_arr.obj(match_idx[i].nlidar).dimensions().y()<<std::endl;
 
 
 
@@ -261,8 +263,8 @@ void ObsToNormal(iv::fusion::fusionobjectarray& lidar_radar_fusion_object_array)
 {
     for(int i = 0; i < lidar_radar_fusion_object_array.obj_size(); i++)
     {
-        if((lidar_radar_fusion_object_array.obj(i).sensor_type() == 0) &&(lidar_radar_fusion_object_array.obj(i).centroid().y() > 20 || abs(lidar_radar_fusion_object_array.obj(i).centroid().x())>10) ) continue;
-        if ((lidar_radar_fusion_object_array.obj(i).sensor_type() == 0)&&(lidar_radar_fusion_object_array.obj(i).centroid().y()>10 && abs(lidar_radar_fusion_object_array.obj(i).centroid().x())<1.3)) continue;
+//        if((lidar_radar_fusion_object_array.obj(i).sensor_type() == 0) &&(lidar_radar_fusion_object_array.obj(i).centroid().y() > 20 || abs(lidar_radar_fusion_object_array.obj(i).centroid().x())>10) ) continue;
+//        if ((lidar_radar_fusion_object_array.obj(i).sensor_type() == 0)&&(lidar_radar_fusion_object_array.obj(i).centroid().y()>10 && abs(lidar_radar_fusion_object_array.obj(i).centroid().x())<1.3)) continue;
         if((lidar_radar_fusion_object_array.obj(i).sensor_type() == 0)&&(lidar_radar_fusion_object_array.obj(i).centroid().y() <1.0  && abs(lidar_radar_fusion_object_array.obj(i).centroid().x())<1.3)) continue;
 
         if((lidar_radar_fusion_object_array.obj(i).dimensions().x()>0)&&

+ 1 - 1
src/fusion/lidar_radar_fusion_cnn/fusion_probabilities.cpp

@@ -9,7 +9,7 @@ CONFIG -= app_bundle
 # depend on your compiler). Please consult the documentation of the
 # deprecated API in order to know how to port your code away from it.
 DEFINES += QT_DEPRECATED_WARNINGS
-DEFINES += DEBUG_SHOW
+#DEFINES += DEBUG_SHOW
 INCLUDEPATH +=Tracker
 
 HEADERS += \

+ 14 - 14
src/fusion/lidar_radar_fusion_cnn/main.cpp

@@ -87,7 +87,7 @@ void Listenlidarcnndetect(const char * strdata,const unsigned int nSize,const un
     }
     //    std::cout<<"  lidar  is  ok   "<<lidarobj.obj_size()<<std::endl;
     gMutex.lock();
-    //    std::cout<<"   obj size  "<<lidarobj.obj_size()<<std::endl;
+        std::cout<<"   obj size  "<<lidarobj.obj_size()<<std::endl;
     datafusion(lidarobj,radarobjvec,li_ra_fusion);
     gMutex.unlock();
 }
@@ -127,9 +127,9 @@ void datafusion(iv::lidar::objectarray& lidar_obj,iv::radar::radarobjectarray& r
 
     //    li_ra_fusion.Clear();
     //      std::cout<<" RLFusion     begin    "<<std::endl;
-    AddMobileye(li_ra_fusion,mobileye_info);
+//    AddMobileye(li_ra_fusion,mobileye_info);
     //    std::cout<<" RLFusion     end      "<<std::endl;
-    mobileye_info.clear_xobj();
+//    mobileye_info.clear_xobj();
     //        std::cout<< "     fusion size  "<<li_ra_fusion.obj_size()<<std::endl;
     //    for(int i=0;i<li_ra_fusion.obj_size();i++)
     //    {
@@ -159,20 +159,20 @@ void datafusion(iv::lidar::objectarray& lidar_obj,iv::radar::radarobjectarray& r
     //    gMutex.lock();
     //    std::cout<<" track   begin"<<std::endl;
     //---------------------------------------------  init tracker  -------------------------------------------------
-    if (!m_isTrackerInitialized)
-    {
-        m_isTrackerInitialized = InitTracker(tracker);
-        if (!m_isTrackerInitialized)
-        {
-            std::cerr << "Tracker initialize error!!!" << std::endl;
-        }
-    }
-    iv::fusion::fusionobjectarray trackedobjvec = Tracking(li_ra_fusion, tracker);
+//    if (!m_isTrackerInitialized)
+//    {
+//        m_isTrackerInitialized = InitTracker(tracker);
+//        if (!m_isTrackerInitialized)
+//        {
+//            std::cerr << "Tracker initialize error!!!" << std::endl;
+//        }
+//    }
+//    iv::fusion::fusionobjectarray trackedobjvec = Tracking(li_ra_fusion, tracker);
     //    std::<<"track    end"<<std::endl;
 
     //--------------------------------------------  end tracking  --------------------------------------------------
     //    gMutex.unlock();
-    iv::fusion::fusionobjectarray out_fusion = trackedobjvec;
+    iv::fusion::fusionobjectarray out_fusion = li_ra_fusion;
     ObsToNormal(out_fusion);
     string out;
 
@@ -214,7 +214,7 @@ int main(int argc, char *argv[])
 
     void *gpa;
     gpa = iv::modulecomm::RegisterRecv("radar",Listenesrfront);
-    gpa = iv::modulecomm::RegisterRecv("lidar_pointpillar",Listenlidarcnndetect);
+    gpa = iv::modulecomm::RegisterRecv("lidar_track",Listenlidarcnndetect);
     gpa = iv::modulecomm::RegisterRecv("mobileye",Listenmobileye);
     return a.exec();
 }

+ 1 - 1
src/fusion/lidar_radar_fusion_cnn/perceptionoutput.cpp

@@ -17,7 +17,7 @@
 #define VIEW_WIDTH 2000
 #define VIEW_HEIGHT 2000
 //ConsumerProducerQueue<cv::Mat> *imageBuffer = new ConsumerProducerQueue<cv::Mat>(1, true);
-std::string gstrperceptitle[] = {"image00","lidar_track","radar","lidarobj","fusion","imgdet"};
+std::string gstrperceptitle[] = {"lidar_pc","lidar_pointpillar","lidar_track","li_ra_fusion","obstacledata"};//{"image00","lidar_track","lidar_pc","lidar_pointpillar","radar","lidarobj","fusion","imgdet"};
 //std::string gstrperceptitle[] = {"image00","lidar","radar","fusion","lidarobj","imgdet"};
 //std::string gstrmemname[] = {"image00","lidarpc_center","radar","radafds","fusion"};
 std::string gstrmemname[] = {"image00","lidarpc_center","radar","fusion"};

+ 5 - 5
src/tool/data_serials/mainwindow.cpp

@@ -8,9 +8,9 @@ MainWindow::MainWindow(QWidget *parent)
     ui->setupUi(this);
     mp_tabWidget = ui->tabWidget;
 
-    ui->checkBoxAcc->setEnabled(false);
+    ui->checkBoxAcc->setEnabled(true);
     ui->checkBoxBrake->setEnabled(false);
-    ui->checkBoxEps->setEnabled(false);
+    ui->checkBoxEps->setEnabled(true);
     ui->checkBoxHeading->setEnabled(false);
     ui->checkBoxLidarObs->setEnabled(false);
     ui->checkBoxObsDis->setEnabled(false);
@@ -26,14 +26,14 @@ MainWindow::MainWindow(QWidget *parent)
 //    iniTabWidgetLines(mp_widgetOnlineLines, &mq_plotOnlineLines, true);
 //    iniTabWidgetLines(mp_widgetOfflineLines, &mq_plotOffineLines, false);
     //初始化地图曲线
-    iniTabWidgetMap();
+//    iniTabWidgetMap();
     //显示导入的离线决策数据
 //    initGraphOffline();
-    mp_tabWidget->addTab(mp_plotOnlineMap,"地图轨迹");
+//    mp_tabWidget->addTab(mp_plotOnlineMap,"地图轨迹");
     mp_tabWidget->addTab(mp_widgetOnlineLines,"在线曲线");
 //    mp_tabWidget->addTab(mp_widgetOffline,"离线数据");
 
-    connect(mp_dataParser,SIGNAL(signalUpGPS()),this,SLOT(on_updataGPS()));
+//    connect(mp_dataParser,SIGNAL(signalUpGPS()),this,SLOT(on_updataGPS()));
     connect(mp_dataParser,SIGNAL(signalUpDecision()),this,SLOT(on_updataDecision()));
 
 }

+ 402 - 0
src/tool/picview/moc_predefs.h

@@ -0,0 +1,402 @@
+#define __SSP_STRONG__ 3
+#define __DBL_MIN_EXP__ (-1021)
+#define __FLT32X_MAX_EXP__ 1024
+#define __cpp_attributes 200809
+#define __UINT_LEAST16_MAX__ 0xffff
+#define __ARM_SIZEOF_WCHAR_T 4
+#define __ATOMIC_ACQUIRE 2
+#define __FLT128_MAX_10_EXP__ 4932
+#define __FLT_MIN__ 1.17549435082228750796873653722224568e-38F
+#define __GCC_IEC_559_COMPLEX 2
+#define __UINT_LEAST8_TYPE__ unsigned char
+#define __INTMAX_C(c) c ## L
+#define __CHAR_BIT__ 8
+#define __UINT8_MAX__ 0xff
+#define __WINT_MAX__ 0xffffffffU
+#define __FLT32_MIN_EXP__ (-125)
+#define __cpp_static_assert 200410
+#define __ORDER_LITTLE_ENDIAN__ 1234
+#define __SIZE_MAX__ 0xffffffffffffffffUL
+#define __WCHAR_MAX__ 0xffffffffU
+#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
+#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
+#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
+#define __DBL_DENORM_MIN__ double(4.94065645841246544176568792868221372e-324L)
+#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
+#define __GCC_ATOMIC_CHAR_LOCK_FREE 2
+#define __GCC_IEC_559 2
+#define __FLT32X_DECIMAL_DIG__ 17
+#define __FLT_EVAL_METHOD__ 0
+#define __unix__ 1
+#define __cpp_binary_literals 201304
+#define __FLT64_DECIMAL_DIG__ 17
+#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2
+#define __cpp_variadic_templates 200704
+#define __UINT_FAST64_MAX__ 0xffffffffffffffffUL
+#define __SIG_ATOMIC_TYPE__ int
+#define __DBL_MIN_10_EXP__ (-307)
+#define __FLT16_EPSILON__ 9.76562500000000000000000000000000000e-4F16
+#define __FINITE_MATH_ONLY__ 0
+#define __ARM_FEATURE_UNALIGNED 1
+#define __GNUC_PATCHLEVEL__ 0
+#define __FLT32_HAS_DENORM__ 1
+#define __UINT_FAST8_MAX__ 0xff
+#define __has_include(STR) __has_include__(STR)
+#define __DEC64_MAX_EXP__ 385
+#define __INT8_C(c) c
+#define __INT_LEAST8_WIDTH__ 8
+#define __UINT_LEAST64_MAX__ 0xffffffffffffffffUL
+#define __SHRT_MAX__ 0x7fff
+#define __LDBL_MAX__ 1.18973149535723176508575932662800702e+4932L
+#define __ARM_FEATURE_IDIV 1
+#define __FLT64X_MAX_10_EXP__ 4932
+#define __ARM_FP 14
+#define __UINT_LEAST8_MAX__ 0xff
+#define __GCC_ATOMIC_BOOL_LOCK_FREE 2
+#define __FLT128_DENORM_MIN__ 6.47517511943802511092443895822764655e-4966F128
+#define __UINTMAX_TYPE__ long unsigned int
+#define __linux 1
+#define __DEC32_EPSILON__ 1E-6DF
+#define __FLT_EVAL_METHOD_TS_18661_3__ 0
+#define __OPTIMIZE__ 1
+#define __CHAR_UNSIGNED__ 1
+#define __UINT32_MAX__ 0xffffffffU
+#define __GXX_EXPERIMENTAL_CXX0X__ 1
+#define __AARCH64_CMODEL_SMALL__ 1
+#define __LDBL_MAX_EXP__ 16384
+#define __FLT128_MIN_EXP__ (-16381)
+#define __WINT_MIN__ 0U
+#define __linux__ 1
+#define __FLT128_MIN_10_EXP__ (-4931)
+#define __INT_LEAST16_WIDTH__ 16
+#define __SCHAR_MAX__ 0x7f
+#define __FLT128_MANT_DIG__ 113
+#define __WCHAR_MIN__ 0U
+#define __INT64_C(c) c ## L
+#define __DBL_DIG__ 15
+#define __GCC_ATOMIC_POINTER_LOCK_FREE 2
+#define __FLT64X_MANT_DIG__ 113
+#define _FORTIFY_SOURCE 2
+#define __SIZEOF_INT__ 4
+#define __SIZEOF_POINTER__ 8
+#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2
+#define __USER_LABEL_PREFIX__ 
+#define __FLT64X_EPSILON__ 1.92592994438723585305597794258492732e-34F64x
+#define __STDC_HOSTED__ 1
+#define __LDBL_HAS_INFINITY__ 1
+#define __ARM_ALIGN_MAX_STACK_PWR 16
+#define __FLT32_DIG__ 6
+#define __FLT_EPSILON__ 1.19209289550781250000000000000000000e-7F
+#define __GXX_WEAK__ 1
+#define __SHRT_WIDTH__ 16
+#define __LDBL_MIN__ 3.36210314311209350626267781732175260e-4932L
+#define __DEC32_MAX__ 9.999999E96DF
+#define __cpp_threadsafe_static_init 200806
+#define __ARM_SIZEOF_MINIMAL_ENUM 4
+#define __FLT64X_DENORM_MIN__ 6.47517511943802511092443895822764655e-4966F64x
+#define __FLT32X_HAS_INFINITY__ 1
+#define __INT32_MAX__ 0x7fffffff
+#define __INT_WIDTH__ 32
+#define __SIZEOF_LONG__ 8
+#define __STDC_IEC_559__ 1
+#define __STDC_ISO_10646__ 201706L
+#define __UINT16_C(c) c
+#define __PTRDIFF_WIDTH__ 64
+#define __DECIMAL_DIG__ 36
+#define __FLT64_EPSILON__ 2.22044604925031308084726333618164062e-16F64
+#define __gnu_linux__ 1
+#define __INTMAX_WIDTH__ 64
+#define __FLT64_MIN_EXP__ (-1021)
+#define __has_include_next(STR) __has_include_next__(STR)
+#define __FLT64X_MIN_10_EXP__ (-4931)
+#define __LDBL_HAS_QUIET_NAN__ 1
+#define __FLT16_MIN_EXP__ (-13)
+#define __FLT64_MANT_DIG__ 53
+#define __GNUC__ 7
+#define __GXX_RTTI 1
+#define __pie__ 2
+#define __cpp_delegating_constructors 200604
+#define __FLT_HAS_DENORM__ 1
+#define __SIZEOF_LONG_DOUBLE__ 16
+#define __BIGGEST_ALIGNMENT__ 16
+#define __STDC_UTF_16__ 1
+#define __FLT64_MAX_10_EXP__ 308
+#define __FLT16_MAX_10_EXP__ 4
+#define __FLT32_HAS_INFINITY__ 1
+#define __DBL_MAX__ double(1.79769313486231570814527423731704357e+308L)
+#define __cpp_raw_strings 200710
+#define __INT_FAST32_MAX__ 0x7fffffffffffffffL
+#define __DBL_HAS_INFINITY__ 1
+#define __INT64_MAX__ 0x7fffffffffffffffL
+#define __DEC32_MIN_EXP__ (-94)
+#define __INTPTR_WIDTH__ 64
+#define __FLT32X_HAS_DENORM__ 1
+#define __INT_FAST16_TYPE__ long int
+#define __LDBL_HAS_DENORM__ 1
+#define __cplusplus 201103L
+#define __cpp_ref_qualifiers 200710
+#define __DEC128_MAX__ 9.999999999999999999999999999999999E6144DL
+#define __INT_LEAST32_MAX__ 0x7fffffff
+#define __DEC32_MIN__ 1E-95DF
+#define __DEPRECATED 1
+#define __cpp_rvalue_references 200610
+#define __DBL_MAX_EXP__ 1024
+#define __WCHAR_WIDTH__ 32
+#define __FLT32_MAX__ 3.40282346638528859811704183484516925e+38F32
+#define __DEC128_EPSILON__ 1E-33DL
+#define __FLT16_DECIMAL_DIG__ 5
+#define __PTRDIFF_MAX__ 0x7fffffffffffffffL
+#define __STDC_NO_THREADS__ 1
+#define __FLT32_HAS_QUIET_NAN__ 1
+#define __GNUG__ 7
+#define __LONG_LONG_MAX__ 0x7fffffffffffffffLL
+#define __SIZEOF_SIZE_T__ 8
+#define __cpp_rvalue_reference 200610
+#define __ARM_ALIGN_MAX_PWR 28
+#define __cpp_nsdmi 200809
+#define __FLT64X_MIN_EXP__ (-16381)
+#define __SIZEOF_WINT_T__ 4
+#define __LONG_LONG_WIDTH__ 64
+#define __cpp_initializer_lists 200806
+#define __FLT32_MAX_EXP__ 128
+#define __cpp_hex_float 201603
+#define __GCC_HAVE_DWARF2_CFI_ASM 1
+#define __ARM_FP16_FORMAT_IEEE 1
+#define __GXX_ABI_VERSION 1011
+#define __FLT128_HAS_INFINITY__ 1
+#define __FLT_MIN_EXP__ (-125)
+#define __FLT16_MANT_DIG__ 11
+#define __cpp_lambdas 200907
+#define __FLT64X_HAS_QUIET_NAN__ 1
+#define __INT_FAST64_TYPE__ long int
+#define __FP_FAST_FMAF 1
+#define __FLT64_DENORM_MIN__ 4.94065645841246544176568792868221372e-324F64
+#define __DBL_MIN__ double(2.22507385850720138309023271733240406e-308L)
+#define __PIE__ 2
+#define __FLT16_DENORM_MIN__ 5.96046447753906250000000000000000000e-8F16
+#define __LP64__ 1
+#define __FLT_EVAL_METHOD_C99__ 0
+#define __FLT32X_EPSILON__ 2.22044604925031308084726333618164062e-16F32x
+#define __aarch64__ 1
+#define __FLT64_MIN_10_EXP__ (-307)
+#define __ARM_FP16_ARGS 1
+#define __FLT16_MIN_10_EXP__ (-4)
+#define __FLT64X_DECIMAL_DIG__ 36
+#define __DEC128_MIN__ 1E-6143DL
+#define __REGISTER_PREFIX__ 
+#define __UINT16_MAX__ 0xffff
+#define __DBL_HAS_DENORM__ 1
+#define __FLT32_MIN__ 1.17549435082228750796873653722224568e-38F32
+#define __UINT8_TYPE__ unsigned char
+#define __FLT_MANT_DIG__ 24
+#define __LDBL_DECIMAL_DIG__ 36
+#define __VERSION__ "7.5.0"
+#define __UINT64_C(c) c ## UL
+#define __cpp_unicode_characters 200704
+#define _STDC_PREDEF_H 1
+#define __ARM_FEATURE_FMA 1
+#define __GCC_ATOMIC_INT_LOCK_FREE 2
+#define __FLT128_MAX_EXP__ 16384
+#define __FLT32_MANT_DIG__ 24
+#define __FLOAT_WORD_ORDER__ __ORDER_LITTLE_ENDIAN__
+#define __FLT32X_MIN_EXP__ (-1021)
+#define __FLT16_DIG__ 3
+#define __STDC_IEC_559_COMPLEX__ 1
+#define __FLT128_HAS_DENORM__ 1
+#define __FLT128_DIG__ 33
+#define __SCHAR_WIDTH__ 8
+#define __INT32_C(c) c
+#define __DEC64_EPSILON__ 1E-15DD
+#define __ORDER_PDP_ENDIAN__ 3412
+#define __DEC128_MIN_EXP__ (-6142)
+#define __FLT32_MAX_10_EXP__ 38
+#define __ARM_64BIT_STATE 1
+#define __INT_FAST32_TYPE__ long int
+#define __UINT_LEAST16_TYPE__ short unsigned int
+#define __FLT64X_HAS_INFINITY__ 1
+#define unix 1
+#define __INT16_MAX__ 0x7fff
+#define __cpp_rtti 199711
+#define __SIZE_TYPE__ long unsigned int
+#define __UINT64_MAX__ 0xffffffffffffffffUL
+#define __FLT64X_DIG__ 33
+#define __INT8_TYPE__ signed char
+#define __ELF__ 1
+#define __FLT_RADIX__ 2
+#define __INT_LEAST16_TYPE__ short int
+#define __ARM_ARCH_PROFILE 65
+#define __LDBL_EPSILON__ 1.92592994438723585305597794258492732e-34L
+#define __UINTMAX_C(c) c ## UL
+#define __GLIBCXX_BITSIZE_INT_N_0 128
+#define __ARM_PCS_AAPCS64 1
+#define __SIG_ATOMIC_MAX__ 0x7fffffff
+#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2
+#define __SIZEOF_PTRDIFF_T__ 8
+#define __FLT32X_MANT_DIG__ 53
+#define __AARCH64EL__ 1
+#define __FLT16_MAX_EXP__ 16
+#define __DEC32_SUBNORMAL_MIN__ 0.000001E-95DF
+#define __INT_FAST16_MAX__ 0x7fffffffffffffffL
+#define __FLT64_DIG__ 15
+#define __UINT_FAST32_MAX__ 0xffffffffffffffffUL
+#define __UINT_LEAST64_TYPE__ long unsigned int
+#define __FLT_HAS_QUIET_NAN__ 1
+#define __FLT_MAX_10_EXP__ 38
+#define __LONG_MAX__ 0x7fffffffffffffffL
+#define __FLT64X_HAS_DENORM__ 1
+#define __DEC128_SUBNORMAL_MIN__ 0.000000000000000000000000000000001E-6143DL
+#define __FLT_HAS_INFINITY__ 1
+#define __unix 1
+#define __cpp_unicode_literals 200710
+#define __UINT_FAST16_TYPE__ long unsigned int
+#define __DEC64_MAX__ 9.999999999999999E384DD
+#define __INT_FAST32_WIDTH__ 64
+#define __CHAR16_TYPE__ short unsigned int
+#define __PRAGMA_REDEFINE_EXTNAME 1
+#define __SIZE_WIDTH__ 64
+#define __INT_LEAST16_MAX__ 0x7fff
+#define __DEC64_MANT_DIG__ 16
+#define __UINT_LEAST32_MAX__ 0xffffffffU
+#define __FLT32_DENORM_MIN__ 1.40129846432481707092372958328991613e-45F32
+#define __GCC_ATOMIC_LONG_LOCK_FREE 2
+#define __SIG_ATOMIC_WIDTH__ 32
+#define __INT_LEAST64_TYPE__ long int
+#define __ARM_FEATURE_CLZ 1
+#define __INT16_TYPE__ short int
+#define __INT_LEAST8_TYPE__ signed char
+#define __FLT16_MAX__ 6.55040000000000000000000000000000000e+4F16
+#define __DEC32_MAX_EXP__ 97
+#define __INT_FAST8_MAX__ 0x7f
+#define __ARM_ARCH 8
+#define __FLT128_MAX__ 1.18973149535723176508575932662800702e+4932F128
+#define __INTPTR_MAX__ 0x7fffffffffffffffL
+#define linux 1
+#define __cpp_range_based_for 200907
+#define __FLT64_HAS_QUIET_NAN__ 1
+#define __FLT32_MIN_10_EXP__ (-37)
+#define __EXCEPTIONS 1
+#define __LDBL_MANT_DIG__ 113
+#define __DBL_HAS_QUIET_NAN__ 1
+#define __FLT64_HAS_INFINITY__ 1
+#define __FLT64X_MAX__ 1.18973149535723176508575932662800702e+4932F64x
+#define __FLT16_HAS_INFINITY__ 1
+#define __SIG_ATOMIC_MIN__ (-__SIG_ATOMIC_MAX__ - 1)
+#define __INTPTR_TYPE__ long int
+#define __UINT16_TYPE__ short unsigned int
+#define __WCHAR_TYPE__ unsigned int
+#define __SIZEOF_FLOAT__ 4
+#define __pic__ 2
+#define __UINTPTR_MAX__ 0xffffffffffffffffUL
+#define __ARM_ARCH_8A 1
+#define __INT_FAST64_WIDTH__ 64
+#define __DEC64_MIN_EXP__ (-382)
+#define __cpp_decltype 200707
+#define __FLT32_DECIMAL_DIG__ 9
+#define __INT_FAST64_MAX__ 0x7fffffffffffffffL
+#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1
+#define __FLT_DIG__ 6
+#define __FLT64X_MAX_EXP__ 16384
+#define __UINT_FAST64_TYPE__ long unsigned int
+#define __INT_MAX__ 0x7fffffff
+#define __FLT16_HAS_QUIET_NAN__ 1
+#define __INT64_TYPE__ long int
+#define __FLT_MAX_EXP__ 128
+#define __ORDER_BIG_ENDIAN__ 4321
+#define __DBL_MANT_DIG__ 53
+#define __cpp_inheriting_constructors 201511
+#define __INT_LEAST64_MAX__ 0x7fffffffffffffffL
+#define __DEC64_MIN__ 1E-383DD
+#define __WINT_TYPE__ unsigned int
+#define __UINT_LEAST32_TYPE__ unsigned int
+#define __SIZEOF_SHORT__ 2
+#define __LDBL_MIN_EXP__ (-16381)
+#define __FLT64_MAX__ 1.79769313486231570814527423731704357e+308F64
+#define __WINT_WIDTH__ 32
+#define __INT_LEAST8_MAX__ 0x7f
+#define __FLT32X_MAX_10_EXP__ 308
+#define __SIZEOF_INT128__ 16
+#define __FLT16_MIN__ 6.10351562500000000000000000000000000e-5F16
+#define __WCHAR_UNSIGNED__ 1
+#define __LDBL_MAX_10_EXP__ 4932
+#define __ATOMIC_RELAXED 0
+#define __DBL_EPSILON__ double(2.22044604925031308084726333618164062e-16L)
+#define __FLT128_MIN__ 3.36210314311209350626267781732175260e-4932F128
+#define _LP64 1
+#define __UINT8_C(c) c
+#define __FLT64_MAX_EXP__ 1024
+#define __INT_LEAST32_TYPE__ int
+#define __SIZEOF_WCHAR_T__ 4
+#define __ARM_NEON 1
+#define __FLT128_HAS_QUIET_NAN__ 1
+#define __INT_FAST8_TYPE__ signed char
+#define __FLT64X_MIN__ 3.36210314311209350626267781732175260e-4932F64x
+#define __GNUC_STDC_INLINE__ 1
+#define __FLT64_HAS_DENORM__ 1
+#define __FLT32_EPSILON__ 1.19209289550781250000000000000000000e-7F32
+#define __FLT16_HAS_DENORM__ 1
+#define __DBL_DECIMAL_DIG__ 17
+#define __STDC_UTF_32__ 1
+#define __INT_FAST8_WIDTH__ 8
+#define __DEC_EVAL_METHOD__ 2
+#define __FLT32X_MAX__ 1.79769313486231570814527423731704357e+308F32x
+#define __cpp_runtime_arrays 198712
+#define __UINT64_TYPE__ long unsigned int
+#define __UINT32_C(c) c ## U
+#define __INTMAX_MAX__ 0x7fffffffffffffffL
+#define __cpp_alias_templates 200704
+#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
+#define __FLT_DENORM_MIN__ 1.40129846432481707092372958328991613e-45F
+#define __INT8_MAX__ 0x7f
+#define __LONG_WIDTH__ 64
+#define __PIC__ 2
+#define __UINT_FAST32_TYPE__ long unsigned int
+#define __CHAR32_TYPE__ unsigned int
+#define __FLT_MAX__ 3.40282346638528859811704183484516925e+38F
+#define __FP_FAST_FMA 1
+#define __cpp_constexpr 200704
+#define __ARM_FEATURE_NUMERIC_MAXMIN 1
+#define __INT32_TYPE__ int
+#define __SIZEOF_DOUBLE__ 8
+#define __cpp_exceptions 199711
+#define __FLT_MIN_10_EXP__ (-37)
+#define __FLT64_MIN__ 2.22507385850720138309023271733240406e-308F64
+#define __INT_LEAST32_WIDTH__ 32
+#define __INTMAX_TYPE__ long int
+#define __DEC128_MAX_EXP__ 6145
+#define __FLT32X_HAS_QUIET_NAN__ 1
+#define __ATOMIC_CONSUME 1
+#define __GNUC_MINOR__ 5
+#define __GLIBCXX_TYPE_INT_N_0 __int128
+#define __INT_FAST16_WIDTH__ 64
+#define __UINTMAX_MAX__ 0xffffffffffffffffUL
+#define __DEC32_MANT_DIG__ 7
+#define __FLT32X_DENORM_MIN__ 4.94065645841246544176568792868221372e-324F32x
+#define __DBL_MAX_10_EXP__ 308
+#define __LDBL_DENORM_MIN__ 6.47517511943802511092443895822764655e-4966L
+#define __INT16_C(c) c
+#define __ARM_ARCH_ISA_A64 1
+#define __STDC__ 1
+#define __FLT32X_DIG__ 15
+#define __PTRDIFF_TYPE__ long int
+#define __ATOMIC_SEQ_CST 5
+#define __UINT32_TYPE__ unsigned int
+#define __FLT32X_MIN_10_EXP__ (-307)
+#define __UINTPTR_TYPE__ long unsigned int
+#define __DEC64_SUBNORMAL_MIN__ 0.000000000000001E-383DD
+#define __DEC128_MANT_DIG__ 34
+#define __LDBL_MIN_10_EXP__ (-4931)
+#define __FLT128_EPSILON__ 1.92592994438723585305597794258492732e-34F128
+#define __SIZEOF_LONG_LONG__ 8
+#define __cpp_user_defined_literals 200809
+#define __FLT128_DECIMAL_DIG__ 36
+#define __GCC_ATOMIC_LLONG_LOCK_FREE 2
+#define __FLT32X_MIN__ 2.22507385850720138309023271733240406e-308F32x
+#define __LDBL_DIG__ 33
+#define __FLT_DECIMAL_DIG__ 9
+#define __UINT_FAST16_MAX__ 0xffffffffffffffffUL
+#define __GCC_ATOMIC_SHORT_LOCK_FREE 2
+#define __INT_LEAST64_WIDTH__ 64
+#define __UINT_FAST8_TYPE__ unsigned char
+#define _GNU_SOURCE 1
+#define __ATOMIC_ACQ_REL 4
+#define __ATOMIC_RELEASE 3

+ 402 - 0
src/tool/view_message/moc_predefs.h

@@ -0,0 +1,402 @@
+#define __SSP_STRONG__ 3
+#define __DBL_MIN_EXP__ (-1021)
+#define __FLT32X_MAX_EXP__ 1024
+#define __cpp_attributes 200809
+#define __UINT_LEAST16_MAX__ 0xffff
+#define __ARM_SIZEOF_WCHAR_T 4
+#define __ATOMIC_ACQUIRE 2
+#define __FLT128_MAX_10_EXP__ 4932
+#define __FLT_MIN__ 1.17549435082228750796873653722224568e-38F
+#define __GCC_IEC_559_COMPLEX 2
+#define __UINT_LEAST8_TYPE__ unsigned char
+#define __INTMAX_C(c) c ## L
+#define __CHAR_BIT__ 8
+#define __UINT8_MAX__ 0xff
+#define __WINT_MAX__ 0xffffffffU
+#define __FLT32_MIN_EXP__ (-125)
+#define __cpp_static_assert 200410
+#define __ORDER_LITTLE_ENDIAN__ 1234
+#define __SIZE_MAX__ 0xffffffffffffffffUL
+#define __WCHAR_MAX__ 0xffffffffU
+#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
+#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
+#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
+#define __DBL_DENORM_MIN__ double(4.94065645841246544176568792868221372e-324L)
+#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
+#define __GCC_ATOMIC_CHAR_LOCK_FREE 2
+#define __GCC_IEC_559 2
+#define __FLT32X_DECIMAL_DIG__ 17
+#define __FLT_EVAL_METHOD__ 0
+#define __unix__ 1
+#define __cpp_binary_literals 201304
+#define __FLT64_DECIMAL_DIG__ 17
+#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2
+#define __cpp_variadic_templates 200704
+#define __UINT_FAST64_MAX__ 0xffffffffffffffffUL
+#define __SIG_ATOMIC_TYPE__ int
+#define __DBL_MIN_10_EXP__ (-307)
+#define __FLT16_EPSILON__ 9.76562500000000000000000000000000000e-4F16
+#define __FINITE_MATH_ONLY__ 0
+#define __ARM_FEATURE_UNALIGNED 1
+#define __GNUC_PATCHLEVEL__ 0
+#define __FLT32_HAS_DENORM__ 1
+#define __UINT_FAST8_MAX__ 0xff
+#define __has_include(STR) __has_include__(STR)
+#define __DEC64_MAX_EXP__ 385
+#define __INT8_C(c) c
+#define __INT_LEAST8_WIDTH__ 8
+#define __UINT_LEAST64_MAX__ 0xffffffffffffffffUL
+#define __SHRT_MAX__ 0x7fff
+#define __LDBL_MAX__ 1.18973149535723176508575932662800702e+4932L
+#define __ARM_FEATURE_IDIV 1
+#define __FLT64X_MAX_10_EXP__ 4932
+#define __ARM_FP 14
+#define __UINT_LEAST8_MAX__ 0xff
+#define __GCC_ATOMIC_BOOL_LOCK_FREE 2
+#define __FLT128_DENORM_MIN__ 6.47517511943802511092443895822764655e-4966F128
+#define __UINTMAX_TYPE__ long unsigned int
+#define __linux 1
+#define __DEC32_EPSILON__ 1E-6DF
+#define __FLT_EVAL_METHOD_TS_18661_3__ 0
+#define __OPTIMIZE__ 1
+#define __CHAR_UNSIGNED__ 1
+#define __UINT32_MAX__ 0xffffffffU
+#define __GXX_EXPERIMENTAL_CXX0X__ 1
+#define __AARCH64_CMODEL_SMALL__ 1
+#define __LDBL_MAX_EXP__ 16384
+#define __FLT128_MIN_EXP__ (-16381)
+#define __WINT_MIN__ 0U
+#define __linux__ 1
+#define __FLT128_MIN_10_EXP__ (-4931)
+#define __INT_LEAST16_WIDTH__ 16
+#define __SCHAR_MAX__ 0x7f
+#define __FLT128_MANT_DIG__ 113
+#define __WCHAR_MIN__ 0U
+#define __INT64_C(c) c ## L
+#define __DBL_DIG__ 15
+#define __GCC_ATOMIC_POINTER_LOCK_FREE 2
+#define __FLT64X_MANT_DIG__ 113
+#define _FORTIFY_SOURCE 2
+#define __SIZEOF_INT__ 4
+#define __SIZEOF_POINTER__ 8
+#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2
+#define __USER_LABEL_PREFIX__ 
+#define __FLT64X_EPSILON__ 1.92592994438723585305597794258492732e-34F64x
+#define __STDC_HOSTED__ 1
+#define __LDBL_HAS_INFINITY__ 1
+#define __ARM_ALIGN_MAX_STACK_PWR 16
+#define __FLT32_DIG__ 6
+#define __FLT_EPSILON__ 1.19209289550781250000000000000000000e-7F
+#define __GXX_WEAK__ 1
+#define __SHRT_WIDTH__ 16
+#define __LDBL_MIN__ 3.36210314311209350626267781732175260e-4932L
+#define __DEC32_MAX__ 9.999999E96DF
+#define __cpp_threadsafe_static_init 200806
+#define __ARM_SIZEOF_MINIMAL_ENUM 4
+#define __FLT64X_DENORM_MIN__ 6.47517511943802511092443895822764655e-4966F64x
+#define __FLT32X_HAS_INFINITY__ 1
+#define __INT32_MAX__ 0x7fffffff
+#define __INT_WIDTH__ 32
+#define __SIZEOF_LONG__ 8
+#define __STDC_IEC_559__ 1
+#define __STDC_ISO_10646__ 201706L
+#define __UINT16_C(c) c
+#define __PTRDIFF_WIDTH__ 64
+#define __DECIMAL_DIG__ 36
+#define __FLT64_EPSILON__ 2.22044604925031308084726333618164062e-16F64
+#define __gnu_linux__ 1
+#define __INTMAX_WIDTH__ 64
+#define __FLT64_MIN_EXP__ (-1021)
+#define __has_include_next(STR) __has_include_next__(STR)
+#define __FLT64X_MIN_10_EXP__ (-4931)
+#define __LDBL_HAS_QUIET_NAN__ 1
+#define __FLT16_MIN_EXP__ (-13)
+#define __FLT64_MANT_DIG__ 53
+#define __GNUC__ 7
+#define __GXX_RTTI 1
+#define __pie__ 2
+#define __cpp_delegating_constructors 200604
+#define __FLT_HAS_DENORM__ 1
+#define __SIZEOF_LONG_DOUBLE__ 16
+#define __BIGGEST_ALIGNMENT__ 16
+#define __STDC_UTF_16__ 1
+#define __FLT64_MAX_10_EXP__ 308
+#define __FLT16_MAX_10_EXP__ 4
+#define __FLT32_HAS_INFINITY__ 1
+#define __DBL_MAX__ double(1.79769313486231570814527423731704357e+308L)
+#define __cpp_raw_strings 200710
+#define __INT_FAST32_MAX__ 0x7fffffffffffffffL
+#define __DBL_HAS_INFINITY__ 1
+#define __INT64_MAX__ 0x7fffffffffffffffL
+#define __DEC32_MIN_EXP__ (-94)
+#define __INTPTR_WIDTH__ 64
+#define __FLT32X_HAS_DENORM__ 1
+#define __INT_FAST16_TYPE__ long int
+#define __LDBL_HAS_DENORM__ 1
+#define __cplusplus 201103L
+#define __cpp_ref_qualifiers 200710
+#define __DEC128_MAX__ 9.999999999999999999999999999999999E6144DL
+#define __INT_LEAST32_MAX__ 0x7fffffff
+#define __DEC32_MIN__ 1E-95DF
+#define __DEPRECATED 1
+#define __cpp_rvalue_references 200610
+#define __DBL_MAX_EXP__ 1024
+#define __WCHAR_WIDTH__ 32
+#define __FLT32_MAX__ 3.40282346638528859811704183484516925e+38F32
+#define __DEC128_EPSILON__ 1E-33DL
+#define __FLT16_DECIMAL_DIG__ 5
+#define __PTRDIFF_MAX__ 0x7fffffffffffffffL
+#define __STDC_NO_THREADS__ 1
+#define __FLT32_HAS_QUIET_NAN__ 1
+#define __GNUG__ 7
+#define __LONG_LONG_MAX__ 0x7fffffffffffffffLL
+#define __SIZEOF_SIZE_T__ 8
+#define __cpp_rvalue_reference 200610
+#define __ARM_ALIGN_MAX_PWR 28
+#define __cpp_nsdmi 200809
+#define __FLT64X_MIN_EXP__ (-16381)
+#define __SIZEOF_WINT_T__ 4
+#define __LONG_LONG_WIDTH__ 64
+#define __cpp_initializer_lists 200806
+#define __FLT32_MAX_EXP__ 128
+#define __cpp_hex_float 201603
+#define __GCC_HAVE_DWARF2_CFI_ASM 1
+#define __ARM_FP16_FORMAT_IEEE 1
+#define __GXX_ABI_VERSION 1011
+#define __FLT128_HAS_INFINITY__ 1
+#define __FLT_MIN_EXP__ (-125)
+#define __FLT16_MANT_DIG__ 11
+#define __cpp_lambdas 200907
+#define __FLT64X_HAS_QUIET_NAN__ 1
+#define __INT_FAST64_TYPE__ long int
+#define __FP_FAST_FMAF 1
+#define __FLT64_DENORM_MIN__ 4.94065645841246544176568792868221372e-324F64
+#define __DBL_MIN__ double(2.22507385850720138309023271733240406e-308L)
+#define __PIE__ 2
+#define __FLT16_DENORM_MIN__ 5.96046447753906250000000000000000000e-8F16
+#define __LP64__ 1
+#define __FLT_EVAL_METHOD_C99__ 0
+#define __FLT32X_EPSILON__ 2.22044604925031308084726333618164062e-16F32x
+#define __aarch64__ 1
+#define __FLT64_MIN_10_EXP__ (-307)
+#define __ARM_FP16_ARGS 1
+#define __FLT16_MIN_10_EXP__ (-4)
+#define __FLT64X_DECIMAL_DIG__ 36
+#define __DEC128_MIN__ 1E-6143DL
+#define __REGISTER_PREFIX__ 
+#define __UINT16_MAX__ 0xffff
+#define __DBL_HAS_DENORM__ 1
+#define __FLT32_MIN__ 1.17549435082228750796873653722224568e-38F32
+#define __UINT8_TYPE__ unsigned char
+#define __FLT_MANT_DIG__ 24
+#define __LDBL_DECIMAL_DIG__ 36
+#define __VERSION__ "7.5.0"
+#define __UINT64_C(c) c ## UL
+#define __cpp_unicode_characters 200704
+#define _STDC_PREDEF_H 1
+#define __ARM_FEATURE_FMA 1
+#define __GCC_ATOMIC_INT_LOCK_FREE 2
+#define __FLT128_MAX_EXP__ 16384
+#define __FLT32_MANT_DIG__ 24
+#define __FLOAT_WORD_ORDER__ __ORDER_LITTLE_ENDIAN__
+#define __FLT32X_MIN_EXP__ (-1021)
+#define __FLT16_DIG__ 3
+#define __STDC_IEC_559_COMPLEX__ 1
+#define __FLT128_HAS_DENORM__ 1
+#define __FLT128_DIG__ 33
+#define __SCHAR_WIDTH__ 8
+#define __INT32_C(c) c
+#define __DEC64_EPSILON__ 1E-15DD
+#define __ORDER_PDP_ENDIAN__ 3412
+#define __DEC128_MIN_EXP__ (-6142)
+#define __FLT32_MAX_10_EXP__ 38
+#define __ARM_64BIT_STATE 1
+#define __INT_FAST32_TYPE__ long int
+#define __UINT_LEAST16_TYPE__ short unsigned int
+#define __FLT64X_HAS_INFINITY__ 1
+#define unix 1
+#define __INT16_MAX__ 0x7fff
+#define __cpp_rtti 199711
+#define __SIZE_TYPE__ long unsigned int
+#define __UINT64_MAX__ 0xffffffffffffffffUL
+#define __FLT64X_DIG__ 33
+#define __INT8_TYPE__ signed char
+#define __ELF__ 1
+#define __FLT_RADIX__ 2
+#define __INT_LEAST16_TYPE__ short int
+#define __ARM_ARCH_PROFILE 65
+#define __LDBL_EPSILON__ 1.92592994438723585305597794258492732e-34L
+#define __UINTMAX_C(c) c ## UL
+#define __GLIBCXX_BITSIZE_INT_N_0 128
+#define __ARM_PCS_AAPCS64 1
+#define __SIG_ATOMIC_MAX__ 0x7fffffff
+#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2
+#define __SIZEOF_PTRDIFF_T__ 8
+#define __FLT32X_MANT_DIG__ 53
+#define __AARCH64EL__ 1
+#define __FLT16_MAX_EXP__ 16
+#define __DEC32_SUBNORMAL_MIN__ 0.000001E-95DF
+#define __INT_FAST16_MAX__ 0x7fffffffffffffffL
+#define __FLT64_DIG__ 15
+#define __UINT_FAST32_MAX__ 0xffffffffffffffffUL
+#define __UINT_LEAST64_TYPE__ long unsigned int
+#define __FLT_HAS_QUIET_NAN__ 1
+#define __FLT_MAX_10_EXP__ 38
+#define __LONG_MAX__ 0x7fffffffffffffffL
+#define __FLT64X_HAS_DENORM__ 1
+#define __DEC128_SUBNORMAL_MIN__ 0.000000000000000000000000000000001E-6143DL
+#define __FLT_HAS_INFINITY__ 1
+#define __unix 1
+#define __cpp_unicode_literals 200710
+#define __UINT_FAST16_TYPE__ long unsigned int
+#define __DEC64_MAX__ 9.999999999999999E384DD
+#define __INT_FAST32_WIDTH__ 64
+#define __CHAR16_TYPE__ short unsigned int
+#define __PRAGMA_REDEFINE_EXTNAME 1
+#define __SIZE_WIDTH__ 64
+#define __INT_LEAST16_MAX__ 0x7fff
+#define __DEC64_MANT_DIG__ 16
+#define __UINT_LEAST32_MAX__ 0xffffffffU
+#define __FLT32_DENORM_MIN__ 1.40129846432481707092372958328991613e-45F32
+#define __GCC_ATOMIC_LONG_LOCK_FREE 2
+#define __SIG_ATOMIC_WIDTH__ 32
+#define __INT_LEAST64_TYPE__ long int
+#define __ARM_FEATURE_CLZ 1
+#define __INT16_TYPE__ short int
+#define __INT_LEAST8_TYPE__ signed char
+#define __FLT16_MAX__ 6.55040000000000000000000000000000000e+4F16
+#define __DEC32_MAX_EXP__ 97
+#define __INT_FAST8_MAX__ 0x7f
+#define __ARM_ARCH 8
+#define __FLT128_MAX__ 1.18973149535723176508575932662800702e+4932F128
+#define __INTPTR_MAX__ 0x7fffffffffffffffL
+#define linux 1
+#define __cpp_range_based_for 200907
+#define __FLT64_HAS_QUIET_NAN__ 1
+#define __FLT32_MIN_10_EXP__ (-37)
+#define __EXCEPTIONS 1
+#define __LDBL_MANT_DIG__ 113
+#define __DBL_HAS_QUIET_NAN__ 1
+#define __FLT64_HAS_INFINITY__ 1
+#define __FLT64X_MAX__ 1.18973149535723176508575932662800702e+4932F64x
+#define __FLT16_HAS_INFINITY__ 1
+#define __SIG_ATOMIC_MIN__ (-__SIG_ATOMIC_MAX__ - 1)
+#define __INTPTR_TYPE__ long int
+#define __UINT16_TYPE__ short unsigned int
+#define __WCHAR_TYPE__ unsigned int
+#define __SIZEOF_FLOAT__ 4
+#define __pic__ 2
+#define __UINTPTR_MAX__ 0xffffffffffffffffUL
+#define __ARM_ARCH_8A 1
+#define __INT_FAST64_WIDTH__ 64
+#define __DEC64_MIN_EXP__ (-382)
+#define __cpp_decltype 200707
+#define __FLT32_DECIMAL_DIG__ 9
+#define __INT_FAST64_MAX__ 0x7fffffffffffffffL
+#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1
+#define __FLT_DIG__ 6
+#define __FLT64X_MAX_EXP__ 16384
+#define __UINT_FAST64_TYPE__ long unsigned int
+#define __INT_MAX__ 0x7fffffff
+#define __FLT16_HAS_QUIET_NAN__ 1
+#define __INT64_TYPE__ long int
+#define __FLT_MAX_EXP__ 128
+#define __ORDER_BIG_ENDIAN__ 4321
+#define __DBL_MANT_DIG__ 53
+#define __cpp_inheriting_constructors 201511
+#define __INT_LEAST64_MAX__ 0x7fffffffffffffffL
+#define __DEC64_MIN__ 1E-383DD
+#define __WINT_TYPE__ unsigned int
+#define __UINT_LEAST32_TYPE__ unsigned int
+#define __SIZEOF_SHORT__ 2
+#define __LDBL_MIN_EXP__ (-16381)
+#define __FLT64_MAX__ 1.79769313486231570814527423731704357e+308F64
+#define __WINT_WIDTH__ 32
+#define __INT_LEAST8_MAX__ 0x7f
+#define __FLT32X_MAX_10_EXP__ 308
+#define __SIZEOF_INT128__ 16
+#define __FLT16_MIN__ 6.10351562500000000000000000000000000e-5F16
+#define __WCHAR_UNSIGNED__ 1
+#define __LDBL_MAX_10_EXP__ 4932
+#define __ATOMIC_RELAXED 0
+#define __DBL_EPSILON__ double(2.22044604925031308084726333618164062e-16L)
+#define __FLT128_MIN__ 3.36210314311209350626267781732175260e-4932F128
+#define _LP64 1
+#define __UINT8_C(c) c
+#define __FLT64_MAX_EXP__ 1024
+#define __INT_LEAST32_TYPE__ int
+#define __SIZEOF_WCHAR_T__ 4
+#define __ARM_NEON 1
+#define __FLT128_HAS_QUIET_NAN__ 1
+#define __INT_FAST8_TYPE__ signed char
+#define __FLT64X_MIN__ 3.36210314311209350626267781732175260e-4932F64x
+#define __GNUC_STDC_INLINE__ 1
+#define __FLT64_HAS_DENORM__ 1
+#define __FLT32_EPSILON__ 1.19209289550781250000000000000000000e-7F32
+#define __FLT16_HAS_DENORM__ 1
+#define __DBL_DECIMAL_DIG__ 17
+#define __STDC_UTF_32__ 1
+#define __INT_FAST8_WIDTH__ 8
+#define __DEC_EVAL_METHOD__ 2
+#define __FLT32X_MAX__ 1.79769313486231570814527423731704357e+308F32x
+#define __cpp_runtime_arrays 198712
+#define __UINT64_TYPE__ long unsigned int
+#define __UINT32_C(c) c ## U
+#define __INTMAX_MAX__ 0x7fffffffffffffffL
+#define __cpp_alias_templates 200704
+#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
+#define __FLT_DENORM_MIN__ 1.40129846432481707092372958328991613e-45F
+#define __INT8_MAX__ 0x7f
+#define __LONG_WIDTH__ 64
+#define __PIC__ 2
+#define __UINT_FAST32_TYPE__ long unsigned int
+#define __CHAR32_TYPE__ unsigned int
+#define __FLT_MAX__ 3.40282346638528859811704183484516925e+38F
+#define __FP_FAST_FMA 1
+#define __cpp_constexpr 200704
+#define __ARM_FEATURE_NUMERIC_MAXMIN 1
+#define __INT32_TYPE__ int
+#define __SIZEOF_DOUBLE__ 8
+#define __cpp_exceptions 199711
+#define __FLT_MIN_10_EXP__ (-37)
+#define __FLT64_MIN__ 2.22507385850720138309023271733240406e-308F64
+#define __INT_LEAST32_WIDTH__ 32
+#define __INTMAX_TYPE__ long int
+#define __DEC128_MAX_EXP__ 6145
+#define __FLT32X_HAS_QUIET_NAN__ 1
+#define __ATOMIC_CONSUME 1
+#define __GNUC_MINOR__ 5
+#define __GLIBCXX_TYPE_INT_N_0 __int128
+#define __INT_FAST16_WIDTH__ 64
+#define __UINTMAX_MAX__ 0xffffffffffffffffUL
+#define __DEC32_MANT_DIG__ 7
+#define __FLT32X_DENORM_MIN__ 4.94065645841246544176568792868221372e-324F32x
+#define __DBL_MAX_10_EXP__ 308
+#define __LDBL_DENORM_MIN__ 6.47517511943802511092443895822764655e-4966L
+#define __INT16_C(c) c
+#define __ARM_ARCH_ISA_A64 1
+#define __STDC__ 1
+#define __FLT32X_DIG__ 15
+#define __PTRDIFF_TYPE__ long int
+#define __ATOMIC_SEQ_CST 5
+#define __UINT32_TYPE__ unsigned int
+#define __FLT32X_MIN_10_EXP__ (-307)
+#define __UINTPTR_TYPE__ long unsigned int
+#define __DEC64_SUBNORMAL_MIN__ 0.000000000000001E-383DD
+#define __DEC128_MANT_DIG__ 34
+#define __LDBL_MIN_10_EXP__ (-4931)
+#define __FLT128_EPSILON__ 1.92592994438723585305597794258492732e-34F128
+#define __SIZEOF_LONG_LONG__ 8
+#define __cpp_user_defined_literals 200809
+#define __FLT128_DECIMAL_DIG__ 36
+#define __GCC_ATOMIC_LLONG_LOCK_FREE 2
+#define __FLT32X_MIN__ 2.22507385850720138309023271733240406e-308F32x
+#define __LDBL_DIG__ 33
+#define __FLT_DECIMAL_DIG__ 9
+#define __UINT_FAST16_MAX__ 0xffffffffffffffffUL
+#define __GCC_ATOMIC_SHORT_LOCK_FREE 2
+#define __INT_LEAST64_WIDTH__ 64
+#define __UINT_FAST8_TYPE__ unsigned char
+#define _GNU_SOURCE 1
+#define __ATOMIC_ACQ_REL 4
+#define __ATOMIC_RELEASE 3

+ 2 - 2
src/ui/ui_ads_hmi/ADCIntelligentVehicle.cpp

@@ -1304,9 +1304,9 @@ void ADCIntelligentVehicle::paintEvent(QPaintEvent *)
         // draw plan trace end
 /////////////////////////////////////apollo add car icon  20200409
         QPixmap pix;
-        //pix.load("car.png");
+        pix.load("car.png");
 //        pix.load(":/ADCIntelligentVehicle/car1.png");
-//        painter->drawPixmap(435,667,30,67,pix);
+        painter->drawPixmap(435,667,30,67,pix);
 //        painter_small->drawPixmap(442,683,16,34,pix);
 ///////////////////////////////////////////////////////////////////
 

+ 0 - 2939
thirdpartylib/FastRTPS/include/fastcdr/Cdr.h

@@ -1,2939 +0,0 @@
-// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
-//
-// 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.
-
-#ifndef _FASTCDR_CDR_H_
-#define _FASTCDR_CDR_H_
-
-#include "fastcdr_dll.h"
-#include "FastBuffer.h"
-#include "exceptions/NotEnoughMemoryException.h"
-#include <stdint.h>
-#include <string>
-#include <vector>
-#include <map>
-#include <iostream>
-
-#if !__APPLE__ && !__FreeBSD__ && !__VXWORKS__
-#include <malloc.h>
-#else
-#include <stdlib.h>
-#endif
-
-#if HAVE_CXX0X
-#include <array>
-#endif
-
-namespace eprosima
-{
-    namespace fastcdr
-    {
-        /*!
-         * @brief This class offers an interface to serialize/deserialize some basic types using CDR protocol inside an eprosima::fastcdr::FastBuffer.
-         * @ingroup FASTCDRAPIREFERENCE
-         */
-        class Cdr_DllAPI Cdr
-        {
-            public:
-
-                //! @brief This enumeration represents the two kinds of CDR serialization supported by eprosima::fastcdr::CDR.
-                typedef enum
-                {
-                    //! @brief Common CORBA CDR serialization.
-                    CORBA_CDR,
-                    //! @brief DDS CDR serialization.
-                    DDS_CDR
-                } CdrType;
-
-                //! @brief This enumeration represents the two posible values of the flag that points if the content is a parameter list (only in DDS CDR).
-                typedef enum
-#ifdef HAVE_CXX0X
-                    : uint8_t
-#endif
-                    {
-                        //! @brief Specifies that the content is not a parameter list.
-                        DDS_CDR_WITHOUT_PL = 0x0,
-                        //! @brief Specifies that the content is a parameter list.
-                        DDS_CDR_WITH_PL = 0x2
-                    } DDSCdrPlFlag;
-
-                /*!
-                 * @brief This enumeration represents endianness types.
-                 */
-                typedef enum
-#ifdef HAVE_CXX0X
-                    : uint8_t
-#endif
-                    {
-                        //! @brief Big endianness.
-                        BIG_ENDIANNESS = 0x0,
-                        //! @brief Little endianness.
-                        LITTLE_ENDIANNESS = 0x1
-                    } Endianness;
-
-                //! @brief Default endiness in the system.
-                static const Endianness DEFAULT_ENDIAN;
-
-                /*!
-                 * @brief This class stores the current state of a CDR serialization.
-                 */
-                class Cdr_DllAPI state
-                {
-                    friend class Cdr;
-                    public:
-
-                    /*!
-                     * @brief Default constructor.
-                     */
-                    state(const Cdr &cdr);
-
-                    /*!
-                     * @brief Copy constructor.
-                     */
-                    state(const state&);
-
-                    private:
-
-                    state& operator=(const state&) = delete;
-
-                    //! @brief The position in the buffer when the state was created.
-                    const FastBuffer::iterator m_currentPosition;
-
-                    //! @brief The position from the aligment is calculated,  when the state was created..
-                    const FastBuffer::iterator m_alignPosition;
-
-                    //! @brief This attribute specified if it is needed to swap the bytes when the state was created..
-                    bool m_swapBytes;
-
-                    //! @brief Stores the last datasize serialized/deserialized when the state was created.
-                    size_t m_lastDataSize;
-                };
-
-                /*!
-                 * @brief This constructor creates an eprosima::fastcdr::Cdr object that can serialize/deserialize
-                 * the assigned buffer.
-                 *
-                 * @param cdrBuffer A reference to the buffer that contains (or will contain) the CDR representation.
-                 * @param endianness The initial endianness that will be used. The default value is the endianness of the system.
-                 * @param cdrType Represents the type of CDR that will be used in serialization/deserialization. The default value is CORBA CDR.
-                 */
-                Cdr(FastBuffer &cdrBuffer, const Endianness endianness = DEFAULT_ENDIAN, const CdrType cdrType = CORBA_CDR);
-
-                /*!
-                 * @brief This function reads the encapsulation of the CDR stream.
-                 *        If the CDR stream contains an encapsulation, then this function should be called before starting to deserialize.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 * @exception exception::BadParamException This exception is thrown when trying to deserialize an invalid value.
-                 */
-                Cdr& read_encapsulation();
-
-                /*!
-                 * @brief This function writes the encapsulation of the CDR stream.
-                 *        If the CDR stream should contain an encapsulation, then this function should be called before starting to serialize.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serialize_encapsulation();
-
-                /*!
-                 * @brief This function returns the parameter list flag when the CDR type is eprosima::fastcdr::DDS_CDR.
-                 * @return The flag that specifies if the content is a parameter list.
-                 */
-                DDSCdrPlFlag getDDSCdrPlFlag() const;
-
-                /*!
-                * @brief This function sets the parameter list flag when the CDR type is eprosima::fastcdr::DDS_CDR.
-                * @param plFlag New value for the flag that specifies if the content is a parameter list.
-                */
-                void setDDSCdrPlFlag(DDSCdrPlFlag plFlag);
-
-                /*!
-                 * @brief This function returns the option flags when the CDR type is eprosima::fastcdr::DDS_CDR.
-                 * @return The option flags.
-                 */
-                uint16_t getDDSCdrOptions() const;
-
-                /*!
-                * @brief This function sets the option flags when the CDR type is eprosima::fastcdr::DDS_CDR.
-                * @param options New value for the option flags.
-                */
-                void setDDSCdrOptions(uint16_t options);
-
-                /*!
-                * @brief This function sets the current endianness used by the CDR type.
-                * @param endianness The new endianness value.
-                */
-                void changeEndianness(Endianness endianness);
-
-                /*!
-                 * @brief This function returns the current endianness used by the CDR type.
-                 * @return The endianness.
-                 */
-                Endianness endianness() const { return static_cast<Endianness>(m_endianness); }
-
-                /*!
-                 * @brief This function skips a number of bytes in the CDR stream buffer.
-                 * @param numBytes The number of bytes that will be jumped.
-                 * @return True is returned when it works successfully. Otherwise, false is returned.
-                 */
-                bool jump(size_t numBytes);
-
-                /*!
-                 * @brief This function resets the current position in the buffer to the beginning.
-                 */
-                void reset();
-
-                /*!
-                 * @brief This function returns the pointer to the current used buffer.
-                 * @return Pointer to the starting position of the buffer.
-                 */
-                char* getBufferPointer();
-
-                /*!
-                 * @brief This function returns the current position in the CDR stream.
-                 * @return Pointer to the current position in the buffer.
-                 */
-                char* getCurrentPosition();
-
-                /*!
-                 * @brief This function returns the length of the serialized data inside the stream.
-                 * @return The length of the serialized data.
-                 */
-                inline size_t getSerializedDataLength() const { return m_currentPosition - m_cdrBuffer.begin();}
-
-                /*!
-                 * @brief Get the number of bytes needed to align a position to certain data size.
-                 * @param current_alignment Position to be aligned.
-                 * @param dataSize Size of next data to process (should be power of two).
-                 * @return Number of required alignment bytes.
-                 */
-                inline static size_t alignment(size_t current_alignment, size_t dataSize) { return (dataSize - (current_alignment % dataSize)) & (dataSize-1);}
-
-                /*!
-                 * @brief This function returns the current state of the CDR serialization process.
-                 * @return The current state of the CDR serialization process.
-                 */
-                state getState();
-
-                /*!
-                 * @brief This function sets a previous state of the CDR serialization process;
-                 * @param state Previous state that will be set.
-                 */
-                void setState(state &state);
-
-                /*!
-                 * @brief This function moves the alignment forward.
-                 * @param numBytes The number of bytes the alignment should advance.
-                 * @return True If alignment was moved successfully.
-                 */
-                bool moveAlignmentForward(size_t numBytes);
-
-                /*!
-                 * @brief This function resets the alignment to the current position in the buffer.
-                 */
-                inline void resetAlignment(){m_alignPosition = m_currentPosition;}
-
-                /*!
-                 * @brief This operator serializes an octet.
-                 * @param octet_t The value of the octet that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator<<(const uint8_t octet_t){return serialize(octet_t);}
-
-                /*!
-                 * @brief This operator serializes a character.
-                 * @param char_t The value of the character that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator<<(const char char_t){return serialize(char_t);}
-
-                /*!
-                 * @brief This operator serializes a int8_t.
-                 * @param int8 The value of the int8_t that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator<<(const int8_t int8){return serialize(int8);}
-
-                /*!
-                 * @brief This operator serializes an unsigned short.
-                 * @param ushort_t The value of the unsigned short that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator<<(const uint16_t ushort_t){return serialize(ushort_t);}
-
-                /*!
-                 * @brief This operator serializes a short.
-                 * @param short_t The value of the short that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator<<(const int16_t short_t){return serialize(short_t);}
-
-                /*!
-                 * @brief This operator serializes an unsigned long.
-                 * @param ulong_t The value of the unsigned long that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator<<(const uint32_t ulong_t){return serialize(ulong_t);}
-
-                /*!
-                 * @brief This operator serializes a long.
-                 * @param ulong_t The value of the long that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator<<(const int32_t long_t){return serialize(long_t);}
-
-                /*!
-                 * @brief This operator serializes a wide-char.
-                 * @param wchar The value of the wide-char that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator<<(const wchar_t wchar){return serialize(wchar);}
-
-                /*!
-                 * @brief This operator serializes an unsigned long long.
-                 * @param ulonglong_t The value of the unsigned long long that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator<<(const uint64_t ulonglong_t){return serialize(ulonglong_t);}
-
-                /*!
-                 * @brief This operator serializes a long long.
-                 * @param longlong_t The value of the long long that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator<<(const int64_t longlong_t){return serialize(longlong_t);}
-
-                /*!
-                 * @brief This operator serializes a float.
-                 * @param float_t The value of the float that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator<<(const float float_t){return serialize(float_t);}
-
-                /*!
-                 * @brief This operator serializes a double.
-                 * @param double_t The value of the double that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator<<(const double double_t){return serialize(double_t);}
-
-                /*!
-                 * @brief This operator serializes a long double.
-                 * @param ldouble_t The value of the long double that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator<<(const long double ldouble_t){return serialize(ldouble_t);}
-
-                /*!
-                 * @brief This operator serializes a boolean.
-                 * @param bool_t The value of the boolean that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator<<(const bool bool_t){return serialize(bool_t);}
-
-                /*!
-                 * @brief This operator serializes a null-terminated c-string.
-                 * @param string_t Pointer to the begining of the string that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator<<(const char *string_t){return serialize(string_t);}
-
-                /*!
-                 * @brief This operator serializes a null-terminated c-string.
-                 * @param string_t Pointer to the begining of the string that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator<<(char *string_t){return serialize(string_t);}
-
-                /*!
-                 * @brief This operator serializes a string.
-                 * @param string_t The string that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator<<(const std::string &string_t){return serialize(string_t);}
-
-                /*!
-                 * @brief This operator serializes a wstring.
-                 * @param string_t The wstring that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator<<(const std::wstring &string_t){return serialize(string_t);}
-
-#if HAVE_CXX0X
-                /*!
-                 * @brief This operator template is used to serialize arrays.
-                 * @param array_t The array that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                template<class _T, size_t _Size>
-                    inline Cdr& operator<<(const std::array<_T, _Size> &array_t){return serialize<_T, _Size>(array_t);}
-#endif
-
-                /*!
-                 * @brief This operator template is used to serialize sequences.
-                 * @param vector_t The sequence that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    inline Cdr& operator<<(const std::vector<_T> &vector_t){return serialize<_T>(vector_t);}
-
-                /*!
-                 * @brief This operator template is used to serialize maps.
-                 * @param map_t The map that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                template<class _K, class _T>
-                    inline Cdr& operator<<(const std::map<_K, _T> &map_t){return serialize<_K, _T>(map_t);}
-
-                /*!
-                 * @brief This operator template is used to serialize any other non-basic type.
-                 * @param type_t A reference to the object that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    inline Cdr& operator<<(const _T &type_t)
-                    {
-                        type_t.serialize(*this);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This operator deserializes an octet.
-                 * @param octet_t The variable that will store the octet read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator>>(uint8_t &octet_t){return deserialize(octet_t);}
-
-                /*!
-                 * @brief This operator deserializes a character.
-                 * @param char_t The variable that will store the character read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator>>(char &char_t){return deserialize(char_t);}
-
-                /*!
-                 * @brief This operator deserializes a int8_t.
-                 * @param int8 The variable that will store the int8_t read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator>>(int8_t &int8){return deserialize(int8);}
-
-                /*!
-                 * @brief This operator deserializes an unsigned short.
-                 * @param ushort_t The variable that will store the unsigned short read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator>>(uint16_t &ushort_t){return deserialize(ushort_t);}
-
-                /*!
-                 * @brief This operator deserializes a short.
-                 * @param short_t The variable that will store the short read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator>>(int16_t &short_t){return deserialize(short_t);}
-
-                /*!
-                 * @brief This operator deserializes an unsigned long.
-                 * @param ulong_t The variable that will store the unsigned long read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator>>(uint32_t &ulong_t){return deserialize(ulong_t);}
-
-                /*!
-                 * @brief This operator deserializes a long.
-                 * @param long_t The variable that will store the long read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator>>(int32_t &long_t){return deserialize(long_t);}
-
-                // TODO in FastCdr
-                /*!
-                 * @brief This operator deserializes a wide-char.
-                 * @param wchar The variable that will store the wide-char read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator>>(wchar_t &wchar){return deserialize(wchar);}
-
-                /*!
-                 * @brief This operator deserializes a unsigned long long.
-                 * @param ulonglong_t The variable that will store the unsigned long long read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator>>(uint64_t &ulonglong_t){return deserialize(ulonglong_t);}
-
-                /*!
-                 * @brief This operator deserializes a long long.
-                 * @param longlong_t The variable that will store the long long read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator>>(int64_t &longlong_t){return deserialize(longlong_t);}
-
-                /*!
-                 * @brief This operator deserializes a float.
-                 * @param float_t The variable that will store the float read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator>>(float &float_t){return deserialize(float_t);}
-
-                /*!
-                 * @brief This operator deserializes a double.
-                 * @param double_t The variable that will store the double read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator>>(double &double_t){return deserialize(double_t);}
-
-                /*!
-                 * @brief This operator deserializes a long double.
-                 * @param ldouble_t The variable that will store the long double read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator>>(long double &ldouble_t){return deserialize(ldouble_t);}
-
-                /*!
-                 * @brief This operator deserializes a boolean.
-                 * @param bool_t The variable that will store the boolean read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 * @exception exception::BadParamException This exception is thrown when trying to deserialize an invalid value.
-                 */
-                inline Cdr& operator>>(bool &bool_t){return deserialize(bool_t);}
-
-                /*!
-                 * @brief This operator deserializes a null-terminated c-string.
-                 * @param string_t The variable that will store the c-string read from the buffer.
-                 *                 Please note that a newly allocated string will be returned.
-                 *                 The caller should free the returned pointer when appropiate.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 * @exception exception::BadParamException This exception is thrown when trying to deserialize an invalid value.
-                 */
-                inline Cdr& operator>>(char *&string_t){return deserialize(string_t);}
-
-                /*!
-                 * @brief This operator deserializes a string.
-                 * @param string_t The variable that will store the string read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator>>(std::string &string_t){return deserialize(string_t);}
-
-                /*!
-                 * @brief This operator deserializes a string.
-                 * @param string_t The variable that will store the string read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& operator>>(std::wstring &string_t){return deserialize(string_t);}
-
-#if HAVE_CXX0X
-                /*!
-                 * @brief This operator template is used to deserialize arrays.
-                 * @param array_t The variable that will store the array read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                template<class _T, size_t _Size>
-                    inline Cdr& operator>>(std::array<_T, _Size> &array_t){return deserialize<_T, _Size>(array_t);}
-#endif
-
-                /*!
-                 * @brief This operator template is used to deserialize sequences.
-                 * @param vector_t The variable that will store the sequence read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    inline Cdr& operator>>(std::vector<_T> &vector_t){return deserialize<_T>(vector_t);}
-
-                /*!
-                 * @brief This operator template is used to deserialize maps.
-                 * @param map_t The variable that will store the map read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                template<class _K, class _T>
-                    inline Cdr& operator>>(std::map<_K, _T> &map_t){return deserialize<_K, _T>(map_t);}
-
-                /*!
-                 * @brief This operator template is used to deserialize any other non-basic type.
-                 * @param type_t The variable that will store the object read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    inline Cdr& operator>>(_T &type_t)
-                    {
-                        type_t.deserialize(*this);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function serializes an octet.
-                 * @param octet_t The value of the octet that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serialize(const uint8_t octet_t)
-                    {
-                        return serialize(static_cast<char>(octet_t));
-                    }
-
-                /*!
-                 * @brief This function serializes an octet with a different endianness.
-                 * @param octet_t The value of the octet that will be serialized in the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serialize(const uint8_t octet_t, Endianness endianness)
-                    {
-                        return serialize(static_cast<char>(octet_t), endianness);
-                    }
-
-                /*!
-                 * @brief This function serializes a character.
-                 * @param char_t The value of the character that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serialize(const char char_t);
-
-                /*!
-                 * @brief This function serializes a character with a different endianness.
-                 * @param char_t The value of the character that will be serialized in the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serialize(const char char_t, Endianness /*endianness*/)
-                    {
-                        return serialize(char_t);
-                    }
-
-                /*!
-                 * @brief This function serializes an int8_t.
-                 * @param int8 The value of the int8_t that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serialize(const int8_t int8)
-                    {
-                        return serialize(static_cast<char>(int8));
-                    }
-
-                /*!
-                 * @brief This function serializes an int8_t with a different endianness.
-                 * @param octet_t The value of the int8_t that will be serialized in the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serialize(const int8_t int8, Endianness endianness)
-                    {
-                        return serialize(static_cast<char>(int8), endianness);
-                    }
-
-                /*!
-                 * @brief This function serializes an unsigned short.
-                 * @param ushort_t The value of the unsigned short that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serialize(const uint16_t ushort_t)
-                    {
-                        return serialize(static_cast<int16_t>(ushort_t));
-                    }
-
-                /*!
-                 * @brief This function serializes an unsigned short with a different endianness.
-                 * @param ushort_t The value of the unsigned short that will be serialized in the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serialize(const uint16_t ushort_t, Endianness endianness)
-                    {
-                        return serialize(static_cast<int16_t>(ushort_t), endianness);
-                    }
-
-                /*!
-                 * @brief This function serializes a short.
-                 * @param short_t The value of the short that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serialize(const int16_t short_t);
-
-                /*!
-                 * @brief This function serializes a short with a different endianness.
-                 * @param short_t The value of the short that will be serialized in the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serialize(const int16_t short_t, Endianness endianness);
-
-                /*!
-                 * @brief This function serializes an unsigned long.
-                 * @param ulong_t The value of the unsigned long that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serialize(const uint32_t ulong_t)
-                    {
-                        return serialize(static_cast<int32_t>(ulong_t));
-                    }
-
-                /*!
-                 * @brief This function serializes an unsigned long with a different endianness.
-                 * @param ulong_t The value of the unsigned long that will be serialized in the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serialize(const uint32_t ulong_t, Endianness endianness)
-                    {
-                        return serialize(static_cast<int32_t>(ulong_t), endianness);
-                    }
-
-                /*!
-                 * @brief This function serializes a long.
-                 * @param long_t The value of the long that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serialize(const int32_t long_t);
-
-                /*!
-                 * @brief This function serializes a long with a different endianness.
-                 * @param long_t The value of the long that will be serialized in the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serialize(const int32_t long_t, Endianness endianness);
-
-                /*!
-                 * @brief This function serializes a wide-char.
-                 * @param wchar The value of the wide-char that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serialize(const wchar_t wchar)
-                    {
-                        return serialize(static_cast<uint32_t>(wchar));
-                    }
-
-                /*!
-                 * @brief This function serializes a wide-char with a different endianness.
-                 * @param wchar The value of the wide-char that will be serialized in the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serialize(const wchar_t wchar, Endianness endianness)
-                    {
-                        return serialize(static_cast<uint32_t>(wchar), endianness);
-                    }
-
-                /*!
-                 * @brief This function serializes an unsigned long long.
-                 * @param ulonglong_t The value of the unsigned long long that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serialize(const uint64_t ulonglong_t)
-                    {
-                        return serialize(static_cast<int64_t>(ulonglong_t));
-                    }
-
-                /*!
-                 * @brief This function serializes an unsigned long long with a different endianness.
-                 * @param ulonglong_t The value of the unsigned long long that will be serialized in the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serialize(const uint64_t ulonglong_t, Endianness endianness)
-                    {
-                        return serialize(static_cast<int64_t>(ulonglong_t), endianness);
-                    }
-
-                /*!
-                 * @brief This function serializes a long long.
-                 * @param longlong_t The value of the long long that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serialize(const int64_t longlong_t);
-
-                /*!
-                 * @brief This function serializes a long long with a different endianness.
-                 * @param longlong_t The value of the long long that will be serialized in the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serialize(const int64_t longlong_t, Endianness endianness);
-
-                /*!
-                 * @brief This function serializes a float.
-                 * @param float_t The value of the float that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serialize(const float float_t);
-
-                /*!
-                 * @brief This function serializes a float with a different endianness.
-                 * @param float_t The value of the float that will be serialized in the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serialize(const float float_t, Endianness endianness);
-
-                /*!
-                 * @brief This function serializes a double.
-                 * @param double_t The value of the double that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serialize(const double double_t);
-
-                /*!
-                 * @brief This function serializes a double with a different endianness.
-                 * @param double_t The value of the double that will be serialized in the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serialize(const double double_t, Endianness endianness);
-
-
-                /*!
-                 * @brief This function serializes a long double.
-                 * @param ldouble_t The value of the long double that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 * @note Due to internal representation differences, WIN32 and *NIX like systems are not compatible.
-                 */
-                Cdr& serialize(const long double ldouble_t);
-
-                /*!
-                 * @brief This function serializes a long double with a different endianness.
-                 * @param ldouble_t The value of the long double that will be serialized in the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 * @note Due to internal representation differences, WIN32 and *NIX like systems are not compatible.
-                 */
-                Cdr& serialize(const long double ldouble_t, Endianness endianness);
-
-                /*!
-                 * @brief This function serializes a boolean.
-                 * @param bool_t The value of the boolean that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serialize(const bool bool_t);
-
-                /*!
-                 * @brief This function serializes a boolean with a different endianness.
-                 * @param bool_t The value of the boolean that will be serialized in the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serialize(const bool bool_t, Endianness /*endianness*/)
-                    {
-                        return serialize(bool_t);
-                    }
-
-                /*!
-                 * @brief This function serializes a string.
-                 * @param string_t The pointer to the string that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline Cdr& serialize(char *string_t) { return serialize(static_cast<const char*>(string_t)); }
-
-                /*!
-                 * @brief This function serializes a string.
-                 * @param string_t The pointer to the string that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serialize(const char *string_t);
-
-                /*!
-                 * @brief This function serializes a wstring.
-                 * @param string_t The pointer to the wstring that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serialize(const wchar_t *string_t);
-
-                /*!
-                 * @brief This function serializes a string with a different endianness.
-                 * @param string_t The pointer to the string that will be serialized in the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serialize(const char *string_t, Endianness endianness);
-
-                /*!
-                 * @brief This function serializes a wstring with a different endianness.
-                 * @param string_t The pointer to the wstring that will be serialized in the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serialize(const wchar_t *string_t, Endianness endianness);
-
-                /*!
-                 * @brief This function serializes a std::string.
-                 * @param string_t The string that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serialize(const std::string &string_t) {return serialize(string_t.c_str());}
-
-                /*!
-                 * @brief This function serializes a std::wstring.
-                 * @param string_t The wstring that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serialize(const std::wstring &string_t) {return serialize(string_t.c_str());}
-
-                /*!
-                 * @brief This function serializes a std::string with a different endianness.
-                 * @param string_t The string that will be serialized in the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serialize(const std::string &string_t, Endianness endianness)  {return serialize(string_t.c_str(), endianness);}
-
-#if HAVE_CXX0X
-                /*!
-                 * @brief This function template serializes an array.
-                 * @param array_t The array that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                template<class _T, size_t _Size>
-                    inline Cdr& serialize(const std::array<_T, _Size> &array_t)
-                    { return serializeArray(array_t.data(), array_t.size());}
-
-                /*!
-                 * @brief This function template serializes an array with a different endianness.
-                 * @param array_t The array that will be serialized in the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                template<class _T, size_t _Size>
-                    inline Cdr& serialize(const std::array<_T, _Size> &array_t, Endianness endianness)
-                    { return serializeArray(array_t.data(), array_t.size(), endianness);}
-#endif
-
-#if !defined(_MSC_VER) && HAVE_CXX0X
-                /*!
-                 * @brief This function template serializes a sequence of booleans.
-                 * @param vector_t The sequence that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                template<class _T = bool>
-                    Cdr& serialize(const std::vector<bool> &vector_t)
-                    {
-                        return serializeBoolSequence(vector_t);
-                    }
-#endif
-
-                /*!
-                 * @brief This function template serializes a sequence.
-                 * @param vector_t The sequence that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    Cdr& serialize(const std::vector<_T> &vector_t)
-                    {
-                        state state_before_error(*this);
-
-                        *this << static_cast<int32_t>(vector_t.size());
-
-                        try
-                        {
-                            return serializeArray(vector_t.data(), vector_t.size());
-                        }
-                        catch(eprosima::fastcdr::exception::Exception &ex)
-                        {
-                            setState(state_before_error);
-                            ex.raise();
-                        }
-
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function template serializes a map.
-                 * @param map_t The map that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                template<class _K, class _T>
-                    Cdr& serialize(const std::map<_K, _T> &map_t)
-                    {
-                        state state_(*this);
-
-                        *this << static_cast<int32_t>(map_t.size());
-
-                        try
-                        {
-                            for (auto it_pair = map_t.begin(); it_pair != map_t.end(); ++it_pair)
-                            {
-                                *this << it_pair->first;
-                                *this << it_pair->second;
-                            }
-                            //return serializeArray(map_t.data(), map_t.size());
-                        }
-                        catch(eprosima::fastcdr::exception::Exception &ex)
-                        {
-                            setState(state_);
-                            ex.raise();
-                        }
-
-                        return *this;
-                    }
-
-#ifdef _MSC_VER
-                /*!
-                 * @brief This function template serializes a sequence of booleans.
-                 * @param vector_t The sequence that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                template<>
-                    Cdr& serialize<bool>(const std::vector<bool> &vector_t)
-                    {
-                        return serializeBoolSequence(vector_t);
-                    }
-#endif
-
-                /*!
-                 * @brief This function template serializes a sequence with a different endianness.
-                 * @param vector_t The sequence that will be serialized in the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    Cdr& serialize(const std::vector<_T> &vector_t, Endianness endianness)
-                    {
-                        bool auxSwap = m_swapBytes;
-                        m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
-
-                        try
-                        {
-                            serialize(vector_t);
-                            m_swapBytes = auxSwap;
-                        }
-                        catch(eprosima::fastcdr::exception::Exception &ex)
-                        {
-                            m_swapBytes = auxSwap;
-                            ex.raise();
-                        }
-
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function template serializes a non-basic object.
-                 * @param type_t The object that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    inline Cdr& serialize(const _T &type_t)
-                    {
-                        type_t.serialize(*this);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function serializes an array of octets.
-                 * @param octet_t The sequence of octets that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serializeArray(const uint8_t *octet_t, size_t numElements)
-                    {
-                        return serializeArray(reinterpret_cast<const char*>(octet_t), numElements);
-                    }
-
-                /*!
-                 * @brief This function serializes an array of octets with a different endianness.
-                 * @param octet_t The array of octets that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serializeArray(const uint8_t *octet_t, size_t numElements, Endianness /*endianness*/)
-                    {
-                        return serializeArray(reinterpret_cast<const char*>(octet_t), numElements);
-                    }
-
-                /*!
-                 * @brief This function serializes an array of characters.
-                 * @param char_t The array of characters that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serializeArray(const char *char_t, size_t numElements);
-
-                /*!
-                 * @brief This function serializes an array of characters with a different endianness.
-                 * @param char_t The array of characters that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serializeArray(const char *char_t, size_t numElements, Endianness /*endianness*/)
-                    {
-                        return serializeArray(char_t, numElements);
-                    }
-
-                /*!
-                 * @brief This function serializes an array of int8_t.
-                 * @param int8 The sequence of int8_t that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serializeArray(const int8_t *int8, size_t numElements)
-                    {
-                        return serializeArray(reinterpret_cast<const char*>(int8), numElements);
-                    }
-
-                /*!
-                 * @brief This function serializes an array of int8_t with a different endianness.
-                 * @param int8 The array of int8_t that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serializeArray(const int8_t *int8, size_t numElements, Endianness /*endianness*/)
-                    {
-                        return serializeArray(reinterpret_cast<const char*>(int8), numElements);
-                    }
-
-                /*!
-                 * @brief This function serializes an array of unsigned shorts.
-                 * @param ushort_t The array of unsigned shorts that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serializeArray(const uint16_t *ushort_t, size_t numElements)
-                    {
-                        return serializeArray(reinterpret_cast<const int16_t*>(ushort_t), numElements);
-                    }
-
-                /*!
-                 * @brief This function serializes an array of unsigned shorts with a different endianness.
-                 * @param ushort_t The array of unsigned shorts that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serializeArray(const uint16_t *ushort_t, size_t numElements, Endianness endianness)
-                    {
-                        return serializeArray(reinterpret_cast<const int16_t*>(ushort_t), numElements, endianness);
-                    }
-
-                /*!
-                 * @brief This function serializes an array of shorts.
-                 * @param short_t The array of shorts that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serializeArray(const int16_t *short_t, size_t numElements);
-
-                /*!
-                 * @brief This function serializes an array of shorts with a different endianness.
-                 * @param short_t The array of shorts that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serializeArray(const int16_t *short_t, size_t numElements, Endianness endianness);
-
-                /*!
-                 * @brief This function serializes an array of unsigned longs.
-                 * @param ulong_t The array of unsigned longs that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serializeArray(const uint32_t *ulong_t, size_t numElements)
-                    {
-                        return serializeArray(reinterpret_cast<const int32_t*>(ulong_t), numElements);
-                    }
-
-                /*!
-                 * @brief This function serializes an array of unsigned longs with a different endianness.
-                 * @param ulong_t The array of unsigned longs that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serializeArray(const uint32_t *ulong_t, size_t numElements, Endianness endianness)
-                    {
-                        return serializeArray(reinterpret_cast<const int32_t*>(ulong_t), numElements, endianness);
-                    }
-
-                /*!
-                 * @brief This function serializes an array of longs.
-                 * @param long_t The array of longs that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serializeArray(const int32_t *long_t, size_t numElements);
-
-                /*!
-                 * @brief This function serializes an array of longs with a different endianness.
-                 * @param long_t The array of longs that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serializeArray(const int32_t *long_t, size_t numElements, Endianness endianness);
-
-                /*!
-                 * @brief This function serializes an array of wide-chars.
-                 * @param wchar The array of wide-chars that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serializeArray(const wchar_t *wchar, size_t numElements);
-
-                /*!
-                 * @brief This function serializes an array of wide-chars with a different endianness.
-                 * @param wchar The array of longs that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serializeArray(const wchar_t *wchar, size_t numElements, Endianness endianness);
-
-                /*!
-                 * @brief This function serializes an array of unsigned long longs.
-                 * @param ulonglong_t The array of unsigned long longs that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serializeArray(const uint64_t *ulonglong_t, size_t numElements)
-                    {
-                        return serializeArray(reinterpret_cast<const int64_t*>(ulonglong_t), numElements);
-                    }
-
-                /*!
-                 * @brief This function serializes an array of unsigned long longs with a different endianness.
-                 * @param ulonglong_t The array of unsigned long longs that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serializeArray(const uint64_t *ulonglong_t, size_t numElements, Endianness endianness)
-                    {
-                        return serializeArray(reinterpret_cast<const int64_t*>(ulonglong_t), numElements, endianness);
-                    }
-
-                /*!
-                 * @brief This function serializes an array of long longs.
-                 * @param longlong_t The array of long longs that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serializeArray(const int64_t *longlong_t, size_t numElements);
-
-                /*!
-                 * @brief This function serializes an array of long longs with a different endianness.
-                 * @param longlong_t The array of long longs that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serializeArray(const int64_t *longlong_t, size_t numElements, Endianness endianness);
-
-                /*!
-                 * @brief This function serializes an array of floats.
-                 * @param float_t The array of floats that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serializeArray(const float *float_t, size_t numElements);
-
-                /*!
-                 * @brief This function serializes an array of floats with a different endianness.
-                 * @param float_t The array of floats that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serializeArray(const float *float_t, size_t numElements, Endianness endianness);
-
-                /*!
-                 * @brief This function serializes an array of doubles.
-                 * @param double_t The array of doubles that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serializeArray(const double *double_t, size_t numElements);
-
-                /*!
-                 * @brief This function serializes an array of doubles with a different endianness.
-                 * @param double_t The array of doubles that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serializeArray(const double *double_t, size_t numElements, Endianness endianness);
-
-                /*!
-                 * @brief This function serializes an array of long doubles.
-                 * @param ldouble_t The array of long doubles that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serializeArray(const long double *ldouble_t, size_t numElements);
-
-                /*!
-                 * @brief This function serializes an array of long doubles with a different endianness.
-                 * @param ldouble_t The array of long doubles that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serializeArray(const long double *ldouble_t, size_t numElements, Endianness endianness);
-
-                /*!
-                 * @brief This function serializes an array of booleans.
-                 * @param bool_t The array of booleans that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                Cdr& serializeArray(const bool *bool_t, size_t numElements);
-
-                /*!
-                 * @brief This function serializes an array of booleans with a different endianness.
-                 * @param bool_t The array of booleans that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serializeArray(const bool *bool_t, size_t numElements, Endianness /*endianness*/)
-                    {
-                        return serializeArray(bool_t, numElements);
-                    }
-
-                /*!
-                 * @brief This function serializes an array of strings.
-                 * @param string_t The array of strings that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serializeArray(const std::string *string_t, size_t numElements)
-                    {
-                        for(size_t count = 0; count < numElements; ++count)
-                            serialize(string_t[count].c_str());
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function serializes an array of wide-strings.
-                 * @param string_t The array of wide-strings that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serializeArray(const std::wstring *string_t, size_t numElements)
-                    {
-                        for(size_t count = 0; count < numElements; ++count)
-                            serialize(string_t[count].c_str());
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function serializes an array of strings with a different endianness.
-                 * @param string_t The array of strings that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serializeArray(const std::string *string_t, size_t numElements, Endianness endianness)
-                    {
-                        bool auxSwap = m_swapBytes;
-                        m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
-
-                        try
-                        {
-                            serializeArray(string_t, numElements);
-                            m_swapBytes = auxSwap;
-                        }
-                        catch(eprosima::fastcdr::exception::Exception &ex)
-                        {
-                            m_swapBytes = auxSwap;
-                            ex.raise();
-                        }
-
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function serializes an array of wide-strings with a different endianness.
-                 * @param string_t The array of wide-strings that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& serializeArray(const std::wstring *string_t, size_t numElements, Endianness endianness)
-                    {
-                        bool auxSwap = m_swapBytes;
-                        m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
-
-                        try
-                        {
-                            serializeArray(string_t, numElements);
-                            m_swapBytes = auxSwap;
-                        }
-                        catch(eprosima::fastcdr::exception::Exception &ex)
-                        {
-                            m_swapBytes = auxSwap;
-                            ex.raise();
-                        }
-
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function template serializes an array of sequences of objects.
-                 * @param vector_t The array of sequences of objects that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    Cdr& serializeArray(const std::vector<_T> *vector_t, size_t numElements)
-                    {
-                        for(size_t count = 0; count < numElements; ++count)
-                            serialize(vector_t[count]);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function template serializes an array of non-basic objects.
-                 * @param type_t The array of objects that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    Cdr& serializeArray(const _T *type_t, size_t numElements)
-                    {
-                        for(size_t count = 0; count < numElements; ++count)
-                            type_t[count].serialize(*this);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function template serializes an array of non-basic objects with a different endianness.
-                 * @param type_t The array of objects that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    Cdr& serializeArray(const _T *type_t, size_t numElements, Endianness endianness)
-                    {
-                        bool auxSwap = m_swapBytes;
-                        m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
-
-                        try
-                        {
-                            serializeArray(type_t, numElements);
-                            m_swapBytes = auxSwap;
-                        }
-                        catch(eprosima::fastcdr::exception::Exception &ex)
-                        {
-                            m_swapBytes = auxSwap;
-                            ex.raise();
-                        }
-
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function template serializes a raw sequence.
-                 * @param sequence_t Pointer to the sequence that will be serialized in the buffer.
-                 * @param numElements The number of elements contained in the sequence.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    Cdr& serializeSequence(const _T *sequence_t, size_t numElements)
-                    {
-                        state state_before_error(*this);
-
-                        serialize(static_cast<int32_t>(numElements));
-
-                        try
-                        {
-                            return serializeArray(sequence_t, numElements);
-                        }
-                        catch(eprosima::fastcdr::exception::Exception &ex)
-                        {
-                            setState(state_before_error);
-                            ex.raise();
-                        }
-
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function template serializes a raw sequence with a different endianness.
-                 * @param sequence_t Pointer to the sequence that will be serialized in the buffer.
-                 * @param numElements The number of elements contained in the sequence.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    Cdr& serializeSequence(const _T *sequence_t, size_t numElements, Endianness endianness)
-                    {
-                        bool auxSwap = m_swapBytes;
-                        m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
-
-                        try
-                        {
-                            serializeSequence(sequence_t, numElements);
-                            m_swapBytes = auxSwap;
-                        }
-                        catch(eprosima::fastcdr::exception::Exception &ex)
-                        {
-                            m_swapBytes = auxSwap;
-                            ex.raise();
-                        }
-
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function deserializes an octet.
-                 * @param octet_t The variable that will store the octet read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserialize(uint8_t &octet_t)
-                    {
-                        return deserialize(reinterpret_cast<char&>(octet_t));
-                    }
-
-                /*!
-                 * @brief This function deserializes an octet with a different endianness.
-                 * @param octet_t The variable that will store the octet read from the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserialize(uint8_t &octet_t, Endianness endianness)
-                    {
-                        return deserialize(reinterpret_cast<char&>(octet_t), endianness);
-                    }
-
-                /*!
-                 * @brief This function deserializes a character.
-                 * @param char_t The variable that will store the character read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserialize(char &char_t);
-
-                /*!
-                 * @brief This function deserializes a character with a different endianness.
-                 * @param char_t The variable that will store the character read from the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserialize(char &char_t, Endianness /*endianness*/)
-                    {
-                        return deserialize(char_t);
-                    }
-
-                /*!
-                 * @brief This function deserializes an int8_t.
-                 * @param int8 The variable that will store the int8_t read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserialize(int8_t &int8)
-                    {
-                        return deserialize(reinterpret_cast<char&>(int8));
-                    }
-
-                /*!
-                 * @brief This function deserializes an int8_t with a different endianness.
-                 * @param int8 The variable that will store the int8_t read from the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserialize(int8_t &int8, Endianness endianness)
-                    {
-                        return deserialize(reinterpret_cast<char&>(int8), endianness);
-                    }
-
-                /*!
-                 * @brief This function deserializes an unsigned short.
-                 * @param ushort_t The variable that will store the unsigned short read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserialize(uint16_t &ushort_t)
-                    {
-                        return deserialize(reinterpret_cast<int16_t&>(ushort_t));
-                    }
-
-                /*!
-                 * @brief This function deserializes an unsigned short with a different endianness.
-                 * @param ushort_t The variable that will store the unsigned short read from the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserialize(uint16_t &ushort_t, Endianness endianness)
-                    {
-                        return deserialize(reinterpret_cast<int16_t&>(ushort_t), endianness);
-                    }
-
-                /*!
-                 * @brief This function deserializes a short.
-                 * @param short_t The variable that will store the short read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserialize(int16_t &short_t);
-
-                /*!
-                 * @brief This function deserializes a short with a different endianness.
-                 * @param short_t The variable that will store the short read from the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserialize(int16_t &short_t, Endianness endianness);
-
-                /*!
-                 * @brief This function deserializes an unsigned long.
-                 * @param ulong_t The variable that will store the unsigned long read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserialize(uint32_t &ulong_t)
-                    {
-                        return deserialize(reinterpret_cast<int32_t&>(ulong_t));
-                    }
-
-                /*!
-                 * @brief This function deserializes an unsigned long with a different endianness.
-                 * @param ulong_t The variable that will store the unsigned long read from the buffer..
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserialize(uint32_t &ulong_t, Endianness endianness)
-                    {
-                        return deserialize(reinterpret_cast<int32_t&>(ulong_t), endianness);
-                    }
-
-                /*!
-                 * @brief This function deserializes a long.
-                 * @param long_t The variable that will store the long read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserialize(int32_t &long_t);
-
-                /*!
-                 * @brief This function deserializes a long with a different endianness.
-                 * @param long_t The variable that will store the long read from the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserialize(int32_t &long_t, Endianness endianness);
-
-                /*!
-                 * @brief This function deserializes a wide-char.
-                 * @param wchar The variable that will store the wide-char read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserialize(wchar_t &wchar)
-                    {
-                        uint32_t ret;
-                        deserialize(ret);
-                        wchar = static_cast<wchar_t>(ret);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function deserializes a wide-char with a different endianness.
-                 * @param wchar The variable that will store the wide-char read from the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserialize(wchar_t &wchar, Endianness endianness)
-                    {
-                        uint32_t ret;
-                        deserialize(ret, endianness);
-                        wchar = static_cast<wchar_t>(ret);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function deserializes an unsigned long long.
-                 * @param ulonglong_t The variable that will store the unsigned long long read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserialize(uint64_t &ulonglong_t)
-                    {
-                        return deserialize(reinterpret_cast<int64_t&>(ulonglong_t));
-                    }
-
-                /*!
-                 * @brief This function deserializes an unsigned long long with a different endianness.
-                 * @param ulonglong_t The variable that will store the unsigned long long read from the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserialize(uint64_t &ulonglong_t, Endianness endianness)
-                    {
-                        return deserialize(reinterpret_cast<int64_t&>(ulonglong_t), endianness);
-                    }
-
-                /*!
-                 * @brief This function deserializes a long long.
-                 * @param longlong_t The variable that will store the long long read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserialize(int64_t &longlong_t);
-
-                /*!
-                 * @brief This function deserializes a long long with a different endianness.
-                 * @param longlong_t The variable that will store the long long read from the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserialize(int64_t &longlong_t, Endianness endianness);
-
-                /*!
-                 * @brief This function deserializes a float.
-                 * @param float_t The variable that will store the float read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserialize(float &float_t);
-
-                /*!
-                 * @brief This function deserializes a float with a different endianness.
-                 * @param float_t The variable that will store the float read from the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserialize(float &float_t, Endianness endianness);
-
-                /*!
-                 * @brief This function deserializes a double.
-                 * @param double_t The variable that will store the double read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserialize(double &double_t);
-
-                /*!
-                 * @brief This function deserializes a double with a different endianness.
-                 * @param double_t The variable that will store the double read from the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserialize(double &double_t, Endianness endianness);
-
-                /*!
-                 * @brief This function deserializes a long double.
-                 * @param ldouble_t The variable that will store the long double read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 * @note Due to internal representation differences, WIN32 and *NIX like systems are not compatible.
-                 */
-                Cdr& deserialize(long double &ldouble_t);
-
-                /*!
-                 * @brief This function deserializes a long double with a different endianness.
-                 * @param ldouble_t The variable that will store the long double read from the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 * @note Due to internal representation differences, WIN32 and *NIX like systems are not compatible.
-                 */
-                Cdr& deserialize(long double &ldouble_t, Endianness endianness);
-
-                /*!
-                 * @brief This function deserializes a boolean.
-                 * @param bool_t The variable that will store the boolean read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 * @exception exception::BadParamException This exception is thrown when trying to deserialize an invalid value.
-                 */
-                Cdr& deserialize(bool &bool_t);
-
-                /*!
-                 * @brief This function deserializes a boolean with a different endianness.
-                 * @param bool_t The variable that will store the boolean read from the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 * @exception exception::BadParamException This exception is thrown when trying to deserialize an invalid value.
-                 */
-                inline
-                    Cdr& deserialize(bool &bool_t, Endianness /*endianness*/)
-                    {
-                        return deserialize(bool_t);
-                    };
-
-                /*!
-                 * @brief This function deserializes a string.
-                 * This function allocates memory to store the string. The user pointer will be set to point this allocated memory.
-                 * The user will have to free this allocated memory using free()
-                 * @param string_t The pointer that will point to the string read from the buffer.
-                 * The user will have to free the allocated memory using free()
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserialize(char *&string_t);
-
-                /*!
-                 * @brief This function deserializes a wide string.
-                 * This function allocates memory to store the wide string. The user pointer will be set to point this allocated memory.
-                 * The user will have to free this allocated memory using free()
-                 * @param string_t The pointer that will point to the wide string read from the buffer.
-                 * The user will have to free the allocated memory using free()
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserialize(wchar_t *&string_t);
-
-                /*!
-                 * @brief This function deserializes a string with a different endianness.
-                 * This function allocates memory to store the string. The user pointer will be set to point this allocated memory.
-                 * The user will have to free this allocated memory using free()
-                 * @param string_t The pointer that will point to the string read from the buffer.
-                 * The user will have to free the allocated memory using free()
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserialize(char *&string_t, Endianness endianness);
-
-                /*!
-                 * @brief This function deserializes a wide string with a different endianness.
-                 * This function allocates memory to store the wide string. The user pointer will be set to point this allocated memory.
-                 * The user will have to free this allocated memory using free()
-                 * @param string_t The pointer that will point to the wide string read from the buffer.
-                 * The user will have to free the allocated memory using free()
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserialize(wchar_t *&string_t, Endianness endianness);
-
-                /*!
-                 * @brief This function deserializes a std::string.
-                 * @param string_t The variable that will store the string read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserialize(std::string &string_t)
-                    {
-                        uint32_t length = 0;
-                        const char *str = readString(length);
-                        string_t = std::string(str, length);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function deserializes a std::string.
-                 * @param string_t The variable that will store the string read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserialize(std::wstring &string_t)
-                    {
-                        uint32_t length = 0;
-                        string_t = readWString(length);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function deserializes a string with a different endianness.
-                 * @param string_t The variable that will store the string read from the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserialize(std::string &string_t, Endianness endianness)
-                    {
-                        bool auxSwap = m_swapBytes;
-                        m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
-
-                        try
-                        {
-                            deserialize(string_t);
-                            m_swapBytes = auxSwap;
-                        }
-                        catch(eprosima::fastcdr::exception::Exception &ex)
-                        {
-                            m_swapBytes = auxSwap;
-                            ex.raise();
-                        }
-
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function deserializes a string with a different endianness.
-                 * @param string_t The variable that will store the string read from the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserialize(std::wstring &string_t, Endianness endianness)
-                    {
-                        bool auxSwap = m_swapBytes;
-                        m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
-
-                        try
-                        {
-                            deserialize(string_t);
-                            m_swapBytes = auxSwap;
-                        }
-                        catch(eprosima::fastcdr::exception::Exception &ex)
-                        {
-                            m_swapBytes = auxSwap;
-                            ex.raise();
-                        }
-
-                        return *this;
-                    }
-
-#if HAVE_CXX0X
-                /*!
-                 * @brief This function template deserializes an array.
-                 * @param array_t The variable that will store the array read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                template<class _T, size_t _Size>
-                    inline Cdr& deserialize(std::array<_T, _Size> &array_t)
-                    { return deserializeArray(array_t.data(), array_t.size());}
-
-                /*!
-                 * @brief This function template deserializes an array with a different endianness.
-                 * @param array_t The variable that will store the array read from the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                template<class _T, size_t _Size>
-                    inline Cdr& deserialize(std::array<_T, _Size> &array_t, Endianness endianness)
-                    { return deserializeArray(array_t.data(), array_t.size(), endianness);}
-#endif
-
-#if !defined(_MSC_VER) && HAVE_CXX0X
-                /*!
-                 * @brief This function template deserializes a sequence.
-                 * @param vector_t The variable that will store the sequence read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                template<class _T = bool>
-                    Cdr& deserialize(std::vector<bool> &vector_t)
-                    {
-                        return deserializeBoolSequence(vector_t);
-                    }
-#endif
-
-                /*!
-                 * @brief This function template deserializes a sequence.
-                 * @param vector_t The variable that will store the sequence read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    Cdr& deserialize(std::vector<_T> &vector_t)
-                    {
-                        uint32_t seqLength = 0;
-                        state state_before_error(*this);
-
-                        *this >> seqLength;
-
-                        try
-                        {
-                            vector_t.resize(seqLength);
-                            return deserializeArray(vector_t.data(), vector_t.size());
-                        }
-                        catch(eprosima::fastcdr::exception::Exception &ex)
-                        {
-                            setState(state_before_error);
-                            ex.raise();
-                        }
-
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function template deserializes a map.
-                 * @param map_t The variable that will store the map read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                template<class _K, class _T>
-                    Cdr& deserialize(std::map<_K, _T> &map_t)
-                    {
-                        uint32_t seqLength = 0;
-                        state state_(*this);
-
-                        *this >> seqLength;
-
-                        try
-                        {
-                            for (uint32_t i = 0; i < seqLength; ++i)
-                            {
-                                _K key;
-                                _T value;
-                                *this >> key;
-                                *this >> value;
-                                map_t.emplace(std::pair<_K, _T>(std::move(key), std::move(value)));
-                            }
-                        }
-                        catch(eprosima::fastcdr::exception::Exception &ex)
-                        {
-                            setState(state_);
-                            ex.raise();
-                        }
-
-                        return *this;
-                    }
-
-#ifdef _MSC_VER
-                /*!
-                 * @brief This function template deserializes a sequence.
-                 * @param vector_t The variable that will store the sequence read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                template<>
-                    Cdr& deserialize<bool>(std::vector<bool> &vector_t)
-                    {
-                        return deserializeBoolSequence(vector_t);
-                    }
-#endif
-
-                /*!
-                 * @brief This function template deserializes a sequence with a different endianness.
-                 * @param vector_t The variable that will store the sequence read from the buffer.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    Cdr& deserialize(std::vector<_T> &vector_t, Endianness endianness)
-                    {
-                        bool auxSwap = m_swapBytes;
-                        m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
-
-                        try
-                        {
-                            deserialize(vector_t);
-                            m_swapBytes = auxSwap;
-                        }
-                        catch(exception::Exception &ex)
-                        {
-                            m_swapBytes = auxSwap;
-                            ex.raise();
-                        }
-
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function template deserializes a non-basic object.
-                 * @param type_t The variable that will store the object read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    inline Cdr& deserialize(_T &type_t)
-                    {
-                        type_t.deserialize(*this);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function deserializes an array of octets.
-                 * @param octet_t The variable that will store the array of octets read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserializeArray(uint8_t *octet_t, size_t numElements)
-                    {
-                        return deserializeArray(reinterpret_cast<char*>(octet_t), numElements);
-                    }
-
-                /*!
-                 * @brief This function deserializes an array of octets with a different endianness.
-                 * @param octet_t The variable that will store the array of octets read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserializeArray(uint8_t *octet_t, size_t numElements, Endianness endianness)
-                    {
-                        return deserializeArray(reinterpret_cast<char*>(octet_t), numElements, endianness);
-                    }
-
-                /*!
-                 * @brief This function deserializes an array of characters.
-                 * @param char_t The variable that will store the array of characters read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserializeArray(char *char_t, size_t numElements);
-
-                /*!
-                 * @brief This function deserializes an array of characters with a different endianness.
-                 * @param char_t The variable that will store the array of characters read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserializeArray(char *char_t, size_t numElements, Endianness /*endianness*/)
-                    {
-                        return deserializeArray(char_t, numElements);
-                    }
-
-                /*!
-                 * @brief This function deserializes an array of int8_t.
-                 * @param int8 The variable that will store the array of int8_t read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserializeArray(int8_t *int8, size_t numElements)
-                    {
-                        return deserializeArray(reinterpret_cast<char*>(int8), numElements);
-                    }
-
-                /*!
-                 * @brief This function deserializes an array of int8_t with a different endianness.
-                 * @param int8 The variable that will store the array of int8_t read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserializeArray(int8_t *int8, size_t numElements, Endianness endianness)
-                    {
-                        return deserializeArray(reinterpret_cast<char*>(int8), numElements, endianness);
-                    }
-
-                /*!
-                 * @brief This function deserializes an array of unsigned shorts.
-                 * @param ushort_t The variable that will store the array of unsigned shorts read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserializeArray(uint16_t *ushort_t, size_t numElements)
-                    {
-                        return deserializeArray(reinterpret_cast<int16_t*>(ushort_t), numElements);
-                    }
-
-                /*!
-                 * @brief This function deserializes an array of unsigned shorts with a different endianness.
-                 * @param ushort_t The variable that will store the array of unsigned shorts read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserializeArray(uint16_t *ushort_t, size_t numElements, Endianness endianness)
-                    {
-                        return deserializeArray(reinterpret_cast<int16_t*>(ushort_t), numElements, endianness);
-                    }
-
-                /*!
-                 * @brief This function deserializes an array of shorts.
-                 * @param short_t The variable that will store the array of shorts read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserializeArray(int16_t *short_t, size_t numElements);
-
-                /*!
-                 * @brief This function deserializes an array of shorts with a different endianness.
-                 * @param short_t The variable that will store the array of shorts read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserializeArray(int16_t *short_t, size_t numElements, Endianness endianness);
-
-                /*!
-                 * @brief This function deserializes an array of unsigned longs.
-                 * @param ulong_t The variable that will store the array of unsigned longs read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserializeArray(uint32_t *ulong_t, size_t numElements)
-                    {
-                        return deserializeArray(reinterpret_cast<int32_t*>(ulong_t), numElements);
-                    }
-
-                /*!
-                 * @brief This function deserializes an array of unsigned longs with a different endianness.
-                 * @param ulong_t The variable that will store the array of unsigned longs read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserializeArray(uint32_t *ulong_t, size_t numElements, Endianness endianness)
-                    {
-                        return deserializeArray(reinterpret_cast<int32_t*>(ulong_t), numElements, endianness);
-                    }
-
-                /*!
-                 * @brief This function deserializes an array of longs.
-                 * @param long_t The variable that will store the array of longs read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserializeArray(int32_t *long_t, size_t numElements);
-
-                /*!
-                 * @brief This function deserializes an array of longs with a different endianness.
-                 * @param long_t The variable that will store the array of longs read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserializeArray(int32_t *long_t, size_t numElements, Endianness endianness);
-
-                /*!
-                 * @brief This function deserializes an array of wide-chars.
-                 * @param wchar The variable that will store the array of wide-chars read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserializeArray(wchar_t *wchar, size_t numElements);
-
-                /*!
-                 * @brief This function deserializes an array of wide-chars with a different endianness.
-                 * @param wchar The variable that will store the array of wide-chars read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserializeArray(wchar_t *wchar, size_t numElements, Endianness endianness);
-
-                /*!
-                 * @brief This function deserializes an array of unsigned long longs.
-                 * @param ulonglong_t The variable that will store the array of unsigned long longs read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserializeArray(uint64_t *ulonglong_t, size_t numElements)
-                    {
-                        return deserializeArray(reinterpret_cast<int64_t*>(ulonglong_t), numElements);
-                    }
-
-                /*!
-                 * @brief This function deserializes an array of unsigned long longs with a different endianness.
-                 * @param ulonglong_t The variable that will store the array of unsigned long longs read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserializeArray(uint64_t *ulonglong_t, size_t numElements, Endianness endianness)
-                    {
-                        return deserializeArray(reinterpret_cast<int64_t*>(ulonglong_t), numElements, endianness);
-                    }
-
-                /*!
-                 * @brief This function deserializes an array of long longs.
-                 * @param longlong_t The variable that will store the array of long longs read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserializeArray(int64_t *longlong_t, size_t numElements);
-
-                /*!
-                 * @brief This function deserializes an array of long longs with a different endianness.
-                 * @param longlong_t The variable that will store the array of long longs read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserializeArray(int64_t *longlong_t, size_t numElements, Endianness endianness);
-
-                /*!
-                 * @brief This function deserializes an array of floats.
-                 * @param float_t The variable that will store the array of floats read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserializeArray(float *float_t, size_t numElements);
-
-                /*!
-                 * @brief This function deserializes an array of floats with a different endianness.
-                 * @param float_t The variable that will store the array of floats read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserializeArray(float *float_t, size_t numElements, Endianness endianness);
-
-                /*!
-                 * @brief This function deserializes an array of doubles.
-                 * @param double_t The variable that will store the array of doubles read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserializeArray(double *double_t, size_t numElements);
-
-                /*!
-                 * @brief This function deserializes an array of doubles with a different endianness.
-                 * @param double_t The variable that will store the array of doubles read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserializeArray(double *double_t, size_t numElements, Endianness endianness);
-
-                /*!
-                 * @brief This function deserializes an array of long doubles.
-                 * @param ldouble_t The variable that will store the array of long doubles read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserializeArray(long double *ldouble_t, size_t numElements);
-
-                /*!
-                 * @brief This function deserializes an array of long doubles with a different endianness.
-                 * @param ldouble_t The variable that will store the array of long doubles read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserializeArray(long double *ldouble_t, size_t numElements, Endianness endianness);
-
-                /*!
-                 * @brief This function deserializes an array of booleans.
-                 * @param bool_t The variable that will store the array of booleans read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                Cdr& deserializeArray(bool *bool_t, size_t numElements);
-
-                /*!
-                 * @brief This function deserializes an array of booleans with a different endianness.
-                 * @param bool_t The variable that will store the array of booleans read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserializeArray(bool *bool_t, size_t numElements, Endianness /*endianness*/)
-                    {
-                        return deserializeArray(bool_t, numElements);
-                    }
-
-                /*!
-                 * @brief This function deserializes an array of strings.
-                 * @param string_t The variable that will store the array of strings read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserializeArray(std::string *string_t, size_t numElements)
-                    {
-                        for(size_t count = 0; count < numElements; ++count)
-                            deserialize(string_t[count]);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function deserializes an array of wide-strings.
-                 * @param string_t The variable that will store the array of wide-strings read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserializeArray(std::wstring *string_t, size_t numElements)
-                    {
-                        for(size_t count = 0; count < numElements; ++count)
-                            deserialize(string_t[count]);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function deserializes an array of strings with a different endianness.
-                 * @param string_t The variable that will store the array of strings read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserializeArray(std::string *string_t, size_t numElements, Endianness endianness)
-                    {
-                        bool auxSwap = m_swapBytes;
-                        m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
-
-                        try
-                        {
-                            deserializeArray(string_t, numElements);
-                            m_swapBytes = auxSwap;
-                        }
-                        catch(eprosima::fastcdr::exception::Exception &ex)
-                        {
-                            m_swapBytes = auxSwap;
-                            ex.raise();
-                        }
-
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function deserializes an array of wide-strings with a different endianness.
-                 * @param string_t The variable that will store the array of wide-strings read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                inline
-                    Cdr& deserializeArray(std::wstring *string_t, size_t numElements, Endianness endianness)
-                    {
-                        bool auxSwap = m_swapBytes;
-                        m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
-
-                        try
-                        {
-                            deserializeArray(string_t, numElements);
-                            m_swapBytes = auxSwap;
-                        }
-                        catch(eprosima::fastcdr::exception::Exception &ex)
-                        {
-                            m_swapBytes = auxSwap;
-                            ex.raise();
-                        }
-
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function deserializes an array of sequences of objects.
-                 * @param string_t The variable that will store the array of sequences of objects read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    Cdr& deserializeArray(std::vector<_T> *vector_t, size_t numElements)
-                    {
-                        for(size_t count = 0; count < numElements; ++count)
-                            deserialize(vector_t[count]);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function template deserializes an array of non-basic objects.
-                 * @param type_t The variable that will store the array of objects read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    Cdr& deserializeArray(_T *type_t, size_t numElements)
-                    {
-                        for(size_t count = 0; count < numElements; ++count)
-                            type_t[count].deserialize(*this);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function template deserializes an array of non-basic objects with a different endianness.
-                 * @param type_t The variable that will store the array of objects read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    Cdr& deserializeArray(_T *type_t, size_t numElements, Endianness endianness)
-                    {
-                        bool auxSwap = m_swapBytes;
-                        m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
-
-                        try
-                        {
-                            deserializeArray(type_t, numElements);
-                            m_swapBytes = auxSwap;
-                        }
-                        catch(eprosima::fastcdr::exception::Exception &ex)
-                        {
-                            m_swapBytes = auxSwap;
-                            ex.raise();
-                        }
-
-                        return *this;
-                    }
-
-#if !defined(_MSC_VER) && HAVE_CXX0X
-                /*!
-                 * @brief This function template deserializes a string sequence.
-                 * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory.
-                 * The user will have to free this allocated memory using free()
-                 * @param sequence_t The pointer that will store the sequence read from the buffer.
-                 * @param numElements This variable return the number of elements of the sequence.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                template<class _T = std::string>
-                    Cdr& deserializeSequence(std::string *&sequence_t, size_t &numElements)
-                    {
-                        return deserializeStringSequence(sequence_t, numElements);
-                    }
-
-                /*!
-                 * @brief This function template deserializes a wide-string sequence.
-                 * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory.
-                 * The user will have to free this allocated memory using free()
-                 * @param sequence_t The pointer that will store the sequence read from the buffer.
-                 * @param numElements This variable return the number of elements of the sequence.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                template<class _T = std::wstring>
-                    Cdr& deserializeSequence(std::wstring *&sequence_t, size_t &numElements)
-                    {
-                        return deserializeWStringSequence(sequence_t, numElements);
-                    }
-#endif
-
-                /*!
-                 * @brief This function template deserializes a raw sequence.
-                 * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory.
-                 * The user will have to free this allocated memory using free()
-                 * @param sequence_t The pointer that will store the sequence read from the buffer.
-                 * @param numElements This variable return the number of elements of the sequence.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    Cdr& deserializeSequence(_T *&sequence_t, size_t &numElements)
-                    {
-                        uint32_t seqLength = 0;
-                        state state_before_error(*this);
-
-                        deserialize(seqLength);
-
-                        try
-                        {
-                            sequence_t = reinterpret_cast<_T*>(calloc(seqLength, sizeof(_T)));
-                            deserializeArray(sequence_t, seqLength);
-                        }
-                        catch(eprosima::fastcdr::exception::Exception &ex)
-                        {
-                            free(sequence_t);
-                            sequence_t = NULL;
-                            setState(state_before_error);
-                            ex.raise();
-                        }
-
-                        numElements = seqLength;
-                        return *this;
-                    }
-
-#ifdef _MSC_VER
-                /*!
-                 * @brief This function template deserializes a string sequence.
-                 * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory.
-                 * The user will have to free this allocated memory using free()
-                 * @param sequence_t The pointer that will store the sequence read from the buffer.
-                 * @param numElements This variable return the number of elements of the sequence.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                template<>
-                    Cdr& deserializeSequence<std::string>(std::string *&sequence_t, size_t &numElements)
-                    {
-                        return deserializeStringSequence(sequence_t, numElements);
-                    }
-
-                /*!
-                 * @brief This function template deserializes a wide-string sequence.
-                 * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory.
-                 * The user will have to free this allocated memory using free()
-                 * @param sequence_t The pointer that will store the sequence read from the buffer.
-                 * @param numElements This variable return the number of elements of the sequence.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                template<>
-                    Cdr& deserializeSequence<std::wstring>(std::wstring *&sequence_t, size_t &numElements)
-                    {
-                        return deserializeWStringSequence(sequence_t, numElements);
-                    }
-#endif
-
-                /*!
-                 * @brief This function template deserializes a raw sequence with a different endianness.
-                 * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory.
-                 * The user will have to free this allocated memory using free()
-                 * @param sequence_t The pointer that will store the sequence read from the buffer.
-                 * @param numElements This variable return the number of elements of the sequence.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    Cdr& deserializeSequence(_T *&sequence_t, size_t &numElements, Endianness endianness)
-                    {
-                        bool auxSwap = m_swapBytes;
-                        m_swapBytes = (m_swapBytes && (m_endianness == endianness)) || (!m_swapBytes && (m_endianness != endianness));
-
-                        try
-                        {
-                            deserializeSequence(sequence_t, numElements);
-                            m_swapBytes = auxSwap;
-                        }
-                        catch(eprosima::fastcdr::exception::Exception &ex)
-                        {
-                            m_swapBytes = auxSwap;
-                            ex.raise();
-                        }
-
-                        return *this;
-                    }
-
-            private:
-
-                Cdr(const Cdr&) = delete;
-
-                Cdr& operator=(const Cdr&) = delete;
-
-                Cdr& serializeBoolSequence(const std::vector<bool> &vector_t);
-
-                Cdr& deserializeBoolSequence(std::vector<bool> &vector_t);
-
-                Cdr& deserializeStringSequence(std::string *&sequence_t, size_t &numElements);
-
-                Cdr& deserializeWStringSequence(std::wstring *&sequence_t, size_t &numElements);
-
-#if HAVE_CXX0X
-                /*!
-                 * @brief This function template detects the content type of the STD container array and serializes the array.
-                 * @param array_t The array that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                template<class _T, size_t _Size>
-                    Cdr& serializeArray(const std::array<_T, _Size> *array_t, size_t numElements)
-                    {
-                        return serializeArray(array_t->data(), numElements * array_t->size());
-                    }
-
-                /*!
-                 * @brief This function template detects the content type of the STD container array and serializes the array with a different endianness.
-                 * @param array_t The array that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size.
-                 */
-                template<class _T, size_t _Size>
-                    Cdr& serializeArray(const std::array<_T, _Size> *array_t, size_t numElements, Endianness endianness)
-                    {
-                        return serializeArray(array_t->data(), numElements * array_t->size(), endianness);
-                    }
-
-                /*!
-                 * @brief This function template detects the content type of the STD container array and deserializes the array.
-                 * @param array_t The variable that will store the array read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                template<class _T, size_t _Size>
-                    Cdr& deserializeArray(std::array<_T, _Size> *array_t, size_t numElements)
-                    {
-                        return deserializeArray(array_t->data(), numElements * array_t->size());
-                    }
-
-                /*!
-                 * @brief This function template detects the content type of STD container array and deserializes the array with a different endianness.
-                 * @param array_t The variable that will store the array read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @param endianness Endianness that will be used in the serialization of this value.
-                 * @return Reference to the eprosima::fastcdr::Cdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 */
-                template<class _T, size_t _Size>
-                    Cdr& deserializeArray(std::array<_T, _Size> *array_t, size_t numElements, Endianness endianness)
-                    {
-                        return deserializeArray(array_t->data(), numElements * array_t->size(), endianness);
-                    }
-#endif
-
-                /*!
-                 * @brief This function returns the extra bytes regarding the allignment.
-                 * @param dataSize The size of the data that will be serialized.
-                 * @return The size needed for the aligment.
-                 */
-                inline size_t alignment(size_t dataSize) const {return dataSize > m_lastDataSize ? (dataSize - ((m_currentPosition - m_alignPosition) % dataSize)) & (dataSize-1) : 0;}
-
-                /*!
-                 * @brief This function jumps the number of bytes of the alignment. These bytes should be calculated with the function eprosima::fastcdr::Cdr::alignment.
-                 * @param align The number of bytes to be skipped.
-                 */
-                inline void makeAlign(size_t align){m_currentPosition += align;}
-
-                /*!
-                 * @brief This function resizes the internal buffer. It only applies if the FastBuffer object was created with the default constructor.
-                 * @param minSizeInc Minimun size increase for the internal buffer
-                 * @return True if the resize was succesful, false if it was not
-                 */
-                bool resize(size_t minSizeInc);
-
-                //TODO
-                const char* readString(uint32_t &length);
-                const std::wstring readWString(uint32_t &length);
-
-                //! @brief Reference to the buffer that will be serialized/deserialized.
-                FastBuffer &m_cdrBuffer;
-
-                //! @brief The type of CDR that will be use in serialization/deserialization.
-                CdrType m_cdrType;
-
-                //! @brief Using DDS_CDR type, this attribute stores if the stream buffer contains a parameter list or not.
-                DDSCdrPlFlag m_plFlag;
-
-                //! @brief This attribute stores the option flags when the CDR type is DDS_CDR;
-                uint16_t m_options;
-
-                //! @brief The endianness that will be applied over the buffer.
-                uint8_t m_endianness;
-
-                //! @brief This attribute specifies if it is needed to swap the bytes.
-                bool m_swapBytes;
-
-                //! @brief Stores the last datasize serialized/deserialized. It's used to optimize.
-                size_t m_lastDataSize;
-
-                //! @brief The current position in the serialization/deserialization process.
-                FastBuffer::iterator m_currentPosition;
-
-                //! @brief The position from where the aligment is calculated.
-                FastBuffer::iterator m_alignPosition;
-
-                //! @brief The last position in the buffer;
-                FastBuffer::iterator m_lastPosition;
-        };
-    } //namespace fastcdr
-} //namespace eprosima
-
-#endif // _CDR_CDR_H_

+ 0 - 312
thirdpartylib/FastRTPS/include/fastcdr/FastBuffer.h

@@ -1,312 +0,0 @@
-// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
-//
-// 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.
-
-#ifndef _FASTCDR_CDRBUFFER_H_
-#define _FASTCDR_CDRBUFFER_H_
-
-#include "fastcdr_dll.h"
-#include <stdint.h>
-#include <cstdio>
-#include <string.h>
-#include <cstddef>
-#include <utility>
-
-inline uint32_t size_to_uint32(size_t val) {
-  #if defined(_WIN32) || !defined(FASTCDR_ARM32)
-  // On 64 bit platforms and all Windows architectures (because of C4267), explicitly cast.
-  return static_cast<uint32_t>(val);
-  #else
-  // Skip useless cast on 32-bit builds.
-  return val;
-  #endif
-}
-
-namespace eprosima
-{
-    namespace fastcdr
-    {
-        /*!
-         * @brief This class implements the iterator used to go through a FastBuffer.
-         */
-        class Cdr_DllAPI _FastBuffer_iterator
-        {
-            public:
-
-                /*!
-                 * @brief Default constructor.
-                 * The iterator points any position.
-                 */
-                _FastBuffer_iterator() : m_buffer(NULL), m_currentPosition(NULL) {}
-
-                /*!
-                 * @brief Constructor.
-                 * The iterator points to the indicated position.
-                 * @param buffer Pointer to the raw buffer.
-                 * @param index Position of the raw buffer where the iterator will point.
-                 */
-                explicit _FastBuffer_iterator(char *buffer, size_t index) : m_buffer(buffer), m_currentPosition(&m_buffer[index]){}
-
-                /*!
-                 * @brief This operator changes the iterator's raw buffer.
-                 * This operator makes the iterator point to the same position but in another raw buffer.
-                 * The new raw buffer is the same than the source iterator's.
-                 * @param iterator The source iterator. The iterator will use the source iterator's raw buffer after this operation.
-                 */
-                inline
-                    void operator<<(const _FastBuffer_iterator &iterator)
-                    {
-                        ptrdiff_t diff = m_currentPosition - m_buffer;
-                        m_buffer = iterator.m_buffer;
-                        m_currentPosition = m_buffer + diff;
-                    }
-
-                /*!
-                 * @brief This operator changes the position where the iterator points.
-                 * This operator takes the index of the source iterator, but the iterator continues using its raw buffer.
-                 * @param The source iterator. The iterator will use the source's iterator index to point to its own raw buffer.
-                 */
-                inline
-                    void operator>>(const _FastBuffer_iterator &iterator)
-                    {
-                        ptrdiff_t diff = iterator.m_currentPosition - iterator.m_buffer;
-                        m_currentPosition = m_buffer + diff;
-                    }
-
-                /*!
-                 * @brief This operator copies a data in the raw buffer.
-                 * The copy uses the size of the data type.
-                 * @param data Data to be copied. Cannot be NULL.
-                 */
-                template<typename _T>
-                    inline
-                    void operator<<(const _T &data)
-                    {
-                        memcpy(m_currentPosition, &data, sizeof(_T));
-                    }
-
-                /*!
-                 * @brief This operator copies data from the raw buffer to a variable.
-                 * The copy uses the size of the data type.
-                 * @param data Data to be filled.
-                 */
-                template<typename _T>
-                    inline
-                    void operator>>(_T &data)
-                    {
-                        memcpy(&data, m_currentPosition, sizeof(_T));
-                    }
-
-                /*!
-                 * @brief This function copies a buffer into the raw buffer.
-                 * @param src The source buffer.
-                 * @param size The number of bytes to be copied.
-                 */
-                inline
-                    void memcopy(const void* src, const size_t size)
-                    {
-                        if (size > 0) {
-                            memcpy(m_currentPosition, src, size);
-                        }
-                    }
-
-                /*!
-                 * @brief This function copies from the raw buffer to a external buffer.
-                 * @param dst The destination buffer.
-                 * @param size The size of bytes to be copied.
-                 */
-                inline
-                    void rmemcopy(void* dst, const size_t size)
-                    {
-                        if (size > 0) {
-                            memcpy(dst, m_currentPosition, size);
-                        }
-                    }
-
-                /*!
-                 * @brief This function increments the position where the iterator points.
-                 * @param numBytes Number of bytes the iterator moves the position.
-                 */
-                inline
-                    void operator+=(size_t numBytes)
-                    {
-                        m_currentPosition += numBytes;
-                    }
-
-                /*!
-                 * @brief This operator returns the subtraction of the current interator's position and the source iterator's position.
-                 * @iterator Source iterator whose position is subtracted to the current iterator's position.
-                 * @return The result of subtract the current iterator's position and the source iterator's position.
-                 */
-                inline
-                    size_t operator-(const _FastBuffer_iterator &it) const
-                    {
-                        return static_cast<size_t>(m_currentPosition - it.m_currentPosition);
-                    }
-
-                /*!
-                 * @brief This function increments the iterator in one the position.
-                 * @return The current iterator.
-                 */
-                inline
-                    _FastBuffer_iterator operator++()
-                    {
-                        ++m_currentPosition;
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function increments the iterator in one the position.
-                 * @return The current iterator.
-                 */
-                inline
-                    _FastBuffer_iterator operator++(int)
-                    {
-                        _FastBuffer_iterator tmp = *this;
-                        ++*this;
-                        return tmp;
-                    }
-
-                /*!
-                 * @brief This function returns the current position in the raw buffer.
-                 * @return The current position in the raw buffer.
-                 */
-                inline
-                    char* operator&()
-                    {
-                        return m_currentPosition;
-                    }
-
-            private:
-
-                //! Pointer to the raw buffer.
-                char *m_buffer;
-
-                //! Current position in the raw buffer.
-                char *m_currentPosition;
-        };
-
-        /*!
-         * @brief This class represents a stream of bytes that contains (or will contain)
-         * serialized data. This class is used by the serializers to serialize
-         * or deserialize using their representation.
-         * @ingroup FASTCDRAPIREFERENCE
-         */
-        class Cdr_DllAPI FastBuffer
-        {
-            public:
-                typedef _FastBuffer_iterator iterator;
-
-                /*!
-                 * @brief This constructor creates an internal stream and assigns it to the eprosima::fastcdr::FastBuffers object.
-                 * The user can obtain this internal stream using the function eprosima::fastcdr::FastBuffers::getBuffer(). Be careful because this internal stream
-                 * is deleted in the destruction of the eprosima::fastcdr::FastBuffers object.
-                 */
-                FastBuffer();
-
-                /*!
-                 * @brief This constructor assigns the user's stream of bytes to the eprosima::fastcdr::FastBuffers object.
-                 * The user's stream will be used to serialize.
-                 *
-                 * @param buffer The user's buffer that will be used. This buffer is not deallocated in the object's destruction. Cannot be NULL.
-                 * @param bufferSize The length of user's buffer.
-                 */
-                FastBuffer(char* const buffer, const size_t bufferSize);
-
-                //! Move constructor
-                FastBuffer(FastBuffer&& fbuffer) : m_buffer(nullptr), m_bufferSize(0), m_internalBuffer(true)
-                {
-                    std::swap(m_buffer, fbuffer.m_buffer);
-                    std::swap(m_bufferSize, fbuffer.m_bufferSize);
-                    std::swap(m_internalBuffer, fbuffer.m_internalBuffer);
-                }
-
-                //! Move assignment
-                FastBuffer& operator=(FastBuffer&& fbuffer)
-                {
-                    std::swap(m_buffer, fbuffer.m_buffer);
-                    std::swap(m_bufferSize, fbuffer.m_bufferSize);
-                    std::swap(m_internalBuffer, fbuffer.m_internalBuffer);
-                    return *this;
-                }
-
-                /*!
-                 * @brief Default destructor.
-                 */
-                virtual ~FastBuffer();
-
-                /*!
-                 * @brief This function returns the stream that the eprosima::fastcdr::FastBuffers uses to serialize data.
-                 * @return The stream used by eprosima::fastcdr::FastBuffers to serialize data.
-                 */
-                inline char* getBuffer() const { return m_buffer;}
-
-                /*!
-                 * @brief This function returns the size of the allocated memory of the stream that the eprosima::fastcdr::FastBuffers uses to serialize data.
-                 * @return The size of the allocated memory of the stream used by the eprosima::fastcdr::FastBuffers to serialize data.
-                 */
-                inline size_t getBufferSize() const { return m_bufferSize;}
-
-                /*!
-                 * @brief This function returns a iterator that points to the begining of the stream.
-                 * @return The new iterator.
-                 */
-                inline
-                    iterator begin()
-                    {
-                        return (iterator(m_buffer, 0));
-                    }
-
-                /*!
-                 * @brief This function returns a iterator that points to the end of the stream.
-                 * @return The new iterator.
-                 */
-                inline
-                    iterator end()
-                    {
-                        return (iterator(m_buffer, m_bufferSize));
-                    }
-
-                /*!
-                 * @brief This function reserves memory for the internal raw buffer. It will only do so if the buffer is not yet allocated and is not externally set.
-                 * @param size The size of the memory to be allocated.
-                 * @return True if the allocation suceeded. False if the raw buffer was set externally or is already allocated.
-                 */
-                bool reserve(size_t size);
-
-                /*!
-                 * @brief This function resizes the raw buffer. It will call the user's defined function for this purpose.
-                 * @param minSizeInc The minimun growth expected of the current raw buffer.
-                 * @return True if the operation works. False if it does not.
-                 */
-                bool resize(size_t minSizeInc);
-
-            private:
-
-                FastBuffer(const FastBuffer&) = delete;
-
-                FastBuffer& operator=(const FastBuffer&) = delete;
-
-                //! @brief Pointer to the stream of bytes that contains the serialized data.
-                char *m_buffer;
-
-                //! @brief The total size of the user's buffer.
-                size_t m_bufferSize;
-
-                //! @brief This variable indicates if the managed buffer is internal or is from the user.
-                bool m_internalBuffer;
-        };
-    } //namespace fastcdr
-} //namespace eprosima
-
-#endif // _FASTCDR_FASTCDRBUFFER_H_

+ 0 - 1756
thirdpartylib/FastRTPS/include/fastcdr/FastCdr.h

@@ -1,1756 +0,0 @@
-// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
-//
-// 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.
-
-#ifndef _FASTCDR_FASTCDR_H_
-#define _FASTCDR_FASTCDR_H_
-
-#include "fastcdr_dll.h"
-#include "FastBuffer.h"
-#include "exceptions/NotEnoughMemoryException.h"
-#include <stdint.h>
-#include <string>
-#include <vector>
-
-#if !__APPLE__ && !__FreeBSD__ && !__VXWORKS__
-#include <malloc.h>
-#else
-#include <stdlib.h>
-#endif
-
-#if HAVE_CXX0X
-#include <array>
-#endif
-
-namespace eprosima
-{
-    namespace fastcdr
-    {
-        /*!
-         * @brief This class offers an interface to serialize/deserialize some basic types using a modified CDR protocol inside a eprosima::FastBuffer.
-         * This modified CDR protocol provides a serialization mechanism much faster than common CDR protocol, because it doesn't use alignment.
-         * @ingroup FASTCDRAPIREFERENCE
-         */
-        class Cdr_DllAPI FastCdr
-        {
-            public:
-
-                /*!
-                 * @brief This class stores the current state of a CDR serialization.
-                 */
-                class Cdr_DllAPI state
-                {
-                    friend class FastCdr;
-                    public:
-
-                    /*!
-                     * @brief Default constructor.
-                     */
-                    state(const FastCdr &fastcdr);
-
-                    /*!
-                     * @brief Copy constructor.
-                     */
-                    state(const state&);
-
-                    private:
-
-                    state& operator=(const state&) = delete;
-
-                    //! @brief The position in the buffer when the state was created.
-                    const FastBuffer::iterator m_currentPosition;
-                };
-                /*!
-                 * @brief This constructor creates a eprosima::fastcdr::FastCdr object that can serialize/deserialize
-                 * the assigned buffer.
-                 *
-                 * @param cdrBuffer A reference to the buffer that contains (or will contain) the CDR representation.
-                 */
-                FastCdr(FastBuffer &cdrBuffer);
-
-                /*!
-                 * @brief This function skips a number of bytes in the CDR stream buffer.
-                 * @param numBytes The number of bytes that will be jumped.
-                 * @return True is returned when the jump operation works successfully. Otherwise, false is returned.
-                 */
-                bool jump(size_t numBytes);
-
-                /*!
-                 * @brief This function resets the current position in the buffer to the begining.
-                 */
-                void reset();
-
-                /*!
-                 * @brief This function returns the current position in the CDR stream.
-                 * @return Pointer to the current position in the buffer.
-                 */
-                char* getCurrentPosition();
-
-                /*!
-                 * @brief This function returns the length of the serialized data inside the stream.
-                 * @return The length of the serialized data.
-                 */
-                inline size_t getSerializedDataLength() const { return m_currentPosition - m_cdrBuffer.begin();}
-
-                /*!
-                 * @brief This function returns the current state of the CDR stream.
-                 * @return The current state of the buffer.
-                 */
-                FastCdr::state getState();
-
-                /*!
-                 * @brief This function sets a previous state of the CDR stream;
-                 * @param state Previous state that will be set again.
-                 */
-                void setState(FastCdr::state &state);
-
-                /*!
-                 * @brief This operator serializes an octet.
-                 * @param octet_t The value of the octet that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator<<(const uint8_t octet_t){return serialize(octet_t);}
-
-                /*!
-                 * @brief This operator serializes a character.
-                 * @param char_t The value of the character that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator<<(const char char_t){return serialize(char_t);}
-
-                /*!
-                 * @brief This operator serializes a int8_t.
-                 * @param int8 The value of the int8_t that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator<<(const int8_t int8){return serialize(int8);}
-
-                /*!
-                 * @brief This operator serializes an unsigned short.
-                 * @param ushort_t The value of the unsigned short that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator<<(const uint16_t ushort_t){return serialize(ushort_t);}
-
-                /*!
-                 * @brief This operator serializes a short.
-                 * @param short_t The value of the short that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator<<(const int16_t short_t){return serialize(short_t);}
-
-                /*!
-                 * @brief This operator serializes an unsigned long.
-                 * @param ulong_t The value of the unsigned long that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator<<(const uint32_t ulong_t){return serialize(ulong_t);}
-
-                /*!
-                 * @brief This operator serializes a long.
-                 * @param long_t The value of the long that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator<<(const int32_t long_t){return serialize(long_t);}
-
-                /*!
-                 * @brief This operator serializes a wide-char.
-                 * @param wchar The value of the wide-char that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator<<(const wchar_t wchar){return serialize(wchar);}
-
-                /*!
-                 * @brief This operator serializes an unsigned long long.
-                 * @param ulonglong_t The value of the unsigned long long that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator<<(const uint64_t ulonglong_t){return serialize(ulonglong_t);}
-
-                /*!
-                 * @brief This operator serializes a long long.
-                 * @param longlong_t The value of the long long that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator<<(const int64_t longlong_t){return serialize(longlong_t);}
-
-                /*!
-                 * @brief This operator serializes a float.
-                 * @param float_t The value of the float that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator<<(const float float_t){return serialize(float_t);}
-
-                /*!
-                 * @brief This operator serializes a ldouble.
-                 * @param double_t The value of the double that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator<<(const double double_t){return serialize(double_t);}
-
-                /*!
-                 * @brief This operator serializes a long double.
-                 * @param ldouble_t The value of the long double that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator<<(const long double ldouble_t){return serialize(ldouble_t);}
-
-                /*!
-                 * @brief This operator serializes a boolean.
-                 * @param bool_t The value of the boolean that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator<<(const bool bool_t){return serialize(bool_t);}
-
-                /*!
-                 * @brief This operator serializes a null-terminated string.
-                 * @param string_t The value of the string that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator<<(const char *string_t){return serialize(string_t);}
-
-                /*!
-                 * @brief This operator serializes a null-terminated wide-string.
-                 * @param string_t The value of the wide-string that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator<<(const wchar_t *string_t){return serialize(string_t);}
-
-                /*!
-                 * @brief This operator serializes a string.
-                 * @param string_t The string that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator<<(const std::string &string_t){return serialize(string_t);}
-
-                /*!
-                 * @brief This operator serializes a wstring.
-                 * @param string_t The wstring that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator<<(const std::wstring &string_t){return serialize(string_t);}
-
-#if HAVE_CXX0X
-                /*!
-                 * @brief This operator template is used to serialize arrays.
-                 * @param array_t The array that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                template<class _T, size_t _Size>
-                    inline FastCdr& operator<<(const std::array<_T, _Size> &array_t){return serialize<_T, _Size>(array_t);}
-#endif
-
-                /*!
-                 * @brief This operator template is used to serialize sequences.
-                 * @param vector_t The sequence that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    inline FastCdr& operator<<(const std::vector<_T> &vector_t){return serialize<_T>(vector_t);}
-
-                /*!
-                 * @brief This operator template is used to serialize non-basic types.
-                 * @param type_t The object that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    inline FastCdr& operator<<(const _T &type_t)
-                    {
-                        type_t.serialize(*this);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This operator deserializes an octet.
-                 * @param octet_t The variable that will store the octet read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator>>(uint8_t &octet_t){return deserialize(octet_t);}
-
-                /*!
-                 * @brief This operator deserializes a character.
-                 * @param char_t The variable that will store the character read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator>>(char &char_t){return deserialize(char_t);}
-
-                /*!
-                 * @brief This operator deserializes an int8_t.
-                 * @param int8 The variable that will store the int8_t read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator>>(int8_t &int8){return deserialize(int8);}
-
-                /*!
-                 * @brief This operator deserializes an unsigned short.
-                 * @param ushort_t The variable that will store the unsigned short read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator>>(uint16_t &ushort_t){return deserialize(ushort_t);}
-
-                /*!
-                 * @brief This operator deserializes a short.
-                 * @param short_t The variable that will store the short read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator>>(int16_t &short_t){return deserialize(short_t);}
-
-                /*!
-                 * @brief This operator deserializes an unsigned long.
-                 * @param ulong_t The variable that will store the unsigned long read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator>>(uint32_t &ulong_t){return deserialize(ulong_t);}
-
-                /*!
-                 * @brief This operator deserializes a long.
-                 * @param long_t The variable that will store the long read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator>>(int32_t &long_t){return deserialize(long_t);}
-
-                /*!
-                 * @brief This operator deserializes a wide-char.
-                 * @param wchar The variable that will store the wide-char read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator>>(wchar_t &wchar){return deserialize(wchar);}
-
-                /*!
-                 * @brief This operator deserializes an unsigned long long.
-                 * @param ulonglong_t The variable that will store the unsigned long long read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator>>(uint64_t &ulonglong_t){return deserialize(ulonglong_t);}
-
-                /*!
-                 * @brief This operator deserializes a long long.
-                 * @param longlong_t The variable that will store the long long read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator>>(int64_t &longlong_t){return deserialize(longlong_t);}
-
-                /*!
-                 * @brief This operator deserializes a float.
-                 * @param float_t The variable that will store the float read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator>>(float &float_t){return deserialize(float_t);}
-
-                /*!
-                 * @brief This operator deserializes a double.
-                 * @param double_t The variable that will store the double read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator>>(double &double_t){return deserialize(double_t);}
-
-                /*!
-                 * @brief This operator deserializes a long double.
-                 * @param ldouble_t The variable that will store the long double read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator>>(long double &ldouble_t){return deserialize(ldouble_t);}
-
-                /*!
-                 * @brief This operator deserializes a boolean.
-                 * @param bool_t The variable that will store the boolean read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 * @exception exception::BadParamException This exception is thrown when trying to deserialize in an invalid value.
-                 */
-                inline FastCdr& operator>>(bool &bool_t){return deserialize(bool_t);}
-
-                /*!
-                 * @brief This operator deserializes a null-terminated c-string.
-                 * @param string_t The variable that will store the c-string read from the buffer.
-                 *                 Please note that a newly allocated string will be returned.
-                 *                 The caller should free the returned pointer when appropiate.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size.
-                 * @exception exception::BadParamException This exception is thrown when trying to deserialize an invalid value.
-                 */
-                inline FastCdr& operator>>(char *&string_t){return deserialize(string_t);}
-
-                /*!
-                 * @brief This operator deserializes a string.
-                 * @param string_t The variable that will store the string read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator>>(std::string &string_t){return deserialize(string_t);}
-
-                /*!
-                 * @brief This operator deserializes a wstring.
-                 * @param string_t The variable that will store the wstring read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline FastCdr& operator>>(std::wstring &string_t){return deserialize(string_t);}
-
-#if HAVE_CXX0X
-                /*!
-                 * @brief This operator template is used to deserialize arrays.
-                 * @param array_t The variable that will store the array read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                template<class _T, size_t _Size>
-                    inline FastCdr& operator>>(std::array<_T, _Size> &array_t){return deserialize<_T, _Size>(array_t);}
-#endif
-
-                /*!
-                 * @brief This operator template is used to deserialize sequences.
-                 * @param vector_t The variable that will store the sequence read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    inline FastCdr& operator>>(std::vector<_T> &vector_t){return deserialize<_T>(vector_t);}
-
-                /*!
-                 * @brief This operator template is used to deserialize non-basic types.
-                 * @param type_t The variable that will store the object read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    inline FastCdr& operator>>(_T &type_t)
-                    {
-                        type_t.deserialize(*this);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function serializes an octet.
-                 * @param octet_t The value of the octet that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& serialize(const uint8_t octet_t)
-                    {
-                        return serialize(static_cast<char>(octet_t));
-                    }
-
-                /*!
-                 * @brief This function serializes a character.
-                 * @param char_t The value of the character that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& serialize(const char char_t)
-                    {
-                        if(((m_lastPosition - m_currentPosition) >= sizeof(char_t)) || resize(sizeof(char_t)))
-                        {
-                            m_currentPosition++ << char_t;
-                            return *this;
-                        }
-
-                        throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
-                    }
-
-                /*!
-                 * @brief This function serializes an int8_t.
-                 * @param int8 The value of the int8_t that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& serialize(const int8_t int8)
-                    {
-                        return serialize(static_cast<char>(int8));
-                    }
-
-                /*!
-                 * @brief This function serializes an unsigned short.
-                 * @param ushort_t The value of the unsigned short that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& serialize(const uint16_t ushort_t)
-                    {
-                        return serialize(static_cast<int16_t>(ushort_t));
-                    }
-
-                /*!
-                 * @brief This function serializes a short.
-                 * @param short_t The value of the short that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& serialize(const int16_t short_t)
-                    {
-                        if(((m_lastPosition - m_currentPosition) >= sizeof(short_t)) || resize(sizeof(short_t)))
-                        {
-                            m_currentPosition << short_t;
-                            m_currentPosition += sizeof(short_t);
-
-                            return *this;
-                        }
-
-                        throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
-                    }
-
-                /*!
-                 * @brief This function serializes an unsigned long.
-                 * @param ulong_t The value of the unsigned long that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& serialize(const uint32_t ulong_t)
-                    {
-                        return serialize(static_cast<int32_t>(ulong_t));
-                    }
-
-                /*!
-                 * @brief This function serializes a long.
-                 * @param long_t The value of the long that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& serialize(const int32_t long_t)
-                    {
-                        if(((m_lastPosition - m_currentPosition) >= sizeof(long_t)) || resize(sizeof(long_t)))
-                        {
-                            m_currentPosition << long_t;
-                            m_currentPosition += sizeof(long_t);
-
-                            return *this;
-                        }
-
-                        throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
-                    }
-
-                /*!
-                 * @brief This function serializes a wide-char.
-                 * @param wchar The value of the wide-char that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& serialize(const wchar_t wchar)
-                    {
-                        return serialize(static_cast<uint32_t>(wchar));
-                    }
-
-                /*!
-                 * @brief This function serializes an unsigned long long.
-                 * @param ulonglong_t The value of the unsigned long long that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& serialize(const uint64_t ulonglong_t)
-                    {
-                        return serialize(static_cast<int64_t>(ulonglong_t));
-                    }
-
-                /*!
-                 * @brief This function serializes a long long.
-                 * @param longlong_t The value of the long long that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& serialize(const int64_t longlong_t)
-                    {
-                        if(((m_lastPosition - m_currentPosition) >= sizeof(longlong_t)) || resize(sizeof(longlong_t)))
-                        {
-                            m_currentPosition << longlong_t;
-                            m_currentPosition += sizeof(longlong_t);
-
-                            return *this;
-                        }
-
-                        throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
-                    }
-
-                /*!
-                 * @brief This function serializes a float.
-                 * @param float_t The value of the float that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& serialize(const float float_t)
-                    {
-                        if(((m_lastPosition - m_currentPosition) >= sizeof(float_t)) || resize(sizeof(float_t)))
-                        {
-                            m_currentPosition << float_t;
-                            m_currentPosition += sizeof(float_t);
-
-                            return *this;
-                        }
-
-                        throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
-                    }
-
-                /*!
-                 * @brief This function serializes a double.
-                 * @param double_t The value of the double that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& serialize(const double double_t)
-                    {
-                        if(((m_lastPosition - m_currentPosition) >= sizeof(double_t)) || resize(sizeof(double_t)))
-                        {
-                            m_currentPosition << double_t;
-                            m_currentPosition += sizeof(double_t);
-
-                            return *this;
-                        }
-
-                        throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
-                    }
-
-                /*!
-                 * @brief This function serializes a long double.
-                 * @param ldouble_t The value of the long double that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& serialize(const long double ldouble_t)
-                    {
-                        if(((m_lastPosition - m_currentPosition) >= sizeof(ldouble_t)) || resize(sizeof(ldouble_t)))
-                        {
-                            m_currentPosition << ldouble_t;
-#if defined(_WIN32)
-                            m_currentPosition += sizeof(ldouble_t);
-                            m_currentPosition << static_cast<long double>(0);
-#endif
-                            m_currentPosition += sizeof(ldouble_t);
-
-                            return *this;
-                        }
-
-                        throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
-                    }
-
-                /*!
-                 * @brief This function serializes a boolean.
-                 * @param bool_t The value of the boolean that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                FastCdr& serialize(const bool bool_t);
-
-                /*!
-                 * @brief This function serializes a string.
-                 * @param string_t The pointer to the string that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                FastCdr& serialize(const char *string_t);
-
-                /*!
-                 * @brief This function serializes a wstring.
-                 * @param string_t The pointer to the wstring that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                FastCdr& serialize(const wchar_t *string_t);
-
-                /*!
-                 * @brief This function serializes a std::string.
-                 * @param string_t The string that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& serialize(const std::string &string_t) {return serialize(string_t.c_str());}
-
-                /*!
-                 * @brief This function serializes a std::wstring.
-                 * @param string_t The wstring that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& serialize(const std::wstring &string_t) {return serialize(string_t.c_str());}
-
-#if HAVE_CXX0X
-                /*!
-                 * @brief This function template serializes an array.
-                 * @param array_t The array that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                template<class _T, size_t _Size>
-                    inline FastCdr& serialize(const std::array<_T, _Size> &array_t)
-                    { return serializeArray(array_t.data(), array_t.size());}
-#endif
-
-#if !defined(_MSC_VER) && HAVE_CXX0X
-                /*!
-                 * @brief This function template serializes a sequence of booleans.
-                 * @param vector_t The sequence that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                template<class _T = bool>
-                    FastCdr& serialize(const std::vector<bool> &vector_t)
-                    {
-                        return serializeBoolSequence(vector_t);
-                    }
-#endif
-
-                /*!
-                 * @brief This function template serializes a sequence.
-                 * @param vector_t The sequence that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    FastCdr& serialize(const std::vector<_T> &vector_t)
-                    {
-                        state state_before_error(*this);
-
-                        *this << static_cast<int32_t>(vector_t.size());
-
-                        try
-                        {
-                            return serializeArray(vector_t.data(), vector_t.size());
-                        }
-                        catch(eprosima::fastcdr::exception::Exception &ex)
-                        {
-                            setState(state_before_error);
-                            ex.raise();
-                        }
-
-                        return *this;
-                    }
-
-#ifdef _MSC_VER
-                /*!
-                 * @brief This function template serializes a sequence of booleans.
-                 * @param vector_t The sequence that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                template<>
-                    FastCdr& serialize<bool>(const std::vector<bool> &vector_t)
-                    {
-                        return serializeBoolSequence(vector_t);
-                    }
-#endif
-
-                /*!
-                 * @brief This function template serializes a non-basic type.
-                 * @param type_t The object that will be serialized in the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    inline FastCdr& serialize(const _T &type_t)
-                    {
-                        type_t.serialize(*this);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function serializes an array of octets.
-                 * @param octet_t The sequence of octets that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& serializeArray(const uint8_t *octet_t, size_t numElements)
-                    {
-                        return serializeArray(reinterpret_cast<const char*>(octet_t), numElements);
-                    }
-
-                /*!
-                 * @brief This function serializes an array of characters.
-                 * @param char_t The array of characters that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                FastCdr& serializeArray(const char *char_t, size_t numElements);
-
-                /*!
-                 * @brief This function serializes an array of int8_t.
-                 * @param int8 The sequence of int8_t that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& serializeArray(const int8_t *int8, size_t numElements)
-                    {
-                        return serializeArray(reinterpret_cast<const char*>(int8), numElements);
-                    }
-
-                /*!
-                 * @brief This function serializes an array of unsigned shorts.
-                 * @param ushort_t The array of unsigned shorts that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& serializeArray(const uint16_t *ushort_t, size_t numElements)
-                    {
-                        return serializeArray(reinterpret_cast<const int16_t*>(ushort_t), numElements);
-                    }
-
-                /*!
-                 * @brief This function serializes an array of shorts.
-                 * @param short_t The array of shorts that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                FastCdr& serializeArray(const int16_t *short_t, size_t numElements);
-
-                /*!
-                 * @brief This function serializes an array of unsigned longs.
-                 * @param ulong_t The array of unsigned longs that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& serializeArray(const uint32_t *ulong_t, size_t numElements)
-                    {
-                        return serializeArray(reinterpret_cast<const int32_t*>(ulong_t), numElements);
-                    }
-
-                /*!
-                 * @brief This function serializes an array of longs.
-                 * @param long_t The array of longs that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                FastCdr& serializeArray(const int32_t *long_t, size_t numElements);
-
-                /*!
-                 * @brief This function serializes an array of wide-chars.
-                 * @param wchar The array of wide-chars that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                FastCdr& serializeArray(const wchar_t *wchar, size_t numElements);
-
-                /*!
-                 * @brief This function serializes an array of unsigned long longs.
-                 * @param ulonglong_t The array of unsigned long longs that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& serializeArray(const uint64_t *ulonglong_t, size_t numElements)
-                    {
-                        return serializeArray(reinterpret_cast<const int64_t*>(ulonglong_t), numElements);
-                    }
-
-                /*!
-                 * @brief This function serializes an array of long longs.
-                 * @param longlong_t The array of  long longs that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                FastCdr& serializeArray(const int64_t *longlong_t, size_t numElements);
-
-                /*!
-                 * @brief This function serializes an array of floats.
-                 * @param float_t The array of floats that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                FastCdr& serializeArray(const float *float_t, size_t numElements);
-
-                /*!
-                 * @brief This function serializes an array of doubles.
-                 * @param double_t The array of doubles that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                FastCdr& serializeArray(const double *double_t, size_t numElements);
-
-                /*!
-                 * @brief This function serializes an array of long doubles.
-                 * @param ldouble_t The array of long doubles that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                FastCdr& serializeArray(const long double *ldouble_t, size_t numElements);
-
-                /*!
-                 * @brief This function serializes an array of booleans.
-                 * @param bool_t The array of booleans that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                FastCdr& serializeArray(const bool *bool_t, size_t numElements);
-
-                /*!
-                 * @brief This function serializes an array of strings.
-                 * @param string_t The array of strings that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& serializeArray(const std::string *string_t, size_t numElements)
-                    {
-                        for(size_t count = 0; count < numElements; ++count)
-                            serialize(string_t[count].c_str());
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function serializes an array of wstrings.
-                 * @param string_t The array of wstrings that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& serializeArray(const std::wstring *string_t, size_t numElements)
-                    {
-                        for(size_t count = 0; count < numElements; ++count)
-                            serialize(string_t[count].c_str());
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function template serializes an array of sequences.
-                 * @param vector_t The array of sequences that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    FastCdr& serializeArray(const std::vector<_T> *vector_t, size_t numElements)
-                    {
-                        for(size_t count = 0; count < numElements; ++count)
-                            serialize(vector_t[count]);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function template serializes an array of non-basic type objects.
-                 * @param string_t The array of objects that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    FastCdr& serializeArray(const _T *type_t, size_t numElements)
-                    {
-                        for(size_t count = 0; count < numElements; ++count)
-                            type_t[count].serialize(*this);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function template serializes a raw sequence.
-                 * @param sequence_t Pointer to the sequence that will be serialized in the buffer.
-                 * @param numElements The number of elements contained in the sequence.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    FastCdr& serializeSequence(const _T *sequence_t, size_t numElements)
-                    {
-                        state state_before_error(*this);
-
-                        serialize(static_cast<int32_t>(numElements));
-
-                        try
-                        {
-                            return serializeArray(sequence_t, numElements);
-                        }
-                        catch(eprosima::fastcdr::exception::Exception &ex)
-                        {
-                            setState(state_before_error);
-                            ex.raise();
-                        }
-
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function deserializes an octet.
-                 * @param octet_t The variable that will store the octet read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& deserialize(uint8_t &octet_t)
-                    {
-                        return deserialize(reinterpret_cast<char&>(octet_t));
-                    }
-
-                /*!
-                 * @brief This function deserializes a character.
-                 * @param char_t The variable that will store the character read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& deserialize(char &char_t)
-                    {
-                        if((m_lastPosition - m_currentPosition) >= sizeof(char_t))
-                        {
-                            m_currentPosition++ >> char_t;
-                            return *this;
-                        }
-
-                        throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
-                    }
-
-                /*!
-                 * @brief This function deserializes an int8_t.
-                 * @param int8 The variable that will store the int8_t read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& deserialize(int8_t &int8)
-                    {
-                        return deserialize(reinterpret_cast<char&>(int8));
-                    }
-
-                /*!
-                 * @brief This function deserializes an unsigned short.
-                 * @param ushort_t The variable that will store the unsigned short read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& deserialize(uint16_t &ushort_t)
-                    {
-                        return deserialize(reinterpret_cast<int16_t&>(ushort_t));
-                    }
-
-                /*!
-                 * @brief This function deserializes a short.
-                 * @param short_t The variable that will store the short read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& deserialize(int16_t &short_t)
-                    {
-                        if((m_lastPosition - m_currentPosition) >= sizeof(short_t))
-                        {
-                            m_currentPosition >> short_t;
-                            m_currentPosition += sizeof(short_t);
-
-                            return *this;
-                        }
-
-                        throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
-                    }
-
-                /*!
-                 * @brief This function deserializes an unsigned long.
-                 * @param ulong_t The variable that will store the unsigned long read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& deserialize(uint32_t &ulong_t)
-                    {
-                        return deserialize(reinterpret_cast<int32_t&>(ulong_t));
-                    }
-
-                /*!
-                 * @brief This function deserializes a long.
-                 * @param long_t The variable that will store the long read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& deserialize(int32_t &long_t)
-                    {
-                        if((m_lastPosition - m_currentPosition) >= sizeof(long_t))
-                        {
-                            m_currentPosition >> long_t;
-                            m_currentPosition += sizeof(long_t);
-
-                            return *this;
-                        }
-
-                        throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
-                    }
-
-                /*!
-                 * @brief This function deserializes a wide-char.
-                 * @param wchar The variable that will store the wide-char read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& deserialize(wchar_t &wchar)
-                    {
-                        uint32_t ret;
-                        deserialize(ret);
-                        wchar = static_cast<wchar_t>(ret);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function deserializes an unsigned long long.
-                 * @param ulonglong_t The variable that will store the unsigned long long read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& deserialize(uint64_t &ulonglong_t)
-                    {
-                        return deserialize(reinterpret_cast<int64_t&>(ulonglong_t));
-                    }
-
-                /*!
-                 * @brief This function deserializes a long long.
-                 * @param longlong_t The variable that will store the long long read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& deserialize(int64_t &longlong_t)
-                    {
-                        if((m_lastPosition - m_currentPosition) >= sizeof(longlong_t))
-                        {
-                            m_currentPosition >> longlong_t;
-                            m_currentPosition += sizeof(longlong_t);
-
-                            return *this;
-                        }
-
-                        throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
-                    }
-
-                /*!
-                 * @brief This function deserializes a float.
-                 * @param float_t The variable that will store the float read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& deserialize(float &float_t)
-                    {
-                        if((m_lastPosition - m_currentPosition) >= sizeof(float_t))
-                        {
-                            m_currentPosition >> float_t;
-                            m_currentPosition += sizeof(float_t);
-
-                            return *this;
-                        }
-
-                        throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
-                    }
-
-                /*!
-                 * @brief This function deserializes a double.
-                 * @param double_t The variable that will store the double read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& deserialize(double &double_t)
-                    {
-                        if((m_lastPosition - m_currentPosition) >= sizeof(double_t))
-                        {
-                            m_currentPosition >> double_t;
-                            m_currentPosition += sizeof(double_t);
-
-                            return *this;
-                        }
-
-                        throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
-                    }
-
-                /*!
-                 * @brief This function deserializes a long double.
-                 * @param ldouble_t The variable that will store the long double read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& deserialize(long double &ldouble_t)
-                    {
-                        if((m_lastPosition - m_currentPosition) >= sizeof(ldouble_t))
-                        {
-                            m_currentPosition >> ldouble_t;
-                            m_currentPosition += sizeof(ldouble_t);
-#if defined(_WIN32)
-                            m_currentPosition += sizeof(ldouble_t);
-#endif
-
-                            return *this;
-                        }
-
-                        throw exception::NotEnoughMemoryException(exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
-                    }
-
-                /*!
-                 * @brief This function deserializes a boolean.
-                 * @param bool_t The variable that will store the boolean read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 * @exception exception::BadParamException This exception is thrown when trying to deserialize in an invalid value.
-                 */
-                FastCdr& deserialize(bool &bool_t);
-
-                /*!
-                 * @brief This function deserializes a string.
-                 * This function allocates memory to store the string. The user pointer will be set to point this allocated memory.
-                 * The user will have to free this allocated memory using free()
-                 * @param string_t The pointer that will point to the string read from the buffer.
-                 * The user will have to free the allocated memory using free()
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                FastCdr& deserialize(char *&string_t);
-
-                /*!
-                 * @brief This function deserializes a wide string.
-                 * This function allocates memory to store the wide string. The user pointer will be set to point this allocated memory.
-                 * The user will have to free this allocated memory using free()
-                 * @param string_t The pointer that will point to the wide string read from the buffer.
-                 * The user will have to free the allocated memory using free()
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                FastCdr& deserialize(wchar_t *&string_t);
-
-                /*!
-                 * @brief This function deserializes a std::string.
-                 * @param string_t The variable that will store the string read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& deserialize(std::string &string_t)
-                    {
-                        uint32_t length = 0;
-                        const char *str = readString(length);
-                        string_t = std::string(str, length);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function deserializes a std::wstring.
-                 * @param string_t The variable that will store the wstring read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& deserialize(std::wstring &string_t)
-                    {
-                        uint32_t length = 0;
-                        string_t = readWString(length);
-                        return *this;
-                    }
-
-#if HAVE_CXX0X
-                /*!
-                 * @brief This function template deserializes an array.
-                 * @param array_t The variable that will store the array read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                template<class _T, size_t _Size>
-                    inline FastCdr& deserialize(std::array<_T, _Size> &array_t)
-                    { return deserializeArray(array_t.data(), array_t.size());}
-#endif
-
-#if !defined(_MSC_VER) && HAVE_CXX0X
-                /*!
-                 * @brief This function template deserializes a sequence of booleans.
-                 * @param vector_t The variable that will store the sequence read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                template<class _T = bool>
-                    FastCdr& deserialize(std::vector<bool> &vector_t)
-                    {
-                        return deserializeBoolSequence(vector_t);
-                    }
-#endif
-
-                /*!
-                 * @brief This function template deserializes a sequence.
-                 * @param vector_t The variable that will store the sequence read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    FastCdr& deserialize(std::vector<_T> &vector_t)
-                    {
-                        uint32_t seqLength = 0;
-                        state state_before_error(*this);
-
-                        *this >> seqLength;
-
-                        try
-                        {
-                            vector_t.resize(seqLength);
-                            return deserializeArray(vector_t.data(), vector_t.size());
-                        }
-                        catch(eprosima::fastcdr::exception::Exception &ex)
-                        {
-                            setState(state_before_error);
-                            ex.raise();
-                        }
-
-                        return *this;
-                    }
-
-#ifdef _MSC_VER
-                /*!
-                 * @brief This function template deserializes a sequence of booleans.
-                 * @param vector_t The variable that will store the sequence read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                template<>
-                    FastCdr& deserialize<bool>(std::vector<bool> &vector_t)
-                    {
-                        return deserializeBoolSequence(vector_t);
-                    }
-#endif
-
-                /*!
-                 * @brief This function template deserializes a non-basic type object.
-                 * @param type_t The variable that will store the object read from the buffer.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    inline FastCdr& deserialize(_T &type_t)
-                    {
-                        type_t.deserialize(*this);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function deserializes an array of octets.
-                 * @param octet_t The variable that will store the array of octets read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& deserializeArray(uint8_t *octet_t, size_t numElements)
-                    {
-                        return deserializeArray(reinterpret_cast<char*>(octet_t), numElements);
-                    }
-
-                /*!
-                 * @brief This function deserializes an array of characters.
-                 * @param char_t The variable that will store the array of characters read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                FastCdr& deserializeArray(char *char_t, size_t numElements);
-
-                /*!
-                 * @brief This function deserializes an array of int8_t.
-                 * @param int8 The variable that will store the array of int8_t read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& deserializeArray(int8_t *int8, size_t numElements)
-                    {
-                        return deserializeArray(reinterpret_cast<char*>(int8), numElements);
-                    }
-
-                /*!
-                 * @brief This function deserializes an array of unsigned shorts.
-                 * @param ushort_t The variable that will store the array of unsigned shorts read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& deserializeArray(uint16_t *ushort_t, size_t numElements)
-                    {
-                        return deserializeArray(reinterpret_cast<int16_t*>(ushort_t), numElements);
-                    }
-
-                /*!
-                 * @brief This function deserializes an array of shorts.
-                 * @param short_t The variable that will store the array of shorts read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                FastCdr& deserializeArray(int16_t *short_t, size_t numElements);
-
-                /*!
-                 * @brief This function deserializes an array of unsigned longs.
-                 * @param ulong_t The variable that will store the array of unsigned longs read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& deserializeArray(uint32_t *ulong_t, size_t numElements)
-                    {
-                        return deserializeArray(reinterpret_cast<int32_t*>(ulong_t), numElements);
-                    }
-
-                /*!
-                 * @brief This function deserializes an array of longs.
-                 * @param long_t The variable that will store the array of longs read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                FastCdr& deserializeArray(int32_t *long_t, size_t numElements);
-
-                /*!
-                 * @brief This function deserializes an array of wide-chars.
-                 * @param wchar The variable that will store the array of wide-chars read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                FastCdr& deserializeArray(wchar_t *wchar, size_t numElements);
-
-                /*!
-                 * @brief This function deserializes an array of unsigned long longs.
-                 * @param ulonglong_t The variable that will store the array of unsigned long longs read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& deserializeArray(uint64_t *ulonglong_t, size_t numElements)
-                    {
-                        return deserializeArray(reinterpret_cast<int64_t*>(ulonglong_t), numElements);
-                    }
-
-                /*!
-                 * @brief This function deserializes an array of long longs.
-                 * @param longlong_t The variable that will store the array of long longs read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                FastCdr& deserializeArray(int64_t *longlong_t, size_t numElements);
-
-                /*!
-                 * @brief This function deserializes an array of floats.
-                 * @param float_t The variable that will store the array of floats read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                FastCdr& deserializeArray(float *float_t, size_t numElements);
-
-                /*!
-                 * @brief This function deserializes an array of doubles.
-                 * @param double_t The variable that will store the array of doubles read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                FastCdr& deserializeArray(double *double_t, size_t numElements);
-
-                /*!
-                 * @brief This function deserializes an array of long doubles.
-                 * @param ldouble_t The variable that will store the array of long doubles read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                FastCdr& deserializeArray(long double *ldouble_t, size_t numElements);
-
-                /*!
-                 * @brief This function deserializes an array of booleans.
-                 * @param bool_t The variable that will store the array of booleans read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                FastCdr& deserializeArray(bool *bool_t, size_t numElements);
-
-                /*!
-                 * @brief This function deserializes an array of strings.
-                 * @param string_t The variable that will store the array of strings read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& deserializeArray(std::string *string_t, size_t numElements)
-                    {
-                        for(size_t count = 0; count < numElements; ++count)
-                            deserialize(string_t[count]);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function deserializes an array of wide-strings.
-                 * @param string_t The variable that will store the array of strings read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                inline
-                    FastCdr& deserializeArray(std::wstring *string_t, size_t numElements)
-                    {
-                        for(size_t count = 0; count < numElements; ++count)
-                            deserialize(string_t[count]);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function template deserializes an array of sequences.
-                 * @param vector_t The variable that will store the array of sequences read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    FastCdr& deserializeArray(std::vector<_T> *vector_t, size_t numElements)
-                    {
-                        for(size_t count = 0; count < numElements; ++count)
-                            deserialize(vector_t[count]);
-                        return *this;
-                    }
-
-                /*!
-                 * @brief This function template deserializes an array of non-basic type objects.
-                 * @param type_t The variable that will store the array of objects read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    FastCdr& deserializeArray(_T *type_t, size_t numElements)
-                    {
-                        for(size_t count = 0; count < numElements; ++count)
-                            type_t[count].deserialize(*this);
-                        return *this;
-                    }
-
-#if !defined(_MSC_VER) && HAVE_CXX0X
-                /*!
-                 * @brief This function template deserializes a string sequence.
-                 * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory.
-                 * The user will have to free this allocated memory using free()
-                 * @param sequence_t The pointer that will store the sequence read from the buffer.
-                 * @param numElements This variable return the number of elements of the sequence.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                template<class _T = std::string>
-                    FastCdr& deserializeSequence(std::string *&sequence_t, size_t &numElements)
-                    {
-                        return deserializeStringSequence(sequence_t, numElements);
-                    }
-
-                /*!
-                 * @brief This function template deserializes a wide-string sequence.
-                 * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory.
-                 * The user will have to free this allocated memory using free()
-                 * @param sequence_t The pointer that will store the sequence read from the buffer.
-                 * @param numElements This variable return the number of elements of the sequence.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                template<class _T = std::wstring>
-                    FastCdr& deserializeSequence(std::wstring *&sequence_t, size_t &numElements)
-                    {
-                        return deserializeWStringSequence(sequence_t, numElements);
-                    }
-#endif
-
-                /*!
-                 * @brief This function template deserializes a raw sequence.
-                 * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory.
-                 * The user will have to free this allocated memory using free()
-                 * @param sequence_t The pointer that will store the sequence read from the buffer.
-                 * @param numElements This variable return the number of elements of the sequence.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                template<class _T>
-                    FastCdr& deserializeSequence(_T *&sequence_t, size_t &numElements)
-                    {
-                        uint32_t seqLength = 0;
-                        state state_before_error(*this);
-
-                        deserialize(seqLength);
-
-                        try
-                        {
-                            sequence_t = reinterpret_cast<_T*>(calloc(seqLength, sizeof(_T)));
-                            deserializeArray(sequence_t, seqLength);
-                        }
-                        catch(eprosima::fastcdr::exception::Exception &ex)
-                        {
-                            free(sequence_t);
-                            sequence_t = NULL;
-                            setState(state_before_error);
-                            ex.raise();
-                        }
-
-                        numElements = seqLength;
-                        return *this;
-                    }
-
-#ifdef _MSC_VER
-                /*!
-                 * @brief This function template deserializes a string sequence.
-                 * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory.
-                 * The user will have to free this allocated memory using free()
-                 * @param sequence_t The pointer that will store the sequence read from the buffer.
-                 * @param numElements This variable return the number of elements of the sequence.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                template<>
-                    FastCdr& deserializeSequence<std::string>(std::string *&sequence_t, size_t &numElements)
-                    {
-                        return deserializeStringSequence(sequence_t, numElements);
-                    }
-
-                /*!
-                 * @brief This function template deserializes a wide-string sequence.
-                 * This function allocates memory to store the sequence. The user pointer will be set to point this allocated memory.
-                 * The user will have to free this allocated memory using free()
-                 * @param sequence_t The pointer that will store the sequence read from the buffer.
-                 * @param numElements This variable return the number of elements of the sequence.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                template<>
-                    FastCdr& deserializeSequence<std::wstring>(std::wstring *&sequence_t, size_t &numElements)
-                    {
-                        return deserializeWStringSequence(sequence_t, numElements);
-                    }
-#endif
-
-            private:
-
-                FastCdr(const FastCdr&) = delete;
-
-                FastCdr& operator=(const FastCdr&) = delete;
-
-                FastCdr& serializeBoolSequence(const std::vector<bool> &vector_t);
-
-                FastCdr& deserializeBoolSequence(std::vector<bool> &vector_t);
-
-                FastCdr& deserializeStringSequence(std::string *&sequence_t, size_t &numElements);
-
-                FastCdr& deserializeWStringSequence(std::wstring *&sequence_t, size_t &numElements);
-
-#if HAVE_CXX0X
-                /*!
-                 * @brief This function template detects the content type of the STD container array and serializes the array.
-                 * @param array_t The array that will be serialized in the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size.
-                 */
-                template<class _T, size_t _Size>
-                    FastCdr& serializeArray(const std::array<_T, _Size> *array_t, size_t numElements)
-                    {
-                        return serializeArray(array_t->data(), numElements * array_t->size());
-                    }
-
-                /*!
-                 * @brief This function template detects the content type of the STD container array and deserializes the array.
-                 * @param array_t The variable that will store the array read from the buffer.
-                 * @param numElements Number of the elements in the array.
-                 * @return Reference to the eprosima::fastcdr::FastCdr object.
-                 * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size.
-                 */
-                template<class _T, size_t _Size>
-                    FastCdr& deserializeArray(std::array<_T, _Size> *array_t, size_t numElements)
-                    {
-                        return deserializeArray(array_t->data(), numElements * array_t->size());
-                    }
-#endif
-
-                bool resize(size_t minSizeInc);
-
-                const char* readString(uint32_t &length);
-
-                std::wstring readWString(uint32_t &length);
-
-                //! @brief Reference to the buffer that will be serialized/deserialized.
-                FastBuffer &m_cdrBuffer;
-
-                //! @brief The current position in the serialization/deserialization process.
-                FastBuffer::iterator m_currentPosition;
-
-                //! @brief The last position in the buffer;
-                FastBuffer::iterator m_lastPosition;
-        };
-    } //namespace fastcdr
-} //namespace eprosima
-
-#endif //_FASTCDR_FASTCDR_H_

+ 0 - 53
thirdpartylib/FastRTPS/include/fastcdr/config.h

@@ -1,53 +0,0 @@
-// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
-//
-// 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.
-
-#ifndef _FASTCDR_CONFIG_H_
-#define _FASTCDR_CONFIG_H_
-
-#define FASTCDR_VERSION_MAJOR 1
-#define FASTCDR_VERSION_MINOR 0
-#define FASTCDR_VERSION_MICRO 14
-#define FASTCDR_VERSION_STR "1.0.14"
-
-// C++11 support defines
-#ifndef HAVE_CXX11
-#define HAVE_CXX11 1
-#endif
-
-// C++0x support defines
-#ifndef HAVE_CXX0X
-#define HAVE_CXX0X 1
-#endif
-
-// C++ constexpr support
-#ifndef HAVE_CXX_CONSTEXPR
-#define HAVE_CXX_CONSTEXPR 1
-#endif
-
-#if HAVE_CXX_CONSTEXPR
-#define CONSTEXPR constexpr
-#else
-#define CONSTEXPR const
-#endif
-
-// Endianness defines
-#ifndef __BIG_ENDIAN__
-#define __BIG_ENDIAN__ 0
-#endif
-
-#if defined(__ARM_ARCH) && __ARM_ARCH <= 7
-#define FASTCDR_ARM32
-#endif
-
-#endif // _FASTCDR_CONFIG_H_

+ 0 - 53
thirdpartylib/FastRTPS/include/fastcdr/config.h.in

@@ -1,53 +0,0 @@
-// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
-//
-// 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.
-
-#ifndef _FASTCDR_CONFIG_H_
-#define _FASTCDR_CONFIG_H_
-
-#define FASTCDR_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
-#define FASTCDR_VERSION_MINOR @PROJECT_VERSION_MINOR@
-#define FASTCDR_VERSION_MICRO @PROJECT_VERSION_PATCH@
-#define FASTCDR_VERSION_STR "@PROJECT_VERSION@"
-
-// C++11 support defines
-#ifndef HAVE_CXX11
-#define HAVE_CXX11 @HAVE_CXX11@
-#endif
-
-// C++0x support defines
-#ifndef HAVE_CXX0X
-#define HAVE_CXX0X @HAVE_CXX0X@
-#endif
-
-// C++ constexpr support
-#ifndef HAVE_CXX_CONSTEXPR
-#define HAVE_CXX_CONSTEXPR @HAVE_CXX_CONSTEXPR@
-#endif
-
-#if HAVE_CXX_CONSTEXPR
-#define CONSTEXPR constexpr
-#else
-#define CONSTEXPR const
-#endif
-
-// Endianness defines
-#ifndef __BIG_ENDIAN__
-#define __BIG_ENDIAN__ @__BIG_ENDIAN__@
-#endif
-
-#if defined(__ARM_ARCH) && __ARM_ARCH <= 7
-#define FASTCDR_ARM32
-#endif
-
-#endif // _FASTCDR_CONFIG_H_

+ 0 - 66
thirdpartylib/FastRTPS/include/fastcdr/eProsima_auto_link.h

@@ -1,66 +0,0 @@
-// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
-//
-// 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.
-
-/*
- Expected defines.
-
- - EPROSIMA_LIB_NAME
- - FASTCDR_VERSION_MAJOR
- - FASTCDR_VERSION_MINOR
-*/
-
-#if defined(_MSC_VER)
-    #define EPROSIMA_STRINGIZE(X) EPROSIMA_DO_STRINGIZE(X)
-    #define EPROSIMA_DO_STRINGIZE(X) #X
-
-    #if defined(_DEBUG)
-        #define EPROSIMA_LIB_DEBUG_TAG "d"
-    #else
-        #define EPROSIMA_LIB_DEBUG_TAG
-    #endif // _DEBUG
-
-    // Select linkage option.
-    #if (defined(_DLL) || defined(_RTLDLL)) && defined(EPROSIMA_DYN_LINK)
-        #define EPROSIMA_LIB_PREFIX
-    #elif defined(EPROSIMA_DYN_LINK)
-        #error "Mixing a dll eprosima library with a static runtime is a bad idea"
-    #else
-        #define EPROSIMA_LIB_PREFIX "lib"
-    #endif
-
-    // Include library
-    #if defined(EPROSIMA_LIB_NAME) \
-	&& defined(EPROSIMA_LIB_PREFIX) \
-	&& defined(EPROSIMA_LIB_DEBUG_TAG) \
-	&& defined(FASTCDR_VERSION_MAJOR) \
-	&& defined(FASTCDR_VERSION_MINOR)
-        #pragma comment(lib, EPROSIMA_LIB_PREFIX EPROSIMA_STRINGIZE(EPROSIMA_LIB_NAME) EPROSIMA_LIB_DEBUG_TAG "-" EPROSIMA_STRINGIZE(FASTCDR_VERSION_MAJOR) "." EPROSIMA_STRINGIZE(FASTCDR_VERSION_MINOR) ".lib")
-    #else
-    #error "Some required macros where not defined"
-    #endif
-
-#endif // _MSC_VER
-    
-// Undef macros
-#ifdef EPROSIMA_LIB_PREFIX
-#undef EPROSIMA_LIB_PREFIX
-#endif
-
-#ifdef EPROSIMA_LIB_NAME
-#undef EPROSIMA_LIB_NAME
-#endif
-
-#ifdef EPROSIMA_LIB_DEBUG_TAG
-#undef EPROSIMA_LIB_DEBUG_TAG
-#endif

+ 0 - 85
thirdpartylib/FastRTPS/include/fastcdr/exceptions/BadParamException.h

@@ -1,85 +0,0 @@
-// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
-//
-// 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.
-
-#ifndef _FASTCDR_EXCEPTIONS_BADPARAMEXCEPTION_H_
-#define _FASTCDR_EXCEPTIONS_BADPARAMEXCEPTION_H_
-
-#include "Exception.h"
-
-namespace eprosima
-{
-    namespace fastcdr
-    {
-        namespace exception
-        {
-            /*!
-             * @brief This class is thrown as an exception when a invalid parameter was being serialized.
-             * @ingroup EXCEPTIONMODULE
-             */
-            class BadParamException : public Exception
-            {
-                public:
-
-                    /*!
-                     * @brief Default constructor.
-                     *
-                     * @param message A error message. This message pointer is copied.
-                     */
-                    Cdr_DllAPI BadParamException(const char* const &message) noexcept;
-
-                    /*!
-                     * @brief Default copy constructor.
-                     *
-                     * @param ex BadParamException that will be copied.
-                     */
-                    Cdr_DllAPI BadParamException(const BadParamException &ex) noexcept;
-
-#if HAVE_CXX0X
-                    /*!
-                     * @brief Default move constructor.
-                     *
-                     * @param ex BadParamException that will be moved.
-                     */
-                    Cdr_DllAPI BadParamException(BadParamException&& ex) noexcept;
-#endif
-
-                    /*!
-                     * @brief Assigment operation.
-                     *
-                     * @param ex BadParamException that will be copied.
-                     */
-                    Cdr_DllAPI BadParamException& operator=(const BadParamException &ex) noexcept;
-
-#if HAVE_CXX0X
-                    /*!
-                     * @brief Assigment operation.
-                     *
-                     * @param ex BadParamException that will be moved.
-                     */
-                    BadParamException& operator=(BadParamException&& ex) noexcept;
-#endif
-
-                    //! @brief Default constructor
-                    virtual Cdr_DllAPI ~BadParamException() noexcept;
-
-                    //! @brief This function throws the object as exception.
-                    virtual Cdr_DllAPI void raise() const;
-
-                    //! @brief Default message used in the library.
-                    static Cdr_DllAPI const char* const BAD_PARAM_MESSAGE_DEFAULT;
-            };
-        } //namespace exception
-    } //namespace fastcdr
-} //namespace eprosima
-#endif // _FASTCDR_EXCEPTIONS_BADPARAMEXCEPTION_H_

+ 0 - 98
thirdpartylib/FastRTPS/include/fastcdr/exceptions/Exception.h

@@ -1,98 +0,0 @@
-// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
-//
-// 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.
-
-#ifndef _FASTCDR_EXCEPTIONS_EXCEPTION_H_
-#define _FASTCDR_EXCEPTIONS_EXCEPTION_H_
-
-#include "../fastcdr_dll.h"
-#include <string>
-#include <exception>
-
-namespace eprosima
-{
-    namespace fastcdr
-    {
-        namespace exception
-        {
-            /*!
-             * @brief This abstract class is used to create exceptions.
-             * @ingroup EXCEPTIONMODULE
-             */
-            class Exception : public std::exception
-            {
-                public:
-
-                    //! \brief Default destructor.
-                    virtual Cdr_DllAPI ~Exception() noexcept;
-
-                    //! \brief This function throws the object as exception.
-                    virtual Cdr_DllAPI void raise() const = 0;
-
-                    /*!
-                     * @brief This function returns the error message.
-                     *
-                     * @return The error message.
-                     */
-                    virtual Cdr_DllAPI const char* what() const noexcept ;
-
-                protected:
-
-                    /*!
-                     * @brief Default constructor.
-                     *
-                     * @param message A error message. This message pointer is copied.
-                     */
-                    Cdr_DllAPI Exception(const char* const &message) noexcept;
-
-                    /*!
-                     * @brief Default copy constructor.
-                     *
-                     * @param ex Exception that will be copied.
-                     */
-                    Cdr_DllAPI Exception(const Exception &ex) noexcept;
-
-#if HAVE_CXX0X
-                    /*!
-                     * @brief Default move constructor.
-                     *
-                     * @param ex Exception that will be moved.
-                     */
-                    Cdr_DllAPI Exception(Exception&& ex) noexcept;
-#endif
-
-                    /*!
-                     * @brief Assigment operation.
-                     *
-                     * @param ex Exception that will be copied.
-                     */
-                    Cdr_DllAPI Exception& operator=(const Exception &ex) noexcept;
-
-#if HAVE_CXX0X
-                    /*!
-                     * @brief Assigment operation.
-                     *
-                     * @param ex Exception that will be moved.
-                     */
-                    Cdr_DllAPI Exception& operator=(Exception&&) noexcept;
-#endif
-
-                private:
-
-                    const char* m_message;
-            };
-        } //namespace exception
-    } //namespace fastcdr
-} //namespace eprosima
-
-#endif // _FASTCDR_EXCEPTIONS_EXCEPTION_H_

+ 0 - 85
thirdpartylib/FastRTPS/include/fastcdr/exceptions/NotEnoughMemoryException.h

@@ -1,85 +0,0 @@
-// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
-//
-// 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.
-
-#ifndef _FASTCDR_EXCEPTIONS_NOTENOUGHMEMORYEXCEPTION_H_
-#define _FASTCDR_EXCEPTIONS_NOTENOUGHMEMORYEXCEPTION_H_
-
-#include "Exception.h"
-
-namespace eprosima
-{
-    namespace fastcdr
-    {
-        namespace exception
-        {
-            /*!
-             * @brief This class is thrown as an exception when the buffer's internal memory reachs its size limit.
-             * @ingroup EXCEPTIONMODULE
-             */
-            class NotEnoughMemoryException : public Exception
-            {
-                public:
-
-                    /*!
-                     * @brief Default constructor.
-                     *
-                     * @param message A error message. This message pointer is copied.
-                     */
-                    Cdr_DllAPI NotEnoughMemoryException(const char* const &message) noexcept;
-
-                    /*!
-                     * @brief Default copy constructor.
-                     *
-                     * @param ex NotEnoughMemoryException that will be copied.
-                     */
-                    Cdr_DllAPI NotEnoughMemoryException(const NotEnoughMemoryException &ex) noexcept;
-
-#if HAVE_CXX0X
-                    /*!
-                     * @brief Default move constructor.
-                     *
-                     * @param ex NotEnoughMemoryException that will be moved.
-                     */
-                    Cdr_DllAPI NotEnoughMemoryException(NotEnoughMemoryException&& ex) noexcept;
-#endif
-
-                    /*!
-                     * @brief Assigment operation.
-                     *
-                     * @param ex NotEnoughMemoryException that will be copied.
-                     */
-                    Cdr_DllAPI NotEnoughMemoryException& operator=(const NotEnoughMemoryException &ex) noexcept;
-
-#if HAVE_CXX0X
-                    /*!
-                     * @brief Assigment operation.
-                     *
-                     * @param ex NotEnoughMemoryException that will be moved.
-                     */
-                    Cdr_DllAPI NotEnoughMemoryException& operator=(NotEnoughMemoryException&& ex) noexcept;
-#endif
-
-                    //! @brief Default constructor
-                    virtual Cdr_DllAPI ~NotEnoughMemoryException() noexcept;
-
-                    //! @brief This function throws the object as exception.
-                    virtual Cdr_DllAPI void raise() const;
-
-                    //! @brief Default message used in the library.
-                    static Cdr_DllAPI const char* const NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT;
-            };
-        } //namespace exception
-    } //namespace fastcdr
-} //namespace eprosima
-#endif // _FASTCDR_EXCEPTIONS_NOTENOUGHMEMORYEXCEPTION_H_

Vissa filer visades inte eftersom för många filer har ändrats