Exemplo n.º 1
0
        /// <summary>
        /// </summary>
        public bool Intersects(Box3d box, Func <V2d[], IMask2d> create)
        {
            try
            {
                var cs3 = box.ComputeCorners().Map(c => m_model2mask.Forward.TransformPosProj(c));
                if (cs3.All(c => c.Z < 0.0))
                {
                    return(false);
                }
                if (cs3.Any(c => c.Z < 0.0))
                {
                    return(true);
                }
                var cs      = cs3.Map(c => c.XY);
                var outline = create(new[] { cs[0], cs[2], cs[3], cs[1] })
                              .Or(create(new[] { cs[0], cs[4], cs[5], cs[1] }))
                              .Or(create(new[] { cs[1], cs[5], cs[7], cs[3] }))
                              .Or(create(new[] { cs[3], cs[7], cs[6], cs[2] }))
                              .Or(create(new[] { cs[2], cs[6], cs[4], cs[0] }))
                              .Or(create(new[] { cs[4], cs[6], cs[7], cs[5] }))
                ;
                var r = outline.And(m_mask);

                return(!r.IsEmpty);
            }
            catch
            {
                return(false);
            }
        }
        /// <summary>
        /// Returns points inside view frustum (defined by viewProjection and canonicalViewVolume).
        /// </summary>
        public static IEnumerable <Chunk> QueryPointsInViewFrustum(
            this PointSet self, M44d viewProjection, Box3d canonicalViewVolume
            )
        {
            var t    = viewProjection.Inverse;
            var cs   = canonicalViewVolume.ComputeCorners().Map(t.TransformPosProj);
            var hull = new Hull3d(new[]
            {
                new Plane3d(cs[0], cs[2], cs[1]), // near
                new Plane3d(cs[5], cs[7], cs[4]), // far
                new Plane3d(cs[0], cs[1], cs[4]), // bottom
                new Plane3d(cs[1], cs[3], cs[5]), // left
                new Plane3d(cs[4], cs[6], cs[0]), // right
                new Plane3d(cs[3], cs[2], cs[7]), // top
            });

            return(QueryPointsInsideConvexHull(self, hull));
        }
 /// <summary></summary>
 public bool IsFullyInside(Box3d box)
 {
     return(box.ComputeCorners().TrueForAll(Contains));
 }