Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

DenseIntVectSet.H

Go to the documentation of this file.
00001 /* _______              __
00002   / ___/ /  ___  __ _  / /  ___
00003  / /__/ _ \/ _ \/  ' \/ _ \/ _ \
00004  \___/_//_/\___/_/_/_/_.__/\___/ 
00005 */
00006 //
00007 // This software is copyright (C) by the Lawrence Berkeley
00008 // National Laboratory.  Permission is granted to reproduce
00009 // this software for non-commercial purposes provided that
00010 // this notice is left intact.
00011 // 
00012 // It is acknowledged that the U.S. Government has rights to
00013 // this software under Contract DE-AC03-765F00098 between
00014 // the U.S.  Department of Energy and the University of
00015 // California.
00016 //
00017 // This software is provided as a professional and academic
00018 // contribution for joint exchange. Thus it is experimental,
00019 // is provided ``as is'', with no warranties of any kind
00020 // whatsoever, no support, no promise of updates, or printed
00021 // documentation. By using this software, you acknowledge
00022 // that the Lawrence Berkeley National Laboratory and
00023 // Regents of the University of California shall have no
00024 // liability with respect to the infringement of other
00025 // copyrights by any part of this software.
00026 //
00027 
00028 #include "BitSet.H"
00029 #include "IntVect.H"
00030 #include "Box.H"
00031 #include "Vector.H"
00032 #include "ProblemDomain.H"
00033 
00034 class ProblemDomain;
00035 class DenseIntVectSetIterator;
00037 
00041 class DenseIntVectSet
00042 {
00043 public:
00045   DenseIntVectSet(){;}
00046 
00048 
00049   DenseIntVectSet(const Box& a_domain, bool init = true);
00050   // copy, and operator= should be fine
00051 
00053 
00056   DenseIntVectSet& operator-=(const Box& box);
00057 
00059 
00062   DenseIntVectSet& operator-=(const IntVect& intvect);
00063 
00065 
00068   DenseIntVectSet& operator-=(const DenseIntVectSet& ivs);
00069 
00071 
00074   DenseIntVectSet& operator&=(const Box& box);
00075  
00077 
00080   DenseIntVectSet& operator&=(const ProblemDomain& domain);
00081 
00083 
00088   DenseIntVectSet& operator|=(const IntVect& intvect);
00089 
00091 
00096   DenseIntVectSet& operator|=(const Box& b);
00097 
00099 
00104   DenseIntVectSet& operator|=(const DenseIntVectSet& b);
00105 
00107 
00110   DenseIntVectSet& operator&=(const DenseIntVectSet& ivs);
00111 
00113 
00116   void shift(const IntVect& iv);
00117 
00118   //
00119   /* slower, constant time pointwise access.
00120      You should not build a BoxIterator, then access this
00121      method if you intend to iterate over the objects true
00122      or false terms.  you should build a DenseIntVectSetIterator */
00123   bool operator[](const IntVect& index) const;
00124 
00126 
00128   bool contains(const Box& box) const;
00129 
00131 
00134   void coarsen(int iref);
00135 
00137 
00140   void refine(int iref);
00141 
00143 
00146   void grow(int igrow);
00147 
00149 
00152   void grow(int idir, int igrow);
00153 
00155 
00160   DenseIntVectSet chop(int dir, int chop_pnt);
00161 
00162   inline const Box& box() const;
00163 
00165 
00167   void nestingRegion(int a_radius, const Box& a_domain);
00168 
00170 
00172   void nestingRegion(int a_radius, const ProblemDomain& a_domain);
00173 
00175 
00178   bool isEmpty() const; //cheaper than numPts by wide margin
00179 
00181 
00184   bool isFull() const;  // cheaper than numPts, bu significant margin
00185 
00187 
00190   int  numPts() const;
00191 
00193 
00196   Vector<Box> createBoxes() const;
00198 
00202   void compact() const ; 
00203 
00204   void recalcMinBox() const;
00205 
00206   const Box& mBox() const {return m_minBox;}
00207 
00208 private:
00209 
00210   void grow(const IntVect& iv);
00211   // version without checking intersect or empty
00212   DenseIntVectSet& intersect(const DenseIntVectSet& rhs);
00213   Box m_domain;
00214   BitSet m_bits;
00215   friend class DenseIntVectSetIterator;
00216   Box m_minBox;
00217 };
00218 
00220 
00222 class DenseIntVectSetIterator
00223 {
00224 public:
00225 
00227   DenseIntVectSetIterator();
00228 
00230   DenseIntVectSetIterator(const DenseIntVectSet& ivs);
00231 
00233   void define(const DenseIntVectSet& ivs);
00234   //default null, assignment, copy and destructor should work fine.
00235 
00237   const IntVect& operator()() const ;
00238 
00240   bool ok() const;
00241 
00243   void operator++();
00244 
00246   void begin();
00247 
00249   void end();
00250 
00251   static DenseIntVectSet    emptyDenseIntVectSet;
00252 
00253 private:
00254   BitSetIterator m_iterator;
00255   IntVect        m_current;
00256   const DenseIntVectSet*    m_ivsPtr;
00257   int isize, ijsize, bigi, bigj;
00258 
00259   void nextIntVect();
00260   void nextIntVect(int skip);
00261 
00262 };
00263 
00264 //===================================================================
00265 
00266 // inline functions
00267 
00268 
00269 inline
00270 const Box& DenseIntVectSet::box() const { return m_domain;}
00271 
00272 
00273 
00274 inline
00275 DenseIntVectSet& DenseIntVectSet::operator-=(const IntVect& intvect)
00276 {
00277   if(m_domain.contains(intvect))
00278     m_bits.setFalse(m_domain.index(intvect));
00279   return *this;
00280 }
00281 
00282 inline void DenseIntVectSet::shift(const IntVect& iv)
00283 {
00284   m_domain.shift(iv);
00285   m_minBox.shift(iv);
00286 }
00287 
00288 inline
00289 DenseIntVectSetIterator::DenseIntVectSetIterator()
00290   : m_ivsPtr(&emptyDenseIntVectSet)
00291 {
00292   ;
00293 }
00294 
00295 inline
00296 void DenseIntVectSetIterator::define(const DenseIntVectSet& ivs)
00297 {
00298   m_ivsPtr = &ivs;
00299   begin();
00300 }
00301 
00302 inline
00303 DenseIntVectSetIterator::DenseIntVectSetIterator(const DenseIntVectSet& ivs)
00304   : m_ivsPtr(&ivs)
00305 {
00306   begin();
00307 }
00308 
00309 inline
00310 const IntVect& DenseIntVectSetIterator::operator()() const
00311 {
00312   return m_current;
00313 }
00314 
00315 inline
00316 bool DenseIntVectSetIterator::ok() const
00317 {
00318   return m_iterator.ok();
00319 }
00320 
00321 
00322 inline 
00323 void DenseIntVectSetIterator::end()
00324 {
00325   m_iterator.end();
00326 }
00327 
00328 //  inline 
00329 //  void DenseIntVectSetIterator::operator++()
00330 //  {
00331 //    ++m_iterator;
00332 //    nextIntVect();
00333 //    while(!m_iterator() && m_iterator.ok())
00334 //      {
00335 //        ++m_iterator; // next bit please
00336 //        nextIntVect();
00337 //      }
00338 //  }
00339 inline 
00340 void DenseIntVectSetIterator::operator++()
00341 {
00342   ++m_iterator;
00343   int i=1;
00344   while(m_iterator.ok() && !m_iterator())
00345     {
00346       ++m_iterator; // next bit please
00347       ++i;
00348     }
00349   nextIntVect(i);
00350 }

Generated on Wed Apr 16 14:26:49 2003 for Chombo by doxygen1.2.16