using System;
using Dll_CSharp_VSensorLaser;
using System.Collections.Generic;
namespace testdll
{
    public class Program
    {
        public static int cameraSize = 2;
        static void Main(string[] args)
        {
            try
            {
                //获取相对路径
                string path = System.IO.Directory.GetCurrentDirectory();
                //实例化设备
                VSensorLaserDLL[] VSensor = new VSensorLaserDLL[cameraSize];
                for (int i = 0; i < cameraSize; i++)
                {
                    VSensor[i] = new VSensorLaserDLL();
                }
                //多相机
                for (int i = 0; i < cameraSize; i++)
                {
                    //获取设备列表
                    int num = 0;
                    List<VSensorLaserCameraInfoCLR> list = new List<VSensorLaserCameraInfoCLR>(20);
                    for (int j = 0; j < 20; j++)
                    {
                        list.Add(new VSensorLaserCameraInfoCLR());
                    }
                    for (int j = 0; j < cameraSize; j++)
                    {
                        VSensor[i].GetDeviceList(ref list, ref num);
                    }
                    for (int j = 0; j < num; j++)
                    {
                        Console.WriteLine("device num {0} : list[{1}] = {2}\n", j, j, list[j].CameraName);
                    }
                    //连接第一台设备
                    int status = VSensor[i].DeviceConnect(i);
                    if (status != 0)
                    {
                        Console.WriteLine("connect device failed, status = {0}\n", status);
                        Console.ReadLine();
                    }
                    //设置曝光时间
                    status = VSensor[i].SetExposureTime(2.0);
                    if (status != 0)
                    {
                        Console.WriteLine("set exposure time failed, status = {0}\n", status);
                        Console.ReadLine();
                    }
                    //设置投影等级
                    status = VSensor[i].SetProjectLight(1);
                    if (status != 0)
                    {
                        Console.WriteLine("set project light failed, status = {0}\n", status);
                        Console.ReadLine();
                    }
                    //设置为采集模式
                    status = VSensor[i].SetCaptureMode(1);
                    if (status != 0)
                    {
                        Console.WriteLine("set capture mode failed, status = {0}\n", status);
                        Console.ReadLine();
                    }
                    //单次采集测试
                    Console.WriteLine("single restruction ...\n");
                    status = VSensor[i].SingleRestruction(0);
                    if (status != 0)
                    {
                        Console.WriteLine("single restruction failed, status = {0}\n", status);
                        Console.ReadLine();
                    }
                    //获取当前相机输出分辨率
                    int width = 0, height = 0;
                    VSensor[i].GetImageResolution(ref width, ref height);
                    VSensorLaserResultCLR result = new VSensorLaserResultCLR(width, height);
                    VSensor[i].GetRestructionResult(ref result);
                    //保存点云为ply格式
                    status = VSensor[i].Save3DCloud(path + @"\test.ply", result, 0);
                    if (status != 0)
                    {
                        Console.WriteLine("save 3D points failed, status = {0}\n", status);
                        Console.ReadLine();
                    }
                    //反初始化设备
                    status = VSensor[i].DeviceUnInit();
                    if (status != 0)
                    {
                        Console.WriteLine("device release failed, status = {0}\n", status);
                        Console.ReadLine();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"ex:{ex}");
            }
            Console.WriteLine("run success");
            Console.ReadLine();
            Console.ReadKey();
        }
    }
}
