3
0
Fork 0
mirror of https://github.com/lubosz/overte.git synced 2025-04-17 22:19:27 +02:00

jobflow: RegionTracker --> RegionState

This commit is contained in:
Andrew Meadows 2018-03-07 11:19:47 -08:00
parent 03a5a6f4e0
commit 0d9b1a7368
9 changed files with 172 additions and 73 deletions

View file

@ -1,34 +0,0 @@
//
// ClassificationTracker.cpp
// libraries/workload/src/workload
//
// Created by Andrew Meadows 2018.02.21
// Copyright 2018 High Fidelity, Inc.
//
// Originally from lighthouse3d. Modified to utilize glm::vec3 and clean up to our coding standards
// Simple plane class.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "ClassificationTracker.h"
using namespace workload;
void ClassificationTracker::configure(const Config& config) {
}
void ClassificationTracker::run(const WorkloadContextPointer& context, Outputs& outputs) {
auto space = context->_space;
if (space) {
Changes changes;
space->categorizeAndGetChanges(changes);
outputs.resize(workload::Region::NUM_TRANSITIONS);
for (uint32_t i = 0; i < changes.size(); ++i) {
int32_t j = Region::computeTransitionIndex(changes[i].prevRegion, changes[i].region);
assert(j >= 0 && j < workload::Region::NUM_TRANSITIONS);
outputs[j].push_back(changes[i].proxyId);
}
}
}

View file

@ -17,29 +17,10 @@
#include <iostream>
#include "ViewTask.h"
#include "ClassificationTracker.h"
#include "RegionTracker.h"
#include "RegionState.h"
namespace workload {
class DebugCout {
public:
using Inputs = SortedChanges;
using JobModel = workload::Job::ModelI<DebugCout, Inputs>;
DebugCout() {}
void run(const workload::WorkloadContextPointer& renderContext, const Inputs& inputs) {
qDebug() << "Some message from " << inputs.size();
int i = 0;
for (auto& b: inputs) {
qDebug() << " Bucket Number" << i << " size is " << b.size();
i++;
}
}
protected:
};
WorkloadContext::WorkloadContext(const SpacePointer& space) : task::JobContext(trace_workload()), _space(space) {}
class EngineBuilder {
@ -48,8 +29,8 @@ namespace workload {
using JobModel = Task::ModelI<EngineBuilder, Inputs>;
void build(JobModel& model, const Varying& in, Varying& out) {
model.addJob<SetupViews>("setupViews", in);
const auto classifications = model.addJob<ClassificationTracker>("classificationTracker");
// model.addJob<DebugCout>("debug", classifications);
const auto regionChanges = model.addJob<RegionTracker>("regionTracker");
model.addJob<RegionState>("regionState", regionChanges);
}
};

View file

@ -0,0 +1,69 @@
//
// RegionState.cpp
// libraries/workload/src/workload
//
// Created by Andrew Meadows 2018.03.07
// Copyright 2018 High Fidelity, Inc.
//
// Originally from lighthouse3d. Modified to utilize glm::vec3 and clean up to our coding standards
// Simple plane class.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "RegionState.h"
using namespace workload;
void RegionState::run(const workload::WorkloadContextPointer& renderContext, const Inputs& inputs) {
// inputs is a vector of vectors of proxyId's:
//
// inputs[0] = vector of ids exiting region 0
// inputs[1] = vector of ids entering region 0
// ...
// inputs[2N] = vector of ids exiting region N
// inputs[2N + 1] = vector of ids entering region N
assert(inputs.size() == 2 * Region::UNKNOWN);
// The id's in each vector are sorted in ascending order
// because the source vectors are scanned in ascending order.
for (uint32_t i = 0; i < _state.size(); ++i) {
const IndexVector& going = inputs[2 * i];
const IndexVector& coming = inputs[2 * i - 1];
if (coming.size() == 0 && going.size() == 0) {
continue;
}
if (_state[i].empty()) {
assert(going.empty());
_state[i] = coming;
} else {
// NOTE: all vectors are sorted by proxyId!
// which means we can build the new vector by walking three vectors (going, current, coming) in one pass
IndexVector& oldState = _state[i];
IndexVector newState;
newState.reserve(oldState.size() - going.size() + coming.size());
uint32_t goingIndex = 0;
uint32_t comingIndex = 0;
for (uint32_t j = 0; j < oldState.size(); ++j) {
int32_t proxyId = oldState[j];
while (comingIndex < coming.size() && coming[comingIndex] < proxyId) {
newState.push_back(coming[comingIndex]);
++comingIndex;
}
if (goingIndex < going.size() && going[goingIndex] == proxyId) {
++goingIndex;
} else {
newState.push_back(proxyId);
}
}
assert(goingIndex == going.size());
while (comingIndex < coming.size()) {
newState.push_back(coming[comingIndex]);
++comingIndex;
}
oldState.swap(newState);
}
}
}

View file

@ -0,0 +1,38 @@
//
// RegionState.h
// libraries/workload/src/workload
//
// Created by Andrew Meadows 2018.03.07
// Copyright 2018 High Fidelity, Inc.
//
// Originally from lighthouse3d. Modified to utilize glm::vec3 and clean up to our coding standards
// Simple plane class.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_workload_RegionState_h
#define hifi_workload_RegionState_h
#include "Space.h"
#include "Engine.h"
namespace workload {
class RegionState {
public:
using Inputs = IndexVectors;
using JobModel = workload::Job::ModelI<RegionState, Inputs>;
RegionState() {
_state.resize(Region::UNKNOWN);
}
void run(const workload::WorkloadContextPointer& renderContext, const Inputs& inputs);
protected:
IndexVectors _state;
};
}
#endif // hifi_workload_RegionState_h

View file

@ -0,0 +1,43 @@
//
// RegionTracker.cpp
// libraries/workload/src/workload
//
// Created by Andrew Meadows 2018.02.21
// Copyright 2018 High Fidelity, Inc.
//
// Originally from lighthouse3d. Modified to utilize glm::vec3 and clean up to our coding standards
// Simple plane class.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "RegionTracker.h"
#include "Region.h"
using namespace workload;
void RegionTracker::configure(const Config& config) {
}
void RegionTracker::run(const WorkloadContextPointer& context, Outputs& outputs) {
outputs.clear();
auto space = context->_space;
if (space) {
Changes changes;
space->categorizeAndGetChanges(changes);
// use exit/enter lists for each region less than Region::UNKNOWN
outputs.resize(2 * (workload::Region::NUM_CLASSIFICATIONS - 1));
for (uint32_t i = 0; i < changes.size(); ++i) {
Space::Change& change = changes[i];
if (change.prevRegion < Region::UNKNOWN) {
// EXIT list index = 2 * regionIndex
outputs[2 * change.prevRegion].push_back(change.proxyId);
}
if (change.region < Region::UNKNOWN) {
// ENTER list index = 2 * regionIndex + 1
outputs[2 * change.region + 1].push_back(change.proxyId);
}
}
}
}

View file

@ -1,5 +1,5 @@
//
// ClassificationTracker.h
// RegionTracker.h
// libraries/workload/src/workload
//
// Created by Andrew Meadows 2018.02.21
@ -12,27 +12,27 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_workload_ClassificationTracker_h
#define hifi_workload_ClassificationTracker_h
#ifndef hifi_workload_RegionTracker_h
#define hifi_workload_RegionTracker_h
#include "Space.h"
#include "Engine.h"
namespace workload {
class ClassificationTrackerConfig : public Job::Config {
class RegionTrackerConfig : public Job::Config {
Q_OBJECT
public:
ClassificationTrackerConfig() : Job::Config(true) {}
RegionTrackerConfig() : Job::Config(true) {}
};
class ClassificationTracker {
class RegionTracker {
public:
using Config = ClassificationTrackerConfig;
using Outputs = SortedChanges;
using JobModel = workload::Job::ModelO<ClassificationTracker, Outputs, Config>;
using Config = RegionTrackerConfig;
using Outputs = IndexVectors;
using JobModel = workload::Job::ModelO<RegionTracker, Outputs, Config>;
ClassificationTracker() {}
RegionTracker() {}
void configure(const Config& config);
void run(const workload::WorkloadContextPointer& renderContext, Outputs& outputs);
@ -42,4 +42,4 @@ namespace workload {
} // namespace workload
#endif // hifi_workload_ClassificationTracker_h
#endif // hifi_workload_RegionTracker_h

View file

@ -24,6 +24,8 @@
namespace workload {
using IndexVector = std::vector<int32_t>;
class Space {
public:
using Sphere = glm::vec4; // <x,y,z> = center, w = radius
@ -52,7 +54,7 @@ public:
void clear();
int32_t createProxy(const Sphere& sphere);
void deleteProxies(const std::vector<int32_t>& deadIndices);
void deleteProxies(const IndexVector& deadIndices);
void updateProxies(const std::vector<ProxyUpdate>& changedProxies);
void setViews(const std::vector<View>& views);
@ -72,12 +74,12 @@ private:
std::vector<Proxy> _proxies;
Views _views;
std::vector<int32_t> _freeIndices;
IndexVector _freeIndices;
};
using SpacePointer = std::shared_ptr<Space>;
using Changes = std::vector<Space::Change>;
using SortedChanges = std::vector<std::vector<int32_t>>;
using IndexVectors = std::vector<IndexVector>;
} // namespace workload

View file

@ -45,4 +45,4 @@ void View::updateRegions(View& view) {
view.regions[i] = evalRegionSphere(view, refClose * weight, refFar * weight);
refFar *= 2.0f;
}
}
}

View file

@ -63,4 +63,4 @@ using Views = std::vector<View>;
} // namespace workload
#endif // hifi_workload_View_h
#endif // hifi_workload_View_h