public void Accumulate(System.Drawing.Point pixel, Ray r, double t) {
   PerPixel pp = _grid[pixel];
   if (pp == null) {
     pp = new PerPixel(_max_entries, r, t);
     _grid[pixel] = pp;
   } else {
     pp.Add(t);
   }
 }
 /// <summary>
 /// Ray/Plane intersection
 /// </summary>
 /// <param name="r">Ray</param>
 /// <param name="p">Plane</param>
 /// <param name="t">Parametric t</param>
 /// <returns></returns>
 public static bool RayPlane(Ray r, Plane p, out double t) {
   // http://www.siggraph.org/education/materials/HyperGraph/raytrace/rayplane_intersection.htm
   double denom = Vector.ScalarProduct(p.Normal, r.Direction);
   if (Math.Abs(denom) > 1e-10) {
     // Since the ray passes through the origin, the intersection calculation can
     // be greatly simplified.
     t = -p.D / denom;
     return true;
   } else {
     t = Double.MaxValue;
     return false;
   }
 }
    /// <summary>
    /// Find best intersection of eye-rays and reference planes.
    /// </summary>
    /// <remarks>Best is defined as the the plane with the shortest distance</remarks>
    /// <param name="eye_rays">Eye-rays</param>
    /// <param name="planes">Calibrated reference planes</param>
    /// <param name="isect_t">Parametric ray intersection distance</param>
    /// <param name="isect_p">Intersection points (optional).</param>
    public static void FindEyeRayPlaneIntersections(Ray[] eye_rays, Plane[] planes, out double[] isect_t, out Vector[] isect_p, out int[] isect_plane_ids) {
      isect_t = new double[eye_rays.Length];
      isect_p = new Vector[eye_rays.Length];
      isect_plane_ids = new int[eye_rays.Length];

      for (int i = 0; i < eye_rays.Length; ++i) {
        Ray r = eye_rays[i];
        double t = Double.MaxValue;
        int id = -1;
        for (int p = 0; p < planes.Length; ++p) {
          double this_t;
          Intersection.RayPlane(r, planes[p], out this_t);
          if (this_t < t) {
            t = this_t;
            id = p;
          } 
        }
        isect_t[i] = t;
        isect_p[i] = r.At(t);
        isect_plane_ids[i] = id;
      }
    }
Exemple #4
0
    /// <summary>
    /// Construct eye-rays through the specified pixels
    /// </summary>
    /// <param name="icp">Intrinsic camera parameters</param>
    /// <param name="pixels">Pixels</param>
    /// <returns>Enumerable ray collection</returns>
    public static Ray[] EyeRays(Emgu.CV.IntrinsicCameraParameters icp, PointF[] pixels) {
      Ray[] rays = new Ray[pixels.Length];
      if (pixels.Length > 0) {
        // 1. Undistort pixels
        PointF[] undistorted_pixels = icp.Undistort(pixels, null, icp.IntrinsicMatrix);
        // 2. Create rays
        // Use inverse intrinsic calibration and depth = 1
        double cx = icp.IntrinsicMatrix.Data[0, 2];
        double cy = icp.IntrinsicMatrix.Data[1, 2];
        double fx = icp.IntrinsicMatrix.Data[0, 0];
        double fy = icp.IntrinsicMatrix.Data[1, 1];


        Vector direction = new Vector(3);
        for (int i = 0; i < undistorted_pixels.Length; ++i) {
          PointF pixel = undistorted_pixels[i];
          direction[0] = (pixel.X - cx) / fx;
          direction[1] = (pixel.Y - cy) / fy;
          direction[2] = 1;
          rays[i] = new Ray(direction.Normalize());
        }
      }
      return rays;
    }
 /// <summary>
 /// Construct from capacity and first entry
 /// </summary>
 /// <param name="capacity"></param>
 /// <param name="first"></param>
 public PerPixel(int capacity, Ray r, double t) {
   _ts = new List<double>(capacity);
   _ts.Add(t);
   _r = r;
 }
 /// <summary>
 /// Construct PerPixel from first entry:
 /// Since this the first t-value is passed to the constructor,
 /// t_mean is set to t.
 /// </summary>
 /// <param name="first"></param>
 public PerPixel(Ray r, double t) {
   _tmean = t;
   _r = r;
   _t_count = 1;
 }
Exemple #7
0
 public void At() {
   Ray r = new Ray(MakeVector(1, 0, 0));
   Assert.AreEqual(0, (MakeVector(1, 0, 0) - r.At(1)).Norm(), 0.00001);
   Assert.AreEqual(0, (MakeVector(5, 0, 0) - r.At(5)).Norm(), 0.00001);
 }
Exemple #8
0
 public void Construction() {
   Ray r = new Ray(MakeVector(1, 0, 0));
   Assert.AreEqual(0, (MakeVector(1, 0, 0) - r.Direction).Norm(), 0.0001);
 }