/// <summary> /// Map points /// </summary> /// <param name="laserLocations"></param> /// <param name="image"></param> /// <returns></returns> public ScanLine MapPoints(List <PointF> laserLocations, Bitmap image, bool useCorrection) { Point3DList points = Mapper.MapPoints(laserLocations, image, DefaultColor); ScanLine ret = new ScanLine(Id, points.Count); ret.DisplayAsLine = true; if (useCorrection) { Matrix4d m = Correction.GetMatrix(); int count = points.Count; for (int i = 0; i < count; i++) { Point3D p = points[i]; Vector3d v = Vector3d.Transform(p.Position, m); Vector3d n = Vector3d.Transform(p.Normal, m); n.Normalize(); ret.Add(new Point3D(v, n, p.Color)); } } else { ret.Add(points); } return(ret); }
/// <summary> /// Map points /// </summary> /// <param name="laserLocations"></param> /// <param name="image"></param> /// <returns></returns> public ScanLine MapPoints(List<PointF> laserLocations, Bitmap image, bool useCorrection) { Point3DList points = Mapper.MapPoints(laserLocations, image, DefaultColor); ScanLine ret = new ScanLine(Id, points.Count); ret.DisplayAsLine = true; if (useCorrection) { Matrix4d m = Correction.GetMatrix(); int count = points.Count; for (int i = 0; i < count; i++) { Point3D p = points[i]; Vector3d v = Vector3d.Transform(p.Position, m); Vector3d n = Vector3d.Transform(p.Normal, m); n.Normalize(); ret.Add(new Point3D(v, n, p.Color)); } } else { ret.Add(points); } return ret; }
/// <summary> /// Render thes Slice WireFrame /// </summary> /// <param name="context"></param> protected void RenderAsWireFrame(ref RenderingContext context) { PrimitiveType oldPrim = m_Primitive; m_Primitive = PrimitiveType.LineStrip; context.ApplyLineDefault(); base.Render(ref context); ScanLine l1 = new ScanLine(-1, Count / 2); ScanLine l2 = new ScanLine(-1, Count / 2); for (int i = 0; i < Count; i++) { if (i % 2 == 0) { l1.Add(this[i]); } else { l2.Add(this[i]); } } l1.Render(ref context); l2.Render(ref context); m_Primitive = oldPrim; }
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
/// <summary> /// Render thes Slice WireFrame /// </summary> /// <param name="context"></param> protected void RenderAsWireFrame(ref RenderingContext context) { PrimitiveType oldPrim = m_Primitive; m_Primitive = PrimitiveType.LineStrip; context.ApplyLineDefault(); base.Render(ref context); ScanLine l1 = new ScanLine(-1, Count / 2); ScanLine l2 = new ScanLine(-1, Count / 2); for (int i = 0; i < Count; i++) if (i % 2 == 0) l1.Add(this[i]); else l2.Add(this[i]); l1.Render(ref context); l2.Render(ref context); m_Primitive = oldPrim; }