25
25
import android .view .SurfaceHolder ;
26
26
27
27
import com .google .ar .core .Anchor ;
28
+ import com .google .ar .core .AugmentedImage ;
28
29
import com .google .ar .core .HitResult ;
29
30
import com .google .ar .core .Plane ;
30
31
import com .google .ar .core .Pose ;
31
32
import com .google .ar .core .Trackable ;
32
33
import com .google .ar .core .TrackingState ;
34
+ import com .google .ar .core .Config ;
35
+ import com .google .ar .core .Session ;
33
36
34
37
import java .net .URL ;
35
38
import java .nio .FloatBuffer ;
@@ -70,15 +73,19 @@ public class ARGraphics extends PGraphics3D {
70
73
protected float [] colorCorrection = new float [4 ];
71
74
72
75
protected ArrayList <ARTracker > trackers = new ArrayList <ARTracker >();
73
- protected ArrayList <Plane > trackPlanes = new ArrayList <Plane >();
76
+ protected ArrayList <Trackable > trackObjects = new ArrayList <Trackable >();
74
77
protected HashMap <Plane , float []> trackMatrices = new HashMap <Plane , float []>();
75
- protected HashMap <Plane , Integer > trackIds = new HashMap <Plane , Integer >();
78
+ // protected HashMap<Plane, Integer> trackIds = new HashMap<Plane, Integer>();
76
79
protected HashMap <Integer , Integer > trackIdx = new HashMap <Integer , Integer >();
77
80
78
81
protected ArrayList <Plane > newPlanes = new ArrayList <Plane >();
79
82
protected ArrayList <Integer > delAnchors = new ArrayList <Integer >();
80
83
81
84
protected HashMap <Integer , Anchor > anchors = new HashMap <Integer , Anchor >();
85
+ // protected ArrayList<Plane> trackObjects = new ArrayList<Trackable>(); // replace trackPlanes with this
86
+
87
+ // Use Trackable as the the key's type to it hand hold both Plane and AugmentedImage objects trackImages
88
+ protected HashMap <Trackable , Integer > trackIds = new HashMap <Trackable , Integer >();
82
89
83
90
protected float [] pointIn = new float [3 ];
84
91
protected float [] pointOut = new float [3 ];
@@ -218,22 +225,19 @@ public void removeTracker(ARTracker tracker) {
218
225
219
226
220
227
public int trackableCount () {
221
- return trackPlanes .size ();
228
+ return trackObjects .size ();
222
229
}
223
230
224
-
225
-
226
231
public int trackableId (int i ) {
227
- return trackIds .get (trackPlanes .get (i ));
232
+ return trackIds .get (trackObjects .get (i ));
228
233
}
229
234
230
-
231
235
public int trackableIndex (int id ) {
232
236
return trackIdx .get (id );
233
237
}
234
238
235
239
public int trackableType (int i ) {
236
- Plane plane = trackPlanes .get (i );
240
+ Plane plane = ( Plane ) trackObjects .get (i );
237
241
if (plane .getType () == Plane .Type .HORIZONTAL_UPWARD_FACING ) {
238
242
return PLANE_FLOOR ;
239
243
} else if (plane .getType () == Plane .Type .HORIZONTAL_DOWNWARD_FACING ) {
@@ -245,7 +249,7 @@ public int trackableType(int i) {
245
249
}
246
250
247
251
public int trackableStatus (int i ) {
248
- Plane plane = trackPlanes .get (i );
252
+ Plane plane = ( Plane ) trackObjects .get (i );
249
253
if (plane .getTrackingState () == TrackingState .PAUSED ) {
250
254
return PAUSED ;
251
255
} else if (plane .getTrackingState () == TrackingState .TRACKING ) {
@@ -257,12 +261,12 @@ public int trackableStatus(int i) {
257
261
}
258
262
259
263
public boolean trackableNew (int i ) {
260
- Plane plane = trackPlanes .get (i );
264
+ Plane plane = ( Plane ) trackObjects .get (i );
261
265
return newPlanes .contains (plane );
262
266
}
263
267
264
268
public boolean trackableSelected (int i , int mx , int my ) {
265
- Plane planei = trackPlanes .get (i );
269
+ Plane planei = ( Plane ) trackObjects .get (i );
266
270
for (HitResult hit : surfar .frame .hitTest (mx , my )) {
267
271
Trackable trackable = hit .getTrackable ();
268
272
if (trackable instanceof Plane ) {
@@ -281,7 +285,7 @@ protected HitResult getHitResult(int mx, int my) {
281
285
Trackable trackable = hit .getTrackable ();
282
286
if (trackable instanceof Plane ) {
283
287
Plane plane = (Plane )trackable ;
284
- if (trackPlanes .contains (plane ) && plane .isPoseInPolygon (hit .getHitPose ())) {
288
+ if (trackObjects .contains (plane ) && plane .isPoseInPolygon (hit .getHitPose ())) {
285
289
return hit ;
286
290
}
287
291
}
@@ -291,7 +295,7 @@ protected HitResult getHitResult(int mx, int my) {
291
295
292
296
protected int getTrackable (HitResult hit ) {
293
297
Plane plane = (Plane ) hit .getTrackable ();
294
- return trackPlanes .indexOf (plane );
298
+ return trackObjects .indexOf (plane );
295
299
}
296
300
297
301
public float [] getTrackablePolygon (int i ) {
@@ -300,7 +304,7 @@ public float[] getTrackablePolygon(int i) {
300
304
301
305
302
306
public float [] getTrackablePolygon (int i , float [] points ) {
303
- Plane plane = trackPlanes .get (i );
307
+ Plane plane = ( Plane ) trackObjects .get (i );
304
308
FloatBuffer buffer = plane .getPolygon ();
305
309
buffer .rewind ();
306
310
if (points == null || points .length < buffer .capacity ()) {
@@ -312,13 +316,13 @@ public float[] getTrackablePolygon(int i, float[] points) {
312
316
313
317
314
318
public float getTrackableExtentX (int i ) {
315
- Plane plane = trackPlanes .get (i );
319
+ Plane plane = ( Plane ) trackObjects .get (i );
316
320
return plane .getExtentX ();
317
321
}
318
322
319
323
320
324
public float getTrackableExtentZ (int i ) {
321
- Plane plane = trackPlanes .get (i );
325
+ Plane plane = ( Plane ) trackObjects .get (i );
322
326
return plane .getExtentZ ();
323
327
}
324
328
@@ -332,7 +336,7 @@ public PMatrix3D getTrackableMatrix(int i, PMatrix3D target) {
332
336
target = new PMatrix3D ();
333
337
}
334
338
335
- Plane plane = trackPlanes .get (i );
339
+ Plane plane = ( Plane ) trackObjects .get (i );
336
340
float [] mat = trackMatrices .get (plane );
337
341
target .set (mat [0 ], mat [4 ], mat [8 ], mat [12 ],
338
342
mat [1 ], mat [5 ], mat [9 ], mat [13 ],
@@ -344,7 +348,7 @@ public PMatrix3D getTrackableMatrix(int i, PMatrix3D target) {
344
348
345
349
346
350
public int createAnchor (int i , float x , float y , float z ) {
347
- Plane plane = trackPlanes .get (i );
351
+ Plane plane = ( Plane ) trackObjects .get (i );
348
352
Pose planePose = plane .getCenterPose ();
349
353
pointIn [0 ] = x ;
350
354
pointIn [1 ] = y ;
@@ -362,7 +366,7 @@ public int createAnchor(int mx, int my) {
362
366
Trackable trackable = hit .getTrackable ();
363
367
if (trackable instanceof Plane ) {
364
368
Plane plane = (Plane )trackable ;
365
- if (trackPlanes .contains (plane ) && plane .isPoseInPolygon (hit .getHitPose ())) {
369
+ if (trackObjects .contains (plane ) && plane .isPoseInPolygon (hit .getHitPose ())) {
366
370
return createAnchor (hit );
367
371
}
368
372
}
@@ -449,6 +453,7 @@ protected void updateMatrices() {
449
453
450
454
protected void updateTrackables () {
451
455
Collection <Plane > planes = surfar .frame .getUpdatedTrackables (Plane .class );
456
+
452
457
for (Plane plane : planes ) {
453
458
if (plane .getSubsumedBy () != null ) continue ;
454
459
float [] mat ;
@@ -457,7 +462,7 @@ protected void updateTrackables() {
457
462
} else {
458
463
mat = new float [16 ];
459
464
trackMatrices .put (plane , mat );
460
- trackPlanes .add (plane );
465
+ trackObjects .add (plane );
461
466
trackIds .put (plane , ++lastTrackableId );
462
467
newPlanes .add (plane );
463
468
}
@@ -466,10 +471,10 @@ protected void updateTrackables() {
466
471
}
467
472
468
473
// Remove stopped and subsummed trackables
469
- for (int i = trackPlanes .size () - 1 ; i >= 0 ; i --) {
470
- Plane plane = trackPlanes .get (i );
474
+ for (int i = trackObjects .size () - 1 ; i >= 0 ; i --) {
475
+ Plane plane = ( Plane ) trackObjects .get (i );
471
476
if (plane .getTrackingState () == TrackingState .STOPPED || plane .getSubsumedBy () != null ) {
472
- trackPlanes .remove (i );
477
+ trackObjects .remove (i );
473
478
trackMatrices .remove (plane );
474
479
int pid = trackIds .remove (plane );
475
480
trackIdx .remove (pid );
@@ -478,16 +483,24 @@ protected void updateTrackables() {
478
483
}
479
484
480
485
// Update indices
481
- for (int i = 0 ; i < trackPlanes .size (); i ++) {
482
- Plane plane = trackPlanes .get (i );
486
+ for (int i = 0 ; i < trackObjects .size (); i ++) {
487
+ Plane plane = ( Plane ) trackObjects .get (i );
483
488
int pid = trackIds .get (plane );
484
489
trackIdx .put (pid , i );
485
490
if (newPlanes .contains (plane )) {
486
491
for (ARTracker t : trackers ) t .create (i );
487
492
}
488
493
}
494
+ //Augmented Images
495
+ Collection <AugmentedImage > images = surfar .frame .getUpdatedTrackables (AugmentedImage .class );
496
+ for (AugmentedImage image : images ) {
497
+ trackObjects .add (image );
498
+ }
489
499
}
490
500
501
+ // public int trackableId(int i) {
502
+ // return trackIds.get(trackObjects.get(i));
503
+ // }
491
504
492
505
protected void cleanup () {
493
506
newPlanes .clear ();
0 commit comments