using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace LB_SmartVisionCameraSDK.PHM6000
{
///
/// 设置图像大小,用于逐行添加显示数据
///
/// 二维显示控件的句柄
/// 宽度
/// 高度
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void SetImageSize_t(IntPtr pHandle, int nWidth, int nHeight);
///
/// 清除数据,在显示新的图象前调用
///
/// 二维显示控件的句柄
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void ClearAllPoints_t(IntPtr pHandle);
///
/// 刷新显示窗口,此控件在传入数据时并不更新显示,直到调用此函数。
///
/// 二维显示控件的句柄
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void RefreshPilot2D_t(IntPtr pHandle);
///
/// 添加强度数据
///
/// 二维显示控件的句柄
/// 兰宝线扫描传感器输出的数据指针, LBPointZA* points
/// 指定上述数据的指针里的点的数量
/// 函数调用成功返回1,失败返回-1
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate int AddIntensityData_t(IntPtr pHandle, IntPtr points, int nCount);
///
/// 添加深度数据,此函数具有颜色渲染功能
///
/// 二维显示控件的句柄
/// 兰宝线扫描传感器输出的数据指针, LBPointZA* points
/// 指定上述数据的指针里的点的数量
/// 指定深度中的最小值,用于颜色渲染
/// 指定深度中的最大值,用于颜色渲染
/// 函数调用成功返回1,失败返回-1
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate int AddDepthData_t(IntPtr pHandle, IntPtr points, int nCount, short nMinDepth, short nMaxDepth);
///
/// 添加质心数据
///
/// 二维显示控件的句柄
/// 兰宝线扫描传感器输出的数据指针LBPointZA*
/// 指定上述数据的指针里的点的数量
/// 兰宝线扫描传感器检测的最小距离(从说明书获得,取值225.0)
/// 兰宝线扫描传感器检测的最大距离(从说明书获得,取值473.0)
/// 兰宝线扫描传感器检测的标准距离(从说明书获得,取值325.0)
/// 函数调用成功返回1,失败返回-1
///
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate int AddBarycentreDataZA_t(IntPtr pHandle, IntPtr points, int nCount, float fMinDistance, float fMaxDistance, float fStdDistance);
///
/// 清除点云实例增加数据点内部数据点
///
/// PCL显示实例句柄
/// 失败返回0,成功返回1。
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate int ClearPCLPoints_t(IntPtr pInstance);
///
/// 向点云实例增加数据点,失败返回-1,否则返回当前点云中点的个数(不小于0)。
///
/// PCL显示实例句柄
/// 包含深度(Z)和强度(A)信息的点数据
/// 点的数量
/// x分辨率
/// y分辨率
/// 降采样倍数
/// 失败返回-1,否则返回当前点云中点的个数(不小于0)。
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate int AddZAPoints_t(IntPtr pInstance, IntPtr points, int nCount, float fStepX, float fStepY, int nDownSample);
///
/// 渲染点云窗口,无返回
///
/// PCL显示实例句柄
/// 窗口宽度
/// 窗口高度
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void RenderPCLWindow_t(IntPtr pInstance, int nWidth, int nHeight);
///
/// 更新PCL点云数据显示的颜色
///
/// PCL显示实例句柄
/// W,B,r,g,b,x,y,z 对应于白黑红绿蓝和xyz三轴
/// 失败返回0,成功返回1。
[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public delegate int UpdatePCLPointColors_t(IntPtr pInstance, string szColoring);
///
/// 显示正方体坐标系,无返回
///
/// PCL显示实例句柄
/// 是否初始化
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void ShowCubeAxes_t(IntPtr pInstance, int bInit);
///
/// 显示颜色表
///
/// PCL显示实例句柄
/// 显示位置,数值是与窗口宽度的比值
/// 显示位置,数值是与窗口高度的比值
/// 水平宽度,数值是与窗口宽度的比值
/// 垂直宽度,数值是与窗口高度的比值
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void ShowLookUpTable_t(IntPtr pInstance, double x, double y, double xWide, double yWide);
///
/// 获取PCL点云数据的范围
///
/// PCL显示实例句柄
/// 返回最小值
/// 返回最大值
/// 失败返回0,成功返回1。
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate int GetPointCloudBound_t(IntPtr pInstance, ref double pMin, ref double pMax);
///
/// 设置颜色表范围,无返回值
///
/// PCL显示实例句柄
/// 最小值
/// 最大值
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void SetLookUpTableRange_t(IntPtr pInstance, double fMin, double fMax);
///
/// 定义下面的结构是为了向相机接口动态库传递Pilot2D.dll中的同名函数指针
///
[StructLayout(LayoutKind.Sequential)]
public struct PILOT2D_FUNC
{
///
/// 设置图像大小,用于逐行添加显示数据
///
[MarshalAs(UnmanagedType.FunctionPtr)]
public SetImageSize_t SetImageSize;
///
/// 清除数据,在显示新的图象前调用
///
[MarshalAs(UnmanagedType.FunctionPtr)]
public ClearAllPoints_t ClearAllPoints;
///
/// 刷新显示窗口,此控件在传入数据时并不更新显示,直到调用此函数。
///
[MarshalAs(UnmanagedType.FunctionPtr)]
public RefreshPilot2D_t RefreshPilot2D;
///
/// 添加强度数据
///
[MarshalAs(UnmanagedType.FunctionPtr)]
public AddIntensityData_t AddIntensityData;
///
/// 添加深度数据,此函数具有颜色渲染功能
///
[MarshalAs(UnmanagedType.FunctionPtr)]
public AddDepthData_t AddDepthData;
///
/// 添加质心数据
///
[MarshalAs(UnmanagedType.FunctionPtr)]
public AddBarycentreDataZA_t AddBarycentreDataZA;
}
///
/// 对应于PointCloud3D.dll中的同名函数的形式,具体函数功能参见PointCloud3D.dll的调用说明
///
[StructLayout(LayoutKind.Sequential)]
public struct VTK3D_FUNC
{
///
/// 清除点云实例增加数据点内部数据点
///
[MarshalAs(UnmanagedType.FunctionPtr)]
public ClearPCLPoints_t ClearPCLPoints;
///
/// 向点云实例增加数据点,失败返回-1,否则返回当前点云中点的个数(不小于0)。
///
[MarshalAs(UnmanagedType.FunctionPtr)]
public AddZAPoints_t AddZAPoints;
///
/// 渲染点云窗口,无返回
///
[MarshalAs(UnmanagedType.FunctionPtr)]
public RenderPCLWindow_t RenderPCLWindow;
///
/// 更新PCL点云数据显示的颜色
///
[MarshalAs(UnmanagedType.FunctionPtr)]
public UpdatePCLPointColors_t UpdatePCLPointColors;
///
/// 显示正方体坐标系,无返回
///
[MarshalAs(UnmanagedType.FunctionPtr)]
public ShowCubeAxes_t ShowCubeAxes;
///
/// 显示颜色表
///
[MarshalAs(UnmanagedType.FunctionPtr)]
public ShowLookUpTable_t ShowLookUpTable;
///
/// 获取PCL点云数据的范围
///
[MarshalAs(UnmanagedType.FunctionPtr)]
public GetPointCloudBound_t GetPointCloudBound;
///
/// 设置颜色表范围,无返回值
///
[MarshalAs(UnmanagedType.FunctionPtr)]
public SetLookUpTableRange_t SetLookUpTableRange;
}
//typedef void (__stdcall* ShowDebugInfoCallback) (char* szMessage, int nLength);
///
/// 显示调试信息的回调函数格式,无返回值
///
/// 消息字符串
/// 字符串长度
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void ShowDebugInfoCallback(string szMessage, int nLength);
//typedef void (__stdcall* StartMotorCallback) (int direction, int move_steps, double move_speed);
///
/// 启动电机,此回调函数由编写电机驱动者按此格式提供调用。
///
/// 运动方向
/// 移动步数
/// 移动速度
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void StartMotorCallback(int direction, int move_steps, double move_speed);
//typedef void (__stdcall* StopMotorCallback) ();
///
/// 停止电机,此回调函数由编写电机驱动者按此格式提供调用。
///
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void StopMotorCallback();
//typedef void (__stdcall* AcquisitionCallbackZA) (void* pInstance, void* buffer, int points);
///
/// 采集数据的回调函数
///
/// 回调函数提供者的句柄
/// LBPointZA格式的数据缓冲区指针
/// 数据中包含点的数量
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void AcquisitionCallbackZA(IntPtr pInstance, IntPtr buffer, int points);
//typedef void (__stdcall* AcquisitionCompletedCallback) (void* pInstance, int nOption);
///
/// 采集结束的回调函数,可供用户在采集结束后做些处理
///
/// 回调函数提供者的句柄
/// 为0时表示一批数据结束,为1时表时全部采集完成
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void AcquisitionCompletedCallback(IntPtr pInstance, int nOption);
///
/// 相机连接成功回调函数,
///
/// 相机序列号
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void AcquisitionConnectCompletedCallback(string strSN);
///
/// 相机接口类
///
public class PHM6000Profiler
{
//PHM6000_API(void*) CreateCameraEntry();
///
/// 创建照相机接口,
///
/// 返回相机句柄
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "CreateCameraEntry")]
public static extern IntPtr CreateCameraEntry();
//PHM6000_API(void) DestroyCameraEntry(void* pHandle);
///
/// 销毁照相机接口
///
/// 相机接口句柄
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "DestroyCameraEntry")]
public static extern void DestroyCameraEntry(IntPtr pHandle);
//PHM6000_API(int) DiscoverCameras(void* pHandle);
///
/// 查找照相机
///
/// 相机接口句柄
/// 查找失败返回-1,否则返回相机个数。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "DiscoverCameras")]
public static extern int DiscoverCameras(IntPtr pHandle);
//PHM6000_API(int) GetCameraInfo(void* pHandle, int nIndex, LBCameraInfo* pCameraInfo);
///
/// 获取照相机信息
///
/// 相机接口句柄
/// 相机序号
/// 相机信息结构指针, LBCameraInfo* pCameraInfo
/// 获取失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetCameraInfo")]
public static extern int GetCameraInfo(IntPtr pHandle, int nIndex, IntPtr pCameraInfo);
//PHM6000_API(int) GetCameraInformation(void* pHandle, int nIndex, char* szModuleType, char* szSerialNumber);
///
/// 获取照相机信息(方便C#调用增加的)
///
/// 相机接口句柄
/// 相机序号
/// 模块名, char* szModuleType
/// 序列号, char* szSerialNumber
/// 获取失败返回-1,否则返回0。
//[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetCameraInformation")]
//public static extern int GetCameraInformation(IntPtr pHandle, int nIndex, IntPtr szModuleType, IntPtr szSerialNumber);
//PHM6000_API(int) GetCameraInformation(void* pHandle, int nIndex, char* szModuleType, char* szSerialNumber);
///
/// 获取照相机信息
///
/// 开的接口
/// 第几个
/// 型号
/// 序列号
///
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetCameraInformation")]
public static extern int GetCameraInformation(IntPtr pHandle, int nlndex, byte[] szModuleType, byte[] szSerialNumber);
//PHM6000_API(int) GetCameraAddress(void* pHandle, int nIndex, char* szAddress, int* nPort);
///
/// 获取照相机IP信息
///
/// 相机接口句柄
/// 相机序号
/// IP地址字符串, char* szAddress
/// 端口号, int* nPort
/// 获取失败返回-1,否则返回0。
//[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetCameraAddress")]
//public static extern int GetCameraAddress(IntPtr pHandle, int nIndex, IntPtr szAddress, IntPtr nPort);
//PHM6000_API(int) GetCameraAddress(void* pHandle, int nIndex, char* szAddress, int* nPort);
///
/// 得到连接的IP
///
/// 开的接口
/// 第几个
/// 返回的地址
/// 返回的端口
/// 连接失败返回-1,否则返回0
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetCameraAddress")]
public static extern int GetCameraAddress(IntPtr pHandle, int nlndex, byte[] szAddress, ref int nPort);
//PHM6000_API(int) ConnectToCamera(void* pHandle, char* szIpAddress, int nPort);
///
/// 连接照相机
///
/// 相机接口句柄
/// IP地址字符串
/// 端口号
/// 连接失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetCameraAddress")]
public static extern int GetCameraAddress(IntPtr pHandle, string szAddress, int nPort);
//PHM6000_API(int) ConnectToCamera(void* pHandle, char* szIpAddress, int nPort);
///
/// 连接照相机
///
/// 相机接口句柄
/// IP地址字符串
/// 端口号
/// 连接失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "ConnectToCamera")]
public static extern int ConnectToCamera(IntPtr pHandle, IntPtr szAddress, int nPort);
//PHM6000_API(int) ConnectToCamera(void* pHandle, char* szIpAddress, int nPort);
///
/// 连接照相机
///
/// 相机接口句柄
/// IP地址字符串
/// 端口号
/// 连接失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "ConnectToCamera")]
public static extern int ConnectToCamera(IntPtr pHandle, byte[] szAddress, int nPort);
//PHM6000_API(int) DisconnectFromCamera(void* pHandle, char* szIpAddress);
///
/// 断开照相机
///
/// 相机接口句柄
/// 指定要断开的相机的IP地址
/// 断开失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "DisconnectFromCamera")]
public static extern int DisconnectFromCamera(IntPtr pHandle, string szIpAddress);
//PHM6000_API(int) SetAcquisitionCallbackZA(void* pHandle, AcquisitionCallbackZA callbackZA, void* pInstance);
///
/// 设置紧凑的采集回调函数
///
/// 相机接口句柄
/// 回调函数, AcquisitionCallbackZA callbackZA
/// 回调函数提供者的句柄
/// 设置失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "SetAcquisitionCallbackZA")]
public static extern int SetAcquisitionCallbackZA(IntPtr pHandle, AcquisitionCallbackZA callbackZA, IntPtr pInstance);
//PHM6000_API(int) SetAcquisitionCallbackZA(void* pHandle, AcquisitionCallbackZA callbackZA, void* pInstance);
///
/// 设置紧凑的采集回调函数
///
/// 相机接口句柄
/// 回调函数, AcquisitionCallbackZA callbackZA
/// 回调函数提供者的句柄
/// 设置失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "SetAcquisitionCallbackZA")]
public static extern int SetAcquisitionCallbackZA(IntPtr pHandle, IntPtr callbackZA, IntPtr pInstance);
//PHM6000_API(int) SetMotorCallbackFunction(void* pHandle, StartMotorCallback startFunction, StopMotorCallback stopFunction);
///
/// 设置马达回调函数,没有这两个回调函数就不调用此函数来设置回调功能。
///
/// 相机接口句柄
/// 马达启动回调函数
/// 马达停止回调函数
/// 设置失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "SetMotorCallbackFunction")]
public static extern int SetMotorCallbackFunction(IntPtr pHandle, StartMotorCallback startFunction, StopMotorCallback stopFunction);
//PHM6000_API(int) SetAcquisitionMode(void* pHandle, int bScanMode, int bContinuedMode);
///
/// 设置采集模式
///
/// 相机接口句柄
/// 为1时是扫描模式,为0时是轮廓模式
/// 为1时是连接模式,为0时是单次模式
/// 设置失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "SetAcquisitionMode")]
public static extern int SetAcquisitionMode(IntPtr pHandle, int bScanMode, int bContinuedMode);
//PHM6000_API(int) StartAcquisition(void* pHandle, int motor_direction, int move_steps, double move_speed);
///
/// 启动采集
///
/// 相机接口句柄
/// 马达的运动方向,如果没有马达回调函数,置零即可。
/// 马达移动步数,如果没有马达回调函数,置零即可。
/// 马达移动速度,如果没有马达回调函数,置零即可。
/// 启动失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "StartAcquisition")]
public static extern int StartAcquisition(IntPtr pHandle, int motor_direction, int move_steps, double move_speed);
//PHM6000_API(int) StopAcquisition(void* pHandle);
///
/// 停止采集
///
/// 相机接口句柄
/// 停止失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "StopAcquisition")]
public static extern int StopAcquisition(IntPtr pHandle);
//PHM6000_API(int) GetRawImage(void* pHandle, LBPointBGRA** image, int* w, int* h);
///
/// 获取原始图像数据,暂不支持
///
/// 相机接口句柄
/// 图像数据指针, LBPointBGRA** image
/// 图像宽度, int* w
/// 图像高度, int* h
/// 获取失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetRawImage")]
public static extern int GetRawImage(IntPtr pHandle, out IntPtr image, out int w, out int h);
//PHM6000_API(int) GetParameterGroupCount(void* pHandle);
///
/// 获取参数组的个数
///
/// 相机接口句柄
/// 获取失败返回-1,否则返回参数组的数量。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetParameterGroupCount")]
public static extern int GetParameterGroupCount(IntPtr pHandle);
//PHM6000_API(int) GetParameterGroupName(void* pHandle, int group_index, char* groupName);
///
/// 获取全部参数组的名称
///
/// 相机接口句柄
/// 组序号
/// 组名称,UTF-8格式的字符
/// 获取失败返回-1,否则返回名称的长度。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetParameterGroupName")]
public static extern int GetParameterGroupName(IntPtr pHandle, int group_index, byte[] groupName);
//PHM6000_API(int) GetCurrentParameterGroup(void* pHandle, char* groupName);
///
/// 获取当前参数组的名称
///
/// 相机接口句柄
/// 参数名称,UTF-8格式的字符
/// 获取失败返回-1,否则返回名称的长度。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetCurrentParameterGroup")]
public static extern int GetCurrentParameterGroup(IntPtr pHandle, byte[] groupName);
//PHM6000_API(int) SelectParameterGroup(void* pHandle, const char* groupName);
///
/// 选择参数组
///
/// 相机接口句柄
/// 参数组名称
/// 获取失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "SelectParameterGroup")]
public static extern int SelectParameterGroup(IntPtr pHandle, byte[] groupName);
//PHM6000_API(int) AddParameterGroup(void* pHandle, const char* groupName);
///
/// 添加参数组
///
/// 相机接口句柄
/// 参数组名称
/// 获取失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "AddParameterGroup")]
public static extern int AddParameterGroup(IntPtr pHandle, byte[] groupName);
//PHM6000_API(int) DeleteParameterGroup(void* pHandle, const char* groupName);
///
/// 删除参数组
///
/// 相机接口句柄
/// 参数组名称
/// 获取失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "DeleteParameterGroup")]
public static extern int DeleteParameterGroup(IntPtr pHandle, byte[] groupName);
//PHM6000_API(int) RenameParameterGroup(void* pHandle, const char* newName);
///
/// 重命名参数组
///
/// 相机接口句柄
/// 新参数组名称
/// 获取失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "RenameParameterGroup")]
public static extern int RenameParameterGroup(IntPtr pHandle, byte[] newName);
//PHM6000_API(int) LoadParameters(void* pHandle, char* szJSONFileName);
///
/// 加载相机参数
///
/// 相机接口句柄
/// json格式文件名
/// 加载失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "LoadParameters")]
public static extern int LoadParameters(IntPtr pHandle, byte[] szJSONFileName);
//PHM6000_API(int) SaveParameters(void* pHandle, char* szJSONFileName);
///
/// 保存相机参数
///
/// 相机接口句柄
/// json格式文件名
/// 保存失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "SaveParameters")]
public static extern int SaveParameters(IntPtr pHandle, byte[] szJSONFileName);
//PHM6000_API(int) GetProfilerParameter(void* pHandle, int nNameId, int* intValue, double* floatValue, int* enumValue);
///
/// 获取线扫相机参数,每次读取一种参数,参数在相应类型处返回,其它类型位置忽略
///
/// 相机接口句柄
/// 参数名的枚举值
/// 整型值指针
/// 双精度型指针
/// 枚举型指针
/// 获取失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetProfilerParameter")]
public static extern int GetProfilerParameter(IntPtr pHandle, int nNameId, ref int intvalue, ref double floatValue, ref int enumValue);
//PHM6000_API(int) GetProfilerParameter(void* pHandle, int nNameId, int* intValue, double* floatValue, int* enumValue);
///
/// 获取线扫相机参数,每次读取一种参数,参数在相应类型处返回,其它类型位置忽略
///
/// 相机接口句柄
/// 参数名的枚举值
/// 整型值指针
/// 双精度型指针
/// 枚举型指针
/// 获取失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetProfilerParameter")]
public static extern int GetProfilerParameter(IntPtr pHandle, int nNameId, ref int intvalue, IntPtr floatValue, ref int enumValue);
//PHM6000_API(int) SetProfilerParameter(void* pHandle, int nNameId, int intValue, double floatValue, int enumValue);
///
/// 设置线扫相机参数,每次设置一种参数,参数在相应类型处输入,其它类型位置置零
///
/// 相机接口句柄
/// 参数名的枚举值
/// 整型值
/// 双精度型值
/// 枚举型值
/// 设置失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "SetProfilerParameter")]
public static extern int SetProfilerParameter(IntPtr pHandle, int nNameId, int intvalue, double floatValue, int enumValue);
//PHM6000_API(int) GetParameterNameCount(void* pHandle);
///
/// 获取参数名的个数
///
/// 相机接口句柄
/// 获取失败返回-1,否则返回参数名的数量。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetParameterNameCount")]
public static extern int GetParameterNameCount(IntPtr pHandle);
//PHM6000_API(int) GetParameterName(void* pHandle, int param_index, char* paramName);
///
/// 获取全部参数的名称
///
/// 相机接口句柄
/// 参数名序号
/// 参数名称,UTF-8格式的字符
/// 获取失败返回-1,否则返回名称的长度。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetParameterName")]
public static extern int GetParameterName(IntPtr pHandle, int param_index, byte[] paramName);
//PHM6000_API(int) ResetAllParametersToDefault(void* pHandle);
///
/// 将全部参数的值复位成默认值
///
/// 相机接口句柄
/// 获取失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "ResetAllParametersToDefault")]
public static extern int ResetAllParametersToDefault(IntPtr pHandle);
//PHM6000_API(int) SaveAllParametersToDevice(void* pHandle);
///
/// 将全部参数的值保存到设置
///
/// 相机接口句柄
/// 获取失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "SaveAllParametersToDevice")]
public static extern int SaveAllParametersToDevice(IntPtr pHandle);
//PHM6000_API(int) SetOutputGPIO(void* pHandle, GPIOLine LineIndex, int Level);
///
/// 设置GPIO输出
///
/// 相机接口句柄
/// 引脚序号
/// 输出电平,1输出高电平
/// 获取失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "SetOutputGPIO")]
public static extern int SetOutputGPIO(IntPtr pHandle, GPIOLine LineIndex, int Level);
//PHM6000_API(int) RegisterShowDebugInfoCallback(void* pHandle, ShowDebugInfoCallback callback);
///
/// 注册调试信息回调函数,用于调试
///
/// 相机接口句柄
/// 调试用回调函数指针
/// 获取失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "RegisterShowDebugInfoCallback")]
public static extern int RegisterShowDebugInfoCallback(IntPtr pHandle, ShowDebugInfoCallback callback);
//PHM6000_API(int) RegisterAcquisitionCompletedCallback(void* pHandle, AcquisitionCompletedCallback callback, void* pInstance);
///
/// 注册采集完成回调函数
///
/// 相机接口句柄
/// 采集完成回调函数指针
/// 调用者的句柄
/// 获取失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "RegisterAcquisitionCompletedCallback")]
public static extern int RegisterAcquisitionCompletedCallback(IntPtr pHandle, AcquisitionCompletedCallback callback, IntPtr pInstance);
//PHM6000_API(int) LoadDataFromFile(void* pHandle, const char* szFileName);
///
/// 从文件加载数据(后缀名:*.lb3d)
///
/// 相机接口句柄
/// 文件名
/// 获取失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "LoadDataFromFile")]
public static extern int LoadDataFromFile(IntPtr pHandle, byte[] szFileName);
//PHM6000_API(int) SaveDataToFile(void* pHandle, const char* szFileName);
///
/// 向文件保存数据(后缀名:*.lb3d)
///
/// 相机接口句柄
/// 文件名
/// 获取失败返回-1,否则返回0。
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "SaveDataToFile")]
public static extern int SaveDataToFile(IntPtr pHandle, byte[] szFileName);
//PHM6000_API(void) SetShowHandles(void* pHandle, void* pIntensityHandle, void* pDepthHandle, void* pRawHandle, void* pVTK3dHandle, void* pChartHandle = nullptr);
///
/// 设置显示控件的句柄,无返回值
///
/// 相机接口句柄
/// 强度控件句柄
/// 深度控件句柄
/// 原图控件句柄
/// 三维显示控件句柄
/// 图表显控件句柄
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "SetShowHandles")]
public static extern void SetShowHandles(IntPtr pHandle, IntPtr pIntensityHandle, IntPtr pDepthHandle, IntPtr pRawHandle, IntPtr pVTK3dHandle, IntPtr pChartHandle = new IntPtr());
//PHM6000_API(void) SetPilot2dFunc(void* pHandle, PILOT2D_FUNC func);
///
/// 设置二维显示控件所需的功能函数结构体,无返回值
///
/// 相机接口句柄
/// 二维显示控件所需的功能函数结构体
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "SetPilot2dFunc")]
public static extern void SetPilot2dFunc(IntPtr pHandle, PILOT2D_FUNC func);
//PHM6000_API(void) SetVTK3dFunc(void* pHandle, VTK3D_FUNC func);
///
/// 设置三维显示控件所需的功能函数结构体,无返回值
///
/// 相机接口句柄
/// 三维显示控件所需的功能函数结构体
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "SetVTK3dFunc")]
public static extern void SetVTK3dFunc(IntPtr pHandle, VTK3D_FUNC func);
//PHM6000_API(unsigned char*) GetIntensityData(void* pHandle, int& nWidth, int& nHeight);
///
/// 获取强度数据
///
/// 相机接口句柄
/// 回传强度数据的宽度
/// 回传强度数据的高度
/// 返回强度数据的指针,返回值为NULL时表示调用失败,(unsigned char*)
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetIntensityData")]
public static extern IntPtr GetIntensityData(IntPtr pHandle, ref int nWidth, ref int nHeight);
//PHM6000_API(float*) GetDepthData(void* pHandle, int& nWidth, int& nHeight, float* fMinValue = NULL, float* fMaxValue = NULL);
///
/// 获取深度数据
///
/// 相机接口句柄
/// 回传深度数据的宽度
/// 回传深度数据的高度
/// 用于回传深度的最小值, float* fMinValue = NULL
/// 用于回传深度的最大值, float* fMaxValue = NULL
/// 返回深度数据的指针,返回值为NULL时表示调用失败,(float*)
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetDepthData")]
public static extern IntPtr GetDepthData(IntPtr pHandle, ref int nWidth, ref int nHeight, IntPtr fMinValue = new IntPtr(), IntPtr fMaxValue = new IntPtr());
//PHM6000_API(float*) GetDepthDataInRectangle(void* pHandle, int nLeft, int nTop, int& nWidth, int& nHeight);
///
/// 获取矩形兴趣区内的深度数据
///
/// 相机接口句柄
/// 矩形左上角的x坐标
/// 矩形左上角的y坐标
/// 矩形兴趣区的宽度
/// 矩形兴趣区的高度
/// 返回深度数据的指针,返回值为NULL时表示调用失败,(float*)
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetDepthDataInRectangle")]
public static extern IntPtr GetDepthDataInRectangle(IntPtr pHandle, int nLeft, int nTop, ref int nWidth, ref int nHeight);
//PHM6000_API(float*) GetDepthDataInCircle(void* pHandle, int& nWidth, int& nHeight, int nXPos, int nYPos, int nRadius);
///
/// 获取圆形兴趣区内的深度数据
///
/// 相机接口句柄
/// 回传深度数据的宽度
/// 回传深度数据的高度
/// 圆形中心的x坐标
/// 圆形中心的y坐标
/// 圆形的半径
/// 返回深度数据的指针,返回值为NULL时表示调用失败,(float*)
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetDepthDataInCircle")]
public static extern IntPtr GetDepthDataInCircle(IntPtr pHandle, ref int nWidth, ref int nHeight, int nXPos, int nYPos, int nRadius);
//PHM6000_API(float*) GetDepthDataInAnnulus(void* pHandle, int& nWidth, int& nHeight, int nXPos, int nYPos, int nRadius, float fRadiusRatio);
///
/// 获取环形兴趣区内的深度数据
///
/// 相机接口句柄
/// 回传深度数据的宽度
/// 回传深度数据的高度
/// 环形中心的x坐标
/// 环形中心的y坐标
/// 环形的半径
/// 环形的内外半径比,大于1时内外颠倒
/// 返回深度数据的指针,返回值为NULL时表示调用失败,(float*)
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetDepthDataInAnnulus")]
public static extern IntPtr GetDepthDataInAnnulus(IntPtr pHandle, ref int nWidth, ref int nHeight, int nXPos, int nYPos, int nRadius, float fRadiusRatio);
//PHM6000_API(float*) GetDepthDataInPolygon(void* pHandle, int& nWidth, int& nHeight, void* points, int nCount);
///
/// 获取多边形兴趣区内的深度数据
///
/// 相机接口句柄
/// 回传深度数据的宽度
/// 回传深度数据的高度
/// 多边形顶点坐标数组的指针
/// 多边形顶点的数量
/// 返回深度数据的指针,返回值为NULL时表示调用失败,(float*)
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetDepthDataInPolygon")]
public static extern IntPtr GetDepthDataInPolygon(IntPtr pHandle, ref int nWidth, ref int nHeight, IntPtr points, int nCount);
//PHM6000_API(int) InsertionSort(void* pHandle, float* pData, int nWidth, int nHeight);
///
/// 从大到小排序函数并具有无效深度的过滤功能
///
/// 相机接口句柄
/// 从兴趣区获得的深度数据指针, float* pData
/// 从兴趣区获得的深度数据的宽度
/// 从兴趣区获得的深度数据的高度
/// 返回剔除无效数据后的深度数据个数,返回值为-1时表示调用失败
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "InsertionSort")]
public static extern int InsertionSort(IntPtr pHandle, IntPtr pData, int nWidth, int nHeight);
//PHM6000_API(int) GetEncoderValueRange(void* pHandle, int nBeginLine, int nEndLine, unsigned long* nBeginValue, unsigned long* nEndValue);
///
/// 获取编码器的值
///
/// 相机接口句柄
/// 开始行的序号
/// 结束行的序号
/// 用于返回开始行的编码器值, unsigned long* nBeginValue
/// 用于返回结束行的编码器值, unsigned long* nEndValue
/// 返回值为-1时表示调用失败
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetEncoderValueRange")]
public static extern int GetEncoderValueRange(IntPtr pHandle, int nBeginLine, int nEndLine, out uint nBeginValue, out uint nEndValue);
//PHM6000_API(LBLineDataZA*) GetLineDataByEncoder(void* pHandle, unsigned long nEncoderValue);
///
/// 获取编码器值指向的数据
///
/// 相机接口句柄
/// 编码器的值
/// 返回值为NULL时表示调用失败,(LBLineDataZA*)
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetLineDataByEncoder")]
public static extern IntPtr GetLineDataByEncoder(IntPtr pHandle, uint nEncoderValue);
//PHM6000_API(LBLineDataZA*) GetLineDataByIndex(void* pHandle, unsigned long nIndex);
///
/// 通过编码器值获取数据
///
/// 相机接口句柄
/// 数据的行序号
/// 返回值为NULL时表示获取数据失败,(LBLineDataZA*)
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetLineDataByIndex")]
public static extern IntPtr GetLineDataByIndex(IntPtr pHandle, uint nIndex);
//PHM6000_API(LBLineDataZA*) GetLineDataByIndex(void* pHandle, unsigned long nIndex);
///
/// 通过编码器值获取数据
///
/// 相机接口句柄
/// 数据的行序号
/// 返回值为NULL时表示获取数据失败,(LBLineDataZA*)
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetLineDataByIndex")]
public static extern IntPtr GetLineDataByIndex(IntPtr pHandle, ulong nIndex);
//PHM6000_API(void) SetTransformParameter(void* pHandle, float fAngle, int xOffset, int yOffset, int hMirror, int vMirror, int KeepImageSize = 0);
///
/// 设置转换参数,用于获取转换后兴趣区内的数据
///
/// 相机接口句柄
/// 旋转角度
/// x向平移量
/// y向平移量
/// 为1时水平镜像,为0时不变
/// 为1时垂直镜像,为0时不变
/// 图像大小是否保持
[DllImport("PHM6000API", CallingConvention = CallingConvention.StdCall, EntryPoint = "SetTransformParameter")]
public static extern void SetTransformParameter(IntPtr pHandle, float fAngle, int xOffset, int yOffset, int hMirror, int vMirror, int KeepImageSize = 0);
#region PointCloud3D Functions
[DllImport("PointCloud3D", CallingConvention = CallingConvention.StdCall, EntryPoint = "AddZAPoints")]
public static extern int AddZAPoints(IntPtr pInstance, IntPtr points, int nCount, float fStepX, float fStepY, int nDownSample);
[DllImport("PointCloud3D", CallingConvention = CallingConvention.StdCall, EntryPoint = "ClearPCLPoints")]
public static extern int ClearPCLPoints(IntPtr pInstance);
[DllImport("PointCloud3D", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetPointCloudBound")]
public static extern int GetPointCloudBound(IntPtr pInstance, ref double pMin, ref double pMax);
[DllImport("PointCloud3D", CallingConvention = CallingConvention.StdCall, EntryPoint = "RenderPCLWindow")]
public static extern void RenderPCLWindow(IntPtr pInstance, int nWidth, int nHeight);
[DllImport("PointCloud3D", CallingConvention = CallingConvention.StdCall, EntryPoint = "SetLookUpTableRange")]
public static extern void SetLookUpTableRange(IntPtr pInstance, double fMin, double fMax);
[DllImport("PointCloud3D", CallingConvention = CallingConvention.StdCall, EntryPoint = "ShowCubeAxes")]
public static extern void ShowCubeAxes(IntPtr pInstance, int bInit);
[DllImport("PointCloud3D", CallingConvention = CallingConvention.StdCall, EntryPoint = "ShowLookUpTable")]
public static extern void ShowLookUpTable(IntPtr pInstance, double x, double y, double xWide, double yWide);
[DllImport("PointCloud3D", CallingConvention = CallingConvention.StdCall, EntryPoint = "UpdatePCLPointColors")]
public static extern int UpdatePCLPointColors(IntPtr pInstance, string szColoring);
#endregion
///
/// 将结构体指针转换为double(模拟C++的(double)(int64)&操作)
///
/// IntPtr structurePtr
/// double
public static double StructurePtrToDouble(IntPtr structurePtr)
{
// 将指针转换为long,然后转换为double
long ptrValue = structurePtr.ToInt64();
return (double)ptrValue;
}
///
/// 将结构体转换为IntPtr并返回对应的double值
///
/// T
/// T structure
/// double
public static double StructureToDoublePtr(ref T structure)
{
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(T)));
Marshal.StructureToPtr(structure, ptr, false);
long ptrValue = ptr.ToInt64();
return (double)ptrValue;
}
///
/// 从double值恢复为指针并读取结构体
///
/// T
/// double doublePtr
/// T
public static T DoublePtrToStructure(double doublePtr)
{
long ptrValue = (long)doublePtr;
IntPtr ptr = new IntPtr(ptrValue);
return (T)Marshal.PtrToStructure(ptr, typeof(T));
}
///
/// 释放由StructureToDoublePtr分配的内存
///
/// double doublePtr
public static void FreeDoublePtr(double doublePtr)
{
long ptrValue = (long)doublePtr;
IntPtr ptr = new IntPtr(ptrValue);
Marshal.FreeHGlobal(ptr);
}
///
/// IntPtr To LBLineDataZA
///
/// IntPtr ptr
/// LBLineDataZA
public static LBLineDataZA ConvertToLBLineDataZA(IntPtr ptr)
{
// 首先读取info
LBLineHeadInfo info = Marshal.PtrToStructure(ptr);
// 计算数组开始的指针:ptr偏移info的大小
IntPtr arrayPtr = ptr + Marshal.SizeOf();
UInt32 pointCount = info.nPointCount;
LBPointZA[] points = new LBPointZA[pointCount];
int sizeOfPoint = Marshal.SizeOf();
for (int i = 0; i < pointCount; i++)
{
points[i] = Marshal.PtrToStructure(arrayPtr + i * sizeOfPoint);
}
//Marshal.FreeHGlobal(arrayPtr);
return new LBLineDataZA { info = info, data = points };
}
}
}