public static CompressedElement GuessUpperBits(this CompressedElement newcpos, CompressedElement oldcpos, ElementCrusher ec, BitCullingLevel bcl)
 {
     //var crusher = oldcpos.crusher;
     return(new CompressedElement(
                ec,
                ec.XCrusher.GuessUpperBits(newcpos[0], oldcpos[0], bcl),
                ec.YCrusher.GuessUpperBits(newcpos[1], oldcpos[1], bcl),
                ec.ZCrusher.GuessUpperBits(newcpos[2], oldcpos[2], bcl)
                ));
 }
        public static bool TestMatchingUpper(CompressedElement a, CompressedElement b, BitCullingLevel bcl)
        {
            ElementCrusher ec = a.crusher;

            return
                (
                TestMatchingUpper(a.cx, b.cx, ec.XCrusher.GetBits(bcl)) &&
                TestMatchingUpper(a.cy, b.cy, ec.YCrusher.GetBits(bcl)) &&
                TestMatchingUpper(a.cz, b.cz, ec.ZCrusher.GetBits(bcl))
                );
        }
 public static bool TestMatchingUpper(CompressedElement a, CompressedElement b, FloatCrusher[] ec, BitCullingLevel bcl)
 {
     return
         (
         TestMatchingUpper(a.cx, b.cx, ec[0].GetBitsAtCullLevel(bcl)) &&
         TestMatchingUpper(a.cy, b.cy, ec[1].GetBitsAtCullLevel(bcl)) &&
         TestMatchingUpper(a.cz, b.cz, ec[2].GetBitsAtCullLevel(bcl))
         );
 }
Beispiel #4
0
        /// <summary>
        /// Return the smallest bit culling level that will be able to communicate the changes between two compressed elements.
        /// </summary>
        public static BitCullingLevel FindBestBitCullLevel(CompressedElement prev, CompressedElement next, FloatRange[] ar, BitCullingLevel maxCulling)
        {
            if (maxCulling == BitCullingLevel.NoCulling || !TestMatchingUpper(prev, next, ar, BitCullingLevel.DropThird))
            {
                return(BitCullingLevel.NoCulling);
            }

            if (maxCulling == BitCullingLevel.DropThird || !TestMatchingUpper(prev, next, ar, BitCullingLevel.DropHalf))
            {
                return(BitCullingLevel.DropThird);
            }

            if (maxCulling == BitCullingLevel.DropHalf || prev != next)
            {
                return(BitCullingLevel.DropHalf);
            }

            // both values are the same
            return(BitCullingLevel.DropAll);
        }
        public static BitCullingLevel FindBestBitCullLevel(CompressedElement a, CompressedElement b, FloatCrusher[] ec, BitCullingLevel maxCulling)
        {
            if (maxCulling == BitCullingLevel.NoCulling || !TestMatchingUpper(a, b, ec, BitCullingLevel.DropThird))
            {
                return(BitCullingLevel.NoCulling);
            }

            if (maxCulling == BitCullingLevel.DropThird || !TestMatchingUpper(a, b, ec, BitCullingLevel.DropHalf))
            {
                return(BitCullingLevel.DropThird);
            }

            if (maxCulling == BitCullingLevel.DropHalf || !TestMatchingUpper(a, b, ec, BitCullingLevel.DropAll))
            {
                return(BitCullingLevel.DropHalf);
            }

            // both values are the same
            return(BitCullingLevel.DropAll);
        }
 public static CompressedElement ZeroLowerBits(this CompressedElement fullpos, ElementCrusher ec, BitCullingLevel bcl)
 {
     return(new CompressedElement(
                ec,          //fullpos.crusher,
                ec[0].ZeroLowerBits(fullpos.cx, bcl),
                ec[1].ZeroLowerBits(fullpos.cy, bcl),
                ec[2].ZeroLowerBits(fullpos.cz, bcl)
                ));
 }
        public static CompressedFloat Write(this FloatCrusher fc, uint c, ref Bitstream bitstream, BitCullingLevel bcl = BitCullingLevel.NoCulling)
        {
            int bits = fc._bits[(int)bcl];

            bitstream.Write(c, bits);
            return(new CompressedFloat(fc, c));
        }
Beispiel #8
0
 public uint ZeroUpperBits(uint val, BitCullingLevel level = BitCullingLevel.DropTopThird)
 {
     return(val & maxValue[BitsAtCullingLevel(level)]);
 }
 public void Serialize(byte[] buffer, ref int bitposition, IncludedAxes ia, BitCullingLevel bcl = BitCullingLevel.NoCulling)
 {
     crusher.Write(this, buffer, ref bitposition, ia, bcl);
 }
Beispiel #10
0
 public static CompressedElement ZeroUpperBits(this CompressedElement fullpos, FloatRange[] ranges, BitCullingLevel bcl)
 {
     return(new CompressedElement(
                ranges[0].ZeroUpperBits(fullpos.x, bcl),
                ranges[1].ZeroUpperBits(fullpos.y, bcl),
                ranges[2].ZeroUpperBits(fullpos.z, bcl)
                ));
 }
Beispiel #11
0
        public uint ZeroLowerBits(uint val, BitCullingLevel level = BitCullingLevel.DropTopThird)
        {
            int shift = BitsAtCullingLevel(level);

            return((val >> shift) << shift);
        }
Beispiel #12
0
 /// <summary>
 /// Replace the upperbits of the first compressed element with the upper bits of the second, using BitCullingLevel as the separation point.
 /// </summary>
 public static CompressedElement OverwriteUpperBits(this CompressedElement low, CompressedElement up, FloatRange[] ranges, BitCullingLevel bcl)
 {
     return(new CompressedElement(
                ranges[0].OverwriteUpperBits(low.x, up.x, bcl),
                ranges[1].OverwriteUpperBits(low.y, up.y, bcl),
                ranges[2].OverwriteUpperBits(low.z, up.z, bcl)
                ));
 }
Beispiel #13
0
 /// <summary>
 /// Alternative to OverwriteUpperBits that attempts to guess the upperbits by seeing if each axis of the new position would be
 /// closer to the old one if the upper bit is incremented by one, two, three etc. Stops trying when it fails to get a better result.
 /// </summary>
 /// <param name="oldcpos">Last best position test against.</param>
 /// <returns>Returns a corrected CompressPos</returns>
 public static CompressedElement GuessUpperBits(this CompressedElement newcpos, CompressedElement oldcpos, FloatRange[] axesranges, BitCullingLevel bcl)
 {
     return(new CompressedElement(
                axesranges[0].GuessUpperBits(newcpos[0], oldcpos[0], bcl),
                axesranges[1].GuessUpperBits(newcpos[1], oldcpos[1], bcl),
                axesranges[2].GuessUpperBits(newcpos[2], oldcpos[2], bcl)
                ));
 }
Beispiel #14
0
 public static bool TestMatchingUpper(CompressedElement prevPos, CompressedElement b, FloatRange[] ar, BitCullingLevel bcl)
 {
     return
         (
         TestMatchingUpper(prevPos.x, b.x, ar[0].BitsAtCullLevel(bcl)) &&
         TestMatchingUpper(prevPos.y, b.y, ar[1].BitsAtCullLevel(bcl)) &&
         TestMatchingUpper(prevPos.z, b.z, ar[2].BitsAtCullLevel(bcl))
         );
 }
        //public static CompressedElement GuessUpperBits(this CompressedElement newcpos, CompressedElement oldcpos, FloatCrusher[] ec, BitCullingLevel bcl)
        //{
        //	var crusher = oldcpos.crusher;
        //	return new CompressedElement(
        //		crusher,
        //		new CompressedValue(crusher.xcrusher, ec[0].GuessUpperBits(newcpos.cx, oldcpos.cx, bcl), crusher.xcrusher.GetBits(bcl)),
        //		new CompressedValue(crusher.ycrusher, ec[1].GuessUpperBits(newcpos.cx, oldcpos.cx, bcl), crusher.xcrusher.GetBits(bcl)),
        //		new CompressedValue(crusher.zcrusher, ec[2].GuessUpperBits(newcpos.cx, oldcpos.cx, bcl), crusher.xcrusher.GetBits(bcl))
        //		);
        //}

        /// <summary>
        /// Replace the upperbits of the first compressed element with the upper bits of the second, using BitCullingLevel as the separation point.
        /// </summary>
        public static void OverwriteUpperBits(this CompressedElement low, CompressedElement uppers, BitCullingLevel bcl)
        {
            ElementCrusher ec = low.crusher;

            low.Set(
                ec,
                ec.XCrusher.OverwriteUpperBits(low.cx, uppers.cx, bcl),
                ec.YCrusher.OverwriteUpperBits(low.cy, uppers.cy, bcl),
                ec.ZCrusher.OverwriteUpperBits(low.cz, uppers.cz, bcl)
                );
        }
        /// <summary>
        /// Test changes between two compressed Vector3 elements and returns the ideal BitCullingLevel for that change, with the assumption
        /// that it will be recreated using best guess (process where the upperbits are incremented and deincremented until the closest position
        /// to compare positon is returned.
        /// NOT FULLY TESTED
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="maxCullLvl"></param>
        /// <returns></returns>
        public static BitCullingLevel GetGuessableBitCullLevel(CompressedElement a, CompressedElement b, BitCullingLevel maxCullLvl)
        {
            for (BitCullingLevel lvl = maxCullLvl; lvl > 0; lvl--)
            {
                a.ZeroLowerBits(uppers, lvl);
                b.ZeroUpperBits(lowers, lvl);

                if ((uppers.cx | lowers.cx) == b.cx &&
                    (uppers.cy | lowers.cy) == b.cy &&
                    (uppers.cz | lowers.cz) == b.cz)
                {
                    return(lvl);
                }
            }
            return(BitCullingLevel.NoCulling);
        }
 public static CompressedElement OverwriteUpperBits(this CompressedElement low, CompressedElement up, ElementCrusher ec, BitCullingLevel bcl)
 {
     return(new CompressedElement(
                ec,
                ec[0].OverwriteUpperBits(low.cx, up.cx, bcl),
                ec[1].OverwriteUpperBits(low.cy, up.cy, bcl),
                ec[2].OverwriteUpperBits(low.cz, up.cz, bcl)
                ));
 }
        public static BitCullingLevel GetGuessableBitCullLevel(CompressedElement oldComp, CompressedElement newComp, ElementCrusher ec, BitCullingLevel maxCullLvl)
        {
            for (BitCullingLevel lvl = maxCullLvl; lvl > 0; lvl--)
            {
                oldComp.ZeroLowerBits(uppers, lvl);
                newComp.ZeroUpperBits(lowers, lvl);

                if ((uppers.cx | lowers.cx) == newComp.cx &&
                    (uppers.cy | lowers.cy) == newComp.cy &&
                    (uppers.cz | lowers.cz) == newComp.cz)
                {
                    return(lvl);
                }
            }
            return(BitCullingLevel.NoCulling);
        }
        //public static CompressedElement ZeroLowerBits(this CompressedElement fullpos, FloatCrusher[] ec, BitCullingLevel bcl)
        //{
        //	return new CompressedElement(
        //		fullpos.crusher,
        //		ec[0].ZeroLowerBits(fullpos.cx, bcl),
        //		ec[1].ZeroLowerBits(fullpos.cy, bcl),
        //		ec[2].ZeroLowerBits(fullpos.cz, bcl)
        //		);
        //}
        public static void ZeroUpperBits(this CompressedElement fullpos, CompressedElement target, BitCullingLevel bcl)
        {
            ElementCrusher ec = fullpos.crusher;

            target.Set(
                ec,                 /*fullpos.crusher,*/
                ec.XCrusher.ZeroUpperBits(fullpos.cx, bcl),
                ec.YCrusher.ZeroUpperBits(fullpos.cy, bcl),
                ec.ZCrusher.ZeroUpperBits(fullpos.cz, bcl)
                );
        }
        public static BitCullingLevel FindBestBitCullLevel(CompressedElement a, CompressedElement b, ElementCrusher ec, BitCullingLevel maxCulling)
        {
            /// Quats can't cull upper bits, so its an all or nothing. Either the bits match or they don't
            if (ec.TRSType == TRSType.Quaternion)
            {
                if ((ulong)a.cQuat == (ulong)b.cQuat)
                {
                    return(BitCullingLevel.DropAll);
                }
                else
                {
                    return(BitCullingLevel.NoCulling);
                }
            }

            if (maxCulling == BitCullingLevel.NoCulling || !TestMatchingUpper(a, b, ec, BitCullingLevel.DropThird))
            {
                return(BitCullingLevel.NoCulling);
            }

            if (maxCulling == BitCullingLevel.DropThird || !TestMatchingUpper(a, b, ec, BitCullingLevel.DropHalf))
            {
                return(BitCullingLevel.DropThird);
            }

            if (maxCulling == BitCullingLevel.DropHalf || !TestMatchingUpper(a, b, ec, BitCullingLevel.DropAll))
            {
                return(BitCullingLevel.DropHalf);
            }

            // both values are the same
            return(BitCullingLevel.DropAll);
        }
        public static CompressedFloat Read(this FloatCrusher fc, ref Bitstream bitstream, BitCullingLevel bcl = BitCullingLevel.NoCulling)
        {
            int bits = fc._bits[(int)bcl];

            return(new CompressedFloat(fc, (uint)bitstream.Read(bits)));
        }
Beispiel #22
0
 /// <summary>
 /// Test changes between two compressed Vector3 elements and return the ideal BitCullingLevel for that change.
 /// </summary>
 public static BitCullingLevel GetGuessableBitCullLevel(CompressedElement oldComp, CompressedElement newComp, FloatRange[] fr, BitCullingLevel maxCullLvl)
 {
     for (BitCullingLevel lvl = maxCullLvl; lvl > 0; lvl--)
     {
         // Starting guess is the new lower bits using the previous upperbits
         if (Compare(newComp, (oldComp.ZeroLowerBits(lvl) | newComp.ZeroUpperBits(lvl))))
         {
             return(lvl);
         }
     }
     return(BitCullingLevel.NoCulling);
 }