/// <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); }
public Point3D GetSample(ScanLine line, int numClass, int index) { int classCount = line.Count / numClass; int classStart = index * classCount; if (classCount == 0 && line.Count > 0) { return(line[0]); } List <Point3D> sub = new List <Point3D>(); for (int i = 0; i < classCount; i++) { sub.Add(line[classStart + i]); } return(Point3D.Average(sub)); }
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); }
public void AddPolygon(Point3D[] points) { if (points.Length < 3) throw new ArgumentException("points.Length < 3"); Point3D innerPoint = new Point3D { X = points.Average(p => p.X), Y = points.Average(p => p.Y), Z = points.Average(p => p.Z) }; Vector3D ortVec = Vector3D.CrossProduct(innerPoint - points[0], points[1] - points[0]); Plane plane = new Plane(ortVec, points[0]); Plane[] ortPlanes = new Plane[points.Length]; for (int n = 0; n < points.Length; n++) { ortPlanes[n] = new Plane(Vector3D.CrossProduct(points[(n + 1) % points.Length] - points[n], ortVec), points[n]); ortPlanes[n].Normalize(); } AddRayTracedObject(points, (int xProj, int yProj, double eyeXPos, out double x, out double z) => GetPlaneRayIntersection(xProj, yProj, eyeXPos, plane.A, plane.B, plane.C, plane.D, out x, out z, (x1, y1, z1) => ortPlanes.All(p => p.A * x1 + p.B * y1 + p.C * z1 + p.D > -1e-8))); }