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

Added scene management #379

Merged
merged 5 commits into from
May 4, 2018
Merged

Added scene management #379

merged 5 commits into from
May 4, 2018

Conversation

favreau
Copy link
Member

@favreau favreau commented May 2, 2018

Introduced the notion of models.

  • A scene has a set of models than can handle various assets such as meshes, point clouds, circuits, etc.
  • Each models contains the materials that are required by the geometry it handles.
  • Models can manage several instances of the geometry it handles, with a different transformation for every instance.
  • Models also contain metadata that are exposed to the HTTP interface via the v1/scene end-point.
  • Models provide a simple API to add primitives such as spheres, cones, cylinders, and triangle meshes.

@favreau favreau force-pushed the models branch 10 times, most recently from 372d694 to fc8907f Compare May 3, 2018 13:26
Copy link
Contributor

@tribal-tec tribal-tec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty good overall!

I would like to have a test of adding a second model in the uploadpath and/or -binary test.

Also, the change of CMake/common should be reverted too I think.

@@ -482,6 +468,12 @@ struct Brayns::Impl : public PluginAPI
_engine->getStatistics().setSceneSizeInBytes(
_engine->getScene().getSizeInBytes());

// Set default camera position
const auto frameSize = Vector2f(_engine->getFrameBuffer().getSize());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_engine->setDefaultCamera(); ?

@@ -1226,17 +1183,20 @@ struct Brayns::Impl : public PluginAPI

void _gradientMaterials()
{
_engine->initializeMaterials(MaterialsColorMap::gradient);
_engine->getScene().setMaterialsColorMap(MaterialsColorMap::gradient);
_engine->getFrameBuffer().clear();
}

void _pastelMaterials()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer used, remove?

@@ -1287,10 +1247,9 @@ struct Brayns::Impl : public PluginAPI

ParametersManager _parametersManager;
EngineFactory _engineFactory;
EnginePtr _engine;
EnginePtr _engine{nullptr};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed

KeyboardHandler _keyboardHandler;
AbstractManipulatorPtr _cameraManipulator;
MeshLoader _meshLoader;
AbstractManipulatorPtr _cameraManipulator{nullptr};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@@ -55,6 +55,6 @@ class BaseObject
}

private:
std::atomic_bool _modified{true};
bool _modified{true};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we revert this too? we can have a look offline if this is needed though be changed

@@ -77,7 +77,6 @@ class SnapshotFunctor : public TaskFunctor
*_camera = *_params.camera;
else
*_camera = engine.getCamera();
_camera->setAspectRatio(float(_params.size.x()) / _params.size.y());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you sure? the snapshot has a different ratio. it's handled in the assignment now?

h->add_property("bounds", &s->getWorldBounds(),
Flags::IgnoreRead | Flags::Optional);
h->add_property("materials", &s->getMaterials());
auto bounds = s->getBounds();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, the bounds would ideally be cached by the scene, so they don't have to computed here. Let's discuss offline maybe.

#define OSPRAYMATERIAL_H

#include <brayns/common/material/Material.h>
#include <ospray_cpp/Data.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used? in any case, don't use they're cpp API, it's terrible :)

#include <brayns/common/material/Material.h>
namespace
{
const size_t BOUNDINGBOX_MATERIAL_ID = 9999;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no more than 10000-2 materials? so sad 📦

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I regularly use more than that actually. Maybe set it to size_t (-1)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, shouldn't these be in types.h class? Next to
const size_t NO_MATERIAL = std::numeric_limits<size_t>::max();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that! Done.

@@ -45,8 +45,9 @@ const size_t SERVER_PROCESS_RETRIES = 10; /*ms*/
class ForeverLoader : public brayns::Loader
{
public:
void importFromBlob(brayns::Blob&&, brayns::Scene&, const brayns::Matrix4f&,
const size_t) final
void importFromBlob(brayns::Blob&&, brayns::Scene&, const size_t = 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those default values are not needed here. they're already in the base class

if (_materials.find(materialId) == _materials.end())
throw std::runtime_error("Material " + std::to_string(materialId) +
" is not registered in the model");
return _materials[materialId];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double lookup of materialId in map.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

catch (const std::runtime_error&)
{
createMaterial(materialId, std::to_string(materialId));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to just do a _materials.find() instead of trying and catching exceptions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The really fishy thing is that getMaterial doesn't return anything. It should have a different name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thanks.

{
ModelTransformation() = default;
ModelTransformation(ModelTransformation&& rhs) = default;
ModelTransformation& operator=(ModelTransformation&& rhs) = default;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All constructors/assignment are default, maybe remove all?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot because there is another constructor with a different signature below :(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I missed that 👍

private:
Vector3f _translation{0.f, 0.f, 0.f};
Vector3f _scale{1.f, 1.f, 1.f};
Vector3f _rotation{0.f, 0.f, 0.f};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess my opinion doesn't count very much here, but this looks like Euler angles, which are quite cumbersome to specify formally (is this xzx, xyz, xyx, intrinsic, extrinsic, ...?). The interpretation is not even documented here.
Why don't you use a quaternion or an angle, axis representation, which are unambiguous and self-explanatory?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I guess we will match these with what the user uses in the UI.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a discussion that comes and go on a regular basis ;) I don't have a strong opinion there, I simply find the translation/scaling/rotation more human readable, and since this is what is exposed to the HTTP interface, I decided to use that representation. I guess the JS guy's opinion also is to consider. I'll ask input from @rolandjitsu

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This interface doesn't have to match what users see necessarily. This class could use a matrix to encode the transformations and the client could use whatever is preferable depending on the use case, converting it to a matrix at the last step. That would be my choice, in fact.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this discussion is recurrent and I don't what to start it again here. My criticism is that the way the rotation is expressed in this API is unclear (If you give this to two different people, the chances of ending up with a different transformation are quite high). At the very least, it should be documented better. And since it's not so easy to document easily, I suggest to use something which is unambiguous instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any method for manipulating objects from the GUI in a natural way and relative to the camera position will have to do some transformations, no matter what this API is, and for that you need an algebraic representation (matrix or quaternion), which means that in the end you need to transform the user input to a matrix or quaternion.
If this API describes the rotation as something else, it means that you need to transform the algebraic representation to whatever this API requires. Any representation can be easily converted to a quaternion or a matrix, but I find the opposite more annoying.
For me these are good reasons to choose a quaternion.

Flags::IgnoreRead | Flags::Optional);
h->add_property("materials", &s->getMaterials());
auto bounds = s->getBounds();
h->add_property("bounds", &bounds, Flags::IgnoreRead | Flags::Optional);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sending a pointer to a temporary variable 'bounds' here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! :) Fixed ;)

material->setDiffuseColor({colorMap[materialId].R / 255.f,
colorMap[materialId].G / 255.f,
colorMap[materialId].B / 255.f});
for (const auto& sphere : spheresPerMaterial.second)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you use colorMap[i] and colorMap[materialId] for the same material?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

@karjonas
Copy link
Contributor

karjonas commented May 4, 2018

I cannot comment too much on the design since I am not familiar enough with all the pieces but to me it looks fine :)

@favreau favreau force-pushed the models branch 5 times, most recently from 799710f to 3794847 Compare May 4, 2018 14:59
@favreau
Copy link
Member Author

favreau commented May 4, 2018

Retest this please

@favreau favreau merged commit 55fe57a into BlueBrain:master May 4, 2018
@rolandjitsu rolandjitsu mentioned this pull request Jun 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants