Skip to content

Commit e0cb00f

Browse files
smathimechbeutlich
authored andcommitted
Added four Visualizer colormap function and png files
1 parent e5bdd0a commit e0cb00f

9 files changed

Lines changed: 234 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
within Modelica.Mechanics.MultiBody.Visualizers.Colors.ColorMaps;
2+
function CoolWarm "Returns the \"CoolWarm\" color map"
3+
extends Modelica.Mechanics.MultiBody.Interfaces.partialColorMap;
4+
5+
protected
6+
final Real Start[3] = {59/255, 76/255, 192/255}; // blue
7+
final Real Mid[3] = {242/255, 242/255, 242/255}; // gray
8+
final Real End[3] = {180/255, 4/255, 38/255}; // red
9+
10+
final Real cm[n_colors,3];
11+
final Real t; // normalized position
12+
final Real u; // interpolation factor
13+
14+
algorithm
15+
if n_colors >= 1 then
16+
for i in 1:n_colors loop
17+
t := (i-1)/(n_colors-1);
18+
19+
if t <= 0.5 then
20+
u := t/0.5;
21+
cm[i,:] := (1-u)*Start + u*Mid;
22+
else
23+
u := (t-0.5)/0.5;
24+
cm[i,:] := (1-u)*Mid + u*End;
25+
end if;
26+
end for;
27+
28+
colorMap := 255*cm;
29+
else
30+
colorMap := [59,76,192];
31+
end if;
32+
33+
annotation (Documentation(info="<html>
34+
<h4>Syntax</h4>
35+
<blockquote><pre>
36+
ColorMaps.<strong>CoolWarm</strong>();
37+
ColorMaps.<strong>CoolWarm</strong>(n_colors=64);
38+
</pre></blockquote>
39+
<h4>Description</h4>
40+
<p>
41+
This function returns the color map \"CoolWarm.\" A color map
42+
is a Real[:,3] array where every row represents a color.
43+
With the optional argument \"n_colors\" the number of rows
44+
of the returned array can be defined. The default value is
45+
\"n_colors=64\" (it is usually best if n_colors is a multiple of 4).
46+
Image of the \"CoolWarm\" color map:
47+
</p>
48+
49+
<blockquote>
50+
<img src=\"modelica://Modelica/Resources/Images/Mechanics/MultiBody/Visualizers/Colors/ColorMaps/CoolWarm.png\">
51+
</blockquote>
52+
53+
<h4>See also</h4>
54+
<a href=\"modelica://Modelica.Mechanics.MultiBody.Visualizers.Colors.ColorMaps\">ColorMaps</a>,
55+
<a href=\"modelica://Modelica.Mechanics.MultiBody.Visualizers.Colors.colorMapToSvg\">colorMapToSvg</a>,
56+
<a href=\"modelica://Modelica.Mechanics.MultiBody.Visualizers.Colors.scalarToColor\">scalarToColor</a>.
57+
</html>"));
58+
end CoolWarm;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
within Modelica.Mechanics.MultiBody.Visualizers.Colors.ColorMaps;
2+
function Plasma
3+
extends .Modelica.Mechanics.MultiBody.Interfaces.partialColorMap;
4+
5+
protected
6+
final Real Start[3] = {13/255, 8/255, 135/255};
7+
final Real Mid[3] = {219/255, 92/255, 104};
8+
final Real End[3] = {240/255, 249/255, 33/255};
9+
10+
final Real cm[n_colors,3];
11+
final Real t; // normalized position
12+
final Real u; // interpolation factor
13+
algorithm
14+
if n_colors >= 1 then
15+
for i in 1:n_colors loop
16+
t := (i-1)/(n_colors-1);
17+
18+
if t <= 0.5 then
19+
u := t/0.5;
20+
cm[i,:] := (1-u)*Start + u*Mid;
21+
else
22+
u := (t-0.5)/0.5;
23+
cm[i,:] := (1-u)*Mid + u*End;
24+
end if;
25+
end for;
26+
27+
colorMap := 255*cm;
28+
else
29+
colorMap := [122,76,192];
30+
end if;
31+
32+
annotation (Documentation(info="<html>
33+
<h4>Syntax</h4>
34+
<blockquote><pre>
35+
ColorMaps.<strong>Plasma</strong>();
36+
ColorMaps.<strong>Plasma</strong>(n_colors=64);
37+
</pre></blockquote>
38+
<h4>Description</h4>
39+
<p>
40+
This function returns the color map \"Plasma.\" A color map
41+
is a Real[:,3] array where every row represents a color.
42+
With the optional argument \"n_colors\" the number of rows
43+
of the returned array can be defined. The default value is
44+
\"n_colors=64\" (it is usually best if n_colors is a multiple of 4).
45+
Image of the \"Plasma\" color map:
46+
</p>
47+
48+
<blockquote>
49+
<img src=\"modelica://Modelica/Resources/Images/Mechanics/MultiBody/Visualizers/Colors/ColorMaps/Plasma.png\">
50+
</blockquote>
51+
52+
<h4>See also</h4>
53+
<a href=\"modelica://Modelica.Mechanics.MultiBody.Visualizers.Colors.ColorMaps\">ColorMaps</a>,
54+
<a href=\"modelica://Modelica.Mechanics.MultiBody.Visualizers.Colors.colorMapToSvg\">colorMapToSvg</a>,
55+
<a href=\"modelica://Modelica.Mechanics.MultiBody.Visualizers.Colors.scalarToColor\">scalarToColor</a>.
56+
</html>"));
57+
end Plasma;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
within Modelica.Mechanics.MultiBody.Visualizers.Colors.ColorMaps;
2+
function TrafficlightColor
3+
extends Modelica.Mechanics.MultiBody.Interfaces.partialColorMap;
4+
5+
protected
6+
final Real Start[3] = {122/255, 255/255, 122/255}; // mid-green
7+
final Real Mid[3] = {255/255, 230/255, 0}; // orange
8+
final Real End[3] = {128/255, 0, 0}; // red
9+
10+
final Real cm[n_colors,3];
11+
final Real t; // normalized position
12+
final Real u; // interpolation factor
13+
algorithm
14+
if n_colors >= 1 then
15+
for i in 1:n_colors loop
16+
t := (i-1)/(n_colors-1);
17+
18+
if t <= 0.5 then
19+
u := t/0.5;
20+
cm[i,:] := (1-u)*Start + u*Mid;
21+
else
22+
u := (t-0.5)/0.5;
23+
cm[i,:] := (1-u)*Mid + u*End;
24+
end if;
25+
end for;
26+
27+
colorMap := 255*cm;
28+
else
29+
colorMap := [122,76,192];
30+
end if;
31+
32+
annotation (Documentation(info="<html>
33+
<h4>Syntax</h4>
34+
<blockquote><pre>
35+
ColorMaps.<strong>TracficColour</strong>();
36+
ColorMaps.<strong>TracficColour</strong>(n_colors=64);
37+
</pre></blockquote>
38+
<h4>Description</h4>
39+
<p>
40+
This function returns the color map \"TracficColour.\" A color map
41+
is a Real[:,3] array where every row represents a color.
42+
With the optional argument \"n_colors\" the number of rows
43+
of the returned array can be defined. The default value is
44+
\"n_colors=64\" (it is usually best if n_colors is a multiple of 4).
45+
Image of the \"TracficColour\" color map:
46+
</p>
47+
48+
<blockquote>
49+
<img src=\"modelica://Modelica/Resources/Images/Mechanics/MultiBody/Visualizers/Colors/ColorMaps/TrafficColour.png\">
50+
</blockquote>
51+
52+
<h4>See also</h4>
53+
<a href=\"modelica://Modelica.Mechanics.MultiBody.Visualizers.Colors.ColorMaps\">ColorMaps</a>,
54+
<a href=\"modelica://Modelica.Mechanics.MultiBody.Visualizers.Colors.colorMapToSvg\">colorMapToSvg</a>,
55+
<a href=\"modelica://Modelica.Mechanics.MultiBody.Visualizers.Colors.scalarToColor\">scalarToColor</a>.
56+
</html>"));
57+
58+
end TrafficlightColor;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
within Modelica.Mechanics.MultiBody.Visualizers.Colors.ColorMaps;
2+
function Viridis
3+
extends .Modelica.Mechanics.MultiBody.Interfaces.partialColorMap;
4+
5+
protected
6+
final Real Start[3] = {13/255, 8/255, 135/255};
7+
final Real Mid[3] = {219/255, 92/255, 104};
8+
final Real End[3] = {240/255, 249/255, 33/255};
9+
10+
final Real cm[n_colors,3];
11+
final Real t; // normalized position
12+
final Real u; // interpolation factor
13+
algorithm
14+
if n_colors >= 1 then
15+
for i in 1:n_colors loop
16+
t := (i-1)/(n_colors-1);
17+
18+
if t <= 0.5 then
19+
u := t/0.5;
20+
cm[i,:] := (1-u)*Start + u*Mid;
21+
else
22+
u := (t-0.5)/0.5;
23+
cm[i,:] := (1-u)*Mid + u*End;
24+
end if;
25+
end for;
26+
27+
colorMap := 255*cm;
28+
else
29+
colorMap := [122,76,192];
30+
end if;
31+
32+
annotation (Documentation(info="<html>
33+
<h4>Syntax</h4>
34+
<blockquote><pre>
35+
ColorMaps.<strong>Viridis</strong>();
36+
ColorMaps.<strong>Viridis</strong>(n_colors=64);
37+
</pre></blockquote>
38+
<h4>Description</h4>
39+
<p>
40+
This function returns the color map \"Viridis.\" A color map
41+
is a Real[:,3] array where every row represents a color.
42+
With the optional argument \"n_colors\" the number of rows
43+
of the returned array can be defined. The default value is
44+
\"n_colors=64\" (it is usually best if n_colors is a multiple of 4).
45+
Image of the \"Viridis\" color map:
46+
</p>
47+
48+
<blockquote>
49+
<img src=\"modelica://Modelica/Resources/Images/Mechanics/MultiBody/Visualizers/Colors/ColorMaps/Viridis.png\">
50+
</blockquote>
51+
52+
<h4>See also</h4>
53+
<a href=\"modelica://Modelica.Mechanics.MultiBody.Visualizers.Colors.ColorMaps\">ColorMaps</a>,
54+
<a href=\"modelica://Modelica.Mechanics.MultiBody.Visualizers.Colors.colorMapToSvg\">colorMapToSvg</a>,
55+
<a href=\"modelica://Modelica.Mechanics.MultiBody.Visualizers.Colors.scalarToColor\">scalarToColor</a>.
56+
</html>"));
57+
end Viridis;

Modelica/Mechanics/MultiBody/Visualizers/Colors/ColorMaps/package.order

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ spring
55
summer
66
autumn
77
winter
8+
CoolWarm
9+
TrafficlightColor
10+
Plasma
11+
Viridis
1.35 KB
Loading
1.34 KB
Loading
1.25 KB
Loading
1.33 KB
Loading

0 commit comments

Comments
 (0)