void resetCropping(MapGenerator* pGenerator) { XnCropping crop; crop.bEnabled = FALSE; crop.nXOffset = crop.nYOffset = 0; crop.nXSize = crop.nYSize = 0; setStreamCropping(pGenerator, &crop); }
void drawCropStream(MapGenerator* pGenerator, IntRect location, IntRect selection, int dividedBy) { if (!pGenerator->IsCapabilitySupported(XN_CAPABILITY_CROPPING)) { return; } XnMapOutputMode Mode; pGenerator->GetMapOutputMode(Mode); // check if entire selection is in location if (selection.uLeft >= location.uLeft && selection.uRight <= location.uRight && selection.uBottom >= location.uBottom && selection.uTop <= location.uTop) { IntRect cropRect; cropRect.uBottom = Mode.nYRes * (selection.uBottom - location.uBottom) / (location.uTop - location.uBottom); cropRect.uTop = Mode.nYRes * (selection.uTop - location.uBottom) / (location.uTop - location.uBottom); cropRect.uLeft = Mode.nXRes * (selection.uLeft - location.uLeft) / (location.uRight - location.uLeft); cropRect.uRight = Mode.nXRes * (selection.uRight - location.uLeft) / (location.uRight - location.uLeft); XnCropping cropping; cropping.bEnabled = TRUE; cropping.nXOffset = cropRect.uLeft; cropping.nYOffset = cropRect.uBottom; cropping.nXSize = cropRect.uRight - cropRect.uLeft; cropping.nYSize = cropRect.uTop - cropRect.uBottom; if ((cropping.nXOffset % dividedBy) != 0) cropping.nXOffset -= (cropping.nXOffset % dividedBy); if ((cropping.nXSize % dividedBy) != 0) cropping.nXSize += dividedBy - (cropping.nXSize % dividedBy); setStreamCropping(pGenerator, &cropping); } }
void drawCropStream(openni::VideoStream& stream, IntRect location, IntRect selection, int dividedBy) { if (!stream.isCroppingSupported()) { return; } openni::VideoMode Mode = stream.getVideoMode(); // check if entire selection is in location if (selection.uLeft >= location.uLeft && selection.uRight <= location.uRight && selection.uBottom >= location.uBottom && selection.uTop <= location.uTop) { IntRect cropRect; cropRect.uBottom = Mode.getResolutionY() * (selection.uBottom - location.uBottom) / (location.uTop - location.uBottom); cropRect.uTop = Mode.getResolutionY() * (selection.uTop - location.uBottom) / (location.uTop - location.uBottom); cropRect.uLeft = Mode.getResolutionX() * (selection.uLeft - location.uLeft) / (location.uRight - location.uLeft); cropRect.uRight = Mode.getResolutionX() * (selection.uRight - location.uLeft) / (location.uRight - location.uLeft); int originX, originY, width, height; originX = cropRect.uLeft; originY = cropRect.uBottom; width = cropRect.uRight - cropRect.uLeft; height = cropRect.uTop - cropRect.uBottom; if ((originX % dividedBy) != 0) originX -= (originX % dividedBy); if ((width % dividedBy) != 0) width += dividedBy - (width % dividedBy); setStreamCropping(stream, originX, originY, width, height); } }