示例#1
0
        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");
        }
示例#3
0
        /// <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);
        }
示例#4
0
        /// <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);
        }
示例#5
0
        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();
        }
示例#6
0
        //---------------------------------------------------------------------
        //      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;
        }
示例#7
0
        _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));
        }
示例#8
0
 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;
        }
示例#10
0
        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();
        }
示例#11
0
        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;
        }
示例#12
0
        public HookHelper(Key[] keys, FuncDelegate externFunc)
        {
            _hookedKeys.AddRange(keys);
            ExternFunc = externFunc;
            var th = new Thread(() => { StartMonitor(_monitorStatus); });

            th.SetApartmentState(ApartmentState.STA);
            th.Start();
        }
示例#13
0
        static void Main(string[] args)
        {
            Disk disk = new Disk();

            FuncDelegate cleanfunc = disk.Clean;

            disk.Clean(null);   //clean 메서드를 호출
            cleanfunc(null);    //델리게이트 인스턴스를 통해 clean 메서드를 호출
        }
示例#14
0
 /// <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);
     });
 }
示例#15
0
        static void Main(string[] args)
        {
            Disk disk = new Disk();

            FuncDelegate cleanFunc = new FuncDelegate(disk.Clean);
            FuncDelegate workFunc  = disk.Clean;

            disk.Clean(null);
            cleanFunc(null);
        }
示例#16
0
        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 메서드를 호출
        }
示例#17
0
        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);
        }
示例#18
0
        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);
        }
示例#19
0
 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;
 }
示例#20
0
        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);
        }
示例#21
0
        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);
        }
示例#22
0
 private UnloadWorldHook()
 {
     Console.WriteLine("UnloadWorldHook loaded");
     _unloadWorldDelegate =
         Memory.Reader.RegisterDelegate <FuncDelegate>((IntPtr)0x490CE0);
     _unloadWorldHook =
         Memory.Reader.Detours.CreateAndApply(
             _unloadWorldDelegate,
             new FuncDelegate(Unregister),
             "UnloadWorldHook");
 }
示例#23
0
        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);
            }
        }
示例#24
0
 public static void ThrowsException <T>(FuncDelegate func) where T : System.Exception
 {
     try
     {
         func();
     }
     catch (T)
     {
         return;
     }
     Assert.IsTrue(false, "Expected exception to be thrown");
 }
示例#25
0
        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);
        }
示例#26
0
        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);
        }
示例#27
0
        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();
        }
示例#28
0
        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();
        }
示例#29
0
 _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();
 }
示例#30
0
 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;
 }
示例#31
0
        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);
        }
示例#32
0
 public IList BuildAll(FuncDelegate<object,Crossbow> convert)
 {
     return BuildAll().Convert(convert);
 }
示例#33
0
        /// <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;
            }
        }
示例#34
0
        /// <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;
        }
示例#35
0
 public static void Run(FuncDelegate target)
 {
     target();
 }
示例#36
0
        /// <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);
        }