///<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);
        }
Beispiel #2
0
            /// <summary>
            /// Intesects all NURBS Surfaces with Voxels.
            /// </summary>
            /// <param name="Model">the scene.</param>
            /// <param name="Box">the voxel</param>
            /// <param name="Index">the index of the surface to test.</param>
            /// <returns></returns>
            private bool BoxIntersection(RhCommon_Scene Model, OnBoundingBox Box, int Index)
            {
                On3dPoint Center = Box.Center();
                double    Radius = Center.DistanceTo(Box.Min());
                double    s      = 0;
                double    t      = 0;
                On3dPoint point  = new On3dPoint();

                if (RhUtil.RhinoBrepClosestPoint(Model.Brep(Index), Center, new OnCOMPONENT_INDEX(), ref s, ref t, point, Radius))
                //if (Center.DistanceTo(point) < Radius)
                {
                    return(true);
                }
                return(false);
            }
        ///<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;
        }
Beispiel #4
0
        private static double GetCurveArea(IOnCurve crv, double tol)
        {
            double area = 0.0;

            if (null != crv && crv.IsClosed())
            {
                OnPlane plane = new OnPlane();
                if (crv.IsPlanar(plane, tol))
                {
                    OnBoundingBox    bbox  = crv.BoundingBox();
                    On3dPoint        point = plane.ClosestPointTo(bbox.Center());
                    OnMassProperties mp    = new OnMassProperties();
                    if (crv.AreaMassProperties(point, plane.Normal(), ref mp))
                    {
                        area = Math.Abs(mp.Area());
                    }
                }
            }
            return(area);
        }
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            Model.globalContext = context;

            // get file info after it has been loaded into memory.
            Model.txtFilename = context.m_doc.GetPathName();
            Model.txtTitle = context.m_doc.GetTitle();
            //  http://wiki.mcneel.com/developer/sdksamples/meshvolume
            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;

            /*
            System.Guid id = CsDockingDialogDockBar.ID();
              bool bVisible = RMA.UI.MRhinoDockBarManager.IsDockBarVisible(id);

              string prompt;
              if (bVisible)
            prompt = string.Format("{0} window is visible. New value", EnglishCommandName());
              else
            prompt = string.Format("{0} window is hidden. New value", EnglishCommandName());

              MRhinoGetOption go = new MRhinoGetOption();
              go.SetCommandPrompt(prompt);
              int h_option = go.AddCommandOption(new MRhinoCommandOptionName("Hide"));
              int s_option = go.AddCommandOption(new MRhinoCommandOptionName("Show"));
              int t_option = go.AddCommandOption(new MRhinoCommandOptionName("Toggle"));
              go.GetOption();
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              IRhinoCommandOption opt = go.Option();
              if (opt == null)
            return IRhinoCommand.result.failure;

              int option_index = opt.m_option_index;
              if (h_option == option_index)
              {
            if (bVisible)
              RMA.UI.MRhinoDockBarManager.ShowDockBar(id, false, false);
              }
              else if (s_option == option_index)
              {
            if (!bVisible)
              RMA.UI.MRhinoDockBarManager.ShowDockBar(id, true, false);
              }
              else if (t_option == option_index)
              {
            if (bVisible)
              RMA.UI.MRhinoDockBarManager.ShowDockBar(id, false, false);
            else
              RMA.UI.MRhinoDockBarManager.ShowDockBar(id, true, false);
              }

              return IRhinoCommand.result.success;*/
        }
 /// <summary>
 /// Intesects all NURBS Surfaces with Voxels.
 /// </summary>
 /// <param name="Model">the scene.</param>
 /// <param name="Box">the voxel</param>
 /// <param name="Index">the index of the surface to test.</param>
 /// <returns></returns>
 private bool BoxIntersection(RhCommon_Scene Model, OnBoundingBox Box, int Index)
 {
     On3dPoint Center = Box.Center();
     double Radius = Center.DistanceTo(Box.Min());
     double s = 0;
     double t = 0;
     On3dPoint point = new On3dPoint();
     if (RhUtil.RhinoBrepClosestPoint(Model.Brep(Index), Center, new OnCOMPONENT_INDEX(), ref s, ref t, point, Radius))
     //if (Center.DistanceTo(point) < Radius)
     {
         return true;
     }
     return false;
 }