Skip to content

Commit

Permalink
Clip planes moved from Camera to Scene
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Hernando Vieites committed Aug 8, 2018
1 parent 0e4f4cb commit 3c1538a
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 21 deletions.
2 changes: 0 additions & 2 deletions brayns/common/camera/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ Camera& Camera::operator=(const Camera& rhs)
_initialTarget = rhs._initialTarget;
_initialUp = rhs._initialUp;

setClipPlanes(rhs.getClipPlanes());

_matrix = rhs._matrix;
return *this;
}
Expand Down
15 changes: 1 addition & 14 deletions brayns/common/camera/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,8 @@ class Camera : public PropertyObject
BRAYNS_API virtual void setEnvironmentMap(
const bool environmentMap BRAYNS_UNUSED){};

/**
Sets the camera clip planes
*/
void setClipPlanes(const ClipPlanes clipPlanes)
{
_updateValue(_clipPlanes, clipPlanes);
}

/**
@return the camera clip planes
*/
const ClipPlanes& getClipPlanes() const { return _clipPlanes; }
virtual bool isSideBySideStereo() const { return false; }

private:
Vector3f _position;
Vector3f _target;
Expand All @@ -136,8 +125,6 @@ class Camera : public PropertyObject
Vector3f _initialTarget;
Vector3f _initialUp;

ClipPlanes _clipPlanes;

/*! rotation matrice along x and y axis */
Matrix4f _matrix;

Expand Down
1 change: 1 addition & 0 deletions brayns/common/scene/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Scene& Scene::operator=(const Scene& rhs)
_backgroundMaterial->markModified();

_lights = rhs._lights;
_clipPlanes = rhs._clipPlanes;

if (rhs._simulationHandler)
{
Expand Down
14 changes: 14 additions & 0 deletions brayns/common/scene/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,19 @@ class Scene : public BaseObject
return _parametersManager;
}

/**
Sets the clip planes
*/
void setClipPlanes(const ClipPlanes& clipPlanes)
{
_clipPlanes = clipPlanes;
markModified();
}
/**
@return the clip planes
*/
const ClipPlanes& getClipPlanes() const { return _clipPlanes; }

/**
Returns the simulutation handler
*/
Expand Down Expand Up @@ -272,6 +285,7 @@ class Scene : public BaseObject
mutable std::shared_timed_mutex _modelMutex;

Lights _lights;
ClipPlanes _clipPlanes;

// Simulation
AbstractSimulationHandlerPtr _simulationHandler{nullptr};
Expand Down
5 changes: 3 additions & 2 deletions plugins/RocketsPlugin/jsonSerialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ inline void init(brayns::ClipPlane* c, ObjectHandler* h)

inline void init(brayns::Camera* c, ObjectHandler* h)
{
h->add_property("clip_planes", &c->_clipPlanes, Flags::Optional);
h->add_property("look_at", Vector3fArray(c->_target), Flags::Optional);
h->add_property("origin", Vector3fArray(c->_position), Flags::Optional);
h->add_property("current", &c->_currentType, Flags::Optional);
Expand Down Expand Up @@ -330,8 +329,10 @@ inline void init(brayns::Scene* s, ObjectHandler* h)
{
h->add_property("bounds", &s->getBounds(),
Flags::IgnoreRead | Flags::Optional);
h->add_property("clip_planes", &s->_clipPlanes, Flags::Optional);
std::shared_lock<std::shared_timed_mutex> lock(s->modelMutex());
h->add_property("models", &s->getModelDescriptors(), Flags::IgnoreRead);
h->add_property("models", &s->getModelDescriptors(),
Flags::Optional | Flags::IgnoreRead);
h->set_flags(Flags::DisallowUnknownKey);
}

Expand Down
15 changes: 12 additions & 3 deletions plugins/engines/ospray/OSPRayCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include <brayns/common/scene/Scene.h>

#include "OSPRayCamera.h"
#include "utils.h"

Expand Down Expand Up @@ -49,11 +51,10 @@ void OSPRayCamera::commit()
setOSPRayProperties(*this, _camera);

// Clip planes
const auto& clipPlanes = getClipPlanes();
if (!clipPlanes.empty())
if (!_clipPlanes.empty())
{
auto clipPlaneData =
ospNewData(clipPlanes.size(), OSP_FLOAT4, clipPlanes.data());
ospNewData(_clipPlanes.size(), OSP_FLOAT4, _clipPlanes.data());
ospSetData(_camera, "clipPlanes", clipPlaneData);
ospRelease(clipPlaneData);
}
Expand All @@ -69,6 +70,14 @@ void OSPRayCamera::setEnvironmentMap(const bool environmentMap)
ospCommit(_camera);
}

void OSPRayCamera::setClipPlanes(const ClipPlanes& clipPlanes)
{
if (_clipPlanes == clipPlanes)
return;
_clipPlanes = clipPlanes;
markModified();
}

bool OSPRayCamera::isSideBySideStereo() const
{
return hasProperty("stereoMode") && getProperty<int>("stereoMode") == 3;
Expand Down
8 changes: 8 additions & 0 deletions plugins/engines/ospray/OSPRayCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,17 @@ class OSPRayCamera : public Camera
*/
void commit() final;

/**
Set the clipping planes to use in this camera.
Currently, this only works for the clippedperspective camera.
*/
void setClipPlanes(const ClipPlanes& clipPlanes);

/** @copydoc Camera::setEnvironmentMap */
void setEnvironmentMap(const bool environmentMap) final;

bool isSideBySideStereo() const final;

/**
Gets the OSPRay implementation of the camera object
@return OSPRay implementation of the camera object
Expand All @@ -57,6 +64,7 @@ class OSPRayCamera : public Camera
private:
OSPCamera _camera{nullptr};
std::string _currentOSPCamera;
ClipPlanes _clipPlanes;
};
}
#endif // OSPRAYCAMERA_H
4 changes: 4 additions & 0 deletions plugins/engines/ospray/OSPRayRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ void OSPRayRenderer::commit()
ospSet1f(_renderer, "transferFunctionRange",
_scene->getTransferFunction().getValuesRange().y() -
_scene->getTransferFunction().getValuesRange().x());

// Setting the clip planes in the camera
_camera->setClipPlanes(_scene->getClipPlanes());
_camera->commit();
}

ospSet1f(_renderer, "timestamp", ap.getFrame());
Expand Down

0 comments on commit 3c1538a

Please sign in to comment.