MCPcopy Create free account
hub / github.com/OpenNI/OpenNI / FillTexture

Method FillTexture

Samples/NiUserSelection/UserTracker.cpp:215–271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

213}
214
215void UserTracker::FillTexture(unsigned char* pTexBuf, XnUInt16 nTexWidth, XnUInt16 /*nTexHeight*/, XnBool bDrawBackground)
216{
217 // get the size of the depth map and its pixels.
218 XnUInt16 xRes,yRes;
219 GetImageRes(xRes, yRes);
220 const XnDepthPixel* pDepth = GetDepthData(); // holds the depth map, i.e. the depth for each pixel
221
222 CalcHistogram(pDepth, xRes, yRes);
223
224 XnDepthPixel nValue; // will hold temporary pixel values.
225
226 const XnLabel* pLabels = GetUsersPixelsData(); // holds a label map, i.e. the label (user ID) for each pixel
227
228 // Prepare the texture map, i.e. go over all relevant elements and set their value based
229 // on the depth and user.
230 // NOTE: we go over the original map and the assumption is that the texture size is equal or larger
231 // to the depth map resolution and that anything larger (e.g. because we increase to the closest,
232 // larger power of two) is not changed (therefore will remain whatever color was set before which
233 // in the initialization is probably 0).
234 for (XnUInt16 nY=0; nY<yRes; nY++)
235 {
236 for (XnUInt16 nX=0; nX < xRes; nX++)
237 {
238 // init to 0 (just in case we don't have better data.
239 pTexBuf[0] = 0;
240 pTexBuf[1] = 0;
241 pTexBuf[2] = 0;
242 // if pLabels is 0 it is background. Therefore we only set the color of the background
243 // if bDrawBackground is true.
244 if (bDrawBackground || *pLabels != 0)
245 {
246 nValue = *pDepth; // the depth of the current pixel
247 XnLabel label = *pLabels; // the label of the current pixel
248 XnUInt32 nColorID = label % s_nColors; // the color for the current label
249 if (label == 0)
250 {
251 nColorID = s_nColors; // special background color
252 }
253
254 if (nValue != 0)
255 {
256 XnFloat newValue = s_pDepthHist[nValue]; // translate to the multiplier from the histogram
257
258 pTexBuf[0] = (unsigned char)(newValue * s_Colors[nColorID][0]);
259 pTexBuf[1] = (unsigned char)(newValue * s_Colors[nColorID][1]);
260 pTexBuf[2] = (unsigned char)(newValue * s_Colors[nColorID][2]);
261 }
262 }
263
264 pDepth++;
265 pLabels++;
266 pTexBuf+=3; // each element is RGB so we move 3 at a time.
267 }
268
269 pTexBuf += (nTexWidth - xRes) *3; // move to the next line
270 }
271}
272

Callers 1

DrawDepthMapTextureMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected