Load all data sets ahead of time.
This allows for easier flipping through all images.
This commit is contained in:
@@ -60,6 +60,46 @@ static void renderLoadingScreen()
|
|||||||
restorePerspectiveProjection();
|
restorePerspectiveProjection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef std::vector<std::vector<std::pair<std::unique_ptr<LayerVisualisation>, std::unique_ptr<Animation>>>> VisualisationList;
|
||||||
|
|
||||||
|
static VisualisationList loadVisualisations(const Options& options)
|
||||||
|
{
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
auto [layerInfo, layerData] = Simulator::loadSimulationData(options);
|
||||||
|
|
||||||
|
VisualisationList result;
|
||||||
|
|
||||||
|
for (auto &&item : layerData) {
|
||||||
|
vector<unique_ptr<LayerVisualisation>> layers;
|
||||||
|
vector<unique_ptr<Animation>> animations;
|
||||||
|
LayerData* prevData = nullptr;
|
||||||
|
|
||||||
|
for (LayerData &layer : item) {
|
||||||
|
unique_ptr<LayerVisualisation> layerVisualisation(getVisualisationForLayer(layer, layerInfo.at(layer.name())));
|
||||||
|
|
||||||
|
if (prevData != nullptr) {
|
||||||
|
auto animation = getActivityAnimation(*prevData, layer, layerInfo.at(layer.name()), (*layers.rbegin())->nodePositions(), layerVisualisation->nodePositions());
|
||||||
|
animations.emplace_back(animation);
|
||||||
|
}
|
||||||
|
|
||||||
|
layers.emplace_back(move(layerVisualisation));
|
||||||
|
prevData = &layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
VisualisationList::value_type dataSet;
|
||||||
|
|
||||||
|
for (auto i = 0u; i < layers.size(); ++i) {
|
||||||
|
auto interaction = i < animations.size() ? move(animations[i]) : nullptr;
|
||||||
|
dataSet.emplace_back(move(layers[i]), move(interaction));
|
||||||
|
}
|
||||||
|
|
||||||
|
result.push_back(move(dataSet));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void RenderingState::move(unsigned char key, bool sprint)
|
void RenderingState::move(unsigned char key, bool sprint)
|
||||||
{
|
{
|
||||||
float speed = 0.5f;
|
float speed = 0.5f;
|
||||||
@@ -233,43 +273,6 @@ void RenderingState::handleMouseAt(int x, int y)
|
|||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderingState::queueUpdate()
|
|
||||||
{
|
|
||||||
// Make sure that visualisations are cleared in the current thread
|
|
||||||
layerVisualisations.clear();
|
|
||||||
interactionAnimations.clear();
|
|
||||||
|
|
||||||
visualisationFuture = std::async(std::launch::async, []() {
|
|
||||||
RenderingState::instance().updateVisualisers();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderingState::updateVisualisers()
|
|
||||||
{
|
|
||||||
layerVisualisations.clear();
|
|
||||||
interactionAnimations.clear();
|
|
||||||
LayerData *prevState = nullptr;
|
|
||||||
LayerVisualisation *prevVisualisation = nullptr;
|
|
||||||
|
|
||||||
for (LayerData &layer : *currentData) {
|
|
||||||
LayerVisualisation *visualisation = getVisualisationForLayer(layer, layerInfo.at(layer.name()));
|
|
||||||
if (prevState && prevVisualisation && visualisation) {
|
|
||||||
auto interaction = getActivityAnimation(*prevState, layer, layerInfo.at(layer.name()),
|
|
||||||
prevVisualisation->nodePositions(), visualisation->nodePositions());
|
|
||||||
interactionAnimations.emplace_back(interaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
layerVisualisations.emplace_back(visualisation);
|
|
||||||
|
|
||||||
prevVisualisation = visualisation;
|
|
||||||
prevState = &layer;
|
|
||||||
}
|
|
||||||
|
|
||||||
glutPostRedisplay();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderingState::render(float time) const
|
void RenderingState::render(float time) const
|
||||||
{
|
{
|
||||||
// Clear Color and Depth Buffers
|
// Clear Color and Depth Buffers
|
||||||
@@ -317,13 +320,16 @@ void RenderingState::drawLayer(float time, unsigned long i) const
|
|||||||
{
|
{
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
renderLayerName(currentData->at(i).name());
|
auto& layer = currentData->at(i);
|
||||||
|
|
||||||
|
// TODO: make names available again.
|
||||||
|
// renderLayerName(currentData->at(i).name());
|
||||||
if (options.renderLayers) {
|
if (options.renderLayers) {
|
||||||
layerVisualisations[i]->draw(time);
|
layer.first->draw(time);
|
||||||
}
|
}
|
||||||
if (options.renderInteractions && i < interactionAnimations.size() && interactionAnimations[i]) {
|
if (options.renderInteractions && layer.second) {
|
||||||
interactionAnimations[i]->draw(time);
|
layer.second->draw(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
@@ -361,7 +367,7 @@ void RenderingState::renderLayerName(const std::string &name) const
|
|||||||
glColor3f(0.5, 0.5, 0.5);
|
glColor3f(0.5, 0.5, 0.5);
|
||||||
auto layerName = name;
|
auto layerName = name;
|
||||||
layerName += ": ";
|
layerName += ": ";
|
||||||
layerName += LayerInfo::nameByType(layerInfo.at(name).type());
|
//layerName += LayerInfo::nameByType(layerInfo.at(name).type());
|
||||||
renderText(layerName);
|
renderText(layerName);
|
||||||
|
|
||||||
glTranslatef(0, 0, -10);
|
glTranslatef(0, 0, -10);
|
||||||
@@ -375,19 +381,17 @@ void RenderingState::handleSpecialKey(int key)
|
|||||||
}
|
}
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case GLUT_KEY_LEFT:
|
case GLUT_KEY_LEFT:
|
||||||
if (currentData == layerData.begin()) {
|
if (currentData == visualisations.begin()) {
|
||||||
currentData = layerData.end();
|
currentData = visualisations.end();
|
||||||
}
|
}
|
||||||
--currentData;
|
--currentData;
|
||||||
queueUpdate();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GLUT_KEY_RIGHT:
|
case GLUT_KEY_RIGHT:
|
||||||
++currentData;
|
++currentData;
|
||||||
if (currentData == layerData.end()) {
|
if (currentData == visualisations.end()) {
|
||||||
currentData = layerData.begin();
|
currentData = visualisations.begin();
|
||||||
}
|
}
|
||||||
queueUpdate();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GLUT_KEY_F1:
|
case GLUT_KEY_F1:
|
||||||
@@ -420,7 +424,7 @@ void RenderingState::loadOptions(const Options &programOptions)
|
|||||||
options.layerAlpha = programOptions.layerTransparancy();
|
options.layerAlpha = programOptions.layerTransparancy();
|
||||||
options.interactionAlpha = programOptions.interactionTransparancy();
|
options.interactionAlpha = programOptions.interactionTransparancy();
|
||||||
|
|
||||||
simulationFuture = std::async(std::launch::async, Simulator::loadSimulationData, programOptions);
|
loadingFuture = std::async(std::launch::async, loadVisualisations, programOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Color &RenderingState::pathColor() const
|
const Color &RenderingState::pathColor() const
|
||||||
@@ -485,19 +489,10 @@ static std::optional<T> awaitCompletion(std::future<T>& f)
|
|||||||
void RenderingState::idleFunc()
|
void RenderingState::idleFunc()
|
||||||
{
|
{
|
||||||
if (isLoading()) {
|
if (isLoading()) {
|
||||||
if (visualisationFuture.valid()) {
|
if (auto result = awaitCompletion(loadingFuture); result) {
|
||||||
auto result = awaitCompletion(visualisationFuture);
|
visualisations = std::move(*result);
|
||||||
if (result) {
|
loadGLItems();
|
||||||
loadGLItems();
|
currentData = visualisations.begin();
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else if (simulationFuture.valid()) {
|
|
||||||
auto result = awaitCompletion(simulationFuture);
|
|
||||||
if (result) {
|
|
||||||
tie(layerInfo, layerData) = std::move(*result);
|
|
||||||
currentData = layerData.begin();
|
|
||||||
queueUpdate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (options.mouse_1_pressed) {
|
if (options.mouse_1_pressed) {
|
||||||
@@ -513,11 +508,17 @@ void RenderingState::idleFunc()
|
|||||||
|
|
||||||
void RenderingState::loadGLItems()
|
void RenderingState::loadGLItems()
|
||||||
{
|
{
|
||||||
std::for_each(layerVisualisations.begin(), layerVisualisations.end(), [](auto& x) { x->glLoad(); });
|
for (auto &item : visualisations) {
|
||||||
std::for_each(interactionAnimations.begin(), interactionAnimations.end(), [](auto& x) { if (x) x->glLoad(); });
|
for (auto &item2 : item) {
|
||||||
|
item2.first->glLoad();
|
||||||
|
if (item2.second) {
|
||||||
|
item2.second->glLoad();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RenderingState::isLoading() const
|
bool RenderingState::isLoading() const
|
||||||
{
|
{
|
||||||
return visualisationFuture.valid() || simulationFuture.valid();
|
return loadingFuture.valid();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,13 +73,10 @@ namespace fmri
|
|||||||
} options;
|
} options;
|
||||||
std::array<float, 3> pos;
|
std::array<float, 3> pos;
|
||||||
std::array<float, 2> angle;
|
std::array<float, 2> angle;
|
||||||
std::map<std::string, LayerInfo> layerInfo;
|
std::vector<std::vector<std::pair<std::unique_ptr<LayerVisualisation>, std::unique_ptr<Animation>>>> visualisations;
|
||||||
std::vector<std::vector<LayerData>> layerData;
|
std::future<decltype(visualisations)> loadingFuture;
|
||||||
std::vector<std::vector<LayerData>>::iterator currentData;
|
|
||||||
std::vector<std::unique_ptr<LayerVisualisation>> layerVisualisations;
|
decltype(visualisations)::iterator currentData;
|
||||||
std::vector<std::unique_ptr<Animation>> interactionAnimations;
|
|
||||||
std::future<bool> visualisationFuture;
|
|
||||||
std::future<std::pair<decltype(layerInfo), decltype(layerData)>> simulationFuture;
|
|
||||||
|
|
||||||
|
|
||||||
RenderingState() noexcept;
|
RenderingState() noexcept;
|
||||||
@@ -87,7 +84,7 @@ namespace fmri
|
|||||||
void configureRenderingContext() const;
|
void configureRenderingContext() const;
|
||||||
|
|
||||||
void move(unsigned char key, bool sprint);
|
void move(unsigned char key, bool sprint);
|
||||||
void updateVisualisers();
|
|
||||||
void idleFunc();
|
void idleFunc();
|
||||||
|
|
||||||
std::string debugInfo() const;
|
std::string debugInfo() const;
|
||||||
@@ -96,8 +93,6 @@ namespace fmri
|
|||||||
|
|
||||||
void drawLayer(float time, unsigned long i) const;
|
void drawLayer(float time, unsigned long i) const;
|
||||||
|
|
||||||
void queueUpdate();
|
|
||||||
|
|
||||||
void renderVisualisation(float time) const;
|
void renderVisualisation(float time) const;
|
||||||
|
|
||||||
void loadGLItems();
|
void loadGLItems();
|
||||||
|
|||||||
Reference in New Issue
Block a user