/// <summary> /// Sets the specified algorithm as the input at the specified index. /// </summary> /// <remarks> /// This function also automatically updates the seed value for the /// new input layer as well. /// </remarks> public void SetInput(int index, RuntimeLayer input) { if (!this.CanBeInput(index, input)) { throw new InvalidOperationException("Specified algorithm can not be set as input at this index."); } this.m_Inputs[index] = input; if (this.m_Inputs[index] != null) { this.m_Inputs[index].SetSeed(this.Seed); } }
/// <summary> /// Determines whether or not the specified input algorithm can be used as an /// input for the current algorithm in the specified index slot. /// </summary> public bool CanBeInput(int index, RuntimeLayer input) { if (input == null) { return(true); } if (index < 0 || index >= this.m_Algorithm.InputTypes.Length) { return(false); } return(input.m_Algorithm.OutputType == this.m_Algorithm.InputTypes[index]); }
public AnalyseForm( IStorageAccess storageAccess, FlowElement flowElement) { this.InitializeComponent(); this.m_Layer = storageAccess.ToRuntime(((AlgorithmFlowElement)flowElement).Layer); this.c_AnalysisAddOptionsMenu.Items.AddRange(( from assembly in AppDomain.CurrentDomain.GetAssemblies() from type in assembly.GetTypes() where typeof(AnalysisEngine).IsAssignableFrom(type) && !type.IsGenericType && !type.IsAbstract select new TypeWrapper(type)).ToArray()); }
public ExportForm( IRenderingLocationProvider renderingLocationProvider, IStorageAccess storageAccess, FlowElement flowElement) { this.InitializeComponent(); this.m_StorageAccess = storageAccess; this.m_RenderingLocationProvider = renderingLocationProvider; this.m_Layer = this.m_StorageAccess.ToRuntime(((AlgorithmFlowElement)flowElement).Layer); this.m_Bitmap = new Bitmap(1024 + 32, 1024 + 256); this.c_RenderBox.Image = this.m_Bitmap; this.c_Timer.Start(); }
public TraceForm( IStorageAccess storageAccess, IAlgorithmTraceImageGeneration algorithmTraceImageGeneration, FlowElement flowElement, ICurrentWorldSeedProvider currentWorldSeedProvider) { this.m_AlgorithmTraceImageGeneration = algorithmTraceImageGeneration; this.InitializeComponent(); this.m_Layer = storageAccess.ToRuntime(((AlgorithmFlowElement)flowElement).Layer); this.m_Layer.SetSeed(currentWorldSeedProvider.Seed); this.c_FormZoomSize.Items.Add(new ZoomLevel { Level = 1 }); this.c_FormZoomSize.Items.Add(new ZoomLevel { Level = 2 }); this.c_FormZoomSize.SelectedIndex = 0; }
/// <summary> /// Converts the loaded storage layer into a runtime layer. /// </summary> public static RuntimeLayer ToRuntime(StorageLayer layer) { // Handle null conversion. if (layer == null) { return(null); } // Convert runtime layer. var runtime = new RuntimeLayer(layer.Algorithm); if (layer.Inputs != null) { for (var i = 0; i < layer.Inputs.Length; i++) { runtime.SetInput(i, StorageAccess.ToRuntime(layer.Inputs[i])); } } return(runtime); }
/// <summary> /// Converts the runtime layer representation into /// a storage layer so that it can be saved. /// </summary> public static StorageLayer FromRuntime(RuntimeLayer layer) { // Handle null conversion. if (layer == null) { return(null); } // Create storage. var storage = new StorageLayer { Algorithm = layer.Algorithm }; // Convert inputs. for (int i = 0; i < layer.GetInputs().Length; i++) { storage.Inputs[i] = StorageAccess.FromRuntime(layer.GetInputs()[i]); } // Return storage. return(storage); }
/// <summary> /// Converts the loaded storage layer into a runtime layer. /// </summary> public RuntimeLayer ToRuntime(StorageLayer layer) { // Handle null conversion. if (layer == null) return null; // Convert runtime layer. var runtime = new RuntimeLayer( this.m_Pool, this.m_ArrayPool, layer.Algorithm, this.m_AssetManagerProvider); if (layer.Inputs != null) for (var i = 0; i < layer.Inputs.Length; i++) runtime.SetInput(i, ToRuntime(layer.Inputs[i])); return runtime; }
private void PerformOperationRecursively(Action<RuntimeLayer> operation, RuntimeLayer layer) { operation(layer); foreach (var input in layer.GetInputs().Where(input => input != null)) PerformOperationRecursively(operation, input); }
private Bitmap RenderPartial3D(RuntimeLayer layer, int sx, int sy, int sz, int width, int height, int depth) { var bitmap = new Bitmap(width * 2, height * 3); var graphics = Graphics.FromImage(bitmap); graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit; int[] data; try { int computations; layer.SetSeed(12345); data = layer.GenerateData( this.m_RenderingLocationProvider.X + sx, this.m_RenderingLocationProvider.Y + sy, this.m_RenderingLocationProvider.Z + sz, width, height, depth, out computations); var render = GetCellRenderOrder(RenderToNE, width, height); var ztop = layer.Algorithm.Is2DOnly ? 1 : depth; var zbottom = 0; for (var z = zbottom; z < ztop; z++) { var rcx = width / 2 - 1 + 16; var rcy = height / 2 - 15 + 32; var rw = 2; var rh = 1; for (var i = 0; i < render.Length; i++) { // Calculate the X / Y of the tile in the grid. var x = render[i] % width; var y = render[i] / width; // Calculate the render position on screen. var rx = rcx + (int) ((x - y) / 2.0 * rw); var ry = rcy + (x + y) * rh - (rh / 2 * (width + height)) - (z - zbottom) * 1; while (true) { try { Color lc; if (layer.GetInputs().Length > 0) lc = layer.Algorithm.GetColorForValue( this.m_StorageAccess.FromRuntime(layer.GetInputs()[0]), data[x + (y * width) + (z * width * height)]); else lc = layer.Algorithm.GetColorForValue( null, data[x + (y * width) + (z * width * height)]); var sb = new SolidBrush(Color.FromArgb(lc.A, lc.R, lc.G, lc.B)); graphics.FillRectangle( sb, new Rectangle(rx, ry, rw, rh)); break; } catch (InvalidOperationException) { // Graphics can be in use elsewhere, but we don't care; just try again. } } } } } catch (Exception) { } return bitmap; }
// Just finding offsets, then use them to determine max width, start X location, etc. public static void FindMaximumOffsets( RuntimeLayer layer, out int offsetX, out int offsetY, out int offsetZ, out int halfX, out int halfY, out int halfZ) { if (layer == null) { throw new ArgumentNullException("layer"); } offsetX = 0; offsetY = 0; offsetZ = 0; halfX = 0; halfY = 0; halfZ = 0; if (layer.m_Inputs.Length != 0) { int inputs = 0; var TempOffsetX = new int[layer.m_Inputs.Length]; var TempOffsetY = new int[layer.m_Inputs.Length]; var TempOffsetZ = new int[layer.m_Inputs.Length]; var TempHalfX = new int[layer.m_Inputs.Length]; var TempHalfY = new int[layer.m_Inputs.Length]; var TempHalfZ = new int[layer.m_Inputs.Length]; foreach (var input in layer.m_Inputs) { if (input == null) { continue; } // can't just divide offsets after half by half // // TempOffsetX[inputs] += (layer.m_Algorithm.InputWidthAtHalfSize[inputs] ? Math.Abs(layer.m_Algorithm.RequiredXBorder[inputs]) * 2 : Math.Abs(layer.m_Algorithm.RequiredXBorder[inputs])); // TempOffsetY[inputs] += (layer.m_Algorithm.InputHeightAtHalfSize[inputs] ? Math.Abs(layer.m_Algorithm.RequiredYBorder[inputs]) * 2 : Math.Abs(layer.m_Algorithm.RequiredYBorder[inputs])); // TempOffsetZ[inputs] += (layer.m_Algorithm.InputDepthAtHalfSize[inputs] ? Math.Abs(layer.m_Algorithm.RequiredZBorder[inputs]) * 2 : Math.Abs(layer.m_Algorithm.RequiredZBorder[inputs])); TempHalfX[inputs] += (layer.m_Algorithm.InputWidthAtHalfSize[inputs] ? 1 : 0); TempHalfY[inputs] += (layer.m_Algorithm.InputHeightAtHalfSize[inputs] ? 1 : 0); TempHalfZ[inputs] += (layer.m_Algorithm.InputDepthAtHalfSize[inputs] ? 1 : 0); TempOffsetX[inputs] += Math.Abs(layer.m_Algorithm.RequiredXBorder[inputs]); TempOffsetY[inputs] += Math.Abs(layer.m_Algorithm.RequiredYBorder[inputs]); TempOffsetZ[inputs] += Math.Abs(layer.m_Algorithm.RequiredZBorder[inputs]); FindMaximumOffsets(input, out offsetX, out offsetY, out offsetZ, out halfX, out halfY, out halfZ); TempOffsetX[inputs] += offsetX; TempOffsetY[inputs] += offsetY; TempOffsetZ[inputs] += offsetZ; TempHalfX[inputs] += halfX; TempHalfY[inputs] += halfY; TempHalfZ[inputs] += halfZ; inputs++; } for (int count = 0; count < inputs; count++) { if (offsetX < TempOffsetX[count]) { offsetX = TempOffsetX[count]; } if (offsetY < TempOffsetY[count]) { offsetY = TempOffsetY[count]; } if (offsetZ < TempOffsetZ[count]) { offsetZ = TempOffsetZ[count]; } if (halfX < TempHalfX[count]) { halfX = TempHalfX[count]; } if (halfY < TempHalfY[count]) { halfY = TempHalfY[count]; } if (halfZ < TempHalfZ[count]) { halfZ = TempHalfZ[count]; } } } }
/// <summary> /// Compiles the runtime layer. /// </summary> public static IGenerator ToCompiled(RuntimeLayer layer) { return(LayerCompiler.Compile(layer)); }
/// <summary> /// Sets the specified algorithm as the input at the specified index. /// </summary> /// <remarks> /// This function also automatically updates the seed value for the /// new input layer as well. /// </remarks> public void SetInput(int index, RuntimeLayer input) { if (!this.CanBeInput(index, input)) throw new InvalidOperationException("Specified algorithm can not be set as input at this index."); this.m_Inputs[index] = input; if (this.m_Inputs[index] != null) this.m_Inputs[index].SetSeed(this.Seed); }
/// <summary> /// Determines whether or not the specified input algorithm can be used as an /// input for the current algorithm in the specified index slot. /// </summary> public bool CanBeInput(int index, RuntimeLayer input) { if (input == null) return true; if (index < 0 || index >= this.m_Algorithm.InputTypes.Length) return false; if (this.m_Algorithm.Is2DOnly && !input.m_Algorithm.Is2DOnly) return false; return input.m_Algorithm.OutputType == this.m_Algorithm.InputTypes[index]; }
// Just finding offsets, then use them to determine max width, start X location, etc. public static void FindMaximumOffsets( RuntimeLayer layer, ref int offsetX, ref int offsetY, ref int offsetZ, ref int maxOffsetX, ref int maxOffsetY, ref int maxOffsetZ) { if (layer == null) throw new ArgumentNullException("layer"); if (layer.m_Inputs.Length != 0) { var offsetSaveX = offsetX; var offsetSaveY = offsetY; var offsetSaveZ = offsetZ; var inputs = 0; var TempOffsetX = new int[layer.m_Inputs.Length]; var TempOffsetY = new int[layer.m_Inputs.Length]; var TempOffsetZ = new int[layer.m_Inputs.Length]; foreach (var input in layer.m_Inputs) { if (input == null) continue; offsetX = offsetSaveX; offsetY = offsetSaveY; offsetZ = offsetSaveZ; if (layer.m_Algorithm.InputWidthAtHalfSize[inputs] && offsetX != 0) { offsetX = offsetX / 2; } if (layer.m_Algorithm.InputHeightAtHalfSize[inputs] && offsetY != 0) { offsetY = offsetY / 2; } if (layer.m_Algorithm.InputDepthAtHalfSize[inputs] && offsetZ != 0) { offsetZ = offsetZ / 2; } offsetX = offsetX + Math.Abs(layer.m_Algorithm.RequiredXBorder[inputs]); offsetY = offsetY + Math.Abs(layer.m_Algorithm.RequiredYBorder[inputs]); offsetZ = offsetZ + Math.Abs(layer.m_Algorithm.RequiredZBorder[inputs]); if (offsetX > maxOffsetX) maxOffsetX = offsetX; if (offsetY > maxOffsetY) maxOffsetY = offsetY; if (offsetZ > maxOffsetZ) maxOffsetZ = offsetZ; FindMaximumOffsets(input, ref offsetX, ref offsetY, ref offsetZ, ref maxOffsetX, ref maxOffsetY, ref maxOffsetZ); TempOffsetX[inputs] = offsetX; TempOffsetY[inputs] = offsetY; TempOffsetZ[inputs] = offsetZ; inputs++; } for (var count = 0; count < inputs; count++) { if (offsetX < TempOffsetX[count]) offsetX = TempOffsetX[count]; if (offsetY < TempOffsetY[count]) offsetY = TempOffsetY[count]; if (offsetZ < TempOffsetZ[count]) offsetZ = TempOffsetZ[count]; } } }
/// <summary> /// Converts the runtime layer representation into /// a storage layer so that it can be saved. /// </summary> public StorageLayer FromRuntime(RuntimeLayer layer) { // Handle null conversion. if (layer == null) return null; // Create storage. var storage = new StorageLayer { Algorithm = layer.Algorithm }; // Convert inputs. for (var i = 0; i < layer.GetInputs().Length; i++) storage.Inputs[i] = FromRuntime(layer.GetInputs()[i]); // Return storage. return storage; }
/// <summary> /// Compiles the runtime layer. /// </summary> public IGenerator ToCompiled(RuntimeLayer layer) { var result = LayerCompiler.Compile(layer); result.SetSeed(layer.Seed); return result; }