-
Notifications
You must be signed in to change notification settings - Fork 46
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
SDF geometries support #391
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look pretty good in general! Some unit tests would be nice too :-)
brayns/common/CMakeLists.txt
Outdated
@@ -42,6 +42,7 @@ set(BRAYNSCOMMON_PUBLIC_HEADERS | |||
geometry/Cylinder.h | |||
geometry/Sphere.h | |||
geometry/TrianglesMesh.h | |||
geometry/SDFGeometry.h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alphabetical order
brayns/io/MorphologyLoader.cpp
Outdated
@@ -66,7 +81,7 @@ class MorphologyLoader::Impl | |||
model.getCylinders(), | |||
model.getCones(), | |||
model.getTrianglesMeshes(), | |||
model.getBounds()); | |||
model.getBounds(), model); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm, looks like it should only take model as a parameter then. But maybe there was a reason for not passing the model before..?
brayns/io/MorphologyLoader.cpp
Outdated
* @param compartmentReport Compartment report to map to the morphology | ||
* @param scene Scene to which the morphology should be loaded into | ||
* @return True if the loading was successful, false otherwise | ||
* @brief _connectSDFSomaChildren Creates an SDF soma by adding and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rm "@brief _connectSDFSomaChildren"
brayns/common/geometry/SDFGeometry.h
Outdated
inline SDFGeometry createSDFConePill(const Vector3f& p0, const Vector3f& p1, | ||
const float radiusBottom, | ||
const float radiusTip, | ||
const float sigmoid = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since ConePill and ConePillSigmoid are two separate SDFTypes, it would probably be more consistent to have a createSDFConePillSigmoid() function.
In general, bool parameters are not ideal because they are not self-describing when reading the calling code.
In:
createSDFConePill(somaPosition, sample, somaRadius * 0.5f, radiusEnd, true);
it is not obvious what true means.
brayns/io/MorphologyLoader.cpp
Outdated
} | ||
|
||
/** | ||
* @brief _finalizeSDFGeometries Calculates all neighbours and adds the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rm "@brief _finalizeSDFGeometries"
vec2f t = make_vec2f(max(tmin.x, tmin.y), max(tmin.x, tmin.z)); | ||
t0 = max(t.x, t.y); | ||
t = make_vec2f(min(tmax.x, tmax.y), min(tmax.x, tmax.z)); | ||
t1 = min(t.x, t.y); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
n * const
brayns/common/scene/Model.h
Outdated
std::vector<size_t> _SDFNeighboursFlat; | ||
std::vector<std::vector<size_t>> _SDFNeighbours; | ||
std::vector<SDFGeometry> _SDFGeometries; | ||
bool _SDFGeometriesDirty{false}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, but that's a lot of additions to the Model class, could maybe go into a separate SDF class instanced here..?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering in general if this should be in the core at all or rather be a 'real' plugin? Maybe not now, but latest when the circuit loader and friends are moved to a plugin, this shall move as well.
brayns/common/scene/Model.h
Outdated
const std::vector<size_t>& neighbourIndices); | ||
|
||
/** Builds the flat list of neighbours for the SDF geometries */ | ||
void buildSDFGeometryNeighboursFlat(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this have to be public? Who should call it, why and when?
brayns/common/scene/Model.h
Outdated
@param neighbourIndices Indices of the neighbours | ||
*/ | ||
void setSDFGeometryNeighbours(size_t geometryIdx, | ||
const std::vector<size_t>& neighbourIndices); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about renaming this function to updateSDFGeometryNeighbours? They are already set in addSDFGeometry() if I'm correct.
Also, this may be a stupid question, but where do I find the geometryIdx to pass to this function?
brayns/common/scene/Model.h
Outdated
Adds a SDFGeometry to the scene | ||
@param materialId Material of the geometry | ||
@param geom Geometry to add | ||
@param neighbours List of global indices of the geometry neighbours |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For people like me who are not familiar with SDF terminology, it would great if you could document what neighbours are used for and how I should compute them.
677dbe6
to
7682fbe
Compare
All issues should be fixed now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good for me otherwise. Maybe trying to use the texture coordinates to support simulation mapping.
brayns/common/scene/Model.cpp
Outdated
_bounds.merge(geom.center + Vector3f(geom.radius)); | ||
break; | ||
} | ||
case brayns::SDFType::Pill: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use default: instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a throw on the default case so that you do not forget to set the bounds if you add a new geometry type.
Ultra super cool PR! :) |
A new geometry type called ExtendedSDFGeometries is added. This PR also includes a thickness smoothing algorithm used when loading morphologies. It can be activated by adding '--dampen-branch-thickness-changerate true' when running Brayns. To create SDF geometries when loading a morphology you add '--use-sdf-geometries true'
I also added the textures and timestamp variables to the SDF geometries now so we can get the proper simulation colors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for me, just a few last comments :-)
brayns/common/scene/Model.cpp
Outdated
void Model::updateSDFGeometryNeighbours( | ||
size_t geometryIdx, const std::vector<size_t>& neighbourIndices) | ||
{ | ||
_sdfGeometryData.neighbours[geometryIdx] = neighbourIndices; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't this make the geometry dirty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, fixed
brayns/common/scene/Model.cpp
Outdated
} | ||
default: | ||
throw std::runtime_error("No bounds found for SDF type."); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would refactor this a bit, moving the logic to get the min/max to the geometry class and keep here only something like:
_bounds.merge(geom.getMin());
_bounds.merge(geom.getMax());
As an added benefit, it lets you unit test independently the geom.getMin/Max() code :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I created a function that returns the bounding box.
brayns/common/scene/Model.cpp
Outdated
_sdfGeometryData.neighbours.size()); | ||
|
||
_sdfGeometryData.neighbours.push_back(neighbourIndices); | ||
_sdfGeometryData.geometries.push_back(geom); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To limit indirection and make the code more readable, the above could moved to a function of sdfGeometryData and have here:
_sdfGeometryData.add(materialId, geom, neighbourIndices);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed the variable to _sdf. Do you think it is readable enough then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm sure, although my point was not exactly about the variable name. What I was trying to say is more that since those lines of code operate exclusively on the struct members, it could make sense to put them a member function of the struct which is called it from here... but that's fine as well.
brayns/common/scene/Model.h
Outdated
|
||
std::vector<std::vector<size_t>> neighbours; | ||
std::vector<size_t> neighboursFlat; | ||
bool isDirty{false}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the dirty flag for other types of data is kept separately, maybe do the same for consistency..?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, fixed.
A new geometry type called ExtendedSDFGeometries is added. This PR also includes a thickness smoothing algorithm used when loading morphologies. It can be activated by adding '--dampen-branch-thickness-changerate true' when running Brayns. To create SDF geometries when loading a morphology you add '--use-sdf-geometries true'