/// <summary> /// Tries to get a managed coordinate transformation for the specified coordinate reference systems. /// </summary> /// <param name="sourceId">The source coordinate reference system.</param> /// <param name="targetId">The source coordinate reference system.</param> /// <param name="transform">The managed coordinate transformation, returned on success.</param> /// <returns>True, if a valid managed coordinate transformation could be found a/o created. False otherwise.</returns> internal static bool TryGet(string sourceId, string targetId, out ICoordinateTransformation transform) { transform = null; TransformDelegate t = null; if (OnGetTransform != null) { t = OnGetTransform(sourceId, targetId); } if (t == null) { if (string.Compare(sourceId, targetId, true) == 0) { t = IdentityTransform; } else { CoordinateTransformations.TryGetTransformation(sourceId, targetId, out t); } } if (t != null) { transform = new CoordinateTransformation(t); } return(transform != null); }
/// <summary> /// Tries to get a transformation chain for the given CRS identifiers. /// </summary> /// <param name="sourceId">Identifier of the source coordinate reference system.</param> /// <param name="targetId">Identifier of the target coordinate reference system.</param> /// <param name="transform">The transformmation deleagte, returned on success.</param> /// <returns>True, if a valid managed transformation chain could be found. False otherwise.</returns> private static bool TryGetTransformationChain(string sourceId, string targetId, out TransformDelegate transform) { transform = null; string[][] chains = new string[][] { new[] { sourceId, WGS84, targetId }, new[] { sourceId, PTV_MERCATOR, targetId }, new[] { sourceId, WGS84, PTV_MERCATOR, targetId }, new[] { sourceId, PTV_MERCATOR, WGS84, targetId } }; foreach (string[] chain in chains) { TransformDelegate[] delegates = new TransformDelegate[chain.Length - 1]; for (int i = 0; delegates != null && i < chain.Length - 1; ++i) { if (!TryGetTransformation(chain[i], chain[i + 1], out delegates[i])) { delegates = null; } } if (delegates == null) { continue; } transform = new TransformDelegate(new TransformationChain(delegates).Transform); return(true); } return(false); }
public RewriteRule(string debugName, LambdaExpression find, LambdaExpression replace, Func <Match, Expression, bool> condition, TransformDelegate transform) { DebugName = debugName; Find = find; Replace = replace; Condition = condition; Transform = transform; }
/// <summary> /// Creates a new instance of the <see cref="CC_ExecuteMethod"/> class /// </summary> /// <param name="method">The method to execute</param> public CC_ExecuteMethod(TransformDelegate method) { if (method == null) { throw new ArgumentNullException(nameof(method)); } MethodT = method; }
/// <summary> /// Initializes a new instance of the <see cref="ImageTransformer"/> class. /// </summary> /// <param name="pipeline">The pipeline to add the component to.</param> /// <param name="transformer">Function for transforming the source image.</param> /// <param name="pixelFormat">Pixel format for destination image.</param> /// <param name="sharedImageAllocator ">Optional image allocator for creating new shared image.</param> public ImageTransformer(Pipeline pipeline, TransformDelegate transformer, PixelFormat pixelFormat, System.Func <int, int, PixelFormat, Shared <Image> > sharedImageAllocator = null) : base(pipeline) { this.transformer = transformer; this.pixelFormat = pixelFormat; sharedImageAllocator ??= (width, height, pixelFormat) => ImagePool.GetOrCreate(width, height, pixelFormat); this.sharedImageAllocator = sharedImageAllocator; }
public static ITransformer ToTransformer(this TransformDelegate transformDelegate) { if (transformDelegate is null) { throw new ArgumentNullException(nameof(transformDelegate)); } return(new TransformDelegateWrapper(transformDelegate)); }
public Dictionary <string, object> GetComputedTags(TemplateMetadata metadata, Dictionary <string, object> tagValues) { var result = new Dictionary <string, object>(); if (metadata.ComputedTags != null) { var interpreter = new Interpreter(); foreach (var tag in tagValues) { interpreter.SetVariable(tag.Key, tag.Value); } CountDelegate countFunc = Count; TransformDelegate xmlEncodeFunc = XmlEncode; TransformDelegate lowerCaseFunc = LowerCase; TransformDelegate upperCaseFunc = UpperCase; TransformDelegate titleCaseFunc = TitleCase; TransformDelegate kebabCaseFunc = KebabCase; interpreter.SetFunction("Count", countFunc); interpreter.SetFunction("count", countFunc); interpreter.SetFunction("xmlEncode", xmlEncodeFunc); interpreter.SetFunction("lowerCase", lowerCaseFunc); interpreter.SetFunction("lowerCaseInvariant", lowerCaseFunc); interpreter.SetFunction("upperCase", upperCaseFunc); interpreter.SetFunction("upperCaseInvariant", upperCaseFunc); interpreter.SetFunction("titleCase", titleCaseFunc); interpreter.SetFunction("kebabCase", kebabCaseFunc); foreach (var computedTag in metadata.ComputedTags) { try { if (!result.ContainsKey(computedTag.Key)) { object value = interpreter.Eval(computedTag.Expression); object computedValue = value is bool?((bool)value) == true : value; result.Add(computedTag.Key, computedValue); if (!tagValues.ContainsKey(computedTag.Key)) { interpreter.SetVariable(computedTag.Key, computedValue); } } } catch (Exception ex) { var error = $"Cannot compute `{computedTag.Key}` expression `{computedTag.Expression}: {ex}`"; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(error); Console.ResetColor(); } } } return(result); }
/// <summary> /// Tries to get a managed coordinate transformation for the specified coordinate reference systems. /// </summary> /// <param name="source">The source coordinate reference system.</param> /// <param name="target">The source coordinate reference system.</param> /// <param name="transform">The managed coordinate transformation, returned on success.</param> /// <returns>True, if a valid managed coordinate transformation could be found a/o created. False otherwise.</returns> internal static bool TryGet(CoordinateReferenceSystem source, CoordinateReferenceSystem target, out ICoordinateTransformation transform) { transform = null; if (source == null || target == null) { return(false); } return(TryGet(source.getId(), target.getId(), out transform)); }
static List <TOut> Transform <TIn, TOut>(List <TIn> data, TransformDelegate <TIn, TOut> transform) { List <TOut> result = new List <TOut>(); foreach (TIn item in data) { result.Add(transform(item)); } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="ImageTransformer"/> class. /// </summary> /// <param name="pipeline">The pipeline to add the component to.</param> /// <param name="transformer">Function for transforming the source image.</param> /// <param name="pixelFormat">Pixel format for destination image.</param> /// <param name="sharedImageAllocator ">Optional image allocator for creating new shared image.</param> /// <param name="name">An optional name for the component.</param> public ImageTransformer( Pipeline pipeline, TransformDelegate transformer, PixelFormat pixelFormat, Func <int, int, PixelFormat, Shared <Image> > sharedImageAllocator = null, string name = nameof(ImageTransformer)) : base(pipeline, name) { this.transformer = transformer; this.pixelFormat = pixelFormat; this.sharedImageAllocator = sharedImageAllocator ?? ((width, height, pixelFormat) => ImagePool.GetOrCreate(width, height, pixelFormat)); }
/// <summary> /// Tries to get a managed transformation for the given CRS identifiers. /// </summary> /// <param name="sourceId">Identifier of the source coordinate reference system.</param> /// <param name="targetId">Identifier of the target coordinate reference system.</param> /// <param name="transform">The transformmation deleagte, returned on success.</param> /// <returns>True, if a valid managed transformation could be found. False otherwise.</returns> public static bool TryGetTransformation(string sourceId, string targetId, out TransformDelegate transform) { sourceId = sourceId.GetRootId(); targetId = targetId.GetRootId(); if (string.Compare(sourceId, targetId, true) != 0) { return(transformations.TryGetValue(GetTransformationKey(sourceId, targetId), out transform)); } transform = new TransformDelegate(CoordinateTransformation.IdentityTransform); return(true); }
/// <summary> /// Gets a managed coordinate transformation for the specified coordinate reference system identifiers. /// </summary> /// <param name="sourceId">Identifier of the source coordinate reference system.</param> /// <param name="targetId">Identifier of the target coordinate reference system.</param> /// <returns>The managed coordinate transformation, provided through <see cref="ICoordinateTransformation"/>.</returns> /// <exception cref="TransformationNotFoundException">Thrown if no transformation is available to transform coordinates /// from the specified source to the specified target coordinate reference system.</exception> public new static ICoordinateTransformation Get(string sourceId, string targetId) { TransformDelegate t = null; if (OnGetTransform != null) { t = OnGetTransform(sourceId, targetId); } return(new CoordinateTransformation( t ?? (string.Compare(sourceId, targetId, true) == 0 ? new TransformDelegate(IdentityTransform) : CoordinateTransformations.GetTransformation(sourceId, targetId)) )); }
/////////////////////////////////////////////////////////// // this method sets the appropriate delegate for the trans- // formation and syncs 'State' with the parent transform /////////////////////////////////////////////////////////// protected void RefreshTransformType() { switch (Modifier) { case TransformType.Position: State = m_Transform.localPosition; m_TransformFunc = new TransformDelegate(Position); break; case TransformType.Rotation: State = m_Transform.localEulerAngles; m_TransformFunc = new TransformDelegate(Rotation); break; case TransformType.Scale: State = m_Transform.localScale; m_TransformFunc = new TransformDelegate(Scale); break; case TransformType.PositionAdditive: State = m_Transform.localPosition; m_TransformFunc = new TransformDelegate(PositionAdditive); break; case TransformType.RotationAdditive: State = m_Transform.localEulerAngles; m_TransformFunc = new TransformDelegate(RotationAdditive); break; case TransformType.ScaleAdditive: State = m_Transform.localScale; m_TransformFunc = new TransformDelegate(ScaleAdditive); break; } m_CurrentTransformType = Modifier; RestState = State; }
public RgbImage Transform(int newWidth, int newHeight, TransformDelegate transform) { var res = new RgbImage(newWidth, newHeight); for (int y = 0; y < PixelHeight; y++) { for (int x = 0; x < PixelWidth; x++) { var newPos = transform(new Point(x, y)); if (newPos.X < 0 || newPos.X >= newWidth) { continue; } if (newPos.Y < 0 || newPos.Y >= newHeight) { continue; } res[newPos] = this[x, y]; } } return(res); }
internal TransformDelegateWrapper(TransformDelegate transformDelegate) { this.Delegate = transformDelegate; }
public WindowHeader(ContextMenuStrip menuStrip, TransformDelegate <Point> transform) { this.menuStrip = menuStrip; this.transform = transform; }
/// <summary> /// /// </summary> /// <param name="targetType">Parent Type of delegate function</param> /// <param name="delegateName">Name of delegate function</param> public TransformAttribute(Type targetType, string delegateName) { this.targetType = targetType; this.delegateInstance = (string data) => targetType.GetMethod(delegateName).Invoke(System.Activator.CreateInstance(targetType), new[] { data }); }
/// <summary> /// Initializes a new instance of the <see cref="CoordinateTransformation"/> class. /// </summary> /// <param name="transformMethod">The core coordinate transformation method to encapsulate.</param> private CoordinateTransformation(MethodInfo transformMethod) { transform = transformMethod == null ? null : (TransformDelegate)Delegate.CreateDelegate(typeof(TransformDelegate), transformMethod); }
char level6(char Operator) { /* * see if end of bracketed expression */ CurrentOperator = Operator; if (Operator == ')') { return(CurrentOperator); } cur_fac = fac; // at this point we clear the fac as this level will hopefully find a new value for it fac = 0; if (ExpressionPosition >= Expression.Length) { return('\0'); } while (ExpressionPosition < Expression.Length && Char.IsWhiteSpace(Expression[ExpressionPosition])) { ExpressionPosition++; } // the current Operator (symbol). if (ExpressionPosition >= Expression.Length) { throw new InvalidOperationException("Expression incomplete at end of expression"); } Operator = Expression[ExpressionPosition]; /* * handle variables */ if (Operator == '\'') { int end = ++ExpressionPosition; while (end < Expression.Length && Expression[end] != '\'') { end++; } var sv = Expression.Substring(ExpressionPosition, end - ExpressionPosition); ExpressionPosition = end + 1; // this will throw an exception if not found. Operator = nextOperator(); if (Operator == '\'' || Char.IsLetterOrDigit(Operator)) { throw new InvalidOperationException("Unexpected symbol at character " + ExpressionPosition.ToString()); } fac = GetSymbol(sv, Operator); } else if (Char.IsLetter(Operator)) { int end = ExpressionPosition; while (end < Expression.Length && (Expression[end] == '.' || Char.IsLetterOrDigit(Expression[end]))) { end++; } var sv = Expression.Substring(ExpressionPosition, end - ExpressionPosition); ExpressionPosition = end; // this will throw an exception if not found. Operator = nextOperator(); if (Operator == '(') { if (!Functions.ContainsKey(sv)) { throw new InvalidOperationException("Unknown function " + sv); } TransformDelegate func = Functions[sv]; var newop = level1('\0'); //level1(Expression[ExpressionPosition]); if (newop != ')') { throw new InvalidOperationException(String.Format("Missing close bracket for function {0}", sv)); } fac = func(fac); } else { if (Operator == '\'' || Char.IsLetterOrDigit(Operator)) { throw new InvalidOperationException("Unexpected symbol at character " + ExpressionPosition.ToString()); } fac = GetSymbol(sv, Operator); } } else { // handle any as yet unprocessed Operators; the aim of this // is to get a value and store it in the FAC. switch (Operator) { case '(': { ExpressionPosition++; Operator = Expression[ExpressionPosition]; CurrentDepth++; var newop = level1('\0'); //level1(Expression[ExpressionPosition]); if (newop == '\0') { if (CurrentDepth > 1) { throw new InvalidOperationException(String.Format("There are {0} missing closing brackets", CurrentDepth)); } else { throw new InvalidOperationException("Missing closing bracket"); } } CurrentDepth--; } break; case ')': throw new InvalidOperationException("Unexpected closing bracket at character " + ExpressionPosition.ToString()); default: { var end = ExpressionPosition; bool can_negate = true; bool can_posate = false; while (end < Expression.Length && (Char.IsWhiteSpace(Expression[end]) || Char.IsDigit(Expression[end]) || Expression[end] == '.' || Expression[end] == 'E' || Expression[end] == 'e' || (can_negate && Expression[end] == '-') || (can_posate && Expression[end] == '+') ) ) { if (Expression[end] == 'E' || Expression[end] == 'e') { can_negate = true; can_posate = true; } else { can_negate = false; } end++; } var sv = Expression.Substring(ExpressionPosition, end - ExpressionPosition); fac = Double.Parse(sv); ExpressionPosition = end; break; } } Operator = nextOperator(); } return(Operator); }
/// <summary> /// Initializes a new instance of the <see cref="ImageTransformer"/> class. /// </summary> /// <param name="pipeline">Pipeline this component is a part of</param> /// <param name="transformer">Function for transforming the source image</param> /// <param name="pixelFormat">Pixel format for destination image</param> public ImageTransformer(Pipeline pipeline, TransformDelegate transformer, PixelFormat pixelFormat) : base(pipeline) { this.transformer = transformer; this.pixelFormat = pixelFormat; }
public static extern IntPtr mleap_transformer_load_ex(string c_path, LoadModelDelegate c_load_model, TransformDelegate c_transform);
private void RegisterFunction(string name, TransformDelegate function) { Functions[name] = function; }
public static RewriteRule Create <T1, T2, T3, T4, T5, TResult>(string debugName, Expression <Func <T1, T2, T3, T4, T5, TResult> > find, Expression <Func <T1, T2, T3, T4, T5, TResult> > replace = null, Func <Match, Expression, bool> condition = null, TransformDelegate transform = null) => new RewriteRule(debugName, find, replace, condition, transform);
internal Next(TransformDelegate f, Func <string?, string?> n) { _func = f; _next = n; }
/// <summary> /// Operator that converts an image /// </summary> /// <param name="source">Source image to compress</param> /// <param name="transformer">Method for converting an image sample</param> /// <param name="pixelFormat">Pixel format to use for converted image</param> /// <param name="deliveryPolicy">Delivery policy</param> /// <returns>Returns a producer that generates the transformed images</returns> public static IProducer <Shared <Image> > Transform(this IProducer <Shared <Image> > source, TransformDelegate transformer, PixelFormat pixelFormat, DeliveryPolicy deliveryPolicy = null) { return(source.PipeTo(new TransformImageComponent(source.Out.Pipeline, transformer, pixelFormat), deliveryPolicy)); }
/// <summary> /// Initializes a new instance of the <see cref="CoordinateTransformation"/> class. /// </summary> /// <param name="transformMethod">The transform delegate to encapsulate.</param> private CoordinateTransformation(TransformDelegate transformMethod) { transform = transformMethod; }
public void RefreshTransformType () { switch (Modifier) { case TransformType.Position: State = m_transform.localPosition; m_transformFunction = new TransformDelegate (Position); break; case TransformType.Rotation: State = m_transform.localEulerAngles; m_transformFunction = new TransformDelegate (Rotation); break; case TransformType.Scale: State = m_transform.localScale; m_transformFunction = new TransformDelegate (Scale); break; case TransformType.PositionAdditive: State = m_transform.localPosition; m_transformFunction = new TransformDelegate (PositionAdditive); break; case TransformType.RotationAdditive: State = m_transform.localEulerAngles; m_transformFunction = new TransformDelegate (RotationAdditive); break; case TransformType.ScaleAdditive: State = m_transform.localScale; m_transformFunction = new TransformDelegate (ScaleAdditive); break; } m_currentTransformType = Modifier; RestState = State; }
/// <summary> /// Converts a shared image to a different pixel format using the specified transformer. /// </summary> /// <param name="source">Source image to compress.</param> /// <param name="transformer">Method for converting an image sample.</param> /// <param name="pixelFormat">Pixel format to use for converted image.</param> /// <param name="deliveryPolicy">An optional delivery policy.</param> /// <param name="sharedImageAllocator">Optional image allocator for creating new shared image.</param> /// <returns>Returns a producer that generates the transformed images.</returns> public static IProducer <Shared <Image> > Transform(this IProducer <Shared <Image> > source, TransformDelegate transformer, PixelFormat pixelFormat, DeliveryPolicy <Shared <Image> > deliveryPolicy = null, Func <int, int, PixelFormat, Shared <Image> > sharedImageAllocator = null) { return(source.PipeTo(new ImageTransformer(source.Out.Pipeline, transformer, pixelFormat, sharedImageAllocator), deliveryPolicy)); }
private void btnTransform_Click(object sender, EventArgs e) { if (_transforming) { MessageBox.Show("Polygons are currently being transformed. Try again in a moment."); return; } if (TwoTrails.Engine.Values.AdjustingPolygons) { MessageBox.Show("Polygons are currently being saved. Try again in a moment."); return; } if (!CheckControls()) return; /* foreach (TtPoint p in _AdjPoints) { if (!p.IsGpsType()) { if (MessageBox.Show("The Adjusting Polygon has non GPS type points in it. You will need to make a copy of the polygon in order to transform it. Do you want to Copy and Transform now?", "", MessageBoxButtons.UnAdjYesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) == DialogResult.OK) { makeCopy = true; } else return; break; } } */ TtPolygon newPoly = new TtPolygon(); TtPolygon transPoly = cboTransAdjPoly.SelectedItem as TtPolygon; string polyName = String.Format("{0} (Transformed)", transPoly.Name); bool renaming = true; int inc = 2; while (renaming) { renaming = false; foreach (TtPolygon poly in dal.GetPolygons()) { if (poly.Name.Equals(polyName, StringComparison.InvariantCultureIgnoreCase)) { polyName = String.Format("{0} (Transformed {1})", transPoly.Name, inc); inc++; renaming = true; break; } } } newPoly.Name = polyName; newPoly.PointStartIndex = (int)(dal.GetPolyCount() + 1010); _TransformedPoints = new List<GpsPoint>(); int index = 0; GpsPoint tmpPoint; foreach (GpsPoint p in _AdjPoints) { if (p.IsGpsType()) { tmpPoint = TtUtils.ClonePoint(p) as GpsPoint; tmpPoint.Index = index; tmpPoint.PolyCN = newPoly.CN; tmpPoint.PolyName = newPoly.Name; index++; _TransformedPoints.Add(tmpPoint); } } TransformDelegate del = new TransformDelegate(DoTransform); del.BeginInvoke(null, null); dal.InsertPolygon(newPoly); }