Exemple #1
0
        //[Fact]
        public static void TestClassify()
        {
            DirectoryInfo dir;

            if (Directory.Exists("../../../../TestFiles"))
            {
                //x64
                dir = new DirectoryInfo("../../../../TestFiles");
            }
            else
            {
                //x86
                dir = new DirectoryInfo("../../../TestFiles");
            }
            //            brace.stl - holes showing up?
            // radiobox - missing holes - weird skip in outline
            // KnuckleTopOp flecks
            // mendel_extruder - one show up blank
            //var fileNames = dir.GetFiles("Obliq*").ToArray();
            var fileNames = dir.GetFiles("*athtub*").ToArray();

            for (var i = 0; i < fileNames.Length - 0; i++)
            {
                var filename = fileNames[i].FullName;
                var name     = fileNames[i].Name;
                Console.WriteLine("Attempting: " + filename);
                var solid  = (TessellatedSolid)IO.Open(filename);
                var voxsol = new VoxelizedSolid(solid, 1000);
                Console.WriteLine("now presenting!");
                Presenter.ShowAndHang(voxsol);
                Presenter.ShowAndHang(voxsol.ConvertToTessellatedSolidMarchingCubes(5));
            }
        }
Exemple #2
0
        private static void TestVoxelization()
        {
            var dir = new DirectoryInfo(".");

            while (!Directory.Exists(dir.FullName + Path.DirectorySeparatorChar + "TestFiles"))
            {
                dir = dir.Parent;
            }
            dir = new DirectoryInfo(dir.FullName + Path.DirectorySeparatorChar + "TestFiles");

            //var fileName = dir.FullName + Path.DirectorySeparatorChar + "test.json";
            var fileNames = dir.GetFiles("*atht*").OrderBy(x => r.NextDouble()).ToArray();

            for (var i = 0; i < fileNames.Length; i++)
            {
                var filename = fileNames[i].FullName;
                var name     = fileNames[i].Name;
                Console.WriteLine("Attempting: " + filename);
                var solid = (TessellatedSolid)IO.Open(filename);
                Presenter.ShowAndHang(solid);
                if (solid.Errors != null)
                {
                    Console.WriteLine("    ===>" + filename + " has errors: " + solid.Errors.ToString());
                    continue;
                }
                Console.WriteLine("voxelizing...");
                var voxsol = new VoxelizedSolid(solid, 1000);
                Console.WriteLine("now presenting " + name);
                Presenter.ShowAndHang(voxsol.ConvertToTessellatedSolidMarchingCubes(5));
                Console.WriteLine("draft in pos y");
                var yposVoxSol = voxsol.DraftToNewSolid(CartesianDirections.YPositive);
                Console.WriteLine("presenting");
                Presenter.ShowAndHang(yposVoxSol.ConvertToTessellatedSolidMarchingCubes(5));

                Console.WriteLine("draft in neg y");
                var ynegVoxSol = voxsol.DraftToNewSolid(CartesianDirections.YNegative);
                Console.WriteLine("presenting");
                Presenter.ShowAndHang(ynegVoxSol.ConvertToTessellatedSolidMarchingCubes(5));

                Console.WriteLine("union of y solids");
                var yUnion = yposVoxSol.UnionToNewSolid(ynegVoxSol);
                Console.WriteLine("presenting");
                Presenter.ShowAndHang(yUnion.ConvertToTessellatedSolidMarchingCubes(5));

                Console.WriteLine("draft in neg z");
                var znegVoxSol = voxsol.DraftToNewSolid(CartesianDirections.ZNegative);
                Console.WriteLine("intersecting");
                var intersect = znegVoxSol.IntersectToNewSolid(yUnion);
                Console.WriteLine("presenting");
                Presenter.ShowAndHang(intersect.ConvertToTessellatedSolidMarchingCubes(5));
            }
        }
        private static void Run()
        {
            #region TessellatedSolid
            var ts = new TessellatedSolid();
            ts = new TessellatedSolid(new[] { new List <Vector3>() }, true, new TVGL.Color[0]);
            ts = new TessellatedSolid(new Vector3[0], new[] { new[] { 1, 2, 3 } }, true, new TVGL.Color[0]);
            ts.AddPrimitive(new Plane());
            ts.CheckModelIntegrity();
            ts.Complexify();
            ts.Copy();
            ts.OrientedBoundingBox();
            ts.CreateSilhouette(Vector3.UnitX);
            ts.Repair();
            ts.SetToOriginAndSquare(out var backTransform);
            ts.SetToOriginAndSquareToNewSolid(out backTransform);
            ts.Simplify();
            ts.SimplifyFlatPatches();
            ts.Transform(new Matrix4x4());
            ts.TransformToNewSolid(new Matrix4x4());
            ts.SliceOnInfiniteFlat(new Plane(), out List <TessellatedSolid> solids, out ContactData contactData);
            ts.SliceOnFlatAsSingleSolids(new Plane(), out TessellatedSolid positiveSideSolids, out TessellatedSolid negativeSideSolid);
            ts.GetSliceContactData(new Plane(), out contactData, false);
            ts.ConvexHull.Vertices.MinimumBoundingCylinder();
            ts.ConvexHull.Vertices.OrientedBoundingBox();
            var length = ts.ConvexHull.Vertices.GetLengthAndExtremeVertices(Vector3.UnitX, out List <IVertex3D> bottomVertices,
                                                                            out List <IVertex3D> topVertices);
            length = ts.ConvexHull.Vertices.GetLengthAndExtremeVertex(Vector3.UnitX, out Vertex bottomVertex,
                                                                      out Vertex topVertex);

            #endregion

            #region CrossSectionSolid
            var cs = new CrossSectionSolid(new Dictionary <int, double>());
            //cs.Add(new List<Vertex>)
            #endregion

            #region VoxelizedSolid
            var vs1 = new VoxelizedSolid(ts, 0.1);
            vs1.ConvertToTessellatedSolidMarchingCubes(5);
            vs1.ConvertToTessellatedSolidRectilinear();
            var vs2 = (VoxelizedSolid)vs1.Copy();
            vs1.DirectionalErodeToConstraintToNewSolid(in vs2, CartesianDirections.XNegative);
            vs1.Draft(CartesianDirections.XNegative);
            var vs3 = vs1.DraftToNewSolid(CartesianDirections.XNegative);

            #endregion
        }
Exemple #4
0
        private MeshGeometryModel3D ConvertVoxelizedSolidtoObject3D(VoxelizedSolid vs)
        {
            if (false)
            {
                var ts = vs.ConvertToTessellatedSolidMarchingCubes(20);
                ts.SolidColor = new Color(KnownColors.MediumSeaGreen)
                {
                    Af = 0.80f
                };
                return(ConvertTessellatedSolidtoObject3D(ts));
            }

            var normalsTemplate = new[]
            {
                new float[] { -1, 0, 0 }, new float[] { -1, 0, 0 },
                new float[] { 1, 0, 0 }, new float[] { 1, 0, 0 },
                new float[] { 0, -1, 0 }, new float[] { 0, -1, 0 },
                new float[] { 0, 1, 0 }, new float[] { 0, 1, 0 },
                new float[] { 0, 0, -1 }, new float[] { 0, 0, -1 },
                new float[] { 0, 0, 1 }, new float[] { 0, 0, 1 }
            };

            var coordOffsets = new[]
            {
                new[] { new float[] { 0, 0, 0 }, new float[] { 0, 0, 1 }, new float[] { 0, 1, 0 } },
                new[] { new float[] { 0, 1, 0 }, new float[] { 0, 0, 1 }, new float[] { 0, 1, 1 } }, //x-neg
                new[] { new float[] { 1, 0, 0 }, new float[] { 1, 1, 0 }, new float[] { 1, 0, 1 } },
                new[] { new float[] { 1, 1, 0 }, new float[] { 1, 1, 1 }, new float[] { 1, 0, 1 } }, //x-pos
                new[] { new float[] { 0, 0, 0 }, new float[] { 1, 0, 0 }, new float[] { 0, 0, 1 } },
                new[] { new float[] { 1, 0, 0 }, new float[] { 1, 0, 1 }, new float[] { 0, 0, 1 } }, //y-neg
                new[] { new float[] { 0, 1, 0 }, new float[] { 0, 1, 1 }, new float[] { 1, 1, 0 } },
                new[] { new float[] { 1, 1, 0 }, new float[] { 0, 1, 1 }, new float[] { 1, 1, 1 } }, //y-pos
                new[] { new float[] { 0, 0, 0 }, new float[] { 0, 1, 0 }, new float[] { 1, 0, 0 } },
                new[] { new float[] { 1, 0, 0 }, new float[] { 0, 1, 0 }, new float[] { 1, 1, 0 } }, //z-neg
                new[] { new float[] { 0, 0, 1 }, new float[] { 1, 0, 1 }, new float[] { 0, 1, 1 } },
                new[] { new float[] { 1, 0, 1 }, new float[] { 1, 1, 1 }, new float[] { 0, 1, 1 } }, //z-pos
            };
            var positions = new Vector3Collection();
            var normals   = new Vector3Collection();

            var s = (float)vs.VoxelSideLength;

            for (var i = 0; i < vs.numVoxelsX; i++)
            {
                for (var j = 0; j < vs.numVoxelsY; j++)
                {
                    for (var k = 0; k < vs.numVoxelsZ; k++)
                    {
                        if (!vs[i, j, k])
                        {
                            continue;
                        }

                        if (!vs.GetNeighbors(i, j, k, out var neighbors))
                        {
                            continue;
                        }

                        var x = i * s + (float)vs.Offset[0];
                        var y = j * s + (float)vs.Offset[1];
                        var z = k * s + (float)vs.Offset[2];
                        for (var m = 0; m < 12; m++)
                        {
                            if (neighbors[m / 2] != null)
                            {
                                continue;
                            }
                            for (var n = 0; n < 3; n++)
                            {
                                positions.Add(new Vector3(x + (coordOffsets[m][n][0] * s), y + coordOffsets[m][n][1] * s,
                                                          z + coordOffsets[m][n][2] * s));
                                normals.Add(new Vector3(normalsTemplate[m][0], normalsTemplate[m][1],
                                                        normalsTemplate[m][2]));
                            }
                        }
                    }
                }
            }
            return(new MeshGeometryModel3D
            {
                Material = new PhongMaterial()
                {
                    DiffuseColor = new SharpDX.Color4(vs.SolidColor.Rf, vs.SolidColor.Gf, vs.SolidColor.Bf,
                                                      vs.SolidColor.Af)
                                   //(float)0.75 * vs.SolidColor.Af)
                },
                Geometry = new HelixToolkit.Wpf.SharpDX.MeshGeometry3D
                {
                    Positions = positions,
                    Indices = new IntCollection(Enumerable.Range(0, positions.Count)),
                    Normals = normals
                }
            });
        }