private static OnCurve CreateOuterTrimmingCurve(
            OnSurface s,
            int side                   // 0 = SW to SE
            // 1 = SE to NE
            // 2 = NE to NW
            // 3 = NW to SW
            )
        {
            // A trimming curve is a 2d curve whose image lies in the surface's domain.
            // The "active" portion of the surface is to the left of the trimming curve.
            // An outer trimming loop consists of a simple closed curve running
            // counter-clockwise around the region it trims.

            //In cases when trim curve is not easily defined in surface domain,
            //use ON_Surface::Pullback only be careful about curve direction to ensure
            //loop trims run anti-clockwise for outer loop and clockwise for inner loop.

            //In this case, trim curves lie on the four edges of the surface
            On2dPoint from = new On2dPoint();
            On2dPoint to = new On2dPoint();
            double    u0 = double.NaN, u1 = double.NaN, v0 = double.NaN, v1 = double.NaN;

            s.GetDomain(0, ref u0, ref u1);
            s.GetDomain(1, ref v0, ref v1);

            switch (side)
            {
            case 0: // SW to SE
                from.x = u0; from.y = v0;
                to.x   = u1; to.y = v0;
                break;

            case 1: // SE to NE
                from.x = u1; from.y = v0;
                to.x   = u1; to.y = v1;
                break;

            case 2: // NE to NW
                from.x = u1; from.y = v1;
                to.x   = u0; to.y = v1;
                break;

            case 3: // NW to SW
                from.x = u0; from.y = v1;
                to.x   = u0; to.y = v0;
                break;

            default:
                return(null);
            }

            OnCurve c2d = new OnLineCurve(from, to);

            if (c2d != null)
            {
                c2d.SetDomain(0.0, 1.0);
            }
            return(c2d);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// TwistedCubeEdgeCurve
        /// </summary>
        static OnCurve TwistedCubeEdgeCurve(
            IOn3dPoint from,
            IOn3dPoint to
            )
        {
            // Creates a 3d line segment to be used as a 3d curve in a OnBrep
            OnLineCurve c3d = new OnLineCurve(from, to);

            c3d.SetDomain(0.0, 1.0);
            return(c3d);
        }
        private static OnCurve CreateLinearCurve(On3dPoint from, On3dPoint to)
        {
            // creates a 3d line segment to be used as a 3d curve in a ON_Brep
            OnCurve c3d = new OnLineCurve(from, to);

            if (c3d != null)
            {
                c3d.SetDomain(0.0, 10.0);
            }

            return(c3d);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// TwistedCubeTrimmingCurve
        /// </summary>
        static OnCurve TwistedCubeTrimmingCurve(
            IOnSurface s,
            int side // 0 = SW to SE
                     // 1 = SE to NE
                     // 2 = NE to NW
                     // 3 = NW to SW
            )
        {
            // A trimming curve is a 2d curve whose image lies in the surface's domain.
            // The "active" portion of the surface is to the left of the trimming curve.
            // An outer trimming loop consists of a simple closed curve running
            // counter-clockwise around the region it trims.

            On2dPoint from = new On2dPoint();
            On2dPoint to = new On2dPoint();
            double    u0 = 0.0, u1 = 0.0, v0 = 0.0, v1 = 0.0;

            s.GetDomain(0, ref u0, ref u1);
            s.GetDomain(1, ref v0, ref v1);

            switch (side)
            {
            case 0: // SW to SE
                from.x = u0; from.y = v0;
                to.x   = u1; to.y = v0;
                break;

            case 1: // SE to NE
                from.x = u1; from.y = v0;
                to.x   = u1; to.y = v1;
                break;

            case 2: // NE to NW
                from.x = u1; from.y = v1;
                to.x   = u0; to.y = v1;
                break;

            case 3: // NW to SW
                from.x = u0; from.y = v1;
                to.x   = u0; to.y = v0;
                break;

            default:
                return(null);
            }

            OnLineCurve c2d = new OnLineCurve(from, to);

            c2d.SetDomain(0.0, 1.0);

            return(c2d);
        }
        private static OnCurve CreateTrimmingCurve(
            OnSurface s,
            int side                    // 0 = SW to SE
            // 1 = SE to NE
            // 2 = NE to NW
            // 3 = NW to SW
            )
        {
            // A trimming curve is a 2d curve whose image lies in the surface's domain.
            // The "active" portion of the surface is to the left of the trimming curve.
            // An outer trimming loop consists of a simple closed curve running
            // counter-clockwise around the region it trims.
            // An inner trimming loop consists of a simple closed curve running
            // clockwise around the region the hole.

            On2dPoint from = new On2dPoint();
            On2dPoint to = new On2dPoint();
            double    u0 = double.NaN, u1 = double.NaN, v0 = double.NaN, v1 = double.NaN;

            s.GetDomain(0, ref u0, ref u1);
            s.GetDomain(1, ref v0, ref v1);

            switch (side)
            {
            case 0: // SW to SE
                from.x = u0; from.y = v0;
                to.x   = u1; to.y = v0;
                break;

            case 1: // diagonal
                from.x = u1; from.y = v0;
                to.x   = (u0 + u1) / 2; to.y = v1;
                break;

            case 2: // diagonal
                from.x = (u0 + u1) / 2; from.y = v1;
                to.x   = u0; to.y = v0;
                break;

            default:
                return(null);
            }

            OnCurve c2d = new OnLineCurve(from, to);

            if (c2d != null)
            {
                c2d.SetDomain(0.0, 1.0);
            }
            return(c2d);
        }
        /// <summary>
        /// TwistedCubeTrimmingCurve
        /// </summary>
        static OnCurve TwistedCubeTrimmingCurve(
      IOnSurface s,
      int side // 0 = SW to SE
               // 1 = SE to NE
               // 2 = NE to NW
               // 3 = NW to SW
      )
        {
            // A trimming curve is a 2d curve whose image lies in the surface's domain.
              // The "active" portion of the surface is to the left of the trimming curve.
              // An outer trimming loop consists of a simple closed curve running
              // counter-clockwise around the region it trims.

              On2dPoint from = new On2dPoint();
              On2dPoint to = new On2dPoint();
              double u0 = 0.0, u1 = 0.0, v0 = 0.0, v1 = 0.0;

              s.GetDomain(0, ref u0, ref u1);
              s.GetDomain(1, ref v0, ref v1);

              switch (side)
              {
              case 0:  // SW to SE
            from.x = u0; from.y = v0;
            to.x   = u1; to.y   = v0;
            break;
              case 1: // SE to NE
            from.x = u1; from.y = v0;
            to.x   = u1; to.y   = v1;
            break;
              case 2: // NE to NW
            from.x = u1; from.y = v1;
            to.x   = u0; to.y   = v1;
            break;
              case 3: // NW to SW
            from.x = u0; from.y = v1;
            to.x   = u0; to.y   = v0;
            break;
              default:
            return null;
              }

              OnLineCurve c2d = new OnLineCurve(from, to);
              c2d.SetDomain(0.0, 1.0);

              return c2d;
        }
   /// <summary>
   /// TwistedCubeEdgeCurve
   /// </summary>
   static OnCurve TwistedCubeEdgeCurve(
 IOn3dPoint from, 
 IOn3dPoint to
 )
   {
       // Creates a 3d line segment to be used as a 3d curve in a OnBrep
         OnLineCurve c3d = new OnLineCurve(from, to);
         c3d.SetDomain(0.0, 1.0);
         return c3d;
   }
        private static OnCurve CreateLinearCurve(On3dPoint from, On3dPoint to)
        {
            // creates a 3d line segment to be used as a 3d curve in a ON_Brep
              OnCurve c3d = new OnLineCurve(from, to);
              if (c3d != null)
            c3d.SetDomain(0.0, 10.0);

              return c3d;
        }
        private static OnCurve CreateOuterTrimmingCurve(
                              OnSurface s,
                              int side // 0 = SW to SE
      // 1 = SE to NE
      // 2 = NE to NW
      // 3 = NW to SW
                              )
        {
            // A trimming curve is a 2d curve whose image lies in the surface's domain.
              // The "active" portion of the surface is to the left of the trimming curve.
              // An outer trimming loop consists of a simple closed curve running
              // counter-clockwise around the region it trims.

              //In cases when trim curve is not easily defined in surface domain,
              //use ON_Surface::Pullback only be careful about curve direction to ensure
              //loop trims run anti-clockwise for outer loop and clockwise for inner loop.

              //In this case, trim curves lie on the four edges of the surface
              On2dPoint from = new On2dPoint();
              On2dPoint to = new On2dPoint();
              double u0 = double.NaN, u1 = double.NaN, v0 = double.NaN, v1 = double.NaN;

              s.GetDomain(0, ref u0, ref u1);
              s.GetDomain(1, ref v0, ref v1);

              switch (side)
              {
            case 0:  // SW to SE
              from.x = u0; from.y = v0;
              to.x = u1; to.y = v0;
              break;
            case 1: // SE to NE
              from.x = u1; from.y = v0;
              to.x = u1; to.y = v1;
              break;
            case 2: // NE to NW
              from.x = u1; from.y = v1;
              to.x = u0; to.y = v1;
              break;
            case 3: // NW to SW
              from.x = u0; from.y = v1;
              to.x = u0; to.y = v0;
              break;
            default:
              return null;
              }

              OnCurve c2d = new OnLineCurve(from, to);
              if (c2d != null)
            c2d.SetDomain(0.0, 1.0);
              return c2d;
        }
        //Trim curves must run is clockwise direction
        private static OnCurve CreateInnerTrimmingCurve(
                  OnSurface s,
                  int side // 0 = near SE to SW
      // 1 = near SW to NW
      // 2 = near NW to NE
      // 3 = near NE to SE
                  )
        {
            // A trimming curve is a 2d curve whose image lies in the surface's domain.
              // The "active" portion of the surface is to the left of the trimming curve.
              // An inner trimming loop consists of a simple closed curve running
              // clockwise around the region the hole.

              //In this case, trim curves lie with 0.2 domain distance from surface edge
              On2dPoint from = new On2dPoint();
              On2dPoint to = new On2dPoint();
              double u0 = double.NaN,
              u1 = double.NaN,
              v0 = double.NaN,
              v1 = double.NaN;

              s.GetDomain(0, ref u0, ref u1);
              s.GetDomain(1, ref v0, ref v1);

              double udis = 0.2 * (u1 - u0);
              double vdis = 0.2 * (v1 - v0);

              u0 += udis;
              u1 -= udis;
              v0 += vdis;
              v1 -= vdis;

              switch (side)
              {
            case 0:  // near SE to SW
              from.x = u1; from.y = v0;
              to.x = u0; to.y = v0;
              break;
            case 1: // near SW to NW
              from.x = u0; from.y = v0;
              to.x = u0; to.y = v1;
              break;
            case 2: // near NW to NE
              from.x = u0; from.y = v1;
              to.x = u1; to.y = v1;
              break;
            case 3: // near NE to SE
              from.x = u1; from.y = v1;
              to.x = u1; to.y = v0;
              break;
            default:
              return null;
              }

              OnCurve c2d = new OnLineCurve(from, to);
              if (c2d != null)
            c2d.SetDomain(0.0, 1.0);

              return c2d;
        }
Ejemplo n.º 11
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            // Define geometry for rail and shape curves
              On3dPoint start_point = new On3dPoint(0, 0, 0);
              On3dPoint end_point = new On3dPoint(10, 0, 0);
              OnPlane plane = new OnPlane(OnUtil.On_yz_plane);

              plane.SetOrigin(start_point);
              OnCircle circle0 = new OnCircle(plane, 5);

              plane.SetOrigin(end_point);
              OnCircle circle1 = new OnCircle(plane, 2);

              // Build rail and shape curves
              OnLineCurve line_curve = new OnLineCurve(start_point, end_point);
              OnArcCurve arc_curve0 = new OnArcCurve(circle0);
              OnArcCurve arc_curve1 = new OnArcCurve(circle1);

              // Build poly edge curve
              MRhinoPolyEdge rail_curve = new MRhinoPolyEdge();
              rail_curve.Create(line_curve);

              // Create sweep arguments
              MArgsRhinoSweep1 args = new MArgsRhinoSweep1();

              // Add rail curve and related settings
              args.m_rail_curve = rail_curve;
              args.m_bHaveRailPickPoint = false;
              args.m_bClosed = false;
              args.m_bUsePivotPoint = false;

              // Add shape curves
              List<OnCurve> shape_curves = new List<OnCurve>();
              shape_curves.Add(arc_curve0);
              shape_curves.Add(arc_curve1);
              args.m_shape_curves = shape_curves.ToArray();

              // Specify parameters on rail closest to shapes
              args.m_rail_params.Append(rail_curve.Domain()[0]);
              args.m_rail_params.Append(rail_curve.Domain()[1]);

              // No starting sweep point
              args.set_m_bUsePoints(0, 0);
              // No ending sweep point
              args.set_m_bUsePoints(1, 0);
              // 0 = Freeform
              args.m_style = 0;
              // 0 = Do Not Simplify
              args.m_simplify = 0;
              // Sample point count for rebuilding shapes
              args.m_rebuild_count = -1;
              // 0 = don't miter
              args.m_miter_type = 0;
              // Standard tolerances
              args.m_refit_tolerance = context.m_doc.AbsoluteTolerance();
              args.m_sweep_tolerance = context.m_doc.AbsoluteTolerance();
              args.m_angle_tolerance = context.m_doc.AngleToleranceRadians();

              OnBrep[] breps = null;
              if (RhUtil.RhinoSweep1(ref args, out breps))
              {
            for (int i = 0; i < breps.Length; i++)
              context.m_doc.AddBrepObject(breps[i]);
            context.m_doc.Redraw();
              }

              return IRhinoCommand.result.success;
        }
Ejemplo n.º 12
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            // Define geometry for rail and shape curves
            On3dPoint start_point = new On3dPoint(0, 0, 0);
            On3dPoint end_point   = new On3dPoint(10, 0, 0);
            OnPlane   plane       = new OnPlane(OnUtil.On_yz_plane);

            plane.SetOrigin(start_point);
            OnCircle circle0 = new OnCircle(plane, 5);

            plane.SetOrigin(end_point);
            OnCircle circle1 = new OnCircle(plane, 2);

            // Build rail and shape curves
            OnLineCurve line_curve = new OnLineCurve(start_point, end_point);
            OnArcCurve  arc_curve0 = new OnArcCurve(circle0);
            OnArcCurve  arc_curve1 = new OnArcCurve(circle1);

            // Build poly edge curve
            MRhinoPolyEdge rail_curve = new MRhinoPolyEdge();

            rail_curve.Create(line_curve);

            // Create sweep arguments
            MArgsRhinoSweep1 args = new MArgsRhinoSweep1();

            // Add rail curve and related settings
            args.m_rail_curve         = rail_curve;
            args.m_bHaveRailPickPoint = false;
            args.m_bClosed            = false;
            args.m_bUsePivotPoint     = false;

            // Add shape curves
            List <OnCurve> shape_curves = new List <OnCurve>();

            shape_curves.Add(arc_curve0);
            shape_curves.Add(arc_curve1);
            args.m_shape_curves = shape_curves.ToArray();

            // Specify parameters on rail closest to shapes
            args.m_rail_params.Append(rail_curve.Domain()[0]);
            args.m_rail_params.Append(rail_curve.Domain()[1]);

            // No starting sweep point
            args.set_m_bUsePoints(0, 0);
            // No ending sweep point
            args.set_m_bUsePoints(1, 0);
            // 0 = Freeform
            args.m_style = 0;
            // 0 = Do Not Simplify
            args.m_simplify = 0;
            // Sample point count for rebuilding shapes
            args.m_rebuild_count = -1;
            // 0 = don't miter
            args.m_miter_type = 0;
            // Standard tolerances
            args.m_refit_tolerance = context.m_doc.AbsoluteTolerance();
            args.m_sweep_tolerance = context.m_doc.AbsoluteTolerance();
            args.m_angle_tolerance = context.m_doc.AngleToleranceRadians();

            OnBrep[] breps = null;
            if (RhUtil.RhinoSweep1(ref args, out breps))
            {
                for (int i = 0; i < breps.Length; i++)
                {
                    context.m_doc.AddBrepObject(breps[i]);
                }
                context.m_doc.Redraw();
            }

            return(IRhinoCommand.result.success);
        }
        //Trim curves must run is clockwise direction
        private static OnCurve CreateInnerTrimmingCurve(
            OnSurface s,
            int side       // 0 = near SE to SW
            // 1 = near SW to NW
            // 2 = near NW to NE
            // 3 = near NE to SE
            )
        {
            // A trimming curve is a 2d curve whose image lies in the surface's domain.
            // The "active" portion of the surface is to the left of the trimming curve.
            // An inner trimming loop consists of a simple closed curve running
            // clockwise around the region the hole.

            //In this case, trim curves lie with 0.2 domain distance from surface edge
            On2dPoint from = new On2dPoint();
            On2dPoint to   = new On2dPoint();
            double    u0   = double.NaN,
                      u1   = double.NaN,
                      v0   = double.NaN,
                      v1   = double.NaN;

            s.GetDomain(0, ref u0, ref u1);
            s.GetDomain(1, ref v0, ref v1);

            double udis = 0.2 * (u1 - u0);
            double vdis = 0.2 * (v1 - v0);

            u0 += udis;
            u1 -= udis;
            v0 += vdis;
            v1 -= vdis;

            switch (side)
            {
            case 0: // near SE to SW
                from.x = u1; from.y = v0;
                to.x   = u0; to.y = v0;
                break;

            case 1: // near SW to NW
                from.x = u0; from.y = v0;
                to.x   = u0; to.y = v1;
                break;

            case 2: // near NW to NE
                from.x = u0; from.y = v1;
                to.x   = u1; to.y = v1;
                break;

            case 3: // near NE to SE
                from.x = u1; from.y = v1;
                to.x   = u1; to.y = v0;
                break;

            default:
                return(null);
            }

            OnCurve c2d = new OnLineCurve(from, to);

            if (c2d != null)
            {
                c2d.SetDomain(0.0, 1.0);
            }

            return(c2d);
        }