Пример #1
0
        private Bitmap DrawMemFuncGraph(byte[] mf_array, int top)
        {
            Graphics g;
              Pen p;
              Bitmap bitmap = new Bitmap(BM_WIDTH * 2, BM_HEIGHT);
              g = Graphics.FromImage(bitmap);
              g.Clear(System.Drawing.Color.White);
              p = new Pen(Color.LightGray);
              //g.DrawLine(p, 130, 1, 130, BM_HEIGHT - 1);
              g.DrawLine(p, BM_WIDTH, 1, BM_WIDTH, BM_HEIGHT - 1);
              p.Color = Color.Red;

              // pos has 5 trapezoidal functions consisting of 4 bytes
              TrapezoidalFunc trap_func;
              for(int i = 0; i < (mf_array.Length / 4); i++)
              {
            // TrapezoidalFunc struct uses 4 consecutive elements from byte array
            trap_func = new TrapezoidalFunc(mf_array, 4 * i);

            // Draw trapezoid
            DrawTrapezoid(g, p, i, trap_func);
              }

              g.Dispose();
              p.Dispose();

              return bitmap;
        }
Пример #2
0
        private void DrawTrapezoid(Graphics g, Pen p, int index, TrapezoidalFunc trap_func)
        {
            int tmp0, tmp1;

              // Add 2 for border + padding
              if(index == 0)
              {
            tmp1 = (int)trap_func.p1 - (0xFF / (int)trap_func.s1);
            g.DrawLine(p, tmp1 + 2, 1, (int)trap_func.p1 + 2, BM_HEIGHT - 1);
            g.DrawLine(p, 1, 1, tmp1 + 2, 1);
              }
              else if(index == 4)
              {
            tmp1 = (int)trap_func.p0 + (0xFF / (int)trap_func.s0);
            g.DrawLine(p, tmp1 + 2, 1, (int)trap_func.p0 + 2, BM_HEIGHT - 1);
            g.DrawLine(p, tmp1 + 2, 1, 0xFF + 1, 1);
              }
              else
              {
            tmp0 = (int)trap_func.p0 + (0xFF / (int)trap_func.s0);
            g.DrawLine(p, tmp0 + 2, 1, (int)trap_func.p0 + 2, BM_HEIGHT - 1);
            tmp1 = (int)trap_func.p1 - (0xFF / (int)trap_func.s1);
            g.DrawLine(p, tmp1 + 2, 1, (int)trap_func.p1 + 2, BM_HEIGHT - 1);
            g.DrawLine(p, tmp0 + 2, 1, tmp1 + 2, 1);
              }
        }
Пример #3
0
        /******************************************************************************/
        public void Build()
        {
            if(_pos_mf_array != null && _spd_mf_array != null && _out_singleton_array != null)
              {
            // pos has 5 trapezoidal functions consisting of 4 bytes
            for(int i = 0; i < (_pos_mf_array.Length / 4); i++)
            {
              FuzzyMemFunc pos_mem_func;
              // Programmatically create FuzzyMemFunc objects if not already existent
              if(_pos_funcs_ht.ContainsKey(i))
              {
            pos_mem_func = _pos_funcs_ht[i];
              }
              else
              {
            pos_mem_func = new FuzzyMemFunc(_container, Strings.fuzzyPosRuleStrings[i], i, LOC_POS_TOP, LOC_LEFT, UpdatePosFuncs);
            _pos_funcs_ht.Add(i, pos_mem_func);
              }

              // TrapezoidalFunc struct uses 4 consecutive elements from byte array
              TrapezoidalFunc pos_trap_func = new TrapezoidalFunc(_pos_mf_array, 4 * i);
              pos_mem_func.TrapezoidalFunc = pos_trap_func;
            }
            if(_picBxPosErr == null)
            {
              _picBxPosErr = new PictureBox();
              _picBxPosErr.Size = new Size(BM_WIDTH, BM_HEIGHT);
              _picBxPosErr.Location = new Point(BM_LEFT, LOC_POS_TOP);
              _picBxPosErr.BorderStyle = BorderStyle.FixedSingle;
              _container.Controls.Add(_picBxPosErr);
            }
            // Resize the graph width by .5 to fit in UI
            //_picBxPosErr.Image = DrawPosGraph();
            _picBxPosErr.Image = ResizeImage(DrawPosGraph(), BM_WIDTH, BM_HEIGHT);

            // spd has 5 trapezoidal functions consisting of 4 bytes
            for(int i = 0; i < (_spd_mf_array.Length / 4); i++)
            {
              FuzzyMemFunc spd_mem_func;

              // Programmatically create FuzzyMemFunc objects if not extant
              if(_spd_funcs_ht.ContainsKey(i))
              {
            spd_mem_func = _spd_funcs_ht[i];
              }
              else
              {
            spd_mem_func = new FuzzyMemFunc(_container, Strings.fuzzyPosRuleStrings[i + 5], i, LOC_SPD_TOP, LOC_LEFT, UpdateSpdFuncs);
            _spd_funcs_ht.Add(i, spd_mem_func);
              }

              // TrapezoidalFunc struct uses 4 consecutive elements from byte array
              TrapezoidalFunc spd_trap_func = new TrapezoidalFunc(_spd_mf_array, 4 * i);
              spd_mem_func.TrapezoidalFunc = spd_trap_func;
            }
            if(_picBxSpd == null)
            {
              _picBxSpd = new PictureBox();
              _picBxSpd.Size = new Size(BM_WIDTH, BM_HEIGHT);
              _picBxSpd.Location = new Point(BM_LEFT, LOC_SPD_TOP);
              _picBxSpd.BorderStyle = BorderStyle.FixedSingle;
              _container.Controls.Add(_picBxSpd);
            }
            //_picBxSpd.Image = DrawSpdGraph();
            _picBxSpd.Image = ResizeImage(DrawSpdGraph(), BM_WIDTH, BM_HEIGHT);

            // Programmatically build controls to hold output singleton values
            Font f_reg = new Font("Microsoft Sans Serif", 7);
            for(int i = 0; i < _out_singleton_array.Length; i++)
            {
              if(_output_text_box_list.Count < i + 1)
              {
            Label lbl = new Label();
            lbl.Font = f_reg;
            lbl.Location = new Point(LABEL_LEFT, LOC_OUT_TOP + (TB_HEIGHT * i) + 2);
            lbl.AutoSize = false;
            lbl.RightToLeft = RightToLeft.Yes;
            lbl.Size = new Size(LABEL_WIDTH, LABEL_HEIGHT);
            lbl.Text = Strings.fuzzyPosRuleStrings[i + 10];
            _container.Controls.Add(lbl);

            TextBox tb = new TextBox();
            tb.Font = f_reg;
            tb.Size = new Size(TB_WIDTH, TB_HEIGHT);
            tb.Location = new Point(LOC_LEFT, LOC_OUT_TOP + (TB_HEIGHT * i));
            _container.Controls.Add(tb);
            _output_text_box_list.Add(tb);
              }
            }
            if(_picBxOutput == null)
            {
              _picBxOutput = new PictureBox();
              _picBxOutput.Size = new Size(BM_WIDTH, BM_HEIGHT);
              _picBxOutput.Location = new Point(BM_LEFT, LOC_OUT_TOP);
              _picBxOutput.BorderStyle = BorderStyle.FixedSingle;
              _container.Controls.Add(_picBxOutput);
            }
            if(SetOutputText())
            {
              //_picBxOutput.Image = DrawOutputGraph();
              _picBxOutput.Image = ResizeImage(DrawOutputGraph(), BM_WIDTH, BM_HEIGHT);
            }

            this.Enable(_enable_mem_funcs);
              }
              else
              {
            MsgBox.Show("Membership Function arrays are not initialized");
              }
        }