Skip to content

Commit 4314ace

Browse files
author
Dominik Wetzel
committed
Minor passthrough algorithm refinement and made it buildable
1 parent 78ca2c4 commit 4314ace

File tree

5 files changed

+37
-46
lines changed

5 files changed

+37
-46
lines changed

code/mobile/android/PhoneVR/app/src/main/cpp/passthrough.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#include <GLES2/gl2ext.h>
44
#include <vector>
55

6-
#include "passthrough.h"
76
#include "utils.h"
7+
#include "passthrough.h"
88

99
GLuint LoadGLShader(GLenum type, const char *shader_source) {
1010
GLuint shader = GL(glCreateShader(type));

code/mobile/android/PhoneVR/app/src/main/cpp/passthrough.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#ifndef PHONEVR_PASSTHROUGH_H
2+
#define PHONEVR_PASSTHROUGH_H
23

34
#include "cardboard.h"
45

@@ -24,6 +25,4 @@ void passthrough_cleanup(PassthroughInfo *info);
2425
void passthrough_setup(PassthroughInfo *info);
2526
void passthrough_render(PassthroughInfo *info, CardboardEyeTextureDescription viewDescs[]);
2627

27-
#define PHONEVR_PASSTHROUGH_H
28-
2928
#endif // PHONEVR_PASSTHROUGH_H

code/mobile/android/PhoneVR/app/src/main/cpp/utils.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
const char LOG_TAG[] = "ALVR_PVR_NATIVE";
1414

15-
void log(AlvrLogLevel level,
15+
static void log(AlvrLogLevel level,
1616
const char *FILE_NAME,
1717
unsigned int LINE_NO,
1818
const char *FUNC,

code/mobile/android/PhoneVR/app/src/main/java/viritualisres/phonevr/ALVRActivity.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,7 @@ public void onCreate(Bundle savedInstance) {
144144
pref = PreferenceManager.getDefaultSharedPreferences(this);
145145
passthrough =
146146
new Passthrough(
147-
pref,
148-
(SensorManager) getSystemService(SENSOR_SERVICE),
149-
width,
150-
height);
147+
pref, (SensorManager) getSystemService(SENSOR_SERVICE), width, height);
151148
}
152149

153150
@Override

code/mobile/android/PhoneVR/app/src/main/java/viritualisres/phonevr/Passthrough.java

+33-38
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
public class Passthrough implements SensorEventListener {
2121

2222
static {
23-
System.loadLibrary("native-lib");
23+
System.loadLibrary("native-lib-alvr");
2424
}
2525

2626
private static final String TAG = Passthrough.class.getSimpleName() + "-Java";
@@ -154,50 +154,45 @@ public void onSensorChanged(SensorEvent event) {
154154
// these may occur on any axis
155155
for (List<Float> elem : accelAbs) {
156156
// we look at two halves of the passthrough_delay
157-
// we check:
158-
// - if in the first and second half is a real peak
159-
// - whether the peaks are in the bounds
160-
// - if the summed mean is in the bounds
161-
// - if the first summed mean is below lower_bound
162-
// (to assure a resting stage before the triggering)
163-
// - if the second maximum is decending under the lower bound until curr value
164-
// If all is fulfilled we consider this a potential passthrough_change event.
165-
// The sum must then decend under lower bound until passthrough_delay
166-
int middle = halfSize - 1;
167-
List<Float> t1 = elem.subList(0, halfSize);
168-
List<Float> t2 = elem.subList(middle, elem.size());
157+
List<Float> t1 = elem.subList(0, halfSize + 1);
158+
List<Float> t2 = elem.subList(halfSize, elem.size());
169159

160+
// and get the maxima
170161
float max1 = Collections.max(t1);
171162
float max2 = Collections.max(t2);
172-
173-
if (max1 - t1.get(0) < detectionLowerBound
174-
|| max1 - t1.get(t1.size() - 1) < detectionLowerBound
175-
|| max2 - t2.get(0) < detectionLowerBound
176-
|| max2 - t2.get(t2.size() - 1) < detectionLowerBound
177-
|| max1 < detectionLowerBound
178-
|| max1 > detectionUpperBound
179-
|| max2 < detectionLowerBound
180-
|| max2 > detectionUpperBound
181-
|| sumMean < detectionLowerBound
182-
|| sumMean > detectionUpperBound) {
183-
continue;
184-
}
185-
186-
int end2 = 0;
187-
for (int i = 0; i < t2.size(); ++i) {
188-
if (t2.get(i) == max2) {
163+
// and check whether the 2nd half goes belowe lower bound
164+
int end2 = t2.indexOf(max2);
165+
for (int i = end2; i < t2.size(); ++i) {
166+
if (t2.get(i) < detectionLowerBound) {
189167
end2 = i;
190-
}
191-
if (end2 > 0) {
192-
if (t2.get(i) < detectionLowerBound) {
193-
end2 = i;
194-
break;
195-
}
168+
break;
196169
}
197170
}
198171

199-
if (cumSums.get(0) < Math.max(detectionLowerBound - 0.3f, 0.5f)
200-
&& t2.get(end2) < max2) {
172+
// We check
173+
if (t1.get(halfSize - 1) > t2.get(0) // if halfSize is a local minimum
174+
&& t2.get(1) > t2.get(0)
175+
&& max1 - t1.get(0) >= detectionLowerBound // max - start > lower bound
176+
&& max1 - t1.get(t1.size() - 1)
177+
>= detectionLowerBound // max - end > lower bound
178+
&& max2 - t2.get(0) >= detectionLowerBound
179+
&& max2 - t2.get(t2.size() - 1) >= detectionLowerBound
180+
&& max1 >= detectionLowerBound // max are in bounds
181+
&& max1 <= detectionUpperBound
182+
&& max2 >= detectionLowerBound
183+
&& max2 <= detectionUpperBound
184+
&& sumMean >= detectionLowerBound // sumMean is in bounds
185+
&& sumMean <= detectionUpperBound
186+
&& t2.get(end2) < max2 // the 2nd half goes below lower bound
187+
&& cumSums.get(0)
188+
< Math.max(
189+
detectionLowerBound - 0.3f,
190+
0.5f) // the first sumMean (of window) is below lower
191+
// bounds
192+
) {
193+
// If all is fulfilled we consider this a potential passthrough_change
194+
// event.
195+
// The sum must then decend under lower bound until passthrough_delay
201196
timestampAfterCandidate = event.timestamp;
202197
break;
203198
}

0 commit comments

Comments
 (0)