Changeset 1419 in Sophya for trunk/SophyaLib/SkyMap
- Timestamp:
- Feb 23, 2001, 12:26:48 PM (25 years ago)
- Location:
- trunk/SophyaLib/SkyMap
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/SkyMap/localmap.cc
r1308 r1419 101 101 recopierVariablesSimples(a); 102 102 pixels_.CloneOrShare(a.pixels_); 103 if (mInfo_) {delete mInfo_; mInfo_ = NULL;} 104 if (a.mInfo_) mInfo_ = new DVList(*(a.mInfo_)); 105 } 106 template<class T> 107 void 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_)); 103 113 } 104 114 … … 556 566 } 557 567 568 // ...... Operations de calcul ...... 569 570 571 //! Fill a LocalMap with a constant value \b a 572 template <class T> 573 LocalMap<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 */ 582 template <class T> 583 LocalMap<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 */ 592 template <class T> 593 LocalMap<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 */ 602 template <class T> 603 LocalMap<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 */ 612 template <class T> 613 LocalMap<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 624 template <class T> 625 LocalMap<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 636 template <class T> 637 LocalMap<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) 648 template <class T> 649 LocalMap<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 558 662 559 663 //++ -
trunk/SophyaLib/SkyMap/localmap.h
r1217 r1419 104 104 void print(ostream& os) const; 105 105 106 // Operations diverses = , +=, ... 107 108 109 virtual LocalMap<T>& Set(const LocalMap<T>& a); 106 110 inline LocalMap<T>& operator = (const LocalMap<T>& a) {return Set(a);} 107 111 112 // A += -= *= /= x (ajoute, soustrait, ... x a tous les elements) 113 114 //! Fill LocalMap with all elements equal to \b x 115 virtual LocalMap<T>& SetT(T a); 116 inline LocalMap<T>& operator = (T a) {return SetT(a);} 117 118 //! Add \b x to all elements 119 virtual LocalMap<T>& Add(T a); 120 inline LocalMap<T>& operator += (T x) { return Add(x); } 121 //! Substract \b x to all elements 122 virtual LocalMap<T>& Sub(T a); 123 inline LocalMap<T>& operator -= (T x) { return Sub(x); } 124 //! Multiply all elements by \b x 125 virtual LocalMap<T>& Mul(T a); 126 inline LocalMap<T>& operator *= (T x) { return Mul(x); } 127 //! Divide all elements by \b x 128 virtual LocalMap<T>& Div(T a); 129 inline 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 146 void CloneOrShare(const LocalMap<T>& a); 147 void Share(const LocalMap<T>& a); 148 LocalMap<T>& CopyElt(const LocalMap<T>& a); 108 149 109 150 … … 120 161 121 162 void 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);125 163 126 164 … … 146 184 }; 147 185 186 //////////////////////////////////////////////////////////////// 187 // Surcharge d'operateurs A (+,-,*,/) (T) x 188 /*! \ingroup LocalMap \fn operator+(const LocalMap<T>&,T) 189 \brief Operator LocalMap = LocalMap + constant */ 190 template <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 */ 195 template <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 */ 202 template <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 */ 208 template <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 */ 214 template <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 */ 220 template <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 */ 226 template <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 */ 232 template <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 */ 241 template <class T> 242 inline 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 */ 250 template <class T> 251 inline 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; } 148 256 149 257 -
trunk/SophyaLib/SkyMap/pixelmap.h
r1375 r1419 96 96 /*! Setting pixel values to a constant */ 97 97 virtual T SetPixels(T v); 98 inline T operator = (T v) { return(SetPixels(v)); } 98 PixelMap<T>& SetT(T v); 99 //inline T operator = (T v) { return(SetPixels(v)); } 100 inline PixelMap<T>& operator = (T v) { return(SetT(v)); } 99 101 100 102 … … 141 143 return(v); 142 144 } 145 template <class T> 146 PixelMap<T>& PixelMap<T>::SetT(T v) 147 { 148 int k; 149 for(k=0; k<NbPixels(); k++) PixVal(k) = v; 150 return(*this); 151 } 143 152 144 153 -
trunk/SophyaLib/SkyMap/spherehealpix.cc
r1304 r1419 127 127 } 128 128 129 //! Clone if \b a is not temporary, share if temporary 130 /*! \sa NDataBlock::CloneOrShare(const NDataBlock<T>&) */ 129 131 template<class T> 130 132 void SphereHEALPix<T>::CloneOrShare(const SphereHEALPix<T>& a) … … 136 138 sliceBeginIndex_.CloneOrShare(a.sliceBeginIndex_); 137 139 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 145 template<class T> 146 void 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_)); 141 156 } 142 157 … … 149 164 150 165 if (a.NbPixels() < 1) 151 throw RangeCheckError("SphereHEALPix<T>::Set(a ) - Arraya not allocated ! ");166 throw RangeCheckError("SphereHEALPix<T>::Set(a ) - SphereHEALPix a not allocated ! "); 152 167 if (NbPixels() < 1) CloneOrShare(a); 153 168 else CopyElt(a); … … 165 180 { 166 181 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 ! "); 168 183 if (NbPixels() != a.NbPixels()) 169 184 throw(SzMismatchError("SphereHEALPix<T>::CopyElt(const SphereHEALPix<T>&) SizeMismatch")) ; … … 177 192 return(*this); 178 193 } 194 195 196 179 197 //++ 180 198 // Titre Destructor … … 542 560 return ring2nest(nSide_,k); 543 561 } 562 563 // ...... Operations de calcul ...... 564 565 //! Fill a SphereHEALPix with a constant value \b a 566 template <class T> 567 SphereHEALPix<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 */ 576 template <class T> 577 SphereHEALPix<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 */ 586 template <class T> 587 SphereHEALPix<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 */ 596 template <class T> 597 SphereHEALPix<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 */ 606 template <class T> 607 SphereHEALPix<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 618 template <class T> 619 SphereHEALPix<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 630 template <class T> 631 SphereHEALPix<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) 642 template <class T> 643 SphereHEALPix<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 544 654 545 655 -
trunk/SophyaLib/SkyMap/spherehealpix.h
r1217 r1419 127 127 128 128 129 130 131 132 133 134 // Operations diverses = , +=, ... 135 136 137 SphereHEALPix<T>& Set(const SphereHEALPix<T>& a); 129 138 inline SphereHEALPix<T>& operator = (const SphereHEALPix<T>& a) 130 139 {return Set(a);} 131 140 141 // A += -= *= /= x (ajoute, soustrait, ... x a tous les elements) 142 143 //! Fill SphereHEALPix with all elements equal to \b x 144 virtual SphereHEALPix<T>& SetT(T a); 145 inline SphereHEALPix<T>& operator = (T a) {return SetT(a);} 146 147 //! Add \b x to all elements 148 virtual SphereHEALPix<T>& Add(T a); 149 inline SphereHEALPix<T>& operator += (T x) { return Add(x); } 150 //! Substract \b x to all elements 151 virtual SphereHEALPix<T>& Sub(T a); 152 inline SphereHEALPix<T>& operator -= (T x) { return Sub(x); } 153 //! Multiply all elements by \b x 154 virtual SphereHEALPix<T>& Mul(T a); 155 inline SphereHEALPix<T>& operator *= (T x) { return Mul(x); } 156 //! Divide all elements by \b x 157 virtual SphereHEALPix<T>& Div(T a); 158 inline 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 132 175 void CloneOrShare(const SphereHEALPix<T>& a); 133 SphereHEALPix<T>& Set(const SphereHEALPix<T>& a);176 void Share(const SphereHEALPix<T>& a); 134 177 SphereHEALPix<T>& CopyElt(const SphereHEALPix<T>& a); 135 178 … … 164 207 }; 165 208 166 209 //////////////////////////////////////////////////////////////// 210 // Surcharge d'operateurs A (+,-,*,/) (T) x 211 /*! \ingroup SphereHEALPix \fn operator+(const SphereHEALPix<T>&,T) 212 \brief Operator SphereHEALPix = SphereHEALPix + constant */ 213 template <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 */ 218 template <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 */ 225 template <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 */ 231 template <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 */ 237 template <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 */ 243 template <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 */ 249 template <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 */ 255 template <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 */ 264 template <class T> 265 inline 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 */ 273 template <class T> 274 inline 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; } 167 279 168 280 } // Fin du namespace -
trunk/SophyaLib/SkyMap/spherethetaphi.cc
r980 r1419 55 55 // m is the number of slices in theta on an hemisphere (the polar cap 56 56 // forms the first slice). 57 // pet is a dummy parameter at the moment.58 57 //-- 59 58 { … … 129 128 Theta_.CloneOrShare(a.Theta_); 130 129 pixels_.CloneOrShare(a.pixels_); 130 if (mInfo_) {delete mInfo_; mInfo_ = NULL;} 131 if (a.mInfo_) mInfo_ = new DVList(*(a.mInfo_)); 132 } 133 template<class T> 134 void 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_)); 131 146 } 132 147 … … 710 725 os << endl; 711 726 } 727 728 // ...... Operations de calcul ...... 729 730 731 //! Fill a SphereThetaPhi with a constant value \b a 732 template <class T> 733 SphereThetaPhi<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 */ 742 template <class T> 743 SphereThetaPhi<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 */ 752 template <class T> 753 SphereThetaPhi<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 */ 762 template <class T> 763 SphereThetaPhi<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 */ 772 template <class T> 773 SphereThetaPhi<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 784 template <class T> 785 SphereThetaPhi<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 796 template <class T> 797 SphereThetaPhi<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) 808 template <class T> 809 SphereThetaPhi<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 712 819 713 820 -
trunk/SophyaLib/SkyMap/spherethetaphi.h
r1196 r1419 182 182 void print(ostream& os) const; 183 183 184 185 186 // Operations diverses = , +=, ... 187 188 189 SphereThetaPhi<T>& Set(const SphereThetaPhi<T>& a); 190 inline 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 196 virtual SphereThetaPhi<T>& SetT(T a); 197 inline SphereThetaPhi<T>& operator = (T a) {return SetT(a);} 198 199 //! Add \b x to all elements 200 virtual SphereThetaPhi<T>& Add(T a); 201 inline SphereThetaPhi<T>& operator += (T x) { return Add(x); } 202 //! Substract \b x to all elements 203 virtual SphereThetaPhi<T>& Sub(T a); 204 inline SphereThetaPhi<T>& operator -= (T x) { return Sub(x); } 205 //! Multiply all elements by \b x 206 virtual SphereThetaPhi<T>& Mul(T a); 207 inline SphereThetaPhi<T>& operator *= (T x) { return Mul(x); } 208 //! Divide all elements by \b x 209 virtual SphereThetaPhi<T>& Div(T a); 210 inline 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 184 227 void CloneOrShare(const SphereThetaPhi<T>& a); 185 186 SphereThetaPhi<T>& Set(const SphereThetaPhi<T>& a); 228 void Share(const SphereThetaPhi<T>& a); 229 187 230 SphereThetaPhi<T>& CopyElt(const SphereThetaPhi<T>& a); 188 231 189 inline SphereThetaPhi<T>& operator = (const SphereThetaPhi<T>& a) 190 {return Set(a);} 232 233 234 235 191 236 192 237 // friend declaration for classes which handle persistence and FITS IO … … 216 261 }; 217 262 263 //////////////////////////////////////////////////////////////// 264 // Surcharge d'operateurs A (+,-,*,/) (T) x 265 /*! \ingroup SphereThetaPhi \fn operator+(const SphereThetaPhi<T>&,T) 266 \brief Operator SphereThetaPhi = SphereThetaPhi + constant */ 267 template <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 */ 272 template <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 */ 279 template <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 */ 285 template <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 */ 291 template <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 */ 297 template <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 */ 303 template <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 */ 309 template <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 */ 318 template <class T> 319 inline 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 */ 327 template <class T> 328 inline 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; } 218 333 219 334
Note:
See TracChangeset
for help on using the changeset viewer.