Exemple #1
0
        /// <summary>
        /// Create Top and Bottom of mesh
        /// </summary>
        /// <param name="pts"></param>
        /// <param name="invert"></param>
        /// <returns></returns>
        protected ScanSlice CreateForTopBottom(Point3DList pts, bool invert = false)
        {
            int count = pts.Count;

            if (count < 2)
            {
                return(new ScanSlice(pts));
            }
            ScanSlice outerList = new ScanSlice(count);
            double    x         = 0;
            double    y         = 0;
            double    z         = 0;

            for (int i = 0; i < count + 1; i++)
            {
                Point3D p = pts[i % count];
                if (i == 0 || (pts[i - 1].Position - p.Position).LengthFast != 0)
                {
                    outerList.Add(p);
                    if (i < count)
                    {
                        x += p.Position.X;
                        y += p.Position.Y;
                        z += p.Position.Z;
                    }
                }
            }
            Vector3d center = new Vector3d((double)(x / count), (double)(y / count), (double)(z / count));

            count = outerList.Count;
            if (count < 2)
            {
                return(outerList);
            }

            ScanSlice ret = new ScanSlice(count * 2);
            int       idx = 0;

            for (idx = 0; idx < count; idx++)
            {
                Point3D pt = outerList[idx];
                if (invert)
                {
                    ret.Add(new Point3D(center, pt.Normal, pt.Color));
                }
                ret.Add(pt);
                if (!invert)
                {
                    ret.Add(new Point3D(center, pt.Normal, pt.Color));
                }
            }

            return(ret);
        }
 /// <summary>
 /// Create a strip result for 2 Scanline (with same Nbr of Points)
 /// </summary>
 /// <param name="prev"></param>
 /// <param name="current"></param>
 public StripResult(ScanLine prev, ScanLine current)
 {
     if (prev.Count != current.Count)
         throw new Exception(" previous and current pointlist doesn't have the same point count");
     Previous = prev;
     Current = current;
     Result = new ScanSlice(Previous.Count + current.Count);
     //GL.Begin(PrimitiveType.LineStrip);
     int count = Math.Min(Previous.Count, current.Count);
     for (int i = 0; i < count; i++)
     {
         Result.Add(Previous[i]);
         Result.Add(current[i]);
     }
     AbstractMeshBuilder.AdjustNormalFromTriangleStrip(Result);
 }
Exemple #3
0
        /// <summary>
        /// Create a strip result for 2 Scanline (with same Nbr of Points)
        /// </summary>
        /// <param name="prev"></param>
        /// <param name="current"></param>
        public StripResult(ScanLine prev, ScanLine current)
        {
            if (prev.Count != current.Count)
            {
                throw new Exception(" previous and current pointlist doesn't have the same point count");
            }
            Previous = prev;
            Current  = current;
            Result   = new ScanSlice(Previous.Count + current.Count);
            //GL.Begin(PrimitiveType.LineStrip);
            int count = Math.Min(Previous.Count, current.Count);

            for (int i = 0; i < count; i++)
            {
                Result.Add(Previous[i]);
                Result.Add(current[i]);
            }
            AbstractMeshBuilder.AdjustNormalFromTriangleStrip(Result);
        }
        /// <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);
        }
        /// <summary>
        /// Create Top and Bottom of mesh
        /// </summary>
        /// <param name="pts"></param>
        /// <param name="invert"></param>
        /// <returns></returns>
        protected ScanSlice CreateForTopBottom(Point3DList pts, bool invert = false)
        {
            int count = pts.Count;
            if (count < 2)
                return new ScanSlice(pts);
            ScanSlice outerList = new ScanSlice(count);
            double x = 0;
            double y = 0;
            double z = 0;
            for (int i = 0; i < count + 1; i++)
            {
                Point3D p = pts[i % count];
                if (i == 0 || (pts[i - 1].Position - p.Position).LengthFast != 0)
                {
                    outerList.Add(p);
                    if (i < count)
                    {
                        x += p.Position.X;
                        y += p.Position.Y;
                        z += p.Position.Z;
                    }
                }
            }
            Vector3d center = new Vector3d((double)(x / count), (double)(y / count), (double)(z / count));

            count = outerList.Count;
            if (count < 2)
                return outerList;

            ScanSlice ret = new ScanSlice(count * 2);
            int idx = 0;
            for (idx = 0; idx < count; idx++)
            {
                Point3D pt = outerList[idx];
                if (invert)
                    ret.Add(new Point3D(center, pt.Normal, pt.Color));
                ret.Add(pt);
                if (!invert)
                    ret.Add(new Point3D(center, pt.Normal, pt.Color));
            }

            return ret;
        }