//
// Created by zx on 22-12-2.
//

#ifndef LIO_LIVOX_CPP__PANGOLINVIEWER_H_
#define LIO_LIVOX_CPP__PANGOLINVIEWER_H_

#include <pangolin/var/var.h>
#include <pangolin/var/varextra.h>
#include <pangolin/gl/gl.h>
#include <pangolin/gl/gldraw.h>
#include <pangolin/display/display.h>
#include <pangolin/display/view.h>
#include <pangolin/display/widgets.h>
#include <pangolin/display/default_font.h>
#include <pangolin/handler/handler.h>
#include <thread>
#include "dijkstra/dijkstra.h"
#include "dijkstra/trajectory.h"
#include "define/typedef.h"

class PangolinViewer
{
 public:
    typedef void(*ViewerSpinOnceCallback)(PangolinViewer*);
    typedef void(*StartLocateBtnCallback)(std::string);
    typedef void(*StartBtnCallback)();
    typedef void(*PauseBtnCallback)();
    typedef void(*StopBtnCallback)();
    typedef void(*AutoTestBtnCallback)();
    typedef void(*FreqChangedCallback)(int);
    typedef bool(*DijkstraBtnCallback)(int ,int ,float& ,std::vector<int>&);
 public:
    static PangolinViewer* CreateViewer();

    void SetCallbacks(ViewerSpinOnceCallback spinOnce,DijkstraBtnCallback dijkstra);

    void SetNavigationCallbacks(StartBtnCallback startBtn,
                                PauseBtnCallback pauseBtn,
                      StopBtnCallback stopBtn);
    void SetAutoTestNavCallback(AutoTestBtnCallback callback);
    void ShowRealtimeStatu(Eigen::Matrix4d pose,double velocity,double angular);
    void ShowBrotherStatu(Eigen::Matrix4d pose,double velocity,double angular);

    void ResetPathInfo(int beg,int end,float distance);

    void DrawCloud(PointCloud::Ptr cloud,double r,double g,double b,
     double alpha,double psize);
    void DrawDijkastraMap(PathMap& map,std::vector<int> path);
    void DrawTrajectory(const Trajectory& traj,double r,double g,double b,double ptsize);
    void Join();
    ~PangolinViewer();

 private:
    static void loop(PangolinViewer* p);
    PangolinViewer();

    void Init();

 protected:
    static PangolinViewer* viewer_;
    std::thread* thread_;


    pangolin::GlFont *text_font_ ;
    pangolin::OpenGlRenderState* s_cam_;
    pangolin::View *d_cam_ ;

    pangolin::Var<bool>* lvx_checkbox_;
    pangolin::Var<std::string>* lvx_file_;

    /*pangolin::Var<bool>* start_button_;
    pangolin::Var<bool>* stop_button_;
    pangolin::Var<double>* freq_double_;*/

    pangolin::Var<std::string>* timequeue_string_;
    pangolin::Var<std::string>* xyz_string_;
    pangolin::Var<std::string>* rpy_string_;
    pangolin::Var<std::string>* velocity_string_;

    pangolin::Var<int>* beg_Int_;
    pangolin::Var<int>* end_Int_;

    pangolin::Var<double>* v_;
    pangolin::Var<double>* a_;

    pangolin::Var<std::string>* path_string_;
    pangolin::Var<std::string>* distance_string_;

    std::vector<int> shortest_path_;

    ViewerSpinOnceCallback spinOnce_callback_=nullptr;
    DijkstraBtnCallback dijkstraBtn_callback_= nullptr;

    StartBtnCallback naviagtion_startBtn_callback_=nullptr;
    PauseBtnCallback naviagtion_pauseBtn_callback_=nullptr;
    StopBtnCallback navigation_stopBtn_callback_= nullptr;
    AutoTestBtnCallback navigation_AutoBtn_callback_= nullptr;

};


#endif //LIO_LIVOX_CPP__PANGOLINVIEWER_H_
