proj home

Files   Classes   Functions   Hierarchy  

mazematrixmapD2.h

Go to the documentation of this file.
00001 #ifndef MAZEMATRIXMAPD2_H
00002 #define MAZEMATRIXMAPD2_H
00003 
00004 #include <deque>
00005 #include <map>
00006 using namespace std;
00007 
00008 #include <mazematrixD2.h>
00009 #include <point.h>
00010 #include <print.h>
00011 
00021 template< typename T, typename W >
00022 class mazematrixmapD2
00023 {
00024 public:
00025 
00026   typedef map< T, point2<W> > mapping;
00027   typedef typename mapping::iterator mappingiterator;
00028 
00030   mapping ipt;
00032   mappingiterator iter;
00034   T zeroindex;
00035 
00037   mazematrixD2<T> & mz;
00038 
00040   W dx;
00042   W dy;
00043 
00045   void relativeto(T i); 
00046 
00048   void eval(); 
00049 
00051   void changeSet(W dx_, W dy_)
00052     { dx=dx_; dy=dy_; }
00053 
00055   mazematrixmapD2( mazematrixD2<T> & mz_, W dx_, W dy_ )
00056     : zeroindex(0), mz(mz_)
00057     { changeSet(dx_,dy_); }
00058 
00060   void reset()
00061     { iter=ipt.begin(); }
00062 
00064   T currentIndex()
00065     { return (*iter).first; }
00067   cellD2<T>& currentCell()
00068     { return mz.vi[(*iter).first]; }
00070   point2<W>& currentPosition()
00071     { return (*iter).second; }
00072   
00074   boolc operator ! () 
00075     { return iter != ipt.end(); } 
00077   void operator ++()
00078     { ++iter; }
00079   
00081   boolc add( T id );
00082 
00083 };
00084 
00085 
00086 
00087 //----------------------------------------------------------
00088 // Implementation
00089 
00090 template< typename T, typename W >
00091 void mazematrixmapD2<T,W>::relativeto(T i)
00092 {
00093   ipt.clear();
00094   assert(i<mz.vi.size());
00095   cellD2<T> & x = mz.vi[i];
00096   ipt.insert( make_pair(x.id,point2<W>(0,0)) ); 
00097 
00098   zeroindex=i;
00099 }
00100 
00101 template< typename T, typename W >
00102 void mazematrixmapD2<T,W>::eval()
00103 {
00104   iter = ipt.begin();
00105   cellD2<T>& x(currentCell());
00106 
00107   deque<T> process;
00108   process.push_back(x.id);
00109 /*
00110   for (uint k=0; k<4; ++k)
00111   {
00112     if (x.ni[k]!=0)
00113       process.push_back(x.ni[k]);
00114   }
00115 */
00116 
00117   T id;
00118   for ( ; ! process.empty(); )
00119   {
00120     id = process.front();
00121 //cout << SHOW(id) << endl;
00122     process.pop_front();
00123 
00124     assert(id < mz.vi.size());
00125 
00126     cellD2<T>& x2(mz.vi[id]);
00127 
00128     for (uint k=0; k<4; ++k)
00129     {
00130       if (x2.ni[k]!=0)
00131       {
00132         if (ipt.find(x2.ni[k])==ipt.end())
00133           process.push_back(x2.ni[k]);
00134       }
00135     }
00136 
00137     add(id);
00138   }
00139   
00140 }
00141 
00142 template< typename T, typename W >
00143 boolc mazematrixmapD2<T,W>::add(T id)
00144 {
00145   assert(id!=0);
00146   assert(id<mz.vi.size());
00147 
00148   if (id==0)
00149     return false;
00150   if (id >= mz.vi.size())
00151     return false;
00152 
00153   iter = ipt.find(id); 
00154 
00155   assert(iter!=ipt.end());
00156   if (iter==ipt.end())
00157     return false;
00158   
00159   point2<W> k((*iter).second);
00160 
00161   // Assume uniqueness of cells. 
00162 
00163   mappingiterator i2;
00164   cellD2<T> & x(mz.vi[id]);
00165 
00166   if (x.ni[0]!=0)
00167   {
00168     i2=ipt.find(x.ni[0]);
00169     if (i2==ipt.end())
00170     {
00171       ipt.insert( make_pair(x.ni[0],point2<W>(k.x,k.y+dy)) );
00172     }
00173   }
00174 
00175   if (x.ni[2]!=0)
00176   {
00177     i2=ipt.find(x.ni[2]);
00178     if (i2==ipt.end())
00179     {
00180       ipt.insert( make_pair(x.ni[2],point2<W>(k.x,k.y-dy)) );
00181     }
00182   }
00183 
00184   if (x.ni[1]!=0)
00185   {
00186     i2=ipt.find(x.ni[1]);
00187     if (i2==ipt.end())
00188     {
00189       ipt.insert( make_pair(x.ni[1],point2<W>(k.x+dx,k.y)) );
00190     }
00191   }
00192 
00193   if (x.ni[3]!=0)
00194   {
00195     i2=ipt.find(x.ni[3]);
00196     if (i2==ipt.end())
00197     {
00198       ipt.insert( make_pair(x.ni[3],point2<W>(k.x-dx,k.y)) );
00199     }
00200   }
00201 
00202   return true;
00203 }
00204 
00205 
00206 /*
00207 template< typename T >
00208 uint mazematrixmapD2<W>::indexInv( point2<W> const & x ) const
00209 {
00210   uint imax=index.size();
00211   for (uint i=0; i<imax; ++i)
00212   {
00213     if (index[i]==x)
00214       return i;
00215   }
00216 
00217   return 0;
00218 }
00219 */
00220 
00221 
00222 #endif
00223 

Generated on Fri Mar 4 00:49:29 2011 for Chelton Evans Source by  doxygen 1.5.8