Skip to content

Commit

Permalink
Update to support Qt6 and changes in inviwo
Browse files Browse the repository at this point in the history
  • Loading branch information
ResearchDaniel committed Sep 24, 2021
1 parent 0770bdb commit 8e02eb0
Show file tree
Hide file tree
Showing 13 changed files with 249 additions and 229 deletions.
42 changes: 25 additions & 17 deletions apps/visualneuro/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ project(VisualNeuroApp)

include(version.cmake)

find_package(Qt5 5.12.0 QUIET REQUIRED COMPONENTS Core Gui Widgets OpenGL)# WebEngine WebEngineWidgets WebSockets)
# https://doc-snapshots.qt.io/qt6-dev/cmake-qt5-and-qt6-compatibility.html#supporting-older-qt-5-versions
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Widgets REQUIRED)

#--------------------------------------------------------------------
# Add MOC files
Expand All @@ -14,16 +16,16 @@ set(MOC_FILES
splashscreen.h
)
# Add resource file
qt5_add_resources(QRC_FILE "visualneuro.qrc")
source_group("Resource Files" FILES
visualneuro.qrc
${QRC_FILE}
)
if(QT_VERSION_MAJOR EQUAL 6)
qt_add_resources(QRC_FILE "visualneuro.qrc")
else()
qt5_add_resources(QRC_FILE "visualneuro.qrc")
endif()
source_group("Resource Files" FILES visualneuro.qrc ${QRC_FILE})

#--------------------------------------------------------------------
# Add header files
set(HEADER_FILES
visualneurocommondefines.h # auto-generated
${MOC_FILES})
ivw_group("Header Files" ${HEADER_FILES})

Expand All @@ -38,8 +40,12 @@ set(SOURCE_FILES
ivw_group("Source Files" ${SOURCE_FILES})

# Add moc files
qt5_wrap_cpp(MOC_FILES ${MOC_FILES})
source_group("MOC Files" FILES ${MOC_FILES})
if(QT_VERSION_MAJOR EQUAL 6)
qt_wrap_cpp(MOCED_FILES ${MOC_FILES})
else()
qt5_wrap_cpp(MOCED_FILES ${MOC_FILES})
endif()
source_group("MOC Files" FILES ${MOCED_FILES})


ivw_retrieve_all_modules(enabled_modules)
Expand All @@ -60,17 +66,17 @@ endif()
source_group("Resource Files" FILES ${RES_FILES})

# Create application
add_executable(VisualNeuro MACOSX_BUNDLE WIN32 ${SOURCE_FILES} ${QRC_FILE} ${MOC_FILES} ${RES_FILES})
add_executable(VisualNeuro MACOSX_BUNDLE WIN32
${SOURCE_FILES}
${HEADER_FILES}
${QRC_FILE}
${MOCED_FILES}
${RES_FILES})
target_link_libraries(VisualNeuro PUBLIC
inviwo::core
inviwo::qtapplicationbase
Qt5::Core
Qt5::Gui
Qt5::Widgets
Qt5::OpenGL
#Qt5::WebEngine
#Qt5::WebEngineWidgets
#Qt5::WebSockets
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Widgets
)
target_include_directories(VisualNeuro PUBLIC
${CMAKE_BINARY_DIR}/apps/visualneuro/include
Expand Down Expand Up @@ -138,6 +144,8 @@ endif()
# " /SUBSYSTEM:CONSOLE /ENTRY:mainCRTStartup")
#endif()

ivw_deploy_qt(VisualNeuro)

set_property(CACHE IVW_PACKAGE_SELECT_APP APPEND PROPERTY STRINGS "VisualNeuro")

if(IVW_PACKAGE_SELECT_APP STREQUAL "VisualNeuro")
Expand Down
12 changes: 6 additions & 6 deletions apps/visualneuro/consolewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
#include <QMessageBox>
#include <warn/pop>

#include <inviwo/core/common/inviwo.h>
#include <inviwo/core/common/inviwoapplication.h>
#include "consolewidget.h"
#include <inviwo/core/util/filesystem.h>
#include <inviwo/core/util/stringconversion.h>
Expand Down Expand Up @@ -112,7 +112,7 @@ ConsoleWidget::ConsoleWidget(QWidget* parent)

tableView_->setContextMenuPolicy(Qt::ActionsContextMenu);
clearAction_ = new QAction(QIcon(":/svgicons/log-clear.svg"), tr("&Clear Log"), this);
clearAction_->setShortcut(Qt::ControlModifier + Qt::Key_E);
clearAction_->setShortcut(Qt::CTRL | Qt::Key_E);
connect(clearAction_, &QAction::triggered, [&]() { clear(); });

tableView_->hideColumn(static_cast<int>(LogTableModelEntry::ColumnID::Date));
Expand Down Expand Up @@ -203,15 +203,15 @@ ConsoleWidget::ConsoleWidget(QWidget* parent)

auto levelCallback = [this, updateRowsHeights](bool /*checked*/) {
if (util::all_of(levels, [](const auto& level) { return level.action->isChecked(); })) {
levelFilter_->setFilterRegExp("");
levelFilter_->setFilterRegularExpression("");
} else {
std::stringstream ss;
auto joiner = util::make_ostream_joiner(ss, "|");
joiner = "None";
for (const auto& level : levels) {
if (level.action->isChecked()) joiner = level.level;
}
levelFilter_->setFilterRegExp(QString::fromStdString(ss.str()));
levelFilter_->setFilterRegularExpression(QString::fromStdString(ss.str()));
}
updateRowsHeights();
};
Expand Down Expand Up @@ -246,15 +246,15 @@ ConsoleWidget::ConsoleWidget(QWidget* parent)

connect(filterPattern_, &QLineEdit::textChanged,
[this, updateRowsHeights, clearFilter](const QString& text) {
filter_->setFilterRegExp(text);
filter_->setFilterRegularExpression(text);
updateRowsHeights();
clearFilter->setEnabled(!text.isEmpty());
});

connect(clearFilter, &QAction::triggered, [this]() { filterPattern_->setText(""); });

auto filterAction = new QAction(makeIcon("find"), "&Filter", this);
filterAction->setShortcut(Qt::ControlModifier + Qt::AltModifier + Qt::Key_F);
filterAction->setShortcut(Qt::CTRL | Qt::ALT | Qt::Key_F);
connect(filterAction, &QAction::triggered, [this]() {
raise();
filterPattern_->setFocus();
Expand Down
1 change: 0 additions & 1 deletion apps/visualneuro/splashscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include <QPainter>
#include <QSplashScreen>
#include <QTextStream>
#include <QDesktopWidget>
#include <warn/pop>

namespace inviwo {
Expand Down
34 changes: 9 additions & 25 deletions apps/visualneuro/visualneuromainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#include <inviwo/core/processors/compositeprocessor.h>
#include <inviwo/core/processors/compositeprocessorutils.h>

#include <modules/openglqt/canvasprocessorwidgetqt.h>
#include <inviwo/core/processors/canvasprocessorwidget.h>

#include <inviwo/core/rendering/datavisualizermanager.h>

Expand All @@ -68,7 +68,6 @@
#include <QGridLayout>
#include <QActionGroup>
#include <QClipboard>
#include <QDesktopWidget>
#include <QFileDialog>
#include <QList>
#include <QMessageBox>
Expand Down Expand Up @@ -121,16 +120,17 @@ VisualNeuroMainWindow::VisualNeuroMainWindow(InviwoApplicationQt* app)

currentWorkspaceFileName_ = "";

const QDesktopWidget dw;
auto screen = dw.screenGeometry(this);
auto screen = QGuiApplication::primaryScreen();
const float maxRatio = 0.8f;
const auto ssize = screen->availableSize();

QSize size = utilqt::emToPx(this, QSizeF(192, 108));
size.setWidth(std::min(size.width(), static_cast<int>(screen.width() * maxRatio)));
size.setHeight(std::min(size.height(), static_cast<int>(screen.height() * maxRatio)));
size.setWidth(std::min(size.width(), static_cast<int>(ssize.width() * maxRatio)));
size.setHeight(std::min(size.height(), static_cast<int>(ssize.height() * maxRatio)));


// Center Window
QPoint pos{screen.width() / 2 - size.width() / 2, screen.height() / 2 - size.height() / 2};
QPoint pos{ssize.width() / 2 - ssize.width() / 2, ssize.height() / 2 - ssize.height() / 2};

resize(size);
move(pos);
Expand Down Expand Up @@ -431,7 +431,7 @@ bool VisualNeuroMainWindow::openWorkspace(QString workspaceFileName, bool isExam
processor->invalidate(InvalidationLevel::InvalidResources);

auto processorWidget =
dynamic_cast<CanvasProcessorWidgetQt*>(processor->getProcessorWidget());
dynamic_cast<CanvasProcessorWidget*>(processor->getProcessorWidget());
if (processorWidget) {
// Assume that the main canvas is called Canvas. Otherwise just use the first
// one that comes up.
Expand Down Expand Up @@ -471,27 +471,11 @@ bool VisualNeuroMainWindow::openWorkspace(QString workspaceFileName, bool isExam
centralLayout = gridLayout;

centralLayout->setSpacing(0);
centralLayout->setMargin(0);
centralLayout->setContentsMargins(0, 0, 0, 0);

setCentralWidget(central);

// END OF FIXME
#ifdef QWEBENGINE_TEST
auto processorWidget = dynamic_cast<CanvasProcessorWidgetQt*>(mainCanvasWidget);
auto view = new QWebEngineView(mainCanvasWidget);

QGridLayout* gl = new QGridLayout(dynamic_cast<CanvasQt*>(processorWidget->getCanvas()));
gl->setContentsMargins(0, 0, 0, 0);
gl->addWidget(view, 0, 0);
view->setUrl(
QUrl("C:/Users/danjo/Documents/inviwo/research/apps/visualneuro/index.html"));
view->setAttribute(Qt::WA_TranslucentBackground);
view->setStyleSheet("background:transparent");
auto page = view->page();
// https://bugreports.qt.io/browse/QTBUG-41960
page->setBackgroundColor(Qt::transparent);
view->show();
#endif
mainCanvasWidget->show();

// Will make the central widget a parent to the overlay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@

#include <modules/visualneuro/visualneuromoduledefine.h>


#include <inviwo/core/datastructures/volume/volume.h>
#include <inviwo/core/util/glm.h>
#include <inviwo/core/util/stringconversion.h>

#include <inviwo/dataframe/datastructures/dataframe.h>

#include <string>
#include <optional>

Expand All @@ -49,113 +53,20 @@ class IVW_MODULE_VISUALNEURO_API VolumeAtlas {
std::optional<glm::vec4> color;
bool operator==(std::string label) { return name == label; }
};
VolumeAtlas(std::shared_ptr<const Volume> atlas, std::shared_ptr<const DataFrame> labels)
: atlas_(atlas) {
std::shared_ptr<const Column> idCol;
std::shared_ptr<const Column> labelCol;
std::shared_ptr<const Column> colorCol;
for (auto col : *labels) {
if (iCaseCmp(col->getHeader(), "Index")) {
idCol = col;
} else if (iCaseCmp(col->getHeader(), "Region")) {
labelCol = col;
} else if (iCaseCmp(col->getHeader(), "Color")) {
colorCol = col;
}
}
if (!idCol) {
idCol = *std::find_if(++labels->begin(), labels->end(), [](auto r) {
auto type = r->getBuffer()->getDataFormat()->getNumericType();
return type == NumericType::UnsignedInteger || type == NumericType::SignedInteger;
});
}
if (!labelCol) {
labelCol = *std::find_if(++labels->begin(), labels->end(), [](auto r) {
return dynamic_cast<const CategoricalColumn*>(r.get());
});
}
if (!idCol) {
throw Exception(
"Could not find Index column for atlas labels. Add Index column with id of each "
"region");
}
if (!labelCol) {
for (auto i = 0u; i < idCol->getSize(); ++i) {
labels_[static_cast<int>(idCol->getAsDouble(i))] = Label{};
}
} else {
for (auto i = 0u; i < idCol->getSize(); ++i) {
std::string colorString = colorCol ? colorCol->getAsString(i) : "";
std::stringstream ss(colorString);
vec4 c{};
for (auto elem = 0; elem < 4; elem++) {
ss >> c[elem];
}
labels_[static_cast<int>(idCol->getAsDouble(i))] =
Label{labelCol->getAsString(i),
ss.fail() ? std::nullopt : std::optional<glm::vec4>(c)};
}
}
}
VolumeAtlas(std::shared_ptr<const Volume> atlas, std::shared_ptr<const DataFrame> labels);

int getLabelId(const ivec3 indexPos) const {
if (glm::all(glm::lessThan(indexPos, ivec3(atlas_->getDimensions()))) &&
glm::all(glm::lessThan(ivec3(0, 0, 0), indexPos))) {
// get the voxel value at given position and look it up in the atlas
return static_cast<int>(atlas_->getRepresentation<VolumeRAM>()->getAsDouble(indexPos));
} else {
return -1;
}
}
int getLabelId(std::string label) const {
auto elemIt = std::find_if(labels_.begin(), labels_.end(),
[label](auto elem) { return elem.second == label; });
if (elemIt == labels_.end()) {
return -1;
} else {
return elemIt->first;
}
}
int getLabelId(vec3 worldPos) const {
const mat4 trans = atlas_->getCoordinateTransformer().getWorldToIndexMatrix();
const ivec3 indexPos(ivec3(trans * vec4(worldPos, 1)));
return getLabelId(indexPos);
}
int getLabelId(const ivec3 indexPos) const;
int getLabelId(std::string label) const;
int getLabelId(vec3 worldPos) const;

double getLabelIdNormalized(int labelId) const {
return atlas_->dataMap_.mapFromValueToNormalized(static_cast<double>(labelId));
}
double getLabelIdNormalized(int labelId) const;

std::optional<Label> getLabel(int id) const {
auto elemIt = labels_.find(id);
if (elemIt == labels_.end()) {
return std::nullopt;
} else {
return elemIt->second;
}
}
std::optional<Label> getLabel(int id) const;

std::string getLabelName(int id) const {
auto elemIt = labels_.find(id);
if (elemIt == labels_.end()) {
return "";
} else {
return elemIt->second.name;
}
}
std::optional<vec4> getLabelColor(int id) const {
auto elemIt = labels_.find(id);
if (elemIt == labels_.end()) {
return std::nullopt;
} else {
return elemIt->second.color;
}
}
std::string getLabelName(int id) const;
std::optional<vec4> getLabelColor(int id) const;

bool hasColors() const {
return std::any_of(labels_.cbegin(), labels_.cend(),
[](const auto l) { return l.second.color != std::nullopt; });
}
bool hasColors() const;

private:
std::shared_ptr<const Volume> atlas_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <modules/visualneuro/visualneuromoduledefine.h>
#include <modules/visualneuro/statistics/ttest.h>

#include <inviwo/core/util/assertion.h>

#include <tuple>

namespace inviwo {
Expand Down
Loading

0 comments on commit 8e02eb0

Please sign in to comment.