コード例 #1
0
        private vdPolyface CreatePolyFaceFromCurve(vdPolyline curvePath, double diameter)
        {
            var pf = new vdPolyface();

            pf.SetUnRegisterDocument(vDraw.ActiveDocument);
            pf.setDocumentDefaults();

            var circle = new vdCircle {
                Radius = diameter / 2.0
            };

            vdCurve path = curvePath;

            if (curvePath.VertexList.Count == 2)
            {
                var line = new vdLine();
                line.SetUnRegisterDocument(vDraw.ActiveDocument);
                line.setDocumentDefaults();
                line.StartPoint = curvePath.getStartPoint();
                line.EndPoint   = curvePath.getEndPoint();
                path            = line;
            }

            pf.Generate3dPathSection(path, circle, new gPoint(0, 0, 0), 6, 1);
            pf.SmoothAngle         = 45;
            pf.PenColor.ColorIndex = 2;
            vDraw.ActiveDocument.ActiveLayOut.Entities.Add(pf);

            return(pf);
        }
コード例 #2
0
        private void InitEntityInModelBlock()
        {
            if (ModelBlock == null)
            {
                return;
            }

            foreach (MeshData mesh in ModelBlock.Meshs)
            {
                vdPolyface vdp = AddMeshToEntities(vDraw.ActiveDocument.ActiveLayOut.Entities, mesh);
                if (vdp != null && ExportSetting.SystemSetting.DefaultLayerName.Length > 1)
                {
                    SetEntityLayer(vdp, ExportSetting.SystemSetting.DefaultLayerName);
                }
            }

            foreach (InsertData ins in ModelBlock.Inserts)
            {
                vdInsert vdi = AddInsertToEntities(vDraw.ActiveDocument.ActiveLayOut.Entities, ins);
                if (vdi != null && ExportSetting.SystemSetting.DefaultLayerName.Length > 1)
                {
                    SetEntityLayer(vdi, ExportSetting.SystemSetting.DefaultLayerName);
                }
            }

            vDraw.ActiveDocument.CommandAction.Zoom("E", null, null);
        }
コード例 #3
0
        string Polyface2string(vdPolyface vdp)
        {
            if (vdp == null)
            {
                return("");
            }
            StringBuilder sb = new StringBuilder();

            foreach (int i in vdp.FaceList)
            {
                sb.Append(i + ",");
            }
            sb.Append("\n");
            foreach (gPoint gp in vdp.VertexList)
            {
                sb.Append(gp.x + "," + gp.y + "," + gp.z + ",");
            }
            sb.Append("\n");
            sb.AppendLine(vdp.Layer.Name);
            sb.AppendLine(vdp.PenColor.ColorIndex.ToString());
            sb.AppendLine(vdp.PenWidth.ToString());
            sb.AppendLine(vdp.SmoothAngle.ToString());
            sb.AppendLine(vdp.visibility.ToString());
            return(sb.ToString());
        }
コード例 #4
0
        string GetBlkMd5(vdBlock vdb)
        {
            SortedList <string, string> ss = new SortedList <string, string>();

            //Dictionary<string, string> dics = new Dictionary<string, string>();
            foreach (vdFigure vdf in vdb.Entities)
            {
                if (vdf is vdPolyface)
                {
                    vdPolyface vdp  = vdf as vdPolyface;
                    string     str1 = Polyface2string(vdp);
                    if (!ss.ContainsKey(str1))
                    {
                        ss.Add(str1, str1);
                    }
                }
            }
            StringBuilder sb = new StringBuilder();

            foreach (KeyValuePair <string, string> s in ss)
            {
                sb.AppendLine(s.Key);
            }

            string str2 = GetMD5HashFromString(sb.ToString());

            return(str2);
        }
コード例 #5
0
        public void Convert()
        {
            //doc.Purge();
            SetProgress(5);
            Dictionary <string, bool> kvs = new Dictionary <string, bool>();

            int ipr   = 0;
            int count = doc.Blocks.Count;

            foreach (vdBlock vdb in doc.Blocks)
            {
                ipr++;

                foreach (vdFigure vdf1 in vdb.Entities)
                {
                    if (vdf1 is vdPolyface)
                    {
                        vdPolyface vdff = vdf1 as vdPolyface;
                        bool       ret  = GetVDPBorderLine(vdff, null);
                        if (!ret)
                        {
                            Merge3DFace(vdff);
                        }
                    }
                }
                SetProgress(5 + (ipr * 65) / count);
            }


            ipr = 0;
            foreach (vdFigure vdf in doc.ActiveLayOut.Entities)
            {
                ipr++;

                //                 for (int i = vdf.XProperties.Count - 1; i >= 0; i--)
                //                 {
                //                     vdXProperty vdx = vdf.XProperties[i];
                //                     if (vdx.Name.StartsWith("CylinderFaceData") || vdx.Name.StartsWith("POINTVECTOR"))
                //                     {
                //                         vdf.XProperties.RemoveItem(vdx);
                //                     }
                //                 }

                if (vdf is vdPolyface)
                {
                    kvs.Clear();
                    vdPolyface vdp = vdf as vdPolyface;
                    bool       ret = GetVDPBorderLine(vdp, vdp);
                    if (!ret)
                    {
                        Merge3DFace(vdp);
                    }
                }

                SetProgress(70 + (ipr * 30) / doc.ActiveLayOut.Entities.Count);
            }
            //doc.Purge();
        }
コード例 #6
0
 string GetPolyFace(vdPolyface vdf, vdXProperties vdxs)
 {
     foreach (vdXProperty vdx in vdxs)
     {
         if (vdx.Name.StartsWith(""))
         {
             string   str  = vdx.PropValue.ToString();
             string[] strs = str.Split(',');
         }
     }
     return("");
 }
コード例 #7
0
        /// <summary>
        /// 找到对应的点和向量
        /// </summary>
        /// <param name="i32">定点数组</param>
        /// <param name="points">坐标数组</param>
        /// <param name="vdPf">父图形,里面存点和向量</param>
        /// <param name="orgin">输出找到的点</param>
        /// <param name="vector">输出找到的向量</param>
        /// <returns>是否找到</returns>
        ///
        bool FindPointVector(gPoints Points, vdPolyface vdp, vdFigure vdPf, ref gPoint orign, ref Vector vector)
        {
            int iii = 1;

            while (true)
            {
                string strName = "POINTVECTOR" + iii.ToString();
                iii++;
                vdXProperty vdx = vdPf.XProperties.FindName(strName);
                if (vdx != null)
                {
                    string   strValue = (string)vdx.PropValue;
                    string[] strs     = strValue.Split(new char[] { ',' });
                    orign  = new gPoint(double.Parse(strs[0]), double.Parse(strs[1]), double.Parse(strs[2]));
                    vector = new Vector(double.Parse(strs[3]), double.Parse(strs[4]), double.Parse(strs[5]));



                    double d    = -1.0;
                    gPoint gEnd = orign + vector;


                    int currenti = 0;
                    for (int i = 0; i < Points.Count; i++)
                    {
                        currenti = i;
                        gPoint gp = Points[i];
                        double dd = gp.DistanceFromLine(orign, gEnd);
                        if (d < 0)
                        {
                            d = dd;
                        }
                        else
                        {
                            if (Math.Abs(dd - d) > Globals.VD_ZERO5)
                            {
                                //MessageBox.Show("Error!");
                                break;
                            }
                        }
                    }
                    if (currenti == Points.Count - 1)
                    {
                        return(true);
                    }
                }
                else
                {
                    return(false);
                }
            }
        }
コード例 #8
0
        private vdPolyface AddMeshToEntities(vdEntities entities, MeshData mesh)
        {
            vdPolyface onepolyface = new vdPolyface();

            onepolyface.SetUnRegisterDocument(vDraw.ActiveDocument);
            onepolyface.setDocumentDefaults();

            // 顶点数组输入
            foreach (PointData point in mesh.Vertexes)
            {
                onepolyface.VertexList.Add(point.X * Tools.Ft2MmScale, point.Y * Tools.Ft2MmScale, point.Z * Tools.Ft2MmScale);
            }

            // 面片索引输入
            foreach (TriangleIndexData index in mesh.TriangleIndexes)
            {
                onepolyface.AddFaceItem(index.V1 + 1, index.V2 + 1, index.V3 + 1, index.V1 + 1, -1);
            }

            onepolyface.SmoothAngle = 45;
            onepolyface.Layer       = vDraw.ActiveDocument.Layers.FindName(mesh.MaterialName);
            entities.Add(onepolyface);

            if (ExportSetting.SystemSetting.IsExportTextureFile)
            {
                var material = Materials.Find(m => m.Name == mesh.MaterialName);
                if (material != null && !string.IsNullOrEmpty(material.GetValidMapFile()))
                {
                    var img = vDraw.ActiveDocument.Images.FindName(Path.GetFileNameWithoutExtension(material.GetValidMapFile()));
                    if (img != null)
                    {
                        onepolyface.PenColor.SystemColor   = Color.Gray;
                        onepolyface.PenColor.MaterialImage = img;

                        Matrix mtx = new Matrix();
                        mtx.IdentityMatrix();
                        mtx.ScaleMatrix(0.001, 0.001, 1);
                        onepolyface.PenColor.MaterialMatrix = mtx;
                    }
                }
            }

            onepolyface.Invalidate();
            onepolyface.Update();

            return(onepolyface);
        }
コード例 #9
0
 public CRevit2vdl(string strFile, ProgressBar pgressBar)
 {
     progressBar1 = pgressBar;
     vec.EnsureDocument();
     vec.ActiveDocument.EnsureDefaults();
     doc           = vec.ActiveDocument;
     vec.Progress += vec_Progress;
     doc.Open(strFile);
     foreach (vdFigure vdf in doc.ActiveLayOut.Entities)
     {
         if (vdf is vdPolyface)
         {
             vdPolyface vdp = vdf as vdPolyface;
             gPoints    gps = vdp.VertexList.Clone() as gPoints;
             gps.RemoveEqualPoints();
         }
     }
 }
コード例 #10
0
        Int32Array[] MergeList(vdPolyface vdp, Int32Array i32)
        {
            vdPolyface vdp1 = new vdPolyface();

            gTriangles gts = vdp.GetTriangles();
            gTriangle  gt  = gts[1];

            Vector vec1 = new Vector();
            Vector vec2 = new Vector();
            gPoint gp1  = new gPoint();
            gPoint gp2  = new gPoint();

            gt.GetPlane(out vec1, out gp1);

            //找到两个不共线的3三角形
            Int32Array[] aa = null;
            return(aa);
        }
コード例 #11
0
        private void AddPipeToEntities(vdEntities entities, double diameter, gPoint ptStart, gPoint ptEnd, string layerName)
        {
            var pf = new vdPolyface();

            pf.SetUnRegisterDocument(vDraw.ActiveDocument);
            pf.setDocumentDefaults();

            var line   = new vdLine(ptStart, ptEnd);
            var circle = new vdCircle
            {
                Radius = diameter / 2.0
            };

            pf.Generate3dPathSection(line, circle, new gPoint(0, 0, 0), 6, 1);
            pf.Layer       = vDraw.ActiveDocument.Layers.FindName(layerName);
            pf.SmoothAngle = 45;
            entities.Add(pf);
        }
コード例 #12
0
        /// <summary>
        /// Implementation of the Slice command.
        /// </summary>
        /// <param name="doc"></param>
        public static void Slice(vdDocument doc)
        {
            doc.Prompt("Select a vdPolyface Figure");
            vdFigure fig;
            gPoint   userpt;
            //This command waits until thew user clicks an entity.
            StatusCode code = doc.ActionUtility.getUserEntity(out fig, out userpt);

            doc.Prompt(null);
            if (code == StatusCode.Success)
            {
                vdPolyface face = fig as vdPolyface;
                if (face != null)
                {
                    doc.Prompt("Pick the Origin Point");
                    gPoint origin;
                    code = doc.ActionUtility.getUserPoint(out origin);
                    doc.Prompt(null);
                    if (code != StatusCode.Success)
                    {
                        return;
                    }
                    doc.Prompt("Give the Slice Direction Vector");
                    gPoint vector;
                    code = doc.ActionUtility.getUserPoint(out vector);
                    doc.Prompt(null);
                    if (code != StatusCode.Success)
                    {
                        return;
                    }
                    Vector v = new Vector(vector);
                    face.Invalidate();
                    face.Slice(origin, v);
                    face.Update();
                    face.Invalidate();
                }
            }
        }
コード例 #13
0
        public static void Merge(VectorDrawBaseControl v, FormProgress p)
        {
            p.Text = "合并面片...";

            int ii    = 0;
            int count = v.ActiveDocument.Blocks.Count;
            vdArray <vdBlock> blocks = new vdArray <vdBlock>();
            bool LargeNum            = false;

            foreach (vdBlock vdb in v.ActiveDocument.Blocks)
            {
                if (vdb.Entities.Count == 0)
                {
                    blocks.AddItem(vdb);
                }
                ii++;
                int value = (ii * 100) / count;
                Dictionary <string, vdPolyface> layFaces = new Dictionary <string, vdPolyface>();
                Dictionary <int, int>           ids      = new Dictionary <int, int>();
                int icount = 0;

                p.SetProgress(value);

                //if (vdb.Entities.Count > 5000)
                //{
                //    LargeNum = true;
                //}
                //else
                //{
                //    LargeNum = false;
                //}

                foreach (vdFigure vdf in vdb.Entities)
                {
                    if (vdf is vdPolyface)
                    {
                        vdPolyface vdp = vdf as vdPolyface;

                        if (!layFaces.ContainsKey(vdp.Layer.Name))
                        {
                            layFaces.Add(vdp.Layer.Name, vdp);
                            ids.Add(vdp.Id, vdp.Id);
                        }
                        else
                        {
                            layFaces[vdp.Layer.Name].MergePolyface1(vdp);
                        }

                        //if (LargeNum)
                        //{
                        //    icount++;
                        //}
                    }
                }

                icount = 0;
                for (int i = vdb.Entities.Count - 1; i >= 0; i--)
                {
                    vdFigure vdf = vdb.Entities[i];
                    if (vdf is vdPolyface && ids.ContainsKey(vdf.Id))
                    {
                        vdPolyface vdp1 = vdf as vdPolyface;
                        if (vdp1.FaceList.Count > 0)
                        {
                            vdp1.ClearVerticies1();
                        }
                        else
                        {
                            vdb.Entities.RemoveItem(vdf);
                            vdf.Dispose();
                            vdf = null;
                        }
                    }
                    else if (vdf is vdPolyface)
                    {
                        vdb.Entities.RemoveItem(vdf);
                        vdf.Dispose();
                        vdf = null;
                    }

                    //if (LargeNum)
                    //{
                    //    icount++;
                    //}
                }

                //vdb.Update();
            }
            foreach (vdBlock vdb in blocks)
            {
                v.ActiveDocument.Blocks.RemoveItem(vdb);
                vdb.Dispose();
                //vdb = null;
            }


            GC.Collect();
        }
コード例 #14
0
        /// <summary>
        /// 旧的合并方法,已经弃用
        /// </summary>
        /// <param name="v"></param>
        /// <param name="p"></param>
        public static void Merge1(VectorDrawBaseControl v, FormProgress p)
        {
            p.Text = "合并面片...";
            int ii    = 0;
            int count = v.ActiveDocument.Blocks.Count;

            vdArray <vdBlock> blocks = new vdArray <vdBlock>();

            foreach (vdBlock vdb in v.ActiveDocument.Blocks)
            {
                if (vdb.Entities.Count == 0)
                {
                    blocks.AddItem(vdb);
                }

                int percent = (int)((++ii * 1.0 / count) * 100);

                p.SetProgress(percent);

                Dictionary <string, vdPolyface> layFaces = new Dictionary <string, vdPolyface>();
                Dictionary <int, int>           ids      = new Dictionary <int, int>();
                foreach (vdFigure vdf in vdb.Entities)
                {
                    if (vdf is vdPolyface)
                    {
                        vdPolyface vdp = vdf as vdPolyface;

                        if (!layFaces.ContainsKey(vdp.Layer.Name))
                        {
                            layFaces.Add(vdp.Layer.Name, vdp);
                            ids.Add(vdp.Id, vdp.Id);
                        }
                        else
                        {
                            layFaces[vdp.Layer.Name].MergePolyface1(vdp);
                        }
                    }
                }
                for (int i = vdb.Entities.Count - 1; i >= 0; i--)
                {
                    vdFigure vdf = vdb.Entities[i];
                    if (vdf is vdPolyface && ids.ContainsKey(vdf.Id))
                    {
                        vdPolyface vdp1 = vdf as vdPolyface;
                        if (vdp1.FaceList.Count > 0)
                        {
                            vdp1.ClearVerticies();
                        }
                        else
                        {
                            vdb.Entities.RemoveItem(vdf);
                            vdf.Dispose();
                            vdf = null;
                        }
                    }
                    else if (vdf is vdPolyface)
                    {
                        vdb.Entities.RemoveItem(vdf);
                        vdf.Dispose();
                        vdf = null;
                    }
                }
            }
            foreach (vdBlock vdb in blocks)
            {
                v.ActiveDocument.Blocks.RemoveItem(vdb);
                vdb.Dispose();
                //vdb = null;
            }
            GC.Collect();
        }
コード例 #15
0
        bool Merge3DFace(vdPolyface vdp)
        {
            int                   II       = int.MaxValue;
            Int32Array            i32      = vdp.FaceList;
            Dictionary <int, int> deleteID = new Dictionary <int, int>();

            Dictionary <int, int> kk1 = new Dictionary <int, int>();
            Dictionary <int, int> kk2 = new Dictionary <int, int>();

            //合并三角形
            #region 合并三角形
            for (int i = 0; i < i32.Count; i = i + 5)
            {
                if (i32[i + 4] != II && i32[i] == i32[i + 3]) //一定是没有被合并过的,说明是三角形
                {
                    int i1 = i32[i];
                    int i2 = i32[i + 1];
                    int i3 = i32[i + 2];
                    kk1.Clear();
                    kk1.Add(i1, i1);
                    kk1.Add(i2, i2);
                    kk1.Add(i3, i3);

                    for (int j = i + 5; j < i32.Count; j = j + 5)
                    {
                        if (i32[j + 4] != II && i32[j] == i32[j + 3])   //剔除已经处理过的
                        {
                            int j1 = i32[j];
                            int j2 = i32[j + 1];
                            int j3 = i32[j + 2];

                            //kk2.Clear();
                            //kk2.Add(j1, j1);
                            //kk2.Add(j2, j2);
                            //kk2.Add(j3, j3);


                            int k1 = 0;
                            int k2 = 0;
                            int k3 = 0;
                            int k4 = 0;

                            //找到公共边
                            if ((i1 == j1 || i1 == j2 || i1 == j3) && (i2 == j1 || i2 == j2 || i2 == j3))
                            {
                                k1 = i3;
                                k2 = i1;
                                k4 = i2;
                            }
                            else if ((i2 == j1 || i2 == j2 || i2 == j3) && (i3 == j1 || i3 == j2 || i3 == j3))
                            {
                                k1 = i1;
                                k2 = i2;
                                k4 = i3;
                            }
                            else if ((i1 == j1 || i1 == j2 || i1 == j3) && (i3 == j1 || i3 == j2 || i3 == j3))
                            {
                                k1 = i2;
                                k2 = i3;
                                k4 = i1;
                            }
                            else
                            {
                                continue;
                            }

                            if (!kk1.ContainsKey(j1))
                            {
                                k3 = j1;
                            }

                            if (!kk1.ContainsKey(j2))
                            {
                                k3 = j2;
                            }

                            if (!kk1.ContainsKey(j3))
                            {
                                k3 = j3;
                            }

                            //检查是否共面

                            gPoints gps3 = new gPoints();
                            //gps3.Add(vdp.VertexList[i1 - 1]);
                            //gps3.Add(vdp.VertexList[i2 - 1]);
                            //gps3.Add(vdp.VertexList[i3 - 1]);

                            gps3.Add(vdp.VertexList[k1 - 1]);
                            gps3.Add(vdp.VertexList[k2 - 1]);
                            gps3.Add(vdp.VertexList[k4 - 1]);


                            Vector vec = gps3.GetNormal();

                            // 导出时,下面计算dist的方法有异常OutOfRange异常抛出,特加以下判断
                            if (k3 > vdp.VertexList.Count || k1 > vdp.VertexList.Count || k3 <= 0 || k1 <= 0)
                            {
                                continue;
                            }

                            double dist = Globals.DistancePointToPlane(vdp.VertexList[k3 - 1], vec,
                                                                       vdp.VertexList[k1 - 1]);
                            if (Math.Abs(dist) > Globals.VD_ZERO6)
                            {
                                continue;
                            }

                            //判断是否是凹多边形   凹多边形有显示问题

                            ////判断是否构成了三角形
                            gps3.InsertAt(3, vdp.VertexList[k3 - 1]);

                            //gPoints gps4=gps3.Clone() as gPoints;
                            //gps3.makeClosed();
                            //gps4.makeClosed();
                            //gps4.RemoveInLinePoints();

                            //if (gps3.Count != gps4.Count) continue;


                            double area1 = GetArea3D(gps3[0], gps3[1], gps3[2]);
                            double area2 = GetArea3D(gps3[3], gps3[1], gps3[2]);
                            double area3 = GetArea3D(gps3[0], gps3[1], gps3[3]);
                            double area4 = GetArea3D(gps3[0], gps3[2], gps3[3]);

                            double area = Math.Max(area3, area4);
                            if (area1 + area2 <= area)  //凹多边形
                            {
                                continue;
                            }


                            i32[i]     = k4;
                            i32[i + 1] = k1;
                            i32[i + 2] = k2;
                            i32[i + 3] = k3;//这里放到第3个点经常出现问题


                            i32[j + 4] = II;
                            break;
                        }
                    }
                }
            }
            #endregion
            #region 生成新的polyface
            Int32Array iii32 = new Int32Array();
            for (int i = 0; i < vdp.FaceList.Count; i = i + 5)
            {
                if (vdp.FaceList[i + 4] != II)
                {
                    iii32.Add(i32[i]);
                    iii32.Add(i32[i + 1]);
                    iii32.Add(i32[i + 2]);
                    iii32.Add(i32[i + 3]);
                    iii32.Add(i32[i + 4]);
                }
            }
            vdp.FaceList = iii32;
            vdp.Invalidate();
            #endregion
            return(true);
        }
コード例 #16
0
        /// <summary>
        /// /处理polyface
        /// </summary>
        //bool <param name="vdp"></param>
        bool GetVDPBorderLine(vdPolyface vdp, vdFigure vdPf)
        {
            vdPolyface vdpOut             = new vdPolyface();
            Dictionary <string, bool> kvs = new Dictionary <string, bool>();
            Int32Array iii32 = vdp.FaceList;

            for (int i = 0; i < iii32.Count; i++)
            {
                if (vdp.FaceList[i] < 0)
                {
                    if (i % 5 != 4)
                    {
                        vdp.FaceList[i] = -vdp.FaceList[i];
                    }
                }
            }
            iii32 = vdp.FaceList;
            for (int i = 0; i < iii32.Count; i = i + 5)
            {
                AddSide(kvs, iii32[i], iii32[i + 1]);
                AddSide(kvs, iii32[i + 1], iii32[i + 2]);
                AddSide(kvs, iii32[i + 2], iii32[i]);
            }
            //找到外边界
            Int32Array i32 = ParaseSide2List(kvs, vdp.VertexList.Count + 1);

            if (i32.Count < 5)
            {
                return(false);
            }

            //找到向量
            ///int iii = 1;
            gPoints Points = vdp.VertexList;

            Points.makeClosed();
            gPoints gps = new gPoints();// Points.Clone() as gPoints;

            foreach (int ii in i32)
            {
                gps.Add(Points[ii - 1]);
            }
            gps.RemoveEqualPoints(Globals.VD_ZERO5);

            //gps.RemoveInLinePoints();

            Int32Array ii32 = new Int32Array();
            gPoints    gpss = new gPoints();


            #region  延长线段到最长

            gpss.Add(gps[0]);


            for (int i = 0; i < gps.Count - 1; i++)
            {
                //if (i == 5)
                //{
                //    int j = 0;
                //}

                if (i != gps.Count - 2)
                {
                    double dd = Globals.distPointFromLine(gps[i + 2], gps[i], gps[i + 1]);
                    if (Globals.distPointFromLine(gps[i + 2], gps[i], gps[i + 1]) < 0.2)
                    {
                        continue;
                    }
                    else
                    {
                        gpss.Add(gps[i + 1]);
                    }
                }

                if (i == gps.Count - 2)
                {
                    if (Globals.distPointFromLine(gps[1], gps[i], gps[i + 1]) < 0.2)
                    {
                        gpss.RemoveAt(0);
                    }
                    else
                    {
                        gpss.Add(gps[i + 1]);
                    }
                }
            }

            #endregion
            gpss.makeClosed();
            gpss.RemoveLast();


            //找到四条边中符合圆柱体标准的。

            if (gpss.Count % 2 != 0 || gpss.Count < 10)
            {
                return(false);
            }

            int half = gpss.Count / 2;

            gPoints gEndSide1  = new gPoints();
            gPoints gEndSide2  = new gPoints();
            gPoints gParaSide1 = new gPoints();
            gPoints gParaSide2 = new gPoints();



            for (int i = 0; i < gpss.Count / 2; i++)
            {
                Vector v1 = new Vector(gpss[i], gpss[i + 1]);
                Vector v2 = new Vector(gpss[i + half], gpss[(half + i + 1) % gpss.Count]);
                v1.Cross(v2);
                if (v1.Length < Globals.VD_ZERO6)  //说明平行
                {
                    gEndSide1.RemoveAll();
                    gEndSide2.RemoveAll();
                    gParaSide1.RemoveAll();
                    gParaSide2.RemoveAll();

                    gParaSide1.Add(gpss[i]);
                    gParaSide1.Add(gpss[i + 1]);

                    gParaSide2.Add(gpss[i + half]);
                    gParaSide2.Add(gpss[(half + i + 1) % gpss.Count]);



                    for (int j = i + 1; j < i + half; j++)
                    {
                        gEndSide1.Add(gpss[j]);
                    }

                    for (int j = i + half + 1; j < i + 2 * half; j++)
                    {
                        gEndSide2.Add(gpss[j % gpss.Count]);
                    }

                    gPoint sp1    = new gPoint();
                    gPoint sp2    = new gPoint();
                    double radius = 0.0;

                    //判断是个边是否符合圆柱体标准
                    if (!IS4SideCyln(gEndSide1, gEndSide2, gParaSide1, gParaSide2, ref sp1, ref sp2, out radius))  //不符合圆柱体标准 ,直接返回错误
                    {
                        continue;
                    }
                    gpss.RemoveAll();


                    //这里可以进行圆柱简化



                    gpss.AddRange(gEndSide1);
                    gpss.AddRange(gParaSide2);
                    gpss.AddRange(gEndSide2);
                    gpss.AddRange(gParaSide1);


                    //是否齐头圆柱,即没有切过的圆柱,如果齐圆柱头,特殊处理,此处暂时不变,



                    //

                    half = gpss.Count / 2;

                    vdpOut.VertexList = gpss;
                    vdpOut.FaceList   = new Int32Array();

                    for (int ii = 1; ii < half; ii++)
                    {
                        vdpOut.FaceList.Add(ii);
                        vdpOut.FaceList.Add(ii + 1);
                        vdpOut.FaceList.Add(gpss.Count - (ii + 1) + 1);
                        vdpOut.FaceList.Add(gpss.Count - ii + 1);
                        vdpOut.FaceList.Add(-1);
                    }


                    vdp.FaceList   = vdpOut.FaceList;
                    vdp.VertexList = vdpOut.VertexList;
                    //vdp.Invalidate();
                    //vdp.Update();

                    break;
                }
            }


            //找到两个顶边,如果多个就扔掉了。

            //GetNonParaSide(vdp.VertexList, i32, orign, vector);
            return(true);
            //Int32Array side1=
        }
コード例 #17
0
        public void Convert(string outFileName)
        {
            SetProgress(5);
            Dictionary <string, bool> kvs = new Dictionary <string, bool>();

            int ipr   = 0;
            int count = doc.Blocks.Count;

            foreach (vdBlock vdb in doc.Blocks)   //处理块中的面片
            {
                ipr++;

                foreach (vdFigure vdf1 in vdb.Entities)
                {
                    if (vdf1 is vdPolyface)
                    {
                        vdPolyface vdff = vdf1 as vdPolyface;
                        bool       ret  = GetVDPBorderLine(vdff, null); //处理圆柱
                        if (!ret)
                        {
                            Merge3DFace(vdff);    //合并面片到四边形
                        }
                    }
                }


                //while (true)   //合并圆柱体
                //{
                //    vdArray< vdFigure> tmps=new vdArray<vdFigure>();
                //    for (int i = 0; i < vdb.Entities.Count; i++)
                //    {
                //        vdFigure vdf = vdb.Entities[i];
                //        if (vdf is vdPolyface)
                //        {
                //            vdPolyface vdff1 = vdf as vdPolyface;
                //            for (int j = 0; j < vdb.Entities.Count; j++)
                //            {
                //                if (vdb.Entities[j] is vdPolyface)
                //                {
                //                    vdPolyface vdff2 = vdb.Entities[j] as vdPolyface;

                //                    vdff1.MergePolyface(vdff2);
                //                }

                //            }
                //        }
                //    }
                //}


                SetProgress(5 + (ipr * 65) / count);
            }


            ipr = 0;
            foreach (vdFigure vdf in doc.ActiveLayOut.Entities)  //合并处理处理当前的面片
            {
                ipr++;

                for (int i = vdf.XProperties.Count - 1; i >= 0; i--)
                {
                    vdXProperty vdx = vdf.XProperties[i];
                    if (vdx.Name.StartsWith("CylinderFaceData") || vdx.Name.StartsWith("POINTVECTOR"))
                    {
                        vdf.XProperties.RemoveItem(vdx);
                    }
                }

                if (vdf is vdPolyface)
                {
                    kvs.Clear();
                    vdPolyface vdp = vdf as vdPolyface;


                    bool ret = GetVDPBorderLine(vdp, vdp);   //处理圆柱体

                    if (!ret)
                    {
                        Merge3DFace(vdp);   //合并到四边形
                    }
                }

                SetProgress(70 + (ipr * 30) / doc.ActiveLayOut.Entities.Count);
            }

            //圆柱片试图合并成圆柱

            doc.Purge();
            SaveAs(outFileName);

            MessageBox.Show("转化已完成!");
        }