protected void ScanTriangleLine(Plane plane, int y, float x1, float x2, Candidate candidate) { var startX = (int)Math.Ceiling(Math.Min(x1, x2)); var endX = (int)Math.Floor(Math.Max(x1, x2)); if (startX > endX) { return; } var z0 = plane[startX, y]; var dz = plane.A; for (var x = startX; x <= endX; x++) { if (PointStates[x, y] != PointState.Used) { var z = HeightMap[x, y]; var diff = Math.Abs(z - z0); candidate.Consider(x, y, diff); } z0 += dz; } }
public void ScanTriangle(TrackedTriangle tri) { var zPlane = new Plane(); ComputePlane(zPlane, tri, HeightMap); var vecArray = new[] { tri.Point1, tri.Point2, tri.Point3 }; Array.Sort(vecArray, new Vector2TriangleComparer()); var x1 = vecArray[0].X; var x2 = vecArray[0].X; var dx1 = (vecArray[1].X - vecArray[0].X) / (vecArray[1].Y - vecArray[0].Y); var dx2 = (vecArray[2].X - vecArray[0].X) / (vecArray[2].Y - vecArray[0].Y); var startY = (int)vecArray[0].Y; var endY = (int)vecArray[1].Y; var candidate = new Candidate(); for (var y = startY; y < endY; y++) { ScanTriangleLine(zPlane, y, x1, x2, candidate); x1 += dx1; x2 += dx2; } dx1 = (vecArray[2].X - vecArray[1].X) / (vecArray[2].Y - vecArray[1].Y); x1 = vecArray[1].X; startY = (int)vecArray[1].Y; endY = (int)vecArray[2].Y; for (var y = startY; y < endY; y++) { ScanTriangleLine(zPlane, y, x1, x2, candidate); x1 += dx1; x2 += dx2; } if (candidate.Importance < 1e-4f) { if (tri.Token != Heap.NOT_IN_HEAP) { heap.Kill(tri.Token); } tri.SetCandidate(-69, -69, 0.0f); return; } Debug.Assert(PointStates[candidate.X, candidate.Y] == PointState.Unused); tri.SetCandidate(candidate.X, candidate.Y, candidate.Importance); if (tri.Token == Heap.NOT_IN_HEAP) { heap.Insert(tri, candidate.Importance); } else { heap.Update(tri, candidate.Importance); } }
public float Eval(int x, int y) { var point = new Vector2(x, y); var tri = Locate(point).LFace; var zPlane = new Plane(); ComputePlane(zPlane, tri, HeightMap); return zPlane[x, y]; }
public float Eval(int x, int y) { var point = new Vector2(x, y); var tri = Locate(point).LFace; var zPlane = new Plane(); ComputePlane(zPlane, tri, HeightMap); return(zPlane[x, y]); }
protected void ComputePlane(Plane plane, Triangle tri, Map map) { var point1 = tri.Point1; var point2 = tri.Point2; var point3 = tri.Point3; var vec1 = new Vector3(point1, map[point1.X, point1.Y]); var vec2 = new Vector3(point2, map[point2.X, point2.Y]); var vec3 = new Vector3(point3, map[point3.X, point3.Y]); plane.Init(vec1, vec2, vec3); }
protected void ScanTriangleLine(Plane plane, int y, float x1, float x2, Candidate candidate) { var startX = (int) Math.Ceiling(Math.Min(x1, x2)); var endX = (int) Math.Floor(Math.Max(x1, x2)); if (startX > endX) return; var z0 = plane[startX, y]; var dz = plane.A; for (var x = startX; x <= endX; x++) { if (PointStates[x, y] != PointState.Used) { var z = HeightMap[x, y]; var diff = Math.Abs(z - z0); candidate.Consider(x, y, diff); } z0 += dz; } }
protected void ComputePlane(Plane plane, LinkedListTriangle tri, Map map) { var point1 = tri.Point1; var point2 = tri.Point2; var point3 = tri.Point3; var vec1 = new Vector3(point1, map[point1.X, point1.Y]); var vec2 = new Vector3(point2, map[point2.X, point2.Y]); var vec3 = new Vector3(point3, map[point3.X, point3.Y]); plane.Init(vec1, vec2, vec3); }
public void ScanTriangle(TrackedTriangle tri) { var zPlane = new Plane(); ComputePlane(zPlane, tri, HeightMap); var vecArray = new[] {tri.Point1, tri.Point2, tri.Point3}; Array.Sort(vecArray, new Vector2TriangleComparer()); var x1 = vecArray[0].X; var x2 = vecArray[0].X; var dx1 = (vecArray[1].X - vecArray[0].X)/(vecArray[1].Y - vecArray[0].Y); var dx2 = (vecArray[2].X - vecArray[0].X)/(vecArray[2].Y - vecArray[0].Y); var startY = (int) vecArray[0].Y; var endY = (int) vecArray[1].Y; var candidate = new Candidate(); for(var y = startY; y < endY; y++) { ScanTriangleLine(zPlane, y, x1, x2, candidate); x1 += dx1; x2 += dx2; } dx1 = (vecArray[2].X - vecArray[1].X)/(vecArray[2].Y - vecArray[1].Y); x1 = vecArray[1].X; startY = (int) vecArray[1].Y; endY = (int) vecArray[2].Y; for (var y = startY; y < endY; y++) { ScanTriangleLine(zPlane, y, x1, x2, candidate); x1 += dx1; x2 += dx2; } if (candidate.Importance < 1e-4f) { if (tri.Token != Heap.NOT_IN_HEAP) { heap.Kill(tri.Token); } tri.SetCandidate(-69, -69, 0.0f); return; } Debug.Assert(PointStates[candidate.X, candidate.Y] == PointState.Unused); tri.SetCandidate(candidate.X, candidate.Y, candidate.Importance); if (tri.Token == Heap.NOT_IN_HEAP) { heap.Insert(tri, candidate.Importance); } else { heap.Update(tri, candidate.Importance); } }