Ejemplo n.º 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");
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
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);
        }