Commit dbad14c0 authored by schultezub's avatar schultezub
Browse files

* introducing GenericGeometryTransferFunction as base type for Geometry1DTF and Geometry2DTF

* introducint Geometry2DTransferFunction and TFGeometry2D

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@324 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 9a988b85
......@@ -108,9 +108,9 @@ namespace TUMVis {
glClear(GL_COLOR_BUFFER_BIT);
LGL_ERROR;
// render TF geometries
// renderIntoEditor TF geometries
for (std::vector<TFGeometry1D*>::const_iterator it = geometries.begin(); it != geometries.end(); ++it) {
(*it)->render();
(*it)->renderIntoEditor();
}
// render histogram if existent
......
......@@ -104,6 +104,15 @@ namespace TUMVis {
shader->setIgnoreUniformLocationError(tmp);
}
void AbstractTransferFunction::uploadTexture() {
{
tbb::mutex::scoped_lock lock(_localMutex);
if (_texture == 0 || _dirtyTexture) {
createTexture();
}
}
}
void AbstractTransferFunction::setIntensityDomain(const tgt::vec2& newDomain) {
tgtAssert(newDomain.x <= newDomain.y, "Intensity domain is not a valid interval.");
{
......
......@@ -98,6 +98,12 @@ namespace TUMVis {
* \param textureParametersUniform Uniform name to store texture parameters
*/
void bind(tgt::Shader* shader, const tgt::TextureUnit& texUnit, const std::string& textureUniform = "_tfTex", const std::string& textureParametersUniform = "_tfTextureParameters");
/**
* Creates the OpenGL texture.
* \note Calling thread must have a valid OpenGL context.
*/
void uploadTexture();
/**
* Sets the intensity domain where the transfer function is mapped to during classification.
......
// ================================================================================================
//
// This file is part of the TUMVis Visualization 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
//
// 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 GENERICGEOMETRYTRANSFERFUNCTION_H__
#define GENERICGEOMETRYTRANSFERFUNCTION_H__
#include "core/classification/abstracttransferfunction.h"
#include "tgt/assert.h"
#include "tgt/framebufferobject.h"
#include "tgt/logmanager.h"
#include "tgt/shadermanager.h"
#include "tgt/texture.h"
#include "tgt/textureunit.h"
#include <vector>
namespace TUMVis {
/**
* Generic base class for transfer functions built from multiple geometries.
* \tparam T Type of the base geometry class.
*/
template<class T>
class GenericGeometryTransferFunction : public AbstractTransferFunction, public sigslot::has_slots<> {
public:
/// Typedef for the geometry class this transfer function is built from.
typedef T GeometryType;
/**
* Creates a new GenericGeometryTransferFunction.
* \param size Size of the transfer function texture
* \param intensityDomain Intensity Domain where the transfer function is mapped to during classification
*/
GenericGeometryTransferFunction(const tgt::vec3& size, const tgt::vec2& intensityDomain = tgt::vec2(0.f, 1.f));
/**
* Destructor, make sure to delete the OpenGL texture beforehand by calling deinit() with a valid OpenGL context!
*/
virtual ~GenericGeometryTransferFunction();
/**
* Deletes the OpenGL texture, hence, this methods has to be called from a thread with a valid OpenGL context!
*/
virtual void deinit();
/**
* Gets the list of transfer function geometries.
* \return _geometries
*/
const std::vector<T*>& getGeometries() const;
/**
* Adds the given TF geometry to this transfer function.
* \note GenericGeometryTransferFunction takes ownership \a geometry.
* \param geometry TF geometry to add, GenericGeometryTransferFunction takes the ownership.
*/
void addGeometry(T* geometry);
/**
* Removes the given TF geometry from this transfer function.
* \note After the call \a geometry will no longer be valid as GenericGeometryTransferFunction deletes the given T.
* \param geometry TF geometry to remove, GenericGeometryTransferFunction will delete it
*/
void removeGeometry(T* geometry);
/**
* Slot to be called by T's s_changed signal.
*/
void onGeometryChanged();
/// Signal to be emitted when the vector of T objects (_geometries) changed (The collection, not the actual geometry).
sigslot::signal0<> s_geometryCollectionChanged;
protected:
/**
* Creates the texture and uploads it to OpenGL.
* Gets called by bind() with the local mutex already acquired.
*/
virtual void createTexture();
std::vector<T*> _geometries; ///< The list of transfer function geometries.
tgt::FramebufferObject* _fbo; ///< The FBO used for render into texture.
};
// ================================================================================================
template<class T>
TUMVis::GenericGeometryTransferFunction<T>::GenericGeometryTransferFunction(const tgt::vec3& size, const tgt::vec2& intensityDomain /*= tgt::vec2(0.f, 1.f)*/)
: AbstractTransferFunction(size, intensityDomain)
, _fbo(0)
{
}
template<class T>
TUMVis::GenericGeometryTransferFunction<T>::~GenericGeometryTransferFunction() {
for (std::vector<T*>::iterator it = _geometries.begin(); it != _geometries.end(); ++it) {
(*it)->s_changed.disconnect(this);
delete *it;
}
}
template<class T>
void TUMVis::GenericGeometryTransferFunction<T>::deinit() {
if (_fbo != 0) {
_fbo->activate();
_fbo->detachAll();
_fbo->deactivate();
LGL_ERROR;
delete _fbo;
}
AbstractTransferFunction::deinit();
}
template<class T>
const std::vector<T*>& TUMVis::GenericGeometryTransferFunction<T>::getGeometries() const {
return _geometries;
}
template<class T>
void TUMVis::GenericGeometryTransferFunction<T>::addGeometry(T* geometry) {
{
tbb::mutex::scoped_lock lock(_localMutex);
_geometries.push_back(geometry);
}
geometry->s_changed.connect(this, &GenericGeometryTransferFunction<T>::onGeometryChanged);
_dirtyTexture = true;
s_geometryCollectionChanged();
s_changed();
}
template<class T>
void TUMVis::GenericGeometryTransferFunction<T>::removeGeometry(T* geometry) {
{
tbb::mutex::scoped_lock lock(_localMutex);
for (std::vector<T*>::iterator it = _geometries.begin(); it != _geometries.end(); ++it) {
if (*it == geometry) {
_geometries.erase(it);
break;
}
}
}
geometry->s_changed.disconnect(this);
delete geometry;
_dirtyTexture = true;
s_geometryCollectionChanged();
s_changed();
}
template<class T>
void TUMVis::GenericGeometryTransferFunction<T>::onGeometryChanged() {
_dirtyTexture = true;
s_changed();
}
template<class T>
void TUMVis::GenericGeometryTransferFunction<T>::createTexture() {
// acqiure a new TextureUnit, so that we don't mess with other currently bound textures during texture upload...
tgt::TextureUnit tfUnit;
tfUnit.activate();
// detach old texture from FBO and delete it
if (_texture != 0 && _fbo != 0) {
_fbo->activate();
_fbo->detachAll();
_fbo->deactivate();
}
delete _texture;
// create FBO if needed
if (_fbo == 0)
_fbo = new tgt::FramebufferObject();
_fbo->activate();
LGL_ERROR;
// create texture
GLenum dataType = GL_UNSIGNED_BYTE;
_texture = new tgt::Texture(_size, GL_RGBA, dataType, tgt::Texture::LINEAR);
_texture->setWrapping(tgt::Texture::CLAMP);
_texture->uploadTexture();
LGL_ERROR;
// attach texture to FBO
_fbo->attachTexture(_texture);
if (! _fbo->isComplete()) {
LERROR("Incomplete FBO.");
_fbo->deactivate();
return;
}
LGL_ERROR;
// render TF geometries into texture
glPushAttrib(GL_ALL_ATTRIB_BITS);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, _texture->getWidth(), _texture->getHeight());
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, 1, 0, 1, -1, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
for (std::vector<T*>::const_iterator it = _geometries.begin(); it != _geometries.end(); ++it) {
(*it)->render();
}
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glPopAttrib();
LGL_ERROR;
// deactivate FBO
_fbo->deactivate();
LGL_ERROR;
tgt::TextureUnit::setZeroUnit();
_dirtyTexture = false;
}
}
#endif // GENERICGEOMETRYTRANSFERFUNCTION_H__
......@@ -41,75 +41,15 @@ namespace TUMVis {
const std::string Geometry1DTransferFunction::loggerCat_ = "TUMVis.core.classification.Geometry1DTransferFunction";
Geometry1DTransferFunction::Geometry1DTransferFunction(size_t size, const tgt::vec2& intensityDomain /*= tgt::vec2(0.f, 1.f)*/)
: AbstractTransferFunction(tgt::svec3(size, 1, 1), intensityDomain)
: GenericGeometryTransferFunction<TFGeometry1D>(tgt::svec3(size, 1, 1), intensityDomain)
{
}
Geometry1DTransferFunction::~Geometry1DTransferFunction() {
for (std::vector<TFGeometry1D*>::iterator it = _geometries.begin(); it != _geometries.end(); ++it) {
(*it)->s_changed.disconnect(this);
delete *it;
}
}
size_t Geometry1DTransferFunction::getDimensionality() const {
return 1;
}
void Geometry1DTransferFunction::createTexture() {
delete _texture;
GLenum dataType = GL_UNSIGNED_BYTE;
_texture = new tgt::Texture(_size, GL_RGBA, dataType, tgt::Texture::LINEAR);
_texture->setWrapping(tgt::Texture::CLAMP);
GLubyte* ptr = _texture->getPixelData();
memset(ptr, 0, _texture->getArraySize());
for (std::vector<TFGeometry1D*>::const_iterator it = _geometries.begin(); it != _geometries.end(); ++it) {
(*it)->rasterize(*_texture);
}
_texture->uploadTexture();
_dirtyTexture = false;
}
const std::vector<TFGeometry1D*>& Geometry1DTransferFunction::getGeometries() const {
return _geometries;
}
void Geometry1DTransferFunction::addGeometry(TFGeometry1D* geometry) {
{
tbb::mutex::scoped_lock lock(_localMutex);
_geometries.push_back(geometry);
}
geometry->s_changed.connect(this, &Geometry1DTransferFunction::onGeometryChanged);
_dirtyTexture = true;
s_geometryCollectionChanged();
s_changed();
}
void Geometry1DTransferFunction::removeGeometry(TFGeometry1D* geometry) {
{
tbb::mutex::scoped_lock lock(_localMutex);
for (std::vector<TFGeometry1D*>::iterator it = _geometries.begin(); it != _geometries.end(); ++it) {
if (*it == geometry) {
_geometries.erase(it);
break;
}
}
}
geometry->s_changed.disconnect(this);
delete geometry;
_dirtyTexture = true;
s_geometryCollectionChanged();
s_changed();
}
void Geometry1DTransferFunction::onGeometryChanged() {
_dirtyTexture = true;
s_changed();
}
}
\ No newline at end of file
......@@ -29,7 +29,7 @@
#ifndef GEOMETRY1DTRANSFERFUNCTION_H__
#define GEOMETRY1DTRANSFERFUNCTION_H__
#include "core/classification/abstracttransferfunction.h"
#include "core/classification/genericgeometrytransferfunction.h"
#include <vector>
......@@ -40,7 +40,7 @@ namespace TUMVis {
/**
* A 1D transfer function built from multiple geometries.
*/
class Geometry1DTransferFunction : public AbstractTransferFunction, public sigslot::has_slots<> {
class Geometry1DTransferFunction : public GenericGeometryTransferFunction<TFGeometry1D> {
public:
/**
* Creates a new Geometry1DTransferFunction.
......@@ -60,42 +60,7 @@ namespace TUMVis {
*/
virtual size_t getDimensionality() const;
/**
* Gets the list of transfer function geometries.
* \return _geometries
*/
const std::vector<TFGeometry1D*>& getGeometries() const;
/**
* Adds the given TF geometry to this transfer function.
* \note Geometry1DTransferFunction takes ownership \a geometry.
* \param geometry TF geometry to add, Geometry1DTransferFunction takes the ownership.
*/
void addGeometry(TFGeometry1D* geometry);
/**
* Removes the given TF geometry from this transfer function.
* \note After the call \a geometry will no longer be valid as Geometry1DTransferFunction deletes the given TFGeometry1D.
* \param geometry TF geometry to remove, Geometry1DTransferFunction will delete it
*/
void removeGeometry(TFGeometry1D* geometry);
/**
* Slot to be called by TFGeometry1D's s_changed signal.
*/
void onGeometryChanged();
/// Signal to be emitted when the vector of TFGeometry1D objects (_geometries) changed (The collection, not the actual geometry).
sigslot::signal0<> s_geometryCollectionChanged;
protected:
/**
* Creates the texture and uploads it to OpenGL.
* Gets called by bind() with the local mutex already acquired.
*/
virtual void createTexture();
std::vector<TFGeometry1D*> _geometries; ///< The list of transfer function geometries.
static const std::string loggerCat_;
......
// ================================================================================================
//
// This file is part of the TUMVis Visualization 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
//
// 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 "geometry2dtransferfunction.h"
#include "tgt/assert.h"
#include "tgt/logmanager.h"
#include "tgt/shadermanager.h"
#include "tgt/texture.h"
#include "tgt/textureunit.h"
#include "core/classification/tfgeometry2d.h"
namespace TUMVis {
const std::string Geometry2DTransferFunction::loggerCat_ = "TUMVis.core.classification.Geometry2DTransferFunction";
Geometry2DTransferFunction::Geometry2DTransferFunction(const tgt::svec2& size, const tgt::vec2& intensityDomain /*= tgt::vec2(0.f, 1.f)*/)
: GenericGeometryTransferFunction<TFGeometry2D>(tgt::svec3(size, 1), intensityDomain)
{
}
Geometry2DTransferFunction::~Geometry2DTransferFunction() {
}
size_t Geometry2DTransferFunction::getDimensionality() const {
return 2;
}
}
\ No newline at end of file
// ================================================================================================
//
// This file is part of the TUMVis Visualization 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
//
// 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 GEOMETRY2DTRANSFERFUNCTION_H__
#define GEOMETRY2DTRANSFERFUNCTION_H__
#include "core/classification/genericgeometrytransferfunction.h"
#include <vector>
namespace TUMVis {
class TFGeometry2D;
/**
* A 2D transfer function built from multiple geometries.
*/
class Geometry2DTransferFunction : public GenericGeometryTransferFunction<TFGeometry2D> {
public:
/**
* Creates a new Geometry2DTransferFunction.
* \param size Size of the transfer function texture
* \param intensityDomain Intensity Domain where the transfer function is mapped to during classification
*/
Geometry2DTransferFunction(const tgt::svec2& size, const tgt::vec2& intensityDomain = tgt::vec2(0.f, 1.f));
/**
* Destructor, make sure to delete the OpenGL texture beforehand by calling deinit() with a valid OpenGL context!
*/
virtual ~Geometry2DTransferFunction();
/**
* Returns the dimensionality of the transfer function.
* \return The dimensionality of the transfer function.
*/
virtual size_t getDimensionality() const;
protected:
static const std::string loggerCat_;
};
}
#endif // GEOMETRY2DTRANSFERFUNCTION_H__
......@@ -34,24 +34,6 @@
#include <algorithm>
namespace {
tgt::col4 toCol(const tgt::vec4& c) {
return tgt::col4(
static_cast<uint8_t>(255 * c.r),
static_cast<uint8_t>(255 * c.g),
static_cast<uint8_t>(255 * c.b),
static_cast<uint8_t>(255 * c.a));
}
tgt::vec4 toVec(const tgt::col4& c) {
return tgt::vec4(
static_cast<float>(c.r) / 255.f,
static_cast<float>(c.g) / 255.f,
static_cast<float>(c.b) / 255.f,
static_cast<float>(c.a) / 255.f);
}
}
namespace TUMVis {