[med-svn] [Git][med-team/bart-view][master] 50 commits: remove UNUSED, as it was removed from bart
Martin Uecker (@uecker-guest)
gitlab at salsa.debian.org
Sun Nov 8 13:40:06 GMT 2026
Martin Uecker pushed to branch master at Debian Med / bart-view
Commits:
3f462480 by Christian Holme at 2024-01-11T13:54:37+01:00
remove UNUSED, as it was removed from bart
- - - - -
bbdd4193 by Moritz Blumenthal at 2024-01-12T15:50:58+01:00
slice option for cfl2png
- - - - -
1ae7293d by Christian Holme at 2024-02-28T11:19:25+01:00
add lipari and navia colormaps for T1 and T2
As they are recommended by the QMRI Study Group of the ISMRM
- - - - -
0a1c4d75 by Philip Schaten at 2024-03-05T12:07:27+01:00
Split up view_s into separate structs.
The goal is to separate program logic and widget toolkit implementation:
- view_settings_s should contain all parameters to render an image.
- view_control_s is the state of the 'application logic', e.g.
last_x last_y for windowing etc..
- view_gtk_ui_s holds implementation specific widget toolkit state.
- view_s acts as the "parent" struct that is not opaque and contains
shared state.
- - - - -
1a319f2f by Philip Schaten at 2024-03-05T12:07:35+01:00
Separate UI toolkit specific functions from view.c
Program logic is kept in view.c as far as possible,
while gtk_ui.c should mostly contain only gtk function calls.
- - - - -
ff969387 by Philip Schaten at 2024-03-05T12:07:35+01:00
Split up almost all remaining functions in view.c.
This decouples motion_notify_event, show_hide, window_close, window_new,
window_clone, draw_callback, toggle_sync, toggle_plot, toggle_abs_windowing, set_position and button_press_event.
Splitting up motion_notify_event introduces a race condition (one thread
might be redrawing while the settings struct is only half updated),
which is fixed in a later commit.
- - - - -
dca97bb4 by Philip Schaten at 2024-03-05T12:07:35+01:00
remove gtk dependencies from view.c and main.c, cleanup.
- - - - -
9a602080 by Philip Schaten at 2024-03-05T12:07:35+01:00
Remove implicit callback chains from gtk_ui
Some program logic in view relies on callbacks triggering other
callbacks in the UI framework.
To allow swapping the UI framework, this commit splits up one such chain.
- - - - -
8b0c7fad by Philip Schaten at 2024-03-05T12:07:35+01:00
renaming of callbacks
gtk_ui exposes a lot of callbacks but also 'normal' functions to the
controller (view.c).
view.c also contains matching functions that are usually called by these
callbacks.
This commit makes the naming more consistent.
- - - - -
34141b09 by Philip Schaten at 2024-03-05T12:07:35+01:00
Remove program logic from gtk_ui.c
To be able to easily switch UI backends, the UI implementation
should contain as few "application logic" as possible.
- - - - -
98152fe3 by Philip Schaten at 2024-03-05T12:07:35+01:00
Finalize UI backend separation
- fixes a race condition introduced earlier
- removes shared state as far as possible
- general renaming, cleanup etc
- - - - -
2010a634 by Philip Schaten at 2024-03-05T12:07:35+01:00
.gitignore ide files
- - - - -
04dfe05b by Martin Uecker at 2024-04-02T14:37:04+02:00
copyright & coding style
- - - - -
4b1d485f by Martin Uecker at 2024-04-02T16:22:14+02:00
introduce enum for color tables
- - - - -
33e6842e by Martin Uecker at 2024-04-09T21:43:11+02:00
fix flickering
- - - - -
8a571bbc by Blumenthal, Moritz at 2024-04-23T18:36:46+02:00
linking cuda needs blas
- - - - -
2725d7b3 by Blumenthal, Moritz at 2024-04-23T18:45:53+02:00
open 3D images in center
- - - - -
d35cffdd by Christian Holme at 2024-07-02T09:18:11+02:00
view: fix position sync in 3D datasets
now, view will again show the new slice, if we change the slice in a
synced window
- - - - -
385e8be8 by Christian Holme at 2024-07-02T10:34:41+02:00
view: fix status bar
Since we sync the positions anyway, each view only needs to update its
own status bar. Also, it also knows what it should sample: whatever is
in its own position array.
- - - - -
9f1896ae by Christian Holme at 2024-07-02T10:37:31+02:00
view.c: style
no need to pass a pointer to an array when we can just pass the array
(which decays to a pointer anyway)
- - - - -
88116915 by Christian Holme at 2024-07-02T14:32:40+02:00
main.c: allow running view -h without a display
by initializing the UI only after exiting from `-h`
- - - - -
1720468d by Holme, Hans Christian Martin at 2024-07-02T14:32:40+02:00
Add simple tests for view and cfl2png
- - - - -
7d9c7826 by Christian Holme at 2024-07-02T15:34:57+02:00
gitlab-CI: cache apt packages
in local gitlab-runner cache. This means that we do not download the
same apt-packages over and over again
TODO: automatically clear cache after a while
- - - - -
d47cb970 by Christian Holme at 2024-09-20T14:06:58+02:00
view: changes for newer bart version
* -std=gnu11 instead of c11, because we use [[gnu::alloc_size(x)] in
misc/misc.h
* misc/misc.h defines a CLAMP macro, so we undef the glib-version
* the count of ARG_TUPLE is now an int and not a long
- - - - -
a789dfaa by Philip Schaten at 2024-09-23T14:04:30+02:00
realtime update position with bart streams.
- - - - -
7e005a0f by Martin Uecker at 2024-09-29T14:49:52+02:00
compatibility with old bart package & style
- - - - -
53b34642 by Martin Uecker at 2024-09-29T15:21:31+02:00
style
- - - - -
12f97e07 by Martin Uecker at 2024-09-29T15:37:16+02:00
possible null pointer issue, style, C compliance
- - - - -
f29a0c14 by Martin Uecker at 2024-09-29T16:43:57+02:00
style
- - - - -
2ff6bef6 by Martin Uecker at 2024-09-29T18:16:21+02:00
fix 100% CPU issue
- - - - -
f35a94dc by Martin Uecker at 2024-09-29T18:23:57+02:00
add -Werror and analyzer build to CI
- - - - -
da178048 by Martin Uecker at 2024-09-30T10:22:55+02:00
update toolbox path in README
- - - - -
b79a154b by Philip Schaten at 2025-04-09T18:50:31+02:00
fix view crashing on too small zoom/aniso
- - - - -
3512794c by Philip Schaten at 2025-04-09T19:42:35+02:00
fix view freezing on save/save movie dialogue
- - - - -
cc452b49 by Philip Schaten at 2025-04-09T19:57:49+02:00
fix flickering when zoom is set to fit
- - - - -
2ebedf6d by Philip Schaten at 2025-04-09T20:16:39+02:00
fit plots to window using anisotropy
- - - - -
b2ce6e21 by Moritz Blumenthal at 2025-04-10T00:11:39+02:00
fixup deactivation of fit
- - - - -
18f4e19a by Moritz Blumenthal at 2025-04-10T00:15:38+02:00
allow for 1d files
- - - - -
f64f8a07 by Blumenthal, Moritz at 2025-09-20T13:38:55+02:00
add phase option to cfl2png
- - - - -
56aa140c by Martin Uecker at 2026-09-01T16:52:50+02:00
remove duplicate STRINGIFY
- - - - -
baf0b08e by Martin Uecker at 2026-09-01T16:52:50+02:00
add missing libraries (Mac needs updating)
- - - - -
c5e86e2a by Martin Uecker at 2026-09-01T17:05:16+02:00
update ci
- - - - -
380f5d92 by Martin Uecker at 2026-11-08T14:11:49+01:00
different stock icons
- - - - -
97a81b13 by Martin Uecker at 2026-11-08T14:12:54+01:00
copyright
- - - - -
2db6a70c by Martin Uecker at 2026-11-08T14:24:17+01:00
Merge branch 'upstream'
- - - - -
c70bd801 by Martin Uecker at 2026-11-08T14:27:29+01:00
update copyright
- - - - -
2cb04287 by Martin Uecker at 2026-11-08T14:28:51+01:00
update watch file
- - - - -
875c6849 by Martin Uecker at 2026-11-08T14:29:03+01:00
update bart dependency
- - - - -
08fadc7f by Martin Uecker at 2026-11-08T14:31:36+01:00
update upstream
- - - - -
88035bc5 by Martin Uecker at 2026-11-08T14:33:32+01:00
changelog
- - - - -
20 changed files:
- .gitignore
- .gitlab-ci.yml
- LICENSE
- Makefile
- README.md
- debian/changelog
- debian/control
- debian/copyright
- debian/upstream/metadata
- debian/watch
- src/cfl2png.c
- src/colormaps.inc
- src/draw.c
- src/draw.h
- + src/gtk_ui.c
- + src/gtk_ui.h
- src/main.c
- src/view.c
- src/view.h
- src/viewer.ui
Changes:
=====================================
.gitignore
=====================================
@@ -4,3 +4,5 @@ viewer.inc
tags
*.swp
Makefile.local
+compile_commands.json
+.cache
=====================================
.gitlab-ci.yml
=====================================
@@ -1,23 +1,47 @@
variables:
OMP_NUM_THREADS: "1"
+image: debian:trixie
before_script:
- - apt-get update -qq && apt-get install -y -qq
- - apt-get install -y -qq make git gcc
- - apt-get install -y -qq libgtk-3-dev
- - apt-get install -y -qq libbart-dev
+ - apt-get update -yqq
+ - apt-get install -y make git gcc libgtk-3-dev libbart-dev libblas3-dev libfftw3-dev
stages:
- build
+ - test
Build:
- image: debian:bookworm
stage: build
script:
- - make all
+ - CFLAGS="-Werror" make all
artifacts:
paths:
- view
- cfl2png
+Build_Analyzer:
+ stage: build
+ script:
+ - CFLAGS="-fanalyzer -Werror" DEBUG=0 make all
+ artifacts:
+ paths:
+ - view
+ - cfl2png
+ expire_in: 45 minutes
+ allow_failure: true
+
+
+Test_cfl2png:
+ stage: test
+ script:
+ - apt-get install -y bart
+ - bart phantom pha.ra
+ - ./view -h
+ - ./cfl2png -x1 -u0.5 -CV pha.ra pha.png
+ artifacts:
+ paths:
+ - pha.png
+ needs: [Build]
+ dependencies:
+ - Build
=====================================
LICENSE
=====================================
@@ -1,5 +1,6 @@
Copyright (c) 2015-2023. Martin Uecker.
Copyright (c) 2017-2023. AG Uecker. University Medical Center Göttingen.
+Copyright (c) 2021-2026. Graz University of Technology.
All rights reserved.
Redistribution and use in source and binary forms, with or without
=====================================
Makefile
=====================================
@@ -30,7 +30,7 @@ ifeq ($(origin CC), default)
CC = gcc
endif
-CFLAGS ?= -Wall
+CFLAGS ?= -Wall -Wextra
ifeq ($(DEBUG),1)
CFLAGS += -Og -g
@@ -39,9 +39,9 @@ else
endif
ifeq ($(BUILDTYPE), MacOSX)
- CFLAGS += -std=c11 -Xpreprocessor
+ CFLAGS += -std=gnu11 -Xpreprocessor
else
- CFLAGS += -std=c11
+ CFLAGS += -std=gnu11
endif
ifeq ($(OMP),1)
@@ -60,7 +60,7 @@ endif
ifeq ($(CUDA),1)
- CUDA_L := -L$(CUDA_BASE)/$(CUDA_LIB) -lcufft -lcudart -lcublas
+ CUDA_L := -L$(CUDA_BASE)/$(CUDA_LIB) -lcufft -lcudart -lcublas -lblas
else
CUDA_L :=
endif
@@ -72,7 +72,7 @@ EXPDYN = -rdynamic
ifeq ($(BUILDTYPE), MacOSX)
LDFLAGS += -L/opt/local/lib -lm -lpng -lomp -lrt
else
- LDFLAGS += -lm -lpng -lrt
+ LDFLAGS += -lm -lpng -lrt -lblas -lfftw3f -lfftw3f_threads
endif
@@ -82,8 +82,8 @@ all: view cfl2png
src/viewer.inc: src/viewer.ui
@echo "STRINGIFY(`cat src/viewer.ui`)" > src/viewer.inc
-view: src/main.c src/view.[ch] src/draw.[ch] src/viewer.inc
- $(CC) $(CFLAGS) $(CPPFLAGS) $(EXPDYN) -o view -I$(TOOLBOX_INC) `$(PKG_CONFIG) --cflags gtk+-3.0` src/main.c src/view.c src/draw.c `$(PKG_CONFIG) --libs gtk+-3.0` $(TOOLBOX_LIB)/libmisc.a $(TOOLBOX_LIB)/libgeom.a $(TOOLBOX_LIB)/libnum.a $(TOOLBOX_LIB)/libmisc.a $(CUDA_L) $(LDFLAGS)
+view: src/main.c src/view.[ch] src/draw.[ch] src/gtk_ui.[ch] src/viewer.inc
+ $(CC) $(CFLAGS) $(CPPFLAGS) $(EXPDYN) -o view -I$(TOOLBOX_INC) `$(PKG_CONFIG) --cflags gtk+-3.0` src/main.c src/view.c src/gtk_ui.c src/draw.c `$(PKG_CONFIG) --libs gtk+-3.0` $(TOOLBOX_LIB)/libmisc.a $(TOOLBOX_LIB)/libgeom.a $(TOOLBOX_LIB)/libnum.a $(TOOLBOX_LIB)/libmisc.a $(CUDA_L) $(LDFLAGS)
cfl2png: src/cfl2png.c src/view.[ch] src/draw.[ch] src/viewer.inc
$(CC) $(CFLAGS) $(CPPFLAGS) $(EXPDYN) -o cfl2png -I$(TOOLBOX_INC) src/cfl2png.c src/draw.c $(TOOLBOX_LIB)/libmisc.a $(TOOLBOX_LIB)/libgeom.a $(TOOLBOX_LIB)/libnum.a $(TOOLBOX_LIB)/libmisc.a $(CUDA_L) $(LDFLAGS)
=====================================
README.md
=====================================
@@ -26,7 +26,7 @@ sudo apt-get install libgtk-3-dev
-Compile with make after setting the TOOLBOX_PATH
+Compile with make after setting the BART_TOOLBOX_PATH
environment variable to the directory where BART
is installed.
=====================================
debian/changelog
=====================================
@@ -1,3 +1,9 @@
+bart-view (0.4.00-1) UNRELEASED; urgency=medium
+
+ * New upstream version (Closes: #1139466)
+
+ -- Martin Uecker <uecker at tugraz.at> Sun, 08 Nov 2026 14:31:40 +0100
+
bart-view (0.3.00-1) unstable; urgency=medium
* New upstream version (Closes: #1058276, 1043926)
=====================================
debian/control
=====================================
@@ -4,7 +4,7 @@ Uploaders: Martin Uecker <uecker at tugraz.at>
Section: science
Priority: optional
Build-Depends: debhelper-compat (= 13),
- libbart-dev (>= 0.8.00),
+ libbart-dev (>= 1.0.00),
libgtk-3-dev
Standards-Version: 4.6.2
Vcs-Browser: https://salsa.debian.org/med-team/bart-view
=====================================
debian/copyright
=====================================
@@ -1,10 +1,12 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: view
-Upstream-Contact: Martin Uecker <martin.uecker at med.uni-goettingen.de>
-Source: https://github.com/mrirecon/view
+Upstream-Contact: Martin Uecker <uecker at tugraz.at>
+Source: https://codeberg.org/IBI-TUGraz/view
Files: *
-Copyright: 2015-2022 Martin Uecker
+Copyright: 2021-2026 Graz University of Technology
+ 2015-2022 Martin Uecker
+ 2017-2023 AG Uecker. University Medical Center Göttingen
2016-2017 Christian Holme
2016 Sebastian Rosenzweig
License: BSD-3-clause
=====================================
debian/upstream/metadata
=====================================
@@ -1,7 +1,7 @@
---
-Archive: GitHub
-Bug-Database: https://github.com/mrirecon/view/issues
-Bug-Submit: https://github.com/mrirecon/view/issues/new
-Changelog: https://github.com/mrirecon/view/tags
-Repository: https://github.com/mrirecon/view.git
-Repository-Browse: https://github.com/mrirecon/view
+Archive: Codeberg
+Bug-Database: https://codeberg.org/IBI-TUGraz/view/issues
+Bug-Submit: https://codeberg.org/IBI-TUGraz/view/new
+Changelog: https://codeberg.org/IBI-TUGraz/view/tags
+Repository: https://codeberg.org/IBI-TUGraz/view.git
+Repository-Browse: https://codeberg.org/IBI-TUGraz/view/
=====================================
debian/watch
=====================================
@@ -1,3 +1,3 @@
version=4
opts=filenamemangle=s/.+\/v?(\d\S*)\.tar\.gz/view-$1\.tar\.gz/ \
- https://github.com/mrirecon/view/tags .*/v?(\d\S*)\.tar\.gz
+ https://codeberg.org/IBI-TUGraz/view/tags .*/v?(\d\S*)\.tar\.gz
=====================================
src/cfl2png.c
=====================================
@@ -17,6 +17,7 @@
#include "misc/mmio.h"
#include "misc/opts.h"
#include "misc/png.h"
+
#if 0
#include "misc/io.h"
#else
@@ -34,8 +35,35 @@ extern void io_unregister(const char* name);
#define DIMS 16
#endif
+enum cmode_t {
+ CM_MAGN, CM_MAGN_VIRIDIS, CM_CMPL, CM_CMPL_MYGBM, CM_PHSE, CM_PHSE_MYGBM,
+ CM_REAL, CM_MAGN_TURBO, CM_FLOW, CM_LIPARI_T1, CM_NAVIA_T2,
+};
+
+struct {
+ enum mode_t mode;
+ enum color_t ctab;
+
+} cm_table[] = {
-static void export_images(const char* output_prefix, int xdim, int ydim, float windowing[2], bool absolute_windowing, float zoom, enum mode_t mode, enum flip_t flip, enum interp_t interpolation, const long dims[DIMS], const complex float* idata);
+ [CM_MAGN] = { MAGN, NONE },
+ [CM_MAGN_VIRIDIS] = { MAGN, VIRIDIS },
+ [CM_MAGN_TURBO] = { MAGN, TURBO },
+ [CM_LIPARI_T1] = { MAGN, LIPARI },
+ [CM_NAVIA_T2] = { MAGN, NAVIA },
+ [CM_CMPL] = { CMPLX, NONE },
+ [CM_CMPL_MYGBM] = { CMPLX, MYGBM },
+ [CM_REAL] = { REAL, NONE },
+ [CM_FLOW] = { FLOW, NONE },
+ [CM_PHSE] = { PHASE, NONE },
+ [CM_PHSE_MYGBM] = { PHASE, MYGBM },
+};
+
+
+static void export_images(const char* output_prefix, int xdim, int ydim, float windowing[2],
+ bool absolute_windowing, float zoom, enum mode_t mode, enum color_t ctab,
+ enum flip_t flip, enum interp_t interpolation, const long dims[DIMS],
+ unsigned long loopflags, long pos[DIMS], const complex float* idata);
static const char help_str[] = "Export images to png.";
@@ -56,23 +84,29 @@ int main(int argc, char* argv[argc])
int xdim = 0;
int ydim = 0;
- float windowing[2] = {0.f, 1.f};
+ float windowing[2] = { 0.f, 1.f };
bool absolute_windowing = false;
- enum mode_t mode = MAGN;
float zoom =2.f;
enum flip_t flip = OO;
enum interp_t interpolation = NLINEAR;
+ unsigned long sliceflags = 0;
+
+ long pos[DIMS] = { [0 ... DIMS - 1] = 0 };
+ long pos_slc[DIMS] = { [0 ... DIMS - 1] = 0 };
+ int pos_count = 0;
+
+ enum cmode_t mode = CM_MAGN;
struct opt_s modeopt[] = {
- OPT_SELECT('M', enum mode_t, &mode, MAGN, "magnitude gray (default) "),
- OPT_SELECT('V', enum mode_t, &mode, MAGN_VIRIDS, "magnitude viridis"),
- OPT_SELECT('C', enum mode_t, &mode, CMPL, "complex"),
- OPT_SELECT('G', enum mode_t, &mode, CMPL_MYGBM, "complex MYGBM"),
- OPT_SELECT('P', enum mode_t, &mode, PHSE, "phase"),
- OPT_SELECT('Y', enum mode_t, &mode, PHSE_MYGBM, "phase MYGBM"),
- OPT_SELECT('R', enum mode_t, &mode, REAL, "real"),
- OPT_SELECT('T', enum mode_t, &mode, MAGN_TURBO, "magnitude turbo"),
- OPT_SELECT('F', enum mode_t, &mode, FLOW, "flow"),
+ OPT_SELECT('M', enum cmode_t, &mode, CM_MAGN, "magnitude gray (default) "),
+ OPT_SELECT('V', enum cmode_t, &mode, CM_MAGN_VIRIDIS, "magnitude viridis"),
+ OPT_SELECT('C', enum cmode_t, &mode, CM_CMPL, "complex"),
+ OPT_SELECT('G', enum cmode_t, &mode, CM_CMPL_MYGBM, "complex MYGBM"),
+ OPT_SELECT('P', enum cmode_t, &mode, CM_PHSE, "phase"),
+ OPT_SELECT('Y', enum cmode_t, &mode, CM_PHSE_MYGBM, "phase MYGBM"),
+ OPT_SELECT('R', enum cmode_t, &mode, CM_REAL, "real"),
+ OPT_SELECT('T', enum cmode_t, &mode, CM_MAGN_TURBO, "magnitude turbo"),
+ OPT_SELECT('F', enum cmode_t, &mode, CM_FLOW, "flow"),
};
struct opt_s flipopt[] = {
@@ -100,18 +134,38 @@ int main(int argc, char* argv[argc])
OPT_SUBOPT('F', "flip", "flip. -Fh for help.", ARRAY_SIZE(flipopt), flipopt),
OPT_SUBOPT('I', "interp", "interp. -Ih for help.", ARRAY_SIZE(interpopt), interpopt),
OPT_INT('d', &debug_level, "level", "Debug level"),
+ OPT_ULONG('S', &sliceflags, "flags", "slice selected dims"),
+#ifdef OPT_VECC
+ OPT_VECC('P', &pos_count, pos_slc, "position for sliced dimensions"),
+#endif
+#ifdef OPT_VECN
+ OPT_VECN('p', pos, "(provide all positions (useful if position is exported from view))"),
+#endif
};
cmdline(&argc, argv, ARRAY_SIZE(args), args, help_str, ARRAY_SIZE(opts), opts);
- if (!absolute_windowing)
+ if (!absolute_windowing) {
+
assert( (windowing[0] >= 0.f)
&& (windowing[1] <= 1.f)
&& (windowing[0] < windowing[1]));
+ }
assert((0 <= xdim) && (xdim < DIMS));
assert((0 <= ydim) && (ydim < DIMS));
+ assert(0 == pos_count || pos_count == bitcount(sliceflags));
+
+ if (0 < pos_count) {
+
+ for (int i = 0, ip = 0; i < DIMS; i++) {
+
+ if (MD_IS_SET(sliceflags, i))
+ pos[i] = pos_slc[ip++];
+ }
+ }
+
/*
* If the filename ends in ".hdr", ".cfl" or just "." (from
* tab-completion), just replace the "." with a \0-character.
@@ -140,7 +194,11 @@ int main(int argc, char* argv[argc])
*ext = '\0';
}
- export_images(out_prefix, xdim, ydim, windowing, absolute_windowing, zoom, mode, flip, interpolation, dims, idata);
+
+
+ export_images(out_prefix, xdim, ydim, windowing, absolute_windowing, zoom,
+ cm_table[mode].mode, cm_table[mode].ctab, flip, interpolation,
+ dims, ~sliceflags, pos, idata);
unmap_cfl(DIMS, dims, idata);
@@ -156,6 +214,7 @@ int main(int argc, char* argv[argc])
static void unravel_index(int D, long pos[D], unsigned long flags, const long dims[D], long index)
{
long ind = index;
+
for (int d = 0; d < D; ++d) {
if (!MD_IS_SET(flags, d))
@@ -166,7 +225,9 @@ static void unravel_index(int D, long pos[D], unsigned long flags, const long di
}
}
-void export_images(const char* output_prefix, int xdim, int ydim, float windowing[2], bool absolute_windowing, float zoom, enum mode_t mode, enum flip_t flip, enum interp_t interpolation, const long dims[DIMS], const complex float* idata)
+void export_images(const char* output_prefix, int xdim, int ydim, float windowing[2], bool absolute_windowing,
+ float zoom, enum mode_t mode, enum color_t ctab, enum flip_t flip, enum interp_t interpolation,
+ const long dims[DIMS], unsigned long loopflags, long _pos[DIMS], const complex float* idata)
{
if (xdim == ydim) {
@@ -188,6 +249,7 @@ void export_images(const char* output_prefix, int xdim, int ydim, float windowin
if (absolute_windowing) {
max = 1.;
+
} else {
for (long j = 0; j < md_calc_size(DIMS, dims); j++)
@@ -204,10 +266,10 @@ void export_images(const char* output_prefix, int xdim, int ydim, float windowin
// loop over all dims other than xdim and ydim
long loopdims[DIMS];
- unsigned long imflags = (MD_BIT(xdim)|MD_BIT(ydim));
- md_select_dims(DIMS, ~imflags, loopdims, dims);
+ loopflags &= ~(MD_BIT(xdim)|MD_BIT(ydim));
+ md_select_dims(DIMS, loopflags, loopdims, dims);
- debug_printf(DP_DEBUG3, "imflags: %lu\nloopdims: ", imflags);
+ debug_printf(DP_DEBUG3, "imflags: %lu\nloopdims: ", (MD_BIT(xdim)|MD_BIT(ydim)));
debug_print_dims(DP_DEBUG3, DIMS, loopdims);
@@ -219,8 +281,13 @@ void export_images(const char* output_prefix, int xdim, int ydim, float windowin
#pragma omp parallel for
for (unsigned long d = 0l; d < md_calc_size(DIMS, loopdims); ++d) {
- long pos[DIMS] = { [0 ... DIMS - 1] = 0 };
- unravel_index(DIMS, pos, ~0L, loopdims, d);
+ long pos[DIMS];
+ md_copy_dims(DIMS, pos, _pos);
+
+ for (int i = 0; i < DIMS; i++)
+ pos[i] = MIN(pos[i], dims[i] - 1);
+
+ unravel_index(DIMS, pos, loopflags, loopdims, d);
debug_printf(DP_DEBUG3, "\ti: %lu\n\t", d);
debug_print_dims(DP_DEBUG3, DIMS, pos);
@@ -239,7 +306,7 @@ void export_images(const char* output_prefix, int xdim, int ydim, float windowin
unsigned char* rgb = xmalloc(rgbh * rgbstr);
draw(rgbw, rgbh, rgbstr, (unsigned char(*)[rgbw][rgbstr / 4][4])rgb,
- mode, 1. / max, windowing[0], windowing[1], 0,
+ mode, ctab, 1. / max, windowing[0], windowing[1], 0,
rgbw, buf);
xfree(buf);
=====================================
src/colormaps.inc
=====================================
@@ -562,3 +562,38 @@ static const double viridis[256][3] = {
// The look-up tables contains 256 entries. Each entry is a an sRGB triplet.
static const double turbo[256][3] = {{0.18995,0.07176,0.23217},{0.19483,0.08339,0.26149},{0.19956,0.09498,0.29024},{0.20415,0.10652,0.31844},{0.20860,0.11802,0.34607},{0.21291,0.12947,0.37314},{0.21708,0.14087,0.39964},{0.22111,0.15223,0.42558},{0.22500,0.16354,0.45096},{0.22875,0.17481,0.47578},{0.23236,0.18603,0.50004},{0.23582,0.19720,0.52373},{0.23915,0.20833,0.54686},{0.24234,0.21941,0.56942},{0.24539,0.23044,0.59142},{0.24830,0.24143,0.61286},{0.25107,0.25237,0.63374},{0.25369,0.26327,0.65406},{0.25618,0.27412,0.67381},{0.25853,0.28492,0.69300},{0.26074,0.29568,0.71162},{0.26280,0.30639,0.72968},{0.26473,0.31706,0.74718},{0.26652,0.32768,0.76412},{0.26816,0.33825,0.78050},{0.26967,0.34878,0.79631},{0.27103,0.35926,0.81156},{0.27226,0.36970,0.82624},{0.27334,0.38008,0.84037},{0.27429,0.39043,0.85393},{0.27509,0.40072,0.86692},{0.27576,0.41097,0.87936},{0.27628,0.42118,0.89123},{0.27667,0.43134,0.90254},{0.27691,0.44145,0.91328},{0.27701,0.45152,0.92347},{0.27698,0.46153,0.93309},{0.27680,0.47151,0.94214},{0.27648,0.48144,0.95064},{0.27603,0.49132,0.95857},{0.27543,0.50115,0.96594},{0.27469,0.51094,0.97275},{0.27381,0.52069,0.97899},{0.27273,0.53040,0.98461},{0.27106,0.54015,0.98930},{0.26878,0.54995,0.99303},{0.26592,0.55979,0.99583},{0.26252,0.56967,0.99773},{0.25862,0.57958,0.99876},{0.25425,0.58950,0.99896},{0.24946,0.59943,0.99835},{0.24427,0.60937,0.99697},{0.23874,0.61931,0.99485},{0.23288,0.62923,0.99202},{0.22676,0.63913,0.98851},{0.22039,0.64901,0.98436},{0.21382,0.65886,0.97959},{0.20708,0.66866,0.97423},{0.20021,0.67842,0.96833},{0.19326,0.68812,0.96190},{0.18625,0.69775,0.95498},{0.17923,0.70732,0.94761},{0.17223,0.71680,0.93981},{0.16529,0.72620,0.93161},{0.15844,0.73551,0.92305},{0.15173,0.74472,0.91416},{0.14519,0.75381,0.90496},{0.13886,0.76279,0.89550},{0.13278,0.77165,0.88580},{0.12698,0.78037,0.87590},{0.12151,0.78896,0.86581},{0.11639,0.79740,0.85559},{0.11167,0.80569,0.84525},{0.10738,0.81381,0.83484},{0.10357,0.82177,0.82437},{0.10026,0.82955,0.81389},{0.09750,0.83714,0.80342},{0.09532,0.84455,0.79299},{0.09377,0.85175,0.78264},{0.09287,0.85875,0.77240},{0.09267,0.86554,0.76230},{0.09320,0.87211,0.75237},{0.09451,0.87844,0.74265},{0.09662,0.88454,0.73316},{0.09958,0.89040,0.72393},{0.10342,0.89600,0.71500},{0.10815,0.90142,0.70599},{0.11374,0.90673,0.69651},{0.12014,0.91193,0.68660},{0.12733,0.91701,0.67627},{0.13526,0.92197,0.66556},{0.14391,0.92680,0.65448},{0.15323,0.93151,0.64308},{0.16319,0.93609,0.63137},{0.17377,0.94053,0.61938},{0.18491,0.94484,0.60713},{0.19659,0.94901,0.59466},{0.20877,0.95304,0.58199},{0.22142,0.95692,0.56914},{0.23449,0.96065,0.55614},{0.24797,0.96423,0.54303},{0.26180,0.96765,0.52981},{0.27597,0.97092,0.51653},{0.29042,0.97403,0.50321},{0.30513,0.97697,0.48987},{0.32006,0.97974,0.47654},{0.33517,0.98234,0.46325},{0.35043,0.98477,0.45002},{0.36581,0.98702,0.43688},{0.38127,0.98909,0.42386},{0.39678,0.99098,0.41098},{0.41229,0.99268,0.39826},{0.42778,0.99419,0.38575},{0.44321,0.99551,0.37345},{0.45854,0.99663,0.36140},{0.47375,0.99755,0.34963},{0.48879,0.99828,0.33816},{0.50362,0.99879,0.32701},{0.51822,0.99910,0.31622},{0.53255,0.99919,0.30581},{0.54658,0.99907,0.29581},{0.56026,0.99873,0.28623},{0.57357,0.99817,0.27712},{0.58646,0.99739,0.26849},{0.59891,0.99638,0.26038},{0.61088,0.99514,0.25280},{0.62233,0.99366,0.24579},{0.63323,0.99195,0.23937},{0.64362,0.98999,0.23356},{0.65394,0.98775,0.22835},{0.66428,0.98524,0.22370},{0.67462,0.98246,0.21960},{0.68494,0.97941,0.21602},{0.69525,0.97610,0.21294},{0.70553,0.97255,0.21032},{0.71577,0.96875,0.20815},{0.72596,0.96470,0.20640},{0.73610,0.96043,0.20504},{0.74617,0.95593,0.20406},{0.75617,0.95121,0.20343},{0.76608,0.94627,0.20311},{0.77591,0.94113,0.20310},{0.78563,0.93579,0.20336},{0.79524,0.93025,0.20386},{0.80473,0.92452,0.20459},{0.81410,0.91861,0.20552},{0.82333,0.91253,0.20663},{0.83241,0.90627,0.20788},{0.84133,0.89986,0.20926},{0.85010,0.89328,0.21074},{0.85868,0.88655,0.21230},{0.86709,0.87968,0.21391},{0.87530,0.87267,0.21555},{0.88331,0.86553,0.21719},{0.89112,0.85826,0.21880},{0.89870,0.85087,0.22038},{0.90605,0.84337,0.22188},{0.91317,0.83576,0.22328},{0.92004,0.82806,0.22456},{0.92666,0.82025,0.22570},{0.93301,0.81236,0.22667},{0.93909,0.80439,0.22744},{0.94489,0.79634,0.22800},{0.95039,0.78823,0.22831},{0.95560,0.78005,0.22836},{0.96049,0.77181,0.22811},{0.96507,0.76352,0.22754},{0.96931,0.75519,0.22663},{0.97323,0.74682,0.22536},{0.97679,0.73842,0.22369},{0.98000,0.73000,0.22161},{0.98289,0.72140,0.21918},{0.98549,0.71250,0.21650},{0.98781,0.70330,0.21358},{0.98986,0.69382,0.21043},{0.99163,0.68408,0.20706},{0.99314,0.67408,0.20348},{0.99438,0.66386,0.19971},{0.99535,0.65341,0.19577},{0.99607,0.64277,0.19165},{0.99654,0.63193,0.18738},{0.99675,0.62093,0.18297},{0.99672,0.60977,0.17842},{0.99644,0.59846,0.17376},{0.99593,0.58703,0.16899},{0.99517,0.57549,0.16412},{0.99419,0.56386,0.15918},{0.99297,0.55214,0.15417},{0.99153,0.54036,0.14910},{0.98987,0.52854,0.14398},{0.98799,0.51667,0.13883},{0.98590,0.50479,0.13367},{0.98360,0.49291,0.12849},{0.98108,0.48104,0.12332},{0.97837,0.46920,0.11817},{0.97545,0.45740,0.11305},{0.97234,0.44565,0.10797},{0.96904,0.43399,0.10294},{0.96555,0.42241,0.09798},{0.96187,0.41093,0.09310},{0.95801,0.39958,0.08831},{0.95398,0.38836,0.08362},{0.94977,0.37729,0.07905},{0.94538,0.36638,0.07461},{0.94084,0.35566,0.07031},{0.93612,0.34513,0.06616},{0.93125,0.33482,0.06218},{0.92623,0.32473,0.05837},{0.92105,0.31489,0.05475},{0.91572,0.30530,0.05134},{0.91024,0.29599,0.04814},{0.90463,0.28696,0.04516},{0.89888,0.27824,0.04243},{0.89298,0.26981,0.03993},{0.88691,0.26152,0.03753},{0.88066,0.25334,0.03521},{0.87422,0.24526,0.03297},{0.86760,0.23730,0.03082},{0.86079,0.22945,0.02875},{0.85380,0.22170,0.02677},{0.84662,0.21407,0.02487},{0.83926,0.20654,0.02305},{0.83172,0.19912,0.02131},{0.82399,0.19182,0.01966},{0.81608,0.18462,0.01809},{0.80799,0.17753,0.01660},{0.79971,0.17055,0.01520},{0.79125,0.16368,0.01387},{0.78260,0.15693,0.01264},{0.77377,0.15028,0.01148},{0.76476,0.14374,0.01041},{0.75556,0.13731,0.00942},{0.74617,0.13098,0.00851},{0.73661,0.12477,0.00769},{0.72686,0.11867,0.00695},{0.71692,0.11268,0.00629},{0.70680,0.10680,0.00571},{0.69650,0.10102,0.00522},{0.68602,0.09536,0.00481},{0.67535,0.08980,0.00449},{0.66449,0.08436,0.00424},{0.65345,0.07902,0.00408},{0.64223,0.07380,0.00401},{0.63082,0.06868,0.00401},{0.61923,0.06367,0.00410},{0.60746,0.05878,0.00427},{0.59550,0.05399,0.00453},{0.58336,0.04931,0.00486},{0.57103,0.04474,0.00529},{0.55852,0.04028,0.00579},{0.54583,0.03593,0.00638},{0.53295,0.03169,0.00705},{0.51989,0.02756,0.00780},{0.50664,0.02354,0.00863},{0.49321,0.01963,0.00955},{0.47960,0.01583,0.01055}};
+
+
+
+
+// Lipari and Navia are the colormaps recommended by the Quantitative-MR Study Group of the ISMRM.
+// See
+// https://cig-utrecht.org/blog/2023/11/27/colormap-relaxometry.html
+// for more information.
+
+// These colormaps are licensed unser an MIT License by their creator:
+
+// The Scientific colour maps are licensed under a MIT License
+// Copyright (c) 2023, Fabio Crameri
+// Permission is hereby granted, free of charge, to any person ob
+// taining a copy of this software and associated documentation
+// files (the ”Software”), to deal in the Software without restric
+// tion, including without limitation the rights to use, copy, modify,
+// merge, publish, distribute, sublicense, and/or sell copies of the
+// Software, and to permit persons to whom the Software is fur
+// nished to do so, subject to the following conditions:
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// THE SOFTWARE IS PROVIDED ”AS IS”, WITHOUT WARRANTY OF
+// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
+// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
+// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN AC
+// TION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
+// OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+
+static const double lipari[256][3] = {{0.011370,0.073240,0.148284},{0.013965,0.079062,0.155370},{0.015899,0.084718,0.162521},{0.017234,0.090035,0.169728},{0.018046,0.095138,0.176970},{0.018987,0.100000,0.184274},{0.019970,0.104911,0.191606},{0.021000,0.109963,0.198961},{0.022084,0.114884,0.206390},{0.023227,0.119924,0.213776},{0.024440,0.124981,0.221213},{0.025732,0.130104,0.228657},{0.027114,0.135178,0.236104},{0.028602,0.140291,0.243540},{0.030209,0.145478,0.251025},{0.031951,0.150619,0.258480},{0.033828,0.155833,0.265955},{0.036137,0.161049,0.273414},{0.038425,0.166276,0.280837},{0.040951,0.171536,0.288282},{0.043537,0.176819,0.295697},{0.046467,0.182111,0.303085},{0.049594,0.187473,0.310472},{0.052785,0.192789,0.317790},{0.056373,0.198137,0.325072},{0.060123,0.203522,0.332335},{0.064059,0.208893,0.339525},{0.068323,0.214290,0.346641},{0.072795,0.219688,0.353691},{0.077499,0.225063,0.360661},{0.082595,0.230463,0.367551},{0.087912,0.235873,0.374351},{0.093441,0.241239,0.381025},{0.099307,0.246590,0.387560},{0.105413,0.251937,0.393974},{0.111813,0.257230,0.400242},{0.118433,0.262485,0.406341},{0.125243,0.267672,0.412263},{0.132308,0.272835,0.417985},{0.139522,0.277918,0.423506},{0.146980,0.282919,0.428820},{0.154569,0.287803,0.433888},{0.162316,0.292606,0.438725},{0.170138,0.297302,0.443314},{0.178074,0.301843,0.447622},{0.186034,0.306290,0.451681},{0.194038,0.310565,0.455448},{0.202008,0.314663,0.458938},{0.210000,0.318627,0.462138},{0.217939,0.322418,0.465058},{0.225808,0.326006,0.467698},{0.233544,0.329454,0.470063},{0.241213,0.332694,0.472151},{0.248744,0.335738,0.473965},{0.256094,0.338600,0.475542},{0.263329,0.341290,0.476858},{0.270378,0.343785,0.477950},{0.277238,0.346109,0.478825},{0.283919,0.348279,0.479499},{0.290422,0.350279,0.479979},{0.296766,0.352104,0.480280},{0.302897,0.353796,0.480422},{0.308898,0.355368,0.480419},{0.314684,0.356787,0.480285},{0.320355,0.358086,0.480032},{0.325830,0.359270,0.479670},{0.331185,0.360355,0.479208},{0.336416,0.361358,0.478660},{0.341527,0.362272,0.478039},{0.346516,0.363098,0.477353},{0.351412,0.363861,0.476608},{0.356223,0.364562,0.475814},{0.360933,0.365208,0.474974},{0.365601,0.365807,0.474080},{0.370195,0.366362,0.473154},{0.374753,0.366868,0.472216},{0.379261,0.367335,0.471236},{0.383746,0.367781,0.470232},{0.388198,0.368207,0.469210},{0.392637,0.368608,0.468151},{0.397066,0.368982,0.467095},{0.401502,0.369337,0.466002},{0.405945,0.369677,0.464911},{0.410391,0.370008,0.463798},{0.414838,0.370329,0.462661},{0.419318,0.370641,0.461530},{0.423806,0.370946,0.460367},{0.428335,0.371246,0.459212},{0.432886,0.371542,0.458027},{0.437471,0.371834,0.456836},{0.442084,0.372124,0.455637},{0.446721,0.372413,0.454430},{0.451402,0.372700,0.453200},{0.456112,0.372987,0.451972},{0.460861,0.373274,0.450722},{0.465644,0.373563,0.449468},{0.470480,0.373853,0.448196},{0.475346,0.374142,0.446922},{0.480239,0.374430,0.445630},{0.485169,0.374716,0.444348},{0.490149,0.375002,0.443038},{0.495165,0.375292,0.441725},{0.500209,0.375588,0.440391},{0.505298,0.375890,0.439053},{0.510431,0.376194,0.437723},{0.515595,0.376498,0.436363},{0.520808,0.376800,0.435003},{0.526060,0.377102,0.433614},{0.531345,0.377408,0.432248},{0.536679,0.377717,0.430847},{0.542039,0.378031,0.429441},{0.547450,0.378347,0.428030},{0.552900,0.378667,0.426602},{0.558389,0.378991,0.425175},{0.563937,0.379317,0.423722},{0.569504,0.379648,0.422267},{0.575126,0.379984,0.420807},{0.580790,0.380325,0.419345},{0.586496,0.380672,0.417860},{0.592251,0.381023,0.416371},{0.598033,0.381375,0.414871},{0.603878,0.381729,0.413368},{0.609753,0.382092,0.411849},{0.615676,0.382468,0.410336},{0.621644,0.382858,0.408797},{0.627665,0.383257,0.407260},{0.633729,0.383660,0.405726},{0.639835,0.384073,0.404170},{0.645983,0.384501,0.402616},{0.652186,0.384947,0.401076},{0.658430,0.385413,0.399501},{0.664720,0.385899,0.397959},{0.671065,0.386410,0.396398},{0.677455,0.386948,0.394848},{0.683877,0.387517,0.393300},{0.690355,0.388122,0.391767},{0.696877,0.388769,0.390232},{0.703442,0.389446,0.388729},{0.710045,0.390171,0.387222},{0.716690,0.390967,0.385745},{0.723361,0.391808,0.384300},{0.730077,0.392714,0.382885},{0.736813,0.393699,0.381501},{0.743578,0.394768,0.380152},{0.750358,0.395931,0.378850},{0.757152,0.397174,0.377604},{0.763951,0.398543,0.376424},{0.770753,0.400018,0.375287},{0.777544,0.401621,0.374250},{0.784314,0.403371,0.373272},{0.791048,0.405253,0.372388},{0.797746,0.407293,0.371603},{0.804395,0.409503,0.370926},{0.810973,0.411881,0.370362},{0.817473,0.414442,0.369920},{0.823879,0.417202,0.369609},{0.830181,0.420143,0.369436},{0.836353,0.423287,0.369406},{0.842390,0.426648,0.369526},{0.848263,0.430214,0.369804},{0.853968,0.433978,0.370247},{0.859490,0.437974,0.370858},{0.864803,0.442161,0.371642},{0.869899,0.446539,0.372604},{0.874767,0.451122,0.373748},{0.879389,0.455884,0.375054},{0.883761,0.460820,0.376553},{0.887860,0.465922,0.378203},{0.891692,0.471184,0.380033},{0.895246,0.476567,0.382020},{0.898512,0.482077,0.384174},{0.901498,0.487690,0.386470},{0.904197,0.493374,0.388928},{0.906618,0.499143,0.391507},{0.908756,0.504965,0.394202},{0.910625,0.510820,0.397017},{0.912225,0.516705,0.399943},{0.913575,0.522593,0.402968},{0.914675,0.528483,0.406078},{0.915540,0.534347,0.409251},{0.916190,0.540189,0.412504},{0.916636,0.546003,0.415797},{0.916889,0.551762,0.419152},{0.916963,0.557475,0.422534},{0.916874,0.563131,0.425965},{0.916636,0.568719,0.429427},{0.916264,0.574252,0.432909},{0.915775,0.579733,0.436411},{0.915186,0.585140,0.439927},{0.914509,0.590475,0.443461},{0.913754,0.595759,0.447003},{0.912931,0.600980,0.450565},{0.912059,0.606142,0.454139},{0.911148,0.611261,0.457722},{0.910211,0.616321,0.461331},{0.909249,0.621333,0.464954},{0.908289,0.626308,0.468602},{0.907326,0.631251,0.472281},{0.906374,0.636160,0.475986},{0.905445,0.641036,0.479732},{0.904539,0.645900,0.483509},{0.903673,0.650752,0.487354},{0.902853,0.655593,0.491251},{0.902079,0.660426,0.495194},{0.901366,0.665267,0.499209},{0.900717,0.670121,0.503303},{0.900141,0.674976,0.507492},{0.899641,0.679851,0.511757},{0.899223,0.684756,0.516121},{0.898892,0.689692,0.520598},{0.898654,0.694648,0.525185},{0.898515,0.699650,0.529889},{0.898480,0.704692,0.534713},{0.898551,0.709779,0.539663},{0.898735,0.714907,0.544759},{0.899033,0.720090,0.549990},{0.899448,0.725327,0.555359},{0.899981,0.730608,0.560882},{0.900635,0.735945,0.566560},{0.901414,0.741342,0.572384},{0.902319,0.746799,0.578354},{0.903350,0.752305,0.584490},{0.904502,0.757873,0.590772},{0.905785,0.763489,0.597217},{0.907189,0.769161,0.603808},{0.908714,0.774888,0.610543},{0.910365,0.780666,0.617427},{0.912129,0.786497,0.624458},{0.914016,0.792365,0.631624},{0.916005,0.798281,0.638924},{0.918116,0.804242,0.646354},{0.920324,0.810234,0.653908},{0.922640,0.816274,0.661585},{0.925046,0.822341,0.669369},{0.927548,0.828436,0.677263},{0.930142,0.834563,0.685252},{0.932811,0.840714,0.693336},{0.935565,0.846882,0.701504},{0.938387,0.853077,0.709763},{0.941274,0.859286,0.718088},{0.944228,0.865508,0.726484},{0.947235,0.871746,0.734943},{0.950290,0.877987,0.743453},{0.953394,0.884237,0.752011},{0.956533,0.890486,0.760613},{0.959709,0.896742,0.769246},{0.962913,0.902994,0.777919},{0.966140,0.909240,0.786616},{0.969388,0.915482,0.795324},{0.972654,0.921726,0.804056},{0.975921,0.927954,0.812794},{0.979202,0.934179,0.821550},{0.982484,0.940402,0.830308},{0.985762,0.946610,0.839070},{0.989038,0.952817,0.847836},{0.992307,0.959017,0.856609}};
+
+static const double navia[256][3] = {{0.013420,0.075817,0.152989},{0.015121,0.080634,0.159960},{0.016255,0.085228,0.167073},{0.016803,0.089716,0.174205},{0.016961,0.093990,0.181411},{0.017336,0.098133,0.188743},{0.017703,0.102263,0.196117},{0.018058,0.106514,0.203551},{0.018404,0.110739,0.211044},{0.018742,0.114975,0.218604},{0.019071,0.119327,0.226230},{0.019395,0.123667,0.233875},{0.019714,0.128112,0.241609},{0.020031,0.132548,0.249362},{0.020346,0.137020,0.257176},{0.020663,0.141543,0.265003},{0.020984,0.146080,0.272884},{0.021310,0.150645,0.280769},{0.021644,0.155250,0.288708},{0.021990,0.159855,0.296649},{0.022349,0.164550,0.304590},{0.022726,0.169252,0.312535},{0.023123,0.173933,0.320514},{0.023543,0.178678,0.328453},{0.023992,0.183406,0.336383},{0.024471,0.188212,0.344302},{0.024987,0.192980,0.352204},{0.025542,0.197784,0.360075},{0.026143,0.202606,0.367909},{0.026794,0.207462,0.375703},{0.027501,0.212323,0.383455},{0.028270,0.217191,0.391145},{0.029108,0.222061,0.398763},{0.030020,0.226972,0.406327},{0.031016,0.231888,0.413802},{0.032099,0.236810,0.421189},{0.033282,0.241728,0.428497},{0.034665,0.246655,0.435701},{0.036177,0.251620,0.442789},{0.037711,0.256558,0.449756},{0.039376,0.261524,0.456594},{0.041190,0.266493,0.463294},{0.042961,0.271453,0.469870},{0.045066,0.276447,0.476271},{0.047153,0.281406,0.482514},{0.049396,0.286374,0.488587},{0.051602,0.291371,0.494481},{0.053996,0.296335,0.500174},{0.056570,0.301290,0.505677},{0.059155,0.306271,0.510984},{0.061738,0.311207,0.516069},{0.064526,0.316148,0.520947},{0.067354,0.321058,0.525594},{0.070218,0.325940,0.530009},{0.073219,0.330814,0.534182},{0.076127,0.335670,0.538131},{0.079162,0.340477,0.541813},{0.082310,0.345245,0.545267},{0.085333,0.349976,0.548472},{0.088490,0.354659,0.551417},{0.091644,0.359270,0.554118},{0.094766,0.363832,0.556572},{0.097864,0.368336,0.558778},{0.100919,0.372752,0.560753},{0.104007,0.377108,0.562497},{0.107081,0.381374,0.564002},{0.110099,0.385537,0.565273},{0.113065,0.389625,0.566351},{0.115972,0.393615,0.567218},{0.118845,0.397510,0.567882},{0.121615,0.401307,0.568363},{0.124403,0.404991,0.568671},{0.127118,0.408585,0.568816},{0.129840,0.412081,0.568808},{0.132441,0.415470,0.568659},{0.135022,0.418767,0.568380},{0.137551,0.421970,0.567982},{0.139985,0.425101,0.567475},{0.142452,0.428133,0.566866},{0.144870,0.431091,0.566160},{0.147220,0.433959,0.565369},{0.149576,0.436782,0.564516},{0.151851,0.439525,0.563597},{0.154137,0.442220,0.562611},{0.156434,0.444849,0.561566},{0.158673,0.447417,0.560478},{0.160888,0.449959,0.559346},{0.163114,0.452457,0.558172},{0.165274,0.454907,0.556983},{0.167499,0.457313,0.555739},{0.169695,0.459700,0.554492},{0.171844,0.462052,0.553207},{0.174021,0.464387,0.551920},{0.176160,0.466681,0.550603},{0.178369,0.468960,0.549279},{0.180492,0.471215,0.547940},{0.182644,0.473440,0.546595},{0.184823,0.475673,0.545236},{0.186971,0.477869,0.543872},{0.189125,0.480063,0.542508},{0.191270,0.482238,0.541130},{0.193440,0.484393,0.539754},{0.195587,0.486551,0.538389},{0.197750,0.488697,0.537010},{0.199899,0.490844,0.535616},{0.202078,0.492957,0.534235},{0.204288,0.495093,0.532857},{0.206475,0.497214,0.531468},{0.208638,0.499326,0.530082},{0.210837,0.501454,0.528697},{0.213030,0.503562,0.527302},{0.215251,0.505676,0.525907},{0.217492,0.507811,0.524508},{0.219733,0.509929,0.523111},{0.221968,0.512056,0.521697},{0.224223,0.514200,0.520288},{0.226532,0.516330,0.518887},{0.228826,0.518491,0.517467},{0.231132,0.520642,0.516028},{0.233434,0.522815,0.514608},{0.235808,0.524993,0.513165},{0.238158,0.527190,0.511714},{0.240527,0.529397,0.510260},{0.242938,0.531613,0.508803},{0.245362,0.533842,0.507323},{0.247837,0.536101,0.505829},{0.250281,0.538380,0.504350},{0.252797,0.540662,0.502829},{0.255325,0.542974,0.501320},{0.257852,0.545302,0.499775},{0.260437,0.547651,0.498247},{0.263045,0.550026,0.496671},{0.265674,0.552426,0.495106},{0.268327,0.554845,0.493511},{0.271026,0.557299,0.491915},{0.273750,0.559769,0.490291},{0.276504,0.562275,0.488653},{0.279291,0.564792,0.487000},{0.282108,0.567358,0.485321},{0.284940,0.569938,0.483632},{0.287830,0.572565,0.481933},{0.290758,0.575210,0.480205},{0.293713,0.577887,0.478456},{0.296725,0.580608,0.476693},{0.299755,0.583353,0.474918},{0.302814,0.586141,0.473100},{0.305952,0.588949,0.471290},{0.309104,0.591813,0.469452},{0.312267,0.594697,0.467584},{0.315523,0.597624,0.465694},{0.318795,0.600585,0.463804},{0.322118,0.603591,0.461886},{0.325473,0.606628,0.459945},{0.328904,0.609705,0.457993},{0.332367,0.612819,0.456024},{0.335866,0.615981,0.454041},{0.339437,0.619188,0.452047},{0.343048,0.622419,0.450027},{0.346709,0.625704,0.447996},{0.350441,0.629031,0.445960},{0.354216,0.632401,0.443930},{0.358071,0.635814,0.441885},{0.361985,0.639273,0.439829},{0.365969,0.642778,0.437786},{0.370017,0.646328,0.435739},{0.374165,0.649930,0.433689},{0.378375,0.653574,0.431684},{0.382682,0.657277,0.429670},{0.387076,0.661018,0.427695},{0.391586,0.664815,0.425736},{0.396188,0.668672,0.423819},{0.400915,0.672578,0.421948},{0.405747,0.676534,0.420141},{0.410710,0.680539,0.418384},{0.415800,0.684609,0.416716},{0.421036,0.688741,0.415117},{0.426430,0.692921,0.413622},{0.431996,0.697151,0.412238},{0.437712,0.701442,0.410969},{0.443601,0.705794,0.409842},{0.449678,0.710198,0.408859},{0.455945,0.714651,0.408050},{0.462409,0.719165,0.407425},{0.469094,0.723723,0.407003},{0.475974,0.728332,0.406801},{0.483066,0.732990,0.406834},{0.490390,0.737682,0.407121},{0.497935,0.742421,0.407680},{0.505675,0.747187,0.408529},{0.513668,0.751981,0.409686},{0.521853,0.756797,0.411156},{0.530269,0.761628,0.412971},{0.538886,0.766471,0.415116},{0.547692,0.771318,0.417631},{0.556690,0.776152,0.420499},{0.565854,0.780975,0.423745},{0.575184,0.785778,0.427379},{0.584655,0.790546,0.431376},{0.594246,0.795277,0.435745},{0.603948,0.799967,0.440475},{0.613718,0.804596,0.445574},{0.623571,0.809166,0.451034},{0.633452,0.813660,0.456821},{0.643349,0.818084,0.462930},{0.653247,0.822434,0.469371},{0.663131,0.826693,0.476077},{0.672961,0.830863,0.483052},{0.682722,0.834941,0.490287},{0.692413,0.838924,0.497751},{0.701988,0.842817,0.505395},{0.711468,0.846607,0.513248},{0.720806,0.850311,0.521252},{0.730018,0.853916,0.529404},{0.739078,0.857435,0.537670},{0.747979,0.860865,0.546036},{0.756716,0.864214,0.554480},{0.765293,0.867473,0.562995},{0.773690,0.870656,0.571548},{0.781928,0.873770,0.580146},{0.789985,0.876809,0.588748},{0.797871,0.879788,0.597375},{0.805587,0.882702,0.605980},{0.813135,0.885563,0.614576},{0.820517,0.888367,0.623153},{0.827735,0.891117,0.631684},{0.834795,0.893822,0.640175},{0.841696,0.896485,0.648607},{0.848439,0.899102,0.656986},{0.855036,0.901678,0.665289},{0.861480,0.904216,0.673526},{0.867785,0.906721,0.681675},{0.873943,0.909184,0.689751},{0.879964,0.911616,0.697724},{0.885854,0.914016,0.705609},{0.891606,0.916374,0.713389},{0.897231,0.918701,0.721062},{0.902724,0.920996,0.728629},{0.908093,0.923262,0.736080},{0.913337,0.925486,0.743425},{0.918458,0.927676,0.750645},{0.923468,0.929837,0.757743},{0.928353,0.931959,0.764721},{0.933130,0.934048,0.771578},{0.937802,0.936108,0.778308},{0.942365,0.938126,0.784921},{0.946819,0.940114,0.791406},{0.951178,0.942064,0.797775},{0.955439,0.943981,0.804030},{0.959606,0.945864,0.810165},{0.963686,0.947720,0.816201},{0.967690,0.949541,0.822128},{0.971611,0.951338,0.827953},{0.975464,0.953108,0.833700},{0.979259,0.954852,0.839361},{0.982996,0.956574,0.844951},{0.986688,0.958281,0.850479}};
=====================================
src/draw.c
=====================================
@@ -38,14 +38,6 @@ static double window(double a, double b, double x)
return clamp(0., 1., (x - a) / (b - a));
}
-static void trans_magnitude(double rgb[3], double a, double b, complex double value)
-{
- double magn = window(a, b, cabs(value));
-
- rgb[0] *= magn;
- rgb[1] *= magn;
- rgb[2] *= magn;
-}
static void interpolate_cmap(double rgb[3], double x, const double cmap[256][3])
{
@@ -58,68 +50,74 @@ static void interpolate_cmap(double rgb[3], double x, const double cmap[256][3])
rgb[i] *= cmap[a][i] + f * (cmap[b][i] - cmap[a][i]);
}
-static void trans_magnitude_viridis(double rgb[3], double a, double b, complex double value)
-{
- double magn = window(a, b, cabs(value));
+typedef const double color_table_t[256][3];
+
+static color_table_t* ctables[] = {
+ [VIRIDIS] = &viridis,
+ [MYGBM] = &cyclic_mygbm,
+ [TURBO] = &turbo,
+ [LIPARI] = &lipari,
+ [NAVIA] = &navia,
+};
- interpolate_cmap(rgb, magn, viridis);
-}
-static void trans_magnitude_turbo(double rgb[3], double a, double b, complex double value)
+static void trans_magnitude(double rgb[3], enum color_t ctab, double a, double b, complex double value)
{
double magn = window(a, b, cabs(value));
- interpolate_cmap(rgb, magn, turbo);
+ switch (ctab) {
+
+ case NONE:
+
+ rgb[0] *= magn;
+ rgb[1] *= magn;
+ rgb[2] *= magn;
+ break;
+
+ default:
+
+ interpolate_cmap(rgb, magn, *ctables[ctab]);
+ break;
+ }
}
-static void trans_real(double rgb[3], double a, double b, complex double value)
+static void trans_real(double rgb[3], enum color_t /* ctab */, double a, double b, complex double value)
{
rgb[0] *= window(a, b, +creal(value));
rgb[1] *= window(a, b, -creal(value));
rgb[2] *= 0.;
}
-static void trans_phase(double rgb[3], double a, double b, complex double value)
-{
- UNUSED(a);
- UNUSED(b);
-
- rgb[0] *= (1. + sin(carg(value) + 0. * 2. * M_PI / 3.)) / 2.;
- rgb[1] *= (1. + sin(carg(value) + 1. * 2. * M_PI / 3.)) / 2.;
- rgb[2] *= (1. + sin(carg(value) + 2. * 2. * M_PI / 3.)) / 2.;
-}
-
-static void trans_phase_MYGBM(double rgb[3], double a, double b, complex double value)
+static void trans_phase(double rgb[3], enum color_t ctab, double /*a*/, double /*b*/, complex double value)
{
- UNUSED(a);
- UNUSED(b);
-
double arg = carg(value);
- if (isfinite(arg)) {
+ switch (ctab) {
+ case MYGBM:
double val = (arg + M_PI) / 2. / M_PI;
assert((0.0 <= val) && (val <= 1.0));
interpolate_cmap(rgb, val, cyclic_mygbm);
- }
-}
+ break;
-static void trans_complex(double rgb[3], double a, double b, complex double value)
-{
- trans_magnitude(rgb, a, b, value);
- trans_phase(rgb, a, b, value);
+ default:
+ rgb[0] *= (1. + sin(arg + 0. * 2. * M_PI / 3.)) / 2.;
+ rgb[1] *= (1. + sin(arg + 1. * 2. * M_PI / 3.)) / 2.;
+ rgb[2] *= (1. + sin(arg + 2. * 2. * M_PI / 3.)) / 2.;
+ break;
+ }
}
-static void trans_complex_MYGBM(double rgb[3], double a, double b, complex double value)
+static void trans_complex(double rgb[3], enum color_t ctab, double a, double b, complex double value)
{
- trans_magnitude(rgb, a, b, value);
- trans_phase_MYGBM(rgb, a, b, value);
+ trans_magnitude(rgb, NONE, a, b, value);
+ trans_phase(rgb, ctab, a, b, value);
}
-static void trans_flow(double rgb[3], double a, double b, complex double value)
+static void trans_flow(double rgb[3], enum color_t /* ctab */, double a, double b, complex double value)
{
- trans_magnitude(rgb, a, b, value);
+ trans_magnitude(rgb, NONE, a, b, value);
double pha = clamp(-1., 1., carg(value) / M_PI);
@@ -346,7 +344,7 @@ extern void resample(int X, int Y, long str, complex float* buf,
extern void draw(int X, int Y, int rgbstr, unsigned char (*rgbbuf)[Y][rgbstr / 4][4],
- enum mode_t mode, float scale, float winlow, float winhigh, float phrot,
+ enum mode_t mode, enum color_t ctab, float scale, float winlow, float winhigh, float phrot,
long str, const complex float* buf)
{
#pragma omp parallel for collapse(2)
@@ -363,15 +361,11 @@ extern void draw(int X, int Y, int rgbstr, unsigned char (*rgbbuf)[Y][rgbstr / 4
switch (mode) {
- case MAGN: trans_magnitude(rgb, winlow, winhigh, val); break;
- case MAGN_VIRIDS: trans_magnitude_viridis(rgb, winlow, winhigh, val); break;
- case PHSE: trans_phase(rgb, winlow, winhigh, val); break;
- case PHSE_MYGBM: trans_phase_MYGBM(rgb, winlow, winhigh, val); break;
- case CMPL: trans_complex(rgb, winlow, winhigh, val); break;
- case CMPL_MYGBM: trans_complex_MYGBM(rgb, winlow, winhigh, val); break;
- case REAL: trans_real(rgb, winlow, winhigh, val); break;
- case MAGN_TURBO: trans_magnitude_turbo(rgb, winlow, winhigh, val); break;
- case FLOW: trans_flow(rgb, winlow, winhigh, val); break;
+ case MAGN: trans_magnitude(rgb, ctab, winlow, winhigh, val); break;
+ case PHASE: trans_phase(rgb, ctab, winlow, winhigh, val); break;
+ case CMPLX: trans_complex(rgb, ctab, winlow, winhigh, val); break;
+ case REAL: trans_real(rgb, ctab, winlow, winhigh, val); break;
+ case FLOW: trans_flow(rgb, ctab, winlow, winhigh, val); break;
default: assert(0);
}
@@ -486,7 +480,7 @@ extern void draw_grid(int X, int Y, int rgbstr, unsigned char (*rgbbuf)[Y][rgbst
extern void draw_plot(int X, int Y, int rgbstr, unsigned char (*rgbbuf)[Y][rgbstr / 4][4],
- enum mode_t mode, float scale, float winlow, float winhigh, float phrot,
+ enum mode_t /* mode */, enum color_t /* ctab */, float scale, float winlow, float winhigh, float phrot,
long str, const complex float* buf)
{
unsigned char bg[4] = { 255, 255, 255, 0 };
=====================================
src/draw.h
=====================================
@@ -2,10 +2,7 @@
#include <complex.h>
#include <stdbool.h>
-
-enum mode_t { MAGN, MAGN_VIRIDS, CMPL, CMPL_MYGBM, PHSE, PHSE_MYGBM, REAL, MAGN_TURBO, FLOW };
-enum flip_t { OO, XO, OY, XY };
-enum interp_t { NLINEAR, NLINEARMAG, NEAREST, LIINCO };
+#include "view.h"
extern complex float sample(int N, const float pos[N], const long dims[N], const long strs[N], enum interp_t interpolation, const complex float* in);
@@ -14,11 +11,11 @@ extern void resample(int X, int Y, long str, complex float* buf,
const long dims[N], const long strs[N], enum interp_t interpolation, const complex float* in);
extern void draw(int X, int Y, int rgbstr, unsigned char (*rgbbuf)[Y][rgbstr / 4][4],
- enum mode_t mode, float scale, float winlow, float winhigh, float phrot,
+ enum mode_t mode, enum color_t ctab, float scale, float winlow, float winhigh, float phrot,
long str, const complex float* buf);
extern void draw_plot(int X, int Y, int rgbstr, unsigned char (*rgbbuf)[Y][rgbstr / 4][4],
- enum mode_t mode, float scale, float winlow, float winhigh, float phrot,
+ enum mode_t mode, enum color_t ctab, float scale, float winlow, float winhigh, float phrot,
long str, const complex float* buf);
extern void update_buf(long xdim, long ydim, int N, const long dims[N], const long strs[N], const long pos[N],
=====================================
src/gtk_ui.c
=====================================
@@ -0,0 +1,563 @@
+/* Copyright 2015-2019. Martin Uecker.
+ * Copyright 2023-2024. TU Graz. Institute of Biomedical Imaging.
+ * All rights reserved. Use of this source code is governed by
+ * a BSD-style license which can be found in the LICENSE file.
+ */
+
+#define _GNU_SOURCE
+
+#include <gtk/gtk.h>
+#include <pango/pango.h>
+#include <pango/pangocairo.h>
+#include <cairo.h>
+#undef MIN
+#undef MAX
+#undef CLAMP
+
+#include <libgen.h>
+#include <string.h>
+
+#include "gtk_ui.h"
+#include "view.h"
+
+#include "misc/misc.h"
+
+#ifndef STRINGIFY
+#define STRINGIFY(x) # x
+#endif
+const char* viewer_gui =
+#include "viewer.inc"
+;
+
+
+struct view_gtk_ui_s {
+
+ // UI
+ cairo_surface_t* source;
+
+ // widgets
+ GtkComboBox* gtk_mode;
+ GtkComboBox* gtk_flip;
+ GtkComboBox* gtk_interp;
+ GtkWidget* gtk_drawingarea;
+ GtkWidget* gtk_viewport;
+ GtkAdjustment* gtk_winlow;
+ GtkAdjustment* gtk_winhigh;
+ GtkSpinButton* gtk_button_winlow;
+ GtkSpinButton* gtk_button_winhigh;
+ GtkToolItem* toolbar_scale1;
+ GtkToolItem* toolbar_scale2;
+ GtkToolItem* toolbar_button1;
+ GtkToolItem* toolbar_button2;
+ GtkAdjustment* gtk_zoom;
+ GtkAdjustment* gtk_aniso;
+ GtkEntry* gtk_entry;
+ GtkToggleToolButton* gtk_transpose;
+ GtkToggleToolButton* gtk_fit;
+ GtkToggleToolButton* gtk_sync;
+ GtkToggleToolButton* gtk_absolutewindowing;
+
+ GtkAdjustment* gtk_posall[DIMS];
+ GtkCheckButton* gtk_checkall[DIMS];
+
+ GtkWidget *dialog; // Save dialog
+ GtkFileChooser *chooser; // Save dialog
+ GtkWindow *window;
+};
+
+
+extern gboolean fit_callback(GtkWidget* /*widget*/, gpointer data)
+{
+ struct view_s* v = data;
+
+ if (!view_acquire(v, false))
+ return FALSE;
+
+ ui_configure(v);
+
+ view_release(v);
+
+ return FALSE;
+}
+
+
+extern gboolean configure_callback(GtkWidget *widget, GdkEvent* /*event*/, gpointer data)
+{
+ return fit_callback(widget, data);
+}
+
+extern gboolean geom_callback(GtkWidget* widget, gpointer data)
+{
+ struct view_s* v = data;
+
+ if (!view_acquire(v,false))
+ return FALSE;
+
+ long pos[DIMS];
+ bool selected[DIMS];
+
+ for (int j = 0; j < DIMS; j++) {
+
+ pos[j] = gtk_adjustment_get_value(v->ui->gtk_posall[j]);
+ selected[j] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(v->ui->gtk_checkall[j]));
+ }
+
+ double zoom = gtk_adjustment_get_value(v->ui->gtk_zoom);
+
+ if (GTK_IS_RANGE(widget) && (gtk_range_get_adjustment(GTK_RANGE(widget)) == v->ui->gtk_zoom))
+ gtk_toggle_tool_button_set_active(v->ui->gtk_fit, FALSE);
+
+ double aniso = gtk_adjustment_get_value(v->ui->gtk_aniso);
+
+ if (v->settings.plot && GTK_IS_RANGE(widget) && (gtk_range_get_adjustment(GTK_RANGE(widget)) == v->ui->gtk_aniso))
+ gtk_toggle_tool_button_set_active(v->ui->gtk_fit, FALSE);
+
+ bool transpose = gtk_toggle_tool_button_get_active(v->ui->gtk_transpose);
+
+ enum flip_t flip = gtk_combo_box_get_active(v->ui->gtk_flip);
+ enum interp_t interp = gtk_combo_box_get_active(v->ui->gtk_interp);
+
+ view_geom(v, selected, pos, zoom, aniso, transpose, flip, interp);
+
+ view_release(v);
+
+ return FALSE;
+}
+
+extern gboolean refresh_callback(GtkWidget* /*widget*/, gpointer data)
+{
+ struct view_s* v = data;
+
+ if (!view_acquire(v, false))
+ return FALSE;
+
+ view_refresh(data);
+
+ view_release(v);
+
+ return FALSE;
+}
+
+extern gboolean window_callback(GtkWidget* /*widget*/, gpointer data)
+{
+ struct view_s* v = data;
+
+ enum mode_t mode = gtk_combo_box_get_active(v->ui->gtk_mode);
+ double winlow = gtk_adjustment_get_value(v->ui->gtk_winlow);
+ double winhigh = gtk_adjustment_get_value(v->ui->gtk_winhigh);
+
+ if (!view_acquire(v, false))
+ return FALSE;
+
+ view_window(v, mode, winlow, winhigh);
+
+ view_release(v);
+
+ return FALSE;
+}
+
+extern gboolean save_callback(GtkWidget* /*widget*/, gpointer data)
+{
+ struct view_s* v = data;
+
+ char* name = construct_filename_view2(v);
+
+ v->ui->dialog = gtk_file_chooser_dialog_new("Save File",
+ v->ui->window,
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ "Cancel",
+ GTK_RESPONSE_CANCEL,
+ "Save",
+ GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ v->ui->chooser = GTK_FILE_CHOOSER(v->ui->dialog);
+
+ gtk_file_chooser_set_current_name(v->ui->chooser, basename(name));
+
+ char* dname = strdup(v->name);
+
+ // Outputfolder = Inputfolder
+ gtk_file_chooser_set_current_folder(v->ui->chooser, dirname(dname));
+ gtk_file_chooser_set_do_overwrite_confirmation(v->ui->chooser, TRUE);
+
+ gint res = gtk_dialog_run(GTK_DIALOG(v->ui->dialog));
+
+ if (!view_acquire(v, true))
+ return FALSE;
+
+ if (GTK_RESPONSE_ACCEPT == res) {
+
+ // export single image
+ char *filename = gtk_file_chooser_get_filename(v->ui->chooser);
+
+ if (view_save_png(v, filename))
+ gtk_entry_set_text(v->ui->gtk_entry, "Error: writing image file.\n");
+
+ gtk_entry_set_text(v->ui->gtk_entry, "Saved!");
+
+ g_free(filename);
+ }
+
+ view_release(v);
+
+ gtk_widget_destroy (v->ui->dialog);
+
+ xfree(name);
+ xfree(dname);
+
+ return FALSE;
+}
+
+extern gboolean save_movie_callback(GtkWidget* /*widget*/, gpointer data)
+{
+ struct view_s* v = data;
+
+ v->ui->dialog = gtk_file_chooser_dialog_new("Export movie to folder",
+ v->ui->window,
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ "Cancel",
+ GTK_RESPONSE_CANCEL,
+ "Export",
+ GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ v->ui->chooser = GTK_FILE_CHOOSER(v->ui->dialog);
+
+
+ char* dname = strdup(v->name);
+
+ // Outputfolder = Inputfolder
+ gtk_file_chooser_set_current_folder(v->ui->chooser, dirname(dname));
+
+ gint res = gtk_dialog_run(GTK_DIALOG (v->ui->dialog));
+
+ if (!view_acquire(v, true))
+ return FALSE;
+
+ if (GTK_RESPONSE_ACCEPT == res) {
+
+ char *chosen_dir = gtk_file_chooser_get_filename(v->ui->chooser);
+
+ if (view_save_pngmovie(v, chosen_dir))
+ gtk_entry_set_text(v->ui->gtk_entry, "Movie exported.");
+ else
+ gtk_entry_set_text(v->ui->gtk_entry, "Movie export FAILED.");
+
+ g_free(chosen_dir);
+ }
+
+ view_release(v);
+
+ gtk_widget_destroy (v->ui->dialog);
+
+ xfree(dname);
+
+ return FALSE;
+}
+
+extern gboolean motion_callback(GtkWidget* /*widget*/, GdkEventMotion *event, gpointer data)
+{
+ struct view_s* v = data;
+
+ if (!view_acquire(v, false))
+ return FALSE;
+
+ double inc_low = gtk_adjustment_get_step_increment(v->ui->gtk_winlow);
+ double inc_high = gtk_adjustment_get_step_increment(v->ui->gtk_winhigh);
+
+ view_motion(v, event->x, event->y, inc_low, inc_high, (event->state & GDK_BUTTON1_MASK) ? 1 : 0);
+
+ view_release(v);
+
+ return FALSE;
+}
+
+extern gboolean click_callback(GtkWidget* /*widget*/, GdkEventButton *event, gpointer data)
+{
+ struct view_s* v = data;
+
+ if (!view_acquire(v, false))
+ return FALSE;
+
+ if (event->button == GDK_BUTTON_PRIMARY)
+ view_click(v, event->x, event->y, 1);
+
+ if (event->button == GDK_BUTTON_SECONDARY)
+ view_click(v, event->x, event->y, 2);
+
+ view_release(v);
+
+ return FALSE;
+}
+
+extern gboolean show_hide_callback(GtkWidget *widget, GtkCheckButton* button)
+{
+ gboolean flag = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(button));
+
+ (flag ? gtk_widget_show : gtk_widget_hide)(widget);
+
+ return FALSE;
+}
+
+extern gboolean window_close_callback(GtkWidget* /*widget*/, GdkEvent* /*event*/, gpointer data)
+{
+ struct view_s* v = data;
+
+ view_window_close(v);
+
+ return FALSE;
+}
+
+extern gboolean window_clone_callback(GtkWidget* /*widget*/, gpointer data)
+{
+ struct view_s* v = data;
+
+ view_window_clone(v);
+
+ return FALSE;
+}
+
+extern gboolean draw_callback(GtkWidget* /*widget*/, cairo_t *cr, gpointer data)
+{
+ struct view_s* v = data;
+ view_acquire(v, true);
+
+ view_draw(v);
+
+ cairo_set_source_surface(cr, v->ui->source, 0, 0);
+ cairo_paint(cr);
+
+ view_release(v);
+
+ return FALSE;
+}
+
+extern gboolean toggle_sync_callback(GtkToggleButton* /*button*/, gpointer data)
+{
+ struct view_s* v = data;
+
+ if (!view_acquire(v, true))
+ return FALSE;
+
+ v->sync = gtk_toggle_tool_button_get_active(v->ui->gtk_sync);
+
+ view_release(v);
+
+ return FALSE;
+}
+
+extern gboolean toggle_plot_callback(GtkToggleButton* /*button*/, gpointer data)
+{
+ struct view_s* v = data;
+
+ if (!view_acquire(v, true))
+ return FALSE;
+
+ view_toggle_plot(v);
+
+ view_release(v);
+
+ return FALSE;
+}
+
+extern gboolean toogle_absolute_windowing_callback(GtkToggleToolButton* button, gpointer data)
+{
+ struct view_s* v = data;
+
+ if (!view_acquire(v, true))
+ return FALSE;
+
+ view_toggle_absolute_windowing(v, (TRUE == gtk_toggle_tool_button_get_active(button)));
+
+ view_release(v);
+
+ return FALSE;
+}
+
+static gboolean io_callback(GIOChannel * /* gio_channel */, GIOCondition giocondition, gpointer data)
+{
+ struct io_callback_data* cb = data;
+
+ if (G_IO_IN != giocondition)
+ return FALSE;
+
+ cb->f(cb->context);
+
+ return TRUE;
+}
+
+
+extern void ui_configure(struct view_s *v)
+{
+ gboolean flag = gtk_toggle_tool_button_get_active(v->ui->gtk_fit);
+
+ if (!flag)
+ return;
+
+ GtkAllocation alloc;
+ gtk_widget_get_allocation(v->ui->gtk_viewport, &alloc);
+
+ view_fit(v, alloc.width, alloc.height);
+}
+
+void ui_trigger_redraw(struct view_s* v)
+{
+ gtk_widget_queue_draw(v->ui->gtk_drawingarea);
+}
+
+void ui_rgbbuffer_disconnect(struct view_s* v)
+{
+ if (NULL != v->ui->source)
+ cairo_surface_destroy(v->ui->source);
+}
+
+void ui_rgbbuffer_connect(struct view_s* v, int rgbw, int rgbh, int rgbstr, unsigned char *buf)
+{
+ gtk_widget_set_size_request(v->ui->gtk_drawingarea, rgbw, rgbh);
+
+ v->ui->source = cairo_image_surface_create_for_data(buf, CAIRO_FORMAT_RGB24, rgbw, rgbh, rgbstr);
+}
+
+void ui_set_msg(struct view_s* v, const char* msg)
+{
+ gtk_entry_set_text(v->ui->gtk_entry, msg);
+}
+
+void ui_window_new(struct view_s* v, int N, const long dims[N], const struct view_settings_s settings)
+{
+ v->ui = xmalloc(sizeof(struct view_gtk_ui_s));
+
+ for (int i = 0; i < DIMS; i++)
+ v->ui_params.selected[i] = (i == settings.xdim || i == settings.ydim);
+
+ v->ui->source = NULL;
+
+ GtkBuilder* builder = gtk_builder_new();
+ gtk_builder_add_from_string(builder, viewer_gui, -1, NULL);
+
+ v->ui->gtk_drawingarea = GTK_WIDGET(gtk_builder_get_object(builder, "drawingarea1"));
+ v->ui->gtk_viewport = GTK_WIDGET(gtk_builder_get_object(builder, "scrolledwindow1"));
+
+ v->ui->gtk_winlow = GTK_ADJUSTMENT(gtk_builder_get_object(builder, "winlow"));
+ v->ui->gtk_winhigh = GTK_ADJUSTMENT(gtk_builder_get_object(builder, "winhigh"));
+
+ v->ui->gtk_entry = GTK_ENTRY(gtk_builder_get_object(builder, "entry"));
+
+ v->ui->gtk_zoom = GTK_ADJUSTMENT(gtk_builder_get_object(builder, "zoom"));
+ v->ui->gtk_aniso = GTK_ADJUSTMENT(gtk_builder_get_object(builder, "aniso"));
+ v->ui->gtk_mode = GTK_COMBO_BOX(gtk_builder_get_object(builder, "mode"));
+ gtk_combo_box_set_active(v->ui->gtk_mode, settings.mode);
+
+ v->ui->gtk_flip = GTK_COMBO_BOX(gtk_builder_get_object(builder, "flip"));
+ gtk_combo_box_set_active(v->ui->gtk_flip, settings.flip);
+
+ v->ui->gtk_interp = GTK_COMBO_BOX(gtk_builder_get_object(builder, "interp"));
+ gtk_combo_box_set_active(v->ui->gtk_interp, settings.interpolation);
+
+ v->ui->gtk_transpose = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(builder, "transpose"));
+ gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(v->ui->gtk_transpose), TRUE);
+
+ v->ui->gtk_fit = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(builder, "fit"));
+ gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(v->ui->gtk_fit), TRUE);
+
+ v->ui->gtk_sync = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(builder, "sync"));
+ gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(v->ui->gtk_sync), v->sync ? TRUE : FALSE);
+
+ v->ui->gtk_button_winlow = GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "scale1_button"));
+ v->ui->gtk_button_winhigh = GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "scale2_button"));
+
+ v->ui->toolbar_scale1 = GTK_TOOL_ITEM(gtk_builder_get_object(builder, "toolbar_scale1"));
+ v->ui->toolbar_scale2 = GTK_TOOL_ITEM(gtk_builder_get_object(builder, "toolbar_scale2"));
+ v->ui->toolbar_button1 = GTK_TOOL_ITEM(gtk_builder_get_object(builder, "toolbar_button1"));
+ v->ui->toolbar_button2 = GTK_TOOL_ITEM(gtk_builder_get_object(builder, "toolbar_button2"));
+
+ v->ui->gtk_absolutewindowing = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(builder, "abswindow"));
+ gtk_toggle_tool_button_set_active(v->ui->gtk_absolutewindowing, settings.absolute_windowing ? TRUE : FALSE);
+
+ for (int j = 0; j < DIMS; j++) {
+
+ char pname[10];
+ snprintf(pname, 10, "pos%02d", j);
+
+ v->ui->gtk_posall[j] = GTK_ADJUSTMENT(gtk_builder_get_object(builder, pname));
+ gtk_adjustment_set_upper(v->ui->gtk_posall[j], dims[j] - 1);
+
+ snprintf(pname, 10, "check%02d", j);
+
+ v->ui->gtk_checkall[j] = GTK_CHECK_BUTTON(gtk_builder_get_object(builder, pname));
+ }
+
+ gtk_builder_connect_signals(builder, v);
+
+ GtkWindow* window = GTK_WINDOW(gtk_builder_get_object(builder, "window1"));
+
+ g_object_unref(G_OBJECT(builder));
+
+ v->ui->window = window;
+
+ gtk_window_set_title(window, v->name);
+ gtk_widget_show(GTK_WIDGET(window));
+}
+
+void ui_init(int* argc_p, char** argv_p[])
+{
+ gtk_disable_setlocale();
+ gtk_init(argc_p, argv_p);
+}
+
+void ui_main()
+{
+ gtk_main();
+}
+
+void ui_loop_quit()
+{
+ gtk_main_quit();
+}
+
+void ui_add_io_callback(int fd, struct io_callback_data* cb)
+{
+ GIOChannel* giochannel_strm = g_io_channel_unix_new(fd);
+ g_io_add_watch(giochannel_strm, G_IO_IN | G_IO_HUP | G_IO_ERR, io_callback, cb);
+}
+
+
+bool gtk_ui_save_png(struct view_s* v, const char* filename)
+{
+ return (CAIRO_STATUS_SUCCESS != cairo_surface_write_to_png(v->ui->source, filename));
+}
+
+void ui_set_params(struct view_s* v, struct view_ui_params_s params, struct view_settings_s img_params)
+{
+ for (int j = 0; j < DIMS; j++) {
+
+ bool selected = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(v->ui->gtk_checkall[j]));
+
+ if (selected != params.selected[j])
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(v->ui->gtk_checkall[j]), params.selected[j] ? TRUE : FALSE);
+
+ gtk_adjustment_set_value(v->ui->gtk_posall[j], img_params.pos[j]);
+ }
+
+ gtk_adjustment_set_value(v->ui->gtk_zoom, params.zoom);
+
+ gtk_adjustment_set_value(v->ui->gtk_aniso, params.aniso);
+
+ gtk_widget_set_sensitive(GTK_WIDGET(v->ui->gtk_mode),
+ img_params.plot ? FALSE : TRUE);
+
+ gtk_adjustment_configure(v->ui->gtk_winhigh, img_params.winhigh, 0, params.windowing_max, params.windowing_inc,
+ gtk_adjustment_get_page_increment(v->ui->gtk_winhigh), gtk_adjustment_get_page_size(v->ui->gtk_winhigh));
+ gtk_adjustment_configure(v->ui->gtk_winlow, img_params.winlow, 0, params.windowing_max, params.windowing_inc,
+ gtk_adjustment_get_page_increment(v->ui->gtk_winlow), gtk_adjustment_get_page_size(v->ui->gtk_winlow));
+
+ gtk_spin_button_set_digits(v->ui->gtk_button_winhigh, params.windowing_digits);
+ gtk_spin_button_set_digits(v->ui->gtk_button_winlow, params.windowing_digits);
+
+ gtk_widget_set_visible(GTK_WIDGET(v->ui->toolbar_scale1), img_params.absolute_windowing ? FALSE : TRUE);
+ gtk_widget_set_visible(GTK_WIDGET(v->ui->toolbar_scale2), img_params.absolute_windowing ? FALSE : TRUE);
+ gtk_widget_set_visible(GTK_WIDGET(v->ui->toolbar_button1), img_params.absolute_windowing ? TRUE : FALSE);
+ gtk_widget_set_visible(GTK_WIDGET(v->ui->toolbar_button2), img_params.absolute_windowing ? TRUE : FALSE);
+}
+
=====================================
src/gtk_ui.h
=====================================
@@ -0,0 +1,35 @@
+
+#include <stdbool.h>
+
+struct view_s;
+struct view_ui_params_s;
+struct view_settings_s;
+
+typedef void (*io_callback_function)(void *);
+
+struct io_callback_data {
+
+ io_callback_function f;
+ void* context;
+};
+
+extern void ui_rgbbuffer_disconnect(struct view_s* v);
+extern void ui_rgbbuffer_connect(struct view_s* v, int rgbw, int rgbh, int rgbstr, unsigned char* buf);
+
+void ui_set_params(struct view_s* v, struct view_ui_params_s params, struct view_settings_s img_params);
+
+extern void ui_set_msg(struct view_s* v, const char* msg);
+
+extern void ui_window_new(struct view_s* v, int N, const long dims[N], const struct view_settings_s settings);
+
+extern void ui_main();
+extern void ui_init(int* argc_p, char** argv_p[]);
+extern void ui_loop_quit();
+
+extern void ui_configure(struct view_s* v);
+extern void ui_trigger_redraw(struct view_s* v);
+
+void ui_add_io_callback(int fd, struct io_callback_data* cb);
+
+extern bool gtk_ui_save_png(struct view_s* v, const char* filename);
+
=====================================
src/main.c
=====================================
@@ -1,4 +1,5 @@
/* Copyright 2015-2023. Martin Uecker.
+ * Copyright 2023-2024. TU Graz. Institute of Biomedical Imaging.
* All rights reserved. Use of this source code is governed by
* a BSD-style license which can be found in the LICENSE file.
*/
@@ -6,14 +7,18 @@
#include <complex.h>
#include <string.h>
-#include <gtk/gtk.h>
-
-#undef MAX
-#undef MIN
+#include "num/multind.h"
#include "misc/misc.h"
#include "misc/mmio.h"
#include "misc/opts.h"
+
+#if defined __has_include
+#if __has_include ("misc/stream.h")
+#define HAS_BART_STREAM
+#endif
+#endif
+
#if 0
#include "misc/io.h"
#else
@@ -22,6 +27,7 @@ extern void io_unregister(const char* name);
#endif
#include "view.h"
+#include "gtk_ui.h"
@@ -30,11 +36,14 @@ static const char help_str[] = "View images.";
int main(int argc, char* argv[argc])
{
- gtk_disable_setlocale();
- gtk_init(&argc, &argv);
-
+// unused was remove in newer versionf of bart, use it detect new version
+#ifdef UNUSED
long count;
+#else
+ int count;
+#endif
const char** in_files;
+ int realtime = -1;
struct arg_s args[] = {
@@ -42,14 +51,27 @@ int main(int argc, char* argv[argc])
};
bool absolute_windowing = false;
+ enum color_t ctab = NONE;;
const struct opt_s opts[] = {
OPT_SET('a', &absolute_windowing, "Use absolute windowing"),
+ OPT_SELECT('V', enum color_t, &ctab, VIRIDIS, "viridis"),
+ OPT_SELECT('Y', enum color_t, &ctab, MYGBM, "MYGBM"),
+ OPT_SELECT('T', enum color_t, &ctab, TURBO, "turbo"),
+ OPT_SELECT('L', enum color_t, &ctab, LIPARI, "lipari"),
+ OPT_SELECT('N', enum color_t, &ctab, NAVIA, "navia"),
+
+#ifdef HAS_BART_STREAM
+ OPTL_INT(0, "real-time", &realtime, "n", "Realtime Input along axis n"),
+#endif
};
cmdline(&argc, argv, ARRAY_SIZE(args), args, help_str, ARRAY_SIZE(opts), opts);
+ // We initialize the UI after cmdline(), so that we can run '-h' without needing a display
+ ui_init(&argc, &argv);
+
struct view_s* v = NULL;
for (int i = 0; i < count; i++) {
@@ -66,6 +88,7 @@ int main(int argc, char* argv[argc])
*/
io_unregister(in_files[i]);
+
char* dot = strrchr(in_files[i], '.');
if ((NULL != dot) && ( !strcmp(dot, ".cfl")
@@ -73,13 +96,32 @@ int main(int argc, char* argv[argc])
|| !strcmp(dot, ".")))
*dot = '\0';
+
io_reserve_input(in_files[i]);
+
+#ifdef HAS_BART_STREAM
+ complex float* x = ((0 <= realtime) ? load_async_cfl : load_cfl)(in_files[i], DIMS, dims);
+#else
complex float* x = load_cfl(in_files[i], DIMS, dims);
+#endif
+ long pos[DIMS] = { 0 };
+ for (int i = 0; i < 3; i++)
+ pos[i] = dims[i] / 2;
+#ifdef HAS_BART_STREAM
+ // absolute windowing for realtime. avoids access to 'unsynced'
+ // memory when calculating the windowing
+ if (0 <= realtime) {
+ absolute_windowing = true;
+
+ // don't set position for streamed dimension.
+ md_select_strides(DIMS, ~MD_BIT(realtime), pos, pos);
+ }
+#endif
// FIXME: we never delete them
- struct view_s* v2 = window_new(in_files[i], NULL, dims, x, absolute_windowing);
+ struct view_s* v2 = window_new(in_files[i], pos, dims, x, absolute_windowing, ctab, realtime);
// If multiple files are passed on the commandline, add them to window
// list. This enables sync of windowing and so on...
@@ -94,7 +136,8 @@ int main(int argc, char* argv[argc])
}
}
- gtk_main();
+ ui_main();
return 0;
}
+
=====================================
src/view.c
=====================================
@@ -1,23 +1,18 @@
-/* Copyright 2015-2016. Martin Uecker.
+/* Copyright 2015-2019. Martin Uecker.
+ * Copyright 2023-2024. TU Graz. Institute of Biomedical Imaging.
* All rights reserved. Use of this source code is governed by
* a BSD-style license which can be found in the LICENSE file.
*/
#define _GNU_SOURCE
-#include <unistd.h>
#include <complex.h>
#include <stdbool.h>
#include <math.h>
+#include <stdatomic.h>
+#include <threads.h>
+#include <stdio.h>
-#include <libgen.h>
-
-#include <gtk/gtk.h>
-#include <pango/pango.h>
-#include <pango/pangocairo.h>
-#include <cairo.h>
-
-#undef MAX
-#undef MIN
+#include "gtk_ui.h"
#include "num/multind.h"
@@ -25,105 +20,70 @@
#include "misc/png.h"
#include "misc/debug.h"
+#ifdef __has_include
+#if __has_include ("misc/stream.h")
+#define HAS_BART_STREAM
+#include "misc/stream.h"
+#endif
+#endif
+
#include "draw.h"
#include "view.h"
+
#ifndef DIMS
#define DIMS 16
#endif
-#define STRINGIFY(x) # x
-const char* viewer_gui =
-#include "viewer.inc"
-;
-
-struct view_s {
-
- struct view_s* next;
- struct view_s* prev;
- bool sync;
+struct view_control_s {
- bool cross_hair;
- bool status_bar;
-
- const char* name;
+ // change-management
+ bool invalid;
+ bool rgb_invalid;
- // geometry
- long* pos; //[DIMS];
- int xdim;
- int ydim;
- double xzoom;
- double yzoom;
- enum flip_t flip;
- bool transpose;
+ //data
+ long dims[DIMS];
+ long strs[DIMS];
+ const complex float* data;
- // representation
- bool plot;
- bool absolute_windowing;
- enum mode_t mode;
- double winhigh;
- double winlow;
- double phrot;
- double max;
- enum interp_t interpolation;
+ int realtime;
+ struct io_callback_data rt_callback;
+ // interpolation buffer
complex float* buf;
- cairo_surface_t* source;
-
// rgb buffer
int rgbh;
int rgbw;
int rgbstr;
unsigned char* rgb;
- bool invalid;
- bool rgb_invalid;
-
- // data
- long dims[DIMS];
- long strs[DIMS];
- const complex float* data;
// geometry
unsigned long geom_flags;
const float (*geom)[3][3];
const float (*geom_current)[3][3];
- // widgets
- GtkComboBox* gtk_mode;
- GtkComboBox* gtk_flip;
- GtkComboBox* gtk_interp;
- GtkWidget* gtk_drawingarea;
- GtkWidget* gtk_viewport;
- GtkAdjustment* gtk_winlow;
- GtkAdjustment* gtk_winhigh;
- GtkSpinButton* gtk_button_winlow;
- GtkSpinButton* gtk_button_winhigh;
- GtkToolItem* toolbar_scale1;
- GtkToolItem* toolbar_scale2;
- GtkToolItem* toolbar_button1;
- GtkToolItem* toolbar_button2;
- GtkAdjustment* gtk_zoom;
- GtkAdjustment* gtk_aniso;
- GtkEntry* gtk_entry;
- GtkToggleToolButton* gtk_transpose;
- GtkToggleToolButton* gtk_fit;
- GtkToggleToolButton* gtk_sync;
- GtkToggleToolButton* gtk_absolutewindowing;
-
- GtkAdjustment* gtk_posall[DIMS];
- GtkCheckButton* gtk_checkall[DIMS];
-
- GtkWidget *dialog; // Save dialog
- GtkFileChooser *chooser; // Save dialog
- GtkWindow *window;
-
// windowing
int lastx;
int lasty;
+
+ // misc
+ bool status_bar;
+ double max;
+
+ mtx_t mx;
+
+ bool transpose;
};
+static void view_window_nosync(struct view_s* v, enum mode_t mode, double winlow, double winhigh);
+static void view_geom2(struct view_s* v);
+
+#ifdef HAS_BART_STREAM
+static void add_rt_callback(struct view_s *ptr);
+static void view_ff_realtime_position(void *v);
+#endif
#if 0
static void add_text(cairo_surface_t* surface, int x, int y, int size, const char* text)
@@ -154,115 +114,80 @@ static void add_text(cairo_surface_t* surface, int x, int y, int size, const cha
}
#endif
-extern void update_geom(struct view_s* v)
+bool view_acquire(struct view_s* v, bool wait)
{
- if (NULL == v->geom)
- return;
-
- long dims[DIMS];
- md_select_dims(DIMS, v->geom_flags, dims, v->dims);
+ if (wait)
+ mtx_lock(&v->control->mx);
+ else if (0 != mtx_trylock(&v->control->mx))
+ return false;
- long strs[DIMS];
- md_calc_strides(DIMS, strs, dims, 1);
-
- v->geom_current = &v->geom[md_calc_offset(DIMS, strs, v->pos)];
-
- printf("%f %f %f %f %f %f %f %f %f\n",
- (*v->geom_current)[0][0], (*v->geom_current)[0][1], (*v->geom_current)[0][2],
- (*v->geom_current)[1][0], (*v->geom_current)[1][1], (*v->geom_current)[1][2],
- (*v->geom_current)[2][0], (*v->geom_current)[2][1], (*v->geom_current)[2][2]);
+ return true;
}
-
-extern gboolean update_view(struct view_s* v)
+void view_release(struct view_s* v)
{
- if (NULL != v->source)
- cairo_surface_destroy(v->source);
-
- v->rgbw = v->dims[v->xdim] * v->xzoom;
- v->rgbh = v->dims[v->ydim] * v->yzoom;
- v->rgbstr = 4 * v->rgbw;
- v->rgb = realloc(v->rgb, v->rgbh * v->rgbstr);
-
- v->buf = realloc(v->buf, v->rgbh * v->rgbw * sizeof(complex float));
-
- v->source = cairo_image_surface_create_for_data(v->rgb,
- CAIRO_FORMAT_RGB24, v->rgbw, v->rgbh, v->rgbstr);
-
- // trigger redraw
-
- gtk_widget_set_size_request(v->gtk_drawingarea, v->rgbw, v->rgbh);
- gtk_widget_queue_draw(v->gtk_drawingarea);
-
- return FALSE;
+ mtx_unlock(&v->control->mx);
}
-extern gboolean fit_callback(GtkWidget *widget, gpointer data)
+void update_geom(struct view_s* v)
{
- UNUSED(widget);
- struct view_s* v = data;
-
- gboolean flag = gtk_toggle_tool_button_get_active(v->gtk_fit);
-
- if (!flag)
- return FALSE;
-
- double aniso = gtk_adjustment_get_value(v->gtk_aniso);
-
- GtkAllocation alloc;
- gtk_widget_get_allocation(v->gtk_viewport, &alloc);
- double xz = (double)(alloc.width - 5) / (double)v->dims[v->xdim];
- double yz = (double)(alloc.height - 5) / (double)v->dims[v->ydim];
+ if (NULL == v->control->geom)
+ return;
+ long dims[DIMS];
+ md_select_dims(DIMS, v->control->geom_flags, dims, v->control->dims);
- if (yz > xz / aniso)
- yz = xz / aniso; // aniso
+ long strs[DIMS];
+ md_calc_strides(DIMS, strs, dims, 1);
- gtk_adjustment_set_value(v->gtk_zoom, yz);
+ v->control->geom_current = &v->control->geom[md_calc_offset(DIMS, strs, v->settings.pos)];
- return FALSE;
+ printf("%f %f %f %f %f %f %f %f %f\n",
+ (*v->control->geom_current)[0][0], (*v->control->geom_current)[0][1], (*v->control->geom_current)[0][2],
+ (*v->control->geom_current)[1][0], (*v->control->geom_current)[1][1], (*v->control->geom_current)[1][2],
+ (*v->control->geom_current)[2][0], (*v->control->geom_current)[2][1], (*v->control->geom_current)[2][2]);
}
-
-extern gboolean configure_callback(GtkWidget *widget, GdkEvent* event, gpointer data)
+void view_sync(struct view_s* v)
{
- UNUSED(event);
- return fit_callback(widget, data);
-}
+ for (struct view_s* v2 = v->next; v2 != v; v2 = v2->next) {
+
+ if (v->sync && v2->sync) {
+ view_acquire(v2, true);
-extern void view_setpos(struct view_s* v, unsigned int flags, const long pos[DIMS])
-{
- for (unsigned int i = 0; i < DIMS; i++) {
+ v2->settings.pos[v->settings.xdim] = v->settings.pos[v->settings.xdim];
+ v2->settings.pos[v->settings.ydim] = v->settings.pos[v->settings.ydim];
- if (MD_IS_SET(flags, i)) {
+ // if we have changed anything outside of the current x/y dims of v2, we need to reinterpolate
+ // this is common when changing slices in 3D datasets
+ if ((v2->settings.xdim != v->settings.xdim) || (v2->settings.ydim != v->settings.ydim))
+ v2->control->invalid = true;
- gtk_adjustment_set_value(v->gtk_posall[i], pos[i]);
+ view_window_nosync(v2, v->settings.mode, v->settings.winlow, v->settings.winhigh);
+ ui_set_params(v2, v2->ui_params, v2->settings);
- for (struct view_s* v2 = v->next; v2 != v; v2 = v2->next)
- if (v->sync && v2->sync)
- gtk_adjustment_set_value(v2->gtk_posall[i], pos[i]);
+ view_release(v2);
}
}
}
-
-extern void view_refresh(struct view_s* v)
+void view_refresh(struct view_s* v)
{
- if (v->absolute_windowing) {
+ if (v->settings.absolute_windowing) {
long idims[DIMS];
- md_select_dims(DIMS, MD_BIT(v->xdim) | MD_BIT(v->ydim), idims, v->dims);
-
+ md_select_dims(DIMS, MD_BIT(v->settings.xdim) | MD_BIT(v->settings.ydim), idims, v->control->dims);
+
complex float* tmp = md_alloc(DIMS, idims, sizeof(complex float));
-
+
long pos[DIMS];
- md_copy_dims(DIMS, pos, v->pos);
- pos[v->xdim] = 0;
- pos[v->ydim] = 0;
+ md_copy_dims(DIMS, pos, v->settings.pos);
+ pos[v->settings.xdim] = 0;
+ pos[v->settings.ydim] = 0;
- md_slice(DIMS, ~(MD_BIT(v->xdim) | MD_BIT(v->ydim)), pos, v->dims, tmp, v->data, sizeof(complex float));
+ md_slice(DIMS, ~(MD_BIT(v->settings.xdim) | MD_BIT(v->settings.ydim)), pos, v->control->dims, tmp, v->control->data, sizeof(complex float));
long size = md_calc_size(DIMS, idims);
@@ -275,98 +200,93 @@ extern void view_refresh(struct view_s* v)
md_free(tmp);
- if (0 == v->max) {
+ if (0 == v->control->max) {
- gtk_adjustment_set_upper(v->gtk_winhigh, max);
- gtk_adjustment_set_value(v->gtk_winhigh, max);
- gtk_adjustment_set_upper(v->gtk_winlow, max);
- v->max = max;
+ v->settings.winhigh = max;
+ v->control->max = max;
}
- if (v->max < max) {
+ if (v->control->max < max)
+ v->control->max = max;
- gtk_adjustment_set_upper(v->gtk_winhigh, max);
- gtk_adjustment_set_upper(v->gtk_winlow, max);
- v->max = max;
- }
} else {
- long size = md_calc_size(DIMS, v->dims);
+ long size = md_calc_size(DIMS, v->control->dims);
double max = 0.;
for (long j = 0; j < size; j++)
- if (max < cabsf(v->data[j]))
- max = cabsf(v->data[j]);
-
+ if (max < cabsf(v->control->data[j]))
+ max = cabsf(v->control->data[j]);
+
max = MIN(1.e10, max);
if (0. == max)
max = 1.;
- v->max = max;
+ v->control->max = max;
}
- update_view(v);
+ v->ui_params.windowing_max = v->control->max;
+
+ ui_set_params(v, v->ui_params, v->settings);
+ ui_trigger_redraw(v);
}
-extern void view_add_geometry(struct view_s* v, unsigned long flags, const float (*geom)[3][3])
+void view_add_geometry(struct view_s* v, unsigned long flags, const float (*geom)[3][3])
{
- v->geom_flags = flags;
- v->geom = geom;
- v->geom_current = NULL;
+ v->control->geom_flags = flags;
+ v->control->geom = geom;
+ v->control->geom_current = NULL;
update_geom(v);
}
-extern gboolean refresh_callback(GtkWidget *widget, gpointer data)
+void view_geom(struct view_s* v, const bool* selected, const long* pos, double zoom, double aniso, _Bool transpose, enum flip_t flip, enum interp_t interp)
{
- UNUSED(widget);
- view_refresh(data);
- return FALSE;
-}
+ for (int j = 0; j < DIMS; j++) {
+ v->ui_params.selected[j] = selected[j];
+ v->settings.pos[j] = pos[j];
+ }
-extern gboolean geom_callback(GtkWidget *widget, gpointer data)
-{
- UNUSED(widget);
- struct view_s* v = data;
+ v->ui_params.zoom = zoom;
+ v->ui_params.aniso = aniso;
+ v->control->transpose = transpose;
+ v->settings.flip = flip;
+ v->settings.interpolation = interp;
- // Avoid calling this function from itself.
- // Toggling the GTK_TOOGLE_BUTTONs below would normally lead to another call of this function.
- static bool in_callback = false;
- if (in_callback)
- return FALSE;
- in_callback = true;
+ view_geom2(v);
+}
+static void view_geom2(struct view_s* v)
+{
for (int j = 0; j < DIMS; j++) {
- v->pos[j] = gtk_adjustment_get_value(v->gtk_posall[j]);
- bool check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(v->gtk_checkall[j]));
-
- if (!check)
+ if (!v->ui_params.selected[j])
continue;
- if (1 == v->dims[j]) {
+ if (1 == v->control->dims[j]) {
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(v->gtk_checkall[j]), FALSE);
- } else if ((j != v->xdim) && (j != v->ydim)) {
+ v->ui_params.selected[j] = false;
+
+ } else if ((j != v->settings.xdim) && (j != v->settings.ydim)) {
for (int i = 0; i < DIMS; i++) {
- if (v->xdim == (DIMS + j - i) % DIMS) {
+ if (v->settings.xdim == (DIMS + j - i) % DIMS) {
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(v->gtk_checkall[v->xdim]), FALSE);
- v->xdim = j;
+ v->ui_params.selected[v->settings.xdim] = false;
+ v->settings.xdim = j;
break;
}
- if (v->ydim == (DIMS + j - i) % DIMS) {
+ if (v->settings.ydim == (DIMS + j - i) % DIMS) {
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(v->gtk_checkall[v->ydim]), FALSE);
- v->ydim = j;
+ v->ui_params.selected[v->settings.ydim] = false;
+ v->settings.ydim = j;
break;
}
@@ -374,245 +294,160 @@ extern gboolean geom_callback(GtkWidget *widget, gpointer data)
}
}
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(v->gtk_checkall[v->xdim]), TRUE);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(v->gtk_checkall[v->ydim]), TRUE);
-
- double zoom = gtk_adjustment_get_value(v->gtk_zoom);
- double aniso = gtk_adjustment_get_value(v->gtk_aniso);
- v->xzoom = zoom * aniso;
- v->yzoom = zoom;
+ v->ui_params.selected[v->settings.xdim] = true;
+ v->ui_params.selected[v->settings.ydim] = true;
- v->flip = gtk_combo_box_get_active(v->gtk_flip);
- v->interpolation = gtk_combo_box_get_active(v->gtk_interp);
- v->transpose = gtk_toggle_tool_button_get_active(v->gtk_transpose);
+ v->settings.xzoom = v->ui_params.zoom * v->ui_params.aniso;
+ v->settings.yzoom = v->ui_params.zoom;
- if (v->transpose) {
+ if (v->control->transpose) {
- if (v->xdim < v->ydim) {
+ if (v->settings.xdim < v->settings.ydim) {
- int swp = v->xdim;
- v->xdim = v->ydim;
- v->ydim = swp;
+ int swp = v->settings.xdim;
+ v->settings.xdim = v->settings.ydim;
+ v->settings.ydim = swp;
}
} else {
- if (v->xdim > v->ydim) {
+ if (v->settings.xdim > v->settings.ydim) {
- int swp = v->xdim;
- v->xdim = v->ydim;
- v->ydim = swp;
+ int swp = v->settings.xdim;
+ v->settings.xdim = v->settings.ydim;
+ v->settings.ydim = swp;
}
}
- v->lastx = -1;
- v->lasty = -1;
+ v->control->lastx = -1;
+ v->control->lasty = -1;
- v->invalid = true;
+ v->control->invalid = true;
update_geom(v);
- update_view(v);
- in_callback = false;
- return FALSE;
+ ui_set_params(v, v->ui_params, v->settings);
+ ui_trigger_redraw(v);
}
-extern gboolean window_callback(GtkWidget *widget, gpointer data)
+static void view_window_nosync(struct view_s* v, enum mode_t mode, double winlow, double winhigh)
{
- UNUSED(widget);
- struct view_s* v = data;
-
- v->mode = gtk_combo_box_get_active(v->gtk_mode);
- v->winlow = gtk_adjustment_get_value(v->gtk_winlow);
- v->winhigh = gtk_adjustment_get_value(v->gtk_winhigh);
-
- for (struct view_s* v2 = v->next; v2 != v; v2 = v2->next) {
-
- if (v->sync && v2->sync) {
-
- gtk_adjustment_set_value(v2->gtk_winlow, v->winlow);
- gtk_adjustment_set_value(v2->gtk_winhigh, v->winhigh);
- gtk_combo_box_set_active(v2->gtk_mode, v->mode);
- }
- }
-
- v->rgb_invalid = true;
+ v->settings.mode = mode;
+ v->settings.winlow = winlow;
+ v->settings.winhigh = winhigh;
+ v->control->rgb_invalid = true;
+ ui_trigger_redraw(v);
+}
- update_view(v);
- return FALSE;
+void view_window(struct view_s* v, enum mode_t mode, double winlow, double winhigh)
+{
+ view_window_nosync(v, mode, winlow, winhigh);
+ view_sync(v);
}
static void update_buf_view(struct view_s* v)
{
- update_buf(v->xdim, v->ydim, DIMS, v->dims, v->strs, v->pos,
- v->flip, v->interpolation, v->xzoom, v->yzoom, v->plot,
- v->rgbw, v->rgbh, v->data, v->buf);
+ update_buf(v->settings.xdim, v->settings.ydim, DIMS, v->control->dims, v->control->strs, v->settings.pos,
+ v->settings.flip, v->settings.interpolation, v->settings.xzoom, v->settings.yzoom, v->settings.plot,
+ v->control->rgbw, v->control->rgbh, v->control->data, v->control->buf);
}
-extern gboolean save_callback(GtkWidget *widget, gpointer data)
+char *construct_filename_view2(struct view_s* v)
{
- UNUSED(widget);
- struct view_s* v = data;
-
long loopdims[DIMS];
- md_select_dims(DIMS, ~(MD_BIT(v->xdim) | MD_BIT(v->ydim)), loopdims, v->dims);
-
- char* name = construct_filename_view(DIMS, loopdims, v->pos, v->name, "png");
-
- v->dialog = gtk_file_chooser_dialog_new("Save File",
- v->window,
- GTK_FILE_CHOOSER_ACTION_SAVE,
- "Cancel",
- GTK_RESPONSE_CANCEL,
- "Save",
- GTK_RESPONSE_ACCEPT,
- NULL);
-
- v->chooser = GTK_FILE_CHOOSER(v->dialog);
-
- gtk_file_chooser_set_current_name(v->chooser, basename(name));
-
- char* dname = strdup(v->name);
+ md_select_dims(DIMS, ~(MD_BIT(v->settings.xdim) | MD_BIT(v->settings.ydim)), loopdims, v->control->dims);
- // Outputfolder = Inputfolder
- gtk_file_chooser_set_current_folder(v->chooser, dirname(dname));
- gtk_file_chooser_set_do_overwrite_confirmation(v->chooser, TRUE);
-
- gint res = gtk_dialog_run(GTK_DIALOG(v->dialog));
-
- if (GTK_RESPONSE_ACCEPT == res) {
-
- // export single image
- char *filename = gtk_file_chooser_get_filename(v->chooser);
-
- if (CAIRO_STATUS_SUCCESS != cairo_surface_write_to_png(v->source, filename))
- gtk_entry_set_text(v->gtk_entry, "Error: writing image file.\n");
-
- gtk_entry_set_text(v->gtk_entry, "Saved!");
-
- g_free(filename);
- }
-
- gtk_widget_destroy (v->dialog);
-
- xfree(name);
- xfree(dname);
-
- return FALSE;
+ return construct_filename_view(DIMS, loopdims, v->settings.pos, v->name, "png");
}
+bool view_save_png(struct view_s* v, const char *filename)
+{
+ return gtk_ui_save_png(v, filename);
+}
-extern gboolean save_movie_callback(GtkWidget *widget, gpointer data)
+bool view_save_pngmovie(struct view_s* v, const char *folder)
{
- UNUSED(widget);
- struct view_s* v = data;
-
int frame_dim = 10;
- v->dialog = gtk_file_chooser_dialog_new("Export movie to folder",
- v->window,
- GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
- "Cancel",
- GTK_RESPONSE_CANCEL,
- "Export",
- GTK_RESPONSE_ACCEPT,
- NULL);
-
- v->chooser = GTK_FILE_CHOOSER(v->dialog);
+ for (int f = 0; f < v->control->dims[frame_dim]; f++) {
+ v->settings.pos[frame_dim] = f;
+ update_buf_view(v);
- char* dname = strdup(v->name);
-
- // Outputfolder = Inputfolder
- gtk_file_chooser_set_current_folder(v->chooser, dirname(dname));
-
- gint res = gtk_dialog_run(GTK_DIALOG (v->dialog));
-
- if (GTK_RESPONSE_ACCEPT == res) {
-
- char *chosen_dir = gtk_file_chooser_get_filename(v->chooser);
-
- for (unsigned int f = 0; f < v->dims[frame_dim]; f++) {
-
- v->pos[frame_dim] = f;
- update_buf_view(v);
+ draw(v->control->rgbw, v->control->rgbh, v->control->rgbstr, (unsigned char(*)[v->control->rgbw][v->control->rgbstr / 4][4])v->control->rgb,
+ v->settings.mode, v->settings.colortable, 1. / v->control->max, v->settings.winlow, v->settings.winhigh, v->settings.phrot,
+ v->control->rgbw, v->control->buf);
- draw(v->rgbw, v->rgbh, v->rgbstr, (unsigned char(*)[v->rgbw][v->rgbstr / 4][4])v->rgb,
- v->mode, 1. / v->max, v->winlow, v->winhigh, v->phrot,
- v->rgbw, v->buf);
+ char output_name[256];
+ int len = snprintf(output_name, 256, "%s/mov-%04d.png", folder, f);
- char output_name[256];
- int len = snprintf(output_name, 256, "%s/mov-%04d.png", chosen_dir, f);
+ if (len + 1 >= (int)sizeof(output_name)) {
- if (len + 1 >= sizeof(output_name)) {
+ ui_set_msg(v, "Error: writing image file.\n");
+ goto fail;
+ }
- gtk_entry_set_text(v->gtk_entry, "Error: writing image file.\n");
- break;
- }
+ if (gtk_ui_save_png(v, output_name)) {
- if (CAIRO_STATUS_SUCCESS != cairo_surface_write_to_png(v->source, output_name))
- gtk_entry_set_text(v->gtk_entry, "Error: writing image file.\n");
+ ui_set_msg(v, "Error: writing image file.\n");
+ goto fail;
}
-
- g_free(chosen_dir);
- gtk_entry_set_text(v->gtk_entry, "Movie exported.");
}
- gtk_widget_destroy (v->dialog);
-
- xfree(dname);
+ return true;
- return FALSE;
+fail:
+ return false;
}
struct xy_s { float x; float y; };
-static struct xy_s pos2screen(const struct view_s* v, const float (*pos)[DIMS])
+static struct xy_s pos2screen(const struct view_s* v, const float pos[DIMS])
{
- float x = (*pos)[v->xdim];
- float y = (*pos)[v->ydim];
+ float x = pos[v->settings.xdim];
+ float y = pos[v->settings.ydim];
- if ((XY == v->flip) || (XO == v->flip))
- x = v->dims[v->xdim] - 1 - x;
+ if ((XY == v->settings.flip) || (XO == v->settings.flip))
+ x = v->control->dims[v->settings.xdim] - 1 - x;
- if ((XY == v->flip) || (OY == v->flip))
- y = v->dims[v->ydim] - 1 - y;
+ if ((XY == v->settings.flip) || (OY == v->settings.flip))
+ y = v->control->dims[v->settings.ydim] - 1 - y;
// shift to the center of pixels
x += 0.5;
y += 0.5;
- x *= v->xzoom;
- y *= v->yzoom;
+ x *= v->settings.xzoom;
+ y *= v->settings.yzoom;
- if (v->plot)
- y = v->rgbh / 2;
+ if (v->settings.plot)
+ y = v->control->rgbh / 2;
return (struct xy_s){ x, y };
}
static void screen2pos(const struct view_s* v, float (*pos)[DIMS], struct xy_s xy)
{
- for (unsigned int i = 0; i < DIMS; i++)
- (*pos)[i] = v->pos[i];
+ for (int i = 0; i < DIMS; i++)
+ (*pos)[i] = v->settings.pos[i];
- float x = xy.x / v->xzoom - 0.5;
- float y = xy.y / v->yzoom - 0.5;
+ float x = xy.x / v->settings.xzoom - 0.5;
+ float y = xy.y / v->settings.yzoom - 0.5;
- if ((XY == v->flip) || (XO == v->flip))
- x = v->dims[v->xdim] - 1 - x;
+ if ((XY == v->settings.flip) || (XO == v->settings.flip))
+ x = v->control->dims[v->settings.xdim] - 1 - x;
- if ((XY == v->flip) || (OY == v->flip))
- y = v->dims[v->ydim] - 1 - y;
+ if ((XY == v->settings.flip) || (OY == v->settings.flip))
+ y = v->control->dims[v->settings.ydim] - 1 - y;
- (*pos)[v->xdim] = roundf(x);
+ (*pos)[v->settings.xdim] = roundf(x);
- if (!v->plot)
- (*pos)[v->ydim] = roundf(y);
+ if (!v->settings.plot)
+ (*pos)[v->settings.ydim] = roundf(y);
}
@@ -620,86 +455,91 @@ static void screen2pos(const struct view_s* v, float (*pos)[DIMS], struct xy_s x
static void clear_status_bar(struct view_s* v)
{
char buf = '\0';
- gtk_entry_set_text(v->gtk_entry, &buf);
+ ui_set_msg(v, &buf);
}
-static void update_status_bar(struct view_s* v, const float (*pos)[DIMS])
+static void update_status_bar(struct view_s* v)
{
- int x2 = (*pos)[v->xdim];
- int y2 = (*pos)[v->ydim];
+ int x2 = v->settings.pos[v->settings.xdim];
+ int y2 = v->settings.pos[v->settings.ydim];
+
+ float posf[DIMS];
+ for (int i = 0; i < DIMS; i++)
+ posf[i] = v->settings.pos[i];
+
- complex float val = sample(DIMS, *pos, v->dims, v->strs, v->interpolation, v->data);
+ complex float val = sample(DIMS, posf, v->control->dims, v->control->strs, v->settings.interpolation, v->control->data);
// FIXME: make sure this matches exactly the pixel
char buf[100];
snprintf(buf, 100, "Pos: %03d %03d Magn: %.3e Val: %+.3e%+.3ei Arg: %+.2f", x2, y2,
cabsf(val), crealf(val), cimagf(val), cargf(val));
- gtk_entry_set_text(v->gtk_entry, buf);
+ ui_set_msg(v, buf);
}
-extern gboolean draw_callback(GtkWidget *widget, cairo_t *cr, gpointer data)
+void view_draw(struct view_s* v)
{
- UNUSED(widget);
- struct view_s* v = data;
+ v->control->rgbw = MAX(1L, v->control->dims[v->settings.xdim] * v->settings.xzoom);
+ v->control->rgbh = MAX(1L, v->control->dims[v->settings.ydim] * v->settings.yzoom);
+ v->control->rgbstr = 4 * v->control->rgbw;
- if (v->invalid) {
+ if (v->control->invalid) {
+
+ v->control->buf = realloc(v->control->buf, v->control->rgbh * v->control->rgbw * sizeof(complex float));
update_buf_view(v);
- v->invalid = false;
- v->rgb_invalid = true;
+ v->control->invalid = false;
+ v->control->rgb_invalid = true;
}
- if (v->rgb_invalid) {
+ if (v->control->rgb_invalid) {
- (v->plot ? draw_plot : draw)(v->rgbw, v->rgbh, v->rgbstr,
- (unsigned char(*)[v->rgbw][v->rgbstr / 4][4])v->rgb,
- v->mode, v->absolute_windowing ? 1. : 1. / v->max, v->winlow, v->winhigh, v->phrot,
- v->rgbw, v->buf);
+ ui_rgbbuffer_disconnect(v);
- v->rgb_invalid = false;
- }
+ void *newbuf = realloc(v->control->rgb, v->control->rgbh * v->control->rgbstr);
+ if (NULL == newbuf)
+ abort();
- // add_text(v->source, 3, 3, 10, v->name);
+ v->control->rgb = newbuf;
- if (v->cross_hair) {
+ ui_rgbbuffer_connect(v, v->control->rgbw, v->control->rgbh, v->control->rgbstr, v->control->rgb);
- float posi[DIMS];
- for (unsigned int i = 0; i < DIMS; i++)
- posi[i] = v->pos[i];
+ (v->settings.plot ? draw_plot : draw)(v->control->rgbw, v->control->rgbh, v->control->rgbstr,
+ (unsigned char(*)[v->control->rgbw][v->control->rgbstr / 4][4])v->control->rgb,
+ v->settings.mode, v->settings.colortable, v->settings.absolute_windowing ? 1. : 1. / v->control->max, v->settings.winlow, v->settings.winhigh, v->settings.phrot,
+ v->control->rgbw, v->control->buf);
- struct xy_s xy = pos2screen(v, &posi);
+ v->control->rgb_invalid = false;
+ }
- draw_line(v->rgbw, v->rgbh, v->rgbstr, (unsigned char (*)[v->rgbw][v->rgbstr / 4][4])v->rgb,
- 0, (int)xy.y, v->rgbw - 1, (int)xy.y, (v->xdim > v->ydim) ? &color_red : &color_blue);
- draw_line(v->rgbw, v->rgbh, v->rgbstr, (unsigned char (*)[v->rgbw][v->rgbstr / 4][4])v->rgb,
- (int)xy.x, 0, (int)xy.x, v->rgbh - 1, (v->xdim < v->ydim) ? &color_red : &color_blue);
+ // add_text(v->ui->source, 3, 3, 10, v->name);
-// float coords[4][2] = { { 0, 0 }, { 100, 0 }, { 0, 100 }, { 100, 100 } };
-// draw_grid(v->rgbw, v->rgbh, v->rgbstr, (unsigned char (*)[v->rgbw][v->rgbstr / 4][4])v->rgb, &coords, 4, &color_white);
- }
+ if (v->settings.cross_hair) {
+
+ float posf[DIMS];
+ for (int i = 0; i < DIMS; i++)
+ posf[i] = v->settings.pos[i];
- if (v->status_bar) {
+ struct xy_s xy = pos2screen(v, posf);
- float posi[DIMS];
- for (unsigned int i = 0; i < DIMS; i++)
- posi[i] = v->pos[i];
+ draw_line(v->control->rgbw, v->control->rgbh, v->control->rgbstr, (unsigned char (*)[v->control->rgbw][v->control->rgbstr / 4][4])v->control->rgb,
+ 0, (int)xy.y, v->control->rgbw - 1, (int)xy.y, (v->settings.xdim > v->settings.ydim) ? &color_red : &color_blue);
- update_status_bar(v, &posi);
+ draw_line(v->control->rgbw, v->control->rgbh, v->control->rgbstr, (unsigned char (*)[v->control->rgbw][v->control->rgbstr / 4][4])v->control->rgb,
+ (int)xy.x, 0, (int)xy.x, v->control->rgbh - 1, (v->settings.xdim < v->settings.ydim) ? &color_red : &color_blue);
- for (struct view_s* v2 = v->next; v2 != v; v2 = v2->next)
- if (v->sync && v2->sync)
- update_status_bar(v2, &posi);
+// float coords[4][2] = { { 0, 0 }, { 100, 0 }, { 0, 100 }, { 100, 100 } };
+// draw_grid(v->control->rgbw, v->control->rgbh, v->control->rgbstr, (unsigned char (*)[v->control->rgbw][v->control->rgbstr / 4][4])v->control->rgb, &coords, 4, &color_white);
}
- cairo_set_source_surface(cr, v->source, 0, 0);
- cairo_paint(cr);
- return FALSE;
+ if (v->control->status_bar)
+ update_status_bar(v);
}
@@ -715,53 +555,68 @@ struct view_s* create_view(const char* name, const long pos[DIMS], const long di
if (1 != dims[i])
sq_dims[l++] = i;
+ if (1 == l)
+ sq_dims[l++] = 0 == sq_dims[0] ? 1 : 0;
+
assert(2 == l);
struct view_s* v = xmalloc(sizeof(struct view_s));
+ v->control = xmalloc(sizeof(struct view_control_s));
+ v->ui_params.selected = xmalloc(sizeof(bool[DIMS]));
+ v->settings.pos = xmalloc(DIMS * sizeof(long));
v->next = v->prev = v;
v->sync = true;
-
- v->cross_hair = false;
- v->status_bar = false;
-
v->name = name;
- v->max = 0.;
-
- v->pos = xmalloc(DIMS * sizeof(long));
-
- for (int i = 0; i < DIMS; i++)
- v->pos[i] = (NULL != pos) ? pos[i] : 0;
-
- v->xdim = sq_dims[0];
- v->ydim = sq_dims[1];
-
- v->plot = false;
+ v->ui = NULL;
+
+ v->settings.mode = MAGN;
+ v->settings.interpolation = NLINEAR;
+ v->settings.colortable = NONE;
+ v->settings.flip = OO;
+ v->settings.cross_hair = false;
+ v->settings.plot = false;
+ v->settings.xzoom = 2.;
+ v->settings.yzoom = 2.;
+ v->settings.xdim = sq_dims[0];
+ v->settings.ydim = sq_dims[1];
+
+ v->settings.winlow = 0.;
+ v->settings.winhigh = 1.;
+ v->settings.phrot = 0.;
+
+ for (int i = 0; i < DIMS; i++) {
+
+ v->settings.pos[i] = (NULL == pos) ? 0 : pos[i];
+ v->ui_params.selected[i] = false;
+ }
- v->xzoom = 2.;
- v->yzoom = 2.;
+ v->ui_params.selected[v->settings.xdim] = true;
+ v->ui_params.selected[v->settings.ydim] = true;
+ v->ui_params.zoom = 2;
- v->source = NULL;
- v->rgb = NULL;
- v->buf = NULL;
+ md_copy_dims(DIMS, v->control->dims, dims);
+ md_calc_strides(DIMS, v->control->strs, dims, sizeof(complex float));
+ v->control->data = data;
+ v->control->rgb = NULL;
+ v->control->buf = NULL;
+ v->control->status_bar = false;
+ v->control->max = 0.;
- md_copy_dims(DIMS, v->dims, dims);
- md_calc_strides(DIMS, v->strs, dims, sizeof(complex float));
- v->data = data;
+ v->control->geom_flags = 0ul;
+ v->control->geom = NULL;
+ v->control->geom_current = NULL;
- v->geom_flags = 0ul;
- v->geom = NULL;
- v->geom_current = NULL;
+ v->control->lastx = -1;
+ v->control->lasty = -1;
- v->winlow = 0.;
- v->winhigh = 1.;
- v->phrot = 0.;
+ v->ui_params.aniso = 1;
+ v->control->transpose = true;
- v->lastx = -1;
- v->lasty = -1;
+ v->control->invalid = true;
- v->invalid = true;
+ mtx_init(&v->control->mx, mtx_plain);
return v;
}
@@ -772,310 +627,188 @@ static void delete_view(struct view_s* v)
v->next->prev = v->prev;
v->prev->next = v->next;
- free(v->buf);
- free(v->rgb);
+ free(v->control->buf);
+ free(v->control->rgb);
+
+ free(v->ui_params.selected);
+
+ mtx_destroy(&v->control->mx);
#if 0
- free(v->pos);
+ free(v->settings.pos);
//free(v);
#endif
}
-
-extern gboolean toggle_sync(GtkToggleButton* button, gpointer data)
-{
- UNUSED(button);
- struct view_s* v = data;
- v->sync = gtk_toggle_tool_button_get_active(v->gtk_sync);
-
- return FALSE;
-}
-
-
-extern gboolean toggle_plot(GtkToggleButton* button, gpointer data)
+static void view_set_windowing(struct view_s* v)
{
- UNUSED(button);
- struct view_s* v = data;
- v->plot = !v->plot;
-
- gtk_widget_set_sensitive(GTK_WIDGET(v->gtk_mode),
- v->plot ? FALSE : TRUE);
+ double max = v->settings.absolute_windowing ? v->control->max : 1.;
- v->invalid = true;
- update_view(v);
-
- return FALSE;
-}
-
-static void set_windowing(struct view_s* v)
-{
- double max = v->absolute_windowing ? v->max : 1;
max = MIN(1.e10, max);
- double inc = exp(log(10) * round(log(max) / log(10.))) * 0.001;
- int digits = MAX(3, 3 - (int)round(log(max) / log(10.)));
-
- gtk_adjustment_configure(v->gtk_winhigh, v->winhigh, 0, max, inc, gtk_adjustment_get_page_increment(v->gtk_winhigh), gtk_adjustment_get_page_size(v->gtk_winhigh));
- gtk_adjustment_configure(v->gtk_winlow, v->winlow, 0, max, inc, gtk_adjustment_get_page_increment(v->gtk_winlow), gtk_adjustment_get_page_size(v->gtk_winlow));
- gtk_spin_button_set_digits(v->gtk_button_winhigh, digits);
- gtk_spin_button_set_digits(v->gtk_button_winlow, digits);
-
- gtk_widget_set_visible(GTK_WIDGET(v->toolbar_scale1), v->absolute_windowing ? FALSE : TRUE);
- gtk_widget_set_visible(GTK_WIDGET(v->toolbar_scale2), v->absolute_windowing ? FALSE : TRUE);
- gtk_widget_set_visible(GTK_WIDGET(v->toolbar_button1), v->absolute_windowing ? TRUE : FALSE);
- gtk_widget_set_visible(GTK_WIDGET(v->toolbar_button2), v->absolute_windowing ? TRUE : FALSE);
+
+ v->ui_params.windowing_max = max;
+ v->ui_params.windowing_inc = exp(log(10) * round(log(max) / log(10.))) * 0.001;
+ v->ui_params.windowing_digits = MAX(3, 3 - (int)round(log(max) / log(10.)));
}
-extern gboolean toogle_absolute_windowing(GtkToggleToolButton* button, gpointer data)
+void view_toggle_absolute_windowing(struct view_s* v, bool state)
{
- UNUSED(button);
- struct view_s* v = data;
-
- if ((TRUE == gtk_toggle_tool_button_get_active(button)) == v->absolute_windowing)
- return FALSE;
+ if (state && v->settings.absolute_windowing)
+ return;
- if (v->absolute_windowing) {
+ if (v->settings.absolute_windowing) {
- long size = md_calc_size(DIMS, v->dims);
+ long size = md_calc_size(DIMS, v->control->dims);
double max = 0.;
-
+
for (long j = 0; j < size; j++)
- if (max < cabsf(v->data[j]))
- max = cabsf(v->data[j]);
+ if (max < cabsf(v->control->data[j]))
+ max = cabsf(v->control->data[j]);
max = MIN(1.e10, max);
if (0. == max)
max = 1.;
- v->max = max;
- v->winhigh = MIN(v->winhigh / v->max, 1);
- v->winlow = MIN(v->winlow / v->max, 1);
+ v->control->max = max;
+ v->settings.winhigh = MIN(v->settings.winhigh / v->control->max, 1);
+ v->settings.winlow = MIN(v->settings.winlow / v->control->max, 1);
+
+ v->settings.absolute_windowing = false;
- v->absolute_windowing = false;
} else {
- v->winhigh *= v->max;
- v->winlow *= v->max;
- v->absolute_windowing = true;
+ v->settings.winhigh *= v->control->max;
+ v->settings.winlow *= v->control->max;
+ v->settings.absolute_windowing = true;
}
- set_windowing(v);
+ view_set_windowing(v);
- return FALSE;
+ ui_set_params(v, v->ui_params, v->settings);
}
-
-extern void set_position(struct view_s* v, unsigned int dim, unsigned int p)
+static void view_set_position(struct view_s* v, float pos[DIMS])
{
- v->pos[dim] = p;
-
- gtk_adjustment_set_value(v->gtk_posall[dim], p);
+ v->settings.pos[v->settings.xdim] = pos[v->settings.xdim];
+ v->settings.pos[v->settings.ydim] = pos[v->settings.ydim];
- for (struct view_s* v2 = v->next; v2 != v; v2 = v2->next)
- if (v->sync && v2->sync)
- gtk_adjustment_set_value(v2->gtk_posall[dim], p);
+ ui_set_params(v, v->ui_params, v->settings);
+ view_sync(v);
}
-
-extern gboolean button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data)
+void view_click(struct view_s* v, int x, int y, int button)
{
- UNUSED(widget);
- struct view_s* v = data;
-
- struct xy_s xy = { event->x, event->y };
+ struct xy_s xy = { x, y };
float pos[DIMS];
screen2pos(v, &pos, xy);
- if (event->button == GDK_BUTTON_PRIMARY) {
+ if (1 == button) {
- v->cross_hair = false;
- v->status_bar = false;
+ v->settings.cross_hair = false;
+ v->control->status_bar = false;
clear_status_bar(v);
-
- v->rgb_invalid = true;
- update_view(v);
}
- if (event->button == GDK_BUTTON_SECONDARY) {
-
- v->cross_hair = true;
- v->status_bar = true;
+ if (2 == button) {
- set_position(v, v->xdim, pos[v->xdim]);
- set_position(v, v->ydim, pos[v->ydim]);
+ v->settings.cross_hair = true;
+ v->control->status_bar = true;
+ view_set_position(v, pos);
}
- return FALSE;
+ v->control->rgb_invalid = true;
+ ui_trigger_redraw(v);
}
-
-
-extern gboolean motion_notify_event(GtkWidget *widget, GdkEventMotion *event, gpointer data)
+void view_motion(struct view_s* v, int x, int y, double inc_low, double inc_high, int button)
{
- UNUSED(widget);
- struct view_s* v = data;
-
- int y = event->y;
- int x = event->x;
+ bool changed = false;
- if (event->state & GDK_BUTTON1_MASK) {
+ if (0 == button) {
- if (-1 != v->lastx) {
+ v->control->lastx = -1;
+ v->control->lasty = -1;
+ return;
+ }
- double low = gtk_adjustment_get_value(v->gtk_winlow);
- double high = gtk_adjustment_get_value(v->gtk_winhigh);
+ if (1 == button) {
- low -= (x - v->lastx) * gtk_adjustment_get_step_increment(v->gtk_winlow) * 5;
- high -= (y - v->lasty) * gtk_adjustment_get_step_increment(v->gtk_winhigh) * 5;
+ if (-1 != v->control->lastx) {
- if (high > low) {
+ double low = v->settings.winlow;
+ double high = v->settings.winhigh;
- gtk_adjustment_set_value(v->gtk_winlow, low);
- gtk_adjustment_set_value(v->gtk_winhigh, high);
+ low -= (x - v->control->lastx) * inc_low * 5;
+ high -= (y - v->control->lasty) * inc_high * 5;
- for (struct view_s* v2 = v->next; v2 != v; v2 = v2->next) {
+ if (high > low) {
- if (v->sync && v2->sync) {
+ v->settings.winlow = MAX(0, low);
+ v->settings.winhigh = MIN(v->ui_params.windowing_max, high);
- gtk_adjustment_set_value(v2->gtk_winlow, low);
- gtk_adjustment_set_value(v2->gtk_winhigh, high);
- }
- }
+ changed = true;
}
}
- v->lastx = x;
- v->lasty = y;
-
- } else {
-
- v->lastx = -1;
- v->lasty = -1;
+ v->control->lastx = x;
+ v->control->lasty = y;
}
- return FALSE;
-}
-
-
+ if (changed) {
-extern gboolean show_hide(GtkWidget *widget, GtkCheckButton* button)
-{
- gboolean flag = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(button));
- (flag ? gtk_widget_show : gtk_widget_hide)(widget);
-
- return FALSE;
+ ui_set_params(v, v->ui_params, v->settings);
+ view_window(v, v->settings.mode, v->settings.winlow, v->settings.winhigh);
+ }
}
static int nr_windows = 0;
-extern gboolean window_close(GtkWidget *widget, GdkEvent* event, gpointer data)
+void view_window_close(struct view_s* v)
{
- UNUSED(widget);
- UNUSED(event);
- struct view_s* v = data;
-
delete_view(v);
if (0 == --nr_windows)
- gtk_main_quit();
-
- return FALSE;
+ ui_loop_quit();
}
-extern struct view_s* window_new(const char* name, const long pos[DIMS], const long dims[DIMS], const complex float* x, bool absolute_windowing)
+struct view_s* window_new(const char* name, const long pos[DIMS], const long dims[DIMS], const complex float* x,
+ bool absolute_windowing, enum color_t ctab, int realtime)
{
struct view_s* v = create_view(name, pos, dims, x);
- GtkBuilder* builder = gtk_builder_new();
- // gtk_builder_add_from_file(builder, "viewer.ui", NULL);
- gtk_builder_add_from_string(builder, viewer_gui, -1, NULL);
-
- v->gtk_drawingarea = GTK_WIDGET(gtk_builder_get_object(builder, "drawingarea1"));
- v->gtk_viewport = GTK_WIDGET(gtk_builder_get_object(builder, "scrolledwindow1"));
+ view_acquire(v, true);
- v->gtk_winlow = GTK_ADJUSTMENT(gtk_builder_get_object(builder, "winlow"));
- v->gtk_winhigh = GTK_ADJUSTMENT(gtk_builder_get_object(builder, "winhigh"));
+ v->settings.absolute_windowing = absolute_windowing;
+ v->settings.colortable = ctab;
- v->gtk_entry = GTK_ENTRY(gtk_builder_get_object(builder, "entry"));
-#if 0
- PangoFontDescription* desc = pango_font_description_new();
- pango_font_description_set_family(desc, "mono");
- pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD);
- pango_font_description_set_absolute_size(desc, 10 * PANGO_SCALE);
- gtk_widget_override_font(GTK_WIDGET(v->gtk_entry), desc);
- pango_font_description_free(desc);
-#endif
- v->gtk_zoom = GTK_ADJUSTMENT(gtk_builder_get_object(builder, "zoom"));
- v->gtk_aniso = GTK_ADJUSTMENT(gtk_builder_get_object(builder, "aniso"));
-
- v->gtk_mode = GTK_COMBO_BOX(gtk_builder_get_object(builder, "mode"));
- gtk_combo_box_set_active(v->gtk_mode, 0);
-
- v->gtk_flip = GTK_COMBO_BOX(gtk_builder_get_object(builder, "flip"));
- gtk_combo_box_set_active(v->gtk_flip, 0);
-
- v->gtk_interp = GTK_COMBO_BOX(gtk_builder_get_object(builder, "interp"));
- gtk_combo_box_set_active(v->gtk_interp, 0);
-
- v->gtk_transpose = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(builder, "transpose"));
- gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(v->gtk_transpose), TRUE);
- v->gtk_fit = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(builder, "fit"));
- gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(v->gtk_fit), TRUE);
-
- v->gtk_sync = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(builder, "sync"));
- gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(v->gtk_sync), v->sync ? TRUE : FALSE);
+ ui_window_new(v, DIMS, dims, v->settings);
+ nr_windows++;
- v->gtk_button_winlow = GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "scale1_button"));
- v->gtk_button_winhigh = GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "scale2_button"));
+ ui_configure(v);
- v->toolbar_scale1 = GTK_TOOL_ITEM(gtk_builder_get_object(builder, "toolbar_scale1"));
- v->toolbar_scale2 = GTK_TOOL_ITEM(gtk_builder_get_object(builder, "toolbar_scale2"));
- v->toolbar_button1 = GTK_TOOL_ITEM(gtk_builder_get_object(builder, "toolbar_button1"));
- v->toolbar_button2 = GTK_TOOL_ITEM(gtk_builder_get_object(builder, "toolbar_button2"));
+ view_refresh(v);
+ view_geom2(v);
+ view_set_windowing(v);
+ view_window(v, v->settings.mode, v->settings.winlow, v->settings.winhigh);
- v->absolute_windowing = absolute_windowing;
- v->gtk_absolutewindowing = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(builder, "abswindow"));
- gtk_toggle_tool_button_set_active(v->gtk_absolutewindowing , absolute_windowing ? TRUE : FALSE);
+ ui_set_params(v, v->ui_params, v->settings);
- for (int j = 0; j < DIMS; j++) {
+ v->control->realtime = realtime;
- char pname[10];
- snprintf(pname, 10, "pos%02d", j);
- v->gtk_posall[j] = GTK_ADJUSTMENT(gtk_builder_get_object(builder, pname));
- gtk_adjustment_set_upper(v->gtk_posall[j], v->dims[j] - 1);
- gtk_adjustment_set_value(v->gtk_posall[j], v->pos[j]);
+#ifdef HAS_BART_STREAM
+ if (0 <= realtime) {
- snprintf(pname, 10, "check%02d", j);
- v->gtk_checkall[j] = GTK_CHECK_BUTTON(gtk_builder_get_object(builder, pname));
+ view_ff_realtime_position(v);
+ add_rt_callback(v);
}
-
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(v->gtk_checkall[v->xdim]), TRUE);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(v->gtk_checkall[v->ydim]), TRUE);
-
-#if 0
- gtk_widget_hide(GTK_WIDGET(gtk_builder_get_object(builder, "toolbar1")));
- gtk_widget_hide(GTK_WIDGET(gtk_builder_get_object(builder, "toolbar2")));
- gtk_widget_hide(GTK_WIDGET(gtk_builder_get_object(builder, "entry")));
#endif
- gtk_builder_connect_signals(builder, v);
- GtkWindow* window = GTK_WINDOW(gtk_builder_get_object(builder, "window1"));
- g_object_unref(G_OBJECT(builder));
- v->window = window;
- gtk_window_set_title(window, name);
- gtk_widget_show(GTK_WIDGET(window));
-
- nr_windows++;
-
-// fit_callback(NULL, v);
- refresh_callback(NULL, v);
- geom_callback(NULL, v);
- window_callback(NULL, v);
- set_windowing(v);
+ view_release(v);
return v;
}
@@ -1088,26 +821,92 @@ void window_connect_sync(struct view_s* v, struct view_s* v2)
v2->prev = v;
v->next = v2;
- window_callback(NULL, v);
+ // set windowing
+ view_window(v, v->settings.mode, v->settings.winlow, v->settings.winhigh);
}
-struct view_s* view_clone(struct view_s* v, const long pos[DIMS])
+struct view_s* view_window_clone(struct view_s* v)
{
- struct view_s* v2 = window_new(v->name, pos, v->dims, v->data, v->absolute_windowing);
+ struct view_s* v2 = window_new(v->name, v->settings.pos, v->control->dims, v->control->data,
+ v->settings.absolute_windowing, v->settings.colortable, v->control->realtime);
window_connect_sync(v, v2);
return v2;
}
-extern gboolean window_clone(GtkWidget *widget, gpointer data)
+void view_fit(struct view_s* v, int width, int height)
+{
+ double xz = (double)(width - 5) / (double)v->control->dims[v->settings.xdim];
+ double yz = (double)(height - 5) / (double)v->control->dims[v->settings.ydim];
+
+ if (v->settings.plot)
+ v->ui_params.aniso = xz / yz;
+
+ if (yz > xz / v->ui_params.aniso)
+ yz = xz / v->ui_params.aniso; // aniso
+
+ v->ui_params.zoom = yz;
+
+
+ view_geom2(v);
+}
+
+void view_toggle_plot(struct view_s* v)
{
- UNUSED(widget);
- struct view_s* v = data;
+ v->settings.plot = !v->settings.plot;
+ v->control->invalid = true;
+
+ ui_set_params(v, v->ui_params, v->settings);
+ ui_trigger_redraw(v);
+}
+
+
+#ifdef HAS_BART_STREAM
+static void view_ff_realtime_position(void *_v)
+{
+ struct view_s* v = _v;
+ struct view_control_s* control = v->control;
+
+ stream_t s = stream_lookup(control->data);
+
+ if (NULL == s)
+ return;
+
+ stream_fetch(s);
- view_clone(v, v->pos);
+ long pos[DIMS] = { 0 };
+ stream_get_latest_pos(s, DIMS, pos);
- return FALSE;
+ long new_pos = pos[control->realtime];
+
+ if (new_pos > v->settings.pos[control->realtime]) {
+
+ v->settings.pos[control->realtime] = new_pos;
+ ui_set_params(v, v->ui_params, v->settings);
+ view_sync(v);
+
+ control->rgb_invalid = true;
+ view_refresh(v);
+ }
}
+static void add_rt_callback(struct view_s *v)
+{
+ stream_t s = stream_lookup(v->control->data);
+
+ if (NULL == s)
+ return;
+
+ int fd = stream_get_fd(s);
+
+ if (0 <= fd) {
+
+ v->control->rt_callback.context = v;
+ v->control->rt_callback.f = view_ff_realtime_position;
+
+ ui_add_io_callback(fd, &v->control->rt_callback);
+ }
+}
+#endif
=====================================
src/view.h
=====================================
@@ -1,15 +1,113 @@
+#ifndef VIEW_VIEW_H
+#define VIEW_VIEW_H
#ifndef DIMS
#define DIMS 16
#endif
-struct view_s;
+#include <stdbool.h>
-extern struct view_s* window_new(const char* name, const long pos[DIMS], const long dims[DIMS], const complex float* x, _Bool absolute_windowing);
-extern void view_add_geometry(struct view_s* v, unsigned long flags, const float (*geom)[3][3]);
+enum mode_t { MAGN, CMPLX, PHASE, REAL, FLOW };
+enum flip_t { OO, XO, OY, XY };
+enum interp_t { NLINEAR, NLINEARMAG, NEAREST, LIINCO };
+enum color_t { NONE, VIRIDIS, MYGBM, TURBO, LIPARI, NAVIA };
+
+
+struct view_settings_s {
+
+ long* pos; //[DIMS];
+
+ int xdim;
+ int ydim;
+
+ double xzoom;
+ double yzoom;
+
+ enum flip_t flip;
+
+ enum mode_t mode;
+
+ bool cross_hair;
+ bool plot;
+
+ bool absolute_windowing;
+ double winhigh;
+ double winlow;
+
+ double phrot;
+
+ enum interp_t interpolation;
+ enum color_t colortable;
+};
+
+struct view_ui_params_s {
+
+ bool* selected;
+
+ double zoom;
+ double aniso;
+
+ int windowing_digits;
+ double windowing_max;
+ double windowing_inc;
+};
+
+
+struct view_s {
+
+ const char* name;
+
+ struct view_control_s* control;
+ struct view_gtk_ui_s* ui;
+
+ struct view_settings_s settings;
+ struct view_ui_params_s ui_params;
+
+ // multi-window
+ struct view_s* next;
+ struct view_s* prev;
+ bool sync;
+};
+
+
+// setup etc
+extern struct view_s* window_new(const char* name, const long pos[DIMS], const long dims[DIMS], const _Complex float* x, _Bool absolute_windowing, enum color_t ctab, int realtime);
+
extern void window_connect_sync(struct view_s* a, struct view_s* b);
+
+// usually callbacks:
+extern void view_fit(struct view_s* v, int width, int height);
+extern void view_geom(struct view_s* v, const bool* selected, const long* pos, double zoom, double aniso, _Bool transpose, enum flip_t flip, enum interp_t interp);
extern void view_refresh(struct view_s* v);
-extern void view_setpos(struct view_s* v, unsigned int flags, const long pos[DIMS]);
-extern struct view_s* view_clone(struct view_s* v, const long pos[DIMS]);
+extern void view_window(struct view_s* v, enum mode_t mode, double winlow, double winhigh);
+
+extern void view_draw(struct view_s* v);
+
+extern bool view_save_png(struct view_s* v, const char *filename);
+extern bool view_save_pngmovie(struct view_s* v, const char *folder);
+
+extern void view_motion(struct view_s* v, int x, int y, double inc_low, double inc_high, int button);
+
+extern void view_click(struct view_s* v, int x, int y, int button);
+
+extern void view_toggle_plot(struct view_s* v);
+extern void view_toggle_absolute_windowing(struct view_s* v, _Bool state);
+
+extern void view_add_geometry(struct view_s* v, unsigned long flags, const float (*geom)[3][3]);
+
+extern struct view_s* view_window_clone(struct view_s* v);
+
+extern void view_window_close(struct view_s* v);
+
+
+//
+extern _Bool view_acquire(struct view_s* v, _Bool wait);
+extern void view_release(struct view_s* v);
+
+// helpers
+extern char *construct_filename_view2(struct view_s* v);
+
+#endif
+
=====================================
src/viewer.ui
=====================================
@@ -15,29 +15,17 @@
</columns>
<data>
<row>
- <col id="0" translatable="yes">MAGNITUDE (gray)</col>
- </row>
- <row>
- <col id="0" translatable="yes">MAGNITUDE (viridis)</col>
+ <col id="0" translatable="yes">MAGNITUDE</col>
</row>
<row>
<col id="0" translatable="yes">COMPLEX</col>
</row>
- <row>
- <col id="0" translatable="yes">COMPLEX (MYGBM)</col>
- </row>
<row>
<col id="0" translatable="yes">PHASE</col>
</row>
- <row>
- <col id="0" translatable="yes">PHASE (MYGBM)</col>
- </row>
<row>
<col id="0" translatable="yes">REAL</col>
</row>
- <row>
- <col id="0" translatable="yes">MAGNITUDE (turbo)</col>
- </row>
<row>
<col id="0" translatable="yes">FLOW</col>
</row>
@@ -168,7 +156,7 @@
<property name="can_focus">False</property>
<property name="default_height">600</property>
<property name="default_width">600</property>
- <signal name="delete-event" handler="window_close" swapped="no"/>
+ <signal name="delete-event" handler="window_close_callback" swapped="no"/>
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
@@ -188,7 +176,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
- <signal name="clicked" handler="window_clone" swapped="no"/>
+ <signal name="clicked" handler="window_clone_callback" swapped="no"/>
<child>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
@@ -379,8 +367,8 @@
<property name="can_focus">False</property>
<property name="label" translatable="yes">sync</property>
<property name="use_underline">True</property>
- <property name="stock_id">gtk-connect</property>
- <signal name="clicked" handler="toggle_sync" swapped="no"/>
+ <property name="stock_id">gtk-disconnect</property>
+ <signal name="clicked" handler="toggle_sync_callback" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
@@ -393,8 +381,8 @@
<property name="can_focus">False</property>
<property name="label" translatable="yes">plot</property>
<property name="use_underline">True</property>
- <property name="stock_id">gtk-connect</property>
- <signal name="clicked" handler="toggle_plot" swapped="no"/>
+ <property name="stock_id">gtk-select-color</property>
+ <signal name="clicked" handler="toggle_plot_callback" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
@@ -407,8 +395,8 @@
<property name="can_focus">False</property>
<property name="label" translatable="yes">absolute windowing</property>
<property name="use_underline">True</property>
- <property name="stock_id">gtk-italic</property>
- <signal name="clicked" handler="toogle_absolute_windowing" swapped="no"/>
+ <property name="stock_id">gtk-index</property>
+ <signal name="clicked" handler="toogle_absolute_windowing_callback" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
@@ -611,7 +599,7 @@
<property name="label" translatable="yes">showpos</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-preferences</property>
- <signal name="toggled" handler="show_hide" object="scrolledwindow2" swapped="yes"/>
+ <signal name="toggled" handler="show_hide_callback" object="scrolledwindow2" swapped="yes"/>
</object>
<packing>
<property name="expand">False</property>
@@ -645,9 +633,9 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON2_MOTION_MASK | GDK_BUTTON3_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_STRUCTURE_MASK</property>
- <signal name="button-press-event" handler="button_press_event" swapped="no"/>
+ <signal name="button-press-event" handler="click_callback" swapped="no"/>
<signal name="draw" handler="draw_callback" swapped="no"/>
- <signal name="motion-notify-event" handler="motion_notify_event" swapped="no"/>
+ <signal name="motion-notify-event" handler="motion_callback" swapped="no"/>
<signal name="configure-event" handler="configure_callback" swapped="no"/>
</object>
</child>
View it on GitLab: https://salsa.debian.org/med-team/bart-view/-/compare/49885ec4465dc61df475e5ab77505799b0623318...88035bc588b5b235fdf0ff3e4288b3bb235a10d6
--
View it on GitLab: https://salsa.debian.org/med-team/bart-view/-/compare/49885ec4465dc61df475e5ab77505799b0623318...88035bc588b5b235fdf0ff3e4288b3bb235a10d6
You're receiving this email because of your account on salsa.debian.org. Manage all notifications: https://salsa.debian.org/-/profile/notifications | Help: https://salsa.debian.org/help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20261108/ea82fa1a/attachment-0001.htm>
More information about the debian-med-commit
mailing list