~ubuntu-branches/ubuntu/wily/eso-midas/wily-proposed

« back to all changes in this revision

Viewing changes to prim/display/libsrc/drimg.c

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-okiwi1assxkkiz39
Tags: upstream-13.09pl1.2+dfsg
ImportĀ upstreamĀ versionĀ 13.09pl1.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*===========================================================================
 
2
  Copyright (C) 1994-2009 European Southern Observatory (ESO)
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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, 
 
17
  MA 02139, USA.
 
18
 
 
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 
 
25
                        GERMANY
 
26
===========================================================================*/
 
27
 
 
28
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
29
.IDENTIFIER  DRIMG_C
 
30
.LANGUAGE    C
 
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
 
35
.INPUT/OUTPUT:
 
36
    call as  DRIMG_C( dsplay, chan, over, iaux, data, npix, 
 
37
                                    icen, cuts, scale, angle )
 
38
 
 
39
  input:
 
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
 
52
 
 
53
.RETURNS     nothing
 
54
.COMMENTS    none
 
55
.ENVIRONment MIDAS
 
56
             #include <midas_def.h>   Prototypes for MIDAS interfaces
 
57
 
 
58
.VERSIONS    1.00       940517  F -> C, converted from RDIMG.FOR   RvH
 
59
.VERSIONS    1.10       941122  fix it, KB
 
60
 
 
61
 090706         last modif
 
62
------------------------------------------------------------*/
 
63
 
 
64
 
 
65
/* Define _POSIX_SOURCE to indicate that this is a POSIX program */
 
66
 
 
67
#define  _POSIX_SOURCE 1
 
68
 
 
69
/* definition of the used functions in this module */
 
70
 
 
71
#include <math.h>
 
72
#include <stdio.h>
 
73
#include <stdlib.h>
 
74
 
 
75
#include <midas_def.h>
 
76
#include <idinumd.h>
 
77
#include <proto_II.h>
 
78
 
 
79
#ifndef  PI
 
80
#define  PI             3.14159265358979325e0
 
81
#endif
 
82
 
 
83
#define DEG2RAD         (PI / 180)
 
84
 
 
85
/*
 
86
 
 
87
*/
 
88
 
 
89
/*++++++++++++++++++++++++++++++
 
90
.IDENTIFIER  D1PACK
 
91
.PURPOSE     pack a real array (from an image) into I*4 value
 
92
             for plotting in ImageDisplay
 
93
  input:
 
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
 
100
  output:
 
101
         int   *ldata :         scaled line with pixels
 
102
         
 
103
.RETURNS     nothing
 
104
.COMMENTS    static function
 
105
--------------------------------*/
 
106
#ifdef __STDC__
 
107
      static void D1PACK( int hilim, float *data, int ndim, int iscal, 
 
108
                                     double mfact, float *cuts, int *ldata )
 
109
#else
 
110
      static void D1PACK( hilim, data, ndim, iscal, mfact, cuts, ldata )
 
111
      int    hilim, ndim, iscal, *ldata;
 
112
      float  *data, *cuts;
 
113
      double mfact;
 
114
#endif
 
115
 
 
116
{
 
117
register float turbo, *pntr;
 
118
 
 
119
 
 
120
/*      loop + scale data */
 
121
 
 
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 */
 
125
if ( iscal >= 1 )
 
126
   {
 
127
   while (pntr < data) 
 
128
      {
 
129
      if (*pntr >= cuts[1])     
 
130
         *ldata++ = hilim;
 
131
      else if ( *pntr > *cuts )     
 
132
         *ldata++ = (int) (mfact * *pntr + turbo);
 
133
      else
 
134
         *ldata++ = 0;
 
135
      pntr += iscal;
 
136
      }
 
137
   }
 
138
 
 
139
else                                             /* "zoom" + scale data down */
 
140
   {
 
141
   register int kk, value;
 
142
 
 
143
   iscal *= -1;
 
144
   iscal -= 1;
 
145
 
 
146
   do {
 
147
      if (*pntr >= cuts[1])     
 
148
         value = hilim;
 
149
      else if (*pntr > *cuts)     
 
150
         value = (int) (mfact * *pntr + turbo);
 
151
      else
 
152
         value = 0;
 
153
      for (kk=0; kk<iscal; kk++) *ldata++ = value;
 
154
      } while ( ++pntr < data );
 
155
   }
 
156
}
 
157
 
 
158
/*
 
159
 
 
160
*/
 
161
 
 
162
/*++++++++++++++++++++++++++++++
 
163
.IDENTIFIER  ROTA
 
164
.PURPOSE     rotate coordinate pair IX,IY
 
165
.ALGORITHM   straight forward
 
166
.INPUT/OUTPUT
 
167
  input:
 
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
 
172
 
 
173
  output:
 
174
         int    *ioutx :        rotated x-coordinate
 
175
         int    *iouty :        rotated y-coordinate
 
176
         
 
177
.RETURNS     nothing
 
178
.COMMENTS    static function
 
179
------------------------------*/
 
180
#ifdef __STDC__
 
181
      static void ROTA( double ca, double sa, int ix, int iy, 
 
182
                                              int *ioutx, int *iouty )
 
183
#else
 
184
      static void ROTA( ca, sa, ix, iy, ioutx, iouty )
 
185
      int    ix, iy, *ioutx, *iouty;
 
186
      double ca, sa;
 
187
#endif
 
188
 
 
189
{
 
190
*ioutx = CGN_NINT(ix * ca - iy * sa);
 
191
*iouty = CGN_NINT(iy * ca + ix * sa);
 
192
}
 
193
 
 
194
/*
 
195
 
 
196
*/
 
197
 
 
198
 
 
199
#ifdef __STDC__
 
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 )
 
202
#else
 
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; 
 
206
#endif
 
207
 
 
208
{
 
209
register int nn;
 
210
 
 
211
int    color, nfx, nsx, sfpx, sfpy, sspx, sspy, *xdata, *ydata;
 
212
double ca, sa, mfact;
 
213
      
 
214
static int ltype = 1;                                          /* solid line */
 
215
 
 
216
 
 
217
/*      calculate no. of x-pixels  (y-stuff is clear...) */
 
218
 
 
219
sfpy = iaux[0];
 
220
sspy = iaux[2];
 
221
color = iaux[3];
 
222
 
 
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)));
 
226
 
 
227
 
 
228
/* if overlay flag = 0, clear channel first */
 
229
 
 
230
if (over != 1) (void) IIMCMY_C(dsplay,&chan,1,0);
 
231
 
 
232
 
 
233
/* scale image */
 
234
 
 
235
if ((cuts[1] - *cuts) < 10.e-25)            /* range interval too small... */
 
236
   { 
 
237
   mfact = 1.0;
 
238
   cuts[1] = 0.;
 
239
   }
 
240
else
 
241
   {
 
242
   mfact = iaux[1];
 
243
   mfact /= (cuts[1] - *cuts);
 
244
   }
 
245
 
 
246
data += (sfpx-1) + ((sfpy-1)*npix);                     /* init pointer line */
 
247
D1PACK(iaux[1],data,nfx,*scale,mfact,cuts,ydata);
 
248
 
 
249
 
 
250
/* plot parallel to the base line */
 
251
 
 
252
if ((float) fabs((double) angle) <= 10.e-3)
 
253
   {
 
254
   for (nn=sspx; nn<sspx+nsx; nn++) *xdata++ = nn;
 
255
 
 
256
   xdata -= nsx;
 
257
   if ( sspy != 0 ) 
 
258
      {
 
259
      for (nn=sspx; nn<sspx+nsx; nn++) *ydata++ += sspy;
 
260
      ydata -= nsx;
 
261
      }
 
262
   }
 
263
 
 
264
else                                                  /* plot with an angle */
 
265
   {
 
266
   angle *= DEG2RAD;
 
267
   ca = cos(angle);
 
268
   sa = sin(angle);
 
269
 
 
270
   for (nn=0; nn<nsx; nn++)
 
271
      {
 
272
      ROTA(ca,sa,nn,*ydata,xdata,ydata);
 
273
      *xdata++ += sspx;
 
274
      *ydata++ += sspy;
 
275
      }
 
276
   xdata -= nsx;
 
277
   ydata -= nsx;
 
278
   }
 
279
 
 
280
/* now plot */
 
281
 
 
282
(void)IIGPLY_C(dsplay,chan,xdata,ydata,nsx,color,ltype);
 
283
 
 
284
(void) free((char *) xdata);
 
285
(void) free((char *) ydata);
 
286
}
 
287