Horus Doc || C++ Reference || Class Overview   Pixels   Images   Detector   Geometry   Registry || Doxygen's quick Index  

HxNgbHilditch.h

00001 /*
00002  *  Copyright (c) 2002, University of Amsterdam, The Netherlands.
00003  *  All rights reserved.
00004  *
00005  *  Author(s):
00006  *  Leon Todoran            (todoran@science.uva.nl)
00007  */
00008 
00009 #ifndef HxNgbHilditch_h
00010 #define HxNgbHilditch_h
00011 
00012 #include "HxClassName.h"
00013 #include "HxSizes.h"
00014 #include "HxCategories.h"
00015 #include "HxTagList.h"
00016 
00017 #include <algorithm>
00018 
00021 template <class ArgType, class ResType>
00022 class HxNgbHilditch 
00023 {
00024 public:
00025 
00027     typedef HxTagLoop        IteratorCategory;
00028 
00030     typedef HxTag1Phase      PhaseCategory;
00031 
00032 
00035 //                          HxNgbHilditch();
00036                             HxNgbHilditch(HxTagList& tags);
00037                             ~HxNgbHilditch();
00038 
00039     HxSizes                 size();
00040     void                    init(int, int, ArgType);
00041 
00042     void                    next(int x, int y, ArgType value);
00043     ResType                  result();// const;
00044 
00046     static HxString         className();
00047 
00048 private:
00049     int                     _pctIdx;
00050     int                     _size;  //this 
00051     bool                    _changed; 
00052 
00053     HxTagList&              _tags;
00054 
00055     ArgType*                 _values;
00056     int                     _i;
00057 
00058 
00059     int idxKernel[9];//={ 6, 7, 8,11,12,13,16,17,18};
00060     int idxAp1[9];//    ={ 7, 8,13,18,17,16,11, 6, 7};
00061     int idxAp2[9];//    ={ 2, 3, 8,13,12,11, 6, 1, 2};
00062     int idxAp4[9];//    ={ 8, 9,14,19,18,17,12, 7, 8};
00063 
00064 
00065 };
00066 
00067 template <class ArgType, class ResType>
00068 ostream&
00069 operator<<(ostream& os, const HxNgbHilditch<ArgType, ResType>& pct)
00070 {
00071     return pct.put(os);
00072 }
00073 
00074 template <class ArgType, class ResType>
00075 inline HxString
00076 HxNgbHilditch<ArgType, ResType>::className()
00077 {
00078     static HxString s("hilditch");
00079     return s;
00080 }
00081 
00082 template <class ArgType, class ResType>
00083 inline void
00084 HxNgbHilditch<ArgType, ResType>::init(int, int, ArgType)
00085 {
00086     _i = 0;
00087 }
00088 
00089 template <class ArgType, class ResType>
00090 inline void
00091 HxNgbHilditch<ArgType, ResType>::next(int, int, ArgType value)
00092 {
00093     _values[_i++] = value;
00094 }
00095 
00096 template <class ArgType, class ResType>
00097 inline HxSizes
00098 HxNgbHilditch<ArgType, ResType>::size()
00099 {
00100     return HxSizes(_size, _size, 1);
00101 }
00102 
00103 template <class ArgType, class ResType>
00104 inline ResType
00105 HxNgbHilditch<ArgType, ResType>::result() //const
00106 {
00107     //we are only interested in pixels that ore 0 (object)
00108     if(_values[_pctIdx].x() !=0 )
00109         return _values[_pctIdx];
00110     int j;
00111     int nrNZN=0; //number of non-zero neighbors
00112     int ap1=0,ap2=0,ap4=0; //in fact I'm interested to know only if this value is 1 or not
00113     bool p2p4p8, p2p4p6;
00114     p2p4p8 = (_values[7].x()==1) || (_values[13].x()==1) || (_values[11].x()==1);
00115     p2p4p6 = (_values[7].x()==1) || (_values[13].x()==1) || (_values[17].x()==1);
00116 //  printf("p2p4p8=%d, p2p4p6=%d, ap2=%d, ap4=%d\n", p2p4p8, p2p4p6,ap2,  ap4);
00117 
00118     for(j=0;j<9;j++)
00119         if(_values[idxKernel[j]].x()!=0 && j!=4)
00120             nrNZN++;
00121 
00122     if( (nrNZN>=2) && (nrNZN<=6) )
00123     {
00124 
00125         //locate the first 0 pixel
00126         for(j=0;j<9;j++)
00127             if(_values[idxAp1[j]]==0)
00128                 break;
00129         if(j<8) 
00130             for(j++;j<9;j++)
00131                 if(_values[idxAp1[j]]!=0)
00132                 {
00133                     ap1++;
00134                     break;
00135                 }
00136         if(j<8) 
00137             for(j++ ;j<9;j++)
00138                 if(_values[idxAp1[j]]==0)
00139                     break;
00140         if(j<8) 
00141             for(j++ ;j<9;j++)
00142                 if(_values[idxAp1[j]]!=0)
00143                 {
00144                     ap1++;
00145                     break;
00146                 }
00147 
00148         if( ap1==1 ) 
00149         {
00150         
00151             //I compute ap2 only if I really need it
00152              if( !p2p4p8)
00153              {
00154              
00155             //locate the first 0 pixel
00156             for(j=0;j<9;j++)
00157                 if(_values[idxAp2[j]]==0)
00158                     break;
00159             if(j<8) 
00160                 for(j++ ;j<9;j++)
00161                     if(_values[idxAp2[j]]!=0)
00162                     {
00163                         ap2++;
00164                         break;
00165                     }
00166             if(j<8) 
00167                 for(j++ ;j<9;j++)
00168                     if(_values[idxAp2[j]]==0)
00169                         break;
00170             if(j<8) 
00171                 for(j++ ;j<9;j++)
00172                     if(_values[idxAp2[j]]!=0)
00173                     {
00174                         ap2++;
00175                         break;
00176                     }
00177              }
00178 
00179              if( !p2p4p6 )
00180              {   
00181                 //locate the first 0 pixel
00182                 for(j=0;j<9;j++)
00183                     if(_values[idxAp4[j]]==0)
00184                         break;
00185                 if(j<8) 
00186                     for(j++ ;j<9;j++)
00187                         if(_values[idxAp4[j]]!=0)
00188                         {
00189                             ap4++;
00190                             break;
00191                         }
00192                 if(j<8) 
00193                     for(j++ ;j<9;j++)
00194                         if(_values[idxAp4[j]]==0)
00195                             break;
00196                 if(j<8) 
00197                     for(j++ ;j<9;j++)
00198                         if(_values[idxAp4[j]]!=0)
00199                         {
00200                             ap4++;
00201                             break;
00202                         }
00203              }
00204 
00205             //for optimization, I split up this condition
00206     //  if( (nrNZN>=2) && (nrNZN<=6) && 
00207     //      if( (ap1==1) &&
00208             if( ( p2p4p8 || ap2!=1) &&
00209                 ( p2p4p6 || ap4!=1)
00210                 )
00211             {
00212                 //set the changed flag
00213                     _changed = true;
00214                     return 1;
00215             }
00216         }//end if a1==1
00217     }//end if nrNonZeroNeighbors >2 &<6
00218     return _values[_pctIdx];
00219 }
00220 
00221 #ifdef INC_TEMPLATE_SRC
00222 #include "HxNgbHilditch.c"
00223 #endif
00224 
00225 
00226 #endif

Generated on Tue Feb 3 14:18:40 2004 for C++Reference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001