Commit 27e6e524 authored by schultezub's avatar schultezub

more work on DataContainerInspectorCanvas

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@285 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 47ec05ba
// ================================================================================================
//
// 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.
//
// ================================================================================================
#version 330
in vec3 ex_TexCoord;
out vec4 out_Color;
#include "tools/texture2d.frag"
uniform Texture2D _texture;
uniform vec4 _color;
void main() {
out_Color = getElement2DNormalized(_texture, ex_TexCoord.xy);
}
......@@ -30,11 +30,16 @@
#include "tgt/assert.h"
#include "tgt/shadermanager.h"
#include "tgt/textureunit.h"
#include "core/datastructures/datacontainer.h"
#include "core/datastructures/datahandle.h"
#include "core/datastructures/imagedatarendertarget.h"
#include "core/datastructures/imagedatagl.h"
#include "core/datastructures/facegeometry.h"
#include "core/tools/job.h"
#include "core/tools/quadrenderer.h"
#include "application/gui/datacontainertreewidget.h"
namespace TUMVis {
......@@ -43,8 +48,24 @@ namespace TUMVis {
: tgt::QtThreadedCanvas("DataContainer Inspector", tgt::ivec2(640, 480), tgt::GLCanvas::RGBA_BUFFER, parent, true)
, _dataContainer(0)
, _paintShader(0)
, _quad(0)
, dimX_(0)
, dimY_(0)
, scaledWidth_(0)
, scaledHeight_(0)
, selected_(0)
, fullscreen_(false)
{
makeCurrent();
// Init GLEW for this context
GLenum err = glewInit();
if (err != GLEW_OK) {
// Problem: glewInit failed, something is seriously wrong.
tgtAssert(false, "glewInit failed");
std::cerr << "glewInit failed, error: " << glewGetErrorString(err) << std::endl;
exit(EXIT_FAILURE);
}
}
DataContainerInspectorCanvas::~DataContainerInspectorCanvas() {
......@@ -52,11 +73,14 @@ namespace TUMVis {
}
void DataContainerInspectorCanvas::init() {
GLJobProc.registerContext(this);
_paintShader = ShdrMgr.loadSeparate("core/glsl/passthrough.vert", "application/glsl/datacontainerinspector.frag", "", false);
_paintShader->setAttributeLocation(0, "in_Position");
_paintShader->setAttributeLocation(1, "in_TexCoords");
}
void DataContainerInspectorCanvas::deinit() {
ShdrMgr.dispose(_paintShader);
}
void DataContainerInspectorCanvas::setDataContainer(DataContainer* dataContainer) {
......@@ -108,25 +132,26 @@ namespace TUMVis {
std::vector<const tgt::Texture*> textures;
for (std::map<std::string, const DataHandle*>::iterator it = _handles.begin(); it != _handles.end(); ++it) {
if (const ImageDataGL* imgGL = dynamic_cast<const ImageDataGL*>(it->second)) {
textures.push_back(imgGL->getTexture());
if (const ImageDataGL* imgGL = dynamic_cast<const ImageDataGL*>(it->second->getData())) {
if (imgGL->getDimensionality() == 2)
textures.push_back(imgGL->getTexture());
}
else if (const ImageDataRenderTarget* imgRT = dynamic_cast<const ImageDataRenderTarget*>(it->second)) {
textures.push_back(imgRT->getColorTexture());
textures.push_back(imgRT->getDepthTexture());
else if (const ImageDataRenderTarget* imgRT = dynamic_cast<const ImageDataRenderTarget*>(it->second->getData())) {
if (imgRT->getDimensionality() == 2) {
textures.push_back(imgRT->getColorTexture());
textures.push_back(imgRT->getDepthTexture());
}
}
}
glPushAttrib(GL_ALL_ATTRIB_BITS);
glEnable(GL_TEXTURE_2D);
glViewport(0, 0, size_.x, size_.y);
glClearColor(0.7f, 0.7f, 0.7f, 1.f);
glClear(GL_COLOR_BUFFER_BIT);
glColor4f(1.f, 1.f, 1.f, 1.f);
LGL_ERROR;
if (_handles.empty()) {
if (textures.empty()) {
glPopAttrib();
return;
}
......@@ -137,37 +162,38 @@ namespace TUMVis {
memsize += textures[i]->getSizeOnGPU();
}
memsize /= 1024 * 1024;
QString title = tr("DataContainer Inspector: %1 Textures (%2 mb)").arg(textures.size()).arg(memsize);
/*QString title = tr("DataContainer Inspector: %1 Textures (%2 mb)").arg(textures.size()).arg(memsize);
if (parentWidget() && parentWidget()->parentWidget())
parentWidget()->parentWidget()->setWindowTitle(title);
else
setWindowTitle(title);
setWindowTitle(title);*/
// render port contents
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glOrtho(0, size_.x, 0, size_.y, -1, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
// glMatrixMode(GL_PROJECTION);
// glPushMatrix();
// glOrtho(0, size_.x, 0, size_.y, -1, 1);
//
// glMatrixMode(GL_MODELVIEW);
// glPushMatrix();
// glLoadIdentity();
LGL_ERROR;
// if (textures.empty()) {
// renderFont(13, 13, "No rendertargets selected.");
// glPopMatrix();
// glMatrixMode(GL_PROJECTION);
// glPopMatrix();
// glPopAttrib();
// return;
// }
// update layout dimensions
dimX_ = (int)ceil(sqrt((float)textures.size()));
dimY_ = ceil((float)textures.size() / dimX_);
scaledWidth_ = size_.x / dimX_;
scaledHeight_ = size_.y / dimY_;
createQuad(scaledWidth_, scaledHeight_);
_paintShader->activate();
tgt::mat4 projection = tgt::mat4::createOrtho(0, size_.x, 0, size_.y, -1, 1);
_paintShader->setUniform("_projectionMatrix", projection);
tgt::TextureUnit tu;
tu.activate();
_paintShader->setUniform("_texture._texture", tu.getUnitNumber());
if (fullscreen_) {
if(selected_ >= 0 && selected_ < (int)textures.size()) {
......@@ -181,31 +207,48 @@ namespace TUMVis {
if (index >= static_cast<int>(textures.size()))
break;
glPushMatrix();
glTranslatef(scaledWidth_ * x, scaledHeight_ * y, 0.0);
glScalef(1.f, 1.f, 1.f);
tgt::mat4 translation = tgt::mat4::createTranslation(tgt::vec3(scaledWidth_ * x, scaledHeight_ * y, 0.f));
_paintShader->setUniform("_modelMatrix", translation);
paintTexture(textures[index]);
glPopMatrix();
}
}
}
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
_paintShader->deactivate();
LGL_ERROR;
glPopAttrib();
}
void DataContainerInspectorCanvas::paintTexture(const tgt::Texture* texture) {
_paintShader->activate();
texture->bind();
_paintShader->setIgnoreUniformLocationError(true);
_paintShader->setUniform("_texture._size", tgt::vec2(texture->getDimensions().xy()));
_paintShader->setUniform("_texture._sizeRCP", tgt::vec2(1.f) / tgt::vec2(texture->getDimensions().xy()));
_paintShader->setIgnoreUniformLocationError(false);
_quad->render();
}
void DataContainerInspectorCanvas::invalidate() {
GLJobProc.enqueueJob(this, new CallMemberFuncJob<DataContainerInspectorCanvas>(this, &DataContainerInspectorCanvas::paint), OpenGLJobProcessor::PaintJob);
}
void DataContainerInspectorCanvas::createQuad(float width, float height) {
std::vector<tgt::vec3> vertices, texCorods;
vertices.push_back(tgt::vec3( 0.f, 0.f, 0.f));
vertices.push_back(tgt::vec3(width, 0.f, 0.f));
vertices.push_back(tgt::vec3(width, height, 0.f));
vertices.push_back(tgt::vec3( 0.f, height, 0.f));
texCorods.push_back(tgt::vec3(0.f, 1.f, 0.f));
texCorods.push_back(tgt::vec3(1.f, 1.f, 0.f));
texCorods.push_back(tgt::vec3(1.f, 0.f, 0.f));
texCorods.push_back(tgt::vec3(0.f, 0.f, 0.f));
delete _quad;
_quad = new FaceGeometry(vertices, texCorods);
_quad->createGLBuffers();
}
}
\ No newline at end of file
......@@ -40,6 +40,7 @@
namespace tgt {
class Shader;
class Texture;
class TextureUnit;
}
namespace TUMVis {
......@@ -47,6 +48,7 @@ namespace TUMVis {
class DataContainer;
class DataContainerTreeWidget;
class DataHandle;
class FaceGeometry;
class DataContainerInspectorCanvas : public tgt::QtThreadedCanvas, public sigslot::has_slots<> {
Q_OBJECT;
......@@ -110,11 +112,14 @@ namespace TUMVis {
void paintTexture(const tgt::Texture* texture);
void createQuad(float width, float height);
DataContainer* _dataContainer; ///< The DataContainer this widget is inspecting
std::map<std::string, const DataHandle*> _handles; ///< Local copy of the DataHandles to inspect
tbb::mutex _localMutex;
tgt::Shader* _paintShader;
FaceGeometry* _quad;
int dimX_;
int dimY_;
......
......@@ -31,6 +31,7 @@
#include "tgt/assert.h"
#include "application/tumvisapplication.h"
#include "application/gui/datacontainerinspectorwidget.h"
#include "application/gui/datacontainerinspectorcanvas.h"
#include "core/pipeline/abstractpipeline.h"
#include "core/pipeline/abstractprocessor.h"
......@@ -43,6 +44,7 @@ namespace TUMVis {
, _pipelineWidget(0)
, _propCollectionWidget(0)
, _dcInspectorWidget(0)
, _dcInspectorCanvas(0)
, _btnExecute(0)
, _btnShowDataContainerInspector(0)
, _selectedPipeline(0)
......@@ -57,6 +59,9 @@ namespace TUMVis {
}
void MainWindow::setup() {
_dcInspectorCanvas = new DataContainerInspectorCanvas();
_dcInspectorCanvas->show();
_centralWidget = new QWidget(this);
QHBoxLayout* mainLayout = new QHBoxLayout();
mainLayout->setSpacing(4);
......@@ -115,6 +120,8 @@ namespace TUMVis {
if (AbstractPipeline* pipeline = dynamic_cast<AbstractPipeline*>(ptr)) {
_selectedPipeline = pipeline;
_selectedProcessor = 0;
_dcInspectorCanvas->setDataContainer(&_selectedPipeline->getDataContainer());
if (_dcInspectorWidget != 0)
onBtnShowDataContainerInspectorClicked();
}
......@@ -148,4 +155,14 @@ namespace TUMVis {
}
}
void MainWindow::init() {
if (_dcInspectorCanvas != 0)
_dcInspectorCanvas->init();
}
void MainWindow::deinit() {
if (_dcInspectorCanvas != 0)
_dcInspectorCanvas->deinit();
}
}
\ No newline at end of file
......@@ -42,6 +42,7 @@
namespace TUMVis {
class DataContainerInspectorWidget;
class DataContainerInspectorCanvas;
/**
* Main Window for the TUMVis application.
......@@ -62,6 +63,16 @@ namespace TUMVis {
*/
~MainWindow();
/**
* Initializes all OpenGL related stuff
*/
void init();
/**
* Deinitializes all OpenGL related stuff
*/
void deinit();
/**
* Slot to be called by the application when its collection of pipelines has changed.
......@@ -110,6 +121,8 @@ namespace TUMVis {
PropertyCollectionWidget* _propCollectionWidget; ///< Widget for brosing the PropertyCollection of the selected pipeline/processor
DataContainerInspectorWidget* _dcInspectorWidget; ///< Widget for inspecting the DataContainer of the selected pipeline.
DataContainerInspectorCanvas* _dcInspectorCanvas;
QPushButton* _btnExecute; ///< Button to execute the selected pipeline/processor
QPushButton* _btnShowDataContainerInspector; ///< Button to show the DataContainerInspector for the selected pipeline
......
......@@ -129,6 +129,8 @@ namespace TUMVis {
}
}
_mainWindow->init();
// init pipeline first
for (std::vector<AbstractPipeline*>::iterator it = _pipelines.begin(); it != _pipelines.end(); ++it) {
(*it)->init();
......@@ -162,6 +164,8 @@ namespace TUMVis {
it->second->deinit();
}
_mainWindow->deinit();
// deinit OpenGL and tgt
tgt::deinitGL();
......
......@@ -41,7 +41,4 @@ void main() {
vec2 fragCoord = gl_FragCoord.xy * _viewportSizeRCP;
out_Color = getElement2DNormalized(_colorTexture, fragCoord);
gl_FragDepth = getElement2DNormalized(_depthTexture, fragCoord).z;
// gl_FragData[0] = getElement2DNormalized(_colorTexture, fragCoord);
// gl_FragDepth = getElement2DNormalized(_depthTexture, fragCoord).z;
}
......@@ -104,11 +104,11 @@ namespace TUMVis {
float nearPlaneDistToOrigin = tgt::dot(_camera.getValue().getPosition(), -_camera.getValue().getLook()) - _camera.getValue().getNearDist() - .001f;
MeshGeometry clipped = proxyGeometry->clipAgainstPlane(nearPlaneDistToOrigin, -_camera.getValue().getLook(), true, 0.02f);
// set modelview and projection matrices
// start render setup
glPushAttrib(GL_ALL_ATTRIB_BITS);
_shader->activate();
// setup virtual mirror if necessary
tgt::mat4 mirrorMatrix = tgt::mat4::identity;
if (_enableMirror.getValue()) {
DataContainer::ScopedTypedData<FaceGeometry> mirrorGeometry(data, _mirrorID.getValue());
......@@ -131,11 +131,8 @@ namespace TUMVis {
LERROR("No suitable virtual mirror geometry found.");
}
}
_shader->setUniform("_modelMatrix", mirrorMatrix);
_shader->setUniform("_projectionMatrix", _camera.getValue().getProjectionMatrix());
_shader->setUniform("_viewMatrix", _camera.getValue().getViewMatrix());
// setup masking if necessary
tgt::TextureUnit maskUnit;
if (_applyMask.getValue()) {
_shader->setUniform("_viewportSizeRCP", 1.f / tgt::vec2(_renderTargetSize.getValue()));
......@@ -146,6 +143,11 @@ namespace TUMVis {
mask->bind(_shader, &maskUnit, 0, "_maskImage");
}
}
_shader->setUniform("_modelMatrix", mirrorMatrix);
_shader->setUniform("_projectionMatrix", _camera.getValue().getProjectionMatrix());
_shader->setUniform("_viewMatrix", _camera.getValue().getViewMatrix());
glEnable(GL_CULL_FACE);
// create entry points texture
......@@ -178,6 +180,8 @@ namespace TUMVis {
data.addData(_entryImageID.getValue(), entrypoints);
data.addData(_exitImageID.getValue(), exitpoints);
_entryImageID.issueWrite();
_exitImageID.issueWrite();
}
else {
LERROR("Input image must have dimensionality of 3.");
......
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