From 81480d62561dcb75a1fc968814ace1368fe5181b Mon Sep 17 00:00:00 2001 From: wells.liu <wells.liu@broconcentric.com> Date: 星期四, 16 七月 2020 11:57:08 +0800 Subject: [PATCH] Merge branch 'master' of http://gitblit.broconcentric.com:8088/r/M071 --- src/Bro.Device.Gocator/GocatorDriver.cs | 94 ++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 88 insertions(+), 6 deletions(-) diff --git a/src/Bro.Device.Gocator/GocatorDriver.cs b/src/Bro.Device.Gocator/GocatorDriver.cs index 39fb4a2..ae21a3f 100644 --- a/src/Bro.Device.Gocator/GocatorDriver.cs +++ b/src/Bro.Device.Gocator/GocatorDriver.cs @@ -1,11 +1,13 @@ 锘縰sing Bro.Common.Base; using Bro.Common.Helper; using Bro.Common.Interface; +using Bro.Common.Model; using HalconDotNet; using Lmi3d.GoSdk; using Lmi3d.GoSdk.Messages; using Lmi3d.Zen; using Lmi3d.Zen.Io; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Drawing; @@ -86,18 +88,98 @@ long bufferSize = width * height; IntPtr bufferPointer = surfaceMsg.Data; + float zoomFactor = (float)((double)surfaceMsg.YResolution / (double)surfaceMsg.XResolution); + int zoomHeight = (int)(zoomFactor * height); + IntPtr zoomPtr = Marshal.AllocHGlobal(zoomHeight * (int)width * 2); + + //娌℃湁鎻掑�硷紝榛樿0 + //Parallel.For(0, height, h => + // { + // CopyMemory((IntPtr)((long)zoomPtr + width * 2 * Math.Floor(h * zoomFactor)), (IntPtr)((long)bufferPointer + width * 2 * h), width * 2); + // }); + + //浣跨敤涓婁竴琛屽師鏈夋暟鎹� + Parallel.For(0, zoomHeight, h => + { + int originHeightIndex = (int)Math.Floor((double)height * h / (double)zoomHeight); + + CopyMemory((IntPtr)((long)zoomPtr + width * 2 * h), (IntPtr)((long)bufferPointer + width * 2 * originHeightIndex), width * 2); + }); + if (imgSet != null) { imgSet.HImage = new HImage(); - imgSet.HImage.GenImage1("uint2", (int)width, (int)height, bufferPointer); + imgSet.HImage.GenImage1("uint2", (int)width, zoomHeight, zoomPtr); imgSet.HImage_2 = new HImage(); - imgSet.HImage_2.GenImage1("uint2", (int)width, (int)height, bufferPointer); + imgSet.HImage_2.GenImage1("uint2", (int)width, zoomHeight, zoomPtr); + + LaserScanParam para = new LaserScanParam() + { + Resolution_X = surfaceMsg.XResolution, + Resolution_Y = surfaceMsg.YResolution, + Resolution_Z = surfaceMsg.ZResolution, + Offset_X = surfaceMsg.XOffset, + Offset_Y = surfaceMsg.YOffset, + Offset_Z = surfaceMsg.ZOffset, + Angle_Z = surfaceMsg.ZAngle, + }; + imgSet.ImageData = JsonConvert.SerializeObject(para); + + //imgSet.HImage_2 = imgSet.HImage_2.ZoomImageSize((int)width, zoomHeight, "constant"); } - Generate16GrayImageByPointer((int)width, (int)height, bufferPointer, imgSet?.Id); + Generate16GrayImageByPointer((int)width, zoomHeight, zoomPtr, imgSet?.Id).ContinueWith(t => + { + Marshal.FreeHGlobal(zoomPtr); + }); + + //int zoomHeight = (int)(((double)surfaceMsg.YResolution / (double)surfaceMsg.XResolution) * (double)surfaceMsg.Length); + + //if (imgSet != null) + //{ + // imgSet.HImage = new HImage(); + // imgSet.HImage.GenImage1("uint2", (int)width, (int)height, bufferPointer); + // imgSet.HImage = imgSet.HImage.ZoomImageSize((int)width, zoomHeight, "constant"); + + + // imgSet.HImage_2 = new HImage(); + // imgSet.HImage_2.GenImage1("uint2", (int)width, (int)height, bufferPointer); + + // imgSet.HImage_2 = imgSet.HImage_2.ZoomImageSize((int)width, zoomHeight, "constant"); + //} + + //Generate16GrayImageByPointer((int)width, (int)height, bufferPointer, imgSet?.Id); } break; + //case GoDataMessageType.SurfaceIntensity: + // { + // GoSurfaceIntensityMsg surfaceMsg = (GoSurfaceIntensityMsg)dataObj; + // long width = surfaceMsg.Width; + // long height = surfaceMsg.Length; + // long bufferSize = width * height; + // IntPtr bufferPointer = surfaceMsg.Data; + + // //int zoomHeight = (surfaceMsg.YResolution * (int)surfaceMsg.Length * 10) / surfaceMsg.XResolution; + + // int zoomHeight = (int)(((double)surfaceMsg.YResolution / (double)surfaceMsg.XResolution) * (double)surfaceMsg.Length); + + // if (imgSet != null) + // { + // imgSet.HImage = new HImage(); + // imgSet.HImage.GenImage1("uint2", (int)width, (int)height, bufferPointer); + // imgSet.HImage = imgSet.HImage.ZoomImageSize((int)width, zoomHeight, "constant"); + + + // imgSet.HImage_2 = new HImage(); + // imgSet.HImage_2.GenImage1("uint2", (int)width, (int)height, bufferPointer); + + // imgSet.HImage_2 = imgSet.HImage_2.ZoomImageSize((int)width, zoomHeight, "constant"); + // } + + // Generate16GrayImageByPointer((int)width, (int)height, bufferPointer, imgSet?.Id); + // } + // break; } } } @@ -336,9 +418,9 @@ public override async void SaveOriginImage(Bitmap map, Bitmap showImage, string imgSetId) { Task.Run(() => - { - OnImageUpdated?.Invoke(this, showImage, imgSetId); - }); + { + OnImageUpdated?.Invoke(this, showImage, imgSetId); + }); GoImageSet set = _imageSetList.FirstOrDefault(u => u.Id == imgSetId) as GoImageSet; -- Gitblit v1.8.0