public static void WriteSkeletonOverFrame(DepthSensorKinect2 sensor, VisTypes visType, SkeletonOfBody skeleton, int sizePoint, ref ushort[] buffDepth16) { // Draw joints pixels over the depth image switch (visType) { case VisTypes.Color: // Overwrite the points over the depth image in color space foreach (var pos in skeleton.jointColorSpace) { for (int m = -sizePoint; m <= sizePoint; m++) { for (int n = -sizePoint; n <= sizePoint; n++) { int posX = (int)pos.X + m; int posY = (int)pos.Y + n; if ((posX >= 0 && posX < sensor.ColorImageSize.Width) && (posY >= 0 && posY < sensor.ColorImageSize.Height)) { int indexDepth = posY * sensor.ColorImageSize.Width + posX; // Highlight the pixel buffDepth16[indexDepth] = 0xffff; } } } } break; case VisTypes.Depth: case VisTypes.Infrared: case VisTypes.BodyIndex: // Overwrite the points over the depth image in depth space foreach (var pos in skeleton.jointDepthSpace) { for (int m = -sizePoint; m <= sizePoint; m++) { for (int n = -sizePoint; n <= sizePoint; n++) { int posX = (int)pos.X + m; int posY = (int)pos.Y + n; if ((posX >= 0 && posX < sensor.DepthImageSize.Width) && (posY >= 0 && posY < sensor.DepthImageSize.Height)) { int indexDepth = posY * sensor.DepthImageSize.Width + posX; // Highlight the pixel buffDepth16[indexDepth] = 0xffff; } } } } break; case VisTypes.None: break; default: break; } }
public override void AddActionPreferencesToList(ConsideredActions alreadyConsidered, IList <string> log) { double storedVis = VisTypes.Sum(v => _mage.GetVisCount(v)); _visStillNeeded = AmountNeeded - storedVis; if (_visStillNeeded > 0) { // extract if (_vimSufficient) { if (!_auraCondition.ConditionFulfilled) { _auraCondition.AddActionPreferencesToList(alreadyConsidered, log); } else if (!_labCondition.ConditionFulfilled) { _labCondition.AddActionPreferencesToList(alreadyConsidered, log); } else { double currentDistillRate = _mage.GetVisDistillationRate(); double extractDesirability = GetDesirabilityOfVisGain(currentDistillRate, ConditionDepth); if (extractDesirability > 0.00001) { // we can get what we want in one season, go ahead and do it log.Add("Extracting vis worth " + extractDesirability.ToString("0.000")); alreadyConsidered.Add(new VisExtracting(Abilities.MagicTheory, extractDesirability)); if (currentDistillRate < _visStillNeeded) { // we are in the multi-season-to-fulfill scenario // the difference between the desire of starting now // and the desire of starting after gaining experience // is the effective value of raising skills double labTotal = _mage.GetLabTotal(MagicArtPairs.CrVi, Activity.DistillVis); LabTotalIncreaseHelper helper = new LabTotalIncreaseHelper(_mage, AgeToCompleteBy - 1, extractDesirability / labTotal, (ushort)(ConditionDepth + 1), MagicArtPairs.CrVi, false, GetDesirabilityOfLabTotalGain); helper.AddActionPreferencesToList(alreadyConsidered, log); } } } } // search for vis source FindVisSourceHelper visSourceHelper = new FindVisSourceHelper(_mage, VisTypes, AgeToCompleteBy - 1, Desire, (ushort)(ConditionDepth + 1), !_vimSufficient, GetDesirabilityOfVisGain); visSourceHelper.AddActionPreferencesToList(alreadyConsidered, log); // consider writing a book to trade for vis WritingHelper writingHelper = new WritingHelper(_mage, AgeToCompleteBy - 1, Desire, (ushort)(ConditionDepth + 1), GetDesirabilityOfVisGain); writingHelper.AddActionPreferencesToList(alreadyConsidered, log); } }
/// <summary> /// Converts the specified 3D CameraSpacePoint into a 2D ImageSpacePoint. /// </summary> /// <param name="visType">The type of the conversion (color, depth, infrared, or bodyindex).</param> /// <param name="position3D">The CameraSpacePoint to convert.</param> /// <param name="coordinateMapper">The CoordinateMapper to make the conversion.</param> /// <returns>The corresponding 2D integer point.</returns> public static Point ToPoint(CoordinateMapper coordinateMapper, VisTypes visType, CameraSpacePoint position3D) { //System.Drawing. Point point = new Point(0, 0); switch (visType) { case VisTypes.Color: { // SDK Coordinate mapping ColorSpacePoint colorPoint = coordinateMapper.MapCameraPointToColorSpace(position3D); // The sentinel value is (-Inf, -Inf), meaning that no depth pixel corresponds to this color pixel. point.X = float.IsNegativeInfinity(colorPoint.X) ? 0 : (int)(colorPoint.X + 0.5f); point.Y = float.IsNegativeInfinity(colorPoint.Y) ? 0 : (int)(colorPoint.Y + 0.5f); } break; case VisTypes.Depth: case VisTypes.Infrared: case VisTypes.BodyIndex: { DepthSpacePoint depthPoint = coordinateMapper.MapCameraPointToDepthSpace(position3D); point.X = float.IsNegativeInfinity(depthPoint.X) ? 0 : (int)(depthPoint.X + 0.5f); point.Y = float.IsNegativeInfinity(depthPoint.Y) ? 0 : (int)(depthPoint.Y + 0.5f); } break; case VisTypes.None: break; default: break; } return(point); }
public static void WriteFaceOverFrame(DepthSensorKinect2 sensor, VisTypes visType, BoxFace boxFace, int sizeLine, ref ushort[] buffDepth16) { // Box = (topX, topY, width, height) // Box = new BoxFace(boxColor.Left, boxColor.Top, (boxColor.Right - boxColor.Left), (boxColor.Bottom - boxColor.Top)); int _left = boxFace.topX; int _right = boxFace.width + _left; int _top = boxFace.topY; int _bottom = boxFace.height + _top; switch (visType) { case VisTypes.Color: for (int ii = _left; ii <= _right; ii++) { for (int a = -sizeLine; a <= sizeLine; a++) { for (int b = -sizeLine; b <= sizeLine; b++) { int posX = ii + a; int posY1 = _top + b; int posY2 = _bottom + b; if ( (posX >= 0 && posX < sensor.ColorImageSize.Width) && (posY1 >= 0 && posY1 < sensor.ColorImageSize.Height) && (posY2 >= 0 && posY2 < sensor.ColorImageSize.Height) ) { // top line int indexDepth1 = posY1 * sensor.ColorImageSize.Width + posX; buffDepth16[indexDepth1] = 0xffff; // bottom line int indexDepth2 = posY2 * sensor.ColorImageSize.Width + posX; buffDepth16[indexDepth2] = 0xffff; } } } } //EndFor for (int jj = _top; jj <= _bottom; jj++) { for (int a = -sizeLine; a <= sizeLine; a++) { for (int b = -sizeLine; b <= sizeLine; b++) { int posY = jj + b; int posX1 = _left + a; int posX2 = _right + a; if ( (posX1 >= 0 && posX1 < sensor.ColorImageSize.Width) && (posY >= 0 && posY < sensor.ColorImageSize.Height) && (posX2 >= 0 && posX2 < sensor.ColorImageSize.Width) ) { // left line int indexDepth1 = posY * sensor.ColorImageSize.Width + posX1; buffDepth16[indexDepth1] = 0xffff; // right line int indexDepth2 = posY * sensor.ColorImageSize.Width + posX2; buffDepth16[indexDepth2] = 0xffff; } } } } //EndFor break; case VisTypes.Depth: case VisTypes.Infrared: case VisTypes.BodyIndex: for (int ii = _left; ii <= _right; ii++) { for (int a = -sizeLine; a <= sizeLine; a++) { for (int b = -sizeLine; b <= sizeLine; b++) { int posX = ii + a; int posY1 = _top + b; int posY2 = _bottom + b; if ( (posX >= 0 && posX < sensor.DepthImageSize.Width) && (posY1 >= 0 && posY1 < sensor.DepthImageSize.Height) && (posY2 >= 0 && posY2 < sensor.DepthImageSize.Height) ) { // top line int indexDepth1 = posY1 * sensor.DepthImageSize.Width + posX; buffDepth16[indexDepth1] = 0xffff; // bottom line int indexDepth2 = posY2 * sensor.DepthImageSize.Width + posX; buffDepth16[indexDepth2] = 0xffff; } } } } //EndFor for (int jj = _top; jj <= _bottom; jj++) { for (int a = -sizeLine; a <= sizeLine; a++) { for (int b = -sizeLine; b <= sizeLine; b++) { int posY = jj + b; int posX1 = _left + a; int posX2 = _right + a; if ( (posX1 >= 0 && posX1 < sensor.DepthImageSize.Width) && (posY >= 0 && posY < sensor.DepthImageSize.Height) && (posX2 >= 0 && posX2 < sensor.DepthImageSize.Width) ) { // left line int indexDepth1 = posY * sensor.DepthImageSize.Width + posX1; buffDepth16[indexDepth1] = 0xffff; // right line int indexDepth2 = posY * sensor.DepthImageSize.Width + posX2; buffDepth16[indexDepth2] = 0xffff; } } } } //EndFor break; case VisTypes.None: break; default: break; } }