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