回文章列表
作者easterday@bbs.ee.ntu.edu.tw (數牙), 信區: medeng
標題antct.cpp
時間台大電機 Maxwell BBS (Sun Aug 29 20:53:47 1999)
轉信站: GIBBS!news.mc.ntu!Maxwell

// ANTCT.cpp
#include <iostream.h>
#include <stdlib.h>
#include "antct.h"

double func_q(double *ct,int i, int j, int MCOL, int mcol, int YROW, int yrow)
{
// ex.MCOL=COL; mcol=0; YROW=ROW; yrow=0;
//***  { 0=<i<MCOL, 0=<j<YROW }***
// this func_q is quite alike which in ct2.cpp
// they are different in float
        float tmp1,tmp2;
        int f,x,y;
        // set sub-code init
    f=0;
  x=i; y=j;tmp1=0;
  while ( (MCOL>(x-f)) && ((x-f)>=mcol) && (YROW>(y-f))&& ((y-f)>=yrow) )
    {                                                   // debug code
//      cout<<"x="<<x<<"\n";
//      cout<<"(x-f,y-f)=("<<x-f<<","<<y-f<<");   ";
//      cout<<"ct[(x-f)+(y-f)*COL]="<<ct[(x-f)+(y-f)*COL] <<"\n";
                                                        // debug code
        tmp1+=ct[(x-f)+(y-f)*MCOL];
// for debug:
//      cout<<"tmp1="<<tmp1;sleep(1);
        f++;
      }
//      cout<<"jump out while1!\n";
                                // set sub-code init
  f=1;
  x=i; y=j;tmp2=0;

  while ( (MCOL>(x+f)) && ((x+f)>=mcol) && (YROW>(y+f))&& ((y+f)>=yrow) )
    {                                                   // debug code
//      cout<<"(x+f,y+f)=("<<x+f<<","<<y+f<<");   ";
//      cout<<"ct[(x+f)+(y+f)*COL]="<<ct[(x+f)+(y+f)*COL] <<"\n";

                                                        // debug code
        tmp2+=ct[(x+f)+(y+f)*MCOL];
//      cout<<"tmp2="<<tmp2;sleep(1);                   // for debug:
        f++;}
//      cout<<"jump out while2!\n";
  // transfer tmp1+tmp2 to q[0~COL]
  return (tmp1+tmp2);
//      cout<<"part2 (tmp1,tmp2)=("<<tmp1<<","<<tmp2<<")\n";    //debug code

}

int num_q( int i, int j, int MCOL=Max_elem, int YROW=Max_elem)
{
// actually, the value of  num_q(i,j,MCOL,YROW) is to consider
// func_q(i,j,MCOL,0,YROW,0) in a
//                                      1 1 1 1 1 1
//                                      1 1 1 1 p 1
//                                      1 1 1 1 1 1
//                                      1 1 1 1 1 1
        double *qk;
        qk= new double [MCOL*YROW];

        for ( int p=0; p<MCOL*YROW; p++)        qk[p]=1;
        float tmp;
        tmp=func_q(qk,i,j,MCOL,0,YROW,0);
        return int(tmp);

}

  void ANTCT::print()
{   for (int j = 0; j < ROW; j++)
        {   for (int i=0; i <COL; i++)
                 cout<<" "<<(ct[j*COL+i]);
          cout<<"\n";
          }
}
  void ANTCT::fp()
{   for (int j = 0; j < ROW; j++)
        {   for (int i=0; i <COL; i++)
               { if (ct[j*COL+i]-int(ct[j*COL+i])>0.50)
                    cout<< int(ct[j*COL+i])+1<<" ";
                        else
                         cout<<int(ct[j*COL+i])<<" ";
                }
          cout<<"\n";
          }
}



 int ANTCT::h_step()
{    cout<<"step_h is starting\n";
     float *tmp1;
     tmp1= new float[COL];
     for (int c=0; c<COL; c++)  tmp1[c]=0;      // init tmp1[]

                                // this section is copy from the CT.h_img()
//   cout<<"h_img starting:\n";
   for (int i=0; i<COL; i++)
   {
    for (int j=0; j<ROW; j++)
      { tmp1[i]+=ct[j*COL+i];
/**     ^^^^^ change only here to put in tmp[] **/
// pre-print h_img
//for Debug:
// cout<<"h["<<i<<"]=ct["<<i*ROW+j<<"]="<<h[i]<<"\n";
//             ^           ^^^^^^^          ^
       }
    }
//    cout<<"h_img is ok!\n";
                                // CT.h_img() is over
     for (int p=0; p<COL; p++)
     { tmp1[p]=(vv[p]-tmp1[p])/ROW; };
     for (int y=0; y<ROW; y++)
         for (int x=0; x<COL; x++)
     { ct[y*COL+x]+=tmp1[x]; }
  return 0;
};


   int ANTCT::q_step()
   {
     cout <<"step_q is starting\n";
     float *tmp1;
     tmp1= new float[COL+ROW-1];
     for (int c=0; c<COL+ROW-1; c++)  tmp1[c]=0;        // init tmp1[]
                                // this section is copy from the CT.q_img()
  // cout<<"q_img starting:\n";

  for (int i=COL-1;i>=0;i--)
  {    int j=0;
        tmp1[COL-1-i]=func_q(ct,i,j,COL,0,ROW,0);
/***    ^^^^^^^^^^ change only here */
//              cout<< "tmp["<<COL-1-i<<"]="<<tmp1[COL-1-i]<<"\n"; // debug code
  }

  for (int j=1;j<ROW;j++)
  {     i=0;
        tmp1[COL-1+j]=func_q(ct,i,j,COL,0,ROW,0);
/***    ^^^^^^^^^^ change only here */
//              cout<< "tmp["<<COL-1+j<<"]="<<tmp1[COL+j]<<"\n"; // debug code
  }
//  leng_q=ROW+COL-1;
//  cout<<"\nq_img is ok!";
                                // code from CT.q_img() is over

        for (int n1=0; n1<COL; n1++)
        {
//       cout<<"tmp1[n1]="<<tmp1[n1]<<"\n";
//       cout<<"qq[n1]="<<qq[n1]<<"\n";
//       cout<<num_q(COL-1-n1,0,COL,ROW)<<"\n";
         tmp1[n1]=(qq[n1]-tmp1[n1])/num_q(COL-1-n1,0,COL,ROW) ;
//       cout<<"f_tmp["<<n1<<"]="<<tmp1[n1]<<"\n";

         }
// ps: num_q is considering p(i,j) in 1 1 1 1 p
//                                    1 1 1 1 1
//                                    1 1 1 1 1
// ps: n2=COL-1 now...
        for (int n2=1; n2<ROW; n2++)
        {
 tmp1[COL-1+n2]=(qq[COL-1+n2]-tmp1[COL-1+n2])/num_q(0,n2,COL,ROW);

//       cout<<"f_tmp[="<<COL-1+n2<<"]="<<tmp1[COL-1+n2]<<"\n"; // debug code
        }
        // construct a array dt like
        /*            3 2 1 0
                      4 3 2 1
                      5 4 3 2
        */
                 int *dt;
                 dt= new int [ROW*COL];
         for (int n3=0; n3<COL; n3++)
            for (int n4=0; n4<ROW; n4++)
                { dt[n3+n4*COL]=abs( n3-(COL-1))+abs(n4);
//                cout<<"dt["<<n3+n4*COL<<"]="<<dt[n3+n4*COL]<<"\n";// debug
                  }

        // the value of dt[x] shows which q[] should push into ct.
        // (if dt[x]=1  ==> q[1] should put into ct
         for (int x=0; x<COL; x++)
             {  for (int y=0; y<ROW; y++)
                       {
//                                                              debug code
//                     cout<<"ct["<<y*ROW+x<<"]-->"<<dt[y*ROW+x]<<"\n";
//                     cout<<"ct["<<y*ROW+x<<"]="<<ct[y*ROW+x]<<"\n";
                       ct[y*ROW+x]+=tmp1[dt[y*ROW+x]];
                       }
             }

   return 0;
   }


   int ANTCT::v_step()
{       cout<<"step_v is starting\n";
     float *tmp1;
     tmp1= new float[ROW];
     for (int c=0; c<ROW; c++)  tmp1[c]=0;      // init tmp1[]

   for (int j=0; j<ROW; j++)
   {
    for (int i=0; i<COL; i++)
      { tmp1[i]+=ct[j*COL+i];
// pre-print h_img
//for Debug:
// cout<<"h["<<i<<"]=ct["<<i*ROW+j<<"]="<<h[i]<<"\n";
//             ^           ^^^^^^^          ^
       }
    }
//    cout<<"h_img is ok!\n";
//    leng_h=COL;
     for (int p=0; p<ROW; p++)
     { tmp1[p]=(vv[p]-tmp1[p])/COL; };
     for (int y=0; y<ROW; y++)
         for (int x=0; x<COL; x++)
     { ct[y*COL+x]+=tmp1[y]; }

   return 0;
};
--
※ Origin: 臺大電機 Maxwell 站 ◆ From: h120.s155.ts32.hinet.net
文章選讀←離開[主題上]主題下(k)上篇(j)下篇S/a搜尋 G串列 TAB精華 ↑↓捲 Pg/Space翻