#include "VSensorLaser.h" 
#include <signal.h> 
#include <direct.h> 
#pragma comment(lib, "VSensorLaserSDK.lib")
using namespace std;
using namespace VSENSORLASER;
#define CAMERA_MAXSIZE  (2) //相机连接个数
int main()
{
    //获取相对路径
    char cwd[200];
    if (_getcwd(cwd, 200) == nullptr)
    {
        printf("get path failed\n");
    }
    //实例化设备
    VSensorLaser VSensor[CAMERA_MAXSIZE];
    //多相机
    for (int i = 0; i < CAMERA_MAXSIZE; ++i)
    {
        //获取设备列表
        VSensorLaserCameraInfo cameraList[20];
        int num = 0;
        VSensor[i].GetDeviceList(cameraList, &num);
        for (int j = 0; j < num; ++j)
        {
            printf("device num %d : list[%d] = %s\n", j, j, cameraList[j].CameraName);
        }
        //连接设备
        int status = VSensor[i].DeviceConnect(i);
        if (status != CAMERA_STATUS_SUCCESS)
        {
            printf("connect device failed status = %d\n", status);
            system("pause");
        }
        //设置曝光时间
        status = VSensor[i].SetExposureTime(2.0);
        if (status != CAMERA_STATUS_SUCCESS)
        {
            printf("set exposure time failed, status = %d\n", status);
            system("pause");
        }
        //设置投影等级
        status = VSensor[i].SetProjectLight(1);
        if (status != CAMERA_STATUS_SUCCESS)
        {
            printf("set project light failed, status = %d\n", status);
            system("pause");
        }
        //设置为采集模式
        status = VSensor[i].SetCaptureMode(emVSensorLaserCaptureMode::MODE_SOFT);
        if (status != CAMERA_STATUS_SUCCESS)
        {
            printf("set capture mode failed, status = %d\n", status);
            system("pause");
        }
        //单次采集
        printf("start single capture...\n");
        VSensorLaserResult* pResult = new VSensorLaserResult;
        status = VSensor[i].SingleRestruction(pResult, emVSensorLaserCaptureOutputMode::OUTPUT_MODE_ALL);
        if (status != CAMERA_STATUS_SUCCESS)
        {
            printf("single resturction failed, status = %d\n", status);
            system("pause");
        }
        //保存无序点云为pcd格式
        string str(string(cwd) + "//test" + to_string(i + 1) + ".pcd");
        status = VSensor[i].Save3DCloud(str, pResult, emVSensorLaserPointType::POINT_TYPR_DISORDER);
        if (status != CAMERA_STATUS_SUCCESS)
        {
            printf("save 3D points failed, status = %d\n", status);
            system("pause");
        }
        //反初始化设备
        status = VSensor[i].DeviceUnInit();
        if (status != CAMERA_STATUS_SUCCESS)
        {
            printf("device release failed, status = %d\n", status);
            system("pause");
        }
        delete pResult;
    }
    printf("run success\n");
    system("pause");
    return 0;
}