contextCount function (context query)

Syntax

  • float contextCount(target-selector, label)

Parameters

  1. target-selectorkeyword

    Target selector for the query.

    • intra—Checks against labeled shapes in the same shape tree (i.e. from the same inital shape).
    • inter—Checks against labeled shapes in other shape trees (i.e. generated by other initial shapes in the neighborhood).
    • all—checks both intra andinter.
  2. labelstring
    The context query is performed only on shapes that match the requested label . Must not be empty. If the label is empty, 0 is returned.

Description

The contextCount function is a context query that returns the number of shapes with the specified label in the environment.

Note:

  • Learn more about important characteristics for context queries in conditions and inter context.
  • Each label operation does not "label" the current shape but rather creates a new labeled shape that is counted separately.

Returns

The number of shapes with the given label. If no shape is found matching the specified label, 0 is returned.

Related

Examples

In this example the Lot rule is applied to a single initial shape (intra context). Depending on the size of the shape a diffent number of tiles is genertarated by the split operations. The contextCount() query is uesd to color the tiles according to the total number of shapes with label "Tile".

Lot --> split(x) { ~1 : Split }*

Split --> split(z) { ~1 : Tile }*

Tile --> label("Tile") Color

Color --> case contextCount(intra, "Tile") <= 9 : color(0,1,0)
          else : color(1,0,0)
Lot rule with contextCount applied

In this topic