internal static void Init() { _FuncDelegate = Register; IntPtr addrToRegisterFunc = Marshal.GetFunctionPointerForDelegate(_FuncDelegate); string[] detour = new string[] { "pushfd", "pushad", "cmp edx, 0x004C4690", "jne @outRegister", "call " + addrToRegisterFunc, "@outRegister:", "popad", "popfd", "push esi", "push edi", "mov edi, ecx", "call 0x007040D0", "jmp 0x00704129", }; IntPtr detourPtr = Memory.InjectAsm(detour, "RegisterFunctionDetour"); byte[] orig = Memory.Reader.ReadBytes((IntPtr)0x00704120, 5); Memory.InjectAsm(0x00704120, "jmp " + detourPtr, "RegisterFunctionJmp"); }
internal static void Init() { _FuncDelegate = Unregister; IntPtr addrToRegisterFunc = Marshal.GetFunctionPointerForDelegate(_FuncDelegate); string[] detour = new string[] { "pushfd", "pushad", "push ecx", "call " + addrToRegisterFunc, "popad", "popfd", "PUSH ESI", "PUSH EDI", "MOV EDI,ECX", "CALL 0x007040D0", "jmp 0x00704169", }; IntPtr detourPtr = Memory.InjectAsm(detour, "UnregisterFunctionDetour"); byte[] orig = Memory.Reader.ReadBytes((IntPtr)0x00704160, 5); Memory.InjectAsm(0x00704160, "jmp " + detourPtr, "UnregisterFunctionJmp"); }
/// <summary> /// Initializes the image dimension, mouse delegation, and the /// graphical context setup of the instance. /// </summary> /// <param name="view"> HALCON window </param> public HWndCtrl(HWindowControlWPF view) { viewPort = view; stateView = MODE_VIEW_NONE; windowWidth = viewPort.ActualWidth; windowHeight = viewPort.ActualHeight; zoomWndFactor = (double)imageWidth / viewPort.ActualWidth; zoomAddOn = Math.Pow(0.9, 5); zoomWndSize = 150; /*default*/ CompRangeX = new int[] { 0, 100 }; CompRangeY = new int[] { 0, 100 }; prevCompX = prevCompY = 0; dispROI = MODE_INCLUDE_ROI;//1; //viewPort.HMouseUp += ViewPort_HMouseUp; //viewPort.HMouseDown += ViewPort_HMouseDown; //viewPort.HMouseMove += ViewPort_HMouseMove; viewPort.HMouseWheel += ViewPort_HMouseWheel; viewPort.SizeChanged += ViewPort_SizeChanged; addInfoDelegate = new FuncDelegate(dummyV); NotifyIconObserver = new IconicDelegate(dummy); // graphical stack HObjList = new ArrayList(20); mGC = new GraphicsContext(); mGC.gcNotification = new GCDelegate(exceptionGC); }
/// <summary> /// Initializes the image dimension, mouse delegation, and the /// graphical context setup of the instance. /// </summary> /// <param name="view"> HALCON window </param> protected internal HWndCtrl(HWindowControl view) { viewPort = view; stateView = MODE_VIEW_NONE; windowWidth = viewPort.Size.Width; windowHeight = viewPort.Size.Height; zoomWndFactor = (double)imageWidth / viewPort.Width; zoomAddOn = Math.Pow(0.9, 5); zoomWndSize = 150; /*default*/ CompRangeX = new int[] { 0, 100 }; CompRangeY = new int[] { 0, 100 }; prevCompX = prevCompY = 0; dispROI = MODE_INCLUDE_ROI;//1; viewPort.HMouseUp += new HalconDotNet.HMouseEventHandler(this.mouseUp); viewPort.HMouseDown += new HalconDotNet.HMouseEventHandler(this.mouseDown); viewPort.HMouseWheel += new HalconDotNet.HMouseEventHandler(this.HMouseWheel); viewPort.HMouseMove += new HalconDotNet.HMouseEventHandler(this.mouseMoved); addInfoDelegate = new FuncDelegate(dummyV); NotifyIconObserver = new IconicDelegate(dummy); // graphical stack HObjImageList = new ArrayList(20); mGC = new GraphicsContext(); mGC.gcNotification = new GCDelegate(exceptionGC); }
static void Task2() { FuncDelegate[] fd = new FuncDelegate[3]; fd[0] = new FuncDelegate(F2); fd[1] = EXP; fd[2] = LogDec; int func = 0; Console.Write("\nВыберите ф-ию (1 - полином 2-ой степени, 2 - экспонента, 3 - Log10): "); func = Int32.Parse(Console.ReadLine()); Console.Write("\nВведите диапазон и шаг через пробел (min max delta): "); string[] data = Console.ReadLine().Split(' '); SaveFunc("data.bin", double.Parse(data[0]), double.Parse(data[1]), double.Parse(data[2]), fd[func - 1]); double min; double[] mas = Load("data.bin", out min); Console.WriteLine($"Минимальное значение: {min}"); Console.WriteLine("Рассчитанные значения: "); foreach (var d in mas) { Console.WriteLine(d.ToString()); } Console.ReadKey(); }
//--------------------------------------------------------------------- // Newton method solver //--------------------------------------------------------------------- public static bool newton_solver(FuncDelegate func, JacobyDelegate J, decimal[] error, ref decimal[] x) { decimal[] dx; decimal[] f; int iter_count = 0; bool is_solved = true; do { DMatrix A = J(x); f = func(x); decimal[] b = new decimal[x.Length]; for (int i = 0; i < x.Length; i++) { b[i] = -f[i]; } dx = gauss_solver(A, b); for (int i = 0; i < x.Length; i++) x[i] = x[i] + dx[i]; f = func(x); iter_count++; } while ((is_error(f, error)) && (iter_count <= NEWTON_ITER_MAX)); if (iter_count > NEWTON_ITER_MAX) is_solved = false; return is_solved; }
_fit( FuncDelegate objective, GradientDelegate gradient, double[] start_params = null, object fargs = null, Dictionary <string, object> kwargs = null, HessianDelegate hessian = null, string method = "cg", int maxiter = 100, bool full_output = true, bool disp = true, alglib.ndimensional_rep callback = null, bool retall = true) { // Default value is array of zeros if (start_params == null) { var n = 10; start_params = new double[n]; } Dictionary <string, FitDelegate> fit_funcs = new Dictionary <string, FitDelegate> { { "bc", _fit_bc }, { "bleic", _fit_bleic }, { "cg", _fit_cg }, { "comp", _fit_comp }, { "lbfgs", _fit_lbfgs }, { "lm", _fit_lm }, { "nlc", _fit_nlc }, { "ns", _fit_ns }, { "qp", _fit_qp } }; string[] _methods = { "bc", "bleic", "cg", "comp", "lbfgs", "lm", "nlc", "ns", "qp" }; List <string> methods = new List <string>(_methods); _check_method(method, methods); var func = fit_funcs[method]; var _output = func(objective, gradient, start_params, fargs, kwargs, disp, maxiter, callback, retall, full_output, hessian); var xopt = _output.Item1; var retvals = _output.Item2; Dictionary <string, object> optim_settings = new Dictionary <string, object> { { "optimizer", method }, { "start_params", start_params }, { "maxiter", maxiter }, { "full_output", full_output }, { "disp", disp }, { "fargs", fargs }, { "callback", callback }, { "retall", retall } }; optim_settings = (Dictionary <string, object>)optim_settings.Concat(kwargs); return(Tuple.Create(xopt, retvals, optim_settings)); }
internal static void SetUtcNowProvider(FuncDelegate <DateTime> utcNowProvider) { if (utcNowProvider == null) { throw new ArgumentNullException("utcNowProvider"); } SetUtcNowProvider(utcNowProvider, true); }
/// <summary> /// Initializes the image dimension, mouse delegation, and the /// graphical context setup of the instance. /// </summary> /// <param name="view"> HALCON window </param> public HWndCtrl(HWindowControl view) { viewPort = view; stateView = MODE_VIEW_NONE; windowWidth = viewPort.Size.Width; windowHeight = viewPort.Size.Height; // initialize the image part to window size initializeDisplayImagePart(); resetImagePart(widthImagePart, heightImagePart); if (widthImagePart > 0) { zoomWndFactor = (double)widthImagePart / viewPort.Width; } else { zoomWndFactor = 1; } zoomAddOn = Math.Pow(0.9, 5); zoomWndSize = 150; /*Set the boundaries and steps for changes for the GUI elements*/ /*default*/ CompRangeX = new int[] { 0, 100 }; CompRangeY = new int[] { 0, 100 }; prevCompX = prevCompY = 0; initValX = initValY = 0; /* Initialize the values for value range, step for * some GUI elements */ setGUICompRangeX(CompRangeX, prevCompX); setGUICompRangeY(CompRangeY, prevCompY); //displayMode = MODE_VIEW_NONE; dispROI = MODE_INCLUDE_ROI;//1; viewPort.HMouseUp += new HalconDotNet.HMouseEventHandler(this.mouseUp); viewPort.HMouseDown += new HalconDotNet.HMouseEventHandler(this.mouseDown); viewPort.HMouseMove += new HalconDotNet.HMouseEventHandler(this.mouseMoved); viewPort.HMouseWheel += new HalconDotNet.HMouseEventHandler(this.mouseWheel); addInfoDelegate = new FuncDelegate(dummyV); NotifyIconObserver = new IconicDelegate(dummy); // graphical stack HObjList = new ArrayList(20); mGC = new GraphicsContext(); mGC.gcNotification = new GCDelegate(exceptionGC); // set the variable bufferWindow to null for repaint-Method bufferWindow = null; }
static void Main(string[] args) { FuncDelegate func = new FuncDelegate(); GetNumber getNumber = new GetNumber(); //這邊我們動態決定了要使用乘法,傳進去4*5 Console.WriteLine(getNumber.ReturnString(func.Multiplied, 4, 5)); Console.ReadLine(); }
public NumericIntegrator(int funcNumber, double a, double b, double precision, FuncDelegate func) { this.FuncNumber = funcNumber; this.A = a; this.B = b; this.Accuracy = precision; _func = func; }
public HookHelper(Key[] keys, FuncDelegate externFunc) { _hookedKeys.AddRange(keys); ExternFunc = externFunc; var th = new Thread(() => { StartMonitor(_monitorStatus); }); th.SetApartmentState(ApartmentState.STA); th.Start(); }
static void Main(string[] args) { Disk disk = new Disk(); FuncDelegate cleanfunc = disk.Clean; disk.Clean(null); //clean 메서드를 호출 cleanfunc(null); //델리게이트 인스턴스를 통해 clean 메서드를 호출 }
/// <summary> /// Wrapping function and gradient delegates into alglib version of gradient delegate /// </summary> /// <param name="objective"></param> /// <param name="gradient"></param> /// <returns></returns> public static alglib.ndimensional_grad _get_alglib_grad( FuncDelegate objective, GradientDelegate gradient) { return((double[] arg, ref double func, double[] grad, object obj) => { func = objective(arg); grad = gradient(arg); }); }
static void Main(string[] args) { Disk disk = new Disk(); FuncDelegate cleanFunc = new FuncDelegate(disk.Clean); FuncDelegate workFunc = disk.Clean; disk.Clean(null); cleanFunc(null); }
static void Main(string[] args) { Disk disk = new Disk(); FuncDelegate cleanFunc = new FuncDelegate(disk.Clean); FuncDelegate workFunc = disk.Clean; disk.Clean(null); //clean 메서드를 직접 호출 cleanFunc(null); // 델리게이트 인ㄴ스턴스를 통해 Clean 메서드를 호출 }
public static double MidRectIntegral(double a, double b, int n, FuncDelegate f) { double result = 0, h = (b - a) / n; for (int i = 0; i < n; ++i) { result += f(a + (i + 0.5) * h); } return(result * h); }
public static double SimpsonIntegral(double a, double b, int n, FuncDelegate f) { double sum = 0; double h = (b - a) / n; for (int i = 0; i < n; i++) { sum += (f(a + h * i) + 4 * f(a + h * (i + 0.5)) + f(a + h * (i + 1)) * h / 3); } return(sum); }
public static double QuadCentral(double a, double b, double n, FuncDelegate func) { Console.WriteLine("Метод центральних прямокутникiв"); double h = (b - a) / n; double q = 0; for (double x = a; x < b; x += h) { q += func(x + h / 2); } return q * h; }
public static double TrapIntegral(double a, double b, int n, FuncDelegate f) { double sum = 0.0; double h = (b - a) / n; for (int i = 0; i < n; i++) { sum += 0.5 * h * (f(a + i * h) + f(a + (i + 1) * h)); } return(sum); }
public static double QuadCentral(double a, double b, double n, FuncDelegate func) { double h = (b - a) / n; double q = 0; for (double x = a; x < b; x += h) { q += func(x + h / 2); } return(q * h); }
private UnloadWorldHook() { Console.WriteLine("UnloadWorldHook loaded"); _unloadWorldDelegate = Memory.Reader.RegisterDelegate <FuncDelegate>((IntPtr)0x490CE0); _unloadWorldHook = Memory.Reader.Detours.CreateAndApply( _unloadWorldDelegate, new FuncDelegate(Unregister), "UnloadWorldHook"); }
static void Test() { Console.WriteLine("Enter a?b ?(+-*/) "); string expression = Console.ReadLine(); ///20+30 char sign = ' '; try { if (expression.Contains('+')) { sign = '+'; } if (expression.Contains('-')) { sign = '-'; } if (expression.Contains('*')) { sign = '*'; } if (expression.Contains('/')) { sign = '/'; } string[] numbers = expression.Split(sign); double a = double.Parse(numbers[0]); double b = double.Parse(numbers[1]); Matem matem = new Matem(); FuncDelegate func = null; double res = 0; switch (sign) { case '+': func = matem.Sum; break; case '-': func = new FuncDelegate(matem.Sub); break; case '*': func = Matem.Mult; break; case '/': func = Matem.Div; break; default: throw new Exception("no sign"); } // Console.WriteLine($"{a}{sign}{b}={func?.Invoke(a,b)}"); Console.WriteLine($"{a}{sign}{b}={func(a, b)}"); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void ThrowsException <T>(FuncDelegate func) where T : System.Exception { try { func(); } catch (T) { return; } Assert.IsTrue(false, "Expected exception to be thrown"); }
public static double RightRectIntegral(double a, double b, int n, FuncDelegate f) { double h = (b - a) / n; double sum = 0d; for (int i = 1; i <= n; i++) { double x = a + i * h; sum += f(x); } return(h * sum); }
public static double QuadCentral(double a, double b, double n, FuncDelegate func) { Console.WriteLine("Метод трапеції"); double h = (b - a) / n; double q = 0; for (double x = a; x < b; x += h) { q += func(x + h / 2); } return(q * h); }
public static void SaveFunc(string fileName, double a, double b, double h, FuncDelegate f) { FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write); BinaryWriter bw = new BinaryWriter(fs); double x = a; while (x <= b) { bw.Write(f(x)); x += h;// x=x+h; } bw.Close(); fs.Close(); }
static void Main(string[] args) { // No delegate GetNumber getNumber = new GetNumber(new CaculatePlus(6, 3)); Console.WriteLine(getNumber.ReturnString()); //funcDelegate var func = new FuncDelegate(); var getNumberDelegate = new GetNumberByDelegate(); Console.WriteLine(getNumberDelegate.ReturnString(func.Plus, 5, 3)); Console.ReadLine(); }
_fit_qp( FuncDelegate objective, GradientDelegate gradient, double[] start_params, object fargs, Dictionary <string, object> kwargs, bool disp, int maxiter, alglib.ndimensional_rep callback, bool retall, bool full_output, HessianDelegate hessian) { throw new NotImplementedException(); }
public static double QuadRight(double a, double b, double n, FuncDelegate func) { Console.WriteLine("Метод правих прямокутникiв"); double h = (b - a) / n; double y1; double x1; double Intgrl = 0; for (int i = 1; i <= n; i++) { x1 = a + i * h; y1 = func(x1); Intgrl += y1 * h; } return Intgrl; }
public static double QuadLeft(double a, double b, double n, FuncDelegate func) { Console.WriteLine("---------------------Метод лівих прямокутників------------------"); double h = (b - a) / n; double y1; double x1; double Intgrl = 0; for (int i = 0; i < n; i++) { x1 = a + i * h; y1 = func(x1); Intgrl += y1 * h; } return(Intgrl); }
public IList BuildAll(FuncDelegate<object,Crossbow> convert) { return BuildAll().Convert(convert); }
/// <summary> /// 自定义处理函数注册 /// </summary> /// <param name="strPath"></param> /// <param name="func"></param> /// <returns></returns> public bool RegisterFunction(string strPath, FuncDelegate func) { lock (servletDicLock) { if (pathToServletDic.ContainsKey(strPath)) return false; if (pathToFuncDic.ContainsKey(strPath)) return false; pathToFuncDic.Add(strPath, func); return true; } }
/// <summary> /// Initializes the image dimension, mouse delegation, and the /// graphical context setup of the instance. /// </summary> /// <param name="view"> HALCON window </param> public HWndCtrl(HWindowControl view) { viewPort = view; stateView = MODE_VIEW_NONE; windowWidth = viewPort.Size.Width; windowHeight = viewPort.Size.Height; // initialize the image part to window size initializeDisplayImagePart(); resetImagePart(widthImagePart, heightImagePart); if (widthImagePart > 0) zoomWndFactor = (double)widthImagePart / viewPort.Width; else zoomWndFactor = 1; zoomAddOn = Math.Pow(0.9, 5); zoomWndSize = 150; /*Set the boundaries and steps for changes for the GUI elements*/ /*default*/ CompRangeX = new int[] { 0, 100 }; CompRangeY = new int[] { 0, 100 }; prevCompX = prevCompY = 0; initValX = initValY = 0; /* Initialize the values for value range, step for * some GUI elements */ setGUICompRangeX(CompRangeX, prevCompX); setGUICompRangeY(CompRangeY, prevCompY); //displayMode = MODE_VIEW_NONE; dispROI = MODE_INCLUDE_ROI;//1; viewPort.HMouseUp += new HalconDotNet.HMouseEventHandler(this.mouseUp); viewPort.HMouseDown += new HalconDotNet.HMouseEventHandler(this.mouseDown); viewPort.HMouseMove += new HalconDotNet.HMouseEventHandler(this.mouseMoved); viewPort.HMouseWheel += new HalconDotNet.HMouseEventHandler(this.mouseWheel); addInfoDelegate = new FuncDelegate(dummyV); NotifyIconObserver = new IconicDelegate(dummy); // graphical stack HObjList = new ArrayList(20); mGC = new GraphicsContext(); mGC.gcNotification = new GCDelegate(exceptionGC); // set the variable bufferWindow to null for repaint-Method bufferWindow = null; }
public static void Run(FuncDelegate target) { target(); }
/// <summary> /// Initializes the image dimension, mouse delegation, and the /// graphical context setup of the instance. /// </summary> /// <param name="view"> HALCON window </param> public HWndCtrl(HWindowControl view) { _viewPort = view; _stateView = MODE_VIEW_NONE; windowWidth = _viewPort.Size.Width; windowHeight = _viewPort.Size.Height; zoomWndFactor = (double)imageWidth / _viewPort.Width; zoomAddOn = Math.Pow(0.9, 5); zoomWndSize = 150; /*default*/ CompRangeX = new int[] { 0, 100 }; CompRangeY = new int[] { 0, 100 }; prevCompX = prevCompY = 0; _dispROI = MODE_INCLUDE_ROI;//1; _viewPort.HMouseUp += new HalconDotNet.HMouseEventHandler(this.mouseUp); _viewPort.HMouseDown += new HalconDotNet.HMouseEventHandler(this.mouseDown); _viewPort.HMouseMove += new HalconDotNet.HMouseEventHandler(this.mouseMoved); addInfoDelegate = new FuncDelegate(dummyV); NotifyIconObserver = new IconicDelegate(dummy); // graphical stack HObjList = new ArrayList(20); mGC = new GraphicsContext(); mGC.gcNotification = new GCDelegate(exceptionGC); }