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);
        }
        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);
            }
        }
        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);
            }
        }
        public Mesh DoStitching()
        {
            Mesh m = new Mesh();

            int[] upMap = new int[lineUpProcessed.Count];
            float dx1   = boxUp.GetCenter().X;
            float dy1   = boxUp.GetCenter().Y;
            float dx2   = boxDown.GetCenter().X;
            float dy2   = boxDown.GetCenter().Y;

            int[] downMap = new int[lineDownProcessed.Count];
            for (int i = 0; i < lineDownProcessed.Count; i++)
            {
                Point3d p = new Point3d(lineDownProcessed[i].X + dx2, lineDownProcessed[i].Y + dy2, lineDown.GetZ());
                downMap[i] = m.AddVertex(p);
            }
            for (int i = 0; i < lineUpProcessed.Count; i++)
            {
                Point3d p = new Point3d(lineUpProcessed[i].X + dx1, lineUpProcessed[i].Y + dy1, lineUp.GetZ());
                upMap[i] = m.AddVertex(p);
            }

            int      upIndex   = 0;
            int      downIndex = 0;
            QuadUnit quad      = new QuadUnit();

            quad.lineDown = lineDownProcessed;
            quad.lineUp   = lineUpProcessed;
            while (true)
            {
                if (upIndex == lineUpProcessed.Count - 1 || downIndex == lineDownProcessed.Count - 1)
                {
                    break;
                }
                quad.Init(upIndex, downIndex);
                if (quad.DiaU0D1Len < quad.DiaU1D0Len)
                {
                    Triangle t = new Triangle(upMap[quad.UpIndex0], downMap[quad.DownIndex0], downMap[quad.DownIndex1]);
                    m.AddFace(t);
                    downIndex++;
                }
                else
                {
                    Triangle t = new Triangle(upMap[quad.UpIndex0], downMap[quad.DownIndex0], upMap[quad.UpIndex1]);
                    m.AddFace(t);
                    upIndex++;
                }
            }
            if (upIndex == lineUpProcessed.Count - 1 || downIndex == lineDownProcessed.Count - 1)
            {
                if (downIndex == lineDownProcessed.Count - 1)
                {
                    int last = lineDownProcessed.Count - 1;
                    while (upIndex != lineUpProcessed.Count - 1)
                    {
                        Triangle t = new Triangle(downMap[last], upMap[upIndex + 1], upMap[upIndex]);
                        m.AddFace(t);
                        upIndex++;
                    }
                }
                else
                {
                    int last = lineUpProcessed.Count - 1;
                    while (downIndex != lineDownProcessed.Count - 1)
                    {
                        Triangle t = new Triangle(upMap[last], downMap[downIndex], downMap[downIndex + 1]);
                        m.AddFace(t);
                        downIndex++;
                    }
                }
            }
            quad.InitLast();
            if (quad.DiaU0D1Len < quad.DiaU1D0Len)
            {
                Triangle t  = new Triangle(upMap[quad.UpIndex0], downMap[quad.DownIndex0], downMap[quad.DownIndex1]);
                Triangle t2 = new Triangle(upMap[quad.UpIndex0], downMap[quad.DownIndex1], upMap[quad.UpIndex1]);
                m.AddFace(t);
                m.AddFace(t2);
            }
            else
            {
                Triangle t  = new Triangle(upMap[quad.UpIndex0], downMap[quad.DownIndex0], upMap[quad.UpIndex1]);
                Triangle t2 = new Triangle(upMap[quad.UpIndex1], downMap[quad.DownIndex0], downMap[quad.DownIndex1]);
                m.AddFace(t);
                m.AddFace(t2);
            }
            return(m);
        }