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

Merge branch 'volumeexplorer' of campcloud.informatik.tu-muenchen.de:berge/campvis into development

parents 3a5c6b23 01a45fcc
......@@ -33,6 +33,7 @@
#include "modules/vis/pipelines/ixpvdemo.h"
#include "modules/vis/pipelines/dvrvis.h"
#include "modules/vis/pipelines/volumerendererdemo.h"
#include "modules/vis/pipelines/volumeexplorerdemo.h"
#include "modules/vis/pipelines/slicevis.h"
#ifdef HAS_KISSCL
#include "modules/opencl/pipelines/openclpipeline.h"
......@@ -70,7 +71,8 @@ int main(int argc, char** argv) {
// app.addVisualizationPipeline("IXPV", new IxpvDemo());
//app.addVisualizationPipeline("SliceVis", new SliceVis());
app.addVisualizationPipeline("DVRVis", new DVRVis());
app.addVisualizationPipeline("VolumeRendererDemo", new VolumeRendererDemo());
//app.addVisualizationPipeline("VolumeRendererDemo", new VolumeRendererDemo());
app.addVisualizationPipeline("VolumeExplorerDemo", new VolumeExplorerDemo());
#ifdef HAS_KISSCL
//app.addVisualizationPipeline("DVR with OpenCL", new OpenCLPipeline());
#endif
......
......@@ -170,7 +170,7 @@ namespace campvis {
if (_pipeline != 0) {
_pipeline->s_renderTargetChanged.disconnect(this);
if (getCanvas()->getEventHandler() != 0)
getCanvas()->getEventHandler()->removeListener(_pipeline);
getCanvas()->getEventHandler()->removeEventListener(_pipeline);
_pipeline = 0;
}
}
......@@ -180,14 +180,14 @@ namespace campvis {
if (_pipeline != 0) {
_pipeline->s_renderTargetChanged.disconnect(this);
if (getCanvas()->getEventHandler() != 0)
getCanvas()->getEventHandler()->removeListener(_pipeline);
getCanvas()->getEventHandler()->removeEventListener(_pipeline);
}
_pipeline = pipeline;
_pipeline->s_renderTargetChanged.connect(this, &TumVisPainter::onRenderTargetChanged);
_pipeline->setRenderTargetSize(getCanvas()->getSize());
if (getCanvas()->getEventHandler() != 0)
getCanvas()->getEventHandler()->addListenerToFront(_pipeline);
getCanvas()->getEventHandler()->addEventListenerToFront(_pipeline);
}
void TumVisPainter::repaint() {
......
......@@ -90,7 +90,7 @@ namespace campvis {
// set this as painter to get notified when window size changes
setPainter(this, false);
getEventHandler()->addListenerToFront(this);
getEventHandler()->addEventListenerToFront(this);
}
void DataContainerInspectorCanvas::deinit() {
......
......@@ -72,7 +72,7 @@ namespace campvis {
Geometry1DTransferFunctionEditor::~Geometry1DTransferFunctionEditor() {
tbb::mutex::scoped_lock lock(_localMutex);
// clear and delete former stuff
// clearEventListeners and delete former stuff
_selectedGeometry = 0;
for (std::vector<AbstractTFGeometryManipulator*>::iterator it = _manipulators.begin(); it != _manipulators.end(); ++it) {
if (WholeTFGeometryManipulator* tester = dynamic_cast<WholeTFGeometryManipulator*>(*it)) {
......@@ -278,9 +278,9 @@ namespace campvis {
void Geometry1DTransferFunctionEditor::updateManipulators() {
tbb::mutex::scoped_lock lock(_localMutex);
// clear and delete former stuff
// clearEventListeners and delete former stuff
_selectedGeometry = 0;
_canvas->getEventHandler()->clear();
_canvas->getEventHandler()->clearEventListeners();
for (std::vector<AbstractTFGeometryManipulator*>::iterator it = _manipulators.begin(); it != _manipulators.end(); ++it) {
if (WholeTFGeometryManipulator* tester = dynamic_cast<WholeTFGeometryManipulator*>(*it)) {
tester->s_selected.disconnect(this);
......@@ -295,17 +295,17 @@ namespace campvis {
// Add manipulator for the whole geometry and register it as event handler:
WholeTFGeometryManipulator* wtf = new WholeTFGeometryManipulator(_canvas->getSize(), *git);
_manipulators.push_back(wtf);
_canvas->getEventHandler()->addListenerToFront(wtf);
_canvas->getEventHandler()->addEventListenerToFront(wtf);
wtf->s_selected.connect(this, &Geometry1DTransferFunctionEditor::onWholeTFGeometryManipulatorSelected);
// Add a manipulator for each KeyPoint and register it as event handler:
for (std::vector<TFGeometry1D::KeyPoint>::iterator kpit = (*git)->getKeyPoints().begin(); kpit != (*git)->getKeyPoints().end(); ++kpit) {
_manipulators.push_back(new KeyPointManipulator(_canvas->getSize(), *git, kpit));
_canvas->getEventHandler()->addListenerToFront(_manipulators.back());
_canvas->getEventHandler()->addEventListenerToFront(_manipulators.back());
}
}
_canvas->getEventHandler()->addListenerToFront(this);
_canvas->getEventHandler()->addEventListenerToFront(this);
}
void Geometry1DTransferFunctionEditor::onGeometryCollectionChanged() {
......
......@@ -261,7 +261,7 @@ namespace campvis {
void Geometry2DTransferFunctionEditor::updateManipulators() {
tbb::mutex::scoped_lock lock(_localMutex);
_canvas->getEventHandler()->addListenerToFront(this);
_canvas->getEventHandler()->addEventListenerToFront(this);
}
void Geometry2DTransferFunctionEditor::onGeometryCollectionChanged() {
......
......@@ -30,9 +30,29 @@
#ifndef ABSTRACTDATA_H__
#define ABSTRACTDATA_H__
#include "tgt/bounds.h"
#include "core/tools/referencecounted.h"
namespace campvis {
/**
* Interface class for data which can compute their bounds in world coordinates.
*/
class IHasWorldBounds {
public:
/// Default empty constructor
IHasWorldBounds() {};
/// Virtual Destructor
virtual ~IHasWorldBounds() {};
/**
* Returns the data extent in world coordinates.
* \return The data extent in world coordinates.
*/
virtual tgt::Bounds getWorldBounds() const = 0;
};
/**
* Abstract base class for data handled by a DataHandle and stored in a DataContainer.
*
......
......@@ -46,7 +46,7 @@ namespace campvis {
*
* \todo
*/
class GeometryData : public AbstractData {
class GeometryData : public AbstractData, public IHasWorldBounds {
public:
GeometryData();
......
......@@ -31,7 +31,6 @@
#define IMAGEDATA_H__
#include "tbb/concurrent_vector.h"
#include "tgt/bounds.h"
#include "tgt/logmanager.h"
#include "tgt/vector.h"
#include "core/datastructures/abstractdata.h"
......@@ -51,7 +50,7 @@ namespace campvis {
*
* \todo
*/
class ImageData : public AbstractData {
class ImageData : public AbstractData, public IHasWorldBounds {
// friend so that it can add itself as representation
friend class AbstractImageRepresentation;
......@@ -126,7 +125,7 @@ namespace campvis {
* Returns the image extent in world coordinates.
* \return The image extent in world coordinates.
*/
tgt::Bounds getWorldBounds() const;
virtual tgt::Bounds getWorldBounds() const;
/**
* Returns the image extent in world coordinates for the given voxel coordinates.
......
......@@ -27,39 +27,29 @@
//
// ================================================================================================
#include "mwheeltonumericpropertyeventhandler.h"
#include "mwheeltonumericpropertyeventlistener.h"
#include "tgt/assert.h"
#include "tgt/event/mouseevent.h"
#include "core/properties/numericproperty.h"
namespace campvis {
const std::string MWheelToNumericPropertyEventHandler::loggerCat_ = "CAMPVis.core.eventhandler.MWheelToNumericPropertyEventHandler";
const std::string MWheelToNumericPropertyEventListener::loggerCat_ = "CAMPVis.core.eventhandler.MWheelToNumericPropertyEventListener";
MWheelToNumericPropertyEventHandler::MWheelToNumericPropertyEventHandler(INumericProperty* property)
: AbstractEventHandler()
MWheelToNumericPropertyEventListener::MWheelToNumericPropertyEventListener(INumericProperty* property)
: tgt::EventListener()
, _prop(property)
{
tgtAssert(_prop != 0, "Assigned property must not be 0.");
setEventTypes(tgt::Event::WHEELEVENT);
}
MWheelToNumericPropertyEventHandler::~MWheelToNumericPropertyEventHandler() {
}
MWheelToNumericPropertyEventListener::~MWheelToNumericPropertyEventListener() {
bool MWheelToNumericPropertyEventHandler::accept(tgt::Event* e) {
if (tgt::MouseEvent* me = dynamic_cast<tgt::MouseEvent*>(e)) {
return me->action() == tgt::MouseEvent::WHEEL;
}
return false;
}
void MWheelToNumericPropertyEventHandler::execute(tgt::Event* e) {
tgtAssert(dynamic_cast<tgt::MouseEvent*>(e) != 0, "Given event has wrong type. Check if the event is accepted by this event handler before executing it!");
// this is only to be executed when the event was accepted, so the static cast is safe.
tgt::MouseEvent* me = static_cast<tgt::MouseEvent*>(e);
tgtAssert(me->action() == tgt::MouseEvent::WHEEL, "Given event has wrong type. Check if the event is accepted by this event handler before executing it!");
switch (me->button()) {
void MWheelToNumericPropertyEventListener::wheelEvent(tgt::MouseEvent* e) {
switch (e->button()) {
case tgt::MouseEvent::MOUSE_WHEEL_UP:
_prop->increment();
e->ignore();
......
......@@ -31,43 +31,31 @@
#define MWHEELTONUMERICPROPERTYEVENTHANDLER_H__
#include "tgt/logmanager.h"
#include "core/eventhandlers/abstracteventhandler.h"
#include "tgt/event/eventlistener.h"
namespace campvis {
class INumericProperty;
/**
* Event handler that maps mouse wheel events to a numeric property.
*
*/
class MWheelToNumericPropertyEventHandler : public AbstractEventHandler {
class MWheelToNumericPropertyEventListener : public tgt::EventListener {
public:
/**
* Creates a MWheelToNumericPropertyEventHandler.
* Creates a MWheelToNumericPropertyEventListener.
*/
MWheelToNumericPropertyEventHandler(INumericProperty* property);
MWheelToNumericPropertyEventListener(INumericProperty* property);
/**
* Virtual Destructor
**/
virtual ~MWheelToNumericPropertyEventHandler();
virtual ~MWheelToNumericPropertyEventListener();
/**
* Checks, whether the given event \a e is handled by this EventHandler.
* \param e The event to check
* \return True, if the given event is handled by this EventHandler.
*/
virtual bool accept(tgt::Event* e);
/**
* Performs the event handling.
* \param e The event to handle
*/
virtual void execute(tgt::Event* e);
/// \see tgt::EventListener::wheelEvent()
virtual void wheelEvent(tgt::MouseEvent* e);
protected:
INumericProperty* _prop;
INumericProperty* _prop; ///< The Property to map the event to
static const std::string loggerCat_;
};
......
......@@ -27,11 +27,12 @@
//
// ================================================================================================
#include "trackballnavigationeventhandler.h"
#include "trackballnavigationeventlistener.h"
#include "tgt/assert.h"
#include "tgt/event/mouseevent.h"
#include "core/datastructures/abstractdata.h"
#include "core/properties/cameraproperty.h"
#include "core/pipeline/visualizationpipeline.h"
#include "core/pipeline/visualizationprocessor.h"
namespace campvis {
......@@ -60,52 +61,40 @@ namespace campvis {
_dirty = false;
}
// = TrackballNavigationEventHandler ==============================================================
// = TrackballNavigationEventListener ==============================================================
const std::string TrackballNavigationEventHandler::loggerCat_ = "CAMPVis.core.eventhandler.TrackballNavigationEventHandler";
const std::string TrackballNavigationEventListener::loggerCat_ = "CAMPVis.core.eventhandler.TrackballNavigationEventListener";
TrackballNavigationEventHandler::TrackballNavigationEventHandler(VisualizationPipeline* parentPipeline, CameraProperty* cameraProperty, const tgt::ivec2& viewportSize)
: AbstractEventHandler()
, _parentPipeline(parentPipeline)
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.");
TrackballNavigationEventHandler::~TrackballNavigationEventHandler() {
delete _trackball;
_trackball = new tgt::Trackball(&_cpnw, viewportSizeProp->getValue());
_viewportSizeProp->s_changed.connect(this, &TrackballNavigationEventListener::onViewportSizePropChanged);
}
bool TrackballNavigationEventHandler::accept(tgt::Event* e) {
if (typeid(*e) == typeid(tgt::MouseEvent)) {
tgt::MouseEvent* me = static_cast<tgt::MouseEvent*>(e);
if (me->action() == tgt::MouseEvent::PRESSED)
return true;
else if (me->action() == tgt::MouseEvent::RELEASED)
return true;
else if (me->action() == tgt::MouseEvent::MOTION)
return true;
else if (me->action() == tgt::MouseEvent::WHEEL)
return true;
}
else if (typeid(*e) == typeid(tgt::KeyEvent)) {
return true;
}
return false;
TrackballNavigationEventListener::~TrackballNavigationEventListener() {
_viewportSizeProp->s_changed.disconnect(this);
delete _trackball;
}
void TrackballNavigationEventHandler::execute(tgt::Event* e) {
void TrackballNavigationEventListener::onEvent(tgt::Event* e) {
if (typeid(*e) == typeid(tgt::MouseEvent)) {
tgt::MouseEvent* me = static_cast<tgt::MouseEvent*>(e);
if (me->action() == tgt::MouseEvent::PRESSED) {
_parentPipeline->enableLowQualityMode();
for (std::vector<VisualizationProcessor*>::iterator it = _lqModeProcessors.begin(); it != _lqModeProcessors.end(); ++it)
(*it)->p_lqMode.setValue(true);
_trackball->mousePressEvent(me);
}
else if (me->action() == tgt::MouseEvent::RELEASED) {
_parentPipeline->disableLowQualityMode();
for (std::vector<VisualizationProcessor*>::iterator it = _lqModeProcessors.begin(); it != _lqModeProcessors.end(); ++it)
(*it)->p_lqMode.setValue(false);
_trackball->mouseReleaseEvent(me);
}
else if (me->action() == tgt::MouseEvent::MOTION)
......@@ -118,24 +107,56 @@ namespace campvis {
}
}
void TrackballNavigationEventHandler::reinitializeCamera(const tgt::vec3& position, const tgt::vec3& focus, const tgt::vec3& upVector) {
void TrackballNavigationEventListener::reinitializeCamera(const tgt::vec3& position, const tgt::vec3& focus, const tgt::vec3& upVector) {
_trackball->reinitializeCamera(position, focus, upVector);
}
void TrackballNavigationEventHandler::setCenter(const tgt::vec3& center) {
_trackball->setCenter(center);
void TrackballNavigationEventListener::reinitializeCamera(const IHasWorldBounds* hwb) {
reinitializeCamera(hwb->getWorldBounds());
}
void TrackballNavigationEventHandler::setViewportSize(const tgt::ivec2& viewportSize) {
_trackball->setViewprtSize(viewportSize);
void TrackballNavigationEventListener::reinitializeCamera(const tgt::Bounds& worldBounds) {
if (_sceneBounds != worldBounds) {
tgt::vec3 pos = worldBounds.center() - tgt::vec3(0, 0, tgt::length(worldBounds.diagonal()));
setSceneBounds(worldBounds);
setCenter(worldBounds.center());
reinitializeCamera(pos, worldBounds.center(), _cameraProperty->getValue().getUpVector());
}
}
void TrackballNavigationEventHandler::setSceneBounds(const tgt::Bounds& bounds) {
void TrackballNavigationEventListener::setCenter(const tgt::vec3& center) {
_trackball->setCenter(center);
}
void TrackballNavigationEventListener::setSceneBounds(const tgt::Bounds& bounds) {
_trackball->setSceneBounds(bounds);
}
const tgt::Bounds& TrackballNavigationEventHandler::getSceneBounds() const {
const tgt::Bounds& TrackballNavigationEventListener::getSceneBounds() const {
return _trackball->getSceneBounds();
}
void TrackballNavigationEventListener::addLqModeProcessor(VisualizationProcessor* vp) {
tgtAssert(vp != 0, "Pointer to processor must not be 0.");
tgtAssert(std::find(_lqModeProcessors.begin(), _lqModeProcessors.end(), vp) == _lqModeProcessors.end(), "Processor already in list of LQ mode processors.");
_lqModeProcessors.push_back(vp);
}
void TrackballNavigationEventListener::removeLqModeProcessor(VisualizationProcessor* vp) {
for (std::vector<VisualizationProcessor*>::iterator it = _lqModeProcessors.begin(); it != _lqModeProcessors.end(); ++it) {
if (*it == vp)
_lqModeProcessors.erase(it);
}
}
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,25 +30,41 @@
#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/eventhandlers/abstracteventhandler.h"
#include "core/datastructures/datahandle.h"
#include "core/properties/numericproperty.h"
#include <vector>
namespace campvis {
class CameraProperty;
class VisualizationPipeline;
class IHasWorldBounds;
class VisualizationProcessor;
/**
* Wrapper to adapt a CameraProperty to the tgt::Trackball interface.
*/
class CamPropNavigationWrapper : public tgt::IHasCamera {
public:
/**
* Constructor
* \param camProp The CameraProperty to wrap around.
*/
CamPropNavigationWrapper(CameraProperty* camProp);
/// Virtual Destructor
virtual ~CamPropNavigationWrapper();
/// \see tgt::IHasCamera::getCamera()
virtual tgt::Camera* getCamera();
/// \see tgt::IHasCamera::update()
virtual void update();
private:
......@@ -61,43 +77,51 @@ 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 TrackballNavigationEventHandler : public AbstractEventHandler {
class TrackballNavigationEventListener : public tgt::EventListener, public sigslot::has_slots<> {
public:
/**
* Creates a TrackballNavigationEventHandler.
* \param parentPipeline Parent pipeline of this event handler, must not be 0.
* \param cameraProperty The CameraProperty to apply the navigation to.
* \param viewportSize Initial viewport size
* Creates a TrackballNavigationEventListener.
* \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.
*/
TrackballNavigationEventHandler(VisualizationPipeline* parentPipeline, CameraProperty* cameraProperty, const tgt::ivec2& viewportSize);
TrackballNavigationEventListener(CameraProperty* cameraProperty, IVec2Property* viewportSizeProp);
/**
* Virtual Destructor
**/
virtual ~TrackballNavigationEventHandler();
virtual ~TrackballNavigationEventListener();
/**
* Checks, whether the given event \a e is handled by this EventHandler.
* \param e The event to check
* \return True, if the given event is handled by this EventHandler.
*/
virtual bool accept(tgt::Event* e);
/// \see tgt::EventListener::onEvent()
virtual void onEvent(tgt::Event* e);
/**
* Performs the event handling.
* \param e The event to handle
* Reinitializes the camera using the data in \a hwb.
* If the scene bounds have changed, the camera setup is reinitialized positioning the
* camera in front of the data along the z-axis and looking at the center of the data.
*
* \param hwb Data to use for reinitialization, must not be 0.
*/
virtual void execute(tgt::Event* e);
void reinitializeCamera(const IHasWorldBounds* hwb);
/**
* Sets the viewport size to \a viewportSize.
* \param viewportSize The new viewport size.
* Reinitializes the camera using the data in \a hwb.
* If the scene bounds have changed, the camera setup is reinitialized positioning the
* camera in front of the data along the z-axis and looking at the center of the data.
*
* \param hwb Data to use for reinitialization, must not be 0.
*/
void setViewportSize(const tgt::ivec2& viewportSize);
void reinitializeCamera(const tgt::Bounds& worldBounds);
/**
* Reinitalizes the camera by the given parameters.
......@@ -125,13 +149,36 @@ namespace campvis {
*/
const tgt::Bounds& getSceneBounds() const;
/**
* Adds \a vp to the list of LQ mode processors.
* During interaction, TrackballNavigationEventListener will set the LQ mode flag of all
* LQ mode processors.
* \param vp VisualizationProcessor to add to the list of LQ mode processors.
*/
void addLqModeProcessor(VisualizationProcessor* vp);
/**
* Removes \a vp from the list of LQ mode processors.
* \param vp VisualizationProcessor to remove from the list of LQ mode processors.
*/
void removeLqModeProcessor(VisualizationProcessor* vp);
protected:
VisualizationPipeline* _parentPipeline; ///< The parent VisualizationPipeline
/// 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)
/// List of processors for which to enable LQ mode during interaction
std::vector<VisualizationProcessor*> _lqModeProcessors;
static const std::string loggerCat_;
};
......
......@@ -27,7 +27,7 @@
//
// ================================================================================================
#include "transfuncwindowingeventhandler.h"
#include "transfuncwindowingeventlistener.h"
#include "tgt/assert.h"
#include "tgt/event/mouseevent.h"
......@@ -35,34 +35,22 @@
#include "core/properties/transferfunctionproperty.h"