Skip to content

Commit

Permalink
Added color scheme for layers, e-types and m-types
Browse files Browse the repository at this point in the history
  • Loading branch information
favreau committed Apr 4, 2017
1 parent 9f01bcf commit fa1b919
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 38 deletions.
11 changes: 7 additions & 4 deletions brayns/common/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,13 @@ enum class ColorScheme
neuron_by_id = 1,
neuron_by_type = 2,
neuron_by_segment_type = 3,
protein_by_id = 4,
protein_atoms = 5,
protein_chains = 6,
protein_residues = 7
neuron_by_layer = 4,
neuron_by_mtype = 5,
neuron_by_etype = 6,
protein_by_id = 7,
protein_atoms = 8,
protein_chains = 9,
protein_residues = 10
};

/** Define the environment that is added to the default scene */
Expand Down
11 changes: 7 additions & 4 deletions brayns/common/vocabulary/parameters.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ enum ColorScheme: uint {
neuron_by_id = 1,
neuron_by_type = 2,
neuron_by_segment_type = 3,
protein_by_id = 4,
protein_atoms = 5,
protein_chain = 6,
protein_residue = 7
neuron_by_layer = 4,
neuron_by_mtype = 5,
neuron_by_etype = 6,
protein_by_id = 7,
protein_atoms = 8,
protein_chain = 9,
protein_residue = 10
}

enum SceneEnvironment: uint {
Expand Down
101 changes: 80 additions & 21 deletions brayns/io/MorphologyLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ brain::neuron::SectionTypes _getSectionTypes(
return sectionTypes;
}

bool MorphologyLoader::_importMorphologyAsMesh(const servus::URI& source,
const size_t morphologyIndex,
const MaterialsMap& materials,
const Matrix4f& transformation,
TrianglesMeshMap& meshes,
Boxf& bounds)
bool MorphologyLoader::_importMorphologyAsMesh(
const servus::URI& source, const size_t morphologyIndex,
const MaterialsMap& materials, const Matrix4f& transformation,
TrianglesMeshMap& meshes, Boxf& bounds, const size_t forcedMaterial)
{
try
{
Expand All @@ -85,7 +83,8 @@ bool MorphologyLoader::_importMorphologyAsMesh(const servus::URI& source,
// Soma
const brain::neuron::Soma& soma = morphology.getSoma();
const size_t material = _getMaterialFromSectionType(
morphologyIndex, size_t(brain::neuron::SectionType::soma));
morphologyIndex, forcedMaterial,
size_t(brain::neuron::SectionType::soma));
const Vector3f center = soma.getCentroid();

const float radius =
Expand All @@ -112,7 +111,7 @@ bool MorphologyLoader::_importMorphologyAsMesh(const servus::URI& source,
}

const auto material =
_getMaterialFromSectionType(morphologyIndex,
_getMaterialFromSectionType(morphologyIndex, forcedMaterial,
size_t(section.getType()));
const auto& samples = section.getSamples();
if (samples.empty())
Expand Down Expand Up @@ -144,8 +143,10 @@ bool MorphologyLoader::_importMorphologyAsMesh(const servus::URI& source,
const size_t gridSize = _geometryParameters.getMetaballsGridSize();
const float threshold = _geometryParameters.getMetaballsThreshold();
MetaballsGenerator metaballsGenerator;
const size_t material = _getMaterialFromSectionType(
morphologyIndex, size_t(brain::neuron::SectionType::soma));
const size_t material =
_getMaterialFromSectionType(morphologyIndex, forcedMaterial,
size_t(
brain::neuron::SectionType::soma));
metaballsGenerator.generateMesh(metaballs, gridSize, threshold,
materials, material, meshes);
}
Expand Down Expand Up @@ -182,7 +183,8 @@ bool MorphologyLoader::_importMorphology(
const Matrix4f& transformation,
const SimulationInformation* simulationInformation, SpheresMap& spheres,
CylindersMap& cylinders, ConesMap& cones, Boxf& bounds,
const size_t simulationOffset, float& maxDistanceToSoma)
const size_t simulationOffset, float& maxDistanceToSoma,
const size_t forcedMaterial)
{
maxDistanceToSoma = 0.f;
try
Expand Down Expand Up @@ -233,7 +235,8 @@ bool MorphologyLoader::_importMorphology(
// Soma
const brain::neuron::Soma& soma = morphology.getSoma();
const size_t material = _getMaterialFromSectionType(
morphologyIndex, size_t(brain::neuron::SectionType::soma));
morphologyIndex, forcedMaterial,
size_t(brain::neuron::SectionType::soma));
const Vector3f somaPosition = soma.getCentroid() + translation;

float radius =
Expand Down Expand Up @@ -272,7 +275,7 @@ bool MorphologyLoader::_importMorphology(
for (const auto& section : sections)
{
const size_t material =
_getMaterialFromSectionType(morphologyIndex,
_getMaterialFromSectionType(morphologyIndex, forcedMaterial,
size_t(section.getType()));
const Vector4fs& samples = section.getSamples();
if (samples.empty())
Expand Down Expand Up @@ -374,6 +377,37 @@ bool MorphologyLoader::_importMorphology(
return true;
}

brion::NeuronAttributes getNeuronAttributes(const ColorScheme& colorScheme)
{
brion::NeuronAttributes neuronAttributes;
switch (colorScheme)
{
case ColorScheme::neuron_by_layer:
neuronAttributes = brion::NEURON_LAYER;
break;
case ColorScheme::neuron_by_mtype:
neuronAttributes = brion::NEURON_MTYPE;
break;
case ColorScheme::neuron_by_etype:
neuronAttributes = brion::NEURON_ETYPE;
break;
default:
neuronAttributes = brion::NEURON_ALL;
break;
}
return neuronAttributes;
}

const brion::NeuronMatrix getNeuronMatrix(
const brion::BlueConfig& bc, const brain::GIDSet& gids,
const brion::NeuronAttributes& neuronAttributes)
{
// Load the brion circuit to get cell types
// TO BE REMOVED when this is available in the brain API
const brion::Circuit brionCircuit(bc.getCircuitSource());
return brionCircuit.get(gids, neuronAttributes);
}

bool MorphologyLoader::importCircuit(const servus::URI& circuitConfig,
const std::string& target, Scene& scene)
{
Expand All @@ -388,13 +422,16 @@ bool MorphologyLoader::importCircuit(const servus::URI& circuitConfig,
return false;
}
const Matrix4fs& transforms = circuit.getTransforms(gids);

const brain::URIs& uris = circuit.getMorphologyURIs(gids);

BRAYNS_INFO << "Loading " << uris.size() << " cells" << std::endl;

std::map<size_t, float> morphologyOffsets;
const brion::NeuronAttributes neuronAttributes =
getNeuronAttributes(_geometryParameters.getColorScheme());
const brion::NeuronMatrix& neuronMatrix =
getNeuronMatrix(bc, gids, neuronAttributes);

std::map<size_t, float> morphologyOffsets;
size_t simulationOffset = 1;
size_t simulatedCells = 0;
size_t progress = 0;
Expand All @@ -409,19 +446,23 @@ bool MorphologyLoader::importCircuit(const servus::URI& circuitConfig,
{
const auto& uri = uris[i];
float maxDistanceToSoma = 0.f;
const size_t material =
(neuronAttributes == brion::NEURON_ALL)
? NO_MATERIAL
: boost::lexical_cast<size_t>(neuronMatrix[i][0]);

if (_geometryParameters.useMetaballs())
{
_importMorphologyAsMesh(uri, i, scene.getMaterials(),
transforms[i],
scene.getTriangleMeshes(),
scene.getWorldBounds());
scene.getWorldBounds(), material);
}

if (_importMorphology(uri, i, transforms[i], 0, private_spheres,
private_cylinders, private_cones,
private_bounds, simulationOffset,
maxDistanceToSoma))
maxDistanceToSoma, material))
{
morphologyOffsets[simulatedCells] = maxDistanceToSoma;
simulationOffset += maxDistanceToSoma;
Expand Down Expand Up @@ -499,6 +540,11 @@ bool MorphologyLoader::importCircuit(const servus::URI& circuitConfig,
brain::URIs cr_uris;
const brain::GIDSet& cr_gids = compartmentReport.getGIDs();

const brion::NeuronAttributes neuronAttributes =
getNeuronAttributes(_geometryParameters.getColorScheme());
const brion::NeuronMatrix& neuronMatrix =
getNeuronMatrix(bc, gids, neuronAttributes);

BRAYNS_INFO << "Loading " << cr_gids.size() << " simulated cells"
<< std::endl;
for (const auto cr_gid : cr_gids)
Expand All @@ -521,19 +567,23 @@ bool MorphologyLoader::importCircuit(const servus::URI& circuitConfig,
const auto& uri = cr_uris[i];
const SimulationInformation simulationInformation = {
&compartmentCounts[i], &compartmentOffsets[i]};
const size_t material =
(neuronAttributes == brion::NEURON_ALL)
? NO_MATERIAL
: boost::lexical_cast<size_t>(neuronMatrix[i][0]);

if (_geometryParameters.useMetaballs())
{
_importMorphologyAsMesh(uri, i, scene.getMaterials(),
transforms[i],
scene.getTriangleMeshes(),
scene.getWorldBounds());
scene.getWorldBounds(), material);
}

float maxDistanceToSoma;
_importMorphology(uri, i, transforms[i], &simulationInformation,
private_spheres, private_cylinders, private_cones,
private_bounds, 0, maxDistanceToSoma);
private_bounds, 0, maxDistanceToSoma, material);

BRAYNS_PROGRESS(progress, cr_uris.size());
#pragma omp atomic
Expand Down Expand Up @@ -609,9 +659,15 @@ bool MorphologyLoader::importCircuit(const servus::URI& circuitConfig,
float maxDistanceToSoma;
const auto& uri = allUris[i];

const size_t material =
(neuronAttributes == brion::NEURON_ALL)
? NO_MATERIAL
: boost::lexical_cast<size_t>(neuronMatrix[i][0]);

_importMorphology(uri, i, allTransforms[i], 0, private_spheres,
private_cylinders, private_cones,
private_bounds, 0, maxDistanceToSoma);
private_bounds, 0, maxDistanceToSoma,
material);

BRAYNS_PROGRESS(progress, allUris.size());
#pragma omp atomic
Expand Down Expand Up @@ -767,8 +823,11 @@ bool MorphologyLoader::importSimulationData(const servus::URI&,
#endif

size_t MorphologyLoader::_getMaterialFromSectionType(
const size_t morphologyIndex, const size_t sectionType)
const size_t morphologyIndex, const size_t forcedMaterial,
const size_t sectionType)
{
if (forcedMaterial != NO_MATERIAL)
return forcedMaterial;
size_t material;
switch (_geometryParameters.getColorScheme())
{
Expand Down
11 changes: 7 additions & 4 deletions brayns/io/MorphologyLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,19 @@ class MorphologyLoader
SpheresMap& spheres, CylindersMap& cylinders,
ConesMap& cones, Boxf& bounds,
const size_t simulationOffset,
float& maxDistanceToSoma);
float& maxDistanceToSoma,
const size_t forcedMaterial = NO_MATERIAL);

bool _importMorphologyAsMesh(const servus::URI& source,
const size_t morphologyIndex,
const MaterialsMap& materials,
const Matrix4f& transformation,
TrianglesMeshMap& meshes, Boxf& bounds);
TrianglesMeshMap& meshes, Boxf& bounds,
const size_t forcedMaterial = NO_MATERIAL);

size_t _getMaterialFromSectionType(size_t morphologyIndex,
size_t sectionType);
size_t _getMaterialFromSectionType(const size_t morphologyIndex,
const size_t forcedMaterial,
const size_t sectionType);

const GeometryParameters& _geometryParameters;
};
Expand Down
16 changes: 11 additions & 5 deletions brayns/parameters/GeometryParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,17 @@ 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",
"neuron-by-type", "neuron-by-segment-type",
"protein-by-id", "protein-atoms",
"protein-chains", "protein-residues"};
const std::string COLOR_SCHEMES[11] = {"none",
"neuron-by-id",
"neuron-by-type",
"neuron-by-segment-type",
"neuron-by-layer",
"neuron-by-mtype",
"neuron-by-etype",
"protein-by-id",
"protein-atoms",
"protein-chains",
"protein-residues"};

const std::string SCENE_ENVIRONMENTS[4] = {"none", "ground", "wall",
"bounding-box"};
Expand Down

0 comments on commit fa1b919

Please sign in to comment.