Git Product home page Git Product logo

view2.5d's Introduction

NetLogo View2.5D Extension

The view2.5d extension allows you to visualize 2d models on a 3d surface, using height to represent agent properties.

Building

Use the netlogo.jar.url environment variable to tell sbt which NetLogo.jar to compile against (defaults to NetLogo 6.0). For example:

sbt -Dnetlogo.jar.url=file:///path/to/NetLogo/target/NetLogo.jar package

If compilation succeeds, view2.5d.jar will be created.

The View2.5D extension offers visualization for Patch and Turtle reporters, in real time, in a simulation's context.

How to Use

The view2.5d extension is pre-installed in NetLogo.

To use the view2.5d extension in your model, add a line to the top of your Code tab:

extensions [view2.5d]

If your model already uses other extensions, then it already has an extensions line in it, so just add view2.5d to the list.

For more information on using NetLogo extensions, see the Extensions Guide

Incorporating Into Models

open a window using either the view2.5d:patch-view or view2.5d:turtle-view commands (it can be a good idea to put these in your 'SETUP' procedure or a separate button).

update your window's view using one of the update commands (put these in your 'GO' procedure).

See the View2.5d Code Examples in the NetLogo models library.

Feedback

Send comments, bugs, or other feedback to CCL Feedback.

Primitives

view2.5d:patch-view view2.5d:decorate-patch-view view2.5d:undecorate-patch-view view2.5d:turtle-view view2.5d:update-all-patch-views view2.5d:update-patch-view view2.5d:update-turtle-view view2.5d:get-z-scale view2.5d:set-z-scale view2.5d:set-turtle-stem-thickness view2.5d:set-turtle-stem-color view2.5d:show-links-xy-plane view2.5d:show-links-xyz view2.5d:get-observer-angles view2.5d:set-observer-angles view2.5d:get-observer-xy-focus view2.5d:set-observer-xy-focus view2.5d:get-observer-distance view2.5d:set-observer-distance view2.5d:remove-patch-view view2.5d:remove-turtle-view view2.5d:remove-all-patch-views view2.5d:remove-all-turtle-views view2.5d:count-windows

view2.5d:patch-view

view2.5d:patch-view Title Reporter

This command must be called from the Observer context. (Attempting to call from another context causes an error) The Title is a string, which will be used to label the new Window and to call for subsequent updates and modifications. Specification of the Reporter uses the NetLogo anonymous procedure syntax, from the Observer perspective.

Example:

view2.5d:patch-view "Test"  [ [the-patch] -> [pxcor] of the-patch ]

view2.5d:decorate-patch-view

view2.5d:decorate-patch-view Title

This command must be called from the Observer context. (Attempting to call from another context causes an error) The Title is a string, the label of an existing Patch View Window. Effect: draws the turtles of the model at their current location, on top of the Patch view display

NOTE: only has an effect in the "structures" patch view (in the others, the patch value is inclined based on neighbors & gradient)

NOTE: for negative patch values, the turtle shapes are drawn below (orbit underneath to see them)

Example:

view2.5d:decorate-patch-view "Test"

view2.5d:undecorate-patch-view

view2.5d:undecorate-patch-view Title

This command must be called from the Observer context. (Attempting to call from another context causes an error)

The Title is a string, the label of an existing Patch View Window. Effect: STOPS drawing the turtles of the model at their current location, on top of the Patch view display

Example:

view2.5d:undecorate-patch-view "Test"

view2.5d:turtle-view

view2.5d:turtle-view Title Agents Reporter

This command must be called from the Observer context. (Attempting to call from another context causes an error) The Title is a string, which will be used to label the new Window and to call for subsequent updates. The turtle-set is any selector for turtles. Reporter is an anonymous reporter that should take a turtle as input, and report some number from it.

Example:

view2.5d:turtle-view "Test" turtles with [color = red] [ the-turtle -> [energy] of the-turtle]
; This would create a new 2.5d window, plotting the ENERGY value of all turtles that are red.

view2.5d:update-all-patch-views

view2.5d:update-all-patch-views

This command must be called from the Observer context. Updates all existing patch-view windows according to the latest values.

view2.5d:update-patch-view

view2.5d:update-patch-view Title

This command must be called from the Observer context. Updates only the patch-view window with the specified title (if any).

view2.5d:update-turtle-view

view2.5d:update-turtle-view Title Agents

This command must be called from the Observer context. Updates only the turtle-view window with the specified title (if any). The turtle-set selector must be supplied to refresh the set of turtles.

view2.5d:get-z-scale

view2.5d:get-z-scale title

This reporter must be called from the Observer context. Returns the current z-scale of the turtle-view or patch-view window with the specified title (if any).

view2.5d:set-z-scale

view2.5d:set-z-scale Title new-z-scale

This command must be called from the Observer context. Updates only the turtle-view or patch-view window with the specified title (if any). The view is now displayed with the new z-scale.

view2.5d:set-turtle-stem-thickness

view2.5d:set-turtle-stem-thickness Title thickness

This command must be called from the Observer context. Updates only the turtle-view window with the specified title (if any). Turtles are now drawn with "pins" or "stems" that have the specified thickness (instead of the hairline default).

view2.5d:set-turtle-stem-color

view2.5d:set-turtle-stem-color Title colorReporter

This command must be called from the Observer context. Updates only the turtle-view window with the specified title (if any). colorReporter is an anonymous reporter that should take a turtle as input, and report some number representing a color from it. Turtles are now drawn with "pins" or "stems" that have the specified color (instead of the grey default).

Example:

;; setup view with 2 turtles
crt 1 [ set color green  setxy 2 3]
crt 1 [ set color red  setxy 5 4]
view2.5d:turtle-view "Test" turtles [ the-turtle -> [ xcor] of the-turtle ]
view2.5d:set-observer-distance "Test" 40
view2.5d:set-z-scale "Test" 2
view2.5d:set-observer-angles "Test" 25 30

;; increase the stem thickness
view2.5d:set-turtle-stem-thickness "Test" .2

;; change the stem color to  match the turtle-color
view2.5d:set-turtle-stem-color "Test" [ the-turtle -> [ color ] of the-turtle ]

; now make the stems orange
view2.5d:set-turtle-stem-color "Test" [ orange ]

view2.5d:show-links-xy-plane

view2.5d:show-links-xy-plane Title

This command must be called from the Observer context. Updates only the turtle-view or patch-view window with the specified title (if any). Links are drawn in the xy-plane (instead of the turtle to turtle default). This option can be selected using the Link Options xy-plane radio Button in the 3D view.

view2.5d:show-links-xyz

view2.5d:show-links-xyz Title

This command must be called from the Observer context. Updates only the turtle-view or patch-view window with the specified title (if any). Links are drawn from turtle to turtle (this is the default way links are displayed). This option can be selected using the Link Options xyz radio Button in the 3D view.

view2.5d:get-observer-angles

view2.5d:get-observer-angles Title

This reporter must be called from the Observer context. Returns a list reflecting the observer's angular perspective { heading pitch } (the place on an imaginary sphere at the zoom distance is updated to obey heading & pitch given)

view2.5d:set-observer-angles

view2.5d:set-observer-angles Title heading pitch

This command must be called from the Observer context. Updates only the turtle-view window with the specified title (if any). Sets the observer's angular perspective (the place on an imaginary sphere at the zoom distance is updated to obey heading & pitch given)

view2.5d:get-observer-xy-focus

view2.5d:get-observer-xy-focus Title

This reporter must be called from the Observer context. Returns a list reflecting the x and y coordinates the observer is "looking at" in the patch plane.

view2.5d:set-observer-xy-focus

view2.5d:set-observer-xy-focus Title number ycor

This command must be called from the Observer context. Updates only the turtle-view window with the specified title (if any). Sets the x and y coordinates the observer that is "looking at" in the patch plane.

view2.5d:get-observer-distance

view2.5d:get-observer-distance Title

This reporter must be called from the Observer context. Returns the observer's distance from its "focus point"

view2.5d:set-observer-distance

view2.5d:set-observer-distance Title new-distance

This command must be called from the Observer context. Updates only the turtle-view window with the specified title (if any). Sets the observer's distance from its "focus point"

view2.5d:remove-patch-view

view2.5d:remove-patch-view Title

This command closes and removes the specified patch view programmatically (equivalent to closing the window manually).

view2.5d:remove-turtle-view

view2.5d:remove-turtle-view Title

This command closes and removes the specified turtle view programmatically (equivalent to closing the window manually).

view2.5d:remove-all-patch-views

view2.5d:remove-all-patch-views

This command closes and removes all patch views programmatically (equivalent to closing the windows manually).

view2.5d:remove-all-turtle-views

view2.5d:remove-all-turtle-views

This command closes and removes all turtle views programmatically (equivalent to closing the windows manually).

view2.5d:count-windows

view2.5d:count-windows

This reporter returns the number of turtle and patch views that are currently active.

Acknowledgement

For development of the View 2.5D NetLogo Extension, we acknowledge financial support from Joshua M. Epstein's NIH Director's Pioneer Award (DP1).

view2.5d's People

Contributors

aab77 avatar brandesnw avatar cbradyatinquire avatar lacuneta avatar mrerrormessage avatar nicolaspayette avatar qiemem avatar thebizzle avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

kleopatra999

view2.5d's Issues

NullPointerException when deleting a shape and closing/opening a turtle view

Using the sample model from issue #11, update it to extract the view2.5d turtle view setup like below, to be able to call it stand-alone:

to setup-turtle-view
  ; Set up a Turtle view
  view2.5d:turtle-view "Turtle View 1" turtles [ the-turtle -> [.2 * abs xcor] of the-turtle ]
  wait 1
  view2.5d:set-observer-distance "Turtle View 1" 40

  view2.5d:set-z-scale "Turtle View 1" 2
  view2.5d:set-observer-angles "Turtle View 1" 25 30
  ;; increase the stem thickness
  view2.5d:set-turtle-stem-thickness "Turtle View 1" .2
  view2.5d:update-turtle-view "Turtle View 1" turtles
end

I then could produce an exception reliably with these steps:

  • I ran setup then create-arrow and confirmed things looked good in both views.
  • I went into the shapes editor and deleted the arrow shape and things updated in both views.
  • I closed the turtle view.
  • I ran setup-turtle-view in the command center, and got the below exception.
NetLogo is unable to supply you with more details about this error.  Please report the problem
 at https://github.com/NetLogo/NetLogo/issues, or to [email protected], and paste the
contents of this window into your report.


com.jogamp.opengl.GLException: Caught NullPointerException: null on thread AWT-EventQueue-0
 at com.jogamp.opengl.GLException.newGLException(GLException.java:76)
 at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1327)
 at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
 at com.jogamp.opengl.awt.GLCanvas$12.run(GLCanvas.java:1442)
 at com.jogamp.opengl.Threading.invoke(Threading.java:223)
 at com.jogamp.opengl.awt.GLCanvas.display(GLCanvas.java:503)
 at com.jogamp.opengl.awt.GLCanvas.paint(GLCanvas.java:557)
 at sun.awt.RepaintArea.paintComponent(RepaintArea.java:264)
 at sun.awt.X11.XRepaintArea.paintComponent(XRepaintArea.java:64)
 at sun.awt.RepaintArea.paint(RepaintArea.java:240)
 at sun.awt.X11.XComponentPeer.handleEvent(XComponentPeer.java:584)
 at java.awt.Component.dispatchEventImpl(Component.java:4965)
 at java.awt.Component.dispatchEvent(Component.java:4711)
 at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
 at java.awt.EventQueue.access$500(EventQueue.java:97)
 at java.awt.EventQueue$3.run(EventQueue.java:709)
 at java.awt.EventQueue$3.run(EventQueue.java:703)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
 at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
 at java.awt.EventQueue$4.run(EventQueue.java:733)
 at java.awt.EventQueue$4.run(EventQueue.java:731)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
 at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
 at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
 at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
 at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
 at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.NullPointerException
 at view25d.view.gl.TurtleGL.display(TurtleGL.java:154)
 at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692)
 at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674)
 at com.jogamp.opengl.awt.GLCanvas$11.run(GLCanvas.java:1428)
 at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293)
 ... 29 more

NetLogo 6.2.0
main: org.nlogo.app.AppFrame
thread: AWT-EventQueue-0
OpenJDK 64-Bit Server VM 1.8.0_292 (BellSoft; 1.8.0_292-b10)
operating system: Linux 5.8.0-50-generic (amd64 processor)
Scala version 2.12.12
JOGL: (3D View not initialized)
OpenGL Graphics: (3D View not initialized)
model: test-25dshape-change

08:13:56.408 PeriodicUpdateEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
08:13:56.401 PeriodicUpdateEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
08:13:56.399 AddJobEvent (org.nlogo.app.common.CommandLine) AWT-EventQueue-0
08:13:56.399 OutputEvent (org.nlogo.app.common.CommandLine) AWT-EventQueue-0
08:13:56.399 CompiledEvent (org.nlogo.window.CompilerManager) AWT-EventQueue-0
08:13:56.394 CompileMoreSourceEvent (org.nlogo.app.common.CommandLine) AWT-EventQueue-0
08:13:56.237 PeriodicUpdateEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
08:13:56.037 PeriodicUpdateEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
08:13:55.836 PeriodicUpdateEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
08:13:55.636 PeriodicUpdateEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0

Interestingly, the shape delete is necessary to reproduce the error. Just closing the turtle view isn't enough to trigger it, if you re-run the setup-turtle-view without deleting the shape it'll complete just fine. This error was found with the PR for issue #11 merged, as well as with the bundled version in NetLogo 6.2.0.

view2.5d:turtle-view raises NullPointerExceptation error

I want to show the property of turtles using 2.5d-view, but it always gives NullPointerExceptation error.
e.g. the following simple codes.

extensions [view2.5d]

turtles-own[
energy
]

to setup
ca
create-turtles 50[
set color red
setxy random-xcor random-ycor
set energy random 1000
]
create-turtles 50[
set energy random 1000
setxy random-xcor random-ycor
]
view2.5d:turtle-view "test" turtles [the-turtle -> [energy] of the-turtle]
reset-ticks
end

Error after running slime for a while

java.util.ConcurrentModificationException
 at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
 at java.util.AbstractList$Itr.next(AbstractList.java:343)
 at view25d.view.gl.PatchGL.display(PatchGL.java:250)
 at com.sun.opengl.impl.GLDrawableHelper.display(GLDrawableHelper.java:78)
 at javax.media.opengl.GLCanvas$DisplayAction.run(GLCanvas.java:435)
 at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:194)
 at javax.media.opengl.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:412)
 at javax.media.opengl.GLCanvas.display(GLCanvas.java:244)
 at javax.media.opengl.GLCanvas.paint(GLCanvas.java:277)
 at javax.media.opengl.GLCanvas.update(GLCanvas.java:354)
 at sun.awt.RepaintArea.updateComponent(RepaintArea.java:267)
 at sun.awt.RepaintArea.paint(RepaintArea.java:233)
 at apple.awt.ComponentModel.handleEvent(ComponentModel.java:263)
 at java.awt.Component.dispatchEventImpl(Component.java:4852)
 at java.awt.Component.dispatchEvent(Component.java:4604)
 at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:717)
 at java.awt.EventQueue.access$400(EventQueue.java:82)
 at java.awt.EventQueue$2.run(EventQueue.java:676)
 at java.awt.EventQueue$2.run(EventQueue.java:674)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
 at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:97)
 at java.awt.EventQueue$3.run(EventQueue.java:690)
 at java.awt.EventQueue$3.run(EventQueue.java:688)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
 at java.awt.EventQueue.dispatchEvent(EventQueue.java:687)
 at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
 at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
 at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
 at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

I suspect this is a timing bug that will be hard to reproduce. I had messed around with the view (just mouse manipulation, not code), but wasn't when the error occurred.

The view2.5D extension does not handle shape changes

In view2.5D extension if a shape is created, edited, deleted or imported no corresponding action happens in the 3D view.
Shapes can be turtle or link shapes.

Except in the case of editing a shape, an uncaught exception occurs.

To reproduce the bug.

Create a model that includes the following code

extensions [ view2.5d ]

to setup
  view2.5d:remove-all-turtle-views
  view2.5d:remove-all-turtle-views

  view2.5d:turtle-view "Test" turtles [ the-turtle -> [3 +  abs xcor] of the-turtle ]
  wait 1
  view2.5d:set-observer-distance "Test" 40

  view2.5d:set-z-scale "Test" 2
  view2.5d:set-observer-angles "Test" 25 30
  ;; increase the stem thickness
  view2.5d:set-turtle-stem-thickness "Test" .2
  view2.5d:update-turtle-view "Test" turtles
end

to create-ambulance
  create-turtles 1 [ set color orange set size 4 set shape "ambulance" setxy -2 3]
  view2.5d:update-turtle-view "Test" turtles
end

  1. Open the model
  2. Run the setup procedure
  3. Import the ambulance shape
  1. Open the Turtle Shapes Editor from the Tools menu
  2. Click on Import from Library ...
  3. Click on the ambulance entry
  4. Click Import
  1. Run the create-ambulance procedure

Result is

NetLogo is unable to supply you with more details about this error. Please report the problem
at https://github.com/NetLogo/NetLogo/issues, or to [email protected], and paste the
contents of this window into your report.

com.jogamp.opengl.GLException: Caught NullPointerException: null on thread AWT-EventQueue-0
at com.jogamp.opengl.GLException.newGLException(GLException.java:76)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1327)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
at com.jogamp.opengl.awt.GLCanvas$12.run(GLCanvas.java:1442)

...

Drawing links

Thanks for the handy extension. Have you ever looked into drawing links between turtles? It would be very handy for my work. I can code Java and would be very grateful for a few hints to get me going. -- Thanks greatly Rob

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.