public void add_formatter() { var node = new OutputNode(typeof (Address)); node.AddFormatter<JsonFormatter>(); node.Writers.Single() .ShouldEqual(new WriteWithFormatter(typeof (Address), typeof (JsonFormatter))); }
public void add_html_to_the_end() { var node = new OutputNode(typeof (HtmlTag)); var html = node.AddHtml(); node.Writers.Single().ShouldBeOfType<WriteHtml>() .ResourceType.ShouldEqual(typeof (HtmlTag)); }
/// <summary> /// Constructor for the <c>OutputElement</c> object. This is /// used to create an output element that can create elements for /// an XML document. This requires the writer that is used to /// generate the actual document and the name of this node. /// </summary> /// <param name="parent"> /// this is the parent node to this output node /// </param> /// <param name="writer"> /// this is the writer used to generate the file /// </param> /// <param name="name"> /// this is the name of the element this represents /// </param> public OutputElement(OutputNode parent, NodeWriter writer, String name) { this.scope = new PrefixResolver(parent); this.table = new OutputNodeMap(this); this.mode = Mode.INHERIT; this.writer = writer; this.parent = parent; this.name = name; }
public void has_view_is_positive_with_always() { var node = new OutputNode(typeof(Address)); var viewToken = MockRepository.GenerateMock<ITemplateFile>(); node.AddView(viewToken, null); node.HasView(Always.Flyweight).ShouldBeTrue(); }
public void has_view_is_positive_with_always() { var node = new OutputNode(typeof(Address)); var viewToken = MockRepository.GenerateMock<IViewToken>(); node.AddView(viewToken); node.HasView(typeof(Always)).ShouldBeTrue(); }
public void add_writer_happy_path() { var node = new OutputNode(typeof (Address)); Writer writer = node.AddWriter<FakeAddressWriter>(); node.Writers.Single().ShouldBeTheSameAs(writer); writer.ResourceType.ShouldEqual(typeof (Address)); writer.WriterType.ShouldEqual(typeof (FakeAddressWriter)); }
public void has_view_negative_when_there_is_a_view_but_it_has_different_conditions() { var condition = new FakeConditional(); var node = new OutputNode(typeof(Address)); var viewToken = MockRepository.GenerateMock<ITemplateFile>(); node.AddView(viewToken, condition); node.HasView(Always.Flyweight).ShouldBeFalse(); }
public void has_view_positive_with_different_conditional() { var condition = new FakeConditional(); var node = new OutputNode(typeof(Address)); var viewToken = MockRepository.GenerateMock<ITemplateFile>(); node.AddView(viewToken); node.HasView().ShouldBeTrue(); }
public void has_view_positive_with_different_conditional() { Type conditionType = typeof(FakeConditional); var node = new OutputNode(typeof(Address)); var viewToken = MockRepository.GenerateMock<IViewToken>(); node.AddView(viewToken, conditionType); node.HasView(conditionType).ShouldBeTrue(); }
public void add_view() { var node = new OutputNode(typeof(Address)); var viewToken = MockRepository.GenerateMock<IViewToken>(); var viewNode = node.AddView(viewToken); node.Writers.ShouldContain(viewNode); viewNode.View.ShouldBeTheSameAs(viewToken); }
public void has_view_negative_when_there_is_a_view_but_it_has_different_conditions() { Type conditionType = typeof(FakeConditional); var node = new OutputNode(typeof(Address)); var viewToken = MockRepository.GenerateMock<IViewToken>(); node.AddView(viewToken, conditionType); node.HasView(typeof(Always)).ShouldBeFalse(); }
public void write_with_a_single_output() { var chain = new BehaviorChain(); var node = new OutputNode(typeof (RouteParameter)); chain.AddToEnd(node); var tag = new HtmlTag("td"); var column = new OutputColumn(); column.WriteBody(chain, null, tag); tag.Text().ShouldEqual(node.Description); }
private ServiceActionCall WrapActionCall(ActionCall call) { var outerCall = new ServiceActionCall(call); call.ReplaceWith(outerCall); var validationType = typeof(ServiceValidationBehaviour<>).MakeGenericType(outerCall.InputType()); outerCall.WrapWith(validationType); var jsonBehaviourType = typeof(ServiceOutputRenderBehaviour<>).MakeGenericType(typeof(ServiceCommandOutput)); var outputNode = new OutputNode(jsonBehaviourType); outerCall.AddToEnd(outputNode); return outerCall; }
public void add_view_with_condition() { var node = new OutputNode(typeof(Address)); var viewToken = MockRepository.GenerateMock<IViewToken>(); viewToken.Stub(x => x.ViewModel).Return(typeof(Address)); viewToken.Stub(x => x.ToViewFactoryObjectDef()).Return( ObjectDef.ForValue(MockRepository.GenerateMock<IViewFactory>())); var viewNode = node.AddView(viewToken, typeof(FakeConditional)); viewNode.As<IContainerModel>().ToObjectDef() .FindDependencyDefinitionFor<IConditional>() .Type .ShouldEqual(typeof(FakeConditional)); }
public void write_with_multiple_outputs() { var chain = new BehaviorChain(); var json = new OutputNode(typeof (RouteParameter)); chain.AddToEnd(json); var text = new RenderTextNode<RouteParameter>(); chain.AddToEnd(text); var tag = new HtmlTag("td"); var column = new OutputColumn(); column.WriteBody(chain, null, tag); tag.Text().ShouldEqual(json.Description + ", " + text.Description); }
public void ReferenceTest() { float delta = 1.25f; int length = 24; float[] xval = (new float[length]).Select((_, idx) => idx * idx / 144f - 0.5f).ToArray(); float[] tval = (new float[length]).Select((_, idx) => ((float)idx - 12) / 12).ToArray(); Tensor xtensor = new Tensor(Shape.Vector(length), xval); Tensor ttensor = new Tensor(Shape.Vector(length), tval); ParameterField x = xtensor; VariableField t = ttensor; Field loss = HuberLoss(x, t, delta); OutputNode diffnode = Abs(x - t).Value.Save(); OutputNode lossnode = loss.Value.Save(); (Flow flow, Parameters Parameters) = Flow.Optimize(loss); flow.Execute(); float[] diff = diffnode.Tensor.State; Assert.IsTrue(diff.Where((v) => v > delta).Count() > 0); Assert.IsTrue(diff.Where((v) => v < delta).Count() > 0); float[] loss_actual = lossnode.Tensor.State; AssertError.Tolerance(loss_expect, loss_actual, 1e-7f, 1e-5f, $"not equal loss"); float[] gx_actual = x.GradTensor.State; AssertError.Tolerance(gx_expect, gx_actual, 1e-7f, 1e-5f, $"not equal gx"); }
public void ReferenceMethod() { int channels = 3, batch = 4; float[] xval = { 1, 2, 3, -2, 1, 3, 3, 2, -1, 1, 2, 2 }; float[] tval = { 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0 }; Tensor xtensor = new Tensor(Shape.Map0D(channels, batch), xval); Tensor ttensor = new Tensor(Shape.Map0D(channels, batch), tval); ParameterField x = xtensor; VariableField t = ttensor; Field loss = Sum(SoftmaxCrossEntropy(x, t), axes: new int[] { Axis.Map0D.Channels }); OutputNode lossnode = loss.Value.Save(); (Flow flow, Parameters parameters) = Flow.Optimize(loss); flow.Execute(); float[] loss_actual = lossnode.Tensor.State; AssertError.Tolerance(loss_expect, loss_actual, 1e-6f, 1e-4f, $"not equal loss"); float[] gx_actual = x.GradTensor.State; AssertError.Tolerance(gx_expect, gx_actual, 1e-6f, 1e-4f, $"not equal gx"); }
public void TestBasicWrite() { StringWriter out = new StringWriter(); OutputNode root = NodeBuilder.write(out).getChild("root"); assertTrue(root.isRoot()); AssertEquals("root", root.getName()); root.setAttribute("id", "test"); root.setAttribute("name", "testRoot"); AssertEquals("test", root.getAttributes().get("id").getValue()); AssertEquals("testRoot", root.getAttributes().get("name").getValue()); OutputNode childOfRoot = root.getChild("child-of-root"); childOfRoot.setAttribute("name", "child of root"); assertFalse(childOfRoot.isRoot()); AssertEquals("child-of-root", childOfRoot.getName()); AssertEquals("child of root", childOfRoot.getAttributes().get("name").getValue()); OutputNode childOfChildOfRoot = childOfRoot.getChild("child-of-child-of-root"); childOfChildOfRoot.setValue("I am a child of the child-of-root element and a grand child of the root element"); assertFalse(childOfChildOfRoot.isRoot()); AssertEquals("child-of-child-of-root", childOfChildOfRoot.getName()); OutputNode anotherChildOfRoot = root.getChild("another-child-of-root"); anotherChildOfRoot.setAttribute("id", "yet another child of root"); anotherChildOfRoot.setValue("I am a sibling to child-of-root"); assertFalse(anotherChildOfRoot.isRoot()); AssertEquals("another-child-of-root", anotherChildOfRoot.getName()); OutputNode readonlyChildOfRoot = root.getChild("readonly-child-of-root"); readonlyChildOfRoot.setValue("this element is a child of root"); assertFalse(readonlyChildOfRoot.isRoot()); assertTrue(root.isRoot()); root.commit(); validate(out.toString()); }
public void SetInputsTest() { var inputNode1 = new InputNode("in1"); var inputNode2 = new InputNode("in2"); var orNode = new OrNode("or"); var outputNode = new OutputNode("out"); var nodeConnections = new List <NodeConnection> { new NodeConnection( new List <NodeBase> { inputNode1, inputNode2 }, orNode), new NodeConnection(orNode, outputNode) }; var inputNodes = new List <InputNode> { inputNode1, inputNode2 }; var simulation = new NodeSimulation(nodeConnections); var inputValues = new Dictionary <string, State> { { inputNode1.NodeId, new State(true) }, { inputNode2.NodeId, new State(false) } }; simulation.SetInputs(inputValues); Assert.True(simulation.GetInputNodes().Where(x => x.NodeId == inputNode1.NodeId).Single().CurrentState.LogicState); Assert.False(simulation.GetInputNodes().Where(x => x.NodeId == inputNode2.NodeId).Single().CurrentState.LogicState); }
public void TestPrefixResolver() { StringWriter writer = new StringWriter(); OutputNode node = NodeBuilder.write(writer); // <root xmlns="ns1"> OutputNode root = node.getChild("root"); root.setReference("ns1"); root.getNamespaces().put("ns1", "n"); // <child xmlns="ns2"> OutputNode child = root.getChild("child"); child.setReference("ns2"); child.getNamespaces().put("ns2", "n"); // <grandchild xmlns="ns1"> OutputNode grandchild = child.getChild("grandchild"); grandchild.setReference("ns1"); grandchild.getNamespaces().put("ns1", "n"); root.commit(); String text = writer.toString(); System.out.println(text); }
/// <summary> /// 处理当前节点的子节点 /// </summary> /// <returns>子孙叶子节点</returns> private OutputNode[] TravelDepth(object id, object[] leafIds, int maxDepth, IDictionary <object, int> levelDict, IList <OutputNode> nodes) { DataRow[] subRows = TreeSource.GetChildren(id); int depth = levelDict[id] + 1; List <OutputNode> results = new List <OutputNode>(); foreach (var row in subRows) { object subId = row[TreeSource.IdField]; bool isLeaf = leafIds.Contains(subId); OutputNode node = new OutputNode() { Content = row[Field], RowIndex = RowIndex + depth - 1 }; if (isLeaf) { // 根节点需要指定Tag,用于BodySource映射 node.Tag = row[HeaderBodyRelation.Field]; node.ColumnIndex = ColumnIndex + Array.IndexOf(leafIds, subId); node.ColumnSpan = 1; node.RowSpan = maxDepth - depth + 1; results.Add(node); } else { OutputNode[] leafNodes = TravelDepth(subId, leafIds, maxDepth, levelDict, nodes); node.ColumnIndex = leafNodes.Min(p => p.ColumnIndex); node.ColumnSpan = leafNodes.Length; node.RowSpan = 1; results.AddRange(leafNodes); } nodes.Add(node); } return(results.ToArray()); }
public void ExecuteTest() { for (decimal prob = 0; prob <= 1; prob += 0.05m) { int length = 65535 * 16; Shape shape = Shape.Vector(length); Tensor tensor = Tensor.BinaryRandom(shape, new Random(1234), (float)prob); float[] y = tensor.State; Assert.AreEqual((float)prob, y.Average(), 1e-3f); } { int length = 5000; Shape shape = Shape.Vector(length); InputNode node = VariableNode.BinaryRandom(shape, new Random(1234), 0.5f); OutputNode output = node.Save(); Flow flow = Flow.FromInputs(node); flow.Execute(); float[] y1 = output.Tensor.State; flow.Execute(); float[] y2 = output.Tensor.State; CollectionAssert.AreNotEqual(y1, y2); Assert.AreEqual(0, y2.Where((v) => v > 1e-5f && v < 1 - 1e-5f).Count()); } }
public void ExecuteTest() { const int length = 256; Random rd = new Random(1234); int[] idxes = (new int[length]).Select((_, idx) => idx).ToArray(); float[] x = (new float[length]).Select((_) => (float)rd.NextDouble() * 4 - 2).ToArray(); float alpha = 0.5f; float elu(float v) { return(v > 0 ? v : alpha *((float)Math.Exp(v) - 1)); } { Tensor t = new Tensor(Shape.Vector(length), x); Tensor o = Tensor.Elu(t, alpha); AssertError.Tolerance(idxes.Select((idx) => elu(x[idx])).ToArray(), o.State, 1e-7f, 1e-5f); } { InputNode t = new Tensor(Shape.Vector(length), x); var n = t + 0; OutputNode o = VariableNode.Elu(n, alpha).Save(); Flow flow = Flow.FromOutputs(o); flow.Execute(); AssertError.Tolerance(idxes.Select((idx) => elu(x[idx])).ToArray(), o.State, 1e-7f, 1e-5f); } }
public void AddOutput(Func<OutputFormatDetector, bool> isMatch, OutputNode output) { _outputs.Add(new OutputHolder(isMatch, output)); }
/// <summary> /// This <c>write</c> method will write the key value pairs /// within the provided map to the specified XML node. This will /// write each entry type must contain a key and value so that /// the entry can be deserialized in to the map as a pair. If the /// key or value object is composite it is read as a root object /// so its <c>Root</c> annotation must be present. /// </summary> /// <param name="node"> /// this is the node the map is to be written to /// </param> /// <param name="source"> /// this is the source map that is to be written /// </param> public void Write(OutputNode node, Object source) { Dictionary map = (Map) source; for(Object index : map.keySet()) { String root = entry.Entry; String name = style.GetElement(root); OutputNode next = node.getChild(name); Object item = map.get(index); key.Write(next, index); value.Write(next, item); } }
protected override List <OutputNode> CalulateNodes() { List <OutputNode> nodes = new List <OutputNode>(); if (Source.Table == null) { return(nodes); } if (SpanRule == CornerSpanRule.AllInOne) { OutputNode node = new OutputNode() { Content = Source.Table.Rows[0][0], ColumnIndex = this.ColumnIndex, RowIndex = this.RowIndex, ColumnSpan = this.ColumnCount, RowSpan = this.RowCount }; nodes.Add(node); } else if (SpanRule == CornerSpanRule.BaseOnRowHeader) { string tmpField = !string.IsNullOrEmpty(Field) && Source.Table.Columns.Contains(Field) ? Field : Source.Table.Columns[0].ColumnName; int span = this.ColumnCount; int rows = Math.Min(this.ColumnCount, Source.Table.Rows.Count); for (int i = 0; i < rows; i++) { OutputNode node = new OutputNode() { Content = Source.Table.Rows[i][tmpField], ColumnIndex = this.ColumnIndex, RowIndex = this.RowIndex + i, ColumnSpan = span, RowSpan = 1 }; nodes.Add(node); } } else if (SpanRule == CornerSpanRule.BaseOnColumnHeader) { string tmpField = !string.IsNullOrEmpty(Field) && Source.Table.Columns.Contains(Field) ? Field : Source.Table.Columns[0].ColumnName; int span = this.RowCount; int rows = Math.Min(this.ColumnCount, Source.Table.Rows.Count); for (int i = 0; i < rows; i++) { OutputNode node = new OutputNode() { Content = Source.Table.Rows[i][tmpField], ColumnIndex = this.ColumnIndex + i, RowIndex = this.RowIndex, ColumnSpan = 1, RowSpan = span }; nodes.Add(node); } } else { int rows = Math.Min(this.RowCount, Source.Table.Rows.Count); int columns = Math.Min(this.ColumnCount, Source.Table.Columns.Count); for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { OutputNode node = new OutputNode() { Content = Source.Table.Rows[i][j], RowIndex = this.RowIndex + i, ColumnIndex = this.ColumnIndex + j, RowSpan = 1, ColumnSpan = 1 }; nodes.Add(node); } } } return(nodes); }
/// <summary> /// This <c>write</c> method will serialize the contents of /// the provided object to the given XML element. This will use /// the <c>String.valueOf</c> method to convert the object to /// a string if the object represents a primitive, if however the /// object represents an enumerated type then the text value is /// created using <c>Enum.name</c>. /// </summary> /// <param name="source"> /// this is the object to be serialized /// </param> /// <param name="node"> /// this is the XML element to have its text set /// </param> public void Write(OutputNode node, Object source) { String text = factory.GetText(source); if(text != null) { node.setValue(text); } }
public void JsonOnly_with_existing_stuff() { var node = new OutputNode(typeof(Address)); node.UsesFormatter<XmlFormatter>(); node.JsonOnly(); node.Writers.ShouldHaveCount(1); node.UsesFormatter<JsonFormatter>().ShouldBeTrue(); }
public override void VTrain(VMatrix features, VMatrix labels) { if (Layers.Count < 1) { // create the layers if (Parameters.Hidden.Length < 1) { Parameters.Hidden = new[] { features.Cols() * 2 }; } // add the input nodes var iNodes = new List <Node>(); for (var i = 0; i < features.Cols(); i++) { iNodes.Add(new InputNode(i, i, _rand)); } var iLayer = new Layer() { Type = LayerType.Input, Nodes = iNodes, Previous = null, Next = null }; Layers.Add(iLayer); var prevLayer = iLayer; // add the hidden nodes foreach (var t in Parameters.Hidden) { var hNodes = new List <Node>(); for (var n = 0; n < t; n++) { var node = new HiddenNode(n, prevLayer.Nodes.Count + 1, t, _rand); hNodes.Add(node); } var hLayer = new Layer() { Type = LayerType.Hidden, Nodes = hNodes, Previous = prevLayer, Next = null }; Layers.Add(hLayer); prevLayer.Next = hLayer; prevLayer = hLayer; } // add the output nodes var oNodes = new List <Node>(); var oCount = 0; for (var col = 0; col < labels.Cols(); col++) { var labelValueCount = labels.ValueCount(col); if (labelValueCount < 2) { // continuous oCount++; } else { oCount += labelValueCount; } } for (var col = 0; col < labels.Cols(); col++) { var labelValueCount = labels.ValueCount(col); if (labelValueCount < 2) { // continuous var node = new OutputNode(oNodes.Count, true, col, -1, prevLayer.Nodes.Count + 1, oCount, _rand); oNodes.Add(node); } else { for (var n = 0; n < labelValueCount; n++) { var node = new OutputNode(oNodes.Count, false, col, n, prevLayer.Nodes.Count + 1, oCount, _rand); oNodes.Add(node); } } } var oLayer = new Layer() { Type = LayerType.Output, Nodes = oNodes, Previous = prevLayer }; Layers.Add(oLayer); prevLayer.Next = oLayer; } var trainSize = (int)(0.75 * features.Rows()); var trainFeatures = new VMatrix(features, 0, 0, trainSize, features.Cols()); var trainLabels = new VMatrix(labels, 0, 0, trainSize, labels.Cols()); var validationFeatures = new VMatrix(features, trainSize, 0, features.Rows() - trainSize, features.Cols()); var validationLabels = new VMatrix(labels, trainSize, 0, labels.Rows() - trainSize, labels.Cols()); Console.Write("Layers: "); foreach (var layer in Layers) { Console.Write(layer.Nodes.Count); if (layer.Type == LayerType.Output) { Console.WriteLine(); } else { Console.Write('x'); } } Console.WriteLine("AF: " + Parameters.Activation); Console.WriteLine("Epoch\tMSE (validation)"); int epoch; // current epoch number var bestEpoch = 0; // epoch number of best MSE var eCount = 0; // number of epochs since the best MSE var checkDone = false; // if true, check to see if we're done var initialMse = Parameters.InitialMse; // MSE for first epoch var bestMse = Parameters.StartMse; // best validation MSE so far double bestAccuracy = 0; var batchCount = (trainFeatures.Rows() + Parameters.BatchSize - 1) / Parameters.BatchSize; int countInterval = batchCount / 10; if (countInterval < 1) { countInterval = 1; } var startEpoch = Parameters.StartEpoch + 1; for (epoch = startEpoch;; epoch++) { // shuffle the training set trainFeatures.Shuffle(_rand, trainLabels); var cl = Console.CursorLeft; for (var batch = 0; batch < batchCount; batch++) { var startIdx = batch * Parameters.BatchSize; var count = Parameters.BatchSize; if ((startIdx + count) > trainFeatures.Rows()) { count = trainFeatures.Rows() - startIdx; } TrainBatch(trainFeatures, trainLabels, startIdx, count); if ((((batch + 1) % countInterval) == 0) || (batch == (batchCount - 1))) { Console.SetCursorPosition(cl, Console.CursorTop); Console.Write(batch + 1); } } Console.WriteLine(); // check the MSE var mse = VGetMSE(validationFeatures, validationLabels); if ((epoch == startEpoch) && (initialMse == 0)) { // save the initial MSE initialMse = mse; } var accuracy = VMeasureAccuracy(validationFeatures, validationLabels, null); if ((epoch % Parameters.SnapshotInterval) == 0) { SaveSnapshot(epoch, mse, initialMse, accuracy); } Console.WriteLine($"{epoch}-{eCount}\t{mse}"); if ((mse == 0) || (epoch > 5000)) { break; } if ((epoch == startEpoch) || (mse < bestMse)) { if ((epoch != startEpoch) && !checkDone && (mse < initialMse * 0.9)) { checkDone = true; } eCount = 0; // save the best for later bestMse = mse; bestEpoch = epoch; bestAccuracy = accuracy; foreach (var layer in Layers) { foreach (var node in layer.Nodes) { node.SaveBestWeights(); } } } else if (checkDone) { // check to see if we're done eCount++; if (eCount >= 20) { break; } } } if ((bestEpoch > 0) && (bestEpoch != epoch)) { foreach (var layer in Layers) { foreach (var node in layer.Nodes) { node.RestoreBestWeights(); } } } SaveSnapshot(bestEpoch, bestMse, initialMse, bestAccuracy, true); }
public override object Execute(Workflow workflow) { logger.Trace("Executing xmlinput module"); Logger.Log(Severity.DEBUG, LogCategory.MODULE, "Test"); if (this.OutputNode.State == null) { this.OutputNode.State = new ModuleState(); } var msg = ""; bool failed = false; try { Program.Main(this.OutputNode.State); } catch (Exception e) { msg = $"Critical failure in XML Converter: {e.Message}"; } if (Program.form == null) { return(null); } if (Program.form.isCancel) { return(null); } if (msg.Length > 0) { failed = true; } else if (this.OutputNode.State.Schema == null || this.OutputNode.State.DataFilePath == null) { msg += "Procedure not completed."; if (this.OutputNode.State.Schema == null) { msg += " Schema not available. Please generate a schema before closing the window."; } if (this.OutputNode.State.DataFilePath == null) { msg += " Input path not available. Input file was not added before closing the window."; } failed = true; } else { if (!File.Exists(this.OutputNode.State.DataFilePath)) { msg += string.Format("Input file does not exist at path: {0}.", this.OutputNode.State.DataFilePath); failed = true; } } if (failed) { if (OutputNode.IsConnected()) { msg = "Disconnecting module: " + msg; OutputNode.Disconnect(); } Logger.Log(Severity.WARN, LogCategory.MODULE, msg); System.Windows.Forms.MessageBox.Show(msg); this.OutputNode.State.DataFilePath = ""; return(null); } logger.Info("Calling RequestStateUpdate?.Invoke(workflow)"); RequestStateUpdate?.Invoke(workflow); return(null); }
public void implements_the_IMayHaveResourceType_interface() { var node = new OutputNode(typeof(Address)); node.As <IMayHaveResourceType>().ResourceType().ShouldEqual(node.ResourceType); }
public Expression Transform(OutputNode item) { throw new NotImplementedException(); }
public override Task Export(string path) { int i = 0; string name = graph.Name; Queue <Task> runningTasks = new Queue <Task>(); foreach (var s in graph.OutputNodes) { Node n = null; if (graph.NodeLookup.TryGetValue(s, out n)) { if (n is OutputNode) { OutputNode on = n as OutputNode; if (on.OutType == OutputType.basecolor) { RawBitmap bmp = null; byte[] bits = on.GetPreview(on.Width, on.Height); if (bits != null) { var t = Task.Run(() => { bmp = new RawBitmap(on.Width, on.Height, bits); var src = bmp.ToBitmap(); using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_color.png"), FileMode.OpenOrCreate)) { src.Save(fs, System.Drawing.Imaging.ImageFormat.Png); } src.Dispose(); }); runningTasks.Enqueue(t); } } else if (on.OutType == OutputType.normal) { RawBitmap bmp = null; byte[] bits = on.GetPreview(on.Width, on.Height); if (bits != null) { var t = Task.Run(() => { bmp = new RawBitmap(on.Width, on.Height, bits); var src = bmp.ToBitmap(); using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_normal.png"), FileMode.OpenOrCreate)) { src.Save(fs, System.Drawing.Imaging.ImageFormat.Png); } src.Dispose(); }); runningTasks.Enqueue(t); } } else if (on.OutType == OutputType.metallic) { RawBitmap bmp = null; byte[] bits = on.GetPreview(on.Width, on.Height); if (bits != null) { var t = Task.Run(() => { bmp = new RawBitmap(on.Width, on.Height, bits); var src = bmp.ToBitmap(); using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_metallic.png"), FileMode.OpenOrCreate)) { src.Save(fs, System.Drawing.Imaging.ImageFormat.Png); } src.Dispose(); }); runningTasks.Enqueue(t); } } else if (on.OutType == OutputType.roughness) { RawBitmap bmp = null; byte[] bits = on.GetPreview(on.Width, on.Height); if (bits != null) { var t = Task.Run(() => { bmp = new RawBitmap(on.Width, on.Height, bits); var src = bmp.ToBitmap(); using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_roughness.png"), FileMode.OpenOrCreate)) { src.Save(fs, System.Drawing.Imaging.ImageFormat.Png); } src.Dispose(); }); runningTasks.Enqueue(t); } } else if (on.OutType == OutputType.occlusion) { RawBitmap bmp = null; byte[] bits = on.GetPreview(on.Width, on.Height); if (bits != null) { var t = Task.Run(() => { bmp = new RawBitmap(on.Width, on.Height, bits); var src = bmp.ToBitmap(); using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_occlusion.png"), FileMode.OpenOrCreate)) { src.Save(fs, System.Drawing.Imaging.ImageFormat.Png); } src.Dispose(); }); runningTasks.Enqueue(t); } } else if (on.OutType == OutputType.height) { RawBitmap bmp = null; byte[] bits = on.GetPreview(on.Width, on.Height); if (bits != null) { var t = Task.Run(() => { bmp = new RawBitmap(on.Width, on.Height, bits); var src = bmp.ToBitmap(); using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_height.png"), FileMode.OpenOrCreate)) { src.Save(fs, System.Drawing.Imaging.ImageFormat.Png); } src.Dispose(); }); runningTasks.Enqueue(t); } } else if (on.OutType == OutputType.thickness) { RawBitmap bmp = null; byte[] bits = on.GetPreview(on.Width, on.Height); if (bits != null) { var t = Task.Run(() => { bmp = new RawBitmap(on.Width, on.Height, bits); var src = bmp.ToBitmap(); using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_thickness.png"), FileMode.OpenOrCreate)) { src.Save(fs, System.Drawing.Imaging.ImageFormat.Png); } src.Dispose(); }); runningTasks.Enqueue(t); } } } } } int totalTasks = runningTasks.Count; ProgressChanged(0, totalTasks, 0); return(Task.Run(async() => { while (runningTasks.Count > 0) { i = totalTasks - runningTasks.Count + 1; Task t = runningTasks.Dequeue(); ProgressChanged(i, totalTasks, (float)i / (float)totalTasks); if (!t.IsCompleted && !t.IsCanceled) { await t; } } })); }
private void Update() { if (Dragging()) { line.SetPosition(1, App.Instance.Worldpoint()); if (Input.GetMouseButtonDown(1)) { line.enabled = false; currentDragging = null; } } ///element bar if (Input.mousePosition.y <= pointerThreshold) { animationActive = false; //stop all corutines before StartCoroutine(Move(open)); } else { animationActive = false; //stop all corutines before StartCoroutine(Move(close)); } ///control bar if (Input.mousePosition.y >= Screen.height - controlPointerThreshold) { controlAnimationActive = false; //stop all corutines before StartCoroutine(MoveControlbar(controlOpen)); } else { controlAnimationActive = false; //stop all corutines before StartCoroutine(MoveControlbar(controlClose)); } if (objDragging != null) { objDragging.transform.position = App.Instance.Worldpoint(); if (Input.GetMouseButtonDown(0)) { if (objDragging.GetComponentsInChildren <Gate>().Length > 0) { Gate[] gates = objDragging.GetComponentsInChildren <Gate>(); foreach (Gate g in gates) { g.EnableDropdown(); } } objDragging = null; } else if (Input.GetMouseButtonDown(1)) { Destroy(currentDragging); currentDragging = null; } } }
public void StartDragging(OutputNode node) { currentDragging = node; line.enabled = true; line.SetPosition(0, node.transform.position); }
public void Write(OutputNode node, Chicken chicken) { node.setAttribute("name", chicken.Name); node.setAttribute("age", String.valueOf(chicken.Age)); node.setAttribute("legs", String.valueOf(chicken.Legs)); }
/// <summary> /// This <c>write</c> method will write the specified object /// to the given XML element as as list entries. Each entry within /// the given list must be assignable to the given primitive type. /// This will deserialize each entry type as a primitive value. In /// order to do this the parent string provided forms the element. /// </summary> /// <param name="source"> /// this is the source object array to be serialized /// </param> /// <param name="node"> /// this is the XML element container to be populated /// </param> public void Write(OutputNode node, Object source) { Collection list = (Collection) source; for(Object item : list) { if(item != null) { OutputNode child = node.getChild(parent); if(!IsOverridden(child, item)) { root.Write(child, item); } } } }
public void Transform(OutputNode item) { return; }
void ContextCallback(object obj) { string clb = obj.ToString(); if (clb.Equals("noiseNode")) { NoiseNode noiseNode = new NoiseNode(); noiseNode.windowRect = new Rect(mousePos, new Vector2(200, 150)); //noiseNode.myComputeTextureCreator = computeTextureCreator; nodes.Add(noiseNode); noiseNode.name = "zzz" + noiseNode.name + saver.assetAmount.ToString(); noiseNode.index = nodes.Count - 1; saver.assetAmount += 1; saver.nodes.Add(noiseNode); AssetDatabase.AddObjectToAsset(noiseNode, pathName); AssetDatabase.SaveAssets(); //AssetDatabase.ImportAsset(pathName); } else if (clb.Equals("calculationNode")) { CalculationNode noiseNode = new CalculationNode(); noiseNode.windowRect = new Rect(mousePos, new Vector2(200, 150)); nodes.Add(noiseNode); noiseNode.name = "zzz" + noiseNode.name + saver.assetAmount.ToString(); saver.assetAmount += 1; saver.nodes.Add(noiseNode); AssetDatabase.AddObjectToAsset(noiseNode, pathName); AssetDatabase.SaveAssets(); } else if (clb.Equals("outputNode")) { OutputNode noiseNode = new OutputNode(); noiseNode.windowRect = new Rect(mousePos, new Vector2(200, 200)); nodes.Add(noiseNode); noiseNode.name = "zzz" + noiseNode.name + saver.assetAmount.ToString(); saver.assetAmount += 1; saver.nodes.Add(noiseNode); AssetDatabase.AddObjectToAsset(noiseNode, pathName); AssetDatabase.SaveAssets(); } else if (clb.Equals("waveNode")) { WaveNode noiseNode = new WaveNode(); noiseNode.windowRect = new Rect(mousePos, new Vector2(200, 200)); nodes.Add(noiseNode); noiseNode.name = "zzz" + noiseNode.name + saver.assetAmount.ToString(); saver.assetAmount += 1; saver.nodes.Add(noiseNode); AssetDatabase.AddObjectToAsset(noiseNode, pathName); AssetDatabase.SaveAssets(); } else if (clb.Equals("makeTransition")) { bool clickedOnWindow = false; BaseNode tempSelectedNode = null; foreach (BaseNode node in nodes) { if (node.windowRect.Contains(mousePos)) { tempSelectedNode = node; clickedOnWindow = true; break; } } if (clickedOnWindow) { selectedNode = tempSelectedNode; makeTransitionMode = true; } AssetDatabase.SaveAssets(); } else if (clb.Equals("callMethod")) { foreach (BaseNode node in nodes) { if (node.windowRect.Contains(mousePos)) { ((NoiseNode)(node)).TheMethod(0); break; } } } else if (clb.Equals("deleteNode")) { bool clickedOnWindow = false; BaseNode tempSelectedNode = null; int index = 0; foreach (BaseNode node in nodes) { if (node.windowRect.Contains(mousePos)) { index = nodes.IndexOf(node); tempSelectedNode = node; clickedOnWindow = true; break; } } if (clickedOnWindow) { //nodes = nodes.Where(x => x.index != index).ToList(); //nodes.Remove(tempSelectedNode); nodes.Remove(tempSelectedNode); saver.nodes.Remove(tempSelectedNode); //nodes.RemoveAt(index); foreach (BaseNode node in nodes) { node.NodeDeleted(tempSelectedNode); //node.NodeDeleted(index); } DestroyImmediate(tempSelectedNode, true); AssetDatabase.SaveAssets(); //AssetDatabase.ImportAsset(pathName); } } }
/// <summary> /// This is used to write the namespaces of the specified node to /// the output. This will iterate over each namespace entered on /// to the node. Once written the node is considered qualified. /// </summary> /// <param name="node"> /// this is the node to have is attributes written /// </param> public void WriteNamespaces(OutputNode node) { NamespaceMap map = node.getNamespaces(); for(String name : map) { String prefix = map.get(name); writer.WriteNamespace(name, prefix); } }
public void Write(OutputNode node, Cow cow) { node.setAttribute("name", cow.Name); node.setAttribute("age", String.valueOf(cow.Age)); node.setAttribute("legs", String.valueOf(cow.Legs)); }
public override bool CanAcceptNode(OutputNode outputNode) { return(outputNode.OutputType == InputType); }
public void UsesFormatter() { var node = new OutputNode(typeof(Address)); node.UsesFormatter<XmlFormatter>().ShouldBeFalse(); node.UsesFormatter<JsonFormatter>().ShouldBeFalse(); node.AddFormatter<XmlFormatter>(); node.UsesFormatter<XmlFormatter>().ShouldBeTrue(); node.UsesFormatter<JsonFormatter>().ShouldBeFalse(); node.AddFormatter<JsonFormatter>(); node.UsesFormatter<XmlFormatter>().ShouldBeTrue(); node.UsesFormatter<JsonFormatter>().ShouldBeTrue(); }
void ContextCallback(object obj) { //make the passed object to a string string clb = obj.ToString(); //add the node we want if (clb.Equals("inputNode")) { InputNode inputNode = new InputNode(); inputNode.windowRect = new Rect(mousePos.x, mousePos.y, 200, 150); windows.Add(inputNode); } else if (clb.Equals("outputNode")) { OutputNode outputNode = new OutputNode(); outputNode.windowRect = new Rect(mousePos.x, mousePos.y, 200, 100); windows.Add(outputNode); } /* * else if (clb.Equals("makeTransition")) * { * bool clickedOnWindow = false; * int selectedIndex = -1; * //find the window that it was clicked * for (int i = 0; i < windows.Count; i++) * { * if (windows[i].windowRect.Contains(mousePos)) * { * selectedIndex = i; * clickedOnWindow = true; * break; * } * } * * //and make it the selected node of the transition * if (clickedOnWindow) * { * selectedNode = windows[selectedIndex]; * makeTransitionMode = true; * } * * } * else if (clb.Equals("deleteNode")) //if it's a delete node * { * bool clickedOnWindow = false; * int selectedIndex = -1; * * //find the selected node * for (int i = 0; i < windows.Count; i++) * { * if (windows[i].windowRect.Contains(mousePos)) * { * selectedIndex = i; * clickedOnWindow = true; * break; * } * } * * * if (clickedOnWindow) * { * //delete it from our list * BaseNode selNode = windows[selectedIndex]; * windows.RemoveAt(selectedIndex); * * //then pass it to all our nodes that is deleted * foreach (BaseNode n in windows) * { * n.NodeDeleted(selNode); * } * } * } */ //we use else if instead of a switch because: /*Selecting from a set of multiple cases is faster with if statements than with switch */ }
public OutputBuilder(string outputType, string inputName) { Node = new OutputNode(outputType, inputName); }
/// <summary> /// This is used to determine whether the specified value has been /// overridden by the strategy. If the item has been overridden /// then no more serialization is require for that value, this is /// effectively telling the serialization process to stop writing. /// </summary> /// <param name="node"> /// the node that a potential override is written to /// </param> /// <param name="value"> /// this is the object instance to be serialized /// </param> /// <returns> /// returns true if the strategy overrides the object /// </returns> public bool IsOverridden(OutputNode node, Object value) { return(factory.setOverride(entry, value, node)); }
public void SetUp() { theChain = BehaviorChain.For<ActionJackson>(x => x.OneInOneOut(null)); theOutputNode = new OutputNode(typeof(OutputBehavior)); theChain.AddToEnd(theOutputNode); // Nothing up my sleeve theChain.Any(x => x is ConnegNode).ShouldBeFalse(); }
public void OnUpdate() { if (!DebugOn.Value) { return; } if (Input.GetKeyDown(NodeDocKey.Value)) { string target = DebugOutDir.Value + "游戏指令(OutputNode)文档.json"; ModOutputNodeConverter.ExportDoc(target); target = DebugOutDir.Value + "txt表格(Item)文档.json"; ItemDocConverter.ExportDoc(target); } if (Input.GetKeyDown(NodeFileKey.Value) && !string.IsNullOrEmpty(NodeContent.Value)) { // OutputNode string target = DebugOutDir.Value + NodeFilePath.Value; OutputNode obj = OutputNodeConvert.Deserialize(NodeContent.Value); var strJsonMod = ModJson.ToJsonMod(obj, typeof(OutputNode), JsonPritty.Value); Console.WriteLine("Json版 = " + strJsonMod); GlobalLib.ToFile(strJsonMod, target); } if (Input.GetKeyDown(MovieFileKey.Value) && !string.IsNullOrEmpty(MovieFileId.Value)) { // movie string source = string.Format(MovieFileType.Value == MovieType.Cinematic ? GameConfig.CinematicPath : GameConfig.SchedulerPath, MovieFileId.Value); string target = string.Format(DebugOutDir.Value + MovieFilePath.Value, MovieFileId.Value); var obj = ModJson.FromJsonResource <ScheduleGraph.Bundle>(source); if (JsonFormat.Value) { var strJsonMod = ModJson.ToJsonMod(obj, typeof(ScheduleGraph.Bundle), JsonPritty.Value); Console.WriteLine("Json版 = " + strJsonMod); GlobalLib.ToFile(strJsonMod, target); // 测试读取并对比重新通过Json构建的是否有差 var obj2 = ModJson.FromJsonMod <ScheduleGraph.Bundle>(strJsonMod); JsonSerializerSettings originalSetting = new JsonSerializerSettings { Converters = new JsonConverter[] { new OutputNodeJsonConverter() } }; string str2 = ModJson.ToJson(obj2, typeof(ScheduleGraph.Bundle), originalSetting, JsonPritty.Value); Console.WriteLine("重构脚本 = " + str2); } else { GlobalLib.ToFile(Game.Resource.LoadString(source), target); } } if (Input.GetKeyDown(BattleFileKey.Value) && !string.IsNullOrEmpty(BattleFileId.Value)) { // battle schedule string source = string.Format(GameConfig.BattleSchedulePath, GameConfig.Language, BattleFileId.Value + ".json"); string target = string.Format(DebugOutDir.Value + BattleFilePath.Value, BattleFileId.Value); if (JsonFormat.Value) { BattleSchedule obj = ModJson.FromJsonResource <BattleSchedule>(source); var strJsonMod = ModJson.ToJsonMod(obj, typeof(BattleSchedule), JsonPritty.Value); Console.WriteLine("Json版 = " + strJsonMod); GlobalLib.ToFile(strJsonMod, target); } else { GlobalLib.ToFile(Game.Resource.LoadString(source), target); } } if (Input.GetKeyDown(BuffFileKey.Value) && !string.IsNullOrEmpty(BuffFileId.Value)) { // buff string source = string.Format(GameConfig.ButtleBufferPath, GameConfig.Language, BuffFileId.Value + ".json"); string target = string.Format(DebugOutDir.Value + BuffFilePath.Value, BuffFileId.Value); if (JsonFormat.Value) { Heluo.Data.Buffer obj = ModJson.FromJsonResource <Heluo.Data.Buffer>(source); var strJsonMod = ModJson.ToJsonMod(obj, typeof(Heluo.Data.Buffer), true); Console.WriteLine("Json版 = " + strJsonMod); GlobalLib.ToFile(strJsonMod, target); } else { GlobalLib.ToFile(Game.Resource.LoadString(source), target); } } }
public override void VTrain(VMatrix features, VMatrix labels) { if (m_hidden.Length < 1) { m_hidden = new int[1] { features.Cols() * 2 }; } // add the input nodes List <Node> iNodes = new List <Node>(); for (var i = 0; i < features.Cols(); i++) { iNodes.Add(new InputNode(i, i, m_rand)); } m_layers.Add(iNodes); int prevNodes = iNodes.Count + 1; // add the hidden nodes for (var layer = 0; layer < m_hidden.Length; layer++) { List <Node> hNodes = new List <Node>(); for (var n = 0; n < m_hidden[layer]; n++) { var node = new HiddenNode(n, prevNodes, m_rand); if (m_activation == "relu") { if (m_actRandom) { node.alpha = m_actAlpha * m_rand.NextDouble(); node.threshold = m_actThreshold * m_rand.NextDouble(); node.beta = ((m_actBeta - 1.0) * m_rand.NextDouble()) + 1.0; } else { node.alpha = m_actAlpha; node.threshold = m_actThreshold; node.beta = m_actBeta; } } hNodes.Add(node); } m_layers.Add(hNodes); prevNodes = hNodes.Count + 1; } // add the output nodes List <Node> oNodes = new List <Node>(); for (var col = 0; col < labels.Cols(); col++) { var labelValueCount = labels.ValueCount(col); if (labelValueCount < 2) { // continuous var node = new OutputNode(oNodes.Count, prevNodes, true, col, -1, m_rand); if (m_activation == "relu") { if (m_actRandom) { node.alpha = m_actAlpha * m_rand.NextDouble(); node.threshold = m_actThreshold * m_rand.NextDouble(); node.beta = ((m_actBeta - 1.0) * m_rand.NextDouble()) + 1.0; } else { node.alpha = m_actAlpha; node.threshold = m_actThreshold; node.beta = m_actBeta; } } oNodes.Add(node); } else { for (var n = 0; n < labelValueCount; n++) { var node = new OutputNode(oNodes.Count, prevNodes, false, col, n, m_rand); if (m_activation == "relu") { if (m_actRandom) { node.alpha = m_actAlpha * m_rand.NextDouble(); node.threshold = m_actThreshold * m_rand.NextDouble(); node.beta = ((m_actBeta - 1.0) * m_rand.NextDouble()) + 1.0; } else { node.alpha = m_actAlpha; node.threshold = m_actThreshold; node.beta = m_actBeta; } } oNodes.Add(node); } } } m_layers.Add(oNodes); int trainSize = (int)(0.75 * features.Rows()); VMatrix trainFeatures = new VMatrix(features, 0, 0, trainSize, features.Cols()); VMatrix trainLabels = new VMatrix(labels, 0, 0, trainSize, labels.Cols()); VMatrix validationFeatures = new VMatrix(features, trainSize, 0, features.Rows() - trainSize, features.Cols()); VMatrix validationLabels = new VMatrix(labels, trainSize, 0, labels.Rows() - trainSize, labels.Cols()); Console.Write("Layers: "); Console.Write(iNodes.Count); Console.Write('x'); for (var l = 0; l < m_hidden.Length; l++) { Console.Write(m_hidden[l]); Console.Write('x'); } Console.WriteLine(oNodes.Count); Console.WriteLine("AF: " + m_activation); Console.WriteLine(string.Format("AParam: {0},{1},{2},{3}", m_actAlpha, m_actThreshold, m_actBeta, m_actRandom)); Console.WriteLine("Boost: " + m_boost); Console.WriteLine("Epoch\tMSE (validation)"); if (m_outputFile != null) { m_outputFile.Write("Layers: "); m_outputFile.Write(iNodes.Count); m_outputFile.Write('x'); for (var l = 0; l < m_hidden.Length; l++) { m_outputFile.Write(m_hidden[l]); m_outputFile.Write('x'); } m_outputFile.WriteLine(oNodes.Count); m_outputFile.WriteLine("Momentum: " + m_momentum); m_outputFile.WriteLine("AF: " + m_activation); m_outputFile.WriteLine(string.Format("AParam: {0},{1},{2},{3}", m_actAlpha, m_actThreshold, m_actBeta, m_actRandom)); m_outputFile.WriteLine("Boost: " + m_boost); m_outputFile.WriteLine(); m_outputFile.WriteLine("Weights"); PrintWeights(); m_outputFile.WriteLine("Epoch\tMSE (validation)"); } for (int round = 1; round < m_layers.Count; round++) { int epoch = 0; // current epoch number int bestEpoch = 0; // epoch number of best MSE int eCount = 0; // number of epochs since the best MSE bool checkDone = false; // if true, check to see if we're done double initialMSE = double.MaxValue; // MSE for first epoch double bestMSE = double.MaxValue; // best validation MSE so far for (; ;) { // shuffle the training set trainFeatures.Shuffle(m_rand, trainLabels); TrainEpoch(++epoch, trainFeatures, trainLabels, round); // check the MSE after this epoch double mse = VGetMSE(validationFeatures, validationLabels); Console.WriteLine(string.Format("{0}:{1}-{2}\t{3}", round, epoch, eCount, mse)); if (m_outputFile != null) { m_outputFile.WriteLine(string.Format("{0}:{1}-{2}\t{3}", round, epoch, eCount, mse)); m_outputFile.Flush(); } if ((mse == 0.0) || (epoch > 5000)) { break; } else if ((epoch == 1) || (mse < bestMSE)) { if (epoch == 1) { // save the initial MSE initialMSE = mse; } else if (!checkDone && (mse < initialMSE * 0.9)) { checkDone = true; } eCount = 0; // save the best for later bestMSE = mse; bestEpoch = epoch; for (var layer = 1; layer < m_layers.Count; layer++) { foreach (var node in m_layers[layer]) { node.SaveBestWeights(); } } } else if (checkDone) { // check to see if we're done eCount++; if (eCount >= 20) { break; } } if ((bestEpoch > 0) && (bestEpoch != epoch)) { for (var layer = round; layer < m_layers.Count; layer++) { foreach (var node in m_layers[layer]) { node.RestoreBestWeights(); node.InitDeltas(); } } if (m_outputFile != null) { m_outputFile.WriteLine(); m_outputFile.WriteLine(string.Format("Best Weights (from Epoch {0}, valMSE={1})", bestEpoch, bestMSE)); PrintWeights(); } } } } if (m_outputFile != null) { m_outputFile.WriteLine(); m_outputFile.WriteLine("Weights"); PrintWeights(); m_outputFile.Close(); } }
public void ApplyRules(OutputNode node) { Rules.Top.ApplyOutputs(node, node.ParentChain() ?? new BehaviorChain(), this); }
public OutputHolder(Func<OutputFormatDetector, bool> predicate, OutputNode outputNode) { Predicate = predicate; OutputNode = outputNode; }
public void ClearAll() { var node = new OutputNode(typeof (Address)); node.UsesFormatter<XmlFormatter>(); node.UsesFormatter<JsonFormatter>(); node.ClearAll(); node.Writers.Any().ShouldBeFalse(); }
void ContextCallback(object obj) { string clb = obj.ToString(); if (clb.Equals("inputNode")) { InputNode inputNode = new InputNode(); inputNode.windowRect = new Rect(mousePos.x, mousePos.y, 200, 150); windows.Add(inputNode); } else if (clb.Equals("outputNode")) { OutputNode outputNode = new OutputNode(); outputNode.windowRect = new Rect(mousePos.x, mousePos.y, 200, 100); windows.Add(outputNode); } else if (clb.Equals("calcNode")) { CalcNode calcNode = new CalcNode(); calcNode.windowRect = new Rect(mousePos.x, mousePos.y, 200, 150); windows.Add(calcNode); } else if (clb.Equals("compNode")) { ComparisonNode compNode = new ComparisonNode(); compNode.windowRect = new Rect(mousePos.x, mousePos.y, 200, 200); windows.Add(compNode); } else if (clb.Equals("makeTransition")) { bool clickedOnWindow = false; int selectIndex = -1; for (int i = 0; i < windows.Count; i++) { if (windows[i].windowRect.Contains(mousePos)) { selectIndex = i; clickedOnWindow = true; break; } } if (clickedOnWindow) { selectedNode = windows[selectIndex]; makeTransitionMode = true; } } else if (clb.Equals("deleteNode")) { bool clickedOnWindow = false; int selectIndex = -1; for (int i = 0; i < windows.Count; i++) { if (windows[i].windowRect.Contains(mousePos)) { selectIndex = i; clickedOnWindow = true; break; } } if (clickedOnWindow) { BaseNode selNode = windows[selectIndex]; windows.RemoveAt(selectIndex); // inform each basenode in the window that this specific node was deleted. foreach (BaseNode n in windows) { n.NodeDeleted(selNode); } } } }
public void has_view_is_false_when_it_is_empty() { var node = new OutputNode(typeof(Address)); node.HasView(typeof (Always)).ShouldBeFalse(); }
/// <summary> /// This is used to determine whether the specified value has been /// overridden by the strategy. If the item has been overridden /// then no more serialization is require for that value, this is /// effectively telling the serialization process to stop writing. /// </summary> /// <param name="node"> /// the node that a potential override is written to /// </param> /// <param name="value"> /// this is the object instance to be serialized /// </param> /// <returns> /// returns true if the strategy overrides the object /// </returns> public bool IsOverridden(OutputNode node, Object value) { return factory.setOverride(entry, value, node); }
public void implements_the_IMayHaveResourceType_interface() { var node = new OutputNode(typeof(Address)); node.As<IMayHaveResourceType>().ResourceType().ShouldEqual(node.ResourceType); }
public void has_view_is_false_when_it_is_empty() { var node = new OutputNode(typeof(Address)); node.HasView(typeof(Always)).ShouldBeFalse(); }
public void JsonOnly_from_scratch() { var node = new OutputNode(typeof(Address)); node.JsonOnly(); node.Writers.ShouldHaveCount(1); node.UsesFormatter<JsonFormatter>().ShouldBeTrue(); }
protected override void Update() { if (Unit == null || Operation == null) { return; } if (underlay.sprite != null) { float target_image_alpha = 0; float target_underlay_alpha = 1; if (this.IsPointedAt()) { target_image_alpha = 1; target_underlay_alpha = 0.1f; } Image.color = Image.color.AlphaChangedTo( Mathf.Lerp(Image.color.a, target_image_alpha, Time.deltaTime * 5)); underlay.color = underlay.color.AlphaChangedTo( Mathf.Lerp(underlay.color.a, target_underlay_alpha, Time.deltaTime * 5)); } description_text.gameObject.SetActive(this.IsPointedAt()); SelectionOverlay.gameObject.SetActive(IsSelected); InputNode.gameObject.SetActive(Operation.TakesInput); OutputNode.gameObject.SetActive(Operation.HasOutput); GotoNode.gameObject.SetActive(Operation.TakesGoto); if (IsInProgramInterface) { if (InputNode.VariableTile != null) { Operation.Input.PrimaryVariableName = InputNode.VariableTile.Variable.Name; } if (OutputNode.VariableTile != null) { Operation.Output.PrimaryVariableName = OutputNode.VariableTile.Variable.Name; } if (GotoNode.GotoOperationTile != null) { Operation.Goto = GotoNode.GotoOperationTile.Operation; } } else if (IsInOperationMenu && IsSelected) { bool is_complete = false; if (operation.TakesGoto) { is_complete = GotoNode.GotoOperationTile != null; } else if ((!operation.TakesInput || InputNode.VariableTile != null) && (!operation.HasOutput || OutputNode.VariableTile != null)) { is_complete = true; } if (is_complete) { Operation operation = Operation.Instantiate(); if (operation.TakesInput && InputNode.VariableTile != null) { operation.Input.PrimaryVariableName = InputNode.VariableTile.Variable.Name; } if (operation.HasOutput && OutputNode.VariableTile != null) { operation.Output.PrimaryVariableName = OutputNode.VariableTile.Variable.Name; } if (operation.TakesGoto && GotoNode.GotoOperationTile != null) { operation.Goto = GotoNode.GotoOperationTile.Operation; } Unit.Program.Add(operation); if (Input.GetKey(KeyCode.LeftShift)) { if (Unit.Program.Next == null) { Unit.Program.Next = operation; } } else { Unit.Program.Next = operation; if (operation is Task) { Unit.Task = null; operation.Execute(Unit); } } InputNode.VariableName = null; InputNode.IsSelected = false; OutputNode.VariableName = null; OutputNode.IsSelected = false; GotoNode.GotoOperationTile = null; GotoNode.IsSelected = false; IsSelected = false; } } if (!InputUtility.DidDragOccur && this.IsPointedAt() && !InputNode.IsPointedAt() && !OutputNode.IsPointedAt() && !GotoNode.IsPointedAt() && this.UseMouseLeftRelease()) { if (IsInOperationMenu) { IsSelected = true; } else if (IsInProgramInterface) { Unit.Program.Next = Operation; Operation.Execute(Unit); } } if (InputUtility.WasMouseRightReleased) { if (IsSelected) { IsSelected = false; } } if (IsSelected) { if (Operation.TakesInput && InputNode.VariableTile == null && !Operation.TakesGoto) { if (!InputNode.IsSelected) { InputNode.IsSelected = true; } } else if (Operation.HasOutput && OutputNode.VariableTile == null) { if (!OutputNode.IsSelected) { OutputNode.IsSelected = true; } } else if (Operation.TakesGoto && GotoNode.GotoOperationTile == null) { if (!GotoNode.IsSelected) { GotoNode.IsSelected = true; } } } base.Update(); }
public override void ExportSync(string path) { string name = graph.Name; foreach (var s in graph.OutputNodes) { Node n = null; if (graph.NodeLookup.TryGetValue(s, out n)) { if (n is OutputNode) { OutputNode on = n as OutputNode; if (on.OutType == OutputType.basecolor) { RawBitmap bmp = null; byte[] bits = on.GetPreview(on.Width, on.Height); if (bits != null) { bmp = new RawBitmap(on.Width, on.Height, bits); var src = bmp.ToBitmap(); using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_color.png"), FileMode.OpenOrCreate)) { src.Save(fs, System.Drawing.Imaging.ImageFormat.Png); } src.Dispose(); } } else if (on.OutType == OutputType.normal) { RawBitmap bmp = null; byte[] bits = on.GetPreview(on.Width, on.Height); if (bits != null) { bmp = new RawBitmap(on.Width, on.Height, bits); var src = bmp.ToBitmap(); using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_normal.png"), FileMode.OpenOrCreate)) { src.Save(fs, System.Drawing.Imaging.ImageFormat.Png); } src.Dispose(); } } else if (on.OutType == OutputType.metallic) { RawBitmap bmp = null; byte[] bits = on.GetPreview(on.Width, on.Height); if (bits != null) { bmp = new RawBitmap(on.Width, on.Height, bits); var src = bmp.ToBitmap(); using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_metallic.png"), FileMode.OpenOrCreate)) { src.Save(fs, System.Drawing.Imaging.ImageFormat.Png); } src.Dispose(); } } else if (on.OutType == OutputType.roughness) { RawBitmap bmp = null; byte[] bits = on.GetPreview(on.Width, on.Height); if (bits != null) { bmp = new RawBitmap(on.Width, on.Height, bits); var src = bmp.ToBitmap(); using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_roughness.png"), FileMode.OpenOrCreate)) { src.Save(fs, System.Drawing.Imaging.ImageFormat.Png); } src.Dispose(); } } else if (on.OutType == OutputType.occlusion) { RawBitmap bmp = null; byte[] bits = on.GetPreview(on.Width, on.Height); if (bits != null) { bmp = new RawBitmap(on.Width, on.Height, bits); var src = bmp.ToBitmap(); using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_occlusion.png"), FileMode.OpenOrCreate)) { src.Save(fs, System.Drawing.Imaging.ImageFormat.Png); } src.Dispose(); } } else if (on.OutType == OutputType.height) { RawBitmap bmp = null; byte[] bits = on.GetPreview(on.Width, on.Height); if (bits != null) { bmp = new RawBitmap(on.Width, on.Height, bits); var src = bmp.ToBitmap(); using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_height.png"), FileMode.OpenOrCreate)) { src.Save(fs, System.Drawing.Imaging.ImageFormat.Png); } src.Dispose(); } } else if (on.OutType == OutputType.thickness) { RawBitmap bmp = null; byte[] bits = on.GetPreview(on.Width, on.Height); if (bits != null) { bmp = new RawBitmap(on.Width, on.Height, bits); var src = bmp.ToBitmap(); using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_thickness.png"), FileMode.OpenOrCreate)) { src.Save(fs, System.Drawing.Imaging.ImageFormat.Png); } src.Dispose(); } } else if (on.OutType == OutputType.emission) { RawBitmap bmp = null; byte[] bits = on.GetPreview(on.Width, on.Height); if (bits != null) { bmp = new RawBitmap(on.Width, on.Height, bits); var src = bmp.ToBitmap(); using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_emission.png"), FileMode.OpenOrCreate)) { src.Save(fs, System.Drawing.Imaging.ImageFormat.Png); } src.Dispose(); } } } } } }