Exemple #1
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.
        }
        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.
        }
Exemple #3
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);
        }
        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);
        }