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)
        {
            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.º 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);

            #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.º 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 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
        }