Beispiel #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);
        }
        private static void CreateFace(ref OnBrep brep, int si)
        {
            //Add new face to brep
            OnBrepFace face = brep.NewFace(si);

            //Create outer loop and trims for the face
            MakeOuterTrimmingLoop(ref brep, ref face,
                                  A, B, C, D, // Indices of vertices listed in SW,SE,NW,NE order
                                  AB, +1,     // South side edge and its orientation with respect to
                                              // to the trimming curve.  (AB)
                                  BC, +1,     // East side edge and its orientation with respect to
                                              // to the trimming curve.  (BC)
                                  CD, +1,     // North side edge and its orientation with respect to
                                              // to the trimming curve   (CD)
                                  AD, -1      // West side edge and its orientation with respect to
                                              // to the trimming curve   (AD)
                                  );


            //Create loop and trims for the face
            MakeInnerTrimmingLoop(ref brep, ref face,
                                  E, F, G, H, // Indices of hole vertices
                                  EF, +1,     // Parallel to south side edge and its orientation with respect to
                                              // to the trimming curve.  (EF)
                                  FG, +1,     // Parallel to east side edge and its orientation with respect to
                                              // to the trimming curve.  (FG)
                                  GH, +1,     // Parallel to north side edge and its orientation with respect to
                                              // to the trimming curve   (GH)
                                  EH, -1      // Parallel to west side edge and its orientation with respect to
                                              // to the trimming curve   (EH)
                                  );

            //Set face direction relative to surface direction
            face.m_bRev = false;
        }
        private static void CreateEdges(ref OnBrep brep)
        {
            // In this simple example, the edge indices exactly match the 3d
            // curve indices.  In general,the correspondence between edge and
            // curve indices can be arbitrary.  It is permitted for multiple
            // edges to use different portions of the same 3d curve.  The
            // orientation of the edge always agrees with the natural
            // parametric orientation of the curve.

            //outer edges
            // edge that runs from A to B
            CreateOneEdge(ref brep, A, B, AB);

            // edge that runs from B to C
            CreateOneEdge(ref brep, B, C, BC);

            // edge that runs from C to D
            CreateOneEdge(ref brep, C, D, CD);

            // edge that runs from A to D
            CreateOneEdge(ref brep, A, D, AD);

            //Inner Edges
            // edge that runs from E to F
            CreateOneEdge(ref brep, E, F, EF);

            // edge that runs from F to G
            CreateOneEdge(ref brep, F, G, FG);

            // edge that runs from G to H
            CreateOneEdge(ref brep, G, H, GH);

            // edge that runs from E to H
            CreateOneEdge(ref brep, E, H, EH);
        }
Beispiel #4
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);
        }
Beispiel #5
0
        /// <summary>
        /// MakeTwistedCubeFace
        /// </summary>
        static void MakeTwistedCubeFace(
            ref OnBrep brep,
            int si,                                 // index of 3d surface
            int s_dir,                              // orientation of surface with respect to brep
            int vSWi, int vSEi, int vNEi, int vNWi, // Indices of corner vertices listed in SW, SE, NW, NE order
            int eSi,                                // index of edge on south side of surface
            int eS_dir,                             // orientation of edge with respect to surface trim
            int eEi,                                // index of edge on south side of surface
            int eE_dir,                             // orientation of edge with respect to surface trim
            int eNi,                                // index of edge on south side of surface
            int eN_dir,                             // orientation of edge with respect to surface trim
            int eWi,                                // index of edge on south side of surface
            int eW_dir                              // orientation of edge with respect to surface trim
            )
        {
            OnBrepFace face = brep.NewFace(si);

            MakeTwistedCubeTrimmingLoop(
                ref brep,
                ref face,
                vSWi, vSEi, vNEi, vNWi,
                eSi, eS_dir,
                eEi, eE_dir,
                eNi, eN_dir,
                eWi, eW_dir
                );

            face.m_bRev = (s_dir == -1);
        }
        private static void MakeTrimmedFace(ref OnBrep brep,
                                            int si,                 // index of 3d surface
                                            int s_dir,              // orientation of surface with respect to surfce
                                            int v0, int v1, int v2, // Indices of corner vertices
                                            int e0,                 // index of first edge
                                            int e0_dir,             // orientation of edge
                                            int e1,                 // index of second edge
                                            int e1_dir,             // orientation of edge
                                            int e2,                 // index of third edge
                                            int e2_dir              // orientation of edge
                                            )
        {
            //Add new face to brep
            OnBrepFace face = brep.NewFace(si);

            //Create loop and trims for the face
            MakeTrimmingLoop(ref brep, ref face,
                             v0, v1, v2,
                             e0, e0_dir,
                             e1, e1_dir,
                             e2, e2_dir
                             );

            //Set face direction relative to surface direction
            face.m_bRev = (s_dir == -1);
        }
        ///<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;
        }
 private static void CreateFace(ref OnBrep brep, int si)
 {
     MakeTrimmedFace(ref brep,
                     ABC_i,   // Index of face
                     +1,      // orientation of surface with respect to surface
                     A, B, C, // Indices of vertices
                     AB, +1,  // Side edge and its orientation with respect to
                              // to the trimming curve.  (AB)
                     BC, +1,  // Side edge and its orientation with respect to
                              // to the trimming curve.  (BC)
                     AC, -1   // Side edge and its orientation with respect to
                              // to the trimming curve   (AC)
                     );
 }
Beispiel #9
0
        /// <summary>
        /// MakeTwistedCubeEdge
        /// </summary>
        static void MakeTwistedCubeEdge(
            ref OnBrep brep,
            int vi0, // index of start vertex
            int vi1, // index of end vertex
            int c3i  // index of 3d curve
            )
        {
            OnBrepVertex v0   = brep.m_V[vi0];
            OnBrepVertex v1   = brep.m_V[vi1];
            OnBrepEdge   edge = brep.NewEdge(ref v0, ref v1, c3i);

            edge.m_tolerance = 0.0; // this simple example is exact - for models with
                                    // non-exact data, set tolerance as explained in
                                    // definition of OnBrepEdge.
        }
Beispiel #10
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            IRhinoCommand.result rc = IRhinoCommand.result.failure;

            OnBrep brep = MakeTwistedCube();

            if (null != brep && brep.IsValid())
            {
                context.m_doc.AddBrepObject(brep);
                context.m_doc.Redraw();
                rc = IRhinoCommand.result.success;
            }

            return(rc);
        }
Beispiel #11
0
        /// <summary>
        /// MakeTwistedCubeEdges
        /// </summary>
        static void MakeTwistedCubeEdges(
            ref OnBrep brep
            )
        {
            // In this simple example, the edge indices exactly match the 3d
            // curve indices.  In general,the correspondence between edge and
            // curve indices can be arbitrary.  It is permitted for multiple
            // edges to use different portions of the same 3d curve.  The
            // orientation of the edge always agrees with the natural
            // parametric orientation of the curve.

            // Edge that runs from A to B
            MakeTwistedCubeEdge(ref brep, A, B, AB);

            // Edge that runs from B to C
            MakeTwistedCubeEdge(ref brep, B, C, BC);

            // Edge that runs from C to D
            MakeTwistedCubeEdge(ref brep, C, D, CD);

            // Edge that runs from A to D
            MakeTwistedCubeEdge(ref brep, A, D, AD);

            // Edge that runs from E to F
            MakeTwistedCubeEdge(ref brep, E, F, EF);

            // Edge that runs from F to G
            MakeTwistedCubeEdge(ref brep, F, G, FG);

            // Edge that runs from G to H
            MakeTwistedCubeEdge(ref brep, G, H, GH);

            // Edge that runs from E to H
            MakeTwistedCubeEdge(ref brep, E, H, EH);

            // Edge that runs from A to E
            MakeTwistedCubeEdge(ref brep, A, E, AE);

            // Edge that runs from B to F
            MakeTwistedCubeEdge(ref brep, B, F, BF);

            // Edge that runs from C to G
            MakeTwistedCubeEdge(ref brep, C, G, CG);

            // Edge that runs from D to H
            MakeTwistedCubeEdge(ref brep, D, H, DH);
        }
        private static void CreateOneEdge(ref OnBrep brep,
                                          int vi0, // index of start vertex
                                          int vi1, // index of end vertex
                                          int c3i  // index of 3d curve
                                          )
        {
            OnBrepVertex v0   = brep.m_V[vi0];
            OnBrepVertex v1   = brep.m_V[vi1];
            OnBrepEdge   edge = brep.NewEdge(ref v0, ref v1, c3i);

            if (edge != null)
            {
                edge.m_tolerance = 0.0; // this simple example is exact - for models with
            }
            // non-exact data, set tolerance as explained in
            // definition of ON_BrepEdge.
        }
        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)
        {
            IRhinoCommand.result rc = IRhinoCommand.result.nothing;
            OnBrep brep             = SampleCsTrimmedPlaneHelper.MakeTrimmedBrepFace();

            if (brep != null)
            {
                if (context.m_doc.AddBrepObject(brep) != null)
                {
                    context.m_doc.Redraw();
                    rc = IRhinoCommand.result.success;
                }
                else
                {
                    rc = IRhinoCommand.result.failure;
                }
            }
            return(rc);
        }
    ///<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;
    }
Beispiel #16
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);
        }
        ///<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);
        }
        public static OnBrep MakeTrimmedBrepFace()
        {
            // This example demonstrates how to construct a ON_Brep
              // with the topology shown below.
              //
              //
              //    E-------C--------D
              //    |       /\       |
              //    |      /  \      |
              //    |     /    \     |
              //    |    e2      e1  |
              //    |   /        \   |
              //    |  /          \  |
              //    | /            \ |
              //    A-----e0-------->B
              //
              //
              //  Things need to be defined in a valid brep:
              //   1- Vertices
              //   2- 3D Curves (geometry)
              //   3- Edges (topology - reference curve geometry)
              //   4- Surface (geometry)
              //   5- Faces (topology - reference surface geometry)
              //   6- Loops (2D parameter space of faces)
              //   4- Trims and 2D curves (2D parameter space of edges)
              //

              //Vertex points
              // define the corners of the face with hole
              On3dPoint[] point = new On3dPoint[5];
              point[0] = new On3dPoint(0.0, 0.0, 0.0);  //point A = geometry for vertex 0 (and surface SW corner)
              point[1] = new On3dPoint(10.0, 0.0, 0.0); // point B = geometry for vertex 1 (and surface SE corner)
              point[2] = new On3dPoint(5.0, 10.0, 0.0); // point C = geometry for vertex 2
              point[3] = new On3dPoint(10.0, 10.0, 0.0);// point D (surface NE corner)
              point[4] = new On3dPoint(0.0, 10.0, 0.0); // point E (surface NW corner)

              // Build the brep
              OnBrep brep = new OnBrep();

              // create four vertices of the outer edges
              int vi;
              for (vi = 0; vi < 3; vi++)
              {
            OnBrepVertex v = brep.NewVertex(point[vi]);
            v.m_tolerance = 0.0;// this simple example is exact - for models with
            // non-exact data, set tolerance as explained in
            // definition of ON_BrepVertex.
              }

              // Create 3d curve geometry - the orientations are arbitrarily chosen
              // so that the end vertices are in alphabetical order.
              brep.m_C3.Append(CreateLinearCurve(point[A], point[B])); // line AB
              brep.m_C3.Append(CreateLinearCurve(point[B], point[C])); // line BC
              brep.m_C3.Append(CreateLinearCurve(point[A], point[C])); // line CD

              // Create edge topology for each curve in the brep.
              CreateEdges(ref brep);

              // Create 3d surface geometry - the orientations are arbitrarily chosen so
              // that some normals point into the cube and others point out of the cube.
              brep.m_S.Append(CreateNurbsSurface(point[A], point[B], point[D], point[E])); // ABCD

              // Create face topology and 2d parameter space loops and trims.
              CreateFace(ref brep, ABC_i);

              return brep;
        }
        private static int MakeTrimmingLoop(ref OnBrep brep, // returns index of loop
         ref OnBrepFace face,  // face loop is on
         int v0, int v1, int v2, // Indices of corner vertices listed in A,B,C order
         int e0,     // index of first edge
         int e0_dir, // orientation of edge
         int e1,     // index second edgee
         int e1_dir, // orientation of edge
         int e2,     // index third edge
         int e2_dir  // orientation of edge
                                    )
        {
            OnSurface srf = brep.m_S[face.m_si];

              //Create new loop
              OnBrepLoop loop = brep.NewLoop(IOnBrepLoop.TYPE.outer, ref face);

              // Create trimming curves running counter clockwise around the surface's domain.
              // Note that trims of outer loops run counter clockwise while trims of inner loops (holes) run anti-clockwise.
              // Also note that when trims locate on surface N,S,E or W ends, then trim_iso becomes N_iso, S_iso, E_iso and W_iso respectfully.
              // While if trim is parallel to surface N,S or E,W, then trim is becomes y_iso and x_iso respectfully.

              // Start at the south side
              OnCurve c2;
              int c2i, ei = 0;
              bool bRev3d = false;
              IOnSurface.ISO iso = IOnSurface.ISO.not_iso;

              for (int side = 0; side < 3; side++)
              {
            // side: 0=south, 1=east, 2=north, 3=west

            c2 = CreateTrimmingCurve(srf, side);

            //Add trimming curve to brep trmming curves array
            c2i = brep.m_C2.Count();
            brep.m_C2.Append(c2);

            switch (side)
            {
              case 0: // south
            ei = e0;
            bRev3d = (e0_dir == -1);
            iso = IOnSurface.ISO.S_iso;
            break;
              case 1: // diagonal
            ei = e1;
            bRev3d = (e1_dir == -1);
            iso = IOnSurface.ISO.not_iso;
            break;
              case 2: // diagonal
            ei = e2;
            bRev3d = (e2_dir == -1);
            iso = IOnSurface.ISO.not_iso;
            break;
            }

            //Create new trim topology that references edge, direction reletive to edge, loop and trim curve geometry
            OnBrepEdge edge = brep.m_E[ei];
            OnBrepTrim trim = brep.NewTrim(ref edge, bRev3d, ref loop, c2i);
            if (trim != null)
            {
              trim.m_iso = iso;
              trim.m_type = IOnBrepTrim.TYPE.boundary; // This one b-rep face, so all trims are boundary ones.
              trim.set_m_tolerance(0, 0.0); // This simple example is exact - for models with non-exact
              trim.set_m_tolerance(1, 0.0); // data, set tolerance as explained in definition of ON_BrepTrim.
            }
              }
              return loop.m_loop_index;
        }
        private static void MakeTrimmedFace(ref OnBrep brep,
                             int si,      // index of 3d surface
                             int s_dir,   // orientation of surface with respect to surfce
                             int v0, int v1, int v2, // Indices of corner vertices
                             int e0,     // index of first edge
                             int e0_dir,  // orientation of edge
                             int e1,     // index of second edge
                             int e1_dir,  // orientation of edge
                             int e2,     // index of third edge
                             int e2_dir  // orientation of edge
                               )
        {
            //Add new face to brep
              OnBrepFace face = brep.NewFace(si);

              //Create loop and trims for the face
              MakeTrimmingLoop(ref brep, ref face,
                    v0, v1, v2,
                    e0, e0_dir,
                    e1, e1_dir,
                    e2, e2_dir
                    );

              //Set face direction relative to surface direction
              face.m_bRev = (s_dir == -1);
        }
Beispiel #21
0
        /// <summary>
        /// MakeTwistedCubeFaces
        /// </summary>
        static void MakeTwistedCubeFaces(
            ref OnBrep brep
            )
        {
            MakeTwistedCubeFace(ref brep,
                                ABCD,       // Index of surface ABCD
                                +1,         // orientation of surface with respect to brep
                                A, B, C, D, // Indices of vertices listed in SW,SE,NW,NE order
                                AB, +1,     // South side edge and its orientation with respect to
                                            // to the trimming curve.  (AB)
                                BC, +1,     // South side edge and its orientation with respect to
                                            // to the trimming curve.  (BC)
                                CD, +1,     // South side edge and its orientation with respect to
                                            // to the trimming curve   (CD)
                                AD, -1      // South side edge and its orientation with respect to
                                            // to the trimming curve   (AD)
                                );

            MakeTwistedCubeFace(ref brep,
                                BCGF,       // Index of surface BCGF
                                -1,         // orientation of surface with respect to brep
                                B, C, G, F, // Indices of vertices listed in SW,SE,NW,NE order
                                BC, +1,     // South side edge and its orientation with respect to
                                            // to the trimming curve.  (BC)
                                CG, +1,     // South side edge and its orientation with respect to
                                            // to the trimming curve.  (CG)
                                FG, -1,     // South side edge and its orientation with respect to
                                            // to the trimming curve   (FG)
                                BF, -1      // South side edge and its orientation with respect to
                                            // to the trimming curve   (BF)
                                );

            MakeTwistedCubeFace(ref brep,
                                CDHG,       // Index of surface CDHG
                                -1,         // orientation of surface with respect to brep
                                C, D, H, G, // Indices of vertices listed in SW,SE,NW,NE order
                                CD, +1,     // South side edge and its orientation with respect to
                                            // to the trimming curve.  (CD)
                                DH, +1,     // South side edge and its orientation with respect to
                                            // to the trimming curve.  (DH)
                                GH, -1,     // South side edge and its orientation with respect to
                                            // to the trimming curve   (GH)
                                CG, -1      // South side edge and its orientation with respect to
                                            // to the trimming curve   (CG)
                                );

            MakeTwistedCubeFace(ref brep,
                                ADHE,       // Index of surface ADHE
                                +1,         // orientation of surface with respect to brep
                                A, D, H, E, // Indices of vertices listed in SW,SE,NW,NE order
                                AD, +1,     // South side edge and its orientation with respect to
                                            // to the trimming curve.  (AD)
                                DH, +1,     // South side edge and its orientation with respect to
                                            // to the trimming curve.  (DH)
                                EH, -1,     // South side edge and its orientation with respect to
                                            // to the trimming curve   (EH)
                                AE, -1      // South side edge and its orientation with respect to
                                            // to the trimming curve   (AE)
                                );

            MakeTwistedCubeFace(ref brep,
                                ABFE,       // Index of surface ABFE
                                -1,         // orientation of surface with respect to brep
                                A, B, F, E, // Indices of vertices listed in SW,SE,NW,NE order
                                AB, +1,     // South side edge and its orientation with respect to
                                            // to the trimming curve.  (AB)
                                BF, +1,     // South side edge and its orientation with respect to
                                            // to the trimming curve.  (BF)
                                EF, -1,     // South side edge and its orientation with respect to
                                            // to the trimming curve   (EF)
                                AE, -1      // South side edge and its orientation with respect to
                                            // to the trimming curve   (AE)
                                );

            MakeTwistedCubeFace(ref brep,
                                EFGH,       // Index of surface EFGH
                                -1,         // orientation of surface with respect to brep
                                E, F, G, H, // Indices of vertices listed in SW,SE,NW,NE order
                                EF, +1,     // South side edge and its orientation with respect to
                                            // to the trimming curve.  (EF)
                                FG, +1,     // South side edge and its orientation with respect to
                                            // to the trimming curve.  (FG)
                                GH, +1,     // South side edge and its orientation with respect to
                                            // to the trimming curve   (GH)
                                EH, -1      // South side edge and its orientation with respect to
                                            // to the trimming curve   (EH)
                                );
        }
        private static int MakeInnerTrimmingLoop(ref OnBrep brep, // returns index of loop
         ref OnBrepFace face,  // face loop is on
         int vSWi, int vSEi, int vNEi, int vNWi, // Indices of hole vertices
         int eSi,     // index of edge close to south side of surface
         int eS_dir,  // orientation of edge with respect to surface trim
         int eEi,     // index of edge close to east side of surface
         int eE_dir,  // orientation of edge with respect to surface trim
         int eNi,     // index of edge close to north side of surface
         int eN_dir,  // orientation of edge with respect to surface trim
         int eWi,     // index of edge close to west side of surface
         int eW_dir   // orientation of edge with respect to surface trim
                            )
        {
            OnSurface srf = brep.m_S[face.m_si];
              //Create new inner loop
              OnBrepLoop loop = brep.NewLoop(IOnBrepLoop.TYPE.inner, ref face);

              // Create trimming curves running counter clockwise around the surface's domain.
              // Note that trims of outer loops run counter clockwise while trims of inner loops (holes) run clockwise.
              // Also note that when trims locate on surface N,S,E or W ends, then trim_iso becomes N_iso, S_iso, E_iso and W_iso respectfully.
              // While if trim is parallel to surface N,S or E,W, then trim iso becomes y_iso and x_iso respectfully.
              // All other cases, iso is set to not_iso

              // Start near the south side
              OnCurve c2;
              int c2i, ei = 0;
              bool bRev3d = false;
              IOnSurface.ISO iso = IOnSurface.ISO.not_iso;

              for (int side = 0; side < 4; side++)
              {
            // side: 0=near south(y_iso), 1=near west(x_iso), 2=near north(y_iso), 3=near east(x_iso)

            //Create trim 2d curve
            c2 = CreateInnerTrimmingCurve(srf, side);

            //Add trimming curve to brep trmming curves array
            c2i = brep.m_C2.Count();
            brep.m_C2.Append(c2);

            switch (side)
            {
              case 0: // near south
            ei = eSi;
            bRev3d = (eS_dir == -1);
            iso = IOnSurface.ISO.y_iso;
            break;
              case 1: // near west
            ei = eEi;
            bRev3d = (eE_dir == -1);
            iso = IOnSurface.ISO.x_iso;
            break;
              case 2: // near north
            ei = eNi;
            bRev3d = (eN_dir == -1);
            iso = IOnSurface.ISO.y_iso;
            break;
              case 3: // near east
            ei = eWi;
            bRev3d = (eW_dir == -1);
            iso = IOnSurface.ISO.x_iso;
            break;
            }

            //Create new trim topology that references edge, direction reletive to edge, loop and trim curve geometry
            OnBrepEdge edge = brep.m_E[ei];
            OnBrepTrim trim = brep.NewTrim(ref edge, bRev3d, ref loop, c2i);
            if (trim != null)
            {
              trim.m_iso = iso;
              trim.m_type = IOnBrepTrim.TYPE.boundary; // This one b-rep face, so all trims are boundary ones.
              trim.set_m_tolerance(0, 0.0); // This simple example is exact - for models with non-exact
              trim.set_m_tolerance(1, 0.0); // data, set tolerance as explained in definition of ON_BrepTrim.
            }
              }

              return loop.m_loop_index;
        }
        /// <summary>
        /// MakeTwistedCubeTrimmingLoop
        /// </summary>
        static int MakeTwistedCubeTrimmingLoop(
      ref OnBrep brep, // returns index of loop
      ref OnBrepFace face,  // face loop is on
      int vSWi, int vSEi, int vNEi, int vNWi, // Indices of corner vertices listed in SW, SE, NW, NE order
      int eSi,     // index of edge on south side of surface
      int eS_dir,  // orientation of edge with respect to surface trim
      int eEi,     // index of edge on south side of surface
      int eE_dir,  // orientation of edge with respect to surface trim
      int eNi,     // index of edge on south side of surface
      int eN_dir,  // orientation of edge with respect to surface trim
      int eWi,     // index of edge on south side of surface
      int eW_dir   // orientation of edge with respect to surface trim
                                   )
        {
            IOnSurface srf = brep.m_S[face.m_si];

              OnBrepLoop loop = brep.NewLoop(IOnBrepLoop.TYPE.outer, ref face);

              // Create trimming curves running counter clockwise around the surface's domain.
              // Start at the south side
              int c2i = 0, ei = 0;
              bool bRev3d = false;
              IOnSurface.ISO iso = IOnSurface.ISO.not_iso;

              for (int side = 0; side < 4; side++ )
              {
            // side: 0=south, 1=east, 2=north, 3=west
            OnCurve c2 = TwistedCubeTrimmingCurve(srf, side);
            c2i = brep.m_C2.Count();
            brep.m_C2.Append(c2);

            switch (side)
            {
            case 0: // south
              ei = eSi;
              bRev3d = (eS_dir == -1);
              iso = IOnSurface.ISO.S_iso;
              break;
            case 1: // east
              ei = eEi;
              bRev3d = (eE_dir == -1);
              iso = IOnSurface.ISO.E_iso;
              break;
            case 2: // north
              ei = eNi;
              bRev3d = (eN_dir == -1);
              iso = IOnSurface.ISO.N_iso;
              break;
            case 3: // west
              ei = eWi;
              bRev3d = (eW_dir == -1);
              iso = IOnSurface.ISO.W_iso;
              break;
            }

            OnBrepEdge edge = brep.m_E[ei];
            OnBrepTrim trim = brep.NewTrim(ref edge, bRev3d, ref loop, c2i);
            trim.m_iso = iso;
            trim.m_type = IOnBrepTrim.TYPE.mated; // This b-rep is closed, so all trims have mates.
            trim.set_m_tolerance(0, 0.0); // This simple example is exact - for models with
            trim.set_m_tolerance(1, 0.0); // non-exact data, set tolerance as explained in
                                      // definition of OnBrepTrim.
              }

              return loop.m_loop_index;
        }
        /// <summary>
        /// The one and only MakeBox
        /// </summary>
        static OnBrep MakeBox()
        {
            /*
              This example demonstrates how to construct a OnBrep
              with the topology shown below.

              v7_______e6_____v6
               |\             |\
               | e7           | e5
               |  \ ______e4_____\
              e11  v4         |   v5
               |   |        e10   |
               |   |          |   |
              v3---|---e2----v2   e9
               \   e8         \   |
            e3 |           e1 |
             \ |            \ |
              \v0_____e0_____\v1

              */

              On3dPoint[] points = new On3dPoint[8];
              points[0] = new On3dPoint(0.0, 0.0, 0.0);
              points[1] = new On3dPoint(10.0, 0.0, 0.0);
              points[2] = new On3dPoint(10.0, 10.0, 0.0);
              points[3] = new On3dPoint(0.0, 10.0, 0.0);
              points[4] = new On3dPoint(0.0, 0.0, 10.0);
              points[5] = new On3dPoint(10.0, 0.0, 10.0);
              points[6] = new On3dPoint(10.0, 10.0, 10.0);
              points[7] = new On3dPoint(0.0, 10.0, 10.0);

              OnBrep brep = new OnBrep();

              int vi = 0, ei = 0, fi = 0, si = 0, c2i = 0;

              for (vi = 0; vi < 8; vi++)
            brep.NewVertex(points[vi], 0.0);

              for (ei = 0; ei < 4; ei++)
              {
            OnBrepVertex v0 = brep.m_V[ei];
            OnBrepVertex v1 = brep.m_V[(ei + 1) % 4];
            brep.m_C3.Append(new OnLineCurve(v0.point, v1.point));
            brep.NewEdge(ref v0, ref v1, ei, null, 0.0);
              }
              for (ei = 4; ei < 8; ei++)
              {
            OnBrepVertex v0 = brep.m_V[ei];
            OnBrepVertex v1 = brep.m_V[ei == 7 ? 4 : (ei + 1)];
            brep.m_C3.Append(new OnLineCurve(v0.point, v1.point));
            brep.NewEdge(ref v0, ref v1, ei, null, 0.0);
              }
              for (ei = 8; ei < 12; ei++)
              {
            OnBrepVertex v0 = brep.m_V[ei - 8];
            OnBrepVertex v1 = brep.m_V[ei - 4];
            brep.m_C3.Append(new OnLineCurve(v0.point, v1.point));
            brep.NewEdge(ref v0, ref v1, ei, null, 0.0);
              }

              OnBrepBoxFaceInfo[] f = new OnBrepBoxFaceInfo[6];
              f[0] = new OnBrepBoxFaceInfo(0, 9, 4, 8, false, false, true, true);
              f[1] = new OnBrepBoxFaceInfo(1, 10, 5, 9, false, false, true, true);
              f[2] = new OnBrepBoxFaceInfo(2, 11, 6, 10, false, false, true, true);
              f[3] = new OnBrepBoxFaceInfo(3, 8, 7, 11, false, false, true, true);
              f[4] = new OnBrepBoxFaceInfo(3, 2, 1, 0, true, true, true, true);
              f[5] = new OnBrepBoxFaceInfo(4, 5, 6, 7, false, false, false, false);

              for (fi = 0; fi < 6; fi++ )
              {
            OnBrepEdge e0 = brep.m_E[f[fi].e[0]];
            OnBrepEdge e1 = brep.m_E[f[fi].e[1]];
            OnBrepEdge e2 = brep.m_E[f[fi].e[2]];
            OnBrepEdge e3 = brep.m_E[f[fi].e[3]];
            OnBrepVertex v0 = brep.m_V[e0.get_m_vi(f[fi].bRev[0] ? 1 : 0)];
            OnBrepVertex v1 = brep.m_V[e1.get_m_vi(f[fi].bRev[1] ? 1 : 0)];
            OnBrepVertex v2 = brep.m_V[e2.get_m_vi(f[fi].bRev[2] ? 1 : 0)];
            OnBrepVertex v3 = brep.m_V[e3.get_m_vi(f[fi].bRev[3] ? 1 : 0)];

            si = brep.AddSurface(OnUtil.ON_NurbsSurfaceQuadrilateral(v0.point, v1.point, v2.point, v3.point));
            OnInterval s = brep.m_S[si].Domain(0);
            OnInterval t = brep.m_S[si].Domain(1);
            On2dPoint p0 = new On2dPoint(s[0], t[0]);
            On2dPoint p1 = new On2dPoint(s[1], t[0]);
            On2dPoint p2 = new On2dPoint(s[1], t[1]);
            On2dPoint p3 = new On2dPoint(s[0], t[1]);

            OnBrepFace face = brep.NewFace(si);
            OnBrepLoop loop = brep.NewLoop(IOnBrepLoop.TYPE.outer, ref face);

            loop.m_pbox.m_min.x = s[0];
            loop.m_pbox.m_min.y = t[0];
            loop.m_pbox.m_min.z = 0.0;

            loop.m_pbox.m_max.x = s[1];
            loop.m_pbox.m_max.y = t[1];
            loop.m_pbox.m_max.z = 0.0;

            // south side of surface
            c2i = brep.AddTrimCurve(new OnLineCurve(p0, p1));
            OnBrepTrim trim0 = brep.NewTrim(ref e0, f[fi].bRev[0], ref loop, c2i);
            trim0.set_m_tolerance(0, 0.0);
            trim0.set_m_tolerance(1, 0.0);
            trim0.m_type = (trim0.get_m_vi(0) != trim0.get_m_vi(1)) ? IOnBrepTrim.TYPE.mated : IOnBrepTrim.TYPE.singular;
            trim0.m_iso = IOnSurface.ISO.S_iso;

            // east side of surface
            c2i = brep.AddTrimCurve(new OnLineCurve(p1, p2));
            OnBrepTrim trim1 = brep.NewTrim(ref e1, f[fi].bRev[1], ref loop, c2i);
            trim1.set_m_tolerance(0, 0.0);
            trim1.set_m_tolerance(1, 0.0);
            trim1.m_type = (trim1.get_m_vi(0) != trim1.get_m_vi(1)) ? IOnBrepTrim.TYPE.mated : IOnBrepTrim.TYPE.singular;
            trim1.m_iso = IOnSurface.ISO.E_iso;

            // north side of surface
            c2i = brep.AddTrimCurve(new OnLineCurve(p2, p3));
            OnBrepTrim trim2 = brep.NewTrim(ref e2, f[fi].bRev[2], ref loop, c2i);
            trim2.set_m_tolerance(0, 0.0);
            trim2.set_m_tolerance(1, 0.0);
            trim2.m_type = (trim2.get_m_vi(0) != trim2.get_m_vi(1)) ? IOnBrepTrim.TYPE.mated : IOnBrepTrim.TYPE.singular;
            trim2.m_iso = IOnSurface.ISO.N_iso;

            // west side of surface
            c2i = brep.AddTrimCurve(new OnLineCurve(p3, p0));
            OnBrepTrim trim3 = brep.NewTrim(ref e3, f[fi].bRev[3], ref loop, c2i);
            trim3.set_m_tolerance(0, 0.0);
            trim3.set_m_tolerance(1, 0.0);
            trim3.m_type = (trim3.get_m_vi(0) != trim3.get_m_vi(1)) ? IOnBrepTrim.TYPE.mated : IOnBrepTrim.TYPE.singular;
            trim3.m_iso = IOnSurface.ISO.W_iso;
              }

              if (!brep.IsValid())
            return null;

              return brep;
        }
        /// <summary>
        /// MakeTwistedCubeFace
        /// </summary>
        static void MakeTwistedCubeFace( 
      ref OnBrep brep,
      int si,      // index of 3d surface
      int s_dir,   // orientation of surface with respect to brep
      int vSWi, int vSEi, int vNEi, int vNWi, // Indices of corner vertices listed in SW, SE, NW, NE order
      int eSi,     // index of edge on south side of surface
      int eS_dir,  // orientation of edge with respect to surface trim
      int eEi,     // index of edge on south side of surface
      int eE_dir,  // orientation of edge with respect to surface trim
      int eNi,     // index of edge on south side of surface
      int eN_dir,  // orientation of edge with respect to surface trim
      int eWi,     // index of edge on south side of surface
      int eW_dir   // orientation of edge with respect to surface trim
      )
        {
            OnBrepFace face = brep.NewFace(si);

              MakeTwistedCubeTrimmingLoop(
            ref brep,
            ref face,
            vSWi, vSEi, vNEi, vNWi,
            eSi, eS_dir,
            eEi, eE_dir,
            eNi, eN_dir,
            eWi, eW_dir
            );

              face.m_bRev = (s_dir == -1);
        }
   /// <summary>
   /// MakeTwistedCubeEdge
   /// </summary>
   static void MakeTwistedCubeEdge(
 ref OnBrep brep,
 int vi0, // index of start vertex
 int vi1, // index of end vertex
 int c3i  // index of 3d curve
 )
   {
       OnBrepVertex v0 = brep.m_V[vi0];
         OnBrepVertex v1 = brep.m_V[vi1];
         OnBrepEdge edge = brep.NewEdge(ref v0, ref v1, c3i);
         edge.m_tolerance = 0.0;  // this simple example is exact - for models with
                          // non-exact data, set tolerance as explained in
                          // definition of OnBrepEdge.
   }
        public static OnBrep MakeTrimmedBrepFace()
        {
            // This example demonstrates how to construct a ON_Brep
            // with the topology shown below.
            //
            //
            //    E-------C--------D
            //    |       /\       |
            //    |      /  \      |
            //    |     /    \     |
            //    |    e2      e1  |
            //    |   /        \   |
            //    |  /          \  |
            //    | /            \ |
            //    A-----e0-------->B
            //
            //
            //  Things need to be defined in a valid brep:
            //   1- Vertices
            //   2- 3D Curves (geometry)
            //   3- Edges (topology - reference curve geometry)
            //   4- Surface (geometry)
            //   5- Faces (topology - reference surface geometry)
            //   6- Loops (2D parameter space of faces)
            //   4- Trims and 2D curves (2D parameter space of edges)
            //

            //Vertex points
            // define the corners of the face with hole
            On3dPoint[] point = new On3dPoint[5];
            point[0] = new On3dPoint(0.0, 0.0, 0.0);   //point A = geometry for vertex 0 (and surface SW corner)
            point[1] = new On3dPoint(10.0, 0.0, 0.0);  // point B = geometry for vertex 1 (and surface SE corner)
            point[2] = new On3dPoint(5.0, 10.0, 0.0);  // point C = geometry for vertex 2
            point[3] = new On3dPoint(10.0, 10.0, 0.0); // point D (surface NE corner)
            point[4] = new On3dPoint(0.0, 10.0, 0.0);  // point E (surface NW corner)

            // Build the brep
            OnBrep brep = new OnBrep();

            // create four vertices of the outer edges
            int vi;

            for (vi = 0; vi < 3; vi++)
            {
                OnBrepVertex v = brep.NewVertex(point[vi]);
                v.m_tolerance = 0.0;// this simple example is exact - for models with
                // non-exact data, set tolerance as explained in
                // definition of ON_BrepVertex.
            }

            // Create 3d curve geometry - the orientations are arbitrarily chosen
            // so that the end vertices are in alphabetical order.
            brep.m_C3.Append(CreateLinearCurve(point[A], point[B])); // line AB
            brep.m_C3.Append(CreateLinearCurve(point[B], point[C])); // line BC
            brep.m_C3.Append(CreateLinearCurve(point[A], point[C])); // line CD

            // Create edge topology for each curve in the brep.
            CreateEdges(ref brep);

            // Create 3d surface geometry - the orientations are arbitrarily chosen so
            // that some normals point into the cube and others point out of the cube.
            brep.m_S.Append(CreateNurbsSurface(point[A], point[B], point[D], point[E])); // ABCD

            // Create face topology and 2d parameter space loops and trims.
            CreateFace(ref brep, ABC_i);

            return(brep);
        }
        /// <summary>
        /// The one and only MakeBox
        /// </summary>
        static OnBrep MakeBox()
        {
            /*
             * This example demonstrates how to construct a OnBrep
             * with the topology shown below.
             *
             * v7_______e6_____v6
             |\             |\
             | e7           | e5
             |  \ ______e4_____\
             | e11  v4         |   v5
             |   |        e10   |
             |   |          |   |
             | v3---|---e2----v2   e9
             \   e8         \   |
             \ e3 |           e1 |
             \ |            \ |
             \  \v0_____e0_____\v1
             \
             */

            On3dPoint[] points = new On3dPoint[8];
            points[0] = new On3dPoint(0.0, 0.0, 0.0);
            points[1] = new On3dPoint(10.0, 0.0, 0.0);
            points[2] = new On3dPoint(10.0, 10.0, 0.0);
            points[3] = new On3dPoint(0.0, 10.0, 0.0);
            points[4] = new On3dPoint(0.0, 0.0, 10.0);
            points[5] = new On3dPoint(10.0, 0.0, 10.0);
            points[6] = new On3dPoint(10.0, 10.0, 10.0);
            points[7] = new On3dPoint(0.0, 10.0, 10.0);

            OnBrep brep = new OnBrep();

            int vi = 0, ei = 0, fi = 0, si = 0, c2i = 0;

            for (vi = 0; vi < 8; vi++)
            {
                brep.NewVertex(points[vi], 0.0);
            }

            for (ei = 0; ei < 4; ei++)
            {
                OnBrepVertex v0 = brep.m_V[ei];
                OnBrepVertex v1 = brep.m_V[(ei + 1) % 4];
                brep.m_C3.Append(new OnLineCurve(v0.point, v1.point));
                brep.NewEdge(ref v0, ref v1, ei, null, 0.0);
            }
            for (ei = 4; ei < 8; ei++)
            {
                OnBrepVertex v0 = brep.m_V[ei];
                OnBrepVertex v1 = brep.m_V[ei == 7 ? 4 : (ei + 1)];
                brep.m_C3.Append(new OnLineCurve(v0.point, v1.point));
                brep.NewEdge(ref v0, ref v1, ei, null, 0.0);
            }
            for (ei = 8; ei < 12; ei++)
            {
                OnBrepVertex v0 = brep.m_V[ei - 8];
                OnBrepVertex v1 = brep.m_V[ei - 4];
                brep.m_C3.Append(new OnLineCurve(v0.point, v1.point));
                brep.NewEdge(ref v0, ref v1, ei, null, 0.0);
            }

            OnBrepBoxFaceInfo[] f = new OnBrepBoxFaceInfo[6];
            f[0] = new OnBrepBoxFaceInfo(0, 9, 4, 8, false, false, true, true);
            f[1] = new OnBrepBoxFaceInfo(1, 10, 5, 9, false, false, true, true);
            f[2] = new OnBrepBoxFaceInfo(2, 11, 6, 10, false, false, true, true);
            f[3] = new OnBrepBoxFaceInfo(3, 8, 7, 11, false, false, true, true);
            f[4] = new OnBrepBoxFaceInfo(3, 2, 1, 0, true, true, true, true);
            f[5] = new OnBrepBoxFaceInfo(4, 5, 6, 7, false, false, false, false);

            for (fi = 0; fi < 6; fi++)
            {
                OnBrepEdge   e0 = brep.m_E[f[fi].e[0]];
                OnBrepEdge   e1 = brep.m_E[f[fi].e[1]];
                OnBrepEdge   e2 = brep.m_E[f[fi].e[2]];
                OnBrepEdge   e3 = brep.m_E[f[fi].e[3]];
                OnBrepVertex v0 = brep.m_V[e0.get_m_vi(f[fi].bRev[0] ? 1 : 0)];
                OnBrepVertex v1 = brep.m_V[e1.get_m_vi(f[fi].bRev[1] ? 1 : 0)];
                OnBrepVertex v2 = brep.m_V[e2.get_m_vi(f[fi].bRev[2] ? 1 : 0)];
                OnBrepVertex v3 = brep.m_V[e3.get_m_vi(f[fi].bRev[3] ? 1 : 0)];

                si = brep.AddSurface(OnUtil.ON_NurbsSurfaceQuadrilateral(v0.point, v1.point, v2.point, v3.point));
                OnInterval s  = brep.m_S[si].Domain(0);
                OnInterval t  = brep.m_S[si].Domain(1);
                On2dPoint  p0 = new On2dPoint(s[0], t[0]);
                On2dPoint  p1 = new On2dPoint(s[1], t[0]);
                On2dPoint  p2 = new On2dPoint(s[1], t[1]);
                On2dPoint  p3 = new On2dPoint(s[0], t[1]);

                OnBrepFace face = brep.NewFace(si);
                OnBrepLoop loop = brep.NewLoop(IOnBrepLoop.TYPE.outer, ref face);

                loop.m_pbox.m_min.x = s[0];
                loop.m_pbox.m_min.y = t[0];
                loop.m_pbox.m_min.z = 0.0;

                loop.m_pbox.m_max.x = s[1];
                loop.m_pbox.m_max.y = t[1];
                loop.m_pbox.m_max.z = 0.0;

                // south side of surface
                c2i = brep.AddTrimCurve(new OnLineCurve(p0, p1));
                OnBrepTrim trim0 = brep.NewTrim(ref e0, f[fi].bRev[0], ref loop, c2i);
                trim0.set_m_tolerance(0, 0.0);
                trim0.set_m_tolerance(1, 0.0);
                trim0.m_type = (trim0.get_m_vi(0) != trim0.get_m_vi(1)) ? IOnBrepTrim.TYPE.mated : IOnBrepTrim.TYPE.singular;
                trim0.m_iso  = IOnSurface.ISO.S_iso;

                // east side of surface
                c2i = brep.AddTrimCurve(new OnLineCurve(p1, p2));
                OnBrepTrim trim1 = brep.NewTrim(ref e1, f[fi].bRev[1], ref loop, c2i);
                trim1.set_m_tolerance(0, 0.0);
                trim1.set_m_tolerance(1, 0.0);
                trim1.m_type = (trim1.get_m_vi(0) != trim1.get_m_vi(1)) ? IOnBrepTrim.TYPE.mated : IOnBrepTrim.TYPE.singular;
                trim1.m_iso  = IOnSurface.ISO.E_iso;

                // north side of surface
                c2i = brep.AddTrimCurve(new OnLineCurve(p2, p3));
                OnBrepTrim trim2 = brep.NewTrim(ref e2, f[fi].bRev[2], ref loop, c2i);
                trim2.set_m_tolerance(0, 0.0);
                trim2.set_m_tolerance(1, 0.0);
                trim2.m_type = (trim2.get_m_vi(0) != trim2.get_m_vi(1)) ? IOnBrepTrim.TYPE.mated : IOnBrepTrim.TYPE.singular;
                trim2.m_iso  = IOnSurface.ISO.N_iso;

                // west side of surface
                c2i = brep.AddTrimCurve(new OnLineCurve(p3, p0));
                OnBrepTrim trim3 = brep.NewTrim(ref e3, f[fi].bRev[3], ref loop, c2i);
                trim3.set_m_tolerance(0, 0.0);
                trim3.set_m_tolerance(1, 0.0);
                trim3.m_type = (trim3.get_m_vi(0) != trim3.get_m_vi(1)) ? IOnBrepTrim.TYPE.mated : IOnBrepTrim.TYPE.singular;
                trim3.m_iso  = IOnSurface.ISO.W_iso;
            }

            if (!brep.IsValid())
            {
                return(null);
            }

            return(brep);
        }
        public static OnBrep MakeBrepFace()
        {
            // This example demonstrates how to construct a ON_Brep
              // with the topology shown below.
              //
              //
              //   D---------e2-----C
              //   |                |
              //   |  G----e6---H   |
              //   |  |         |   |
              //   e3 e5        e7  |
              //   |  |         |   |
              //   |  F<---e4---E   |
              //   |                |
              //   A-------e0------>B
              //
              //  Things need to be defined in a valid brep:
              //   1- Vertices
              //   2- 3D Curves (geometry)
              //   3- Edges (topology - reference curve geometry)
              //   4- Surface (geometry)
              //   5- Faces (topology - reference surface geometry)
              //   6- Loops (2D parameter space of faces)
              //   4- Trims and 2D curves (2D parameter space of edges)
              //

              //Vertex points
              // define the corners of the face with hole
              On3dPoint[] point = new On3dPoint[8];
              point[0] = new On3dPoint(0.0, 0.0, 0.0);
              point[1] = new On3dPoint(10.0, 0.0, 0.0);
              point[2] = new On3dPoint(10.0, 10.0, 0.0);
              point[3] = new On3dPoint(0.0, 10.0, 0.0);

              point[4] = new On3dPoint(8.0, 2.0, 0.0);
              point[5] = new On3dPoint(2.0, 2.0, 0.0);
              point[6] = new On3dPoint(2.0, 8.0, 0.0);
              point[7] = new On3dPoint(8.0, 8.0, 0.0);

              // Build the brep
              OnBrep brep = new OnBrep();

              // create four vertices of the outer edges
              int vi;
              for (vi = 0; vi < 8; vi++)
              {
            OnBrepVertex v = brep.NewVertex(point[vi]);
            v.m_tolerance = 0.0; // this simple example is exact - for models with
            // non-exact data, set tolerance as explained in
            // definition of ON_BrepVertex.
              }

              // Create 3d curve geometry of the outer boundary
              // The orientations are arbitrarily chosen
              // so that the end vertices are in alphabetical order.
              brep.m_C3.Append(CreateLinearCurve(point[A], point[B])); // line AB
              brep.m_C3.Append(CreateLinearCurve(point[B], point[C])); // line BC
              brep.m_C3.Append(CreateLinearCurve(point[C], point[D])); // line CD
              brep.m_C3.Append(CreateLinearCurve(point[A], point[D])); // line AD

              // Create 3d curve geometry of the hole
              brep.m_C3.Append(CreateLinearCurve(point[E], point[F])); // line EF
              brep.m_C3.Append(CreateLinearCurve(point[F], point[G])); // line GH
              brep.m_C3.Append(CreateLinearCurve(point[G], point[H])); // line HI
              brep.m_C3.Append(CreateLinearCurve(point[E], point[H])); // line EI

              // Create edge topology for each curve in the brep.
              CreateEdges(ref brep);

              // Create 3d surface geometry - the orientations are arbitrarily chosen so
              // that some normals point into the cube and others point out of the cube.
              brep.m_S.Append(CreateNurbsSurface(point[A], point[B], point[C], point[D])); // ABCD

              // Create face topology and 2d parameter space loops and trims.
              CreateFace(ref brep, ABCD);

              return brep;
        }
Beispiel #30
0
        /// <summary>
        /// MakeTwistedCubeTrimmingLoop
        /// </summary>
        static int MakeTwistedCubeTrimmingLoop(
            ref OnBrep brep,                        // returns index of loop
            ref OnBrepFace face,                    // face loop is on
            int vSWi, int vSEi, int vNEi, int vNWi, // Indices of corner vertices listed in SW, SE, NW, NE order
            int eSi,                                // index of edge on south side of surface
            int eS_dir,                             // orientation of edge with respect to surface trim
            int eEi,                                // index of edge on south side of surface
            int eE_dir,                             // orientation of edge with respect to surface trim
            int eNi,                                // index of edge on south side of surface
            int eN_dir,                             // orientation of edge with respect to surface trim
            int eWi,                                // index of edge on south side of surface
            int eW_dir                              // orientation of edge with respect to surface trim
            )
        {
            IOnSurface srf = brep.m_S[face.m_si];

            OnBrepLoop loop = brep.NewLoop(IOnBrepLoop.TYPE.outer, ref face);

            // Create trimming curves running counter clockwise around the surface's domain.
            // Start at the south side
            int  c2i = 0, ei = 0;
            bool bRev3d = false;

            IOnSurface.ISO iso = IOnSurface.ISO.not_iso;

            for (int side = 0; side < 4; side++)
            {
                // side: 0=south, 1=east, 2=north, 3=west
                OnCurve c2 = TwistedCubeTrimmingCurve(srf, side);
                c2i = brep.m_C2.Count();
                brep.m_C2.Append(c2);

                switch (side)
                {
                case 0: // south
                    ei     = eSi;
                    bRev3d = (eS_dir == -1);
                    iso    = IOnSurface.ISO.S_iso;
                    break;

                case 1: // east
                    ei     = eEi;
                    bRev3d = (eE_dir == -1);
                    iso    = IOnSurface.ISO.E_iso;
                    break;

                case 2: // north
                    ei     = eNi;
                    bRev3d = (eN_dir == -1);
                    iso    = IOnSurface.ISO.N_iso;
                    break;

                case 3: // west
                    ei     = eWi;
                    bRev3d = (eW_dir == -1);
                    iso    = IOnSurface.ISO.W_iso;
                    break;
                }

                OnBrepEdge edge = brep.m_E[ei];
                OnBrepTrim trim = brep.NewTrim(ref edge, bRev3d, ref loop, c2i);
                trim.m_iso  = iso;
                trim.m_type = IOnBrepTrim.TYPE.mated; // This b-rep is closed, so all trims have mates.
                trim.set_m_tolerance(0, 0.0);         // This simple example is exact - for models with
                trim.set_m_tolerance(1, 0.0);         // non-exact data, set tolerance as explained in
                                                      // definition of OnBrepTrim.
            }

            return(loop.m_loop_index);
        }
        private static void CreateEdges(ref OnBrep brep)
        {
            // In this simple example, the edge indices exactly match the 3d
              // curve indices.  In general,the correspondence between edge and
              // curve indices can be arbitrary.  It is permitted for multiple
              // edges to use different portions of the same 3d curve.  The
              // orientation of the edge always agrees with the natural
              // parametric orientation of the curve.

              //outer edges
              // edge that runs from A to B
              CreateOneEdge(ref brep, A, B, AB);

              // edge that runs from B to C
              CreateOneEdge(ref brep, B, C, BC);

              // edge that runs from C to D
              CreateOneEdge(ref brep, A, C, AC);
        }
        public static OnBrep MakeBrepFace()
        {
            // This example demonstrates how to construct a ON_Brep
            // with the topology shown below.
            //
            //
            //   D---------e2-----C
            //   |                |
            //   |  G----e6---H   |
            //   |  |         |   |
            //   e3 e5        e7  |
            //   |  |         |   |
            //   |  F<---e4---E   |
            //   |                |
            //   A-------e0------>B
            //
            //  Things need to be defined in a valid brep:
            //   1- Vertices
            //   2- 3D Curves (geometry)
            //   3- Edges (topology - reference curve geometry)
            //   4- Surface (geometry)
            //   5- Faces (topology - reference surface geometry)
            //   6- Loops (2D parameter space of faces)
            //   4- Trims and 2D curves (2D parameter space of edges)
            //

            //Vertex points
            // define the corners of the face with hole
            On3dPoint[] point = new On3dPoint[8];
            point[0] = new On3dPoint(0.0, 0.0, 0.0);
            point[1] = new On3dPoint(10.0, 0.0, 0.0);
            point[2] = new On3dPoint(10.0, 10.0, 0.0);
            point[3] = new On3dPoint(0.0, 10.0, 0.0);

            point[4] = new On3dPoint(8.0, 2.0, 0.0);
            point[5] = new On3dPoint(2.0, 2.0, 0.0);
            point[6] = new On3dPoint(2.0, 8.0, 0.0);
            point[7] = new On3dPoint(8.0, 8.0, 0.0);

            // Build the brep
            OnBrep brep = new OnBrep();

            // create four vertices of the outer edges
            int vi;

            for (vi = 0; vi < 8; vi++)
            {
                OnBrepVertex v = brep.NewVertex(point[vi]);
                v.m_tolerance = 0.0; // this simple example is exact - for models with
                // non-exact data, set tolerance as explained in
                // definition of ON_BrepVertex.
            }

            // Create 3d curve geometry of the outer boundary
            // The orientations are arbitrarily chosen
            // so that the end vertices are in alphabetical order.
            brep.m_C3.Append(CreateLinearCurve(point[A], point[B])); // line AB
            brep.m_C3.Append(CreateLinearCurve(point[B], point[C])); // line BC
            brep.m_C3.Append(CreateLinearCurve(point[C], point[D])); // line CD
            brep.m_C3.Append(CreateLinearCurve(point[A], point[D])); // line AD

            // Create 3d curve geometry of the hole
            brep.m_C3.Append(CreateLinearCurve(point[E], point[F])); // line EF
            brep.m_C3.Append(CreateLinearCurve(point[F], point[G])); // line GH
            brep.m_C3.Append(CreateLinearCurve(point[G], point[H])); // line HI
            brep.m_C3.Append(CreateLinearCurve(point[E], point[H])); // line EI

            // Create edge topology for each curve in the brep.
            CreateEdges(ref brep);

            // Create 3d surface geometry - the orientations are arbitrarily chosen so
            // that some normals point into the cube and others point out of the cube.
            brep.m_S.Append(CreateNurbsSurface(point[A], point[B], point[C], point[D])); // ABCD

            // Create face topology and 2d parameter space loops and trims.
            CreateFace(ref brep, ABCD);

            return(brep);
        }
 private static void CreateFace(ref OnBrep brep, int si)
 {
     MakeTrimmedFace(ref brep,
     ABC_i,      // Index of face
     +1,         // orientation of surface with respect to surface
     A, B, C,    // Indices of vertices
     AB, +1,      // Side edge and its orientation with respect to
     // to the trimming curve.  (AB)
     BC, +1,      // Side edge and its orientation with respect to
     // to the trimming curve.  (BC)
     AC, -1       // Side edge and its orientation with respect to
     // to the trimming curve   (AC)
     );
 }
Beispiel #34
0
        /// <summary>
        /// The one and only MakeTwistedCube
        /// </summary>
        static OnBrep MakeTwistedCube()
        {
            /*
             * This example demonstrates how to construct a OnBrep
             * with the topology shown below.
             *
             *         H-------e6-------G
             *        /                /|
             *       / |              / |
             *      /  e7            /  e5
             *     /   |            /   |
             *    /                e10  |
             *   /     |          /     |
             *  e11    E- - e4- -/- - - F
             * /                /      /
             * /      /         /      /
             * D---------e2-----C      e9
             |     /          |     /
             |    e8          |    /
             | e3  /            e1  /
             |                |  /
             | /              | /
             |                |/
             | A-------e0-------B
             |
             */

            On3dPoint[] points = new On3dPoint[8];
            points[0] = new On3dPoint(0.0, 0.0, 0.0);   // point A = geometry for vertex 0
            points[1] = new On3dPoint(10.0, 0.0, 0.0);  // point B = geometry for vertex 1
            points[2] = new On3dPoint(10.0, 8.0, -1.0); // point C = geometry for vertex 2
            points[3] = new On3dPoint(0.0, 6.0, 0.0);   // point D = geometry for vertex 3
            points[4] = new On3dPoint(1.0, 2.0, 11.0);  // point E = geometry for vertex 4
            points[5] = new On3dPoint(10.0, 0.0, 12.0); // point F = geometry for vertex 5
            points[6] = new On3dPoint(10.0, 7.0, 13.0); // point G = geometry for vertex 6
            points[7] = new On3dPoint(0.0, 6.0, 12.0);  // point H = geometry for vertex 7

            OnBrep brep = new OnBrep();

            // Create eight vertices located at the eight points
            int vi;

            for (vi = 0; vi < 8; vi++)
            {
                OnBrepVertex v = brep.NewVertex(points[vi]);
                v.m_tolerance = 0.0;
            }

            // Create 3d curve geometry - the orientations are arbitrarily chosen
            // so that the end vertices are in alphabetical order.
            brep.m_C3.Append(TwistedCubeEdgeCurve(points[A], points[B])); // line AB
            brep.m_C3.Append(TwistedCubeEdgeCurve(points[B], points[C])); // line BC
            brep.m_C3.Append(TwistedCubeEdgeCurve(points[C], points[D])); // line CD
            brep.m_C3.Append(TwistedCubeEdgeCurve(points[A], points[D])); // line AD
            brep.m_C3.Append(TwistedCubeEdgeCurve(points[E], points[F])); // line EF
            brep.m_C3.Append(TwistedCubeEdgeCurve(points[F], points[G])); // line FG
            brep.m_C3.Append(TwistedCubeEdgeCurve(points[G], points[H])); // line GH
            brep.m_C3.Append(TwistedCubeEdgeCurve(points[E], points[H])); // line EH
            brep.m_C3.Append(TwistedCubeEdgeCurve(points[A], points[E])); // line AE
            brep.m_C3.Append(TwistedCubeEdgeCurve(points[B], points[F])); // line BF
            brep.m_C3.Append(TwistedCubeEdgeCurve(points[C], points[G])); // line CG
            brep.m_C3.Append(TwistedCubeEdgeCurve(points[D], points[H])); // line DH

            // Create the 12 edges that connect the corners of the cube.
            MakeTwistedCubeEdges(ref brep);

            // Create 3d surface geometry - the orientations are arbitrarily chosen so
            // that some normals point into the cube and others point out of the cube.
            brep.m_S.Append(TwistedCubeSideSurface(points[A], points[B], points[C], points[D])); // ABCD
            brep.m_S.Append(TwistedCubeSideSurface(points[B], points[C], points[G], points[F])); // BCGF
            brep.m_S.Append(TwistedCubeSideSurface(points[C], points[D], points[H], points[G])); // CDHG
            brep.m_S.Append(TwistedCubeSideSurface(points[A], points[D], points[H], points[E])); // ADHE
            brep.m_S.Append(TwistedCubeSideSurface(points[A], points[B], points[F], points[E])); // ABFE
            brep.m_S.Append(TwistedCubeSideSurface(points[E], points[F], points[G], points[H])); // EFGH

            // Create the CRhinoBrepFaces
            MakeTwistedCubeFaces(ref brep);

            if (!brep.IsValid())
            {
                return(null);
            }

            return(brep);
        }
        private static int MakeTrimmingLoop(ref OnBrep brep,        // returns index of loop
                                            ref OnBrepFace face,    // face loop is on
                                            int v0, int v1, int v2, // Indices of corner vertices listed in A,B,C order
                                            int e0,                 // index of first edge
                                            int e0_dir,             // orientation of edge
                                            int e1,                 // index second edgee
                                            int e1_dir,             // orientation of edge
                                            int e2,                 // index third edge
                                            int e2_dir              // orientation of edge
                                            )
        {
            OnSurface srf = brep.m_S[face.m_si];

            //Create new loop
            OnBrepLoop loop = brep.NewLoop(IOnBrepLoop.TYPE.outer, ref face);

            // Create trimming curves running counter clockwise around the surface's domain.
            // Note that trims of outer loops run counter clockwise while trims of inner loops (holes) run anti-clockwise.
            // Also note that when trims locate on surface N,S,E or W ends, then trim_iso becomes N_iso, S_iso, E_iso and W_iso respectfully.
            // While if trim is parallel to surface N,S or E,W, then trim is becomes y_iso and x_iso respectfully.

            // Start at the south side
            OnCurve c2;
            int     c2i, ei = 0;
            bool    bRev3d = false;

            IOnSurface.ISO iso = IOnSurface.ISO.not_iso;

            for (int side = 0; side < 3; side++)
            {
                // side: 0=south, 1=east, 2=north, 3=west

                c2 = CreateTrimmingCurve(srf, side);

                //Add trimming curve to brep trmming curves array
                c2i = brep.m_C2.Count();
                brep.m_C2.Append(c2);

                switch (side)
                {
                case 0: // south
                    ei     = e0;
                    bRev3d = (e0_dir == -1);
                    iso    = IOnSurface.ISO.S_iso;
                    break;

                case 1: // diagonal
                    ei     = e1;
                    bRev3d = (e1_dir == -1);
                    iso    = IOnSurface.ISO.not_iso;
                    break;

                case 2: // diagonal
                    ei     = e2;
                    bRev3d = (e2_dir == -1);
                    iso    = IOnSurface.ISO.not_iso;
                    break;
                }

                //Create new trim topology that references edge, direction reletive to edge, loop and trim curve geometry
                OnBrepEdge edge = brep.m_E[ei];
                OnBrepTrim trim = brep.NewTrim(ref edge, bRev3d, ref loop, c2i);
                if (trim != null)
                {
                    trim.m_iso  = iso;
                    trim.m_type = IOnBrepTrim.TYPE.boundary; // This one b-rep face, so all trims are boundary ones.
                    trim.set_m_tolerance(0, 0.0);            // This simple example is exact - for models with non-exact
                    trim.set_m_tolerance(1, 0.0);            // data, set tolerance as explained in definition of ON_BrepTrim.
                }
            }
            return(loop.m_loop_index);
        }
        /// <summary>
        /// MakeTwistedCubeEdges
        /// </summary>
        static void MakeTwistedCubeEdges(
      ref OnBrep brep
      )
        {
            // In this simple example, the edge indices exactly match the 3d
              // curve indices.  In general,the correspondence between edge and
              // curve indices can be arbitrary.  It is permitted for multiple
              // edges to use different portions of the same 3d curve.  The
              // orientation of the edge always agrees with the natural
              // parametric orientation of the curve.

              // Edge that runs from A to B
              MakeTwistedCubeEdge(ref brep, A, B, AB);

              // Edge that runs from B to C
              MakeTwistedCubeEdge(ref brep, B, C, BC);

              // Edge that runs from C to D
              MakeTwistedCubeEdge(ref brep, C, D, CD);

              // Edge that runs from A to D
              MakeTwistedCubeEdge(ref brep, A, D, AD);

              // Edge that runs from E to F
              MakeTwistedCubeEdge(ref brep, E, F, EF);

              // Edge that runs from F to G
              MakeTwistedCubeEdge(ref brep, F, G, FG);

              // Edge that runs from G to H
              MakeTwistedCubeEdge(ref brep, G, H, GH);

              // Edge that runs from E to H
              MakeTwistedCubeEdge(ref brep, E, H, EH);

              // Edge that runs from A to E
              MakeTwistedCubeEdge(ref brep, A, E, AE);

              // Edge that runs from B to F
              MakeTwistedCubeEdge(ref brep, B, F, BF);

              // Edge that runs from C to G
              MakeTwistedCubeEdge(ref brep, C, G, CG);

              // Edge that runs from D to H
              MakeTwistedCubeEdge(ref brep, D, H, DH);
        }
Beispiel #37
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);
        }
        /// <summary>
        /// MakeTwistedCubeFaces
        /// </summary>
        static void MakeTwistedCubeFaces(
      ref OnBrep brep 
      )
        {
            MakeTwistedCubeFace(ref brep,
            ABCD,       // Index of surface ABCD
            +1,         // orientation of surface with respect to brep
            A, B, C, D, // Indices of vertices listed in SW,SE,NW,NE order
            AB,+1,      // South side edge and its orientation with respect to
                    // to the trimming curve.  (AB)
            BC,+1,      // South side edge and its orientation with respect to
                    // to the trimming curve.  (BC)
            CD,+1,      // South side edge and its orientation with respect to
                    // to the trimming curve   (CD)
            AD,-1       // South side edge and its orientation with respect to
                    // to the trimming curve   (AD)
            );

              MakeTwistedCubeFace(ref brep,
            BCGF,       // Index of surface BCGF
            -1,         // orientation of surface with respect to brep
            B, C, G, F, // Indices of vertices listed in SW,SE,NW,NE order
            BC,+1,      // South side edge and its orientation with respect to
                    // to the trimming curve.  (BC)
            CG,+1,      // South side edge and its orientation with respect to
                    // to the trimming curve.  (CG)
            FG,-1,      // South side edge and its orientation with respect to
                    // to the trimming curve   (FG)
            BF,-1       // South side edge and its orientation with respect to
                    // to the trimming curve   (BF)
            );

              MakeTwistedCubeFace(ref brep,
            CDHG,       // Index of surface CDHG
            -1,         // orientation of surface with respect to brep
            C, D, H, G, // Indices of vertices listed in SW,SE,NW,NE order
            CD,+1,      // South side edge and its orientation with respect to
                    // to the trimming curve.  (CD)
            DH,+1,      // South side edge and its orientation with respect to
                    // to the trimming curve.  (DH)
            GH,-1,      // South side edge and its orientation with respect to
                    // to the trimming curve   (GH)
            CG,-1       // South side edge and its orientation with respect to
                    // to the trimming curve   (CG)
            );

              MakeTwistedCubeFace(ref brep,
            ADHE,       // Index of surface ADHE
            +1,         // orientation of surface with respect to brep
            A, D, H, E, // Indices of vertices listed in SW,SE,NW,NE order
            AD,+1,      // South side edge and its orientation with respect to
                    // to the trimming curve.  (AD)
            DH,+1,      // South side edge and its orientation with respect to
                    // to the trimming curve.  (DH)
            EH,-1,      // South side edge and its orientation with respect to
                    // to the trimming curve   (EH)
            AE,-1       // South side edge and its orientation with respect to
                    // to the trimming curve   (AE)
            );

              MakeTwistedCubeFace(ref brep,
            ABFE,       // Index of surface ABFE
            -1,         // orientation of surface with respect to brep
            A, B, F, E, // Indices of vertices listed in SW,SE,NW,NE order
            AB,+1,      // South side edge and its orientation with respect to
                    // to the trimming curve.  (AB)
            BF,+1,      // South side edge and its orientation with respect to
                    // to the trimming curve.  (BF)
            EF,-1,      // South side edge and its orientation with respect to
                    // to the trimming curve   (EF)
            AE,-1       // South side edge and its orientation with respect to
                    // to the trimming curve   (AE)
            );

              MakeTwistedCubeFace(ref brep,
            EFGH,       // Index of surface EFGH
            -1,         // orientation of surface with respect to brep
            E, F, G, H, // Indices of vertices listed in SW,SE,NW,NE order
            EF,+1,      // South side edge and its orientation with respect to
                    // to the trimming curve.  (EF)
            FG,+1,      // South side edge and its orientation with respect to
                    // to the trimming curve.  (FG)
            GH,+1,      // South side edge and its orientation with respect to
                    // to the trimming curve   (GH)
            EH,-1       // South side edge and its orientation with respect to
                    // to the trimming curve   (EH)
            );
        }
        private static void CreateFace(ref OnBrep brep, int si)
        {
            //Add new face to brep
              OnBrepFace face = brep.NewFace(si);

              //Create outer loop and trims for the face
              MakeOuterTrimmingLoop(ref brep, ref face,
                                A, B, C, D, // Indices of vertices listed in SW,SE,NW,NE order
                                AB, +1,      // South side edge and its orientation with respect to
            // to the trimming curve.  (AB)
                                BC, +1,      // East side edge and its orientation with respect to
            // to the trimming curve.  (BC)
                                CD, +1,      // North side edge and its orientation with respect to
            // to the trimming curve   (CD)
                                AD, -1       // West side edge and its orientation with respect to
            // to the trimming curve   (AD)
                        );

              //Create loop and trims for the face
              MakeInnerTrimmingLoop(ref brep, ref face,
                                E, F, G, H, // Indices of hole vertices
                                EF, +1,      // Parallel to south side edge and its orientation with respect to
            // to the trimming curve.  (EF)
                                FG, +1,      // Parallel to east side edge and its orientation with respect to
            // to the trimming curve.  (FG)
                                GH, +1,      // Parallel to north side edge and its orientation with respect to
            // to the trimming curve   (GH)
                                EH, -1       // Parallel to west side edge and its orientation with respect to
            // to the trimming curve   (EH)
                        );

              //Set face direction relative to surface direction
              face.m_bRev = false;
        }
        /// <summary>
        /// The one and only MakeTwistedCube
        /// </summary>
        static OnBrep MakeTwistedCube()
        {
            /*
              This example demonstrates how to construct a OnBrep
              with the topology shown below.

                 H-------e6-------G
                /                /|
               / |              / |
              /  e7            /  e5
             /   |            /   |
            /                e10  |
               /     |          /     |
              e11    E- - e4- -/- - - F
             /                /      /
            /      /         /      /
               D---------e2-----C      e9
               |     /          |     /
               |    e8          |    /
               e3  /            e1  /
               |                |  /
               | /              | /
               |                |/
               A-------e0-------B

              */

              On3dPoint[] points = new On3dPoint[8];
              points[0] = new On3dPoint(0.0, 0.0, 0.0);   // point A = geometry for vertex 0
              points[1] = new On3dPoint(10.0, 0.0, 0.0);  // point B = geometry for vertex 1
              points[2] = new On3dPoint(10.0, 8.0, -1.0); // point C = geometry for vertex 2
              points[3] = new On3dPoint(0.0, 6.0, 0.0);   // point D = geometry for vertex 3
              points[4] = new On3dPoint(1.0, 2.0, 11.0);  // point E = geometry for vertex 4
              points[5] = new On3dPoint(10.0, 0.0, 12.0); // point F = geometry for vertex 5
              points[6] = new On3dPoint(10.0, 7.0, 13.0); // point G = geometry for vertex 6
              points[7] = new On3dPoint(0.0, 6.0, 12.0);  // point H = geometry for vertex 7

              OnBrep brep = new OnBrep();

              // Create eight vertices located at the eight points
              int vi;
              for (vi = 0; vi < 8; vi++)
              {
            OnBrepVertex v = brep.NewVertex(points[vi]);
            v.m_tolerance = 0.0;
              }

              // Create 3d curve geometry - the orientations are arbitrarily chosen
              // so that the end vertices are in alphabetical order.
              brep.m_C3.Append(TwistedCubeEdgeCurve(points[A], points[B])); // line AB
              brep.m_C3.Append(TwistedCubeEdgeCurve(points[B], points[C])); // line BC
              brep.m_C3.Append(TwistedCubeEdgeCurve(points[C], points[D])); // line CD
              brep.m_C3.Append(TwistedCubeEdgeCurve(points[A], points[D])); // line AD
              brep.m_C3.Append(TwistedCubeEdgeCurve(points[E], points[F])); // line EF
              brep.m_C3.Append(TwistedCubeEdgeCurve(points[F], points[G])); // line FG
              brep.m_C3.Append(TwistedCubeEdgeCurve(points[G], points[H])); // line GH
              brep.m_C3.Append(TwistedCubeEdgeCurve(points[E], points[H])); // line EH
              brep.m_C3.Append(TwistedCubeEdgeCurve(points[A], points[E])); // line AE
              brep.m_C3.Append(TwistedCubeEdgeCurve(points[B], points[F])); // line BF
              brep.m_C3.Append(TwistedCubeEdgeCurve(points[C], points[G])); // line CG
              brep.m_C3.Append(TwistedCubeEdgeCurve(points[D], points[H])); // line DH

              // Create the 12 edges that connect the corners of the cube.
              MakeTwistedCubeEdges(ref brep);

              // Create 3d surface geometry - the orientations are arbitrarily chosen so
              // that some normals point into the cube and others point out of the cube.
              brep.m_S.Append(TwistedCubeSideSurface(points[A], points[B], points[C], points[D])); // ABCD
              brep.m_S.Append(TwistedCubeSideSurface(points[B], points[C], points[G], points[F])); // BCGF
              brep.m_S.Append(TwistedCubeSideSurface(points[C], points[D], points[H], points[G])); // CDHG
              brep.m_S.Append(TwistedCubeSideSurface(points[A], points[D], points[H], points[E])); // ADHE
              brep.m_S.Append(TwistedCubeSideSurface(points[A], points[B], points[F], points[E])); // ABFE
              brep.m_S.Append(TwistedCubeSideSurface(points[E], points[F], points[G], points[H])); // EFGH

              // Create the CRhinoBrepFaces
              MakeTwistedCubeFaces(ref brep);

              if (!brep.IsValid())
            return null;

              return brep;
        }
        private static int MakeInnerTrimmingLoop(ref OnBrep brep,                        // returns index of loop
                                                 ref OnBrepFace face,                    // face loop is on
                                                 int vSWi, int vSEi, int vNEi, int vNWi, // Indices of hole vertices
                                                 int eSi,                                // index of edge close to south side of surface
                                                 int eS_dir,                             // orientation of edge with respect to surface trim
                                                 int eEi,                                // index of edge close to east side of surface
                                                 int eE_dir,                             // orientation of edge with respect to surface trim
                                                 int eNi,                                // index of edge close to north side of surface
                                                 int eN_dir,                             // orientation of edge with respect to surface trim
                                                 int eWi,                                // index of edge close to west side of surface
                                                 int eW_dir                              // orientation of edge with respect to surface trim
                                                 )
        {
            OnSurface srf = brep.m_S[face.m_si];
            //Create new inner loop
            OnBrepLoop loop = brep.NewLoop(IOnBrepLoop.TYPE.inner, ref face);

            // Create trimming curves running counter clockwise around the surface's domain.
            // Note that trims of outer loops run counter clockwise while trims of inner loops (holes) run clockwise.
            // Also note that when trims locate on surface N,S,E or W ends, then trim_iso becomes N_iso, S_iso, E_iso and W_iso respectfully.
            // While if trim is parallel to surface N,S or E,W, then trim iso becomes y_iso and x_iso respectfully.
            // All other cases, iso is set to not_iso

            // Start near the south side
            OnCurve c2;
            int     c2i, ei = 0;
            bool    bRev3d = false;

            IOnSurface.ISO iso = IOnSurface.ISO.not_iso;

            for (int side = 0; side < 4; side++)
            {
                // side: 0=near south(y_iso), 1=near west(x_iso), 2=near north(y_iso), 3=near east(x_iso)

                //Create trim 2d curve
                c2 = CreateInnerTrimmingCurve(srf, side);

                //Add trimming curve to brep trmming curves array
                c2i = brep.m_C2.Count();
                brep.m_C2.Append(c2);

                switch (side)
                {
                case 0: // near south
                    ei     = eSi;
                    bRev3d = (eS_dir == -1);
                    iso    = IOnSurface.ISO.y_iso;
                    break;

                case 1: // near west
                    ei     = eEi;
                    bRev3d = (eE_dir == -1);
                    iso    = IOnSurface.ISO.x_iso;
                    break;

                case 2: // near north
                    ei     = eNi;
                    bRev3d = (eN_dir == -1);
                    iso    = IOnSurface.ISO.y_iso;
                    break;

                case 3: // near east
                    ei     = eWi;
                    bRev3d = (eW_dir == -1);
                    iso    = IOnSurface.ISO.x_iso;
                    break;
                }

                //Create new trim topology that references edge, direction reletive to edge, loop and trim curve geometry
                OnBrepEdge edge = brep.m_E[ei];
                OnBrepTrim trim = brep.NewTrim(ref edge, bRev3d, ref loop, c2i);
                if (trim != null)
                {
                    trim.m_iso  = iso;
                    trim.m_type = IOnBrepTrim.TYPE.boundary; // This one b-rep face, so all trims are boundary ones.
                    trim.set_m_tolerance(0, 0.0);            // This simple example is exact - for models with non-exact
                    trim.set_m_tolerance(1, 0.0);            // data, set tolerance as explained in definition of ON_BrepTrim.
                }
            }

            return(loop.m_loop_index);
        }