Skip to content

Commit 70c3d30

Browse files
authored
Merge pull request #1940 from abuts/1939_draw_mask_doc
`draw_mask` algorithm documentation
2 parents fdbe60f + 744f64e commit 70c3d30

8 files changed

Lines changed: 124 additions & 17 deletions

File tree

documentation/release_notes/v4.2.0.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,24 @@
22

33
# Highlights
44

5+
- #1925 Horace images now contain references to the Horace objects, plotted from them.
6+
`src(figure)` command allows one to retrieve the object from the figure and continue
7+
analysing this object.
8+
9+
- #1937 new algorithm `draw_mask` allows generation of requested mask providing sequence of points
10+
surrounding masked area.
11+
If image processing toolbox (IPT) is available, the mask may be drawn on a Horace image directly.
12+
If IPT does not available, user needs to read coordinates of the points surrounding area
13+
he wants to mask manually and provide their coordinates as 2-dimensional array of points.
14+
515
- #1668, #1908, #1918 Symmetry operations interface (for `SymopReflection` and `SymopRotation`)
6-
have been modified to define rotation or reflection plane using either normal vector to the
7-
plane or two vectors within this plane, whatever user prefers.
8-
Both options produce the same results for orthogonal crystal lattice but for a non-orthogonal lattice
9-
the definition which uses normal vector needs
10-
additional information about the coordinate system this vector is expressed in.
11-
User documentation have been modified to reflect the changes and describe
12-
what is necessary for different lattices.
16+
have been modified to define rotation or reflection plane using either normal vector to the
17+
plane or two vectors within this plane, whatever user prefers.
18+
Both options produce the same results for orthogonal crystal lattice but for a non-orthogonal lattice
19+
the definition which uses normal vector needs
20+
additional information about the coordinate system this vector is expressed in.
21+
User documentation have been modified to reflect the changes and describe
22+
what is necessary for different lattices.
1323

1424
- #1822 fixed issues with pixels missing in cuts build using symmetry operations. The cuts now contain pixels modified
1525
correctly so that the follow-up cuts from cut objects can be performed properly. Also fixed issues with
@@ -31,7 +41,7 @@
3141
in the original file is described by projection axis. Resulting cut ranges were
3242
incorrectly reduced by half of original binning step in each direction.
3343
- #1848 `symmetrize_sqw` now can work with rotational symmetry operations.
34-
To achieve that, algorithm which calculates transformation ranges when
44+
To achieve that, algorithm which calculates transformation ranges when
3545
`sqw` transformation during `sqw` generation is provided was modified. In addition to that,
3646
the algorithm to generate `sqw` objects when transformation is present
3747
has to be modified too. This fixed bugs and improve the efficiency of this
210 KB
Loading

documentation/user_docs/docs/manual/Changing_Horace_settings.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ All configurations have the following settings:
3737
- ``config_folder``: Folder where configurations are stored for reloading for
3838
new Matlab sessions.
3939

40+
41+
.. _hor_config_settings:
42+
4043
Horace Config
4144
=============
4245

@@ -58,6 +61,7 @@ functionality and ``parallel_config`` to control the parameters of parallel jobs
5861
use_mex: 1
5962
delete_tmp: 1
6063
working_directory: '/temp/Horace_4.0.0.f2f508726'
64+
store_src_in_plots: 1
6165
force_mex_if_use_mex: 0
6266
hpc_config: [1×1 hpc_config]
6367
parallel_config: [1×1 parallel_config]
@@ -95,6 +99,9 @@ functionality and ``parallel_config`` to control the parameters of parallel jobs
9599
- ``delete_tmp`` : Whether to automatically delete temporary files after
96100
generating SQW files.
97101
- ``working_directory`` : The directory to which temporary files are written
102+
- ``store_src_in_plots`` : if true (default) all Horace objects are attached to the figures displaying these objects.
103+
``src`` command then may be applied to an image to provide this object back to user. If you set this property to false,
104+
objects become not available any more. (Advanced) : Reference to the plotted object is stored in MATLAB's ``fig.UserData`` property.
98105
- ``hpc_config`` : Reference to the HPC configuration (:ref:`see below <HPC config>`:)
99106
- ``parallel_config`` : Reference to the settings to run parallel jobs (:ref:`see below <Parallel Config>`:)
100107

documentation/user_docs/docs/manual/Generic_Transformation.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,9 @@ Simplest form of the function, which allows combining multiple cuts into single
494494
proj_array(i).alatt = targ_proj.alatt;
495495
proj_array(i).angdeg = targ_proj.angdeg;
496496
% transform momentum transfer values from current page of data into
497-
% image associated with proj_array(i) projection
497+
% image associated with proj_array(i) projection. x-axis (data.p{1})
498+
% of image, produced by this projection have to coincide for all
499+
% combined images.
498500
coord_tr = proj_array(i).transform_pix_to_img(q_coord);
499501
% find the data falling outside of the target image range
500502
% forcing target image and the image produced by current projection to

documentation/user_docs/docs/manual/Plotting.rst

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -615,12 +615,31 @@ e.g. following a spin wave dispersion ring/cone as a function of energy.
615615
Miscellaneous functions
616616
=======================
617617

618-
``meta(fig)`` allows you to copy the figure into a metafile. On Windows, this
619-
function puts the file in the clipboard so that it can be pasted directly into
620-
Word, Powerpoint etc.
618+
* ``meta(fig)`` allows you to copy the figure into a metafile.
619+
On Windows, this function puts the file in the clipboard so that it can be pasted directly into
620+
Word, Powerpoint etc.
621621

622-
``genieplot`` is a singleton, which describes common settings (configuration) used in Horace plots.
622+
* ``genieplot`` is a singleton, which describes common settings (configuration) used in Horace plots.
623623

624-
``genieplot.instance()`` gives one access to the settings, similar to one, used for changing properties of MATLAB ``figure`` classes.
624+
* ``genieplot.instance()`` gives access to the settings common to all Horace figures.
625+
The result behaves similarly to the properties of MATLAB ``figure`` classes, but is applied for all
626+
figures plotted after the change.
625627

626-
See :ref:`geneplot_settings` to get more details about Horace graphics configurations.
628+
See :ref:`geneplot_settings` to get more details about Horace graphics configurations.
629+
630+
* ``src(fig)``. If you plotted an object and want to return the object, used as the source of the figure,
631+
you may use ``src`` command:
632+
633+
::
634+
635+
>>source = src(fig);
636+
or
637+
>>source = src(figure_number);
638+
639+
This command returns you the Horace object (``sqw``, ``dnd`` or ``IX_dataset_nD``) used as the source of the plot. The option to store references to plotted objects in figure
640+
handles is configured by :ref:`Horace Configuration Settings <hor_config_settings>` property
641+
``store_src_in_plots``. If your machine has very limited memory, you may want set this property to ``false`` so this option becomes unavailable and you may delete your resulting
642+
objects immediately after they were plotted. By default, reference to plotted Horace object is stored in figure handle's ``UserData`` property, so the source object exist until its figure exists. ``src`` command finds appropriate figure handle and returns contents of ``UserData`` property.
643+
644+
* ``draw_mask``. The algorithm allows you to define mask by drawing it on plotted image if image processing toolbox is installed.
645+
See :ref:`draw_mask_algorithm` for more details about this routine.

documentation/user_docs/docs/manual/Reshaping_etc.rst

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ are convoluted.
234234
``function`` may be either either ``'hat'`` or ``'gaussian'`` to apply the
235235
respective windowing function.
236236

237+
.. _mask_algorithm:
238+
237239
``mask``
238240
========
239241

@@ -385,3 +387,68 @@ The inputs are:
385387
The output is:
386388

387389
- ``wout``, the output sqw object with mask applied
390+
391+
.. _draw_mask_algorithm:
392+
393+
``draw_mask``
394+
=============
395+
396+
Take 2-dimensional image or 2-dimensional Horace object and construct mask for this object for future use with
397+
``mask`` algorithm :ref:`above <mask_algorithm>`.
398+
Mask may be drawn on a Matlab image or defined by 2-dimensional array of image points. Drawing mask requests image processing toolbox being
399+
installed but option to provide mask vertices in array works for any MATLAB version.
400+
401+
.. code-block:: matlab
402+
403+
msk = draw_mask(win);
404+
msk = draw_mask(fig_num);
405+
msk = draw_mask(fig_ax_handle);
406+
407+
msk = draw_mask(__,'mask_vertices',[x1,x2,x3...;y1,y2,y3]);
408+
[msk,ax,mask_vertices] = draw_mask(__);
409+
410+
411+
The possible inputs are:
412+
413+
* ``win`` -- ``sqw`` object to be masked **or**
414+
* ``fig_num`` -- number of existing figure to draw mask on **or**
415+
* ``fig_ax_handle`` -- handle to the image(``gcf`` for current) or the axis (``gca`` for current) to draw mask on.
416+
417+
Optional:
418+
419+
* ``'mask_vertices'`` -- key followed by 2-dimensional array of coordinates, defining points surrounding area to mask.
420+
**Mandatory** if you do not have image processing toolbox installed.
421+
* ``'-keep_area'`` -- If option provided, area surrounded by input points is kept and external area is masked. By default,
422+
mask excludes selected part of the image.
423+
* ``'-freehand_draw'`` -- use MATLAB "drawfreehand" routine to draw mask on the image provided. If this key is not provided,
424+
routine uses MATLAB's "drawpolygon" routine to draw the mask. Option is ignored if ``fig_info`` is Horace
425+
dataset and ``mask_vertices`` are provided. Drawing options are available only if image processing toolbox is installed.
426+
427+
Returns:
428+
429+
* ``msk`` logical array with dimensions of masked image i.e. ``size(win.data.npix)`` or ``win.data.img_size`` if input ``win`` object
430+
is an ``sqw`` object. Object contains ``true`` for cells to keep and ``false`` for masked areas.
431+
432+
Additional returns:
433+
434+
* ``ax`` -- the axes handle for the image to mask.
435+
* ``mask_vertices`` -- the vertices which define mask. Output ``mask_vertices`` coincide with input mask vertices
436+
if you provided them, or are the coordinates of the points drawn on the image in image coordinate system if they were drawn. (needs image processing toolbox).
437+
438+
439+
The figure below shows the result of executing the following code:
440+
441+
.. code-block:: matlab
442+
443+
msk = draw_mask(6);
444+
wout = mask(src(6),msk);
445+
plot(wout); lz 0 0.5;
446+
447+
where image number 6 was present in Matlab workspace. If image processing toolbox is available, one can draw the points
448+
highlighted by red arrow on the left part of the image using mouse, but if toolbox is not available one needs to
449+
read the coordinates of these points from the image and provide them as 2x6 array of image coordinates values
450+
for 'mask_vertices' key.
451+
452+
.. figure:: ../images/Draw_mask_and_apply_it_to_object.png
453+
:align: center
454+
:width: 800

documentation/user_docs/docs/manual/Symmetrising_etc.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ i.e. applied in the reverse order of the list).
253253
.. code-block:: matlab
254254
255255
% Rotate 90 deg about X, Reflect across X, Rotate back 90 deg about X
256-
>> big_sym = [SymopRotation([1 0 0], 90), SymopReflection([0 1 0], [0 0 1]), SymopRotation([1 0 0], -90)];
256+
big_sym = [SymopRotation([1 0 0], 90), SymopReflection([0 1 0], [0 0 1]), SymopRotation([1 0 0], -90)];
257257
258258
.. note::
259259

examples/move_all_to_proj.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
proj_array(i).alatt = targ_proj.alatt;
4343
proj_array(i).angdeg = targ_proj.angdeg;
4444
% transform momentum transfer values from current page of data into
45-
% image associated with proj_array(i) projection.
45+
% image associated with proj_array(i) projection. x-axis (data.p{1})
46+
% of image, produced by this projection have to coincide for all
47+
% combined images.
4648
coord_tr = proj_array(i).transform_pix_to_img(q_coord);
4749
% Assume these coordinates are in the target coordinate system instead
4850
% of the actual coordinate system defined initially by proj_array(i).

0 commit comments

Comments
 (0)