Mercurial > octave
annotate scripts/image/cubehelix.m @ 27918:b442ec6dda5c
use centralized file for copyright info for individual contributors
* COPYRIGHT.md: New file.
* In most other files, use "Copyright (C) YYYY-YYYY The Octave Project
Developers" instead of tracking individual names in separate source
files. The motivation is to reduce the effort required to update the
notices each year.
Until now, the Octave source files contained copyright notices that
list individual contributors. I adopted these file-scope copyright
notices because that is what everyone was doing 30 years ago in the
days before distributed version control systems. But now, with many
contributors and modern version control systems, having these
file-scope copyright notices causes trouble when we update copyright
years or refactor code.
Over time, the file-scope copyright notices may become outdated as new
contributions are made or code is moved from one file to
another. Sometimes people contribute significant patches but do not
add a line claiming copyright. Other times, people add a copyright
notice for their contribution but then a later refactoring moves part
or all of their contribution to another file and the notice is not
moved with the code. As a practical matter, moving such notices is
difficult -- determining what parts are due to a particular
contributor requires a time-consuming search through the project
history. Even managing the yearly update of copyright years is
problematic. We have some contributors who are no longer
living. Should we update the copyright dates for their contributions
when we release new versions? Probably not, but we do still want to
claim copyright for the project as a whole.
To minimize the difficulty of maintaining the copyright notices, I
would like to change Octave's sources to use what is described here:
https://softwarefreedom.org/resources/2012/ManagingCopyrightInformation.html
in the section "Maintaining centralized copyright notices":
The centralized notice approach consolidates all copyright
notices in a single location, usually a top-level file.
This file should contain all of the copyright notices
provided project contributors, unless the contribution was
clearly insignificant. It may also credit -- without a copyright
notice -- anyone who helped with the project but did not
contribute code or other copyrighted material.
This approach captures less information about contributions
within individual files, recognizing that the DVCS is better
equipped to record those details. As we mentioned before, it
does have one disadvantage as compared to the file-scope
approach: if a single file is separated from the distribution,
the recipient won't see the contributors' copyright notices.
But this can be easily remedied by including a single
copyright notice in each file's header, pointing to the
top-level file:
Copyright YYYY-YYYY The Octave Project Developers
See the COPYRIGHT file at the top-level directory
of this distribution or at https://octave.org/COPYRIGHT.html.
followed by the usual GPL copyright statement.
For more background, see the discussion here:
https://lists.gnu.org/archive/html/octave-maintainers/2020-01/msg00009.html
Most files in the following directories have been skipped intentinally
in this changeset:
doc
libgui/qterminal
liboctave/external
m4
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 15:38:17 -0500 |
parents | 5a6a19a4e3da |
children | 1891570abac8 |
rev | line source |
---|---|
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27800
diff
changeset
|
1 ## Copyright (C) 2014-2019 The Octave Project Developers |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27800
diff
changeset
|
2 ## |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27800
diff
changeset
|
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27800
diff
changeset
|
4 ## or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27800
diff
changeset
|
5 ## |
19530
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
6 ## |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
7 ## This file is part of Octave. |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
8 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
9 ## Octave is free software: you can redistribute it and/or modify it |
19530
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
10 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
11 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
12 ## (at your option) any later version. |
19530
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
13 ## |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
14 ## Octave is distributed in the hope that it will be useful, but |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## GNU General Public License for more details. |
19530
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
18 ## |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
19 ## You should have received a copy of the GNU General Public License |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
20 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
21 ## <https://www.gnu.org/licenses/>. |
19530
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
22 |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
23 ## -*- texinfo -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20724
diff
changeset
|
24 ## @deftypefn {} {@var{map} =} cubehelix () |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20724
diff
changeset
|
25 ## @deftypefnx {} {@var{map} =} cubehelix (@var{n}) |
19530
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
26 ## Create cubehelix colormap. |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
27 ## |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
28 ## This colormap varies from black to white going though blue, green, and red |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
29 ## tones while maintaining a monotonically increasing perception of intensity. |
21315
ea2c2e08ceda
doc: Periodic spellcheck of documentation.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
30 ## This is achieved by traversing a color cube from black to white through |
19530
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
31 ## a helix, hence the name cubehelix, while taking into account the perceived |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
32 ## brightness of each channel according to the NTSC specifications from 1953. |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
33 ## |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
34 ## @example |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
35 ## rgbplot (cubehelix (256)) |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
36 ## @end example |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
37 ## |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20098
diff
changeset
|
38 ## The argument @var{n} must be a scalar. |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20098
diff
changeset
|
39 ## If unspecified, the length of the current colormap, or 64, is used. |
19530
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
40 ## |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20098
diff
changeset
|
41 ## Reference: Green, D. A., 2011, |
27800
5a6a19a4e3da
doc: Use Texinfo non-sentence ending periods in citations.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
42 ## @cite{A @nospell{colour} scheme for the display of astronomical intensity |
5a6a19a4e3da
doc: Use Texinfo non-sentence ending periods in citations.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
43 ## images}, Bulletin of the Astronomical Society of India, 39, 289. |
19530
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
44 ## |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
45 ## @seealso{colormap} |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
46 ## @end deftypefn |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
47 |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
48 ## Author: Carnë Draug <carandraug@octave.org> |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
49 |
24800
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
50 function map = cubehelix (n, start = 0.5, rots = -1.5, hue = 1, gamma = 1) |
19530
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
51 |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
52 if (nargin > 5) |
21385
89fa0694aa2e
Fix check-missing-semicolon QA target (bug #47277).
Rik <rik@octave.org>
parents:
21315
diff
changeset
|
53 print_usage (); |
24800
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
54 elseif (nargin > 0) |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
55 if (! isscalar (n)) |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
56 error ("cubehelix: N must be a scalar"); |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
57 endif |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
58 n = double (n); |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
59 else |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
60 hf = get (0, "currentfigure"); |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
61 if (! isempty (hf)) |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
62 n = rows (get (hf, "colormap")); |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
63 else |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
64 n = 64; |
2dc04b6e1740
Don't create new figure when calling colormap functions (bug #53217).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
65 endif |
19530
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
66 endif |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21385
diff
changeset
|
67 |
19611
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19530
diff
changeset
|
68 if (n > 1) |
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19530
diff
changeset
|
69 coeff = [ -0.14861 -0.29227 1.97294 |
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19530
diff
changeset
|
70 1.78277 -0.90649 0.00000]; |
19530
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
71 |
19611
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19530
diff
changeset
|
72 fract = ((0:n-1) / (n-1))'; |
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19530
diff
changeset
|
73 angle = 2 * pi * (start/3 + 1 + rots*fract); |
20231
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
74 fract .^= gamma; |
19611
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19530
diff
changeset
|
75 amp = hue * fract .* (1-fract) /2; |
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19530
diff
changeset
|
76 map = fract + amp .* ([cos(angle) sin(angle)] * coeff); |
19530
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
77 |
19611
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19530
diff
changeset
|
78 ## Clip values (only in case users have changed values of hue or gamma) |
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19530
diff
changeset
|
79 map(map < 0) = 0; |
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19530
diff
changeset
|
80 map(map > 1) = 1; |
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19530
diff
changeset
|
81 elseif (n > 0) |
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19530
diff
changeset
|
82 map = [0, 0, 0]; |
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19530
diff
changeset
|
83 else |
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19530
diff
changeset
|
84 map = zeros (0, 3); |
ed4eeb4314e6
cubehelix: fix for the corner cases when N is 1 or 0.
Carnë Draug <carandraug@octave.org>
parents:
19530
diff
changeset
|
85 endif |
19530
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
86 |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
87 endfunction |
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
88 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
89 |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21385
diff
changeset
|
90 ## A better demo of this colormap would be a 3D plot in NTSC instead of |
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21385
diff
changeset
|
91 ## RGB values. That would really show what this colormap is about. |
19530
5ab6fcf32d1e
New function for colormap cubehelix.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
92 %!demo |
20724
0338dc274ec5
Rewrite colormap demos with rgbplot() to show both composite and profile.
Carnë Draug <carandraug@octave.org>
parents:
20231
diff
changeset
|
93 %! ## Show the 'cubehelix' colormap profile and as an image |
0338dc274ec5
Rewrite colormap demos with rgbplot() to show both composite and profile.
Carnë Draug <carandraug@octave.org>
parents:
20231
diff
changeset
|
94 %! cmap = cubehelix (256); |
0338dc274ec5
Rewrite colormap demos with rgbplot() to show both composite and profile.
Carnë Draug <carandraug@octave.org>
parents:
20231
diff
changeset
|
95 %! subplot (2, 1, 1); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
21973
diff
changeset
|
96 %! rgbplot (cmap, "composite"); |
20724
0338dc274ec5
Rewrite colormap demos with rgbplot() to show both composite and profile.
Carnë Draug <carandraug@octave.org>
parents:
20231
diff
changeset
|
97 %! subplot (2, 1, 2); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
21973
diff
changeset
|
98 %! rgbplot (cmap); |