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

Added simulation model #142

Merged
merged 2 commits into from
Apr 4, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion brayns/Brayns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ struct Brayns::Impl
auto& scene = _engine->getScene();

strings filters = {".obj", ".dae", ".fbx", ".ply", ".lwo",
".stl", ".3ds", ".ase", ".ifc"};
".stl", ".3ds", ".ase", ".ifc", ".off"};
strings files = parseFolder(folder, filters);
size_t progress = 0;
for (const auto& file : files)
Expand Down
1 change: 1 addition & 0 deletions brayns/common/vocabulary/parameters.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ table DataSource {
end_simulation_time: float;
simulation_values_range: [float:2];
simulation_cache_file: string;
use_simulation_model: bool;
nest_cache_file: string;
morphology_section_types: [SectionType];
morphology_layout: MorphologyLayout;
Expand Down
32 changes: 27 additions & 5 deletions brayns/io/MorphologyLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,38 @@ bool MorphologyLoader::_importMorphology(
const brain::neuron::Soma& soma = morphology.getSoma();
const size_t material = _getMaterialFromSectionType(
morphologyIndex, size_t(brain::neuron::SectionType::soma));
const Vector3f& center = soma.getCentroid() + translation;
const Vector3f somaPosition = soma.getCentroid() + translation;

const float radius =
float radius =
(_geometryParameters.getRadiusCorrection() != 0.f
? _geometryParameters.getRadiusCorrection()
: soma.getMeanRadius() *
_geometryParameters.getRadiusMultiplier());
spheres[material].push_back(
SpherePtr(new Sphere(material, center, radius, 0.f, offset)));
bounds.merge(center);

spheres[material].push_back(SpherePtr(
new Sphere(material, somaPosition, radius, 0.f, offset)));
bounds.merge(somaPosition);

if (_geometryParameters.getUseSimulationModel())
{
// When using a simulation model, parametric geometries must
// occupy as much space as possible in the mesh. This code
// inserts a Cone between the soma and the beginning of each
// branch.
const auto& children = soma.getChildren();
for (const auto& child : children)
{
const auto& samples = child.getSamples();
const Vector3f sample = {samples[0].x(), samples[0].y(),
samples[0].z()};
cones[material].push_back(ConePtr(
new Cone(material, somaPosition, sample, radius,
samples[0].w() * 0.5f *
_geometryParameters.getRadiusMultiplier(),
0.f, offset)));
bounds.merge(sample);
}
}
}

// Dendrites and axon
Expand Down
11 changes: 10 additions & 1 deletion brayns/parameters/GeometryParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const std::string PARAM_METABALLS_GRIDSIZE = "metaballs-grid-size";
const std::string PARAM_METABALLS_THRESHOLD = "metaballs-threshold";
const std::string PARAM_METABALLS_SAMPLES_FROM_SOMA =
"metaballs-samples-from-soma";
const std::string PARAM_USE_SIMULATION_MODEL = "use-simulation-model";

const std::string COLOR_SCHEMES[8] = {
"none", "neuron-by-id",
Expand Down Expand Up @@ -93,6 +94,7 @@ GeometryParameters::GeometryParameters()
, _metaballsGridSize(0)
, _metaballsThreshold(1.f)
, _metaballsSamplesFromSoma(3)
, _useSimulationModel(false)
{
_parameters.add_options()(PARAM_MORPHOLOGY_FOLDER.c_str(),
po::value<std::string>(),
Expand Down Expand Up @@ -170,7 +172,10 @@ GeometryParameters::GeometryParameters()
"Metaballs threshold [float]")(
PARAM_METABALLS_SAMPLES_FROM_SOMA.c_str(), po::value<size_t>(),
"Number of morphology samples (or segments) from soma used by "
"automated meshing [int]");
"automated meshing [int]")(PARAM_USE_SIMULATION_MODEL.c_str(),
po::value<bool>(),
"Defines if a different model is used to "
"handle the simulation geometry [bool]");
}

bool GeometryParameters::_parse(const po::variables_map& vm)
Expand Down Expand Up @@ -282,6 +287,8 @@ bool GeometryParameters::_parse(const po::variables_map& vm)
if (vm.count(PARAM_METABALLS_SAMPLES_FROM_SOMA))
_metaballsSamplesFromSoma =
vm[PARAM_METABALLS_SAMPLES_FROM_SOMA].as<size_t>();
if (vm.count(PARAM_USE_SIMULATION_MODEL))
_useSimulationModel = vm[PARAM_USE_SIMULATION_MODEL].as<bool>();

return true;
}
Expand Down Expand Up @@ -351,6 +358,8 @@ void GeometryParameters::print()
<< std::endl;
BRAYNS_INFO << " - Samples from soma : " << _metaballsSamplesFromSoma
<< std::endl;
BRAYNS_INFO << "Use simulation model : "
<< (_useSimulationModel ? "Yes" : "No") << std::endl;
}

const std::string& GeometryParameters::getColorSchemeAsString(
Expand Down
13 changes: 13 additions & 0 deletions brayns/parameters/GeometryParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ class GeometryParameters : public AbstractParameters

/** Metaballs enabled? */
bool useMetaballs() const { return _metaballsGridSize != 0; }
/**
* Defines if a different model is used to handle the simulation geometry.
* If set to True, the shading of the main geometry model will be done
* using information stored in a secondary model that contains the
* simulation information. See OSPRay simulation renderer for more details.
*/
bool getUseSimulationModel() const { return _useSimulationModel; }
void setUseSimulationModel(const bool value)
{
_useSimulationModel = value;
}

protected:
bool _parse(const po::variables_map& vm) final;

Expand Down Expand Up @@ -204,6 +216,7 @@ class GeometryParameters : public AbstractParameters
size_t _metaballsGridSize;
float _metaballsThreshold;
size_t _metaballsSamplesFromSoma;
bool _useSimulationModel;
};
}
#endif // GEOMETRYPARAMETERS_H
8 changes: 5 additions & 3 deletions plugins/engines/ospray/OSPRayRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,14 @@ void OSPRayRenderer::commit()
_scene->getParametersManager().getSceneParameters().getTimestamp();
const auto model = osprayScene->modelImpl(ts);
if (model)
{
ospSetObject(_renderer, "world", *model);
ospCommit(_renderer);
}
else
BRAYNS_ERROR << "No model found for timestamp " << ts << std::endl;

const auto simulationModel = osprayScene->simulationModelImpl();
if (simulationModel)
ospSetObject(_renderer, "simulationModel", *simulationModel);
ospCommit(_renderer);
}

void OSPRayRenderer::setCamera(CameraPtr camera)
Expand Down
48 changes: 44 additions & 4 deletions plugins/engines/ospray/OSPRayScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static TextureTypeMaterialAttribute textureTypeMaterialAttribute[6] = {
OSPRayScene::OSPRayScene(Renderers renderers,
ParametersManager& parametersManager)
: Scene(renderers, parametersManager)
, _simulationModel(0)
, _ospLightData(0)
, _ospMaterialData(0)
, _ospVolumeData(0)
Expand All @@ -77,6 +78,21 @@ void OSPRayScene::reset()
ospCommit(model.second);
}

if (_simulationModel)
{
for (size_t materialId = 0; materialId < _materials.size();
++materialId)
{
ospRemoveGeometry(_simulationModel,
_ospExtendedSpheres[materialId]);
ospRemoveGeometry(_simulationModel,
_ospExtendedCylinders[materialId]);
ospRemoveGeometry(_simulationModel, _ospExtendedCones[materialId]);
}
ospCommit(_simulationModel);
}
_simulationModel = 0;

_models.clear();

_ospMaterials.clear();
Expand All @@ -99,6 +115,11 @@ void OSPRayScene::commit()
{
for (auto model : _models)
ospCommit(model.second);
if (_simulationModel)
{
BRAYNS_INFO << "Committing simulation model" << std::endl;
ospCommit(_simulationModel);
}
}

OSPModel* OSPRayScene::modelImpl(const size_t timestamp)
Expand Down Expand Up @@ -501,6 +522,7 @@ void OSPRayScene::_createModel(const size_t timestamp)

uint64_t OSPRayScene::_serializeSpheres(const size_t materialId)
{
const auto& geometryParameters = _parametersManager.getGeometryParameters();
uint64_t size = 0;

size_t count = 0;
Expand Down Expand Up @@ -558,7 +580,12 @@ uint64_t OSPRayScene::_serializeSpheres(const size_t materialId)

ospCommit(_ospExtendedSpheres[materialId]);

ospAddGeometry(model.second, _ospExtendedSpheres[materialId]);
if (geometryParameters.getUseSimulationModel())
ospAddGeometry(_simulationModel,
_ospExtendedSpheres[materialId]);
else
ospAddGeometry(model.second,
_ospExtendedSpheres[materialId]);
}
}
}
Expand All @@ -567,6 +594,7 @@ uint64_t OSPRayScene::_serializeSpheres(const size_t materialId)

uint64_t OSPRayScene::_serializeCylinders(const size_t materialId)
{
const auto& geometryParameters = _parametersManager.getGeometryParameters();
uint64_t size = 0;

size_t count = 0;
Expand Down Expand Up @@ -624,7 +652,12 @@ uint64_t OSPRayScene::_serializeCylinders(const size_t materialId)
_ospMaterials[materialId]);

ospCommit(_ospExtendedCylinders[materialId]);
ospAddGeometry(model.second, _ospExtendedCylinders[materialId]);
if (geometryParameters.getUseSimulationModel())
ospAddGeometry(_simulationModel,
_ospExtendedCylinders[materialId]);
else
ospAddGeometry(model.second,
_ospExtendedCylinders[materialId]);
}
}
}
Expand All @@ -633,6 +666,7 @@ uint64_t OSPRayScene::_serializeCylinders(const size_t materialId)

uint64_t OSPRayScene::_serializeCones(const size_t materialId)
{
const auto& geometryParameters = _parametersManager.getGeometryParameters();
uint64_t size = 0;

size_t count = 0;
Expand Down Expand Up @@ -685,8 +719,11 @@ uint64_t OSPRayScene::_serializeCones(const size_t materialId)
_ospMaterials[materialId]);

ospCommit(_ospExtendedCones[materialId]);
ospRemoveGeometry(model.second, _ospExtendedCones[materialId]);
ospAddGeometry(model.second, _ospExtendedCones[materialId]);
if (geometryParameters.getUseSimulationModel())
ospAddGeometry(_simulationModel,
_ospExtendedCones[materialId]);
else
ospAddGeometry(model.second, _ospExtendedCones[materialId]);
}
}
}
Expand Down Expand Up @@ -776,6 +813,9 @@ void OSPRayScene::buildGeometry()
// If no timestamp is available, create a default model at timestamp 0
_models[0] = ospNewModel();

if (_parametersManager.getGeometryParameters().getUseSimulationModel())
_simulationModel = ospNewModel();

BRAYNS_INFO << "Models to process: " << _models.size() << std::endl;

uint64_t size = serializeGeometry();
Expand Down
3 changes: 2 additions & 1 deletion plugins/engines/ospray/OSPRayScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class OSPRayScene : public brayns::Scene
bool isVolumeSupported(const std::string& volumeFile) const final;

OSPModel* modelImpl(const size_t timestamp);

OSPModel* simulationModelImpl() { return &_simulationModel; };
private:
OSPTexture2D _createTexture2D(const std::string& textureName);
void _createModel(const size_t timestamp);
Expand All @@ -93,6 +93,7 @@ class OSPRayScene : public brayns::Scene
void _saveCacheFile();

std::map<size_t, OSPModel> _models;
OSPModel _simulationModel;
std::vector<OSPMaterial> _ospMaterials;
std::map<std::string, OSPTexture2D> _ospTextures;

Expand Down
3 changes: 1 addition & 2 deletions plugins/engines/ospray/ispc/render/ProximityRenderer.ispc
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ inline vec3f ProximityRenderer_shadeRay(
ray.t < self->detectionDistance * 1000.f)
{
// Generate random ray and trace it
varying vec3f ao_dir =
getRandomVector(sample, normal, self->abstract.randomNumber);
varying vec3f ao_dir = getRandomVector(normal);

if (dot(ao_dir, normal) < 0.f)
ao_dir = ao_dir * -1.f;
Expand Down
5 changes: 4 additions & 1 deletion plugins/engines/ospray/ispc/render/SimulationRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

// ospray
#include <ospray/SDK/common/Data.h>
#include <ospray/SDK/common/Model.h>

// ispc exports
#include "SimulationRenderer_ispc.h"
Expand All @@ -36,6 +37,7 @@ void SimulationRenderer::commit()
{
AbstractRenderer::commit();

_simulationModel = (ospray::Model*)getParamObject("simulationModel", 0);
_volumeData = getParamData("volumeData");
_volumeDimensions = getParam3i("volumeDimensions", ospray::vec3i(0));
_volumeElementSpacing =
Expand All @@ -52,7 +54,8 @@ void SimulationRenderer::commit()
_threshold = getParam1f("threshold", _transferFunctionMinValue);

ispc::SimulationRenderer_set(
getIE(), (ispc::vec3f&)_bgColor, _shadowsEnabled, _softShadowsEnabled,
getIE(), (_simulationModel ? _simulationModel->getIE() : nullptr),
(ispc::vec3f&)_bgColor, _shadowsEnabled, _softShadowsEnabled,
_ambientOcclusionStrength, _shadingEnabled, _randomNumber, _timestamp,
_spp, _electronShadingEnabled, _lightPtr, _lightArray.size(),
_materialPtr, _materialArray.size(),
Expand Down
2 changes: 2 additions & 0 deletions plugins/engines/ospray/ispc/render/SimulationRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class SimulationRenderer : public AbstractRenderer
void commit() final;

private:
ospray::Model *_simulationModel;

ospray::Ref<ospray::Data> _volumeData;
ospray::Ref<ospray::Data> _simulationData;
ospray::Ref<ospray::Data> _transferFunctionDiffuseData;
Expand Down
Loading