Lesson 3: Modify and write a first rule

Lesson 2

 

In this lesson you will learn how to use the Jerboa editor to write rules like the ones you have used in the generated modeler. You will continue to use this same modeler as the first two lessons but you will be running it as a java project and modifying it in the editor.

The Jerboa package includes an Editor, a Core Library and a Viewer Library. The editor will enable you to edit the generated modeler kernel and it’s rules, the core library enables you to interpret the modeler and apply the rules you write to compute operations and the viewer library enables you to launch a viewer in the project to manipulate the modeler kernel with a graphic interface.

First let’s set up your development environment.

 

DOWNLOAD AND INSTALL

You will need an IDE ( Integrated Development Environment). This tutorial is written for the use of Eclipse but you can use the IDE of your choosing, just remember to adjust certain instructions to fit.

You will also need to download the Jerboa Modeler Editor V2 and the Tutorial package.

  • the editor is a jar file so you may have to change the access rights to launch it by opening a terminal in the same directory as the jar file and type « chmod 755 JerboaModelerEditor.jar » if you are using linux

You should now be able to open the editor with a double click on the file icon.

  • copy the « JerboaTurorial1 » package to your IDE workspace and unpack it
  • open the « JerboaTutorial1 » project in your IDE of choice

In eclipse this is done by creating a « New Java Project »,  giving it a name « JerboaTutorial1 » and setting the « JerboaTutorial1 » folder as the project directory as shown in screen 3.1.

Sorry, you'll ahve to use your imagination
Screen 3.1: New java project

You should be all set!

MODIFYING YOUR FIRST RULE

  • open the project in your IDE
  • launch the viewer this time by executing the « Launcher » file in « src – jerboatutorial1 » (right click – run as – Java application)
  • execute “c_IcositeHexagon”
  • select a dart on the object
  • apply the  “MakeBlue” rule and observe it’s behavior

Any modification of an object is achieved by modifying it with rules.

A rule in Jerboa includes the transformation of a graph (which is the topology) and the modification of embeddings (the geometric, physical and applicative characteristics).

A rule consists of two patterns, the left pattern specifies which sub-graph is to be matched (the matched sub-graph is the one to which the rule is applied) and the right pattern specifies which transformations are to be applied to the matched pattern. Each embedding of the transformed pattern can be modified with an embedding expression in the Jerboa language.

 

  • open the Jerboa editor that you downloaded and load the editor (go to « file » « load » and select the « jerboatutorial1.jme » file which you will find in the main directory of the JerboaTutorial1 java project)
  • double click on the « MakeBlue » rule in the Lesson3 folder, it will open and you can now edit it (see Screen 3.2).

This rule is exactly the same as the MakeRed rule from Lesson2 only it makes faces blue instead of making them red.

 

Screen 3.2: The MakeBlue rule in the editor

 

Note that the node in the left pattern has two rings.

This indicates that the node is also a hook which is the starting node for matching the graph to be transformed. The hook corresponds to the dart you will select when you want to apply the rule in the viewer.

The orbit of the nodes in the left pattern indicates which arcs are to be used to match the sub-graph starting from the hook (in this case <> is the orbit of a dart).

  • change the color embedding of the dart in the RightPattern
    • click on the dart in the RightPattern
    • select the color embedding and click EDIT
    • change the color in the embedding expression (see Screen 3.3) (using the java.awt.color preset colors like « color::YELLOW »
    • click on « Apply »
Sorry, you'll have to use your imagination !
Screen 3.3: The color embedding expression

 

It is important to always click on « Apply » when modifying an expression to make sure it is saved to the rule.

  • rename the rule to fit the color you chose by opening the « Details » tab (see Screen3.4) and changing the name
Sorry, you'll have to use your imagination !
Screen 3.4: The details tab
  • click on Apply, save the modeler (ctrl+s) and then export the code to the project (file : export Java)

Remember that if you only export the modeler without saving it you will be able to use the rules you wrote in your modeler project but you won’t be able to modify them the next time you use the editor because your changes won’t have been saved to the modeler.jme file. Think to save the modeler as regularly as possible.

  • open the IDE, refresh the project to update the modeler and execute the Launcher again after having closed it
  • try the first steps again to see what has changed when you apply the new rule, you should see the faces around your selected dart change to the color you chose

 

MODIFYING A SECOND RULE

The Jerboa viewer shows a 3D render of objects created and modified with the modeler generated kernel. The x axis is red, the y axis is green and the z axis is blue.

  • select a dart on the object
  • apply the  “MoveDown” rule and observe it’s behavior
  • open the editor and double click on the name of the rule to edit it
  • change the point embedding on the node in the right pattern

    • select the node in the right pattern
    • select the point embedding and click EDIT
    • modify the embedding expression (see Screen 3.5) to change the coordinates of the returned point
Screen 5.3: point embedding expression

 

  • rename the rule by opening the « Details » tab and changing the name
  • click on Apply, save the modeler (ctrl+s) and then export (file : export Java)
  • open the IDE, refresh the project to update the modeler and execute the Launcher again
  • try the first steps again to see what has changed when you apply your new rule

A rule uses the left pattern to match the correct graph starting from the hook node and following the given orbit. The graph is transformed to suite the graph in the right pattern. The embeddings are changed by the embedding expressions in the rule. Note that when an embedding is modified it is changed for every dart in the orbit to which it is associated even if another orbit is specified in the rule. You may have noticed that the MakeBlue rule made the whole face blue even though the orbit of the hook in the left pattern is the orbit of a dart.

WRITING YOUR FIRST RULE

Now you will create a new rule which applies the operations of the two previous rules.

  • open the editor and click on the New Atomic Rule button
  • call the rule “MakeBlueMoveDown” and press enter
  • right click in the left pattern to create a node and then select it with the left click
  • tick the Hook box

This node doesn’t need an orbit because when we modify the embedding, this modification will automatically be applied to all the darts in the orbit with which the embedding is associated.

  • create a node in the right pattern
  • edit the point embedding of the node in the right pattern to be the same as that of the MoveDown rule
  • edit the color embedding of the same node to be the same as that of the MakeBlue rule
  • save the modeler and export it
  • open the IDE, refresh the project to update the modeler and execute the Launcher again
  • try your rule on a dart of the IcositeHexagon

 


What have your learned?

  • How many embedding expressions can be written for each node ?
  • Which darts are matched by a hook node ?
  • What is the difference between saving and exporting?

Lesson 4