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 7b800d4f authored by schultezub's avatar schultezub
Browse files

* implemented TrackballNavigationEventHandler using tgt::Trackball

 * fixed EEPGenerator and added TrackballNavigationEventHandler to DVRVis

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@217 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent aaeac138
......@@ -4,25 +4,91 @@
#include "core/properties/cameraproperty.h"
namespace TUMVis {
CamPropNavigationWrapper::CamPropNavigationWrapper(CameraProperty* camProp)
: _cameraProperty(camProp)
, _dirty(false)
{
}
CamPropNavigationWrapper::~CamPropNavigationWrapper() {
}
tgt::Camera* CamPropNavigationWrapper::getCamera() {
if (! _dirty) {
// perform deep copy (hopefully thread-safe...)
_localCopy = _cameraProperty->getValue();
_dirty = true;
}
return &_localCopy;
}
void CamPropNavigationWrapper::update() {
_cameraProperty->setValue(_localCopy);
_dirty = false;
}
// = TrackballNavigationEventHandler ==============================================================
const std::string TrackballNavigationEventHandler::loggerCat_ = "TUMVis.core.eventhandler.TrackballNavigationEventHandler";
TrackballNavigationEventHandler::TrackballNavigationEventHandler(CameraProperty* property)
TrackballNavigationEventHandler::TrackballNavigationEventHandler(CameraProperty* cameraProperty, const tgt::ivec2& viewportSize)
: AbstractEventHandler()
, _cameraProperty(property)
, _cameraProperty(cameraProperty)
, _cpnw(cameraProperty)
, _trackball(0)
{
tgtAssert(_cameraProperty != 0, "Assigned property must not be 0.");
_trackball = new tgt::Trackball(&_cpnw, viewportSize);
}
TrackballNavigationEventHandler::~TrackballNavigationEventHandler() {
delete _trackball;
}
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;
}
void TrackballNavigationEventHandler::execute(tgt::Event* e) {
if (typeid(*e) == typeid(tgt::MouseEvent)) {
tgt::MouseEvent* me = static_cast<tgt::MouseEvent*>(e);
if (me->action() == tgt::MouseEvent::PRESSED)
_trackball->mousePressEvent(me);
else if (me->action() == tgt::MouseEvent::RELEASED)
_trackball->mouseReleaseEvent(me);
else if (me->action() == tgt::MouseEvent::MOTION)
_trackball->mouseMoveEvent(me);
else if (me->action() == tgt::MouseEvent::WHEEL)
_trackball->wheelEvent(me);
}
else if (typeid(*e) == typeid(tgt::KeyEvent)) {
_trackball->keyEvent(static_cast<tgt::KeyEvent*>(e));
}
}
void TrackballNavigationEventHandler::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);
}
}
......@@ -2,21 +2,40 @@
#define TRACKBALLNAVIGATIONEVENTHANDLER_H__
#include "tgt/logmanager.h"
#include "tgt/navigation/trackball.h"
#include "core/eventhandlers/abstracteventhandler.h"
namespace TUMVis {
class CameraProperty;
class CamPropNavigationWrapper : public tgt::IHasCamera {
public:
CamPropNavigationWrapper(CameraProperty* camProp);
virtual ~CamPropNavigationWrapper();
virtual tgt::Camera* getCamera();
virtual void update();
private:
CameraProperty* _cameraProperty; ///< CameraProperty this class wraps around
/// Temporary copy of the property's camera which will be modified and written back to the property upon update().
tgt::Camera _localCopy;
/// Flag whether _localCopy is dirty (needs to be written back)
bool _dirty;
};
/**
* Event handler that maps mouse wheel events to a numeric property.
*
* EventHandler implementing a trackball navigation for a CameraProperty.
* Implementation inspired by http://www.opengl.org/wiki/Trackball
*/
class TrackballNavigationEventHandler : public AbstractEventHandler {
public:
/**
* Creates a TrackballNavigationEventHandler.
*/
TrackballNavigationEventHandler(CameraProperty* property);
TrackballNavigationEventHandler(CameraProperty* cameraProperty, const tgt::ivec2& viewportSize);
/**
* Virtual Destructor
......@@ -37,8 +56,14 @@ namespace TUMVis {
*/
virtual void execute(tgt::Event* e);
void reinitializeCamera(const tgt::vec3& position, const tgt::vec3& focus, const tgt::vec3& upVector);
void setCenter(const tgt::vec3& center);
protected:
CameraProperty* _cameraProperty;
CamPropNavigationWrapper _cpnw;
tgt::Trackball* _trackball;
static const std::string loggerCat_;
};
......
......@@ -10,12 +10,18 @@ namespace TUMVis {
: VisualizationPipeline()
, _imageReader()
, _eepGenerator(_renderTargetSize)
, _trackballEH(0)
{
_trackballEH = new TrackballNavigationEventHandler(&_eepGenerator._camera, _renderTargetSize.getValue());
_eventHandlers.push_back(_trackballEH);
_processors.push_back(&_imageReader);
_processors.push_back(&_eepGenerator);
addProperty(&_renderTargetID);
}
DVRVis::~DVRVis() {
delete _trackballEH;
}
void DVRVis::init() {
......@@ -28,8 +34,8 @@ namespace TUMVis {
_eepGenerator._entryImageID.setValue("eep.entry");
_eepGenerator._exitImageID.setValue("eep.exit");
_renderTargetID.setValue("renderTarget");
_renderTargetID.addSharedProperty(&(_eepGenerator._entryImageID));
_renderTargetID.setValue("eep.entry");
//_renderTargetID.addSharedProperty(&(_eepGenerator._entryImageID));
_imageReader.s_invalidated.connect<DVRVis>(this, &DVRVis::onProcessorInvalidated);
_eepGenerator.s_invalidated.connect<DVRVis>(this, &DVRVis::onProcessorInvalidated);
......@@ -52,8 +58,15 @@ namespace TUMVis {
if (gl != 0) {
_data.addData("eep.input", gl);
}
}
tgt::Bounds volumeExtent = img->getWorldBounds();
tgt::vec3 pos = volumeExtent.center() - tgt::vec3(0, 0, tgt::length(volumeExtent.diagonal()));
_trackballEH->setCenter(volumeExtent.center());
_trackballEH->reinitializeCamera(pos, volumeExtent.center(), _eepGenerator._camera.getValue().getUpVector());
/* tgt::Camera cam(pos, volumeExtent.center());
cam.setFarDist(500.f);
_eepGenerator._camera.setValue(cam);*/
}
}
if (! _eepGenerator.getInvalidationLevel().isValid()) {
lockGLContextAndExecuteProcessor(_eepGenerator);
......
......@@ -2,7 +2,7 @@
#define DVRVIS_H__
#include "core/datastructures/imagedatalocal.h"
#include "core/eventhandlers/mwheeltonumericpropertyeventhandler.h"
#include "core/eventhandlers/trackballnavigationeventhandler.h"
#include "core/pipeline/visualizationpipeline.h"
#include "modules/io/mhdimagereader.h"
#include "modules/vis/eepgenerator.h"
......@@ -35,6 +35,7 @@ namespace TUMVis {
protected:
MhdImageReader _imageReader;
EEPGenerator _eepGenerator;
TrackballNavigationEventHandler* _trackballEH;
};
}
......
......@@ -22,13 +22,15 @@ namespace TUMVis {
, _entryImageID("entryImageID", "Output Entry Points Image", "")
, _exitImageID("exitImageID", "Output Exit Points Image", "")
, _camera("camera", "Camera")
, _jitterEntryPoints("jitterEntryPoints", "Jitter Entry Points", true)
, _shader(0)
{
addProperty(&_sourceImageID);
addProperty(&_entryImageID);
addProperty(&_exitImageID);
addProperty(&_camera);
tgt::Camera c;
c.setFarDist(512.f);
_camera.setValue(c);
}
EEPGenerator::~EEPGenerator() {
......@@ -52,35 +54,30 @@ namespace TUMVis {
if (img->getDimensionality() == 3) {
// TODO: implement some kind of proxy geometry...
tgt::Bounds volumeExtent = img->getWorldBounds();
//tgt::Bounds volumeExtent(tgt::vec3(-1.f), tgt::vec3(1.f));
tgt::Bounds textureBounds(tgt::vec3(0.f), tgt::vec3(1.f));
tgt::vec3 pos = volumeExtent.center() - tgt::vec3(0, 0, tgt::length(volumeExtent.diagonal()));
tgt::Camera cam(pos, volumeExtent.center());
cam.setFarDist(500.f);
// set modelview and projection matrices
glPushAttrib(GL_ALL_ATTRIB_BITS);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
tgt::loadMatrix(cam.getProjectionMatrix());
tgt::loadMatrix(_camera.getValue().getProjectionMatrix());
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
tgt::loadMatrix(cam.getViewMatrix());
tgt::loadMatrix(_camera.getValue().getViewMatrix());
_shader->activate();
glEnable(GL_CULL_FACE);
// create entry points texture
ImageDataRenderTarget* entrypoints = new ImageDataRenderTarget(tgt::svec3(_renderTargetSize.getValue(), 1));
entrypoints->activate();
glDepthFunc(GL_LESS);
glClearDepth(1.0f);
glDepthFunc(GL_GREATER);
glClearDepth(0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glCullFace(GL_BACK);
_shader->setUniform("_jitterPoints", _jitterEntryPoints.getValue());
glCullFace(GL_FRONT);
renderProxyGeometry(volumeExtent, textureBounds);
entrypoints->deactivate();
......@@ -89,11 +86,10 @@ namespace TUMVis {
ImageDataRenderTarget* exitpoints = new ImageDataRenderTarget(tgt::svec3(_renderTargetSize.getValue(), 1));
exitpoints->activate();
glDepthFunc(GL_GREATER);
glClearDepth(0.0f);
glDepthFunc(GL_LESS);
glClearDepth(1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glCullFace(GL_FRONT);
_shader->setUniform("_jitterPoints", false);
glCullFace(GL_BACK);
renderProxyGeometry(volumeExtent, textureBounds);
exitpoints->deactivate();
......@@ -132,13 +128,13 @@ namespace TUMVis {
glBegin(GL_QUADS);
// front
glTexCoord3f(tLlf.x, tLlf.y, tLlf.z);
glVertex3fv(llf.elem);
glVertex3f(llf.x, llf.y, llf.z);
glTexCoord3f(tUrb.x, tLlf.y, tLlf.z);
glVertex3f(urb.x, llf.y, llf.z);
glTexCoord3f(tUrb.x, tUrb.y, tLlf.z);
glVertex3f(urb.x, urb.y, llf.z);
glTexCoord3f(tLlf.x, tLlf.y, tLlf.z);
glVertex3f(llf.x, llf.y, llf.z);
glTexCoord3f(tLlf.x, tUrb.y, tLlf.z);
glVertex3f(llf.x, urb.y, llf.z);
// right
glTexCoord3f(tUrb.x, tLlf.y, tLlf.z);
......@@ -171,14 +167,14 @@ namespace TUMVis {
glVertex3f(llf.x, urb.y, urb.z);
// bottom
glTexCoord3f(tLlf.x, tLlf.y, tLlf.z);
glVertex3f(llf.x, llf.y, llf.z);
glTexCoord3f(tLlf.x, tLlf.y, tUrb.z);
glVertex3f(llf.x, llf.y, urb.z);
glTexCoord3f(tUrb.x, tLlf.y, tUrb.z);
glVertex3f(urb.x, llf.y, urb.z);
glTexCoord3f(tUrb.x, tLlf.y, tLlf.z);
glVertex3f(urb.x, llf.y, llf.z);
glTexCoord3f(tLlf.x, tLlf.y, tLlf.z);
glVertex3f(llf.x, llf.y, llf.z);
// back
glTexCoord3f(tUrb.x, tLlf.y, tUrb.z);
......
......@@ -48,7 +48,6 @@ namespace TUMVis {
GenericProperty<std::string> _exitImageID; ///< image ID for output exit points image
CameraProperty _camera;
BoolProperty _jitterEntryPoints;
protected:
void renderProxyGeometry(const tgt::Bounds& bounds, const tgt::Bounds& texBounds);
......
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