Пример #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);
        }
Пример #2
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 polysurface to explode");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object);
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            IOnBrep brep = go.Object(0).Brep();

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

            for (int i = 0; i < brep.m_F.Count(); i++)
            {
                OnBrep faceBrep = brep.DuplicateFace(i, true);
                if (null != faceBrep)
                {
                    context.m_doc.AddBrepObject(faceBrep);
                }
            }

            context.m_doc.DeleteObject(go.Object(0));
            context.m_doc.Redraw();

            return(IRhinoCommand.result.success);
        }
        ///<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 surface edge");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.edge_object);
            go.EnableSubObjectSelect();
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            MRhinoObjRef obj_ref   = go.Object(0);
            IOnBrepEdge  brep_edge = obj_ref.Edge();

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

            IOnBrep brep = brep_edge.Brep();

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

            // TODO: add functionality here...

            return(IRhinoCommand.result.success);
        }
Пример #4
0
 public SampleCsSurfaceDirectionConduit()
     : base(new MSupportChannels(MSupportChannels.SC_DRAWOVERLAY), false)
 {
     m_brep    = null;
     m_bFlip   = false;
     m_points  = new ArrayOn3dPoint();
     m_normals = new ArrayOn3dVector();
 }
        ///<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 two surfaces or polysurfacs to intersect");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object);
            go.EnableSubObjectSelect(false);
            go.GetObjects(2, 2);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            IOnBrep B0 = go.Object(0).Brep();
            IOnBrep B1 = go.Object(1).Brep();

            if (null == B0 || null == B1)
            {
                return(IRhinoCommand.result.failure);
            }

            OnCurve[]      curves = null;
            On3dPointArray points = null;
            bool           rc     = RhUtil.RhinoIntersectBreps(B0, B1, context.m_doc.AbsoluteTolerance(), out curves, out points);

            if (
                false == rc ||
                null == curves ||
                0 == curves.Length ||
                null == points ||
                0 == curves.Length
                )
            {
                RhUtil.RhinoApp().Print("No intersections found.\n");
                return(IRhinoCommand.result.nothing);
            }

            if (null != curves)
            {
                for (int i = 0; i < curves.Length; i++)
                {
                    context.m_doc.AddCurveObject(curves[i]);
                }
            }

            if (null != points)
            {
                for (int i = 0; i < points.Count(); i++)
                {
                    context.m_doc.AddPointObject(points[i]);
                }
            }

            context.m_doc.Redraw();

            return(IRhinoCommand.result.success);
        }
Пример #6
0
        private static double GetBrepVolume(IOnBrep brep)
        {
            double volume = 0.0;

            if (null != brep)
            {
                OnMassProperties mp = new OnMassProperties();
                if (brep.VolumeMassProperties(ref mp, true))
                {
                    volume = Math.Abs(mp.Volume());
                }
            }
            return(volume);
        }
Пример #7
0
        private static double GetBrepArea(IOnBrep brep)
        {
            double area = 0.0;

            if (null != brep)
            {
                OnMassProperties mp = new OnMassProperties();
                if (brep.AreaMassProperties(ref mp, true))
                {
                    area = Math.Abs(mp.Area());
                }
            }
            return(area);
        }
Пример #8
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);
        }
    ///<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 edge curve");
      go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.edge_object);
      go.GetObjects(1, 1);
      if (go.CommandResult() != IRhinoCommand.result.success)
        return go.CommandResult();

      IRhinoObject obj = go.Object(0).Object();
      IOnBrep brep = go.Object(0).Brep();
      IOnBrepEdge edge = go.Object(0).Edge();
      if (null == obj || null == brep || null == edge)
        return IRhinoCommand.result.failure;

      MRhinoObjectAttributes attribs = new MRhinoObjectAttributes(obj.Attributes());
      if (attribs.GroupCount() > 0)
        attribs.RemoveFromAllGroups();

      for (int i = 0; i < edge.TrimCount(); i++)
      {
        IOnBrepTrim trim = edge.Trim(i);
        if (null != trim)
        {
          IOnBrepFace face = trim.Face();
          if (null != face)
          {
            OnBrep face_brep = brep.DuplicateFace(face.m_face_index, true);
            if (null != face_brep)
            {
              MRhinoBrepObject face_brep_obj = context.m_doc.AddBrepObject(face_brep, attribs);
              if (null != face_brep_obj)
                face_brep_obj.Select();
            }
          }
        }
      }

      context.m_doc.Redraw();

      return IRhinoCommand.result.success;
    }
Пример #10
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 GetBrepVolume(IOnBrep brep)
 {
     double volume = 0.0;
       if (null != brep)
       {
     OnMassProperties mp = new OnMassProperties();
     if (brep.VolumeMassProperties(ref mp, true))
       volume = Math.Abs(mp.Volume());
       }
       return volume;
 }
 private static double GetBrepArea(IOnBrep brep)
 {
     double area = 0.0;
       if (null != brep)
       {
     OnMassProperties mp = new OnMassProperties();
     if (brep.AreaMassProperties(ref mp, true))
       area = Math.Abs(mp.Area());
       }
       return area;
 }
Пример #13
0
        public void SetBrep(IOnBrep brep)
        {
            if (null == brep || !brep.IsValid())
            {
                return;
            }

            m_brep = brep;

            int face_count = m_brep.m_F.Count();

            m_points.Reserve(face_count * SURFACE_ARROW_COUNT * SURFACE_ARROW_COUNT);
            m_normals.Reserve(face_count * SURFACE_ARROW_COUNT * SURFACE_ARROW_COUNT);

            m_points.SetCount(0);
            m_normals.SetCount(0);

            for (int i = 0; i < face_count; i++)
            {
                IOnBrepFace face = m_brep.m_F[i];
                IOnBrepLoop loop = face.OuterLoop();
                if (null == loop)
                {
                    continue;
                }

                OnInterval udomain = face.Domain(0);
                OnInterval vdomain = face.Domain(1);

                if (loop.m_pbox.IsValid())
                {
                    OnInterval domain = new OnInterval();
                    domain.Set(loop.m_pbox.m_min.x, loop.m_pbox.m_max.x);
                    domain.Intersection(udomain);
                    if (domain.IsIncreasing())
                    {
                        udomain.Set(domain.Min(), domain.Max());
                    }
                    domain.Set(loop.m_pbox.m_min.y, loop.m_pbox.m_max.y);
                    domain.Intersection(vdomain);
                    if (domain.IsIncreasing())
                    {
                        vdomain.Set(domain.Min(), domain.Max());
                    }
                }

                bool bUntrimmed = m_brep.FaceIsSurface(i);

                ArrayOnInterval intervals = new ArrayOnInterval();
                bool            bRev      = face.m_bRev;

                for (double u = 0.0; u < SURFACE_ARROW_COUNT; u += 1.0)
                {
                    double d = u / (SURFACE_ARROW_COUNT - 1.0);
                    double s = udomain.ParameterAt(d);

                    intervals.SetCount(0);

                    if (bUntrimmed || RhUtil.RhinoGetIsoIntervals(face, 1, s, intervals) > 0)
                    {
                        for (double v = 0.0; v < SURFACE_ARROW_COUNT; v += 1.0)
                        {
                            d = v / (SURFACE_ARROW_COUNT - 1.0);
                            double t = vdomain.ParameterAt(d);

                            bool bAdd = bUntrimmed;
                            for (int k = 0; !bAdd && k < intervals.Count(); k++)
                            {
                                if (intervals[k].Includes(t))
                                {
                                    bAdd = true;
                                }
                            }

                            if (bAdd)
                            {
                                On3dPoint  pt  = new On3dPoint();
                                On3dVector du  = new On3dVector();
                                On3dVector dv  = new On3dVector();
                                On3dVector dir = new On3dVector();
                                if (face.EvNormal(s, t, ref pt, ref du, ref dv, ref dir))
                                {
                                    m_points.Append(pt);
                                    if (bRev)
                                    {
                                        dir.Reverse();
                                    }
                                    m_normals.Append(dir);
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #14
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 surface or polysurface for direction display");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object);
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            MRhinoObjRef obj_ref = go.Object(0);
            IOnBrep      brep    = obj_ref.Brep();

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

            bool bIsSolid = brep.IsSolid();
            bool bFlip    = false;

            SampleCsSurfaceDirectionConduit conduit = new SampleCsSurfaceDirectionConduit();

            conduit.SetBrep(brep);
            conduit.Enable();
            context.m_doc.Redraw();

            MRhinoGetOption gf = new MRhinoGetOption();

            gf.SetCommandPrompt("Press Enter when done");
            gf.AcceptNothing();
            if (!bIsSolid)
            {
                gf.AddCommandOption(new MRhinoCommandOptionName("Flip"));
            }

            for (; ;)
            {
                IRhinoGet.result res = gf.GetOption();

                if (res == IRhinoGet.result.option)
                {
                    bFlip = !bFlip;
                    conduit.SetFlip(bFlip);
                    context.m_doc.Redraw();
                    continue;
                }

                if (res == IRhinoGet.result.nothing)
                {
                    if (!bIsSolid && bFlip)
                    {
                        OnBrep flipped_brep = new OnBrep(brep);
                        flipped_brep.Flip();
                        context.m_doc.ReplaceObject(obj_ref, flipped_brep);
                    }
                }

                break;
            }

            conduit.Disable();
            context.m_doc.Redraw();

            return(IRhinoCommand.result.success);
        }
        public void SetBrep(IOnBrep brep)
        {
            if (null == brep || !brep.IsValid())
            return;

              m_brep = brep;

              int face_count = m_brep.m_F.Count();
              m_points.Reserve(face_count * SURFACE_ARROW_COUNT * SURFACE_ARROW_COUNT);
              m_normals.Reserve(face_count * SURFACE_ARROW_COUNT * SURFACE_ARROW_COUNT);

              m_points.SetCount(0);
              m_normals.SetCount(0);

              for (int i = 0; i < face_count; i++)
              {
            IOnBrepFace face = m_brep.m_F[i];
            IOnBrepLoop loop = face.OuterLoop();
            if (null == loop)
              continue;

            OnInterval udomain = face.Domain(0);
            OnInterval vdomain = face.Domain(1);

            if (loop.m_pbox.IsValid())
            {
              OnInterval domain = new OnInterval();
              domain.Set(loop.m_pbox.m_min.x, loop.m_pbox.m_max.x);
              domain.Intersection(udomain);
              if (domain.IsIncreasing())
            udomain.Set(domain.Min(), domain.Max());
              domain.Set(loop.m_pbox.m_min.y, loop.m_pbox.m_max.y);
              domain.Intersection(vdomain);
              if (domain.IsIncreasing())
            vdomain.Set(domain.Min(), domain.Max());
            }

            bool bUntrimmed = m_brep.FaceIsSurface(i);

            ArrayOnInterval intervals = new ArrayOnInterval();
            bool bRev = face.m_bRev;

            for (double u = 0.0; u < SURFACE_ARROW_COUNT; u += 1.0)
            {
              double d = u / (SURFACE_ARROW_COUNT - 1.0);
              double s = udomain.ParameterAt(d);

              intervals.SetCount(0);

              if (bUntrimmed || RhUtil.RhinoGetIsoIntervals(face, 1, s, intervals) > 0)
              {
            for (double v = 0.0; v < SURFACE_ARROW_COUNT; v += 1.0)
            {
              d = v / (SURFACE_ARROW_COUNT - 1.0);
              double t = vdomain.ParameterAt(d);

              bool bAdd = bUntrimmed;
              for (int k = 0; !bAdd && k < intervals.Count(); k++)
              {
                if (intervals[k].Includes(t))
                  bAdd = true;
              }

              if (bAdd)
              {
                On3dPoint pt = new On3dPoint();
                On3dVector du = new On3dVector();
                On3dVector dv = new On3dVector();
                On3dVector dir = new On3dVector();
                if (face.EvNormal(s, t, ref pt, ref du, ref dv, ref dir))
                {
                  m_points.Append(pt);
                  if (bRev)
                    dir.Reverse();
                  m_normals.Append(dir);
                }
              }
            }
              }
            }
              }
        }
 public SampleCsSurfaceDirectionConduit()
     : base(new MSupportChannels(MSupportChannels.SC_DRAWOVERLAY), false)
 {
     m_brep = null;
       m_bFlip = false;
       m_points = new ArrayOn3dPoint();
       m_normals = new ArrayOn3dVector();
 }