#ifndef UI_TVR_3D_VIEWER_H_
#define UI_TVR_3D_VIEWER_H_
#if _WIN32
#define NOMINMAX
#endif
#include <QGLWidget>
#include <QImage>
#include "libmv/base/vector.h"
#include "libmv/scene_graph/scene_graph_simple.h"
#include "ui/tvr/tvr_document.h"
#include "ui/tvr/gl_texture.h"
class SceneObject {
public:
virtual ~SceneObject() {};
enum ObjectType {
Camera, PointCloud, Image
};
virtual void Draw() {};
virtual ObjectType GetType() = 0;
};
class SceneCamera : public SceneObject {
public:
void Draw();
ObjectType GetType() { return Camera; }
void SetParameters(libmv::Mat3 K, libmv::Mat3 R, libmv::Vec3 t);
void SetTexture(GLTexture texture) { texture_ = texture; }
~SceneCamera() {};
private:
libmv::Mat3 K_;
libmv::Mat3 R_;
libmv::Vec3 t_;
GLTexture texture_;
};
class ScenePointCloud : public SceneObject {
public:
void Draw();
ObjectType GetType() { return PointCloud; }
void AddPoint(libmv::Vec3 &point, libmv::Vec3f &color);
~ScenePointCloud() {};
private:
std::vector<libmv::Vec3> points_;
std::vector<libmv::Vec3f> colors_;
};
class ViewerCamera {
public:
ViewerCamera();
void SetScreenSize(int width, int height);
void SetUpGlCamera();
void MouseTranslate(float x1, float y1, float x2, float y2);
void MouseRevolve(float x1, float y1, float x2, float y2);
void MouseZoom(float dw);
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
private:
float field_of_view_;
float near_;
float far_;
float screen_width_;
float screen_height_;
libmv::Vec3f revolve_point_;
libmv::Vec3f revolve_point_in_cam_coords_; Eigen::Quaternionf orientation_;
float translation_speed_;
float zoom_speed_;
};
class Viewer3D : public QGLWidget {
Q_OBJECT
public:
Viewer3D(QGLWidget *share, GLTexture *textures, QWidget *parent);
~Viewer3D() {};
QSize minimumSizeHint() const;
QSize sizeHint() const;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
public slots:
void SetDocument(TvrDocument *);
void GLUpdate() { updateGL(); }
void TextureChange();
protected:
void initializeGL();
void paintGL();
void resizeGL(int, int);
void mousePressEvent(QMouseEvent *);
void mouseMoveEvent(QMouseEvent *);
void wheelEvent(QWheelEvent *);
private:
TvrDocument *document_;
GLTexture *textures_;
ScenePointCloud scene_point_cloud_;
SceneCamera scene_cameras_[2];
libmv::scene::Node<SceneObject> scene_graph_;
ViewerCamera viewer_camera_;
QPoint lastPos_;
};
#endif