Commit 01a45fcc authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

Further work on Issue #141: Introducing...

Further work on Issue #141: Introducing TrackballNavigationEventListener::reinitializeCamera() with tgt::Bounds or the new IHasWorldBounds interface as argument
parent 5e451d9b
......@@ -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.
......
......@@ -30,6 +30,7 @@
#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/visualizationprocessor.h"
......@@ -110,6 +111,20 @@ namespace campvis {
_trackball->reinitializeCamera(position, focus, upVector);
}
void TrackballNavigationEventListener::reinitializeCamera(const IHasWorldBounds* hwb) {
reinitializeCamera(hwb->getWorldBounds());
}
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 TrackballNavigationEventListener::setCenter(const tgt::vec3& center) {
_trackball->setCenter(center);
}
......
......@@ -37,12 +37,14 @@
#include "tgt/event/eventlistener.h"
#include "tgt/navigation/trackball.h"
#include "core/datastructures/datahandle.h"
#include "core/properties/numericproperty.h"
#include <vector>
namespace campvis {
class CameraProperty;
class IHasWorldBounds;
class VisualizationProcessor;
/**
......@@ -101,6 +103,26 @@ namespace campvis {
/// \see tgt::EventListener::onEvent()
virtual void onEvent(tgt::Event* e);
/**
* 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 reinitializeCamera(const IHasWorldBounds* hwb);
/**
* 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 reinitializeCamera(const tgt::Bounds& worldBounds);
/**
* Reinitalizes the camera by the given parameters.
* \param position New camera position
......@@ -127,7 +149,6 @@ 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
......@@ -143,9 +164,12 @@ 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
......
......@@ -241,14 +241,8 @@ namespace campvis {
// convert data
DataContainer::ScopedTypedData<ImageData> img(_data, _usReader.p_targetImageID.getValue());
if (img != 0) {
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());
_trackballEH->reinitializeCamera(img);
}
}
}
......
......@@ -48,7 +48,7 @@ namespace campvis {
/**
* Data object storing fiber data.
*/
class FiberData : public AbstractData {
class FiberData : public AbstractData, public IHasWorldBounds {
public:
/**
* Struct storing meta information about a single fiber.
......@@ -139,7 +139,7 @@ namespace campvis {
* \note Caution: Calling this method is expensive as the bounds are computed each time.
* \return The fiber data extent in world coordinates.
*/
tgt::Bounds getWorldBounds() const;
virtual tgt::Bounds getWorldBounds() const;
/**
* Renders the Fiber geometry of this data set in the current OpenGL context.
......
......@@ -160,14 +160,7 @@ namespace campvis {
// update camera
DataContainer::ScopedTypedData<ImageData> img(_data, _imageSplitter.p_outputID.getValue());
if (img != 0) {
tgt::Bounds volumeExtent = img->getWorldBounds();
if (_trackballEH->getSceneBounds() != volumeExtent) {
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());
}
}
}
}
......
......@@ -53,7 +53,7 @@ namespace campvis {
DataContainer::ScopedTypedData<ImageSeries> series(data, p_inputID.getValue());
if (series != 0) {
if (hasInvalidProperties()) {
p_imageIndex.setMaxValue(series->getNumImages());
p_imageIndex.setMaxValue(static_cast<int>(series->getNumImages()));
validate(INVALID_PROPERTIES);
}
if (p_imageIndex.getValue() < static_cast<int>(series->getNumImages())) {
......
......@@ -118,13 +118,7 @@ namespace campvis {
GenericImageRepresentationLocal<float, 1>* imageWithFloats = GenericImageRepresentationLocal<float, 1>::create(id, asFloats);
DataHandle dh = _data.addData("clr.input", id);
tgt::Bounds volumeExtent = img->getParent()->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());
_trackballEH->reinitializeCamera(img->getParent());
}
}
}
......
......@@ -60,6 +60,7 @@ namespace campvis {
_reader.p_url.setValue("C:/Users/SchuCh01/Documents/Data/Ultrasound/2012-12-12-Test/9l4sweep/content.xml");
_reader.p_targetImageID.connect(&_renderer.p_sourceImageID);
_renderer.s_boundingBoxChanged.connect(this, &UsCompounding::onBoundingBoxChanged);
_renderer.p_targetImageID.setValue("us.frame.output");
_renderTargetID.setValue(_renderer.p_targetImageID.getValue());
......@@ -75,11 +76,7 @@ namespace campvis {
}
void UsCompounding::onBoundingBoxChanged(tgt::Bounds b) {
tgt::vec3 pos = b.center() - tgt::vec3(0, 0, tgt::length(b.diagonal()));
_trackballEH->setSceneBounds(b);
_trackballEH->setCenter(b.center());
_trackballEH->reinitializeCamera(pos, b.center(), p_camera.getValue().getUpVector());
_trackballEH->reinitializeCamera(b);
}
}
\ No newline at end of file
......@@ -159,12 +159,7 @@ namespace campvis {
// update camera
DataContainer::ScopedTypedData<ImageData> img(_data, _imageReader.p_targetImageID.getValue());
if (img != 0) {
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());
_trackballEH->reinitializeCamera(img);
}
}
}
......
......@@ -93,12 +93,7 @@ namespace campvis {
// update camera
DataContainer::ScopedTypedData<ImageData> img(_data, _imageReader.p_targetImageID.getValue());
if (img != 0) {
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());
_trackballEH->reinitializeCamera(img);
}
}
}
......
......@@ -194,8 +194,8 @@ namespace campvis {
_shader->activate();
tgt::vec2 rts(_viewportSizeProperty->getValue());
const tgt::ivec2& vrs = p_volumeRenderSize.getValue();
const tgt::ivec2& srs = p_sliceRenderSize.getValue();
tgt::vec2 vrs(p_volumeRenderSize.getValue());
tgt::vec2 srs(p_sliceRenderSize.getValue());
_shader->setUniform("_projectionMatrix", tgt::mat4::createOrtho(0, rts.x, rts.y, 0, -1, 1));
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
......@@ -264,12 +264,7 @@ namespace campvis {
p_zSlice.setMaxValue(static_cast<int>(imgSize.z) - 1);
}
tgt::Bounds volumeExtent = static_cast<const ImageData*>(img.getData())->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(), _raycaster.p_camera.getValue().getUpVector());
_trackballEH->reinitializeCamera(static_cast<const ImageData*>(img.getData()));
}
void VolumeExplorer::onEvent(tgt::Event* e) {
......
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