From 6c9572714fde829383bdea68f96792184608db62 Mon Sep 17 00:00:00 2001 From: matlabbe Date: Mon, 27 Feb 2017 16:53:05 -0500 Subject: [PATCH] Tango: added sketchfab links, Color Radius is used when texturing optimized mesh --- app/android/AndroidManifest.xml.in | 2 +- app/android/jni/RTABMapApp.cpp | 53 +++++++++++++++++++ app/android/res/values/strings.xml | 8 ++- .../com/introlab/rtabmap/RTABMapActivity.java | 42 ++++++++++++--- .../introlab/rtabmap/SketchfabActivity.java | 2 +- 5 files changed, 96 insertions(+), 11 deletions(-) diff --git a/app/android/AndroidManifest.xml.in b/app/android/AndroidManifest.xml.in index 1e370090..2b380b84 100644 --- a/app/android/AndroidManifest.xml.in +++ b/app/android/AndroidManifest.xml.in @@ -2,7 +2,7 @@ diff --git a/app/android/jni/RTABMapApp.cpp b/app/android/jni/RTABMapApp.cpp index 06243796..e234406f 100644 --- a/app/android/jni/RTABMapApp.cpp +++ b/app/android/jni/RTABMapApp.cpp @@ -1823,6 +1823,59 @@ bool RTABMapApp::exportMesh( } else { + if(optimizedColorRadius > 0.0f && optimizedCleanWhitePolygons) + { + LOGI("Removing polygons too far from the cloud"); + // transfer color from point cloud to mesh + pcl::search::KdTree::Ptr tree (new pcl::search::KdTree(true)); + tree->setInputCloud(mergedClouds); + pcl::PointCloud::Ptr optimizedCloud(new pcl::PointCloud); + pcl::fromPCLPointCloud2(mesh->cloud, *optimizedCloud); + std::vector closePts(optimizedCloud->size()); + for(unsigned int i=0; isize(); ++i) + { + std::vector kIndices; + std::vector kDistances; + pcl::PointXYZRGBNormal pt; + pt.x = optimizedCloud->at(i).x; + pt.y = optimizedCloud->at(i).y; + pt.z = optimizedCloud->at(i).z; + tree->radiusSearch(pt, optimizedColorRadius, kIndices, kDistances); + if(kIndices.size()) + { + closePts.at(i) = true; + } + else + { + closePts.at(i) = false; + } + } + + // remove far polygons + std::vector filteredPolygons(mesh->polygons.size()); + int oi=0; + for(unsigned int i=0; ipolygons.size(); ++i) + { + bool keepPolygon = true; + for(unsigned int j=0; jpolygons[i].vertices.size(); ++j) + { + if(!closePts.at(mesh->polygons[i].vertices[j])) + { + keepPolygon = false; + break; + } + } + if(keepPolygon) + { + filteredPolygons[oi++] = mesh->polygons[i]; + } + } + filteredPolygons.resize(oi); + mesh->polygons = filteredPolygons; + + LOGI("Removing polygons too far from the cloud...done! %fs", timer.ticks()); + } + LOGI("Texturing..."); textureMesh = rtabmap::util3d::createTextureMesh( mesh, diff --git a/app/android/res/values/strings.xml b/app/android/res/values/strings.xml index ce4067ad..bf3f4e61 100644 --- a/app/android/res/values/strings.xml +++ b/app/android/res/values/strings.xml @@ -109,7 +109,7 @@ pref_key_opt_decimation_factor 60 pref_key_opt_color_radius - 0.2 + 0.05 pref_key_opt_clean_white true pref_key_gain_max_radius @@ -554,7 +554,7 @@ Mesh Decimation Factor Reduce the number of the output polygons on plane areas by this factor. Only used when exporting with texture. This also reduces texture projection time. Color Radius - Radius used to transfer nearest color from the point cloud to reconstructed mesh. + Radius used to transfer nearest color from the point cloud to reconstructed mesh. When exporting with texture, if Clean Mesh is also enabled, this will limit the number of polygons textured in holes. Clean Mesh Clean mesh from textureless or colorless reconstructed polygons. @@ -597,7 +597,9 @@ "1 m" "0.5 m" "0.2 m" + "0.1 m" "0.05 m" + "0.025 m" "0.01 m" "Disabled" @@ -607,7 +609,9 @@ "1" "0.5" "0.2" + "0.1" "0.05" + "0.025" "0.01" "-1" diff --git a/app/android/src/com/introlab/rtabmap/RTABMapActivity.java b/app/android/src/com/introlab/rtabmap/RTABMapActivity.java index 42922ff6..4694e1e6 100644 --- a/app/android/src/com/introlab/rtabmap/RTABMapActivity.java +++ b/app/android/src/com/introlab/rtabmap/RTABMapActivity.java @@ -55,8 +55,12 @@ import android.os.Debug; import android.os.IBinder; import android.preference.PreferenceManager; import android.text.Editable; +import android.text.Html; import android.text.InputType; +import android.text.SpannableString; import android.text.TextPaint; +import android.text.method.LinkMovementMethod; +import android.text.util.Linkify; import android.util.Log; import android.view.Display; import android.view.Menu; @@ -128,6 +132,7 @@ public class RTABMapActivity extends Activity implements OnClickListener { private long mOnPauseStamp = 0; private boolean mOnPause = false; private Date mDateOnPause = new Date(); + private boolean mBlockBack = true; private MenuItem mItemSave; private MenuItem mItemOpen; @@ -344,6 +349,20 @@ public class RTABMapActivity extends Activity implements OnClickListener { } } + @Override + public void onBackPressed() { + + if(mBlockBack) + { + mToast.makeText(this, "Press Back once more to exit", mToast.LENGTH_LONG).show(); + mBlockBack = false; + } + else + { + super.onBackPressed(); + } + } + @Override protected void onPause() { super.onPause(); @@ -1565,12 +1584,12 @@ public class RTABMapActivity extends Activity implements OnClickListener { { mToast.makeText(getActivity(), String.format("Cloud assembled and voxelized at %s m.", cloudVoxelSizeStr), mToast.LENGTH_LONG).show(); } - + // Visualize the result? - new AlertDialog.Builder(getActivity()) + AlertDialog d = new AlertDialog.Builder(getActivity()) .setCancelable(false) .setTitle("Export Successful!") - .setMessage("Do you want visualize the result before saving to file or sharing to Sketchfab?") + .setMessage(Html.fromHtml("Do you want visualize the result before saving to file or sharing to Sketchfab?")) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { mExportedOBJ = isOBJ; @@ -1588,10 +1607,10 @@ public class RTABMapActivity extends Activity implements OnClickListener { updateState(State.STATE_IDLE); RTABMapLib.postExportation(false); - new AlertDialog.Builder(getActivity()) + AlertDialog d2 = new AlertDialog.Builder(getActivity()) .setCancelable(false) .setTitle("Save to...") - .setMessage("Do you want to share to Sketchfab or save it on the device?") + .setMessage(Html.fromHtml("Do you want to share to Sketchfab or save it on device?")) .setPositiveButton("Share to Sketchfab", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { shareToSketchfab(); @@ -1606,10 +1625,16 @@ public class RTABMapActivity extends Activity implements OnClickListener { public void onClick(DialogInterface dialog, int which) { } }) - .show(); + .create(); + d2.show(); + // Make the textview clickable. Must be called after show() + ((TextView)d2.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); } }) - .show(); + .create(); + d.show(); + // Make the textview clickable. Must be called after show() + ((TextView)d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); } else { @@ -1665,6 +1690,7 @@ public class RTABMapActivity extends Activity implements OnClickListener { { Intent intent = new Intent(getActivity(), SettingsActivity.class); startActivity(intent); + mBlockBack = true; } else if(itemId == R.id.about) { @@ -1926,6 +1952,7 @@ public class RTABMapActivity extends Activity implements OnClickListener { public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(getActivity(), SettingsActivity.class); startActivity(intent); + mBlockBack = true; } }) .setNegativeButton("Close", new DialogInterface.OnClickListener() { @@ -1987,5 +2014,6 @@ public class RTABMapActivity extends Activity implements OnClickListener { } startActivityForResult(intent, SKETCHFAB_ACTIVITY_CODE); + mBlockBack = true; } } diff --git a/app/android/src/com/introlab/rtabmap/SketchfabActivity.java b/app/android/src/com/introlab/rtabmap/SketchfabActivity.java index 75e6e4ac..2bd523a2 100644 --- a/app/android/src/com/introlab/rtabmap/SketchfabActivity.java +++ b/app/android/src/com/introlab/rtabmap/SketchfabActivity.java @@ -303,7 +303,7 @@ public class SketchfabActivity extends Activity implements OnClickListener { { Log.i(RTABMapActivity.TAG, String.format("Zipped files = %d MB", fileSizeMB)); builder.setMessage(String.format("Total size to upload = %d MB. %sDo you want to continue?\n\n" - + "Tip: To reduce the model size, you can also look at the Settings->Exporting options to reduce the output size.", fileSizeMB, + + "Tip: To reduce the model size, you can also look at the Settings->Exporting options.", fileSizeMB, fileSizeMB>=50?"Note that for size over 50 MB, a Sketchfab PRO account is required, otherwise the upload may fail. ":"")); }