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

Fixed distance-to-soma issue in CircuitExplorer #841

Merged
merged 2 commits into from
Oct 11, 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
2 changes: 1 addition & 1 deletion plugins/CircuitExplorer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ set(BRAYNSCIRCUITEXPLORER_ISPC_SOURCES
module/ispc/render/ProximityDetectionRenderer.ispc
module/ispc/render/CellGrowthRenderer.ispc
module/ispc/render/utils/CircuitExplorerSimulationRenderer.ispc
module/ispc/render/utils/RandomGenerator.ispc
module/ispc/render/utils/CircuitExplorerRandomGenerator.ispc
module/ispc/render/utils/CircuitExplorerSkyBox.ispc
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ inline bool launchRandomRay(
// normal
randomDirection = neg(randomDirection);

Ray randomRay = sample.ray;
setRay(randomRay, intersection, randomDirection);
Ray randomRay;
randomRay.org = intersection;
randomRay.dir = randomDirection;
randomRay.t0 = geometry.epsilon;
randomRay.t = self->giDistance;
randomRay.time = inf;
randomRay.primID = -1;
randomRay.geomID = -1;
randomRay.instID = -1;
Expand Down Expand Up @@ -429,12 +431,15 @@ inline float shadedLightIntensity(varying ScreenSample& sample,
sample, attributes.normal,
s + attributes.self->randomNumber));

Ray shadowRay = ray;
setRay(shadowRay, dg.P, ld);
Ray shadowRay;
shadowRay.org = dg.P;
shadowRay.dir = ld;
shadowRay.t0 = attributes.self->epsilonFactor * dg.epsilon;
shadowRay.t = attributes.self->giDistance;
shadowRay.time = sample.ray.time;
shadowRay.time = inf;
shadowRay.geomID = -1;
shadowRay.primID = -1;
shadowRay.instID = -1;

while (shadowIntensity < 1.f)
{
Expand Down Expand Up @@ -970,7 +975,7 @@ inline vec3f CircuitExplorerAdvancedRenderer_shadeRay(
const uniform CircuitExplorerAdvancedRenderer* uniform self,
varying ScreenSample& sample)
{
Ray ray = sample.ray;
varying Ray ray = sample.ray;
vec4f color = make_vec4f(0.f);
vec3f bgColor = make_vec3f(0.f);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
#include "../CircuitExplorerMaterial.ih"

// Brayns
#include "CircuitExplorerRandomGenerator.ih"
#include "CircuitExplorerSkyBox.ih"
#include "RandomGenerator.ih"

#include "../../../../../../engines/ospray/ispc/render/utils/Consts.ih"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
#include <ospray/SDK/render/Renderer.ih>
#include <ospray/SDK/render/util.ih>

#include "RandomGenerator.ih"
#include "CircuitExplorerRandomGenerator.ih"

#define HIGH_QUALITY_RANDOM

uniform bool seedInitialized = false;
struct RNGState rngState;

inline float rotate(float x, const float dx)
{
x += dx;
Expand All @@ -35,15 +38,21 @@ inline float rotate(float x, const float dx)

inline float getRandomValue(const varying ScreenSample&, const int)
{
float r;
if (!seedInitialized && programIndex == 0)
{
seed_rng(&rngState, programIndex);
seedInitialized = true;
}

float r = 0.f;
#ifdef HIGH_QUALITY_RANDOM
int nbMaxTries = 10;
while (nbMaxTries >= 0 && rdrand(&r) == false)
--nbMaxTries;
#else
rdrand(&r);
#endif
return r * 10.f;
return r;
}

void getTangentVectors(const vec3f& normal, vec3f& tangent, vec3f& biTangent)
Expand Down
36 changes: 20 additions & 16 deletions plugins/CircuitExplorer/plugin/io/MorphologyLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,10 +646,11 @@ void MorphologyLoader::_addStepConeGeometry(
float MorphologyLoader::_distanceToSoma(const brain::neuron::Section& section,
const size_t sampleId) const
{
float distance = 0.f;
float distance = 0.0;
if (sampleId > 0)
{
const auto& samples = section.getSamples();
for (size_t i = 0; i < sampleId - 1; ++i)
for (size_t i = 0; i < std::min(samples.size(), sampleId) - 1; ++i)
{
const auto& a = samples[i];
const auto& b = samples[i + 1];
Expand All @@ -671,9 +672,9 @@ float MorphologyLoader::_distanceToSoma(const brain::neuron::Section& section,
}
}

return distance * 10.f; // Since user data is uint64_t, we multiply by 10 to
// increase the precision of the growth (first
// decimal value will then be considered)
return distance * 10.f; // Since user data is uint64_t, we multiply by
// 10 to increase the precision of the growth
// (first decimal value will then be considered)
}

void MorphologyLoader::_importMorphologyFromURI(
Expand Down Expand Up @@ -702,8 +703,8 @@ void MorphologyLoader::_importMorphologyFromURI(
const auto maxDistanceToSoma = properties.getProperty<double>(
PROP_MORPHOLOGY_MAX_DISTANCE_TO_SOMA.name);

// If there is no compartment report, the offset in the simulation buffer is
// the index of the morphology in the circuit
// If there is no compartment report, the offset in the simulation
// buffer is the index of the morphology in the circuit
uint64_t userDataOffset = 0;
if (compartmentReport)
userDataOffset = compartmentReport->getOffsets()[index][0];
Expand Down Expand Up @@ -779,7 +780,7 @@ void MorphologyLoader::_importMorphologyFromURI(
{
const auto& counts =
compartmentReport->getCompartmentCounts()[index];
// Number of compartments usually differs from number of samples
// Number of compartments usually differs from number of samples
segmentStep = counts[section.getID()] / double(numSamples);
}

Expand Down Expand Up @@ -820,10 +821,10 @@ void MorphologyLoader::_importMorphologyFromURI(
const auto& counts =
compartmentReport->getCompartmentCounts()[index];

// Update the offset if we have enough compartments aka a
// full compartment report. Otherwise we keep the soma
// offset which happens for soma reports and use this for
// all the sections
// Update the offset if we have enough compartments aka
// a full compartment report. Otherwise we keep the soma
// offset which happens for soma reports and use this
// for all the sections
if (section.getID() < counts.size())
{
if (counts[section.getID()] > 0)
Expand All @@ -835,8 +836,9 @@ void MorphologyLoader::_importMorphologyFromURI(
brain::neuron::SectionType::axon)
userDataOffset = offsets[lastAxon];
else
// This should never happen, but just in case
// use an invalid value to show an error color
// This should never happen, but just in
// case use an invalid value to show an
// error color
userDataOffset =
std::numeric_limits<uint64_t>::max();
}
Expand Down Expand Up @@ -947,10 +949,12 @@ brayns::ModelDescriptorPtr MorphologyLoader::importFromFile(
const std::string& fileName, const brayns::LoaderProgress& /*callback*/,
const brayns::PropertyMap& properties) const
{
// TODO: This needs to be done to work around wrong types coming from the UI
// TODO: This needs to be done to work around wrong types coming from
// the UI
brayns::PropertyMap props = _defaults;
props.merge(properties);
// TODO: This needs to be done to work around wrong types coming from the UI
// TODO: This needs to be done to work around wrong types coming from
// the UI

auto model = _scene.createModel();
importMorphology(props, servus::URI(fileName), *model, 0);
Expand Down