Esempio n. 1
0
        public static RoughPartConcentricMesh3D SimpleChawJuckCylinder(params object[] o)
        {
            //double length = (double)o[0];
            //double radius = (double)o[2];

            double length = -120;
            double radius = 150;
            RoughPartConcentricMesh3D mesh = new RoughPartConcentricMesh3D();
            BVHPolyMesh2D poly2D = new BVHPolyMesh2D();
            List<HEVector2> list = new List<HEVector2>();
            list.Add(new HEVector2(length, 50));
            list.Add(new HEVector2(0, 50));
            list.Add(new HEVector2(0, radius));
            list.Add(new HEVector2(length, radius));

            poly2D.CreateMeshFromVertices(list);
            poly2D.CreateBVH(19, 1);
            mesh.Poly2D = poly2D;
            return mesh;
        }
Esempio n. 2
0
        public static RoughPartConcentricMesh3D RotatingJaw(params object[] o)
        {
            double length = 45;
            RoughPartConcentricMesh3D mesh = new RoughPartConcentricMesh3D();
            BVHPolyMesh2D poly2D = new BVHPolyMesh2D();
            List<HEVector2> list = new List<HEVector2>();
            list.Add(new HEVector2(0, 30));
            list.Add(new HEVector2(length, 30));
            list.Add(new HEVector2(length, 60));
            list.Add(new HEVector2(length-15, 60));
            list.Add(new HEVector2(length-15, 110));
            list.Add(new HEVector2(length - 30, 110));
            list.Add(new HEVector2(length - 30, 150));
            list.Add(new HEVector2(0, 150));

            poly2D.CreateMeshFromVertices(list);
            mesh.Poly2D = poly2D;
            return mesh;
        }
Esempio n. 3
0
        internal BVHPolyMesh2D FeedRate2D(Tool tool, Vector3D direction)
        {
            BVHPolyMesh2D newMesh = new BVHPolyMesh2D();

            List<int> indices = tool.CuttingEdgePolyIndices;
            HalfEdge3Poly p = tool.Mesh.Polys[indices[0]];
            Debug.Assert(EpsilonTests.IsNearlyZeroEpsHigh(direction.Z));
            DataStructures.Tuple<double, HalfEdge3> min = new DataStructures.Tuple<double, HalfEdge3>(Double.MaxValue, null);
            DataStructures.Tuple<double, HalfEdge3> max = new DataStructures.Tuple<double, HalfEdge3>(Double.MinValue, null);

            // build 2d TSV for this poly

            //calc min and max vertex
            foreach (int i in tool.Mesh.GetFaceCirculator(p.OuterComponent))
            {
                HalfEdge3 h = tool.Mesh.HalfEdges[i];
                Debug.Assert(EpsilonTests.IsNearlyZeroEpsHigh(tool.Mesh.Vertices[h.Origin].Z));
                double c = direction.Y * tool.Mesh.Vertices[h.Origin].X - direction.X * tool.Mesh.Vertices[h.Origin].Y;
                if (c < min.Val1)
                {
                    min.Val1 = c;
                    min.Val2 = h;
                }
                if (c >= max.Val1)
                {
                    max.Val1 = c;
                    max.Val2 = h;
                }
            }

            Debug.Assert(min.Val2 != null && max.Val2 != null);
            Debug.Assert(min.Val2 != max.Val2);
            // Create tsv of poly
            List<HEVector2> vertexList = new List<HEVector2>();
            bool onFrontFace = true;
            HalfEdge3 start, it;
            it = start = max.Val2;
            do
            {
                if (it == max.Val2)
                {
                    vertexList.Add(new HEVector2(tool.Mesh.Vertices[it.Origin].X, tool.Mesh.Vertices[it.Origin].Y));
                }
                if (onFrontFace)
                {
                    vertexList.Add(new HEVector2(tool.Mesh.Vertices[it.Origin].X + direction.X, tool.Mesh.Vertices[it.Origin].Y + direction.Y));
                }
                else
                {
                    vertexList.Add(new HEVector2(tool.Mesh.Vertices[it.Origin].X, tool.Mesh.Vertices[it.Origin].Y));
                }
                if (it == min.Val2)
                {
                    vertexList.Add(new HEVector2(tool.Mesh.Vertices[it.Origin].X, tool.Mesh.Vertices[it.Origin].Y));
                    onFrontFace = false;
                }
                it = tool.Mesh.HalfEdges[it.Next];
            }
            while (it != start);
            newMesh.CreateMeshFromVertices(vertexList);
            newMesh.CreateBVH();

            return newMesh;
        }
Esempio n. 4
0
        public static RoughPartConcentricMesh3D Quad(params object[] o)
        {
            double length = (double)o[0];
            double radius = (double)o[2];
            int offset = (int)o[3];
            RoughPartConcentricMesh3D mesh = new RoughPartConcentricMesh3D();

            BVHPolyMesh2D poly2D = new BVHPolyMesh2D();
            List<HEVector2> list = new List<HEVector2>();
            list.Add(new HEVector2(0 + offset, 0));
            list.Add(new HEVector2(length + offset, 0));
            list.Add(new HEVector2(length + offset, radius));
            list.Add(new HEVector2(0 + offset, radius));

            poly2D.CreateMeshFromVertices(list);
            poly2D.CreateBVH(19, 1);
            mesh.Poly2D = poly2D;
            return mesh;
        }
Esempio n. 5
0
        private void Do2DBooleanOps(GeoObject geoObject, BVHPolyMesh2D tsv)
        {
            RoughPartGeoObject o = geoObject as RoughPartGeoObject;
            RoughPartConcentricMesh3D mesh = o.Mesh as RoughPartConcentricMesh3D;
            if (mesh.Poly2D.HECount == 0) // nothing to do
                return;

            BoolDifference subtractor = new BoolDifference(o.VBOManager);

            BVHPolyMesh2D meshA = mesh.Poly2D;
            subtractor.Subtract(mesh.Poly2D.BVH, tsv.BVH);
            mesh.Poly2D = GetMesh(subtractor.MeshesA);
            mesh.Poly2D.BVH = new BVH(mesh.Poly2D);

            #if DEBUG
            foreach (AABRHalfEdge2 h in mesh.Poly2D.HalfEdgeIterator())
            {
                if (h.Origin.X == h.Next.Origin.X && h.Origin.Y == h.Next.Origin.Y)
                    throw new Exception("Vertices are the same");
                if (h.Bucket == null)
                    throw new Exception("Halfedge has no corresponding bucket");
                if(h == h.Twin)
                    throw new Exception("HalfEdge is not correct");
                if (h == h.Next)
                    throw new Exception("HalfEdge is not correct");
            }
            #endif

            o.UpdateMesh();
        }