Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addons and fixes #863

Merged
merged 1 commit into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions plugins/CircuitExplorer/plugin/CircuitExplorerPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include <cstdio>
#include <dirent.h>
#include <fstream>
#include <random>
#include <regex>
#include <unistd.h>

Expand Down Expand Up @@ -701,6 +702,14 @@ void CircuitExplorerPlugin::_setMaterialRange(const MaterialRangeDescriptor& mrd
matIds.push_back(static_cast<size_t>(id));
}

if(mrd.diffuseColor.size() % 3 != 0)
{
PLUGIN_ERROR << "set-material-range: The diffuse colors component is not a multiple of 3" << std::endl;
return;
}

const size_t numColors = mrd.diffuseColor.size() / 3;

for (const auto materialId : matIds)
{
try
Expand All @@ -709,9 +718,10 @@ void CircuitExplorerPlugin::_setMaterialRange(const MaterialRangeDescriptor& mrd
modelDescriptor->getModel().getMaterial(materialId);
if (material)
{
material->setDiffuseColor({mrd.diffuseColor[0],
mrd.diffuseColor[1],
mrd.diffuseColor[2]});
const size_t randomIndex = (rand() % numColors) * 3;
material->setDiffuseColor({mrd.diffuseColor[randomIndex],
mrd.diffuseColor[randomIndex + 1],
mrd.diffuseColor[randomIndex + 2]});
material->setSpecularColor({mrd.specularColor[0],
mrd.specularColor[1],
mrd.specularColor[2]});
Expand Down
57 changes: 55 additions & 2 deletions plugins/Rockets/RocketsPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "ImageGenerator.h"
#include "Throttle.h"

#include <atomic>
#include <dirent.h>
#include <fstream>
#include <limits.h>
Expand Down Expand Up @@ -132,6 +133,7 @@ const std::string METHOD_FS_LIST_DIR = "fs-list-dir";
// JSONRPC notifications
const std::string METHOD_CHUNK = "chunk";
const std::string METHOD_QUIT = "quit";
const std::string METHOD_EXIT_LATER = "exit-later";
const std::string METHOD_RESET_CAMERA = "reset-camera";

const std::string LOADERS_SCHEMA = "loaders-schema";
Expand Down Expand Up @@ -992,6 +994,7 @@ class RocketsPlugin::Impl : public ActionInterface

_handleInspect();
_handleQuit();
_handleExitLater();
_handleResetCamera();
_handleSnapshot();

Expand Down Expand Up @@ -1092,7 +1095,7 @@ class RocketsPlugin::Impl : public ActionInterface

void _broadcastControlledImageJpeg()
{
if(!_controlledStreamingFlag)
if(!_controlledStreamingFlag.load())
{
return;
}
Expand Down Expand Up @@ -1281,6 +1284,42 @@ class RocketsPlugin::Impl : public ActionInterface
});
}

void _handleExitLater()
{
_handleRPC<ExitLaterSchedule>({METHOD_EXIT_LATER,
"Schedules Brayns to shutdown after a given amount of minutes",
"minutes", "Number of minutes after which Brayns will shut down"},
[&](const ExitLaterSchedule& schedule){
std::lock_guard<std::mutex> lock(_scheduleMutex);
if(schedule.minutes > 0)
{
if(_scheduledShutdownActive)
{
_cancelScheduledShutdown = true;
_monitor.notify_all();
_shutDownWorker->join();
_shutDownWorker.reset();
_cancelScheduledShutdown = false;
_scheduledShutdownActive = false;
}

_scheduledShutdownActive = true;
const uint32_t mins = schedule.minutes;
_shutDownWorker = std::unique_ptr<std::thread>(new std::thread([&, mins]()
{
std::chrono::milliseconds timeToWait (mins * 60000);
std::unique_lock<std::mutex> threadLock(_waitLock);
_monitor.wait_for(threadLock, timeToWait);
if(!_cancelScheduledShutdown)
{
_engine.setKeepRunning(false);
_engine.triggerRender();
}
}));
}
});
}

void _handleResetCamera()
{
_handleRPC({METHOD_RESET_CAMERA,
Expand Down Expand Up @@ -2292,8 +2331,22 @@ class RocketsPlugin::Impl : public ActionInterface
// alter the list of renderers for instance
bool _endpointsRegistered{false};

// Wether to use controlled stream (true = client request frames, false = continous stream of frames)
bool _useControlledStream{false};
bool _controlledStreamingFlag{false};
// Flag used to control the frame send when _useControlledStream = true
std::atomic<bool> _controlledStreamingFlag{false};

// Wether a scheduled shutdown is running at the momment
bool _scheduledShutdownActive{false};
// Flag to cancel current scheduled shutdown
bool _cancelScheduledShutdown{false};
// Worker in charge of shutdown
std::unique_ptr<std::thread> _shutDownWorker;
// Lock for safe schedule
std::mutex _scheduleMutex;
// Schedule mechanism
std::mutex _waitLock;
std::condition_variable _monitor;

std::vector<BaseObject*> _objects;

Expand Down
11 changes: 11 additions & 0 deletions plugins/Rockets/jsonSerialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ struct ImageStreamingMethod
std::string type;
};

struct ExitLaterSchedule
{
uint32_t minutes;
};

} // namespace brayns

STATICJSON_DECLARE_ENUM(brayns::GeometryQuality,
Expand Down Expand Up @@ -608,6 +613,12 @@ inline void init(brayns::ImageStreamingMethod* a, ObjectHandler* h)
h->set_flags(Flags::DisallowUnknownKey);
}

inline void init(brayns::ExitLaterSchedule* a, ObjectHandler* h)
{
h->add_property("minutes", &a->minutes);
h->set_flags(Flags::DisallowUnknownKey);
}

} // namespace staticjson

// for rockets::jsonrpc
Expand Down
2 changes: 1 addition & 1 deletion python/brayns/plugins/circuit_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def set_material_range(self, model_id, material_ids, diffuse_color=(1.0, 1.0, 1.
"""
params = dict()
params['modelId'] = model_id
params['materialId'] = material_ids
params['materialIds'] = material_ids
params['diffuseColor'] = diffuse_color
params['specularColor'] = specular_color
params['specularExponent'] = specular_exponent
Expand Down