Beispiel #1
0
        public static void ConvertDataToKdata(SurfaceZSaveDat ssd, string SaveKdatDirectoy, string Side)
        {
            PointMsg   pmoffset = ssd.offset;
            PointMsg   pmscale  = ssd.resolution;;
            Point3d64f poffset  = new Point3d64f()
            {
                x = pmoffset.x, y = pmoffset.y, z = pmoffset.z
            };
            Point3d64f pscale = new Point3d64f()
            {
                x = pmscale.x, y = pmscale.y, z = pmscale.z
            };
            int    size       = Marshal.SizeOf(typeof(short));
            IntPtr surfacePtr = Marshal.AllocHGlobal(size * ssd.points.Length);

            Marshal.Copy(ssd.points, 0, surfacePtr, ssd.points.Length);
            GoSurface insurface = new GoSurface()
            {
                data = surfacePtr, width = (int)ssd.width, height = (int)ssd.height, offset = poffset, scale = pscale
            };

            GoSaveSurfaceGraphic.SaveSufaceToFile($"{SaveKdatDirectoy}{Side}.kdat", ref insurface, false);
            Marshal.FreeHGlobal(surfacePtr);
        }
Beispiel #2
0
        private int OnData(DataContext ctx, IntPtr sys, IntPtr data)
        {
            if (!SecretKey.License.SnOk)
            {
                string errMsg  = "";
                string warnMsg = "传感器试用权限已到期,传感器将停止接收数据,如有疑问请联系:" + tel;
                if (DisConnect(ref errMsg))
                {
                    warnMsg += " !";
                }
                MessageBox.Show(warnMsg);
                return(0);
            }

            if (!IsOnline)
            {
                GoSdkWrapper.GoDestroy(data);
                //GC.Collect();
                return(1);
            }

            IntPtr dataObj = IntPtr.Zero;

            IntPtr  StampMsg = IntPtr.Zero;
            IntPtr  StampPtr = IntPtr.Zero;
            GoStamp stamp    = new GoStamp();

            IntPtr  ProfileMsgZ = IntPtr.Zero;
            Profile mProfile    = new Profile();

            IntPtr ProfileMsgIntensity = IntPtr.Zero;

            IntPtr SurfaceMsgZ         = IntPtr.Zero;
            IntPtr SurfaceMsgIntensity = IntPtr.Zero;

            IntPtr          MeasurementMsg  = IntPtr.Zero;
            MeasurementData measurementData = new MeasurementData();
            bool            isRecSurfaceZOK = false;

            for (uint i = 0; i < GoSdkWrapper.GoDataSet_Count(data); i++)
            {
                dataObj = GoSdkWrapper.GoDataSet_At(data, i);
                switch (GoSdkWrapper.GoDataMsg_Type(dataObj))
                {
                case GoDataMessageTypes.GO_DATA_MESSAGE_TYPE_STAMP:
                    StampMsg = dataObj;
                    StampPtr = GoSdkWrapper.GoStampMsg_At(StampMsg, 0);

                    stamp = (GoStamp)Marshal.PtrToStructure(StampPtr, typeof(GoStamp));
                    //if (stamp.encoder == 0)
                    //{
                    //    stamp.encoder = 0;
                    //}
                    Stamp            = stamp;
                    mProfile.encoder = stamp.encoder;

                    break;

                case GoDataMessageTypes.GO_DATA_MESSAGE_TYPE_SURFACE:

                    SurfaceMsgZ     = dataObj;
                    ctx.xResolution = (double)GoSdkWrapper.GoSurfaceMsg_XResolution(SurfaceMsgZ) / 1000000;
                    ctx.zResolution = (double)GoSdkWrapper.GoSurfaceMsg_ZResolution(SurfaceMsgZ) / 1000000;
                    ctx.yResolution = (double)GoSdkWrapper.GoSurfaceMsg_YResolution(SurfaceMsgZ) / 1000000;
                    ctx.xOffset     = (double)GoSdkWrapper.GoSurfaceMsg_XOffset(SurfaceMsgZ) / 1000;
                    ctx.yOffset     = (double)GoSdkWrapper.GoSurfaceMsg_YOffset(SurfaceMsgZ) / 1000;
                    ctx.zOffset     = (double)GoSdkWrapper.GoSurfaceMsg_ZOffset(SurfaceMsgZ) / 1000;

                    uint    surfaceWidth     = GoSdkWrapper.GoSurfaceMsg_Width(SurfaceMsgZ);
                    uint    surfaceHeight    = GoSdkWrapper.GoSurfaceMsg_Length(SurfaceMsgZ);
                    IntPtr  surfacePtr       = GoSdkWrapper.GoSurfaceMsg_RowAt(SurfaceMsgZ, 0);
                    short[] surfacePoints    = new short[surfaceWidth * surfaceHeight];
                    float[] surfaceData      = new float[surfaceWidth * surfaceHeight];
                    float[] surfaceDataX     = new float[surfaceWidth * surfaceHeight];
                    float[] surfaceDataY     = new float[surfaceWidth * surfaceHeight];
                    byte[]  surfaceDataZByte = new byte[surfaceWidth * surfaceHeight];

                    //保存Kdat
                    Stopwatch sp = new Stopwatch();
                    sp.Start();

                    //if (surfacePoints.Length==0)
                    //{
                    //    break;
                    //}
                    try
                    {
                        Marshal.Copy(surfacePtr, surfacePoints, 0, surfacePoints.Length);
                    }
                    catch (Exception)
                    {
                        return(1);
                    }


                    //保存dat
                    //if (SaveDatFileDirectory != null && !string.IsNullOrEmpty(SaveDatFileDirectory))
                    //{
                    //    PointMsg pmoffset = new PointMsg() { x = ctx.xOffset, y = ctx.yOffset, z = ctx.zOffset };
                    //    PointMsg pmscale = new PointMsg() { x = ctx.xResolution, y = ctx.yResolution, z = ctx.zResolution };
                    //    SurfaceZSaveDat ssd = new SurfaceZSaveDat() { points = surfacePoints, resolution = pmscale, offset = pmoffset,width = (int)surfaceWidth,height = (int)surfaceHeight };
                    //    StaticTool.WriteSerializable($"{SaveDatFileDirectory}Side{RunSide}_H.dat", ssd);
                    //}

                    PointMsg pmoffset = new PointMsg()
                    {
                        x = ctx.xOffset, y = ctx.yOffset, z = ctx.zOffset
                    };
                    PointMsg pmscale = new PointMsg()
                    {
                        x = ctx.xResolution, y = ctx.yResolution, z = ctx.zResolution
                    };
                    SurfaceZSaveDat ssd = new SurfaceZSaveDat()
                    {
                        points = surfacePoints, resolution = pmscale, offset = pmoffset, width = (int)surfaceWidth, height = (int)surfaceHeight
                    };
                    if (!isRecSurfaceZOK)
                    {
                        if (SaveDatFileDirectory != null && !string.IsNullOrEmpty(SaveDatFileDirectory))
                        {
                            StaticTool.WriteSerializable($"{SaveDatFileDirectory}Side{RunSide}_L_H.dat", ssd);
                        }
                        sddList_L.Add(ssd);
                        if (SaveKdatDirectoy != null && !string.IsNullOrEmpty(SaveKdatDirectoy) && RunSide != null)
                        {
                            Point3d64f poffset = new Point3d64f()
                            {
                                x = ctx.xOffset, y = ctx.yOffset, z = ctx.zOffset
                            };
                            Point3d64f pscale = new Point3d64f()
                            {
                                x = ctx.xResolution, y = ctx.yResolution, z = ctx.zResolution
                            };
                            GoSurface insurface = new GoSurface()
                            {
                                data = surfacePtr, width = (int)surfaceWidth, height = (int)surfaceHeight, offset = poffset, scale = pscale
                            };
                            GoSaveSurfaceGraphic.SaveSufaceToFile($"{SaveKdatDirectoy}{DateTime.Now.ToString("yyyyMMdd_HHmmss")}_Side{RunSide}_L.kdat", ref insurface, false);
                        }
                    }
                    else
                    {
                        //保存dat
                        if (SaveDatFileDirectory != null && !string.IsNullOrEmpty(SaveDatFileDirectory))
                        {
                            //PointMsg pmoffset = new PointMsg() { x = ctx.xOffset, y = ctx.yOffset, z = ctx.zOffset };
                            //PointMsg pmscale = new PointMsg() { x = ctx.xResolution, y = ctx.yResolution, z = ctx.zResolution };
                            //SurfaceZSaveDat ssd = new SurfaceZSaveDat() { points = surfacePoints, resolution = pmscale, offset = pmoffset, width = (int)surfaceWidth, height = (int)surfaceHeight };
                            StaticTool.WriteSerializable($"{SaveDatFileDirectory}Side{RunSide}_S_H.dat", ssd);
                        }
                        sddList_S.Add(ssd);
                        if (SaveKdatDirectoy != null && !string.IsNullOrEmpty(SaveKdatDirectoy) && RunSide != null)
                        {
                            Point3d64f poffset = new Point3d64f()
                            {
                                x = ctx.xOffset, y = ctx.yOffset, z = ctx.zOffset
                            };
                            Point3d64f pscale = new Point3d64f()
                            {
                                x = ctx.xResolution, y = ctx.yResolution, z = ctx.zResolution
                            };
                            GoSurface insurface = new GoSurface()
                            {
                                data = surfacePtr, width = (int)surfaceWidth, height = (int)surfaceHeight, offset = poffset, scale = pscale
                            };
                            GoSaveSurfaceGraphic.SaveSufaceToFile($"{SaveKdatDirectoy}{DateTime.Now.ToString("yyyyMMdd_HHmmss")}_Side{RunSide}_S.kdat", ref insurface, false);
                        }
                    }
                    sp.Stop();
                    long b = sp.ElapsedMilliseconds;
                    sp.Start();

                    for (int j = 0; j < surfaceHeight; j++)
                    {
                        for (int k = 0; k < surfaceWidth; k++)
                        {
                            surfaceData[j * surfaceWidth + k]  = surfacePoints[j * surfaceWidth + k] == -32768 ? -12 : (float)(ctx.zOffset + ctx.zResolution * surfacePoints[j * surfaceWidth + k]);
                            surfaceDataX[j * surfaceWidth + k] = (float)(ctx.xOffset + ctx.xResolution * k);
                            surfaceDataY[j * surfaceWidth + k] = (float)(ctx.yOffset + ctx.yResolution * j);
                            if (IsRecSurfaceDataZByte && (!isRecSurfaceZOK))
                            {
                                if (surfacePoints[j * surfaceWidth + k] != -32768)
                                {
                                    surfaceDataZByte[j * surfaceWidth + k] = (byte)Math.Ceiling(((ctx.zOffset + ctx.zResolution * surfacePoints[j * surfaceWidth + k]) - zStart) * z_byte_resolution);
                                }
                                else
                                {
                                    surfaceDataZByte[j * surfaceWidth + k] = 0;
                                }
                            }
                        }
                    }
                    sp.Stop();
                    long a = sp.ElapsedMilliseconds;
                    if (!isRecSurfaceZOK)
                    {
                        this.SurfaceWidth     = surfaceWidth;
                        this.SurfaceHeight    = surfaceHeight;
                        this.SurfaceDataZ     = surfaceData;
                        this.SurfaceDataZByte = surfaceDataZByte;
                        this.surfaceDataX     = surfaceDataX;
                        this.surfaceDataY     = surfaceDataY;
                        isRecSurfaceZOK       = true;
                    }
                    else
                    {
                        this.SurfaceAlignData   = surfaceData;
                        this.SurfaceAlignWidth  = surfaceWidth;
                        this.SurfaceAlignHeight = surfaceHeight;
                    }


                    break;

                case GoDataMessageTypes.GO_DATA_MESSAGE_TYPE_SURFACE_INTENSITY:
                    SurfaceMsgIntensity = dataObj;
                    IntPtr intensityPtr = GoSdkWrapper.GoSurfaceIntensityMsg_RowAt(SurfaceMsgIntensity, 0);
                    surfaceWidth  = GoSdkWrapper.GoSurfaceIntensityMsg_Width(SurfaceMsgIntensity);
                    surfaceHeight = GoSdkWrapper.GoSurfaceIntensityMsg_Length(SurfaceMsgIntensity);
                    byte[] intensityArr = new byte[surfaceWidth * surfaceHeight];
                    Marshal.Copy(intensityPtr, intensityArr, 0, intensityArr.Length);
                    SurfaceDataIntensity = intensityArr;
                    SurfaceIntensitySaveDat sid = new SurfaceIntensitySaveDat()
                    {
                        points = intensityArr, width = (int)surfaceWidth, height = (int)surfaceHeight
                    };
                    if (SaveDatFileDirectory != null && !string.IsNullOrEmpty(SaveDatFileDirectory))
                    {
                        StaticTool.WriteSerializable($"{SaveDatFileDirectory}Side{RunSide}_I.dat", sid);
                    }
                    sddList_I.Add(sid);
                    break;

                case GoDataMessageTypes.GO_DATA_MESSAGE_TYPE_RESAMPLED_PROFILE:
                    if (!EnableProfle)
                    {
                        break;
                    }
                    ProfileMsgZ     = dataObj;
                    ctx.xResolution = ((double)GoSdkWrapper.GoProfileMsg_XResolution(ProfileMsgZ)) / 1000000;
                    ctx.zResolution = ((double)GoSdkWrapper.GoProfileMsg_ZResolution(ProfileMsgZ)) / 1000000;
                    ctx.xOffset     = ((double)GoSdkWrapper.GoProfileMsg_XOffset(ProfileMsgZ)) / 1000;
                    ctx.zOffset     = ((double)GoSdkWrapper.GoProfileMsg_ZOffset(ProfileMsgZ)) / 1000;
                    profileWidth    = GoSdkWrapper.GoProfileMsg_Width(ProfileMsgZ);

                    IntPtr  pointPtr = GoSdkWrapper.GoResampledProfileMsg_At(ProfileMsgZ, 0);
                    short[] points   = new short[profileWidth];
                    Marshal.Copy(pointPtr, points, 0, points.Length);
                    ProfilePoint[] profile = new ProfilePoint[profileWidth];
                    for (int j = 0; j < points.Length; j++)
                    {
                        profile[j].x = (float)(ctx.xOffset + ctx.xResolution * j);
                        profile[j].z = points[j] == -32768 ? -12 : (float)(ctx.zOffset + ctx.zResolution * points[j]);
                    }
                    mProfile.points = profile;
                    isRecProfileZ   = true;
                    break;

                case GoDataMessageTypes.GO_DATA_MESSAGE_TYPE_PROFILE_INTENSITY:
                    if (isRecProfileZ)
                    {
                        ProfileMsgIntensity = dataObj;
                        profileWidth        = GoSdkWrapper.GoProfileIntensityMsg_Width(ProfileMsgIntensity);
                        IntPtr profileIntensityPtr = GoSdkWrapper.GoProfileIntensityMsg_At(ProfileMsgIntensity, 0);
                        byte[] profileIntensityArr = new byte[profileWidth];
                        Marshal.Copy(profileIntensityPtr, profileIntensityArr, 0, profileIntensityArr.Length);
                        for (int j = 0; j < profileIntensityArr.Length; j++)
                        {
                            mProfile.points[j].Intensity = profileIntensityArr[j];
                        }
                    }
                    break;

                case GoDataMessageTypes.GO_DATA_MESSAGE_TYPE_MEASUREMENT:
                    MeasurementMsg = dataObj;
                    IntPtr            measurementPtr = GoSdkWrapper.GoMeasurementMsg_At(MeasurementMsg, 0);
                    GoMeasurementData mData          = (GoMeasurementData)Marshal.PtrToStructure(measurementPtr, typeof(GoMeasurementData));
                    measurementData.id    = GoSdkWrapper.GoMeasurementMsg_Id(MeasurementMsg);
                    measurementData.value = mData.Value;
                    measurementDataList.Add(measurementData);
                    break;

                default:
                    break;
                }
            }
            if (isRecProfileZ)
            {
                profileDataZ.Add(mProfile);
                this.SigleProfile = mProfile;
                isRecProfileZ     = false;
            }
            GoSdkWrapper.GoDestroy(data);
            //GC.Collect();
            return(1);
        }
Beispiel #3
0
 public static extern int SaveSufaceToFile(string filepath, ref GoSurface insurface, bool flag);