Commit d3e77032 authored by schultezub's avatar schultezub
Browse files

* started implementing GeometryTransferFunctionEditor

 * added OpenGLJobProcessor::deregisterContext()

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@309 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 1e66b5dc
......@@ -30,6 +30,7 @@ SET(TUMVIS_APPLICATION_TO_BE_MOCCED
gui/properties/boolpropertywidget.h
gui/properties/intpropertywidget.h
gui/properties/floatpropertywidget.h
gui/properties/geometrytransferfunctioneditor.h
gui/properties/propertycollectionwidget.h
gui/properties/simpletransferfunctioneditor.h
gui/properties/stringpropertywidget.h
......
// ================================================================================================
//
// 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.
//
// ================================================================================================
#include "geometrytransferfunctioneditor.h"
#include "tgt/assert.h"
#include "tgt/shadermanager.h"
#include "tgt/qt/qtcontextmanager.h"
#include "tgt/qt/qtthreadedcanvas.h"
#include "application/gui/qtcolortools.h"
#include "core/classification/geometrytransferfunction.h"
#include "core/classification/tfgeometry.h"
#include "core/properties/transferfunctionproperty.h"
#include "core/tools/opengljobprocessor.h"
#include <QGridLayout>
#include <QLabel>
namespace TUMVis {
GeometryTransferFunctionEditor::GeometryTransferFunctionEditor(GeometryTransferFunction* tf, QWidget* parent /*= 0*/)
: AbstractTransferFunctionEditor(tf, parent)
, _layout(0)
, _canvas(0)
, _shader(0)
{
_layout = new QGridLayout(this);
setLayout(_layout);
_canvas = CtxtMgr.createContext("tfcanvas", "", tgt::ivec2(256, 128), tgt::GLCanvas::RGBA_BUFFER, this, false);
_canvas->doneCurrent();
GLJobProc.registerContext(_canvas);
_canvas->getEventHandler()->addListenerToBack(this);
_canvas->setPainter(this, false);
_layout->addWidget(_canvas, 0, 0);
GLJobProc.enqueueJob(_canvas, new CallMemberFuncJob<GeometryTransferFunctionEditor>(this, &GeometryTransferFunctionEditor::init), OpenGLJobProcessor::SerialJob);
}
GeometryTransferFunctionEditor::~GeometryTransferFunctionEditor() {
//GLJobProc.deregisterContext(_canvas);
}
void GeometryTransferFunctionEditor::updateWidgetFromProperty() {
GeometryTransferFunction* gtf = static_cast<GeometryTransferFunction*>(_transferFunction);
}
void GeometryTransferFunctionEditor::init() {
tgtAssert(_shader == 0, "GeometryTransferFunctionEditor already inited.");
}
void GeometryTransferFunctionEditor::paint() {
GeometryTransferFunction* gtf = static_cast<GeometryTransferFunction*>(_transferFunction);
const std::vector<TFGeometry*>& geometries = gtf->getGeometries();
const tgt::vec2& intensityDomain = gtf->getIntensityDomain();
glPushAttrib(GL_ALL_ATTRIB_BITS);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glViewport(0, 0, _canvas->width(), _canvas->height());
glOrtho(0, 1, 0, 1, -1, 1);
glClearColor(1.f, 1.f, 1.f, 1.f);
glClear(GL_COLOR_BUFFER_BIT);
LGL_ERROR;
// glBegin(GL_QUADS);
// glColor3f(1.f, 0.f, 0.f);
// glVertex2f(0.f, 0.f);
// glColor3f(1.f, 1.f, 0.f);
// glVertex2f(1.f, 0.f);
// glColor3f(0.f, 1.f, 0.f);
// glVertex2f(1.f, 1.f);
// glColor3f(0.f, 0.f, 1.f);
// glVertex2f(0.f, 1.f);
// glEnd();
for (std::vector<TFGeometry*>::const_iterator it = geometries.begin(); it != geometries.end(); ++it) {
(*it)->render();
}
LGL_ERROR;
glPopMatrix();
glPopAttrib();
}
void GeometryTransferFunctionEditor::sizeChanged(const tgt::ivec2&) {
invalidate();
}
void GeometryTransferFunctionEditor::invalidate() {
GLJobProc.enqueueJob(_canvas, new CallMemberFuncJob<GeometryTransferFunctionEditor>(this, &GeometryTransferFunctionEditor::paint), OpenGLJobProcessor::PaintJob);
}
}
\ 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 GEOMETRYTRANSFERFUNCTIONEDITOR_H__
#define GEOMETRYTRANSFERFUNCTIONEDITOR_H__
#include "tgt/painter.h"
#include "tgt/event/eventlistener.h"
#include "application/gui/properties/abstracttransferfunctioneditor.h"
class QGridLayout;
class QLabel;
namespace tgt {
class QtThreadedCanvas;
class Shader;
}
namespace TUMVis {
class ColorPickerWidget;
class GeometryTransferFunction;
/**
* Editor widget for a GeometryTransferFunction.
*/
class GeometryTransferFunctionEditor : public AbstractTransferFunctionEditor, public tgt::EventListener, public tgt::Painter {
Q_OBJECT;
public:
/**
* Creates a new editor widget for the for the TransferFunctionProperty \a property.
* \param tf The transfer function the editor shall handle.
* \param parent Parent Qt widget
*/
GeometryTransferFunctionEditor(GeometryTransferFunction* tf, QWidget* parent = 0);
/**
* Destructor
*/
virtual ~GeometryTransferFunctionEditor();
/**
* Initializes the shader for the OpenGL canvas.
*/
void init();
/**
* Performs the painting.
*/
void paint();
/// \see tgt::Painter::sizeChanged
virtual void sizeChanged(const tgt::ivec2&);
protected:
/**
* Gets called when the property has changed, so that widget can update its state.
*/
virtual void updateWidgetFromProperty();
/**
* To be called when the canvas is invalidated, issues new paint job.
*/
void invalidate();
private slots:
private:
QGridLayout* _layout;
tgt::QtThreadedCanvas* _canvas;
tgt::Shader* _shader;
};
}
#endif // GEOMETRYTRANSFERFUNCTIONEDITOR_H__
......@@ -29,9 +29,11 @@
#include "transferfunctioneditorfactory.h"
#include "application/gui/properties/abstracttransferfunctioneditor.h"
#include "application/gui/properties/geometrytransferfunctioneditor.h"
#include "application/gui/properties/simpletransferfunctioneditor.h"
#include "core/classification/abstracttransferfunction.h"
#include "core/classification/geometrytransferfunction.h"
#include "core/classification/simpletransferfunction.h"
namespace TUMVis {
......@@ -43,6 +45,10 @@ namespace TUMVis {
return new SimpleTransferFunctionEditor(tester);
}
if (GeometryTransferFunction* tester = dynamic_cast<GeometryTransferFunction*>(tf)) {
return new GeometryTransferFunctionEditor(tester);
}
return 0;
}
......
......@@ -96,6 +96,29 @@ namespace TUMVis {
}
}
void TFGeometry::render() const {
// TODO: get rid of intermediade mode?
glBegin(GL_POLYGON);
if (_keyPoints.front()._color.w > 0) {
glColor3ubv(_keyPoints.front()._color.elem);
glVertex2f(_keyPoints.front()._position, 0.f);
}
for (std::vector<KeyPoint>::const_iterator it = _keyPoints.begin(); it != _keyPoints.end(); ++it) {
glColor3ubv(it->_color.elem);
float y = 255.f / static_cast<float>(it->_color.a);
glVertex2f(it->_position, y);
}
if (_keyPoints.back()._color.w > 0) {
glColor3ubv(_keyPoints.back()._color.elem);
glVertex2f(_keyPoints.back()._position, 0.f);
}
glEnd();
}
TFGeometry* TFGeometry::createQuad(const tgt::vec2& interval, const tgt::col4& leftColor, const tgt::vec4 rightColor) {
tgtAssert(interval.x >= 0.f && interval.y <= 1.f, "Interval out of bounds");
......
......@@ -71,6 +71,12 @@ namespace TUMVis {
*/
void rasterize(tgt::Texture& texture) const;
/**
* Renders this transfer function geometry to the current active OpenGL context.
* \note Must be called from an active and valid OpenGL context.
*/
void render() const;
/**
* Creates a simple quad geometry for the given interval.
* A quad geometry consists of two KeyPoints.
......
......@@ -175,5 +175,13 @@ namespace TUMVis {
_contexts.push_back(context);
}
void OpenGLJobProcessor::deregisterContext(tgt::GLCanvas* context) {
tbb::concurrent_hash_map<tgt::GLCanvas*, PerContextJobQueue*>::const_accessor a;
if (_contextQueueMap.find(a, context)) {
delete a->second;
_contextQueueMap.erase(a);
}
}
}
......@@ -91,6 +91,12 @@ namespace TUMVis {
*/
void registerContext(tgt::GLCanvas* context);
/**
* Deregisters the given OpenGL context, so that it has no longer its own job queue.
* \param context OpenGL context to deregister.
*/
void deregisterContext(tgt::GLCanvas* context);
/// \see Runnable::stop
void stop();
......
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