Exemplo n.º 1
0
        public ContourStitcher(ContourLine line1, ContourLine line2)
        {
            if (line1.GetZ() > line2.GetZ())
            {
                lineUp   = line1;
                lineDown = line2;
            }
            else
            {
                lineUp   = line2;
                lineDown = line1;
            }
            lineUpProcessed   = new List <FloatDouble>(lineUp.GetLinePointCount());
            lineDownProcessed = new List <FloatDouble>(lineDown.GetLinePointCount());
            CopyArray(lineUp.GetPointList(), lineUpProcessed);
            CopyArray(lineDown.GetPointList(), lineDownProcessed);
            boxUp   = lineUp.GetBox();
            boxDown = lineDown.GetBox();
            Point3d cU = boxUp.GetCenter();
            Point3d cD = boxDown.GetCenter();

            ContourLineSurfaceGenerator.Transform(lineDownProcessed, -cD.X, -cD.Y);
            ContourLineSurfaceGenerator.Transform(lineUpProcessed, -cU.X, -cU.Y);
            int indexDown = GetNearIndex();

            AdjustDownArray(indexDown);
        }
Exemplo n.º 2
0
        public Box3Float GetBox()
        {
            Box3Float box = new Box3Float();

            for (int i = 0; i < points.Count; i++)
            {
                box.UpdataRange(points[i].X, points[i].Y, 0);
            }
            return(box);
        }
        private void FillUpHole(Mesh m, List <int>[] maps, List <FloatDouble> upContourPrcessed, Box3Float boxU)
        {
            Transform(upContourPrcessed, boxU.GetCenter().X, boxU.GetCenter().Y);
            List <Triangle> up = new List <Triangle>();

            PolyTriangulator.Process(upContourPrcessed, up);
            if (!IsNormalZ2(upContourPrcessed, up))
            {
                ReverseNormal(up);
            }
            for (int i = 0; i < up.Count; i++)
            {
                Triangle t = up[i];
                t.P0Index = maps[lines.Count - 1][t.P0Index];
                t.P1Index = maps[lines.Count - 1][t.P1Index];
                t.P2Index = maps[lines.Count - 1][t.P2Index];
                m.AddFace(t);
            }
        }
        public Mesh GenerateSurface()
        {
            if (lines.Count <= 1)
            {
                return(null);
            }
            lines.Sort();
            for (int i = 0; i < lines.Count; i++)
            {
                List <FloatDouble> linepoints = lines[i].GetPointList();
                if (0.0f > PolyTriangulator.Area(linepoints))
                {
                    ReverseArray(linepoints);
                }
            }

            Mesh m = new Mesh();

            List <int>[] maps = new List <int> [lines.Count];
            for (int i = 0; i < maps.Length; i++)
            {
                maps[i] = new List <int>();
                for (int j = 0; j < lines[i].GetLinePointCount(); j++)
                {
                    maps[i].Add(-1);
                }
            }
            List <FloatDouble> upContourPrcessed = null;
            Box3Float          boxU = lines[lines.Count - 1].GetBox();
            List <FloatDouble> downContourPrcessed = null;
            Box3Float          boxD = lines[0].GetBox();

            for (int i = 0; i < lines.Count - 1; i++)
            {
                ContourStitcher cs = new ContourStitcher(lines[i], lines[i + 1]);
                if (i == 0)
                {
                    downContourPrcessed = cs.lineDownProcessed;
                }
                if (i == lines.Count - 2)
                {
                    upContourPrcessed = cs.lineUpProcessed;
                }
                Mesh submesh = cs.DoStitching();
                //PlyManager.Output(submesh, i+"_.ply");
                int Z0Count = lines[i].GetLinePointCount();
                int Z2Count = lines[i + 1].GetLinePointCount();
                if (submesh.Vertices.Count != Z0Count + Z2Count)
                {
                    throw new Exception();
                }
                for (int j = 0; j < Z0Count; j++)
                {
                    if (maps[i][j] == -1)
                    {
                        maps[i][j] = m.AddVertex(submesh.Vertices[j]);
                    }
                }
                for (int j = 0; j < Z2Count; j++)
                {
                    maps[i + 1][j] = m.AddVertex(submesh.Vertices[j + Z0Count]);
                }
                for (int j = 0; j < submesh.Faces.Count; j++)
                {
                    Triangle t = submesh.Faces[j];
                    if (t.P0Index < Z0Count)
                    {
                        t.P0Index = maps[i][t.P0Index];
                    }
                    else
                    {
                        t.P0Index = maps[i + 1][t.P0Index - Z0Count];
                    }

                    if (t.P1Index < Z0Count)
                    {
                        t.P1Index = maps[i][t.P1Index];
                    }
                    else
                    {
                        t.P1Index = maps[i + 1][t.P1Index - Z0Count];
                    }

                    if (t.P2Index < Z0Count)
                    {
                        t.P2Index = maps[i][t.P2Index];
                    }
                    else
                    {
                        t.P2Index = maps[i + 1][t.P2Index - Z0Count];
                    }
                    m.AddFace(t);
                }
            }
            FillUpHole(m, maps, upContourPrcessed, boxU);
            FillDownHole(m, maps, downContourPrcessed, boxD);
            return(m);
        }
        private void FillDownHole(Mesh m, List <int>[] maps, List <FloatDouble> downContourPrcessed, Box3Float boxD)
        {
            Transform(downContourPrcessed, boxD.GetCenter().X, boxD.GetCenter().Y);
            List <Triangle> down = new List <Triangle>();

            PolyTriangulator.Process(downContourPrcessed, down);
            if (IsNormalZ2(downContourPrcessed, down))
            {
                ReverseNormal(down);
            }
            for (int i = 0; i < down.Count; i++)
            {
                Triangle t = down[i];
                t.P0Index = maps[0][t.P0Index];
                t.P1Index = maps[0][t.P1Index];
                t.P2Index = maps[0][t.P2Index];
                m.AddFace(t);
            }
        }