Skip to content

Commit

Permalink
Brayns 548 add ghost material (#1182)
Browse files Browse the repository at this point in the history
  • Loading branch information
NadirRoGue committed Jun 9, 2023
1 parent dbcabed commit ad1298d
Show file tree
Hide file tree
Showing 19 changed files with 208 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitlab-ci.hpc-spack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ brayns-spack-test:
needs: ["brayns-spack-build"]
timeout: 2h
script:
- export BRAYNS_TMP_DIR=$SHMDIR
- cd ${SPACK_BUILD_DIR}
- spack build-env ${SPACK_FULL_SPEC} -- ninja tests

Expand Down
4 changes: 2 additions & 2 deletions .gitlab-ci.viz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ ubuntu-clangformat-check:

# Install OSPRay
# https://github.com/ospray/ospray/releases
- OSPRAY_TAG=v2.10.0
- OSPRAY_TAG=v2.10.1
- OSPRAY_SRC=/app/ospray

- mkdir -p ${OSPRAY_SRC}
- git clone https://github.com/ospray/ospray.git ${OSPRAY_SRC}
- git clone https://github.com/BlueBrain/ospray.git ${OSPRAY_SRC}
- pushd ${OSPRAY_SRC}
- git checkout ${OSPRAY_TAG}
- mkdir -p build
Expand Down
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,11 @@ RUN mkdir ${OPENVKL_SRC} \
&& ninja -j4 install

# Install OSPRay
# https://github.com/ospray/ospray/releases
ARG OSPRAY_TAG=v2.10.0
ARG OSPRAY_TAG=v2.10.1
ARG OSPRAY_SRC=/app/ospray

RUN mkdir -p ${OSPRAY_SRC} \
&& git clone https://github.com/ospray/ospray.git ${OSPRAY_SRC} \
&& git clone https://github.com/BlueBrain/ospray.git ${OSPRAY_SRC} \
&& cd ${OSPRAY_SRC} \
&& git checkout ${OSPRAY_TAG} \
&& mkdir -p build \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The following components must be installed on the system where Brayns will be bu
* Package config
* SSL Development files
* Python 3.9 or higher
* OSPRay 2.10.0 (https://github.com/ospray/OSPRay/tree/v2.10.0)
* Custom OSPRay 2.10.1 (https://github.com/BlueBrain/ospray/tree/v2.10.1)
* zlib

Optionally, to build the core plugins of Brayns, the following components are required.
Expand Down
10 changes: 10 additions & 0 deletions brayns/engine/json/adapters/MaterialAdapters.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <brayns/engine/material/types/CarPaint.h>
#include <brayns/engine/material/types/Emissive.h>
#include <brayns/engine/material/types/Ghost.h>
#include <brayns/engine/material/types/Glass.h>
#include <brayns/engine/material/types/Matte.h>
#include <brayns/engine/material/types/Metal.h>
Expand Down Expand Up @@ -76,6 +77,15 @@ struct JsonAdapter<Emissive> : ObjectAdapter<Emissive>
}
};

template<>
struct JsonAdapter<Ghost> : ObjectAdapter<Ghost>
{
static JsonObjectInfo reflect()
{
return JsonObjectInfo{"Ghost", {}};
}
};

template<>
struct JsonAdapter<Glass> : ObjectAdapter<Glass>
{
Expand Down
42 changes: 42 additions & 0 deletions brayns/engine/material/types/Ghost.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* Copyright (c) 2015-2023, EPFL/Blue Brain Project
* All rights reserved. Do not distribute without permission.
* Responsible Author: Nadir Roman Guerrero <nadir.romanguerrero@epfl.ch>
*
* This file is part of Brayns <https://github.com/BlueBrain/Brayns>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3.0 as published
* by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "Ghost.h"

#include <brayns/engine/common/MathTypesOsprayTraits.h>

namespace
{
struct DefaultParameters
{
static inline const std::string diffuseColor = "kd";
static inline const std::string shininess = "ns";
};
}

namespace brayns
{
void MaterialTraits<Ghost>::updateData(ospray::cpp::Material &handle, Ghost &data)
{
(void)data;
handle.setParam(DefaultParameters::diffuseColor, Vector3f(1.f));
handle.setParam(DefaultParameters::shininess, -1.f);
}
}
41 changes: 41 additions & 0 deletions brayns/engine/material/types/Ghost.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* Copyright (c) 2015-2023, EPFL/Blue Brain Project
* All rights reserved. Do not distribute without permission.
* Responsible Author: Nadir Roman Guerrero <nadir.romanguerrero@epfl.ch>
*
* This file is part of Brayns <https://github.com/BlueBrain/Brayns>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3.0 as published
* by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#pragma once

#include <brayns/engine/material/MaterialTraits.h>
#include <brayns/utils/MathTypes.h>

namespace brayns
{
struct Ghost
{
};

template<>
class MaterialTraits<Ghost>
{
public:
static inline const std::string handleName = "obj";
static inline const std::string name = "ghost";

static void updateData(ospray::cpp::Material &handle, Ghost &data);
};
}
2 changes: 2 additions & 0 deletions brayns/network/NetworkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class CoreEntrypointRegistry
builder.add<brayns::GetLoadersEntrypoint>(loaders);
builder.add<brayns::GetMaterialCarPaint>(models);
builder.add<brayns::GetMaterialEmissive>(models);
builder.add<brayns::GetMaterialGhost>(models);
builder.add<brayns::GetMaterialGlass>(models);
builder.add<brayns::GetMaterialMatte>(models);
builder.add<brayns::GetMaterialMetal>(models);
Expand Down Expand Up @@ -153,6 +154,7 @@ class CoreEntrypointRegistry
builder.add<brayns::SetStaticFramebufferEntrypoint>(engine);
builder.add<brayns::SetMaterialCarPaint>(models);
builder.add<brayns::SetMaterialEmissive>(models);
builder.add<brayns::SetMaterialGhost>(models);
builder.add<brayns::SetMaterialGlass>(models);
builder.add<brayns::SetMaterialMatte>(models);
builder.add<brayns::SetMaterialMetal>(models);
Expand Down
31 changes: 31 additions & 0 deletions brayns/network/entrypoints/MaterialEntrypoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,22 @@ std::string SetMaterialGlass::getDescription() const
"This material is only usable with the production renderer";
}

SetMaterialGhost::SetMaterialGhost(ModelManager &models):
SetMaterialEntrypoint<Ghost>(models)
{
}

std::string SetMaterialGhost::getMethod() const
{
return "set-material-ghost";
}

std::string SetMaterialGhost::getDescription() const
{
return "Updates the material of the given model to a ghost material. "
"The ghost effect is only visible with the interactive renderer.";
}

SetMaterialMatte::SetMaterialMatte(ModelManager &models):
SetMaterialEntrypoint<Matte>(models)
{
Expand Down Expand Up @@ -224,6 +240,21 @@ std::string GetMaterialGlass::getDescription() const
return "Returns the material of the given model as a glass material, if possible";
}

GetMaterialGhost::GetMaterialGhost(ModelManager &scene):
GetMaterialEntrypoint<Ghost>(scene)
{
}

std::string GetMaterialGhost::getMethod() const
{
return "get-material-ghost";
}

std::string GetMaterialGhost::getDescription() const
{
return "Returns the material of the given model as a ghost material, if possible";
}

GetMaterialMatte::GetMaterialMatte(ModelManager &models):
GetMaterialEntrypoint<Matte>(models)
{
Expand Down
18 changes: 18 additions & 0 deletions brayns/network/entrypoints/MaterialEntrypoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ class SetMaterialEmissive : public SetMaterialEntrypoint<Emissive>
virtual std::string getDescription() const override;
};

class SetMaterialGhost : public SetMaterialEntrypoint<Ghost>
{
public:
explicit SetMaterialGhost(ModelManager &ModelManager);

virtual std::string getMethod() const override;
virtual std::string getDescription() const override;
};

class SetMaterialGlass : public SetMaterialEntrypoint<Glass>
{
public:
Expand Down Expand Up @@ -215,6 +224,15 @@ class GetMaterialGlass : public GetMaterialEntrypoint<Glass>
virtual std::string getDescription() const override;
};

class GetMaterialGhost : public GetMaterialEntrypoint<Ghost>
{
public:
explicit GetMaterialGhost(ModelManager &scene);

virtual std::string getMethod() const override;
virtual std::string getDescription() const override;
};

class GetMaterialMatte : public GetMaterialEntrypoint<Matte>
{
public:
Expand Down
20 changes: 0 additions & 20 deletions plugins/CircuitExplorer/io/bbploader/CellLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,6 @@

#pragma once

/* Copyright (c) 2015-2023, EPFL/Blue Brain Project
* All rights reserved. Do not distribute without permission.
* Responsible Author: Nadir Roman Guerrero <nadir.romanguerrero@epfl.ch>
*
* This file is part of Brayns <https://github.com/BlueBrain/Brayns>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3.0 as published
* by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include <brayns/io/Loader.h>

#include <api/reports/ReportMapping.h>
Expand Down
4 changes: 2 additions & 2 deletions plugins/CircuitExplorer/io/sonataloader/data/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ class MorphologyPathResolver
return it->second;
}

static bool isValid(const std::string &path, std::string_view extension)
static bool isValid(const std::string &path, const std::string &extension)
{
auto pathObject = std::filesystem::path(path);
if (!std::filesystem::is_directory(pathObject))
{
return false;
}

auto testExtension = std::string(".") + std::string(extension);
auto testExtension = "." + extension;
for (auto &item : std::filesystem::directory_iterator(pathObject))
{
if (!std::filesystem::is_regular_file(item))
Expand Down
2 changes: 2 additions & 0 deletions python/brayns/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
GBufferChannel,
GBufferExporter,
Geometry,
GhostMaterial,
GlassMaterial,
Image,
ImageInfo,
Expand Down Expand Up @@ -314,6 +315,7 @@
"get_scene",
"get_simulation",
"get_version",
"GhostMaterial",
"GlassMaterial",
"Image",
"ImageFormat",
Expand Down
2 changes: 2 additions & 0 deletions python/brayns/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
from .material import (
CarPaintMaterial,
EmissiveMaterial,
GhostMaterial,
GlassMaterial,
Material,
MatteMaterial,
Expand Down Expand Up @@ -192,6 +193,7 @@
"get_scene",
"get_simulation",
"get_version",
"GhostMaterial",
"GlassMaterial",
"Image",
"ImageInfo",
Expand Down
23 changes: 23 additions & 0 deletions python/brayns/core/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,29 @@ def update_properties(self, message: dict[str, Any]) -> None:
self.refraction_index = message["index_of_refraction"]


@dataclass
class GhostMaterial(Material):
"""Ghost material."""

@classmethod
@property
def name(cls) -> str:
"""Get the material name.
:return: Material name
:rtype: str
"""
return "ghost"

def get_properties(self) -> dict[str, Any]:
"""Low level API to serialize to JSON."""
return {}

def update_properties(self, message: dict[str, Any]) -> None:
"""Low level API to deserialize from JSON."""
pass


@dataclass
class MatteMaterial(Material):
"""Matte material.
Expand Down
Binary file added python/testapi/core/assets/ghost_material.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 10 additions & 2 deletions python/testapi/core/test_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def test_emissive(self) -> None:
)
self.run_tests(material)

def test_ghost(self) -> None:
material = brayns.GhostMaterial()
self.run_tests(material, brayns.InteractiveRenderer(16, 3))

def test_glass(self) -> None:
material = brayns.GlassMaterial(
refraction_index=2,
Expand Down Expand Up @@ -68,13 +72,17 @@ def test_plastic(self) -> None:
)
self.run_tests(material)

def run_tests(self, material: brayns.Material) -> None:
def run_tests(
self,
material: brayns.Material,
renderer: brayns.Renderer = brayns.ProductionRenderer(16, 3),
) -> None:
model = add_sphere(self)
brayns.set_material(self.instance, model.id, material)
name = brayns.get_material_name(self.instance, model.id)
self.assertEqual(name, material.name)
retreived = brayns.get_material(self.instance, model.id, type(material))
self.assertEqual(material, retreived)
filename = f"{material.name}_material"
settings = RenderSettings(renderer=brayns.ProductionRenderer(16, 3))
settings = RenderSettings(renderer=renderer)
render_and_validate(self, filename, settings)
3 changes: 3 additions & 0 deletions python/tests/core/test_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ def test_emissive(self) -> None:
self.assertEqual(test.intensity, 2)
self.assertEqual(test.color, brayns.Color3.red)

def test_ghost(self) -> None:
self.assertEqual(brayns.GhostMaterial.name, "ghost")

def test_glass(self) -> None:
self.assertEqual(brayns.GlassMaterial.name, "glass")
test = brayns.GlassMaterial(2.5)
Expand Down

0 comments on commit ad1298d

Please sign in to comment.