feat(slam): add rtabmap_ros

This commit is contained in:
X-lanni
2025-07-14 11:34:38 +08:00
parent 3b6641c1fb
commit 943ce5b06f
1635 changed files with 603092 additions and 0 deletions
@@ -0,0 +1,32 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_AXIS_H_
#define TANGO_GL_AXIS_H_
#include "tango-gl/line.h"
namespace tango_gl {
class Axis : public Line {
public:
Axis();
void Render(const glm::mat4& projection_mat, const glm::mat4& view_mat) const;
private:
GLuint attrib_colors_;
std::vector<glm::vec4> vec_colors_;
};
} // namespace tango_gl
#endif // TANGO_GL_AXIS_H_
@@ -0,0 +1,55 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_BAND_H_
#define TANGO_GL_BAND_H_
#include <stdlib.h>
#include <vector>
#include "tango-gl/drawable_object.h"
namespace tango_gl {
class Band : public DrawableObject {
public:
enum BandMode {
kNormal = 0,
kKeepLeft = 1,
kKeepRight = 2
};
Band(const unsigned int max_legnth);
void SetWidth(const float width);
// Render a Band with arrow head, pass in the mode for rendering,
// kKeepLeft is left turn, kKeepRight is right turn,
// when making a turn, vertices only get updated in one side to avoid overlapping.
void UpdateVertexArray(const glm::mat4 m, BandMode mode);
void UpdateVertexArray(const glm::mat4 m);
void SetVertexArray(const std::vector<glm::vec3>& v, const glm::vec3& up);
void ClearVertexArray();
void Render(const glm::mat4& projection_mat, const glm::mat4& view_mat) const;
private:
float band_width_;
unsigned int max_length_;
std::vector<glm::vec3> vertices_v_;
// Current band head's left and right position in world frame.
glm::vec3 pivot_left;
glm::vec3 pivot_right;
};
} // namespace tango_gl
#endif // TANGO_GL_BAND_H_
@@ -0,0 +1,42 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_BOUNDING_BOX_H_
#define TANGO_GL_BOUNDING_BOX_H_
#include <vector>
#include "tango-gl/segment.h"
#include "tango-gl/util.h"
namespace tango_gl {
class BoundingBox {
public:
BoundingBox()
: bounding_min_(glm::vec3(0, 0, 0)), bounding_max_(glm::vec3(0, 0, 0)) {}
BoundingBox(const std::vector<float>& vertices);
BoundingBox(const glm::vec3& min, const glm::vec3& max)
: bounding_min_(min), bounding_max_(max) {}
bool IsIntersecting(const Segment& segment, const glm::quat& rotation,
const glm::mat4& transformation);
private:
// Axis-aligned bounding box minimum and maximum point.
glm::vec3 bounding_min_;
glm::vec3 bounding_max_;
};
} // namespace tango_gl
#endif // TANGO_GL_BOUNDING_BOX_H_
@@ -0,0 +1,69 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_CAMERA_H_
#define TANGO_GL_CAMERA_H_
#include "tango-gl/transform.h"
namespace tango_gl {
class Camera : public Transform {
public:
Camera();
Camera(const Camera& other) = delete;
Camera& operator=(const Camera&) = delete;
~Camera();
void SetWindowSize(const float width, const float height);
void SetFieldOfView(const float fov);
void SetOrthoMode(bool enabled) {ortho_ = enabled;}
void SetOrthoScale(float scale) {orthoScale_ = scale;}
void SetOrthoCropFactor(float value) {orthoCropFactor_ = value;}
void SetNearFarClipPlanes(const float near, const float far);
glm::mat4 GetViewMatrix();
glm::mat4 GetProjectionMatrix();
float getNearClipPlane() const {return near_clip_plane_;}
float getFarClipPlane() const {return far_clip_plane_;}
/**
* Create an OpenGL perspective matrix from window size, camera intrinsics, and clip settings.
*
* @param width - The width of the camera image.
* @param height - The height of the camera image.
* @param fx - The x-axis focal length of the camera.
* @param fy - The y-axis focal length of the camera.
* @param cx - The x-coordinate principal point in pixels.
* @param cy - The y-coordinate principal point in pixels.
* @param near - The desired near z-clipping plane.
* @param far - The desired far z-clipping plane.
*/
static glm::mat4 ProjectionMatrixForCameraIntrinsics(float width, float height,
float fx, float fy,
float cx, float cy,
float near, float far);
protected:
float field_of_view_;
float aspect_ratio_;
float width_;
float height_;
float near_clip_plane_, far_clip_plane_;
bool ortho_;
float orthoScale_;
float orthoCropFactor_;
};
} // namespace tango_gl
#endif // TANGO_GL_CAMERA_H_
@@ -0,0 +1,28 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_CIRCLE_H_
#define TANGO_GL_CIRCLE_H_
#include "tango-gl/mesh.h"
namespace tango_gl {
class Circle : public Mesh {
public:
Circle(float radius, int resolution);
};
} // namespace tango_gl
#endif // TANGO_GL_CIRCLE_H_
@@ -0,0 +1,33 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_COLOR_H_
#define TANGO_GL_COLOR_H_
namespace tango_gl {
class Color {
public:
Color() : r(0), g(0), b(0) {}
Color(float red, float green, float blue) : r(red), g(green), b(blue) {}
Color(const Color&) = default;
Color& operator=(const Color&) = default;
float r;
float g;
float b;
};
} // namespace tango_gl
#endif // TANGO_GL_COLOR_H_
@@ -0,0 +1,132 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_GL_TANGO_CONVERSIONS_H_
#define TANGO_GL_GL_TANGO_CONVERSIONS_H_
#define GLM_FORCE_RADIANS
#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/gtc/quaternion.hpp"
namespace tango_gl {
namespace conversions {
/**
* @brief Creates a glm::vec3 from double[3] = {x, y, z}. This is designed to
* work with the TangoPoseData.translation field.
*/
inline glm::vec3 Vec3FromArray(const double* array) {
return glm::vec3(array[0], array[1], array[2]);
}
/**
* @brief Creates a glm::quat from double[4] = {x, y, z, w}. This is designed to
* work with the TangoPoseData.orientation field.
*/
inline glm::quat QuatFromArray(const double* array) {
// Note GLM expects arguments in order {w, x, y, z}.
return glm::quat(array[3], array[0], array[1], array[2]);
}
/**
* @brief Creates a glm::mat4 rigid-frame transformation matrix from two arrays.
* This is designed for the TangoPoseData translation and orientation fields.
* @param A_p_B Position [x, y, z] of B_origin from A_origin, expressed in A.
* @param A_q_B The quaternion representation [x, y, z, w] of the rotation
* matrix A_R_B.
* @return The transformation matrix A_T_B.
*/
inline glm::mat4 TransformFromArrays(const double* A_p_B, const double* A_q_B) {
glm::vec3 glm_A_p_B = Vec3FromArray(A_p_B);
glm::quat glm_A_q_B = QuatFromArray(A_q_B);
return glm::translate(glm::mat4(1.0f), glm_A_p_B) * glm::mat4_cast(glm_A_q_B);
}
/**
* @brief Creates a glm::mat4 rigid-frame transformation matrix from glm::vec3 and glm::quat.
* This is designed for the TangoPoseData translation and orientation fields.
* @param A_p_B A position vector of B_origin from A_origin, expressed in A.
* @param A_q_B A quaternion representation of the rotation.
* matrix A_R_B.
* @return The transformation matrix A_T_B.
*/
inline glm::mat4 TransformFromVecAndQuat(const glm::vec3& A_p_B, const glm::quat& A_q_B) {
return glm::translate(glm::mat4(1.0f), A_p_B) * glm::mat4_cast(A_q_B);
}
/**
* @brief Convert (re-express, or rotate) a vector from the Tango ADF (or start-
* of-service) frame convention [right, forward, up] to the typical OpenGl world
* frame convention [right, up, backward]. Note this assumes the two frames are
* coincident, and it doesn't know about any additional offsets between a
* particular OpenGl scene and the Tango service frames.
* @param tango_vec A vector expressed in the Tango ADF frame convention.
* @return The same vector expressed using the Opengl frame convention.
*/
inline glm::vec3 Vec3TangoToGl(const glm::vec3& tango_vec) {
return glm::vec3(tango_vec.x, tango_vec.z, -tango_vec.y);
}
/**
* @brief Convert (re-express, or rotate) a vector from the typical OpenGl world
* frame convention [right, up, backward] to the Tango ADF (or start-of-service)
* frame convention [right, forward, up]. Note this assumes the two frames are
* coincident, and it doesn't know about any additional offsets between a
* particular OpenGl scene and the Tango service frames.
* @param gl_vec A vector expressed in the Opengl world frame convention.
* @return The same vector expressed using the Tango ADF frame convention.
*/
inline glm::vec3 Vec3GlToTango(const glm::vec3& gl_vec) {
return glm::vec3(gl_vec.x, -gl_vec.z, gl_vec.y);
}
/**
* @brief Given a quaternion representing the rotation matrix tango_R_any,
* returns the quaternion representing gl_R_any, where "any" is an arbitrary
* frame. Note the gl base frame is rotated by 90-degrees about +X from the
* Tango ADF/start-of-service frame, so this is equivalent to applying such a
* rotation to the quaternion.
* @param tango_q_any A quaternion representing rotation matrix tango_R_any.
* @return The quaternion representing gl_R_any.
*/
glm::quat QuatTangoToGl(const glm::quat& tango_q_any);
/**
* Get the fixed transformation matrix relating the opengl frame convention
* (with Y-up, X-right) and the tango frame convention for the start-of-service
* and ADF frames (with Z-up, X-right), termed "world" here.
*/
glm::mat4 opengl_world_T_tango_world();
/**
* Get the fixed transformation matrix relating the frame convention of the
* device's color camera frame (with Z-forward, X-right) and the opengl camera
* frame (with Z-backward, X-right).
*/
glm::mat4 color_camera_T_opengl_camera();
/**
* Get the fixed transformation matrix relating the frame convention of the
* device's depth camera frame (with Z-forward, X-right) and the opengl camera
* frame (with Z-backward, X-right).
*/
glm::mat4 depth_camera_T_opengl_camera();
} // namespace conversions
} // namespace tango_gl
#endif // TANGO_GL_GL_TANGO_CONVERSIONS_H_
@@ -0,0 +1,28 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_CUBE_H_
#define TANGO_GL_CUBE_H_
#include "tango-gl/mesh.h"
namespace tango_gl {
class Cube : public Mesh {
public:
Cube();
};
} // namespace tango_gl
#endif // TANGO_GL_CUBE_H_
@@ -0,0 +1,63 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_DRAWABLE_OBJECT_H_
#define TANGO_GL_DRAWABLE_OBJECT_H_
#include <vector>
#include "tango-gl/color.h"
#include "tango-gl/transform.h"
#include "tango-gl/util.h"
namespace tango_gl {
class DrawableObject : public Transform {
public:
DrawableObject() : red_(0), green_(0), blue_(0), alpha_(1.0f) {};
DrawableObject(const DrawableObject& other) = delete;
const DrawableObject& operator=(const DrawableObject&) = delete;
void DeleteGlResources();
void SetShader();
void SetColor(const Color& color);
void SetColor(const float red, const float green, const float blue);
void SetAlpha(const float alpha);
void SetVertices(const std::vector<GLfloat>& vertices);
void SetVertices(const std::vector<GLfloat>& vertices,
const std::vector<GLushort>& indices);
void SetVertices(const std::vector<GLfloat>& vertices,
const std::vector<GLfloat>& normals);
virtual void Render(const glm::mat4& projection_mat,
const glm::mat4& view_mat) const = 0;
protected:
float red_;
float green_;
float blue_;
float alpha_;
std::vector<GLushort> indices_;
std::vector<GLfloat> vertices_;
std::vector<GLfloat> normals_;
GLenum render_mode_;
GLuint shader_program_;
GLuint uniform_color_;
GLuint uniform_mvp_mat_;
GLuint attrib_vertices_;
GLuint attrib_normals_;
};
} // namespace tango_gl
#endif // TANGO_GL_DRAWABLE_OBJECT_H_
@@ -0,0 +1,28 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_FRUSTUM_H_
#define TANGO_GL_FRUSTUM_H_
#include "tango-gl/line.h"
namespace tango_gl {
class Frustum : public Line {
public:
Frustum();
};
} // namespace tango_gl
#endif // TANGO_GL_FRUSTUM_H_
@@ -0,0 +1,94 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_GESTURE_CAMERA_H_
#define TANGO_GL_GESTURE_CAMERA_H_
#include "tango-gl/camera.h"
#include "tango-gl/segment.h"
#include "tango-gl/transform.h"
#include "tango-gl/util.h"
namespace tango_gl {
class GestureCamera : public Camera {
public:
enum CameraType {
kFirstPerson = 0,
kThirdPersonFollow = 1,
kTopDown = 2,
kTopOrtho = 3,
kThirdPerson = 4
};
enum TouchEvent {
kTouch0Down = 0,
kTouch0Up = 1,
kTouchMove = 2,
kTouch1Down = 5,
kTouch1Up = 6,
kTouchNone = -1
};
GestureCamera();
~GestureCamera();
void OnTouchEvent(int touch_count, TouchEvent event, float x0, float y0,
float x1, float y1);
// Get the ray in opengl world frame given the 2d touch position on screen,
// normalized touch_x and normalized touch_y should be the same value get from
// OnTouchEvent, x0 and y0, touch_range is the depth of the touch in
// camera frame.
Segment GetSegmentFromTouch(float normalized_x, float normalized_y,
float touch_range);
void SetAnchorPosition(const glm::vec3& pos, const glm::quat & rotation);
void SetAnchorOffset(const glm::vec3& pos) {anchor_offset_ = pos;}
const glm::vec3& GetAnchorOffset() const {return anchor_offset_;}
void SetCameraDistance(float cameraDistance) {cam_cur_dist_ = cameraDistance;}
float GetCameraDistance() const {return cam_cur_dist_;}
// Set camera type, set render camera's parent position and rotation.
void SetCameraType(CameraType camera_index);
CameraType GetCameraType() const { return camera_type_; }
float getFOV() const {return field_of_view_ * RADIAN_2_DEGREE;}
private:
void StartCameraToCurrentTransform();
// Render camera's parent transformation.
Transform* cam_parent_transform_;
CameraType camera_type_;
glm::vec2 cam_start_angle_;
glm::vec2 cam_cur_angle_;
glm::quat cam_cur_target_rot_;
float cam_start_dist_;
float cam_start_fov_;
float cam_cur_dist_;
glm::vec3 anchor_offset_;
float start_touch_dist_;
float cur_touch_dist_;
glm::vec2 touch0_start_position_;
};
} // namespace tango_gl
#endif // TANGO_GL_GESTURE_CAMERA_H_
@@ -0,0 +1,18 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
* Distributed under the Project Tango Preview Development Kit (PDK) Agreement.
* CONFIDENTIAL. AUTHORIZED USE ONLY. DO NOT REDISTRIBUTE.
*/
#ifndef TANGO_GL_GOAL_MARKER_H_
#define TANGO_GL_GOAL_MARKER_H_
#include <tango-gl/mesh.h>
namespace tango_gl {
class GoalMarker : public Mesh {
public:
GoalMarker();
};
} // namespace tango_gl
#endif // TANGO_GL_GOAL_MARKER_H_
@@ -0,0 +1,28 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_GRID_H_
#define TANGO_GL_GRID_H_
#include "tango-gl/line.h"
namespace tango_gl {
class Grid : public Line {
public:
Grid(float density = 1.0f, int qx = 50, int qy = 50);
};
} // namespace tango_gl
#endif // TANGO_GL_GRID_H_
@@ -0,0 +1,37 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_LINE_H_
#define TANGO_GL_LINE_H_
#include "tango-gl/drawable_object.h"
namespace tango_gl {
class Line : public DrawableObject {
public:
Line(float line_width, GLenum render_mode);
void SetLineWidth(const float pixels);
void Render(const glm::mat4& projection_mat, const glm::mat4& view_mat) const;
void UpdateLineVertices(const std::vector<glm::vec3>& vec_vertices) {
vec_vertices_ = vec_vertices;
}
protected:
float line_width_;
std::vector<glm::vec3> vec_vertices_;
};
} // namespace tango_gl
#endif // TANGO_GL_LINE_H_
@@ -0,0 +1,45 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_MESH_H_
#define TANGO_GL_MESH_H_
#include "tango-gl/bounding_box.h"
#include "tango-gl/drawable_object.h"
#include "tango-gl/segment.h"
namespace tango_gl {
class Mesh : public DrawableObject {
public:
Mesh();
Mesh(GLenum render_mode);
void SetShader();
void SetShader(bool is_lighting_on);
void SetBoundingBox();
void SetLightDirection(const glm::vec3& light_direction);
void Render(const glm::mat4& projection_mat, const glm::mat4& view_mat) const;
bool IsIntersecting(const Segment& segment);
protected:
BoundingBox* bounding_box_;
bool is_lighting_on_;
bool is_bounding_box_on_;
glm::vec3 light_direction_;
GLuint uniform_mv_mat_;
GLuint uniform_light_vec_;
};
} // namespace tango_gl
#endif // TANGO_GL_MESH_H_
@@ -0,0 +1,61 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_OBJ_LOADER_H
#define TANGO_GL_OBJ_LOADER_H
#include <vector>
#include "tango-gl/util.h"
namespace tango_gl {
namespace obj_loader {
// Load standard .obj file into vertices, indices or normals vectors,
// OBJ file can be exported from 3D tools like 3ds Max or Blender.
// A readable file with only vertices should look like
// "v 1.00 2.00 3.00
// ...
// f 1 2 3
// f 1 2 3 4
// ..."
//
// If exported with normals, file should look like
// "v 1.00 2.00 3.00
// ...
// f 1//1 2//3 3//4
// f 1//1 2//3 3//4 4//6
// ...
// vn 1.00 2.00 3.00
// ..."
// this can be used with Mesh:
//
// std::vector<GLfloat> vertices;
// std::vector<GLushort> indices;
// std::vector<GLfloat> normals;
// tango_gl::obj_loader::LoadOBJData("/sdcard/model.obj", vertices, indices);
// mesh->SetVertices(vertices, indices);
// or
// tango_gl::obj_loader::LoadOBJData("/sdcard/model.obj", vertices, normals);
// mesh->SetVertices(vertices, normals);
bool LoadOBJData(const char* path, std::vector<GLfloat>& vertices,
std::vector<GLushort>& indices);
bool LoadOBJData(const char* path, std::vector<GLfloat>& vertices,
std::vector<GLfloat>& normals);
} // namespace obj_loader
} // namespace tango_gl
#endif // TANGO_GL_OBJ_LOADER
@@ -0,0 +1,44 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_QUAD_H_
#define TANGO_GL_QUAD_H_
#include "tango-gl/drawable_object.h"
namespace tango_gl {
class Quad : public DrawableObject {
public:
Quad();
Quad(const Quad& other) = delete;
Quad& operator=(const Quad&) = delete;
~Quad();
void Render(const glm::mat4& projection_mat, const glm::mat4& view_mat) const;
void SetTextureId(GLuint texture_id);
private:
GLuint vertex_buffer_;
GLuint shader_program_;
GLuint attrib_vertices_;
GLuint texture_coords_;
GLuint texture_handle;
GLuint uniform_mvp_mat_;
GLuint texture_id_;
};
} // namespace tango_gl
#endif // TANGO_GL_QUAD_H_
@@ -0,0 +1,35 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_SEGMENT_H_
#define TANGO_GL_SEGMENT_H_
#include "glm/glm.hpp"
namespace tango_gl {
class Segment {
public:
Segment() : start(glm::vec3(0, 0, 0)), end(glm::vec3(0, 0, 0)) {}
Segment(const glm::vec3& segment_start, const glm::vec3& segment_end)
: start(segment_start), end(segment_end) {}
Segment(const Segment&) = default;
Segment& operator=(const Segment&) = default;
glm::vec3 start;
glm::vec3 end;
};
} // namespace tango_gl
#endif // TANGO_GL_SEGMENT_H_
@@ -0,0 +1,30 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_SEGMENT_DRAWABLE_H_
#define TANGO_GL_SEGMENT_DRAWABLE_H_
#include "tango-gl/line.h"
#include "tango-gl/segment.h"
namespace tango_gl {
class SegmentDrawable : public Line {
public:
SegmentDrawable();
void UpdateSegment(const Segment& segment);
};
} // namespace tango_gl
#endif // TANGO_GL_SEGMENT_DRAWABLE_H_
@@ -0,0 +1,32 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_SHADERS_H_
#define TANGO_GL_SHADERS_H_
#include <string>
namespace tango_gl {
namespace shaders {
std::string GetBasicVertexShader();
std::string GetBasicFragmentShader();
std::string GetColorVertexShader();
std::string GetVideoOverlayVertexShader();
std::string GetVideoOverlayFragmentShader();
std::string GetShadedVertexShader();
} // namespace shaders
} // namespace tango_gl
#endif // TANGO_GL_SHADERS_H_
@@ -0,0 +1,50 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_TEXTURE_H_
#define TANGO_GL_TEXTURE_H_
#include <errno.h>
#ifdef __ANDROID__
#include <png.h>
#endif
#include "tango-gl/util.h"
namespace tango_gl {
class Texture {
public:
Texture(const char* file_path);
Texture(const Texture& other) = delete;
Texture& operator=(const Texture&) = delete;
~Texture();
#ifdef __ANDROID__
bool LoadFromPNG(const char* file_path);
#endif
GLuint GetTextureID() const;
private:
#ifdef __ANDROID__
png_uint_32 width_, height_;
#endif
int bit_depth_, color_type_;
char* byte_data_;
GLuint texture_id_;
};
} // namespace tango_gl
#endif // TANGO_GL_TEXTURE_H_
@@ -0,0 +1,30 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_TRACE_H_
#define TANGO_GL_TRACE_H_
#include "tango-gl/line.h"
namespace tango_gl {
class Trace : public Line {
public:
Trace();
void UpdateVertexArray(const glm::vec3& v);
void ClearVertexArray();
};
} // namespace tango_gl
#endif // TANGO_GL_TRACE_H_
@@ -0,0 +1,59 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_TRANSFORM_H_
#define TANGO_GL_TRANSFORM_H_
#include "glm/glm.hpp"
#include "glm/gtc/quaternion.hpp"
namespace tango_gl {
class Transform {
public:
Transform();
virtual ~Transform();
Transform(const Transform& other) = delete;
const Transform& operator=(const Transform& rhs) = delete;
void SetPosition(const glm::vec3& position);
glm::vec3 GetPosition() const;
void SetRotation(const glm::quat& rotation);
glm::quat GetRotation() const;
void SetScale(const glm::vec3& scale);
glm::vec3 GetScale() const;
void Translate(const glm::vec3& translation);
void SetTransformationMatrix(const glm::mat4& transform_mat);
glm::mat4 GetTransformationMatrix() const;
void SetParent(Transform* transform);
const Transform* GetParent() const ;
Transform* GetParent() ;
private:
Transform* parent_;
glm::vec3 position_;
glm::quat rotation_;
glm::vec3 scale_;
};
} // namespace tango_gl
#endif // TANGO_GL_TRANSFORM_H_
@@ -0,0 +1,28 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_TRIANGLE_H_
#define TANGO_GL_TRIANGLE_H_
#include "tango-gl/mesh.h"
namespace tango_gl {
class Triangle : public Mesh {
public:
Triangle();
};
} // namespace tango_gl
#endif // TANGO_GL_TRIANGLE_H_
@@ -0,0 +1,106 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_GL_UTIL_H_
#define TANGO_GL_GL_UTIL_H_
#define GLM_FORCE_RADIANS
#define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642
#include <stdlib.h>
#ifdef __ANDROID__
#include <jni.h>
#include <android/log.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#else // __APPLE__
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
#include <syslog.h>
#endif
#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/gtc/quaternion.hpp"
#include "glm/gtc/type_ptr.hpp"
#include "glm/gtx/matrix_decompose.hpp"
#define LOG_TAG "rtabmap"
#if defined(DISABLE_LOG)
#define LOGD(...) ;
#define LOGI(...) ;
#define LOGW(...) ;
#else
#ifdef __APPLE__
#define LOGD(...) fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n")
#define LOGI(...) fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n")
#define LOGW(...) fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n")
#else
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__)
#endif
#endif
#ifdef __APPLE__
#define LOGE(...) fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n")
#define LOGF(...) fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n")
#else
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
#define LOGF(...) __android_log_print(ANDROID_LOG_FATAL,LOG_TAG,__VA_ARGS__)
#endif
#ifndef M_PI
#define M_PI 3.1415926f
#endif
#define RADIAN_2_DEGREE 57.2957795f
#define DEGREE_2_RADIANS 0.0174532925f
namespace tango_gl {
namespace util {
void CheckGlError(const char* operation);
GLuint CreateProgram(const char* vertex_source,
const char* fragment_source);
void DecomposeMatrix(const glm::mat4& transform_mat,
glm::vec3& translation,
glm::quat& rotation,
glm::vec3& scale);
// Get a 3x1 column from the upper 3x4 of a transformation matrix. Columns
// 0, 1, 2 are the rotation/scale portion, and column 3 is the translation.
glm::vec3 GetColumnFromMatrix(const glm::mat4& mat, const int col);
// Get the translation component of a transformation matrix.
glm::vec3 GetTranslationFromMatrix(const glm::mat4& mat);
float Clamp(float value, float min, float max);
void PrintMatrix(const glm::mat4& matrix);
void PrintVector(const glm::vec3& vector);
void PrintQuaternion(const glm::quat& quat);
glm::vec3 LerpVector(const glm::vec3& x, const glm::vec3& y, float a);
float DistanceSquared(const glm::vec3& v1, const glm::vec3& v2);
bool SegmentAABBIntersect(const glm::vec3& aabb_min, const glm::vec3& aabb_max,
const glm::vec3& start, const glm::vec3& end);
glm::vec3 ApplyTransform(const glm::mat4& mat, const glm::vec3& vec);
} // namespace util
} // namespace tango_gl
#endif // TANGO_GL_RENDERER_GL_UTIL
@@ -0,0 +1,39 @@
/*
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TANGO_GL_RENDERER_VIDEO_OVERLAY_H_
#define TANGO_GL_RENDERER_VIDEO_OVERLAY_H_
#include "tango-gl/drawable_object.h"
namespace tango_gl {
class VideoOverlay : public DrawableObject {
public:
VideoOverlay();
void Render(const glm::mat4& projection_mat, const glm::mat4& view_mat) const;
GLuint GetTextureId() const { return texture_id_; }
void SetTextureId(GLuint texture_id) { texture_id_ = texture_id; }
private:
// This id is populated on construction, and is passed to the tango service.
GLuint texture_id_;
GLuint attrib_texture_coords_;
GLuint uniform_texture_;
GLuint vertex_buffers_[3];
};
} // namespace tango_gl
#endif // TANGO_GL_RENDERER_VIDEO_OVERLAY_H_