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

Hot colorscheme switch #873

Merged
merged 4 commits into from
Apr 17, 2020
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
7 changes: 4 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "CMake/common"]
path = CMake/common
url = https://github.com/Eyescale/CMake
[submodule "uvw"]
path = deps/uvw
url = https://github.com/skypjack/uvw.git
Expand All @@ -22,3 +19,7 @@
[submodule "deps/imgui"]
path = deps/imgui
url = https://github.com/ocornut/imgui.git
[submodule "CMake/common"]
path = CMake/common
url = https://github.com/BlueBrain/CMake.git
branch = brayns_recursive_submodules
4 changes: 2 additions & 2 deletions .gitsubprojects
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ endif()

# Data access
if(BRAYNS_CIRCUITVIEWER_ENABLED)
git_subproject(Brion https://github.com/BlueBrain/Brion.git 551fbb0)
git_subproject(Brion https://github.com/BlueBrain/Brion.git 39ad3483)
endif()

if(BRAYNS_BBIC_ENABLED)
if(BRAYNS_BBIC_ENABLED AND NOT TARGET HighFive)
git_subproject(HighFive https://github.com/BlueBrain/HighFive.git 68fbe8e)
endif()
2 changes: 1 addition & 1 deletion CMake/common
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(Brayns VERSION 1.0.1)
set(Brayns_VERSION_ABI 1)

set(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL)
set(OpenGL_GL_PREFERENCE LEGACY)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake
${CMAKE_SOURCE_DIR}/CMake/common)
if(NOT EXISTS ${CMAKE_SOURCE_DIR}/CMake/common/Common.cmake)
Expand Down
7 changes: 7 additions & 0 deletions brayns/common/simulation/AbstractSimulationHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class AbstractSimulationHandler

/** @return the current loaded frame for the simulation. */
uint32_t getCurrentFrame() const { return _currentFrame; }

/**
* @brief Sets the current frame played by this simulation handler
* @param newFrame unsigned integer.
*/
void setCurrentFrame(const uint32_t newFrame) { _currentFrame = newFrame; }

/**
* @brief returns a void pointer to the simulation data for the given frame
* or nullptr if the frame is not loaded yet.
Expand Down
9 changes: 9 additions & 0 deletions brayns/engine/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ void Model::logInformation()
uint64_t nbCylinders = 0;
uint64_t nbCones = 0;
uint64_t nbSdfBeziers = 0;
uint64_t nbSdfGeoms = 0;
uint64_t nbMeshes = _geometries->_triangleMeshes.size();
for (const auto& spheres : _geometries->_spheres)
nbSpheres += spheres.second.size();
Expand All @@ -408,11 +409,14 @@ void Model::logInformation()
nbCones += cones.second.size();
for (const auto& sdfBeziers : _geometries->_sdfBeziers)
nbSdfBeziers += sdfBeziers.second.size();
for (const auto& sdfGeoms : _geometries->_sdf.geometryIndices)
nbSdfGeoms += sdfGeoms.second.size();

BRAYNS_DEBUG << "Spheres: " << nbSpheres
<< ", Cylinders: " << nbCylinders
<< ", Cones: " << nbCones
<< ", SDFBeziers: " << nbSdfBeziers
<< ", SDFGeometries: " << nbSdfGeoms
<< ", Meshes: " << nbMeshes
<< ", Memory: " << _sizeInBytes << " bytes ("
<< _sizeInBytes / 1048576 << " MB), Bounds: " << _bounds
Expand Down Expand Up @@ -469,7 +473,12 @@ void Model::copyFrom(const Model& rhs)
return;

if (rhs._simulationHandler)
{
_simulationHandler = rhs._simulationHandler->clone();
// Reset simulation handler current frame so the simulation data gets commited
// (current frame != animation params current frame)
_simulationHandler->setCurrentFrame(std::numeric_limits<uint32_t>::max());
}

_transferFunction = rhs._transferFunction;
_materials.clear();
Expand Down
84 changes: 84 additions & 0 deletions brayns/engine/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ std::shared_ptr<T> _remove(std::vector<std::shared_ptr<T>>& list,
list.erase(i);
return result;
}

template<typename T, typename U = T>
std::shared_ptr<T> _replace(std::vector<std::shared_ptr<T>>& list,
const size_t id,
std::shared_ptr<T> newObj,
size_t (U::*getID)() const = &T::getID)
{
auto i = std::find_if(list.begin(), list.end(), [id, getID](auto x) {
return id == ((*x).*getID)();
});
if (i == list.end())
return std::shared_ptr<T>{};
auto result = *i;
*i = newObj;
return result;
}
} // namespace

namespace brayns
Expand Down Expand Up @@ -150,6 +166,35 @@ size_t Scene::addModel(ModelDescriptorPtr modelDescriptor)
return modelDescriptor->getModelID();
}

void Scene::addModel(const size_t id, ModelDescriptorPtr modelDescriptor)
{
auto& model = modelDescriptor->getModel();
if (model.empty())
throw std::runtime_error("Empty models not supported.");

const auto defaultBVHFlags = _geometryParameters.getDefaultBVHFlags();

model.setBVHFlags(defaultBVHFlags);
model.buildBoundingBox();

// Since models can be added concurrently we check if that is supported
if (supportsConcurrentSceneUpdates())
model.commitGeometry();

{
if(replaceModel(id, modelDescriptor))
modelDescriptor->setModelID(id);

// add default instance of this model to render something
if (modelDescriptor->getInstances().empty())
modelDescriptor->addInstance(
{true, true, modelDescriptor->getTransformation()});
}

_computeBounds();
markModified();
}

bool Scene::removeModel(const size_t id)
{
ModelDescriptorPtr model = nullptr;
Expand Down Expand Up @@ -183,6 +228,45 @@ bool Scene::removeModel(const size_t id)
return false;
}

bool Scene::isMarkedForReplacement(const size_t id)
{
auto it = _markedForReplacement.find(id);
return it != _markedForReplacement.end();
}

bool Scene::replaceModel(const size_t id, ModelDescriptorPtr modelDescriptor)
{
ModelDescriptorPtr model = nullptr;

if(supportsConcurrentSceneUpdates())
{
{
std::unique_lock<std::shared_timed_mutex> lock(_modelMutex);
model =
_replace(_modelDescriptors, id,
modelDescriptor, &ModelDescriptor::getModelID);
}
}
else
{
{
std::unique_lock<std::shared_timed_mutex> lock(_modelMutex);
model = _find(_modelDescriptors, id, &ModelDescriptor::getModelID);
}
// Make sure it exists
if (model)
_markedForReplacement[id] = modelDescriptor;
}

if(model)
{
markModified();
return true;
}

return false;
}

ModelDescriptorPtr Scene::getModel(const size_t id) const
{
auto lock = acquireReadAccess();
Expand Down
25 changes: 25 additions & 0 deletions brayns/engine/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,36 @@ class Scene : public BaseObject
*/
BRAYNS_API size_t addModel(ModelDescriptorPtr model);

/**
* @brief Adds a model to the scene with the specific model id
* @param id to be used as model identifier
* @param model the model itself
*/
BRAYNS_API void addModel(const size_t id, ModelDescriptorPtr model);

/**
Removes a model from the scene
@param id id of the model (descriptor)
@return True if model was found and removed, false otherwise
*/
BRAYNS_API bool removeModel(const size_t id);

/**
* @brief Check wether a model has been marked for replacement
* for a new model
* @param id the ID of the model to replace the current one
* @return true if the model is on the list to be replaced
*/
BRAYNS_API bool isMarkedForReplacement(const size_t id);

/**
* @brief Replaces an existing model (given its ID) for a new one
* @param id the ID of the model to replace
* @param modelDescriptor The model which will replace the current one
* @return True if the model was found and replace, false otherwise
*/
BRAYNS_API bool replaceModel(const size_t id, ModelDescriptorPtr modelDescriptor);

BRAYNS_API ModelDescriptorPtr getModel(const size_t id) const;

/**
Expand Down Expand Up @@ -206,6 +229,8 @@ class Scene : public BaseObject
ModelDescriptors _modelDescriptors;
mutable std::shared_timed_mutex _modelMutex;

std::unordered_map<size_t, ModelDescriptorPtr> _markedForReplacement;

LightManager _lightManager;
ClipPlanes _clipPlanes;

Expand Down
27 changes: 24 additions & 3 deletions brayns/io/MeshLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,13 @@ ModelDescriptorPtr MeshLoader::importFromBlob(
}

void MeshLoader::_createMaterials(Model& model, const aiScene* aiScene,
const std::string& folder) const
const std::string& folder,
MaterialInfoList& list) const
{
BRAYNS_DEBUG << "Loading " << aiScene->mNumMaterials << " materials"
<< std::endl;

list.resize(aiScene->mNumMaterials);
for (size_t m = 0; m < aiScene->mNumMaterials; ++m)
{
aiMaterial* aimaterial = aiScene->mMaterials[m];
Expand All @@ -223,6 +225,9 @@ void MeshLoader::_createMaterials(Model& model, const aiScene* aiScene,
std::string name{valueString.C_Str()};
auto material = model.createMaterial(m, name);

list[m].name = name;
list[m].materialId = m;

struct TextureTypeMapping
{
aiTextureType aiType;
Expand Down Expand Up @@ -306,8 +311,9 @@ ModelMetadata MeshLoader::_postLoad(const aiScene* aiScene, Model& model,
// Always create placeholder material since it is not guaranteed to exist
model.createMaterial(materialId, "default");

MaterialInfoList matInfoList;
if (materialId == NO_MATERIAL)
_createMaterials(model, aiScene, folder);
_createMaterials(model, aiScene, folder, matInfoList);

std::unordered_map<size_t, size_t> nbVertices;
std::unordered_map<size_t, size_t> nbFaces;
Expand Down Expand Up @@ -409,12 +415,27 @@ ModelMetadata MeshLoader::_postLoad(const aiScene* aiScene, Model& model,
const auto numVertices =
std::accumulate(nbVertices.begin(), nbVertices.end(), 0,
[](auto value, auto& i) { return value + i.second; });

std::string materialInfo = "";
if(!matInfoList.empty())
{
materialInfo += "[";
for(size_t i = 0; i < matInfoList.size(); i++)
{
const auto& mi = matInfoList[i];
const std::string ending = (i + 1 < matInfoList.size())? "," : "";
materialInfo += "{\"name\":\""+mi.name+"\",\"ids\":["+std::to_string(mi.materialId)+"]}" + ending;
}
materialInfo += "]";
}

const auto numFaces =
std::accumulate(nbFaces.begin(), nbFaces.end(), 0,
[](auto value, auto& i) { return value + i.second; });
ModelMetadata metadata{{"meshes", std::to_string(aiScene->mNumMeshes)},
{"vertices", std::to_string(numVertices)},
{"faces", std::to_string(numFaces)}};
{"faces", std::to_string(numFaces)},
{"materialGroups", materialInfo}};
return metadata;
}

Expand Down
10 changes: 9 additions & 1 deletion brayns/io/MeshLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,18 @@ class MeshLoader : public Loader
const GeometryQuality geometryQuality) const;

private:
struct MaterialInfo
{
std::string name;
size_t materialId;
};
typedef std::vector<MaterialInfo> MaterialInfoList;

PropertyMap _defaults;

void _createMaterials(Model& model, const aiScene* aiScene,
const std::string& folder) const;
const std::string& folder,
MaterialInfoList& list) const;

ModelMetadata _postLoad(const aiScene* aiScene, Model& model,
const Matrix4f& transformation,
Expand Down
14 changes: 14 additions & 0 deletions engines/optix/OptiXScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,20 @@ void OptiXScene::commit()
[](const auto& m) { return m->isMarkedForRemoval(); }),
_modelDescriptors.end());

// Replace all models marked for replacement
for(auto& pair : _markedForReplacement)
{
auto it = std::find_if(std::begin(_modelDescriptors),
std::end(_modelDescriptors),
[checkId = pair.first](const auto& m)
{
return m->getModelID() == checkId;
});

if(it != std::end(_modelDescriptors))
*it = pair.second;
}

auto context = OptiXContext::get().getOptixContext();

auto values = std::map<TextureType, std::string>{
Expand Down
6 changes: 1 addition & 5 deletions engines/ospray/ispc/geometry/RayMarching.isph
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ inline float raymarching(const Ray& ray,
float candidate_t = t0;
float prev_radius = 0.f;
float step_length = 0.f;
uniform int step_count = 0;
const uniform bool force_hit = true;

// check if we start inside or outside of the shape
float sdf_sign = (sdfDistance(ray.org, geo, prim, params) < 0 ? -1 : 1);
Expand Down Expand Up @@ -137,11 +135,9 @@ inline float raymarching(const Ray& ray,
break;

t += step_length;

step_count++;
}

if (t > t1 || (candidate_error > pixel_radius && !force_hit))
if (t > t1 || candidate_error > pixel_radius)
return -1.f;

return candidate_t;
Expand Down
3 changes: 1 addition & 2 deletions engines/ospray/ispc/geometry/SDFGeometries.ispc
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,8 @@ inline float sdConePill(const vec3f& p, const vec3f p0, const vec3f p1,
const float b = c1 / c2;
const vec3f Pb = p0 + b * v;

const float thicknessAt = lerp(b, r0, r1);
const float thickness =
useSigmoid ? lerp(smootherstep(b), r0, r1) : thicknessAt;
useSigmoid ? lerp(smootherstep(b), r0, r1) : lerp(b, r0, r1);

return length(p - Pb) - thickness;
}
Expand Down
6 changes: 4 additions & 2 deletions plugins/CircuitExplorer/.gitsubprojects
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- mode: cmake -*-
git_subproject(HighFive https://github.com/BlueBrain/HighFive.git 68fbe8e)
git_subproject(Brion https://github.com/BlueBrain/Brion.git 551fbb0)
git_subproject(Brion https://github.com/BlueBrain/Brion.git 39ad3483)
if(NOT TARGET HighFive)
git_subproject(HighFive https://github.com/BlueBrain/HighFive.git 68fbe8e)
endif()
Loading