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"); }
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); }
/// <summary> /// Find the volume of a tesselated solid with a slower method. /// This method could be exteded to find partial volumes of a solid (e.g. volume between two planes) /// </summary> /// <param name="ts"></param> /// <returns></returns> private static double VolumeViaAreaDecomposition(TessellatedSolid ts) { var normal = new[] { 1.0, 0.0, 0.0 }; //Direction is irrellevant var stepSize = 0.01; var volume = 0.0; var areas = DirectionalDecomposition.NonUniformAreaDecomposition(ts, normal, stepSize); //Trapezoidal approximation. This should be accurate since the lines betweens data points are linear for (var i = 1; i < areas.Count; i++) { var deltaX = areas[i][0] - areas[i - 1][0]; if (deltaX < 0) { throw new Exception("Error in your implementation. This should never occur"); } volume = volume + .5 * (areas[i][1] + areas[i - 1][1]) * deltaX; } return(volume); }