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

implemented automatic adjustment of near-/far clipping planes to scene Bounds

 * added Navigation::setSceneBounds(), TrackballNavigationEventHandler::setSceneBounds()
 * added Navigation::updateClippingPlanes()

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@287 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent d9aa04f9
......@@ -123,4 +123,8 @@ namespace TUMVis {
_trackball->setViewprtSize(viewportSize);
}
void TrackballNavigationEventHandler::setSceneBounds(const tgt::Bounds& bounds) {
_trackball->setSceneBounds(bounds);
}
}
......@@ -29,6 +29,7 @@
#ifndef TRACKBALLNAVIGATIONEVENTHANDLER_H__
#define TRACKBALLNAVIGATIONEVENTHANDLER_H__
#include "tgt/bounds.h"
#include "tgt/logmanager.h"
#include "tgt/navigation/trackball.h"
#include "core/eventhandlers/abstracteventhandler.h"
......@@ -107,10 +108,17 @@ namespace TUMVis {
*/
void setCenter(const tgt::vec3& center);
/**
* Sets the scene bounds for automatic near/far clipping plane adjustment.
* \param bounds New bounds for the rendered scene.
*/
void setSceneBounds(const tgt::Bounds& bounds);
protected:
CameraProperty* _cameraProperty;
CamPropNavigationWrapper _cpnw;
tgt::Trackball* _trackball;
tgt::Bounds _sceneBounds;
static const std::string loggerCat_;
};
......
......@@ -48,6 +48,7 @@ void Navigation::rotateView(float angle, const vec3& axis) {
// Set the new focus-point
getCamera()->setFocus(getCamera()->getPosition() + getCamera()->getFocalLength()*look);
updateClippingPlanes();
}
// Rotate the Camera about horizontal and vertical angles given by the user
......@@ -71,6 +72,7 @@ void Navigation::rotateViewHV(float anglehorz, float anglevert) {
// Set the new focus-point
getCamera()->setFocus(getCamera()->getPosition() + getCamera()->getFocalLength()*look);
updateClippingPlanes();
}
// FIXME: the following few functions should be inline
......@@ -93,6 +95,7 @@ void Navigation::rotateViewHorz(float angle) {
void Navigation::rollCameraHorz(float angle) {
vec3 up = normalize( quat::rotate(getCamera()->getUpVector(), angle, getCamera()->getLook()) );
getCamera()->setUpVector(up);
updateClippingPlanes();
}
// This can be used to rotate (or "roll") the camera forwards and backwards, angle in radian measure
......@@ -101,12 +104,14 @@ void Navigation::rollCameraVert(float angle) {
getCamera()->setUpVector(up);
vec3 look = cross(up, getCamera()->getStrafe());
getCamera()->setFocus(getCamera()->getPosition() + look);
updateClippingPlanes();
}
void Navigation::moveCameraForward(float length) {
vec3 motionvector = length*getCamera()->getLook();
getCamera()->setPosition( getCamera()->getPosition() + motionvector );
getCamera()->setFocus( getCamera()->getFocus() + motionvector );
updateClippingPlanes();
}
void Navigation::moveCameraBackward(float length) {
......@@ -117,6 +122,7 @@ void Navigation::moveCameraUp(float length) {
vec3 motionvector = length*getCamera()->getUpVector();
getCamera()->setPosition( getCamera()->getPosition() + motionvector );
getCamera()->setFocus( getCamera()->getFocus() + motionvector );
updateClippingPlanes();
}
void Navigation::moveCameraDown(float length) {
......@@ -127,6 +133,7 @@ void Navigation::moveCameraRight(float length) {
vec3 motionvector = length*getCamera()->getStrafe();
getCamera()->setPosition( getCamera()->getPosition() + motionvector );
getCamera()->setFocus( getCamera()->getFocus() + motionvector );
updateClippingPlanes();
}
void Navigation::moveCameraLeft(float length) {
......@@ -145,6 +152,13 @@ void Navigation::moveCamera(float length, const vec3& axis) {
void Navigation::moveCamera(const vec3& motionvector) {
getCamera()->setPosition( getCamera()->getPosition() + motionvector );
getCamera()->setFocus( getCamera()->getFocus() + motionvector );
updateClippingPlanes();
}
void Navigation::setSceneBounds(const tgt::Bounds& bounds) {
_sceneBounds = bounds;
updateClippingPlanes();
hcam_->update();
}
/***********************************************************************
......
/**********************************************************************
* *
* tgt - Tiny Graphics Toolbox *
* *
* Copyright (C) 2006-2011 Visualization and Computer Graphics Group, *
* Department of Computer Science, University of Muenster, Germany. *
* <http://viscg.uni-muenster.de> *
* *
* This file is part of the tgt library. This library is free *
* software; you can redistribute it and/or modify it under the terms *
* of the GNU Lesser General Public License version 2.1 as published *
* by the Free Software Foundation. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License in the file "LICENSE.txt" along with this library. *
* If not, see <http://www.gnu.org/licenses/>. *
* *
**********************************************************************/
#ifndef TGT_NAVIGATION_H
#define TGT_NAVIGATION_H
#include "tgt/tgt_gl.h"
#include "tgt/camera.h"
#include "tgt/glcanvas.h"
#include "tgt/types.h"
#include "tgt/vector.h"
#include "tgt/event/mouseevent.h"
#include "tgt/event/eventlistener.h"
/**
This is the base class for navigation metaphores.
Derived classes offer solutions to use typical high-level camera movements in object space
(e.g. moving camera upon a trackball by mouse, make tracking shot following a spline) in a
simple way.
In addition, class it implements basic camera operations like moving or rotating the camera
in object space. Most deriving classes use these operations to do advanced navigations.
*/
namespace tgt {
/**
* Intermediate wrapper class for easier integration of tgt::Navigation into projects using
* separated cameras and canvases.
*/
class TGT_API IHasCamera {
public:
/**
* Pure virtual destructor
*/
virtual ~IHasCamera() = 0 {};
/**
* Returns the camera to modify by Navigation.
* Once a navigation is finished and the scene shall be rerendered, update() is called.
*/
virtual Camera* getCamera() = 0;
/**
* Notifies the camera holding object, that the navigation is finished.
*/
virtual void update() = 0;
};
class TGT_API Navigation : virtual public EventListener {
protected:
// navigation manipulates the camera of a certain canvas.
// we only need a pointer to this canvas, not to the camera (see getCamera).
IHasCamera* hcam_;
public:
Navigation(IHasCamera* hcam) {
hcam_ = hcam;
}
virtual ~Navigation() {}
// void setCanvas(GLCanvas* hcam) { hcam_ = hcam; }
// GLCanvas* getCanvas() const { return hcam_->; }
Camera* getCamera() const { return hcam_->getCamera(); }
/// The following functions may be used to rotate the Camera about
/// an arbitrary axis.
void rotateView(float angle, float x, float y, float z);
void rotateView(float angle, const vec3& axis);
/// This function rotates the view about the up- and strafe-vector
void rotateViewHV(float anglehorz, float anglevert);
/// The following functions may be used to rotate the Camera-View about
/// the Up- and the Strafe-Vector; they exist for reasons of convenience.
void rotateViewVert(float angle);
void rotateViewHorz(float angle);
/// The following functions may be used to rotate the Up-Vector about
/// the Strafe- and the Look-Vector. Use this with care since it may
/// leave the Camera with a "strange" orientation.
void rollCameraVert(float angle);
void rollCameraHorz(float angle);
/// The following functions may be used to move the camera a given
/// distance in a certain direction.
void moveCameraForward(float length);
void moveCameraBackward(float length);
void moveCameraUp(float length);
void moveCameraDown(float length);
void moveCameraRight(float length);
void moveCameraLeft(float length);
void moveCamera(float length, float x, float y, float z);
void moveCamera(float length, const vec3& axis);
void moveCamera(const vec3& motionvector);
};
} // namespace tgt
#endif //TGT_NAVIGATION_H
/**********************************************************************
* *
* tgt - Tiny Graphics Toolbox *
* *
* Copyright (C) 2006-2011 Visualization and Computer Graphics Group, *
* Department of Computer Science, University of Muenster, Germany. *
* <http://viscg.uni-muenster.de> *
* *
* This file is part of the tgt library. This library is free *
* software; you can redistribute it and/or modify it under the terms *
* of the GNU Lesser General Public License version 2.1 as published *
* by the Free Software Foundation. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License in the file "LICENSE.txt" along with this library. *
* If not, see <http://www.gnu.org/licenses/>. *
* *
**********************************************************************/
#ifndef TGT_NAVIGATION_H
#define TGT_NAVIGATION_H
#include "tgt/tgt_gl.h"
#include "tgt/bounds.h"
#include "tgt/camera.h"
#include "tgt/glcanvas.h"
#include "tgt/types.h"
#include "tgt/vector.h"
#include "tgt/event/mouseevent.h"
#include "tgt/event/eventlistener.h"
/**
This is the base class for navigation metaphores.
Derived classes offer solutions to use typical high-level camera movements in object space
(e.g. moving camera upon a trackball by mouse, make tracking shot following a spline) in a
simple way.
In addition, class it implements basic camera operations like moving or rotating the camera
in object space. Most deriving classes use these operations to do advanced navigations.
*/
namespace tgt {
/**
* Intermediate wrapper class for easier integration of tgt::Navigation into projects using
* separated cameras and canvases.
*/
class TGT_API IHasCamera {
public:
/**
* Pure virtual destructor
*/
virtual ~IHasCamera() = 0 {};
/**
* Returns the camera to modify by Navigation.
* Once a navigation is finished and the scene shall be rerendered, update() is called.
*/
virtual Camera* getCamera() = 0;
/**
* Notifies the camera holding object, that the navigation is finished.
*/
virtual void update() = 0;
};
class TGT_API Navigation : virtual public EventListener {
protected:
/**
* Updates the near-/far clipping planes.
* Does not issue an update command to the camera.
*/
void updateClippingPlanes() {
float diag = tgt::length(_sceneBounds.diagonal()) * 0.75f;
float dist = tgt::distance(getCamera()->getPosition(), _sceneBounds.center());
getCamera()->setNearDist(std::max(dist - diag, 0.1f));
getCamera()->setFarDist(diag + dist);
};
Bounds _sceneBounds;
// navigation manipulates the camera of a certain canvas.
// we only need a pointer to this canvas, not to the camera (see getCamera).
IHasCamera* hcam_;
public:
Navigation(IHasCamera* hcam) {
hcam_ = hcam;
}
virtual ~Navigation() {}
/**
* Sets the scene bounds for automatic near/far clipping plane adjustment.
* \param bounds New bounds for the rendered scene.
*/
void setSceneBounds(const tgt::Bounds& bounds);
// void setCanvas(GLCanvas* hcam) { hcam_ = hcam; }
// GLCanvas* getCanvas() const { return hcam_->; }
Camera* getCamera() const { return hcam_->getCamera(); }
/// The following functions may be used to rotate the Camera about
/// an arbitrary axis.
void rotateView(float angle, float x, float y, float z);
void rotateView(float angle, const vec3& axis);
/// This function rotates the view about the up- and strafe-vector
void rotateViewHV(float anglehorz, float anglevert);
/// The following functions may be used to rotate the Camera-View about
/// the Up- and the Strafe-Vector; they exist for reasons of convenience.
void rotateViewVert(float angle);
void rotateViewHorz(float angle);
/// The following functions may be used to rotate the Up-Vector about
/// the Strafe- and the Look-Vector. Use this with care since it may
/// leave the Camera with a "strange" orientation.
void rollCameraVert(float angle);
void rollCameraHorz(float angle);
/// The following functions may be used to move the camera a given
/// distance in a certain direction.
void moveCameraForward(float length);
void moveCameraBackward(float length);
void moveCameraUp(float length);
void moveCameraDown(float length);
void moveCameraRight(float length);
void moveCameraLeft(float length);
void moveCamera(float length, float x, float y, float z);
void moveCamera(float length, const vec3& axis);
void moveCamera(const vec3& motionvector);
};
} // namespace tgt
#endif //TGT_NAVIGATION_H
......@@ -69,6 +69,7 @@ Trackball::~Trackball() {
void Trackball::reset() {
getCamera()->positionCamera(cameraPosition_, cameraFocus_, cameraUpVector_);
updateClippingPlanes();
hcam_->update();
}
......@@ -264,6 +265,7 @@ void Trackball::zoom(float factor) {
factor = 1.f / factor;
getCamera()->setPosition( (1.f-factor) * getCamera()->getFocus()
+ factor * getCamera()->getPosition());
updateClippingPlanes();
hcam_->update();
}
......@@ -273,6 +275,7 @@ void Trackball::zoom(vec2 newMouse) {
void Trackball::zoomAbsolute(float focallength) {
getCamera()->setPosition( getCamera()->getFocus() - focallength * getCamera()->getLook());
updateClippingPlanes();
hcam_->update();
}
......@@ -549,6 +552,7 @@ void Trackball::timerEvent(TimeEvent* e) {
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
} // namespace
......@@ -50,11 +50,6 @@ namespace TUMVis {
{
addProperty(&_camera);
// TODO: remove this ugly hack: automatically adapt near/far plane to volume extent.
tgt::Camera c;
c.setFarDist(512.f);
_camera.setValue(c);
_trackballEH = new TrackballNavigationEventHandler(&_camera, _renderTargetSize.getValue());
_eventHandlers.push_back(_trackballEH);
......@@ -150,8 +145,11 @@ namespace TUMVis {
tgt::Bounds volumeExtent = img->getWorldBounds();
tgt::vec3 pos = volumeExtent.center() - tgt::vec3(0, 0, tgt::length(volumeExtent.diagonal()));
_trackballEH->setSceneBounds(volumeExtent);
_trackballEH->setCenter(volumeExtent.center());
_trackballEH->reinitializeCamera(pos, volumeExtent.center(), _camera.getValue().getUpVector());
}
if (! _pgGenerator.getInvalidationLevel().isValid()) {
executeProcessor(&_pgGenerator);
......
......@@ -149,6 +149,7 @@ namespace TUMVis {
_shader->setUniform("_viewMatrix", _camera.getValue().getViewMatrix());
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
// create entry points texture
ImageDataRenderTarget* entrypoints = new ImageDataRenderTarget(tgt::svec3(_renderTargetSize.getValue(), 1), GL_RGBA16);
......
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