Commit 5e451d9b authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

work in Issue #141: Implemented listening to viewport size property in...

work in Issue #141: Implemented listening to viewport size property in TrackballNavigationEventListener and thus removed obsolete TrackballNavigationEventListener::SetViewportSize().
parent b3913e3d
......@@ -64,17 +64,22 @@ namespace campvis {
const std::string TrackballNavigationEventListener::loggerCat_ = "CAMPVis.core.eventhandler.TrackballNavigationEventListener";
TrackballNavigationEventListener::TrackballNavigationEventListener(CameraProperty* cameraProperty, const tgt::ivec2& viewportSize)
TrackballNavigationEventListener::TrackballNavigationEventListener(CameraProperty* cameraProperty, IVec2Property* viewportSizeProp)
: tgt::EventListener()
, _cameraProperty(cameraProperty)
, _viewportSizeProp(viewportSizeProp)
, _cpnw(cameraProperty)
, _trackball(0)
{
tgtAssert(_cameraProperty != 0, "Assigned property must not be 0.");
_trackball = new tgt::Trackball(&_cpnw, viewportSize);
tgtAssert(_cameraProperty != 0, "Assigned camera property must not be 0.");
tgtAssert(_viewportSizeProp != 0, "Assigned viewport size property must not be 0.");
_trackball = new tgt::Trackball(&_cpnw, viewportSizeProp->getValue());
_viewportSizeProp->s_changed.connect(this, &TrackballNavigationEventListener::onViewportSizePropChanged);
}
TrackballNavigationEventListener::~TrackballNavigationEventListener() {
_viewportSizeProp->s_changed.disconnect(this);
delete _trackball;
}
......@@ -108,11 +113,7 @@ namespace campvis {
void TrackballNavigationEventListener::setCenter(const tgt::vec3& center) {
_trackball->setCenter(center);
}
void TrackballNavigationEventListener::setViewportSize(const tgt::ivec2& viewportSize) {
_trackball->setViewprtSize(viewportSize);
}
void TrackballNavigationEventListener::setSceneBounds(const tgt::Bounds& bounds) {
_trackball->setSceneBounds(bounds);
}
......@@ -135,4 +136,12 @@ namespace campvis {
}
}
void TrackballNavigationEventListener::onViewportSizePropChanged(const AbstractProperty* p) {
tgtAssert(p == _viewportSizeProp, "Signal from unexpected property! Expected p == _viewportSizeProp.");
_trackball->setViewprtSize(_viewportSizeProp->getValue());
float ratio = static_cast<float>(_viewportSizeProp->getValue().x) / static_cast<float>(_viewportSizeProp->getValue().y);
_cameraProperty->setWindowRatio(ratio);
}
}
......@@ -30,11 +30,15 @@
#ifndef TRACKBALLNAVIGATIONEVENTHANDLER_H__
#define TRACKBALLNAVIGATIONEVENTHANDLER_H__
#include <sigslot/sigslot.h>
#include "tgt/bounds.h"
#include "tgt/logmanager.h"
#include "tgt/event/eventlistener.h"
#include "tgt/navigation/trackball.h"
#include "core/properties/numericproperty.h"
#include <vector>
namespace campvis {
......@@ -71,17 +75,22 @@ namespace campvis {
};
/**
* EventHandler implementing a trackball navigation for a CameraProperty.
* EventListener implementing a trackball navigation for a CameraProperty.
* Implementation inspired by http://www.opengl.org/wiki/Trackball
*
* \note Also takes care of automatically adjusting the window ratio for the wrapped
* camera when the viewport size changes.
*/
class TrackballNavigationEventListener : public tgt::EventListener {
class TrackballNavigationEventListener : public tgt::EventListener, public sigslot::has_slots<> {
public:
/**
* Creates a TrackballNavigationEventListener.
* \param cameraProperty The CameraProperty to apply the navigation to.
* \param viewportSize Initial viewport size
* \note TrackballNavigationEventListener keeps and accesses \a viewportSizeProp during the whole
* lifetime. Hence make sure the pointer is valid at all times.
* \param cameraProperty Pointer to the CameraProperty to apply the navigation to, must not be 0.
* \param viewportSizeProp Pointer to the property defining the viewport size, must not be 0.
*/
TrackballNavigationEventListener(CameraProperty* cameraProperty, const tgt::ivec2& viewportSize);
TrackballNavigationEventListener(CameraProperty* cameraProperty, IVec2Property* viewportSizeProp);
/**
* Virtual Destructor
......@@ -91,13 +100,7 @@ namespace campvis {
/// \see tgt::EventListener::onEvent()
virtual void onEvent(tgt::Event* e);
/**
* Sets the viewport size to \a viewportSize.
* \param viewportSize The new viewport size.
*/
void setViewportSize(const tgt::ivec2& viewportSize);
/**
* Reinitalizes the camera by the given parameters.
* \param position New camera position
......@@ -140,7 +143,11 @@ namespace campvis {
void removeLqModeProcessor(VisualizationProcessor* vp);
protected:
/// Slot called when _viewportSizeProp changes
void onViewportSizePropChanged(const AbstractProperty* p);
CameraProperty* _cameraProperty; ///< The CameraProperty to apply the navigation to
IVec2Property* _viewportSizeProp; ///< Pointer to the property defining the viewport size
CamPropNavigationWrapper _cpnw; ///< The CamPropNavigationWrapper used to adapt to the tgt::Trackball interface
tgt::Trackball* _trackball; ///< The tgt::Trackball for the navigation logic
tgt::Bounds _sceneBounds; ///< The extent of the scene (in world coordinates)
......
......@@ -79,7 +79,7 @@ namespace campvis {
addEventListenerToBack(&_wheelHandler);
//addEventHandler(&_tfWindowingHandler);
_trackballEH = new TrackballNavigationEventListener(&_camera, _canvasSize.getValue());
_trackballEH = new TrackballNavigationEventListener(&_camera, &_canvasSize);
addEventListenerToBack(_trackballEH);
}
......@@ -193,9 +193,6 @@ namespace campvis {
_usDVR.p_targetImageID.setValue("us.dvr");
_renderTargetID.setValue("quadview.output");
_trackballEH->setViewportSize(_canvasSize.getValue());
_canvasSize.s_changed.connect<AdvancedUsVis>(this, &AdvancedUsVis::onRenderTargetSizeChanged);
}
void AdvancedUsVis::deinit() {
......@@ -239,12 +236,6 @@ namespace campvis {
return "AdvancedUsVis";
}
void AdvancedUsVis::onRenderTargetSizeChanged(const AbstractProperty* prop) {
_trackballEH->setViewportSize(_canvasSize.getValue());
float ratio = static_cast<float>(_canvasSize.getValue().x) / static_cast<float>(_canvasSize.getValue().y);
_camera.setWindowRatio(ratio);
}
void AdvancedUsVis::onProcessorValidated(AbstractProcessor* processor) {
if (processor = &_usReader) {
// convert data
......
......@@ -77,7 +77,6 @@ namespace campvis {
virtual void keyEvent(tgt::KeyEvent* e);
void onRenderTargetSizeChanged(const AbstractProperty* prop);
protected:
/**
......
......@@ -58,7 +58,7 @@ namespace campvis {
addProperty(&_camera);
addProperty(&_boundsData);
_trackballEH = new TrackballNavigationEventListener(&_camera, _canvasSize.getValue());
_trackballEH = new TrackballNavigationEventListener(&_camera, &_canvasSize);
_trackballEH->addLqModeProcessor(&_vr);
_trackballEH->addLqModeProcessor(&_src);
_trackballEH->addLqModeProcessor(&_sfr);
......@@ -144,9 +144,6 @@ namespace campvis {
_sfr.p_renderTargetID.setValue("sfr");
_sfr.p_renderTargetID.connect(static_cast<DataNameProperty*>(_vr.getProperty("GeometryImageId")));
_sfr.p_renderTargetID.connect(&_compositor.p_firstImageId);
_trackballEH->setViewportSize(_canvasSize.getValue());
_canvasSize.s_changed.connect<Columbia1>(this, &Columbia1::onRenderTargetSizeChanged);
}
void Columbia1::deinit() {
......@@ -158,12 +155,6 @@ namespace campvis {
return "Columbia1";
}
void Columbia1::onRenderTargetSizeChanged(const AbstractProperty* prop) {
_trackballEH->setViewportSize(_canvasSize.getValue());
float ratio = static_cast<float>(_canvasSize.getValue().x) / static_cast<float>(_canvasSize.getValue().y);
_camera.setWindowRatio(ratio);
}
void Columbia1::onProcessorValidated(AbstractProcessor* processor) {
if (processor == &_imageSplitter) {
// update camera
......
......@@ -70,8 +70,6 @@ namespace campvis {
virtual const std::string getName() const;
void onRenderTargetSizeChanged(const AbstractProperty* prop);
protected:
/**
* Slot getting called when one of the observed processors got validated.
......
......@@ -51,7 +51,7 @@ namespace campvis {
{
addProperty(&_camera);
_trackballEH = new TrackballNavigationEventListener(&_camera, _canvasSize.getValue());
_trackballEH = new TrackballNavigationEventListener(&_camera, &_canvasSize);
_trackballEH->addLqModeProcessor(&_clRaycaster);
addEventListenerToBack(_trackballEH);
......@@ -94,9 +94,6 @@ namespace campvis {
_eepGenerator.p_entryImageID.connect(&_clRaycaster._entryImageID);
_eepGenerator.p_exitImageID.connect(&_clRaycaster._exitImageID);
_trackballEH->setViewportSize(_canvasSize.getValue());
_canvasSize.s_changed.connect<OpenCLPipeline>(this, &OpenCLPipeline::onRenderTargetSizeChanged);
}
void OpenCLPipeline::deinit() {
......@@ -108,12 +105,6 @@ namespace campvis {
return "OpenCLPipeline";
}
void OpenCLPipeline::onRenderTargetSizeChanged(const AbstractProperty* prop) {
_trackballEH->setViewportSize(_canvasSize.getValue());
float ratio = static_cast<float>(_canvasSize.getValue().x) / static_cast<float>(_canvasSize.getValue().y);
_camera.setWindowRatio(ratio);
}
void OpenCLPipeline::onProcessorValidated(AbstractProcessor* processor) {
if (processor == &_imageReader) {
// update camera
......
......@@ -60,8 +60,6 @@ namespace campvis {
/// \see AbstractPipeline::getName()
virtual const std::string getName() const;
void onRenderTargetSizeChanged(const AbstractProperty* prop);
protected:
/**
* Slot getting called when one of the observed processors got validated.
......
......@@ -45,7 +45,7 @@ namespace campvis {
addProperty(&p_camera);
_trackballEH = new TrackballNavigationEventListener(&p_camera, _canvasSize.getValue());
_trackballEH = new TrackballNavigationEventListener(&p_camera, &_canvasSize);
addEventListenerToBack(_trackballEH);
}
......@@ -63,9 +63,6 @@ namespace campvis {
_renderer.s_boundingBoxChanged.connect(this, &UsCompounding::onBoundingBoxChanged);
_renderer.p_targetImageID.setValue("us.frame.output");
_renderTargetID.setValue(_renderer.p_targetImageID.getValue());
_trackballEH->setViewportSize(_canvasSize.getValue());
_canvasSize.s_changed.connect<UsCompounding>(this, &UsCompounding::onRenderTargetSizeChanged);
}
void UsCompounding::deinit() {
......@@ -77,12 +74,6 @@ namespace campvis {
return "UsCompounding";
}
void UsCompounding::onRenderTargetSizeChanged(const AbstractProperty* prop) {
_trackballEH->setViewportSize(_canvasSize.getValue());
float ratio = static_cast<float>(_canvasSize.getValue().x) / static_cast<float>(_canvasSize.getValue().y);
p_camera.setWindowRatio(ratio);
}
void UsCompounding::onBoundingBoxChanged(tgt::Bounds b) {
tgt::vec3 pos = b.center() - tgt::vec3(0, 0, tgt::length(b.diagonal()));
......
......@@ -62,8 +62,6 @@ namespace campvis {
virtual const std::string getName() const;
protected:
void onRenderTargetSizeChanged(const AbstractProperty* prop);
void onBoundingBoxChanged(tgt::Bounds b);
CameraProperty p_camera;
......
......@@ -56,7 +56,7 @@ namespace campvis {
{
addProperty(&_camera);
_trackballEH = new TrackballNavigationEventListener(&_camera, _canvasSize.getValue());
_trackballEH = new TrackballNavigationEventListener(&_camera, &_canvasSize);
_trackballEH->addLqModeProcessor(&_dvrNormal);
_trackballEH->addLqModeProcessor(&_dvrVM);
_trackballEH->addLqModeProcessor(&_depthDarkening);
......@@ -143,10 +143,6 @@ namespace campvis {
_dvrNormal.p_targetImageID.connect(&_depthDarkening.p_inputImage);
_depthDarkening.p_outputImage.connect(&_combine.p_normalImageID);
_trackballEH->setViewportSize(_canvasSize.getValue());
_canvasSize.s_changed.connect<DVRVis>(this, &DVRVis::onRenderTargetSizeChanged);
}
void DVRVis::deinit() {
......@@ -158,12 +154,6 @@ namespace campvis {
return "DVRVis";
}
void DVRVis::onRenderTargetSizeChanged(const AbstractProperty* prop) {
_trackballEH->setViewportSize(_canvasSize.getValue());
float ratio = static_cast<float>(_canvasSize.getValue().x) / static_cast<float>(_canvasSize.getValue().y);
_camera.setWindowRatio(ratio);
}
void DVRVis::onProcessorValidated(AbstractProcessor* processor) {
if (processor == &_imageReader) {
// update camera
......
......@@ -67,8 +67,6 @@ namespace campvis {
virtual const std::string getName() const;
void onRenderTargetSizeChanged(const AbstractProperty* prop);
protected:
/**
* Slot getting called when one of the observed processors got validated.
......
......@@ -76,7 +76,7 @@ namespace campvis {
addProperty(&_camera);
_trackballHandler = new TrackballNavigationEventListener(&_camera, _canvasSize.getValue());
_trackballHandler = new TrackballNavigationEventListener(&_camera, &_canvasSize);
addEventListenerToBack(&_wheelHandler);
addEventListenerToBack(_trackballHandler);
}
......@@ -183,20 +183,12 @@ namespace campvis {
_ixpvCompositor.p_targetImageId.setValue("ixpv");
_renderTargetID.setValue("ixpv");
_trackballHandler->setViewportSize(_canvasSize.getValue());
}
const std::string IxpvDemo::getName() const {
return "IXPV Demo";
}
void IxpvDemo::onRenderTargetSizeChanged(const AbstractProperty* prop) {
_trackballHandler->setViewportSize(_canvasSize.getValue());
float ratio = static_cast<float>(_canvasSize.getValue().x) / static_cast<float>(_canvasSize.getValue().y);
_camera.setWindowRatio(ratio);
}
void IxpvDemo::onProcessorValidated(AbstractProcessor* processor) {
if (processor == &_ctReader) {
ImageRepresentationLocal::ScopedRepresentation local(_data, _ctReader.p_targetImageID.getValue());
......
......@@ -70,8 +70,6 @@ namespace campvis {
//virtual void keyEvent(tgt::KeyEvent* e);
void onRenderTargetSizeChanged(const AbstractProperty* prop);
protected:
/**
* Slot getting called when one of the observed processors got validated.
......
......@@ -48,7 +48,7 @@ namespace campvis {
{
addProperty(&_camera);
_trackballEH = new TrackballNavigationEventListener(&_camera, _canvasSize.getValue());
_trackballEH = new TrackballNavigationEventListener(&_camera, &_canvasSize);
_trackballEH->addLqModeProcessor(&_vr);
addEventListenerToBack(_trackballEH);
......@@ -77,9 +77,6 @@ namespace campvis {
dvrTF->addGeometry(TFGeometry1D::createQuad(tgt::vec2(.1f, .125f), tgt::col4(255, 0, 0, 32), tgt::col4(255, 0, 0, 32)));
dvrTF->addGeometry(TFGeometry1D::createQuad(tgt::vec2(.4f, .5f), tgt::col4(0, 255, 0, 128), tgt::col4(0, 255, 0, 128)));
static_cast<TransferFunctionProperty*>(_vr.getProperty("TransferFunction"))->replaceTF(dvrTF);
_trackballEH->setViewportSize(_canvasSize.getValue());
_canvasSize.s_changed.connect<VolumeRendererDemo>(this, &VolumeRendererDemo::onRenderTargetSizeChanged);
}
void VolumeRendererDemo::deinit() {
......@@ -91,12 +88,6 @@ namespace campvis {
return "VolumeRendererDemo";
}
void VolumeRendererDemo::onRenderTargetSizeChanged(const AbstractProperty* prop) {
_trackballEH->setViewportSize(_canvasSize.getValue());
float ratio = static_cast<float>(_canvasSize.getValue().x) / static_cast<float>(_canvasSize.getValue().y);
_camera.setWindowRatio(ratio);
}
void VolumeRendererDemo::onProcessorValidated(AbstractProcessor* processor) {
if (processor == &_imageReader) {
// update camera
......
......@@ -59,8 +59,6 @@ namespace campvis {
virtual const std::string getName() const;
void onRenderTargetSizeChanged(const AbstractProperty* prop);
protected:
/**
* Slot getting called when one of the observed processors got validated.
......
......@@ -86,7 +86,7 @@ namespace campvis {
// Event-Handlers
_trackballEH = new TrackballNavigationEventListener(&_raycaster.p_camera, p_volumeRenderSize.getValue());
_trackballEH = new TrackballNavigationEventListener(&_raycaster.p_camera, &p_volumeRenderSize);
_trackballEH->addLqModeProcessor(&_raycaster);
}
......@@ -119,8 +119,6 @@ namespace campvis {
_quad = new FaceGeometry(vertices, texCorods);
_quad->createGLBuffers();
_trackballEH->setViewportSize(p_volumeRenderSize.getValue());
}
void VolumeExplorer::deinit() {
......@@ -169,10 +167,6 @@ namespace campvis {
if (prop == _viewportSizeProperty) {
p_sliceRenderSize.setValue(tgt::ivec2(_viewportSizeProperty->getValue().y / 3, _viewportSizeProperty->getValue().y / 3));
p_volumeRenderSize.setValue(tgt::ivec2(_viewportSizeProperty->getValue().x - _viewportSizeProperty->getValue().y / 3, _viewportSizeProperty->getValue().y));
_trackballEH->setViewportSize(p_volumeRenderSize.getValue());
float ratio = static_cast<float>(p_volumeRenderSize.getValue().x) / static_cast<float>(p_volumeRenderSize.getValue().y);
_raycaster.p_camera.setWindowRatio(ratio);
}
if (prop == &p_outputImage) {
_raycaster.p_outputImage.setValue(p_outputImage.getValue() + ".raycaster");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment