public void Evaluate(int SpreadMax) { if (this.FOut[0] == null) { this.FOut[0] = new DX11LayerGetSliceOrder(); } this.FOut[0].Enabled = this.FInEnabled[0]; this.FOut[0].FInIndex = this.FInIndex; }
public void Update(ISpread<Blob> availableBlobs) { var hits = TouchUtils.GetBlobHits(Id, availableBlobs); switch (Phase) { case TransformPhase.Idle: if (hits.Count > 0 && TouchUtils.IsAnyNew(hits)) { StartTransformtation(hits); } break; case TransformPhase.Transforming: var pCount = Blobs.Count(); TouchUtils.UpdateBlobs(availableBlobs, Blobs, Id); TouchUtils.AddNewHits(hits.ToSpread(), Blobs); if (pCount != Blobs.SliceCount) PBlobs.SliceCount = 0; if (Blobs.SliceCount == 0) { Debug.WriteLine("Stopped!!!"); StopTransformation(); } break; } }
bool SpectralOr(ISpread<bool> spread) { bool value = false; foreach (bool slice in spread) value |= slice; return value; }
public void Process(ISpread<string> input, int spreadMax) { Output.SliceCount = spreadMax; for (int i = 0; i < spreadMax; i++) { Output[i] = double.Parse(input[i], CultureInfo.InvariantCulture); } }
public static bool AddNewHits(ISpread<Blob> hits, ISpread<Blob> currentBlobs) { var isAdded = false; foreach (var hit in hits.Where(hit => hit.IsNew)) { currentBlobs.Add(hit); isAdded = true; } return isAdded; }
public static PointF[] ImagePoints(ISpread<Vector2D> input) { PointF[] imagePoints = new PointF[input.SliceCount]; for (int i = 0; i < input.SliceCount; i++) { imagePoints[i].X = (float)input[i].x; imagePoints[i].Y = (float)input[i].y; } return imagePoints; }
public static MCvPoint3D32f[] ObjectPoints(ISpread<Vector3D> input, bool toVVVV) { MCvPoint3D32f[] objectPoints = new MCvPoint3D32f[input.SliceCount]; for (int i = 0; i < input.SliceCount; i++) { objectPoints[i].x = (float)input[i].x; objectPoints[i].y = toVVVV ? - (float)input[i].y : (float) input[i].y; objectPoints[i].z = toVVVV ? - (float)input[i].z : (float) input[i].z; } return objectPoints; }
public void Process(ISpread<string> input, ISpread<string> separator, int spreadMax) { Output.SliceCount = spreadMax; for (int i = 0; i < spreadMax; i++) { string[] strings = input[i].Split(separator[i].ToArray()); if (!strings.Any()) continue; if(Output[i] == null) Output[i] = new Spread<string>(1); Output[i].AssignFrom(strings); } }
public ArchitectureNode([Output("Output")] ISpread <string> output, [Output("Is x64")] ISpread <bool> x64) { if (IntPtr.Size == 4) { output[0] = "x86"; } else if (IntPtr.Size == 8) { output[0] = "x64"; x64[0] = true; } else { output[0] = "Welcome to the Future!"; } }
/// <summary> /// Converts a <see cref="ISpread{T}"/> to a <see cref="string"/> of comma seperated values. /// </summary> /// <param name="spread">The <see cref="ISpread{T}"/> to convert to a <see cref="string"/>.</param> /// <returns>A comma seperated <see cref="string"/> of <see cref="ISpread{T}"/>.</returns> public static string AsString <T>(this ISpread <T> spread) { var sb = new StringBuilder(); for (int i = 0; i < spread.SliceCount - 1; i++) { sb.AppendFormat("{0}, ", spread[i].ToString()); } if (spread.SliceCount > 0) { sb.Append(spread[spread.SliceCount - 1].ToString()); } return(sb.ToString()); }
public static void SetSliceCountBy <T>(this ISpread <ISpread <T> > outputSpreads, ISpread <T> inputSpread) { int outputSpreadCount = outputSpreads.SliceCount; int remainder = 0; int sliceCountPerSpread = Math.DivRem(inputSpread.SliceCount, outputSpreadCount, out remainder); if (remainder > 0) { sliceCountPerSpread++; } for (int i = 0; i < outputSpreadCount; i++) { outputSpreads[i].SliceCount = sliceCountPerSpread; } }
public void GetSpread(ISpread <ISpread <double> > output) { var spread = this.Spread; int slicecount = spread.SliceCount; output.SliceCount = slicecount; for (int i = 0; i < slicecount; i++) { int slicecount2 = spread[i].SliceCount; output[i].SliceCount = slicecount2; for (int j = 0; j < slicecount2; j++) { output[i][j] = spread[i][j]; } } }
public MouseEventsSplitNode(IIOFactory factory) { MouseIn = factory.CreateSpread <Mouse>(new InputAttribute("Mouse")); BinSizePin = factory.CreateBinSizeOutput(new OutputAttribute("Bin Size") { Order = int.MaxValue }); EventTypeOut = BinSizePin.CreateBinSizeSpread <MouseNotificationKind>(new OutputAttribute("Event Type")); PositionOut = BinSizePin.CreateBinSizeSpread <Vector2D>(new OutputAttribute("Position")); MouseWheelDeltaOut = BinSizePin.CreateBinSizeSpread <int>(new OutputAttribute("Mouse Wheel Delta")); LeftButtonOut = BinSizePin.CreateBinSizeSpread <bool>(new OutputAttribute("Left Button")); MiddleButtonOut = BinSizePin.CreateBinSizeSpread <bool>(new OutputAttribute("Middle Button")); RightButtonOut = BinSizePin.CreateBinSizeSpread <bool>(new OutputAttribute("Right Button")); X1ButtonOut = BinSizePin.CreateBinSizeSpread <bool>(new OutputAttribute("X1 Button")); X2ButtonOut = BinSizePin.CreateBinSizeSpread <bool>(new OutputAttribute("X2 Button")); }
void WriteSpread <T>(ISpread <T> source, ISpread <ISpread <T> > dest, int index) { if (dest.SliceCount < (index + 1)) { dest.SliceCount = index + 1; } if (source == null) { dest[index] = new Spread <T>(0); } else { dest[index].AssignFrom(source); } }
public void CreateEnumPin(string pinName, string[] entries) { EnumName = "Enum_" + this.GetHashCode().ToString(); EnumManager.UpdateEnum(EnumName, entries[0], entries); var attr = new InputAttribute(pinName); attr.Order = 3; attr.AutoValidate = true; attr.EnumName = EnumName; Type pinType = typeof(ISpread<EnumEntry>); var pin = FIOFactory.CreateIOContainer(pinType, attr); FEnum = (ISpread<EnumEntry>)(pin.RawIOObject); }
private void HandlePinCountChanged <T>(ISpread <int> countSpread, VVVV.PluginInterfaces.V2.Spread <IIOContainer <T> > pinSpread, Func <int, IOAttribute> ioAttributeFactory) where T : class { pinSpread.ResizeAndDispose( countSpread[0], (i) => { var ioAttribute = (InputAttribute)ioAttributeFactory(i + 1); ioAttribute.AutoValidate = false; var io = FIOFactory.CreateIOContainer <T>(ioAttribute); var pin = (IIOContainer <Pin <BehaviorLink> >)io; pin.IOObject.Connected += connect; return(io); } ); }
/// <summary> /// Inserts an item to the <see cref="ISpread{T}"/> at the specified index. /// </summary> /// <param name="spread">The <see cref="ISpread{T}"/> to insert the item into.</param> /// <param name="index">The zero-based index at which item should be inserted.</param> /// <param name="item">The object to insert into the <see cref="ISpread{T}"/>.</param> /// <remarks> /// If index equals the number of items in the <see cref="ISpread{T}"/>, then item is appended to the spread. /// </remarks> public static void Insert <T>(this ISpread <T> spread, int index, T item) { if (index == spread.SliceCount) { spread.Add(item); } else { index = VMath.Zmod(index, spread.SliceCount); spread.SliceCount++; for (int j = spread.SliceCount - 1; j >= index; j--) { spread[j] = spread[j - 1]; } spread[index] = item; } }
public double[] Matrix4x4ToArray3x4(double[] V, ISpread <Matrix4x4> Transform) { int entries = Transform.SliceCount; for (int i = 0; i < entries; i++) { double[] trans = Transform[i].Values; for (int j = 0; j < 4; j++) { for (int k = 0; k < 3; k++) { V[i * 12 + j * 3 + k] = trans[j * 4 + k]; } } } return(V); }
protected void TestConfigPin <T>(T[] sampleData) { var pinName = string.Format("{0} Input", typeof(T)); var attribute = new ConfigAttribute(pinName); ISpread <T> spread = FFactory.CreateIO <ISpread <T> >(attribute); Assert.AreEqual(1, spread.SliceCount, "Initial slice count must be 1 of config spread."); TestSpread(spread, sampleData); // ISpread<ISpread<T>> spreadedSpread = new ConfigWrapperPin<ISpread<T>>(FPluginHost, attribute); // // Assert.True(spreadedSpread.SliceCount == 1); // // TestSpread(spreadedSpread, new ISpread<T>[] { new Spread<T>(sampleData.ToList()), new Spread<T>(sampleData.ToList()) }); }
protected void TestOutputPin <T>(T[] sampleData) { var pinName = string.Format("{0} Input", typeof(T)); var attribute = new OutputAttribute(pinName); ISpread <T> spread = FFactory.CreateIO <ISpread <T> >(attribute); Assert.AreEqual(1, spread.SliceCount, "Initial slice count must be 1 of output spread."); TestSpread(spread, sampleData); ISpread <ISpread <T> > spreadedSpread = FFactory.CreateIO <ISpread <ISpread <T> > >(attribute); Assert.True(spreadedSpread.SliceCount == 1); TestSpread(spreadedSpread, new ISpread <T>[] { new Spread <T>(sampleData.ToList()), new Spread <T>(sampleData.ToList()) }); }
public MouseEventsJoinNode(IIOFactory factory) { BinSizePin = factory.CreateBinSizeInput(new InputAttribute("Bin Size") { DefaultValue = InputAttribute.DefaultBinSize, Order = int.MaxValue }); EventTypeIn = BinSizePin.CreateBinSizeSpread <MouseNotificationKind>(new InputAttribute("Event Type")); PositionIn = BinSizePin.CreateBinSizeSpread <Vector2D>(new InputAttribute("Position")); MouseWheelIn = BinSizePin.CreateBinSizeSpread <int>(new InputAttribute("Mouse Wheel Delta")); LeftButtonIn = BinSizePin.CreateBinSizeSpread <bool>(new InputAttribute("Left Button")); MiddleButtonIn = BinSizePin.CreateBinSizeSpread <bool>(new InputAttribute("Middle Button")); RightButtonIn = BinSizePin.CreateBinSizeSpread <bool>(new InputAttribute("Right Button")); X1ButtonIn = BinSizePin.CreateBinSizeSpread <bool>(new InputAttribute("X1 Button")); X2ButtonIn = BinSizePin.CreateBinSizeSpread <bool>(new InputAttribute("X2 Button")); MouseOut = factory.CreateSpread <Mouse>(new OutputAttribute("Mouse")); MouseOut.SliceCount = 0; }
protected override void Filter(int ei, NotuiElement element, ISpread <string> filter) { bool CompareType(NotuiElement el) { var res = false; foreach (var f in filter) { if (string.IsNullOrWhiteSpace(f)) { continue; } if (el.EnvironmentObject is VEnvironmentData venvdat) { res = FContains[ei] ? venvdat.TypeCSharpName.Contains(f) : venvdat.TypeCSharpName == f; } else { res = FContains[ei] ? el.GetType().GetCSharpName().Contains(f) : el.GetType().GetCSharpName() == f; } if (!res) { continue; } break; } return(FExclude[ei] ? !res : res); }; if (FContains.SliceCount == 0 || FExclude.SliceCount == 0) { return; } else { if (FOut.SliceCount == 0) { return; } FOut[ei].AddRange(element.Children.Values.Where(CompareType)); } }
public void CreateEnumPin(string pinName, string[] entries) { EnumName = "Enum_" + this.GetHashCode().ToString(); EnumManager.UpdateEnum(EnumName, entries[0], entries); var attr = new InputAttribute(pinName); attr.Order = 2; attr.AutoValidate = true; attr.EnumName = EnumName; Type pinType = typeof(ISpread <EnumEntry>); var pin = FIOFactory.CreateIOContainer(pinType, attr); FUseAsID = (ISpread <EnumEntry>)(pin.RawIOObject); }
#pragma warning restore #endregion fields & pins public void OnImportsSatisfied() { var binSizeAttr = new InputAttribute("Bin Size"); binSizeAttr.DefaultValue = -1; binSizeAttr.Order = 4; var binSizeIOContainer = FIOFactory.CreateIOContainer <IInStream <int> >(binSizeAttr); var inAttr = new InputAttribute("Input Breakpoint"); inAttr.Order = 2; FInBp = new InputBinSpread <double>(FIOFactory, inAttr, binSizeIOContainer); var outAttr = new InputAttribute("Output Breakpoint"); outAttr.Order = 3; FOutBp = new InputBinSpread <double>(FIOFactory, outAttr, binSizeIOContainer); }
public static PointF[][] ImagePoints(ISpread <Vector2D> input, int pointsPerImage) { int images = input.SliceCount / pointsPerImage; PointF[][] imagePoints = new PointF[images][]; for (int i = 0; i < images; i++) { imagePoints[i] = new PointF[pointsPerImage]; for (int j = 0; j < pointsPerImage; j++) { imagePoints[i][j].X = (float)input[i * pointsPerImage + j].x; imagePoints[i][j].Y = (float)input[i * pointsPerImage + j].y; } } return(imagePoints); }
public static PointF[][] ImagePoints(ISpread<Vector2D> input, int pointsPerImage) { int images = input.SliceCount / pointsPerImage; PointF[][] imagePoints = new PointF[images][]; for (int i = 0; i < images; i++) { imagePoints[i] = new PointF[pointsPerImage]; for (int j = 0; j < pointsPerImage; j++) { imagePoints[i][j].X = (float)input[i * pointsPerImage + j].x; imagePoints[i][j].Y = (float)input[i * pointsPerImage + j].y; } } return imagePoints; }
//internal use + keyPoint manipulation, i.e. solving zspread //Note: this api will bypass curve calibration public YieldCurve( string name, Date referenceDate, Tuple <Date, double>[] keyPoints, BusinessDayConvention bda, IDayCount dayCount, ICalendar calendar, CurrencyCode currency, Compound compound, Interpolation interpolation, YieldCurveTrait trait, IMarketCondition baseMarket = null, Expression <Func <IMarketCondition, object> >[] calibrateMktUpdateCondition = null, ISpread spread = null, string[] keyTenors = null, InstrumentCurveDefinition rawDefinition = null ) { Name = name; ReferenceDate = referenceDate; Currency = currency; Bda = bda; DayCount = dayCount; Compound = compound; Calendar = calendar; Interpolation = interpolation; Trait = trait; BaseMarket = baseMarket; Spread = spread ?? new ZeroSpread(0.0); CalibrateMktUpdateCondition = calibrateMktUpdateCondition; MarketInstruments = null; KeyPoints = keyPoints.OrderBy(x => x.Item1).ToArray(); KeyTenors = keyTenors ?? KeyPoints.Select(x => new Term(x.Item1 - ReferenceDate, Period.Day)).Select(x => x.ToString()).ToArray(); RawDefinition = rawDefinition; InputRateByTenor = KeyPoints.Select(x => Tuple.Create <string, double> (new Term(x.Item1 - ReferenceDate, Period.Day).ToString(), x.Item2)). ToDictionary(v => v.Item1, v => v.Item2); //_curve = new Curve<Date>(ReferenceDate, KeyPoints, x => x.ToOADate(), interpolation); _curveXInYears = new Curve <double>(0.0, KeyPoints.Select(x => Tuple.Create(DayCount.CalcDayCountFraction(ReferenceDate, x.Item1), x.Item2)).ToArray(), x => x, Interpolation); }
public void Apply(DX11Resource <DX11RenderTextureArray> textureArray, ISpread <int> slices) { int w = textureArray[context].Width; int h = textureArray[context].Height; int d = slices.SliceCount; Format f = textureArray[context].Format; Texture2DDescription descIn = textureArray[context].Resource.Description; // check if parameters match - if not, create a new rt array if (this.rtarr != null) { if (this.rtarr.ElemCnt != d || this.rtarr.Width != w || this.rtarr.Height != h || this.rtarr.Description.MipLevels != descIn.MipLevels || this.rtarr.Format != f) { this.rtarr.Dispose(); this.rtarr = null; } } if (this.rtarr == null) { this.rtarr = new DX11RenderTextureArray(this.context, w, h, d, f, true, descIn.MipLevels); } // copy the ressources over for (int i = 0; i < slices.SliceCount; i++) { int slice = VMath.Zmod(slices[i], textureArray[context].ElemCnt); SlimDX.Direct3D11.Resource source = textureArray[context].Resource; for (int mip = 0; mip < descIn.MipLevels; mip++) { //int mip = 0; int sourceSubres = SlimDX.Direct3D11.Texture2D.CalculateSubresourceIndex(mip, slice, descIn.MipLevels); int destinationSubres = SlimDX.Direct3D11.Texture2D.CalculateSubresourceIndex(mip, i, descIn.MipLevels); context.CurrentDeviceContext.CopySubresourceRegion(source, sourceSubres, this.rtarr.Resource, destinationSubres, 0, 0, 0); } } }
protected override void Filter(int ei, NotuiElement element, ISpread <string> filter) { if (FUseName.SliceCount == 0 || FSeparator.SliceCount == 0) { return; } foreach (var f in filter) { if (string.IsNullOrWhiteSpace(f)) { continue; } if (FOut.SliceCount == 0) { return; } FOut[ei].AddRange(element.Opaq(f, FSeparator[ei], FUseName[ei])); } }
public static bool IsAnyInvalid(this ISpread spread, params ISpread[] spreads) { if (spread.SliceCount == 0 || spread[0] == null) { return(true); } else { for (int i = 0; i < spreads.Length; i++) { if (spreads[i].SliceCount == 0 || spreads[i][0] == null) { return(true); } } } return(false); }
/// <summary> /// Returns the max slice count of all spreads or zero if one of the slice counts is zero. /// </summary> /// <param name="spreads">A spread of spreads for which to return the max slice count.</param> /// <returns>The max slice count of all spreads.</returns> public static int GetMaxSliceCount <T>(this ISpread <ISpread <T> > spreads) { switch (spreads.SliceCount) { case 0: return(0); case 1: return(spreads[0].SliceCount); default: int result = spreads[0].SliceCount; for (int i = 1; i < spreads.SliceCount; i++) { result = result.CombineWith(spreads[i]); } return(result); } }
public static bool IsAnyEmpty(this ISpread spread, params ISpread[] spreads) { if (spread.SliceCount == 0) { return(true); } else { for (int i = 0; i < spreads.Length; i++) { if (spreads[i].SliceCount == 0) { return(true); } } } return(false); }
public static KeyState Join(ISpread <int> keys, int time) { switch (keys.SliceCount) { case 0: return(new KeyState(Keys.None, time)); case 1: return(new KeyState((Keys)keys[0], time)); default: Keys keyCode = Keys.None; foreach (Keys key in keys) { switch (key) { case Keys.ShiftKey: case Keys.LShiftKey: case Keys.RShiftKey: keyCode |= Keys.Shift; break; case Keys.ControlKey: keyCode |= Keys.Control; break; case Keys.Menu: case Keys.LMenu: case Keys.RMenu: keyCode |= Keys.Alt; break; default: // Do not allow more than one "normal" key keyCode &= Keys.Modifiers; keyCode |= key; break; } } return(new KeyState(keyCode, time)); } }
public void Set(DataRow row, ISpread <double> values, ISpread <bool> set) { //check whether slice count is too big. if soo add columns //should generally happen on first row only in a spread of spreads while (Math.Max(values.SliceCount, set.SliceCount) > this.Columns.Count) { this.AddColumn(this.Columns.Count.ToString()); } //set values for (int i = 0; i < row.ItemArray.Length; i++) { if (set[i]) { row[i] = values[i]; } } OnDataChange(null); }
static List <string> ScanDirectories(ISpread <string> directories, ISpread <string> filemasks) { var files = new List <string>(); for (int i = 0; i < directories.SliceCount; i++) { try { var directoryInfo = new DirectoryInfo(directories[i]); var filesInDir = directoryInfo.EnumerateFiles(filemasks[i]) .Where(f => !f.Attributes.HasFlag(FileAttributes.Hidden)) .OrderBy(f => f.Name) .Select(f => f.FullName); files.AddRange(filesInDir); } catch (DirectoryNotFoundException) { } } return(files); }
public static KeyboardState Join(ISpread <int> keys, bool capsLock, int time) { switch (keys.SliceCount) { case 0: return(KeyboardState.Empty); case 1: var key = keys[0]; if (key == 0) { return(new KeyboardState(Enumerable.Empty <Keys>(), capsLock, time)); } else { return(new KeyboardState(keys.Cast <Keys>(), capsLock, time)); } default: return(new KeyboardState(keys.Cast <Keys>(), capsLock, time)); } }
public void CreateEnumPin(string pinName, IEnumerable<string> entries) { EnumName = "Enum_" + this.GetHashCode().ToString(); FillEnum(entries); var attr = new InputAttribute(pinName); attr.Order = 2; attr.AutoValidate = true; attr.BinVisibility = PinVisibility.OnlyInspector; attr.BinSize = -1; attr.BinOrder = 3; attr.CheckIfChanged = true; attr.EnumName = EnumName; Type pinType = typeof(ISpread<ISpread<EnumEntry>>); var pin = FIOFactory.CreateIOContainer(pinType, attr); FUseFields = (ISpread<ISpread<EnumEntry>>)(pin.RawIOObject); }
public IYieldCurve GetSpreadedCurve(ISpread spread) { return(new YieldCurve( Name, ReferenceDate, KeyPoints, Bda, DayCount, Calendar, Currency, Compound, Interpolation, Trait, BaseMarket, CalibrateMktUpdateCondition, spread, KeyTenors ) { MarketInstruments = MarketInstruments }); }
public SystemProcessorsNode([Output("Physical Processors", IsSingle = true)] ISpread <int> physical, [Output("Cores", IsSingle = true)] ISpread <int> cores, [Output("Logical Processors", IsSingle = true)] ISpread <int> logical) { FPhysical = physical; FCores = cores; FLogical = logical; //via http://stackoverflow.com/questions/1542213/how-to-find-the-number-of-cpu-cores-via-net-c foreach (var item in new System.Management.ManagementObjectSearcher("Select * from Win32_ComputerSystem").Get()) { FPhysical[0] = int.Parse(item["NumberOfProcessors"].ToString()); } int coreCount = 0; foreach (var item in new System.Management.ManagementObjectSearcher("Select * from Win32_Processor").Get()) { coreCount += int.Parse(item["NumberOfCores"].ToString()); } FCores[0] = coreCount; FLogical[0] = Environment.ProcessorCount; }
protected void SetData(Message message, int avoidNilIndex, string fieldName, ISpread output) { output.SliceCount = 0; if (!message.Fields.Contains(fieldName)) { // is setting a default necessary? if (!FAvoidNilEnable.IsAnyInvalid() && FAvoidNilEnable[0]) { var avoidNil = FAvoidNil.ToISpread() as ISpread; var results = GetDefaults(avoidNil, avoidNilIndex).ToList(); output.SliceCount = results.Count; for (int j = 0; j < results.Count; j++) { output[j] = results[j]; } } } else // copy from Message { var inputBin = message[fieldName]; output.SliceCount = inputBin.Count; if (TargetDynamicType.IsAssignableFrom(inputBin.GetInnerType())) { for (int j = 0; j < inputBin.Count; j++) { output[j] = inputBin[j]; } } else // will throw Exception, if Conversion is not possible { for (int j = 0; j < inputBin.Count; j++) { output[j] = Convert.ChangeType(inputBin[j], TargetDynamicType, CultureInfo.InvariantCulture); } } } }
public static bool IsAnyInvalid(this ISpread spread, params ISpread[] spreads) { if (spread == null) { return(true); } if (spread.SliceCount == 0 || spread[0] == null) { return(true); } if (spread[0] is ISpread) { if ((spread[0] as ISpread).IsAnyInvalid()) { return(true); } //for (int i= 0; i < spread.SliceCount;i++) //{ // if ((spread[i] as ISpread).IsAnyInvalid()) return true; //} } for (int i = 0; i < spreads.Length; i++) { if (spreads[i] == null) { return(true); } if (spreads[i].SliceCount == 0 || spreads[i][0] == null) { return(true); } } return(false); }
byte[] PinSpreadToPorts(ISpread<double> spread) { int num_ports = spread.SliceCount/8 + (spread.SliceCount%8==0 ? 0 : 1); byte[] bytes = new byte[num_ports]; for(int port_index=0; port_index<num_ports; port_index++) { byte port = 0x00; for (int bit=0; bit<8; bit++) { int src_index = port_index*8+bit; double val = src_index<spread.SliceCount ? spread[src_index]:0; port |= (byte)((val >= 0.5 ? 1:0)<<bit); } bytes[port_index] = port; } return bytes; }
string SetPinStates(ISpread<double> values) { // TODO: handle PWN set pins! byte[] ports = PinSpreadToPorts(values); List<byte> cmd = new List<byte>(); for(int port=0; port<ports.Length; port++) { byte LSB, MSB; GetBytesFromValue(ports[port], out MSB, out LSB); //FLogger.Log(LogType.Debug,port.ToString()); // We take the 4 MSB from the command type and the 4 LSB from the pin byte the_port = ATMegaPorts.getPortForIndex(port); byte writeCommand = (byte)((uint) FirmataCommands.DIGITALMESSAGE | the_port); // Write the command to enable the analog output for the pin we want cmd.Add(writeCommand); cmd.Add(LSB); cmd.Add(MSB); FLogger.Log(LogType.Debug,"To port({0}):",the_port); FLogger.Log(LogType.Debug,Convert.ToString(writeCommand,16)); FLogger.Log(LogType.Debug,Convert.ToString(LSB,2)); FLogger.Log(LogType.Debug,Convert.ToString(MSB,2)); } return Encode(cmd.ToArray()); }
public void Update(int techid, int passid, ISpread<DX11Resource<IDX11Geometry>> geoms) { this.techid = techid; this.passid = passid; this.UpdateTechnique(); //Rebuild Layout this.DisposeLayouts(); for (int i = 0; i < geoms.SliceCount; i++) { try { if (pass.Description.Signature != null) { InputLayout layout = new InputLayout(this.context.Device, pass.Description.Signature, geoms[i][this.context].InputLayout); this.layouts.Add(layout); this.layoutvalid.Add(true); this.layoutmsg.Add("OK"); } else { this.layouts.Add(null); this.layoutvalid.Add(true); this.layoutmsg.Add("OK"); } } catch { try { //Do bit of reflection work to get missing semantic EffectShaderVariable vs = pass.VertexShaderDescription.Variable; int inputcount = vs.GetShaderDescription(0).InputParameterCount; string missingsemantics = "Geometry is missing semantics: "; bool first = true; for (int vip = 0; vip < inputcount; vip++) { ShaderParameterDescription sd = vs.GetInputParameterDescription(0, vip); if (sd.SystemType == SystemValueType.Undefined) //Ignore SV semantics { bool found = false; foreach (InputElement e in geoms[i][this.context].InputLayout) { if (sd.SemanticName == e.SemanticName && sd.SemanticIndex == e.SemanticIndex) { found = true; } } if (!found) { string sem = sd.SemanticIndex == 0 ? "" : sd.SemanticIndex.ToString(); if (first) { first = false; } else { missingsemantics += " : "; } missingsemantics += sd.SemanticName + sem; } } } this.layouts.Add(null); this.layoutvalid.Add(false); this.layoutmsg.Add(missingsemantics); } catch (Exception ex) { //Just in case this.layouts.Add(null); this.layoutvalid.Add(false); this.layoutmsg.Add(ex.Message); } } } }
/// <summary> /// Override in sub class to know when the input has changed /// </summary> /// <param name="newInput"></param> protected virtual void InputWasSet(ISpread<AudioSignal> newInput) { }
public void RemoveOutput(ISpread<AudioSignal> provider) { if(provider == null) return; foreach(var p in provider) MultiInputProvider.Remove(p); }
public void Evaluate(int SpreadMax) { this.FOutCtrl[0] = this; if (this.FOutQueryable[0] == null) { this.FOutQueryable[0] = this; } if (this.FOutBackBuffer[0] == null) { this.FOutBackBuffer[0] = new DX11Resource<DX11SwapChain>(); this.FOuFS = new Spread<DX11Resource<DX11SwapChain>>(); this.FOuFS.SliceCount = 1; this.FOuFS[0] = new DX11Resource<DX11SwapChain>(); } this.updateddevices.Clear(); this.rendereddevices.Clear(); this.FInvalidateSwapChain = false; if (!this.depthmanager.FormatChanged) // do not clear reset if format changed { this.depthmanager.NeedReset = false; } else { this.depthmanager.FormatChanged = false; //Clear flag ok } if (this.oldbbformat != this.FCfgBackBufferFormat[0].Name || FInAASamplesPerPixel.IsChanged) { this.oldbbformat = this.FCfgBackBufferFormat[0]; this.depthmanager.NeedReset = true; this.FInvalidateSwapChain = true; } if (this.FInFullScreen.IsChanged) { string path; this.FHost.GetNodePath(false, out path); INode2 n2 = hde.GetNodeFromPath(path); if (n2.Window != null) { if (n2.Window.IsVisible) { if (this.FInFullScreen[0]) { hde.SetComponentMode(n2, ComponentMode.Fullscreen); } else { hde.SetComponentMode(n2, ComponentMode.InAWindow); } } } } /*if (this.FInFullScreen.IsChanged) { if (this.FInFullScreen[0]) { string path; this.FHost.GetNodePath(false, out path); INode2 n2 = hde.GetNodeFromPath(path); hde.SetComponentMode(n2, ComponentMode.Fullscreen); } else { string path; this.FHost.GetNodePath(false, out path); INode2 n2 = hde.GetNodeFromPath(path); hde.SetComponentMode(n2, ComponentMode.InAWindow); } }*/ this.FOutKState[0] = new KeyboardState(this.FKeys); this.FOutMouseState[0] = MouseState.Create(this.FMousePos.x, this.FMousePos.y, this.FMouseButtons.x > 0.5f, this.FMouseButtons.y > 0.5f, this.FMouseButtons.z> 0.5f, false, false, this.wheel); this.FOutBackBufferSize[0] = new Vector2D(this.Width, this.Height); this.FOutTouchSupport[0] = this.touchsupport; this.FOutTouchData.SliceCount = this.touches.Count; int tcnt = 0; float fw = (float)this.ClientSize.Width; float fh = (float)this.ClientSize.Height; lock (m_touchlock) { foreach (int key in touches.Keys) { TouchData t = touches[key]; this.FOutTouchData[tcnt] = t.Clone(fw, fh); t.IsNew = false; tcnt++; } } }
public void Evaluate(int SpreadMax) { if (In.IsChanged) { Values.SliceCount = PortNumber.SliceCount * 8; // 8 bits per port Port.SliceCount = PortNumber.SliceCount; foreach (string msg in In){ byte[] data = Encoding.GetEncoding(1252).GetBytes(msg); if(!FirmataUtils.ContainsCommand(data,Command.DIGITALMESSAGE)) { continue; // } int port; int[] values; if (FirmataUtils.DecodePortMessage(data, out port, out values)) { Port[0] = port; Values.AssignFrom(values); CachedValues = Values.Clone(); } else { Values = CachedValues.Clone(); } } } }
public static void UpdateBlobs(ISpread<Blob> allBlobs, ISpread<Blob> currentBlobs, int id) { for (var i = 0; i < currentBlobs.Count(); i++) { var found = false; for (var j = 0; j < allBlobs.Count(); j++) { //Check if blob exists if (currentBlobs[i].Id != allBlobs[j].Id) continue; //Check if blob not hited another object //TODO: Find, if this needed or not. //if(allBlobs[j].HitId > 0 && allBlobs[j].HitId != id) continue; currentBlobs[i] = allBlobs[j]; found = true; break; } if(!found) currentBlobs.RemoveAt(i); } }
public static void SetIsNew(ISpread<Blob> blobs, ISpread<Blob> pBlobs) { if (pBlobs.SliceCount == 0) { for (var i = 0; i < blobs.SliceCount; i++) { blobs[i] = new Blob{Position = blobs[i].Position, HitId = blobs[i].HitId, Id = blobs[i].Id, IsNew = true}; } } else { for (var i = 0; i < blobs.SliceCount; i++) { //TODO: Proper new blob detection blobs[i] = new Blob { Position = blobs[i].Position, HitId = blobs[i].HitId, Id = blobs[i].Id, IsNew = pBlobs.All(blob => blob.Id != blobs[i].Id)}; } } pBlobs.SliceCount = blobs.SliceCount; pBlobs.AssignFrom(blobs); }
public static Vector2D FindCentroid(ISpread<Blob> blobs) { var summ = new Vector2D(); return blobs.Aggregate(summ, (current, blob) => current + blob.Position) / blobs.Count(); }
public CVImageOutputSpread(ISpread<CVImageLink> outputPin) { FOutputPin = outputPin; }
public AudioOutNode() { LastProvider = new Spread<AudioSignal>(); }
public static void UpdateBlobs(ISpread<Blob> allBlobs, ISpread<Blob> currentBlobs, int id) { Debug.WriteLine(allBlobs.SliceCount + " " + currentBlobs.SliceCount); for (var i = 0; i < currentBlobs.Count(); i++) { var found = false; for (var j = 0; j < allBlobs.Count(); j++) { //Check if blob exists if (currentBlobs[i].Id != allBlobs[j].Id) continue; //Check if blob not hited another object if(allBlobs[j].HitId > 0 && allBlobs[j].HitId != id) continue; // if (currentBlobs.SliceCount > 2) // { // Debug.WriteLine(allBlobs); // } currentBlobs[i] = allBlobs[j]; found = true; break; } if(!found) currentBlobs.RemoveAt(i); } }
void SetPinStates(ISpread<double> values) { // get the number of output ports // FIXME: Make MAX_PORTS avaiable through Firmata int[] digital_out = new int[OUTPUT_PORT_MASKS.Length]; for(int i=0; i<values.SliceCount; i++) { double value = values[i]; PinMode mode = PinModeForPin(i); switch(mode) { case PinMode.ANALOG: case PinMode.PWM: case PinMode.SERVO: byte LSB,MSB; value *= mode==PinMode.SERVO ? 180 : 255; // servo is in degrees FirmataUtils.GetBytesFromValue((int)value,out MSB,out LSB); CommandBuffer.Enqueue((byte)(Command.ANALOGMESSAGE | i)); CommandBuffer.Enqueue(LSB); CommandBuffer.Enqueue(MSB); break; case PinMode.OUTPUT: case PinMode.INPUT: // fixes PullUp enabling issue, thx to motzi! int port_index = PortIndexForPin(i); // Break, if we have no ouputports we can get if (port_index >= digital_out.Length) break; int shift = i%8; int state = value >= 0.5 ? 0x01 : 0x00; int port_before = digital_out[port_index]; digital_out[port_index] = ((state << shift) | digital_out[port_index]) & OUTPUT_PORT_MASKS[port_index]; break; } } /// Write all the output ports to the command buffer for(int port_index=0; port_index<digital_out.Length; port_index++) { byte LSB,MSB; byte atmega_port = (byte) port_index; //Array.GetValues(Port)[port_index]; FirmataUtils.GetBytesFromValue(digital_out[port_index],out MSB,out LSB); CommandBuffer.Enqueue((byte)(Command.DIGITALMESSAGE | atmega_port)); CommandBuffer.Enqueue(LSB); CommandBuffer.Enqueue(MSB); } }
public CVImageInputSpread(ISpread<CVImageLink> inputPin) { FInputPin = inputPin; CheckInputSize(); }
protected void SetData(Message message, int avoidNilIndex, string fieldName, ISpread output) { output.SliceCount = 0; if (!message.Fields.Contains(fieldName)) { // is setting a default necessary? if (!FAvoidNilEnable.IsAnyInvalid() && FAvoidNilEnable[0]) { var avoidNil = FAvoidNil.ToISpread() as ISpread; var results = GetDefaults(avoidNil, avoidNilIndex).ToList(); output.SliceCount = results.Count; for (int j = 0; j < results.Count; j++) output[j] = results[j]; } } else // copy from Message { var inputBin = message[fieldName]; output.SliceCount = inputBin.Count; if (TargetDynamicType.IsAssignableFrom(inputBin.GetInnerType())) { for (int j = 0; j < inputBin.Count; j++) output[j] = inputBin[j]; } else // will throw Exception, if Conversion is not possible { for (int j = 0; j < inputBin.Count; j++) output[j] = Convert.ChangeType(inputBin[j], TargetDynamicType, CultureInfo.InvariantCulture); } } }
public void Evaluate(int SpreadMax) { this.FOutCtrl[0] = this; this.FOutRef[0] = (INode)this.FHost; if (this.FOutQueryable[0] == null) { this.FOutQueryable[0] = this; } if (this.FOutBackBuffer[0] == null) { this.FOutBackBuffer[0] = new DX11Resource<DX11SwapChain>(); this.FOuFS = new Spread<DX11Resource<DX11SwapChain>>(); this.FOuFS.SliceCount = 1; this.FOuFS[0] = new DX11Resource<DX11SwapChain>(); } this.updateddevices.Clear(); this.rendereddevices.Clear(); this.FInvalidateSwapChain = false; if (!this.depthmanager.FormatChanged) // do not clear reset if format changed { this.depthmanager.NeedReset = false; } else { this.depthmanager.FormatChanged = false; //Clear flag ok } if (FInAASamplesPerPixel.IsChanged || this.FInBufferCount.IsChanged) { this.depthmanager.NeedReset = true; this.FInvalidateSwapChain = true; } if (this.FInFullScreen.IsChanged) { string path; this.FHost.GetNodePath(false, out path); INode2 n2 = hde.GetNodeFromPath(path); if (n2.Window != null) { if (n2.Window.IsVisible) { if (this.FInFullScreen[0]) { // if the pin is true we want to give it priority over the component mode set in the patch. also in the first frame. hde.SetComponentMode(n2, ComponentMode.Fullscreen); } else { // checking for first frame is necessary. the pin will always report to be changed in the very first frame. // however in the first frame we want to respect the component mode that is saved in the patch if (!FirstFrame) hde.SetComponentMode(n2, ComponentMode.InAWindow); } } } } /*if (this.FInFullScreen.IsChanged) { if (this.FInFullScreen[0]) { string path; this.FHost.GetNodePath(false, out path); INode2 n2 = hde.GetNodeFromPath(path); hde.SetComponentMode(n2, ComponentMode.Fullscreen); } else { string path; this.FHost.GetNodePath(false, out path); INode2 n2 = hde.GetNodeFromPath(path); hde.SetComponentMode(n2, ComponentMode.InAWindow); } }*/ this.FOutKState[0] = new KeyboardState(this.FKeys); this.FOutMouseState[0] = MouseState.Create(this.FMousePos.x, this.FMousePos.y, this.FMouseButtons.x > 0.5f, this.FMouseButtons.y > 0.5f, this.FMouseButtons.z> 0.5f, false, false, this.wheel); this.FOutBackBufferSize[0] = new Vector2D(this.Width, this.Height); this.FOutTouchSupport[0] = this.touchsupport; this.FOutTouchData.SliceCount = this.touches.Count; int tcnt = 0; float fw = (float)this.ClientSize.Width; float fh = (float)this.ClientSize.Height; lock (m_touchlock) { foreach (int key in touches.Keys) { TouchData t = touches[key]; this.FOutTouchData[tcnt] = t.Clone(fw, fh); t.IsNew = false; tcnt++; } } FirstFrame = false; }
public MultiSineSignal(ISpread<float> frequency, ISpread<float> gain) { Frequencies = frequency; Gains = gain; Phases = new Spread<float>(); }
private IEnumerable<object> GetDefaults(ISpread avoidNil, int avoidNilIndex) { if (avoidNil == null || avoidNil.SliceCount == 0 || (avoidNil[avoidNilIndex] as ISpread).SliceCount == 0 || (avoidNil[avoidNilIndex] as ISpread)[0] == null ) { // something is fishy with AvoidNil pin, so fetch a safe default here var item = TypeIdentity.Instance[TargetDynamicType].Default(); if (item != null) yield return item; } else // copy all relevant ones from AvoidNil pin { var items = avoidNil[avoidNilIndex] as ISpread; for (int j = 0; j < items.SliceCount; j++) yield return items[j]; } }