Ejemplo n.º 1
0
 public STLMeasuringTool_MultiThread(STL STL2Measure, List<PointD> P, List<Vector> N, int ThreadNumber, EventHandler OnFinish, STLMeasuringTool objSTLMeasurement)
 {
     this.STL2Measure = STL2Measure;
     this.MeasurePoints = P;
     this.MeasurePointNormals = N;
     this.ThreadNumber = ThreadNumber;
     this.OnFinish += OnFinish;
     this.STLMeasurentReferenceObject = objSTLMeasurement;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 讀取STL檔案,可加入過濾方法篩除不必要的三角面
 /// </summary>
 /// <param name="fileName">檔案名稱</param>
 /// <param name="aTriangleFilter">三角面過濾方法</param>
 /// <returns>回傳STL</returns>
 public static async Task<STL> ReadSTLFile(String fileName, Predicate<Triangle> TriangleFilter = null)
 {
     STL stl = new STL();
     //Try ASCII
     stl = await Task.Run<STL>(()=>ReadSTL_ASCII(fileName, TriangleFilter));
     //Try Bynary
     if (stl == null)
         stl = await Task.Run<STL>(() => ReadSTL_Binary(fileName, TriangleFilter));
     
     
     return stl;
 }
Ejemplo n.º 3
0
        public override object Clone()
        {
            STL aSTL = new STL()
            {
                Name = this.Name, Visible = this.Visible, CoordinateSystem = this.CoordinateSystem, Color = this._color
            };

            Entity[] entities = this.Entities.Values.ToArray();
            for (int i = 0; i < entities.Length; i++)
            {
                aSTL.AddEntity(entities[i].Clone() as Entity);
            }

            return(aSTL);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 執行緒結束時觸發此事件
        /// </summary>

        public STLMeasuringTool_P40(
            STL STL2Measure,
            List<TopoFace[]> topoFaces,
            List<PointD[]> pitchPoints
            )
        {
            this.STL2Measure = STL2Measure;
            this.TopoFaces = topoFaces;
            this.PitchPoints = pitchPoints;
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 模擬P40量測類別的建構式
 /// </summary>
 /// <param name="STL2Measure">欲量測的STL</param>
 /// <param name="TopoFace1">第一拓樸面</param>
 /// <param name="TopoFace2">第二拓樸面</param>
 /// <param name="PitchPoint1">第一拓樸面的PitchPoint</param>
 /// <param name="PitchPoint2">第二拓樸面的PitchPoint</param>
 /// <param name="ThreadNumber">執行緒數目</param>
 /// <param name="OnFinish">計算完成時的後續動作</param>
 public STLMeasuringTool_P40_SingleTooth(STL STL2Measure, TopoFace TopoFace1, TopoFace TopoFace2, PointD PitchPoint1, PointD PitchPoint2, int ThreadNumber, EventHandler OnFinish)
 {
     this.STL2Measure = STL2Measure;
     this.TopoFace1 = TopoFace1;
     this.TopoFace2 = TopoFace2;
     this.PitchPoint1 = PitchPoint1;
     this.PitchPoint2 = PitchPoint2;
     this.ThreadNumber = ThreadNumber;
     this.OnFinish += OnFinish;
 }
Ejemplo n.º 6
0
        public override object Clone()
        {
            STL aSTL = new STL() { Name = this.Name, Visible = this.Visible, CoordinateSystem = this.CoordinateSystem, Color = this._color};
            Entity[] entities = this.Entities.Values.ToArray();
            for (int i = 0; i < entities.Length; i++)
                aSTL.AddEntity(entities[i].Clone() as Entity);

            return aSTL;
        }
Ejemplo n.º 7
0
        public static STL ReadSTL_ASCII(String fileName, Predicate<Triangle> TriangleFilter = null)
        {
            System.IO.StreamReader stream = new System.IO.StreamReader(fileName, Encoding.Default);

            string strLine;
            string[] strArray;
            List<String> strList;

            STL newSTL;

            //aSTL.Name = myFile.ReadLine();
            try
            {
                STL aSTL = new STL() { Color = System.Drawing.Color.Gray };
                while (stream.Peek() != -1)
                {
                    Triangle aTriangle = new Triangle() { Color = System.Drawing.Color.Transparent };
                    //1 法向量
                    strLine = stream.ReadLine();
                    strArray = strLine.Split(' ');
                    strList = new List<string>();
                    foreach (var item in strArray)
                    {
                        if (item != "")
                            strList.Add(item);
                    }
                    if (strList[0].ToLower() == "facet")
                    {
                        PointD N = new PointD()
                        {
                            X = Convert.ToDouble(strList[2]),
                            Y = Convert.ToDouble(strList[3]),
                            Z = Convert.ToDouble(strList[4])
                        };
                        aTriangle.N1 = N;
                        //捨棄
                        stream.ReadLine();
                        //點
                        strLine = stream.ReadLine();
                        strArray = strLine.Split(' ');
                        strList = new List<string>();
                        foreach (var item in strArray)
                        {
                            if (item != "")
                                strList.Add(item);
                        }
                        aTriangle.P1 = new PointD()
                        {
                            X = Convert.ToDouble(strList[1]),
                            Y = Convert.ToDouble(strList[2]),
                            Z = Convert.ToDouble(strList[3])
                        };
                        //點
                        strLine = stream.ReadLine();
                        strArray = strLine.Split(' ');
                        strList = new List<string>();
                        foreach (var item in strArray)
                        {
                            if (item != "")
                                strList.Add(item);
                        }
                        aTriangle.P2 = new PointD()
                        {
                            X = Convert.ToDouble(strList[1]),
                            Y = Convert.ToDouble(strList[2]),
                            Z = Convert.ToDouble(strList[3])
                        };
                        //點
                        strLine = stream.ReadLine();
                        strArray = strLine.Split(' ');
                        strList = new List<string>();
                        foreach (var item in strArray)
                        {
                            if (item != "")
                                strList.Add(item);
                        }
                        aTriangle.P3 = new PointD()
                        {
                            X = Convert.ToDouble(strList[1]),
                            Y = Convert.ToDouble(strList[2]),
                            Z = Convert.ToDouble(strList[3])
                        };
                        //捨棄
                        stream.ReadLine();
                        //捨棄
                        stream.ReadLine();


                        if (TriangleFilter != null)
                        {
                            if (TriangleFilter(aTriangle))
                                aSTL.AddEntity(aTriangle);
                        }
                        else
                        {
                            aSTL.AddEntity(aTriangle);
                        }

                    }
                }
                newSTL = aSTL;
            }
            catch 
            {
                newSTL = null;
            }

            stream.Dispose();
            stream.Close();

            if (newSTL.Entities.Count == 0)
                newSTL = null;

            return newSTL;

        }
Ejemplo n.º 8
0
        public static STL ReadSTL_Binary(String fileName, Predicate<Triangle> TriangleFilter = null)
        {
            BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open), Encoding.ASCII);
            STL aSTL = new STL() { Color = System.Drawing.Color.Gray };
            
            try
            {
                //Read Header
                String header = new String(reader.ReadChars(80));

                //Read Triangle Number
                uint TriangleNumber = reader.ReadUInt32();
                
                //Read Triangle
                while (true)
                {
                    Triangle aTriangle = new Triangle() { Color = System.Drawing.Color.Transparent };

                    double[] Normal = new double[3];
                    for (int i = 0; i < 3; i++)
                    {
                        Tuple<bool, float> tryReadResult = reader.TryReadSingle();
                        if (tryReadResult.Item1 == true)
                            Normal[i] = tryReadResult.Item2;
                        else
                        {
                            reader.Close();
                            return aSTL;
                        }
                    }
                    double[] vertex1 = new double[3];
                    for (int i = 0; i < 3; i++)
                    {
                        Tuple<bool, float> tryReadResult = reader.TryReadSingle();
                        if (tryReadResult.Item1 == true)
                            vertex1[i] = tryReadResult.Item2;
                        else
                        {
                            reader.Close();
                            return aSTL;
                        }
                    }
                    double[] vertex2 = new double[3];
                    for (int i = 0; i < 3; i++)
                    {
                        Tuple<bool, float> tryReadResult = reader.TryReadSingle();
                        if (tryReadResult.Item1 == true)
                            vertex2[i] = tryReadResult.Item2;
                        else
                        {
                            reader.Close();
                            return aSTL;
                        }
                    }
                    double[] vertex3 = new double[3];
                    for (int i = 0; i < 3; i++)
                    {
                        Tuple<bool, float> tryReadResult = reader.TryReadSingle();
                        if (tryReadResult.Item1 == true)
                            vertex3[i] = tryReadResult.Item2;
                        else
                        {
                            reader.Close();
                            return aSTL;
                        }
                    }

                    Tuple<bool, UInt16> attributeByteCount = reader.TryReadUInt16();
                    if (attributeByteCount.Item1 == false)
                    {
                        reader.Close();
                        return aSTL;
                    }

                    aTriangle.N1 = new Vector(Normal);
                    aTriangle.P1 = new PointD(vertex1);
                    aTriangle.P2 = new PointD(vertex2);
                    aTriangle.P3 = new PointD(vertex3);

                    if (TriangleFilter != null)
                    {
                        if (TriangleFilter(aTriangle))
                            aSTL.AddEntity(aTriangle);
                    }
                    else
                    {
                        aSTL.AddEntity(aTriangle);
                    }
                }
            }
            catch (Exception)
            {
                aSTL = null;
            }

            if (aSTL.Entities.Count == 0)
                aSTL = null;

            return aSTL;
        }