Skip to content

Commit

Permalink
test structure initial
Browse files Browse the repository at this point in the history
  • Loading branch information
Ou-An Chuang authored and Ou-An Chuang committed Nov 17, 2022
1 parent 98ab349 commit 298c64b
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "templates"]
path = templates
url = https://github.com/junqi108/functional-structural-model-templates.git
url = https://github.com/junqi108/functional-structural-model-templates
1 change: 0 additions & 1 deletion experiments/README.md

This file was deleted.

48 changes: 45 additions & 3 deletions src/graph.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?><graph xmlns:gx="http://grogra.de/xmlpersistence" xmlns="http://grogra.de/xmlpersistence">
<node root="MainGraph" id="0" type="de.grogra.graph.impl.Node">
<data gx:name="extentIndex" gx:value="7"/>
<node id="360" type="de.grogra.rgg.RGGRoot" edges="+">
<node id="362" type="main$Bud" edges="-"/>
<node id="14737" type="de.grogra.rgg.RGGRoot" edges="+">
<node id="14739" type="organs$Bud" edges="-">
<data gx:name="radius" gx:value="0.1"/>
<data gx:name="rank" gx:value="1"/>
<data gx:name="phyllo" gx:value="1"/>
<data gx:name="order" gx:value="1"/>
</node>
<node id="14740" type="de.grogra.turtle.M" edges="-">
<data gx:name="length" gx:value="50.0"/>
<node id="14741" type="de.grogra.turtle.RU" edges="-">
<data gx:name="angle" gx:value="180.0"/>
<node id="14742" type="light$MyLight" edges="-">
<object gx:name="light" gx:type="de.grogra.imp3d.objects.SpotLight">
<object gx:name="color" gx:value="false 1.0 1.0 1.0"/>
<data gx:name="shadowless" gx:value="false"/>
<data gx:name="visualize" gx:value="false"/>
<data gx:name="numberofrays" gx:value="500"/>
<data gx:name="raylength" gx:value="5.0"/>
<data gx:name="power" gx:value="200.0"/>
<data gx:name="attenuationExponent" gx:value="0.0"/>
<data gx:name="attenuationDistance" gx:value="50.0"/>
<data gx:name="innerAngle" gx:value="0.3926991"/>
<data gx:name="outerAngle" gx:value="0.5235988"/>
</object>
</node>
</node>
</node>
</node>
</node>
<node root="MetaGraph" id="1" type="de.grogra.graph.impl.Node">
<data gx:name="extentIndex" gx:value="7"/>
<node id="359" type="main" edges="+">
<node id="14734" type="main" edges="+">
<data gx:name="extentIndex" gx:value="7"/>
<object gx:name="initialTurtleState" color="14" length="100.0" diameter="0.1" tropism="0.0" parameter="0.0" carbon="0.0" heartwood="0.0" internodeCount="0"/>
<object gx:name="lm" gx:type="de.grogra.rgg.LightModel">
<data gx:name="rayCount" gx:value="100000"/>
<data gx:name="depth" gx:value="5"/>
<data gx:name="minPower" gx:value="0.001"/>
<data gx:name="seed" gx:value="0"/>
<data gx:name="threadCount" gx:value="0"/>
<object gx:name="spectrumFactory" gx:type="de.grogra.ray.physics.Spectrum3d" gx:value="0.0 0.0 0.0"/>
<array gx:name="visibleLayers" gx:value="true true true true true true true true true true true true true true true true"/>
</object>
</node>
<node id="14735" type="light" edges="+">
<data gx:name="extentIndex" gx:value="7"/>
<object gx:name="initialTurtleState" color="14" length="100.0" diameter="0.1" tropism="0.0" parameter="0.0" carbon="0.0" heartwood="0.0" internodeCount="0"/>
</node>
<node id="14736" type="organs" edges="+">
<data gx:name="extentIndex" gx:value="7"/>
<object gx:name="initialTurtleState" color="14" length="100.0" diameter="0.1" tropism="0.0" parameter="0.0" carbon="0.0" heartwood="0.0" internodeCount="0"/>
</node>
Expand Down
89 changes: 46 additions & 43 deletions src/main.rgg
Original file line number Diff line number Diff line change
@@ -1,49 +1,52 @@
/**
* The base module for all organs.
*
* @author James Bristow
* @version 1.0
* @since 04-08-2022
*/
abstract module Organ(float len) extends Sphere(0.1)
{
{setShader(GREEN);}
}

/**
* The bud organ.
*
* @author James Bristow
* @version 1.0
* @since 04-08-2022
*/
module Bud extends Organ(0.1) {

protected int ID;
import static light.*;
import static organs.*;

/**
* Gets a plant ID value.
*
* @return The organ ID.
*/
public int getID() {
return ID;
}
}
const float GOLDEN_ANGLE = 137.5;
const float BRANCH_ANGLE = 50;
const float LEAF_ANGLE = 70;
const int PHYLLOCHRON = 1;

/**
* Initialise the model.
*
*/
protected void init ()
protected void init()
[
Axiom ==> Bud;
Axiom ==> Bud(1, PHYLLOCHRON, 1);
// light source is placed
// above the scene
==>> ^ M(50) RU(180) MyLight;
]

/**
* Runs each time step of the simulation.
*/
public void run ()
public void run()
[
Bud ==> F(0.5) [RU(30) RH(90) Bud] [RU(-30) RH(90) Bud];
Bud(r, p, o), (p > 0) ==> Bud(r, p-1, o);
b:Bud(r, p, o), (r < 10 && p == 0 && o < 4) ==> if (forall(distance(b, (* Internode *)) > 0.6)) (
RV(-0.1) Internode Node
[ RL(BRANCH_ANGLE) Bud(r, PHYLLOCHRON, o+1) ]
[ RL(LEAF_ANGLE) Leaf(0f) ]
RH(GOLDEN_ANGLE) RV(-0.1) Internode Bud(r+1, PHYLLOCHRON, o)
);

Bud(r, p, o), (r == 10) ==> RV(-0.1) Internode RV(-0.1) Internode Flower;
]

// light model instance
// 100000: number of random rays
// 5: recursion depth (nb. of reflections)
LightModel lm = new LightModel(100000, 5);

public void grow() {
// apply growth rules
run();
// compute light
lm.compute();
// calculate the amount of light
// (integrated over the whole spectrum),
// absorbed by a leaf
absorb();
}

protected void absorb() [
lf:Leaf ::> {
// 2.25 - conversion factor W -> PAR
// (photosynthetically active radiation [mikro mol/m^2/s])
lf[al] = lm.getAbsorbedPower3d(lf).integrate() * 2.25;
//println(lf[al]);
}
]
14 changes: 14 additions & 0 deletions src/modules/light.rgg
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// the light source
module MyLamp extends SpotLight {
{
setPower(200.0); // power in W
setAttenuationDistance(50.0); // in m
setAttenuationExponent(0.0);
setInnerAngle(22.5 * Math.PI/180.0);
setOuterAngle(30.0 * Math.PI/180.0);
}
}
// light specification with colour (R, G, B)
module MyLight extends LightNode(1.0, 1.0, 1.0) {
{ setLight(new MyLamp()); }
}
40 changes: 40 additions & 0 deletions src/modules/organs.rgg
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const ShaderRef leafmat = new ShaderRef("Leafmat");
const ShaderRef petalmat = new ShaderRef("Petalmat");
const ShaderRef internodemat = new ShaderRef("Internodemat");
const ShaderRef nodemat = new ShaderRef("Nodemat");

// buds are red spheres
module Bud(int rank, int phyllo, int order) extends Sphere(0.1) {
{ setShader(nodemat); }
}
module Node extends Sphere(0.07) {
{ setShader(nodemat); }
}
module Internode extends Cylinder(1, 0.05) {
{ setShader(internodemat); }
}
module Leaf(float al) extends Parallelogram(2, 1) {
{ setShader(leafmat); }
}
module Flower ==>
RU(180) Cone(0.3, 0.3).(setShader(internodemat))
M(-0.25) RL(90)
[
for (int i = 1; i <= 5;i++) (
[ RU(i*360/5) RL(20) Parallelogram(2, 1).(setShader(petalmat)) ]
)
]
RU(45)
[
for (int i = 1; i <= 5; i++) (
[ RU(i*360/5) RL(40) F(0.3, 0.1, 14)
RV(-0.3) F(0.3, 0.1, 14) RV(-0.3) F(0.3, 0.1, 14) ]
)
]
RU(-45)
[
for (int i = 1; i <= 5; i++) (
[ RU(i*360/5) RL(70) Frustum(0.7, 0.2, 0.05).(setColor(0x8DAF58)) ]
)
]
;
22 changes: 13 additions & 9 deletions src/project.gs
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://grogra.de/registry" graph="graph.xml">
<import plugin="de.grogra.math" version="1.6"/>
<import plugin="de.grogra.ray" version="1.6"/>
<import plugin="de.grogra.imp" version="1.6"/>
<import plugin="de.grogra.imp3d" version="1.6"/>
<import plugin="de.grogra.pf" version="1.6"/>
<import plugin="de.grogra.rgg" version="1.6"/>
<import plugin="de.grogra.imp" version="1.6"/>
<import plugin="de.grogra.pf" version="1.6"/>
<registry>
<ref name="project">
<ref name="objects">
<ref name="files">
<de.grogra.pf.ui.registry.SourceFile mimeType="text/x-grogra-rgg" name="pfs:main.rgg"/>
<de.grogra.pf.ui.registry.SourceFile mimeType="text/x-grogra-xl" name="/var/model/src/shared/graph/GraphExport.xl"/>
<de.grogra.pf.ui.registry.SourceFile mimeType="text/x-grogra-rgg" name="/var/model/src/modules/light.rgg"/>
<de.grogra.pf.ui.registry.SourceFile mimeType="text/x-grogra-rgg" name="/var/model/src/modules/organs.rgg"/>
</ref>
<ref name="meta">
<de.grogra.pf.registry.NodeReference name="main" ref="359"/>
<de.grogra.pf.registry.NodeReference name="main" ref="14734"/>
<de.grogra.pf.registry.NodeReference name="light" ref="14735"/>
<de.grogra.pf.registry.NodeReference name="organs" ref="14736"/>
</ref>
</ref>
</ref>
<ref name="workbench">
<ref name="state">
<de.grogra.pf.ui.registry.Layout name="layout">
<de.grogra.pf.ui.registry.MainWindow>
<de.grogra.pf.ui.registry.Split location="0.49267015">
<de.grogra.pf.ui.registry.Split location="0.68154156" orientation="0">
<de.grogra.pf.ui.registry.Split location="0.52677166">
<de.grogra.pf.ui.registry.Split location="0.8" orientation="0">
<de.grogra.pf.ui.registry.Split orientation="0">
<de.grogra.pf.registry.Link source="/ui/panels/rgg/toolbar"/>
<de.grogra.pf.ui.registry.PanelFactory source="/ui/panels/3d/defaultview">
<de.grogra.pf.registry.Option name="panelId" type="java.lang.String" value="/ui/panels/3d/defaultview"/>
<de.grogra.pf.registry.Option name="panelTitle" type="java.lang.String" value="View"/>
<de.grogra.pf.registry.Option name="view" type="de.grogra.imp3d.View3D" value="graphDescriptor=[de.grogra.imp.ProjectGraphDescriptor]visibleScales={true true true true true true true true true true true true true true true}visibleLayers={true true true true true true true true true true true true true true true true}epsilon=1.0E-6 visualEpsilon=0.01 magnitude=1.0 camera=(minZ=0.1 maxZ=2000.0 projection=[de.grogra.imp3d.PerspectiveProjection aspect=1.0 fieldOfView=1.0471976]transformation=(1.0 0.0 0.0 0.0 0.0 0.7071067811865476 0.7071067811865475 0.0 0.0 -0.7071067811865475 0.7071067811865476 -8.0 0.0 0.0 0.0 1.0))navigator=null"/>
<de.grogra.pf.registry.Option name="view" type="de.grogra.imp3d.View3D" value="graphDescriptor=[de.grogra.imp.ProjectGraphDescriptor]visibleScales={true true true true true true true true true true true true true true true}visibleLayers={true true true true true true true true true true true true true true true true}epsilon=1.0E-6 visualEpsilon=0.01 magnitude=1.0 camera=(minZ=0.1 maxZ=2000.0 projection=[de.grogra.imp3d.PerspectiveProjection aspect=1.0 fieldOfView=1.0471976]transformation=(0.0026110166485736885 0.9999965912902207 0.0 0.0 -0.18924923304053543 4.941345825598123E-4 0.9819289605794219 0.0 0.9819256134685717 -0.0025638328637891117 0.18924987813844601 -40.82507045481592 0.0 0.0 0.0 1.0))navigator=null"/>
</de.grogra.pf.ui.registry.PanelFactory>
</de.grogra.pf.ui.registry.Split>
<de.grogra.pf.ui.registry.Split orientation="0">
Expand All @@ -38,10 +42,10 @@
<de.grogra.pf.registry.Link source="/ui/panels/statusbar"/>
</de.grogra.pf.ui.registry.Split>
</de.grogra.pf.ui.registry.Split>
<de.grogra.pf.ui.registry.Split location="0.69776875" orientation="0">
<de.grogra.pf.ui.registry.Split location="0.51968503" orientation="0">
<de.grogra.pf.ui.registry.Tab selectedIndex="0">
<de.grogra.pf.ui.registry.PanelFactory source="/ui/panels/texteditor">
<de.grogra.pf.registry.Option name="documents" type="java.lang.String" value="&quot;\&quot;/var/model/src/shared/config/Config.xl\&quot;,\&quot;/var/model/src/shared/services/Container.xl\&quot;,\&quot;/var/model/src/shared/graph/GraphExport.xl\&quot;,\&quot;pfs:main.rgg\&quot;&quot;"/>
<de.grogra.pf.registry.Option name="documents" type="java.lang.String" value="&quot;\&quot;pfs:main.rgg\&quot;&quot;"/>
<de.grogra.pf.registry.Option name="panelId" type="java.lang.String" value="/ui/panels/texteditor"/>
<de.grogra.pf.registry.Option name="panelTitle" type="java.lang.String" value="jEdit - main.rgg"/>
<de.grogra.pf.registry.Option name="selected" type="java.lang.String" value="pfs:main.rgg"/>
Expand Down

0 comments on commit 298c64b

Please sign in to comment.