Skip to content

Commit

Permalink
Introduce camera-specific properties and runtime type switching
Browse files Browse the repository at this point in the history
Also add enum support (type int with list of strings) to PropertyMap to expose
them property in JSON.
  • Loading branch information
tribal-tec committed Jul 12, 2018
1 parent f735f8a commit 21a64ff
Show file tree
Hide file tree
Showing 37 changed files with 432 additions and 437 deletions.
3 changes: 0 additions & 3 deletions apps/ui/BaseWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,6 @@ void BaseWindow::reshape(const Vector2i& newSize)
{
Engine& engine = _brayns.getEngine();
_windowSize = engine.getSupportedFrameSize(newSize);

engine.getCamera().setAspectRatio(float(_windowSize.x()) /
float(_windowSize.y()));
engine.reshape(_windowSize);

auto& applicationParameters = _brayns.getParametersManager();
Expand Down
13 changes: 7 additions & 6 deletions brayns/Brayns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,8 @@ struct Brayns::Impl : public PluginAPI
_engine->reshape(windowSize);
_engine->preRender();

_engine->commit();

camera.commit();
_engine->commit();

if (_parametersManager.getRenderingParameters().getHeadLight())
{
Expand Down Expand Up @@ -959,31 +958,33 @@ struct Brayns::Impl : public PluginAPI
{
_fieldOfView -= 1.f;
//_fieldOfView = std::max(1.f, _fieldOfView);
_engine->getCamera().setFieldOfView(_fieldOfView);
_engine->getCamera().updateProperty("fovy", _fieldOfView);
BRAYNS_INFO << "Field of view: " << _fieldOfView << std::endl;
}

void _increaseFieldOfView()
{
_fieldOfView += 1.f;
// _fieldOfView = std::min(179.f, _fieldOfView);
_engine->getCamera().setFieldOfView(_fieldOfView);
_engine->getCamera().updateProperty("fovy", _fieldOfView);
BRAYNS_INFO << "Field of view: " << _fieldOfView << std::endl;
}

void _decreaseEyeSeparation()
{
_eyeSeparation -= 0.01f;
//_eyeSeparation = std::max(0.1f, _eyeSeparation);
_engine->getCamera().setEyeSeparation(_eyeSeparation);
_engine->getCamera().updateProperty("interpupillaryDistance",
_eyeSeparation);
BRAYNS_INFO << "Eye separation: " << _eyeSeparation << std::endl;
}

void _increaseEyeSeparation()
{
_eyeSeparation += 0.01f;
//_eyeSeparation = std::min(1.0f, _eyeSeparation);
_engine->getCamera().setEyeSeparation(_eyeSeparation);
_engine->getCamera().updateProperty("interpupillaryDistance",
_eyeSeparation);
BRAYNS_INFO << "Eye separation: " << _eyeSeparation << std::endl;
}

Expand Down
60 changes: 52 additions & 8 deletions brayns/common/PropertyMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ class PropertyMap
};

template <typename T>
Property(const std::string& name_, const std::string& title_,
Property(const std::string& name_, const std::string& label_,
const T& value)
: name(name_)
, title(title_)
, label(label_)
, type(_getType<T>())
, _data(value)
, _min(std::numeric_limits<T>::min())
Expand All @@ -69,14 +69,34 @@ class PropertyMap
}

template <typename T>
Property(const std::string& name_, const std::string& title_,
const T& value, const T& min_, const T& max_)
Property(const std::string& name_, const std::string& label_,
const T& value, const std::pair<T, T>& limits)
: name(name_)
, title(title_)
, label(label_)
, type(_getType<T>())
, _data(value)
, _min(min_)
, _max(max_)
, _min(limits.first)
, _max(limits.second)
{
}

/**
* Specialized for enum properties: type is int32_t, and the possible
* enum values are passed in enums_. The enum/int value and the
* corresponding string maps to the index in the vector.
*/
template <typename T>
Property(
const std::string& name_, const std::string& label_, const T& value,
const std::vector<std::string>& enums_,
typename std::enable_if<std::is_same<T, int32_t>::value>::type* = 0)
: name(name_)
, label(label_)
, type(_getType<T>())
, enums(enums_)
, _data(value)
, _min(0)
, _max(enums_.size())
{
}

Expand Down Expand Up @@ -104,15 +124,28 @@ class PropertyMap
return boost::any_cast<T>(_max);
}

/**
* Read-only property shall not be modified from the outside aka web API
* via JSON.
*/
void markReadOnly() { _readOnly = true; }
bool readOnly() const { return _readOnly; }
const std::string name;
const std::string title;
const std::string label; //!< user-friendly name of the property
const Type type;

/**
* Name of enum values that are mapped to the integer value based on
* the index.
*/
const std::vector<std::string> enums;

private:
friend class PropertyMap;
boost::any _data;
const boost::any _min;
const boost::any _max;
bool _readOnly{false};
template <typename T>
Type _getType();
};
Expand Down Expand Up @@ -173,6 +206,17 @@ class PropertyMap
return findProperty(name) != nullptr;
}

/**
* @return the enum values for the given property, empty if no enum
* property.
*/
const auto& getEnums(const std::string& name) const
{
if (auto property = findProperty(name))
return property->enums;
throw std::runtime_error("No property found with name " + name);
}

/** @return the type of the given property name. */
Property::Type getPropertyType(const std::string& name) const
{
Expand Down
39 changes: 18 additions & 21 deletions brayns/common/PropertyObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,13 @@ class PropertyObject : public BaseObject
template <typename T>
inline void updateProperty(const std::string& name, const T& value)
{
_mappedProperties.at(_currentType).updateProperty(name, value);
markModified();
const auto oldValue =
_properties.at(_currentType).getProperty<T>(name, value);
if (oldValue != value)
{
_properties.at(_currentType).updateProperty(name, value);
markModified();
}
}

/**
Expand All @@ -57,7 +62,7 @@ class PropertyObject : public BaseObject
*/
bool hasProperty(const std::string& name) const
{
return _mappedProperties.at(_currentType).hasProperty(name);
return _properties.at(_currentType).hasProperty(name);
}

/**
Expand All @@ -67,20 +72,20 @@ class PropertyObject : public BaseObject
template <typename T>
inline T getProperty(const std::string& name) const
{
return _mappedProperties.at(_currentType).getProperty<T>(name);
return _properties.at(_currentType).getProperty<T>(name);
}

/** Assign a new set of properties to the current type. */
void setProperties(const PropertyMap& properties)
{
_mappedProperties[_currentType] = properties;
_properties[_currentType] = properties;
markModified();
}

/** Assign a new set of properties to the given type. */
void setProperties(const std::string& type, const PropertyMap& properties)
{
_mappedProperties[type] = properties;
_properties[type] = properties;
markModified();
}

Expand All @@ -90,39 +95,31 @@ class PropertyObject : public BaseObject
void updateProperties(const PropertyMap& properties)
{
for (auto prop : properties.getProperties())
_mappedProperties.at(_currentType).setProperty(*prop);
_properties.at(_currentType).setProperty(*prop);
markModified();
}

/** @return true if the current type has any properties. */
bool hasProperties() const
{
return _mappedProperties.count(_currentType) != 0;
}

bool hasProperties() const { return _properties.count(_currentType) != 0; }
/** @return the entire property map for the current type. */
const auto& getPropertyMap() const
{
return _mappedProperties.at(_currentType);
}

const auto& getPropertyMap() const { return _properties.at(_currentType); }
/** @return the entire property map for the given type. */
const auto& getPropertyMap(const std::string& type) const
{
return _mappedProperties.at(type);
return _properties.at(type);
}

/** @return the list of all registered types. */
strings getTypes() const
{
strings types;
for (const auto& i : _mappedProperties)
for (const auto& i : _properties)
types.push_back(i.first);
return types;
}

private:
protected:
std::string _currentType;
std::map<std::string, PropertyMap> _mappedProperties;
std::map<std::string, PropertyMap> _properties;
};
}
16 changes: 0 additions & 16 deletions brayns/common/camera/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@

namespace brayns
{
Camera::Camera(const CameraType cameraType)
: _type{cameraType}
{
}

Camera::~Camera()
{
}

Camera& Camera::operator=(const Camera& rhs)
{
if (this == &rhs)
Expand All @@ -48,13 +39,6 @@ Camera& Camera::operator=(const Camera& rhs)
_initialTarget = rhs._initialTarget;
_initialUp = rhs._initialUp;

setAspectRatio(rhs.getAspectRatio());
setAperture(rhs.getAperture());
setFocalLength(rhs.getFocalLength());
setFieldOfView(rhs.getFieldOfView());
setStereoMode(rhs.getStereoMode());
setEyeSeparation(rhs.getEyeSeparation());

setClipPlanes(rhs.getClipPlanes());

_matrix = rhs._matrix;
Expand Down
Loading

0 comments on commit 21a64ff

Please sign in to comment.