/// <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)
        {
            MeshGhData hE_MeshData = new MeshGhData();

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

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

            if (!hE_Mesh.IsTriangularMesh())
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Mesh is not triangular!");
                return;
            }

            List <Vector3d> normals       = new List <Vector3d>();
            List <Point3d>  centroids     = new List <Point3d>();
            List <Point3d>  circumcenters = new List <Point3d>();


            foreach (Paramdigma.Core.HalfEdgeMesh.MeshFace face in hE_Mesh.Faces)
            {
                Paramdigma.Core.Geometry.Vector3d v        = Paramdigma.Core.Geometry.MeshGeometry.FaceNormal(face);
                Paramdigma.Core.Geometry.Point3d  centroid = Paramdigma.Core.Geometry.MeshGeometry.Centroid(face);

                normals.Add(new Vector3d(v.X, v.Y, v.Z));
                centroids.Add(new Point3d(centroid.X, centroid.Y, centroid.Z));
            }

            DA.SetDataList(0, normals);
            DA.SetDataList(1, centroids);
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(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;

            if (!hE_Mesh.IsTriangularMesh())
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Mesh is not triangular!");
                return;
            }

            List <Vector3d> normals = new List <Vector3d>();

            foreach (MeshVertex v in hE_Mesh.Vertices)
            {
                Paramdigma.Core.Geometry.Vector3d vect = new Paramdigma.Core.Geometry.Vector3d();

                switch (Selection)
                {
                case NormalSelection.Equal:
                    vect = Paramdigma.Core.Geometry.MeshGeometry.VertexNormalEquallyWeighted(v);
                    break;

                case NormalSelection.Area:
                    vect = Paramdigma.Core.Geometry.MeshGeometry.VertexNormalAreaWeighted(v);
                    break;

                case NormalSelection.Angle:
                    vect = Paramdigma.Core.Geometry.MeshGeometry.VertexNormalAngleWeighted(v);
                    break;

                case NormalSelection.Gauss:
                    vect = Paramdigma.Core.Geometry.MeshGeometry.VertexNormalGaussCurvature(v);
                    break;

                case NormalSelection.Mean:
                    vect = Paramdigma.Core.Geometry.MeshGeometry.VertexNormalMeanCurvature(v);
                    break;

                case NormalSelection.Sphere:
                    vect = Paramdigma.Core.Geometry.MeshGeometry.VertexNormalSphereInscribed(v);
                    break;
                }

                normals.Add(new Vector3d(vect.X, vect.Y, vect.Z));
            }

            DA.SetDataList(0, normals);
        }
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)
        {
            MeshGhData hE_MeshData = new MeshGhData();

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

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

            if (!hE_Mesh.IsTriangularMesh())
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Mesh is not triangular!");
                return;
            }

            List <double> k1 = new List <double>();
            List <double> k2 = new List <double>();
            List <double> K  = new List <double>();
            List <double> km = new List <double>();

            foreach (MeshVertex v in hE_Mesh.Vertices)
            {
                double[] k = Paramdigma.Core.Geometry.MeshGeometry.PrincipalCurvatures(v);
                k1.Add(k[0]);
                k2.Add(k[1]);
                K.Add(Paramdigma.Core.Geometry.MeshGeometry.ScalarGaussCurvature(v));
                km.Add(Paramdigma.Core.Geometry.MeshGeometry.ScalarMeanCurvature(v));
            }

            DA.SetDataList(0, k1);
            DA.SetDataList(1, k2);
            DA.SetDataList(2, K);
            DA.SetDataList(3, km);
        }
        /// <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)
        {
            MeshGhData    hE_MeshData  = new MeshGhData();
            List <double> scalarValues = new List <double>();
            List <double> levels       = new List <double>();
            string        key          = "sets1";

            if (!DA.GetData(0, ref hE_MeshData))
            {
                return;
            }
            if (!DA.GetDataList(1, scalarValues))
            {
                return;
            }
            if (!DA.GetDataList(2, levels))
            {
                return;
            }

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

            // Check for invalid inputs
            if (!hE_Mesh.IsTriangularMesh())
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Mesh is not triangular!");
                return;
            }
            if (levels.Count == 0)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Level count can't be 0!");
                return;
            }
            if (scalarValues.Count == 0)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Value count can't be 0!");
                return;
            }
            // Assign values to mesh vertices
            foreach (MeshVertex v in hE_Mesh.Vertices)
            {
                if (v.UserValues.ContainsKey(key))
                {
                    v.UserValues[key] = scalarValues[v.Index];
                }
                else
                {
                    v.UserValues.Add(key, scalarValues[v.Index]);
                }
            }

            // Compute level sets
            Paramdigma.Core.Curves.LevelSets.ComputeLevels(key, levels, hE_Mesh, out List <List <Paramdigma.Core.Geometry.Line> > levelLines);

            //Convert AR_Lib.Curve.Line to Rhino.Geometry.Line
            DataTree <Line> resultLevel = new DataTree <Line>();
            int             count       = 0;

            foreach (List <Paramdigma.Core.Geometry.Line> tempList in levelLines)
            {
                List <Line> tempResult = new List <Line>();
                foreach (Paramdigma.Core.Geometry.Line l in tempList)
                {
                    tempResult.Add(new Line(new Point3d(l.StartPoint.X, l.StartPoint.Y, l.StartPoint.Z), new Point3d(l.EndPoint.X, l.EndPoint.Y, l.EndPoint.Z)));
                }
                resultLevel.AddRange(tempResult, new GH.Kernel.Data.GH_Path(count));
                count++;
            }

            // Return list of lines
            DA.SetDataTree(0, resultLevel);
        }