public void SaveLevelData() { GeneratedPoint[] points = initialPoint.GetComponentsInChildren <GeneratedPoint>(); PointMap pointMap = ScriptableObject.CreateInstance <PointMap>(); pointMap.points = new Vector2[points.Length]; for (int i = 0; i < points.Length; i++) { pointMap.points[i] = points[i].transform.position; } AssetDatabase.CreateAsset(pointMap, "Assets/Levels/" + fileName + ".asset"); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); }
public MapGraph(TriangleNet.Mesh mesh, PointMap pointMap, int xOffset, int yOffset) { this.pointMap = pointMap; this.xOffset = xOffset; this.yOffset = yOffset; CreateTriangleGraph(mesh); List <Line> edges = new List <Line>(); foreach (var seg in mesh.Segments) { var p1 = new Point(seg.GetVertex(0)); var p2 = new Point(seg.GetVertex(1)); edges.Add(new Line(p1, p2)); } this.interiorEdges = edges.ToArray(); }
/// <summary> /// Draws the perforation. /// </summary> /// <returns></returns> public Result calculatePointMap(List <Circle> circleList) { pointMap = new PointMap(); this.PunchingToolList[0].X = circleList[0].Diameter; // Create the pointMap foreach (Circle circle in circleList) { pointMap.AddPoint(new PunchingPoint(circle.Center)); } SortedDictionary <int, PunchingPoint> xDict0 = null; SortedDictionary <int, PunchingPoint> xDict1 = null; if (pointMap.Count > 0) { xDict0 = pointMap.getXDictionary(0); } if (pointMap.Count > 1) { xDict1 = pointMap.getXDictionary(1); } if (xDict0.Count > 2) { XSpacing = Math.Abs(xDict0.ElementAt(1).Value.Point.X - xDict0.ElementAt(0).Value.Point.X); } if (xDict0.Count > 1 && xDict1.Count > 1) { YSpacing = Math.Abs(xDict1.ElementAt(0).Value.Point.Y - xDict0.ElementAt(0).Value.Point.Y); } return(Result.Success); }
/// <summary> /// Draws the perforation. /// </summary> /// <returns></returns> public override double drawPerforation(Curve boundaryCurve) { List <PointMap> pointMapList = new List <PointMap>(); Random random = new Random(); PointMap pointMapTool1 = new PointMap(); pointMapList.Add(pointMapTool1); double marginX; // Find the boundary BoundingBox boundingBox = boundaryCurve.GetBoundingBox(Plane.WorldXY); Point3d min = boundingBox.Min; Point3d max = boundingBox.Max; double spanX = max.X - min.X; double spanY = max.Y - min.Y; int punchQtyX = ((int)((spanX - punchingToolList[0].X) / XSpacing)) + 1; double secondRowOffset = pitch * Math.Cos(Math.PI * 60 / 180); if (spanX >= ((punchQtyX - 1) * XSpacing + secondRowOffset + punchingToolList[0].X)) { marginX = (spanX - ((punchQtyX - 1) * XSpacing) - secondRowOffset) / 2; } else { marginX = (spanX - ((punchQtyX - 1) * XSpacing)) / 2; } int punchQtyY = ((int)((spanY - punchingToolList[0].Y) / YSpacing)) + 1; double marginY = (spanY - ((punchQtyY - 1) * YSpacing)) / 2; Point3d point; RhinoDoc doc = RhinoDoc.ActiveDoc; double firstX = min.X + marginX; double firstY = min.Y + marginY; // Record the current layer int currentLayer = doc.Layers.CurrentLayerIndex; // Create Perforation Layer // if (punchingToolList[0].ClusterTool.Enable == true) { // RhinoUtilities.SetActiveLayer(Properties.Settings.Default.PerforationLayerName, System.Drawing.Color.Green); doc.Layers.SetCurrentLayerIndex(currentLayer, true); } //else //{ // if (MetrixUtilities.IsLayerFound("PerfTemporaryLayer")) // { // RhinoUtilities.SetActiveLayer("TemporaryToolHit", System.Drawing.Color.Black); // } // else // { // RhinoUtilities.SetActiveLayer(Properties.Settings.Default.ToolHitLayerName, System.Drawing.Color.Black); // } //} bool drawSimpleToolHit = true; for (int i = 0; i < punchingToolList.Count; i++) { // Only draw cluster tool if it is enable if (punchingToolList[i].ClusterTool.Enable == true) { // Draw the cluster tool drawSimpleToolHit = false; break; } } if (drawSimpleToolHit) { int currentlayer = doc.Layers.Find("Tool Hit", true); if (currentlayer < 0) { currentlayer = doc.Layers.Add("Tool Hit", System.Drawing.Color.Black); } doc.Layers.SetCurrentLayerIndex(currentlayer, true); for (int y = 0; y < punchQtyY; y++) { if (y % 2 == 0) // even rows { for (int x = 0; x < punchQtyX; x++) { point = new Point3d(firstX + x * XSpacing, firstY + y * YSpacing, 0); if (punchingToolList[0].isInside(boundaryCurve, point) == true) { if (random.NextDouble() < randomness) { pointMapTool1.AddPoint(new PunchingPoint(point)); punchingToolList[0].drawTool(point); } } } } else // odd rows { for (int x = 0; x < punchQtyX; x++) { point = new Point3d(firstX + secondRowOffset + (x * XSpacing), firstY + y * YSpacing, 0); if (punchingToolList[0].isInside(boundaryCurve, point) == true) { if (random.NextDouble() < randomness) { pointMapTool1.AddPoint(new PunchingPoint(point)); punchingToolList[0].drawTool(point); } } } } } } else { for (int y = 0; y < punchQtyY; y++) { if (y % 2 == 0) // even rows { for (int x = 0; x < punchQtyX; x++) { point = new Point3d(firstX + x * XSpacing, firstY + y * YSpacing, 0); if (punchingToolList[0].isInside(boundaryCurve, point) == true) { if (random.NextDouble() < randomness) { pointMapTool1.AddPoint(new PunchingPoint(point)); if (PunchingToolList[0].Perforation) { punchingToolList[0].drawTool(point); } } } } } else // odd rows { for (int x = 0; x < punchQtyX; x++) { point = new Point3d(firstX + secondRowOffset + (x * XSpacing), firstY + y * YSpacing, 0); if (punchingToolList[0].isInside(boundaryCurve, point) == true) { if (random.NextDouble() < randomness) { pointMapTool1.AddPoint(new PunchingPoint(point)); if (PunchingToolList[0].Perforation) { punchingToolList[0].drawTool(point); } } } } } } } // Display the open area calculation AreaMassProperties area = AreaMassProperties.Compute(boundaryCurve); RhinoApp.WriteLine("Total area: {0} mm^2", area.Area.ToString("#.##")); double toolArea = punchingToolList[0].getArea() * pointMapTool1.Count; RhinoApp.WriteLine("Tool area: {0} mm^2", toolArea.ToString("#.##")); openArea = toolArea * 100 / area.Area; RhinoApp.WriteLine("Open area: {0}%", openArea.ToString("#.")); // Draw the cluster for each tool for (int i = 0; i < punchingToolList.Count; i++) { // Only draw cluster tool if it is enable if (punchingToolList[i].ClusterTool.Enable == true) { // Draw the cluster tool drawCluster(pointMapList[i], punchingToolList[i]); } } doc.Views.Redraw(); doc.Layers.SetCurrentLayerIndex(currentLayer, true); return(openArea); }
/// <summary> /// Draws the perforation. /// </summary> /// <returns></returns> public override double drawPerforation(Curve boundaryCurve) { PointMap[] pointMap = new PointMap[AtomicNumber]; for (int x = 0; x < AtomicNumber; ++x) { pointMap[x] = new PointMap(); } int[] toolHitArray = Enumerable.Repeat(0, atomicNumber).ToArray(); // Find the boundary BoundingBox boundingBox = boundaryCurve.GetBoundingBox(Plane.WorldXY); Point3d min = boundingBox.Min; Point3d max = boundingBox.Max; double spanX = max.X - min.X; double spanY = max.Y - min.Y; int punchQtyX = ((int)((spanX - punchingToolList[0].X) / XSpacing)) + 1; double marginX = (spanX - ((punchQtyX - 1) * XSpacing)) / 2; int punchQtyY = ((int)((spanY - punchingToolList[0].Y) / YSpacing)) + 1; double marginY = (spanY - ((punchQtyY - 1) * YSpacing)) / 2; Point3d point; RhinoDoc doc = RhinoDoc.ActiveDoc; double firstX = min.X + marginX; double firstY = min.Y + marginY; Point3d origin = new Point3d(firstX, firstY, 0); int currentLayer = doc.Layers.CurrentLayerIndex; // Random Engine RandomTiler randomTileEngine = new RandomTiler(); int totalQty = punchQtyX * punchQtyY; // except the last tool percentage will be total - all tool hit List <double> toolHitPercentage = new List <double>(atomicNumber - 1); double average = 1 / (double)atomicNumber; double minPercentage = (average - 0.125 * average); //for (int i = 0; i < atomicNumber-1; i++) //{ // toolHitPercentage.Add(minPercentage + random.NextDouble() * (2*0.125* average)); //} double totalPercentage = 0; for (int i = 0; i < atomicNumber - 1; i++) { if (PunchingToolList[i].Gap > 1) { PunchingToolList[i].Gap = 1; } if (totalPercentage + PunchingToolList[i].Gap <= 1) { totalPercentage += PunchingToolList[i].Gap; toolHitPercentage.Add(PunchingToolList[i].Gap); } else { totalPercentage = 1; PunchingToolList[i].Gap = 1 - totalPercentage; toolHitPercentage.Add(PunchingToolList[i].Gap); } } int toolHitCount = 0; List <int> tileCounts = new List <int>(); foreach (double pc in toolHitPercentage) { int toolHitQty = (int)(totalQty * pc); tileCounts.Add(toolHitQty); toolHitCount = toolHitCount + toolHitQty; } randomTileEngine.Weight = new int[5, 5] { { 1, 1, 2, 1, 1 }, { 1, 2, 2, 2, 1 }, { 2, 2, 0, 2, 2 }, { 1, 2, 2, 2, 1 }, { 1, 1, 2, 1, 1 } }; tileCounts.Add(totalQty - toolHitCount); int[,] tileMap = randomTileEngine.GetTileMap(tileCounts, punchQtyX, punchQtyY); int[] toolHitCounter = new int[atomicNumber]; int type; bool drawClusterToolHit = false; for (int i = 0; i < punchingToolList.Count; i++) { // Only draw cluster tool if it is enable if (punchingToolList[i].ClusterTool.Enable == true) { // Draw the cluster tool drawClusterToolHit = true; break; } } int perforationLayer = currentLayer; int toolHitlayer = doc.Layers.Find("Tool Hit", true); if (toolHitlayer < 0) { toolHitlayer = doc.Layers.Add("Tool Hit", System.Drawing.Color.Black); } doc.Layers.SetCurrentLayerIndex(toolHitlayer, true); for (int y = 0; y < punchQtyY; y++) { for (int x = 0; x < punchQtyX; x++) { point = new Point3d(firstX + x * XSpacing, firstY + y * YSpacing, 0); type = tileMap[x, y] - 1; if (punchingToolList[type].ClusterTool.Enable == true) { doc.Layers.SetCurrentLayerIndex(perforationLayer, true); } else { doc.Layers.SetCurrentLayerIndex(toolHitlayer, true); } if (punchingToolList[type].isInside(boundaryCurve, point) == true) { pointMap[type].AddPoint(new PunchingPoint(point)); for (int t = type; t < AtomicNumber; t++) { pointMap[t].AddPoint(new PunchingPoint(point)); } if (PunchingToolList[type].ClusterTool.Enable == false) { punchingToolList[type].drawTool(point); if (punchingToolList[type].Perforation == true && drawClusterToolHit == true) { doc.Layers.SetCurrentLayerIndex(perforationLayer, true); punchingToolList[type].drawTool(point); } } else if (punchingToolList[type].Perforation == true) { punchingToolList[type].drawTool(point); } toolHitArray[type]++; } } } Rhino.DocObjects.RhinoObject [] perforations = doc.Objects.FindByLayer("Perforation"); foreach (var perforation in perforations) { perforation.Attributes.DisplayOrder = 1; perforation.CommitChanges(); } doc.Views.Redraw(); // Display the open area calculation AreaMassProperties area = AreaMassProperties.Compute(boundaryCurve); RhinoApp.WriteLine("Total area: {0} mm^2", area.Area.ToString("#.##")); double toolArea = 0; double totalToolArea = 0; for (int i = 0; i < this.atomicNumber; i++) { toolArea = punchingToolList[i].getArea() * toolHitArray[i]; totalToolArea = totalToolArea + toolArea; RhinoApp.WriteLine("Tool area{0}: {1} mm^2", i, toolArea.ToString("#.##")); } openArea = totalToolArea * 100 / area.Area; RhinoApp.WriteLine("Open area: {0}%", openArea.ToString("#.")); // Draw the cluster for each tool for (int i = 0; i < punchingToolList.Count; i++) { // Only draw cluster tool if it is enable if (punchingToolList[i].ClusterTool.Enable == true) { // Draw the cluster tool drawCluster(pointMap[i], punchingToolList[i]); } } doc.Views.Redraw(); doc.Layers.SetCurrentLayerIndex(currentLayer, true); return(openArea); }
/// <summary> /// Draws the perforation. /// </summary> /// <returns></returns> public override double drawPerforation(Curve boundaryCurve) { List <PointMap> pointMapList = new List <PointMap>(); PointMap pointMapTool1 = new PointMap(); pointMapList.Add(pointMapTool1); // Find the boundary BoundingBox boundingBox = boundaryCurve.GetBoundingBox(Plane.WorldXY); Point3d min = boundingBox.Min; Point3d max = boundingBox.Max; double spanX = max.X - min.X; double spanY = max.Y - min.Y; int punchQtyX = ((int)((spanX - punchingToolList[0].X) / XSpacing)) + 1; double marginX = (spanX - ((punchQtyX - 1) * XSpacing)) / 2; double YSpacing = XSpacing; int punchQtyY = ((int)((spanY - punchingToolList[0].Y) / YSpacing)) + 1; double marginY = (spanY - ((punchQtyY - 1) * YSpacing)) / 2; Point3d point; RhinoDoc doc = RhinoDoc.ActiveDoc; double firstX = min.X + marginX; double firstY = min.Y + marginY; // Set the current layer int currentLayer = doc.Layers.CurrentLayerIndex; doc.Layers.SetCurrentLayerIndex(currentLayer, false); // We don't use cluster tool so just perf it onto Tool Hit layer //if (!MetrixUtilities.IsLayerFound("TemporaryPerfLayer")) //{ // RhinoUtilities.SetActiveLayer(Properties.Settings.Default.ToolHitLayerName, System.Drawing.Color.Black); //} //else //{ // RhinoUtilities.SetActiveLayer("TemporaryToolHit", System.Drawing.Color.Black); //} // Generate the point map first for (int y = 0; y < punchQtyY; y++) { for (int x = 0; x < punchQtyX; x++) { point = new Point3d(firstX + x * XSpacing, firstY + y * YSpacing, 0); if (punchingToolList[0].isInside(boundaryCurve, point) == true) { pointMapTool1.AddPoint(new PunchingPoint(point)); } } } Random random = new Random(); int testResult; int slotNumber = 1; PunchingTools.Obround threeHoleSlot = new PunchingTools.Obround(); threeHoleSlot.X = 2 * this.XSpacing + punchingToolList[0].X; threeHoleSlot.Y = punchingToolList[0].X; PunchingTools.Obround fiveHoleSlot = new PunchingTools.Obround(); fiveHoleSlot.X = 4 * this.XSpacing + punchingToolList[0].X; fiveHoleSlot.Y = punchingToolList[0].X; int chanceForHoles = 60; int chanceForMidSlot = 86; int chanceForLargeSlot = 100; int holeCounter = 0; int midSlotCounter = 0; int largeSlotCounter = 0; double toolArea = 0; // Go through each point in the point Map list to determine whether it is a hole or a slot. for (int i = 0; i < pointMapTool1.YCount; i++) { SortedDictionary <int, PunchingPoint> xDict = pointMapTool1.getXDictionary(i); chanceForHoles = 60; chanceForMidSlot = 86; chanceForLargeSlot = 100; for (int j = 0; j < xDict.Count; j = j + slotNumber) { if (xDict.Count - j > 4) { // Generate whether the current hole testResult = random.Next(1, chanceForLargeSlot); } else if (xDict.Count - j > 2) { chanceForHoles = 30; chanceForMidSlot = 66; chanceForLargeSlot = 100; // Generate whether the current slot testResult = random.Next(1, chanceForMidSlot); } else { chanceForHoles = 30; chanceForMidSlot = 66; chanceForLargeSlot = 100; // Generate whether the current large slot testResult = random.Next(1, chanceForHoles); } if (testResult >= 1 && testResult <= chanceForHoles) { slotNumber = 1; holeCounter++; midSlotCounter = 0; largeSlotCounter = 0; if (holeCounter == 1) { chanceForHoles = 60; chanceForMidSlot = 86; chanceForLargeSlot = 100; } else if (holeCounter == 2) { chanceForHoles = 30; chanceForMidSlot = 66; chanceForLargeSlot = 100; } else if (holeCounter > 2) { chanceForHoles = 10; chanceForMidSlot = 53; chanceForLargeSlot = 100; } // Draw circle punchingToolList[0].drawTool(xDict.ElementAt(j).Value.Point); toolArea += punchingToolList[0].getArea(); } else if (testResult > chanceForHoles && testResult <= chanceForMidSlot) { slotNumber = 3; holeCounter = 0; midSlotCounter++; largeSlotCounter = 0; if (midSlotCounter == 1) { chanceForHoles = 80; chanceForMidSlot = 90; chanceForLargeSlot = 100; } else if (midSlotCounter > 1) { chanceForHoles = 85; chanceForMidSlot = 93; chanceForLargeSlot = 100; } // Draw slot that span over 3 holes threeHoleSlot.drawTool(xDict.ElementAt(j + 1).Value.Point); toolArea += threeHoleSlot.getArea(); } else if (testResult > chanceForMidSlot && testResult <= chanceForLargeSlot) { slotNumber = 5; holeCounter = 0; midSlotCounter = 0; largeSlotCounter++; if (largeSlotCounter >= 1) { chanceForHoles = 80; chanceForMidSlot = 100; chanceForLargeSlot = 100; } // Draw slot that span over 5 holes fiveHoleSlot.drawTool(xDict.ElementAt(j + 2).Value.Point); toolArea += fiveHoleSlot.getArea(); } } } // Display the open area calculation AreaMassProperties area = AreaMassProperties.Compute(boundaryCurve); RhinoApp.WriteLine("Total area: {0} mm^2", area.Area.ToString("#.##")); RhinoApp.WriteLine("Tool area: {0} mm^2", toolArea.ToString("#.##")); openArea = toolArea * 100 / area.Area; RhinoApp.WriteLine("Open area: {0}%", openArea.ToString("#.")); //for (int y = 0; y < punchQtyY; y++) //{ // for (int x = 0; x < punchQtyX; x++) // { // point = new Point3d(firstX + x * XSpacing, firstY + y * YSpacing, 0); // if (punchingToolList[0].isInside(boundaryCurve, point) == true) // { // pointMap.AddPoint(new PunchingPoint(point)); // punchingToolList[0].drawTool(point); // } // if(random.NextDouble() < randomness) // { // if (punchingToolList[1].isInside(boundaryCurve, point) == true) // { // doc.Layers.SetCurrentLayerIndex(brailleLayerIndex, true); // punchingToolList[1].drawTool(point); // doc.Layers.SetCurrentLayerIndex(perforationlayerIndex, true); // } // } // } //} doc.Views.Redraw(); doc.Layers.SetCurrentLayerIndex(currentLayer, true); return(openArea); }
public CardGrouping(int numBins, PointMap scoring) { array = new CardCollection[numBins]; Reset(); score = scoring; }
/// <summary> /// Draws the perforation. /// </summary> /// <returns></returns> public override double drawPerforation(Curve boundaryCurve) { List <PointMap> pointMapList = new List <PointMap>(); PointMap pointMapTool1 = new PointMap(); PointMap pointMapTool2 = new PointMap(); PointMap pointMapTool3 = new PointMap(); pointMapList.Add(pointMapTool1); // Find the boundary BoundingBox boundingBox = boundaryCurve.GetBoundingBox(Plane.WorldXY); Point3d min = boundingBox.Min; Point3d max = boundingBox.Max; double spanX = max.X - min.X; double spanY = max.Y - min.Y; double gap = XSpacing - punchingToolList[0].X; int punchQtyX = ((int)((spanX - punchingToolList[0].X - gap) / XSpacing)) + 1; double marginX = (spanX - (((punchQtyX - 1) * XSpacing) - gap)) / 2; // Debug purpose // marginX = 0; double YSpacing = XSpacing; int punchQtyY = ((int)((spanY - punchingToolList[0].Y) / YSpacing)) + 1; double marginY = (spanY - ((punchQtyY - 1) * YSpacing)) / 2; Point3d point; RhinoDoc doc = RhinoDoc.ActiveDoc; double firstX = min.X + marginX + gap; double firstY = min.Y + marginY; // Set the current layer int currentLayer = doc.Layers.CurrentLayerIndex; doc.Layers.SetCurrentLayerIndex(currentLayer, false); // We don't use cluster tool so just perf it onto Tool Hit layer //if (!MetrixUtilities.IsLayerFound("TemporaryPerfLayer")){ // RhinoUtilities.SetActiveLayer(Properties.Settings.Default.ToolHitLayerName, System.Drawing.Color.Black); //}else{ // RhinoUtilities.SetActiveLayer("TemporaryToolHit", System.Drawing.Color.Black); //} double runningX = firstX - punchingToolList[0].X / 2; double twoToolTest; double threeToolTest; Random random = new Random(); int roundToolCounter = 0; int slotToolCounter = 0; int tool0Counter = 0; int tool1Counter = 0; int tool2Counter = 0; bool isToolHit = false; int toolMissingCounter = 0; // Generate the pattern for (int y = 0; y < punchQtyY; y++) { // For even rows if (random.NextDouble() < randomness || toolMissingCounter > 0) { isToolHit = true; toolMissingCounter = 0; } else { isToolHit = false; toolMissingCounter++; } if (y % 2 == 0) { // firstX = min.X + marginX + gap; runningX = min.X + gap; twoToolTest = random.Next(42); // Small slot if (twoToolTest < 14) { point = new Point3d(runningX + punchingToolList[1].X / 2, firstY + y * YSpacing, 0); pointMapTool2.AddPoint(new PunchingPoint(point)); runningX = runningX + punchingToolList[1].X + gap; punchingToolList[1].drawTool(point); if (isToolHit) { slotToolCounter = 1; tool1Counter++; } } else // Big slot { point = new Point3d(runningX + punchingToolList[2].X / 2, firstY + y * YSpacing, 0); pointMapTool3.AddPoint(new PunchingPoint(point)); runningX = runningX + punchingToolList[2].X + gap; slotToolCounter = 1; if (isToolHit) { tool2Counter++; punchingToolList[2].drawTool(point); } } } else { //firstX = min.X + marginX; //runningX = firstX - punchingToolList[0].X / 2; runningX = min.X; point = new Point3d(runningX + punchingToolList[0].X / 2, firstY + y * YSpacing, 0); pointMapTool1.AddPoint(new PunchingPoint(point)); runningX = runningX + punchingToolList[0].X + gap; roundToolCounter = 1; if (isToolHit) { tool0Counter++; punchingToolList[0].drawTool(point); } } // for (int x = 0; x < punchQtyX; x++) { // Skip if the point already taken up by the tool if (runningX > firstX + x * XSpacing) { continue; } if (random.NextDouble() < randomness || toolMissingCounter > 0) { isToolHit = true; toolMissingCounter = 0; } else { isToolHit = false; toolMissingCounter++; } threeToolTest = random.Next(100); if (threeToolTest < 16 && slotToolCounter < 2) { point = new Point3d(runningX + punchingToolList[1].X / 2, firstY + y * YSpacing, 0); pointMapTool2.AddPoint(new PunchingPoint(point)); runningX = runningX + punchingToolList[1].X + gap; roundToolCounter = 0; slotToolCounter++; if (isToolHit) { tool1Counter++; punchingToolList[1].drawTool(point); } } else if (threeToolTest < 47 && slotToolCounter < 2) { point = new Point3d(runningX + punchingToolList[2].X / 2, firstY + y * YSpacing, 0); pointMapTool3.AddPoint(new PunchingPoint(point)); runningX = runningX + punchingToolList[2].X + gap; roundToolCounter = 0; slotToolCounter++; if (isToolHit) { tool2Counter++; punchingToolList[2].drawTool(point); } } else if (threeToolTest >= 47 && roundToolCounter < 4) { point = new Point3d(runningX + punchingToolList[0].X / 2, firstY + y * YSpacing, 0); pointMapTool1.AddPoint(new PunchingPoint(point)); runningX = runningX + punchingToolList[0].X + gap; roundToolCounter++; slotToolCounter = 0; if (isToolHit) { tool0Counter++; punchingToolList[0].drawTool(point); } } else { x--; } } } // Display the open area calculation AreaMassProperties area = AreaMassProperties.Compute(boundaryCurve); RhinoApp.WriteLine("Total area: {0} mm^2", area.Area.ToString("#.##")); double tool0Area = punchingToolList[0].getArea() * tool0Counter; double tool1Area = punchingToolList[1].getArea() * tool1Counter; double tool2Area = punchingToolList[2].getArea() * tool2Counter; double totalToolArea = tool0Area + tool1Area + tool2Area; RhinoApp.WriteLine("Tool 1 area: {0} mm^2", tool0Area.ToString("#.##")); RhinoApp.WriteLine("Tool 2 area: {0} mm^2", tool1Area.ToString("#.##")); RhinoApp.WriteLine("Tool 3 area: {0} mm^2", tool2Area.ToString("#.##")); double openArea = (totalToolArea * 100) / area.Area; RhinoApp.WriteLine("Open area: {0} %", openArea.ToString("#.##")); //int testResult; //int slotNumber = 1; //PunchingTools.Obround threeHoleSlot = new PunchingTools.Obround(); //threeHoleSlot.X = 2*this.XSpacing + punchingToolList[0].X; //threeHoleSlot.Y = punchingToolList[0].X; //PunchingTools.Obround fiveHoleSlot = new PunchingTools.Obround(); //fiveHoleSlot.X = 4 * this.XSpacing + punchingToolList[0].X; //fiveHoleSlot.Y = punchingToolList[0].X; //int chanceForHoles = 60; //int chanceForMidSlot = 86; //int chanceForLargeSlot = 100; //int holeCounter = 0; //int midSlotCounter = 0; //int largeSlotCounter = 0; //double toolArea = 0; // // Go through each point in the point Map list to determine whether it is a hole or a slot. //for (int i = 0; i < pointMapTool1.YCount; i++) //{ // SortedDictionary<int, PunchingPoint> xDict = pointMapTool1.getXDictionary(i); // chanceForHoles = 60; // chanceForMidSlot = 86; // chanceForLargeSlot = 100; // for (int j = 0; j < xDict.Count; j = j + slotNumber) // { // if (xDict.Count - j > 4) // { // // Generate whether the current hole // testResult = random.Next(1, chanceForLargeSlot); // } // else if (xDict.Count - j > 2) // { // chanceForHoles = 30; // chanceForMidSlot = 66; // chanceForLargeSlot = 100; // // Generate whether the current slot // testResult = random.Next(1, chanceForMidSlot); // } // else // { // chanceForHoles = 30; // chanceForMidSlot = 66; // chanceForLargeSlot = 100; // // Generate whether the current large slot // testResult = random.Next(1, chanceForHoles); // } // if (testResult >= 1 && testResult <= chanceForHoles) // { // slotNumber = 1; // holeCounter++; // midSlotCounter = 0; // largeSlotCounter = 0; // if (holeCounter == 1) // { // chanceForHoles = 60; // chanceForMidSlot = 86; // chanceForLargeSlot = 100; // } // else if(holeCounter == 2) // { // chanceForHoles = 30; // chanceForMidSlot = 66; // chanceForLargeSlot = 100; // } // else if(holeCounter > 2) // { // chanceForHoles = 10; // chanceForMidSlot = 53; // chanceForLargeSlot = 100; // } // // Draw circle // punchingToolList[0].drawTool(xDict.ElementAt(j).Value.Point); // toolArea += punchingToolList[0].getArea(); // } // else if (testResult > chanceForHoles && testResult <= chanceForMidSlot) // { // slotNumber = 3; // holeCounter = 0; // midSlotCounter++; // largeSlotCounter = 0; // if (midSlotCounter == 1) // { // chanceForHoles = 80; // chanceForMidSlot = 90; // chanceForLargeSlot = 100; // } // else if(midSlotCounter > 1) // { // chanceForHoles = 85; // chanceForMidSlot = 93; // chanceForLargeSlot = 100; // } // // Draw slot that span over 3 holes // threeHoleSlot.drawTool(xDict.ElementAt(j + 1).Value.Point); // toolArea += threeHoleSlot.getArea(); // } // else if (testResult > chanceForMidSlot && testResult <= chanceForLargeSlot) // { // slotNumber = 5; // holeCounter = 0; // midSlotCounter = 0; // largeSlotCounter++; // if(largeSlotCounter >= 1) // { // chanceForHoles = 80; // chanceForMidSlot = 100; // chanceForLargeSlot = 100; // } // // Draw slot that span over 5 holes // fiveHoleSlot.drawTool(xDict.ElementAt(j + 2).Value.Point); // toolArea += fiveHoleSlot.getArea(); // } // } //} // Display the open area calculation //AreaMassProperties area = AreaMassProperties.Compute(boundaryCurve); //RhinoApp.WriteLine("Total area: {0} mm^2", area.Area.ToString("#.##")); // RhinoApp.WriteLine("Tool area: {0} mm^2", toolArea.ToString("#.##")); // openArea = toolArea * 100 / area.Area; // RhinoApp.WriteLine("Open area: {0}%", openArea.ToString("#.")); //for (int y = 0; y < punchQtyY; y++) //{ // for (int x = 0; x < punchQtyX; x++) // { // point = new Point3d(firstX + x * XSpacing, firstY + y * YSpacing, 0); // if (punchingToolList[0].isInside(boundaryCurve, point) == true) // { // pointMap.AddPoint(new PunchingPoint(point)); // punchingToolList[0].drawTool(point); // } // if(random.NextDouble() < randomness) // { // if (punchingToolList[1].isInside(boundaryCurve, point) == true) // { // doc.Layers.SetCurrentLayerIndex(brailleLayerIndex, true); // punchingToolList[1].drawTool(point); // doc.Layers.SetCurrentLayerIndex(perforationlayerIndex, true); // } // } // } //} doc.Views.Redraw(); doc.Layers.SetCurrentLayerIndex(currentLayer, true); return(openArea); }
/// <summary> /// Draws the perforation. /// </summary> /// <returns></returns> public override double drawPerforation(Curve boundaryCurve) { PointMap pointMap = new PointMap(); int[] toolHitArray = Enumerable.Repeat(0, 3).ToArray(); double marginX; // Find the boundary BoundingBox boundingBox = boundaryCurve.GetBoundingBox(Plane.WorldXY); Point3d min = boundingBox.Min; Point3d max = boundingBox.Max; double spanX = max.X - min.X; double spanY = max.Y - min.Y; int punchQtyX = ((int)((spanX - punchingToolList[0].X) / XSpacing)) + 1; double secondRowOffset = pitch * Math.Cos(Math.PI * 60 / 180); if (spanX >= ((punchQtyX - 1) * XSpacing + secondRowOffset + punchingToolList[0].X)) { marginX = (spanX - ((punchQtyX - 1) * XSpacing) - secondRowOffset) / 2; } else { marginX = (spanX - ((punchQtyX - 1) * XSpacing)) / 2; } int punchQtyY = ((int)((spanY - punchingToolList[0].Y) / YSpacing)) + 1; double marginY = (spanY - ((punchQtyY - 1) * YSpacing)) / 2; Point3d point; RhinoDoc doc = RhinoDoc.ActiveDoc; double firstX = min.X + marginX; double firstY = min.Y + marginY; // Record the current layer int currentLayer = doc.Layers.CurrentLayerIndex; // Set the layer to perforation //if (!MetrixUtilities.IsLayerFound("TemporaryPerfLayer")) //{ // RhinoUtilities.SetActiveLayer(Properties.Settings.Default.ToolHitLayerName, System.Drawing.Color.Black); //} //else //{ // RhinoUtilities.SetActiveLayer("TemporaryToolHit", System.Drawing.Color.Black); //} // Random Engine RandomTiler randomTileEngine = new RandomTiler(); int totalQty = punchQtyX * punchQtyY; // except the last tool percentage will be total - all tool hit List <double> toolHitPercentage = new List <double>(3); toolHitPercentage.Add(0.368); toolHitPercentage.Add(0.177); // Create randomness for tool count random = new Random(); int toolHitCount = 0; // Create tile counts List <int> tileCounts = new List <int>(); foreach (double pc in toolHitPercentage) { int toolHitQty = (int)(totalQty * pc); tileCounts.Add(toolHitQty); toolHitCount = toolHitCount + toolHitQty; } tileCounts.Add(totalQty - toolHitCount); randomTileEngine.Weight = new int[5, 5] { { 1, 1, 2, 1, 1 }, { 1, 2, 3, 2, 1 }, { 2, 3, 0, 3, 2 }, { 1, 2, 3, 2, 1 }, { 1, 1, 2, 1, 1 } }; int[,] tileMap = randomTileEngine.GetTileMap(tileCounts, punchQtyX, punchQtyY); int[] toolHitCounter = new int[3]; for (int y = 0; y < punchQtyY; y++) { if (y % 2 == 0) // even rows { for (int x = 0; x < punchQtyX; x++) { point = new Point3d(firstX + x * XSpacing, firstY + y * YSpacing, 0); if (punchingToolList[0].isInside(boundaryCurve, point) == true) { pointMap.AddPoint(new PunchingPoint(point)); punchingToolList[tileMap[x, y] - 1].drawTool(point); toolHitArray[tileMap[x, y] - 1]++; } } } else // odd rows { for (int x = 0; x < punchQtyX; x++) { point = new Point3d(firstX + secondRowOffset + (x * XSpacing), firstY + y * YSpacing, 0); if (punchingToolList[0].isInside(boundaryCurve, point) == true) { pointMap.AddPoint(new PunchingPoint(point)); punchingToolList[tileMap[x, y] - 1].drawTool(point); toolHitArray[tileMap[x, y] - 1]++; } } } } //for (int y = 0; y < punchQtyY; y++) //{ // for (int x = 0; x < punchQtyX; x++) // { // point = new Point3d(firstX + x * XSpacing, firstY + y * YSpacing, 0); // if (punchingToolList[0].isInside(boundaryCurve, point) == true) // { // pointMap.AddPoint(new PunchingPoint(point)); // punchingToolList[tileMap[x, y]-1].drawTool(point); // toolHitArray[tileMap[x, y]-1]++; // } // } //} // Display the open area calculation AreaMassProperties area = AreaMassProperties.Compute(boundaryCurve); RhinoApp.WriteLine("Total area: {0} mm^2", area.Area.ToString("#.##")); double toolArea = 0; double totalToolArea = 0; for (int i = 0; i < 3; i++) { toolArea = punchingToolList[i].getArea() * toolHitArray[i]; totalToolArea = totalToolArea + toolArea; RhinoApp.WriteLine("Tool area{0}: {1} mm^2", i, toolArea.ToString("#.##")); } openArea = totalToolArea * 100 / area.Area; RhinoApp.WriteLine("Open area: {0}%", openArea.ToString("#.")); // Draw the cluster for each tool for (int i = 0; i < punchingToolList.Count; i++) { // Only draw cluster tool if it is enable if (punchingToolList[i].ClusterTool.Enable == true) { // Draw the cluster tool drawCluster(pointMap, punchingToolList[i]); } } doc.Views.Redraw(); doc.Layers.SetCurrentLayerIndex(currentLayer, true); return(openArea); }
/// <summary> /// Draws the perforation. /// </summary> /// <returns></returns> public override double drawPerforation(Curve boundaryCurve) { List <PointMap> pointMapList = new List <PointMap>(); Random random = new Random(); PointMap pointMapTool0 = new PointMap(); PointMap pointMapTool1 = new PointMap(); pointMapList.Add(pointMapTool0); pointMapList.Add(pointMapTool1); double marginX; // Find the boundary BoundingBox boundingBox = boundaryCurve.GetBoundingBox(Plane.WorldXY); Point3d min = boundingBox.Min; Point3d max = boundingBox.Max; double spanX = max.X - min.X; double spanY = max.Y - min.Y; int punchQtyX = ((int)((spanX - punchingToolList[0].X) / XSpacing)) + 1; double secondRowOffset = pitch * Math.Cos(Math.PI * 60 / 180); if (spanX >= ((punchQtyX - 1) * XSpacing + secondRowOffset + punchingToolList[0].X)) { marginX = (spanX - ((punchQtyX - 1) * XSpacing) - secondRowOffset) / 2; } else { marginX = (spanX - ((punchQtyX - 1) * XSpacing)) / 2; } int punchQtyY = ((int)((spanY - punchingToolList[0].Y) / YSpacing)) + 1; double marginY = (spanY - ((punchQtyY - 1) * YSpacing)) / 2; Point3d point; RhinoDoc doc = RhinoDoc.ActiveDoc; double firstX = min.X + marginX; double firstY = min.Y + marginY; // Record the current layer int currentLayer = doc.Layers.CurrentLayerIndex; // Create Perforation Layer // if (punchingToolList[0].ClusterTool.Enable == true) { doc.Layers.SetCurrentLayerIndex(currentLayer, true); } //else //{ // if (!MetrixUtilities.IsLayerFound("TemporaryPerfLayer")) // { // RhinoUtilities.SetActiveLayer(Properties.Settings.Default.ToolHitLayerName, System.Drawing.Color.Black); // } // else // { // RhinoUtilities.SetActiveLayer("TemporaryToolHit", System.Drawing.Color.Black); // } //} int rightSide = 0; bool hasSlot = false; int slotPercentage = 0; int slotQty; for (int y = 0; y < punchQtyY; y++) { if (y % 3 == 1) { hasSlot = true; slotPercentage = random.Next(10, 105); if (slotPercentage > 100) { slotPercentage = 100; } rightSide++; if (rightSide > 2) { rightSide = 0; } } else { hasSlot = false; } if (y % 2 == 0) // even rows { // Slot propagate from the left if (hasSlot == true && rightSide < 2) { slotQty = (int)(slotPercentage * punchQtyX / 100); int x; for (x = 1; x < slotQty; x += 3) { point = new Point3d(firstX + x * XSpacing, firstY + y * YSpacing, 0); if (punchingToolList[1].isInside(boundaryCurve, point) == true) { pointMapList[1].AddPoint(new PunchingPoint(point)); punchingToolList[1].drawTool(point); } } if (slotQty == punchQtyX && slotQty % 3 != 0) { x = punchQtyX - (punchQtyX % 3) + 1; } for (x = x - 1; x < punchQtyX; x++) { point = new Point3d(firstX + x * XSpacing, firstY + y * YSpacing, 0); if (punchingToolList[0].isInside(boundaryCurve, point) == true) { pointMapList[0].AddPoint(new PunchingPoint(point)); punchingToolList[0].drawTool(point); } } } else if (hasSlot == true && rightSide == 2) { slotQty = (int)(slotPercentage * punchQtyX / 100); int x; int holeQty = punchQtyX - slotQty; holeQty = (int)(holeQty / 3) * 3; for (x = 0; x < holeQty; x++) { point = new Point3d(firstX + x * XSpacing, firstY + y * YSpacing, 0); if (punchingToolList[0].isInside(boundaryCurve, point) == true) { pointMapList[0].AddPoint(new PunchingPoint(point)); punchingToolList[0].drawTool(point); } } for (x = x + 1; x < punchQtyX; x += 3) { point = new Point3d(firstX + x * XSpacing, firstY + y * YSpacing, 0); if (punchingToolList[1].isInside(boundaryCurve, point) == true) { pointMapList[1].AddPoint(new PunchingPoint(point)); punchingToolList[1].drawTool(point); } } if (punchQtyX % 3 != 0) { x = punchQtyX - (punchQtyX % 3); } for (; x < punchQtyX; x++) { point = new Point3d(firstX + x * XSpacing, firstY + y * YSpacing, 0); if (punchingToolList[0].isInside(boundaryCurve, point) == true) { pointMapList[0].AddPoint(new PunchingPoint(point)); punchingToolList[0].drawTool(point); } } } else { for (int x = 0; x < punchQtyX; x++) { point = new Point3d(firstX + x * XSpacing, firstY + y * YSpacing, 0); if (punchingToolList[0].isInside(boundaryCurve, point) == true) { pointMapList[0].AddPoint(new PunchingPoint(point)); punchingToolList[0].drawTool(point); } } } } else // odd rows { // Slot propagate from the left if (hasSlot == true && rightSide < 2) { slotQty = (int)(slotPercentage * punchQtyX / 100); int x; for (x = 1; x < slotQty; x += 3) { point = new Point3d(firstX + secondRowOffset + (x * XSpacing), firstY + y * YSpacing, 0); if (punchingToolList[1].isInside(boundaryCurve, point) == true) { pointMapList[1].AddPoint(new PunchingPoint(point)); punchingToolList[1].drawTool(point); } } if (slotQty == punchQtyX && slotQty % 3 != 0) { x = punchQtyX - (punchQtyX % 3) + 1; } for (x = x - 1; x < punchQtyX; x++) { point = new Point3d(firstX + secondRowOffset + (x * XSpacing), firstY + y * YSpacing, 0); if (punchingToolList[0].isInside(boundaryCurve, point) == true) { pointMapList[0].AddPoint(new PunchingPoint(point)); punchingToolList[0].drawTool(point); } } } else if (hasSlot == true && rightSide == 2) { slotQty = (int)(slotPercentage * punchQtyX / 100); int x; int holeQty = punchQtyX - slotQty; holeQty = (int)(holeQty / 3) * 3; for (x = 0; x < holeQty; x++) { point = new Point3d(firstX + secondRowOffset + (x * XSpacing), firstY + y * YSpacing, 0); if (punchingToolList[0].isInside(boundaryCurve, point) == true) { pointMapList[0].AddPoint(new PunchingPoint(point)); punchingToolList[0].drawTool(point); } } for (x = x + 1; x < punchQtyX; x += 3) { point = new Point3d(firstX + secondRowOffset + (x * XSpacing), firstY + y * YSpacing, 0); if (punchingToolList[1].isInside(boundaryCurve, point) == true) { pointMapList[1].AddPoint(new PunchingPoint(point)); punchingToolList[1].drawTool(point); } } if (punchQtyX % 3 != 0) { x = punchQtyX - (punchQtyX % 3); } for (; x < punchQtyX; x++) { point = new Point3d(firstX + secondRowOffset + (x * XSpacing), firstY + y * YSpacing, 0); if (punchingToolList[0].isInside(boundaryCurve, point) == true) { pointMapList[0].AddPoint(new PunchingPoint(point)); punchingToolList[0].drawTool(point); } } } else { for (int x = 0; x < punchQtyX; x++) { point = new Point3d(firstX + secondRowOffset + (x * XSpacing), firstY + y * YSpacing, 0); if (punchingToolList[0].isInside(boundaryCurve, point) == true) { pointMapList[0].AddPoint(new PunchingPoint(point)); punchingToolList[0].drawTool(point); } } } } } // Display the open area calculation AreaMassProperties area = AreaMassProperties.Compute(boundaryCurve); RhinoApp.WriteLine("Total area: {0} mm^2", area.Area.ToString("#.##")); double tool1Area = punchingToolList[0].getArea() * pointMapList[0].Count; RhinoApp.WriteLine("Tool 1 area: {0} mm^2", tool1Area.ToString("#.##")); double tool2Area = punchingToolList[1].getArea() * pointMapList[1].Count; RhinoApp.WriteLine("Tool 2 area: {0} mm^2", tool2Area.ToString("#.##")); openArea = (tool1Area + tool2Area) * 100 / area.Area; RhinoApp.WriteLine("Open area: {0}%", openArea.ToString("#.")); // Draw the cluster for each tool for (int i = 0; i < punchingToolList.Count; i++) { // Only draw cluster tool if it is enable if (punchingToolList[i].ClusterTool.Enable == true) { // Draw the cluster tool drawCluster(pointMapList[i], punchingToolList[i]); } } doc.Views.Redraw(); doc.Layers.SetCurrentLayerIndex(currentLayer, true); return(openArea); }
/// <summary> /// Draws the perforation. /// </summary> /// <returns></returns> public override double drawPerforation(Curve boundaryCurve) { PointMap pointMap = new PointMap(); // Find the boundary BoundingBox boundingBox = boundaryCurve.GetBoundingBox(Plane.WorldXY); Point3d min = boundingBox.Min; Point3d max = boundingBox.Max; double spanX = max.X - min.X; double spanY = max.Y - min.Y; int punchQtyX = ((int)((spanX - punchingToolList[0].X) / XSpacing)) + 1; double marginX = (spanX - ((punchQtyX - 1) * XSpacing)) / 2; int punchQtyY = ((int)((spanY - punchingToolList[0].Y) / YSpacing)) + 1; double marginY = (spanY - ((punchQtyY - 1) * YSpacing)) / 2; Point3d point; RhinoDoc doc = RhinoDoc.ActiveDoc; double firstX = min.X + marginX; double firstY = min.Y + marginY; Point3d origin = new Point3d(firstX, firstY, 0); int currentLayer = doc.Layers.CurrentLayerIndex; // Create the grid Point3d?[,] grid = new Point3d?[punchQtyX, punchQtyY]; // Active points List <Point3d> activePointsList = new List <Point3d>(); // Point list List <Point3d> pointsList = new List <Point3d>(); //doc.Layers.SetCurrentLayerIndex(layerIndex, true); // Add first point random = new Random(); for (int y = 0; y < punchQtyY; y++) { for (int x = 0; x < punchQtyX; x++) { point = new Point3d(firstX + x * XSpacing, firstY + y * YSpacing, 0); if (punchingToolList[0].isInside(boundaryCurve, point) == true) { if (!grid[x, y].HasValue) { pointMap.AddPoint(new PunchingPoint(point)); punchingToolList[0].drawTool(point); } } } } // Display the open area calculation AreaMassProperties area = AreaMassProperties.Compute(boundaryCurve); RhinoApp.WriteLine("Total area: {0} mm^2", area.Area.ToString("#.##")); double toolArea = punchingToolList[0].getArea() * pointMap.Count; RhinoApp.WriteLine("Tool area: {0} mm^2", toolArea.ToString("#.##")); openArea = toolArea * 100 / area.Area; RhinoApp.WriteLine("Open area: {0}%", openArea.ToString("#.")); // Draw the cluster for each tool for (int i = 0; i < punchingToolList.Count; i++) { // Only draw cluster tool if it is enable if (punchingToolList[i].ClusterTool.Enable == true) { // Draw the cluster tool drawCluster(pointMap, punchingToolList[i]); } } doc.Views.Redraw(); doc.Layers.SetCurrentLayerIndex(currentLayer, true); return(openArea); }
/// <summary> /// Draws the perforation. /// </summary> /// <returns></returns> public override double drawPerforation(Curve boundaryCurve) { PointMap pointMap = new PointMap(); // Find the boundary BoundingBox boundingBox = boundaryCurve.GetBoundingBox(Plane.WorldXY); Point3d min = boundingBox.Min; Point3d max = boundingBox.Max; double spanX = max.X - min.X; double spanY = max.Y - min.Y; int punchQtyX = ((int)((spanX - punchingToolList[1].X) / XSpacing)) + 1; double marginX = (spanX - ((punchQtyX - 1) * XSpacing)) / 2; double YSpacing = XSpacing; int punchQtyY = ((int)((spanY - punchingToolList[1].Y) / YSpacing)) + 1; double marginY = (spanY - ((punchQtyY - 1) * YSpacing)) / 2; Point3d point; RhinoDoc doc = RhinoDoc.ActiveDoc; double firstX = min.X + marginX; double firstY = min.Y + marginY; // Record current layer int currentLayer = doc.Layers.CurrentLayerIndex; int tool0Count = 0; for (int y = 0; y < punchQtyY; y++) { for (int x = 0; x < punchQtyX; x++) { point = new Point3d(firstX + x * XSpacing, firstY + y * YSpacing, 0); if (punchingToolList[0].isInside(boundaryCurve, point) == true) { pointMap.AddPoint(new PunchingPoint(point)); // punchingToolList[0].drawTool(point); tool0Count++; } else { punchingToolList[0].drawTool(point); } } } // Display the open area calculation AreaMassProperties area = AreaMassProperties.Compute(boundaryCurve); RhinoApp.WriteLine("Total area: {0} mm^2", area.Area.ToString("#.##")); double tool0Area = punchingToolList[0].getArea() * tool0Count; RhinoApp.WriteLine("Tool 1 area: {0} mm^2", tool0Area.ToString("#.##")); //double tool1Area = punchingToolList[1].getArea() * tool1Count; //RhinoApp.WriteLine("Tool 2 area: {0} mm^2", tool1Area.ToString("#.##")); //double openArea = (tool0Area + tool1Area) * 100 / area.Area; // RhinoApp.WriteLine("Open area: {0}%", openArea.ToString("#.")); doc.Views.Redraw(); doc.Layers.SetCurrentLayerIndex(currentLayer, true); return(0); }
/// <summary> /// Draws the perforation. /// </summary> /// <returns></returns> public override double drawPerforation(Curve boundaryCurve) { PointMap pointMap = new PointMap(); // Find the boundary BoundingBox boundingBox = boundaryCurve.GetBoundingBox(Plane.WorldXY); Point3d min = boundingBox.Min; Point3d max = boundingBox.Max; double d = Math.Tan(Math.PI / 6) * (XSpacing - punchingToolList[0].X) / 2; double rowHeight = (Math.Sqrt(3) * punchingToolList[0].X / 2) + d; double h = (Math.Sqrt(3) * punchingToolList[0].X / 2); double g = d / Math.Sin(Math.PI / 6); YSpacing = rowHeight + g; double spanX = max.X - min.X; double spanY = max.Y - min.Y; int punchQtyX = ((int)((spanX - punchingToolList[0].X) / (XSpacing / 2))) + 1; double marginX = (spanX - ((punchQtyX - 1) * (XSpacing / 2))) / 2; int punchQtyY = ((int)((spanY - rowHeight) / YSpacing)) + 1; double marginY = (spanY - ((punchQtyY - 1) * YSpacing)) / 2; Point3d point; RhinoDoc doc = RhinoDoc.ActiveDoc; double firstX = min.X + marginX; double firstY = min.Y + marginY; Point3d origin = new Point3d(firstX, firstY, 0); // Record the current layer int currentLayer = doc.Layers.CurrentLayerIndex; // Create Perforation Layer // if (punchingToolList[0].ClusterTool.Enable == true) { doc.Layers.SetCurrentLayerIndex(currentLayer, true); } //else //{ // if (!MetrixUtilities.IsLayerFound("TemporaryPerfLayer")) // { // RhinoUtilities.SetActiveLayer(Properties.Settings.Default.ToolHitLayerName, System.Drawing.Color.Black); // } // else // { // RhinoUtilities.SetActiveLayer("TemporaryToolHit", System.Drawing.Color.Black); // } //} for (int y = 0; y < punchQtyY; y++) { if (y % 2 == 0) // even rows { for (int x = 0; x < punchQtyX; x++) { if (x % 2 == 0) // even location { point = new Point3d(firstX + x * (XSpacing / 2), firstY + y * YSpacing - (rowHeight / 2) + (h / 3), 0); if (punchingToolList[0].isInside(boundaryCurve, point, 0) == true) { pointMap.AddPoint(new PunchingPoint(point)); punchingToolList[0].drawTool(point, 0); } } else { point = new Point3d(firstX + x * (XSpacing / 2), firstY + y * YSpacing + (rowHeight / 2) - (h / 3), 0); if (punchingToolList[0].isInside(boundaryCurve, point, Math.PI) == true) { pointMap.AddPoint(new PunchingPoint(point)); punchingToolList[0].drawTool(point, Math.PI); } } } } else { for (int x = 0; x < punchQtyX; x++) { if (x % 2 == 0) // even location { point = new Point3d(firstX + x * (XSpacing / 2), firstY + y * YSpacing + (rowHeight / 2) - (h / 3), 0); if (punchingToolList[0].isInside(boundaryCurve, point, Math.PI) == true) { pointMap.AddPoint(new PunchingPoint(point)); punchingToolList[0].drawTool(point, Math.PI); } } else { point = new Point3d(firstX + x * (XSpacing / 2), firstY + y * YSpacing - (rowHeight / 2) + (h / 3), 0); if (punchingToolList[0].isInside(boundaryCurve, point, 0) == true) { pointMap.AddPoint(new PunchingPoint(point)); punchingToolList[0].drawTool(point, 0); } } } } } // Display the open area calculation AreaMassProperties area = AreaMassProperties.Compute(boundaryCurve); RhinoApp.WriteLine("Total area: {0} mm^2", area.Area.ToString("#.##")); double toolArea = punchingToolList[0].getArea() * pointMap.Count; RhinoApp.WriteLine("Tool area: {0} mm^2", toolArea.ToString("#.##")); openArea = toolArea * 100 / area.Area; RhinoApp.WriteLine("Open area: {0}%", openArea.ToString("#.")); // Draw the cluster for each tool for (int i = 0; i < punchingToolList.Count; i++) { // Only draw cluster tool if it is enable if (punchingToolList[i].ClusterTool.Enable == true) { // Draw the cluster tool drawCluster(pointMap, punchingToolList[i]); } } doc.Views.Redraw(); doc.Layers.SetCurrentLayerIndex(currentLayer, true); return(openArea); }
void OnGUI() { #region GENERATING NEW LEVEL EditorGUILayout.LabelField("Generate New Level", EditorStyles.boldLabel); pointPrefab = (GeneratedPoint)EditorGUILayout.ObjectField(pointPrefab, typeof(GeneratedPoint), false); if (GUILayout.Button("New Level")) { if (initialPoint != null) { DestroyImmediate(initialPoint); } if (pointPrefab != null) { initialPoint = Instantiate(pointPrefab); } } #endregion DrawUILine(Color.black, 1, 25); #region GENERATING NEW POINT EditorGUILayout.LabelField("Add New Point", EditorStyles.boldLabel); if (GUILayout.Button("New Point")) { GameObject[] selectedObjects = UnityEditor.Selection.gameObjects; GeneratedPoint focusPoint; foreach (GameObject selectedObject in selectedObjects) { if (selectedObject.GetComponent <GeneratedPoint>()) { GeneratedPoint newPoint = Instantiate(pointPrefab); newPoint.transform.parent = selectedObject.transform; newPoint.parentPoint = selectedObject; break; } } } #endregion DrawUILine(Color.black, 1, 25); #region LOADING NEW LEVEL EditorGUILayout.LabelField("Load Existing Level", EditorStyles.boldLabel); loadingPointMap = (PointMap)EditorGUILayout.ObjectField(loadingPointMap, typeof(PointMap), true); if (GUILayout.Button("Load Level")) { //clear current level if (initialPoint != null) { Destroy(initialPoint); } if (loadingPointMap != null) { initialPoint = Instantiate(pointPrefab); initialPoint.transform.position = loadingPointMap.points[0]; Transform previousPoint = initialPoint.transform; foreach (Vector2 pointLocation in loadingPointMap.points) { var nextPoint = Instantiate(pointPrefab); nextPoint.transform.position = pointLocation; nextPoint.transform.parent = previousPoint; nextPoint.parentPoint = previousPoint.gameObject; previousPoint = nextPoint.transform; } } } #endregion DrawUILine(Color.black, 1, 25); #region SAVING GENERATED MAP AS SCRIPTABLE OBJECT EditorGUILayout.LabelField("Save Level", EditorStyles.boldLabel); fileName = GUILayout.TextField(fileName); if (fileName == "") { fileName = "newPointMap"; } if (GUILayout.Button("Save Point Map")) { SaveLevelData(); } #endregion }
/// <summary> /// Draws the perforation. /// </summary> /// <returns></returns> public override double drawPerforation(Curve boundaryCurve) { PointMap pointMap = new PointMap(); Random random = new Random(); // Find the boundary BoundingBox boundingBox = boundaryCurve.GetBoundingBox(Plane.WorldXY); Point3d min = boundingBox.Min; Point3d max = boundingBox.Max; double spanX = max.X - min.X; double spanY = max.Y - min.Y; int punchQtyX = ((int)((spanX - punchingToolList[0].X) / XSpacing)) + 1; double marginX = (spanX - ((punchQtyX - 1) * XSpacing)) / 2; double YSpacing = XSpacing; int punchQtyY = ((int)((spanY - punchingToolList[0].Y) / YSpacing)) + 1; double marginY = (spanY - ((punchQtyY - 1) * YSpacing)) / 2; Point3d point; RhinoDoc doc = RhinoDoc.ActiveDoc; double firstX = min.X + marginX; double firstY = min.Y + marginY; // Record the current layer int currentLayer = doc.Layers.CurrentLayerIndex; // Create Perforation Layer // if (punchingToolList[0].ClusterTool.Enable == true) { doc.Layers.SetCurrentLayerIndex(currentLayer, true); //RhinoUtilities.SetActiveLayer(Properties.Settings.Default.PerforationLayerName, System.Drawing.Color.Green); } //else //{ // if (MetrixUtilities.IsLayerFound("TemporaryPerfLayer")) // { // RhinoUtilities.SetActiveLayer("TemporaryToolHit", System.Drawing.Color.Black); // } // else // { // RhinoUtilities.SetActiveLayer(Properties.Settings.Default.ToolHitLayerName, System.Drawing.Color.Black); // } //} for (int y = 0; y < punchQtyY; y++) { for (int x = 0; x < punchQtyX; x++) { point = new Point3d(firstX + x * XSpacing, firstY + y * YSpacing, 0); if (punchingToolList[0].isInside(boundaryCurve, point) == true) { if (random.NextDouble() < randomness) { pointMap.AddPoint(new PunchingPoint(point)); punchingToolList[0].drawTool(point); } } } } // Display the open area calculation AreaMassProperties area = AreaMassProperties.Compute(boundaryCurve); RhinoApp.WriteLine("Total area: {0} mm^2", area.Area.ToString("#.##")); double toolArea = punchingToolList[0].getArea() * pointMap.Count; RhinoApp.WriteLine("Tool area: {0} mm^2", toolArea.ToString("#.##")); openArea = toolArea * 100 / area.Area; RhinoApp.WriteLine("Open area: {0}%", openArea.ToString("#.")); // Draw the cluster for each tool for (int i = 0; i < punchingToolList.Count; i++) { // Only draw cluster tool if it is enable if (punchingToolList[i].ClusterTool.Enable == true) { // Draw the cluster tool drawCluster(pointMap, punchingToolList[i]); } } doc.Views.Redraw(); // Set the active layer back to where it was doc.Layers.SetCurrentLayerIndex(currentLayer, true); return(openArea); }
/// <summary> /// Draws the perforation. /// </summary> /// <param name="boundaryCurve">The boundary curve.</param> /// <returns></returns> public override double drawPerforation(Curve boundaryCurve) { List <PointMap> pointMapList = new List <PointMap>(); Random random = new Random(); PointMap pointMapTool1 = new PointMap(); int tool0count = 0; int tool1count = 0; int tool2count = 0; double marginX; pointMapList.Add(pointMapTool1); // Find the boundary BoundingBox boundingBox = boundaryCurve.GetBoundingBox(Plane.WorldXY); Point3d min = boundingBox.Min; Point3d max = boundingBox.Max; double spanX = max.X - min.X; double spanY = max.Y - min.Y; double gap = xSpacing - punchingToolList[2].X; // Maximum punching qty int punchQtyX = ((int)((spanX - punchingToolList[2].X) / XSpacing)) + 1; // PunchQty need to add 1 if the last bit can fit the small rectangle if (spanX - (punchingToolList[2].X * punchQtyX) > (punchingToolList[0].X + gap)) { punchQtyX = punchQtyX + 1; } // Find the location of the first punch if (spanX >= ((punchQtyX - 1) * XSpacing + punchingToolList[2].X)) { marginX = (spanX - ((punchQtyX - 2) * XSpacing) - (punchingToolList[2].X) - gap) / 2; } else if (spanX >= ((punchQtyX - 1) * XSpacing + punchingToolList[1].X)) { marginX = (spanX - ((punchQtyX - 2) * XSpacing) - (punchingToolList[1].X) - gap) / 2; } else { marginX = (spanX - ((punchQtyX - 2) * XSpacing) - (punchingToolList[0].X) - gap) / 2; } int punchQtyY = ((int)((spanY - punchingToolList[0].Y) / YSpacing)) + 1; double marginY = (spanY - ((punchQtyY - 1) * YSpacing)) / 2; Point3d point; RhinoDoc doc = RhinoDoc.ActiveDoc; double firstX = min.X + marginX; double firstY = min.Y + marginY; // Record the current layer int currentLayer = doc.Layers.CurrentLayerIndex; // Create Perforation Layer //if (punchingToolList[0].ClusterTool.Enable == true) { doc.Layers.SetCurrentLayerIndex(currentLayer, true); } //else //{ // if (!MetrixUtilities.IsLayerFound("TemporaryPerfLayer")) // { // RhinoUtilities.SetActiveLayer(Properties.Settings.Default.ToolHitLayerName, System.Drawing.Color.Black); // } // else // { // RhinoUtilities.SetActiveLayer("TemporaryToolHit", System.Drawing.Color.Black); // } //} // Random Engine RandomTiler randomTileEngine = new RandomTiler(); int totalQty = (punchQtyX + 1) * punchQtyY; int toolHitQty = (int)(totalQty * randomness); int blankQty = totalQty - toolHitQty; List <int> tileCounts = new List <int>(); tileCounts.Add(toolHitQty); tileCounts.Add(blankQty); int[,] tileMap = randomTileEngine.GetTileMap(tileCounts, punchQtyX + 1, punchQtyY); Point3d pointMedL; Point3d pointMedR; Point3d pointShortL; Point3d pointShortR; Point3d pointLeft, pointRight, pointTop, pointBottom; double toolOffset = XSpacing / 6; double rowOffset = XSpacing / 3; for (int y = 0; y < punchQtyY; y++) { if (y % 3 == 0) // Long tool row { // first X firstX = min.X + marginX; } else if (y % 3 == 1) // Med tool row { firstX = min.X + marginX - rowOffset; } else // short tool rows { firstX = min.X + marginX - (2 * rowOffset); } bool isBorderPunch = false; for (int x = 0; x < punchQtyX + 1; x++) { point = new Point3d(firstX + x * XSpacing, firstY + y * YSpacing, 0); pointMedL = new Point3d(firstX + x * XSpacing - toolOffset, firstY + y * YSpacing, 0); pointMedR = new Point3d(firstX + x * XSpacing + toolOffset, firstY + y * YSpacing, 0); pointShortL = new Point3d(firstX + x * XSpacing - 2 * toolOffset, firstY + y * YSpacing, 0); pointShortR = new Point3d(firstX + x * XSpacing + 2 * toolOffset, firstY + y * YSpacing, 0); pointLeft = new Point3d(firstX + (x - 1) * XSpacing, firstY + y * YSpacing, 0); pointRight = new Point3d(firstX + (x + 1) * XSpacing, firstY + y * YSpacing, 0); pointTop = new Point3d(firstX + x * XSpacing, firstY + (y + 1) * YSpacing, 0); pointBottom = new Point3d(firstX + (x + 1) * XSpacing, firstY + (y - 1) * YSpacing, 0); // Test if the current punch is close to border isBorderPunch = false; if (punchingToolList[0].isInside(boundaryCurve, pointLeft) == false) { isBorderPunch = true; } if (punchingToolList[0].isInside(boundaryCurve, pointRight) == false) { isBorderPunch = true; } if (punchingToolList[0].isInside(boundaryCurve, pointTop) == false) { isBorderPunch = true; } if (punchingToolList[0].isInside(boundaryCurve, pointBottom) == false) { isBorderPunch = true; } if (isBorderPunch == true || tileMap[x, y] == 1) { if (punchingToolList[2].isInside(boundaryCurve, point) == true) { pointMapTool1.AddPoint(new PunchingPoint(point)); punchingToolList[2].drawTool(point); tool2count++; } else if (punchingToolList[1].isInside(boundaryCurve, pointMedL) == true) { pointMapTool1.AddPoint(new PunchingPoint(pointMedL)); punchingToolList[1].drawTool(pointMedL); tool1count++; } else if (punchingToolList[1].isInside(boundaryCurve, pointMedR) == true) { pointMapTool1.AddPoint(new PunchingPoint(pointMedR)); punchingToolList[1].drawTool(pointMedR); tool1count++; } else if (punchingToolList[0].isInside(boundaryCurve, pointShortL) == true) { pointMapTool1.AddPoint(new PunchingPoint(pointShortL)); punchingToolList[0].drawTool(pointShortL); tool0count++; } else if (punchingToolList[0].isInside(boundaryCurve, pointShortR) == true) { pointMapTool1.AddPoint(new PunchingPoint(pointShortR)); punchingToolList[0].drawTool(pointShortR); tool0count++; } } } } // Display the open area calculation AreaMassProperties area = AreaMassProperties.Compute(boundaryCurve); RhinoApp.WriteLine("Total area: {0} mm^2", area.Area.ToString("#.##")); double tool0Area = punchingToolList[0].getArea() * tool0count; double tool1Area = punchingToolList[1].getArea() * tool1count; double tool2Area = punchingToolList[2].getArea() * tool2count; RhinoApp.WriteLine("Tool 1 area: {0} mm^2", tool0Area.ToString("#.##")); RhinoApp.WriteLine("Tool 2 area: {0} mm^2", tool1Area.ToString("#.##")); RhinoApp.WriteLine("Tool 3 area: {0} mm^2", tool2Area.ToString("#.##")); openArea = (tool0Area + tool1Area + tool2Area) * 100 / area.Area; RhinoApp.WriteLine("Open area: {0}%", openArea.ToString("#.")); // Draw the cluster for each tool for (int i = 0; i < punchingToolList.Count; i++) { // Only draw cluster tool if it is enable if (punchingToolList[i].ClusterTool.Enable == true) { // Draw the cluster tool drawCluster(pointMapList[i], punchingToolList[i]); } } doc.Views.Redraw(); doc.Layers.SetCurrentLayerIndex(currentLayer, true); return(openArea); }
public void SetPointMap(PointMap pM) { maps = pM; }
/// <summary> /// Draws the perforation. /// </summary> /// <returns></returns> public override double drawPerforation(Curve boundaryCurve) { List <PointMap> pointMapList = new List <PointMap>(); Random random = new Random(); PointMap pointMapTool1 = new PointMap(); PointMap pointMapTool2 = new PointMap(); pointMapList.Add(pointMapTool1); // Find the boundary BoundingBox boundingBox = boundaryCurve.GetBoundingBox(Plane.WorldXY); Point3d min = boundingBox.Min; Point3d max = boundingBox.Max; // Span are the total length of the area double spanX = max.X - min.X; double spanY = max.Y - min.Y; // Number of holes that can be punch in X. int punchQtyX = ((int)((spanX - punchingToolList[0].X) / XSpacing)) + 1; double secondRowOffset = XSpacing / 2; // Calculate the margin - is the distance from the left border double marginX; if (spanX >= ((punchQtyX - 1) * XSpacing + secondRowOffset + (punchingToolList[0].X / 2) + (punchingToolList[2].X / 2))) { marginX = (spanX - ((punchQtyX - 1) * XSpacing) - secondRowOffset - ((punchingToolList[0].X / 2) + (punchingToolList[2].X / 2))) / 2 + (punchingToolList[0].X / 2); } else { marginX = (spanX - ((punchQtyX - 1) * XSpacing)) / 2; } int punchQtyY = ((int)((spanY - punchingToolList[0].Y) / YSpacing)) + 1; double marginY = 0; if (punchQtyY % 2 == 0) // Even { // Make sure the Tool can fit if the row is even row punchQtyY = ((int)((spanY - (punchingToolList[0].Y / 2) - (punchingToolList[2].Y / 2)) / YSpacing)) + 1; } if (punchQtyY % 2 == 0) // Even Row { marginY = (spanY - ((punchQtyY - 1) * YSpacing) - (punchingToolList[0].Y / 2) - (punchingToolList[2].Y / 2)) / 2 + (punchingToolList[0].Y / 2); } else { marginY = (spanY - ((punchQtyY - 1) * YSpacing)) / 2; } Point3d point; RhinoDoc doc = RhinoDoc.ActiveDoc; double firstX = min.X + marginX; double firstY = min.Y + marginY; // Record the current layer int currentLayer = doc.Layers.CurrentLayerIndex; // Create Perforation Layer // if (punchingToolList[0].ClusterTool.Enable == true) { doc.Layers.SetCurrentLayerIndex(currentLayer, true); } //else //{ // if (!MetrixUtilities.IsLayerFound("TemporaryPerfLayer")) // { // RhinoUtilities.SetActiveLayer(Properties.Settings.Default.ToolHitLayerName, System.Drawing.Color.Black); // } // else // { // RhinoUtilities.SetActiveLayer("TemporaryToolHit", System.Drawing.Color.Black); // } //} for (int y = 0; y < punchQtyY; y++) { if (y % 2 == 0) // even rows { for (int x = 0; x < punchQtyX; x++) { point = new Point3d(firstX + x * XSpacing, firstY + y * YSpacing, 0); if (punchingToolList[0].isInside(boundaryCurve, point) == true) { if (random.NextDouble() < randomness) { pointMapTool1.AddPoint(new PunchingPoint(point)); punchingToolList[0].drawTool(point); } } } } else // odd rows { for (int x = 0; x < punchQtyX; x++) { point = new Point3d(firstX + (x * XSpacing) + secondRowOffset, firstY + y * YSpacing, 0); if (punchingToolList[2].isInside(boundaryCurve, point) == true) { if (random.NextDouble() < randomness) { pointMapTool2.AddPoint(new PunchingPoint(point)); punchingToolList[1].drawTool(point); punchingToolList[2].drawTool(point); } } } } } // Display the open area calculation AreaMassProperties area = AreaMassProperties.Compute(boundaryCurve); RhinoApp.WriteLine("Total area: {0} mm^2", area.Area.ToString("#.##")); double tool1Area = punchingToolList[0].getArea() * pointMapTool1.Count; RhinoApp.WriteLine("Tool 1 area: {0} mm^2", tool1Area.ToString("#.##")); double tool2Area = punchingToolList[1].getArea() * pointMapTool2.Count; RhinoApp.WriteLine("Tool 2 area: {0} mm^2", tool2Area.ToString("#.##")); openArea = (tool1Area + tool2Area) * 100 / area.Area; RhinoApp.WriteLine("Open area: {0}%", openArea.ToString("#.")); doc.Views.Redraw(); // Draw the cluster for each tool for (int i = 0; i < punchingToolList.Count; i++) { // Only draw cluster tool if it is enable if (punchingToolList[i].ClusterTool.Enable == true) { // Draw the cluster tool drawCluster(pointMapList[i], punchingToolList[i]); } } doc.Layers.SetCurrentLayerIndex(currentLayer, true); return(openArea); }
// Update is called once per frame void Update() { float rotateHorizontal = Input.GetAxis("Horizontal"); float moveFrontBack = Input.GetAxis("Vertical"); transform.Translate(0.0f, 0.0f, moveFrontBack); transform.Rotate(0.0f, rotateHorizontal, 0.0f); var moveRight = Input.GetKey(KeyCode.Y); //Y. if (moveRight) { transform.Translate(20f, 0.0f, 0.0f); } var moveLeft = Input.GetKey(KeyCode.R); //T if (moveLeft) { transform.Translate(-20f, 0.0f, 0.0f); } var moveUp = Input.GetKey(KeyCode.PageUp); if (moveUp) { transform.Translate(0.0f, 20f, 0.0f); } var moveDown = Input.GetKey(KeyCode.PageDown); if (moveDown) { transform.Translate(0.0f, -20f, 0.0f); } var rotateHeadingRight = Input.GetKey(KeyCode.H); if (rotateHeadingRight) { transform.Rotate(0.0f, 1f, 0.0f); } var rotateHeadingLeft = Input.GetKey(KeyCode.F); //G if (rotateHeadingLeft) { transform.Rotate(0.0f, -1f, 0.0f); } var rotatePitchDown = Input.GetKey(KeyCode.G); //O if (rotatePitchDown) { transform.Rotate(1f, 0.0f, 0.0f); } var rotatePitchUp = Input.GetKey(KeyCode.T); //P if (rotatePitchUp) { transform.Rotate(-1f, 0.0f, 0.0f); } var rotateRollLeft = Input.GetKey(KeyCode.O); //E if (rotateRollLeft) { transform.Rotate(0.0f, 0.0f, 0.5f); } var rotateRollRight = Input.GetKey(KeyCode.P); //R if (rotateRollRight) { transform.Rotate(0.0f, 0.0f, -0.5f); } var mousePosition = Input.mousePosition; Vector3 point = new Vector3(); point = Camera.main.ScreenToWorldPoint(new Vector3(mousePosition.x, mousePosition.y, Camera.main.nearClipPlane)); // begin.transform.position = point ; var informationRequired = Input.GetKeyDown(KeyCode.F1); if (informationRequired) { print("informationRequired at " + point); RaycastHit hit; if (Physics.Raycast(transform.position, point - transform.position, out hit, Mathf.Infinity)) { Debug.Log("Did Hit"); Debug.Log("Target Position: " + hit.collider.gameObject.transform.position); Debug.Log("Hit point : " + hit.point); PointMap pointMap = hit.collider.gameObject.GetComponentInParent <PointMap> (); if (pointMap != null) { SphereCollider sc = pointMap.GetComponent <SphereCollider> (); sc.enabled = false; if (Physics.Raycast(transform.position, point - transform.position, out hit, Mathf.Infinity)) { Debug.Log("Did Hit again"); Debug.Log("Target Position: " + hit.collider.gameObject.transform.position); Debug.Log("Hit point : " + hit.point); Debug.Log("Hit triangle index : " + hit.triangleIndex); pointMap = hit.collider.gameObject.GetComponentInParent <PointMap> (); if (pointMap != null) { print(pointMap.GetProperty(hit.triangleIndex)); } else { Debug.Log("Did not Hit this time"); } } else { Debug.Log("But not on a PointMap"); } sc.enabled = true; } } else { Debug.Log("Did not Hit"); } } }
public Map(string MapID) { var stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); Console.WriteLine("Initializing Map: {0}", MapID); this.MapID = MapID; var mapData = (JObject)(Loader.data.geometry)[MapID]; var mapDef = (JObject)(Loader.data.maps)[MapID]; if (mapData != null) { var MinX = (int)(((dynamic)mapData["min_x"]) ?? -1000); var MinY = (int)(((dynamic)mapData["min_y"]) ?? -1000); var MaxX = (int)(((dynamic)mapData["max_x"]) ?? 1000); var MaxY = (int)(((dynamic)mapData["max_y"]) ?? 1000); if ((dynamic)mapDef["no_bounds"] == true) { MinX = -1000; MaxX = 1000; MinY = -1000; MaxY = 1000; } Width = Math.Abs(MaxX) + Math.Abs(MinX); Height = Math.Abs(MaxY) + Math.Abs(MinY); OffsetX = Math.Abs(MinX); OffsetY = Math.Abs(MinY); List <Line> lines = new List <Line>(); if (mapData.Properties().Where(p => p.Name == "x_lines").FirstOrDefault() != null) { foreach (var xLine in mapData["x_lines"]) { var line = new Line(new Point((int)xLine[0], (int)xLine[1]), new Point((int)xLine[0], (int)xLine[2])); if (line.Points.Length > 1) { lines.Add(line); } } } if (mapData.Properties().Where(p => p.Name == "y_lines").FirstOrDefault() != null) { foreach (var yLine in mapData["y_lines"]) { var line = new Line(new Point((int)yLine[1], (int)yLine[0]), new Point((int)yLine[2], (int)yLine[0])); if (line.Points.Length > 1) { lines.Add(line); } } } PointMap = new PointMap(Width, Height, OffsetX, OffsetY); int xBufferMin = 9; int xBufferMax = 9; int yBufferMin = 4; int yBufferMax = 8; foreach (var line in lines) { PointMap.DrawWall(line, xBufferMin, xBufferMax, yBufferMin, yBufferMax); } var spawns = ((JObject)(Loader.data.maps))[MapID]["spawns"]; List <Point> spawnPoints = new List <Point>(); foreach (var spawn in spawns) { var spawnPoint = new Point((int)spawn[0], (int)spawn[1]); spawnPoints.Add(spawnPoint); } PointMap.FillInterior(spawnPoints); PointMap.FillExterior(); var p1 = new Point(MinX, MinY); var p2 = new Point(MinX, MaxY); var p3 = new Point(MaxX, MaxY); var p4 = new Point(MaxX, MinY); PointMap.DrawWall(new Line(p1, p2), xBufferMin, xBufferMax, yBufferMin, yBufferMax); PointMap.DrawWall(new Line(p2, p3), xBufferMin, xBufferMax, yBufferMin, yBufferMax); PointMap.DrawWall(new Line(p3, p4), xBufferMin, xBufferMax, yBufferMin, yBufferMax); PointMap.DrawWall(new Line(p4, p1), xBufferMin, xBufferMax, yBufferMin, yBufferMax); System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch(); poly = PointMap.BuildPolygon(); Mesh = BuildMesh(); this.edges = PointMap.GetEdges(); PointMap.FillMeshEdges(Mesh); graph = new MapGraph(Mesh, PointMap, OffsetX, OffsetY); GetMapConnections(); stopwatch.Stop(); Console.WriteLine("Initialized Map: {0} in {1}ms", MapID, stopwatch.ElapsedMilliseconds); } else { throw new Exception("Map Doesn't Exist."); } }
public static void DrawBitmap(FastBitmap oTexture, Point topLeft, Point topRight, Point bottomRight, Point bottomLeft, FastBitmap oCanvas) { //top line float nDeltaX = topRight.X - topLeft.X; float nDeltaY = topRight.Y - topLeft.Y; float nNumOfPixels = Math.Max(Math.Abs(nDeltaX), Math.Abs(nDeltaY)); //nNumOfPixels *= 2; float nIncrementX = nDeltaX / nNumOfPixels; float nIncrementY = nDeltaY / nNumOfPixels; FastPointF oPixel = new FastPointF(topLeft.X, topLeft.Y); float nTextureIncrementX = (oTexture.Width / (nNumOfPixels + 1)); float nTextureX = 0; PointMap[] oTopLine = new PointMap[(int)(nNumOfPixels + 1)]; for (int nCurrentPixel = 0; nCurrentPixel <= nNumOfPixels; nCurrentPixel++) { oTopLine[nCurrentPixel] = new PointMap(new FastPointF(nTextureX, 0), oPixel); nTextureX += nTextureIncrementX; oPixel.X += nIncrementX; oPixel.Y += nIncrementY; } //bottom line nDeltaX = bottomRight.X - bottomLeft.X; nDeltaY = bottomRight.Y - bottomLeft.Y; nNumOfPixels = Math.Max(Math.Abs(nDeltaX), Math.Abs(nDeltaY)); //nNumOfPixels *= 2; nIncrementX = nDeltaX / nNumOfPixels; nIncrementY = nDeltaY / nNumOfPixels; oPixel = new FastPointF(bottomLeft.X, bottomLeft.Y); nTextureIncrementX = (oTexture.Width / (nNumOfPixels + 1)); nTextureX = 0; PointMap[] oBottomLine = new PointMap[(int)(nNumOfPixels + 1)]; for (int nCurrentPixel = 0; nCurrentPixel <= nNumOfPixels; nCurrentPixel++) { oBottomLine[nCurrentPixel] = new PointMap(new FastPointF(nTextureX, oTexture.Height - 1), oPixel); oPixel.X += nIncrementX; oPixel.Y += nIncrementY; nTextureX += nTextureIncrementX; } //cross lines PointMap[] oStartLine = oTopLine.Length > oBottomLine.Length ? oTopLine : oBottomLine; PointMap[] oEndLine = oTopLine.Length > oBottomLine.Length ? oBottomLine : oTopLine; float nFactor = (float)oEndLine.Length / (float)oStartLine.Length; Rectangle oBox = _ComputeBox(topLeft, topRight, bottomLeft, bottomRight); Boolean[,] oPainted = new Boolean[oBox.Width + 1, oBox.Height + 1]; for (int s = 0; s < oStartLine.Length; s++) { FastPointF oStart = oStartLine[s].To; FastPointF oStartTexture = oStartLine[s].From; float nEndPoint = (float)Math.Floor(nFactor * s); FastPointF oEnd = oEndLine[(int)nEndPoint].To; FastPointF oEndTexture = oEndLine[(int)nEndPoint].From; nDeltaX = oEnd.X - oStart.X; nDeltaY = oEnd.Y - oStart.Y; nNumOfPixels = Math.Max(Math.Abs(nDeltaX), Math.Abs(nDeltaY)); //nNumOfPixels *= 2; nIncrementX = nDeltaX / nNumOfPixels; nIncrementY = nDeltaY / nNumOfPixels; float nTextureDeltaX = oEndTexture.X - oStartTexture.X; float nTextureDeltaY = oEndTexture.Y - oStartTexture.Y; nTextureIncrementX = nTextureDeltaX / (nNumOfPixels + 1); float nTextureIncrementY = nTextureDeltaY / (nNumOfPixels + 1); FastPointF oDestination = oStart; FastPointF oSource = oStartTexture; for (int nCurrentPixel = 0; nCurrentPixel <= nNumOfPixels; nCurrentPixel++) { RGBColor c = oTexture.GetPixel((int)oSource.X, (int)oSource.Y); oCanvas.SetPixel((int)oDestination.X, (int)oDestination.Y, c); oPainted[(int)(oDestination.X - oBox.X), (int)(oDestination.Y - oBox.Y)] = true; oDestination.X += nIncrementX; oDestination.Y += nIncrementY; oSource.X += nTextureIncrementX; oSource.Y += nTextureIncrementY; } } //paint missing pixels for (int ny = 0; ny < oBox.Height; ny++) { for (int nx = 0; nx < oBox.Width; nx++) { if (oPainted[nx, ny] == true) { continue; } int nNeigh = 0; RGBColor oColor; int R = 0; int G = 0; int B = 0; if (nx > 0 && oPainted[nx - 1, ny] == true) { oColor = oCanvas.GetPixel((nx + oBox.X) - 1, (ny + oBox.Y)); R += oColor.R; G += oColor.G; B += oColor.B; nNeigh++; } if (ny > 0 && oPainted[nx, ny - 1] == true) { oColor = oCanvas.GetPixel((nx + oBox.X), (ny + oBox.Y) - 1); R += oColor.R; G += oColor.G; B += oColor.B; nNeigh++; } if (nx < oCanvas.Width - 1 && oPainted[nx + 1, ny] == true) { oColor = oCanvas.GetPixel((nx + oBox.X) + 1, (ny + oBox.Y)); R += oColor.R; G += oColor.G; B += oColor.B; nNeigh++; } if (ny < oCanvas.Height - 1 && oPainted[nx, ny + 1] == true) { oColor = oCanvas.GetPixel((nx + oBox.X), (ny + oBox.Y) + 1); R += oColor.R; G += oColor.G; B += oColor.B; nNeigh++; } if (nNeigh == 0) { continue; } oCanvas.SetPixel((nx + oBox.X), (ny + oBox.Y), new RGBColor((byte)(R / nNeigh), (byte)(G / nNeigh), (byte)(B / nNeigh))); } } }
/// <summary> /// Draws the cluster. /// </summary> /// <param name="pointMap">The point map.</param> /// <param name="punchingTool">The punching tool.</param> /// <returns></returns> public override Result drawCluster(PointMap pointMap, PunchingTool punchingTool) { RhinoDoc doc = RhinoDoc.ActiveDoc; List <PunchingPoint> clusterPoints = new List <PunchingPoint>(); List <Point3d> clusterRelativePoints = new List <Point3d>(); int clusterCounter = 0; // Create a new layer string layerName = Properties.Settings.Default.ToolHitLayerName; // Does a layer with the same name already exist? int layerIndex = doc.Layers.Find(layerName, true); // If layer does not exist if (layerIndex == -1) { // Add a new layer to the document layerIndex = doc.Layers.Add(layerName, System.Drawing.Color.Black); } int currentLayer = doc.Layers.CurrentLayerIndex; doc.Layers.SetCurrentLayerIndex(layerIndex, true); // Create the cluster tool that has the relative position for (int y = 0; y < punchingTool.ClusterTool.PinsY; y++) { for (int x = 0; x < punchingTool.ClusterTool.PinsX; x++) { clusterRelativePoints.Add(new Point3d(x * XSpacing * punchingTool.ClusterTool.MultiplierX, y * YSpacing * punchingTool.ClusterTool.MultiplierY, 0)); } } Point2d centre = new Point2d(clusterRelativePoints.Last().X / 2, clusterRelativePoints.Last().Y / 2); // Go through each point in the point Map list to find cluster tool starting from bottom left corner for (int i = 0; i < pointMap.YCount; i++) { SortedDictionary <int, PunchingPoint> xDict = pointMap.getXDictionary(i); for (int j = 0; j < xDict.Count; j++) { // If the point has already punched, ignore it. if (xDict.ElementAt(j).Value.HasPunched == true) { continue; } // Clear the cluster points clusterPoints.Clear(); // Add the first point to it clusterPoints.Add(xDict.ElementAt(j).Value); // Cluster tool X+ Y+ configuration for (int k = 1; k < clusterRelativePoints.Count; k++) { // Look for point in the point list PunchingPoint resultPoint = pointMap.getPoint2(clusterPoints[0].Point.X + clusterRelativePoints[k].X, clusterPoints[0].Point.Y + clusterRelativePoints[k].Y); if (resultPoint == null) { // Cannot find point in the cluster tool, then skip break; } else { clusterPoints.Add(resultPoint); } } // If all the points are added if (clusterPoints.Count == clusterRelativePoints.Count) { double clusterX = centre.X + clusterPoints[0].Point.X; double clusterY = centre.Y + clusterPoints[0].Point.Y; // Draw all the points in the cluster tool clusterCounter++; if (Properties.Settings.Default.DrawClusterOnSeparateLayer == true) { doc.Layers.SetCurrentLayerIndex(CreateLayer("Cluster " + clusterCounter), true); doc.Views.Redraw(); } foreach (PunchingPoint pp in clusterPoints) { if (Properties.Settings.Default.DrawClusterOnSeparateLayer == true) { // Draw the tool punchingTool.drawTool(pp.Point); } // Remove all the points in the clustertool list pp.HasPunched = true; } // Draw the rectangle punchingTool.ClusterTool.drawClusterTool(clusterX, clusterY, 0); } } } // If the Cluster tool allow over punch have to do some more work if (punchingTool.ClusterTool.AllowOverPunch == true) { // Bottom right search // Clear the cluster tool points clusterRelativePoints.Clear(); // Create the cluster tool that has the relative position for (int y = 0; y < punchingTool.ClusterTool.PinsY; y++) { for (int x = 0; x < punchingTool.ClusterTool.PinsX; x++) { clusterRelativePoints.Add(new Point3d(-x * XSpacing * punchingTool.ClusterTool.MultiplierX, y * YSpacing * punchingTool.ClusterTool.MultiplierY, 0)); } } // Go through each point in the point Map list to find cluster tool starting from bottom right corner for (int i = 0; i < pointMap.YCount; i++) { SortedDictionary <int, PunchingPoint> xDict = pointMap.getXDictionary(i); for (int j = xDict.Count - 1; j >= 0; j--) { // If the point is punched, skip to the next point if (xDict.ElementAt(j).Value.HasPunched == true) { continue; } clusterPoints.Clear(); clusterPoints.Add(xDict.ElementAt(j).Value); // Cluster tool X- Y+ configuration for (int k = 1; k < clusterRelativePoints.Count; k++) { // Look for point in the point list PunchingPoint resultPoint = pointMap.getPoint2(clusterPoints[0].Point.X + clusterRelativePoints[k].X, clusterPoints[0].Point.Y + clusterRelativePoints[k].Y); if (resultPoint == null) { // Cannot find point in the cluster tool, then skip break; } else { clusterPoints.Add(resultPoint); } } // If all the points are added if (clusterPoints.Count == clusterRelativePoints.Count) { double clusterX = clusterPoints[0].Point.X - centre.X; double clusterY = clusterPoints[0].Point.Y + centre.Y; // Draw all the points in the cluster tool clusterCounter++; if (Properties.Settings.Default.DrawClusterOnSeparateLayer == true) { doc.Layers.SetCurrentLayerIndex(CreateLayer("Cluster " + clusterCounter), true); } foreach (PunchingPoint pp in clusterPoints) { if (Properties.Settings.Default.DrawClusterOnSeparateLayer == true) { // Draw the tool punchingTool.drawTool(pp.Point); } // Remove all the points in the clustertool list pp.HasPunched = true; } // draw the rectangle punchingTool.ClusterTool.drawClusterTool(clusterX, clusterY, 0); } } } // Top Left corner search // Clear the cluster tool points clusterRelativePoints.Clear(); // Create the cluster tool that has the relative position for (int y = 0; y < punchingTool.ClusterTool.PinsY; y++) { for (int x = 0; x < punchingTool.ClusterTool.PinsX; x++) { clusterRelativePoints.Add(new Point3d(x * XSpacing * punchingTool.ClusterTool.MultiplierX, -y * YSpacing * punchingTool.ClusterTool.MultiplierY, 0)); } } // Go through each point in the point Map list to find cluster tool starting from top left for (int i = pointMap.YCount - 1; i >= 0; i--) { SortedDictionary <int, PunchingPoint> xDict = pointMap.getXDictionary(i); for (int j = 0; j < xDict.Count; j++) { // If the point is punched, skip to the next point if (xDict.ElementAt(j).Value.HasPunched == true) { continue; } clusterPoints.Clear(); clusterPoints.Add(xDict.ElementAt(j).Value); // Cluster tool X- Y+ configuration for (int k = 1; k < clusterRelativePoints.Count; k++) { // Look for point in the point list PunchingPoint resultPoint = pointMap.getPoint2(clusterPoints[0].Point.X + clusterRelativePoints[k].X, clusterPoints[0].Point.Y + clusterRelativePoints[k].Y); if (resultPoint == null) { // Cannot find point in the cluster tool, then skip break; } else { clusterPoints.Add(resultPoint); } } // If all the points are added if (clusterPoints.Count == clusterRelativePoints.Count) { double clusterX = clusterPoints[0].Point.X + centre.X; double clusterY = clusterPoints[0].Point.Y - centre.Y; // Draw all the points in the cluster tool clusterCounter++; if (Properties.Settings.Default.DrawClusterOnSeparateLayer == true) { doc.Layers.SetCurrentLayerIndex(CreateLayer("Cluster " + clusterCounter), true); } foreach (PunchingPoint pp in clusterPoints) { if (Properties.Settings.Default.DrawClusterOnSeparateLayer == true) { // Draw the tool punchingTool.drawTool(pp.Point); } // Remove all the points in the clustertool list pp.HasPunched = true; } // draw the rectangle punchingTool.ClusterTool.drawClusterTool(clusterX, clusterY, 0); } } } // Top right corner search // Clear the cluster tool points clusterRelativePoints.Clear(); // Create the cluster tool that has the relative position for (int y = 0; y < punchingTool.ClusterTool.PinsY; y++) { for (int x = 0; x < punchingTool.ClusterTool.PinsX; x++) { clusterRelativePoints.Add(new Point3d(-x * XSpacing * punchingTool.ClusterTool.MultiplierX, -y * YSpacing * punchingTool.ClusterTool.MultiplierY, 0)); } } centre = new Point2d(-clusterRelativePoints.Last().X / 2, -clusterRelativePoints.Last().Y / 2); // Go through each point in the point Map list to find cluster tool starting from top right for (int i = pointMap.YCount - 1; i >= 0; i--) { SortedDictionary <int, PunchingPoint> xDict = pointMap.getXDictionary(i); for (int j = xDict.Count - 1; j >= 0; j--) { // If the point is punched, skip to the next point if (xDict.ElementAt(j).Value.HasPunched == true) { continue; } clusterPoints.Clear(); clusterPoints.Add(xDict.ElementAt(j).Value); // Cluster tool X- Y+ configuration for (int k = 1; k < clusterRelativePoints.Count; k++) { // Look for point in the point list PunchingPoint resultPoint = pointMap.getPoint2(clusterPoints[0].Point.X + clusterRelativePoints[k].X, clusterPoints[0].Point.Y + clusterRelativePoints[k].Y); if (resultPoint == null) { // Cannot find point in the cluster tool, then skip break; } else { clusterPoints.Add(resultPoint); } } // If all the points are added if (clusterPoints.Count == clusterRelativePoints.Count) { double clusterX = clusterPoints[0].Point.X - centre.X; double clusterY = clusterPoints[0].Point.Y - centre.Y; // Draw all the points in the cluster tool clusterCounter++; if (Properties.Settings.Default.DrawClusterOnSeparateLayer == true) { doc.Layers.SetCurrentLayerIndex(CreateLayer("Cluster " + clusterCounter), true); } foreach (PunchingPoint pp in clusterPoints) { if (Properties.Settings.Default.DrawClusterOnSeparateLayer == true) { // Draw the tool punchingTool.drawTool(pp.Point); } // Remove all the points in the clustertool list pp.HasPunched = true; } // draw the cluster tool punchingTool.ClusterTool.drawClusterTool(clusterX, clusterY, 0); } } } } doc.Layers.SetCurrentLayerIndex(layerIndex, true); // Places where cannot cluster punch for (int i = 0; i < pointMap.YCount; i++) { SortedDictionary <int, PunchingPoint> xDict = pointMap.getXDictionary(i); for (int j = 0; j < xDict.Count; j++) { if (xDict.ElementAt(j).Value.HasPunched == false) { // Draw the tool punchingTool.drawTool(xDict.ElementAt(j).Value.Point); } } } doc.Views.Redraw(); doc.Layers.SetCurrentLayerIndex(currentLayer, true); return(Result.Success); }