Tango: added online blending option, background color option, double tap, fixed meshes jiggering on touch, removed raw mesh option

This commit is contained in:
matlabbe
2017-04-17 21:42:01 -04:00
parent 6f148c47e2
commit 0ccba3281e
21 changed files with 563 additions and 220 deletions
@@ -66,6 +66,7 @@ import android.text.method.LinkMovementMethod;
import android.text.util.Linkify;
import android.util.Log;
import android.view.Display;
import android.view.GestureDetector;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuInflater;
@@ -73,6 +74,7 @@ import android.view.MotionEvent;
import android.view.Surface;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.webkit.WebView;
@@ -189,6 +191,8 @@ public class RTABMapActivity extends Activity implements OnClickListener {
private AlertDialog mMemoryWarningDialog = null;
private String[] mStatusTexts = new String[16];
GestureDetector mGesDetect = null;
//Tango Service connection.
ServiceConnection mTangoServiceConnection = new ServiceConnection() {
@@ -270,8 +274,45 @@ public class RTABMapActivity extends Activity implements OnClickListener {
// OpenGL view where all of the graphics are drawn.
mGLView = (GLSurfaceView) findViewById(R.id.gl_surface_view);
mGesDetect = new GestureDetector(this, new DoubleTapGestureDetector());
// Configure OpenGL renderer
mGLView.setEGLContextClientVersion(2);
mGLView.setEGLConfigChooser(8, 8, 8, 8, 24, 0);
mGLView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
mGesDetect.onTouchEvent(event);
// Pass the touch event to the native layer for camera control.
// Single touch to rotate the camera around the device.
// Two fingers to zoom in and out.
int pointCount = event.getPointerCount();
if (pointCount == 1) {
float normalizedX = event.getX(0) / mScreenSize.x;
float normalizedY = event.getY(0) / mScreenSize.y;
RTABMapLib.onTouchEvent(1,
event.getActionMasked(), normalizedX, normalizedY, 0.0f, 0.0f);
}
if (pointCount == 2) {
if (event.getActionMasked() == MotionEvent.ACTION_POINTER_UP) {
int index = event.getActionIndex() == 0 ? 1 : 0;
float normalizedX = event.getX(index) / mScreenSize.x;
float normalizedY = event.getY(index) / mScreenSize.y;
RTABMapLib.onTouchEvent(1,
MotionEvent.ACTION_DOWN, normalizedX, normalizedY, 0.0f, 0.0f);
} else {
float normalizedX0 = event.getX(0) / mScreenSize.x;
float normalizedY0 = event.getY(0) / mScreenSize.y;
float normalizedX1 = event.getX(1) / mScreenSize.x;
float normalizedY1 = event.getY(1) / mScreenSize.y;
RTABMapLib.onTouchEvent(2, event.getActionMasked(),
normalizedX0, normalizedY0, normalizedX1, normalizedY1);
}
}
return true;
}
});
// Configure the OpenGL renderer.
mRenderer = new Renderer(this);
@@ -342,6 +383,8 @@ public class RTABMapActivity extends Activity implements OnClickListener {
public void onDisplayChanged(int displayId) {
synchronized (this) {
setAndroidOrientation();
Display display = getWindowManager().getDefaultDisplay();
display.getSize(mScreenSize);
}
}
@@ -455,6 +498,7 @@ public class RTABMapActivity extends Activity implements OnClickListener {
String optimizer = sharedPref.getString(getString(R.string.pref_key_optimizer), getString(R.string.pref_default_optimizer));
if(!DISABLE_LOG) Log.d(TAG, "set mapping parameters");
RTABMapLib.setOnlineBlending(sharedPref.getBoolean(getString(R.string.pref_key_blending), Boolean.parseBoolean(getString(R.string.pref_default_blending))));
RTABMapLib.setNodesFiltering(sharedPref.getBoolean(getString(R.string.pref_key_nodes_filtering), Boolean.parseBoolean(getString(R.string.pref_default_nodes_filtering))));
RTABMapLib.setAutoExposure(sharedPref.getBoolean(getString(R.string.pref_key_auto_exposure), Boolean.parseBoolean(getString(R.string.pref_default_auto_exposure))));
RTABMapLib.setRawScanSaved(sharedPref.getBoolean(getString(R.string.pref_key_raw_scan_saved), Boolean.parseBoolean(getString(R.string.pref_default_raw_scan_saved))));
@@ -484,6 +528,9 @@ public class RTABMapActivity extends Activity implements OnClickListener {
RTABMapLib.setPointSize(Float.parseFloat(sharedPref.getString(getString(R.string.pref_key_point_size), getString(R.string.pref_default_point_size))));
RTABMapLib.setMeshAngleTolerance(Float.parseFloat(sharedPref.getString(getString(R.string.pref_key_angle), getString(R.string.pref_default_angle))));
RTABMapLib.setMeshTriangleSize(Integer.parseInt(sharedPref.getString(getString(R.string.pref_key_triangle), getString(R.string.pref_default_triangle))));
float bgColor = Float.parseFloat(sharedPref.getString(getString(R.string.pref_key_background_color), getString(R.string.pref_default_background_color)));
RTABMapLib.setBackgroundColor(bgColor);
mRenderer.setTextColor(bgColor==0.5f?0.4f:1.0f-bgColor);
if(!DISABLE_LOG) Log.d(TAG, "set rendering parameters...");
RTABMapLib.setClusterRatio(Float.parseFloat(sharedPref.getString(getString(R.string.pref_key_cluster_ratio), getString(R.string.pref_default_cluster_ratio))));
@@ -592,37 +639,17 @@ public class RTABMapActivity extends Activity implements OnClickListener {
Camera.getCameraInfo(fisheye?1:0, colorCameraInfo);
RTABMapLib.setScreenRotation(display.getRotation(), colorCameraInfo.orientation);
}
class DoubleTapGestureDetector extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onTouchEvent(MotionEvent event) {
// Pass the touch event to the native layer for camera control.
// Single touch to rotate the camera around the device.
// Two fingers to zoom in and out.
int pointCount = event.getPointerCount();
if (pointCount == 1) {
float normalizedX = event.getX(0) / mScreenSize.x;
@Override
public boolean onDoubleTap(MotionEvent event) {
float normalizedX = event.getX(0) / mScreenSize.x;
float normalizedY = event.getY(0) / mScreenSize.y;
RTABMapLib.onTouchEvent(1,
event.getActionMasked(), normalizedX, normalizedY, 0.0f, 0.0f);
}
if (pointCount == 2) {
if (event.getActionMasked() == MotionEvent.ACTION_POINTER_UP) {
int index = event.getActionIndex() == 0 ? 1 : 0;
float normalizedX = event.getX(index) / mScreenSize.x;
float normalizedY = event.getY(index) / mScreenSize.y;
RTABMapLib.onTouchEvent(1,
MotionEvent.ACTION_DOWN, normalizedX, normalizedY, 0.0f, 0.0f);
} else {
float normalizedX0 = event.getX(0) / mScreenSize.x;
float normalizedY0 = event.getY(0) / mScreenSize.y;
float normalizedX1 = event.getX(1) / mScreenSize.x;
float normalizedY1 = event.getY(1) / mScreenSize.y;
RTABMapLib.onTouchEvent(2, event.getActionMasked(),
normalizedX0, normalizedY0, normalizedX1, normalizedY1);
}
}
return true;
}
RTABMapLib.onTouchEvent(3, event.getActionMasked(), normalizedX, normalizedY, 0.0f, 0.0f);
return true;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
@@ -1568,15 +1595,11 @@ public class RTABMapActivity extends Activity implements OnClickListener {
.show();
}
else if(itemId == R.id.export_point_cloud ||
itemId == R.id.export_point_cloud_highrez ||
itemId == R.id.export_mesh ||
itemId == R.id.export_mesh_texture)
itemId == R.id.export_point_cloud_highrez)
{
final boolean isOBJ = itemId == R.id.export_mesh_texture || itemId == R.id.export_optimized_mesh_texture;
final boolean meshing = itemId != R.id.export_point_cloud && itemId != R.id.export_point_cloud_highrez;
final boolean regenerateCloud = itemId == R.id.export_point_cloud_highrez;
export(isOBJ, meshing, regenerateCloud, false, 0);
export(false, false, regenerateCloud, false, 0);
}
else if(itemId == R.id.export_optimized_mesh ||
itemId == R.id.export_optimized_mesh_texture)
@@ -58,6 +58,7 @@ public class RTABMapLib
public static native void setPausedMapping(boolean paused);
public static native void setOnlineBlending(boolean enabled);
public static native void setMapCloudShown(boolean shown);
public static native void setOdomCloudShown(boolean shown);
public static native void setMeshRendering(boolean enabled, boolean withTexture);
@@ -85,6 +86,7 @@ public class RTABMapLib
public static native void setClusterRatio(float value);
public static native void setMaxGainRadius(float value);
public static native void setRenderingTextureDecimation(int value);
public static native void setBackgroundColor(float gray);
public static native int setMappingParameter(String key, String value);
public static native void resetMapping();
@@ -41,6 +41,7 @@ public class Renderer implements GLSurfaceView.Renderer {
private TextManager mTextManager = null;
private float mSurfaceHeight = 0.0f;
private float mTextColor = 1.0f;
private Vector<TextObject> mTexts;
@@ -174,9 +175,7 @@ public class Renderer implements GLSurfaceView.Renderer {
// Create our text manager
mTextManager = new TextManager(mActivity);
GLES20.glEnable(GLES20.GL_BLEND);
GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA);
mTextManager.setColor(mTextColor);
}
public void updateTexts(String[] texts)
@@ -208,4 +207,13 @@ public class Renderer implements GLSurfaceView.Renderer {
mTextChanged = true;
}
}
public void setTextColor(float color)
{
mTextColor = color;
if(mTextManager != null)
{
mTextManager.setColor(mTextColor);
}
}
}
@@ -34,6 +34,7 @@ public class SettingsActivity extends PreferenceActivity implements OnSharedPref
((Preference)findPreference(getString(R.string.pref_key_point_size))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_point_size))).getEntry() + ") "+getString(R.string.pref_summary_point_size));
((Preference)findPreference(getString(R.string.pref_key_angle))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_angle))).getEntry() + ") "+getString(R.string.pref_summary_angle));
((Preference)findPreference(getString(R.string.pref_key_triangle))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_triangle))).getEntry() + ") "+getString(R.string.pref_summary_triangle));
((Preference)findPreference(getString(R.string.pref_key_background_color))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_background_color))).getEntry() + ") "+getString(R.string.pref_summary_background_color));
((Preference)findPreference(getString(R.string.pref_key_rendering_texture_decimation))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_rendering_texture_decimation))).getEntry() + ") "+getString(R.string.pref_summary_rendering_texture_decimation));
((Preference)findPreference(getString(R.string.pref_key_update_rate))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_update_rate))).getEntry() + ") "+getString(R.string.pref_summary_update_rate));
@@ -89,6 +90,7 @@ public class SettingsActivity extends PreferenceActivity implements OnSharedPref
if(key.compareTo(getString(R.string.pref_key_point_size))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_point_size));
if(key.compareTo(getString(R.string.pref_key_angle))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_angle));
if(key.compareTo(getString(R.string.pref_key_triangle))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_triangle));
if(key.compareTo(getString(R.string.pref_key_background_color))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_background_color));
if(key.compareTo(getString(R.string.pref_key_rendering_texture_decimation))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_rendering_texture_decimation));
if(key.compareTo(getString(R.string.pref_key_update_rate))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_update_rate));
@@ -29,23 +29,20 @@ public class TextManager {
public static final String vs_Text =
"uniform mat4 uMVPMatrix;" +
"attribute vec4 vPosition;" +
"attribute vec4 a_Color;" +
"attribute vec2 a_texCoord;" +
"varying vec4 v_Color;" +
"varying vec2 v_texCoord;" +
"void main() {" +
" gl_Position = uMVPMatrix * vPosition;" +
" v_texCoord = a_texCoord;" +
" v_Color = a_Color;" +
"}";
public static final String fs_Text =
"precision mediump float;" +
"varying vec4 v_Color;" +
"uniform float uColor;" +
"varying vec2 v_texCoord;" +
"uniform sampler2D s_texture;" +
"void main() {" +
" gl_FragColor = texture2D( s_texture, v_texCoord ) * v_Color;" +
" gl_FragColor.rgb *= v_Color.a;" +
" gl_FragColor = texture2D( s_texture, v_texCoord );" +
" gl_FragColor.rgb *= uColor;" +
"}";
public static int sp_Text;
@@ -60,21 +57,19 @@ public class TextManager {
private float mUVWidth;
private float mUVHeight;
private float mTextHeight;
private float mColor;
private FloatBuffer vertexBuffer;
private FloatBuffer textureBuffer;
private FloatBuffer colorBuffer;
private ShortBuffer drawListBuffer;
private float[] vecs;
private float[] uvs;
private short[] indices;
private float[] colors;
private int index_vecs;
private int index_indices;
private int index_uvs;
private int index_colors;
private int texturenr;
private int[] mTextures;
@@ -87,7 +82,6 @@ public class TextManager {
{
// Create the arrays
vecs = new float[3 * 10];
colors = new float[4 * 10];
uvs = new float[2 * 10];
indices = new short[10];
@@ -133,6 +127,7 @@ public class TextManager {
}
mUVWidth = (float)RI_TEXT_HEIGHT_BASE/(float)RI_TEXT_TEXTURE_SIZE;
mUVHeight = mTextHeight/(float)RI_TEXT_TEXTURE_SIZE;
mColor = 1.0f;
int colCount = RI_TEXT_TEXTURE_SIZE/(int)RI_TEXT_HEIGHT_BASE;
mCharacterWidth = new float[RI_TEXT_STOP-RI_TEXT_START];
@@ -190,13 +185,6 @@ public class TextManager {
index_vecs++;
}
// We should add the colors, so we can use the same texture for multiple effects.
for(int i=0;i<cs.length;i++)
{
colors[index_colors] = cs[i];
index_colors++;
}
// We should add the uvs
for(int i=0;i<uv.length;i++)
{
@@ -218,7 +206,6 @@ public class TextManager {
index_vecs = 0;
index_indices = 0;
index_uvs = 0;
index_colors = 0;
// Get the total amount of characters
int charcount = 0;
@@ -234,12 +221,10 @@ public class TextManager {
// Create the arrays we need with the correct size.
vecs = null;
colors = null;
uvs = null;
indices = null;
vecs = new float[charcount * 12];
colors = new float[charcount * 16];
uvs = new float[charcount * 8];
indices = new short[charcount * 6];
@@ -269,6 +254,7 @@ public class TextManager {
if(vecs.length > 0)
{
GLES20.glDisable(GLES20.GL_DEPTH_TEST);
GLES20.glEnable(GLES20.GL_BLEND);
// Set the correct shader for our grid object.
GLES20.glUseProgram(sp_Text);
@@ -280,13 +266,6 @@ public class TextManager {
vertexBuffer.put(vecs);
vertexBuffer.position(0);
// The vertex buffer.
ByteBuffer bb3 = ByteBuffer.allocateDirect(colors.length * 4);
bb3.order(ByteOrder.nativeOrder());
colorBuffer = bb3.asFloatBuffer();
colorBuffer.put(colors);
colorBuffer.position(0);
// The texture buffer
ByteBuffer bb2 = ByteBuffer.allocateDirect(uvs.length * 4);
bb2.order(ByteOrder.nativeOrder());
@@ -322,22 +301,16 @@ public class TextManager {
GLES20.glEnableVertexAttribArray ( mPositionHandle );
GLES20.glEnableVertexAttribArray ( mTexCoordLoc );
int mColorHandle = GLES20.glGetAttribLocation(sp_Text, "a_Color");
// Enable a handle to the triangle vertices
GLES20.glEnableVertexAttribArray(mColorHandle);
// Prepare the background coordinate data
GLES20.glVertexAttribPointer(mColorHandle, 4,
GLES20.GL_FLOAT, false,
0, colorBuffer);
// get handle to shape's transformation matrix
int mtrxhandle = GLES20.glGetUniformLocation(sp_Text, "uMVPMatrix");
// Apply the projection and view transformation
GLES20.glUniformMatrix4fv(mtrxhandle, 1, false, m, 0);
// get handle to color value
int colorhandle = GLES20.glGetUniformLocation(sp_Text, "uColor");
GLES20.glUniform1f(colorhandle, mColor);
int mSamplerLoc = GLES20.glGetUniformLocation (sp_Text, "s_texture" );
// Texture activate unit 0
@@ -353,7 +326,6 @@ public class TextManager {
// Disable vertex array
GLES20.glDisableVertexAttribArray(mPositionHandle);
GLES20.glDisableVertexAttribArray(mTexCoordLoc);
GLES20.glDisableVertexAttribArray(mColorHandle);
}
}
@@ -440,4 +412,8 @@ public class TextManager {
public void setUniformscale(float uniformscale) {
this.uniformscale = uniformscale;
}
public void setColor(float color) {
mColor = color;
}
}