16 #ifndef PSEN_SCAN_V2_STANDALONE_LASERSCAN_CONVERSIONS_H 
   17 #define PSEN_SCAN_V2_STANDALONE_LASERSCAN_CONVERSIONS_H 
   33 namespace data_conversion_layer
 
   63   toLaserScan(
const std::vector<data_conversion_layer::monitoring_frame::MessageStamped>& stamped_msgs);
 
   67       const std::vector<data_conversion_layer::monitoring_frame::MessageStamped>& stamped_msgs);
 
   69   calculateMaxAngle(
const std::vector<data_conversion_layer::monitoring_frame::MessageStamped>& stamped_msgs,
 
   72   calculateTimestamp(
const std::vector<data_conversion_layer::monitoring_frame::MessageStamped>& stamped_msgs,
 
   73                      const std::vector<int>& filled_stamped_msgs_indices);
 
   77                            const std::vector<int>& sorted_stamped_msgs_indices);
 
   79   allResolutionsMatch(
const std::vector<data_conversion_layer::monitoring_frame::MessageStamped>& stamped_msgs);
 
   81   allScanCountersMatch(
const std::vector<data_conversion_layer::monitoring_frame::MessageStamped>& stamped_msgs);
 
   83   thetaAnglesFitTogether(
const std::vector<data_conversion_layer::monitoring_frame::MessageStamped>& stamped_msgs,
 
   84                          const std::vector<int>& sorted_stamped_msgs_indices);
 
   88     const std::vector<data_conversion_layer::monitoring_frame::MessageStamped>& stamped_msgs)
 
   90   if (stamped_msgs.empty())
 
   98   const auto min_angle = stamped_msgs[sorted_stamped_msgs_indices[0]].msg_.fromTheta();
 
  104   std::vector<double> measurements;
 
  105   std::vector<double> intensities;
 
  106   std::vector<IOState> io_states;
 
  108   for (
auto index : sorted_stamped_msgs_indices)
 
  110     measurements.insert(measurements.end(),
 
  111                         stamped_msgs[index].msg_.measurements().begin(),
 
  112                         stamped_msgs[index].msg_.measurements().end());
 
  113     if (stamped_msgs[index].msg_.hasIntensitiesField())
 
  115       intensities.insert(intensities.end(),
 
  116                          stamped_msgs[index].msg_.intensities().begin(),
 
  117                          stamped_msgs[index].msg_.intensities().end());
 
  124   for (
const auto& single_msg : stamped_msgs)
 
  126     if (single_msg.msg_.hasIOPinField())
 
  129                      "stamp_: {} fromTheta: {} ioPinDate: {} ",
 
  131                      std::to_string(single_msg.msg_.fromTheta().toRad()),
 
  134       io_states.emplace_back(single_msg.msg_.iOPinData(), single_msg.stamp_);
 
  138   LaserScan scan(stamped_msgs[0].msg_.resolution(),
 
  141                  stamped_msgs[0].msg_.scanCounter(),
 
  142                  stamped_msgs[sorted_stamped_msgs_indices.back()].msg_.activeZoneset(),
 
  154     const std::vector<data_conversion_layer::monitoring_frame::MessageStamped>& stamped_msgs)
 
  156   std::vector<int> sorted_filled_stamped_msgs_indices(stamped_msgs.size());
 
  157   std::iota(sorted_filled_stamped_msgs_indices.begin(), sorted_filled_stamped_msgs_indices.end(), 0);
 
  158   std::sort(sorted_filled_stamped_msgs_indices.begin(),
 
  159             sorted_filled_stamped_msgs_indices.end(),
 
  160             [&stamped_msgs](
int i1, 
int i2) {
 
  161               return stamped_msgs[i1].msg_.fromTheta() < stamped_msgs[i2].msg_.fromTheta();
 
  166   sorted_filled_stamped_msgs_indices.erase(
 
  167       std::remove_if(sorted_filled_stamped_msgs_indices.begin(),
 
  168                      sorted_filled_stamped_msgs_indices.end(),
 
  169                      [&stamped_msgs](
int i) { return stamped_msgs[i].msg_.measurements().empty(); }),
 
  170       sorted_filled_stamped_msgs_indices.end());
 
  173   return sorted_filled_stamped_msgs_indices;
 
  177     const std::vector<data_conversion_layer::monitoring_frame::MessageStamped>& stamped_msgs,
 
  180   const auto resolution = stamped_msgs[0].msg_.resolution();
 
  181   const uint16_t number_of_samples = std::accumulate(
 
  182       stamped_msgs.begin(), stamped_msgs.end(), uint16_t{ 0 }, [](uint16_t total, 
const auto& stamped_msg) {
 
  183         return total + stamped_msg.msg_.measurements().size();
 
  185   return min_angle + resolution * 
static_cast<int>(number_of_samples - 1);
 
  189     const std::vector<data_conversion_layer::monitoring_frame::MessageStamped>& stamped_msgs,
 
  190     const std::vector<int>& filled_stamped_msgs_indices)
 
  192   const auto it = std::min_element(
 
  193       filled_stamped_msgs_indices.begin(), filled_stamped_msgs_indices.end(), [&stamped_msgs](
int i, 
int j) {
 
  194         return stamped_msgs[i].stamp_ < stamped_msgs[j].stamp_;
 
  205   return stamped_msg.
stamp_ - 
static_cast<int64_t
>(std::round(scan_interval_in_degree * time_per_scan_in_ns / 360.0));
 
  209     const std::vector<data_conversion_layer::monitoring_frame::MessageStamped>& stamped_msgs,
 
  210     const std::vector<int>& sorted_stamped_msgs_indices)
 
  227     const std::vector<data_conversion_layer::monitoring_frame::MessageStamped>& stamped_msgs)
 
  229   const auto resolution = stamped_msgs[0].msg_.resolution();
 
  230   return std::all_of(stamped_msgs.begin(), stamped_msgs.end(), [resolution](
const auto& stamped_msg) {
 
  231     return stamped_msg.msg_.resolution() == resolution;
 
  236     const std::vector<data_conversion_layer::monitoring_frame::MessageStamped>& stamped_msgs)
 
  238   const auto scan_counter = stamped_msgs[0].msg_.scanCounter();
 
  239   return std::all_of(stamped_msgs.begin(), stamped_msgs.end(), [scan_counter](
const auto& stamped_msg) {
 
  240     return stamped_msg.msg_.scanCounter() == scan_counter;
 
  245     const std::vector<data_conversion_layer::monitoring_frame::MessageStamped>& stamped_msgs,
 
  246     const std::vector<int>& sorted_filled_stamped_msgs_indices)
 
  248   util::TenthOfDegree last_end = stamped_msgs[sorted_filled_stamped_msgs_indices[0]].msg_.fromTheta();
 
  249   for (
auto index : sorted_filled_stamped_msgs_indices)
 
  251     const auto& stamped_msg = stamped_msgs[index];
 
  252     if (last_end != stamped_msg.msg_.fromTheta())
 
  256     last_end = stamped_msg.msg_.fromTheta() +
 
  257                stamped_msg.msg_.resolution() * 
static_cast<int>(stamped_msg.msg_.measurements().size());
 
  265 #endif  // PSEN_SCAN_V2_STANDALONE_LASERSCAN_CONVERSIONS_H