Performance slow down when addind Point to the Graph

260 views
Skip to first unread message

Julien Martin

unread,
Jul 15, 2014, 2:21:55 PM7/15/14
to jz...@googlegroups.com

Hello everyone.
I am working on optimization problem. I am using Jzy3d to plot Point during my optimization process.
Each time a solution has been calculated by my optimization process, i create a Point, put its coordinates to the solution's value, and i add it to the Graph.
So my optimization process is dynamically adding Point to the graph.

At first, i was only plotting relevant solution, and performance was nice. Today i decided to plot every calcul point in order to better visualize my optimization process and debug it.
It appears adding Point is costly and slow down my optimization process heavily.

I am doing like this :

//a solution with coordinates (xd, yd, zd) has been found
Point p = new Point(new Coord3d(xd, yd, zd), Color.RED, 2);
graph
.add(p, false);

Is there a better way to add dynamically point to a graph in order to get better performance?
I allready tried to add lots of Points to the graph before my optimization process is started, with random coordinates and setDisplayed(false). When a solution is found i set the coordinates of one of those point and setDisplayed(true).
It's better performance wize, but i don't know how much Point i will get and it's not a really good way of coding...

Thank you!

Jzy3d version : 0.9
JOGL version : 2.0



Martin Pernollet

unread,
Jul 15, 2014, 2:46:08 PM7/15/14
to Jzy3d
Well you are doing it right.

Can you quantify how performance drop?

Just an idea : maybe you could use a different thread than your calculation thread to add the point to the graph? Executor and Runnable are your friends.

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "Jzy3d".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse jzy3d+un...@googlegroups.com.
Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.

Klemen Zhivko

unread,
Nov 5, 2014, 4:21:39 AM11/5/14
to jz...@googlegroups.com
I have somehow similar problem.
While adding any Drawable from another Runnable thread I am getting lock in this line of my sample:
SurfaceDemo2.instance.chart.getScene().add(cyl);     // line 742 in SurfaceDemo2.java
 and then I get this in Console:
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Waited 5000ms for: <3d11791d, 4b0a015a>[count 163, qsz 0, owner <Default RequestProcessor-Display-.x11_:0-1-EDT-1>] - <AWT-EventQueue-0>
at jogamp.common.util.locks.RecursiveLockImpl01Unfairish.lock(RecursiveLockImpl01Unfairish.java:198)
at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:669)
at org.jzy3d.plot3d.rendering.canvas.CanvasNewtAwt.display(CanvasNewtAwt.java:99)
at org.jzy3d.plot3d.rendering.canvas.CanvasNewtAwt.forceRepaint(CanvasNewtAwt.java:104)
at org.jzy3d.plot3d.rendering.view.View.shoot(View.java:131)
at org.jzy3d.plot3d.rendering.view.View.updateBounds(View.java:553)
at org.jzy3d.plot3d.rendering.scene.Graph.add(Graph.java:100)
at org.jzy3d.plot3d.rendering.scene.Graph.add(Graph.java:104)
at org.jzy3d.plot3d.rendering.scene.Scene.add(Scene.java:95)
at com.kz.grbl.SurfaceDemo2$Visualizer.run(SurfaceDemo2.java:742)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:744)
at java.awt.EventQueue.access$400(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:697)
at java.awt.EventQueue$3.run(EventQueue.java:691)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:714)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
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)

Is it possible to add dynamical points in other thread than Thread: "Default RequestProcessor".
I am attaching maven project.

Library is very promising and I would like to use it... However it looks to me that dynamically adding points is basic functionality and should already be supported - what I am doing wrong?

regards



Dne torek, 15. julij 2014 20:46:08 UTC+2 je oseba Martin napisala:
grbl.zip

Martin Pernollet

unread,
Nov 5, 2014, 1:52:23 PM11/5/14
to Jzy3d
it is not related at all :)

I am surprised as the Graph.add method is synchronized.
Looking at stack trace I think you could try :

chart.getScene().getGraph().add(bla, FALSE); // no redraw
// then
chart.render()

Klemen Zhivko

unread,
Nov 6, 2014, 5:22:35 AM11/6/14
to jz...@googlegroups.com
Thanks Martin for fast reply.

Your suggestion works, but graph doesn't repaint itself now.
If I try using line, to force refresh
SurfaceDemo2.instance.chart.render();
it causes lock in code like it would be synchronous call, but after 5seconds I get this exception again

Exception in thread "main-AWTAnimator" com.jogamp.opengl.util.AnimatorBase$UncaughtAnimatorException: java.lang.RuntimeException: Waited 5000ms for: <79f3aebd, 4e61db59>[count 195, qsz 0, owner <main-Display-.x11_:0-1-EDT-1>] - <main-AWTAnimator>
at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:84)
at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:446)
at com.jogamp.opengl.util.Animator$MainLoop.run(Animator.java:198)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: Waited 5000ms for: <79f3aebd, 4e61db59>[count 195, qsz 0, owner <main-Display-.x11_:0-1-EDT-1>] - <main-AWTAnimator>
at jogamp.common.util.locks.RecursiveLockImpl01Unfairish.lock(RecursiveLockImpl01Unfairish.java:198)
at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:669)
at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:77)
... 3 more
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Waited 5000ms for: <79f3aebd, 4e61db59>[count 195, qsz 0, owner <main-Display-.x11_:0-1-EDT-1>] - <AWT-EventQueue-0>
at jogamp.common.util.locks.RecursiveLockImpl01Unfairish.lock(RecursiveLockImpl01Unfairish.java:198)
at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:669)
at org.jzy3d.plot3d.rendering.canvas.CanvasNewtAwt.display(CanvasNewtAwt.java:99)
at org.jzy3d.plot3d.rendering.canvas.CanvasNewtAwt.forceRepaint(CanvasNewtAwt.java:104)
at org.jzy3d.plot3d.rendering.view.View.shoot(View.java:131)
at org.jzy3d.chart.Chart.render(Chart.java:143)
at com.kz.grbl.SurfaceDemo2$Visualizer.run(SurfaceDemo2.java:630)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:744)
at java.awt.EventQueue.access$400(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:697)
at java.awt.EventQueue$3.run(EventQueue.java:691)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:714)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
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)


Dne sreda, 05. november 2014 19:52:23 UTC+1 je oseba Martin napisala:
Message has been deleted

Klemen Zhivko

unread,
Nov 6, 2014, 11:51:31 AM11/6/14
to jz...@googlegroups.com
To animate problem I recorded video (without chart.render() since it locks execution also). You can see animation works when I rotate chart by mouse, but self alone it doesn't.

I would need this immediate redraw functionality chart.render() also cause hang to code.

I attached also latest maven source project.
It seems that animation doesn't work when adding from event dispatch thread...
regards

Dne četrtek, 06. november 2014 11:22:35 UTC+1 je oseba Klemen Zhivko napisala:
AnimateProblem.mkv
grbl.zip

Klemen Zhivko

unread,
Nov 7, 2014, 3:29:32 AM11/7/14
to jz...@googlegroups.com
OK, I isolated code that stops animator working properly - I think it is pickingsupport...

So this code is not ok :).

Does anybody have sample of picking support that works with:
<dependency>
<groupId>org.jzy3d</groupId>
<artifactId>jzy3d-api</artifactId>
<version>0.9.2-SNAPSHOT</version>
</dependency>
and
<dependency>
<groupId>org.jogamp.gluegen</groupId>
<artifactId>gluegen-rt-main</artifactId>
<!-- <version>2.1.5-01</version> -->
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.jogamp.jogl</groupId>
<artifactId>jogl-all-main</artifactId>
<!-- <version>2.1.5-01</version> -->
<version>2.2.1</version>
</dependency>


private void enablePicking(List<MyPickablePoint> points, List<PickablePolygon> polygons, Chart chart) {
NewtMousePickingPan2dController<?, ?> mousePicker = new NewtMousePickingPan2dController<>(chart, 5);
PickingSupport picking = mousePicker.getPickingSupport();

for (PickablePoint p : points) {
picking.registerPickableObject(p, p);
}
if (polygons != null)
for (PickablePolygon pPolygon : polygons) {
picking.registerPickableObject(pPolygon, pPolygon);
}

picking.addObjectPickedListener(new IObjectPickedListener() {
@Override
public void objectPicked(List<?> picked, PickingSupport ps) {
if (picked.size() > 0){ // && (System.currentTimeMillis() - camMouse.clickTimeMillis < 200)) {
System.out.println("Size: " + picked.size());
for (int i = 0; i < picked.size(); i++) {
if (picked.get(i).getClass().getName().equals("com.kz.grbl.MyPickablePoint")) {
((Point) picked.get(i)).setBoundingBoxColor(Color.BLACK);
((Point) picked.get(i)).setBoundingBoxDisplayed(true);
MyPickablePoint mp = ((MyPickablePoint) picked.get(i));
System.out.println(mp.toString());
addCylinder(mp.xyz);
SurfaceDemo3.instance.lastClickedPoint = mp;
Thread t = new Visualizer();
t.start();
break;
} else if (picked.get(i).getClass().getName()
.equals("org.jzy3d.plot3d.primitives.pickable.PickablePolygon")) {
System.out.println(picked.get(i).getClass().getName());
} else {
System.out.println(picked.get(i).getClass().getName());
}

}

}
}
});
}


Dne četrtek, 06. november 2014 17:51:31 UTC+1 je oseba Klemen Zhivko napisala:

Klemen Zhivko

unread,
Nov 7, 2014, 6:43:30 AM11/7/14
to jz...@googlegroups.com
Using this line results in breaking of animator:
this.getChart().getCanvas().addMouseController(new NewtMousePickingController(this.getChart(), 5));
Is there any sample that covers this scenario?


Dne torek, 15. julij 2014 20:21:55 UTC+2 je oseba Julien Martin napisala:

Klemen Zhivko

unread,
Nov 7, 2014, 5:55:28 PM11/7/14
to jz...@googlegroups.com
For the record - I finally succeded, buy reworking my code from org.jzy3d.demos.surface;SurfaceDemo.
PickingSupport seems to work also - I used AWTChartComponentFactory.
I attach maven project it could be usefull for someone as sample to see how to enablePicking.
Thanks for fantastic library!

Dne petek, 07. november 2014 12:43:30 UTC+1 je oseba Klemen Zhivko napisala:
grbl.zip

Martin Pernollet

unread,
Nov 9, 2014, 4:54:25 AM11/9/14
to Jzy3d
Thank you Klemen!
Can you tell in a few word what you fixed?


--

Klemen Živkovič

unread,
Nov 9, 2014, 5:01:33 AM11/9/14
to jz...@googlegroups.com
I fixed thing with taking your sample:

public class SurfaceDemo extends AbstractAnalysis

and building apon it.

regards

--
Vous recevez ce message, car vous êtes abonné à un sujet dans le groupe Google Groupes "Jzy3d".
Pour vous désabonner de ce sujet, visitez le site https://groups.google.com/d/topic/jzy3d/ZNwUpUw1PCg/unsubscribe.
Pour vous désabonner de ce groupe et de tous ses sujets, envoyez un e-mail à l'adresse jzy3d+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages