예제 #1
0
        /// <summary>
        /// Transforms a ray by a given matrix.
        /// </summary>
        public static Ray Transform(Ray ray, Matrix transform)
        {
            EPoint p1 = transform.Transform(ray.Origin);
            EPoint p2 = transform.Transform(ray.Origin + ray.Direction);

            return(new Ray(p1, p2 - p1));
        }
예제 #2
0
 /// <summary>
 /// Creates a translation matrix.
 /// </summary>
 /// <param name="vec">The point to become the origin.</param>
 public static Matrix Translation(EPoint pt)
 {
     return(new Matrix(new EVector(1, 0, 0),
                       new EVector(0, 1, 0),
                       new EVector(0, 0, 1),
                       pt.ToVector()));
 }
예제 #3
0
        public static List <int> OcclusionHits4(Scene <Model> scene, List <Rhino.Geometry.Point3d> pts, List <Rhino.Geometry.Vector3d> viewVectors, bool reverseView = false)
        {
            int   ray_packet_size = 4;
            float tnear           = 0.01F;
            int   ptCount         = pts.Count;
            int   viewCount       = viewVectors.Count;
            var   hitCount        = new List <int>(new int[ptCount]); // initialzie with zeros
            var   EViews          = new List <EVector>();

            bool[] hits = null;

            foreach (var v in viewVectors)
            {
                if (reverseView)
                {
                    v.Reverse();
                }
                EViews.Add(new EVector(v.X, v.Y, v.Z));
            }

            int ray_padding = (ray_packet_size - (viewCount % ray_packet_size)) % 4;

            for (int i = 0; i < ray_padding; i++)
            {
                EViews.Add(new EVector(0, 0, -1));
            }


            Parallel.For(0, ptCount,
                         idx =>
            {
                var p             = pts[idx];
                var ePt           = new EPoint(p.X, p.Y, p.Z);
                int processedRays = 0;
                for (int i = 0; i < viewCount; i += ray_packet_size)
                {
                    var rays = new Ray[]
                    {
                        new Ray(ePt, EViews[i]),
                        new Ray(ePt, EViews[i + 1]),
                        new Ray(ePt, EViews[i + 2]),
                        new Ray(ePt, EViews[i + 3])
                    };
                    hits = scene.Occludes4(rays, tnear);
                    foreach (var hit in hits)
                    {
                        processedRays++;
                        if (processedRays > viewCount)
                        {
                            break;
                        }
                        if (hit)
                        {
                            hitCount[idx]++;
                        }
                    }
                }
            });
            return(hitCount);
        }
예제 #4
0
        public static List <int> OcclusionHits(Scene <Model> scene, List <Rhino.Geometry.Point3d> pts, List <Rhino.Geometry.Vector3d> viewVectors, bool reverseView = false)
        {
            int   ptCount  = pts.Count;
            var   hitCount = new List <int>(new int[ptCount]); // initialzie with zeros
            var   Eviews   = new List <EVector>();
            float tnear    = 0.01F;

            foreach (var v in viewVectors)
            {
                if (reverseView)
                {
                    v.Reverse();
                }
                Eviews.Add(new EVector(v.X, v.Y, v.Z));
            }

            Parallel.For(0, ptCount,
                         idx =>
            {
                // int hits = 0;
                var p   = pts[idx];
                var ePt = new EPoint(p.X, p.Y, p.Z);
                foreach (var v in Eviews)
                {
                    bool hit = scene.Occludes(new Ray(ePt, v), tnear);
                    if (hit)
                    {
                        hitCount[idx]++;
                    }
                }
            });

            return(hitCount);
        }
예제 #5
0
        private static Tuple <Ray, float> RayFromVertices(Point3f a, Point3f b)
        {
            EPoint  pt  = new EPoint(a.X, a.Y, a.Z);
            EVector vec = new EVector(b.X - a.X, b.Y - a.Y, b.Z - a.Z);
            Ray     ray = new Ray(pt, vec);
            float   mag = EVector.Length(vec);

            return(new Tuple <Ray, float>(ray, mag));
        }
예제 #6
0
 /// <summary>
 /// Transforms a point by this matrix.
 /// </summary>
 public EPoint Transform(EPoint pt)
 {
     return(Transform(this, pt));
 }
예제 #7
0
 /// <summary>
 /// Transforms a point by a matrix.
 /// </summary>
 public static EPoint Transform(Matrix mat, EPoint pt)
 {
     return((pt.X * mat.U + pt.Y * mat.V + pt.Z * mat.W).ToPoint() + mat.T);
 }
예제 #8
0
 /// <summary>
 /// Constructs a ray with an origin and a direction.
 /// </summary>
 public Ray(EPoint origin, EVector direction)
 {
     this.origin    = origin;
     this.direction = direction.Normalize();
 }
예제 #9
0
 /// <summary>
 /// Converts a point into a vector.
 /// </summary>
 /// <remarks>
 /// This is meaningless mathematically.
 /// </remarks>
 public static EVector ToVector(EPoint p)
 {
     return(p - EPoint.Zero);
 }