summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim <tim.elberfeld@uantwerpen.be>2018-11-16 10:14:17 +0100
committerWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2018-12-12 15:56:11 +0100
commit40979a6f4ab678a2f57ccaf8aede1156713e3bf8 (patch)
tree31262344ee3067691896f67a75d1655ed0cdd15c
parentc19b7e2a4a97ebc3a2c060d67a323e0e6fe66f91 (diff)
downloadastra-40979a6f4ab678a2f57ccaf8aede1156713e3bf8.tar.gz
astra-40979a6f4ab678a2f57ccaf8aede1156713e3bf8.tar.bz2
astra-40979a6f4ab678a2f57ccaf8aede1156713e3bf8.tar.xz
astra-40979a6f4ab678a2f57ccaf8aede1156713e3bf8.zip
add astra_plot_geom command and sample s024
Signed-off-by: Tim <tim.elberfeld@uantwerpen.be>
-rw-r--r--build/linux/Makefile.in3
-rw-r--r--matlab/algorithms/plot_geom/__main.m44
-rw-r--r--matlab/algorithms/plot_geom/astra_create_example_cone.m (renamed from matlab/algorithms/plot_geom/create_example_cone.m)0
-rw-r--r--matlab/algorithms/plot_geom/astra_create_example_fanflat.m (renamed from matlab/algorithms/plot_geom/create_example_fanflat.m)0
-rw-r--r--matlab/algorithms/plot_geom/astra_create_example_parallel3d.m (renamed from matlab/algorithms/plot_geom/create_example_parallel3d.m)0
-rw-r--r--matlab/algorithms/plot_geom/draw/create_gui_figure.m58
-rw-r--r--matlab/algorithms/plot_geom/draw/draw_cad_phantom.m8
-rw-r--r--matlab/algorithms/plot_geom/draw/draw_cone_vec_geom.m26
-rw-r--r--matlab/algorithms/plot_geom/draw/draw_fanflat_vec_geom.m17
-rw-r--r--matlab/algorithms/plot_geom/draw/draw_parallel3d_vec_geom.m14
-rw-r--r--matlab/algorithms/plot_geom/draw/draw_proj_geom.m (renamed from matlab/algorithms/plot_geom/draw/draw_proj_geometry.m)10
-rw-r--r--matlab/algorithms/plot_geom/draw/draw_vol_geom.m22
-rw-r--r--matlab/tools/astra_plot_geom.m91
-rw-r--r--samples/matlab/bunny.stl (renamed from matlab/algorithms/plot_geom/stl/bunny.stl)bin47484 -> 47484 bytes
-rw-r--r--samples/matlab/s024_plot_geometry.m42
15 files changed, 181 insertions, 154 deletions
diff --git a/build/linux/Makefile.in b/build/linux/Makefile.in
index 14df491..73d8279 100644
--- a/build/linux/Makefile.in
+++ b/build/linux/Makefile.in
@@ -529,9 +529,6 @@ install-matlab: $(MATLAB_MEX) install-matlab-so
$(INSTALL_SH) -m 755 -d $(MATLABBASE)/algorithms/plot_geom/draw
$(INSTALL_SH) -m 644 $(srcdir)/../../matlab/algorithms/plot_geom/draw/*.m $(MATLABBASE)/algorithms/plot_geom/draw
- $(INSTALL_SH) -m 755 -d $(MATLABBASE)/algorithms/plot_geom/stl
- $(INSTALL_SH) -m 644 $(srcdir)/../../matlab/algorithms/plot_geom/stl/*.stl $(MATLABBASE)/algorithms/plot_geom/stl
-
$(INSTALL_SH) -m 755 -d $(MATLABBASE)/algorithms/plot_geom/util
$(INSTALL_SH) -m 644 $(srcdir)/../../matlab/algorithms/plot_geom/util/*.m $(MATLABBASE)/algorithms/plot_geom/util
diff --git a/matlab/algorithms/plot_geom/__main.m b/matlab/algorithms/plot_geom/__main.m
deleted file mode 100644
index 607a242..0000000
--- a/matlab/algorithms/plot_geom/__main.m
+++ /dev/null
@@ -1,44 +0,0 @@
-%% main.m
-% brief small tool to render astra geometries in matlab
-%
-% date 20.06.2018
-% author Tim Elberfeld
-% imec VisionLab
-% University of Antwerp
-%
-% - last update 09.07.2018
-%%
-% close all;
-
-[h_gui, is_running] = create_gui_figure();
-
-%proj_geom = create_example_cone('vec');
-%proj_geom = create_example_cone('normal');
-%proj_geom = create_example_cone('helix');
-proj_geom = create_example_parallel3d('vec');
-%proj_geom = create_example_fanflat('vec');
-%proj_geom = create_example_fanflat();
-%proj_geom = create_example_parallel3d();
-
-draw_proj_geometry(proj_geom, h_gui);
-hold on;
-
-vol_magn = 10;
-phantom_size = 5;
-phantom_px = 1500;
-vx_size = phantom_size / phantom_px; % voxel size
-vol_geom = astra_create_vol_geom(phantom_px, phantom_px, phantom_px);
-line_width = 1; % line width for phantom
-draw_vol_geom(vol_geom, vx_size, h_gui, 'Magnification', vol_magn,...
- 'LineWidth', line_width, 'Color', 'r');
-
-% this magnification is empirically chosen to fit the stl file
-cad_magn = 350;
-draw_cad_phantom('stl/bunny.stl', cad_magn, h_gui);
-
-proj_geom = create_example_cone('deform_vec');
-draw_proj_geometry(proj_geom, h_gui, 'VectorIdx', 3, 'Color', 'b',...
- 'RotationAxis', [0,0,1]);
-
-hold off;
-axis equal;
diff --git a/matlab/algorithms/plot_geom/create_example_cone.m b/matlab/algorithms/plot_geom/astra_create_example_cone.m
index 598899f..598899f 100644
--- a/matlab/algorithms/plot_geom/create_example_cone.m
+++ b/matlab/algorithms/plot_geom/astra_create_example_cone.m
diff --git a/matlab/algorithms/plot_geom/create_example_fanflat.m b/matlab/algorithms/plot_geom/astra_create_example_fanflat.m
index 703a618..703a618 100644
--- a/matlab/algorithms/plot_geom/create_example_fanflat.m
+++ b/matlab/algorithms/plot_geom/astra_create_example_fanflat.m
diff --git a/matlab/algorithms/plot_geom/create_example_parallel3d.m b/matlab/algorithms/plot_geom/astra_create_example_parallel3d.m
index e6fdf8e..e6fdf8e 100644
--- a/matlab/algorithms/plot_geom/create_example_parallel3d.m
+++ b/matlab/algorithms/plot_geom/astra_create_example_parallel3d.m
diff --git a/matlab/algorithms/plot_geom/draw/create_gui_figure.m b/matlab/algorithms/plot_geom/draw/create_gui_figure.m
deleted file mode 100644
index a9acecf..0000000
--- a/matlab/algorithms/plot_geom/draw/create_gui_figure.m
+++ /dev/null
@@ -1,58 +0,0 @@
-function [h_ax, running] = create_gui_figure()
-%% create_gui_figure.m
-% brief gui for the geometry drawing functions
-% return h_ax axis to draw into with draw_*() functions
-% running state of the rotation, needs to be passed so that
-% the callback will work
-% date 20.06.2018
-% author Tim Elberfeld
-% imec VisionLab
-% University of Antwerp
-%%
- h_figure = figure('name', 'geometry render', 'ButtonDownFcn', @toggle_rotation);
- h_ax = axes(h_figure);
-
- set(h_figure,'CloseRequestFcn', @handle_close_fig)
-
- xlabel('x axis')
- ylabel('y axis')
- zlabel('z axis')
-
- grid on
- box off
- axis vis3d
- axis equal
- view(0,0)
-
- running = false;
- do_rotation();
-
- function [] = handle_close_fig(h_figure,~)
- % this is necessary to stop the rotation before closing the figure
- if running
- toggle_rotation()
- end
-
- delete(h_figure);
- end
-
- function [] = toggle_rotation(~, ~)
- % toggle rotation state
- running = ~running;
- if running
- view(0,0)
- do_rotation();
- else
- view(45,45);
- end
- end
-
- function [] = do_rotation()
- % rotate the rendered geometry around the origin
- camtarget([0,0,0]); % make origin the camera target and point around which to rotate
- while running
- camorbit(0.5,0,'camera')
- drawnow
- end
- end
-end \ No newline at end of file
diff --git a/matlab/algorithms/plot_geom/draw/draw_cad_phantom.m b/matlab/algorithms/plot_geom/draw/draw_cad_phantom.m
index 18873a8..92af844 100644
--- a/matlab/algorithms/plot_geom/draw/draw_cad_phantom.m
+++ b/matlab/algorithms/plot_geom/draw/draw_cad_phantom.m
@@ -1,9 +1,9 @@
-function [] = draw_cad_phantom(filename, magn, h_ax)
+function [] = draw_cad_phantom(filename, magn)
%% draw_cad_phantom.m
% brief render an stl model into a 3d axis object
% param vol_geom volume geometry describing the phantom
-% param magn magnification multiplier of the phantom. default = 1
% param h_ax handle to axis to plot into
+% param magn magnification multiplier of the phantom. default = 1
%
% date 02.07.2018
% author Alice Presenti
@@ -11,12 +11,10 @@ function [] = draw_cad_phantom(filename, magn, h_ax)
% University of Antwerp
% Modified by Tim Elberfeld
%%
+ h_ax = gca;
if nargin == 1
magn = 1;
end
- if nargin == 2
- h_ax = axes(gcf);
- end
[v,f,~,~] = stlRead(filename);
m = mean(v); % to center the CAD model!
diff --git a/matlab/algorithms/plot_geom/draw/draw_cone_vec_geom.m b/matlab/algorithms/plot_geom/draw/draw_cone_vec_geom.m
index c1ed5b0..bee83b7 100644
--- a/matlab/algorithms/plot_geom/draw/draw_cone_vec_geom.m
+++ b/matlab/algorithms/plot_geom/draw/draw_cone_vec_geom.m
@@ -34,17 +34,15 @@ function [] = draw_cone_vec_geom(h_ax, geom, options)
% draw the points and connect with lines
hold on;
num_angles = size(vectors, 1);
- for jj = 1:num_angles
- s_source = scatter3(h_ax, xray_source(jj, 1), xray_source(jj, 2),...
- xray_source(jj, 3));
- s_source.Marker = options.SourceMarker;
- s_source.MarkerEdgeColor = options.SourceMarkerColor;
-
- s_det = scatter3(h_ax, detector_center(jj, 1),...
- detector_center(jj, 2), detector_center(jj, 3));
- s_det.MarkerEdgeColor = options.DetectorMarkerColor;
- s_det.Marker = options.DetectorMarker;
- end
+ s_source = scatter3(h_ax, xray_source(:, 1), xray_source(:, 2),...
+ xray_source(:, 3));
+ s_source.Marker = options.SourceMarker;
+ s_source.MarkerEdgeColor = options.SourceMarkerColor;
+
+ s_det = scatter3(h_ax, detector_center(:, 1),...
+ detector_center(:, 2), detector_center(:, 3));
+ s_det.MarkerEdgeColor = options.DetectorMarkerColor;
+ s_det.Marker = options.DetectorMarker;
detector = struct;
detector.u = vectors(options.VectorIdx, 7:9);
@@ -56,10 +54,12 @@ function [] = draw_cone_vec_geom(h_ax, geom, options)
vertices = draw_detector_vec(h_ax, detector, options);
connect_source_detector(h_ax, vertices, detector_center, ...
xray_source, options);
- distances = eucl_dist3d(detector_center, xray_source);
- mean_sdd = mean(distances(:)); % mean source detector distance
+ % rotation axis will be roughly as long as the source detector distance
+ distances = eucl_dist3d(detector_center, xray_source);
+ mean_sdd = mean(distances(:)); % mean source detector distance
draw_rotation_axis(h_ax, mean_sdd, options);
+
text(h_ax, xray_source(options.VectorIdx, 1),...
xray_source(options.VectorIdx, 2),...
xray_source(options.VectorIdx, 3), 'x-ray source');
diff --git a/matlab/algorithms/plot_geom/draw/draw_fanflat_vec_geom.m b/matlab/algorithms/plot_geom/draw/draw_fanflat_vec_geom.m
index 9f5d620..b8261cf 100644
--- a/matlab/algorithms/plot_geom/draw/draw_fanflat_vec_geom.m
+++ b/matlab/algorithms/plot_geom/draw/draw_fanflat_vec_geom.m
@@ -29,15 +29,13 @@ function [ output_args ] = draw_fanflat_vec_geom( h_ax, geom, options)
% draw the points and connect with lines
hold on;
- for jj = 1:num_angles
- scatter3(h_ax, xray_source(jj, 1), xray_source(jj, 2),...
- xray_source(jj, 3), options.SourceMarker,...
- options.SourceMarkerColor);
- scatter3(h_ax, detector_center(jj, 1),...
- detector_center(jj, 2), detector_center(jj, 3),...
- options.DetectorMarker, options.DetectorMarkerColor);
- end
-
+ scatter3(h_ax, xray_source(:, 1), xray_source(:, 2),...
+ xray_source(:, 3), options.SourceMarker,...
+ options.SourceMarkerColor);
+ scatter3(h_ax, detector_center(:, 1),...
+ detector_center(:, 2), detector_center(:, 3),...
+ options.DetectorMarker, options.DetectorMarkerColor);
+
detector = struct;
detector.u = [vectors(options.VectorIdx, 5:6), 0];
detector.v = fliplr(detector.u);
@@ -49,6 +47,7 @@ function [ output_args ] = draw_fanflat_vec_geom( h_ax, geom, options)
connect_source_detector(h_ax, vertices, detector_center,...
xray_source, options);
+ % rotation axis will be roughly as long as the source detector distance
distances = eucl_dist3d(detector_center, xray_source);
mean_sdd = mean(distances(:)); % mean source detector distance
draw_rotation_axis(h_ax, mean_sdd, options);
diff --git a/matlab/algorithms/plot_geom/draw/draw_parallel3d_vec_geom.m b/matlab/algorithms/plot_geom/draw/draw_parallel3d_vec_geom.m
index 351ec42..ab63e43 100644
--- a/matlab/algorithms/plot_geom/draw/draw_parallel3d_vec_geom.m
+++ b/matlab/algorithms/plot_geom/draw/draw_parallel3d_vec_geom.m
@@ -23,13 +23,11 @@ function [ ] = draw_parallel3d_vec_geom( h_ax, geom, options)
% draw the points and connect with lines
hold on;
num_angles = size(vectors, 1);
- for jj = 1:num_angles
- scatter3(h_ax, xray_source(jj, 1), xray_source(jj, 2), xray_source(jj, 3),...
- options.SourceMarkerColor,...
- options.SourceMarker);
- scatter3(h_ax, detector_center(jj, 1), detector_center(jj, 2),...
- detector_center(jj, 3), 'k.');
- end
+ scatter3(h_ax, xray_source(:, 1), xray_source(:, 2),...
+ xray_source(:, 3), options.SourceMarkerColor,...
+ options.SourceMarker);
+ scatter3(h_ax, detector_center(:, 1), detector_center(:, 2),...
+ detector_center(:, 3), 'k.');
detector = struct;
detector.u = vectors(options.VectorIdx, 7:9);
@@ -42,9 +40,11 @@ function [ ] = draw_parallel3d_vec_geom( h_ax, geom, options)
connect_source_detector(h_ax, detector, detector_center, xray_source,...
options);
+ % rotation axis will be roughly as long as the source detector distance
distances = eucl_dist3d(detector_center, xray_source);
mean_sdd = mean(distances(:)); % mean source detector distance
draw_rotation_axis(h_ax, mean_sdd, options);
+
text(h_ax, xray_source(options.VectorIdx, 1),...
xray_source(options.VectorIdx, 2), ...
xray_source(options.VectorIdx, 3), 'x-ray source');
diff --git a/matlab/algorithms/plot_geom/draw/draw_proj_geometry.m b/matlab/algorithms/plot_geom/draw/draw_proj_geom.m
index 0d31fa2..c20ddc8 100644
--- a/matlab/algorithms/plot_geom/draw/draw_proj_geometry.m
+++ b/matlab/algorithms/plot_geom/draw/draw_proj_geom.m
@@ -1,9 +1,8 @@
-function [] = draw_proj_geometry(geom, h_ax, varargin)
-%% draw_proj_geometry.m
+function [] = draw_proj_geom(geom, varargin)
+%% draw_proj_geom.m
% brief rendering function for astra geometries.
% param geom the geometry to plot. If geometry type
% is not supported, throws error
-% param h_ax handle to axis to plot into
% ------------------------------
% optional parameters that can be provided as string value pairs:
%
@@ -38,10 +37,7 @@ function [] = draw_proj_geometry(geom, h_ax, varargin)
%
% - last update 07.11.2018
%%
- if nargin == 1
- h_ax = axes(gcf);
- end
-
+ h_ax = gca;
options = parseoptions(varargin);
switch geom.type
diff --git a/matlab/algorithms/plot_geom/draw/draw_vol_geom.m b/matlab/algorithms/plot_geom/draw/draw_vol_geom.m
index e6d550d..0b4fe2f 100644
--- a/matlab/algorithms/plot_geom/draw/draw_vol_geom.m
+++ b/matlab/algorithms/plot_geom/draw/draw_vol_geom.m
@@ -1,17 +1,17 @@
-function [] = draw_vol_geom( vol_geom, vx_size, h_ax, varargin)
+function [] = draw_vol_geom( vol_geom, varargin)
%% draw_vol_geom.m
% brief rendering function for astra volume geometries
% describing a phantom.
% param vol_geom volume geometry describing the phantom
% param vx_size voxel size in unit of preference. must be same unit
% that was used to scale the projection geometry
-% param h_ax handle to axis to plot into
% ------------------------------
% optional parameters that can be provided as string value pairs:
%
% param Magnification magnification factor for the phantom. for small
-% phantoms it might be necessary to scale the render up
-% as otherwise it won't show up in the plot. Default = 1
+% phantoms it might be necessary to scale the render
+% up as otherwise it won't show up in the plot.
+% Default = 1
% param LineWidth line width for the box wireframe. Default = 2
% param Color color of the wireframe. Default = 'r'
%
@@ -20,12 +20,18 @@ function [] = draw_vol_geom( vol_geom, vx_size, h_ax, varargin)
% imec VisionLab
% University of Antwerp
%
-% - last update 09.07.2018
+% - last update 16.11.2018
%%
- if nargin < 4
- h_ax = axes(gcf);
- end
+ h_ax = gca;
+ if mod(size(varargin), 2) ~= 0
+ vx_size = varargin{1};
+ varargin = varargin(2:end); % consumed vx_size from arg list
+ else
+ vx_size = 1;
+ end
+
+
options = struct;
options.Color = 'r';
options.LineWidth = 2;
diff --git a/matlab/tools/astra_plot_geom.m b/matlab/tools/astra_plot_geom.m
new file mode 100644
index 0000000..3a654fd
--- /dev/null
+++ b/matlab/tools/astra_plot_geom.m
@@ -0,0 +1,91 @@
+function [] = astra_plot_geom(geometry, varargin)
+%--------------------------------------------------------------------------
+% [] = astra_plot_geometry(geometry, varargin)
+%
+% plot an astra geometry
+%
+% geometry: any astra geometry, either volume geometry, projection
+% geometry or an *.stl file (powered by stlRead).
+% varargin: supports a variable number of (ordered and unordered)
+% arguments.
+%
+% the remaining arguments depend on the input:
+% if 'geometry' is
+% - a volume geometry
+% vx_size voxel size in unit of preference. Must
+% be same unit that was used to scale the
+% projection geometry.
+% and as unorderd string-value-pairs
+% Magnification magnification factor for the phantom.
+% For small phantoms it might be
+% necessary to scale the render up as
+% otherwise it won't show up in the plot.
+% Default = 1
+% LineWidth line width for the box wireframe.
+% Default = 2
+% Color color of the wireframe. Default = 'r'
+%
+% - a projection geometry (as unordered string-value-pairs)
+% RotationAxis if specified, will change the drawn
+% rotation axis to provided axis.
+% Must be 3-vector. Default value is
+% [NaN, NaN, NaN], (meaning do not draw).
+% RotationAxisOffset if specified, will translate the drawn
+% rotation axis by the provided vector.
+% Default = [0, 0, 0]
+% VectorIdx index of the vector to visualize if
+% vector geometry type. Default = 1
+% Color Color for all markers and lines if not
+% otherwise specified
+% DetectorMarker marker for the detector locations.
+% Default = '.'
+% DetectorMarkerColor color specifier for the detector marker.
+% Default = 'k'
+% DetectorLineColor color for the lines drawing the
+% detector outline
+% DetectorLineWidth line width of detector rectangle
+% SourceMarker marker for the source locations
+% SourceMarkerColor color specifier for the source marker
+% SourceDistance (only for parallel3d and parallel3d_vec)
+% distance of source to origin
+% OpticalAxisColor Color for drawing the optical axis
+%
+% - a path to an *.stl file
+% magn - magnification factor for vertices in
+% CAD file. Default value = 1
+%
+%--------------------------------------------------------------------------
+%--------------------------------------------------------------------------
+% This file is part of the ASTRA Toolbox
+%
+% Copyright: 2010-2018, imec Vision Lab, University of Antwerp
+% 2014-2018, CWI, Amsterdam
+% License: Open Source under GPLv3
+% Contact: astra@astra-toolbox.com
+% Website: http://www.astra-toolbox.com/
+%--------------------------------------------------------------------------
+ addpath(genpath('../algorithms/plot_geom')); % add plot_geom tools to matlab path
+
+ if is_vol_geom(geometry)
+ draw_vol_geom(geometry, varargin{:});
+ elseif is_proj_geom(geometry)
+ draw_proj_geom(geometry, varargin{:});
+ elseif ischar(geometry) % assume 'geometry' is a path to a CAD file
+ draw_cad_phantom(geometry, varargin{:});
+ end
+
+ % ---- helper functions ----
+ function [ res ] = is_vol_geom(geom)
+ res = false;
+ if sum(isfield(geom, {'GridRowCount', 'GridColCount'})) == 2
+ res = true;
+ end
+ end
+
+ function [ res ] = is_proj_geom(geom)
+ res = false;
+ if isfield(geom, 'type')
+ res = true;
+ end
+ end
+end
diff --git a/matlab/algorithms/plot_geom/stl/bunny.stl b/samples/matlab/bunny.stl
index 0b7fcaa..0b7fcaa 100644
--- a/matlab/algorithms/plot_geom/stl/bunny.stl
+++ b/samples/matlab/bunny.stl
Binary files differ
diff --git a/samples/matlab/s024_plot_geometry.m b/samples/matlab/s024_plot_geometry.m
new file mode 100644
index 0000000..dd57997
--- /dev/null
+++ b/samples/matlab/s024_plot_geometry.m
@@ -0,0 +1,42 @@
+%% s024_plot_geometry.m
+% brief example of usage for astra_plot_geom command
+% - last update 16.11.2018
+% -----------------------------------------------------------------------
+% This file is part of the ASTRA Toolbox
+%
+% Copyright: 2010-2018, imec Vision Lab, University of Antwerp
+% 2014-2018, CWI, Amsterdam
+% License: Open Source under GPLv3
+% Contact: astra@astra-toolbox.com
+% Website: http://www.astra-toolbox.com/
+% -----------------------------------------------------------------------
+%%
+close all;
+
+% proj_geom = astra_create_example_cone('vec');
+% proj_geom = astra_create_example_cone('normal');
+proj_geom = astra_create_example_cone('helix');
+% proj_geom = astra_create_example_parallel3d('vec');
+% proj_geom = astra_create_example_fanflat('vec');
+% proj_geom = astra_create_example_fanflat();
+% proj_geom = astra_create_example_parallel3d();
+% proj_geom = create_example_cone('deform_vec');
+
+astra_plot_geom(proj_geom);
+hold on;
+
+vol_magn = 20;
+phantom_size = 5;
+phantom_px = 1500;
+vx_size = phantom_size / phantom_px; % voxel size
+vol_geom = astra_create_vol_geom(phantom_px, phantom_px, phantom_px);
+line_width = 1; % line width for phantom
+astra_plot_geom(vol_geom, vx_size, 'Magnification', vol_magn,...
+ 'LineWidth', line_width, 'Color', 'r');
+
+% this magnification is empirically chosen to fit the stl file
+cad_magn = 900;
+astra_plot_geom('bunny.stl', cad_magn);
+
+hold off;
+axis equal;