Skip to content

Commit

Permalink
Update + Buffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrien4193 committed Sep 12, 2024
1 parent 7da285d commit 14aee1c
Show file tree
Hide file tree
Showing 16 changed files with 202 additions and 69 deletions.
4 changes: 2 additions & 2 deletions src/brayns/core/engine/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ struct PerspectiveCameraSettings
{
float fovy = radians(60.0F);
float aspect = 1.0F;
std::optional<DepthOfField> depthOfField = std::nullopt;
std::optional<DepthOfField> depthOfField = {};
bool architectural = false;
std::optional<Stereo> stereo = std::nullopt;
std::optional<Stereo> stereo = {};
};

class PerspectiveCamera : public Camera
Expand Down
4 changes: 2 additions & 2 deletions src/brayns/core/engine/Framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ struct FramebufferSettings
Size2 resolution;
FramebufferFormat format = FramebufferFormat::Srgba8;
std::set<FramebufferChannel> channels = {FramebufferChannel::Color};
std::optional<Accumulation> accumulation = std::nullopt;
std::optional<Data<ImageOperation>> operations = std::nullopt;
std::optional<Accumulation> accumulation = {};
std::optional<Data<ImageOperation>> operations = {};
};

class FramebufferData
Expand Down
2 changes: 1 addition & 1 deletion src/brayns/core/engine/GeometricModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct Materials
{
std::variant<IndexInRenderer, Data<IndexInRenderer>> values;
std::variant<std::monostate, Color4, Data<Color4>> colors = {};
std::optional<Data<std::uint8_t>> indices = std::nullopt;
std::optional<Data<std::uint8_t>> indices = {};
};

struct GeometricModelSettings
Expand Down
26 changes: 13 additions & 13 deletions src/brayns/core/engine/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class Geometry : public Managed<OSPGeometry>
struct MeshSettings
{
Data<Vector3> positions;
std::optional<Data<Vector3>> normals = std::nullopt;
std::optional<Data<Color4>> colors = std::nullopt;
std::optional<Data<Vector2>> uvs = std::nullopt;
std::optional<Data<Vector3>> normals = {};
std::optional<Data<Color4>> colors = {};
std::optional<Data<Vector2>> uvs = {};
};

class Mesh : public Geometry
Expand All @@ -56,7 +56,7 @@ class Mesh : public Geometry
struct TriangleMeshSettings
{
MeshSettings base;
std::optional<Data<Index3>> indices = std::nullopt;
std::optional<Data<Index3>> indices = {};
};

class TriangleMesh : public Mesh
Expand All @@ -70,7 +70,7 @@ TriangleMesh createTriangleMesh(Device &device, const TriangleMeshSettings &sett
struct QuadMeshSettings
{
MeshSettings base;
std::optional<Data<Index4>> indices = std::nullopt;
std::optional<Data<Index4>> indices = {};
};

class QuadMesh : public Mesh
Expand All @@ -84,7 +84,7 @@ QuadMesh createQuadMesh(Device &device, const QuadMeshSettings &settings);
struct SphereSettings
{
Data<Vector4> spheres;
std::optional<Data<Vector2>> uvs = std::nullopt;
std::optional<Data<Vector2>> uvs = {};
};

class Spheres : public Geometry
Expand All @@ -98,8 +98,8 @@ Spheres createSpheres(Device &device, const SphereSettings &settings);
struct DiscSettings
{
Data<Vector4> spheres;
std::optional<Data<Vector3>> normals = std::nullopt;
std::optional<Data<Vector2>> uvs = std::nullopt;
std::optional<Data<Vector3>> normals = {};
std::optional<Data<Vector2>> uvs = {};
};

class Discs : public Geometry
Expand All @@ -114,8 +114,8 @@ struct CylinderSettings
{
Data<Vector4> spheres;
Data<std::uint32_t> indices;
std::optional<Data<Color4>> colors = std::nullopt;
std::optional<Data<Vector2>> uvs = std::nullopt;
std::optional<Data<Color4>> colors = {};
std::optional<Data<Vector2>> uvs = {};
};

class Cylinders : public Geometry
Expand Down Expand Up @@ -170,8 +170,8 @@ struct CurveSettings
{
Data<Vector4> spheres;
Data<std::uint32_t> indices;
std::optional<Data<Color4>> colors = std::nullopt;
std::optional<Data<Vector2>> uvs = std::nullopt;
std::optional<Data<Color4>> colors = {};
std::optional<Data<Vector2>> uvs = {};
CurveType type = RoundCurve();
CurveBasis basis = LinearCurve();
};
Expand Down Expand Up @@ -200,7 +200,7 @@ Boxes createBoxes(Device &device, const BoxSettings &settings);
struct PlaneSettings
{
Data<Vector4> coefficients;
std::optional<Data<Box3>> bounds = std::nullopt;
std::optional<Data<Box3>> bounds = {};
};

class Planes : public Geometry
Expand Down
2 changes: 1 addition & 1 deletion src/brayns/core/engine/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct RendererSettings
float minContribution = 0.001F;
float varianceThreshold = 0.0F;
Background background = Color4(0.0F, 0.0F, 0.0F, 0.0F);
std::optional<Texture2D> maxDepth = std::nullopt;
std::optional<Texture2D> maxDepth = {};
PixelFilter pixelFilter = PixelFilter::Gauss;
};

Expand Down
2 changes: 1 addition & 1 deletion src/brayns/core/engine/Volume.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct RegularVolumeSettings
Vector3 spacing = {1.0F, 1.0F, 1.0F};
VolumeType type = VolumeType::VertexCentered;
VolumeFilter filter = VolumeFilter::Linear;
std::optional<float> background = std::nullopt;
std::optional<float> background = {};
};

class RegularVolume : public Volume
Expand Down
10 changes: 5 additions & 5 deletions src/brayns/core/engine/World.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ namespace brayns
{
struct GroupSettings
{
std::optional<Data<GeometricModel>> geometries = std::nullopt;
std::optional<Data<GeometricModel>> clippingGeometries = std::nullopt;
std::optional<Data<VolumetricModel>> volumes = std::nullopt;
std::optional<Data<Light>> lights = std::nullopt;
std::optional<Data<GeometricModel>> geometries = {};
std::optional<Data<GeometricModel>> clippingGeometries = {};
std::optional<Data<VolumetricModel>> volumes = {};
std::optional<Data<Light>> lights = {};
};

class Group : public Managed<OSPGroup>
Expand Down Expand Up @@ -67,7 +67,7 @@ Instance createInstance(Device &device, const InstanceSettings &settings);

struct WorldSettings
{
std::optional<Data<Instance>> instances = std::nullopt;
std::optional<Data<Instance>> instances = {};
};

class World : public Managed<OSPWorld>
Expand Down
2 changes: 2 additions & 0 deletions src/brayns/core/json/Json.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "JsonValue.h"

#include "types/Arrays.h"
#include "types/Buffer.h"
#include "types/Consts.h"
#include "types/Enums.h"
#include "types/Maps.h"
Expand All @@ -35,5 +36,6 @@
#include "types/Primitives.h"
#include "types/Schema.h"
#include "types/Sets.h"
#include "types/Update.h"
#include "types/Variants.h"
#include "types/Vectors.h"
10 changes: 5 additions & 5 deletions src/brayns/core/json/JsonSchema.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,16 @@ struct JsonSchema
{
std::string description = {};
bool required = true;
std::optional<JsonValue> defaultValue = std::nullopt;
std::optional<JsonValue> defaultValue = {};
std::vector<JsonSchema> oneOf = {};
JsonType type = JsonType::Undefined;
JsonValue constant = {};
std::optional<double> minimum = std::nullopt;
std::optional<double> maximum = std::nullopt;
std::optional<double> minimum = {};
std::optional<double> maximum = {};
std::vector<JsonSchema> items = {};
bool uniqueItems = false;
std::optional<std::size_t> minItems = std::nullopt;
std::optional<std::size_t> maxItems = std::nullopt;
std::optional<std::size_t> minItems = {};
std::optional<std::size_t> maxItems = {};
std::map<std::string, JsonSchema> properties = {};

bool operator==(const JsonSchema &) const = default;
Expand Down
69 changes: 69 additions & 0 deletions src/brayns/core/json/types/Buffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* Copyright (c) 2015-2024 EPFL/Blue Brain Project
* All rights reserved. Do not distribute without permission.
*
* Responsible Author: adrien.fleury@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/core/json/JsonReflector.h>

namespace brayns
{
template<ReflectedJson T>
class JsonBuffer
{
public:
const JsonValue &get() const
{
return _json;
}

void store(const JsonValue &json)
{
_json = json;
}

void extract(T &value) const
{
deserializeJson(_json, value);
}

private:
JsonValue _json;
};

template<ReflectedJson T>
struct JsonReflector<JsonBuffer<T>>
{
static JsonSchema getSchema()
{
return getJsonSchema<T>();
}

static void serialize(const JsonBuffer<T> &value, JsonValue &json)
{
json = value.get();
}

static void deserialize(const JsonValue &json, JsonBuffer<T> &value)
{
value.store(json);
}
};
}
18 changes: 0 additions & 18 deletions src/brayns/core/json/types/Objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,6 @@ JsonField<Parent> convertJsonField(const JsonField<Child> &child, JsonChildGette
};
}

inline void removeJsonObjectDefaults(std::map<std::string, JsonSchema> &properties)
{
for (auto &[key, field] : properties)
{
field.defaultValue = std::nullopt;
removeJsonObjectDefaults(field.properties);
}
}

class JsonFieldBuilder
{
public:
Expand Down Expand Up @@ -328,15 +319,6 @@ class JsonBuilder
}
}

void removeDefaultValues()
{
for (auto &field : _info.fields)
{
field.schema.defaultValue = std::nullopt;
removeJsonObjectDefaults(field.schema.properties);
}
}

JsonObjectInfo<T> build()
{
return std::exchange(_info, {});
Expand Down
53 changes: 53 additions & 0 deletions src/brayns/core/json/types/Update.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* Copyright (c) 2015-2024 EPFL/Blue Brain Project
* All rights reserved. Do not distribute without permission.
*
* Responsible Author: adrien.fleury@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 "Objects.h"

namespace brayns
{
template<ReflectedJsonObject T>
struct JsonUpdate
{
T value;
};

template<ReflectedJsonObject T>
struct JsonObjectReflector<JsonUpdate<T>>
{
static auto reflect()
{
auto builder = JsonBuilder<JsonUpdate<T>>();
builder.extend([](auto &object) { return &object.value; });

auto info = builder.build();

for (auto &field : info.fields)
{
field.schema.required = false;
field.schema.defaultValue.reset();
}

return info;
}
};
}
2 changes: 1 addition & 1 deletion src/brayns/core/json/types/Variants.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct JsonReflector<std::optional<T>>
{
if (json.isEmpty())
{
value = std::nullopt;
value.reset();
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/brayns/core/jsonrpc/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ std::string composeAsText(const JsonRpcSuccessResponse &response);
std::string composeAsText(const JsonRpcErrorResponse &response);
std::string composeAsBinary(const JsonRpcSuccessResponse &response);
JsonRpcError composeError(const JsonRpcException &e);
JsonRpcErrorResponse composeErrorResponse(const JsonRpcException &e, std::optional<JsonRpcId> id = std::nullopt);
JsonRpcErrorResponse composeErrorResponse(const JsonRpcException &e, std::optional<JsonRpcId> id = {});
}
2 changes: 1 addition & 1 deletion src/brayns/core/websocket/WebSocketServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct WebSocketServerSettings
std::size_t maxThreadCount = 1;
std::size_t maxQueueSize = 64;
std::size_t maxFrameSize = std::numeric_limits<int>::max();
std::optional<SslSettings> ssl = std::nullopt;
std::optional<SslSettings> ssl = {};
};

class WebSocketServer
Expand Down
Loading

0 comments on commit 14aee1c

Please sign in to comment.