Changeset 1419 in Sophya for trunk/SophyaLib/SkyMap


Ignore:
Timestamp:
Feb 23, 2001, 12:26:48 PM (25 years ago)
Author:
lemeur
Message:

surcharge d'operateurs =, +=, *= etc...

Location:
trunk/SophyaLib/SkyMap
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/SkyMap/localmap.cc

    r1308 r1419  
    101101      recopierVariablesSimples(a);     
    102102      pixels_.CloneOrShare(a.pixels_);
     103      if (mInfo_) {delete mInfo_; mInfo_ = NULL;}
     104      if (a.mInfo_) mInfo_ = new DVList(*(a.mInfo_));
     105}
     106template<class T>
     107void LocalMap<T>::Share(const LocalMap<T>& a)
     108{
     109      recopierVariablesSimples(a);     
     110      pixels_.Share(a.pixels_);
     111      if (mInfo_) {delete mInfo_; mInfo_ = NULL;}
     112      if (a.mInfo_) mInfo_ = new DVList(*(a.mInfo_));
    103113}
    104114
     
    556566}
    557567
     568//   ...... Operations de calcul  ......
     569
     570
     571//! Fill a LocalMap with a constant value \b a
     572template <class T>
     573LocalMap<T>& LocalMap<T>::SetT(T a)
     574{
     575  if (NbPixels() < 1)
     576    throw RangeCheckError("LocalMap<T>::SetT(T )  - LocalMap not dimensionned ! ");
     577  pixels_ = a;
     578  return (*this);
     579}
     580
     581/*! Add a constant value \b x to a LocalMap */
     582template <class T>
     583LocalMap<T>& LocalMap<T>::Add(T a)
     584 {
     585  if (NbPixels()< 1)
     586    throw RangeCheckError("LocalMap<T>::Add(T )  - LocalMap not dimensionned ! ");
     587  pixels_ += a;
     588  return (*this);
     589}
     590
     591/*! Substract a constant value \b a to a LocalMap */
     592template <class T>
     593LocalMap<T>& LocalMap<T>::Sub(T a)
     594{
     595  if (NbPixels()< 1)
     596    throw RangeCheckError("LocalMap<T>::Sub(T )  - LocalMap not dimensionned ! ");
     597  pixels_ -= a;
     598  return (*this);
     599}
     600
     601/*! multiply a LocalMap by a constant value \b a */
     602template <class T>
     603LocalMap<T>& LocalMap<T>::Mul(T a)
     604{
     605  if (NbPixels()< 1)
     606    throw RangeCheckError("LocalMap<T>::Mul(T )  - LocalMap not dimensionned ! ");
     607  pixels_ *= a;
     608  return (*this);
     609}
     610
     611/*! divide a LocalMap by a constant value \b a */
     612template <class T>
     613LocalMap<T>& LocalMap<T>::Div(T a)
     614{
     615  if (NbPixels()< 1)
     616    throw RangeCheckError("LocalMap<T>::Div(T )  - LocalMap not dimensionned ! ");
     617  pixels_ /= a;
     618  return (*this);
     619}
     620
     621//  >>>> Operations avec 2nd membre de type LocalMap
     622//! Add two LocalMap
     623
     624template <class T>
     625LocalMap<T>& LocalMap<T>::AddElt(const LocalMap<T>& a)
     626{
     627  if (nSzX_ != a.nSzX_ || nSzY_ != a.nSzY_)
     628    {
     629    throw(SzMismatchError("LocalMap<T>::AddElt(const LocalMap<T>&) SizeMismatch")) ;
     630    }
     631  pixels_ += a.pixels_;
     632  return (*this);
     633}
     634
     635//! Substract two LocalMap
     636template <class T>
     637LocalMap<T>& LocalMap<T>::SubElt(const LocalMap<T>& a)
     638{
     639  if (nSzX_ != a.nSzX_ || nSzY_ != a.nSzY_)
     640    {
     641    throw(SzMismatchError("LocalMap<T>::AddElt(const LocalMap<T>&) SizeMismatch")) ;
     642    }
     643  pixels_ -= a.pixels_;
     644  return (*this);
     645}
     646
     647//! Multiply two LocalMap (elements by elements)
     648template <class T>
     649LocalMap<T>& LocalMap<T>::MulElt(const LocalMap<T>& a)
     650{
     651  if (nSzX_ != a.nSzX_ || nSzY_ != a.nSzY_)
     652    {
     653    throw(SzMismatchError("LocalMap<T>::AddElt(const LocalMap<T>&) SizeMismatch")) ;
     654    }
     655  pixels_ *= a.pixels_;
     656  return (*this);
     657}
     658
     659
     660
     661
    558662
    559663//++
  • trunk/SophyaLib/SkyMap/localmap.h

    r1217 r1419  
    104104void print(ostream& os) const;
    105105
     106// Operations diverses  = , +=, ...
     107
     108
     109virtual LocalMap<T>& Set(const LocalMap<T>& a);
    106110inline  LocalMap<T>& operator = (const LocalMap<T>& a) {return Set(a);}
    107111
     112// A += -= *= /= x (ajoute, soustrait, ... x a tous les elements)
     113
     114  //! Fill LocalMap with all elements equal to \b x
     115virtual LocalMap<T>& SetT(T a);
     116inline  LocalMap<T>& operator = (T a) {return SetT(a);}
     117
     118//! Add \b x to all elements
     119virtual LocalMap<T>& Add(T a);
     120inline  LocalMap<T>&  operator += (T x)  { return Add(x); }
     121//! Substract \b x to all elements
     122virtual LocalMap<T>& Sub(T a);
     123inline   LocalMap<T>&  operator -= (T x)  { return Sub(x); }
     124//! Multiply all elements by \b x
     125virtual LocalMap<T>& Mul(T a);
     126inline  LocalMap<T>&  operator *= (T x)  { return Mul(x); }
     127//! Divide all elements by \b x
     128virtual LocalMap<T>& Div(T a);
     129inline  LocalMap<T>&  operator /= (T x)  { return Div(x); }
     130
     131// A += -=  (ajoute, soustrait element par element les deux spheres )
     132  //! Operator LocalMap += LocalMap
     133  virtual LocalMap<T>&  AddElt(const LocalMap<T>& a);
     134  inline  LocalMap<T>&  operator += (const LocalMap<T>& a)  { return AddElt(a); }
     135
     136
     137
     138  virtual LocalMap<T>&  SubElt(const LocalMap<T>& a);
     139  //! Operator LocalMap -= LocalMap
     140  inline  LocalMap<T>&  operator -= (const LocalMap<T>& a)  { return SubElt(a); }
     141// Multiplication, division element par element les deux LocalMap
     142  virtual LocalMap<T>&  MulElt(const LocalMap<T>& a);
     143  inline  LocalMap<T>&  operator *= (const LocalMap<T>& a)  { return MulElt(a); }
     144
     145
     146void CloneOrShare(const LocalMap<T>& a);
     147void Share(const LocalMap<T>& a);
     148LocalMap<T>& CopyElt(const LocalMap<T>& a);
    108149
    109150
     
    120161
    121162void recopierVariablesSimples(const LocalMap<T>& lm);
    122 LocalMap<T>& Set(const LocalMap<T>& a);
    123 void CloneOrShare(const LocalMap<T>& a);
    124   LocalMap<T>& CopyElt(const LocalMap<T>& a);
    125163
    126164
     
    146184};
    147185
     186////////////////////////////////////////////////////////////////
     187// Surcharge d'operateurs A (+,-,*,/) (T) x
     188/*! \ingroup LocalMap \fn operator+(const LocalMap<T>&,T)
     189  \brief Operator LocalMap = LocalMap + constant */
     190template <class T> inline LocalMap<T> operator + (const LocalMap<T>& a, T b)
     191    {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
     192    result.Add(b); return result;}
     193/*! \ingroup LocalMap \fn operator+(T,const LocalMap<T>&)
     194  \brief Operator LocalMap = constant + LocalMap */
     195template <class T> inline LocalMap<T> operator + (T b,const LocalMap<T>& a)
     196    {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
     197    result.Add(b); return result;}
     198
     199
     200/*! \ingroup LocalMap\fn operator-(const LocalMap<T>&,T)
     201  \brief Operator LocalMap = LocalMap - constant */
     202template <class T> inline LocalMap<T> operator - (const LocalMap<T>& a, T b)
     203    {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
     204    result.Sub(b); return result;}
     205
     206/*! \ingroup  \fn operator-(T,const LocalMap<T>&)
     207  \brief Operator LocalMap = constant - LocalMap */
     208template <class T> inline LocalMap<T> operator - (T b,const LocalMap<T>& a)
     209    {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
     210    result.Sub(b,true); return result;}
     211
     212/*! \ingroup LocalMap \fn operator*(const LocalMap<T>&,T)
     213  \brief Operator LocalMap = LocalMap * constant */
     214template <class T> inline LocalMap<T> operator * (const LocalMap<T>& a, T b)
     215    {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
     216    result.Mul(b); return result;}
     217
     218/*! \ingroup LocalMap \fn operator*(T,const LocalMap<T>&)
     219  \brief Operator LocalMap = constant * LocalMap */
     220template <class T> inline LocalMap<T> operator * (T b,const LocalMap<T>& a)
     221    {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
     222    result.Mul(b); return result;}
     223
     224/*! \ingroup LocalMap \fn operator/(const LocalMap<T>&,T)
     225  \brief Operator LocalMap = LocalMap / constant */
     226template <class T> inline LocalMap<T> operator / (const LocalMap<T>& a, T b)
     227    {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
     228    result.Div(b); return result;}
     229
     230/*! \ingroup LocalMap \fn operator/(T,const LocalMap<T>&)
     231  \brief Operator LocalMap = constant / LocalMap  */
     232template <class T> inline LocalMap<T> operator / (T b, const LocalMap<T>& a)
     233    {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
     234    result.Div(b, true); return result;}
     235
     236////////////////////////////////////////////////////////////////
     237// Surcharge d'operateurs C = A (+,-) B
     238
     239/*! \ingroup LocalMap \fn operator+(const LocalMap<T>&,const LocalMap<T>&)
     240  \brief Operator LocalMap = LocalMap + LocalMap */
     241template <class T>
     242inline LocalMap<T> operator + (const LocalMap<T>& a,const LocalMap<T>& b)
     243    { LocalMap<T> result; result.SetTemp(true);
     244    if (b.IsTemp())  { result.Share(b); result.AddElt(a); }
     245    else { result.CloneOrShare(a); result.AddElt(b); }
     246    return result; }
     247
     248/*! \ingroup LocalMap \fn operator-(const LocalMap<T>&,const LocalMap<T>&)
     249  \brief Operator LocalMap = LocalMap - LocalMap */
     250template <class T>
     251inline LocalMap<T> operator - (const LocalMap<T>& a,const LocalMap<T>& b)
     252    { LocalMap<T> result; result.SetTemp(true);
     253    if (b.IsTemp())  { result.Share(b); result.SubElt(a, true); }
     254    else { result.CloneOrShare(a); result.SubElt(b); }
     255    return result; }
    148256
    149257
  • trunk/SophyaLib/SkyMap/pixelmap.h

    r1375 r1419  
    9696/*! Setting pixel values to a constant */
    9797virtual T SetPixels(T v);
    98 inline T operator = (T v) { return(SetPixels(v)); }
     98PixelMap<T>& SetT(T v);
     99  //inline T operator = (T v) { return(SetPixels(v)); }
     100inline PixelMap<T>& operator = (T v) { return(SetT(v)); }
    99101
    100102
     
    141143return(v);
    142144}
     145template <class T>
     146PixelMap<T>& PixelMap<T>::SetT(T v)
     147{
     148int k;
     149for(k=0; k<NbPixels(); k++) PixVal(k) = v;
     150return(*this);
     151}
    143152
    144153
  • trunk/SophyaLib/SkyMap/spherehealpix.cc

    r1304 r1419  
    127127}
    128128
     129//! Clone if \b a is not temporary, share if temporary
     130/*! \sa NDataBlock::CloneOrShare(const NDataBlock<T>&) */
    129131template<class T>
    130132void SphereHEALPix<T>::CloneOrShare(const SphereHEALPix<T>& a)
     
    136138  sliceBeginIndex_.CloneOrShare(a.sliceBeginIndex_);
    137139  sliceLenght_.CloneOrShare(a.sliceLenght_);
    138 
    139   // pas forcement a conserver, pas forcement a cet endroit (GLM)
    140   //  if (a.IsTemp() ) SetTemp(true);
     140  if (mInfo_) {delete mInfo_; mInfo_ = NULL;}
     141  if (a.mInfo_) mInfo_ = new DVList(*(a.mInfo_));
     142}
     143
     144//! Share data with a
     145template<class T>
     146void SphereHEALPix<T>::Share(const SphereHEALPix<T>& a)
     147{
     148  nSide_= a.nSide_;
     149  nPix_ = a.nPix_;
     150  omeg_ = a.omeg_;
     151  pixels_.Share(a.pixels_);
     152  sliceBeginIndex_.Share(a.sliceBeginIndex_);
     153  sliceLenght_.Share(a.sliceLenght_);
     154  if (mInfo_) {delete mInfo_; mInfo_ = NULL;}
     155  if (a.mInfo_) mInfo_ = new DVList(*(a.mInfo_));
    141156}
    142157
     
    149164     
    150165      if (a.NbPixels() < 1)
    151         throw RangeCheckError("SphereHEALPix<T>::Set(a ) - Array a not allocated ! ");
     166        throw RangeCheckError("SphereHEALPix<T>::Set(a ) - SphereHEALPix a not allocated ! ");
    152167      if (NbPixels() < 1) CloneOrShare(a);
    153168      else CopyElt(a);
     
    165180{
    166181  if (NbPixels() < 1)
    167     throw RangeCheckError("SphereHEALPix<T>::CopyElt(const SphereHEALPix<T>& )  - Not Allocated Array ! ");
     182    throw RangeCheckError("SphereHEALPix<T>::CopyElt(const SphereHEALPix<T>& )  - Not Allocated SphereHEALPix ! ");
    168183  if (NbPixels() != a.NbPixels())
    169184    throw(SzMismatchError("SphereHEALPix<T>::CopyElt(const SphereHEALPix<T>&) SizeMismatch")) ;
     
    177192  return(*this);
    178193}
     194
     195
     196
    179197//++
    180198// Titre        Destructor
     
    542560  return  ring2nest(nSide_,k);
    543561}
     562
     563//   ...... Operations de calcul  ......
     564
     565//! Fill a SphereHEALPix with a constant value \b a
     566template <class T>
     567SphereHEALPix<T>& SphereHEALPix<T>::SetT(T a)
     568{
     569  if (NbPixels() < 1)
     570    throw RangeCheckError("SphereHEALPix<T>::SetT(T )  - SphereHEALPix not dimensionned ! ");
     571  pixels_ = a;
     572  return (*this);
     573}
     574
     575/*! Add a constant value \b x to a SphereHEALPix */
     576template <class T>
     577SphereHEALPix<T>& SphereHEALPix<T>::Add(T a)
     578 {
     579  if (NbPixels() < 1)
     580    throw RangeCheckError("SphereHEALPix<T>::Add(T )  - SphereHEALPix not dimensionned ! ");
     581  pixels_ += a;
     582  return (*this);
     583}
     584
     585/*! Substract a constant value \b a to a SphereHEALPix */
     586template <class T>
     587SphereHEALPix<T>& SphereHEALPix<T>::Sub(T a)
     588{
     589  if (NbPixels() < 1)
     590    throw RangeCheckError("SphereHEALPix<T>::Sub(T )  - SphereHEALPix not dimensionned ! ");
     591  pixels_ -= a;
     592  return (*this);
     593}
     594
     595/*! multiply a SphereHEALPix by a constant value \b a */
     596template <class T>
     597SphereHEALPix<T>& SphereHEALPix<T>::Mul(T a)
     598{
     599  if (NbPixels() < 1)
     600    throw RangeCheckError("SphereHEALPix<T>::Mul(T )  - SphereHEALPix not dimensionned ! ");
     601  pixels_ *= a;
     602  return (*this);
     603}
     604
     605/*! divide a SphereHEALPix by a constant value \b a */
     606template <class T>
     607SphereHEALPix<T>& SphereHEALPix<T>::Div(T a)
     608{
     609  if (NbPixels() < 1)
     610    throw RangeCheckError("SphereHEALPix<T>::Div(T )  - SphereHEALPix not dimensionned ! ");
     611  pixels_ /= a;
     612  return (*this);
     613}
     614
     615//  >>>> Operations avec 2nd membre de type SphereHEALPix
     616//! Add two SphereHEALPix
     617
     618template <class T>
     619SphereHEALPix<T>& SphereHEALPix<T>::AddElt(const SphereHEALPix<T>& a)
     620{
     621  if (NbPixels() != a.NbPixels() )
     622    {
     623    throw(SzMismatchError("SphereHEALPix<T>::AddElt(const SphereHEALPix<T>&) SizeMismatch")) ;
     624    }
     625  pixels_ += a.pixels_;
     626  return (*this);
     627}
     628
     629//! Substract two SphereHEALPix
     630template <class T>
     631SphereHEALPix<T>& SphereHEALPix<T>::SubElt(const SphereHEALPix<T>& a)
     632{
     633  if (NbPixels() != a.NbPixels() )
     634    {
     635    throw(SzMismatchError("SphereHEALPix<T>::SubElt(const SphereHEALPix<T>&) SizeMismatch")) ;
     636    }
     637  pixels_ -= a.pixels_;
     638  return (*this);
     639}
     640
     641//! Multiply two SphereHEALPix (elements by elements)
     642template <class T>
     643SphereHEALPix<T>& SphereHEALPix<T>::MulElt(const SphereHEALPix<T>& a)
     644{
     645  if (NbPixels() != a.NbPixels() )
     646    {
     647    throw(SzMismatchError("SphereHEALPix<T>::SubElt(const SphereHEALPix<T>&) SizeMismatch")) ;
     648    }
     649  pixels_ *= a.pixels_;
     650  return (*this);
     651}
     652
     653
    544654
    545655
  • trunk/SophyaLib/SkyMap/spherehealpix.h

    r1217 r1419  
    127127
    128128
     129
     130 
     131
     132
     133
     134// Operations diverses  = , +=, ...
     135
     136
     137SphereHEALPix<T>& Set(const SphereHEALPix<T>& a);
    129138inline  SphereHEALPix<T>& operator = (const SphereHEALPix<T>& a)
    130139                                                        {return Set(a);}
    131140
     141// A += -= *= /= x (ajoute, soustrait, ... x a tous les elements)
     142
     143  //! Fill SphereHEALPix with all elements equal to \b x
     144virtual SphereHEALPix<T>& SetT(T a);
     145inline  SphereHEALPix<T>& operator = (T a) {return SetT(a);}
     146
     147//! Add \b x to all elements
     148virtual SphereHEALPix<T>& Add(T a);
     149inline  SphereHEALPix<T>&  operator += (T x)  { return Add(x); }
     150//! Substract \b x to all elements
     151virtual SphereHEALPix<T>& Sub(T a);
     152inline   SphereHEALPix<T>&  operator -= (T x)  { return Sub(x); }
     153//! Multiply all elements by \b x
     154virtual SphereHEALPix<T>& Mul(T a);
     155inline  SphereHEALPix<T>&  operator *= (T x)  { return Mul(x); }
     156//! Divide all elements by \b x
     157virtual SphereHEALPix<T>& Div(T a);
     158inline  SphereHEALPix<T>&  operator /= (T x)  { return Div(x); }
     159
     160// A += -=  (ajoute, soustrait element par element les deux spheres )
     161  //! Operator SphereHEALPix += SphereHEALPix
     162  virtual SphereHEALPix<T>&  AddElt(const SphereHEALPix<T>& a);
     163  inline  SphereHEALPix<T>&  operator += (const SphereHEALPix<T>& a)  { return AddElt(a); }
     164
     165
     166
     167  virtual SphereHEALPix<T>&  SubElt(const SphereHEALPix<T>& a);
     168  //! Operator SphereHEALPix -= SphereHEALPix
     169  inline  SphereHEALPix<T>&  operator -= (const SphereHEALPix<T>& a)  { return SubElt(a); }
     170// Multiplication, division element par element les deux SphereHEALPix
     171  virtual SphereHEALPix<T>&  MulElt(const SphereHEALPix<T>& a);
     172  inline  SphereHEALPix<T>&  operator *= (const SphereHEALPix<T>& a)  { return MulElt(a); }
     173
     174
    132175 void CloneOrShare(const SphereHEALPix<T>& a);
    133  SphereHEALPix<T>& Set(const SphereHEALPix<T>& a);
     176 void Share(const SphereHEALPix<T>& a);
    134177 SphereHEALPix<T>& CopyElt(const SphereHEALPix<T>& a);
    135178
     
    164207};
    165208
    166 
     209////////////////////////////////////////////////////////////////
     210// Surcharge d'operateurs A (+,-,*,/) (T) x
     211/*! \ingroup SphereHEALPix \fn operator+(const SphereHEALPix<T>&,T)
     212  \brief Operator SphereHEALPix = SphereHEALPix + constant */
     213template <class T> inline SphereHEALPix<T> operator + (const SphereHEALPix<T>& a, T b)
     214    {SphereHEALPix<T> result; result.CloneOrShare(a); result.SetTemp(true);
     215    result.Add(b); return result;}
     216/*! \ingroup SphereHEALPix \fn operator+(T,const SphereHEALPix<T>&)
     217  \brief Operator SphereHEALPix = constant + SphereHEALPix */
     218template <class T> inline SphereHEALPix<T> operator + (T b,const SphereHEALPix<T>& a)
     219    {SphereHEALPix<T> result; result.CloneOrShare(a); result.SetTemp(true);
     220    result.Add(b); return result;}
     221
     222
     223/*! \ingroup SphereHEALPix\fn operator-(const SphereHEALPix<T>&,T)
     224  \brief Operator SphereHEALPix = SphereHEALPix - constant */
     225template <class T> inline SphereHEALPix<T> operator - (const SphereHEALPix<T>& a, T b)
     226    {SphereHEALPix<T> result; result.CloneOrShare(a); result.SetTemp(true);
     227    result.Sub(b); return result;}
     228
     229/*! \ingroup  \fn operator-(T,const SphereHEALPix<T>&)
     230  \brief Operator SphereHEALPix = constant - SphereHEALPix */
     231template <class T> inline SphereHEALPix<T> operator - (T b,const SphereHEALPix<T>& a)
     232    {SphereHEALPix<T> result; result.CloneOrShare(a); result.SetTemp(true);
     233    result.Sub(b,true); return result;}
     234
     235/*! \ingroup SphereHEALPix \fn operator*(const SphereHEALPix<T>&,T)
     236  \brief Operator SphereHEALPix = SphereHEALPix * constant */
     237template <class T> inline SphereHEALPix<T> operator * (const SphereHEALPix<T>& a, T b)
     238    {SphereHEALPix<T> result; result.CloneOrShare(a); result.SetTemp(true);
     239    result.Mul(b); return result;}
     240
     241/*! \ingroup SphereHEALPix \fn operator*(T,const SphereHEALPix<T>&)
     242  \brief Operator SphereHEALPix = constant * SphereHEALPix */
     243template <class T> inline SphereHEALPix<T> operator * (T b,const SphereHEALPix<T>& a)
     244    {SphereHEALPix<T> result; result.CloneOrShare(a); result.SetTemp(true);
     245    result.Mul(b); return result;}
     246
     247/*! \ingroup SphereHEALPix \fn operator/(const SphereHEALPix<T>&,T)
     248  \brief Operator SphereHEALPix = SphereHEALPix / constant */
     249template <class T> inline SphereHEALPix<T> operator / (const SphereHEALPix<T>& a, T b)
     250    {SphereHEALPix<T> result; result.CloneOrShare(a); result.SetTemp(true);
     251    result.Div(b); return result;}
     252
     253/*! \ingroup SphereHEALPix \fn operator/(T,const SphereHEALPix<T>&)
     254  \brief Operator SphereHEALPix = constant / SphereHEALPix  */
     255template <class T> inline SphereHEALPix<T> operator / (T b, const SphereHEALPix<T>& a)
     256    {SphereHEALPix<T> result; result.CloneOrShare(a); result.SetTemp(true);
     257    result.Div(b, true); return result;}
     258
     259////////////////////////////////////////////////////////////////
     260// Surcharge d'operateurs C = A (+,-) B
     261
     262/*! \ingroup SphereHEALPix \fn operator+(const SphereHEALPix<T>&,const SphereHEALPix<T>&)
     263  \brief Operator SphereHEALPix = SphereHEALPix + SphereHEALPix */
     264template <class T>
     265inline SphereHEALPix<T> operator + (const SphereHEALPix<T>& a,const SphereHEALPix<T>& b)
     266    { SphereHEALPix<T> result; result.SetTemp(true);
     267    if (b.IsTemp())  { result.Share(b); result.AddElt(a); }
     268    else { result.CloneOrShare(a); result.AddElt(b); }
     269    return result; }
     270
     271/*! \ingroup SphereHEALPix \fn operator-(const SphereHEALPix<T>&,const SphereHEALPix<T>&)
     272  \brief Operator SphereHEALPix = SphereHEALPix - SphereHEALPix */
     273template <class T>
     274inline SphereHEALPix<T> operator - (const SphereHEALPix<T>& a,const SphereHEALPix<T>& b)
     275    { SphereHEALPix<T> result; result.SetTemp(true);
     276    if (b.IsTemp())  { result.Share(b); result.SubElt(a, true); }
     277    else { result.CloneOrShare(a); result.SubElt(b); }
     278    return result; }
    167279
    168280} // Fin du namespace
  • trunk/SophyaLib/SkyMap/spherethetaphi.cc

    r980 r1419  
    5555//    m is the number of slices in theta on an hemisphere (the polar cap
    5656//    forms the first slice).
    57 //    pet is a dummy parameter at the moment.
    5857//--
    5958{
     
    129128  Theta_.CloneOrShare(a.Theta_);
    130129  pixels_.CloneOrShare(a.pixels_);
     130  if (mInfo_) {delete mInfo_; mInfo_ = NULL;}
     131  if (a.mInfo_) mInfo_ = new DVList(*(a.mInfo_));
     132}
     133template<class T>
     134void  SphereThetaPhi<T>::Share(const  SphereThetaPhi<T>& a)
     135{
     136
     137  NTheta_= a.NTheta_;
     138  NPix_  = a.NPix_;
     139  Omega_ = a.Omega_;
     140  NPhi_.Share(a.NPhi_);
     141  TNphi_.Share(a.TNphi_);
     142  Theta_.Share(a.Theta_);
     143  pixels_.Share(a.pixels_);
     144  if (mInfo_) {delete mInfo_; mInfo_ = NULL;}
     145  if (a.mInfo_) mInfo_ = new DVList(*(a.mInfo_));
    131146}
    132147
     
    710725  os << endl;
    711726}
     727
     728//   ...... Operations de calcul  ......
     729
     730
     731//! Fill a SphereThetaPhi with a constant value \b a
     732template <class T>
     733SphereThetaPhi<T>& SphereThetaPhi<T>::SetT(T a)
     734{
     735  if (NbPixels() < 1)
     736    throw RangeCheckError("SphereThetaPhi<T>::SetT(T )  - SphereThetaPhi not dimensionned ! ");
     737  pixels_ = a;
     738  return (*this);
     739}
     740
     741/*! Add a constant value \b x to a SphereThetaPhi */
     742template <class T>
     743SphereThetaPhi<T>& SphereThetaPhi<T>::Add(T a)
     744 {
     745  if (NbPixels()< 1)
     746    throw RangeCheckError("SphereThetaPhi<T>::Add(T )  - SphereThetaPhi not dimensionned ! ");
     747  pixels_ += a;
     748  return (*this);
     749}
     750
     751/*! Substract a constant value \b a to a SphereThetaPhi */
     752template <class T>
     753SphereThetaPhi<T>& SphereThetaPhi<T>::Sub(T a)
     754{
     755  if (NbPixels()< 1)
     756    throw RangeCheckError("SphereThetaPhi<T>::Sub(T )  - SphereThetaPhi not dimensionned ! ");
     757  pixels_ -= a;
     758  return (*this);
     759}
     760
     761/*! multiply a SphereThetaPhi by a constant value \b a */
     762template <class T>
     763SphereThetaPhi<T>& SphereThetaPhi<T>::Mul(T a)
     764{
     765  if (NbPixels()< 1)
     766    throw RangeCheckError("SphereThetaPhi<T>::Mul(T )  - SphereThetaPhi not dimensionned ! ");
     767  pixels_ *= a;
     768  return (*this);
     769}
     770
     771/*! divide a SphereThetaPhi by a constant value \b a */
     772template <class T>
     773SphereThetaPhi<T>& SphereThetaPhi<T>::Div(T a)
     774{
     775  if (NbPixels()< 1)
     776    throw RangeCheckError("SphereThetaPhi<T>::Div(T )  - SphereThetaPhi not dimensionned ! ");
     777  pixels_ /= a;
     778  return (*this);
     779}
     780
     781//  >>>> Operations avec 2nd membre de type SphereThetaPhi
     782//! Add two SphereThetaPhi
     783
     784template <class T>
     785SphereThetaPhi<T>& SphereThetaPhi<T>::AddElt(const SphereThetaPhi<T>& a)
     786{
     787  if (NbPixels()!= a.NbPixels())
     788    {
     789    throw(SzMismatchError("SphereThetaPhi<T>::AddElt(const SphereThetaPhi<T>&) SizeMismatch")) ;
     790    }
     791  pixels_ += a.pixels_;
     792  return (*this);
     793}
     794
     795//! Substract two SphereThetaPhi
     796template <class T>
     797SphereThetaPhi<T>& SphereThetaPhi<T>::SubElt(const SphereThetaPhi<T>& a)
     798{
     799  if (NbPixels()!= a.NbPixels())
     800    {
     801    throw(SzMismatchError("SphereThetaPhi<T>::SubElt(const SphereThetaPhi<T>&) SizeMismatch")) ;
     802    }
     803  pixels_ -= a.pixels_;
     804  return (*this);
     805}
     806
     807//! Multiply two SphereThetaPhi (elements by elements)
     808template <class T>
     809SphereThetaPhi<T>& SphereThetaPhi<T>::MulElt(const SphereThetaPhi<T>& a)
     810{
     811  if (NbPixels()!= a.NbPixels())
     812    {
     813    throw(SzMismatchError("SphereThetaPhi<T>::SubElt(const SphereThetaPhi<T>&) SizeMismatch")) ;
     814    }
     815  pixels_ *= a.pixels_;
     816  return (*this);
     817}
     818
    712819
    713820
  • trunk/SophyaLib/SkyMap/spherethetaphi.h

    r1196 r1419  
    182182void print(ostream& os) const;
    183183
     184
     185
     186// Operations diverses  = , +=, ...
     187
     188
     189SphereThetaPhi<T>& Set(const SphereThetaPhi<T>& a);
     190inline  SphereThetaPhi<T>& operator = (const SphereThetaPhi<T>& a)
     191                                                        {return Set(a);}
     192
     193// A += -= *= /= x (ajoute, soustrait, ... x a tous les elements)
     194
     195  //! Fill SphereThetaPhi with all elements equal to \b x
     196virtual SphereThetaPhi<T>& SetT(T a);
     197inline  SphereThetaPhi<T>& operator = (T a) {return SetT(a);}
     198
     199//! Add \b x to all elements
     200virtual SphereThetaPhi<T>& Add(T a);
     201inline  SphereThetaPhi<T>&  operator += (T x)  { return Add(x); }
     202//! Substract \b x to all elements
     203virtual SphereThetaPhi<T>& Sub(T a);
     204inline   SphereThetaPhi<T>&  operator -= (T x)  { return Sub(x); }
     205//! Multiply all elements by \b x
     206virtual SphereThetaPhi<T>& Mul(T a);
     207inline  SphereThetaPhi<T>&  operator *= (T x)  { return Mul(x); }
     208//! Divide all elements by \b x
     209virtual SphereThetaPhi<T>& Div(T a);
     210inline  SphereThetaPhi<T>&  operator /= (T x)  { return Div(x); }
     211
     212// A += -=  (ajoute, soustrait element par element les deux spheres )
     213  //! Operator SphereThetaPhi += SphereThetaPhi
     214  virtual SphereThetaPhi<T>&  AddElt(const SphereThetaPhi<T>& a);
     215  inline  SphereThetaPhi<T>&  operator += (const SphereThetaPhi<T>& a)  { return AddElt(a); }
     216
     217
     218
     219  virtual SphereThetaPhi<T>&  SubElt(const SphereThetaPhi<T>& a);
     220  //! Operator SphereThetaPhi -= SphereThetaPhi
     221  inline  SphereThetaPhi<T>&  operator -= (const SphereThetaPhi<T>& a)  { return SubElt(a); }
     222// Multiplication, division element par element les deux SphereThetaPhi
     223  virtual SphereThetaPhi<T>&  MulElt(const SphereThetaPhi<T>& a);
     224  inline  SphereThetaPhi<T>&  operator *= (const SphereThetaPhi<T>& a)  { return MulElt(a); }
     225
     226
    184227  void CloneOrShare(const SphereThetaPhi<T>& a);
    185 
    186   SphereThetaPhi<T>& Set(const SphereThetaPhi<T>& a);
     228  void Share(const SphereThetaPhi<T>& a);
     229
    187230  SphereThetaPhi<T>& CopyElt(const SphereThetaPhi<T>& a);
    188231
    189   inline  SphereThetaPhi<T>& operator = (const SphereThetaPhi<T>& a)
    190                                                        {return Set(a);}
     232
     233
     234
     235
    191236
    192237 // friend declaration for classes which handle persistence and FITS IO
     
    216261};
    217262
     263////////////////////////////////////////////////////////////////
     264// Surcharge d'operateurs A (+,-,*,/) (T) x
     265/*! \ingroup SphereThetaPhi \fn operator+(const SphereThetaPhi<T>&,T)
     266  \brief Operator SphereThetaPhi = SphereThetaPhi + constant */
     267template <class T> inline SphereThetaPhi<T> operator + (const SphereThetaPhi<T>& a, T b)
     268    {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
     269    result.Add(b); return result;}
     270/*! \ingroup SphereThetaPhi \fn operator+(T,const SphereThetaPhi<T>&)
     271  \brief Operator SphereThetaPhi = constant + SphereThetaPhi */
     272template <class T> inline SphereThetaPhi<T> operator + (T b,const SphereThetaPhi<T>& a)
     273    {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
     274    result.Add(b); return result;}
     275
     276
     277/*! \ingroup SphereThetaPhi\fn operator-(const SphereThetaPhi<T>&,T)
     278  \brief Operator SphereThetaPhi = SphereThetaPhi - constant */
     279template <class T> inline SphereThetaPhi<T> operator - (const SphereThetaPhi<T>& a, T b)
     280    {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
     281    result.Sub(b); return result;}
     282
     283/*! \ingroup  \fn operator-(T,const SphereThetaPhi<T>&)
     284  \brief Operator SphereThetaPhi = constant - SphereThetaPhi */
     285template <class T> inline SphereThetaPhi<T> operator - (T b,const SphereThetaPhi<T>& a)
     286    {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
     287    result.Sub(b,true); return result;}
     288
     289/*! \ingroup SphereThetaPhi \fn operator*(const SphereThetaPhi<T>&,T)
     290  \brief Operator SphereThetaPhi = SphereThetaPhi * constant */
     291template <class T> inline SphereThetaPhi<T> operator * (const SphereThetaPhi<T>& a, T b)
     292    {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
     293    result.Mul(b); return result;}
     294
     295/*! \ingroup SphereThetaPhi \fn operator*(T,const SphereThetaPhi<T>&)
     296  \brief Operator SphereThetaPhi = constant * SphereThetaPhi */
     297template <class T> inline SphereThetaPhi<T> operator * (T b,const SphereThetaPhi<T>& a)
     298    {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
     299    result.Mul(b); return result;}
     300
     301/*! \ingroup SphereThetaPhi \fn operator/(const SphereThetaPhi<T>&,T)
     302  \brief Operator SphereThetaPhi = SphereThetaPhi / constant */
     303template <class T> inline SphereThetaPhi<T> operator / (const SphereThetaPhi<T>& a, T b)
     304    {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
     305    result.Div(b); return result;}
     306
     307/*! \ingroup SphereThetaPhi \fn operator/(T,const SphereThetaPhi<T>&)
     308  \brief Operator SphereThetaPhi = constant / SphereThetaPhi  */
     309template <class T> inline SphereThetaPhi<T> operator / (T b, const SphereThetaPhi<T>& a)
     310    {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
     311    result.Div(b, true); return result;}
     312
     313////////////////////////////////////////////////////////////////
     314// Surcharge d'operateurs C = A (+,-) B
     315
     316/*! \ingroup SphereThetaPhi \fn operator+(const SphereThetaPhi<T>&,const SphereThetaPhi<T>&)
     317  \brief Operator SphereThetaPhi = SphereThetaPhi + SphereThetaPhi */
     318template <class T>
     319inline SphereThetaPhi<T> operator + (const SphereThetaPhi<T>& a,const SphereThetaPhi<T>& b)
     320    { SphereThetaPhi<T> result; result.SetTemp(true);
     321    if (b.IsTemp())  { result.Share(b); result.AddElt(a); }
     322    else { result.CloneOrShare(a); result.AddElt(b); }
     323    return result; }
     324
     325/*! \ingroup SphereThetaPhi \fn operator-(const SphereThetaPhi<T>&,const SphereThetaPhi<T>&)
     326  \brief Operator SphereThetaPhi = SphereThetaPhi - SphereThetaPhi */
     327template <class T>
     328inline SphereThetaPhi<T> operator - (const SphereThetaPhi<T>& a,const SphereThetaPhi<T>& b)
     329    { SphereThetaPhi<T> result; result.SetTemp(true);
     330    if (b.IsTemp())  { result.Share(b); result.SubElt(a, true); }
     331    else { result.CloneOrShare(a); result.SubElt(b); }
     332    return result; }
    218333
    219334
Note: See TracChangeset for help on using the changeset viewer.