Exemplo n.º 1
0
 public override bool ExecConduit(ref MRhinoDisplayPipeline pipeline, uint channel, ref bool terminate)
 {
     if (MSupportChannels.SC_CALCBOUNDINGBOX == channel)
     {
         // If you are dynamically drawing objects, then we must implement the
         // this channel to add to the overall scene bounding box. This will make
         // Rhino adjust its clipping planes to include our geometry.
         for (int i = 0; i < m_objects.Count; i++)
         {
             IRhinoObject obj = m_objects[i];
             if (null != obj)
             {
                 OnBoundingBox bbox = obj.BoundingBox();
                 bbox.Transform(m_xform);
                 m_pChannelAttrs.m_BoundingBox.Union(bbox);
             }
         }
     }
     else if (MSupportChannels.SC_DRAWOVERLAY == channel)
     {
         // This channel is where the drawing takes place.
         for (int i = 0; i < m_objects.Count; i++)
         {
             IRhinoObject obj = m_objects[i];
             if (null != obj)
             {
                 pipeline.SetObjectColor(obj.ObjectDrawColor());
                 pipeline.DrawObject(obj, m_xform);
             }
         }
     }
     return(true);
 }
        ///<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
            public VoxelGrid(RhCommon_Scene ModelSurfaces, List <IOn3dPoint> Pts, int VG_Domain)
            {
                VoxelCT        = VG_Domain;
                VoxelInventory = new List <int> [VoxelCT, VoxelCT, VoxelCT];
                Voxel          = new List <On3dPoint> [VoxelCT, VoxelCT, VoxelCT];
                IRhinoObject[] Surfaces = new IRhinoObject[ModelSurfaces.Count()];

                OnBoundingBox  TightOBox = new OnBoundingBox();
                On3dPoint      BoxMin    = new On3dPoint();
                On3dPoint      BoxMax    = new On3dPoint();
                ArrayOn3dPoint Points    = new ArrayOn3dPoint();

                for (int i = 0; i < Pts.Count; i++)
                {
                    Points.Append(Pts[i]);
                }

                RhUtil.RhinoGetTightBoundingBox(Surfaces, ref TightOBox, false, null);
                TightOBox.Set(Points, true);
                OverallBBox = new OnBoundingBox(new On3dPoint(TightOBox.Min().x - 1, TightOBox.Min().y - 1, TightOBox.Min().z - 1), new On3dPoint(TightOBox.Max().x + 1, TightOBox.Max().y + 1, TightOBox.Max().z + 1));

                this.X_Incr = (OverallBBox.Max().x - OverallBBox.Min().x) / VoxelCT;
                this.Y_Incr = (OverallBBox.Max().y - OverallBBox.Min().y) / VoxelCT;
                this.Z_Incr = (OverallBBox.Max().z - OverallBBox.Min().z) / VoxelCT;

                //For((int XBox = 0; XBox < VoxelCT; XBox++)
                Parallel.For(0, VoxelCT, XBox =>
                {
                    RhUtil.RhinoApp().SetStatusBarMessagePane(string.Format("Voxelizing: {0}%", Math.Round((double)XBox / VoxelCT - 1, 2) * 100));
                    for (int YBox = 0; YBox < VoxelCT; YBox++)
                    {
                        for (int ZBox = 0; ZBox < VoxelCT; ZBox++)
                        {
                            BoxMin = new On3dPoint((OverallBBox.Min().x + this.X_Incr * XBox) - X_Incr / 10, (OverallBBox.Min().y + this.Y_Incr * YBox) - Y_Incr / 10, (OverallBBox.Min().z + this.Z_Incr * ZBox) - Z_Incr / 10);
                            BoxMax = new On3dPoint((OverallBBox.Min().x + this.X_Incr * (XBox + 1)) + X_Incr / 10, (OverallBBox.Min().y + this.Y_Incr * (YBox + 1)) + Y_Incr / 10, (OverallBBox.Min().z + this.Z_Incr * (ZBox + 1)) + X_Incr / 10);
                            this.Voxel[XBox, YBox, ZBox] = new List <On3dPoint>();
                            this.Voxel[XBox, YBox, ZBox].Add(BoxMin);
                            this.Voxel[XBox, YBox, ZBox].Add(BoxMax);
                            this.VoxelInventory[XBox, YBox, ZBox] = new List <int>();
                            for (int Index = 0; Index < ModelSurfaces.Count(); Index++)
                            {
                                OnBoundingBox TestBox = new OnBoundingBox();
                                TestBox = new OnBoundingBox(this.Voxel[XBox, YBox, ZBox][0], this.Voxel[XBox, YBox, ZBox][1]);
                                if (BoxIntersection(ModelSurfaces, TestBox, Index))
                                {
                                    this.VoxelInventory[XBox, YBox, ZBox].Add(Index);
                                }
                            }
                        }
                    }
                });
            }
            public VoxelGrid(RhCommon_Scene ModelSurfaces, List<IOn3dPoint> Pts, int VG_Domain)
            {
                VoxelCT = VG_Domain;
                VoxelInventory = new List<int>[VoxelCT, VoxelCT, VoxelCT];
                Voxel = new List<On3dPoint>[VoxelCT, VoxelCT, VoxelCT];
                IRhinoObject[] Surfaces = new IRhinoObject[ModelSurfaces.Count()];

                OnBoundingBox TightOBox = new OnBoundingBox();
                On3dPoint BoxMin = new On3dPoint();
                On3dPoint BoxMax = new On3dPoint();
                ArrayOn3dPoint Points = new ArrayOn3dPoint();

                for (int i = 0; i < Pts.Count; i++)
                {
                    Points.Append(Pts[i]);
                }

                RhUtil.RhinoGetTightBoundingBox(Surfaces, ref TightOBox, false, null);
                TightOBox.Set(Points, true);
                OverallBBox = new OnBoundingBox(new On3dPoint(TightOBox.Min().x - 1, TightOBox.Min().y - 1, TightOBox.Min().z - 1), new On3dPoint(TightOBox.Max().x + 1, TightOBox.Max().y + 1, TightOBox.Max().z + 1));

                this.X_Incr = (OverallBBox.Max().x - OverallBBox.Min().x) / VoxelCT;
                this.Y_Incr = (OverallBBox.Max().y - OverallBBox.Min().y) / VoxelCT;
                this.Z_Incr = (OverallBBox.Max().z - OverallBBox.Min().z) / VoxelCT;

                //For((int XBox = 0; XBox < VoxelCT; XBox++)
                Parallel.For(0, VoxelCT, XBox =>
                {
                    RhUtil.RhinoApp().SetStatusBarMessagePane(string.Format("Voxelizing: {0}%", Math.Round((double)XBox / VoxelCT-1, 2) * 100));
                    for (int YBox = 0; YBox < VoxelCT; YBox++)
                    {
                        for (int ZBox = 0; ZBox < VoxelCT; ZBox++)
                        {
                            BoxMin = new On3dPoint((OverallBBox.Min().x + this.X_Incr * XBox) - X_Incr / 10, (OverallBBox.Min().y + this.Y_Incr * YBox) - Y_Incr / 10, (OverallBBox.Min().z + this.Z_Incr * ZBox) - Z_Incr / 10);
                            BoxMax = new On3dPoint((OverallBBox.Min().x + this.X_Incr * (XBox + 1)) + X_Incr / 10, (OverallBBox.Min().y + this.Y_Incr * (YBox + 1)) + Y_Incr / 10, (OverallBBox.Min().z + this.Z_Incr * (ZBox + 1)) + X_Incr / 10);
                            this.Voxel[XBox, YBox, ZBox] = new List<On3dPoint>();
                            this.Voxel[XBox, YBox, ZBox].Add(BoxMin);
                            this.Voxel[XBox, YBox, ZBox].Add(BoxMax);
                            this.VoxelInventory[XBox, YBox, ZBox] = new List<int>();
                            for (int Index = 0; Index < ModelSurfaces.Count(); Index++)
                            {
                                OnBoundingBox TestBox = new OnBoundingBox();
                                TestBox = new OnBoundingBox(this.Voxel[XBox, YBox, ZBox][0], this.Voxel[XBox, YBox, ZBox][1]);
                                if (BoxIntersection(ModelSurfaces, TestBox, Index))
                                {
                                    this.VoxelInventory[XBox, YBox, ZBox].Add(Index);
                                }
                            }
                        }
                    }
                });
            }
Exemplo n.º 5
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;
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        ///<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;
 }
Exemplo n.º 10
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            // Select a curve object
            MRhinoGetObject go = new MRhinoGetObject();

            go.SetCommandPrompt("Select curve");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            // Validate the selection
            IRhinoObject obj = go.Object(0).Object();

            if (null == obj)
            {
                return(IRhinoCommand.result.failure);
            }

            // Get the active view
            MRhinoView view = RhUtil.RhinoApp().ActiveView();

            if (null == view)
            {
                return(IRhinoCommand.result.failure);
            }

            // Get the construction plane from the active view
            OnPlane plane = new OnPlane(view.ActiveViewport().ConstructionPlane().m_plane);

            // Create a construction plane aligned bounding box
            OnBoundingBox bbox = new OnBoundingBox();

            IRhinoObject[] objs = new IRhinoObject[1] {
                obj
            };
            bool rc = RhUtil.RhinoGetTightBoundingBox(objs, ref bbox, false, plane);

            if (rc == false)
            {
                return(IRhinoCommand.result.failure);
            }

            // Validate bounding box
            if (0 != bbox.IsDegenerate())
            {
                RhUtil.RhinoApp().Print("Curve's tight bounding box is degenerate.\n");
                return(IRhinoCommand.result.nothing);
            }

            // ON_BrepBox wants 8 points defining the box corners
            // arranged in this order:
            //
            //          v7______________v6
            //           |\             |\
            //           | \            | \
            //           |  \ _____________\ 
            //           |   v4         |   v5
            //           |   |          |   |
            //           |   |          |   |
            //          v3---|---------v2   |
            //           \   |          \   |
            //            \  |           \  |
            //             \ |            \ |
            //              \v0____________\v1
            //
            On3dPoint[] box_corners = new On3dPoint[8];
            box_corners[0] = bbox.Corner(0, 0, 0);
            box_corners[1] = bbox.Corner(1, 0, 0);
            box_corners[2] = bbox.Corner(1, 1, 0);
            box_corners[3] = bbox.Corner(0, 1, 0);
            box_corners[4] = bbox.Corner(0, 0, 1);
            box_corners[5] = bbox.Corner(1, 0, 1);
            box_corners[6] = bbox.Corner(1, 1, 1);
            box_corners[7] = bbox.Corner(0, 1, 1);

            // Transform points to the world-xy plane
            OnXform p2w = new OnXform();

            p2w.ChangeBasis(plane, OnUtil.On_xy_plane);
            for (int i = 0; i < 8; i++)
            {
                box_corners[i].Transform(p2w);
            }

            // Make a brep box
            OnBrep brep = OnUtil.ON_BrepBox(box_corners);

            if (null != brep)
            {
                context.m_doc.AddBrepObject(brep);
                context.m_doc.Redraw();
            }

            return(IRhinoCommand.result.success);
        }
Exemplo n.º 11
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            // Select a curve object
              MRhinoGetObject go = new MRhinoGetObject();
              go.SetCommandPrompt("Select curve");
              go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
              go.GetObjects(1, 1);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              // Validate the selection
              IRhinoObject obj = go.Object(0).Object();
              if (null == obj)
            return IRhinoCommand.result.failure;

              // Get the active view
              MRhinoView view = RhUtil.RhinoApp().ActiveView();
              if (null == view)
            return IRhinoCommand.result.failure;

              // Get the construction plane from the active view
              OnPlane plane = new OnPlane(view.ActiveViewport().ConstructionPlane().m_plane);

              // Create a construction plane aligned bounding box
              OnBoundingBox bbox = new OnBoundingBox();
              IRhinoObject[] objs = new IRhinoObject[1] { obj };
              bool rc = RhUtil.RhinoGetTightBoundingBox(objs, ref bbox, false, plane);
              if (rc == false)
            return IRhinoCommand.result.failure;

              // Validate bounding box
              if (0 != bbox.IsDegenerate())
              {
            RhUtil.RhinoApp().Print("Curve's tight bounding box is degenerate.\n");
            return IRhinoCommand.result.nothing;
              }

              // ON_BrepBox wants 8 points defining the box corners
              // arranged in this order:
              //
              //          v7______________v6
              //           |\             |\
              //           | \            | \
              //           |  \ _____________\
              //           |   v4         |   v5
              //           |   |          |   |
              //           |   |          |   |
              //          v3---|---------v2   |
              //           \   |          \   |
              //            \  |           \  |
              //             \ |            \ |
              //              \v0____________\v1
              //
              On3dPoint[] box_corners = new On3dPoint[8];
              box_corners[0] = bbox.Corner(0, 0, 0);
              box_corners[1] = bbox.Corner(1, 0, 0);
              box_corners[2] = bbox.Corner(1, 1, 0);
              box_corners[3] = bbox.Corner(0, 1, 0);
              box_corners[4] = bbox.Corner(0, 0, 1);
              box_corners[5] = bbox.Corner(1, 0, 1);
              box_corners[6] = bbox.Corner(1, 1, 1);
              box_corners[7] = bbox.Corner(0, 1, 1);

              // Transform points to the world-xy plane
              OnXform p2w = new OnXform();
              p2w.ChangeBasis(plane, OnUtil.On_xy_plane);
              for (int i = 0; i < 8; i++)
            box_corners[i].Transform(p2w);

              // Make a brep box
              OnBrep brep = OnUtil.ON_BrepBox(box_corners);
              if (null != brep)
              {
            context.m_doc.AddBrepObject(brep);
            context.m_doc.Redraw();
              }

              return IRhinoCommand.result.success;
        }