www.pudn.com > QuadTreeLOD4cs.rar > Bit.cpp, change:2006-06-12,size:1164b
// Bit.cpp: implementation of the CBit class.
//
//////////////////////////////////////////////////////////////////////
#include "Bit.h"
#include <memory.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CBit::CBit()
{
m_pBits = 0;
m_nSclae = 1;
}
CBit::~CBit()
{
if(m_pBits)
delete []m_pBits;
}
// x±ØÐëÊÇ8µÄ±¶Êý
bool CBit::Create(int nXBits,int nZRows)
{
m_nXBytes = nXBits/8+1;
m_nZRows = nZRows;
// if(m_nXBits%8!=0)return false;
m_pBits = new unsigned char[m_nXBytes*m_nZRows];
memset(m_pBits,0,m_nXBytes*m_nZRows);
return true;
}
void CBit::Reset()
{
memset(m_pBits,0,m_nXBytes*m_nZRows);
}
bool CBit::IsTrue(int x,int y)
{
x = x/m_nSclae;
y = y/m_nSclae;
unsigned char c = m_pBits[m_nXBytes*y+x/8];
c = c<<(x%8);
return c&0x80;
}
void CBit::Set(int x, int y,bool bFlag)
{
x = x/m_nSclae;
y = y/m_nSclae;
unsigned char &c = m_pBits[m_nXBytes*y+x/8];
unsigned char d = 0x80;
d = d >>(x%8);
if(bFlag)
{
c |=d;
}
else
{
d =~d;
c &=d;
}
}