42 #include "levels_facilities.h" 58 double fact = 1./(maxv-minv);
63 img[i][j] = float((img[i][j]-minv)*fact);
64 int idx = int(img[i][j]*nbins);
65 idx=max(0,min(idx,nbins-1));
70 newpos.
alloc(nbins+1);
72 for (
int m=0; m<nbins; ++m)
74 newpos[m] = double(accu)/pixels;
83 int idx = int(img[i][j]*nbins);
84 idx=max(0,min(idx,nbins-1));
85 double frac = nbins*img[i][j] - idx;
86 img[i][j] = float((1-frac)*newpos[idx] + frac*newpos[idx+1]);
87 img[i][j] = float(minv+(maxv-minv)*img[i][j]);
92 int xsize,
arr2<float> &img,
float &minv,
float &maxv,
bool smooth)
95 img.
alloc(xsize,ysize);
97 double xc=(xsize-1)/2., yc=(ysize-1)/2.;
107 double u = 2*(i-xc)/(xc/1.02);
108 double v = (j-yc)/(yc/1.02);
109 bool mask = ((u*u/4 + v*v) <= 1);
112 pointing ptg (halfpi-(asin(2/pi*(asin(v) + v*sqrt((1-v)*(1+v))))),
113 -halfpi*u/max(sqrt((1-v)*(1+v)),1e-6));
118 img[i][j] = map[map.
ang2pix(pnt)];
121 if (img[i][j]<minv) minv=img[i][j];
122 if (img[i][j]>maxv) maxv=img[i][j];
129 int xsize,
double delta,
arr2<float> &img,
float &minv,
float &maxv,
135 double start=-(xsize/2.)*delta;
136 img.
alloc(xsize,xsize);
142 vec3 pnt (1,-(start+i*delta), start+j*delta);
147 img[i][j] = map[map.
ang2pix(pnt)];
150 if (img[i][j]<minv) minv=img[i][j];
151 if (img[i][j]>maxv) maxv=img[i][j];
157 int ymin,
int ymax,
bool flippal,
const arr<double> &newpos)
159 int nbins = newpos.
size()-1;
160 for (
int i=xmin; i<=xmax; ++i)
162 double val = (double(i)-xmin)/(xmax-xmin);
165 int idx = int(val*nbins);
166 idx=max(0,min(idx,nbins-1));
167 double frac = nbins*val - idx;
168 val = (1-frac)*newpos[idx] + frac*newpos[idx+1];
170 if (flippal) val=1-val;
172 for (
int j=ymin; j<=ymax; ++j)
177 string conv (
double val)
180 if (abs(val)>100 || abs(val)<0.01)
182 os << setw(10) << setprecision(3) << scientific << val;
185 os << setw(10) << setprecision(6) << fixed << val;
186 return trim(os.str());
191 int map2tga_module (
int argc,
const char **argv)
195 " map2tga <init object>\n\n" 197 " map2tga <input file> <output file> [-sig <int>] [-pal <int>]\n" 198 " [-xsz <int>] [-bar] [-log] [-asinh] [-lon <float>] [-lat <float>]\n" 199 " [-mul <float>] [-add <float>] [-min <float>] [-max <float>]\n" 200 " [-res <float>] [-title <string>] [-flippal] [-gnomonic]\n" 201 " [-interpol] [-equalize] [-viewer <viewer>]\n\n");
203 safe_ptr<paramfile> params;
206 vector<string> leading;
207 map<string,string> dict;
208 leading.push_back(
"infile");
209 leading.push_back(
"outfile");
210 parse_cmdline_classic (argc,argv,leading,dict);
211 if (dict.find(
"gnomonic")!=dict.end())
214 dict.erase(
"gnomonic");
221 string infile = params->find<
string>(
"infile");
222 string outfile = params->find<
string>(
"outfile");
223 int colnum = params->find<
int>(
"sig",1);
224 int palnr = params->find<
int>(
"pal",4);
225 bool flippal = params->find<
bool>(
"flippal",
false);
226 int xres = params->find<
int>(
"xsz",1024);
227 bool bar = params->find<
bool>(
"bar",
false);
228 bool logflag = params->find<
bool>(
"log",
false);
229 bool eqflag = params->find<
bool>(
"equalize",
false);
230 bool asinhflag = params->find<
bool>(
"asinh",
false);
231 double lon0 = degr2rad*params->find<
double>(
"lon",0);
232 double lat0 = degr2rad*params->find<
double>(
"lat",0);
233 double factor = params->find<
float>(
"mul",1);
234 double offset = params->find<
float>(
"add",0);
235 float usermin = params->find<
float>(
"min", -1e30);
236 bool min_supplied = (usermin>-1e29);
237 float usermax = params->find<
float>(
"max", 1e30);
238 bool max_supplied = (usermax<1e29);
239 double res = arcmin2rad*params->find<
double>(
"res",1);
240 string title = params->find<
string>(
"title",
"");
241 string viewer = params->find<
string>(
"viewer",
"");
242 bool mollpro = (params->find<
string>(
"pro",
"")!=
"gno");
243 bool interpol = params->find<
bool>(
"interpol",
false);
247 for (
int m=0; m<map.
Npix(); ++m)
251 map[m] = float((map[m]+offset)*factor);
254 : float(log(
double(map[m]))/ln10);
256 map[m] = (map[m]>=0) ?
257 float( log(
double( map[m]+sqrt(map[m]*map[m]+1)))) :
258 float(-log(
double(-map[m]+sqrt(map[m]*map[m]+1))));
259 if (min_supplied)
if (map[m] < usermin) map[m] = usermin;
260 if (max_supplied)
if (map[m] > usermax) map[m] = usermax;
266 mollpro ? pro_mollw (map,lon0,lat0,xres,imgarr,minv,maxv,interpol) :
267 pro_gno (map,lon0,lat0,xres,res,imgarr,minv,maxv,interpol);
270 if (eqflag) histo_eq(imgarr,minv,maxv,newpos);
272 if (min_supplied) minv = usermin;
273 if (max_supplied) maxv = usermax;
274 if (maxv==minv) maxv=minv+1e-10f;
276 int xsz=imgarr.
size1();
277 int ysz=imgarr.
size2();
279 int scale = max(1,xsz/800);
280 if (bar) ysz+=60*scale;
281 if (title !=
"") { ysz+=50*scale; yofs+=50*scale; }
283 img.
fill(Colour(1,1,1));
292 if (imgarr[i][j]>-1e32)
294 Colour c(0.5,0.5,0.5);
297 int col = int((imgarr[i][j]-minv)/(maxv-minv)*256);
298 col = min(255,max(col,0));
299 float colfrac = (imgarr[i][j]-minv)/(maxv-minv);
300 if (flippal) colfrac = 1-colfrac;
309 colorbar (img,pal,xsz/10,(xsz*9)/10,ysz-40*scale,ysz-20*scale,flippal,
320 int retcode = system((viewer+
" "+outfile).c_str());
322 cout <<
"Warning: viewer return code was " << retcode << endl;
I ang2pix(const pointing &ang) const
void put_pixel(tsize i, tsize j, const Colour &col)
void fill(const Colour &col)
void annotate_centered(int xpos, int ypos, const Colour &col, const std::string &text, int scale=1)
void read_Healpix_map_from_fits(fitshandle &inp, Healpix_Map< T > &map, int colnum)
void write_TGA(const std::string &file) const
T interpolated_value(const pointing &ptg) const
void module_startup(const std::string &name, bool argc_valid, const std::string &usage, bool verbose=true)
void set_font(const MP_Font &fnt)
std::string trim(const std::string &orig)
Colour Get_Colour(float f) const
const double Healpix_undef
Healpix value representing "undefined".
void Make_CPAC_Euler_Matrix(double alpha, double beta, double gamma)
void alloc(tsize sz1, tsize sz2)
void setPredefined(int num)
vec3 Transform(const vec3 &vec) const