mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-14 23:28:27 +02:00
compute Space changes
This commit is contained in:
parent
1e71e819f4
commit
c1b8f12b7f
3 changed files with 60 additions and 9 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace workload {
|
|||
class ClassificationTracker {
|
||||
public:
|
||||
using Config = ClassificationTrackerConfig;
|
||||
using Outputs = Classifications;
|
||||
using Outputs = SortedChanges;
|
||||
using JobModel = workload::Job::ModelO<ClassificationTracker, Outputs, Config>;
|
||||
|
||||
ClassificationTracker() {}
|
||||
|
|
|
@ -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<int32_t> _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<Space>;
|
||||
using Classifications = std::vector<Space::Change>;
|
||||
using Changes = std::vector<Space::Change>;
|
||||
using SortedChanges = std::vector<std::vector<int32_t>>;
|
||||
|
||||
} // namespace workload
|
||||
|
||||
|
|
Loading…
Reference in a new issue