OpenCascade.js
API ReferenceFoundationClassesTKernel

Quantity

OCCT package Quantity: Quantity_Color, Quantity_ColorRGBA, Quantity_NameOfColor, Quantity_TypeOfColor.

Quantity_Color

This class allows the definition of an RGB color as triplet of 3 normalized floating point values (red, green, blue).
Although Quantity_Color can be technically used for pass-through storage of RGB triplet in any color space, other OCCT interfaces taking/returning Quantity_Color would expect them in linear space. Therefore, take a look into methods converting to and from non-linear sRGB color space, if needed; for instance, application usually providing color picking within 0..255 range in sRGB color space.

Constructors(3)

Static methods(14)

Instance methods(18)

  • Returns the name of the nearest color from the Quantity_NameOfColor enumeration.

  • Updates the color from specified named color.

    Parameters (1)
    • theName
  • SetValues(theC1: number, theC2: number, theC3: number, theType: Quantity_TypeOfColor): void

    Updates a color according to the mode specified by theType. Throws exception if values are out of range.

    Parameters (4)
    • theC1
    • theC2
    • theC3
    • theType
  • Rgb(): [number, number, number]

    Return the color as vector of 3 float elements.

  • Red(): number

    Returns the Red component (quantity of red) of the color within range [0.0; 1.0].

  • Green(): number

    Returns the Green component (quantity of green) of the color within range [0.0; 1.0].

  • Blue(): number

    Returns the Blue component (quantity of blue) of the color within range [0.0; 1.0].

  • Hue(): number

    Returns the Hue component (hue angle) of the color in degrees within range [0.0; 360.0], 0.0 being Red. -1.0 is a special value reserved for grayscale color (S should be 0.0).

  • Light(): number

    Returns the Light component (value of the lightness) of the color within range [0.0; 1.0].

  • ChangeIntensity(theDelta: number): void

    Increases or decreases the intensity (variation of the lightness). The delta is a percentage. Any value greater than zero will increase the intensity. The variation is expressed as a percentage of the current value.

    Parameters (1)
    • theDelta
  • Saturation(): number

    Returns the Saturation component (value of the saturation) of the color within range [0.0; 1.0].

  • ChangeContrast(theDelta: number): void

    Increases or decreases the contrast (variation of the saturation). The delta is a percentage. Any value greater than zero will increase the contrast. The variation is expressed as a percentage of the current value.

    Parameters (1)
    • theDelta
  • IsDifferent(theOther: Quantity_Color): boolean

    Returns TRUE if the distance between two colors is greater than Epsilon().

    Parameters (1)
    • theOther
  • IsEqual(theOther: Quantity_Color): boolean

    Returns TRUE if the distance between two colors is no greater than Epsilon().

    Parameters (1)
    • theOther
  • Distance(theColor: Quantity_Color): number

    Returns the distance between two colors. It's a value between 0 and the square root of 3 (the black/white distance).

    Parameters (1)
    • theColor
  • SquareDistance(theColor: Quantity_Color): number

    Returns the square of distance between two colors.

    Parameters (1)
    • theColor
  • Delta(theColor: Quantity_Color, DC: number, DI: number): { DC: number; DI: number }

    Returns the percentage change of contrast and intensity between this and another color. <DC> and <DI> are percentages, either positive or negative. The calculation is with respect to this color. If <DC> is positive then <me> is more contrasty. If <DI> is positive then <me> is more intense.

    Parameters (3)
    • theColor
    • DC
    • DI
    Returns

    A result object with fields:

    • DC: updated value from the call.
    • DI: updated value from the call.
  • DeltaE2000(theOther: Quantity_Color): number

    Returns the value of the perceptual difference between this color and theOther, computed using the CIEDE2000 formula. The difference is in range [0, 100.], with 1 approximately corresponding to the minimal perceivable difference (usually difference 5 or greater is needed for the difference to be recognizable in practice).

    Parameters (1)
    • theOther

Quantity_ColorRGBA

The pair of Quantity_Color and Alpha component (1.0 opaque, 0.0 transparent).

Constructors(4)

Static methods(3)

  • ColorFromName(theColorNameString: string, theColor: Quantity_ColorRGBA): boolean

    Finds color from predefined names. For example, the name of the color which corresponds to "BLACK" is Quantity_NOC_BLACK. An alpha component is set to 1.0.

    Parameters (2)
    • theColorNameString
      the color name
    • theColor
      a found color Mutated in place; read the updated value from this argument after the call.
    Returns

    false if the color name is unknown, or true if the search by color name was successful

  • ColorFromHex(theHexColorString: string, theColor: Quantity_ColorRGBA, theAlphaComponentIsOff: boolean): boolean

    Parses the string as a hex color (like "#FF0" for short sRGB color, "#FF0F" for short sRGBA color, "#FFFF00" for RGB color, or "#FFFF00FF" for RGBA color).

    Parameters (3)
    • theHexColorString
      the string to be parsed
    • theColor
      a color that is a result of parsing Mutated in place; read the updated value from this argument after the call.
    • theAlphaComponentIsOff
      the flag that indicates if a color alpha component is presented in the input string (false) or not (true)
    Returns

    true if parsing was successful, or false otherwise

  • ColorToHex(theColor: Quantity_ColorRGBA, theToPrefixHash?: boolean): TCollection_AsciiString

    Returns hex sRGBA string in format "#RRGGBBAA".

    Parameters (2)
    • theColor
    • theToPrefixHash

Instance methods(8)

  • SetValues(theRed: number, theGreen: number, theBlue: number, theAlpha: number): void

    Assign new values to the color.

    Parameters (4)
    • theRed
    • theGreen
    • theBlue
    • theAlpha
  • Return RGB color value.

  • Modify RGB color components without affecting alpha value.

  • SetRGB(theRgb: Quantity_Color): void

    Assign RGB color components without affecting alpha value.

    Parameters (1)
    • theRgb
  • Alpha(): number

    Return alpha value (1.0 means opaque, 0.0 means fully transparent).

  • SetAlpha(theAlpha: number): void

    Assign the alpha value.

    Parameters (1)
    • theAlpha
  • IsDifferent(theOther: Quantity_ColorRGBA): boolean

    Returns true if the distance between colors is greater than Epsilon().

    Parameters (1)
    • theOther
  • IsEqual(theOther: Quantity_ColorRGBA): boolean

    Two colors are considered to be equal if their distance is no greater than Epsilon().

    Parameters (1)
    • theOther

Quantity_NameOfColor

Properties(521)