Commit 665effae authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

Merge branch 'refactor-camera-api' into 'development'

Refactor camera api

See merge request !101
parents 331b5f32 04b29022
......@@ -50,7 +50,6 @@ SET(CampvisApplicationToBeMocced
gui/properties/abstracttransferfunctioneditor.h
gui/properties/boolpropertywidget.h
gui/properties/buttonpropertywidget.h
gui/properties/camerapropertywidget.h
gui/properties/datanamepropertywidget.h
gui/properties/intpropertywidget.h
gui/properties/floatpropertywidget.h
......
......@@ -84,15 +84,6 @@ namespace campvis {
CampVisApplication::~CampVisApplication() {
cgtAssert(_initialized == false, "Destructing initialized CampVisApplication, deinitialize first!");
// delete everything in the right order:
for (std::vector<PipelineRecord>::iterator it = _pipelines.begin(); it != _pipelines.end(); ++it) {
delete it->_painter;
delete it->_pipeline;
}
for (std::vector<DataContainer*>::iterator it = _dataContainers.begin(); it != _dataContainers.end(); ++it) {
delete *it;
}
sigslot::signal_manager::getRef().stop();
sigslot::signal_manager::deinit();
}
......@@ -216,6 +207,15 @@ namespace campvis {
_mainWindow->deinit();
QuadRenderer::deinit();
// now delete everything in the right order:
for (std::vector<PipelineRecord>::iterator it = _pipelines.begin(); it != _pipelines.end(); ++it) {
delete it->_painter;
delete it->_pipeline;
}
for (std::vector<DataContainer*>::iterator it = _dataContainers.begin(); it != _dataContainers.end(); ++it) {
delete *it;
}
// deinit OpenGL and cgt
cgt::deinitGL();
}
......
......@@ -61,8 +61,8 @@ namespace campvis {
, _quadSize(0, 0)
, _localDataContainer("Local DataContainer for DataContainerInspectorCanvas")
, p_viewportSize("ViewportSize", "Viewport Size", cgt::ivec2(200), cgt::ivec2(0, 0), cgt::ivec2(10000))
, _tcp(&p_viewportSize)
, _geometryRenderer(&p_viewportSize)
, _trackballEH(nullptr)
{
static_cast<Geometry1DTransferFunction*>(p_transferFunction.getTF())->addGeometry(TFGeometry1D::createQuad(cgt::vec2(0.f, 1.f), cgt::col4(0, 0, 0, 255), cgt::col4(255, 255, 255, 255)));
......@@ -128,9 +128,6 @@ namespace campvis {
_dataContainer->s_dataAdded.disconnect(this);
}
delete _trackballEH;
_trackballEH = nullptr;
_geometryRenderer.deinit();
_handles.clear();
......@@ -254,9 +251,12 @@ namespace campvis {
void DataContainerInspectorCanvas::invalidate() {
// only if inited
if (_quad != 0 && _paintShader != 0) {
// TODO: check, whether this should be done in an extra thread
cgt::GLContextScopedLock lock(this);
paint();
// avoid recursive paints.
if (! cgt::GlContextManager::getRef().checkWhetherThisThreadHasAcquiredOpenGlContext()) {
// TODO: check, whether this should be done in an extra thread
cgt::GLContextScopedLock lock(this);
paint();
}
}
}
......@@ -320,8 +320,9 @@ namespace campvis {
void DataContainerInspectorCanvas::onEvent(cgt::Event* e) {
cgt::EventListener::onEvent(e);
if (_trackballEH && !e->isAccepted()) {
_trackballEH->onEvent(e);
if (!e->isAccepted()) {
_tcp.onEvent(e);
_tcp.process(_localDataContainer);
e->accept();
_geometriesDirty = true;
invalidate();
......@@ -445,6 +446,7 @@ namespace campvis {
_geometryRenderer.p_geometryID.setValue(name + ".geometry");
_geometryRenderer.p_renderTargetID.setValue(name + ".rendered");
_geometryRenderer.validate(AbstractProcessor::INVALID_PROPERTIES);
_geometryRenderer.invalidate(AbstractProcessor::INVALID_RESULT);
_geometryRenderer.process(_localDataContainer);
// grab render result texture from local DataContainer and push into texture vector.
......@@ -469,12 +471,8 @@ namespace campvis {
cgtAssert(false, "The rendered geometry does exist. Something went wrong.");
}
}
void DataContainerInspectorCanvas::resetTrackball() {
// delete old trackball
delete _trackballEH;
_trackballEH = nullptr;
// check whether we have to render geometries
cgt::Bounds unionBounds;
for (std::map<QString, QtDataHandle>::iterator it = _handles.begin(); it != _handles.end(); ++it) {
......@@ -485,9 +483,11 @@ namespace campvis {
// if so, create a new trackball
if (unionBounds.isDefined()) {
_trackballEH = new TrackballNavigationEventListener(&_geometryRenderer.p_camera, &p_viewportSize);
_trackballEH->reinitializeCamera(unionBounds);
_tcp.reinitializeCamera(unionBounds);
}
_tcp.invalidate(AbstractProcessor::INVALID_RESULT);
_tcp.process(_localDataContainer);
}
}
......@@ -39,9 +39,9 @@
#include "core/properties/numericproperty.h"
#include "core/properties/propertycollection.h"
#include "core/properties/transferfunctionproperty.h"
#include "core/eventhandlers/trackballnavigationeventlistener.h"
#include "modules/base/processors/lightsourceprovider.h"
#include "modules/base/processors/trackballcameraprovider.h"
#include "modules/vis/processors/geometryrenderer.h"
......@@ -220,8 +220,9 @@ namespace campvis {
DataContainer _localDataContainer; ///< Local DataContainer the GeometryRenderer works on
IVec2Property p_viewportSize;
TrackballCameraProvider _tcp; ///< TrackballCameraProvider to do camera stuff
GeometryRenderer _geometryRenderer; ///< GeometryRenderer used to render geometries
TrackballNavigationEventListener* _trackballEH;
};
}
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
#include "camerapropertywidget.h"
#include <QGridLayout>
#include <QLabel>
#include "core/tools/stringutils.h"
namespace campvis {
CameraPropertyWidget::CameraPropertyWidget(CameraProperty* property, DataContainer* dataContainer, QWidget* parent /*= 0*/)
: AbstractPropertyWidget(property, true, dataContainer, parent)
, _lblCameraPosition(0)
, _lblLookDirection(0)
, _lblUpVector(0)
{
_widget = new QWidget(this);
QGridLayout* gridLayout = new QGridLayout(_widget);
_widget->setLayout(gridLayout);
_lblCameraPosition = new QLabel("Position: ", _widget);
gridLayout->addWidget(_lblCameraPosition, 0, 0);
_lblFocusPosition = new QLabel("Focus: ", _widget);
gridLayout->addWidget(_lblFocusPosition, 1, 0);
_lblLookDirection = new QLabel("Look Direction: ", _widget);
gridLayout->addWidget(_lblLookDirection, 2, 0);
_lblUpVector = new QLabel("Up Vector: ", _widget);
gridLayout->addWidget(_lblUpVector, 3, 0);
addWidget(_widget);
updateWidgetFromProperty();
}
CameraPropertyWidget::~CameraPropertyWidget() {
}
void CameraPropertyWidget::updateWidgetFromProperty() {
CameraProperty* prop = static_cast<CameraProperty*>(_property);
_lblCameraPosition->setText("Position: " + QString::fromStdString(StringUtils::toString(prop->getValue().getPosition())));
_lblFocusPosition->setText("Focus: " + QString::fromStdString(StringUtils::toString(prop->getValue().getFocus())));
_lblLookDirection->setText("Look Direction: " + QString::fromStdString(StringUtils::toString(prop->getValue().getLook())));
_lblUpVector->setText("Up Vector: " + QString::fromStdString(StringUtils::toString(prop->getValue().getUpVector())));
}
}
\ No newline at end of file
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
#ifndef CAMERAPROPERTYWIDGET_H__
#define CAMERAPROPERTYWIDGET_H__
#include "application/gui/properties/abstractpropertywidget.h"
#include "application/gui/properties/propertywidgetfactory.h"
#include "core/properties/cameraproperty.h"
class QLabel;
namespace campvis {
/**
* Widget for a Camera.
* For now just offering read-access.
*/
class CameraPropertyWidget : public AbstractPropertyWidget {
Q_OBJECT;
public:
/**
* Creates a new CameraPropertyWidget for the property \a property.
* \param property The property the widget shall handle
* \param dataContainer DataContainer to use (optional), defaults to nullptr.
* \param parent Parent Qt widget
*/
CameraPropertyWidget(CameraProperty* property, DataContainer* dataContainer, QWidget* parent = 0);
/**
* Destructor
*/
virtual ~CameraPropertyWidget();
protected:
/**
* Gets called when the property has changed, so that widget can update its state.
*/
virtual void updateWidgetFromProperty();
private:
QWidget* _widget;
QLabel* _lblCameraPosition;
QLabel* _lblFocusPosition;
QLabel* _lblLookDirection;
QLabel* _lblUpVector;
};
// explicitly instantiate template, so that it gets registered also over DLL boundaries.
template class PropertyWidgetRegistrar<CameraPropertyWidget, CameraProperty>;
}
#endif // CAMERAPROPERTYWIDGET_H__
......@@ -6,8 +6,6 @@
%{
#include "core/datastructures/abstractdata.h"
#include "core/datastructures/imagedata.h"
#include "core/eventhandlers/trackballnavigationeventlistener.h"
#include "core/properties/cameraproperty.h"
#include "core/properties/genericproperty.h"
#include "core/properties/numericproperty.h"
#include "core/properties/floatingpointproperty.h"
......@@ -137,16 +135,6 @@ namespace campvis {
%template(FloatProperty) FloatingPointProperty<float>;
typedef FloatingPointProperty< float > FloatProperty;
/* CameraProperty */
%template(GenericProperty_Camera) GenericProperty<cgt::Camera>;
class CameraProperty : public GenericProperty<cgt::Camera> {
public:
CameraProperty(const std::string& name, const std::string& title, cgt::Camera cam = cgt::Camera());
virtual ~CameraProperty();
};
/* TFGeometry1D */
%nodefaultctor TFGeometry1D;
......@@ -269,12 +257,12 @@ namespace campvis {
/* Downcast the return value of HasPropertyCollection::getProperty to appropriate subclass */
%factory(AbstractProperty* campvis::HasPropertyCollection::getProperty,
campvis::FloatProperty, campvis::IVec2Property, campvis::TransferFunctionProperty,
campvis::DataNameProperty, campvis::StringProperty, campvis::CameraProperty);
campvis::DataNameProperty, campvis::StringProperty);
/* Downcast the return value of HasPropertyCollection::getNestedProperty to appropriate subclass */
%factory(AbstractProperty* campvis::HasPropertyCollection::getNestedProperty,
campvis::FloatProperty, campvis::IVec2Property, campvis::TransferFunctionProperty,
campvis::DataNameProperty, campvis::StringProperty, campvis::CameraProperty);
campvis::DataNameProperty, campvis::StringProperty);
/* HasPropertyCollection */
......@@ -339,20 +327,6 @@ namespace campvis {
explicit VisualizationProcessor(IVec2Property* viewportSizeProp);
~VisualizationProcessor();
};
/* TrackballNavigationEventListener */
class TrackballNavigationEventListener : public cgt::EventListener {
public:
TrackballNavigationEventListener(CameraProperty* cameraProperty, IVec2Property* viewportSizeProp);
virtual ~TrackballNavigationEventListener();
void addLqModeProcessor(VisualizationProcessor* vp);
void removeLqModeProcessor(VisualizationProcessor* vp);
void reinitializeCamera(const IHasWorldBounds* hwb);
void reinitializeCamera(const cgt::Bounds& worldBounds);
};
}
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universität München
// Boltzmannstr. 3, 85748 Garching b. München, Germany
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
//
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ================================================================================================
#include "cameradata.h"
namespace campvis {
CameraData::CameraData(const cgt::Camera& camera /*= cgt::Camera()*/)
: AbstractData()
, _camera(camera)
{
}
CameraData::~CameraData() {
}
CameraData* CameraData::clone() const {
return new CameraData(*this);
}
size_t CameraData::getLocalMemoryFootprint() const {
return sizeof(*this);
}
size_t CameraData::getVideoMemoryFootprint() const {
return 0;
}
const cgt::Camera& CameraData::getCamera() const {
return _camera;
}
cgt::Camera& CameraData::getCamera() {
return _camera;
}
void CameraData::setCamera(const cgt::Camera& camera) {
_camera = camera;
}
}
\ No newline at end of file
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitt Mnchen
// Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
//
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ================================================================================================
#ifndef CAMERADATA_H__
#define CAMERADATA_H__
#include "cgt/camera.h"
#include "core/datastructures/abstractdata.h"
#include <vector>
namespace campvis {
/**
* Data object storing camera data.
*/
class CAMPVIS_CORE_API CameraData : public AbstractData {
public:
/**
* Constructor, creating a new CameraData object initialized by \a camera.
* \param camera Camera object used for initialization (optional)
*/
explicit CameraData(const cgt::Camera& camera = cgt::Camera());
/**
* Destructor.
*/
virtual ~CameraData();
/// \see AbstractData::clone()
virtual CameraData* clone() const;
/// \see AbstractData::getLocalMemoryFootprint()
virtual size_t getLocalMemoryFootprint() const;
/// \see AbstractData::getVideoMemoryFootprint()
virtual size_t getVideoMemoryFootprint() const;
/**
* Const getter for the camera settings.
* \return _camera
*/
const cgt::Camera& getCamera() const;
/**
* Non-const getter for the camera settings.
* \return _camera
*/
cgt::Camera& getCamera();
/**
* Sets the camera settings to \a camera.
* \param camera New camera settings.
*/
void setCamera(const cgt::Camera& camera);
protected:
cgt::Camera _camera; ///< The cgt::Camera object storing the camera setup
};
}
#endif // CAMERADATA_H__
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
#include "trackballnavigationeventlistener.h"
#include "cgt/assert.h"
#include "cgt/event/mouseevent.h"
#include "core/datastructures/abstractdata.h"
#include "core/properties/cameraproperty.h"
#include "core/pipeline/visualizationprocessor.h"
namespace campvis {
CamPropNavigationWrapper::CamPropNavigationWrapper(CameraProperty* camProp)
: _cameraProperty(camProp)
, _dirty(false)
{
}
CamPropNavigationWrapper::~CamPropNavigationWrapper() {
}
cgt::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;
}
// = TrackballNavigationEventListener ==============================================================
const std::string TrackballNavigationEventListener::loggerCat_ = "CAMPVis.core.eventhandler.TrackballNavigationEventListener";
TrackballNavigationEventListener::TrackballNavigationEventListener(CameraProperty* cameraProperty, IVec2Property* viewportSizeProp)
: cgt::EventListener()
, _cameraProperty(cameraProperty)
, _viewportSizeProp(viewportSizeProp)
, _cpnw(cameraProperty)
, _trackball(0)
, _sceneBounds(cgt::vec3(0.f))
{
cgtAssert(_cameraProperty != 0, "Assigned camera property must not be 0.");
cgtAssert(_viewportSizeProp != 0, "Assigned viewport size property must not be 0.");
_trackball = new cgt::Trackball(&_cpnw, viewportSizeProp->getValue());
_viewportSizeProp->s_changed.connect(this, &TrackballNavigationEventListener::onViewportSizePropChanged);
}
TrackballNavigationEventListener::~TrackballNavigationEventListener() {
_viewportSizeProp->s_changed.disconnect(this);
delete _trackball;
}
void TrackballNavigationEventListener::onEvent(cgt::Event* e) {
if (typeid(*e) == typeid(cgt::MouseEvent)) {
cgt::MouseEvent* me = static_cast<cgt::MouseEvent*>(e);
_trackball->setViewprtSize(me->viewport());
if (me->action() == cgt::MouseEvent::PRESSED) {
for (std::vector<VisualizationProcessor*>::iterator it = _lqModeProcessors.begin(); it != _lqModeProcessors.end(); ++it)
(*it)->p_lqMode.setValue(true);
_trackball->mousePressEvent(me);
}
else if (me->action() == cgt::MouseEvent::RELEASED) {
for (std::vector<VisualizationProcessor*>::iterator it = _lqModeProcessors.begin(); it != _lqModeProcessors.end(); ++it)
(*it)->p_lqMode.setValue(false);