Experimental:Pattern Matching

From Derivative
Jump to navigation Jump to search

Experimental - Skipping Glossary Many parameters allow patterns to specify multiple sources to be selected or acted upon. CHOPs, channels, DATs, Geometry COMPs are examples of things that some parameters may allow multiple of. The Render TOP allows for multiple lights, geometry COMPs and cameras. The Join CHOP and Composite TOP accept multiple sources. These patterns allow wild cards which will match all or parts of strings. Patterns are also used in various Python methods such as ops(), to allow specifying more than one OP by a single string.

Basic Patterns[edit]

Basic Pattern matching is also often used to match channel names. It uses the following kinds of patterns to select existing channels in an input CHOP, used in CHOPs like the Select CHOP and the Math CHOP's Scope parameter, where you only want to affect certain channels and leave the rest as-is.

  • pattern - Match string exactly
  • * - Match any sequence of characters
  • ^ - Do not match
  • [alphaset] - Match any one of alphabetic characters enclosed in the square brackets. In TouchDesigner, the [a-g] format is not currently supported, the characters must be listed as [abcdefg]
  • [int1-int2] or [num1-num2:increment] - Match any integer numbers enclosed in the number range, with the optional increment
  • [int1,int2,int3] - Match the specific integers given

Examples[edit]

chan2 Matches a single channel name
chan3 tx ty tz Matches four channel names, separated by spaces
chan* Matches each channel that starts with "chan" and ends with anything
*foot* Matches each channel that has "foot" in it, with anything or nothing before or after
t? The ? matches a single character. t? matches two-character channels starting with t, like the translate channels tx, ty and tz
r[xyz] Matches channels rx, ry and rz. that is, "r" followed by any character between the [ ]
blend[3-5] Matches number range giving blend3, blend4, and blend5.
blend[3-7:2] Matches number ranges giving blend3, blend5, and blend7. (3 to 7 in steps of 2)
blend[2-3,5,13] Matches channels blend2, blend3, blend5, blend13
t[uvwxyz] [uvwxyz] matches characters between u and z, giving channels tu, tv, tw, tx, ty and tz

Operator Patterns[edit]

Some parameters accept Node paths such as Render TOPs Geometry or Lights parameter. Pattern matching in this case can make selecting multiple nodes faster and easier.

  • pattern - Searches the current network and matches any node with the Basic Pattern pattern.
  • /subpattern1/subpattern2/subpattern3/pattern - Searches each sub-path according to it's sub-pattern and matches any nodes with the Basic Pattern pattern

Examples[edit]

geo* Matches all nodes whose names start with "geo" in the current network
/project1/geo* Matches all nodes in /project1 whose names start with "geo"
/project[1-3]/geo* Matches all nodes in /project1, /project2, and /project3 whose names start with "geo"

Index Patterns[edit]

Some parameters only match over indices, usually SOPs and POPs, which is why there is a slightly modified syntax. There is always an implied range of points that the pattern will be matching on, either the number of vertices, faces, points, etc.

  • number - Matches any index with the number exactly
  • * - Match all numbers
  • ^ - Do not match
  • [int1-int2] or [int1-int2:increment] - Match any integer numbers enclosed in the number range, with the optional increment
  • [int1,int2,int3] - Match the specific integers given

Examples[edit]

^20 All indices except 20 are included
[3-15] All indices from 3 to 15 are included
^[100-200] Every index <100 and >200 is included
[0-15:2] Every other point from 0 to 15 is included

SOP Index Patterns[edit]

For certain SOP parameters that are matching the range of primitives there is additional syntax. "S.P", where ,

  • S.P - S is the index of the parent surface and P is the profile index on that surface. Both S and P are Index Patterns

Examples[edit]

0.[0-6] Selects six profiles on primitive 0
^[2-4].[0-6] Selects six profiles on every primitive except 2 to 4
*.^[1-5] Selects every profiles except 1 to 5 on every primitive
^0.* Selects all profiles except those on primitive 0

Set Operator Notation[edit]

The pattern matching rules above can be used in conjunction with set operator notation for more expressive selection. Basic, Multi-Op and Index Patterns (i.e. /project/geo1, t?, chan*, blend[2-6:2]) create sets and |, &, ~ can apply the following set operations between them. The pattern will match any element in the final resulting set.

  • | represents the Union of two sets
  • & represents the Intersection of two sets
  • ~ represents the Set Difference of two sets

The order of precedence of these operations goes (), and then the set operations from left to right in the pattern. NOTE: The |, &, ~ operators have equal precedence. This means for example

  • A | B & C is NOT equal to B & C | A

Examples[edit]

* ~ chan[1,5,6] Matches everything except chan1, chan5, and chan6
(* ~ geo*) | geo3 Matches everything except things that starts with "geo" and ends with anything unless its geo3
./mygeos/geo* ~ ./mygeos/geo[3-5] Matches every node in ./mygeos that starts with "geo" and ends with anything except geo3, geo4, and geo5

Legacy Features (i.e. Deprecated)[edit]

  • Previously for most nodes space and comma separated patterns implied patterns will be ORed together. This logic is still true for pattern not containing the new set operations for backwards compatibility.
    • Prefer using | set operator notation instead
  • Old index matching notation for SOPs will be a legacy toggle that is now off by default for newly placed nodes. When on the new set operator notation will not be available.
    • Prefer using the updated index pattern syntax that is consistent with basic pattern matching
  • Group Name is used
    • @groupname - Expands all the items in the group. Since each group belongs to a network, you can specify a path before the @groupname identifier.
    • op:/path/to/node - Depreated

Old Index Notation[edit]

For Example:

For Group SOP

  • 0.4 2 4 2.5 3.7 selects three profiles and two primitives,
  • 0-100:2 selects every other number from 0 to 100,
  • 0-10:2,3 selects every two of three,
  • 0.0-6 selects six profiles on primitive 0,
  • 0.* selects all profiles on primitive 0,
  • !4 selects every primitive or point except the fourth,
  • 9-0 selects first ten (in reverse if ordered flag is on),
  • !0.* selects all profiles except those on primitive 0,
  • * selects all primitives or points, and no profiles.

For Add SOP

  • 1 2 3 4 - Makes a polygon by connecting point numbers 1,2,3,4.
  • 1 3-15 16 8 - All points from 3-15 are included.
  • 1-234 820-410 235-409 - Points from 1-820 are included, in the specified order.
  • 0-15:2 - Every other point from 0 to 15 is included.
  • 0-15:2,3 - Every 2 of 3 points are included (i.e. 0, 1, 3, 4, 6, 7, 9, 10, 12, 13, 15).
  • !4 - Every point except 4 is included.
  • !100-200 - Every point <100 and >200 is included.
  • * - Include all points.
  • 9-0 - The first ten points are included in reverse order.
  • !9-0 - All but the first ten points are included in reverse order.

See Also[edit]