Exemple #1
0
 public LDSide(LDSide side)
 {
     LDSideSet(side.nodeNumber, side.point, side.direction, side.isEnd, side.width);
 }
    /// <summary>
    /// This procedure contains the user code. Input parameters are provided as regular arguments,
    /// Output parameters as ref arguments. You don't have to assign output parameters,
    /// they will have a default value.
    /// </summary>
    private void RunScript(List <Line> lines_in, double tolerance, double width, double deviation, double angle, int n_u, int n_v, bool zbool, ref object P, ref object LP, ref object PP, ref object PL, ref object lines, ref object ends, ref object connect, ref object brep, ref object M, ref object F, ref object U, ref object V)
    {
        //OUT data
        List <Point3d> points         = new List <Point3d>();
        DataTree <int> lineVertex     = new DataTree <int>();
        DataTree <int> vertexVertexes = new DataTree <int>();
        DataTree <int> vertexLine     = new DataTree <int>();

        List <Line>     linesOut    = new List <Line>();
        DataTree <Line> linesBranch = new DataTree <Line>();
        bool            isEnd;
        List <Line>     linesEnd = new List <Line>();

        List <LDPanel> panels = new List <LDPanel>();

        ///BEGIN TEST INPUTS
        if (lines_in == null)
        {
            return;
        }

        if (lines_in.Count < 1)
        {
            this.Component.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "There must be more than 1 line");
            return;
        }
        LineTopology(lines_in, tolerance, ref points, ref lineVertex, ref vertexVertexes, ref vertexLine);


        for (int i = 0; i < lineVertex.BranchCount; i++)
        {
            Line   lineOut = new Line();
            LDSide side1   = new LDSide();
            LDSide side2   = new LDSide();

            lineOut = LinePerp(points, lineVertex, vertexVertexes, true, true, i, width, out isEnd);
            if (isEnd)
            {
                linesEnd.Add(lineOut);
            }
            linesBranch.Add(lineOut, new GH_Path(i * 2));
            side1 = new LDSide(lineVertex.Branch(i)[1], points[lineVertex.Branch(i)[1]], lineOut.Direction, isEnd);

            lineOut = LinePerp(points, lineVertex, vertexVertexes, false, false, i, width, out isEnd);
            if (isEnd)
            {
                linesEnd.Add(lineOut);
            }
            linesBranch.Add(lineOut, new GH_Path(i * 2));
            side2 = new LDSide(lineVertex.Branch(i)[0], points[lineVertex.Branch(i)[0]], lineOut.Direction, isEnd);
            panels.Add(new LDPanel(side1, side2, i));

            lineOut = LinePerp(points, lineVertex, vertexVertexes, false, true, i, width, out isEnd);
            if (isEnd)
            {
                linesEnd.Add(lineOut);
            }
            linesBranch.Add(lineOut, new GH_Path(i * 2 + 1));
            side1 = new LDSide(lineVertex.Branch(i)[0], points[lineVertex.Branch(i)[0]], lineOut.Direction, isEnd);

            lineOut = LinePerp(points, lineVertex, vertexVertexes, true, false, i, width, out isEnd);
            if (isEnd)
            {
                linesEnd.Add(lineOut);
            }
            linesBranch.Add(lineOut, new GH_Path(i * 2 + 1));
            side2 = new LDSide(lineVertex.Branch(i)[1], points[lineVertex.Branch(i)[1]], lineOut.Direction, isEnd);
            panels.Add(new LDPanel(side1, side2, i));
        }

        DataTree <LDPanel> treePanels = new DataTree <LDPanel>();
        DataTree <int>     treeInt    = new DataTree <int>();

        int test   = 0;
        int branch = 0;

        while ((panels.Count > 0) && (test < 100))
        {
            treePanels.Add(panels[0], new GH_Path(branch));
            treeInt.Add(panels[0].lineNumber, new GH_Path(branch));
            panels.RemoveAt(0);

            int intersections = 0;
            do
            {
                List <LDPanel> intPanels = GetIntersections(treePanels.Branch(branch), panels);
                intersections = intPanels.Count;
                for (int i = (intPanels.Count - 1); i >= 0; i--)
                {
                    treePanels.Add(intPanels[i], new GH_Path(branch));
                    treeInt.Add(intPanels[i].lineNumber, new GH_Path(branch));
                    panels.Remove(intPanels[i]);
                }
            } while (intersections > 0);
            test   += 1;
            branch += 1;
        }
        DataTree <Brep> brepTree = new DataTree <Brep>();

        for (int i = 0; i < treePanels.BranchCount; i++)
        {
            for (int j = 0; j < treePanels.Branch(i).Count; j++)
            {
                brepTree.Add(treePanels.Branch(i)[j].ToBrep(), new GH_Path(i));
            }
        }
        DataTree <Mesh>      meshTree    = new DataTree <Mesh>();
        List <Point3d>       fixedPoints = new List <Point3d>();
        DataTree <LineCurve> listUCurves = new DataTree <LineCurve> ();
        DataTree <LineCurve> listVCurves = new DataTree <LineCurve> ();

        for (int i = 0; i < treePanels.BranchCount; i++)
        {
            for (int j = 0; j < treePanels.Branch(i).Count; j++)
            {
                meshTree.Add(treePanels.Branch(i)[j].ToMesh(n_u, n_v, angle, width, ref fixedPoints, ref listUCurves, ref listVCurves, deviation, zbool), new GH_Path(i));
            }
        }
        P       = points;
        LP      = lineVertex;
        PP      = vertexVertexes;
        PL      = vertexLine;
        lines   = linesBranch;
        ends    = linesEnd;
        connect = treeInt;
        brep    = brepTree;
        M       = meshTree;
        F       = fixedPoints;
        U       = listUCurves;
        V       = listVCurves;
    }
Exemple #3
0
 public LDPanel(LDSide s1, LDSide s2, int line)
 {
     side1      = s1;
     side2      = s2;
     lineNumber = line;
 }
    /// <summary>
    /// This procedure contains the user code. Input parameters are provided as regular arguments,
    /// Output parameters as ref arguments. You don't have to assign output parameters,
    /// they will have a default value.
    /// </summary>
    private void RunScript(List <Line> lines_in, double tolerance, List <double> width_b, List <double> width_e, double deviation, double angle, int n_u, int n_v, bool zbool, ref object P, ref object LP, ref object PP, ref object PL, ref object lines, ref object ends, ref object connect, ref object brep, ref object M, ref object F, ref object U, ref object V)
    {
        //v02
        //Add variable width per lines
        //V03
        //Suppression of limitation in number of run of the while
        //Test of n_u and n_v in order to be no less than 2
        //

        //OUT data
        List <Point3d> points         = new List <Point3d>();
        DataTree <int> lineVertex     = new DataTree <int>();
        DataTree <int> vertexVertexes = new DataTree <int>();
        DataTree <int> vertexLine     = new DataTree <int>();

        List <Line>     linesOut    = new List <Line>();
        DataTree <Line> linesBranch = new DataTree <Line>();
        bool            isEnd;
        List <Line>     linesEnd = new List <Line>();

        List <LDPanel> panels     = new List <LDPanel>();
        double         width_calc = 0.0;

        ///BEGIN TEST INPUTS
        if (lines_in == null)
        {
            return;
        }

        if (lines_in.Count < 1)
        {
            this.Component.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "There must be more than 1 line");
            return;
        }
        LineTopology(lines_in, tolerance, ref points, ref lineVertex, ref vertexVertexes, ref vertexLine);

        //v0.2
        if (width_b.Count < lines_in.Count)
        {
            int size_width = width_b.Count;

            for (int i = size_width; i <= lines_in.Count; i++)
            {
                width_b.Add(width_b[size_width - 1]);
            }
        }

        if (width_e.Count < lines_in.Count)
        {
            int size_width = width_e.Count;

            for (int i = size_width; i <= lines_in.Count; i++)
            {
                width_e.Add(width_e[size_width - 1]);
            }
        }
        //v0.2
        if (n_u < 2)
        {
            n_u = 2;
        }
        if (n_v < 2)
        {
            n_v = 2;
        }

        //For all lines
        for (int i = 0; i < lineVertex.BranchCount; i++)
        {
            Line   lineOut = new Line();
            LDSide side1   = new LDSide();
            LDSide side2   = new LDSide();

            //One side of the line
            lineOut = LinePerp(points, lineVertex, vertexVertexes, true, true, i, width_b, width_e, out isEnd, out width_calc);
            if (isEnd)
            {
                linesEnd.Add(lineOut);
            }
            linesBranch.Add(lineOut, new GH_Path(i * 2));
            side1 = new LDSide(lineVertex.Branch(i)[1], points[lineVertex.Branch(i)[1]], lineOut.Direction, isEnd, width_calc);

            lineOut = LinePerp(points, lineVertex, vertexVertexes, false, false, i, width_b, width_e, out isEnd, out width_calc);
            if (isEnd)
            {
                linesEnd.Add(lineOut);
            }
            linesBranch.Add(lineOut, new GH_Path(i * 2));
            side2 = new LDSide(lineVertex.Branch(i)[0], points[lineVertex.Branch(i)[0]], lineOut.Direction, isEnd, width_calc);
            panels.Add(new LDPanel(side1, side2, i));

            //Other side of the line
            lineOut = LinePerp(points, lineVertex, vertexVertexes, false, true, i, width_b, width_e, out isEnd, out width_calc);
            if (isEnd)
            {
                linesEnd.Add(lineOut);
            }
            linesBranch.Add(lineOut, new GH_Path(i * 2 + 1));
            side1 = new LDSide(lineVertex.Branch(i)[0], points[lineVertex.Branch(i)[0]], lineOut.Direction, isEnd, width_calc);

            lineOut = LinePerp(points, lineVertex, vertexVertexes, true, false, i, width_b, width_e, out isEnd, out width_calc);
            if (isEnd)
            {
                linesEnd.Add(lineOut);
            }
            linesBranch.Add(lineOut, new GH_Path(i * 2 + 1));
            side2 = new LDSide(lineVertex.Branch(i)[1], points[lineVertex.Branch(i)[1]], lineOut.Direction, isEnd, width_calc);
            panels.Add(new LDPanel(side1, side2, i));
        }

        DataTree <LDPanel> treePanels = new DataTree <LDPanel>();
        DataTree <int>     treeInt    = new DataTree <int>();

        int test   = 0;
        int branch = 0;

        while (panels.Count > 0)
        {
            treePanels.Add(panels[0], new GH_Path(branch));
            treeInt.Add(panels[0].lineNumber, new GH_Path(branch));
            panels.RemoveAt(0);

            int intersections = 0;
            do
            {
                List <LDPanel> intPanels = GetIntersections(treePanels.Branch(branch), panels);
                intersections = intPanels.Count;
                for (int i = (intPanels.Count - 1); i >= 0; i--)
                {
                    treePanels.Add(intPanels[i], new GH_Path(branch));
                    treeInt.Add(intPanels[i].lineNumber, new GH_Path(branch));
                    panels.Remove(intPanels[i]);
                }
            } while (intersections > 0);
            test   += 1;
            branch += 1;
        }
        DataTree <Brep> brepTree = new DataTree <Brep>();

        for (int i = 0; i < treePanels.BranchCount; i++)
        {
            for (int j = 0; j < treePanels.Branch(i).Count; j++)
            {
                brepTree.Add(treePanels.Branch(i)[j].ToBrep(), new GH_Path(i));
            }
        }
        DataTree <Mesh>      meshTree    = new DataTree <Mesh>();
        List <Point3d>       fixedPoints = new List <Point3d>();
        DataTree <LineCurve> listUCurves = new DataTree <LineCurve> ();
        DataTree <LineCurve> listVCurves = new DataTree <LineCurve> ();

        for (int i = 0; i < treePanels.BranchCount; i++)
        {
            for (int j = 0; j < treePanels.Branch(i).Count; j++)
            {
                //meshTree.Add(treePanels.Branch(i)[j].ToMesh(n_u, n_v, angle, width_b[0], ref fixedPoints, ref listUCurves, ref  listVCurves, deviation, zbool), new GH_Path(i));
                meshTree.Add(treePanels.Branch(i)[j].ToMesh(n_u, n_v, angle, ref fixedPoints, ref listUCurves, ref listVCurves, deviation, zbool), new GH_Path(i));
            }
        }
        P       = points;
        LP      = lineVertex;
        PP      = vertexVertexes;
        PL      = vertexLine;
        lines   = linesBranch;
        ends    = linesEnd;
        connect = treeInt;
        brep    = brepTree;
        M       = meshTree;
        F       = fixedPoints;
        U       = listUCurves;
        V       = listVCurves;
    }