private void Button_Step_Click(object sender, RoutedEventArgs e) { HashSet <Vector2i> failPoses = null; state.UpdateVisualizationAfterIteration = visualizeUnsetPixels; for (int i = 0; i < stepIncrement; ++i) { var status = state.Iterate(ref failPoses); if (status.HasValue) { Button_Step.IsEnabled = false; if (!status.Value) { Vector2i failPos = failPoses.First(); Label_Failed.Content = "Failed at: " + failPos.x + "," + failPos.y; } break; } else if (false) { //See if the constraints got violated somehow. //If they did, make this obvious by modifying the color of positions that violate it. var outputPixelGetter = state.OutputPixelGetter; var outputColorGetter = state.OutputColorGetter; HashSet <Vector2i> toClear = new HashSet <Vector2i>(); foreach (Vector2i pos in new Vector2i.Iterator(-state.Input.MaxPatternSize, state.Output.SizeXY())) { Vector2i v = pos; if (!state.Input.Patterns.Any(patt => patt.DoesFit(pos, outputColorGetter))) { toClear.Add(pos); } } foreach (Vector2i posToClear in toClear) { var pixel = outputPixelGetter(posToClear); if (pixel != null) { Color?oldVal = pixel.FinalValue; Color newVal = (oldVal.HasValue ? Color.FromRgb(oldVal.Value.R, 100, oldVal.Value.B) : Color.FromRgb(0, 255, 0)); pixel.FinalValue = newVal; pixel.VisualizedValue = newVal; } } } } UpdateOutputTex(); }
private void stepPool(object _) { try { HashSet <Vector2i> failPoses = null; state.UpdateVisualizationAfterIteration = visualizeUnsetPixels; for (int i = 0; isInfinityLoop || i < stepIncrement; ++i) { if (breakPool) { break; } bool?status = state.Iterate(ref failPoses); Dispatcher.Invoke(() => { if (breakPool) { return; } lock (lockPool) { UpdateOutputTex(); if (isInfinityLoop) { Label_status.Content = $"{i + 1}"; } else { Label_status.Content = $"{i + 1} / {stepIncrement}"; } } }); if (breakPool) { break; } if (status.HasValue) { Dispatcher.Invoke(() => { Button_Step.IsEnabled = false; if (!status.Value) { Vector2i failPos = failPoses.First(); Label_Failed.Content = "Failed at: " + failPos.x + "," + failPos.y; } }); break; } } Dispatcher.Invoke(() => UpdateOutputTex()); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Dispatcher.Invoke(() => { // enable Button_Step.IsEnabled = true; Button_Step.Content = "Start"; infinityLoopFlag.IsEnabled = true; Button_SaveToFile.IsEnabled = true; Textbox_StepIncrement.IsReadOnly = false; }); poolIsOn = false; } }