public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args)
        {
            if (SelectedIndex < 0)
            {
                throw new Exception("Please select a mesh node.");
            }

            var node_name = Items[SelectedIndex].Name;

            //             if (InPorts[0].IsConnected)
            //             {
            //                 // send the to the connected node
            //                 return FScheme.Value.NewString(node_name);
            //             }

            var result = FSharpList <FScheme.Value> .Empty;

            if (OutPorts[0].IsConnected)
            {
                // get the data from the connected node
                DynamoMaya.Contract.IService s        = MayaCommunication.openChannelToMaya();
                Point3DCollection            vertices = s.receiveVertexPositionsFromMaya(node_name);

                foreach (Point3D v in vertices)
                {
                    XYZ pt = new XYZ(v.X, v.Y, v.Z);
                    result = FSharpList <FScheme.Value> .Cons(FScheme.Value.NewContainer(pt), result);
                }

                MayaCommunication.closeChannelToMaya(s);
            }

            return(FScheme.Value.NewList(ListModule.Reverse(result)));
        }
예제 #2
0
파일: UV.cs 프로젝트: jimmplan/Dynamo
        public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args)
        {
            var    domain = (DSCoreNodes.Domain2D)((FScheme.Value.Container)args[0]).Item;
            double ui     = ((FScheme.Value.Number)args[1]).Item;
            double vi     = ((FScheme.Value.Number)args[2]).Item;
            double us     = domain.USpan / ui;
            double vs     = domain.VSpan / vi;

            FSharpList <FScheme.Value> result = FSharpList <FScheme.Value> .Empty;

            for (int i = 0; i <= ui; i++)
            {
                double u = domain.Min.x() + i * us;

                for (int j = 0; j <= vi; j++)
                {
                    double v = domain.Min.y() + j * vs;

                    result = FSharpList <FScheme.Value> .Cons(
                        FScheme.Value.NewContainer(new UV(u, v)),
                        result
                        );
                }
            }

            return(FScheme.Value.NewList(
                       ListModule.Reverse(result)
                       ));
        }
예제 #3
0
파일: XYZ.cs 프로젝트: l2obin/Dynamo
        public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args)
        {
            double xi;                                 //, x0, xs;

            xi = ((FScheme.Value.Number)args[1]).Item; // Number
            xi = Math.Round(xi);
            if (xi < System.Double.Epsilon)
            {
                throw new Exception("The point count must be larger than 0.");
            }
            xi = xi - 1;

            //x0 = ((Value.Number)args[2]).Item;// Starting Coord
            //xs = ((Value.Number)args[3]).Item;// Spacing


            var result = FSharpList <FScheme.Value> .Empty;

            Curve crvRef = null;

            if (((FScheme.Value.Container)args[0]).Item is CurveElement)
            {
                var c = (CurveElement)((FScheme.Value.Container)args[0]).Item; // Curve
                crvRef = c.GeometryCurve;
            }
            else
            {
                crvRef = (Curve)((FScheme.Value.Container)args[0]).Item; // Curve
            }

            double t = 0;

            if (xi < System.Double.Epsilon)
            {
                var pt = !XyzOnCurveOrEdge.curveIsReallyUnbound(crvRef) ? crvRef.Evaluate(t, true) : crvRef.Evaluate(t * crvRef.Period, false);
                result = FSharpList <FScheme.Value> .Cons(FScheme.Value.NewContainer(pt), result);

                return(FScheme.Value.NewList(
                           ListModule.Reverse(result)
                           ));
            }

            for (int xCount = 0; xCount <= xi; xCount++)
            {
                t = xCount / xi; // create normalized curve param by dividing current number by total number
                var pt = !XyzOnCurveOrEdge.curveIsReallyUnbound(crvRef) ? crvRef.Evaluate(t, true) : crvRef.Evaluate(t * crvRef.Period, false);
                result = FSharpList <FScheme.Value> .Cons(FScheme.Value.NewContainer(pt), result);
            }

            return(FScheme.Value.NewList(
                       ListModule.Reverse(result)
                       ));
        }
예제 #4
0
파일: XYZ.cs 프로젝트: l2obin/Dynamo
        public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args)
        {
            double xi, yi, zi, x0, y0, z0, xs, ys, zs;

            xi = ((FScheme.Value.Number)args[0]).Item;
            yi = ((FScheme.Value.Number)args[1]).Item;
            zi = ((FScheme.Value.Number)args[2]).Item;
            x0 = ((FScheme.Value.Number)args[3]).Item;
            y0 = ((FScheme.Value.Number)args[4]).Item;
            z0 = ((FScheme.Value.Number)args[5]).Item;
            xs = ((FScheme.Value.Number)args[6]).Item;
            ys = ((FScheme.Value.Number)args[7]).Item;
            zs = ((FScheme.Value.Number)args[8]).Item;

            FSharpList <FScheme.Value> result = FSharpList <FScheme.Value> .Empty;

            double z = z0;

            for (int zCount = 0; zCount < zi; zCount++)
            {
                double y = y0;
                for (int yCount = 0; yCount < yi; yCount++)
                {
                    double x = x0;
                    for (int xCount = 0; xCount < xi; xCount++)
                    {
                        XYZ pt = new XYZ(x, y, z);

                        result = FSharpList <FScheme.Value> .Cons(
                            FScheme.Value.NewContainer(pt),
                            result
                            );

                        x += xs;
                    }
                    y += ys;
                }
                z += zs;
            }

            return(FScheme.Value.NewList(
                       ListModule.Reverse(result)
                       ));
        }
예제 #5
0
파일: UV.cs 프로젝트: jimmplan/Dynamo
        public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args)
        {
            double ui, vi;

            var domain = (DSCoreNodes.Domain2D)((FScheme.Value.Container)args[0]).Item;

            ui = ((FScheme.Value.Number)args[1]).Item;
            vi = ((FScheme.Value.Number)args[2]).Item;

            FSharpList <FScheme.Value> result = FSharpList <FScheme.Value> .Empty;

            //UV min = ((Value.Container)domain[0]).Item as UV;
            //UV max = ((Value.Container)domain[1]).Item as UV;

            var min = new UV(domain.Min.x(), domain.Min.y());
            var max = new UV(domain.Max.x(), domain.Max.y());

            var    r     = new System.Random();
            double uSpan = max.U - min.U;
            double vSpan = max.V - min.V;

            for (int i = 0; i < ui; i++)
            {
                for (int j = 0; j < vi; j++)
                {
                    result = FSharpList <FScheme.Value> .Cons(
                        FScheme.Value.NewContainer(new UV(min.U + r.NextDouble() * uSpan, min.V + r.NextDouble() * vSpan)),
                        result
                        );
                }
            }

            return(FScheme.Value.NewList(
                       ListModule.Reverse(result)
                       ));
        }
예제 #6
0
 IEnumerator <KeyValuePair <K, V> > IEnumerable <KeyValuePair <K, V> > .GetEnumerator()
 {
     return(((IEnumerable <KeyValuePair <K, V> >)SeqModule.Map <Tuple <K, V>, KeyValuePair <K, V> >((FSharpFunc <M0, M1>) new SeriesExtensions.System\u002DCollections\u002DGeneric\u002DIEnumerable\u002DGetEnumerator <K, V>(), (IEnumerable <M0>)ListModule.Reverse <Tuple <K, V> >((FSharpList <M0>)ListModule.Zip <K, V>((FSharpList <M0>) this.keys, (FSharpList <M1>) this.values)))).GetEnumerator());
 }
예제 #7
0
 IEnumerator <KeyValuePair <R, ISeries <C> > > IEnumerable <KeyValuePair <R, ISeries <C> > > .GetEnumerator()
 {
     return(((IEnumerable <KeyValuePair <R, ISeries <C> > >)SeqModule.Map <Tuple <R, ISeries <C> >, KeyValuePair <R, ISeries <C> > >((FSharpFunc <M0, M1>) new FrameBuilder.System\u002DCollections\u002DGeneric\u002DIEnumerable\u002DGetEnumerator <R, C>(), (IEnumerable <M0>)ListModule.Reverse <Tuple <R, ISeries <C> > >((FSharpList <M0>) this.series))).GetEnumerator());
 }
예제 #8
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            double xi;                         //, x0, xs;

            xi = ((Value.Number)args[1]).Item; // Number
            xi = Math.Round(xi);
            if (xi < Double.Epsilon)
            {
                throw new Exception("The point count must be larger than 0.");
            }

            //x0 = ((Value.Number)args[2]).Item;// Starting Coord
            //xs = ((Value.Number)args[3]).Item;// Spacing


            var result = FSharpList <Value> .Empty;

            Curve crvRef = null;

            if (((Value.Container)args[0]).Item is CurveElement)
            {
                var c = (CurveElement)((Value.Container)args[0]).Item; // Curve
                crvRef = c.GeometryCurve;
            }
            else
            {
                crvRef = (Curve)((Value.Container)args[0]).Item; // Curve
            }

            double t = 0.0;

            XYZ startPoint = !dynXYZOnCurveOrEdge.curveIsReallyUnbound(crvRef) ? crvRef.Evaluate(t, true) : crvRef.Evaluate(t * crvRef.Period, false);

            result = FSharpList <Value> .Cons(Value.NewContainer(startPoint), result);

            pts.Add(startPoint);

            t = 1.0;
            XYZ endPoint = !dynXYZOnCurveOrEdge.curveIsReallyUnbound(crvRef) ? crvRef.Evaluate(t, true) : crvRef.Evaluate(t * crvRef.Period, false);

            if (xi > 2.0 + Double.Epsilon)
            {
                int numParams = Convert.ToInt32(xi - 2.0);

                var curveParams = new List <double>();

                for (int ii = 0; ii < numParams; ii++)
                {
                    curveParams.Add((ii + 1.0) / (xi - 1.0));
                }

                int  maxIterNum = 15;
                bool bUnbound   = dynXYZOnCurveOrEdge.curveIsReallyUnbound(crvRef);

                int iterNum = 0;
                for (; iterNum < maxIterNum; iterNum++)
                {
                    XYZ prevPoint = startPoint;
                    XYZ thisXYZ   = null;
                    XYZ nextXYZ   = null;

                    Vector <double> distValues = DenseVector.Create(numParams, (c) => 0.0);

                    Matrix <double> iterMat    = DenseMatrix.Create(numParams, numParams, (r, c) => 0.0);
                    double          maxDistVal = -1.0;
                    for (int iParam = 0; iParam < numParams; iParam++)
                    {
                        t = curveParams[iParam];

                        if (nextXYZ != null)
                        {
                            thisXYZ = nextXYZ;
                        }
                        else
                        {
                            thisXYZ = !bUnbound?crvRef.Evaluate(t, true) : crvRef.Evaluate(t * crvRef.Period, false);
                        }

                        double tNext = (iParam == numParams - 1) ?  1.0 : curveParams[iParam + 1];
                        nextXYZ = (iParam == numParams - 1) ? endPoint :
                                  !bUnbound?crvRef.Evaluate(tNext, true) : crvRef.Evaluate(tNext * crvRef.Period, false);

                        distValues[iParam] = thisXYZ.DistanceTo(prevPoint) - thisXYZ.DistanceTo(nextXYZ);

                        if (Math.Abs(distValues[iParam]) > maxDistVal)
                        {
                            maxDistVal = Math.Abs(distValues[iParam]);
                        }
                        Transform thisDerivTrf = !bUnbound?crvRef.ComputeDerivatives(t, true) : crvRef.ComputeDerivatives(t * crvRef.Period, false);

                        XYZ derivThis = thisDerivTrf.BasisX;
                        if (bUnbound)
                        {
                            derivThis = derivThis.Multiply(crvRef.Period);
                        }
                        double distPrev = thisXYZ.DistanceTo(prevPoint);
                        if (distPrev > Double.Epsilon)
                        {
                            double valDeriv = (thisXYZ - prevPoint).DotProduct(derivThis) / distPrev;
                            iterMat[iParam, iParam] += valDeriv;
                            if (iParam > 0)
                            {
                                iterMat[iParam - 1, iParam] -= valDeriv;
                            }
                        }
                        double distNext = thisXYZ.DistanceTo(nextXYZ);
                        if (distNext > Double.Epsilon)
                        {
                            double valDeriv = (thisXYZ - nextXYZ).DotProduct(derivThis) / distNext;

                            iterMat[iParam, iParam] -= valDeriv;
                            if (iParam < numParams - 1)
                            {
                                iterMat[iParam + 1, iParam] += valDeriv;
                            }
                        }
                        prevPoint = thisXYZ;
                    }

                    Matrix <double> iterMatInvert = iterMat.Inverse();
                    Vector <double> changeValues  = iterMatInvert.Multiply(distValues);

                    double dampingFactor = 1.0;

                    for (int iParam = 0; iParam < numParams; iParam++)
                    {
                        curveParams[iParam] -= dampingFactor * changeValues[iParam];

                        if (iParam == 0 && curveParams[iParam] < 0.000000001)
                        {
                            double oldValue = dampingFactor * changeValues[iParam] + curveParams[iParam];
                            while (curveParams[iParam] < 0.000000001)
                            {
                                curveParams[iParam] = 0.5 * (dampingFactor * changeValues[iParam] + curveParams[iParam]);
                            }
                            changeValues[iParam] = (oldValue - curveParams[iParam]) / dampingFactor;
                        }
                        else if (iParam > 0 && curveParams[iParam] < 0.000000001 + curveParams[iParam - 1])
                        {
                            for (; iParam > -1; iParam--)
                            {
                                curveParams[iParam] = dampingFactor * changeValues[iParam] + curveParams[iParam];
                            }

                            dampingFactor *= 0.5;
                            continue;
                        }
                        else if (iParam == numParams - 1 && curveParams[iParam] > 1.0 - 0.000000001)
                        {
                            double oldValue = dampingFactor * changeValues[iParam] + curveParams[iParam];
                            while (curveParams[iParam] > 1.0 - 0.000000001)
                            {
                                curveParams[iParam] = 0.5 * (1.0 + dampingFactor * changeValues[iParam] + curveParams[iParam]);
                            }
                            changeValues[iParam] = (oldValue - curveParams[iParam]) / dampingFactor;
                        }
                    }
                    if (maxDistVal < 0.000000001)
                    {
                        for (int iParam = 0; iParam < numParams; iParam++)
                        {
                            t       = curveParams[iParam];
                            thisXYZ = !dynXYZOnCurveOrEdge.curveIsReallyUnbound(crvRef) ? crvRef.Evaluate(t, true) : crvRef.Evaluate(t * crvRef.Period, false);
                            result  = FSharpList <Value> .Cons(Value.NewContainer(thisXYZ), result);

                            pts.Add(thisXYZ);
                        }
                        break;
                    }
                }

                if (iterNum == maxIterNum)
                {
                    throw new Exception("could not solve for equal distances");
                }
            }

            if (xi > 1.0 + Double.Epsilon)
            {
                result = FSharpList <Value> .Cons(Value.NewContainer(endPoint), result);

                pts.Add(endPoint);
            }
            return(Value.NewList(
                       ListModule.Reverse(result)
                       ));
        }
예제 #9
0
        public static Tuple <a, BinomialHeap <a> > removeMin <a>(BinomialHeap <a> _arg1)
        {
            BinomialHeap <a>             binomialHeap = _arg1;
            FSharpList <RankedTree <a> > heap         = binomialHeap.Heap;
            IComparer <a> comparer = binomialHeap.Comparer;
            Tuple <RankedTree <a>, FSharpList <RankedTree <a> > > tuple = BinomialHeap.removeMinTree <a>(comparer, heap);
            a a = tuple.Item1.item2;
            FSharpList <RankedTree <a> > fsharpList1 = tuple.Item2;
            FSharpList <RankedTree <a> > fsharpList2 = tuple.Item1.item3;

            return(new Tuple <a, BinomialHeap <a> >(a, new BinomialHeap <a>(comparer, BinomialHeap.mergeTrees <a>(comparer, (FSharpList <RankedTree <a> >)ListModule.Reverse <RankedTree <a> >((FSharpList <M0>)fsharpList2), fsharpList1))));
        }