Eyetribe_Language Tutorials C++

Getting Data

The TET C++ SDK, which is a reference implementation of the TET API in C++, simplifies the connectivity and communication with the server and allows for straightforward data parsing. In this tutorial the use of the SDK’s GazeApi is assumed. To get started first include the main gaze api header to the implementation:

#include <gazeapi.h>

Including the gazeapi.h header is sufficient to work with the C++ SDK as it also includes the gazeapi_types.h and gazeapi_interfaces.h headers. In the constructor of the class we tell the API to connect to the Eye Tracker server in push mode on the default TCP port 6555. The server must be running before we can connect to it. The API automatically sets the version number that is has been released for. The first argument to connect() is bool push_mode, which is set to true. Once the connection has been established we setup a listener for the pushed gaze data. The alternative is to manually fetch gaze data upon request. Objects that wish to automatically receive gaze data should implement the IGazeListener interface. This interface contains the on_gaze_data callback method that will receive the coordinates of the estimated on-screen gaze position, size of the pupils, position relative to the sensor, etc.

Note the Eye Tracker Server must be calibrated before the application can receive any gaze-related details from the GazeData object.

// --- MyGaze definition
class MyGaze : public gtl::IGazeListener
{
    public:
        MyGaze();
        ~MyGaze();
    private:
        // IGazeListener
        void on_gaze_data( gtl::GazeData const & gaze_data );
    private:
        gtl::GazeApi m_api;
};

// --- MyGaze implementation
MyGaze::MyGaze()
{
    // Connect to the server in push mode on the default TCP port (6555)
    if( m_api.connect( true ) )
    {
        // Enable GazeData notifications
        m_api.add_listener( *this );
    }
}

MyGaze::~MyGaze()
{
    m_api.remove_listener( *this );
    m_api.disconnect();
}

void MyGaze::on_gaze_data( gtl::GazeData const & gaze_data )
{
    if( gaze_data.state & gtl::GazeData::GD_STATE_TRACKING_GAZE )
    {
        gtl::Point2D const & smoothedCoordinates = gaze_data.avg;

        // Move GUI point, do hit-testing, log coordinates, etc.
    }
}
Additional points of interest

In the SDK we find the ITrackerStateListener inteface which provides the method on_tracker_connection_changed(int tracker_state) which is called whenever the device has been (re)connected or disconnected. The tracker_state argument can be one of the following anonymous enum values

enum
{
    TRACKER_CONNECTED          = 0,
    TRACKER_NOT_CONNECTED      = 1,
    TRACKER_CONNECTED_BADFW    = 2,
    TRACKER_CONNECTED_NOUSB3   = 3,
    TRACKER_CONNECTED_NOSTREAM = 4
};

State needs to be CONNECTED(0) for the server to work. The NOUSB3(3) means that the device has been connected to a USB2 host.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值