Anaphe Home Page Reference Documentation

Main Page     Namespaces     Classes     Source Code    

P_Histo_2D.ddl

Go to the documentation of this file.
00001 #ifndef _H_P__HISTO_2D_H_
00002 
00003 #if 1
00004         // Persistent case:
00005         #define _H_P__HISTO_2D_H_ 1
00006         #include "HTL/P_I_Histo_2D.h"
00007 #else
00008         // Transient case:
00009         #define _H_T__HISTO_2D_H_ 1
00010         #include "HTL/T_I_Histo_2D.h"
00011 #endif
00012 
00013 #include "HTL/Histo_op.h"
00014 
00057 template< class T_Life, class T_Bin
00058         , class T_Point_X, class T_Partition_X
00059         , class T_Point_Y, class T_Partition_Y >
00060 class P_Histo_2D: public P_I_Histo_2D
00061 {
00062 public:
00064   H_IID_IMPLEMENT( P_Histo_2D );
00065 
00066     typedef P_Histo_2D< T_Life, T_Bin, T_Point_X, T_Partition_X
00067     , T_Point_Y, T_Partition_Y > Like_Current;
00068         
00069   typedef H_P_REF( Like_Current )       Ref_Like_Current;
00070 
00071   typedef T_Bin                                 Bin_Type;
00072   typedef T_Partition_X                         Partition_X_Type;
00073   typedef T_Partition_Y                         Partition_Y_Type;
00074 #if defined __sun && __SUNPRO_CC < 0x500
00075   typedef          T_Partition_X::Mapped_Point  Mapped_Point_X;
00076   typedef          T_Partition_Y::Mapped_Point  Mapped_Point_Y;
00077 #else
00078   typedef typename T_Partition_X::Mapped_Point  Mapped_Point_X;
00079   typedef typename T_Partition_Y::Mapped_Point  Mapped_Point_Y;
00080 #endif
00081 
00082 protected:
00083   P_Histo_2D() {}
00084 public:
00085   virtual ~P_Histo_2D() {}
00086 
00091   P_Histo_2D( const char *a_name
00092                           , const T_Partition_X &a_partition_X
00093                           , const T_Partition_Y &a_partition_Y );
00094 
00104   P_Histo_2D( I_Histo &a_histo, int copy_data = 1 );
00105 
00115   P_Histo_2D( const I_Histo &a_histo, int copy_data = 1 );
00116 
00117 public:
00119   virtual const char *name() const { return P_HTL_STR_CONV(name_);}
00120 
00122   virtual void set_name( const char *a_name ){ update_(); name_ = a_name; }
00123 
00126   virtual I_Bin & i_bin( I_Bin_Location &a_location );
00127 
00130   virtual I_Bin & i_bin ( I_Bin_Location &a_location ) const;
00131 
00136   virtual I_Bin & i_extra_bin( I_Extra_Bin_Location &a_location );
00137 
00142   virtual I_Bin & i_extra_bin ( I_Extra_Bin_Location &a_location ) const;
00143 
00146   virtual Size bin_count() const
00147     { return( partition_X().bin_count() * partition_Y().bin_count() ); }
00148 
00150   virtual Size extra_bin_count() const { 
00151     if ( version() == 0) 
00152       return 9;
00153     else
00154       return (partition_X().bin_count()+partition_Y().bin_count()+2)*2;
00155   }
00160   virtual I_Partition & i_partition( Index p );
00161 
00167   virtual I_Partition & i_partition( Index p ) const ;
00169   virtual I_Bin & i_bin( Index i );
00172   virtual I_Bin & i_bin( Index i ) const;
00174   virtual void reset();
00175 public:
00177    T_Partition_X & partition_X() { return (T_Partition_X &) partition_X_; }
00179    T_Partition_Y & partition_Y() { return (T_Partition_Y &) partition_Y_; }
00181    T_Partition_X& partition_X() const { return (T_Partition_X &) partition_X_;}
00183    T_Partition_Y& partition_Y() const { return (T_Partition_Y &) partition_Y_;}
00184 public:
00188   T_Bin & mapped_bin( T_Point_X x, T_Point_Y y );
00189 
00194   T_Bin & bin( Index i, Index j ) const
00195     {
00196       if ((i >= 0) && (i < Index(partition_X().bin_count()))) {
00197         if ((j >= 0) && (j < Index(partition_Y().bin_count()))) {
00198           return (T_Bin &) bins_[ i + j * partition_X().bin_count() ];
00199         } else {
00200           HTL_ERR("Invalid Y bin index in bin(..)" );
00201           return (T_Bin &) bins_[ partition_Y().bin_count() ];
00202         }
00203       } else {
00204         HTL_ERR("Invalid X bin index in bin(..)" );
00205         return (T_Bin &) bins_[ partition_X().bin_count() ];
00206       }
00207     }
00208 
00213   T_Bin & extra_bin( Extra_Index an_ei, Extra_Index an_ej);
00214 
00219   T_Bin & extra_bin( Extra_Index an_ei, Extra_Index an_ej) const;
00220 
00223   bool is_in_range( Extra_Index an_ei, Extra_Index an_ej) const
00224     { return( EXTRA_IN_RANGE(an_ei) && EXTRA_IN_RANGE(an_ej) ); }
00225 
00227   virtual int version() const { 
00228     if ( bins_.size() == static_cast<size_t> (bin_count()+9)) 
00229       return 0;
00230     else
00231       return 1;
00232   }
00233 
00239   virtual I_Bin & i_any_bin ( I_Bin_Location &a_location ) const;
00240 
00241 public: // Unsafe access to the bins: (NOT DOCUMENTED)
00242   // Unsafe linear access!
00243      T_Bin & _bin( Index i ) { H_BIN_UPDATE return (T_Bin &) bins_[ i ]; }
00244 public:
00249   Ref_Like_Current clone( int copy_data = 1 )
00250   {
00251     Ref_Like_Current h =
00252       H_P_NEW_CLUSTER0 Like_Current( *this, copy_data );
00253     return h;
00254   }
00256   Ref_Like_Current clone( H_P_CLUSTER1(a_place), int copy_data = 1 )
00257     { return H_P_NEW_CLUSTER1(a_place) Like_Current(*this, copy_data); }
00258 
00259 protected:
00260     virtual P_REF_I_Histo clone_( int copy_data = 1 )
00261       { return (P_REF_I_Histo) clone( copy_data ); }
00262 
00263     virtual P_REF_I_Histo clone_( H_P_CLUSTER1(a_place),
00264                                                 int copy_data = 1 )
00265       { return (P_REF_I_Histo) clone( a_place, copy_data ); }
00266 
00267 public:
00270   Ref_Like_Current add( const Ref_Like_Current &other )
00271   {
00272     Ref_Like_Current h = (Ref_Like_Current &) other;
00273     if ( partition_X().is_compatible_with( h->partition_X() )
00274          && partition_Y().is_compatible_with( h->partition_Y())) {
00275       H_BIN_UPDATE
00276         for( Index i = 0; i<bin_count()+extra_bin_count(); i++ )
00277           bins_[i].add( h->_bin(i) );
00278     } else {
00279       HTL_ERR("Incompatible partitions in add(..)" );
00280     }
00281     return H_P_THIS;
00282   }
00283 
00285     void add( const I_Histo &other ) { add_( other ); }
00286 
00289     Ref_Like_Current sub( const Ref_Like_Current &other )
00290     {
00291       Ref_Like_Current h = (Ref_Like_Current &) other;
00292       if( partition_X().is_compatible_with( h->partition_X() )
00293           && partition_Y().is_compatible_with( h->partition_Y())) {
00294         H_BIN_UPDATE
00295           for( Index i=0; i<bin_count()+extra_bin_count(); i++ )
00296             bins_[i].sub( h->_bin(i) );
00297       } else {
00298         HTL_ERR("Incompatible partitions in sub(..)" );
00299       }
00300       return H_P_THIS;
00301     }
00302 
00304       void sub( const I_Histo &other ) { sub_( other ); }
00305 
00308       Ref_Like_Current mul( const Ref_Like_Current &other )
00309       {
00310         Ref_Like_Current h = (Ref_Like_Current &) other;
00311         if( partition_X().is_compatible_with( h->partition_X() )
00312             && partition_Y().is_compatible_with( h->partition_Y())) {
00313           H_BIN_UPDATE
00314             for( Index i=0; i<bin_count()+extra_bin_count(); i++ )
00315               bins_[i].mul( h->_bin(i) );
00316         } else {
00317           HTL_ERR("Incompatible partitions in mul(..)" );
00318         }
00319         return H_P_THIS;
00320       }
00321 
00323             void mul( const I_Histo &other ) { mul_( other ); }
00324 
00327       Ref_Like_Current div( const Ref_Like_Current &other )
00328         {
00329           Ref_Like_Current h = (Ref_Like_Current &) other;
00330           if( partition_X().is_compatible_with( h->partition_X() )
00331               && partition_Y().is_compatible_with( h->partition_Y())) {
00332             H_BIN_UPDATE
00333               for( Index i=0; i<bin_count()+extra_bin_count(); i++ )
00334                 bins_[i].div( h->_bin(i) );
00335           } else {
00336             HTL_ERR("Incompatible partitions in div(..)" );
00337           }
00338           return H_P_THIS;
00339         }
00340 
00342             void div( const I_Histo &other ) { div_( other ); }
00343 
00346       Ref_Like_Current binomial_div( const Ref_Like_Current &other )
00347         {
00348           Ref_Like_Current h = (Ref_Like_Current &) other;
00349             if( partition_X().is_compatible_with( h->partition_X() )
00350                 && partition_Y().is_compatible_with( h->partition_Y())) {
00351               H_BIN_UPDATE
00352                 for( Index i=0; i<bin_count()+extra_bin_count(); i++ )
00353                   bins_[i].binomial_div( h->_bin(i) );
00354             } else {
00355               HTL_ERR("Incompatible partitions in div(..)" );
00356             }
00357             return H_P_THIS;
00358           }
00359 
00361         void binomial_div( const I_Histo &other ) { binomial_div_( other ); }
00363         void add( double x ) { add_( x ); }
00365         void sub( double x ) { sub_( x ); }
00367         void mul( double x ) { mul_( x ); }
00369         void div( double x ) { div_( x ); }
00370 
00371 protected:
00372   virtual void add_( const I_Histo &other );
00373   virtual P_REF_I_Histo add1_( const I_Histo &other );
00374 
00375   virtual void sub_( const I_Histo &other );
00376   virtual P_REF_I_Histo sub1_( const I_Histo &other );
00377 
00378   virtual void mul_( const I_Histo &other );
00379   virtual P_REF_I_Histo mul1_( const I_Histo &other );
00380 
00381   virtual void div_( const I_Histo &other );
00382   virtual P_REF_I_Histo div1_( const I_Histo &other );
00383 
00384   virtual void binomial_div_( const I_Histo &other );
00385   virtual P_REF_I_Histo binomial_div1_(const I_Histo &other);
00386 
00387   virtual void add_( double x );
00388   virtual void sub_( double x );
00389   virtual void mul_( double x );
00390   virtual void div_( double x );
00391   bool compatiblePartitions (const I_Histo &other, const char *oper);
00392   void compute_( const I_Histo &other , binHistoOp &oper) ;
00393   void compute_( double value , binScalarOp &oper) ;
00394   Index realOutRange(Extra_Index ei,Extra_Index ej,Index ni,Index nj) const;
00395   Index summaryOUInfo(Extra_Index ei,Extra_Index ej);
00396   Index computeSummary( Index which, Index from, Index howMany);
00397   Size dummyBinCount () const { return dim()*dim()*(dim()-1);}
00398 
00399 #if 1
00400 public:
00401         virtual void start_update() { bins_.update(); }
00402 
00403 protected:
00404         void update_() // Open object for update
00405         {if( ooUpdate() != oocSuccess) HTL_ERR( "Cant open for update" ); }
00406 #else
00407 public:
00408         virtual void start_update() {}
00409 
00410 protected:
00411         void update_() {}
00412 #endif
00413 
00414 
00416 protected:
00417 #if defined __sun && __SUNPRO_CC < 0x500
00418                  T_Life::S_String name_;
00419 #else
00420         typename T_Life::S_String name_;
00421 #endif
00422                 // Name/Title atached to this histogram.
00423         T_Partition_X partition_X_;
00424                 // 1st Partition associated with current histo.
00425         T_Partition_Y partition_Y_;
00426                 // 2nd Partition associated with current histo.
00427 #if defined __sun && __SUNPRO_CC < 0x500
00428                  T_Life::P_Bin_Container bins_;
00429 #else
00430         typename T_Life::P_Bin_Container bins_;
00431 #endif
00432                 // Container that contains the bins.
00433 };
00434 
00435 
00436 #endif // _HISTO_2D_H_
00437 
00438 
00439 // *************************************************************************** 
00440 // * NOTES:
00441 // *************************************************************************** 
00442 /*
00443 
00444 * November, 1998:
00445 
00446 Stupid VC++ requires a temporary variable before return the persistent
00447 "new( ooThis().containerIn() ) Like_Current(..)" in the clone method.
00448 
00449 
00450 * August, 1998:
00451 
00452 Cannot use the following typedef in the cpp: the compiler wont compile.
00453         typedef T_Partition_X::Mapped_Point     Mapped_Point_X;
00454         typedef T_Partition_Y::Mapped_Point     Mapped_Point_Y;
00455 They can be used in the .h when the method is defined in the class
00456 declaration itself.
00457 
00458 Some other typedefs cannot be used in the cpp, safe in the .h.
00459 
00460 */
00461 
00462 


Anaphe documentation generated by Doxygen (www.doxygen.org)