Skip to content

Commit

Permalink
Merge pull request #341 from favreau/master
Browse files Browse the repository at this point in the history
Improved neurons representation using SDF displacement
  • Loading branch information
favreau authored Dec 8, 2023
2 parents ed1488a + 25b0582 commit 7719b59
Show file tree
Hide file tree
Showing 13 changed files with 390 additions and 265 deletions.
65 changes: 43 additions & 22 deletions bioexplorer/backend/science/common/SDFGeometries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,30 +88,51 @@ void SDFGeometries::addSDFDemo(Model& model)
const Vector3f displacement{0.05f, 10.f, 0.f};

ThreadSafeContainer modelContainer(model, 0.f, Vector3d(), Quaterniond());
if (rand() % 2 == 0)

for (size_t materialId = 0; materialId < 10; ++materialId)
{
const float x = materialId * 3.0f;
Neighbours neighbours;
neighbours.insert(modelContainer.addSphere(Vector3f(0.f + x, 0.f, 0.f), 0.5f, materialId, useSdf, NO_USER_DATA,
neighbours, displacement));
neighbours.insert(modelContainer.addCone(Vector3f(-1.f + x, 0.f, 0.f), 0.25, Vector3d(0.f + x, 0.f, 0.f), 0.1f,
materialId, useSdf, NO_USER_DATA, neighbours, displacement));
neighbours.insert(modelContainer.addCone(Vector3f(0.f + x, 0.f, 0.f), 0.1, Vector3f(1.f + x, 0.f, 0.f), 0.25f,
materialId, useSdf, NO_USER_DATA, neighbours, displacement));
neighbours.insert(modelContainer.addSphere(Vector3f(-0.5 + x, 0.f, 0.f), 0.25f, materialId, useSdf,
NO_USER_DATA, neighbours, displacement));
neighbours.insert(modelContainer.addSphere(Vector3f(0.5 + x, 0.f, 0.f), 0.25f, materialId, useSdf, NO_USER_DATA,
neighbours, displacement));
neighbours.insert(modelContainer.addCone(Vector3f(0.f + x, 0.25, 0.f), 0.5f, Vector3f(0.f + x, 1.f, 0.f), 0.f,
materialId, useSdf, NO_USER_DATA, neighbours, displacement));
neighbours.insert(modelContainer.addTorus(Vector3f(0.f + x, 0.f, 0.f), 1.5f, 0.5f, materialId, NO_USER_DATA,
neighbours, displacement));
neighbours.insert(modelContainer.addCutSphere(Vector3f(0.f + x, 1.f, 0.f), 1.0f, 0.5f, materialId, NO_USER_DATA,
for (size_t materialId = 0; materialId < 10; ++materialId)
{
const float x = materialId * 3.0f;
Neighbours neighbours;
neighbours.insert(modelContainer.addSphere(Vector3f(0.f + x, 0.f, 0.f), 0.5f, materialId, useSdf,
NO_USER_DATA, neighbours, displacement));
neighbours.insert(modelContainer.addCone(Vector3f(-1.f + x, 0.f, 0.f), 0.25, Vector3d(0.f + x, 0.f, 0.f),
0.1f, materialId, useSdf, NO_USER_DATA, neighbours, displacement));
neighbours.insert(modelContainer.addCone(Vector3f(0.f + x, 0.f, 0.f), 0.1, Vector3f(1.f + x, 0.f, 0.f),
0.25f, materialId, useSdf, NO_USER_DATA, neighbours,
displacement));
neighbours.insert(modelContainer.addSphere(Vector3f(-0.5 + x, 0.f, 0.f), 0.25f, materialId, useSdf,
NO_USER_DATA, neighbours, displacement));
neighbours.insert(modelContainer.addSphere(Vector3f(0.5 + x, 0.f, 0.f), 0.25f, materialId, useSdf,
NO_USER_DATA, neighbours, displacement));
neighbours.insert(modelContainer.addCone(Vector3f(0.f + x, 0.25, 0.f), 0.5f, Vector3f(0.f + x, 1.f, 0.f),
0.f, materialId, useSdf, NO_USER_DATA, neighbours, displacement));
neighbours.insert(modelContainer.addTorus(Vector3f(0.f + x, 0.f, 0.f), 1.5f, 0.5f, materialId, NO_USER_DATA,
neighbours, displacement));
neighbours.insert(modelContainer.addVesica(Vector3f(0.f + x, -1.f, 0.f), Vector3f(0.f + x, -1.5f, 0.f), 1.0f,
materialId, NO_USER_DATA, neighbours, displacement));
}
neighbours.insert(modelContainer.addCutSphere(Vector3f(0.f + x, 1.f, 0.f), 1.0f, 0.5f, materialId,
NO_USER_DATA, neighbours, displacement));
neighbours.insert(modelContainer.addVesica(Vector3f(0.f + x, -1.f, 0.f), Vector3f(0.f + x, -1.5f, 0.f),
1.0f, materialId, NO_USER_DATA, neighbours, displacement));
}
else
for (size_t materialId = 0; materialId < 10; ++materialId)
{
const float x = materialId * 3.0f;
Neighbours neighbours;
neighbours.insert(modelContainer.addSphere(Vector3f(0.f + x, 0.f, 0.f), 1.0f, materialId, useSdf,
NO_USER_DATA, {}, displacement));
neighbours.insert(modelContainer.addCone(Vector3f(0.5f + x, 0.f, 0.f), 0.75f, Vector3f(2.f + x, 0.f, 0.f),
0.f, materialId, useSdf, NO_USER_DATA, {}, displacement));
neighbours.insert(modelContainer.addCone(Vector3f(-0.5f + x, 0.f, 0.f), 0.75f, Vector3f(-2.f + x, 0.f, 0.f),
0.f, materialId, useSdf, NO_USER_DATA, {}, displacement));
neighbours.insert(modelContainer.addCone(Vector3f(0.f + x, 0.5f, 0.f), 0.75f, Vector3f(0.f + x, 2.f, 0.f),
0.f, materialId, useSdf, NO_USER_DATA, {}, displacement));
neighbours.insert(modelContainer.addCone(Vector3f(0.f + x, -0.5f, 0.f), 0.75f, Vector3f(0.f + x, -2.f, 0.f),
0.f, materialId, useSdf, NO_USER_DATA, {}, displacement));

for (const auto index : neighbours)
modelContainer.setSDFGeometryNeighbours(index, neighbours);
}
modelContainer.commitToModel();
model.applyDefaultColormap();
}
Expand Down
15 changes: 13 additions & 2 deletions bioexplorer/backend/science/common/ThreadSafeContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#include "Utils.h"

#include <science/common/Logs.h>

#include <platform/core/engineapi/Material.h>
#include <platform/core/engineapi/Model.h>

Expand Down Expand Up @@ -199,11 +201,11 @@ uint64_t ThreadSafeContainer::_addCone(const size_t materialId, const Cone& cone
return 0; // Only used by SDF geometry
}

uint64_t ThreadSafeContainer::_addSDFGeometry(const size_t materialId, const SDFGeometry& geom,
uint64_t ThreadSafeContainer::_addSDFGeometry(const size_t materialId, const SDFGeometry& geometry,
const std::set<size_t>& neighbours)
{
const uint64_t geometryIndex = _sdfMorphologyData.geometries.size();
_sdfMorphologyData.geometries.push_back(geom);
_sdfMorphologyData.geometries.push_back(geometry);
_sdfMorphologyData.neighbours.push_back(neighbours);
_sdfMorphologyData.materials.push_back(materialId);
return geometryIndex;
Expand Down Expand Up @@ -356,5 +358,14 @@ void ThreadSafeContainer::_commitStreamlinesToModel()
}
_streamlinesMap.clear();
}

void ThreadSafeContainer::setSDFGeometryNeighbours(const uint64_t geometryIndex, const std::set<size_t>& neighbours)
{
if (geometryIndex >= _sdfMorphologyData.neighbours.size())
PLUGIN_THROW("Invalid SDF geometry Id");
auto n = neighbours;
n.erase(geometryIndex);
_sdfMorphologyData.neighbours[geometryIndex] = n;
}
} // namespace common
} // namespace bioexplorer
2 changes: 2 additions & 0 deletions bioexplorer/backend/science/common/ThreadSafeContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ class ThreadSafeContainer
*/
void commitToModel();

void setSDFGeometryNeighbours(const uint64_t geometryIndex, const std::set<size_t>& neighbours);

MaterialSet& getMaterialIds() { return _materialIds; }

private:
Expand Down
Loading

0 comments on commit 7719b59

Please sign in to comment.