GEL  2
GEL is a library for Geometry and Linear Algebra
/Users/jab/Documents/Teaching/02585/GEL2_and_demos/GEL/src/CGLA/BitMask.h
00001 #ifndef __CGLA__BITMASK_H__
00002 #define __CGLA__BITMASK_H__
00003 
00004 #include "Vec3i.h"
00005 
00006 namespace CGLA
00007 {
00008         const int MASKS[33] = 
00009                 {
00010                         0x00000000,
00011                         0x00000001,
00012                         0x00000003,
00013                         0x00000007,
00014                         0x0000000f,
00015                         0x0000001f,
00016                         0x0000003f,
00017                         0x0000007f,
00018                         0x000000ff,
00019                         0x000001ff,
00020                         0x000003ff,
00021                         0x000007ff,
00022                         0x00000fff,
00023                         0x00001fff,
00024                         0x00003fff,
00025                         0x00007fff,
00026                         0x0000ffff,
00027                         0x0001ffff,
00028                         0x0003ffff,
00029                         0x0007ffff,
00030                         0x000fffff,
00031                         0x001fffff,
00032                         0x003fffff,
00033                         0x007fffff,
00034                         0x00ffffff,
00035                         0x01ffffff,
00036                         0x03ffffff,
00037                         0x07ffffff,
00038                         0x0fffffff,
00039                         0x1fffffff,
00040                         0x3fffffff,
00041                         0x7fffffff,
00042                         0xffffffff
00043                 };
00044 
00050         class BitMask
00051         {
00052                 int fb, lb, bdiff;
00053                 int msk;
00054 
00055         public:
00056 
00059                 BitMask(int _fb, int _lb):
00060                         fb(_fb), lb(_lb), 
00061                         bdiff(lb-fb+1), msk(MASKS[bdiff]<<fb)
00062                 {}
00063         
00065                 BitMask(int num):
00066                         fb(0),lb(two_to_what_power(num)-1), 
00067                         bdiff(lb-fb+1), msk(MASKS[bdiff]<<fb)
00068                 {}
00069         
00071                 BitMask():
00072                         fb(0), lb(15),
00073                         bdiff(lb-fb+1), msk(MASKS[bdiff]<<fb)
00074                 {}
00075 
00077                 int first_bit() const {return fb;} 
00078 
00080                 int last_bit() const {return lb;}
00081 
00083                 int no_bits() const {return bdiff;}
00084 
00086                 int mask(int var) const {return msk&var;}
00087                 
00090                 int mask_shift(int var) const {return (msk&var)>>fb;}
00091 
00093                 Vec3i mask(const Vec3i& v) const 
00094                 {
00095                         return Vec3i(mask(v[0]),mask(v[1]),mask(v[2]));
00096                 }
00097   
00099                 Vec3i maskshift(const Vec3i& v) const 
00100                 {
00101                         return Vec3i(mask_shift(v[0]),mask_shift(v[1]),mask_shift(v[2]));
00102                 }
00103   
00104         };
00105 
00106 }
00107 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations