RTABMapApp.h
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007     * Redistributions of source code must retain the above copyright
00008       notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright
00010       notice, this list of conditions and the following disclaimer in the
00011       documentation and/or other materials provided with the distribution.
00012     * Neither the name of the Universite de Sherbrooke nor the
00013       names of its contributors may be used to endorse or promote products
00014       derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
00020 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 */
00027 
00028 #ifndef RTABMAP_APP_H_
00029 #define RTABMAP_APP_H_
00030 
00031 #include <jni.h>
00032 #include <memory>
00033 
00034 #include <tango_client_api.h>  // NOLINT
00035 #include <tango-gl/util.h>
00036 
00037 #include <scene.h>
00038 #include <CameraTango.h>
00039 #include <util.h>
00040 
00041 #include <rtabmap/core/RtabmapThread.h>
00042 #include <rtabmap/utilite/UEventsHandler.h>
00043 #include <boost/thread/mutex.hpp>
00044 #include <pcl/pcl_base.h>
00045 
00046 // RTABMapApp handles the application lifecycle and resources.
00047 class RTABMapApp : public UEventsHandler {
00048  public:
00049   // Constructor and deconstructor.
00050   RTABMapApp();
00051   ~RTABMapApp();
00052 
00053   void onCreate(JNIEnv* env, jobject caller_activity);
00054 
00055   void openDatabase(const std::string & databasePath);
00056 
00057   bool onTangoServiceConnected(JNIEnv* env, jobject iBinder);
00058 
00059   // Explicitly reset motion tracking and restart the pipeline.
00060   // Note that this will cause motion tracking to re-initialize.
00061   void TangoResetMotionTracking();
00062 
00063   // Tango Service point cloud callback function for depth data. Called when new
00064   // new point cloud data is available from the Tango Service.
00065   //
00066   // @param pose: The current point cloud returned by the service,
00067   //              caller allocated.
00068   void onPointCloudAvailable(const TangoXYZij* xyz_ij);
00069 
00070   // Tango service pose callback function for pose data. Called when new
00071   // information about device pose is available from the Tango Service.
00072   //
00073   // @param pose: The current pose returned by the service, caller allocated.
00074   void onPoseAvailable(const TangoPoseData* pose);
00075 
00076   // Tango service event callback function for event data. Called when new events
00077   // are available from the Tango Service.
00078   //
00079   // @param event: Tango event, caller allocated.
00080   void onTangoEventAvailable(const TangoEvent* event);
00081 
00082   // Allocate OpenGL resources for rendering, mainly for initializing the Scene.
00083   void InitializeGLContent();
00084 
00085   // Setup the view port width and height.
00086   void SetViewPort(int width, int height);
00087 
00088   // Main render loop.
00089   int Render();
00090 
00091   // Release all non-OpenGL allocated resources.
00092   void onPause();
00093 
00094   // Set render camera's viewing angle, first person, third person or top down.
00095   //
00096   // @param: camera_type, camera type includes first person, third person and
00097   //         top down
00098   void SetCameraType(tango_gl::GestureCamera::CameraType camera_type);
00099 
00100   // Touch event passed from android activity. This function only supports two
00101   // touches.
00102   //
00103   // @param: touch_count, total count for touches.
00104   // @param: event, touch event of current touch.
00105   // @param: x0, normalized touch location for touch 0 on x axis.
00106   // @param: y0, normalized touch location for touch 0 on y axis.
00107   // @param: x1, normalized touch location for touch 1 on x axis.
00108   // @param: y1, normalized touch location for touch 1 on y axis.
00109   void OnTouchEvent(int touch_count, tango_gl::GestureCamera::TouchEvent event,
00110                     float x0, float y0, float x1, float y1);
00111 
00112   void setPausedMapping(bool paused);
00113   void setMapCloudShown(bool shown);
00114   void setOdomCloudShown(bool shown);
00115   void setMeshRendering(bool enabled);
00116   void setLocalizationMode(bool enabled);
00117   void setTrajectoryMode(bool enabled);
00118   void setGraphOptimization(bool enabled);
00119   void setNodesFiltering(bool enabled);
00120   void setGraphVisible(bool visible);
00121   void setAutoExposure(bool enabled);
00122   void setFullResolution(bool enabled);
00123   void setMaxCloudDepth(float value);
00124   void setMeshAngleTolerance(float value);
00125   void setMeshTriangleSize(int value);
00126   int setMappingParameter(const std::string & key, const std::string & value);
00127 
00128   void resetMapping();
00129   void save();
00130   bool exportMesh(const std::string & filePath);
00131   int postProcessing(int approach);
00132 
00133  protected:
00134   virtual void handleEvent(UEvent * event);
00135 
00136  private:
00137   rtabmap::ParametersMap getRtabmapParameters();
00138 
00139  private:
00140   rtabmap::CameraTango * camera_;
00141   rtabmap::RtabmapThread * rtabmapThread_;
00142   rtabmap::Rtabmap * rtabmap_;
00143   LogHandler * logHandler_;
00144 
00145   bool odomCloudShown_;
00146   bool graphOptimization_;
00147   bool nodesFiltering_;
00148   bool localizationMode_;
00149   bool trajectoryMode_;
00150   bool autoExposure_;
00151   bool fullResolution_;
00152   float maxCloudDepth_;
00153   int meshTrianglePix_;
00154   float meshAngleToleranceDeg_;
00155 
00156   rtabmap::ParametersMap mappingParameters_;
00157 
00158 
00159   bool clearSceneOnNextRender_;
00160   int totalPoints_;
00161   int totalPolygons_;
00162   int lastDrawnCloudsCount_;
00163   float renderingFPS_;
00164 
00165   // main_scene_ includes all drawable object for visualizing Tango device's
00166   // movement and point cloud.
00167   Scene main_scene_;
00168 
00169         std::list<rtabmap::Statistics> rtabmapEvents_;
00170         std::list<rtabmap::OdometryEvent> odomEvents_;
00171         std::list<rtabmap::Transform> poseEvents_;
00172 
00173         boost::mutex rtabmapMutex_;
00174         boost::mutex meshesMutex_;
00175         boost::mutex odomMutex_;
00176         boost::mutex poseMutex_;
00177 
00178         struct Mesh
00179         {
00180                 pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud;
00181                 std::vector<pcl::Vertices> polygons;
00182                 rtabmap::Transform pose;
00183                 cv::Mat texture;
00184         };
00185 
00186         std::map<int, Mesh> createdMeshes_;
00187         std::map<int, rtabmap::Transform> rawPoses_;
00188 
00189         std::pair<rtabmap::RtabmapEventInit::Status, std::string> status_;
00190 };
00191 
00192 #endif  // TANGO_POINT_CLOUD_POINT_CLOUD_APP_H_


rtabmap
Author(s): Mathieu Labbe
autogenerated on Sat Jul 23 2016 11:44:17