Exemplo n.º 1
0
        /// <summary>
        /// Calculates the area of an object
        /// </summary>
        public static double GetArea(IRhinoObject obj, double tol)
        {
            if (null != obj)
            {
                IOnCurve crv = OnCurve.ConstCast(obj.Geometry());
                if (null != crv)
                {
                    return(GetCurveArea(crv, tol));
                }

                IOnSurface srf = OnSurface.ConstCast(obj.Geometry());
                if (null != srf)
                {
                    return(GetSurfaceArea(srf));
                }

                IOnBrep brep = OnBrep.ConstCast(obj.Geometry());
                if (null != brep)
                {
                    return(GetBrepArea(brep));
                }

                IOnMesh mesh = OnMesh.ConstCast(obj.Geometry());
                if (null != mesh)
                {
                    return(GetMeshArea(mesh));
                }
            }
            return(0.0);
        }
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoGetObject go = new MRhinoGetObject();

            go.SetCommandPrompt("Select solid meshes for volume calculation");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object);
            go.SetGeometryAttributeFilter(IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.closed_mesh);
            go.EnableSubObjectSelect(false);
            go.EnableGroupSelect();
            go.GetObjects(1, 0);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            List <IOnMesh> meshes = new List <IOnMesh>();

            for (int i = 0; i < go.ObjectCount(); i++)
            {
                IOnMesh mesh = go.Object(i).Mesh();
                if (mesh != null)
                {
                    meshes.Add(mesh);
                }
            }
            if (meshes.Count == 0)
            {
                return(IRhinoCommand.result.nothing);
            }

            OnBoundingBox bbox = new OnBoundingBox();

            for (int i = 0; i < meshes.Count; i++)
            {
                meshes[i].GetBoundingBox(ref bbox, 1);
            }
            On3dPoint base_point = bbox.Center();

            double total_volume         = 0.0;
            double total_error_estimate = 0.0;
            string msg;

            for (int i = 0; i < meshes.Count; i++)
            {
                double error_estimate = 0.0;
                double volume         = meshes[i].Volume(base_point, ref error_estimate);
                msg = string.Format("Mesh {0} = {1:f} (+/- {2:f}\n", i, volume, error_estimate);
                RhUtil.RhinoApp().Print(msg);
                total_volume         += volume;
                total_error_estimate += error_estimate;
            }

            msg = string.Format("Total volume = {0:f} (+/- {1:f})\n",
                                total_volume,
                                total_error_estimate);
            RhUtil.RhinoApp().Print(msg);

            return(IRhinoCommand.result.success);
        }
Exemplo n.º 3
0
        private static double GetMeshVolume(IOnMesh mesh)
        {
            double volume = 0.0;

            if (null != mesh)
            {
                OnMassProperties mp = new OnMassProperties();
                if (mesh.VolumeMassProperties(ref mp, true))
                {
                    volume = Math.Abs(mp.Volume());
                }
            }
            return(volume);
        }
Exemplo n.º 4
0
        private static double GetMeshArea(IOnMesh mesh)
        {
            double area = 0.0;

            if (null != mesh)
            {
                OnMassProperties mp = new OnMassProperties();
                if (mesh.AreaMassProperties(ref mp, true))
                {
                    area = Math.Abs(mp.Area());
                }
            }
            return(area);
        }
Exemplo n.º 5
0
        public override bool CustomGeometryFilter(IRhinoObject obj, IOnGeometry geo, OnCOMPONENT_INDEX ci)
        {
            if (geo != null)
            {
                IOnCurve crv = OnCurve.ConstCast(geo);
                if (crv != null)
                {
                    if (crv.IsClosed() && crv.IsPlanar())
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

                IOnBrep brep = OnBrep.ConstCast(geo);
                if (brep != null)
                {
                    if (brep.m_F.Count() == 1)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

                IOnSurface srf = OnSurface.ConstCast(geo);
                if (srf != null)
                {
                    return(true);
                }

                IOnMesh mesh = OnMesh.ConstCast(geo);
                if (mesh != null)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Calculates the volume of an object
        /// </summary>
        public static double GetVolume(IRhinoObject obj)
        {
            if (null != obj && obj.IsSolid())
            {
                IOnSurface srf = OnSurface.ConstCast(obj.Geometry());
                if (null != srf)
                {
                    return(GetSurfaceVolume(srf));
                }

                IOnBrep brep = OnBrep.ConstCast(obj.Geometry());
                if (null != brep)
                {
                    return(GetBrepVolume(brep));
                }

                IOnMesh mesh = OnMesh.ConstCast(obj.Geometry());
                if (null != mesh)
                {
                    return(GetMeshVolume(mesh));
                }
            }
            return(0.0);
        }
 private static double GetMeshVolume(IOnMesh mesh)
 {
     double volume = 0.0;
       if (null != mesh)
       {
     OnMassProperties mp = new OnMassProperties();
     if (mesh.VolumeMassProperties(ref mp, true))
       volume = Math.Abs(mp.Volume());
       }
       return volume;
 }
 private static double GetMeshArea(IOnMesh mesh)
 {
     double area = 0.0;
       if (null != mesh)
       {
     OnMassProperties mp = new OnMassProperties();
     if (mesh.AreaMassProperties(ref mp, true))
       area = Math.Abs(mp.Area());
       }
       return area;
 }