Starting from 2021-07-01, all LRZ GitLab users will be required to explicitly accept the GitLab Terms of Service. Please see the detailed information at https://doku.lrz.de/display/PUBLIC/GitLab and make sure that your projects conform to the requirements.

Commit b7e1f9b7 authored by schultezub's avatar schultezub
Browse files

introduced MWheelToNumericPropertyEventHandler

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@190 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 37dccfdc
#include "mwheeltonumericpropertyeventhandler.h"
#include "tgt/assert.h"
#include "tgt/event/mouseevent.h"
namespace TUMVis {
const std::string MWheelToNumericPropertyEventHandler::loggerCat_ = "TUMVis.core.eventhandler.MWheelToNumericPropertyEventHandler";
MWheelToNumericPropertyEventHandler::MWheelToNumericPropertyEventHandler(INumericProperty* property)
: AbstractEventHandler()
, _prop(property)
{
tgtAssert(_prop != 0, "Assigned property must not be 0.");
}
MWheelToNumericPropertyEventHandler::~MWheelToNumericPropertyEventHandler() {
}
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()) {
case tgt::MouseEvent::MOUSE_WHEEL_UP:
_prop->increment();
e->ignore();
break;
case tgt::MouseEvent::MOUSE_WHEEL_DOWN:
_prop->decrement();
e->ignore();
break;
}
}
}
#ifndef MWHEELTONUMERICPROPERTYEVENTHANDLER_H__
#define MWHEELTONUMERICPROPERTYEVENTHANDLER_H__
#include "tgt/logmanager.h"
#include "core/eventhandlers/abstracteventhandler.h"
#include "core/properties/numericproperty.h"
namespace TUMVis {
/**
* Event handler that maps mouse wheel events to a numeric property.
*
*/
class MWheelToNumericPropertyEventHandler : public AbstractEventHandler {
public:
/**
* Creates a MWheelToNumericPropertyEventHandler.
*/
MWheelToNumericPropertyEventHandler(INumericProperty* property);
/**
* Virtual Destructor
**/
virtual ~MWheelToNumericPropertyEventHandler();
/**
* 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);
protected:
INumericProperty* _prop;
static const std::string loggerCat_;
};
}
#endif // MWHEELTONUMERICPROPERTYEVENTHANDLER_H__
......@@ -7,6 +7,12 @@
namespace TUMVis {
class INumericProperty {
public:
virtual void increment() = 0;
virtual void decrement() = 0;
};
/**
* Generic class for numeric properties.
* Numeric properties manage a minimum and maximum value and ensure, that the property's
......@@ -15,7 +21,7 @@ namespace TUMVis {
* \tparam T Base type of the property's value.
*/
template<typename T>
class NumericProperty : public GenericProperty<T> {
class NumericProperty : public GenericProperty<T>, public INumericProperty {
public:
/**
* Creates a new NumericProperty.
......@@ -72,8 +78,8 @@ namespace TUMVis {
*/
virtual void setMaxValue(const T& value);
void increment();
void decrement();
virtual void increment();
virtual void decrement();
protected:
......
......@@ -6,36 +6,42 @@ namespace TUMVis {
SliceVis::SliceVis(tgt::GLCanvas* canvas /*= 0*/)
: VisualizationPipeline(canvas)
, _imageReader(0)
, _sliceExtractor(0)
, _imageReader()
, _sliceExtractor(_canvasSize)
, _wheelHandler(&_sliceExtractor._sliceNumber)
{
_imageReader = new MhdImageReader();
_processors.push_back(_imageReader);
_sliceExtractor = new SliceExtractor(_canvasSize);
_processors.push_back(_sliceExtractor);
_processors.push_back(&_imageReader);
_processors.push_back(&_sliceExtractor);
_eventHandlers.push_back(&_wheelHandler);
}
SliceVis::~SliceVis() {
delete _imageReader;
delete _sliceExtractor;
}
void SliceVis::init() {
VisualizationPipeline::init();
_imageReader->_url.setValue("D:\\Medical Data\\smallHeart.mhd");
_imageReader->_targetImageID.setValue("reader.output");
_imageReader._url.setValue("D:\\Medical Data\\smallHeart.mhd");
_imageReader._targetImageID.setValue("reader.output");
_sliceExtractor->_sourceImageID.setValue("se.input");
_sliceExtractor->_sliceNumber.setValue(0);
_sliceExtractor._sourceImageID.setValue("se.input");
_sliceExtractor._sliceNumber.setValue(0);
_renderTargetID.setValue("renderTarget");
_renderTargetID.addSharedProperty(&(_sliceExtractor->_targetImageID));
_renderTargetID.addSharedProperty(&(_sliceExtractor._targetImageID));
_imageReader.addObserver(this);
_sliceExtractor.addObserver(this);
execute();
}
void SliceVis::execute() {
if (! _imageReader->getInvalidationLevel().isValid()) {
_imageReader->process(_data);
{
tbb::spin_mutex::scoped_lock lock(_localMutex);
_invalidationLevel.setValid();
}
if (! _imageReader.getInvalidationLevel().isValid()) {
_imageReader.process(_data);
// convert data
const ImageData* img = _data.getTypedData<ImageData>("reader.output");
......@@ -44,23 +50,26 @@ namespace TUMVis {
_data.addData("se.input", local);
}
}
if (! _sliceExtractor->getInvalidationLevel().isValid()) {
_sliceExtractor->process(_data);
if (! _sliceExtractor.getInvalidationLevel().isValid()) {
_sliceExtractor.process(_data);
}
// TODO: separate execution of the pipeline and rendering to canvas, as we want
// to do this asynchroniously in the mere future.
_canvas->repaint();
}
void SliceVis::keyEvent(tgt::KeyEvent* e) {
if (e->pressed()) {
switch (e->keyCode()) {
case tgt::KeyEvent::K_UP:
_sliceExtractor->_sliceNumber.increment();
_sliceExtractor._sliceNumber.increment();
break;
case tgt::KeyEvent::K_DOWN:
_sliceExtractor->_sliceNumber.decrement();
_sliceExtractor._sliceNumber.decrement();
break;
}
}
_canvas->repaint();
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@
#define SLICEVIS_H__
#include "core/datastructures/imagedatalocal.h"
#include "core/eventhandlers/mwheeltonumericpropertyeventhandler.h"
#include "core/pipeline/visualizationpipeline.h"
#include "modules/io/mhdimagereader.h"
#include "modules/vis/sliceextractor.h"
......@@ -30,8 +31,10 @@ namespace TUMVis {
virtual void keyEvent(tgt::KeyEvent* e);
protected:
MhdImageReader* _imageReader;
SliceExtractor* _sliceExtractor;
MhdImageReader _imageReader;
SliceExtractor _sliceExtractor;
MWheelToNumericPropertyEventHandler _wheelHandler;
};
}
......
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