Anaphe Home Page Reference Documentation

Main Page     Namespaces     Classes     Source Code    

P_Histo_3D.ddl

Go to the documentation of this file.
00001 #ifndef _H_P__HISTO_3D_H_
00002 
00003 #if 1
00004         // Persistent case:
00005         #define _H_P__HISTO_3D_H_ 1
00006         #include "HTL/P_I_Histo_3D.h"
00007 #else
00008         // Transient case:
00009         #define _H_T__HISTO_3D_H_ 1
00010         #include "HTL/T_I_Histo_3D.h"
00011 #endif
00012 
00013 #include "HTL/Histo_op.h"
00014 
00055 template< class T_Life, class T_Bin
00056         , class T_Point_X, class T_Partition_X
00057         , class T_Point_Y, class T_Partition_Y 
00058         , class T_Point_Z, class T_Partition_Z >
00059 class P_Histo_3D: public P_I_Histo_3D
00060 {
00061 public:
00063   H_IID_IMPLEMENT( P_Histo_3D );
00064 
00065     typedef P_Histo_3D< T_Life, T_Bin, T_Point_X, T_Partition_X
00066     , T_Point_Y, T_Partition_Y, T_Point_Z, T_Partition_Z> Like_Current;
00067         
00068   typedef H_P_REF( Like_Current )       Ref_Like_Current;
00069 
00070   typedef T_Bin                                 Bin_Type;
00071   typedef T_Partition_X                         Partition_X_Type;
00072   typedef T_Partition_Y                         Partition_Y_Type;
00073   typedef T_Partition_Z                         Partition_Z_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   typedef          T_Partition_Z::Mapped_Point  Mapped_Point_Z;
00078 #else
00079   typedef typename T_Partition_X::Mapped_Point  Mapped_Point_X;
00080   typedef typename T_Partition_Y::Mapped_Point  Mapped_Point_Y;
00081   typedef typename T_Partition_Z::Mapped_Point  Mapped_Point_Z;
00082 #endif
00083 
00084 protected:
00085   P_Histo_3D() {}
00086 public:
00087   virtual ~P_Histo_3D() {}
00088 
00093   P_Histo_3D( const char *a_name
00094                           , const T_Partition_X &a_partition_X
00095                           , const T_Partition_Y &a_partition_Y 
00096                           , const T_Partition_Z &a_partition_Z );
00097 
00107   P_Histo_3D( I_Histo &a_histo, int copy_data = 1 );
00108 
00118   P_Histo_3D( const I_Histo &a_histo, int copy_data = 1 );
00119 
00120 public:
00122   virtual const char *name() const { return P_HTL_STR_CONV(name_);}
00123 
00125   virtual void set_name( const char *a_name ){ update_(); name_ = a_name; }
00126 
00129   virtual I_Bin & i_bin( I_Bin_Location &a_location );
00130 
00133   virtual I_Bin & i_bin ( I_Bin_Location &a_location ) const;
00134 
00139   virtual I_Bin & i_extra_bin( I_Extra_Bin_Location &a_location );
00140 
00145   virtual I_Bin & i_extra_bin ( I_Extra_Bin_Location &a_location ) const;
00146 
00152   virtual I_Bin & i_any_bin ( I_Bin_Location &a_location ) const;
00153 
00156   virtual Size bin_count() const { 
00157       return (partition_X().bin_count()*partition_Y().bin_count()
00158               *partition_Z().bin_count()); 
00159   }
00160 
00166   virtual I_Partition & i_partition( Index p );
00167 
00174   virtual I_Partition & i_partition( Index p ) const ;
00176   virtual I_Bin & i_bin( Index i );
00179   virtual I_Bin & i_bin( Index i ) const;
00181   virtual void reset();
00182 public:
00184    T_Partition_X & partition_X() { return (T_Partition_X &) partition_X_; }
00186    T_Partition_Y & partition_Y() { return (T_Partition_Y &) partition_Y_; }
00188    T_Partition_Z & partition_Z() { return (T_Partition_Z &) partition_Z_; }
00190    T_Partition_X& partition_X() const { return (T_Partition_X &) partition_X_;}
00192    T_Partition_Y& partition_Y() const { return (T_Partition_Y &) partition_Y_;}
00194    T_Partition_Z& partition_Z() const { return (T_Partition_Z &) partition_Z_;}
00195 public:
00199   T_Bin & mapped_bin( T_Point_X x, T_Point_Y y , T_Point_Z z );
00200 
00207   T_Bin & bin( Index i, Index j , Index k, int updateBin = 1)
00208     {
00209       if ((k >= 0) && (k < Index(partition_Z().bin_count()))) {
00210         if ((i >= 0) && (i < Index(partition_X().bin_count()))) {
00211           if ((j >= 0) && (j < Index(partition_Y().bin_count()))) {
00212             if (updateBin)  {H_BIN_UPDATE}
00213             return (T_Bin &) bins_[ i + j*partition_X().bin_count() +
00214             k*partition_X().bin_count()*partition_Y().bin_count()];
00215           } else {
00216             HTL_ERR("Invalid Y bin index in bin(..)" );
00217             return (T_Bin &) bins_[ partition_Y().bin_count() ];
00218           }
00219         } else {
00220           HTL_ERR("Invalid X bin index in bin(..)" );
00221           return (T_Bin &) bins_[ partition_X().bin_count() ];
00222         }
00223       } else {
00224         HTL_ERR("Invalid Z bin index in bin(..)" );
00225         return (T_Bin &) bins_[ partition_Z().bin_count() ];
00226       }
00227     }
00228 
00234   T_Bin & bin( Index i, Index j , Index k) const
00235     {
00236       if ((k >= 0) && (k < Index(partition_Z().bin_count()))) {
00237         if ((i >= 0) && (i < Index(partition_X().bin_count()))) {
00238           if ((j >= 0) && (j < Index(partition_Y().bin_count()))) {
00239             return (T_Bin &) bins_[ i + j*partition_X().bin_count() +
00240             k*partition_X().bin_count()*partition_Y().bin_count()];
00241           } else {
00242             HTL_ERR("Invalid Y bin index in bin(..)" );
00243             return (T_Bin &) bins_[ partition_Y().bin_count() ];
00244           }
00245         } else {
00246           HTL_ERR("Invalid X bin index in bin(..)" );
00247           return (T_Bin &) bins_[ partition_X().bin_count() ];
00248         }
00249       } else {
00250         HTL_ERR("Invalid Z bin index in bin(..)" );
00251         return (T_Bin &) bins_[ partition_Z().bin_count() ];
00252       }
00253     }
00254 
00259   T_Bin & extra_bin( Extra_Index an_ei, Extra_Index an_ej, Extra_Index an_ek,
00260                      int updateBin = 1);
00261 
00266   T_Bin & extra_bin( Extra_Index an_ei, Extra_Index an_ej, 
00267                      Extra_Index an_ek) const;
00268 
00271   bool is_in_range( Extra_Index an_ei, Extra_Index an_ej, 
00272                     Extra_Index an_ek) const{ 
00273     return
00274       (EXTRA_IN_RANGE(an_ei)&& EXTRA_IN_RANGE(an_ej)&& EXTRA_IN_RANGE(an_ek));
00275   }
00276 
00277 public: // Unsafe access to the bins: (NOT DOCUMENTED)
00278   // Unsafe linear access!
00279      T_Bin & _bin( Index i ) { H_BIN_UPDATE return (T_Bin &) bins_[ i ]; }
00280 public:
00285   Ref_Like_Current clone( int copy_data = 1 )
00286   {
00287     Ref_Like_Current h =
00288       H_P_NEW_CLUSTER0 Like_Current( *this, copy_data );
00289     return h;
00290   }
00292   Ref_Like_Current clone( H_P_CLUSTER1(a_place), int copy_data = 1 )
00293     { return H_P_NEW_CLUSTER1(a_place) Like_Current(*this, copy_data); }
00294 
00295 protected:
00296     virtual P_REF_I_Histo clone_( int copy_data = 1 )
00297       { return (P_REF_I_Histo) clone( copy_data ); }
00298 
00299     virtual P_REF_I_Histo clone_( H_P_CLUSTER1(a_place),
00300                                                 int copy_data = 1 )
00301       { return (P_REF_I_Histo) clone( a_place, copy_data ); }
00302 
00303 public:
00306   Ref_Like_Current add( const Ref_Like_Current &other )
00307   {
00308     Ref_Like_Current h = (Ref_Like_Current &) other;
00309     if ( partition_X().is_compatible_with( h->partition_X() )
00310          && partition_Y().is_compatible_with( h->partition_Y())
00311          && partition_Z().is_compatible_with( h->partition_Z())) {
00312       H_BIN_UPDATE
00313         for( Index i = 0; i<bin_count()+extra_bin_count(); i++ )
00314           bins_[i].add( h->_bin(i) );
00315     } else {
00316       HTL_ERR("Incompatible partitions in add(..)" );
00317     }
00318     return H_P_THIS;
00319   }
00320 
00322     void add( const I_Histo &other ) { add_( other ); }
00323 
00326     Ref_Like_Current sub( const Ref_Like_Current &other )
00327     {
00328       Ref_Like_Current h = (Ref_Like_Current &) other;
00329       if( partition_X().is_compatible_with( h->partition_X() )
00330           && partition_Y().is_compatible_with( h->partition_Y())
00331           && partition_Z().is_compatible_with( h->partition_Z())) {
00332         H_BIN_UPDATE
00333           for( Index i=0; i<bin_count()+extra_bin_count(); i++ )
00334             bins_[i].sub( h->_bin(i) );
00335       } else {
00336         HTL_ERR("Incompatible partitions in sub(..)" );
00337       }
00338       return H_P_THIS;
00339     }
00340 
00342       void sub( const I_Histo &other ) { sub_( other ); }
00343 
00346       Ref_Like_Current mul( 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           && partition_Z().is_compatible_with( h->partition_Z())) {
00352           H_BIN_UPDATE
00353             for( Index i=0; i<bin_count()+extra_bin_count(); i++ )
00354               bins_[i].mul( h->_bin(i) );
00355         } else {
00356           HTL_ERR("Incompatible partitions in mul(..)" );
00357         }
00358         return H_P_THIS;
00359       }
00360 
00362             void mul( const I_Histo &other ) { mul_( other ); }
00363 
00366       Ref_Like_Current div( const Ref_Like_Current &other )
00367         {
00368           Ref_Like_Current h = (Ref_Like_Current &) other;
00369           if( partition_X().is_compatible_with( h->partition_X() )
00370               && partition_Y().is_compatible_with( h->partition_Y())
00371               && partition_Z().is_compatible_with( h->partition_Z())) {
00372             H_BIN_UPDATE
00373               for( Index i=0; i<bin_count()+extra_bin_count(); i++ )
00374                 bins_[i].div( h->_bin(i) );
00375           } else {
00376             HTL_ERR("Incompatible partitions in div(..)" );
00377           }
00378           return H_P_THIS;
00379         }
00380 
00382             void div( const I_Histo &other ) { div_( other ); }
00383 
00386       Ref_Like_Current binomial_div( const Ref_Like_Current &other )
00387         {
00388           Ref_Like_Current h = (Ref_Like_Current &) other;
00389             if( partition_X().is_compatible_with( h->partition_X() )
00390                 && partition_Y().is_compatible_with( h->partition_Y())
00391                 && partition_Z().is_compatible_with( h->partition_Z())) {
00392               H_BIN_UPDATE
00393                 for( Index i=0; i<bin_count()+extra_bin_count(); i++ )
00394                   bins_[i].binomial_div( h->_bin(i) );
00395             } else {
00396               HTL_ERR("Incompatible partitions in div(..)" );
00397             }
00398             return H_P_THIS;
00399           }
00400 
00402         void binomial_div( const I_Histo &other ) { binomial_div_( other ); }
00404         void add( double x ) { add_( x ); }
00406         void sub( double x ) { sub_( x ); }
00408         void mul( double x ) { mul_( x ); }
00410         void div( double x ) { div_( x ); }
00411 
00412 protected:
00413   virtual void add_( const I_Histo &other );
00414   virtual P_REF_I_Histo add1_( const I_Histo &other );
00415 
00416   virtual void sub_( const I_Histo &other );
00417   virtual P_REF_I_Histo sub1_( const I_Histo &other );
00418 
00419   virtual void mul_( const I_Histo &other );
00420   virtual P_REF_I_Histo mul1_( const I_Histo &other );
00421 
00422   virtual void div_( const I_Histo &other );
00423   virtual P_REF_I_Histo div1_( const I_Histo &other );
00424 
00425   virtual void binomial_div_( const I_Histo &other );
00426   virtual P_REF_I_Histo binomial_div1_(const I_Histo &other);
00427 
00428   virtual void add_( double x );
00429   virtual void sub_( double x );
00430   virtual void mul_( double x );
00431   virtual void div_( double x );
00432   bool compatiblePartitions (const I_Histo &other, const char *oper);
00433   void compute_( const I_Histo &other , binHistoOp &oper) ;
00434   void compute_( double value , binScalarOp &oper) ;
00435   Index realOutRange(Extra_Index ei,Extra_Index ej,Extra_Index ek,
00436                      Index ni,Index nj,Index nk) const;
00437   Index summaryOUInfo(Extra_Index ei,Extra_Index ej,Extra_Index ek);
00438   Index computeSummary( Index which, Index low, Index high);
00439   void faceBoundary(Extra_Index an_ei,Extra_Index an_ej,Extra_Index an_ek,
00440                     Index& low, Index& high);
00441   void edgeBoundary(Extra_Index an_ei,Extra_Index an_ej,Extra_Index an_ek,
00442                     Index& low, Index& high); 
00443 #if 1
00444 public:
00445         virtual void start_update() { bins_.update(); }
00446 
00447 protected:
00448         void update_() // Open object for update
00449         {if( ooUpdate() != oocSuccess) HTL_ERR( "Cant open for update" ); }
00450 #else
00451 public:
00452         virtual void start_update() {}
00453 
00454 protected:
00455         void update_() {}
00456 #endif
00457 
00458 
00460 protected:
00461 // Name/Title attached to this histogram.
00462 #if defined __sun && __SUNPRO_CC < 0x500
00463       T_Life::S_String name_;
00464 #else
00465       typename T_Life::S_String name_;
00466 #endif
00467       // 1st Partition associated with current histo.
00468            T_Partition_X partition_X_;
00469       // 2nd Partition associated with current histo.
00470            T_Partition_Y partition_Y_;
00471       // 3rd Partition associated with current histo.
00472            T_Partition_Z partition_Z_;
00473 
00474       // Container that contains the bins.
00475 #if defined __sun && __SUNPRO_CC < 0x500
00476                  T_Life::P_Bin_Container bins_;
00477 #else
00478         typename T_Life::P_Bin_Container bins_;
00479 #endif
00480 };
00481 
00482 
00483 #endif // _HISTO_3D_H_
00484 
00485 
00486 // *************************************************************************** 
00487 // * NOTES:
00488 // *************************************************************************** 
00489 /*
00490 
00491 * November, 1998:
00492 
00493 Stupid VC++ requires a temporary variable before return the persistent
00494 "new( ooThis().containerIn() ) Like_Current(..)" in the clone method.
00495 
00496 
00497 * August, 1998:
00498 
00499 Cannot use the following typedef in the cpp: the compiler wont compile.
00500         typedef T_Partition_X::Mapped_Point     Mapped_Point_X;
00501         typedef T_Partition_Y::Mapped_Point     Mapped_Point_Y;
00502 They can be used in the .h when the method is defined in the class
00503 declaration itself.
00504 
00505 Some other typedefs cannot be used in the cpp, safe in the .h.
00506 
00507 */
00508 
00509 


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