![]() |
OpenNI 1.5.7
|
00001 /***************************************************************************** 00002 * * 00003 * OpenNI 1.x Alpha * 00004 * Copyright (C) 2012 PrimeSense Ltd. * 00005 * * 00006 * This file is part of OpenNI. * 00007 * * 00008 * Licensed under the Apache License, Version 2.0 (the "License"); * 00009 * you may not use this file except in compliance with the License. * 00010 * You may obtain a copy of the License at * 00011 * * 00012 * http://www.apache.org/licenses/LICENSE-2.0 * 00013 * * 00014 * Unless required by applicable law or agreed to in writing, software * 00015 * distributed under the License is distributed on an "AS IS" BASIS, * 00016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 00017 * See the License for the specific language governing permissions and * 00018 * limitations under the License. * 00019 * * 00020 *****************************************************************************/ 00021 #ifndef __XNBITSET_H__ 00022 #define __XNBITSET_H__ 00023 00024 #include <XnArray.h> 00025 00026 class XnBitSet 00027 { 00028 public: 00029 XnBitSet() : m_nSize(0) {} 00030 00033 XnStatus Reserve(XnUInt32 nBits) 00034 { 00035 return m_array.Reserve((nBits >> 5) + 1); 00036 } 00037 00039 XnStatus SetSize(XnUInt32 nBits) 00040 { 00041 return m_array.SetSize((nBits >> 5) + 1, 0); 00042 } 00043 00045 XnStatus Set(XnUInt32 nIndex, XnBool bValue) 00046 { 00047 XnUInt32 nArrayIndex = (nIndex >> 5); 00048 XnUInt32 nMask = (1 << ((~nIndex) & 0x1F)); 00049 XnUInt32 nOldVal = nArrayIndex < m_array.GetSize() ? m_array[nArrayIndex] : 0; 00050 XnUInt32 nNewVal = bValue ? (nOldVal | nMask) : (nOldVal & (~nMask)); 00051 XnStatus nRetVal = m_array.Set(nArrayIndex, nNewVal, 0); 00052 XN_IS_STATUS_OK(nRetVal); 00053 m_nSize = XN_MAX(m_nSize, nIndex + 1); 00054 return XN_STATUS_OK; 00055 } 00056 00058 XnBool IsSet(XnUInt32 nIndex) const 00059 { 00060 XnUInt32 nArrayIndex = (nIndex >> 5); 00061 if (nArrayIndex >= m_array.GetSize()) 00062 { 00063 return FALSE; 00064 } 00065 return (m_array[nArrayIndex] & (1 << ((~nIndex) & 0x1F))) ? TRUE : FALSE; 00066 } 00067 00069 XnStatus SetData(const XnUInt32* pData, XnUInt32 nSizeInDwords) 00070 { 00071 XnStatus nRetVal = m_array.SetData(pData, nSizeInDwords); 00072 XN_IS_STATUS_OK(nRetVal); 00073 m_nSize = (nSizeInDwords << 5); 00074 return XN_STATUS_OK; 00075 } 00076 00078 XnStatus SetDataBytes(const XnUInt8* pData, XnUInt32 nSizeInBytes) 00079 { 00080 //XnStatus nRetVal = m_array.SetData(reinterpret_cast<const XnUInt32*>(pData), XN_MAX(1, nSizeInBytes >> 2)); 00081 XnUInt32 nSizeInDwords = XN_MAX(1, nSizeInBytes >> 2); 00082 XnStatus nRetVal = m_array.SetSize(nSizeInDwords); 00083 XN_IS_STATUS_OK(nRetVal); 00084 for (XnUInt32 nDwordIdx = 0, nByteIdx = 0; nDwordIdx < nSizeInDwords; nDwordIdx++, nByteIdx += 4) 00085 { 00086 m_array[nDwordIdx] = ((pData[nByteIdx] << 24) | (pData[nByteIdx + 1] << 16) | (pData[nByteIdx + 2] << 8) | pData[nByteIdx + 3] ); 00087 } 00088 m_nSize = (nSizeInBytes << 3); 00089 return XN_STATUS_OK; 00090 } 00091 00093 const XnUInt32* GetData() const 00094 { 00095 return m_array.GetData(); 00096 } 00097 00099 XnUInt32* GetData() 00100 { 00101 return m_array.GetData(); 00102 } 00103 00105 XnUInt32 GetDataSize() const 00106 { 00107 return m_array.GetSize(); 00108 } 00109 00111 XnUInt32 GetSize() const 00112 { 00113 return m_nSize; 00114 } 00115 00117 void Clear() 00118 { 00119 m_array.Clear(); 00120 m_nSize = 0; 00121 } 00122 00124 XnBool IsEmpty() const 00125 { 00126 return m_array.IsEmpty(); 00127 } 00128 00129 private: 00130 XnArray<XnUInt32> m_array; 00131 XnUInt32 m_nSize; 00132 }; 00133 00134 #endif // __XNBITSET_H__