2.3.4 Adding property numbers

Apart from the coordinates of its points, a Formex object can also store a set of property numbers. This is a set of integers, one for every element of the Formex. The property numbers are stored in an attribute p of the Formex. They can be set, changed or deleted, and be used for any purpose the user wants, e.g. to number the elements in a different order than their appearence in the coordinate array. Or they can be used as pointers into a large database that stores all kind of properties for that element. Just remember that a Formex either has no property numbers, or a complete set of numbers: one for every element.

Property numbers can play an important role in the modelling process, because they present some means of tracking how the resulting Formex was created. Indeed, each transformation of a Formex that preserves its structure, will also preserve the property numbers. Concatenation of Formices with property numbers will also concatenate the property numbers. If any of the concatenated Formices does not have property numbers, it will receive value 0 for all its elements. If all concatenated Formices are without properties, so will be the resulting Formex.

On transformations that change the structure of the Formex, such as replication, each element of the created Formex will get the property number of Formex element it was generated from.

To create a Formex with property numbers, just specify them as a second argument in the constructor. The following example creates a Formex consisting of two triangles, one with property number 1, the second with property 3. The following lines show the creation of the four Formices displayed in figure 2.8, where elements with proprty value 1 are shown in red, those with property value 3 are shown in blue.

>>> F0 = Formex(mpattern('12-34'),[1,3])
>>> F1 = F0.replic2(4,2)
>>> F2 = F1 + F1.mirror(1)
>>> F3 = F2 + F2.rotate(180.,1)

Figure 2.8: A Formex with property numbers drawn as colors
 
props.png

To create the properties on a Formex without, you should always use the setProp method. This ensures that the properties array is generated with the correct type and shape. If needed, the supplied values will be repeated to match the number of elements in the Formex. Once the p attribute is created, you can safely change the value of any of the property numbers.

>>> F = Formex(mpattern('12-34-32-14'))
>>> F.setProp([1,3])
>>> print F.p
    [1 3 1 3]
>>> F.p[2] = 5
>>> print F.p
    [1 3 5 3]

When drawing a Formex having property numbers with default draw options (i.e. no color specified), pyFormex will use the property numbers as indices in a color table, so different properties are shown in different colors. The default color table has eight colors: [ black, red, green, blue, cyan, magenta, yellow, white] and will wrap around if a property value larger than 7 is used. You can however specify any other and larger colorset to be used for drawing the property colors.