示例#1
0
 protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
 {
     if (mikity.NumericalMethodHelper.FriedChiken.isInitialized)
     {
         double p = 0;
         if (!DA.GetData(0, ref p))
         {
             return;
         }
         nG.Density = p;
     }
     else
     {
         double p = 0;
         if (!DA.GetData(0, ref p))
         {
             return;
         }
         nG          = new mikity.NumericalMethodHelper.materials.formfindGravity();
         m_gvt       = new GH_gravity();
         m_gvt.Value = nG;
         nG.Density  = p;
     }
     DA.SetData(0, m_gvt);
 }
示例#2
0
 protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
 {
     if (!FriedChiken.isInitialized)
     {
         v = new GH_vectorINT(3);
         int x = 0, y = 0, z = 0;
         if (!DA.GetData(0, ref x))
         {
             return;
         }
         if (!DA.GetData(1, ref y))
         {
             return;
         }
         if (!DA.GetData(2, ref z))
         {
             return;
         }
         v[0] = x;
         v[1] = y;
         v[2] = z;
     }
     else
     {
     }
     DA.SetData(0, v);
 }
示例#3
0
 protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
 {
     if (mikity.NumericalMethodHelper.FriedChiken.isInitialized)
     {
         double p = 0, w = 0;
         if (!DA.GetData(0, ref p))
         {
             return;
         }
         if (!DA.GetData(1, ref w))
         {
             return;
         }
         formFind.Power  = p;
         formFind.Weight = w;
     }
     else
     {
         double p = 0, w = 0;
         if (!DA.GetData(0, ref p))
         {
             return;
         }
         if (!DA.GetData(1, ref w))
         {
             return;
         }
         formFind        = new formFindingMaterial();
         m_mat           = new GH_material();
         m_mat.Value     = formFind;
         formFind.Power  = p;
         formFind.Weight = w;
     }
     DA.SetData(0, m_mat);
 }
示例#4
0
 protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
 {
     if (mikity.NumericalMethodHelper.FriedChiken.isInitialized)
     {
         double Y = 0, g = 0;
         if (!DA.GetData(0, ref Y))
         {
             return;
         }
         if (!DA.GetData(1, ref g))
         {
             return;
         }
         stVen.Young   = Y;
         stVen.Poisson = g;
     }
     else
     {
         double Y = 0, g = 0;
         if (!DA.GetData(0, ref Y))
         {
             return;
         }
         if (!DA.GetData(1, ref g))
         {
             return;
         }
         stVen         = new stVenantMaterial();
         m_mat         = new GH_material();
         m_mat.Value   = stVen;
         stVen.Young   = Y;
         stVen.Poisson = g;
     }
     DA.SetData(0, m_mat);
 }
        /// <summary>
        /// You will need to override this method to solve the component.
        /// </summary>
        /// <param name="DA">Grasshopper's DataAccess interface</param>
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            /// Note that you will need to call the SolveInstance method of the base class to process the default parameters and connect them to the framework.
            base.SolveInstance(DA);

            DA.SetData(1, ((SimpleAssessmentExample)this.Assessment).EmbodiedEnergy);
            DA.SetData(2, "Embodied energy: " + ((SimpleAssessmentExample)this.Assessment).EmbodiedEnergy.ToString("0.00"));
        }
 /// <summary>
 /// Enable transparency before calling on the main window implementation
 /// </summary>
 protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
 {
     if (!mw.AllowsTransparency)
     {
         mw.AllowsTransparency = true;
     }
     mw.Background = new SolidColorBrush(Color.FromArgb(100, 255, 255, 255));
     base.SolveInstance(DA);
 }
示例#7
0
 protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
 {
     if (mikity.NumericalMethodHelper.FriedChiken.isInitialized)
     {
     }
     else
     {
         zG          = new mikity.NumericalMethodHelper.materials.zeroGravity();
         m_gvt       = new GH_gravity();
         m_gvt.Value = zG;
     }
     DA.SetData(0, m_gvt);
 }
        /// <summary>
        /// You will need to override this method to solve the component.
        /// </summary>
        /// <param name="DA">Grasshopper's DataAccess interface</param>
        protected override void SolveInstance(GH.Kernel.IGH_DataAccess DA)
        {
            // first set the properties in the SODesigner
            int n = 0;

            if (DA.GetData <int>(1, ref n))
            {
                ((DesignerWithInputExample)this.Designer).NumberOfBeams = n;
            }

            /// Note that you will need to call the SolveInstance method of the base class to process the default parameters and connect them to the framework.
            base.SolveInstance(DA);
        }
示例#9
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            if (!DA.GetData(1, ref v))
            {
                return;
            }

            if (!FriedChiken.isInitialized)
            {
                Rhino.Geometry.Mesh m = null;
                if (!DA.GetData(0, ref m))
                {
                    return;
                }
                newNodes.Clear();
                newNodes.AddRange(m.Vertices.ToPoint3dArray());
                int nNewNodes = newNodes.Count;
                mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    particles[i] = new mikity.NumericalMethodHelper.particle(newNodes[i][0], newNodes[i][1], newNodes[i][2]);
                }

                pS = new GH_particleSystem(particles);
                node[] lNodes = new node[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    lNodes[i] = new node(i);
                    lNodes[i].copyFrom(pS.Value.particles);
                }
                nF = new nodalForce(v.X, v.Y, v.Z);
                for (int i = 0; i < nNewNodes; i++)
                {
                    nF.addNode(lNodes[i]);
                }
                pS.Value.addObject(nF);
                lGeometry = new Rhino.Geometry.Point3d[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    lGeometry[i] = new Rhino.Geometry.Point3d(particles[i][0], particles[i][1], particles[i][2]);
                }
            }
            else
            {
                nF.forceX = v.X;
                nF.forceY = v.Y;
                nF.forceZ = v.Z;
            }

            DA.SetData(0, pS);
        }
示例#10
0
        public static void SetEnum2D <T>(this Grasshopper.Kernel.IGH_DataAccess DA, int index, IEnumerable <IEnumerable <T> > data)
        {
            var tree = new DataTree <T>();

            var basePath = DA.ParameterTargetPath(index);

            foreach (var entry in data.Select((o, i) => new { Index = i, Item = o }))
            {
                var path = basePath.AppendElement(entry.Index);

                tree.AddRange(entry.Item, path);
            }

            DA.SetDataTree(index, tree);
        }
        /// <summary>
        /// You will need to override this method to solve the component.
        /// </summary>
        /// <param name="DA">Grasshopper's DataAccess interface</param>
        protected override void SolveInstance(GH.Kernel.IGH_DataAccess DA)
        {
            // Retrieve the data and pass it to the designer component
            Point3d point   = new Point3d(0, 0, 0);
            double  span    = 10.0;
            double  height  = 1.0;
            int     n       = 1;
            double  spacing = 1.0;

            if (DA.GetData <Point3d>(1, ref point))
            {
                ((DesignerWithVisualOutputExample)this.Designer).basePoint = new SOPoint3d(
                    point.X,
                    point.Y,
                    point.Z);
            }
            if (DA.GetData <double>(2, ref span))
            {
                ((DesignerWithVisualOutputExample)this.Designer).Span = span;
            }
            if (DA.GetData <double>(3, ref height))
            {
                ((DesignerWithVisualOutputExample)this.Designer).Height = height;
            }
            if (DA.GetData <int>(4, ref n))
            {
                ((DesignerWithVisualOutputExample)this.Designer).NumberOfFrames = n;
            }
            if (DA.GetData <double>(5, ref spacing))
            {
                ((DesignerWithVisualOutputExample)this.Designer).Spacing = spacing;
            }

            /// Note that you will need to call the SolveInstance method of the base class to process the default parameters and connect them to the framework.
            base.SolveInstance(DA);

            DesignerWithVisualOutputExample dsn = (DesignerWithVisualOutputExample)this.Designer;

            List <Line> lines = new List <Line>();

            for (int i = 0; i < dsn.NumberOfFrames; i++)
            {
                lines.Add(new Line(dsn.Points2[i].X, dsn.Points2[i].Y, dsn.Points2[i].Z, dsn.Points4[i].X, dsn.Points4[i].Y, dsn.Points4[i].Z));
                lines.Add(new Line(dsn.Points1[i].X, dsn.Points1[i].Y, dsn.Points1[i].Z, dsn.Points2[i].X, dsn.Points2[i].Y, dsn.Points2[i].Z));
                lines.Add(new Line(dsn.Points3[i].X, dsn.Points3[i].Y, dsn.Points3[i].Z, dsn.Points4[i].X, dsn.Points4[i].Y, dsn.Points4[i].Z));
            }
            DA.SetDataList(1, lines);
        }
示例#12
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            bool toggle = false;

            if (!DA.GetData(1, ref toggle))
            {
                return;
            }
            if (!DA.GetData(2, ref rs))
            {
                return;
            }
            if (toggle == false)
            {
                newFunction = new GH_function();
                if (!DA.GetData(0, ref newFunction))
                {
                    return;
                }
                t       = 0;
                numNode = 12 * (newFunction.uMax) * (newFunction.vMax);
                int maxNumMember = 20 * (newFunction.uMax) * (newFunction.vMax);
                x                        = new double[numNode, 3];
                originalX                = new double[numNode, 3];
                force                    = new double[numNode, 3];
                velocity                 = new double[numNode, 3];
                nodeType                 = new int[numNode];
                numberOfMembersAtNode    = new int[numNode];
                maxNumberOfMembersAtNode = new int[numNode];
                numberFarEndsBoundary    = new int[numNode];
                thisEnd                  = new int[maxNumMember];
                thatEnd                  = new int[maxNumMember];
                MemberType               = new int[maxNumMember];

                lP = initNodes(newFunction, numNode);
                lL = initMembers(newFunction, numNode);
            }
            else
            {
                calculation();
                visualization();
                t++;
            }
            DA.SetDataList(0, lP);
            DA.SetDataList(1, lL);
        }
示例#13
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            if (mikity.NumericalMethodHelper.FriedChiken.isInitialized)
            {
                double mu1 = 0, mu2 = 0, K = 0;
                if (!DA.GetData(0, ref mu1))
                {
                    return;
                }
                if (!DA.GetData(1, ref mu2))
                {
                    return;
                }
                if (!DA.GetData(2, ref K))
                {
                    return;
                }

                mooRiv.u1 = mu1;
                mooRiv.u2 = mu2;
                mooRiv.K  = K;
            }
            else
            {
                double mu1 = 0, mu2 = 0, K = 0;
                if (!DA.GetData(0, ref mu1))
                {
                    return;
                }
                if (!DA.GetData(1, ref mu2))
                {
                    return;
                }
                if (!DA.GetData(2, ref K))
                {
                    return;
                }
                mooRiv      = new mooneyRivlinMaterial();
                m_mat       = new GH_material();
                m_mat.Value = mooRiv;
                mooRiv.u1   = mu1;
                mooRiv.u2   = mu2;
                mooRiv.K    = K;
            }
            DA.SetData(0, m_mat);
        }
示例#14
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            double v = -1.0;

            DA.GetData(2, ref v);
            if (!FriedChiken.isInitialized)
            {
                GH_Point[] pointList = new GH_Point[2];
                DA.GetData(0, ref pointList[0]);
                DA.GetData(1, ref pointList[1]);
                cV = new constrainVolumeObject(v);
                mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[_nNodes];
                for (int i = 0; i < _nNodes; i++)
                {
                    particles[i] = new particle(pointList[i].Value.X, pointList[i].Value.Y, pointList[i].Value.Z);
                }
                pS = new GH_particleSystem(particles);
                cV.addElement(new isoparametricElement(0, 1));
                pS.Value.addObject(cV);
                lGeometry.Clear();
                lGeometry2.Clear();
                lGeometry.Add(particles[0][0], particles[0][1], particles[0][2]);
                lGeometry.Add(particles[1][0], particles[1][1], particles[1][2]);
                lGeometry2.Add(particles[0][0], particles[0][1], particles[0][2]);
                lGeometry2.Add(particles[1][0], particles[1][1], particles[1][2]);

                this.DVPW = GetDVPW(lGeometry);
                this.BKGT = GetBKGT(lGeometry);
                pS.DVPW   = GetDVPW(lGeometry2);
                pS.UPGR   = GetUPGR(lGeometry2);
                pS.BKGT   = GetBKGT(lGeometry2);
            }
            else
            {
                if (cV != null)
                {
                    if (v > 0)
                    {
                        cV.refVolume = v;
                    }
                }
            }

            DA.SetData(0, pS);
        }
示例#15
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            if (mikity.NumericalMethodHelper.FriedChiken.isInitialized)
            {
                double u1 = 0, K = 0;
                if (!DA.GetData(0, ref u1))
                {
                    return;
                }
                if (!DA.GetData(1, ref K))
                {
                    return;
                }

                neoHook.mu1 = u1;
                neoHook.K   = K;
            }
            else
            {
                double u1 = 0, K = 0;
                if (!DA.GetData(0, ref u1))
                {
                    return;
                }
                if (!DA.GetData(1, ref K))
                {
                    return;
                }
                neoHook     = new neoHookeanMaterial();
                m_mat       = new GH_material();
                m_mat.Value = neoHook;
                neoHook.mu1 = u1;
                neoHook.K   = K;
            }
            DA.SetData(0, m_mat);
        }
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            List <GH_vectorINT>           el = new List <GH_vectorINT>();
            List <Rhino.Geometry.Point3d> pl = new List <Rhino.Geometry.Point3d>();

            Rhino.Geometry.Mesh m = null;
            if (!DA.GetData(0, ref m))
            {
                return;
            }
            pl.AddRange(m.Vertices.ToPoint3dArray());
            for (int i = 0; i < m.Faces.Count; i++)
            {
                if (m.Faces[i].IsQuad)
                {
                    int[] f = new int[4] {
                        m.Faces[i].A, m.Faces[i].B, m.Faces[i].D, m.Faces[i].C
                    };
                    el.Add(new GH_vectorINT(f));
                }
            }
            DA.SetDataList(0, pl);
            DA.SetDataList(1, el);
        }
示例#17
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(GH.Kernel.IGH_DataAccess DA)
        {
            MeshGhData hE_MeshData = new MeshGhData();

            if (!DA.GetData(0, ref hE_MeshData))
            {
                return;
            }

            Paramdigma.Core.HalfEdgeMesh.Mesh hE_Mesh = hE_MeshData.Value;

            Paramdigma.Core.HalfEdgeMesh.MeshTopology topo = new Paramdigma.Core.HalfEdgeMesh.MeshTopology(hE_Mesh);

            topo.ComputeFaceAdjacency();

            GH.DataTree <int> fvTopo = new GH.DataTree <int>();
            GH.DataTree <int> feTopo = new GH.DataTree <int>();
            GH.DataTree <int> ffTopo = new GH.DataTree <int>();

            foreach (int key in topo.FaceVertex.Keys)
            {
                fvTopo.AddRange(topo.FaceVertex[key], new GH.Kernel.Data.GH_Path(key));
            }
            foreach (int key in topo.FaceVertex.Keys)
            {
                feTopo.AddRange(topo.FaceVertex[key], new GH.Kernel.Data.GH_Path(key));
            }
            foreach (int key in topo.FaceFace.Keys)
            {
                ffTopo.AddRange(topo.FaceFace[key], new GH.Kernel.Data.GH_Path(key));
            }

            DA.SetDataTree(0, fvTopo);
            DA.SetDataTree(1, feTopo);
            DA.SetDataTree(2, ffTopo);
        }
示例#18
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            double x = 0, y = 0, size = 0, h = 0;

            if (!DA.GetData(0, ref x))
            {
                return;
            }
            if (!DA.GetData(1, ref y))
            {
                return;
            }
            if (!DA.GetData(2, ref size))
            {
                return;
            }
            if (!DA.GetData(3, ref h))
            {
                return;
            }
            GH_hill newHill = new GH_hill(x, y, size, h);

            DA.SetData(0, newHill);
        }
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            double v = -1.0;

            DA.GetData(2, ref v);
            if (!FriedChiken.isInitialized)
            {
                GH_Point[]      pointList    = new GH_Point[2];
                List <GH_Point> tmpPointList = new List <GH_Point>();
                GH_Curve        c            = new GH_Curve();
                int[]           nEdgeNodes   = new int[_dim];
                DA.GetData(0, ref c);
                DA.GetData(1, ref nEdgeNodes[0]);
                //cV = new constrainVolumeObject(v);
                for (int i = 0; i < _dim; i++)
                {
                    if (nEdgeNodes[i] < 2)
                    {
                        AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "Integers must be greater than or equal to 2");
                        return;
                    }
                }
                //点群生成
                int nNewNodes = nEdgeNodes[0];
                nElements = nNewNodes - 1;
                mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    Rhino.Geometry.Point3d p = c.Value.PointAt(c.Value.Domain.T0 + (c.Value.Domain.T1 - c.Value.Domain.T0) / nElements * i);
                    particles[i] = new particle(p.X, p.Y, p.Z);
                }
                pS = new GH_particleSystem(particles);
                List <mikity.NumericalMethodHelper.elements.isoparametricElement> e = new List <mikity.NumericalMethodHelper.elements.isoparametricElement>();
                for (int i = 0; i < nElements; i++)
                {
                    e.Add(new mikity.NumericalMethodHelper.elements.isoparametricElement(i, i + 1));
                }
                lCV.Clear();
                for (int i = 0; i < e.Count; i++)
                {
                    lCV.Add(new constrainVolumeObject(v / nElements));
                    lCV[i].addElement(e[i]);
                    pS.Value.addObject(lCV[i]);
                }

                lGeometry.Clear();
                for (int i = 0; i < nNewNodes; i++)
                {
                    lGeometry.Add(pS.Value.particles[i, 0], pS.Value.particles[i, 1], pS.Value.particles[i, 2]);
                }
                this.DVPW = GetDVPW(lGeometry);
                pS.DVPW   = GetDVPW(lGeometry2);
                pS.UPGR   = GetUPGR(lGeometry2);
                pS.BKGT   = GetBKGT(lGeometry2);
            }
            else
            {
                if (lCV != null && v > 0)
                {
                    for (int i = 0; i < lCV.Count; i++)
                    {
                        lCV[i].refVolume = v / nElements;
                    }
                }
            }

            DA.SetData(0, pS);
        }
示例#20
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            if (!FriedChiken.isInitialized)
            {
                List <GH_Point> pointList = new List <GH_Point>();
                DA.GetDataList(0, pointList);
                bool x = true, y = true, z = true;
                if (!DA.GetData(1, ref x))
                {
                    return;
                }
                if (!DA.GetData(2, ref y))
                {
                    return;
                }
                if (!DA.GetData(3, ref z))
                {
                    return;
                }
                bool isGroup = true;
                if (!DA.GetData(4, ref isGroup))
                {
                    return;
                }
                _nNodes = pointList.Count;
                mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[_nNodes];
                for (int i = 0; i < _nNodes; i++)
                {
                    particles[i] = new particle(pointList[i].Value.X, pointList[i].Value.Y, pointList[i].Value.Z);
                }
                pS = new GH_particleSystem(particles);
                node[] lNodes = new node[_nNodes];
                for (int i = 0; i < _nNodes; i++)
                {
                    lNodes[i] = new node(i);
                    lNodes[i].copyFrom(pS.Value.particles);
                }
                if (isGroup)
                {
                    fixedNodes fN = new fixedNodes(x, y, z);

                    for (int i = 0; i < _nNodes; i++)
                    {
                        fN.addNode(lNodes[i]);
                    }
                    pS.Value.addObject(fN);
                }
                else
                {
                    for (int i = 0; i < _nNodes; i++)
                    {
                        fixedNodes fN = new fixedNodes(x, y, z);
                        fN.addNode(lNodes[i]);
                        pS.Value.addObject(fN);
                    }
                }
                lGeometry  = new Rhino.Geometry.Point3d[_nNodes];
                lGeometry2 = new Rhino.Geometry.Point3d[_nNodes];
                for (int i = 0; i < _nNodes; i++)
                {
                    lGeometry[i] = new Rhino.Geometry.Point3d(particles[i][0], particles[i][1], particles[i][2]);
                }
                this.DVPW = GetDVPW(lGeometry);
                this.BKGT = GetBKGT(lGeometry);
                pS.DVPW   = GetDVPW(lGeometry2);
                pS.UPGR   = GetUPGR(lGeometry2);
                pS.BKGT   = GetBKGT(lGeometry2);
            }
            DA.SetData(0, pS);
        }
示例#21
0
        /// <summary>
        /// This function will be called (successively) from within the
        /// ComputeData method of this component
        /// </summary>
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess data)
        {
            Rhino.Geometry.Point3d center = Rhino.Geometry.Point3d.Origin;
            double length = 1.0;

            if (!data.GetData(m_center_index, ref center))
            {
                return;
            }
            if (!data.GetData(m_length_index, ref length))
            {
                return;
            }
            if (!center.IsValid || length <= 0.0)
            {
                return;
            }

            Rhino.Geometry.Vector3d  dir          = center - Rhino.Geometry.Point3d.Origin;
            Rhino.Geometry.Plane     plane        = Rhino.Geometry.Plane.WorldXY;
            Rhino.Geometry.Transform xf_translate = Rhino.Geometry.Transform.Translation(dir);
            Rhino.Geometry.Transform xf_scale     = Rhino.Geometry.Transform.Scale(plane, length, length, length);
            Rhino.Geometry.Transform xf           = xf_translate * xf_scale;
            if (!xf.IsValid)
            {
                return;
            }

            PlatonicsCommon.PlatonicBase geom = Geometry();
            if (null == geom)
            {
                return;
            }

            Rhino.Geometry.Brep[] faces = geom.Faces();
            if (null != faces && 0 < faces.Length)
            {
                foreach (Brep t in faces)
                {
                    t.Transform(xf);
                }
                data.SetDataList(m_faces_index, faces);
            }

            Rhino.Geometry.Curve[] edges = geom.Edges();
            if (null != edges && 0 < edges.Length)
            {
                foreach (Curve t in edges)
                {
                    t.Transform(xf);
                }
                data.SetDataList(m_edges_index, edges);
            }

            Rhino.Geometry.Point3d[] vertices = geom.Vertices();
            if (null != vertices && 0 < vertices.Length)
            {
                for (int i = 0; i < vertices.Length; i++)
                {
                    vertices[i].Transform(xf);
                }
                data.SetDataList(m_vertices_index, vertices);
            }
        }
示例#22
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            if (!FriedChiken.isInitialized)
            {
                GH_Point[]      pointList    = new GH_Point[4];
                List <GH_Point> tmpPointList = new List <GH_Point>();

                int[] nEdgeNodes = new int[_dim];
                eM = new generalSpring();
                DA.GetData(0, ref pointList[0]);
                DA.GetData(1, ref pointList[1]);
                DA.GetData(2, ref pointList[2]);
                DA.GetData(3, ref pointList[3]);
                DA.GetData(4, ref nEdgeNodes[0]);
                DA.GetData(5, ref nEdgeNodes[1]);
                GH_material mat = null;
                GH_gravity  gvt = null;
                if (!DA.GetData(6, ref mat))
                {
                    return;
                }
                if (!DA.GetData(7, ref gvt))
                {
                    return;
                }
                for (int i = 0; i < _dim; i++)
                {
                    if (nEdgeNodes[i] < 2)
                    {
                        AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "Integers must be greater than or equal to 2");
                        return;
                    }
                }
                //点群生成
                double[,] wt = mikity.MathUtil.bicubic(_dim, nEdgeNodes);
                int nNewNodes = wt.GetLength(0);
                mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    particles[i] = new particle(0, 0, 0);
                    for (int j = 0; j < _nNodes; j++)
                    {
                        particles[i][0] += pointList[j].Value.X * wt[i, j];
                        particles[i][1] += pointList[j].Value.Y * wt[i, j];
                        particles[i][2] += pointList[j].Value.Z * wt[i, j];
                    }
                }
                el = MathUtil.isoparametricElements(nEdgeNodes);

                int nElements = el.Length;
                pS = new GH_particleSystem(particles);
                bool isJoin = true;
                if (isJoin)
                {
                    pS.simplify(el);
                }

                for (int i = 0; i < nElements; i++)
                {
                    if (_subdv == subdivide.quad)
                    {
                        eM.addElement(new mikity.NumericalMethodHelper.elements.isoparametricElement(el[i]));
                    }
                    if (_subdv == subdivide.triA)
                    {
                        eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] {
                            el[i][0], el[i][1], el[i][3]
                        }));
                        eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] {
                            el[i][0], el[i][3], el[i][2]
                        }));
                    }
                    if (_subdv == subdivide.triB)
                    {
                        int S = i % (nEdgeNodes[0] - 1);
                        int T = (i - S) / (nEdgeNodes[0] - 1);
                        if (T % 2 == 1)
                        {
                            S++;
                        }
                        if (S % 2 == 0)
                        {
                            eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] {
                                el[i][0], el[i][1], el[i][3]
                            }));
                            eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] {
                                el[i][0], el[i][3], el[i][2]
                            }));
                        }
                        else
                        {
                            eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] {
                                el[i][0], el[i][1], el[i][2]
                            }));
                            eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] {
                                el[i][2], el[i][1], el[i][3]
                            }));
                        }
                    }
                    if (_subdv == subdivide.triC)
                    {
                        int S = i % (nEdgeNodes[0] - 1);
                        if (S % 2 == 0)
                        {
                            eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] {
                                el[i][0], el[i][1], el[i][3]
                            }));
                            eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] {
                                el[i][0], el[i][3], el[i][2]
                            }));
                        }
                        else
                        {
                            eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] {
                                el[i][0], el[i][1], el[i][2]
                            }));
                            eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] {
                                el[i][2], el[i][1], el[i][3]
                            }));
                        }
                    }
                }
                if (_subdv == subdivide.quad)
                {
                    nElements *= 1;
                }
                else
                {
                    nElements *= 2;
                }
                eM.setMaterial(mat.Value, gvt.Value);
                pS.Value.addObject(eM);
                lGeometry  = new Rhino.Geometry.Mesh();
                lGeometry2 = new Rhino.Geometry.Mesh();
                lGeometry.Vertices.Clear();
                lGeometry.Faces.Clear();
                lGeometry2.Faces.Clear();
                for (int i = 0; i < pS.Value.__N; i++)
                {
                    lGeometry.Vertices.Add(particles[i][0], particles[i][1], particles[i][2]);
                }

                for (int i = 0; i < nElements; i++)
                {
                    if (_subdv == subdivide.quad)
                    {
                        lGeometry.Faces.AddFace(eM.elemList[i].el[0], eM.elemList[i].el[1], eM.elemList[i].el[3], eM.elemList[i].el[2]);
                    }
                    else
                    {
                        lGeometry.Faces.AddFace(eM.elemList[i].el[0], eM.elemList[i].el[1], eM.elemList[i].el[2]);
                    }
                }
                for (int i = 0; i < nElements; i++)
                {
                    if (_subdv == subdivide.quad)
                    {
                        lGeometry2.Faces.AddFace(eM.elemList[i].el[0], eM.elemList[i].el[1], eM.elemList[i].el[3], eM.elemList[i].el[2]);
                    }
                    else
                    {
                        lGeometry2.Faces.AddFace(eM.elemList[i].el[0], eM.elemList[i].el[1], eM.elemList[i].el[2]);
                    }
                }
                this.DVPW = GetDVPW(lGeometry);
                pS.DVPW   = GetDVPW(lGeometry2);
                pS.UPGR   = GetUPGR(lGeometry2);
                pS.BKGT   = GetBKGT(lGeometry2);
            }

            DA.SetData(0, pS);
        }
示例#23
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            List <GH_hill> listHill = new List <GH_hill>();
            int            uMax = 0, vMax = 0;
            double         size = 0.0;

            if (!DA.GetDataList(0, listHill))
            {
                return;
            }
            if (!DA.GetData(1, ref size))
            {
                return;
            }
            if (!DA.GetData(2, ref uMax))
            {
                return;
            }
            if (!DA.GetData(3, ref vMax))
            {
                return;
            }
            double ContourInterval = 0.01 * listHill[0].Value.h;
            double seaLevel        = 30.0 * ContourInterval;

            double c      = size / uMax;
            double otherc = size / vMax;

            if (c > otherc)
            {
                c = otherc;
            }
            double maxX = c * uMax / 2d;
            double maxY = c * vMax / 2d;

            GH_function newFunction = new GH_function();

            newFunction.Value      = new function();
            newFunction.Value.Func = new _function((xValue, yValue) => {
                res f          = new res();
                double z       = -seaLevel;
                double zDiff_X = 0;
                double zDiff_Y = 0;
                double dx      = 0;
                double dy      = 0;
                for (int hill = 0; hill < listHill.Count; hill++)
                {
                    dx = xValue - listHill[hill].Value.x;
                    dy = yValue - listHill[hill].Value.y;
                    double expThingy = listHill[hill].Value.h * Math.Exp(-(dx * dx + dy * dy) / (listHill[hill].Value.size * listHill[hill].Value.size));
                    z       += expThingy;
                    zDiff_X -= dx * expThingy / (listHill[hill].Value.size * listHill[hill].Value.size);
                    zDiff_Y -= dy * expThingy / (listHill[hill].Value.size * listHill[hill].Value.size);
                }
                f.z      = z;
                f.zDiffX = zDiff_X;
                f.zDiffY = zDiff_Y;

                return(f);
            });
            Rhino.Geometry.PointCloud pc = new Rhino.Geometry.PointCloud();

            for (int i = 0; i <= uMax * 4; i++)
            {
                for (int j = 0; j <= vMax * 4; j++)
                {
                    double x = -maxX + (c / 4d) * i;
                    double y = -maxY + (c / 4d) * j;
                    pc.Add(new Rhino.Geometry.Point3d(x, y, newFunction.Value.Func(x, y).z));
                }
            }
            Rhino.Geometry.Plane        plane     = new Rhino.Geometry.Plane(new Rhino.Geometry.Point3d(0, 0, 0), new Rhino.Geometry.Vector3d(1.0, 0, 0), new Rhino.Geometry.Vector3d(0.0, 1.0, 0));
            Rhino.Geometry.PlaneSurface planeSurf = new Rhino.Geometry.PlaneSurface(plane, new Rhino.Geometry.Interval(-size / 2d * 1.2d, size / 2d * 1.2d), new Rhino.Geometry.Interval(-size / 2d * 1.2d, size / 2d * 1.2d));
            DA.SetDataList(0, pc.GetPoints().ToList());
            DA.SetData(1, planeSurf);
            newFunction.size            = size;
            newFunction.uMax            = uMax;
            newFunction.vMax            = vMax;
            newFunction.maxX            = maxX;
            newFunction.maxY            = maxY;
            newFunction.c               = c;
            newFunction.seaLevel        = seaLevel;
            newFunction.ContourInterval = ContourInterval;
            newFunction.a               = c * (Math.Sqrt(7.0) - 1.0) / 6.0;
            newFunction.bsin            = c / 4.0;
            newFunction.bcos            = c * (4.0 - Math.Sqrt(7.0)) / 12.0;
            DA.SetData(2, newFunction);
        }
示例#24
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            if (!FriedChiken.isInitialized)
            {
                Rhino.Geometry.Curve c = null;
                if (!DA.GetData(0, ref c))
                {
                    return;
                }
                if (c.IsPolyline())
                {
                    Rhino.Geometry.Polyline pl = null;
                    if (c.TryGetPolyline(out pl))
                    {
                        int nNewNodes = pl.Count();
                        int nElements = nNewNodes - 1;
                        newNodes.Clear();
                        newNodes.AddRange(pl);
                        GH_material mat = null;
                        GH_gravity  gvt = null;
                        if (!DA.GetData(1, ref mat))
                        {
                            return;
                        }
                        if (!DA.GetData(2, ref gvt))
                        {
                            return;
                        }


                        mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[nNewNodes];
                        for (int i = 0; i < nNewNodes; i++)
                        {
                            particles[i] = new mikity.NumericalMethodHelper.particle(newNodes[i][0], newNodes[i][1], newNodes[i][2]);
                        }

                        eM = new generalSpring();
                        pS = new GH_particleSystem(particles);
                        for (int i = 0; i < nElements; i++)
                        {
                            mikity.NumericalMethodHelper.elements.isoparametricElement e = new NumericalMethodHelper.elements.isoparametricElement(i, i + 1);
                            eM.addElement(e);
                        }
                        eM.setMaterial(mat.Value, gvt.Value);
                        pS.Value.addObject(eM);
                        lGeometry  = new Rhino.Geometry.Polyline();
                        lGeometry2 = new Rhino.Geometry.Polyline();

                        for (int i = 0; i < pS.Value.__N; i++)
                        {
                            lGeometry.Add(particles[i][0], particles[i][1], particles[i][2]);
                        }

                        this.DVPW = GetDVPW(lGeometry);
                        pS.DVPW   = GetDVPW(lGeometry2);
                        pS.UPGR   = GetUPGR(lGeometry2);
                        pS.BKGT   = GetBKGT(lGeometry2);
                        this.BKGT = GetBKGT(lGeometry);

                        DA.SetData(0, pS);
                        DA.SetDataList(1, newNodes);
                    }
                }
                else
                {
                    AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "Only polyline is accepted");
                    return;
                }
            }
        }
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            double v = -1.0;

            DA.GetData(1, ref v);
            if (!FriedChiken.isInitialized)
            {
                Rhino.Geometry.Curve c = null;
                if (!DA.GetData(0, ref c))
                {
                    return;
                }
                if (c.IsPolyline())
                {
                    Rhino.Geometry.Polyline pl = null;
                    if (c.TryGetPolyline(out pl))
                    {
                        nNewNodes = pl.Count();
                        nElements = nNewNodes - 1;
                        newNodes.Clear();
                        newNodes.AddRange(pl);


                        mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[nNewNodes];
                        for (int i = 0; i < nNewNodes; i++)
                        {
                            particles[i] = new mikity.NumericalMethodHelper.particle(newNodes[i][0], newNodes[i][1], newNodes[i][2]);
                        }
                        List <mikity.NumericalMethodHelper.elements.isoparametricElement> e = new List <mikity.NumericalMethodHelper.elements.isoparametricElement>();
                        for (int i = 0; i < nElements; i++)
                        {
                            e.Add(new mikity.NumericalMethodHelper.elements.isoparametricElement(i, i + 1));
                        }
                        lCV.Clear();
                        pS = new GH_particleSystem(particles);
                        for (int i = 0; i < e.Count; i++)
                        {
                            lCV.Add(new constrainVolumeObject(v / nElements));
                            lCV[i].addElement(e[i]);
                            pS.Value.addObject(lCV[i]);
                        }

                        lGeometry.Clear();
                        for (int i = 0; i < nNewNodes; i++)
                        {
                            lGeometry.Add(pS.Value.particles[i, 0], pS.Value.particles[i, 1], pS.Value.particles[i, 2]);
                        }
                        this.DVPW = GetDVPW(lGeometry);
                        pS.DVPW   = GetDVPW(lGeometry2);
                        pS.UPGR   = GetUPGR(lGeometry2);
                        pS.BKGT   = GetBKGT(lGeometry2);
                        this.BKGT = GetBKGT(lGeometry);
                    }
                }
                else
                {
                    AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "Only polyline is accepted");
                    return;
                }
            }
            else
            {
                if (lCV != null && v > 0)
                {
                    for (int i = 0; i < lCV.Count; i++)
                    {
                        lCV[i].refVolume = v / nElements;
                    }
                }
            }
            DA.SetData(0, pS);
            DA.SetDataList(1, newNodes);
        }
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            if (!FriedChiken.isInitialized)
            {
                GH_Point[]      pointList    = new GH_Point[2];
                List <GH_Point> tmpPointList = new List <GH_Point>();
                int[]           nEdgeNodes   = new int[_dim];
                DA.GetData(0, ref pointList[0]);
                DA.GetData(1, ref pointList[1]);
                DA.GetData(2, ref nEdgeNodes[0]);
                bool x = true, y = true, z = true;
                if (!DA.GetData(3, ref x))
                {
                    return;
                }
                if (!DA.GetData(4, ref y))
                {
                    return;
                }
                if (!DA.GetData(5, ref z))
                {
                    return;
                }

                for (int i = 0; i < _dim; i++)
                {
                    if (nEdgeNodes[i] < 2)
                    {
                        AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "Integers must be greater than or equal to 2");
                        return;
                    }
                }
                //点群生成
                double[,] wt = mikity.MathUtil.bicubic(_dim, nEdgeNodes);
                int nNewNodes = wt.GetLength(0);
                mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    particles[i] = new particle(0, 0, 0);
                    for (int j = 0; j < _nNodes; j++)
                    {
                        particles[i][0] += pointList[j].Value.X * wt[i, j];
                        particles[i][1] += pointList[j].Value.Y * wt[i, j];
                        particles[i][2] += pointList[j].Value.Z * wt[i, j];
                    }
                }
                pS = new GH_particleSystem(particles);
                node[] lNodes = new node[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    lNodes[i] = new node(i);
                    lNodes[i].copyFrom(pS.Value.particles);
                }
                fixedNodes fN = new fixedNodes(x, y, z);

                for (int i = 0; i < nNewNodes; i++)
                {
                    fN.addNode(lNodes[i]);
                }
                pS.Value.addObject(fN);
                lGeometry = new Rhino.Geometry.Point3d[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    lGeometry[i] = new Rhino.Geometry.Point3d(particles[i][0], particles[i][1], particles[i][2]);
                }
            }
            DA.SetData(0, pS);
        }
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            if (!FriedChiken.isInitialized)
            {
                GH_Point[]      pointList    = new GH_Point[2];
                List <GH_Point> tmpPointList = new List <GH_Point>();

                int[] nEdgeNodes = new int[_dim];
                eM = new generalSpring();
                DA.GetData(0, ref pointList[0]);
                DA.GetData(1, ref pointList[1]);
                DA.GetData(2, ref nEdgeNodes[0]);
                GH_material mat = null;
                if (!DA.GetData(3, ref mat))
                {
                    return;
                }
                GH_gravity gvt = null;
                if (!DA.GetData(4, ref gvt))
                {
                    return;
                }
                for (int i = 0; i < _dim; i++)
                {
                    if (nEdgeNodes[i] < 2)
                    {
                        AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "Integers must be greater than or equal to 2");
                        return;
                    }
                }
                //点群生成
                double[,] wt = mikity.MathUtil.bicubic(_dim, nEdgeNodes);
                int nNewNodes = wt.GetLength(0);
                mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    particles[i] = new particle(0, 0, 0);
                    for (int j = 0; j < _nNodes; j++)
                    {
                        particles[i][0] += pointList[j].Value.X * wt[i, j];
                        particles[i][1] += pointList[j].Value.Y * wt[i, j];
                        particles[i][2] += pointList[j].Value.Z * wt[i, j];
                    }
                }
                el = MathUtil.isoparametricElements(nEdgeNodes);
                int nElements = el.Length;
                pS = new GH_particleSystem(particles);
                for (int i = 0; i < nElements; i++)
                {
                    eM.addElement(new mikity.NumericalMethodHelper.elements.isoparametricElement(el[i]));
                }
                eM.setMaterial(mat.Value, gvt.Value);
                pS.Value.addObject(eM);
                lGeometry  = new Rhino.Geometry.Polyline();
                lGeometry2 = new Rhino.Geometry.Polyline();

                for (int i = 0; i < pS.Value.__N; i++)
                {
                    lGeometry.Add(particles[i][0], particles[i][1], particles[i][2]);
                }

                this.DVPW = GetDVPW(lGeometry);
                pS.DVPW   = GetDVPW(lGeometry2);
                pS.UPGR   = GetUPGR(lGeometry2);
                pS.BKGT   = GetBKGT(lGeometry2);
            }

            DA.SetData(0, pS);
        }
示例#28
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            init();
            _listSrf = new List <Surface>();
            _listCrv = new List <Curve>();
            listPnt  = new List <Point3d>();
            List <string> crvTypes   = new List <string>();
            List <string> pntHeights = new List <string>();

            if (!DA.GetDataList(0, _listSrf))
            {
                return;
            }
            if (!DA.GetDataList(1, _listCrv))
            {
                return;
            }
            if (!DA.GetDataList(2, crvTypes))
            {
                return;
            }
            if (!DA.GetDataList(3, listPnt))
            {
                listPnt.Clear();
            }
            if (!DA.GetData(4, ref globalC))
            {
                return;
            }

            if (_listCrv.Count != crvTypes.Count)
            {
                AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "need types for curves"); return;
            }

            listSlice  = new Dictionary <string, slice>();
            listSlice2 = new Dictionary <string, slice2>();
            listLeaf   = new List <leaf>();
            listBranch = new List <branch>();
            listNode   = new List <node>();
            myControlBox.clearSliders();

            for (int i = 0; i < _listCrv.Count; i++)
            {
                var branch = new branch();
                branch.crv     = _listCrv[i] as NurbsCurve;
                branch.N       = branch.crv.Points.Count;
                branch.dom     = branch.crv.Domain;
                branch.Dim     = branch.crv.Order;
                branch.dDim    = branch.crv.Order - 1;
                branch.nElem   = branch.N - branch.dDim;
                branch.scaleT  = (branch.dom.T1 - branch.dom.T0) / branch.nElem;
                branch.originT = branch.dom.T0;
                if (crvTypes[i].StartsWith("reinforce"))
                {
                    branch.branchType = branch.type.reinforce;
                    var key = crvTypes[i].Replace("reinforce", "");
                    branch.sliceKey = key;
                    try{
                        branch.slice           = listSlice[key];
                        branch.slice.sliceType = slice.type.fr;
                        branch.slice.lB.Add(branch);
                    }
                    catch (KeyNotFoundException e) {
                        listSlice[key]         = new slice();
                        branch.slice           = listSlice[key];
                        branch.slice.sliceType = slice.type.fr;
                        branch.slice.lB.Add(branch);
                    }
                }
                else if (crvTypes[i].StartsWith("kink"))
                {
                    branch.branchType = branch.type.kink;
                    var    key = crvTypes[i].Replace("kink", "");
                    double lb  = 0.0d;
                    double _lb;
                    bool   res = double.TryParse(key, out _lb);
                    if (res)
                    {
                        lb = _lb;
                    }
                    else
                    {
                        lb = 0.0d;
                    }
                    branch.lb = lb;
                    //int NN;
                    //res = int.TryParse(key, out NN);
                    //if (res) { if (NN == 123) { branch.obj = true; } }
                }
                else if (crvTypes[i].StartsWith("open"))
                {
                    branch.branchType = branch.type.open;
                    var key = crvTypes[i].Replace("open", "");
                    branch.sliceKey = key;
                    try
                    {
                        branch.slice           = listSlice[key];
                        branch.slice.sliceType = slice.type.fr;
                        branch.slice.lB.Add(branch);
                    }
                    catch (KeyNotFoundException e)
                    {
                        listSlice[key]         = new slice();
                        branch.slice           = listSlice[key];
                        branch.slice.sliceType = slice.type.fr;
                        branch.slice.lB.Add(branch);
                    }
                }
                else if (crvTypes[i].StartsWith("fix"))
                {
                    branch.branchType = branch.type.fix;
                    var key = crvTypes[i].Replace("fix", "");
                    branch.sliceKey = key;
                    try
                    {
                        branch.slice2 = listSlice2[key];
                    }
                    catch (KeyNotFoundException e)
                    {
                        listSlice2[key] = new slice2();
                        branch.slice2   = listSlice2[key];

                        var slider = myControlBox.addSliderVert(0, 1, 200, 100);
                        slider.Converter = (val) =>
                        {
                            double height = val / 10d - 10d;
                            branch.slice2.height = height;
                            this.ExpirePreview(true);
                            return(height);
                        };
                    }
                }
                else
                {
                    AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "type should be either of reinforce, kink, fix, or open");
                }
                listBranch.Add(branch);
            }

            // Connect nodes
            foreach (var node in listNode)
            {
                node.N = 0;
                node.share.Clear();
                node.number.Clear();
            }
            foreach (var branch in listBranch)
            {
                var  P    = branch.crv.Points[0].Location;
                bool flag = false;
                foreach (var node in listNode)
                {
                    if (node.compare(P))
                    {
                        flag = true;
                        node.N++;
                        node.share.Add(branch);
                        node.number.Add(0);
                        break;
                    }
                }
                if (!flag)
                {
                    var newNode = new node();
                    listNode.Add(newNode);
                    newNode.N++;
                    newNode.share.Add(branch);
                    newNode.number.Add(0);
                    newNode.x = P.X;
                    newNode.y = P.Y;
                    newNode.z = P.Z;
                }
                var Q = branch.crv.Points[branch.N - 1].Location;
                flag = false;
                foreach (var node in listNode)
                {
                    if (node.compare(Q))
                    {
                        flag = true;
                        node.N++;
                        node.share.Add(branch);
                        node.number.Add(branch.N - 1);
                        break;
                    }
                }
                if (!flag)
                {
                    var newNode = new node();
                    listNode.Add(newNode);
                    newNode.N++;
                    newNode.share.Add(branch);
                    newNode.number.Add(branch.N - 1);
                    newNode.x = Q.X;
                    newNode.y = Q.Y;
                    newNode.z = Q.Z;
                }
            }
            for (int i = 0; i < _listSrf.Count; i++)
            {
                var srf  = _listSrf[i];
                var leaf = new leaf();
                listLeaf.Add(leaf);
                leaf.srf     = srf as NurbsSurface;
                leaf.nU      = leaf.srf.Points.CountU;
                leaf.nV      = leaf.srf.Points.CountV;
                leaf.domU    = leaf.srf.Domain(0);
                leaf.domV    = leaf.srf.Domain(1);
                leaf.uDim    = leaf.srf.OrderU;
                leaf.vDim    = leaf.srf.OrderV;
                leaf.uDdim   = leaf.srf.OrderU - 1;
                leaf.vDdim   = leaf.srf.OrderV - 1;
                leaf.nUelem  = leaf.nU - leaf.uDdim;
                leaf.nVelem  = leaf.nV - leaf.vDdim;
                leaf.scaleU  = (leaf.domU.T1 - leaf.domU.T0) / leaf.nUelem;
                leaf.scaleV  = (leaf.domV.T1 - leaf.domV.T0) / leaf.nVelem;
                leaf.originU = leaf.domU.T0;
                leaf.originV = leaf.domV.T0;
                var domainU = leaf.srf.Domain(0);
                var domainV = leaf.srf.Domain(1);
                //Find corresponding curve
                //(0,0)->(1,0)
                var curve = leaf.srf.IsoCurve(0, domainV.T0) as NurbsCurve;
                leaf.flip[0] = findCurve(leaf, ref leaf.branch[0], listBranch, curve);//bottom
                //(1,0)->(1,1)
                curve        = leaf.srf.IsoCurve(1, domainU.T1) as NurbsCurve;
                leaf.flip[1] = findCurve(leaf, ref leaf.branch[1], listBranch, curve);//right
                //(1,1)->(0,1)
                curve        = leaf.srf.IsoCurve(0, domainV.T1) as NurbsCurve;
                leaf.flip[2] = findCurve(leaf, ref leaf.branch[2], listBranch, curve);//top
                //(0,1)->(0,0)
                curve        = leaf.srf.IsoCurve(1, domainU.T0) as NurbsCurve;
                leaf.flip[3] = findCurve(leaf, ref leaf.branch[3], listBranch, curve);//left
            }
            //multiqudric surface
            var A = new Rhino.Geometry.Matrix(listPnt.Count, listPnt.Count);
            var z = new Rhino.Geometry.Matrix(listPnt.Count, 1);

            for (int i = 0; i < listPnt.Count; i++)
            {
                for (int j = 0; j < listPnt.Count; j++)
                {
                    var pi = listPnt[i];
                    var pj = listPnt[j];
                    A[i, j] = quadFunc(pi.X, pj.X, pi.Y, pj.Y);
                    z[i, 0] = pi.Z;
                }
            }
            A.Invert(0.0);  //this parameter should be 0.0
            var c = A * z;

            globalCoeff = new double[listPnt.Count];
            for (int i = 0; i < listPnt.Count; i++)
            {
                globalCoeff[i] = c[i, 0];
            }
            targetSrf  = new List <Point3d>();
            globalFunc = (xi, yi) => {
                double Z = 0;
                for (int j = 0; j < listPnt.Count; j++)
                {
                    Z = Z + globalCoeff[j] * quadFunc(xi, listPnt[j].X, yi, listPnt[j].Y);
                }
                return(Z);
            };
            foreach (var leaf in listLeaf)
            {
                var domU = leaf.domU;
                var domV = leaf.domV;
                for (double i = 0; i <= 1.0; i += 0.05)
                {
                    for (double j = 0; j < 1.0; j += 0.05)
                    {
                        double u = domU[0] + i * (domU[1] - domU[0]);
                        double v = domV[0] + j * (domV[1] - domV[0]);
                        Rhino.Geometry.Point3d    P;
                        Rhino.Geometry.Vector3d[] V;
                        leaf.srf.Evaluate(u, v, 0, out P, out V);
                        var newP = new Rhino.Geometry.Point3d(P.X, P.Y, globalFunc(P.X, P.Y));
                        targetSrf.Add(newP);
                    }
                }
            }
        }
示例#29
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            if (!DA.GetData(2, ref v))
            {
                return;
            }
            if (!FriedChiken.isInitialized)
            {
                GH_Point[]      pointList    = new GH_Point[2];
                List <GH_Point> tmpPointList = new List <GH_Point>();
                GH_Curve        c            = new GH_Curve();
                int[]           nEdgeNodes   = new int[_dim];
                DA.GetData(0, ref c);
                DA.GetData(1, ref nEdgeNodes[0]);
                for (int i = 0; i < _dim; i++)
                {
                    if (nEdgeNodes[i] < 2)
                    {
                        AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "Integers must be greater than or equal to 2");
                        return;
                    }
                }
                //点群生成
                int nNewNodes = nEdgeNodes[0];
                nElements = nNewNodes - 1;
                mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    Rhino.Geometry.Point3d p = c.Value.PointAt(c.Value.Domain.T0 + (c.Value.Domain.T1 - c.Value.Domain.T0) / nElements * i);
                    particles[i] = new particle(p.X, p.Y, p.Z);
                }

                pS = new GH_particleSystem(particles);
                node[] lNodes = new node[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    lNodes[i] = new node(i);
                    lNodes[i].copyFrom(pS.Value.particles);
                }
                nF = new nodalForce(v.X, v.Y, v.Z);
                for (int i = 0; i < nNewNodes; i++)
                {
                    nF.addNode(lNodes[i]);
                }
                pS.Value.addObject(nF);
                lGeometry.Clear();
                for (int i = 0; i < nNewNodes; i++)
                {
                    lGeometry.Add(new Rhino.Geometry.Point3d(particles[i][0], particles[i][1], particles[i][2]));
                }
                this.DVPW = GetDVPW(lGeometry);
                pS.DVPW   = GetDVPW(lGeometry2);
                pS.UPGR   = GetUPGR(lGeometry2);
                pS.BKGT   = GetBKGT(lGeometry2);
            }
            else
            {
                nF.forceX = v.X;
                nF.forceY = v.Y;
                nF.forceZ = v.Z;
            }

            DA.SetData(0, pS);
        }
示例#30
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            if (!DA.GetData(11, ref v))
            {
                return;
            }
            if (!FriedChiken.isInitialized)
            {
                GH_Point[]      pointList    = new GH_Point[8];
                List <GH_Point> tmpPointList = new List <GH_Point>();

                int[] nEdgeNodes = new int[_dim];

                DA.GetData(0, ref pointList[0]);
                DA.GetData(1, ref pointList[1]);
                DA.GetData(2, ref pointList[2]);
                DA.GetData(3, ref pointList[3]);
                DA.GetData(4, ref pointList[4]);
                DA.GetData(5, ref pointList[5]);
                DA.GetData(6, ref pointList[6]);
                DA.GetData(7, ref pointList[7]);
                DA.GetData(8, ref nEdgeNodes[0]);
                DA.GetData(9, ref nEdgeNodes[1]);
                DA.GetData(10, ref nEdgeNodes[2]);
                for (int i = 0; i < _dim; i++)
                {
                    if (nEdgeNodes[i] < 2)
                    {
                        AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "Integers must be greater than or equal to 2");
                        return;
                    }
                }
                //点群生成
                double[,] wt = mikity.MathUtil.bicubic(_dim, nEdgeNodes);
                int nNewNodes = wt.GetLength(0);
                mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[nNewNodes];
                pS = new GH_particleSystem(particles);
                for (int i = 0; i < nNewNodes; i++)
                {
                    particles[i] = new particle(0, 0, 0);
                    for (int j = 0; j < _nNodes; j++)
                    {
                        particles[i][0] += pointList[j].Value.X * wt[i, j];
                        particles[i][1] += pointList[j].Value.Y * wt[i, j];
                        particles[i][2] += pointList[j].Value.Z * wt[i, j];
                    }
                }
                node[] lNodes = new node[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    lNodes[i] = new node(i);
                    lNodes[i].copyFrom(pS.Value.particles);
                }
                nF = new nodalForce(v.X, v.Y, v.Z);
                for (int i = 0; i < nNewNodes; i++)
                {
                    nF.addNode(lNodes[i]);
                }
                pS.Value.addObject(nF);
                lGeometry = new Rhino.Geometry.Point3d[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    lGeometry[i] = new Rhino.Geometry.Point3d(particles[i][0], particles[i][1], particles[i][2]);
                }
            }
            else
            {
                nF.forceX = v.X;
                nF.forceY = v.Y;
                nF.forceZ = v.Z;
            }
            DA.SetData(0, pS);
        }