00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef PIXEL_PHASE_ARRAY_H
00032 #define PIXEL_PHASE_ARRAY_H
00033
00034 #include <iostream>
00035 #include <pixel_array.h>
00036 #include "zernike.h"
00037
00038 namespace Arroyo {
00039
00040 using std::vector;
00041
00045
00046 template <class T>
00047 class pixel_phase_array :
00048 public pixel_array<T> {
00049
00050 public:
00051
00054 pixel_phase_array(){};
00055
00058 pixel_phase_array(const pixel_phase_array<T> & pixpharr){
00059 operator= (pixpharr);
00060 };
00061
00064 pixel_phase_array(const iofits & iof) : pixel_array<T>(iof) {};
00065
00071 pixel_phase_array(const vector<long> & in_axes,
00072 const T * data = NULL,
00073 const float * wts = NULL) :
00074 pixel_array<T>(in_axes, data, wts){};
00075
00078 ~pixel_phase_array(){};
00079
00082 pixel_phase_array & operator = (const pixel_phase_array<T> & pixpharr){
00083 if(this == &pixpharr)
00084 return(*this);
00085 pixel_array<T>::operator=(pixpharr);
00086 return(*this);
00087 };
00088
00091 void wrap(){
00092 int nelem = this->total_space();
00093 double twopi = 2*M_PI;
00094 for(int i=0; i<nelem; i++){
00095 this->pixeldata[i] = fmod(this->pixeldata[i],twopi);
00096 if(this->pixeldata[i]<-M_PI)
00097 this->pixeldata[i] += twopi;
00098 if(this->pixeldata[i]>=M_PI)
00099 this->pixeldata[i] -= twopi;
00100 }
00101 };
00102
00105 void decimate(int nadd){
00106 if(nadd<0 || nadd>this->axes[0] || nadd>this->axes[1]){
00107 cerr << "pixel_phase_array::decimate - error decimating by a factor of " << nadd << endl;
00108 throw(string("pixel_phase_array::decimate"));
00109 }
00110 if(this->axes.size()!=2){
00111 cerr << "pixel_phase_array::decimate - cannot decimate pixel_array with number of dimensions "
00112 << this->axes.size() << endl;
00113 throw(string("pixel_phase_array::decimate"));
00114 }
00115
00116 if(nadd==0 || nadd==1) return;
00117
00118 vector<long> newaxes(2);
00119 for(int i=0; i<newaxes.size(); i++)
00120 newaxes[i] = this->axes[i]/nadd;
00121
00122 float * olddata = this->pixeldata;
00123 this->pixeldata = new T[newaxes[0]*newaxes[1]];
00124
00125 float sumcos, sumsin;
00126 for(int i=0; i<newaxes[1]; i++){
00127 for(int j=0; j<newaxes[0]; j++){
00128 sumcos = 0;
00129 sumsin = 0;
00130 for(int k=0; k<nadd; k++){
00131 for(int l=0; l<nadd; l++){
00132 sumcos += cos(olddata[(i*nadd+k)*this->axes[0]+j*nadd+l]);
00133 sumsin += sin(olddata[(i*nadd+k)*this->axes[0]+j*nadd+l]);
00134 }
00135 }
00136 this->pixeldata[i*newaxes[0]+j] = atan2(sumsin,sumcos);
00137 }
00138 }
00139
00140 this->axes = newaxes;
00141 delete [] olddata;
00142 };
00143
00146 friend int operator ==(const pixel_phase_array<T> &p1, const pixel_phase_array<T> &p2){
00147 if(p1!=p2) return(0);
00148 for(int i=0; i<p1.axes.size(); i++)
00149 for(int j=0; j<p1.axes[i]; j++)
00150 if(p1.pixeldata[i]!=p2.pixeldata[i]) return(0);
00151
00152 if((p1.pixelwts!=NULL && p2.pixelwts==NULL) ||
00153 (p1.pixelwts==NULL && p2.pixelwts!=NULL)){
00154 cerr << "pixel_phase_array & operator += error - weights not defined for both objects\n";
00155 throw(string("pixel_phase_array & operator +="));
00156 }
00157
00158 if(p1.pixelwts!=NULL)
00159 for(int i=0; i<p1.axes.size(); i++)
00160 for(int j=0; j<p1.axes[i]; j++)
00161 if(p1.pixelwts[i]!=p2.pixelwts[i]) return(0);
00162
00163 return(1);
00164 };
00165 };
00166
00167 template<class T>
00168 pixel_phase_array<T> operator + (const pixel_phase_array<T> &p1, const pixel_phase_array<T> &p2){
00169 if(p1.get_axes()!=p2.get_axes()){
00170 cerr << "pixel_phase_array::operator+= error - "
00171 << "mismatched array sizes:\n";
00172 throw(string("pixel_array::operator/="));
00173 }
00174
00175 pixel_phase_array<T> pixpharr(p1);
00176 pixpharr += p2;
00177 return(pixpharr);
00178 }
00179
00180 template<class T>
00181 pixel_phase_array<T> operator - (const pixel_phase_array<T> &p1, const pixel_phase_array<T> &p2){
00182 if(p1.get_axes()!=p2.get_axes()){
00183 cerr << "pixel_phase_array::operator-= error - "
00184 << "mismatched array sizes:\n";
00185 throw(string("pixel_array::operator/="));
00186 }
00187
00188 pixel_phase_array<T> pixpharr(p1);
00189 pixpharr -= p2;
00190 return(pixpharr);
00191 }
00192
00193 template<class T>
00194 pixel_phase_array<T> operator * (const pixel_phase_array<T> &p1, const pixel_phase_array<T> &p2){
00195 cerr << "operator* for pixel_phase_arrays has been intentionally disabled\n";
00196 throw(string("operator*"));
00197 }
00198
00199 template<class T>
00200 pixel_phase_array<T> operator / (const pixel_phase_array<T> &p1, const pixel_phase_array<T> &p2){
00201 cerr << "operator/ for pixel_phase_arrays has been intentionally disabled\n";
00202 throw(string("operator/"));
00203 }
00204
00205 template<class T>
00206 pixel_phase_array<T> operator + (const pixel_phase_array<T> &p1, double & fac){
00207 pixel_phase_array<T> pixpharr(p1);
00208 pixpharr += fac;
00209 return(pixpharr);
00210 }
00211
00212 template<class T>
00213 pixel_phase_array<T> operator - (const pixel_phase_array<T> &p1, double & fac){
00214 pixel_phase_array<T> pixpharr(p1);
00215 pixpharr -= fac;
00216 return(pixpharr);
00217 }
00218
00219 template<class T>
00220 pixel_phase_array<T> operator * (const pixel_phase_array<T> &p1, double & fac){
00221 pixel_phase_array<T> pixpharr(p1);
00222 pixpharr *= fac;
00223 return(pixpharr);
00224 }
00225
00226 template<class T>
00227 pixel_phase_array<T> operator / (const pixel_phase_array<T> &p1, double & fac){
00228 pixel_phase_array<T> pixpharr(p1);
00229 pixpharr /= fac;
00230 return(pixpharr);
00231 }
00232
00233 template<class T>
00234 int operator != (const pixel_phase_array<T> &p1, const pixel_phase_array<T> &p2){
00235 return(!(p1==p2));
00236 }
00237
00238 }
00239
00240 #endif