コード例 #1
0
ファイル: IOFunctions.cs プロジェクト: opensourcer2/TVGL
        public static void Open(Stream s, out CrossSectionSolid solid)
        {
            var serializer = new JsonSerializer();
            var sr         = new StreamReader(s);

            using (var reader = new JsonTextReader(sr))
                solid = serializer.Deserialize <CrossSectionSolid>(reader);
        }
コード例 #2
0
ファイル: IOFunctions.cs プロジェクト: opensourcer2/TVGL
        public static void OpenFromString(string data, out CrossSectionSolid solid)
        {
            var stream = new MemoryStream();

            using (var writer = new StreamWriter(stream))
            {
                writer.Write(data);
                writer.Flush();
            }
            stream.Position = 0;
            Open(stream, out solid);
        }
コード例 #3
0
ファイル: IOFunctions.cs プロジェクト: opensourcer2/TVGL
 public static void Open(string filename, out CrossSectionSolid solid)
 {
     if (File.Exists(filename))
     {
         using (var fileStream = File.OpenRead(filename))
             Open(fileStream, out solid);
     }
     else
     {
         throw new FileNotFoundException("The file was not found at: " + filename);
     }
 }
コード例 #4
0
        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
        }
コード例 #5
0
        private void FillInFromTessellation(TessellatedSolid ts)
        {
            var yBegin = Bounds[0][1] + VoxelSideLength / 2;
            var zBegin = Bounds[0][2] + VoxelSideLength / 2;
            var decomp = CrossSectionSolid.GetUniformlySpacedSlices(ts, CartesianDirections.ZPositive, zBegin, numVoxelsZ, VoxelSideLength);
            var inverseVoxelSideLength = 1 / VoxelSideLength; // since its quicker to multiple then to divide, maybe doing this once at the top will save some time

            Parallel.For(0, numVoxelsZ, k =>
                         //for (var k = 0; k < numVoxelsZ; k++)
            {
                var loops = decomp[k];
                if (loops.Any())
                {
                    var intersections = PolygonOperations.AllPolygonIntersectionPointsAlongY(loops.Select(p => new Polygon(p)), yBegin, numVoxelsY, VoxelSideLength, out var yStartIndex);
                    var numYlines     = intersections.Count;
                    for (int j = 0; j < numYlines; j++)
                    {
                        var intersectionPoints   = intersections[j];
                        var numXRangesOnThisLine = intersectionPoints.Length;
                        for (var m = 0; m < numXRangesOnThisLine; m += 2)
                        {
                            var sp = (ushort)((intersectionPoints[m] - Bounds[0][0]) * inverseVoxelSideLength);
                            if (sp < 0)
                            {
                                sp = 0;
                            }
                            var ep = (ushort)((intersectionPoints[m + 1] - Bounds[0][0]) * inverseVoxelSideLength);
                            if (ep >= numVoxelsX)
                            {
                                ep = (ushort)(numVoxelsX - 1);
                            }
                            ((VoxelRowSparse)voxels[k * zMultiplier + yStartIndex + j]).indices.Add(sp);
                            ((VoxelRowSparse)voxels[k * zMultiplier + yStartIndex + j]).indices.Add(ep);
                        }
                    }
                }
            });
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: opensourcer2/TVGL
        private static void Main(string[] args)
        {
            //Difference2();
            var writer = new TextWriterTraceListener(Console.Out);

            Debug.Listeners.Add(writer);
            TVGL.Message.Verbosity = VerbosityLevels.OnlyCritical;
            DirectoryInfo dir;

            if (Directory.Exists("../../../../TestFiles"))
            {
                //x64
                dir = new DirectoryInfo("../../../../TestFiles");
            }
            else
            {
                //x86
                dir = new DirectoryInfo("../../../TestFiles");
            }
            var random    = new Random();
            var fileNames = dir.GetFiles("*").OrderBy(x => random.Next()).ToArray();

            //var fileNames = dir.GetFiles("*").ToArray();
            //Casing = 18
            //SquareSupport = 75
            for (var i = 0; i < fileNames.Count(); i++)
            {
                //var filename = FileNames[i];
                var filename = fileNames[i].FullName;
                Console.WriteLine("Attempting: " + filename);
                Stream fileStream;
                var    solid = (TessellatedSolid)IO.Open(filename);
                if (solid.Errors != null)
                {
                    continue;
                }
                //Presenter.ShowAndHang(solid);
                var xs = CrossSectionSolid.CreateFromTessellatedSolid(solid, CartesianDirections.ZPositive, 150);
                //Presenter.ShowAndHang(xs);
                var ts2 = xs.ConvertToTessellatedSolidMarchingCubes(10000);
                Console.WriteLine("number of faces = {0}", ts2.NumberOfFaces);
                //Presenter.ShowAndHang(ts2);
                //if (!File.Exists(filename)) continue;
                //using (fileStream = File.OpenRead(filename))
                //    IO.Open(fileStream, filename);
                //IO.Save(xs, solid.FileName+".XS", FileType.TVGL);
                //Color color = new Color(KnownColors.AliceBlue);
                //var xs2 = (CrossSectionSolid)IO.Open(solid.FileName + ".tvgl");
                // Presenter.ShowAndHang(xs2);
                //ts.SolidColor = new Color(KnownColors.MediumSeaGreen)
                //{
                //    Af = 0.25f
                //};
                //Presenter.ShowAndHang(solid);
                // TestCrossSectionSolidToTessellated(ts);
                //TestSlice(ts);
                // var stopWatch = new Stopwatch();
                // Color color = new Color(KnownColors.AliceBlue);
                //ts[0].SetToOriginAndSquare(out var backTransform);
                //ts[0].Transform(new double[,]
                //  {
                //{1,0,0,-(ts[0].XMax + ts[0].XMin)/2},
                //{0,1,0,-(ts[0].YMax+ts[0].YMin)/2},
                //{0,0,1,-(ts[0].ZMax+ts[0].ZMin)/2},
                //  });
                // stopWatch.Restart();
                //PresenterShowAndHang(ts);
                // Console.WriteLine("Voxelizing Tesselated File " + filename);
                //  var vs1 = new VoxelizedSolid(ts[0], VoxelDiscretization.Coarse, false);//, bounds);
                // Presenter.ShowAndHang(vs1);
                //TestVoxelization(ts[0]);
                //bounds = vs1.Bounds;
                // return;
            }

            Console.WriteLine("Completed.");
            //  Console.ReadKey();
        }