Skip to content

Commit 986875c

Browse files
committed
some corrections
1 parent 81a2cd6 commit 986875c

File tree

5 files changed

+89
-86
lines changed

5 files changed

+89
-86
lines changed

mode/libraries/ar/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ dependencies {
99
compileOnly name: "android"
1010
compileOnly "org.p5android:processing-core:${modeVersion}"
1111
implementationAar "com.google.ar:core:${garVersion}"
12-
implementation 'com.google.ar:core:1.37.0'
1312
}
1413

1514
task sourceJar(type: Jar) {

mode/libraries/ar/src/processing/ar/ARGraphics.java

Lines changed: 82 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
Part of the Processing project - http://processing.org
55
6-
Copyright (c) 2019 The Processing Foundation
6+
Copyright (c) 2019-23 The Processing Foundation
77
88
This library is free software; you can redistribute it and/or
99
modify it under the terms of the GNU Lesser General Public
@@ -75,18 +75,14 @@ public class ARGraphics extends PGraphics3D {
7575

7676
protected ArrayList<ARTracker> trackers = new ArrayList<ARTracker>();
7777
protected ArrayList<Trackable> trackObjects = new ArrayList<Trackable>();
78-
protected HashMap<Plane, float[]> trackMatrices = new HashMap<Plane, float[]>();
79-
// protected HashMap<Plane, Integer> trackIds = new HashMap<Plane, Integer>();
78+
protected HashMap<Trackable, float[]> trackMatrices = new HashMap<Trackable, float[]>();
79+
protected HashMap<Trackable, Integer> trackIds = new HashMap<Trackable, Integer>();
8080
protected HashMap<Integer, Integer> trackIdx = new HashMap<Integer, Integer>();
8181

82-
protected ArrayList<Plane> newPlanes = new ArrayList<Plane>();
82+
protected ArrayList<Trackable> newObjects = new ArrayList<Trackable>();
8383
protected ArrayList<Integer> delAnchors = new ArrayList<Integer>();
8484

8585
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>();
9086

9187
protected float[] pointIn = new float[3];
9288
protected float[] pointOut = new float[3];
@@ -229,52 +225,60 @@ public int trackableCount() {
229225
return trackObjects.size();
230226
}
231227

228+
232229
public int trackableId(int i) {
233230
return trackIds.get(trackObjects.get(i));
234231
}
235232

233+
236234
public int trackableIndex(int id) {
237235
return trackIdx.get(id);
238236
}
239237

238+
240239
public int trackableType(int i) {
241-
Plane plane = (Plane)trackObjects.get(i);
242-
if (plane.getType() == Plane.Type.HORIZONTAL_UPWARD_FACING) {
243-
return PLANE_FLOOR;
244-
} else if (plane.getType() == Plane.Type.HORIZONTAL_DOWNWARD_FACING) {
245-
return PLANE_CEILING;
246-
} else if (plane.getType() == Plane.Type.VERTICAL) {
247-
return PLANE_WALL;
240+
Trackable track = trackObjects.get(i);
241+
if (track instanceof Plane) {
242+
Plane plane = (Plane)track;
243+
if (plane.getType() == Plane.Type.HORIZONTAL_UPWARD_FACING) {
244+
return PLANE_FLOOR;
245+
} else if (plane.getType() == Plane.Type.HORIZONTAL_DOWNWARD_FACING) {
246+
return PLANE_CEILING;
247+
} else if (plane.getType() == Plane.Type.VERTICAL) {
248+
return PLANE_WALL;
249+
}
250+
} else if (track instanceof AugmentedImage) {
251+
return IMAGE;
248252
}
249253
return UNKNOWN;
250254
}
251255

256+
252257
public int trackableStatus(int i) {
253-
Plane plane = (Plane)trackObjects.get(i);
254-
if (plane.getTrackingState() == TrackingState.PAUSED) {
258+
Trackable track = trackObjects.get(i);
259+
if (track.getTrackingState() == TrackingState.PAUSED) {
255260
return PAUSED;
256-
} else if (plane.getTrackingState() == TrackingState.TRACKING) {
261+
} else if (track.getTrackingState() == TrackingState.TRACKING) {
257262
return TRACKING;
258-
} else if (plane.getTrackingState() == TrackingState.STOPPED) {
263+
} else if (track.getTrackingState() == TrackingState.STOPPED) {
259264
return STOPPED;
260265
}
261266
return UNKNOWN;
262267
}
263268

269+
264270
public boolean trackableNew(int i) {
265-
Plane plane = (Plane)trackObjects.get(i);
266-
return newPlanes.contains(plane);
271+
Trackable track = trackObjects.get(i);
272+
return newObjects.contains(track);
267273
}
268274

275+
269276
public boolean trackableSelected(int i, int mx, int my) {
270-
Plane planei = (Plane)trackObjects.get(i);
277+
Trackable tracki = trackObjects.get(i);
271278
for (HitResult hit : surfar.frame.hitTest(mx, my)) {
272279
Trackable trackable = hit.getTrackable();
273-
if (trackable instanceof Plane) {
274-
Plane plane = (Plane)trackable;
275-
if (planei.equals(plane) && plane.isPoseInPolygon(hit.getHitPose())) {
276-
return true;
277-
}
280+
if (tracki.equals(trackable) && trackable.isPoseInPolygon(hit.getHitPose())) {
281+
return true;
278282
}
279283
}
280284
return false;
@@ -284,29 +288,28 @@ public boolean trackableSelected(int i, int mx, int my) {
284288
protected HitResult getHitResult(int mx, int my) {
285289
for (HitResult hit : surfar.frame.hitTest(mx, my)) {
286290
Trackable trackable = hit.getTrackable();
287-
if (trackable instanceof Plane) {
288-
Plane plane = (Plane)trackable;
289-
if (trackObjects.contains(plane) && plane.isPoseInPolygon(hit.getHitPose())) {
290-
return hit;
291-
}
291+
if (trackObjects.contains(trackable) && trackable.isPoseInPolygon(hit.getHitPose())) {
292+
return hit;
292293
}
293294
}
294295
return null;
295296
}
296297

298+
297299
protected int getTrackable(HitResult hit) {
298-
Plane plane = (Plane) hit.getTrackable();
299-
return trackObjects.indexOf(plane);
300+
Trackable track = hit.getTrackable();
301+
return trackObjects.indexOf(track);
300302
}
301303

304+
302305
public float[] getTrackablePolygon(int i) {
303306
return getTrackablePolygon(i, null);
304307
}
305308

306309

307310
public float[] getTrackablePolygon(int i, float[] points) {
308-
Plane plane = (Plane)trackObjects.get(i);
309-
FloatBuffer buffer = plane.getPolygon();
311+
Trackable track = trackObjects.get(i);
312+
FloatBuffer buffer = track.getPolygon();
310313
buffer.rewind();
311314
if (points == null || points.length < buffer.capacity()) {
312315
points = new float[buffer.capacity()];
@@ -317,14 +320,14 @@ public float[] getTrackablePolygon(int i, float[] points) {
317320

318321

319322
public float getTrackableExtentX(int i) {
320-
Plane plane = (Plane)trackObjects.get(i);
321-
return plane.getExtentX();
323+
Trackable track = trackObjects.get(i);
324+
return track.getExtentX();
322325
}
323326

324327

325328
public float getTrackableExtentZ(int i) {
326-
Plane plane = (Plane)trackObjects.get(i);
327-
return plane.getExtentZ();
329+
Trackable track = trackObjects.get(i);
330+
return track.getExtentZ();
328331
}
329332

330333
public PMatrix3D getTrackableMatrix(int i) {
@@ -349,14 +352,14 @@ public PMatrix3D getTrackableMatrix(int i, PMatrix3D target) {
349352

350353

351354
public int createAnchor(int i, float x, float y, float z) {
352-
Plane plane = (Plane)trackObjects.get(i);
353-
Pose planePose = plane.getCenterPose();
355+
Trackable track = trackObjects.get(i);
356+
Pose trackPose = track.getCenterPose();
354357
pointIn[0] = x;
355358
pointIn[1] = y;
356359
pointIn[2] = z;
357-
planePose.transformPoint(pointIn, 0, pointOut, 0);
360+
trackPose.transformPoint(pointIn, 0, pointOut, 0);
358361
Pose anchorPose = Pose.makeTranslation(pointOut);
359-
Anchor anchor = plane.createAnchor(anchorPose);
362+
Anchor anchor = track.createAnchor(anchorPose);
360363
anchors.put(++lastAnchorId, anchor);
361364
return lastAnchorId;
362365
}
@@ -365,11 +368,8 @@ public int createAnchor(int i, float x, float y, float z) {
365368
public int createAnchor(int mx, int my) {
366369
for (HitResult hit : surfar.frame.hitTest(mx, my)) {
367370
Trackable trackable = hit.getTrackable();
368-
if (trackable instanceof Plane) {
369-
Plane plane = (Plane)trackable;
370-
if (trackObjects.contains(plane) && plane.isPoseInPolygon(hit.getHitPose())) {
371-
return createAnchor(hit);
372-
}
371+
if (trackObjects.contains(trackable) && trackable.isPoseInPolygon(hit.getHitPose())) {
372+
return createAnchor(hit);
373373
}
374374
}
375375
return 0;
@@ -441,10 +441,12 @@ protected void createBackgroundRenderer() {
441441
backgroundRenderer = new BackgroundRenderer(surfar.getActivity());
442442
}
443443

444+
444445
protected void setCameraTexture() {
445446
surfar.session.setCameraTextureName(backgroundRenderer.getTextureId());
446447
}
447448

449+
448450
protected void updateMatrices() {
449451
surfar.camera.getProjectionMatrix(projMatrix, 0, 0.1f, 100.0f);
450452
surfar.camera.getViewMatrix(viewMatrix, 0);
@@ -454,58 +456,59 @@ protected void updateMatrices() {
454456

455457
protected void updateTrackables() {
456458
Collection<Plane> planes = surfar.frame.getUpdatedTrackables(Plane.class);
457-
458459
for (Plane plane: planes) {
459-
if (plane.getSubsumedBy() != null) continue;
460-
float[] mat;
461-
if (trackMatrices.containsKey(plane)) {
462-
mat = trackMatrices.get(plane);
463-
} else {
464-
mat = new float[16];
465-
trackMatrices.put(plane, mat);
466-
trackObjects.add(plane);
467-
trackIds.put(plane, ++lastTrackableId);
468-
newPlanes.add(plane);
469-
}
470-
Pose pose = plane.getCenterPose();
471-
pose.toMatrix(mat, 0);
460+
addNewObject(plane);
472461
}
473462

463+
464+
Collection<AugmentedImage> images = surfar.frame.getUpdatedTrackables(AugmentedImage.class);
465+
for (AugmentedImage image: images) {
466+
addNewObject(image);
467+
}
468+
469+
474470
// Remove stopped and subsummed trackables
475471
for (int i = trackObjects.size() - 1; i >= 0; i--) {
476-
Plane plane = (Plane)trackObjects.get(i);
477-
if (plane.getTrackingState() == TrackingState.STOPPED || plane.getSubsumedBy() != null) {
472+
Trackable track = trackObjects.get(i);
473+
if (track.getTrackingState() == TrackingState.STOPPED || track.getSubsumedBy() != null) {
478474
trackObjects.remove(i);
479-
trackMatrices.remove(plane);
480-
int pid = trackIds.remove(plane);
475+
trackMatrices.remove(track);
476+
int pid = trackIds.remove(track);
481477
trackIdx.remove(pid);
482478
for (ARTracker t: trackers) t.remove(pid);
483479
}
484480
}
485481

486482
// Update indices
487483
for (int i = 0; i < trackObjects.size(); i++) {
488-
Plane plane = (Plane)trackObjects.get(i);
489-
int pid = trackIds.get(plane);
484+
Trackable track = trackObjects.get(i);
485+
int pid = trackIds.get(track);
490486
trackIdx.put(pid, i);
491-
if (newPlanes.contains(plane)) {
487+
if (newObjects.contains(track)) {
492488
for (ARTracker t: trackers) t.create(i);
493489
}
494490
}
495-
//Augmented Images
496-
Collection<AugmentedImage> images = surfar.frame.getUpdatedTrackables(AugmentedImage.class);
497-
for (AugmentedImage image: images) {
498-
trackObjects.add(image);
491+
}
492+
493+
protected void addNewObject(Trackable track) {
494+
if (track.getSubsumedBy() != null) return;
495+
float[] mat;
496+
if (trackMatrices.containsKey(track)) {
497+
mat = trackMatrices.get(track);
498+
} else {
499+
mat = new float[16];
500+
trackMatrices.put(track, mat);
501+
trackObjects.add(track);
502+
trackIds.put(track, ++lastTrackableId);
503+
newObjects.add(track);
499504
}
505+
Pose pose = track.getCenterPose();
506+
pose.toMatrix(mat, 0);
500507
}
501508

502-
// public int trackableId(int i) {
503-
// return trackIds.get(trackObjects.get(i));
504-
// }
505509

506510
protected void cleanup() {
507-
newPlanes.clear();
508-
511+
newObjects.clear();
509512
for (int id: delAnchors) {
510513
Anchor anchor = anchors.remove(id);
511514
anchor.detach();

mode/libraries/ar/src/processing/ar/ARTracker.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
public class ARTracker {
4242
protected PApplet p;
43-
protected ARGraphics g,arg;
43+
protected ARGraphics g;
4444
protected AugmentedImageDatabase imgDB;
4545

4646
private HashMap<String, ARTrackable> trackables = new HashMap<String, ARTrackable>();
@@ -52,13 +52,14 @@ public ARTracker(PApplet parent) {
5252
this.p = parent;
5353
this.g = (ARGraphics) p.g;
5454
setEventHandler();
55-
this.arg = (ARGraphics)parent.g;
55+
ARGraphics arg = (ARGraphics)parent.g;
5656
this.imgDB = new AugmentedImageDatabase(arg.surfar.session); //A new Database has been created.
5757
}
5858

5959
public void addImage(String name, PImage img) {
6060
Bitmap bitmap = (Bitmap)img.getNative();
61-
int imgIndex = imgDB.addImage(name,bitmap); // User-provided or auto-generated name here, physical size argument seems optional
61+
62+
imgDB.addImage(name, bitmap); // User-provided or auto-generated name here, physical size argument seems optional
6263

6364
// Re-set the session config with the updated image database
6465
Config config = new Config(session);

mode/mode.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ url = https://android.processing.org
44
sentence = This mode lets you use Processing to create Android apps
55
paragraph =
66
imports=processing.mode.java.JavaMode
7-
version = 412
8-
prettyVersion = 4.5.2
7+
version = 411
8+
prettyVersion = 4.5.1
99
minRevision = 1283
1010
maxRevision = 0

mode/version.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ androidx.legacy%legacy-support-v4 = 1.0.0
2222
com.google.android.support%wearable = 2.9.0
2323
com.google.android.gms%play-services-wearable = 18.0.0
2424
com.google.vr = 1.180.0
25-
com.google.ar = 1.35.0
25+
com.google.ar = 1.37.0
2626
org.processing = 4.0.0b7
2727
org.gradle%gradle-tooling-api = 7.2
2828
org.slf4j = 1.7.30

0 commit comments

Comments
 (0)