public override ScanLine DoTask(ScanLine source)
        {
            int      count = source.Count;
            ScanLine ret   = new ScanLine(source.LaserID, count);

            ret.DisplayAsLine = source.DisplayAsLine;
            if (count < 3)
            {
                ret.AddRange(source);
            }
            else
            {
                ret.Add(source[0]);
                for (int i = 1; i < count - 1; i++)
                {
                    if (CancelPending)
                    {
                        return(source);
                    }
                    ret.Add(source[i - 1].Average(source[i + 1]));
                }
                ret.Add(source[count - 1]);
            }
            return(ret);
        }
示例#2
0
        public override ScanLine DoTask(ScanLine source)
        {
            if (source.Count < 5)
            {                             //not enough points, less than 5 points surely a false positive
                return(new ScanLine(source.LaserID, 0));
            }
            ValidityRange range = GetRange(source, Factor);

            ScanLine ret = new ScanLine(source.LaserID, source.Count);

            for (int i = 0; i < source.Count; i++)
            {
                Point3D sp    = source[i];
                bool    valid = range.IsValid(GetVal(sp));
#if DEBUG
                if (ColoriseOnly)
                {
                    Color col = valid ? Color.WhiteSmoke : Color.Red;
                    ret.Add(new Point3D(sp.Position, sp.Normal, col));
                }
                else
#endif
                if (valid)
                {
                    ret.Add(new Point3D(sp.Position, sp.Normal, sp.Color));
                }
            }
            return(ret);
        }
示例#3
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);
        }
		protected override StripResult CreateStrip(ScanLine previous, ScanLine current)
		{
			int count1 = previous.Count;
			int count2 = current.Count;
			ScanLine ret1 = new ScanLine(previous.LaserID, previous.Count);
			ScanLine ret2 = new ScanLine(current.LaserID, current.Count);
			int i1 = 0;
			int i2 = 0;

			while (i1 < count1 && i2 < count2)
			{
				Point3D p1 = previous[i1];
				Point3D p2 = current[i2];
				ret1.Add(p1);
				ret2.Add(p2);
				if (i2 == 0 && p1.Position.Y > p2.Position.Y)
					i1++;
				else if (i1 == 0 && p1.Position.Y < p2.Position.Y)
					i2++;
				else if (i1 == count1 - 1 && i2 != count2 - 1)
					i2++;
				else if (i2 == count2 - 1 && i1 != count1 - 1)
					i1++;
				else
				{
					i1++;
					i2++;
				}
			}

			return new StripResult(ret1, ret2);
		}
示例#5
0
        public override ScanLine DoTask(ScanLine source)
        {
            int count = source.Count;

            if (count <= 2)
            {
                return(source);
            }
            ScanLine ret = new ScanLine(source.LaserID, source.Count);

            ret.DisplayAsLine = source.DisplayAsLine;
            uint order = Order;

            for (int i = 0; i < count; i++)
            {
                if (this.CancelPending)
                {
                    return(ret);
                }
                //                Debug.Write("[");
                List <Point3D> sourceWindow = new List <Point3D>();
                for (int j = 0; j < order; j++)
                {
                    int indice = (int)(i + j - order / 2);
                    indice = Math.Max(0, Math.Min(indice, count - 1));
                    //                   Debug.Write(" "+indice);
                    sourceWindow.Add(source[indice]);
                }

                //                Debug.WriteLine("]");
                ret.Add(Utils.GetMedian(sourceWindow));
            }
            return(ret);
        }
 public override ScanLine DoTask(ScanLine source)
 {
     int count = source.Count;
     ScanLine ret = new ScanLine(source.LaserID, count);
     ret.DisplayAsLine = source.DisplayAsLine;
     if (count < 3)
         ret.AddRange(source);
     else
     {
         ret.Add(source[0]);
         for (int i = 1; i < count - 1; i++)
         {
             if (CancelPending) return source;
             ret.Add(source[i - 1].Average(source[i + 1]));
         }
         ret.Add(source[count - 1]);
     }
     return ret;
 }
示例#7
0
		public override ScanLine DoTask(ScanLine source)
		{
			double clamp = Math.Abs(Utils.DeltaAngle(-180, source.Angle) / 360);
			ScanLine ret = new ScanLine(source.LaserID,source.Count);
			for (int i = 0; i < source.Count; i++)
			{
				Point3D p = source[i];
				Vector4 c = new Vector4(0.25f, 0.25f, 0.25f, 1);
				c[source.LaserID%3] = (float)clamp;
				ret.Add(new Point3D(p.Position,p.Normal,ColorExtension.ColorFromVector(c))); 
			}
			return ret;
		}
示例#8
0
        public override ScanLine DoTask(ScanLine source)
        {
            double   clamp = Math.Abs(Utils.DeltaAngle(-180, source.Angle) / 360);
            ScanLine ret   = new ScanLine(source.LaserID, source.Count);

            for (int i = 0; i < source.Count; i++)
            {
                Point3D p = source[i];
                Vector4 c = new Vector4(0.25f, 0.25f, 0.25f, 1);
                c[source.LaserID % 3] = (float)clamp;
                ret.Add(new Point3D(p.Position, p.Normal, ColorExtension.ColorFromVector(c)));
            }
            return(ret);
        }
示例#9
0
		public override ScanLine DoTask(ScanLine source)
		{
			ScanLine ret = new ScanLine(source.LaserID, source.Count);
			for (int i = 0; i < source.Count; i++)
			{
				Point3D p = source[i];
				Vector3d pos = p.Position;
				pos.X *= XFactor;
				pos.Y *= YFactor;
				pos.Z *= ZFactor;
				ret.Add(new Point3D(pos, p.Normal, p.Color));
			}
			return ret;
		}
示例#10
0
        public override ScanLine DoTask(ScanLine source)
        {
            ScanLine ret = new ScanLine(source.LaserID, source.Count);

            for (int i = 0; i < source.Count; i++)
            {
                Point3D  p   = source[i];
                Vector3d pos = p.Position;
                pos.X *= XFactor;
                pos.Y *= YFactor;
                pos.Z *= ZFactor;
                ret.Add(new Point3D(pos, p.Normal, p.Color));
            }
            return(ret);
        }
示例#11
0
 protected ScanLine AverageLines(int count, int biggestIndex, List<ScanLine> scanlines)
 {
     int numLines = scanlines.Count;
     ScanLine ret = new ScanLine(-1, count);
     for (int i = 0; i < count; i++)
     {
         List<Point3D> list = new List<Point3D>(numLines);
         double refy = scanlines[biggestIndex][i].Position.Y;
         for (int line = 0; line < numLines; line++)
         {
             list.Add(scanlines[line].GetInterpolateByY(refy, i == 0));
         }
         ret.Add(Point3D.Average(list));
     }
     return ret;
 }
示例#12
0
        protected ScanLine AverageLines(int count, int biggestIndex, List <ScanLine> scanlines)
        {
            int      numLines = scanlines.Count;
            ScanLine ret      = new ScanLine(-1, count);

            for (int i = 0; i < count; i++)
            {
                List <Point3D> list = new List <Point3D>(numLines);
                double         refy = scanlines[biggestIndex][i].Position.Y;
                for (int line = 0; line < numLines; line++)
                {
                    list.Add(scanlines[line].GetInterpolateByY(refy, i == 0));
                }
                ret.Add(Point3D.Average(list));
            }
            return(ret);
        }
示例#13
0
        protected override StripResult CreateStrip(ScanLine previous, ScanLine current)
        {
            int      count1 = previous.Count;
            int      count2 = current.Count;
            ScanLine ret1   = new ScanLine(previous.LaserID, previous.Count);
            ScanLine ret2   = new ScanLine(current.LaserID, current.Count);
            int      i1     = 0;
            int      i2     = 0;

            while (i1 < count1 && i2 < count2)
            {
                Point3D p1 = previous[i1];
                Point3D p2 = current[i2];
                ret1.Add(p1);
                ret2.Add(p2);
                if (i2 == 0 && p1.Position.Y > p2.Position.Y)
                {
                    i1++;
                }
                else if (i1 == 0 && p1.Position.Y < p2.Position.Y)
                {
                    i2++;
                }
                else if (i1 == count1 - 1 && i2 != count2 - 1)
                {
                    i2++;
                }
                else if (i2 == count2 - 1 && i1 != count1 - 1)
                {
                    i1++;
                }
                else
                {
                    i1++;
                    i2++;
                }
            }

            return(new StripResult(ret1, ret2));
        }
示例#14
0
        protected ScanData DoIteration(ScanData source, double pctMin, double pctMax)
        {
            ScanData ret = new ScanData(source.Count);

            ret.AddRange(source);
            int count         = source.Count;
            int doneCount     = 0;
            int ParallelCount = Settings.Get <Settings>().Read(Settings.SYSTEM, Settings.MAXTHREADS, 8);

            Parallel.For(1, count + 1, new ParallelOptions {
                MaxDegreeOfParallelism = ParallelCount
            }, i =>
            {                    //for (int i = 1; i <= count; i++)
                {
                    if (this.CancelPending)
                    {
                        return;
                    }
                    ScanLine current = source[i % count];
                    ScanLine prev    = source[(i - 1) % count];
                    ScanLine next    = source[(i + 1) % count];
                    int lineCount    = current.Count;

                    ScanLine smoothed      = new ScanLine(current.Count);
                    smoothed.DisplayAsLine = current.DisplayAsLine;

                    for (int l = 0; l < lineCount; l++)
                    {
                        smoothed.Add(Smooth(l, prev, current, next));
                    }
                    ret[i % count] = smoothed;
                    doneCount++;
                    int pct = (int)(pctMin + ((pctMax - pctMin) * doneCount) / count);
                    UpdatePercent(pct, ret);
                }
            });
            return(ret);
        }
示例#15
0
        public override ScanLine DoTask(ScanLine source)
        {
            int      count = source.Count;
            ScanLine ret   = new ScanLine(source.LaserID, count);

            for (int i = 0; i < count; i++)
            {
                Point3D  p    = source[i];
                Vector3d pos  = p.Position;
                Vector3d norm = p.Normal;
                Color    col  = p.Color;
                double   r    = col.R;
                double   g    = col.G;
                double   b    = col.B;
                if (m_Brigthness != 0)
                {
                    r = r + m_Brigthness;
                    g = g + m_Brigthness;
                    b = b + m_Brigthness;
                }
                if (m_Contrast != 0)
                {
                    double factor = (259 * (m_Contrast + 255)) / (255 * (259 - m_Contrast));
                    r = factor * (r - 128) + 128;
                    g = factor * (g - 128) + 128;
                    b = factor * (b - 128) + 128;
                }
                if (m_Gamma != 0)
                {
                    double gammaCorrection = 1 / m_Gamma;
                    r = 255 * Math.Pow((r / 255), gammaCorrection);
                    g = 255 * Math.Pow((g / 255), gammaCorrection);
                    b = 255 * Math.Pow((b / 255), gammaCorrection);
                }
                ret.Add(new Point3D(pos, norm, Color.FromArgb(255, Truncate(r), Truncate(g), Truncate(b))));
            }
            return(ret);
        }
示例#16
0
 public override ScanLine DoTask(ScanLine source)
 {
     int count =source.Count;
     ScanLine ret = new ScanLine(source.LaserID, count);
     for (int i = 0; i < count;i++ )
     {
         Point3D p = source[i];
         Vector3d pos = p.Position;
         Vector3d norm = p.Normal;
         Color col = p.Color;
         double r = col.R;
         double g = col.G;
         double b = col.B;
         if (m_Brigthness != 0)
         {
             r = r + m_Brigthness;
             g = g + m_Brigthness;
             b = b + m_Brigthness;
         }
         if(m_Contrast!=0)
         {
             double factor = (259 * (m_Contrast + 255)) / (255 * (259 - m_Contrast));
             r   = factor * (r   - 128) + 128;
             g   = factor * (g   - 128) + 128;
             b   = factor * (b   - 128) + 128;
         }
         if(m_Gamma!=0)
         {
             double gammaCorrection = 1 / m_Gamma;
             r = 255 * Math.Pow((r / 255), gammaCorrection);
             g = 255 * Math.Pow((g / 255), gammaCorrection);
             b = 255 * Math.Pow((b / 255), gammaCorrection);
         }
         ret.Add(new Point3D(pos, norm, Color.FromArgb(255,Truncate(r),Truncate(g),Truncate(b))));
     }
     return ret;
 }
        protected override StripResult CreateStrip(ScanLine previous, ScanLine current)
        {
            ScanLine ret1 = new ScanLine(previous.LaserID);
            ScanLine ret2 = new ScanLine(current.LaserID);

            Point3DList all = new Point3DList();
            all.AddRange(previous);
            all.AddRange(current.Where(p2 => previous.All(p1 => p1.Position.Y != p2.Position.Y)));
            all.Sort();
            all.Reverse();
            //            all.AddRange(list1.Union(list2, ));


            for (int i = 0; i < all.Count; i++)
            {
                double y = all[i].Position.Y;
                Point3D p1 = previous.GetNearestY(y);
                Point3D p2 = current.GetNearestY(y);
                ret1.Add(p1);
                ret2.Add(p2);
            }
            return new StripResult(ret1, ret2);

        }
示例#18
0
        protected override StripResult CreateStrip(ScanLine previous, ScanLine current)
        {
            ScanLine ret1 = new ScanLine(previous.LaserID);
            ScanLine ret2 = new ScanLine(current.LaserID);

            Point3DList all = new Point3DList();

            all.AddRange(previous);
            all.AddRange(current.Where(p2 => previous.All(p1 => p1.Position.Y != p2.Position.Y)));
            all.Sort();
            all.Reverse();
            //            all.AddRange(list1.Union(list2, ));


            for (int i = 0; i < all.Count; i++)
            {
                double  y  = all[i].Position.Y;
                Point3D p1 = previous.GetNearestY(y);
                Point3D p2 = current.GetNearestY(y);
                ret1.Add(p1);
                ret2.Add(p2);
            }
            return(new StripResult(ret1, ret2));
        }
示例#19
0
		protected ScanData DoIteration(ScanData source, double pctMin, double pctMax)
		{
			ScanData ret = new ScanData(source.Count);
			ret.AddRange(source);
			int count = source.Count;
			int doneCount = 0;
			int ParallelCount = Settings.Get<Settings>().Read(Settings.SYSTEM, Settings.MAXTHREADS, 8);
			Parallel.For(1, count+1, new ParallelOptions { MaxDegreeOfParallelism = ParallelCount }, i =>
				{//for (int i = 1; i <= count; i++)
					{
						if (this.CancelPending) return;
						ScanLine current = source[i % count];
						ScanLine prev = source[(i - 1) % count];
						ScanLine next = source[(i + 1) % count];
						int lineCount = current.Count;

						ScanLine smoothed = new ScanLine(current.Count);
						smoothed.DisplayAsLine = current.DisplayAsLine;

						for (int l = 0; l < lineCount; l++)
						{
							smoothed.Add(Smooth(l, prev, current, next));
						}
						ret[i % count] = smoothed;
						doneCount++;
						int pct = (int)(pctMin + ((pctMax - pctMin) * doneCount) / count);
						UpdatePercent(pct, ret);
					}
				});
			return ret;
		}
示例#20
0
        public override ScanLine DoTask(ScanLine source)
        {
            int count = source.Count;
            if (count <= 2)
                return source;
            ScanLine ret = new ScanLine(source.LaserID, source.Count);
            ret.DisplayAsLine = source.DisplayAsLine;
            uint order = Order;
            for (int i = 0; i < count; i++)
            {
                if (this.CancelPending) return ret;
                //                Debug.Write("[");
                List<Point3D> sourceWindow = new List<Point3D>();
                for (int j = 0; j < order; j++)
                {
                    int indice =(int)( i + j - order / 2);
                    indice = Math.Max(0, Math.Min(indice, count - 1));
                    //                   Debug.Write(" "+indice);
                    sourceWindow.Add(source[indice]);
                }

                //                Debug.WriteLine("]");
                ret.Add(Utils.GetMedian(sourceWindow));
            }
            return ret;
        }
示例#21
0
        public override ScanLine DoTask(ScanLine source)
        {
					if (source.Count < 5)
					{ //not enough points, less than 5 points surely a false positive
						return new ScanLine(source.LaserID, 0);
					}
            ValidityRange range = GetRange(source, Factor);

						ScanLine ret = new ScanLine(source.LaserID, source.Count);

            for (int i = 0; i < source.Count; i++)
            {
                Point3D sp = source[i];
                bool valid = range.IsValid(GetVal(sp));
#if DEBUG
                if (ColoriseOnly)
                {
                    Color col = valid ? Color.WhiteSmoke : Color.Red;
                    ret.Add(new Point3D(sp.Position, sp.Normal, col));
                }
                else
#endif
                    if(valid)
                        ret.Add(new Point3D(sp.Position, sp.Normal, sp.Color));
            }
            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;

        }
示例#23
0
        public override ScanLine DoTask(ScanLine source)
        {
            try
            {
                //Debug.WriteLine("\nBegin outlier data detection using k-means clustering demo\n");

                //Debug.WriteLine("Loading all (height-weight) data into memory");
                string[]   attributes = new string[] { "X", "Y", "Z" };
                Vector3d[] rawData    = new Vector3d[source.Count]; // in most cases data will be in a text file or SQl table

                for (int i = 0; i < rawData.Length; i++)
                {
                    rawData[i] = new Vector3d(source[i].Position.X, source[i].Position.Y, source[i].Position.Z);
                }

                //Debug.WriteLine("\nRaw data:\n");
                //ShowMatrix(rawData, rawData.Length, true);

                int numAttributes = attributes.Length; // 2 in this demo (height,weight)
                int numClusters   = NumClusters;       // vary this to experiment (must be between 2 and number data tuples)
                int maxCount      = 30;                // trial and error

                //Debug.WriteLine("\nBegin clustering data with k = " + numClusters + " and maxCount = " + maxCount);
                int[] clustering = Cluster(rawData, numClusters, numAttributes, maxCount);
                //Debug.WriteLine("\nClustering complete");

                //Debug.WriteLine("\nClustering in internal format: \n");
                //ShowVector(clustering, true);  // true -> newline after display

                //Debug.WriteLine("\nClustered data:");
                //ShowClustering(rawData, numClusters, clustering, true);


                double     maxDist = Distance(source.Max, source.Min) / (50);
                List <int> outlier = Outlier(rawData, clustering, maxDist);
                //Debug.WriteLine("Outlier for cluster 0 is:");
                //ShowVector(outlier, true);
                //Debug.WriteLine("\nEnd demo\n");
                List <int> count = new List <int>(numClusters);
                for (int i = 0; i < numClusters; i++)
                {
                    count.Add(0);
                }
                for (int i = 0; i < clustering.Length; i++)
                {
                    count[clustering[i]]++;
                }

                int         pointCount = source.Count;
                List <bool> clusterOk  = new List <bool>(numClusters);
                for (int i = 0; i < numClusters; i++)
                {
                    double pct = (100f * count[i]) / pointCount;
                    clusterOk.Add(pct >= this.RejectPercent);
                }

                ScanLine ret = new ScanLine(source.LaserID, source.Count);
                for (int i = 0; i < source.Count; i++)
                {
                    Point3D sp           = source[i];
                    int     clusterIndex = clustering[i];
                    Color   col          = sp.Color;
#if DEBUG
                    if (ColoriseOnly)
                    {
                        float clamp = (float)((1.0f * clusterIndex) / (numClusters - 1));
                        col = ColorExtension.ColorFromVector(new Vector4(clamp, clamp, clamp, clamp));
                        if (!clusterOk[clusterIndex])
                        {
                            col = Color.Green;
                        }
                        else if (outlier.Contains(i))
                        {
                            col = Color.Red;
                        }
                        ret.Add(new Point3D(sp.Position, sp.Normal, col));
                    }
                    else if (clusterOk[clusterIndex] && !outlier.Contains(i))
#endif
                    ret.Add(new Point3D(sp.Position, sp.Normal, col));
                }

                return(ret);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            return(source);
        } // Main