public Point3Df GetSubPixelValue(Point2Df pt) { int loX = (int)Math.Floor(pt.X); int loY = (int)Math.Floor(pt.Y); int hiX = loX + 1; int hiY = loY + 1; double hiXWeight = pt.X - loX; double hiYWeight = pt.Y - loY; double loXWeight = 1 - hiXWeight; double loYWeight = 1 - hiYWeight; Point3Df weightedPixelVal; // loXWeight and loYWeight will always be non-zero because of the relationship between // pt.X/Y and loX/Y. We check to make sure hiXWeight and hiYWeight are not zero to make // sure we don't wander out of the bounds of the image doing calculations weightedPixelVal = GetPixelValue(loX, loY) * loXWeight * loYWeight; if (hiXWeight != 0) { weightedPixelVal += GetPixelValue(hiX, loY) * hiXWeight * loYWeight; } if (hiYWeight != 0) { weightedPixelVal += GetPixelValue(loX, hiY) * loXWeight * hiYWeight; } if (hiXWeight != 0 && hiYWeight != 0) { weightedPixelVal += GetPixelValue(hiX, hiY) * hiXWeight * hiYWeight; } return(weightedPixelVal); }
public Scanline(SceneView source, SceneView target, Point2Df sourcePixel, double minDepth) { this.target = target; // Center of projection of the two scene views. The subtraction is in reverse order // because points translate in the direction opposite the COP shift Point2Df copDiff = (Point2Df)(source.CenterOfProjection - target.CenterOfProjection); // Distance to image plane double d = source.DistanceToImagePlane; Debug.Assert(d == target.DistanceToImagePlane); // Store d * copDiff for efficiency this.d_x_copDiff = d * copDiff; // The start point represents the maximum depth, which is infinity. Pixels at infinity // are at the same point in every perspective. this.start = sourcePixel; Point2Df end = new Point2Df(sourcePixel.X + d_x_copDiff.X / minDepth, sourcePixel.Y - d_x_copDiff.Y / minDepth); // Get the entire step from start to end this.step = end - start; // Scale the step so that it steps by one unit at a time either horizontally // or vertically, whichever results in the fewest steps. This limits the // resolution of the step to pixels. We don't have to worry about step being (0, 0) // because end and start will never be colocated. Store the divisor so we can check // against it while we're stepping. this.maxSteps = Math.Max(Math.Abs(step.X), Math.Abs(step.Y)); this.step /= maxSteps; prevMinDepth = DepthEstimator.Constants.InvalidDepth; }
// Assumes the passed point is on the image plane and converts it to a 2D point in the // top-left coordinate system of this view's image public Point2Df ConvertFromWorld(Point2Df worldLoc) { return(new Point2Df(worldLoc.X + (double)(Image.Width - 1) / 2, (double)(Image.Height - 1) / 2 - worldLoc.Y)); }
public Point2Df ConvertToWorld2D(Point2Df imageLoc) { return(new Point2Df(imageLoc.X - (double)(Image.Width - 1) / 2, (double)(Image.Height - 1) / 2 - imageLoc.Y)); }
// CHECKME add version of this method that returns a Point2Df so we don't have to cast? // Converts the passed image location in a top-left coordinate system to the equivalent // world coordinates public Point3Df ConvertToWorld3D(Point2Df imageLoc) { return(new Point3Df(ConvertToWorld2D(imageLoc), DistanceToImagePlane)); }
public Point3Df(double x, double y, double z) { this.xy = new Point2Df(x, y); this.z = z; }
public Point3Df(Point2Df xy, double z) : this(xy.X, xy.Y, z) { }
public double Distance(Point2Df other) { return(Math.Sqrt(Math.Pow(this.x - other.x, 2) + Math.Pow(this.y - other.y, 2))); }
public bool ContainsLoose(Point2Df pt) { return((pt.X > -0.5) && (pt.Y > -0.5) && (pt.X < this.Width - 0.5) && (pt.Y < this.Height - 0.5)); }
public bool Contains(Point2Df pt) { return((pt.X >= 0) && (pt.Y >= 0) && (pt.X < this.Width - 1) && (pt.Y < this.Height - 1)); }