picking?

Have jReality programming problems or questions? Post them here.
Post Reply
ted
Posts: 57
Joined: Wed 25. Jul 2012, 22:53

picking?

Post by ted » Sat 22. Sep 2012, 04:15

I want to find the distance to the nearest object along a camera path.

When I attempt to call computePick, I get an error - Does it require double[4] coordinates instead of double[3] for parameters from, to? I assume then that from[3] and to[3] should be set to 1 then, correct? It seems reasonable to expect it to work with double[3] parameters as points, but maybe that's asking too much, or do I misunderstand the pick system? Some documentation would be helpful to confirm my suspicion on how it should work, or to point me in the right direction if I'm wrong, Thanks.

Here is what I'm trying to do (The narrow beam is more like an optical range finder than a sonar :) )

Code: Select all

	private double getSonar(SceneGraphPath cameraPath) {
		double sonar = 0;
		PickSystem picker = new AABBPickSystem();
		SceneGraphComponent world = viewer.getSceneRoot();
		picker.setSceneRoot(world);

		// Transform from and to from camera coordinates into world coordinates.
		double[] from = new double[]{0,0,0};
		System.out.printf("From: (%f, %f, %f)\n",from[0],from[1],from[2]);
		double[] to = new double[]{0,0,-36};
		System.out.printf("To: (%f, %f, %f)\n",to[0],to[1],to[2]);
		
		double[] a = cameraPath.getMatrix(new double[16]);
		System.out.println(Rn.matrixToString(a));
		
		Rn.matrixTimesVector(from, a, from);
		System.out.printf("From: (%f, %f, %f)\n",from[0],from[1],from[2]);
		Rn.matrixTimesVector(to, a, to);
		System.out.printf("To: (%f, %f, %f)\n",to[0],to[1],to[2]);
		
		List<PickResult> list = picker.computePick(from, to);[  // This line is RoboticSystem.java:556 
		if (list.isEmpty()) return 0;
		PickResult pickResult = list.get(0);
		double[] point = pickResult.getWorldCoordinates();
		System.out.printf("point: (%f, %f, %f)\n",point[0],point[1],point[2]);
		double[] delta = new double[3];
		R3.minus(from, point, delta);
		System.out.printf("delta: (%f, %f, %f)\n",delta[0],delta[1],delta[2]);
		sonar = Math.sqrt(delta[0]*delta[0]+delta[1]*delta[1]+delta[2]*delta[2]);
		System.out.println("distance: "+sonar);
		return sonar;
	}

Here's the error:

Code: Select all

Vendor = NVIDIA Corporation
Have automipmap generation = true
Using camera #2
From: (0.000000, 0.000000, 0.000000)
To: (0.000000, 0.000000, -36.000000)
6.12323e-17	0.00000	1.00000	36.0000
0.00000	1.00000	0.00000	-12.0000
-1.00000	0.00000	6.12323e-17	2.20436e-15
0.00000	0.00000	0.00000	1.00000

From: (36.000000, -12.000000, 0.000000)
To: (0.000000, -12.000000, 0.000000)
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 3
	at de.jreality.math.P3.barycentricCoordinates(P3.java:1050)
	at de.jreality.math.P3.affineCoordinate(P3.java:1081)
	at de.jreality.scene.pick.BruteForcePicking.intersectSphere(BruteForcePicking.java:314)
	at de.jreality.scene.pick.AABBPickSystem$Impl.visit(AABBPickSystem.java:290)
	at de.jreality.scene.Sphere.accept(Sphere.java:58)
	at de.jreality.scene.SceneGraphComponent.childrenAccept(SceneGraphComponent.java:413)
	at de.jreality.scene.pick.AABBPickSystem$Impl.visit(AABBPickSystem.java:252)
	at de.jreality.scene.SceneGraphComponent.accept(SceneGraphComponent.java:381)
	at de.jreality.scene.SceneGraphComponent.childrenAccept(SceneGraphComponent.java:416)
	at de.jreality.scene.pick.AABBPickSystem$Impl.visit(AABBPickSystem.java:252)
	at de.jreality.scene.SceneGraphComponent.accept(SceneGraphComponent.java:381)
	at de.jreality.scene.SceneGraphComponent.childrenAccept(SceneGraphComponent.java:416)
	at de.jreality.scene.pick.AABBPickSystem$Impl.visit(AABBPickSystem.java:252)
	at de.jreality.scene.SceneGraphComponent.accept(SceneGraphComponent.java:381)
	at de.jreality.scene.SceneGraphComponent.childrenAccept(SceneGraphComponent.java:416)
	at de.jreality.scene.pick.AABBPickSystem$Impl.visit(AABBPickSystem.java:252)
	at de.jreality.scene.SceneGraphComponent.accept(SceneGraphComponent.java:381)
	at de.jreality.scene.SceneGraphComponent.childrenAccept(SceneGraphComponent.java:416)
	at de.jreality.scene.pick.AABBPickSystem$Impl.visit(AABBPickSystem.java:252)
	at de.jreality.scene.SceneGraphComponent.accept(SceneGraphComponent.java:381)
	at de.jreality.scene.SceneGraphComponent.childrenAccept(SceneGraphComponent.java:416)
	at de.jreality.scene.pick.AABBPickSystem$Impl.visit(AABBPickSystem.java:252)
	at de.jreality.scene.pick.AABBPickSystem$Impl.visit(AABBPickSystem.java:282)
	at de.jreality.scene.pick.AABBPickSystem.computePick(AABBPickSystem.java:109)
	at edu.usta.ace.ted.RoboticSystem.getSonar(RoboticSystem.java:556)
	at edu.usta.ace.ted.RoboticSystem.access$4(RoboticSystem.java:536)
	at edu.usta.ace.ted.RoboticSystem$1.keyPressed(RoboticSystem.java:199)
	at java.awt.AWTEventMulticaster.keyPressed(AWTEventMulticaster.java:233)
	at java.awt.Component.processKeyEvent(Component.java:6340)
	at javax.swing.JComponent.processKeyEvent(JComponent.java:2809)
	at java.awt.Component.processEvent(Component.java:6159)
	at java.awt.Container.processEvent(Container.java:2083)
	at java.awt.Component.dispatchEventImpl(Component.java:4744)
	at java.awt.Container.dispatchEventImpl(Container.java:2141)
	at java.awt.Component.dispatchEvent(Component.java:4572)
	at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1856)
	at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:722)
	at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1000)
	at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:865)
	at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:686)
	at java.awt.Component.dispatchEventImpl(Component.java:4616)
	at java.awt.Container.dispatchEventImpl(Container.java:2141)
	at java.awt.Window.dispatchEventImpl(Window.java:2489)
	at java.awt.Component.dispatchEvent(Component.java:4572)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:704)
	at java.awt.EventQueue.access$400(EventQueue.java:82)
	at java.awt.EventQueue$2.run(EventQueue.java:663)
	at java.awt.EventQueue$2.run(EventQueue.java:661)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
	at java.awt.EventQueue$3.run(EventQueue.java:677)
	at java.awt.EventQueue$3.run(EventQueue.java:675)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:674)
	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)
OK, so it works with double[4] instead of double[3[. Perhaps this post belongs in feature requests. Here's a patch to the documentation for you:

Code: Select all

Index: src-core/de/jreality/scene/pick/PickSystem.java
===================================================================
--- src-core/de/jreality/scene/pick/PickSystem.java	(revision 5518)
+++ src-core/de/jreality/scene/pick/PickSystem.java	(working copy)
@@ -57,9 +57,9 @@
    * The parameters need to be homogenious coordinates.
    * 
    * @param from
-   *          foot point of ray in world coordinates
+   *          foot point of ray in world coordinates (x,y,z,1)
    * @param to
-   *          end point of ray in world coordinates (can be at infinity)
+   *          end point of ray in world coordinates  (x,y,z,1) (can be at infinity)
    * Valid pick points are of the form p = a*from+b*to where a*b >= 0
    * That is, the affine coordinate (b/a) of p on the line with basis (from,to) is non-negative
    * @return list of PickResults sorted by distance from foot point

User avatar
gunn
Posts: 323
Joined: Thu 14. Dec 2006, 09:56
Location: TU Berlin
Contact:

Re: picking?

Post by gunn » Mon 24. Sep 2012, 15:23

The top line of the method comment

Code: Select all

   * The parameters need to be homogenious coordinates.
implies that they are in fact 4-vectors. That said, it doesn't hurt to add the explicit "(x, y, z, 1)" information to the other comment lines.

I'll add that when I correct the spelling of "homogeneous" in the first-quoted comment line.
jReality core developer

User avatar
steffen
Posts: 186
Joined: Fri 16. Jun 2006, 13:30
Location: TU Berlin
Contact:

Re: picking?

Post by steffen » Sat 29. Sep 2012, 12:17

The second parameter may be at infinity, but (x, y, z, 1) is not...

Post Reply