27 yaw *= geom::Math::Pi<float>() / 180.0f;
28 const float c = std::cos(yaw);
29 const float s = std::sin(yaw);
31 c * location.
x - s * location.
y,
32 s * location.
x + c * location.
y,
89 if ((prev ==
nullptr) &&
_bounds.compare_exchange(&prev, next)) {
94 constexpr float distance_threshold = 10.0f * std::numeric_limits<float>::epsilon();
95 for (
auto i = 0u; i < 4u; ++i) {
96 if ((next->corners[i] - prev->corners[i]).Length() < distance_threshold) {
103 if (prev->frame >= next->frame) {
106 }
while (!
_bounds.compare_exchange(&prev, next));
109 std::vector<road::element::LaneMarking> crossed_lanes;
110 for (
auto i = 0u; i < 4u; ++i) {
111 const auto lanes =
_map->CalculateCrossedLanes(prev->corners[i], next->corners[i]);
112 crossed_lanes.insert(crossed_lanes.end(), lanes.begin(), lanes.end());
115 if (!crossed_lanes.empty()) {
116 _callback(MakeShared<sensor::data::LaneInvasionEvent>(
121 std::move(crossed_lanes)));
129 const auto location = transform.
location + box.location;
131 return std::make_shared<Bounds>(
Bounds{frame, {
147 auto vehicle = boost::dynamic_pointer_cast<Vehicle>(
GetParent());
148 if (vehicle ==
nullptr) {
155 auto cb = std::make_shared<LaneInvasionCallback>(
157 episode->GetCurrentMap(),
158 std::move(callback));
160 const size_t callback_id = episode->RegisterOnTickEvent([cb=std::move(cb)](
const auto &snapshot) {
163 }
catch (
const std::exception &e) {
164 log_error(
"LaneInvasionSensor:", e.what());
168 const size_t previous =
_callback_id.exchange(callback_id);
169 if (previous != 0u) {
170 episode->RemoveOnTickEvent(previous);
177 if ((previous != 0u) && (episode !=
nullptr)) {
178 episode->RemoveOnTickEvent(previous);
#define DEBUG_ASSERT(predicate)
A very simple atomic shared ptr with release-acquire memory order.
geom::BoundingBox _parent_bounding_box
SharedPtr< const Map > _map
void Tick(const WorldSnapshot &snapshot) const
Sensor::CallbackFunctionType _callback
LaneInvasionCallback(const Vehicle &vehicle, SharedPtr< Map > &&map, Sensor::CallbackFunctionType &&user_callback)
std::shared_ptr< const Bounds > MakeBounds(size_t frame, const geom::Transform &vehicle_transform) const
AtomicSharedPtr< const Bounds > _bounds
std::atomic_size_t _callback_id
void Stop() override
Stop listening for new measurements.
void Listen(CallbackFunctionType callback) override
Register a callback to be executed each time a new measurement is received.
std::function< void(SharedPtr< sensor::SensorData >)> CallbackFunctionType
std::size_t frame
Number of frames elapsed since the simulator was launched.
double elapsed_seconds
Simulated seconds elapsed since the beginning of the current episode.
const Timestamp & GetTimestamp() const
Get timestamp of this snapshot.
boost::optional< ActorSnapshot > Find(ActorId actor_id) const
Find an ActorSnapshot by id.
EpisodeProxy & GetEpisode()
SharedPtr< Actor > GetParent() const
const std::string & GetDisplayId() const
SharedPtrType TryLock() const noexcept
SharedPtrType Lock() const
Same as TryLock but never return nullptr.
static geom::Location Rotate(float yaw, const geom::Location &location)
This file contains definitions of common data structures used in traffic manager.
static void log_error(Args &&... args)
boost::shared_ptr< T > SharedPtr
Use this SharedPtr (boost::shared_ptr) to keep compatibility with boost::python, but it would be nice...
std::array< geom::Location, 4u > corners