Ejemplo n.º 1
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <Point3d> inPoints = new List <Point3d>();

            if (!DA.GetDataList <Point3d>(0, inPoints))
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, Constants.Constants.INPUT_ERROR_MESSAGE);
            }
            else
            {
                List <double> inMasses = new List <double>();
                DA.GetDataList <double>(1, inMasses);
                ValuesAllocator.MatchLists(inPoints, inMasses);

                Point3d       point3D   = new Point3d(0, 0, 0);
                List <double> distances = new List <double>();
                double        totalMass = 0;
                for (int i = 0; i < inPoints.Count; i++)
                {
                    point3D    = point3D + (inPoints[i] * inMasses[i]);
                    totalMass += inMasses[i];
                }
                Point3d  center   = point3D / totalMass;
                GH_Point ghCenter = new GH_Point(center);
                foreach (Point3d pt in inPoints)
                {
                    distances.Add(ghCenter.Value.DistanceTo(pt));
                }
                DA.SetData(0, ghCenter);
                DA.SetDataList(1, distances);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            InputChecker inputChecker = new InputChecker(this);

            List <Curve> inCurves   = new List <Curve>();
            bool         canGetCrvs = DA.GetDataList <Curve>("Curves", inCurves);

            inputChecker.StopIfConversionIsFailed(canGetCrvs);

            List <Plane> inPlanes     = new List <Plane>();
            bool         canGetPlanes = DA.GetDataList <Plane>("Planes", inPlanes);

            inputChecker.StopIfConversionIsFailed(canGetPlanes);
            ValuesAllocator.MatchLists(inCurves, inPlanes);

            List <Curve> orientedCurves = new List <Curve>();

            for (int i = 0; i < inCurves.Count; i++)
            {
                if (inCurves[i].ClosedCurveOrientation(inPlanes[i]) == CurveOrientation.Clockwise)
                {
                    inCurves[i].Reverse();
                }
                orientedCurves.Add(inCurves[i]);
            }
            DA.SetDataList(0, orientedCurves);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            InputChecker inputChecker = new InputChecker(this);

            #region GetDataFromCanvas
            List <Curve> inCurves     = new List <Curve>();
            bool         canGetCurves = DA.GetDataList <Curve>(0, inCurves);
            inputChecker.StopIfConversionIsFailed(canGetCurves);

            List <int> inCurvesDegree   = new List <int>();
            bool       canGetCrvDegrees = DA.GetDataList <int>(1, inCurvesDegree);
            inputChecker.StopIfConversionIsFailed(canGetCrvDegrees);
            ValuesAllocator.MatchLists(inCurves, inCurvesDegree);

            List <double> inRebuildFactors = new List <double>();
            bool          canGetFactors    = DA.GetDataList <double>(2, inRebuildFactors);
            inputChecker.StopIfConversionIsFailed(canGetFactors);
            ValuesAllocator.MatchLists(inCurves, inRebuildFactors);

            List <bool> inPreserveTan     = new List <bool>();
            bool        canGetPreserveTan = DA.GetDataList <bool>(3, inPreserveTan);
            inputChecker.StopIfConversionIsFailed(canGetPreserveTan);
            ValuesAllocator.MatchLists(inCurves, inPreserveTan);

            bool useParallel = false;
            DA.GetData <bool>(4, ref useParallel);
            #endregion

            Curve[]  curves         = inCurves.ToArray();
            int[]    curvesDegree   = inCurvesDegree.ToArray();
            double[] rebuildFactors = inRebuildFactors.ToArray();
            bool[]   preserveTan    = inPreserveTan.ToArray();
            ConcurrentDictionary <int, Curve> rebuildedCurves = new ConcurrentDictionary <int, Curve>();
            if (!useParallel)
            {
                this.Message = Constants.Constants.SERIAL_MESSAGE;
                for (int i = 0; i < (int)curves.Length; i++)
                {
                    CurvesOptimizer.RebuildProportionally(i, curves, curvesDegree, rebuildFactors, preserveTan, rebuildedCurves);
                }
            }
            else
            {
                this.Message = Constants.Constants.PARALLEL_MESSAGE;
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, Constants.Constants.PARALLEL_WARNING);

                int processorCount = Environment.ProcessorCount - 1;;
                Parallel.For(0, curves.Length, new ParallelOptions {
                    MaxDegreeOfParallelism = processorCount
                },
                             i =>
                             CurvesOptimizer.RebuildProportionally(i, curves, curvesDegree, rebuildFactors, preserveTan, rebuildedCurves)
                             );
            }
            List <Curve> curves1 = new List <Curve>();
            curves1.AddRange(rebuildedCurves.Values);
            DA.SetDataList(0, curves1);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            InputChecker inputChecker = new InputChecker(this);

            List <Curve>  inCurves = new List <Curve>();
            List <double> inThres  = new List <double>();
            bool          succes   = DA.GetDataList <Curve>(0, inCurves) && DA.GetDataList <double>(1, inThres);

            inputChecker.StopIfConversionIsFailed(succes);
            ValuesAllocator.MatchLists(inCurves, inThres);

            List <Curve> culledCrvs = CurveProcessor.CullShortCrv(inCurves, inThres);

            #region SendOutputsToCanvas

            DA.SetDataList(0, culledCrvs);

            #endregion
        }
Ejemplo n.º 5
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            InputChecker inputChecker = new InputChecker(this);

            #region GetInputsFromCanvas

            List <Point3d> inPts     = new List <Point3d>();
            bool           canGetPts = DA.GetDataList(0, inPts);
            inputChecker.StopIfConversionIsFailed(canGetPts);

            List <Plane> inPlanes   = new List <Plane>();
            bool         canGetPlns = DA.GetDataList(1, inPlanes);
            inputChecker.StopIfConversionIsFailed(canGetPlns);
            ValuesAllocator.MatchLists(inPts, inPlanes);

            List <double> inRange     = new List <double>();
            bool          canGetRange = DA.GetDataList(2, inRange);
            inputChecker.StopIfConversionIsFailed(canGetRange);
            ValuesAllocator.MatchLists(inPts, inRange);

            List <int> inDensity     = new List <int>();
            bool       canGetDensity = DA.GetDataList(3, inDensity);
            inputChecker.StopIfConversionIsFailed(canGetDensity);
            ValuesAllocator.MatchLists(inPts, inDensity);

            Color inFirstColor   = new Color();
            bool  canGetFirstCol = DA.GetData(4, ref inFirstColor);
            inputChecker.StopIfConversionIsFailed(canGetFirstCol);

            Color inSecondColor     = new Color();
            bool  canGetSecondColor = DA.GetData(5, ref inSecondColor);
            inputChecker.StopIfConversionIsFailed(canGetSecondColor);
            #endregion

            List <Circle> crvsOut   = new List <Circle>();
            List <Color>  crvsColor = new List <Color>();

            for (int i = 0; i < inPts.Count; i++)
            {
                Plane  refPlane = inPlanes[i];
                double maxRad   = inRange[i];
                int    density  = inDensity[i] > 0 ? inDensity[i] : 1;
                double distance = maxRad / density;
                double counter  = distance;
                while (counter < maxRad)
                {
                    crvsOut.Add(new Circle(refPlane, inPts[i], counter));

                    Color color = ColorRemapper.RemappedColor(ref inFirstColor, ref inSecondColor, maxRad, distance, counter);
                    crvsColor.Add(color);

                    counter += distance;
                }
            }

            #region SendOutputsToCanvas

            DA.SetDataList(0, crvsOut);
            DA.SetDataList(1, crvsColor);

            #endregion
        }
Ejemplo n.º 6
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            InputChecker inputChecker = new InputChecker(this);

            #region GetInpuFromCanvas
            Surface inBaseSrf     = null;
            bool    canGetSurface = DA.GetData(0, ref inBaseSrf);
            inputChecker.StopIfConversionIsFailed(canGetSurface);
            inBaseSrf.SetDomain(0, new Interval(0.0, 1.0));
            inBaseSrf.SetDomain(1, new Interval(0.0, 1.0));

            List <double> inData     = new List <double>();
            bool          canGetData = DA.GetDataList(1, inData);
            inputChecker.StopIfConversionIsFailed(canGetData);

            List <Point3d> inBasePts     = new List <Point3d>();
            bool           canConvertPts = DA.GetDataList(2, inBasePts);
            inputChecker.StopIfConversionIsFailed(canConvertPts);
            ValuesAllocator.MatchLists(inData, inBasePts);

            Color inFirstColor = new Color();
            if (!DA.GetData(3, ref inFirstColor))
            {
                return;
            }

            Color inSecondColor = new Color();
            if (!DA.GetData(4, ref inSecondColor))
            {
                return;
            }
            #endregion

            int           lastValueIndex = inData.Count - 1;
            List <double> sortedData     = new List <double>(inData);
            sortedData.Sort();
            double refStartDomain = sortedData[0];
            double refEndDomain   = sortedData[lastValueIndex];

            List <Line>  histogramLines  = new List <Line>();
            List <Color> histogramColors = new List <Color>();

            for (int i = 0; i < inData.Count; i++)
            {
                Point3d inPt = inBasePts[i];
                double  uDir = 0.0;
                double  vDir = 0.0;
                if (!inBaseSrf.ClosestPoint(inPt, out uDir, out vDir))
                {
                    return;
                }
                Plane basePlane = new Plane();
                if (!inBaseSrf.FrameAt(uDir, vDir, out basePlane))
                {
                    return;
                }

                double dataVal = inData[i];
                Line   line    = new Line(basePlane.Origin, basePlane.ZAxis, dataVal);
                histogramLines.Add(line);

                Color color = ColorRemapper.RemappedColor(ref inFirstColor, ref inSecondColor, refEndDomain, refStartDomain, dataVal);
                histogramColors.Add(color);
            }



            #region SetOutput
            DA.SetDataList(0, histogramLines);
            DA.SetDataList(1, histogramColors);
            #endregion
        }
Ejemplo n.º 7
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            InputChecker inputChecker = new InputChecker(this);

            #region AssignInput
            Curve inCrv     = null;
            bool  canGetCrv = DA.GetData(0, ref inCrv);
            inputChecker.StopIfConversionIsFailed(canGetCrv);
            inCrv.Domain = new Interval(0, 1);

            List <double> inData     = new List <double>();
            bool          canGetData = DA.GetDataList(1, inData);
            inputChecker.StopIfConversionIsFailed(canGetData);

            List <double> inDataOptional     = new List <double>();
            bool          canGetDataOptional = DA.GetDataList(2, inDataOptional);
            inputChecker.StopIfConversionIsFailed(canGetDataOptional);
            if (inDataOptional.Count == 0)
            {
                EqualCurveSubD(inData, inDataOptional);
            }
            ValuesAllocator.MatchLists(inData, inDataOptional);

            Color inFirstColor = new Color();
            if (!DA.GetData(3, ref inFirstColor))
            {
                return;
            }

            Color inSecondColor = new Color();
            if (!DA.GetData(4, ref inSecondColor))
            {
                return;
            }

            List <double> inRotationAngles = new List <double>();
            DA.GetDataList(5, inRotationAngles);
            ValuesAllocator.MatchLists(inData, inRotationAngles);

            #endregion

            int           lastValueIndex = inData.Count - 1;
            List <double> sortedData     = new List <double>(inData);
            sortedData.Sort();
            double refStartDomain = sortedData[0];
            double refEndDomain   = sortedData[lastValueIndex];

            List <Line>  histogramLines  = new List <Line>();
            List <Color> histogramColors = new List <Color>();

            for (int i = 0; i < inData.Count; i++)
            {
                Plane  pFrame;
                double tValue = inDataOptional[i];
                inCrv.PerpendicularFrameAt(tValue, out pFrame);

                double angle_rad = inRotationAngles[i];
                if (_useDegrees)
                {
                    angle_rad = RhinoMath.ToRadians(angle_rad);
                }
                pFrame.Rotate(angle_rad, pFrame.ZAxis);

                double dataVal = inData[i];
                Line   line    = new Line(pFrame.Origin, pFrame.YAxis, dataVal);
                histogramLines.Add(line);

                Color color = ColorRemapper.RemappedColor(ref inFirstColor, ref inSecondColor, refEndDomain, refStartDomain, dataVal);
                histogramColors.Add(color);
            }

            #region SetOutput
            DA.SetDataList(0, histogramLines);
            DA.SetDataList(1, histogramColors);
            #endregion
        }
Ejemplo n.º 8
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            InputChecker inputChecker = new InputChecker(this);

            #region getDataFromCanvas
            List <Curve> inCurves     = new List <Curve>();
            bool         canGetCurves = DA.GetDataList(0, inCurves);
            inputChecker.StopIfConversionIsFailed(canGetCurves);

            List <int> inClosingTypes    = new List <int>();
            bool       canGetClosingType = DA.GetDataList(1, inClosingTypes);
            inputChecker.StopIfConversionIsFailed(canGetClosingType);
            ValuesAllocator.MatchLists(inCurves, inClosingTypes);

            List <double> inTollerances     = new List <double>();
            bool          canGetTollerances = DA.GetDataList(2, inTollerances);
            inputChecker.StopIfConversionIsFailed(canGetTollerances);
            ValuesAllocator.MatchLists(inCurves, inTollerances);
            #endregion

            List <Point3d> endPoints      = new List <Point3d>();
            List <Curve>   closedCurves   = new List <Curve>();
            List <bool>    closingResults = new List <bool>();

            for (int i = 0; i < inCurves.Count; i++)
            {
                Curve crv = inCurves[i];
                if (crv.IsClosed)
                {
                    closedCurves.Add(crv);
                    closingResults.Add(true);
                }
                else
                {
                    if (inClosingTypes[i] <= 0)
                    {
                        CurveProcessor.CloseCrvAddingLine(inTollerances, endPoints, closedCurves, closingResults, i, crv);
                    }
                    else if (inClosingTypes[i] >= 1)
                    {
                        bool success = crv.MakeClosed(inTollerances[i]);
                        if (!success)
                        {
                            List <Point3d> endPts = CurveProcessor.GetEndPtsFromOpenCurve(crv);
                            endPoints.AddRange(endPts);
                            closedCurves.Add(null);
                        }
                        else
                        {
                            closedCurves.Add(crv);
                        }

                        closingResults.Add(success);
                    }
                    //TODO: Add blend option for the future
                }
            }

            DA.SetDataList(0, endPoints);
            DA.SetDataList(1, closedCurves);
            DA.SetDataList(2, closingResults);
        }