/// <summary>
        /// Do the task
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public override ScanData DoTask(ScanData source)
        {
            ScanData ret = new ScanData(source.Count);

            source.Sort();
            int count         = source.Count;
            int ParallelCount = Settings.Get <Settings>().Read(Settings.SYSTEM, Settings.MAXTHREADS, 8);

            UpdatePercent(0, ret);
            if (LaunchParallel)
            {
                int doneCount = 0;
                Parallel.For(0, count, new ParallelOptions {
                    MaxDegreeOfParallelism = ParallelCount
                }, i =>
                {
                    if (this.CancelPending)
                    {
                        return;
                    }
                    ScanLine line = DoTask(source[i]);
                    if (line != null)
                    {
                        //line.DisplayAsLine = source[i].DisplayAsLine;
                        lock (ret)
                        {
                            ret.Add(line);
                        }
                        doneCount++;
                        {
                            int percent = (int)((100 * doneCount) / count);
                            if (percent % 10 == 0)
                            {
                                UpdatePercent(percent, ret);
                            }
                        }
                    }
                }
                             );
            }
            else
            {
                for (int i = 0; i < count; i++)
                {
                    if (this.CancelPending)
                    {
                        return(ret);
                    }
                    ScanLine line = DoTask(source[i]);
                    if (line != null)
                    {
                        ret.Add(line);
                    }
                    UpdatePercent((int)(100 * i / count), ret);
                }
            }
            UpdatePercent(100, ret);
            return(ret);
        }
Example #2
0
		public override ScanData DoTask(ScanData source)
		{
			ScanData step1 = base.DoTask(source);
			step1.Sort(); //SORT
            Dictionary<string, ScanLine> step2 = new Dictionary<string, ScanLine>();
			for (int i = 0; i < step1.Count; i++)
			{
				ScanLine line = step1[i];
				if (line.Count > 0)
				{
                    for (int c = 0; c < NumClass; c++)
                    {
                        string key = string.Format("{0}->{1}", line.LaserID, c);
                        if (!step2.ContainsKey(key))
                            step2[key] = new ScanLine(line.LaserID, NumClass);
                        step2[key].Add(GetSample(line, NumClass, c));
                    }

					//step2[line.LaserID].Add(line[0]);
				}
			}

			ScanData step3 = new ScanData(step2.Keys.Count);
			for (int i = 0; i < step2.Keys.Count; i++)
            {
                string k = step2.Keys.ElementAt(i);
                step3.Add(step2[k]);

            }
			return step3;
		}
Example #3
0
        public override ScanData DoTask(ScanData source)
        {
            ScanData step1 = base.DoTask(source);

            step1.Sort();             //SORT
            Dictionary <string, ScanLine> step2 = new Dictionary <string, ScanLine>();

            for (int i = 0; i < step1.Count; i++)
            {
                ScanLine line = step1[i];
                if (line.Count > 0)
                {
                    for (int c = 0; c < NumClass; c++)
                    {
                        string key = string.Format("{0}->{1}", line.LaserID, c);
                        if (!step2.ContainsKey(key))
                        {
                            step2[key] = new ScanLine(line.LaserID, NumClass);
                        }
                        step2[key].Add(GetSample(line, NumClass, c));
                    }

                    //step2[line.LaserID].Add(line[0]);
                }
            }

            ScanData step3 = new ScanData(step2.Keys.Count);

            for (int i = 0; i < step2.Keys.Count; i++)
            {
                string k = step2.Keys.ElementAt(i);
                step3.Add(step2[k]);
            }
            return(step3);
        }
Example #4
0
        public override ScanData DoTask(ScanData source)
        {
            source.Sort();
            ScanData ret = source;
            Dictionary<int, ScanData> laserScanData = new Dictionary<int, ScanData>();
            UpdatePercent(0, ret);
            ret = new ScanData();

            int count = source.Count ;
            double delta_angle = DeltaAngle;
            int step = (int)((count * delta_angle) / 360.0);
            for (double ang = 0; ang < 360; ang += delta_angle)
            {
                int biggestIndex = 0;
                int biggestCount = 0;
                List<ScanLine> lines = GetScanlinesByAngle(ang, ang + delta_angle, source);
                for (int j = 0; j < lines.Count; j++)
                {
                    ScanLine l = lines[j];
                    int cnt = l.Count;
                    if (biggestCount < cnt)
                    {
                        biggestCount = cnt;
                        biggestIndex = j;
                    }
                }
                if(lines.Count>0)
                    ret.Add(AverageLines(biggestCount,biggestIndex, lines));
                UpdatePercent((int)(100 * ang/360), ret);
            }
            UpdatePercent(100, ret);
            return ret;
            
        }
Example #5
0
        /// <summary>
        /// Do the task function override
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public override ScanData DoTask(ScanData source)
        {
            ScanData ret = new ScanData(source.Count);

            UpdatePercent(0, ret);
            source.Sort();
            int count = source.Count;
            //count = 2;
            //primitiveType = PrimitiveType.LineStrip;
            ScanLine top    = new ScanLine(count);
            ScanLine bottom = new ScanLine(count);

            ScanLine prev = source[0];

            top.Add(prev.First());
            bottom.Add(prev.Last());

            for (int i = 1; i <= count; i++)
            {
                if (this.CancelPending)
                {
                    return(source);
                }
                ScanLine    current = source[i % count];
                StripResult strip   = CreateStrip(prev, current);

                top.Add(strip.Current.First());
                bottom.Add(strip.Current.Last());

                prev = strip.Current;

                ret.Add(strip.Result);
                UpdatePercent((int)((100 * i) / count), ret);
            }
            if (count <= 2)
            {
                return(ret);
            }
            Point3D topcenter    = Point3D.Average(top);
            Point3D bottomcenter = Point3D.Average(bottom);

            for (int i = 0; i < ret.Count; i++)
            {
                ret[i].Insert(0, topcenter);
                ret[i].Add(bottomcenter);
                AdjustNormalFromTriangleStrip(ret[i]);
            }
            UpdatePercent(100, ret);
            return(ret);
        }
		/// <summary>
		/// Do the task
		/// </summary>
		/// <param name="source"></param>
		/// <returns></returns>
		public override ScanData DoTask(ScanData source)
		{
			ScanData ret = new ScanData(source.Count);
			source.Sort();
			int count = source.Count;
			int ParallelCount = Settings.Get<Settings>().Read(Settings.SYSTEM, Settings.MAXTHREADS, 8);
			UpdatePercent(0, ret);
			if (LaunchParallel)
			{
				int doneCount = 0;
				Parallel.For(0, count, new ParallelOptions { MaxDegreeOfParallelism = ParallelCount }, i =>
				{
					if (this.CancelPending) return;
					ScanLine line = DoTask(source[i]);
					if (line != null)
					{
						//line.DisplayAsLine = source[i].DisplayAsLine;
						lock (ret)
						{
							ret.Add(line);
						}
						doneCount++;
						{
							int percent = (int)((100 * doneCount) / count);
							if (percent % 10 == 0)
								UpdatePercent(percent, ret);
						}
					}

				}
							 );
			}
			else
			{

				for (int i = 0; i < count; i++)
				{
					if (this.CancelPending) return ret;
					ScanLine line = DoTask(source[i]);
					if (line != null)
						ret.Add(line);
					UpdatePercent((int)(100 * i / count), ret);
				}
			}
			UpdatePercent(100, ret);
			return ret;
		}
Example #7
0
        public override ScanData DoTask(ScanData source)
        {
            ScanData ret = source;
            Dictionary <int, ScanData> laserScanData = new Dictionary <int, ScanData>();

            UpdatePercent(0, ret);
            for (int i = 0; i < source.Count; i++)
            {
                ScanLine currentLine = source[i];
                ScanData data        = laserScanData.ContainsKey(currentLine.LaserID) ? laserScanData[currentLine.LaserID] : new ScanData();
                data.Add(currentLine);
                laserScanData[currentLine.LaserID] = data;
            }
            if (laserScanData.Keys.Count >= 1)
            {
                List <ScanData> datas           = new List <ScanData>(laserScanData.Values);
                int             maxSamplePoints = 10000;
                for (int i = 0; i < datas.Count; i++)
                {
                    maxSamplePoints = Math.Min(maxSamplePoints, datas[i].PointCount());
                }
                //ICP.ICP icp = new ICP.ICP(maxSamplePoints/2, 0.001f, 10);
                ICP.IterativeClosestPointTransform icp = new ICP.IterativeClosestPointTransform();
                icp.NumberOfIterations       = 1000;
                icp.NumberOfStartTrialPoints = maxSamplePoints / 2;
                ICP.IterativeClosestPointTransform.SimulatedAnnealing   = false;
                ICP.IterativeClosestPointTransform.DistanceOptimization = true;

                Point3DList refpoints = CreateListFromScanData(datas[0]);
                for (int i = 1; i < datas.Count; i++)
                {
                    Point3DList points = CreateListFromScanData(datas[i]);
                    Matrix4d    mat    = icp.PerformICP(refpoints, points);
                    datas[i].Transform(mat);

                    //icp.Run(points, refpoints);
                    UpdatePercent((int)(100f * i / datas.Count), ret);
                }
            }

            UpdatePercent(100, ret);
            return(ret);
        }
Example #8
0
        public override ScanData DoTask(ScanData source)
        {
            source.Sort();
            ScanData ret = source;
            Dictionary <int, ScanData> laserScanData = new Dictionary <int, ScanData>();

            UpdatePercent(0, ret);
            ret = new ScanData();

            int    count       = source.Count;
            double delta_angle = DeltaAngle;
            int    step        = (int)((count * delta_angle) / 360.0);

            for (double ang = 0; ang < 360; ang += delta_angle)
            {
                int             biggestIndex = 0;
                int             biggestCount = 0;
                List <ScanLine> lines        = GetScanlinesByAngle(ang, ang + delta_angle, source);
                for (int j = 0; j < lines.Count; j++)
                {
                    ScanLine l   = lines[j];
                    int      cnt = l.Count;
                    if (biggestCount < cnt)
                    {
                        biggestCount = cnt;
                        biggestIndex = j;
                    }
                }
                if (lines.Count > 0)
                {
                    ret.Add(AverageLines(biggestCount, biggestIndex, lines));
                }
                UpdatePercent((int)(100 * ang / 360), ret);
            }
            UpdatePercent(100, ret);
            return(ret);
        }
Example #9
0
        public override ScanData DoTask(ScanData source)
        {
            ScanData ret = source;
            Dictionary <int, ScanData> laserScanData = new Dictionary <int, ScanData>();

            UpdatePercent(0, ret);
            for (int i = 0; i < source.Count; i++)
            {
                ScanLine currentLine = source[i];
                ScanData data        = laserScanData.ContainsKey(currentLine.LaserID)?laserScanData[currentLine.LaserID]: new ScanData();
                data.Add(currentLine);
                laserScanData[currentLine.LaserID] = data;
            }
            int masterLaserId = -1;

            foreach (int lId in laserScanData.Keys)
            {
                if (masterLaserId == -1)
                {
                    masterLaserId = lId;
                }
                else if (laserScanData[masterLaserId].Count < laserScanData[lId].Count)
                {
                    masterLaserId = lId;
                }
                laserScanData[lId].Sort();
            }
            ret = new ScanData();

            ScanData master   = laserScanData[masterLaserId];
            double   maxAngle = 180f / master.Count;

            for (int i = 0; i < master.Count; i++)
            {
                List <ScanLine> lines        = new List <ScanLine>(laserScanData.Keys.Count);
                double          currentAngle = master[i].Angle;
                int             currentCount = master[i].Count;
                int             biggestIndex = 0;
                lines.Add(master[i]);
                foreach (int key in laserScanData.Keys)
                {
                    if (key != masterLaserId)
                    {
                        ScanLine currentLine = laserScanData[key].GetNearestLine(currentAngle);
                        if (currentLine == null)
                        {
                            continue;
                        }
                        if (maxAngle > Math.Abs(Utils.DeltaAngle(currentAngle, currentLine.Angle)))
                        {
                            if (currentCount < currentLine.Count)
                            {
                                currentCount = currentLine.Count;
                                biggestIndex = lines.Count;
                            }
                            lines.Add(currentLine);
                        }
                    }
                }
                ret.Add(AverageLines(currentCount, biggestIndex, lines));
            }
            UpdatePercent(100, ret);
            return(ret);
        }
Example #10
0
		/// <summary>
		/// Read ScanData File
		/// </summary>
		/// <param name="file"></param>
		/// <returns></returns>
		public static ScanData Read(string file)
		{
			ScanData ret = new ScanData();
			using (StreamReader r = System.IO.File.OpenText(file))
			{
				string line = r.ReadLine();
				string[] part = line.Split(":".ToArray());
				int slicecount = int.Parse(part[1]);
				for (int i = 0; i < slicecount; i++)
				{
					line = r.ReadLine();
					part = line.Split(":".ToArray());
					ScanLine slice = new ScanLine((int)double.Parse(part[1]));

					line = r.ReadLine();
					part = line.Split(":".ToArray());
					if (part[0] == "DrawAs")
					{
						OpenTK.Graphics.OpenGL.PrimitiveType primitive = OpenTK.Graphics.OpenGL.PrimitiveType.Points;
						Enum.TryParse<OpenTK.Graphics.OpenGL.PrimitiveType>(part[1], true, out primitive);
						switch (primitive)
						{
							case OpenTK.Graphics.OpenGL.PrimitiveType.TriangleStrip:
								{
									slice = new ScanSlice(10000);
									break;
								}
							case OpenTK.Graphics.OpenGL.PrimitiveType.LineStrip:
								{
									slice.DisplayAsLine = true;
									break;
								}
							default:
								{
									slice.DisplayAsLine = false;
									break;
								}
						}
						line = r.ReadLine();
						part = line.Split(":".ToArray());
					}
					int pointcount = int.Parse(part[1]);

					for (int j = 0; j < pointcount; j++)
					{
						line = r.ReadLine();
						part = line.Split("|".ToArray());

						Vector3d pos = GetVector(part[0]);
						Vector3d normal = pos.Normalized();
						try
						{
							normal = GetVector(part[1]);
						}
						catch { }
						Color color = System.Drawing.ColorTranslator.FromHtml(part[2]);
						Point3D p = new Point3D(pos, normal, color);
						slice.Add(p);
					}
					ret.Add(slice);
				}
			}
			return ret;
		}
Example #11
0
        /// <summary>
        /// Read ScanData File
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public static ScanData Read(string file)
        {
            ScanData ret = new ScanData();

            using (StreamReader r = System.IO.File.OpenText(file))
            {
                string   line       = r.ReadLine();
                string[] part       = line.Split(":".ToArray());
                int      slicecount = int.Parse(part[1]);
                for (int i = 0; i < slicecount; i++)
                {
                    line = r.ReadLine();
                    part = line.Split(":".ToArray());
                    ScanLine slice = new ScanLine((int)double.Parse(part[1]));

                    line = r.ReadLine();
                    part = line.Split(":".ToArray());
                    if (part[0] == "DrawAs")
                    {
                        OpenTK.Graphics.OpenGL.PrimitiveType primitive = OpenTK.Graphics.OpenGL.PrimitiveType.Points;
                        Enum.TryParse <OpenTK.Graphics.OpenGL.PrimitiveType>(part[1], true, out primitive);
                        switch (primitive)
                        {
                        case OpenTK.Graphics.OpenGL.PrimitiveType.TriangleStrip:
                        {
                            slice = new ScanSlice(10000);
                            break;
                        }

                        case OpenTK.Graphics.OpenGL.PrimitiveType.LineStrip:
                        {
                            slice.DisplayAsLine = true;
                            break;
                        }

                        default:
                        {
                            slice.DisplayAsLine = false;
                            break;
                        }
                        }
                        line = r.ReadLine();
                        part = line.Split(":".ToArray());
                    }
                    int pointcount = int.Parse(part[1]);

                    for (int j = 0; j < pointcount; j++)
                    {
                        line = r.ReadLine();
                        part = line.Split("|".ToArray());

                        Vector3d pos    = GetVector(part[0]);
                        Vector3d normal = pos.Normalized();
                        try
                        {
                            normal = GetVector(part[1]);
                        }
                        catch { }
                        Color   color = System.Drawing.ColorTranslator.FromHtml(part[2]);
                        Point3D p     = new Point3D(pos, normal, color);
                        slice.Add(p);
                    }
                    ret.Add(slice);
                }
            }
            return(ret);
        }
Example #12
0
		public override ScanData DoTask(ScanData source)
		{
			ScanData ret = source;
			Dictionary<int, ScanData> laserScanData = new Dictionary<int, ScanData>();
			UpdatePercent(0, ret);
			for (int i = 0; i < source.Count; i++)
			{
				ScanLine currentLine = source[i];
				ScanData data = laserScanData.ContainsKey(currentLine.LaserID)?laserScanData[currentLine.LaserID]: new ScanData();
				data.Add(currentLine);
				laserScanData[currentLine.LaserID] = data;
			}
			int masterLaserId = -1;
			foreach (int lId in laserScanData.Keys)
			{
				if (masterLaserId == -1)
					masterLaserId = lId;
				else if (laserScanData[masterLaserId].Count < laserScanData[lId].Count)
						masterLaserId = lId;
				laserScanData[lId].Sort();
			}
			ret = new ScanData();
			
			ScanData master = laserScanData[masterLaserId];
			double maxAngle = 180f / master.Count;
			for (int i = 0; i < master.Count; i++)
			{
				List<ScanLine> lines = new List<ScanLine>(laserScanData.Keys.Count);
				double currentAngle = master[i].Angle;
				int currentCount = master[i].Count;
				int biggestIndex = 0;
				lines.Add(master[i]);
				foreach (int key in laserScanData.Keys)
				{
					if (key != masterLaserId)
					{
						ScanLine currentLine = laserScanData[key].GetNearestLine(currentAngle);
						if (currentLine == null)
							continue;
						if (maxAngle > Math.Abs(Utils.DeltaAngle(currentAngle,currentLine.Angle)))
						{
							if (currentCount < currentLine.Count)
							{
								currentCount = currentLine.Count;
								biggestIndex = lines.Count;
							}
							lines.Add(currentLine);
						}
					}
				}
				ret.Add(AverageLines(currentCount,biggestIndex, lines));
			}
			UpdatePercent(100, ret);
			return ret;
		}
        /// <summary>
        /// Do the task function override
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public override ScanData DoTask(ScanData source)
        {
            ScanData ret = new ScanData(source.Count);
            UpdatePercent(0, ret);
            source.Sort();
            int count = source.Count;
            //count = 2;
            //primitiveType = PrimitiveType.LineStrip;
            ScanLine top = new ScanLine(count);
            ScanLine bottom = new ScanLine(count);

            ScanLine prev = source[0];
            top.Add(prev.First());
            bottom.Add(prev.Last());

            for (int i = 1; i <= count; i++)
            {
                if (this.CancelPending) return source;
                ScanLine current = source[i % count];
                StripResult strip = CreateStrip(prev, current);

                top.Add(strip.Current.First());
                bottom.Add(strip.Current.Last());

                prev = strip.Current;

                ret.Add(strip.Result);
                UpdatePercent((int)((100 * i) / count), ret);
            }
            if (count <= 2)
                return ret;
            Point3D topcenter = Point3D.Average(top);
            Point3D bottomcenter = Point3D.Average(bottom);
            for (int i = 0; i < ret.Count; i++)
            {
                ret[i].Insert(0, topcenter);
                ret[i].Add(bottomcenter);
                AdjustNormalFromTriangleStrip(ret[i]);
            }
            UpdatePercent(100, ret);
            return ret;

        }
Example #14
0
		public override ScanData DoTask(ScanData source)
		{
			if (!HardwareAvailable)
				throw new Exception(string.Format("HardWare missing : TURNTABLE:{0} LASER:{1} CAMERA:{2}", HardwarePresentTrace(TurnTable), HardwarePresentTrace(Laser), HardwarePresentTrace(Camera)));



			RotationStep = (double)Math.Round(TurnTable.MinimumRotation() + (15f - TurnTable.MinimumRotation()) * ((100 - Precision) / 100f), 2);


			Settings settings = Settings.Get<Settings>();
			CameraLoc.X = settings.Read(Settings.CAMERA, Settings.X, 0f);
			CameraLoc.Y = settings.Read(Settings.CAMERA, Settings.Y, 270f);
			CameraLoc.Z = settings.Read(Settings.CAMERA, Settings.Z, 70f);

			double thres = settings.Read(Settings.LASER_COMMON, Settings.MAGNITUDE_THRESHOLD, 10);
			int min = settings.Read(Settings.LASER_COMMON, Settings.MIN_WIDTH, 1);
			int max = settings.Read(Settings.LASER_COMMON, Settings.MAX_WIDTH, 60);


			ICameraProxy camera = Settings.Get<ICameraProxy>();
			ImageProcessor = new ImageProcessor(thres, min, max);

			SizeF tableSize = new SizeF(
					(float)settings.Read(Settings.TABLE, Settings.DIAMETER, 20f),
                    (float)settings.Read(Settings.TABLE, Settings.HEIGHT, 15f)
					);

			Lasers = new List<LaserInfo>(LaserId.Length);
			for (int i = 0; i < LaserId.Length; i++)
			{
				Lasers.Add(new LaserInfo(LaserId[i], CameraLoc, tableSize));
			}

			ScanData ret = new ScanData();
			UpdatePercent(0, ret);
            int fadeTime = settings.Read(Settings.LASER_COMMON, Settings.FADE_DELAY, 100);

			TurnTable.InitialiseRotation();
			int laserCount = Lasers.Count;
			// Scan all laser location, 
			for (double currentAngle = 0; currentAngle < 360f; currentAngle += RotationStep)
			{
				if (this.CancelPending) return ret;

				Laser.TurnAll(false); // All laser off
                Thread.Sleep(fadeTime); // wait fade laser
                Bitmap imgoff = GetCapture();
				for (int laserIndex = 0; laserIndex < laserCount; laserIndex++)
				{
					Laser.Turn(Lasers[laserIndex].Id, true);
                    Thread.Sleep(fadeTime); // wait fade laser
					Bitmap imgon = GetCapture();
					Laser.Turn(Lasers[laserIndex].Id, false);

                    List<PointF> laserloc = ImageProcessor.Process(imgoff,imgon,null);

					Point3DList samplePoints = Lasers[laserIndex].MapPoints(laserloc, UseTexture ? imgoff : null, UseCorrectionMatrix);
					PositionPostProcess(ref samplePoints, -Utils.DEGREES_TO_RADIANS(currentAngle));
					ScanLine line = new ScanLine(laserIndex, samplePoints);
					line.DisplayAsLine = true;
					ret.Add(line);
				}
				int percent = (int)((currentAngle / 360f) * 100f);
				UpdatePercent(percent, ret);
				TurnTable.Rotate(currentAngle, false);
			}
			LineSort lineSort = new LineSort();
			ret = lineSort.Run(ret, CallerControl, this.Worker, this.WorkerArg);
			if (!string.IsNullOrEmpty(FileName))
			{
				string path = Path.Combine(Program.UserDataPath, FileName);
				ScanDataIO.Write(path, ret);
			}
			return ret;
		}