From c000cb3a0f9e7f0aebf9570ade6d72bfdc929ea7 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Thu, 18 Apr 2024 12:29:51 +0200 Subject: [PATCH] Add GetThingsOfType --- Perception.cpp | 19 +++++++++++++++++++ Perception.h | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/Perception.cpp b/Perception.cpp index 578eeac..be8a886 100644 --- a/Perception.cpp +++ b/Perception.cpp @@ -277,6 +277,25 @@ InterestingThing **Perception::GetTrackedObjects() { return this->trackedObjects; } +unsigned char Perception::GetThingsOfType(unsigned char objectType, + InterestingThing *buffer[], + unsigned char bufferSize) { + unsigned char thingCount = 0; + for (unsigned char objIx = 0; objIx < maxObjectCount; objIx++) { + InterestingThing *thing = this->trackedObjects[objIx]; + if (thing == nullptr) + continue; + + if (thing->type == objectType) { + buffer[thingCount] = thing; + thingCount++; + if (thingCount >= bufferSize) + return bufferSize; + } + } + return thingCount; +} + InterestingThing *Perception::GetMostInterestingThing() { InterestingThing *closestObject = nullptr; float closestDistance = INFINITY; diff --git a/Perception.h b/Perception.h index 5cad413..730624f 100644 --- a/Perception.h +++ b/Perception.h @@ -103,6 +103,10 @@ public: /// currently being tracked. InterestingThing **GetTrackedObjects(); + unsigned char GetThingsOfType(unsigned char objectType, + InterestingThing *buffer[], + unsigned char bufferSize); + InterestingThing *GetMostInterestingThing(); // mainly used for confidence update