public bool pictoricalValueAtPixel(YarnPictorial p, int colunm, int row, out bool healed) { bool frontFace = p.Value(colunm, row); healed = false; if (pictoricalHealed(p, colunm, row)) { if (frontFace == true || p.doubleHealed) { frontFace = !frontFace; healed = true; } } return(frontFace); }
public bool pictoricalHealed(YarnPictorial p, int column, int row) { bool healed = false; if (p.healedStep != -1) { if (column >= p.firstPoint[row] && column <= p.lastPoint[row] || !p.adjusted) { if ((column + (row * p.healedStepGap)) % p.healedStep == 0) { healed = true; } } } return(healed); }
private void SeparateByContours(Vector2Int dilatationSize, string prefix) { Size contoursSize = new Size(100, 100); Mat matOrig = new Mat(contoursSize, CvType.CV_8U); Imgproc.resize(drawing.pattern, matOrig, contoursSize); Mat matDilate = new Mat(contoursSize, CvType.CV_8U); Imgproc.threshold(matOrig, matOrig, 1, 255, Imgproc.THRESH_BINARY); Mat dilateElement = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(dilatationSize.x, dilatationSize.y)); Imgproc.dilate(matOrig, matDilate, dilateElement); List <MatOfPoint> contours = new List <MatOfPoint>(); Mat srcHierarchy = new Mat(); Imgproc.findContours(matDilate, contours, srcHierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); int i = 0; if (contours.Count == 1) { processedPictorials.Add(new YarnPictorial(this)); } else { foreach (var contour in contours) { double area = Imgproc.contourArea(contour); if (area > 25) { YarnPictorial p = new YarnPictorial(this, contour); processedPictorials.Add(p); } i++; } } }
private void WeavePictoricalEspolin(Pictorial pictorial, Transform parent, int index, Rect rect) { YarnPictorial yarnPictorial = pictorial.processedPictorials[index]; yarnPictorial.Prepare(); // // Create each horizontal yarm (pictorical) GameObject go = Instantiate(Resources.Load("Yarn"), parent) as GameObject; yarnPictorial.curve = go.GetComponent <Curve>(); yarnPictorial.curve.speedMultiplier *= gap.x; go.name = "P" + index; Yarn yarn = go.GetComponent <Yarn>(); yarn.attributes = yarnPictorial.yarn; //Just for debug if (yarnPictorial.debugColor != Color.black) { yarn.attributes.color = yarnPictorial.debugColor; } for (int row = (int)rect.yMin; row < rect.yMax; row++) { if (yarnPictorial.firstPoint[row] != -1 && (yarnPictorial.lastPoint[row] - yarnPictorial.firstPoint[row]) > 2) { bool lastUpDown = false; bool healed, healed2; // For each cross with a vertical yarm (warp) if ((row % 2) == 0) { for (var column = yarnPictorial.firstPoint[row]; column <= yarnPictorial.lastPoint[row]; column++) { bool upDown = pictoricalValueAtPixel(yarnPictorial, column, row, out healed); bool nextUpDown = pictoricalValueAtPixel(yarnPictorial, column + 1, row, out healed2); // If the yarm doesn't change is not neccesary a control point if ((column != yarnPictorial.firstPoint[row]) && (column != yarnPictorial.lastPoint[row] - 1) && column < resolution.x - 1) { if ((upDown == lastUpDown) && (upDown == nextUpDown)) // && depth[column,row] == depth[column+1,row]) { continue; } } float up; if (upDown) { up = 2.0f; } else { up = yarnPictorial.CalculateBackDepth(this, index, column, row); } if (healed) { up *= 0.2f; } yarnPictorial.curve.AddControlPoint( new Vector3( (column - rect.x - rect.width * 0.5f) * gap.x, up * gap.y * 0.5f, (row - rect.y - rect.height * 0.5f) * gap.z), Quaternion.LookRotation(Vector3.right, Vector3.forward), lastUpDown != upDown, "Control Point_" + row + "_" + column + " " + healed); lastUpDown = upDown; } } else { for (var column = yarnPictorial.lastPoint[row]; column >= yarnPictorial.firstPoint[row]; column--) { bool upDown = pictoricalValueAtPixel(yarnPictorial, column, row, out healed); bool nextUpDown = pictoricalValueAtPixel(yarnPictorial, column - 1, row, out healed2); // If the yarm doesn't change is not neccesary a control point if ((column != yarnPictorial.firstPoint[row]) && (column != yarnPictorial.lastPoint[row] - 1) && column != resolution.x && column != 0) { if ((upDown == lastUpDown) && (upDown == nextUpDown))// && depth[column,row] == depth[column-1,row]) { continue; } } float up; if (upDown) { up = 2.0f; } else { up = yarnPictorial.CalculateBackDepth(this, index, column, row); } if (healed) { up *= 0.2f; } yarnPictorial.curve.AddControlPoint( new Vector3( (column - rect.x - rect.width * 0.5f) * gap.x, up * gap.y * 0.5f, (row - rect.y - rect.height * 0.5f) * gap.z), Quaternion.LookRotation(Vector3.left, Vector3.back), lastUpDown != upDown, "Control Point_" + row + "_" + column + " " + healed); lastUpDown = upDown; } } } } yarn.UpdateMesh(); bounds.Encapsulate(yarn.bounds); yarnPictorial.ReleaseMem(); //Split mesh //go.GetComponentInChildren<SplitMeshRenderer>().Split(); }