Example #1
0
        private void StartProcessing()
        {
            if (GOCATOR)
            {
                data = surfaceReceiver.GetSurfaceData();
                surfaceReceiver.Stop();
            }

            sw.Start();

            //holds the pixel data
            byte[] rgbData;
            if (GOCATOR)
            {
                //converts gocator data to rgb data
                rgbData = GocatorToRgb32(data.ranges);

                //copy the data to the image, create the bitmaps 
                Copy32BitDataToImage((int)data.SurfaceInfo.Width, (int)data.SurfaceInfo.Height, rgbData);

                //does all of the image processing
                ProcessImage((int)data.SurfaceInfo.Width, (int)data.SurfaceInfo.Height, data.CalculateResolution());
            }
            else
            {
                int xSize = scan.Resolution.Width * scan.Size.Width;
                int ySize = scan.Resolution.Height* scan.Size.Height;
                float res = xSize / (float)ySize;

                rgbData = Get32BitRgbDataFromFile(String.Format("data/{0}",scan.dataFile));

                //copy the data to the image, create the bitmaps 
                Copy32BitDataToImage(scan.Size.Width, scan.Size.Height, rgbData);
                // Copy16BitDataToImage(width, height, textData, out bitmap, out bitmapData, out unmanImg);
                ProcessImage(scan.Size.Width, scan.Size.Height, res);

            }
            sw.Stop();

            dataTextBox.AppendText("Processing Time: " + sw.ElapsedMilliseconds + " ms\n");
            sw.Reset();

            //resultBox.Image = result;

            resultBox.Size = new Size(originalMat.Width, originalMat.Height);

            // originalBox.Image = result;

            originalBox.Size = new Size(originalMat.Width, originalMat.Height);
        }
        /// <summary>
        /// Starts the scanner and returns the surface
        /// </summary>
        /// <returns>
        /// 0 = success, errors codes can be found in gocator manual
        /// -1 general error
        /// </returns>
        public SurfaceData GetSurfaceData()
        {
            Stopwatch sw1 = new Stopwatch();
            sw1.Start();

            SurfaceData surfaceData = new SurfaceData();

            if ((status = (kStatus)GoSystem_Start(system)) != kStatus.kOK)
                throw new Exception("GoSystem_Start Error: " +(int)status);

            while ((status = (kStatus)GoSystem_ReceiveData(system, ref dataset, 2000000)) != kStatus.kOK) ;

            if (GoDataSet_Count(dataset) == 0)
                throw new Exception("GoSystem_ReceiveData Error: Data received, but it was empty. Check ethernet output settings.");

            // each result can have multiple data items
            // loop through all items in result message
            for (UInt32 i = 0; i < GoDataSet_Count(dataset); i++)
            {
                dataObj = GoDataSet_At(dataset, i);
                // retrieve GoStamp message
                if (GoDataMsg_Type(dataObj) == GoDataMessageTypes.GO_DATA_MESSAGE_TYPE_STAMP)
                {
                    stampMsg = dataObj;
                    for (UInt32 j = 0; j < GoStampMsg_Count(stampMsg); j++)
                    {
                        stampPtr = GoStampMsg_At(stampMsg, j);
                        stamp = (GoStamp)Marshal.PtrToStructure(stampPtr, typeof(GoStamp));
                        surfaceData.Stamp = stamp;
                       }
                }

                // retrieve surface data
                if (GoDataMsg_Type(dataObj) == GoDataMessageTypes.GO_DATA_MESSAGE_TYPE_SURFACE)
                {
                    surfaceMsg = dataObj;
                    surfaceData.SurfaceInfo.Width = GoSurfaceMsg_Width(surfaceMsg);
                    surfaceData.SurfaceInfo.Height = GoSurfaceMsg_Length(surfaceMsg);
                    surfaceData.SurfaceInfo.XResolution = GoSurfaceMsg_XResolution(surfaceMsg);
                    surfaceData.SurfaceInfo.YResolution = GoSurfaceMsg_YResolution(surfaceMsg);
                    surfaceData.SurfaceInfo.XOffset = GoSurfaceMsg_XOffset(surfaceMsg);
                    surfaceData.SurfaceInfo.YOffset = GoSurfaceMsg_YOffset(surfaceMsg);
                    surfaceData.SurfaceInfo.ZOffset = GoSurfaceMsg_ZOffset(surfaceMsg);
                    surfaceData.SurfaceInfo.ZResolution = GoSurfaceMsg_ZResolution(surfaceMsg);

                    UInt32 bufferSize = surfaceData.SurfaceInfo.Width * surfaceData.SurfaceInfo.Height;
                    IntPtr bufferPointer = GoSurfaceMsg_RowAt(surfaceMsg, 0);

                    surfaceData.ranges = new short[bufferSize];
                    Marshal.Copy(bufferPointer, surfaceData.ranges, 0, surfaceData.ranges.Length);

                    Stopwatch sw = new Stopwatch();
                        sw.Start();
                      for (int j = 0; j < bufferSize; j++)
                       {
                      //     surfaceData.ranges[j] = (short)(surfaceData.SurfaceInfo.ZOffset + surfaceData.ranges[j] * surfaceData.SurfaceInfo.ZResolution);
                           surfaceData.ranges[j] = (short)(Math.Pow(2, 15) - Math.Abs((int)surfaceData.ranges[j]));
                       }
                       sw.Stop();
                       Console.WriteLine("Time to transform data: {0}", sw.Elapsed);
                    
                    sw.Stop();
                    Console.WriteLine("Time to transform data: {0}", sw.ElapsedMilliseconds);
                }
                // retrieve surface data
                if (GoDataMsg_Type(dataObj) == GoDataMessageTypes.GO_DATA_MESSAGE_TYPE_SURFACE_INTENSITY)
                {
                    surfaceMsg = dataObj;
                    surfaceData.SurfaceIntensityInfo.Width = GoSurfaceIntensityMsg_Width(surfaceMsg);
                    surfaceData.SurfaceIntensityInfo.Height = GoSurfaceIntensityMsg_Length(surfaceMsg);
                    surfaceData.SurfaceIntensityInfo.XResolution = GoSurfaceIntensityMsg_XResolution(surfaceMsg);
                    surfaceData.SurfaceIntensityInfo.YResolution = GoSurfaceIntensityMsg_YResolution(surfaceMsg);
                    surfaceData.SurfaceIntensityInfo.XOffset = GoSurfaceIntensityMsg_XOffset(surfaceMsg);
                    surfaceData.SurfaceIntensityInfo.YOffset = GoSurfaceIntensityMsg_YOffset(surfaceMsg);

                    UInt32 bufferSize = surfaceData.SurfaceIntensityInfo.Width * surfaceData.SurfaceIntensityInfo.Height;
                    IntPtr bufferPointer = GoSurfaceIntensityMsg_RowAt(surfaceMsg, 0);

                    //short[] ranges = new short[bufferSize];
                    surfaceData.intensities = new byte[bufferSize];
                    Marshal.Copy(bufferPointer, surfaceData.intensities, 0, surfaceData.intensities.Length);

                }
            }
            sw1.Stop();
            Console.WriteLine("Time to get all data: {0}", sw1.Elapsed);
            return surfaceData;
        }