Notice: If you are member of any public project or group, please make sure that your GitLab username is not the same as the LRZ identifier/Kennung (see https://gitlab.lrz.de/profile/account). Please change your username if necessary. For more information see the section "Public projects / Öffentliche Projekte" at https://doku.lrz.de/display/PUBLIC/GitLab . Thank you!

...
 
Commits (83)
# EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
root = true
# Windows-style newlines with a newline ending every file
[*]
end_of_line = crlf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4
# Files generated by CMake # Files generated by CMake
CMakeCache.txt CMakeCache.txt
CMakeLists.txt.user
CMakeFiles CMakeFiles
cmake_install.cmake cmake_install.cmake
Makefile Makefile
/core/gen_converterregistration.h /core/gen_converterregistration.h
/modules/gen_pipelineregistration.h /modules/gen_pipelineregistration.h
FailedShader.vert
FailedShader.geom
FailedShader.frag
FailedShader.comp
# Files generated by Qt's moc and uic # Files generated by Qt's moc and uic
moc_*.cxx moc_*.cxx
...@@ -48,3 +53,12 @@ ext/tbb ...@@ -48,3 +53,12 @@ ext/tbb
# SWIG wrapper code # SWIG wrapper code
*LUA_wrap.cxx *LUA_wrap.cxx
# CMake build folders and IDE folders
build*/
.vs/
.vscode/
# Mac specific
.DS_Store
# = CAMPVis - Yet another medical visualization framework ===================== # = CAMPVis - Yet another medical visualization framework =====================
CMAKE_MINIMUM_REQUIRED(VERSION 3.0.2 FATAL_ERROR)
cmake_policy(SET CMP0020 NEW)
PROJECT(CAMPVis) PROJECT(CAMPVis)
CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0 FATAL_ERROR)
SET(CAMPVIS_VERSION 1.0.0) SET(CAMPVIS_VERSION 1.0.0)
# = Global Build Options ====================================================== # = Global Build Options ======================================================
OPTION(BUILD_SHARED_LIBS "Build shared libraries (strongly recommended!)" ON) OPTION(BUILD_SHARED_LIBS "Build shared libraries (strongly recommended!)" ON)
OPTION(CAMPVIS_DEBUG "Activate debug code?" ON) OPTION(CAMPVIS_DEBUG "Activate debug code?" ON)
OPTION(CAMPVIS_BUILD_LIB_CGT "Build CGT Library" ON)
OPTION(CAMPVIS_BUILD_APPLICATION "Build CAMPVis Application" ON) OPTION(CAMPVIS_BUILD_APPLICATION "Build CAMPVis Application" ON)
OPTION(CAMPVIS_BUILD_MODULES "Build CAMPVis Modules" ON) OPTION(CAMPVIS_BUILD_MODULES "Build CAMPVis Modules" ON)
OPTION(CAMPVIS_ENABLE_SCRIPTING "Add support for scripting CAMPVis using Lua" OFF) OPTION(CAMPVIS_ENABLE_SCRIPTING "Add support for scripting CAMPVis using Lua" OFF)
...@@ -27,6 +30,10 @@ ENDIF() ...@@ -27,6 +30,10 @@ ENDIF()
SET(CAMPVIS_DEFAULT_ENABLED_MODULES "STABLE_NO_DEPENDENCIES" CACHE STRING "Default CAMPVis modules to activate") SET(CAMPVIS_DEFAULT_ENABLED_MODULES "STABLE_NO_DEPENDENCIES" CACHE STRING "Default CAMPVis modules to activate")
SET_PROPERTY(CACHE CAMPVIS_DEFAULT_ENABLED_MODULES PROPERTY STRINGS "NONE" "STABLE_NO_DEPENDENCIES" "STABLE_WITH_EXTERNAL_DEPENDENCIES" "TESTING" "ALL") SET_PROPERTY(CACHE CAMPVIS_DEFAULT_ENABLED_MODULES PROPERTY STRINGS "NONE" "STABLE_NO_DEPENDENCIES" "STABLE_WITH_EXTERNAL_DEPENDENCIES" "TESTING" "ALL")
IF(NOT BUILD_SHARED_LIBS)
MESSAGE(WARNING "Building shared libraries is turned off. Thus, CAMPVis will most probably not work as intended!\nPlease turn BUILD_SHARED_LIBS on unless you know what you're doing!")
ENDIF(NOT BUILD_SHARED_LIBS)
# propagate CAMPVIS_ENABLE_SCRIPTING to CAMPVIS_BUILD_LIB_LUA to support deprecated code # propagate CAMPVIS_ENABLE_SCRIPTING to CAMPVIS_BUILD_LIB_LUA to support deprecated code
IF (CAMPVIS_ENABLE_SCRIPTING) IF (CAMPVIS_ENABLE_SCRIPTING)
SET(CAMPVIS_BUILD_LIB_LUA ON) SET(CAMPVIS_BUILD_LIB_LUA ON)
...@@ -68,7 +75,7 @@ ENDIF() ...@@ -68,7 +75,7 @@ ENDIF()
# build campvis-test when enabled # build campvis-test when enabled
IF(CAMPVIS_ENABLE_TESTING) IF(CAMPVIS_ENABLE_TESTING)
ADD_SUBDIRECTORY(ext/gtest-1.7.0) ADD_SUBDIRECTORY(ext/googletest-release-1.8.0)
ADD_SUBDIRECTORY(test) ADD_SUBDIRECTORY(test)
ENDIF() ENDIF()
...@@ -105,15 +112,9 @@ EXPORT(PACKAGE CAMPVis) ...@@ -105,15 +112,9 @@ EXPORT(PACKAGE CAMPVis)
# = Copy Windows DLLs to binary dir for improved development experience ======= # = Copy Windows DLLs to binary dir for improved development experience =======
IF(WIN32) IF(WIN32)
# gather Qt4 DLLs - TODO: remove redundant naming of required components
FIND_PACKAGE(Qt4DLLs COMPONENTS QtCore QtGui QtOpenGL QtNetwork QtXmlPatterns)
LIST(APPEND CampvisExternalDllsDebug ${QT_DEBUG_DLLS})
LIST(APPEND CampvisExternalDllsRelease ${QT_RELEASE_DLLS})
LIST(REMOVE_DUPLICATES CampvisExternalDllsDebug)
LIST(REMOVE_DUPLICATES CampvisExternalDllsRelease)
IF(CAMPVIS_COPY_EXTERNAL_DLLS) IF(CAMPVIS_COPY_EXTERNAL_DLLS)
LIST(REMOVE_DUPLICATES CampvisExternalDllsDebug)
LIST(REMOVE_DUPLICATES CampvisExternalDllsRelease)
COPY_EXTERNAL_DLLS(CampvisExternalDllsDebug CampvisExternalDllsRelease false) COPY_EXTERNAL_DLLS(CampvisExternalDllsDebug CampvisExternalDllsRelease false)
ENDIF() ENDIF()
ENDIF() ENDIF()
......
PROJECT(campvis-application) PROJECT(campvis-application)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0 FATAL_ERROR)
INCLUDE(../cmake/commonconf.cmake) INCLUDE(../cmake/commonconf.cmake)
MESSAGE(STATUS "Configuring CAMPVis-Application") MESSAGE(STATUS "Configuring CAMPVis-Application")
...@@ -106,13 +105,7 @@ FOREACH(ModFile ${CampvisModulesApplicationToBeMocced}) ...@@ -106,13 +105,7 @@ FOREACH(ModFile ${CampvisModulesApplicationToBeMocced})
LIST(APPEND CampvisApplicationToBeMocced ${ModFileRelative}) LIST(APPEND CampvisApplicationToBeMocced ${ModFileRelative})
ENDFOREACH() ENDFOREACH()
# QT5_WRAP_UI(CampvisApplicationFormsHeaders ${CampvisApplicationForms})
# Qt related stuff:
#
QT4_WRAP_CPP(CampvisApplicationMoc ${CampvisApplicationToBeMocced})
LIST(APPEND CampvisApplicationSources ${CampvisApplicationMoc})
QT4_WRAP_UI(CampvisApplicationFormsHeaders ${CampvisApplicationForms})
LIST(APPEND CampvisApplicationSources ${CampvisApplicationFormsHeaders}) LIST(APPEND CampvisApplicationSources ${CampvisApplicationFormsHeaders})
LINK_DIRECTORIES(${CampvisGlobalLinkDirectories} ${CampvisModulesLinkDirectories}) LINK_DIRECTORIES(${CampvisGlobalLinkDirectories} ${CampvisModulesLinkDirectories})
...@@ -127,14 +120,15 @@ ADD_LIBRARY(campvis-application-lib ...@@ -127,14 +120,15 @@ ADD_LIBRARY(campvis-application-lib
${CampvisApplicationSources} ${CampvisApplicationHeaders} ${CampvisApplicationSources} ${CampvisApplicationHeaders}
${CampvisApplicationMoc} ${CampvisApplicationMoc}
) )
ADD_DEFINITIONS(${CampvisGlobalDefinitions} ${CampvisModulesDefinitions} ${CampvisApplicationDefinitions} ${QT_DEFINITIONS}) ADD_DEFINITIONS(${CampvisGlobalDefinitions} ${CampvisModulesDefinitions} ${CampvisApplicationDefinitions})
INCLUDE_DIRECTORIES(${CampvisGlobalIncludeDirs} ${CampvisModulesIncludeDirs}) INCLUDE_DIRECTORIES(${CampvisGlobalIncludeDirs} ${CampvisModulesIncludeDirs})
TARGET_LINK_LIBRARIES(campvis-application-lib ${CampvisMainLibs} ${CampvisGlobalExternalLibs} ${CampvisModulesExternalLibs} ${QT_LIBRARIES}) TARGET_LINK_LIBRARIES(campvis-application-lib ${CampvisMainLibs} ${CampvisGlobalExternalLibs} ${CampvisModulesExternalLibs} Qt5::Widgets Qt5::OpenGL)
# if campvis-core is built as a shared library, CMake will define the following flag to instruct # if campvis-core is built as a shared library, CMake will define the following flag to instruct
# the code to export DLL symbols # the code to export DLL symbols
SET_TARGET_PROPERTIES(campvis-application-lib PROPERTIES DEFINE_SYMBOL "CAMPVIS_APPLICATION_BUILD_DLL") SET_TARGET_PROPERTIES(campvis-application-lib PROPERTIES DEFINE_SYMBOL "CAMPVIS_APPLICATION_BUILD_DLL")
IF(CAMPVIS_GROUP_SOURCE_FILES) IF(CAMPVIS_GROUP_SOURCE_FILES)
DEFINE_SOURCE_GROUPS_FROM_SUBDIR(CampvisApplicationSources ${CampvisHome} "") DEFINE_SOURCE_GROUPS_FROM_SUBDIR(CampvisApplicationSources ${CampvisHome} "")
DEFINE_SOURCE_GROUPS_FROM_SUBDIR(CampvisApplicationHeaders ${CampvisHome} "") DEFINE_SOURCE_GROUPS_FROM_SUBDIR(CampvisApplicationHeaders ${CampvisHome} "")
...@@ -144,9 +138,7 @@ INSTALL(TARGETS campvis-application-lib DESTINATION exports EXPORT campvis-targe ...@@ -144,9 +138,7 @@ INSTALL(TARGETS campvis-application-lib DESTINATION exports EXPORT campvis-targe
ADD_EXECUTABLE(campvis-application "campvis.cpp") ADD_EXECUTABLE(campvis-application "campvis.cpp")
TARGET_LINK_LIBRARIES(campvis-application campvis-application-lib ${CampvisMainLibs} ${CampvisGlobalExternalLibs} ${CampvisModulesExternalLibs} ${QT_LIBRARIES}) TARGET_LINK_LIBRARIES(campvis-application campvis-application-lib ${CampvisMainLibs} ${CampvisGlobalExternalLibs} ${CampvisModulesExternalLibs} Qt5::Widgets Qt5::OpenGL)
IF(CAMPVIS_DEPLOY_SHADERS) IF(CAMPVIS_DEPLOY_SHADERS)
LIST(APPEND CampvisShaderDirectories "application/data") LIST(APPEND CampvisShaderDirectories "application/data")
......
...@@ -46,12 +46,15 @@ ...@@ -46,12 +46,15 @@
#include "core/pipeline/abstractworkflow.h" #include "core/pipeline/abstractworkflow.h"
#include "core/pipeline/pipelinefactory.h" #include "core/pipeline/pipelinefactory.h"
#include "core/pipeline/pipelinepainter.h" #include "core/pipeline/pipelinepainter.h"
#include "core/pipeline/visualizationprocessor.h"
#include "core/datastructures/imagerepresentationconverter.h" #include "core/datastructures/imagerepresentationconverter.h"
#include "core/pipeline/visualizationprocessor.h" #include "core/pipeline/visualizationprocessor.h"
#include "tools/qtjobprocessor.h" #include "tools/qtjobprocessor.h"
#include <QApplication> #include <QApplication>
#include <QThread>
#include <QStyleFactory>
#ifdef CAMPVIS_HAS_SCRIPTING #ifdef CAMPVIS_HAS_SCRIPTING
#include "scripting/glue/luavmstate.h" #include "scripting/glue/luavmstate.h"
...@@ -93,12 +96,11 @@ namespace campvis { ...@@ -93,12 +96,11 @@ namespace campvis {
#endif #endif
} }
_localContext = new QtThreadedCanvas("", cgt::ivec2(16, 16)); _localContext = new cgt::QtThreadedCanvas("", cgt::ivec2(16, 16));
campvis::init(_localContext, searchPaths); campvis::init(_localContext, searchPaths);
_mainWindow = new MainWindow(this); _mainWindow = new MainWindow(this);
cgt::GLContextScopedLock lock(_localContext); GLJobProc.enqueueJobBlocking([&]() {
{
_mainWindow->init(); _mainWindow->init();
// load textureData from file // load textureData from file
...@@ -133,7 +135,7 @@ namespace campvis { ...@@ -133,7 +135,7 @@ namespace campvis {
if (! _luaVmState->injectGlobalObjectPointer(this, "campvis::CampVisApplication *", "application")) if (! _luaVmState->injectGlobalObjectPointer(this, "campvis::CampVisApplication *", "application"))
LERROR("Could not inject the pipeline into the Lua VM."); LERROR("Could not inject the pipeline into the Lua VM.");
#endif #endif
} });
// parse argument list and create pipelines // parse argument list and create pipelines
QStringList pipelinesToAdd = this->arguments(); QStringList pipelinesToAdd = this->arguments();
...@@ -171,6 +173,27 @@ namespace campvis { ...@@ -171,6 +173,27 @@ namespace campvis {
} }
} }
// Set Qt color palette to dark - adapted from https://gist.github.com/QuantumCD/6245215
QApplication::setStyle(QStyleFactory::create("Fusion"));
QPalette darkPalette;
darkPalette.setColor(QPalette::Window, QColor(53, 53, 53));
darkPalette.setColor(QPalette::WindowText, Qt::white);
darkPalette.setColor(QPalette::Base, QColor(25, 25, 25));
darkPalette.setColor(QPalette::AlternateBase, QColor(53, 53, 53));
darkPalette.setColor(QPalette::ToolTipBase, Qt::white);
darkPalette.setColor(QPalette::ToolTipText, Qt::white);
darkPalette.setColor(QPalette::Text, Qt::white);
darkPalette.setColor(QPalette::Button, QColor(53, 53, 53));
darkPalette.setColor(QPalette::ButtonText, Qt::white);
darkPalette.setColor(QPalette::BrightText, Qt::red);
darkPalette.setColor(QPalette::Link, QColor(42, 130, 218));
darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218));
darkPalette.setColor(QPalette::HighlightedText, Qt::black);
setPalette(darkPalette);
setStyleSheet("QMainWindow * {font: 12pt;} QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }");
_initialized = true; _initialized = true;
} }
...@@ -185,10 +208,7 @@ namespace campvis { ...@@ -185,10 +208,7 @@ namespace campvis {
for (auto it = _workflows.begin(); it != _workflows.end(); ++it) for (auto it = _workflows.begin(); it != _workflows.end(); ++it)
(*it)->deinit(); (*it)->deinit();
{ GLJobProc.enqueueJobBlocking([&]() {
// Deinit everything OpenGL related using the local context.
cgt::GLContextScopedLock lock(_localContext);
delete _errorTexture; delete _errorTexture;
// Deinit pipeline and painter first // Deinit pipeline and painter first
...@@ -197,7 +217,9 @@ namespace campvis { ...@@ -197,7 +217,9 @@ namespace campvis {
} }
_mainWindow->deinit(); _mainWindow->deinit();
} });
delete _mainWindow;
// now delete everything in the right order: // now delete everything in the right order:
for (auto it = _pipelines.begin(); it != _pipelines.end(); ++it) { for (auto it = _pipelines.begin(); it != _pipelines.end(); ++it) {
...@@ -254,8 +276,10 @@ namespace campvis { ...@@ -254,8 +276,10 @@ namespace campvis {
#endif #endif
GLCtxtMgr.releaseContext(canvas, false); GLCtxtMgr.releaseContext(canvas, false);
s_PipelinesChanged.emitSignal(); s_PipelinesChanged.emitSignal();
pipeline->start();
startOpenGlThreadAndMoveQtThreadAffinity(pipeline, canvas);
} }
void CampVisApplication::initGlContextAndPipeline(cgt::GLCanvas* canvas, AbstractPipeline* pipeline) { void CampVisApplication::initGlContextAndPipeline(cgt::GLCanvas* canvas, AbstractPipeline* pipeline) {
...@@ -286,7 +310,7 @@ namespace campvis { ...@@ -286,7 +310,7 @@ namespace campvis {
void CampVisApplication::rebuildAllShadersFromFiles() { void CampVisApplication::rebuildAllShadersFromFiles() {
// rebuilding all shaders has to be done from OpenGL context, use the local one. // rebuilding all shaders has to be done from OpenGL context, use the local one.
GLJobProc.enqueueJob(makeJobOnHeap(this, &CampVisApplication::triggerShaderRebuild)); GLJobProc.enqueueJob(cgt::makeJobOnHeap(this, &CampVisApplication::triggerShaderRebuild));
} }
void CampVisApplication::triggerShaderRebuild() { void CampVisApplication::triggerShaderRebuild() {
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
namespace cgt { namespace cgt {
class GLCanvas; class GLCanvas;
class QtCanvas;
class QtThreadedCanvas; class QtThreadedCanvas;
class Texture; class Texture;
} }
...@@ -170,7 +171,7 @@ namespace campvis { ...@@ -170,7 +171,7 @@ namespace campvis {
void triggerShaderRebuild(); void triggerShaderRebuild();
/// A local OpenGL context used for initialization /// A local OpenGL context used for initialization
cgt::GLCanvas* _localContext; cgt::QtCanvas* _localContext;
/// Main window hosting GUI stuff /// Main window hosting GUI stuff
MainWindow* _mainWindow; MainWindow* _mainWindow;
......
...@@ -101,12 +101,17 @@ void main() { ...@@ -101,12 +101,17 @@ void main() {
if (! _renderRChannel) if (! _renderRChannel)
out_Color.r = 0.0; out_Color.r = 0.0;
if (! _renderGChannel) if (! _renderGChannel)
out_Color.g = 0.0; out_Color.g = 0.0;
if (! _renderBChannel) if (! _renderBChannel)
out_Color.b = 0.0; out_Color.b = 0.0;
if (! _renderAChannel) if (! _renderAChannel)
out_Color.a = 1.0; out_Color.a = 1.0;
else if(! _renderRChannel && ! _renderGChannel && ! _renderBChannel)
out_Color = vec4(vec3((abs(out_Color.a) - vec3(_transferFunctionParams._intensityDomain.x)) / (_transferFunctionParams._intensityDomain.y - _transferFunctionParams._intensityDomain.x)), 1);
// mix with fancy checkerboard pattern: // mix with fancy checkerboard pattern:
if ((mod(ex_TexCoord.x * 10.0, 2.0) > 1.0) ^^ (mod(ex_TexCoord.y * 10.0, 2.0) > 1.0)) if ((mod(ex_TexCoord.x * 10.0, 2.0) > 1.0) ^^ (mod(ex_TexCoord.y * 10.0, 2.0) > 1.0))
......
...@@ -45,6 +45,9 @@ namespace campvis { ...@@ -45,6 +45,9 @@ namespace campvis {
} }
DataContainerFileLoaderWidget::~DataContainerFileLoaderWidget() { DataContainerFileLoaderWidget::~DataContainerFileLoaderWidget() {
delete _imgReader;
_imgReader = nullptr;
if (_dataContainer != 0) { if (_dataContainer != 0) {
_dataContainer->s_dataAdded.disconnect(this); _dataContainer->s_dataAdded.disconnect(this);
} }
...@@ -97,14 +100,6 @@ namespace campvis { ...@@ -97,14 +100,6 @@ namespace campvis {
return false; return false;
} }
void DataContainerFileLoaderWidget::init() {
}
void DataContainerFileLoaderWidget::deinit() {
delete _imgReader;
_imgReader = nullptr;
}
void DataContainerFileLoaderWidget::onBtnCancelClicked() { void DataContainerFileLoaderWidget::onBtnCancelClicked() {
delete _imgReader; delete _imgReader;
_imgReader = nullptr; _imgReader = nullptr;
......
...@@ -66,18 +66,7 @@ namespace campvis { ...@@ -66,18 +66,7 @@ namespace campvis {
* \return QSize(300, 350) * \return QSize(300, 350)
*/ */
QSize sizeHint() const; QSize sizeHint() const;
/**
* Initializes the OpenGL stuff (e.g. shaders).
* Must be called with a valid and locked OpenGL context.
*/
virtual void init();
/**
* Deinitializes the OpenGL stuff (e.g. shaders).
* Must be called with a valid and locked OpenGL context.
*/
void deinit();
private slots: private slots:
/** /**
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "ext/cgt/navigation/trackball.h" #include "ext/cgt/navigation/trackball.h"
#include <QWindow>
namespace campvis { namespace campvis {
...@@ -70,7 +71,6 @@ namespace campvis { ...@@ -70,7 +71,6 @@ namespace campvis {
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))); 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)));
GLCtxtMgr.registerContextAndInitGlew(this, "DataContainerInspector"); GLCtxtMgr.registerContextAndInitGlew(this, "DataContainerInspector");
GLCtxtMgr.releaseContext(this, false);
addProperty(p_currentSlice); addProperty(p_currentSlice);
addProperty(p_transferFunction); addProperty(p_transferFunction);
...@@ -103,10 +103,13 @@ namespace campvis { ...@@ -103,10 +103,13 @@ namespace campvis {
p_renderGChannel.setVisible(false); p_renderGChannel.setVisible(false);
p_renderBChannel.setVisible(false); p_renderBChannel.setVisible(false);
p_renderAChannel.setVisible(false); p_renderAChannel.setVisible(false);
connect(this, &DataContainerInspectorCanvas::s_invalidated, this, &DataContainerInspectorCanvas::onInvalidated);
init();
} }
DataContainerInspectorCanvas::~DataContainerInspectorCanvas() { DataContainerInspectorCanvas::~DataContainerInspectorCanvas() {
} }
void DataContainerInspectorCanvas::init() { void DataContainerInspectorCanvas::init() {
...@@ -120,6 +123,7 @@ namespace campvis { ...@@ -120,6 +123,7 @@ namespace campvis {
getEventHandler()->addEventListenerToFront(this); getEventHandler()->addEventListenerToFront(this);
_geometryRenderer.init(); _geometryRenderer.init();
_tcp.init();
} }
void DataContainerInspectorCanvas::deinit() { void DataContainerInspectorCanvas::deinit() {
...@@ -130,6 +134,7 @@ namespace campvis { ...@@ -130,6 +134,7 @@ namespace campvis {
} }
_geometryRenderer.deinit(); _geometryRenderer.deinit();
_tcp.deinit();
_handles.clear(); _handles.clear();
_localDataContainer.clear(); _localDataContainer.clear();
...@@ -157,16 +162,17 @@ namespace campvis { ...@@ -157,16 +162,17 @@ namespace campvis {
_geometriesDirty = false; _geometriesDirty = false;
} }
if (_textures.empty()) {
return;
}
glPushAttrib(GL_ALL_ATTRIB_BITS); glPushAttrib(GL_ALL_ATTRIB_BITS);
glViewport(0, 0, size_.x, size_.y); glViewport(0, 0, size_.x, size_.y);
glClearColor(0.7f, 0.7f, 0.7f, 1.f); glClearColor(0.7f, 0.7f, 0.7f, 1.f);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
LGL_ERROR; LGL_ERROR;
if (_textures.empty()) {
glPopAttrib();
return;
}
// update layout dimensions // update layout dimensions
_numTiles.x = ceil(sqrt(static_cast<float>(_textures.size()))); _numTiles.x = ceil(sqrt(static_cast<float>(_textures.size())));
_numTiles.y = ceil(static_cast<float>(_textures.size()) / _numTiles.x); _numTiles.y = ceil(static_cast<float>(_textures.size()) / _numTiles.x);
...@@ -194,8 +200,8 @@ namespace campvis { ...@@ -194,8 +200,8 @@ namespace campvis {
break; break;
// gather image // gather image
cgtAssert(dynamic_cast<const ImageData*>(_textures[index].getData()), "Found sth. else than ImageData in render texture vector. This should not happen!"); cgtAssert(_textures[index].getData<ImageData>(), "Found sth. else than ImageData in render texture vector. This should not happen!");
const ImageData* id = static_cast<const ImageData*>(_textures[index].getData()); auto id = _textures[index].getData<ImageData>();
// compute transformation matrices // compute transformation matrices
float renderTargetRatio = static_cast<float>(_quadSize.x) / static_cast<float>(_quadSize.y); float renderTargetRatio = static_cast<float>(_quadSize.x) / static_cast<float>(_quadSize.y);
...@@ -249,16 +255,26 @@ namespace campvis { ...@@ -249,16 +255,26 @@ namespace campvis {
LGL_ERROR; LGL_ERROR;
} }
void DataContainerInspectorCanvas::invalidate() { void DataContainerInspectorCanvas::onInvalidated() {
// Prevent drawing when the window is not yet exposed to the window manager
QWindow* wnd = dynamic_cast<QWindow*>(window()->windowHandle());
if (!wnd || !wnd->isExposed()) return;
// only if inited // only if inited
if (_quad != 0 && _paintShader != 0) { if (_quad != 0 && _paintShader != 0 && this->isVisible()) {
this->makeCurrent();
paint();
this->swap();
// avoid recursive paints. // avoid recursive paints.
if (! cgt::GlContextManager::getRef().checkWhetherThisThreadHasAcquiredOpenGlContext()) { // if (! cgt::GlContextManager::getRef().checkWhetherThisThreadHasAcquiredOpenGlContext()) {
SimpleJobProc.enqueueJob([this] () { // SimpleJobProc.enqueueJob(
cgt::GLContextScopedLock lock(this); // [this] () {
paint(); // cgt::GLContextScopedLock lock(this);
}); // paint();
} // });
// }
} }
} }
...@@ -267,11 +283,11 @@ namespace campvis { ...@@ -267,11 +283,11 @@ namespace campvis {
} }
void DataContainerInspectorCanvas::repaint() { void DataContainerInspectorCanvas::repaint() {
invalidate(); emit s_invalidated();
} }
void DataContainerInspectorCanvas::sizeChanged(const cgt::ivec2& size) { void DataContainerInspectorCanvas::sizeChanged(const cgt::ivec2& size) {
invalidate(); emit s_invalidated();
} }
void DataContainerInspectorCanvas::mouseMoveEvent(cgt::MouseEvent* e) void DataContainerInspectorCanvas::mouseMoveEvent(cgt::MouseEvent* e)
...@@ -281,7 +297,7 @@ namespace campvis { ...@@ -281,7 +297,7 @@ namespace campvis {
if (texIndx < 0 || texIndx >= static_cast<int>(_textures.size())) if (texIndx < 0 || texIndx >= static_cast<int>(_textures.size()))
return; return;
const ImageData* id = static_cast<const ImageData*>(_textures[texIndx].getData()); auto id = _textures[texIndx].getData<ImageData>();
const cgt::Texture* tex = id->getRepresentation<ImageRepresentationGL>()->getTexture(); const cgt::Texture* tex = id->getRepresentation<ImageRepresentationGL>()->getTexture();
const ImageRepresentationLocal* localRep = id->getRepresentation<ImageRepresentationLocal>(); const ImageRepresentationLocal* localRep = id->getRepresentation<ImageRepresentationLocal>();
cgt::svec2 imageSize = id->getSize().xy(); cgt::svec2 imageSize = id->getSize().xy();
...@@ -297,7 +313,7 @@ namespace campvis { ...@@ -297,7 +313,7 @@ namespace campvis {
lookupTexelFloat /= (ratioRatio > 1) ? cgt::vec2(1.f, 1.f / ratioRatio) : cgt::vec2(ratioRatio, 1.f); lookupTexelFloat /= (ratioRatio > 1) ? cgt::vec2(1.f, 1.f / ratioRatio) : cgt::vec2(ratioRatio, 1.f);
cgt::svec3 lookupTexel(lookupTexelFloat.x, imageSize.y - lookupTexelFloat.y, 0); cgt::svec3 lookupTexel(lookupTexelFloat.x, imageSize.y - lookupTexelFloat.y, 0);
if (lookupTexel.x >= 0 && lookupTexel.y >= 0 && lookupTexel.x < imageSize.x && lookupTexel.y < imageSize.y) { if (lookupTexel.x < imageSize.x && lookupTexel.y < imageSize.y) {
if (tex->isDepthTexture()) { if (tex->isDepthTexture()) {
emit s_depthChanged(lookupTexel, localRep->getElementNormalized(lookupTexel, 0)); emit s_depthChanged(lookupTexel, localRep->getElementNormalized(lookupTexel, 0));
} }
...@@ -335,7 +351,7 @@ namespace campvis { ...@@ -335,7 +351,7 @@ namespace campvis {
_tcp.process(_localDataContainer); _tcp.process(_localDataContainer);
e->accept(); e->accept();
_geometriesDirty = true; _geometriesDirty = true;
invalidate(); emit s_invalidated();
} }
} }
...@@ -357,7 +373,7 @@ namespace campvis { ...@@ -357,7 +373,7 @@ namespace campvis {
} }
if (_texturesDirty) if (_texturesDirty)
invalidate(); emit s_invalidated();
} }
void DataContainerInspectorCanvas::setDataHandles(const std::vector< std::pair<QString, QtDataHandle> >& handles) { void DataContainerInspectorCanvas::setDataHandles(const std::vector< std::pair<QString, QtDataHandle> >& handles) {
...@@ -384,7 +400,7 @@ namespace campvis { ...@@ -384,7 +400,7 @@ namespace campvis {
_texturesDirty = true; _texturesDirty = true;
} }
invalidate(); emit s_invalidated();
} }
void DataContainerInspectorCanvas::updateTextures() { void DataContainerInspectorCanvas::updateTextures() {
...@@ -394,13 +410,13 @@ namespace campvis { ...@@ -394,13 +410,13 @@ namespace campvis {
p_viewportSize.setValue(cgt::ivec2(width(), height())); p_viewportSize.setValue(cgt::ivec2(width(), height()));
for (std::map<QString, QtDataHandle>::iterator it = _handles.begin(); it != _handles.end(); ++it) { for (std::map<QString, QtDataHandle>::iterator it = _handles.begin(); it != _handles.end(); ++it) {
if (const ImageData* img = dynamic_cast<const ImageData*>(it->second.getData())) { if (auto img = it->second.getData<ImageData>()) {
if (const ImageRepresentationGL* imgGL = img->getRepresentation<ImageRepresentationGL>()) { if (const ImageRepresentationGL* imgGL = img->getRepresentation<ImageRepresentationGL>()) {
_textures.push_back(it->second); _textures.push_back(it->second);
maxSlices = std::max(maxSlices, imgGL->getTexture()->getDimensions().z); maxSlices = std::max(maxSlices, imgGL->getTexture()->getDimensions().z);
} }
} }
else if (const RenderData* rd = dynamic_cast<const RenderData*>(it->second.getData())) { else if (auto rd = it->second.getData<RenderData>()) {
for (size_t i = 0; i < rd->getNumColorTextures(); ++i) { for (size_t i = 0; i < rd->getNumColorTextures(); ++i) {
const ImageRepresentationGL* imgGL = rd->getColorTexture(i)->getRepresentation<ImageRepresentationGL>(); const ImageRepresentationGL* imgGL = rd->getColorTexture(i)->getRepresentation<ImageRepresentationGL>();
if (imgGL) { if (imgGL) {
...@@ -415,7 +431,7 @@ namespace campvis { ...@@ -415,7 +431,7 @@ namespace campvis {
} }
} }
else if (const GeometryData* gd = dynamic_cast<const GeometryData*>(it->second.getData())) { else if (auto gd = it->second.getData<GeometryData>()) {
std::string name = it->first.toStdString(); std::string name = it->first.toStdString();
// copy geometry over to local // copy geometry over to local
...@@ -440,12 +456,12 @@ namespace campvis { ...@@ -440,12 +456,12 @@ namespace campvis {
void DataContainerInspectorCanvas::onPropertyChanged(const AbstractProperty* prop) { void DataContainerInspectorCanvas::onPropertyChanged(const AbstractProperty* prop) {
// ignore properties of the geometry renderer // ignore properties of the geometry renderer
if (prop != &p_geometryRendererProperties) if (prop != &p_geometryRendererProperties)
invalidate(); emit s_invalidated();
} }
void DataContainerInspectorCanvas::onGeometryRendererPropertyChanged(const AbstractProperty* prop) { void DataContainerInspectorCanvas::onGeometryRendererPropertyChanged(const AbstractProperty* prop) {
_geometriesDirty = true; _geometriesDirty = true;
invalidate(); emit s_invalidated();
} }
void DataContainerInspectorCanvas::renderGeometryIntoTexture(const std::string& name, int textureIndex) { void DataContainerInspectorCanvas::renderGeometryIntoTexture(const std::string& name, int textureIndex) {
...@@ -481,7 +497,7 @@ namespace campvis { ...@@ -481,7 +497,7 @@ namespace campvis {
// check whether we have to render geometries // check whether we have to render geometries
cgt::Bounds unionBounds; cgt::Bounds unionBounds;
for (std::map<QString, QtDataHandle>::iterator it = _handles.begin(); it != _handles.end(); ++it) { for (std::map<QString, QtDataHandle>::iterator it = _handles.begin(); it != _handles.end(); ++it) {
if (const GeometryData* gd = dynamic_cast<const GeometryData*>(it->second.getData())) { if (auto gd = it->second.getData<GeometryData>()) {
unionBounds.addVolume(gd->getWorldBounds()); unionBounds.addVolume(gd->getWorldBounds());
} }
} }
......
...@@ -131,6 +131,7 @@ namespace campvis { ...@@ -131,6 +131,7 @@ namespace campvis {
signals: signals:
void s_colorChanged(const cgt::svec3& texel, const cgt::vec4&); void s_colorChanged(const cgt::svec3& texel, const cgt::vec4&);
void s_depthChanged(const cgt::svec3& texel, float depth); void s_depthChanged(const cgt::svec3& texel, float depth);
void s_invalidated(); ///< signals an invalidation event
private slots: private slots:
/** /**
...@@ -140,20 +141,17 @@ namespace campvis { ...@@ -140,20 +141,17 @@ namespace campvis {
*/ */
void onDataContainerChanged(const QString& key, QtDataHandle dh); void onDataContainerChanged(const QString& key, QtDataHandle dh);
/**
* To be called when the canvas is invalidated, issues new paint job.
*/
void onInvalidated();
protected: protected:
/** /**
* Performs the painting. * Performs the painting.
*/ */
virtual void paint(); virtual void paint();
/**
* Gets called when the data collection of this pipeline has changed and thus has notified its observers.
* If \a name equals the name of the renderTarget, the s_renderTargetChanged signal will be emitted.
* \param name Name of the added data.
* \param dh DataHandle to the newly added data.
*/
void onDataContainerDataAdded(const std::string& name, DataHandle dh);
/** /**
* Slot getting called when one of the observed properties changed and notifies its observers. * Slot getting called when one of the observed properties changed and notifies its observers.
* \param prop Property that emitted the signal * \param prop Property that emitted the signal
...@@ -172,11 +170,6 @@ namespace campvis { ...@@ -172,11 +170,6 @@ namespace campvis {
*/ */
void resetTrackball(); void resetTrackball();
/**
* To be called when the canvas is invalidated, issues new paint job.
*/
void invalidate();
/** /**
* Renders the given 2D texture. * Renders the given 2D texture.
* Binds the texture to the shader, sets the uniforms and renders the quad. * Binds the texture to the shader, sets the uniforms and renders the quad.
......
...@@ -89,10 +89,6 @@ namespace campvis { ...@@ -89,10 +89,6 @@ namespace campvis {
} }
DataContainerInspectorWidget::~DataContainerInspectorWidget() { DataContainerInspectorWidget::~DataContainerInspectorWidget() {
if (_dataContainer != 0) {
_dataContainer->s_dataAdded.disconnect(this);
}
delete _pcWidget; delete _pcWidget;
_pcWidget = nullptr; _pcWidget = nullptr;
} }
...@@ -260,7 +256,7 @@ namespace campvis { ...@@ -260,7 +256,7 @@ namespace campvis {
QModelIndex idxName = index->sibling(index->row(), 0); QModelIndex idxName = index->sibling(index->row(), 0);
// only consider non-empty DataHandles // only consider non-empty DataHandles
if (handle.getData() != 0) { if (handle) {
handles.push_back(std::make_pair(idxName.data(Qt::DisplayRole).toString(), handle)); handles.push_back(std::make_pair(idxName.data(Qt::DisplayRole).toString(), handle));
_localFootprint += handle.getData()->getLocalMemoryFootprint(); _localFootprint += handle.getData()->getLocalMemoryFootprint();
_videoFootprint += handle.getData()->getVideoMemoryFootprint(); _videoFootprint += handle.getData()->getVideoMemoryFootprint();
...@@ -272,7 +268,7 @@ namespace campvis { ...@@ -272,7 +268,7 @@ namespace campvis {
_lblName->setText("Name: " + handles.front().first); _lblName->setText("Name: " + handles.front().first);
_lblTimestamp->setText("Timestamp: " + QString::number(handles.front().second.getTimestamp())); _lblTimestamp->setText("Timestamp: " + QString::number(handles.front().second.getTimestamp()));
if (const ImageData* tester = dynamic_cast<const ImageData*>(handles.front().second.getData())) { if (auto tester = handles.front().second.getData<ImageData>()) {
_canvas->p_transferFunction.setImageHandle(handles.front().second); _canvas->p_transferFunction.setImageHandle(handles.front().second);
_lblNumChannels->setText(tr("Number of Channels: ") + QString::number(tester->getNumChannels())); _lblNumChannels->setText(tr("Number of Channels: ") + QString::number(tester->getNumChannels()));
...@@ -294,7 +290,7 @@ namespace campvis { ...@@ -294,7 +290,7 @@ namespace campvis {
_canvas->p_renderAChannel.setVisible(true); _canvas->p_renderAChannel.setVisible(true);
_canvas->p_geometryRendererProperties.setVisible(false); _canvas->p_geometryRendererProperties.setVisible(false);
} }
else if (const GeometryData* tester = dynamic_cast<const GeometryData*>(handles.front().second.getData())) { else if (auto tester = handles.front().second.getData<GeometryData>()) {
_lblSize->setText(tr("Size: n/a")); _lblSize->setText(tr("Size: n/a"));
_lblNumChannels->setText(tr("Number of Channels: n/a")); _lblNumChannels->setText(tr("Number of Channels: n/a"));
...@@ -310,7 +306,7 @@ namespace campvis { ...@@ -310,7 +306,7 @@ namespace campvis {
_canvas->p_renderAChannel.setVisible(false); _canvas->p_renderAChannel.setVisible(false);
_canvas->p_geometryRendererProperties.setVisible(true); _canvas->p_geometryRendererProperties.setVisible(true);
} }
else if (const RenderData* tester = dynamic_cast<const RenderData*>(handles.front().second.getData())) { else if (auto tester = handles.front().second.getData<RenderData>()) {
const ImageData* id = tester->getNumColorTextures() > 0 ? tester->getColorTexture() : tester->getDepthTexture(); const ImageData* id = tester->getNumColorTextures() > 0 ? tester->getColorTexture() : tester->getDepthTexture();
if (id != 0) { if (id != 0) {
_lblNumChannels->setText(tr("Number of Channels: ") + QString::number(id->getNumChannels())); _lblNumChannels->setText(tr("Number of Channels: ") + QString::number(id->getNumChannels()));
...@@ -386,28 +382,17 @@ namespace campvis { ...@@ -386,28 +382,17 @@ namespace campvis {
} }
void DataContainerInspectorWidget::init() { void DataContainerInspectorWidget::init() {
if (_canvas != 0)
_canvas->init();
_inited = true; _inited = true;
} }
void DataContainerInspectorWidget::deinit() { void DataContainerInspectorWidget::deinit() {
_inited = false; _canvas->deinit();
if (_canvas != 0)
_canvas->deinit();
_pcWidget->updatePropCollection(0, 0);
if (_dataContainer != 0) { if (_dataContainer != 0) {
_dataContainer->s_dataAdded.disconnect(this); _dataContainer->s_dataAdded.disconnect(this);
} }
_dataContainer = 0; _inited = false;
_dctWidget->update(0);
if(_propEditorWid != nullptr)
_propEditorWid->deinit();
} }
void DataContainerInspectorWidget::onDCTWidgetSelectionModelSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected) { void DataContainerInspectorWidget::onDCTWidgetSelectionModelSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected) {
...@@ -445,7 +430,7 @@ namespace campvis { ...@@ -445,7 +430,7 @@ namespace campvis {
// only consider non-empty DataHandles that are ImageData and have render target representations // only consider non-empty DataHandles that are ImageData and have render target representations
if (handle.getData() != 0) { if (handle.getData() != 0) {
if (dynamic_cast<const ImageData*>(handle.getData()) && dynamic_cast<const ImageData*>(handle.getData())->getDimensionality() == 3) { if (handle.getData<ImageData>() && handle.getData<ImageData>()->getDimensionality() == 3) {
QString dialogCaption = "Export " + name + " as MHD Image"; QString dialogCaption = "Export " + name + " as MHD Image";
QString directory = tr(""); QString directory = tr("");
const QString fileFilter = tr("*.mhd;;MHD images (*.mhd)"); const QString fileFilter = tr("*.mhd;;MHD images (*.mhd)");
...@@ -453,15 +438,17 @@ namespace campvis { ...@@ -453,15 +438,17 @@ namespace campvis {
QString filename = QFileDialog::getSaveFileName(this, dialogCaption, directory, fileFilter); QString filename = QFileDialog::getSaveFileName(this, dialogCaption, directory, fileFilter);
MhdImageWriter writer; MhdImageWriter writer;
writer.init();
writer.p_fileName.setValue(filename.toStdString()); writer.p_fileName.setValue(filename.toStdString());
writer.p_inputImage.setValue(name.toStdString()); writer.p_inputImage.setValue(name.toStdString());
writer.invalidate(AbstractProcessor::INVALID_RESULT); writer.invalidate(AbstractProcessor::INVALID_RESULT | AbstractProcessor::FIRST_FREE_TO_USE_INVALIDATION_LEVEL); // needed for the save action to actually execute
writer.process(*_dataContainer); writer.process(*_dataContainer);
writer.deinit();
} }
else if (dynamic_cast<const ImageData*>(handle.getData()) || dynamic_cast<const RenderData*>(handle.getData())) { else if (handle.getData<ImageData>() || handle.getData<RenderData>()) {
QString dialogCaption = "Export " + name + " as Image"; QString dialogCaption = "Export " + name + " as Image";
QString directory = tr(""); QString directory = tr("");
const QString fileFilter = tr("*.png;;PNG images (*.png)"); const QString fileFilter = tr("Image (*.png *.bmp *.jpg *.tif);;RAW Image (*.raw);;DirectDraw Surface (*.dds);;C-style header (*.h);;Radiance High Dynamic (*.hdr)");
QString filename = QFileDialog::getSaveFileName(this, dialogCaption, directory, fileFilter); QString filename = QFileDialog::getSaveFileName(this, dialogCaption, directory, fileFilter);
...@@ -484,10 +471,10 @@ namespace campvis { ...@@ -484,10 +471,10 @@ namespace campvis {
// get the ImageData object (either directly or from the RenderData) // get the ImageData object (either directly or from the RenderData)
const ImageData* id = 0; const ImageData* id = 0;
if (const RenderData* tester = dynamic_cast<const RenderData*>(handle.getData())) { if (auto tester = handle.getData<RenderData>()) {
id = tester->getColorTexture(0); id = tester->getColorTexture(0);
} }
else if (const ImageData* tester = dynamic_cast<const ImageData*>(handle.getData())) { else if (auto tester = handle.getData<ImageData>()) {
id = tester; id = tester;
} }
else { else {
...@@ -518,10 +505,13 @@ namespace campvis { ...@@ -518,10 +505,13 @@ namespace campvis {
ilEnable(IL_FILE_OVERWRITE); ilEnable(IL_FILE_OVERWRITE);
ilResetWrite(); ilResetWrite();
ILboolean success = ilSaveImage(filename.c_str()); ILboolean success = ilSaveImage(filename.c_str());
ilDeleteImages(1, &img); ilDeleteImages(1, &img);
if (!success) { if (!success) {
LERRORC("CAMPVis.application.DataContainerInspectorWidget", "Could not save image to file: " << ilGetError()); ILenum error = ilGetError();
LERRORC("CAMPVis.application.DataContainerInspectorWidget", "Could not save image to file: " << error << ": " << iluErrorString(error));
} }
#else #else
return; return;
...@@ -532,8 +522,8 @@ namespace campvis { ...@@ -532,8 +522,8 @@ namespace campvis {
void DataContainerInspectorWidget::onBtnLoadFileClicked() { void DataContainerInspectorWidget::onBtnLoadFileClicked() {
// delete previous PropertyEditor, then create a new one // delete previous PropertyEditor, then create a new one