|
| 1 | +/* |
| 2 | + * Copyright 2022 Robert Bosch GmbH |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + * SPDX-License-Identifier: Apache-2.0 |
| 17 | + */ |
| 18 | +/** |
| 19 | + * \file cloe/component/osi_sensor.hpp |
| 20 | + * \see cloe/component/osi.hpp |
| 21 | + */ |
| 22 | + |
| 23 | +#pragma once |
| 24 | +#ifndef CLOE_COMPONENT_OSI_SENSOR_HPP_ |
| 25 | +#define CLOE_COMPONENT_OSI_SENSOR_HPP_ |
| 26 | + |
| 27 | +#include <memory> // for shared_ptr |
| 28 | + |
| 29 | +#include "osi_groundtruth.pb.h" // for GroundTruth |
| 30 | +#include "osi_sensordata.pb.h" // for SensorData |
| 31 | +#include "osi_sensorview.pb.h" // for SensorView |
| 32 | + |
| 33 | +#include <cloe/component.hpp> // for Component, Json |
| 34 | + |
| 35 | +namespace cloe_osi { |
| 36 | + |
| 37 | +class OsiSensor : public cloe::Component { |
| 38 | + public: |
| 39 | + using cloe::Component::Component; |
| 40 | + OsiSensor() : Component("osi_sensor") {} |
| 41 | + virtual ~OsiSensor() noexcept = default; |
| 42 | + |
| 43 | + /** |
| 44 | + * Return OSI data, if available. |
| 45 | + */ |
| 46 | + |
| 47 | + virtual std::shared_ptr<osi3::GroundTruth> ground_truth() = 0; |
| 48 | + |
| 49 | + virtual std::shared_ptr<osi3::SensorView> sensor_view() = 0; |
| 50 | + |
| 51 | + virtual std::shared_ptr<osi3::SensorData> sensor_data() = 0; |
| 52 | + |
| 53 | + /** |
| 54 | + * Writes JSON representation into j. |
| 55 | + */ |
| 56 | + cloe::Json active_state() const override { |
| 57 | + return cloe::Json{ |
| 58 | + /*{"ground_truth", this->ground_truth()}, |
| 59 | + {"sensor_view", this->sensor_view()}, |
| 60 | + {"sensor_data", this->sensor_data()},*/ |
| 61 | + }; |
| 62 | + } |
| 63 | +}; |
| 64 | + |
| 65 | +class NopOsiSensor : public OsiSensor { |
| 66 | + public: |
| 67 | + using OsiSensor::OsiSensor; |
| 68 | + NopOsiSensor() : OsiSensor("nop_osi_sensor") {} |
| 69 | + virtual ~NopOsiSensor() noexcept = default; |
| 70 | + |
| 71 | + std::shared_ptr<osi3::GroundTruth> ground_truth() override { return ground_truth_; } |
| 72 | + |
| 73 | + std::shared_ptr<osi3::SensorView> sensor_view() override { return sensor_view_; } |
| 74 | + |
| 75 | + std::shared_ptr<osi3::SensorData> sensor_data() override { return sensor_data_; } |
| 76 | + |
| 77 | + void set_ground_truth(const osi3::GroundTruth& gt) { |
| 78 | + ground_truth_ = std::make_shared<osi3::GroundTruth>(gt); |
| 79 | + } |
| 80 | + |
| 81 | + void set_sensor_view(const osi3::SensorView& view) { |
| 82 | + sensor_view_ = std::make_shared<osi3::SensorView>(view); |
| 83 | + } |
| 84 | + |
| 85 | + void set_sensor_data(const osi3::SensorData& data) { |
| 86 | + sensor_data_ = std::make_shared<osi3::SensorData>(data); |
| 87 | + } |
| 88 | + |
| 89 | + void reset() override { |
| 90 | + OsiSensor::reset(); |
| 91 | + ground_truth_.reset(); |
| 92 | + sensor_view_.reset(); |
| 93 | + sensor_data_.reset(); |
| 94 | + } |
| 95 | + |
| 96 | + protected: |
| 97 | + std::shared_ptr<osi3::GroundTruth> ground_truth_{nullptr}; |
| 98 | + std::shared_ptr<osi3::SensorView> sensor_view_{nullptr}; |
| 99 | + std::shared_ptr<osi3::SensorData> sensor_data_{nullptr}; |
| 100 | +}; |
| 101 | + |
| 102 | +} // namespace cloe_osi |
| 103 | + |
| 104 | +#endif // CLOE_COMPONENT_OSI_SENSOR_HPP_ |
0 commit comments