41
XL as an extension of the L-system formalism Tutorial "Modelling Plants with GroIMP", Cottbus, March 11-12, 2008 Winfried Kurth Ole Kniemeyer Reinhard Hemmerling Gerhard Buck-Sorlin Chair for Graphics Systems, BTU Cottbus

XL as an extension of the L-system formalism

  • Upload
    sienna

  • View
    23

  • Download
    0

Embed Size (px)

DESCRIPTION

XL as an extension of the L-system formalism Tutorial "Modelling Plants with GroIMP", Cottbus, March 11-12, 2008 Winfried Kurth Ole Kniemeyer Reinhard Hemmerling Gerhard Buck-Sorlin Chair for Graphics Systems, BTU Cottbus. Roots of the language XL: - PowerPoint PPT Presentation

Citation preview

Page 1: XL as an extension of the L-system formalism

XL as an extension of the L-system formalism

Tutorial "Modelling Plants with GroIMP", Cottbus, March 11-12, 2008

Winfried Kurth Ole Kniemeyer

Reinhard Hemmerling Gerhard Buck-Sorlin

Chair for Graphics Systems, BTU Cottbus

Page 2: XL as an extension of the L-system formalism

Roots of the language XL:

- object-oriented programming (Java)

- imperative programming (Java)

- rule-based programming (L-systems, graph grammars)

- chemical programming

Page 3: XL as an extension of the L-system formalism

Roots of the language XL:

- object-oriented programming (Java)

- imperative programming (Java)

- rule-based programming (L-systems, graph grammars)

- chemical programming

Page 4: XL as an extension of the L-system formalism

Rule-based programming(van Wijngaarden, Lindenmayer)

Computer = transformation machine for structures (or for states).

There exists always a current structure, which is transformed as long as possible.

Working process: Search and application.matching: search for a rule which is applicable to the current structure,rewriting: application of the rule in order to rewrite the current structure.

programme = a set of transformation rules.

finding a programme: specification of the rules.

programming languages: Prolog, L-system languages, Intran

Page 5: XL as an extension of the L-system formalism

Lindenmayer-Systems (L-Systems)• named after Aristid Lindenmayer (Dutch-Hungarian biologist, 1925-1989)• Data structure and language inseparably connected to each other• Data structure is a sequence of (parameterized) symbols, e.g.: F(1) [ + A(1) ] [ - A(1) ]• Every L-system consists of:

- an alphabet (a set of symbols)- a start word (axiom) (in XL: Axiom)- a set of replacement rules (applied in parallel to the developing string), e.g.: A(x) ==> F(x/2) [ + A(x/2) ] [ - A(x/2) ]

Page 6: XL as an extension of the L-system formalism

part of the alphabet:

Turtle commands (imperative programming style)

F0 "Forward", including construction of a cylinder, uses the current step width for length

(the zero stands for "no explicit specification of length")

M0 forward without construction (Move command)

L(x) change the current step width (length) to x

LAdd(x) increment the current step width by x

LMul(x) multiply the current step width by x

D(x), DAdd(x), DMul(x) analogously for current thickness

Page 7: XL as an extension of the L-system formalism

RU(45) Rotation of the turtle around "up" axis by 45°

RL(...), RH(...) analogously around "left" and "head" axis

up-, left- and head axis form an orthogonal, spatial coordinate system, which is always associated with the turtle

RV(x) Rotation "downwards" with a strength specified by x

Page 8: XL as an extension of the L-system formalism

example:L(100) D(3) RU(-90) F(50) RU(90) M0 RU(90) D(10) F0 F0

D(3) RU(90) F0 F0 RU(90) F(150) RU(90) F(140) RU(90)M(30) F(30) M(30) F(30) RU(120) M0 Sphere(15)

generates

what is the result of the interpretation of the string

L(10) F0 RU(45) F0 RU(45) LMul(0.5) F0 M0 F0 ?

Page 9: XL as an extension of the L-system formalism

Repetition of parts of the command string with the keyword "for"

e.g. for ((1:3)) ( A B C )

yields A B C A B C A B C

what is the result of the interpretation of

L(10) for ((1:6)) ( F0 RU(90) LMul(0.8) ) ?

Page 10: XL as an extension of the L-system formalism

Branching: realization with stack commands

[ put current turtle state on stack ("push")

] take current state from stack ("pop") and let this state be the current turtle state (this means: end of the branch, continue with main stem)

Page 11: XL as an extension of the L-system formalism

Example of interpreted L-system:

rules

A ==> F0 [ RU(45) B ] A ;

B ==> F0 B ;

start word (axiom) L(10) A

(A and B are normally not interpreted geometrically.)

Page 12: XL as an extension of the L-system formalism

what a structure is the result of the following L-system

A ==> [ LMul(0.25) RU(-45) F0 ] F0 B;

B ==> [ LMul(0.25) RU(45) F0 ] F0 A;

with start word L(10) A ?

Page 13: XL as an extension of the L-system formalism

what a structure is the result of the following L-system

A ==> [ LMul(0.25) RU(-45) F0 ] F0 B;

B ==> [ LMul(0.25) RU(45) F0 ] F0 A;

with start word L(10) A ?

equivalent rule:

A ==> [ LMul(0.25) RU(-45) F0 ] F0 RH(180) A;

Page 14: XL as an extension of the L-system formalism

a space-filling curve:

module R extends RU(-45); /* inheritance */

module A extends F(10);

Axiom ==> L(100) R X R A R X;

X ==> X F0 X R A R X F0 X;

Page 15: XL as an extension of the L-system formalism

Branching, alternating phyllotaxy and shortening of branches:

Axiom ==> L(10) F0 A ;

A ==> LMul(0.5) [ RU(90) F0 ] F0 RH(180) A ;

Page 16: XL as an extension of the L-system formalism

which structure is given by

Axiom ==> F(10) A ;

A ==> [ RU(-60) F(6) RH(180) A Sphere(3) ] [ RU(40) F(10) RH(180) A Sphere(3) ];

Sphere ==> Z; ?

(F(n) yields line of the given length n,Sphere(n) a sphere with radius n)

Page 17: XL as an extension of the L-system formalism

Stochastic L-systemsusing pseudo-random numbersexample:deterministic stochasticfloat c = 0.7;

Axiom ==> L(100) D(5) A;

A ==> F0 LMul(c) DMul(c) [ RU(50) A ] [ RU(-10) A ];

float c = 0.7;

Axiom ==> L(100) D(5) A;

A ==> F0 LMul(c) DMul(c) if (probability(0.5)) ( [ RU(50) A ] [ RU(-10) A ] ) else ( [ RU(-50) A ] [ RU(10) A ] );

Page 18: XL as an extension of the L-system formalism

Generating a random distribution on a plane:Axiom ==> D(0.5) for ((1:300))

( [ Translate(random(0, 100), random(0, 100), 0)

F(random(5, 30)) ] );

view from above oblique view

Page 19: XL as an extension of the L-system formalism

Which structure is generated by the following L-system?

Axiom ==> [ RU(90) M(1) RU(90) A(1) ] A(1);

A(n) ==> F(n) RU(90) A(n+1);

variant: replace "RU(90)" in the second rule by "RU(92)"

Page 20: XL as an extension of the L-system formalism

context sensitivity

Query for a context which must be present in order for a rule to be applicable

Specification of the context in (* .... *)

example:module A(int age);module B(super.length, super.color) extends F(length, 3, color);Axiom ==> A(0);A(t), (t < 5) ==> B(10, 2) A(t+1);A(t), (t == 5) ==> B(10, 4);B(s, 2) (* B(r, 4) *) ==> B(s, 4);B(s, 4) ==> B(s, 3) [ RH(random(0, 360)) RU(30) F(30, 1, 14) ];

Page 21: XL as an extension of the L-system formalism

Transition to graph grammars:

Rewriting of graphs instead of strings

(strings remain a special case)

Relational growth grammars (RGG): parallel graph grammars with a special graph model

(see Ole Kniemeyer's dissertation for mathematical foundations)

"relational": different edge types of the graph can stand for different relations

Page 22: XL as an extension of the L-system formalism

an RGG rule and its application in graphical form:

rule:

application:

Page 23: XL as an extension of the L-system formalism

critical point here:

the connection of the inserted right-hand side with the rest of the graph

("embedding")

XL offers 3 standard types of rules with different solutions for embedding:

L ==> R L-system rules: embedding made compatible with L-systemsL ==>> R SPO rules (single pushout rules, from algebraic graph grammar theory): after insertion, "dangling edges" are removedL ::> C execution rules: no change of the graph topology at all, only parameters are changed (C: command sequence, imperative)

Page 24: XL as an extension of the L-system formalism

Extended L-Systems (XL)Example for execution rulesgiven: a graph with cycles Spreading rule for a

signal in the network:

XL representation:(* Cell(1) *) c:Cell(0) ::> c[state] := 1;

Page 25: XL as an extension of the L-system formalism

Extended L-Systems (XL)spreading of signal

output:

1 2 3

Page 26: XL as an extension of the L-system formalism

Extended L-Systems (XL)The Game of Life

XL code:static Cell* context(Cell c1){

yield (* c2:Cell, ((c2 != c1) && (c2.distanceLinf(c1) < 1.1)) *); }

public void transition()[

x:Cell(1), (!(sum(context(x)[state]) in (2 : 3))) ::> x[state] := 0;

x:Cell(0), (sum(context(x)[state]) == 3) ::> x[state] := 1;]

Page 27: XL as an extension of the L-system formalism

Extended L-Systems (XL)The Game of Life

Graphical output(a period-8 oscillator):

Page 28: XL as an extension of the L-system formalism

• global sensitivity, graph queries

Example: growth takes place only when there is enough distance to the next object in space

module A(int s);Axiom ==> F(100) [ RU(-30) A(70) ] RU(30) A(100);a:A(s) ==> if ( forall(distance(a, (* F *)) > 60) ) ( RH(180) F(s) [ RU(-30) A(70) ] RU(30) A(100) )

without the condition with the condition

Page 29: XL as an extension of the L-system formalism

Interpretive rules

Insertion of an extra rule application immediately before graphical interpretation takes place (without effect on the next generation)

application of interpretive rules

Turtle interpretation

public void run(){ [ Axiom ==> A; A ==> Scale(0.3333) for (i:(-1:1)) for (j:(-1:1)) if ((i+1)*(j+1) != 1) ( [ Translate(i, j, 0) A ] ); ] applyInterpretation();}

public void interpret() [ A ==> Box; ]

Example:

Page 30: XL as an extension of the L-system formalism

public void run(){ [ Axiom ==> A; A ==> Scale(0.3333) for (i:(-1:1)) for (j:(-1:1)) if ((i+1)*(j+1) != 1) ( [ Translate(i, j, 0) A ] ); ] applyInterpretation();}

public void interpret() [ A ==> Box; ]

(a)

(b) (c)A ==> Sphere(0.5); A ==> Box(0.1, 0.5, 0.1) Translate(0.1, 0.25, 0) Sphere(0.2);

Page 31: XL as an extension of the L-system formalism

what will be generated by this example?

public void run(){ [ Axiom ==> [ A(0, 0.5) D(0.7) F(60) ] A(0, 6) F(100); A(t, speed) ==> A(t+1, speed); ] applyInterpretation();}public void interpret() [ A(t, speed) ==> RU(speed*t); ]

Page 32: XL as an extension of the L-system formalism

Extended L-Systems (XL)simple example: railway simulation

Modules: Train Track Switch

Excerpt of the data structure: Train standingbefore a switch

Page 33: XL as an extension of the L-system formalism

Extended L-Systems (XL)simple example: railway simulation

Rule 1

Rule 2

r1:Rail[t:Train] r2:Rail ==>> r1 r2[t];

r:Rail[t:Train] s:Switch[r2:Rail] r1:Rail ==>> r s[r1[t]] r2;

Page 34: XL as an extension of the L-system formalism

Extended L-Systems (XL)Artificial Chemistry: Prime number generator

A multiset of random integers reacts according to the following rule, thereby distilling prime numbers.

int

Rule:

a b

int int

a b/a

inta divides b

textual output:20 65 68 46 74 53* 22 35 42 21Concentration: 1 / 1020 65 68 46 74 53* 22 35 21 2*Concentration: 2 / 1065 53* 35 21 2* 10 34 23* 37* 11*Concentration: 5 / 1065 53* 35 21 2* 23* 37* 11* 5* 17*Concentration: 7 / 1053* 21 2* 23* 37* 11* 5* 17* 13* 7*Concentration: 9 / 1053* 2* 23* 37* 11* 5* 17* 13* 7* 3*Concentration: 10 / 10

b:int, (* a:int *), (a != b && (b % a) == 0) ==> `b / a`;

Page 35: XL as an extension of the L-system formalism

Extended L-Systems (XL)A herbivore modelModel of a tree population being grazed upon by phytophagous animals.

• Plants with two parameters: age t and radius r, represented by circles of radius r (proportional to energy budget of plant).• Plants reproduce through seed

• at a certain age and • above a certain energy (radius) threshold (number of offspring = f(r)).

• Plant dies whena) it has reached maximum age or b) when its energy budget is exhausted (r<0).

• If plant does not die it grows by fixed amount at each time step• Animals with two parameters: age t and energy budget e, represented by small circles.• While not in contact with a plant (i. e. within its radius): animal moves and consumes fixed amount of its stored energy. • When in contact with a plant: animal’s radius of movement decreased, starts "grazing"

Page 36: XL as an extension of the L-system formalism

behaviour of plants

behaviour of animals

Page 37: XL as an extension of the L-system formalism

/* phytophag.rgg: specification of a grazing and competition model with circular-shaped plants and animals */ module Plant(int t, super.radius) extends Cylinder(1, radius) {{setColor(0x00aa00);}}module Animal(int t, super.radius) extends Cylinder(2, radius) {{setColor(0xff0000); setBaseOpen(true); setTopOpen(true);}}; double pgrow = 0.9; /* regular growth increment per timestep */double seed_rad = 0.1;/* initial radius of a plant */int pmaxage = 30; /* maximal age of a plant */int pgenage1 = 10; /* first reproductive age level */int pgenage2 = 18; /* second reproductive age level */double distmin = 15; /* minimal seed distance */double distmax = 40; /* maximal seed distance */double pminrad = 9; /* necessary plant radius for reproduction */double pgenfac = 0.5; /* ratio #seeds/radius */ int lag = 15; /* sleeping time for animal at start */double shortstep = 0.4;/* movement of animals inside plant canopy */double longstep = 15; /* movement of animals outside */double f_e = 0.2; /* ratio radius / energy of animals */double init_e = 4; /* initial energy amount of animals */double respi = 0.25; /* energy cosumed by animals' respiration */double thr = 7.6; /* energy threshold for reproduction of animals */double eat = 1.1; /* energy transferred during grazing */ 

Page 38: XL as an extension of the L-system formalism

protected void init(){extent().setDerivationMode(PARALLEL_MODE | EXCLUDE_DELETED_FLAG); [ Axiom ==> Plant(0, seed_rad) [ RH(random(0, 360)) RU(90) M(10) RU(-90) Animal(-lag, f_e*init_e) ]; ]}public void make() { growAnimals(); derive(); growPlants(); } public void growAnimals() [ Animal(t, e), (t < 0) ==> Animal(t+1, e); /* start lag */ Animal(t, e), (e <= 0) ==> ; Animal(t, e), (e > f_e*thr) ==> [ RH(random(0, 360)) RU(90) M(shortstep) RU(-90) Animal(0, e/2 - f_e*respi) ] RH(random(0, 360)) RU(90) M(shortstep) RU(-90) Animal(0, e/2 - f_e*respi); a:Animal(t, e), (* p:Plant(u, r) *), (distance(a, p) < p[radius]) ==> RH(random(0, 360)) RU(90) M(shortstep) RU(-90) Animal(t+1, e + f_e*eat - f_e*respi) { p[radius] :-= eat; }; Animal(t, e) ==> RH(random(0, 360)) RU(90) M(longstep) RU(-90) Animal(t+1, e - f_e*respi); ]

Page 39: XL as an extension of the L-system formalism

public void growPlants() [ Plant(t, r), (t > pmaxage) ==> ; Plant(t, r), (r < 0) ==> ; p:Plant, (* q:Plant *), (distance(p, q) < q[radius] && p[radius] <= q[radius]) ==> ; Plant(t, r), ((t == pgenage1 || t == pgenage2) && r >= pminrad) ==> for ((1 : (int) (pgenfac*r))) ( [ RH(random(0, 360)) RU(90) M(random(distmin, distmax)) RU(-90) Plant(0, seed_rad) ] ) Plant(t+1, r); Plant(t, r) ==> Plant(t+1, r+pgrow); ]

Page 40: XL as an extension of the L-system formalism

Extended L-Systems (XL)Herbivore model: output

1219

55 83

Page 41: XL as an extension of the L-system formalism