SegmentationUtils.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <ROS2Sensors/Lidar/ClassSegmentationBus.h>
  9. #include <ROS2Sensors/Lidar/SegmentationUtils.h>
  10. namespace ROS2Sensors::SegmentationUtils
  11. {
  12. uint8_t FetchClassIdForEntity(AZ::EntityId entityId)
  13. {
  14. AZStd::optional<uint8_t> classId;
  15. LmbrCentral::Tags entityTags;
  16. LmbrCentral::TagComponentRequestBus::EventResult(entityTags, entityId, &LmbrCentral::TagComponentRequests::GetTags);
  17. auto* segmentationInterface = ClassSegmentationInterface::Get();
  18. if (!segmentationInterface)
  19. {
  20. return UnknownClassId;
  21. }
  22. for (const auto& tag : entityTags)
  23. {
  24. AZStd::optional<uint8_t> tagClassId = segmentationInterface->GetClassIdForTag(tag);
  25. if (tagClassId.has_value())
  26. {
  27. if (classId.has_value())
  28. {
  29. AZ_Warning(
  30. "EntityManager",
  31. false,
  32. "Entity with ID: %s has more than one class tag. Assigning first class ID %u",
  33. entityId.ToString().c_str(),
  34. classId.value());
  35. }
  36. else
  37. {
  38. classId = tagClassId.value();
  39. }
  40. }
  41. }
  42. if (!classId.has_value())
  43. {
  44. AZ_Warning(
  45. "EntityManager",
  46. false,
  47. "Entity with ID: %s has no class tag. Assigning unknown class ID: %u",
  48. entityId.ToString().c_str(),
  49. UnknownClassId);
  50. }
  51. return classId.value_or(UnknownClassId);
  52. }
  53. } // namespace ROS2Sensors::SegmentationUtils