Modelica.Mechanics.MultiBody.Visualizers.Colors

Library of functions operating on color

Information

This package contains functions to operate on colors. Note, a color is represented as a Real array with 3 elements where the elements are the red, green, blue values of the RGB color model. Every element must be in the range 0..255. The type of a color is Real and not Integer in order that a color can be used with less problems in a model, since in a model an Integer type could only be used in a when-clause. Typical declaration of a color value:

  Real color[3](each min=0, each max=255);

This definition is also available as type Modelica.Mechanics.MultiBody.Types.RealColor.

Extends from Modelica.Icons.FunctionsPackage (Icon for packages containing functions).

Package Content

Name Description
Modelica.Mechanics.MultiBody.Visualizers.Colors.ColorMaps ColorMaps Library of functions returning color maps
Modelica.Mechanics.MultiBody.Visualizers.Colors.colorMapToSvg colorMapToSvg Save a color map on file in svg (scalable vector graphics) format
Modelica.Mechanics.MultiBody.Visualizers.Colors.scalarToColor scalarToColor Map a scalar to a color using a color map

Modelica.Mechanics.MultiBody.Visualizers.Colors.colorMapToSvg Modelica.Mechanics.MultiBody.Visualizers.Colors.colorMapToSvg

Save a color map on file in svg (scalable vector graphics) format

Information

Syntax

Colors.colorMapToSvg(colorMap);
Colors.colorMapToSvg(colorMap,
                     fileName   = "colorMap.svg",
                     width      =  10,  // [mm]
                     height     = 100,  // [mm]
                     x          =  20,  // [mm]
                     y          =  10,  // [mm]
                     T_min      =   0,
                     T_max      = 100,
                     nScalars   =  11,
                     format     = ".3g",
                     fontSize   =  11,  // [pt]
                     textWidth  =   8,  // [mm]
                     caption    = "",
                     headerType = Colors.colorMapToSvg.Header.svgBeginAndEnd)
                                                           // svgBegin
                                                           // svgEnd
                                                           // svgNoHeader

Description

This function saves the color map "Real colorMap[:,3]" on file "fileName" in svg format. The color map has a width of "width" and a height of "height" and the upper left corner is placed at coordinates "(x,y)". Over the color map, a caption "caption" is placed. On the right side of the color map, a set of scalar field values T is displayed where "T_min" is placed at colorMap[1,:], "T_max" is placed at colorMap[end,:] and "nScalars" values between "T_min" and "T_max" (including T_min and T_max) are shown. The printing format of the numbers is defined with "format", see definition below. With argument "headerType" it is defined whether "svg" begin and end lines are printed. If the "begin" svg tag shall be printed, file "fileName" is deleted, if it already exists. Otherwise, all output is appended to the file "fileName".

A "svg" file can be displayed by a web browser, such as Firefox by dragging the file in the browser window. Alternatively, a svg-file can be loaded in a graphics program, such as the free Inkscape, can be manipulated and can be exported in other graphic formats. The following image was generated with a call to "colorMapToSvg", the generated file was loaded in Inkscape and exported in "png" format:

The "format" argument defines the string formatting according to ANSI-C without "%" and "*" character
(e.g., ".6g", "14.5e", "+6f"). In particular:

format = "[<flags>] [<width>] [.<precision>] <conversion>" with

<flags> zero, one or more of
"-": left adjustment of the converted number
"+": number will always be printed with a sign
"0": padding to the field width with leading zeros
<width> Minimum field width. The converted number will be printed in a field at
least this wide and wider if necessary. If the converted number has
fewer characters it will be padded on the left (or the right depending
on <flags>) with blanks or 0 (depending on <flags>).
<precision> The number of digits to be printed after the decimal point for
e, E, or f conversions, or the number of significant digits for
g or G conversions.
<conversion> = "e": Exponential notation using a lower case e
= "E": Exponential notation using an upper case E
= "f": Fixed point notation
= "g": Either "e" or "f"
= "G": Same as "g", but with upper case E

Extends from Modelica.Icons.Function (Icon for functions).

Inputs

NameDescription
colorMap[:, 3]Color map to be stored in svg format
fileNameFile where the svg representation shall be stored
widthWidth in svg-figure [mm]
heightHeight in svg-figure [mm]
xX-Coordinate of left upper corner [mm]
yY-Coordinate of left upper corner [mm]
T_minValue of scalar corresponding to colorMap[1,:]
T_maxValue of scalar corresponding to colorMap[end,:]
nScalarsNumber of scalars to be displayed at the right side
formatFormat of the numbers
fontSizeFont size in [pt]
textWidthNumbers are right justified starting at x+width+textWidth [mm]
captionCaption above the map
headerTypeType of header

Modelica.Mechanics.MultiBody.Visualizers.Colors.scalarToColor Modelica.Mechanics.MultiBody.Visualizers.Colors.scalarToColor

Map a scalar to a color using a color map

Information

Syntax

//Real T, T_min, T_max, colorMap[:,3];
Colors.scalarToColor(T, T_min, T_max, colorMap);

Description

This function returns an rgb color Real[3] that corresponds to the value of "T". The color is selected from the colorMap by interpolation so that "T_min" corresponds to "colorMap[1,:]" and "T_max" corresponds to "colorMap[end,:]".

See also

ColorMaps, colorMapToSvg, PipeWithScalarField.

Extends from Modelica.Icons.Function (Icon for functions).

Inputs

NameDescription
TScalar value
T_minT <= T_min is mapped to colorMap[1,:]
T_maxT >= T_max is mapped to colorMap[end,:]
colorMap[:, 3]Color map

Outputs

NameDescription
color[3]Color of scalar value T
Automatically generated Thu Dec 19 17:20:08 2019.