1
/*===========================================================================
2
Copyright (C) 1994-2009 European Southern Observatory (ESO)
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; either version 2 of
7
the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public
15
License along with this program; if not, write to the Free
16
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
19
Correspondence concerning ESO-MIDAS should be addressed as follows:
20
Internet e-mail: midas@eso.org
21
Postal address: European Southern Observatory
22
Data Management Division
23
Karl-Schwarzschild-Strasse 2
24
D 85748 Garching bei Muenchen
26
===========================================================================*/
28
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
.AUTHOR K. Banse IPG-ESO Garching
32
.KEYWORDS memory, ImageDisplay
33
.PURPOSE plot intensities of a 1-dim image as y-pixels into image channel
34
.ALGORITHM use IDI_PL to do the job
36
call as DRIMG_C( dsplay, chan, over, iaux, data, npix,
37
icen, cuts, scale, angle )
40
int dsplay : device id
41
int chan : channel to draw image in
42
int over : I/0 for over_plot
43
int iaux[4] : yline, yscale + y-screen offset + intensity
44
float *data : pointer to image data
45
int npix : number of pixels in x-direction
46
int icen[2] : frame,screen pixel of centeral x cood.
47
float cuts[2] : low + high cut in z-dir.
48
int scale[2] : scaling factors for image
49
make image smaller, if > 1
50
make image larger, if < 1
51
float angle : angle with base line
56
#include <midas_def.h> Prototypes for MIDAS interfaces
58
.VERSIONS 1.00 940517 F -> C, converted from RDIMG.FOR RvH
59
.VERSIONS 1.10 941122 fix it, KB
62
------------------------------------------------------------*/
65
/* Define _POSIX_SOURCE to indicate that this is a POSIX program */
67
#define _POSIX_SOURCE 1
69
/* definition of the used functions in this module */
75
#include <midas_def.h>
80
#define PI 3.14159265358979325e0
83
#define DEG2RAD (PI / 180)
89
/*++++++++++++++++++++++++++++++
91
.PURPOSE pack a real array (from an image) into I*4 value
92
for plotting in ImageDisplay
94
int hilim : hi limit for scaling
95
float *data : image data
96
int ndim : dimension of array DATA
97
int iscale : scaling factor
98
float mfact : factor to map into [0,255]
99
float cuts[2]: artificial minimum and maximum of data
101
int *ldata : scaled line with pixels
104
.COMMENTS static function
105
--------------------------------*/
107
static void D1PACK( int hilim, float *data, int ndim, int iscal,
108
double mfact, float *cuts, int *ldata )
110
static void D1PACK( hilim, data, ndim, iscal, mfact, cuts, ldata )
111
int hilim, ndim, iscal, *ldata;
117
register float turbo, *pntr;
120
/* loop + scale data */
122
turbo = 0.5 - ((*cuts) * mfact);
123
pntr = data; /* points to first element of data */
124
data += ndim; /* points after the last element of data */
129
if (*pntr >= cuts[1])
131
else if ( *pntr > *cuts )
132
*ldata++ = (int) (mfact * *pntr + turbo);
139
else /* "zoom" + scale data down */
141
register int kk, value;
147
if (*pntr >= cuts[1])
149
else if (*pntr > *cuts)
150
value = (int) (mfact * *pntr + turbo);
153
for (kk=0; kk<iscal; kk++) *ldata++ = value;
154
} while ( ++pntr < data );
162
/*++++++++++++++++++++++++++++++
164
.PURPOSE rotate coordinate pair IX,IY
165
.ALGORITHM straight forward
168
double ca : cosine of rotation
169
double sa : sine of rotation
170
int ix : x-coordinate to be rotated
171
int iy : y-coordinate to be rotated
174
int *ioutx : rotated x-coordinate
175
int *iouty : rotated y-coordinate
178
.COMMENTS static function
179
------------------------------*/
181
static void ROTA( double ca, double sa, int ix, int iy,
182
int *ioutx, int *iouty )
184
static void ROTA( ca, sa, ix, iy, ioutx, iouty )
185
int ix, iy, *ioutx, *iouty;
190
*ioutx = CGN_NINT(ix * ca - iy * sa);
191
*iouty = CGN_NINT(iy * ca + ix * sa);
200
void DRIMG_C( int dsplay, int chan, int over, int *iaux, float *data,
201
int npix, int *icen, float *cuts, int *scale, float angle )
203
void DRIMG_C( dsplay, chan, over, iaux, data, npix, icen, cuts, scale, angle )
204
int dsplay, chan, over, npix, *iaux, *icen, *scale;
205
float angle, *data, *cuts;
211
int color, nfx, nsx, sfpx, sfpy, sspx, sspy, *xdata, *ydata;
212
double ca, sa, mfact;
214
static int ltype = 1; /* solid line */
217
/* calculate no. of x-pixels (y-stuff is clear...) */
223
SIZER_C(QMSZX,npix,*scale,0,icen,&nsx,&sspx,&nfx,&sfpx); /* no averaging */
224
xdata = (int *) malloc((size_t)(nsx*sizeof(int)));
225
ydata = (int *) malloc((size_t)(nsx*sizeof(int)));
228
/* if overlay flag = 0, clear channel first */
230
if (over != 1) (void) IIMCMY_C(dsplay,&chan,1,0);
235
if ((cuts[1] - *cuts) < 10.e-25) /* range interval too small... */
243
mfact /= (cuts[1] - *cuts);
246
data += (sfpx-1) + ((sfpy-1)*npix); /* init pointer line */
247
D1PACK(iaux[1],data,nfx,*scale,mfact,cuts,ydata);
250
/* plot parallel to the base line */
252
if ((float) fabs((double) angle) <= 10.e-3)
254
for (nn=sspx; nn<sspx+nsx; nn++) *xdata++ = nn;
259
for (nn=sspx; nn<sspx+nsx; nn++) *ydata++ += sspy;
264
else /* plot with an angle */
270
for (nn=0; nn<nsx; nn++)
272
ROTA(ca,sa,nn,*ydata,xdata,ydata);
282
(void)IIGPLY_C(dsplay,chan,xdata,ydata,nsx,color,ltype);
284
(void) free((char *) xdata);
285
(void) free((char *) ydata);