public AmanatidesIntersector(HeightField heightField) : base(heightField) { this.epsilonForRayDir = 0.001f; this.epsilonForCorners = 0.0001f; this.epsilonForClosePixelDepth = 0.05f; }
private static void MeasureIntersectionPerformance(HeightField heightfield, Vector3 start, Vector3 end, int iterations) { Vector3 direction = end - start; MyIntersector intersector = new MyIntersector(heightfield); FootprintDebugInfo debugInfo = new FootprintDebugInfo(); Intersection isec = intersector.Intersect(start, end, ref debugInfo); int visitedPixels = debugInfo.VisitedPixels.Count; Stopwatch sw = Stopwatch.StartNew(); for (int i = 0; i < iterations; i++) { Intersection intersection = intersector.Intersect(start, end); } sw.Stop(); Console.WriteLine("Intersection?: {0}", isec != null); Console.WriteLine("Ray length: {0:0.0}", direction.Length); Console.WriteLine("Visited pixels: {0}", visitedPixels); Console.WriteLine("Iterations: {0}", iterations); Console.WriteLine("Total time: {0} ms", sw.ElapsedMilliseconds); Console.WriteLine("Average time: {0:0.000} ms", sw.ElapsedMilliseconds / (double)iterations); double throughput = iterations / ((double)sw.ElapsedMilliseconds * 0.001); Console.WriteLine("Throughput: {0:0.000} traversals/s", throughput); Console.WriteLine("Throughput of visited pixels: {0:0.000} Mpx/s", throughput * visitedPixels * 1e-6); }
public void TrySimpleHeightfield1x1WithPerpendicularRay() { FloatMapImage data = new FloatMapImage(1, 1, PixelFormat.Greyscale); data.Image[0, 0, 0] = 0.5f; HeightField heightfield = new HeightField(new[] { data }); Vector3 start = new Vector3(0.1f, 0.1f, 0.25f); Vector3 end = new Vector3(0.1f, 0.1f, 0.75f); IntersectAndReport(heightfield, start, end); }
public void TrySimpleHeightfield2x2() { FloatMapImage data = new FloatMapImage(2, 2, PixelFormat.Greyscale); data.Image[0, 0, 0] = 0.5f; data.Image[0, 1, 0] = 0.5f; data.Image[1, 0, 0] = 0.5f; data.Image[1, 1, 0] = 0.5f; HeightField heightfield = new HeightField(new[] { data }); Vector3 start = new Vector3(0.5f, 1.5f, 0.0f); Vector3 end = new Vector3(2, 2, 1); IntersectAndReport(heightfield, start, end); }
internal override Intersection Intersect( Vector3 start, Vector3 end, ref FootprintDebugInfo debugInfo) { int stepCount = 5; //float near = 2; //float far = 10; //Vector2 start = (near / (float)ray.Direction.Z) * new Vector2((float)ray.Origin.X, (float)ray.Origin.Y); //Vector3d rayEnd = ray.Origin + ray.Direction; //Vector2 end = (far / (float)ray.Direction.Z) * new Vector2((float)rayEnd.X, (float)rayEnd.Y); Vector2 startXY = start.Xy; Vector2 endXY = end.Xy; float depthSize = 1; float currentDepth = 0; float isecDepth = 1; Vector2 position = startXY; for (int i = 0; i < stepCount; i++) { depthSize *= 0.5f; position = startXY + currentDepth * endXY; float hfDepth = HeightField.GetDepthBilinear(position, 0); if (currentDepth >= hfDepth) { isecDepth = currentDepth; currentDepth -= 2 * depthSize; } currentDepth += depthSize; } if (isecDepth < (1 - 0.0001)) { return(new Intersection(new Vector3d(position.X, position.Y, isecDepth))); } else { return(null); } }
internal override Intersection Intersect(Vector3 start, Vector3 end, ref FootprintDebugInfo debugInfo) { int steps = (int)Math.Floor(Math.Max((end - start).Xy.Length, 1)); Vector3 rayStep = (end - start) / (float)steps; //Vector3 rayStep = (end - start) / (float)Steps; Vector3 currentPos = start; int prevIndicator = GetRayLayerIndicator(start.Z, HeightField.GetDepthBilinear(start.Xy, 0)); int isecLayer = 0; for (int i = 0; i < steps; i++) { currentPos += rayStep; float layerDepth = HeightField.GetDepthBilinear(currentPos.Xy, 0); int indicator = GetRayLayerIndicator(currentPos.Z, layerDepth); if (layerDepth > 0) { // some data present // Find the first layer with indicator value 1. In case // of a single layer it is the single value. int indicatorDiff = prevIndicator - indicator; if (indicatorDiff == 1) { isecLayer = 1; } if (isecLayer != 0) { if (debugInfo != null) { debugInfo.LayerOfIntersection = isecLayer - 1; } return(new Intersection((Vector3d)currentPos)); // TODO: grab color from the particular color layer } } prevIndicator = indicator; } return(null); }
public MyIntersector(HeightField heightField) : base(heightField) { this.epsilonForCorners = 0.001f; this.epsilonForClosePixelDepth = 0.05f; }
public BinarySearchIntersector(HeightField heightField) : base(heightField) { }
public LinearSearchIntersector(HeightField heightField) : base(heightField) { Steps = 10; }
private static void IntersectAndReport(HeightField heightfield, Vector3 start, Vector3 end) { MyIntersector intersector = new MyIntersector(heightfield); Intersection intersection = intersector.Intersect(start, end); Console.WriteLine((intersection != null) ? intersection.Position.ToString() : "no intersection"); }
private static void TryIntersectionPerformance() { List<FloatMapImage> layers = new List<FloatMapImage>(); layers.Add(((Bitmap)Bitmap.FromFile("../../data/2011-05-30_04-50-47_depth_0.png")).ToFloatMap()); layers.Add(((Bitmap)Bitmap.FromFile("../../data/2011-05-30_04-50-47_depth_1.png")).ToFloatMap()); layers.Add(((Bitmap)Bitmap.FromFile("../../data/2011-05-30_04-50-47_depth_2.png")).ToFloatMap()); layers.Add(((Bitmap)Bitmap.FromFile("../../data/2011-05-30_04-50-47_depth_3.png")).ToFloatMap()); layers.Add(((Bitmap)Bitmap.FromFile("../../data/2011-05-30_04-50-47_depth_4.png")).ToFloatMap()); HeightField heightfield = new HeightField(layers); // no isec //Vector3 start = new Vector3(169, 181, 0); //Vector3 end = new Vector3(14, 191, 1); // isec at layer 4 //Vector3 start = new Vector3(178, 180, 0); //Vector3 end = new Vector3(33, 38, 1); // no isec with 5 layers, traversing the filled areas //Vector3 start = new Vector3(9, 190, 0); //Vector3 end = new Vector3(131, 19, 1); Vector3 start = new Vector3(100, 100, 0); Vector3 end = new Vector3(117.5f, 115.5f, 1); int iterations = 100000; MeasureIntersectionPerformance(heightfield, start, end, iterations); }
private void clearAllLayersToolStripMenuItem_Click(object sender, EventArgs e) { layerBitmaps.Clear(); layers.Clear(); heightField = emptyHeightField; UpdateHeightfieldPanel(); }
public AbstractIntersector(HeightField heightField) { this.HeightField = heightField; }
private static void TryFootprintTraversalPerformance() { //HeightField heightfield = new HeightField(1000, 1000); //Vector3 start = new Vector3(2.5, 1.5, 0); //Vector3 end = new Vector3(999.5f, 998.5f, 1); HeightField heightfield = new HeightField(200, 200); //Vector3 start = new Vector3(169, 181, 0); //Vector3 end = new Vector3(14, 191, 1); //Vector3 start = new Vector3(178, 180, 0); //Vector3 end = new Vector3(33, 38, 1); //Vector3 start = new Vector3(9, 190, 0); //Vector3 end = new Vector3(131, 19, 1); Vector3 start = new Vector3(100, 100, 0); Vector3 end = new Vector3(104.5f, 105.5f, 1); //HeightField heightfield = new HeightField(200, 200); //Vector3 start = new Vector3(100, 100.1, 0); //Vector3 end = new Vector3(102.1, 102.2, 1); int iterations = 100000; MeasureIntersectionPerformance(heightfield, start, end, iterations); }
private void addLayerToolStripMenuItem_Click(object sender, EventArgs e) { if (openFileDialog.ShowDialog() == DialogResult.OK) { foreach (var fileName in openFileDialog.FileNames) { Bitmap newLayerBitmap = (Bitmap)Bitmap.FromFile(fileName); layerBitmaps.Add(newLayerBitmap); layers.Add(newLayerBitmap.ToFloatMap()); } heightField = new HeightField(layers.ToArray()); selectedIntersector.HeightField = heightField; UpdateHeightfieldPanel(); } }