示例#1
0
        private static void TestSegmentation(TessellatedSolid ts, int[] segmentCounts)
        {
            var obb = MinimumEnclosure.OrientedBoundingBox(ts);
            var averageNumberOfSteps = 500;

            //Do the average # of slices slices for each direction on a box (l == w == h).
            //Else, weight the average # of slices based on the average obb distance
            var obbAverageLength = (obb.Dimensions[0] + obb.Dimensions[1] + obb.Dimensions[2]) / 3;
            //Set step size to an even increment over the entire length of the solid
            var stepSize = obbAverageLength / averageNumberOfSteps;

            //var startTime = DateTime.Now;

            for (var i = 0; i < 3; i++)
            {
                var direction = obb.Directions[i];

                //Get the forward and reverse segments. They should be mostly the same.
                Dictionary <int, double> stepDistances;
                Dictionary <int, double> sortedVertexDistanceLookup;
                var segments = DirectionalDecomposition.UniformDirectionalSegmentation(ts, direction, stepSize,
                                                                                       out stepDistances, out sortedVertexDistanceLookup, out _);
                Assert.That(segments.Count == segmentCounts[i], "Incorrect Number of Segments");

                //Check to make sure all the faces and edges and vertices are inlcuded into at least one segment.
                CheckAllObjectTypes(ts, segments);

                var reverseSegments = DirectionalDecomposition.UniformDirectionalSegmentation(ts, direction.multiply(-1), stepSize,
                                                                                              out stepDistances, out sortedVertexDistanceLookup, out _);
                Assert.That(reverseSegments.Count == segmentCounts[i], "Incorrect Number of Segments");
                CheckAllObjectTypes(ts, reverseSegments);
            }
            //var totalTime = DateTime.Now - startTime;
            //Debug.WriteLine(totalTime.TotalMilliseconds + " Milliseconds");
        }
示例#2
0
        public static void TestSegmentation(TessellatedSolid ts)
        {
            var obb       = MinimumEnclosure.OrientedBoundingBox(ts);
            var startTime = DateTime.Now;

            var averageNumberOfSteps = 500;

            //Do the average # of slices slices for each direction on a box (l == w == h).
            //Else, weight the average # of slices based on the average obb distance
            var obbAverageLength = (obb.Dimensions[0] + obb.Dimensions[1] + obb.Dimensions[2]) / 3;
            //Set step size to an even increment over the entire length of the solid
            var stepSize = obbAverageLength / averageNumberOfSteps;

            foreach (var direction in obb.Directions)
            {
                Dictionary <int, double> stepDistances;
                Dictionary <int, double> sortedVertexDistanceLookup;
                var segments = DirectionalDecomposition.UniformDirectionalSegmentation(ts, direction,
                                                                                       stepSize, out stepDistances, out sortedVertexDistanceLookup);
                //foreach (var segment in segments)
                //{
                //    var vertexLists = segment.DisplaySetup(ts);
                //    Presenter.ShowVertexPathsWithSolid(vertexLists, new List<TessellatedSolid>() { ts });
                //}
            }

            // var segments = AreaDecomposition.UniformDirectionalSegmentation(ts, obb.Directions[2].multiply(-1), stepSize);
            var totalTime = DateTime.Now - startTime;

            Debug.WriteLine(totalTime.TotalMilliseconds + " Milliseconds");
            //CheckAllObjectTypes(ts, segments);
        }
示例#3
0
        private static void ConvexHullTesting()
        {
            var writer = new TextWriterTraceListener(Console.Out);

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

            if (Directory.Exists("../../../../TVGLTest/Convex Hull Tests"))
            {
                //x64
                dir = new DirectoryInfo("../../../../TVGLTest/Convex Hull Tests");
            }
            else
            {
                //x86
                dir = new DirectoryInfo("../../../TVGLTest/Convex Hull Tests");
            }
            var random    = new Random();
            var fileNames = dir.GetFiles("*").ToArray();

            for (var i = 0; i < fileNames.Count(); i++)
            {
                //var filename = FileNames[i];
                var filename = fileNames[i].FullName;
                if (!File.Exists(filename) || !filename.EndsWith(".PolyLight"))
                {
                    continue;
                }
                Console.WriteLine("Attempting: " + filename);
                var polyLight = PolygonLight.Deserialize(filename);
                var cxvHull   = MinimumEnclosure.ConvexHull2D(polyLight.Path);
                var polygon   = new Polygon(cxvHull.Select(p => new Point(p)));
                if (!polygon.IsConvex())
                {
                    Presenter.ShowAndHang(polyLight.Path, "Convex Hull Error", Plot2DType.Points);
                    Presenter.ShowAndHang(cxvHull);
                }
            }

            Console.WriteLine("Completed.");
            Console.ReadKey();
        }
示例#4
0
        private static void TestOBB(string InputDir)
        {
            var di          = new DirectoryInfo(InputDir);
            var fis         = di.EnumerateFiles();
            var numVertices = new List <int>();
            var data        = new List <double[]>();

            foreach (var fileInfo in fis)
            {
                try
                {
                    IO.Open(fileInfo.Open(FileMode.Open), fileInfo.Name, out TessellatedSolid tessellatedSolid);
                    List <double> times, volumes;
                    MinimumEnclosure.OrientedBoundingBox_Test(tessellatedSolid, out times, out volumes);//, out VolumeData2);
                    data.Add(new[] { tessellatedSolid.ConvexHull.Vertices.Count(), tessellatedSolid.Volume,
                                     times[0], times[1], times[2], volumes[0], volumes[1], volumes[2] });
                }
                catch { }
            }
            // TVGLTest.ExcelInterface.PlotEachSeriesSeperately(VolumeData1, "Edge", "Angle", "Volume");
            TVGLTest.ExcelInterface.CreateNewGraph(new[] { data }, "", "Methods", "Volume", new[] { "PCA", "ChanTan" });
        }
示例#5
0
        internal static void CreateOBB1(List <TessellatedSolid> solids)
        {
            var s = new Stopwatch();

            s.Start();
            Console.WriteLine();
            Console.WriteLine("OBBs are being Created ...");
            Parallel.ForEach(solids, solid =>
            {
                var bb = MinimumEnclosure.OrientedBoundingBox(solid);
                // change the orser of the corner vertices to clock wise:
                bb.CornerVertices = new[]
                {
                    bb.CornerVertices[2], bb.CornerVertices[0], bb.CornerVertices[1], bb.CornerVertices[3],
                    bb.CornerVertices[6], bb.CornerVertices[4], bb.CornerVertices[5], bb.CornerVertices[7]
                };
                lock (OrientedBoundingBoxDic)
                    OrientedBoundingBoxDic.Add(solid, bb);
            }
                             );
            s.Stop();
            Console.WriteLine("OBB Creation is done in:" + "     " + s.Elapsed);
        }