tutorials:custom_storing_node
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorials:custom_storing_node [2025/07/16 11:35] – gaetan | tutorials:custom_storing_node [2025/07/16 14:33] (current) – gaetan | ||
---|---|---|---|
Line 53: | Line 53: | ||
**issue:** The queried Nodes and the Nodes contained in the **main graph** do not match anymore. | **issue:** The queried Nodes and the Nodes contained in the **main graph** do not match anymore. | ||
+ | **Note:** The " | ||
==== Storing Nodes in fields ==== | ==== Storing Nodes in fields ==== | ||
Line 98: | Line 99: | ||
**issue:** The queried Nodes and the Nodes contained in the **main graph** do not match anymore. | **issue:** The queried Nodes and the Nodes contained in the **main graph** do not match anymore. | ||
+ | |||
+ | ===== Cause of the " | ||
+ | |||
+ | The graph queries include Node in the whole **project graph**. The **main graph** is only one of the sub-graphs of the project graph. Nodes can exists in the project graph without being part of the main graph. | ||
+ | Additionally, | ||
+ | |||
+ | ===== Avoid the issue ===== | ||
+ | |||
+ | ==== Use the Node id ==== | ||
+ | |||
+ | The graph in GroIMP works basically like a HashMap of id and Nodes. It also includes many other features to access the Nodes, but the base data structure is a HashMap. The Node are added and retrieved using the hash of their id. | ||
+ | Thus, instead of storing the Nodes themselves, their id should be stored. | ||
+ | |||
+ | For example, in the project: | ||
+ | |||
+ | <code java > | ||
+ | long[] mynodeid = new long[1]; | ||
+ | |||
+ | module B(long parentNode); | ||
+ | module A; | ||
+ | |||
+ | protected void init () | ||
+ | [ | ||
+ | Axiom ==> A; | ||
+ | ] | ||
+ | |||
+ | public void dostuff()[ | ||
+ | a:A ==> B(a.getId()) | ||
+ | {mynodeid[0]=a.getId(); | ||
+ | ; | ||
+ | ] | ||
+ | |||
+ | public void queryA() { | ||
+ | dostuff(); | ||
+ | derive(); | ||
+ | println( (*A*)); | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | The method '' | ||
+ | |||
+ | In this example, the Node A is replaced by a Node B in the main graph. Thus, should not exists anymore. But in other project, the Node A can remains in the graph. E.g. | ||
+ | |||
+ | <code java> | ||
+ | long[] mynodeid = new long[1]; | ||
+ | |||
+ | module B(long parentNode); | ||
+ | module A; | ||
+ | |||
+ | protected void init () | ||
+ | [ | ||
+ | Axiom ==> A; | ||
+ | ] | ||
+ | |||
+ | public void dostuff()[ | ||
+ | a:A ==> a B(a.getId()) | ||
+ | {mynodeid[0]=a.getId(); | ||
+ | ; | ||
+ | ] | ||
+ | |||
+ | public void getTheNode(){ | ||
+ | // Get the node from an array | ||
+ | println(mynodeid[0]); | ||
+ | println(graph().getNodeForId((mynodeid[0]))); | ||
+ | |||
+ | // Get the parentNode of B | ||
+ | [b:B ::> println(graph().getNodeForId( b.parentNode)); | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | Here, as the Node A still is in the main graph, it is accessible with methods such as in '' | ||
+ | |||
+ | Using the id instead of the Node to " | ||
+ | |||
+ | ==== Using custom edges ==== | ||
+ | |||
+ | Relationship between objects of the graph should be stored in the graph. Thus, in the example of '' | ||
+ | |||
+ | * For example if B do **NOT** replace A: | ||
+ | <code java> | ||
+ | module A; | ||
+ | module B; | ||
+ | int e = Library.EDGE_0; | ||
+ | |||
+ | protected void init () | ||
+ | [ | ||
+ | Axiom ==> A F ; | ||
+ | ] | ||
+ | |||
+ | public void grow()[ | ||
+ | a:A ==> a B [-e->a]; | ||
+ | ] | ||
+ | </ | ||
+ | |||
+ | {{: | ||
+ | {{ : | ||
+ | |||
+ | One the left: before the " | ||
+ | |||
+ | * If B do replace A. And the relationship between B and A must exists even though A is not part of the **visible** part of the graph. | ||
+ | <code java> | ||
+ | public void grow()[ | ||
+ | a:A ==> B [-e->a]; | ||
+ | ] | ||
+ | </ | ||
+ | |||
+ | will produce the graph: | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | You can see that the Node A is still part of the main graph. It is XL query-able and reachable from B by following the edge EDGE_O. However, as the Node A is not connected to the Root by neither BRANCH, nor SUCCESSOR edge, it will not be displayed (not part of the 3d view, and raytracer). | ||
+ | |||
+ | **Note:** In the example we used EDGE_O, there are actually 13 usable unique bit-wise edge type defined in Library: EDGE_0 to EDGE_12. But it is also possible to use any Integer as " |
tutorials/custom_storing_node.1752658507.txt.gz · Last modified: 2025/07/16 11:35 by gaetan