diff --git a/libraries/workload/src/workload/ClassificationTracker.cpp b/libraries/workload/src/workload/ClassificationTracker.cpp index 009549737f..15066b1050 100644 --- a/libraries/workload/src/workload/ClassificationTracker.cpp +++ b/libraries/workload/src/workload/ClassificationTracker.cpp @@ -18,7 +18,17 @@ using namespace workload; void ClassificationTracker::configure(const Config& config) { } -void ClassificationTracker::run(const workload::WorkloadContextPointer& renderContext, Outputs& outputs) { - +void ClassificationTracker::run(const WorkloadContextPointer& context, Outputs& outputs) { + auto space = context->_space; + if (space) { + Changes changes; + space->categorizeAndGetChanges(changes); + outputs.resize(workload::Space::NUM_TRANSITIONS); + for (uint32_t i = 0; i < changes.size(); ++i) { + int32_t j = Space::computeTransitionIndex(changes[i].prevRegion, changes[i].region); + assert(j >= 0 && j < workload::Space::NUM_TRANSITIONS); + outputs[j].push_back(changes[i].proxyId); + } + } } diff --git a/libraries/workload/src/workload/ClassificationTracker.h b/libraries/workload/src/workload/ClassificationTracker.h index ca7a919769..e3364950da 100644 --- a/libraries/workload/src/workload/ClassificationTracker.h +++ b/libraries/workload/src/workload/ClassificationTracker.h @@ -29,7 +29,7 @@ namespace workload { class ClassificationTracker { public: using Config = ClassificationTrackerConfig; - using Outputs = Classifications; + using Outputs = SortedChanges; using JobModel = workload::Job::ModelO; ClassificationTracker() {} diff --git a/libraries/workload/src/workload/Space.h b/libraries/workload/src/workload/Space.h index ee06383288..eef1fc17cd 100644 --- a/libraries/workload/src/workload/Space.h +++ b/libraries/workload/src/workload/Space.h @@ -24,6 +24,11 @@ namespace workload { class Space { public: + static const int32_t NUM_CLASSIFICATIONS = 4; + static const int32_t NUM_TRANSITIONS = NUM_CLASSIFICATIONS * (NUM_CLASSIFICATIONS - 1); + + static int32_t computeTransitionIndex(int32_t prevIndex, int32_t newIndex); + static const uint8_t REGION_NEAR = 0; static const uint8_t REGION_MIDDLE = 1; static const uint8_t REGION_FAR = 2; @@ -45,12 +50,12 @@ public: class View { public: View(const glm::vec3& pos, float nearRadius, float midRadius, float farRadius) : center(pos) { - radiuses[0] = nearRadius; - radiuses[1] = midRadius; - radiuses[2] = farRadius; + radiuses[REGION_NEAR] = nearRadius; + radiuses[REGION_MIDDLE] = midRadius; + radiuses[REGION_FAR] = farRadius; } - glm::vec3 center { 0.0f, 0.0f, 0.0f }; - float radiuses[3] { 0.0f, 0.0f, 0.0f }; + glm::vec3 center; + float radiuses[NUM_CLASSIFICATIONS - 1]; }; class Change { @@ -84,8 +89,44 @@ private: std::vector _freeIndices; }; +inline int32_t Space::computeTransitionIndex(int32_t prevIndex, int32_t newIndex) { + // given prevIndex and newIndex compute an index into the transition list, + // where the lists between unchanged indices don't exist (signaled by index = -1). + // + // Given an NxN array + // let p = i + N * j + // + // then k = -1 when i == j + // = p - (1 + p/(N+1)) when i != j + // + // i 0 1 2 3 + // j +-------+-------+-------+-------+ + // |p = 0 | 1 | 2 | 3 | + // 0 | | | | | + // |k = -1 | 0 | 1 | 2 | + // +-------+-------+-------+-------+ + // | 4 | 5 | 6 | 7 | + // 1 | | | | | + // | 3 | -1 | 4 | 5 | + // +-------+-------+-------+-------+ + // | 8 | 9 | 10 | 11 | + // 2 | | | | | + // | 6 | 7 | -1 | 8 | + // +-------+-------+-------+-------+ + // | 12 | 13 | 14 | 15 | + // 3 | | | | | + // | 9 | 10 | 11 | -1 | + // +-------+-------+-------+-------+ + int32_t p = prevIndex + Space::NUM_CLASSIFICATIONS * newIndex; + if (0 == (p % (Space::NUM_CLASSIFICATIONS + 1))) { + return -1; + } + return p - (1 + p / (Space::NUM_CLASSIFICATIONS + 1)); +} + using SpacePointer = std::shared_ptr; -using Classifications = std::vector; +using Changes = std::vector; +using SortedChanges = std::vector>; } // namespace workload