MUSE Pipeline Reference Manual  1.0.2
muse_pixgrid.h
1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set sw=2 sts=2 et cin: */
3 /*
4  * This file is part of the MUSE Instrument Pipeline
5  * Copyright (C) 2005-2014 European Southern Observatory
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef MUSE_PIXGRID_H
23 #define MUSE_PIXGRID_H
24 
25 /*----------------------------------------------------------------------------*
26  * Includes *
27  *----------------------------------------------------------------------------*/
28 #include "muse_pixtable.h"
29 
30 /*----------------------------------------------------------------------------*
31  * Defines *
32  *----------------------------------------------------------------------------*/
33 
34 /*----------------------------------------------------------------------------*
35  * Special variable types *
36  *----------------------------------------------------------------------------*/
37 
41 /*----------------------------------------------------------------------------*/
45 /*----------------------------------------------------------------------------*/
46 typedef struct {
47  int npix; /* number of pixels in this grid point */
48  cpl_size *pix; /* the row number(s) in the pixel table */
50 
51 /*----------------------------------------------------------------------------*/
55 /*----------------------------------------------------------------------------*/
56 typedef struct {
57  cpl_size *pix; /* The pixel grid array, elements can be *
58  * 0: empty *
59  * positive: row_number in the pixel table *
60  * negative: -(i_ext+1) in the extension array */
61  cpl_size size_x; /* horizontal spatial size */
62  cpl_size size_y; /* vertical spatial size */
63  cpl_size size_z; /* size in dispersion direction */
64  cpl_size n_ext; /* number of filled pixels in the extension map */
65  cpl_size n_alloc; /* number of allocated pixels in the extension map */
66  muse_pixels_ext *ext; /* the extension map */
67 } muse_pixgrid;
68 
69 /*----------------------------------------------------------------------------*
70  * Inline functions *
71  *----------------------------------------------------------------------------*/
72 
73 /*---------------------------------------------------------------------------*/
87 /*---------------------------------------------------------------------------*/
88 static inline cpl_size
89 muse_pixgrid_get_index(muse_pixgrid *aPixels, cpl_size aX, cpl_size aY,
90  cpl_size aZ, cpl_boolean aAllowOutside)
91 {
92  if (!aAllowOutside &&
93  (aX < 0 || aX >= aPixels->size_x || aY < 0 || aY >= aPixels->size_y ||
94  aZ < 0 || aZ >= aPixels->size_z)) {
95  return -1;
96  }
97  if (aX < 0) {
98  aX = 0;
99  }
100  if (aX >= aPixels->size_x) {
101  aX = aPixels->size_x - 1;
102  }
103  if (aY < 0) {
104  aY = 0;
105  }
106  if (aY >= aPixels->size_y) {
107  aY = aPixels->size_y - 1;
108  }
109  if (aZ < 0) {
110  aZ = 0;
111  }
112  if (aZ >= aPixels->size_z) {
113  aZ = aPixels->size_z - 1;
114  }
115  return aX + aPixels->size_x * (aY + aPixels->size_y * aZ);
116 } /* muse_pixgrid_get_index() */
117 
118 /*---------------------------------------------------------------------------*/
127 /*---------------------------------------------------------------------------*/
128 static inline cpl_size
129 muse_pixgrid_get_count(muse_pixgrid *aPixels, cpl_size aIndex)
130 {
131  if (aIndex < 0) {
132  return 0;
133  }
134  cpl_size p = aPixels->pix[aIndex];
135  return (p == 0) ? 0
136  : (p > 0) ? 1 : aPixels->ext[-p-1].npix;
137 } /* muse_pixgrid_get_count() */
138 
139 /*---------------------------------------------------------------------------*/
148 /*---------------------------------------------------------------------------*/
149 static inline const cpl_size *
150 muse_pixgrid_get_rows(muse_pixgrid *aPixels, cpl_size aIndex)
151 {
152  if (aIndex < 0) {
153  return 0;
154  }
155  cpl_size p = aPixels->pix[aIndex];
156  return (p == 0) ? NULL
157  : (p > 0) ? aPixels->pix + aIndex : aPixels->ext[-p-1].pix;
158 } /* muse_pixgrid_get_rows() */
159 
162 /*----------------------------------------------------------------------------*
163  * Function prototypes *
164  *----------------------------------------------------------------------------*/
165 muse_pixgrid *muse_pixgrid_create(muse_pixtable *, cpl_propertylist *, cpl_size, cpl_size, cpl_size);
166 muse_pixgrid *muse_pixgrid_2d_create(cpl_table *, double, double, double, double, float *);
168 
169 #endif /* MUSE_PIXGRID_H */
muse_pixgrid * muse_pixgrid_2d_create(cpl_table *, double, double, double, double, float *)
Convert selected rows of a pixel table into 2D pixgrid, linking the grid points to entries (=rows) in...
Definition: muse_pixgrid.c:330
muse_pixgrid * muse_pixgrid_create(muse_pixtable *, cpl_propertylist *, cpl_size, cpl_size, cpl_size)
Convert selected rows of a pixel table into pixel grid, linking the grid points to entries (=rows) in...
Definition: muse_pixgrid.c:168
The pixel extension map.
Definition: muse_pixgrid.h:46
The pixel grid.
Definition: muse_pixgrid.h:56
Structure definition of MUSE pixel table.
static const cpl_size * muse_pixgrid_get_rows(muse_pixgrid *aPixels, cpl_size aIndex)
Return a pointer to the rows stored in one pixel.
Definition: muse_pixgrid.h:150
void muse_pixgrid_delete(muse_pixgrid *)
Delete a pixgrid and remove its memory.
Definition: muse_pixgrid.c:398
static cpl_size muse_pixgrid_get_index(muse_pixgrid *aPixels, cpl_size aX, cpl_size aY, cpl_size aZ, cpl_boolean aAllowOutside)
Get the grid index determined from all three coordinates.
Definition: muse_pixgrid.h:89
static cpl_size muse_pixgrid_get_count(muse_pixgrid *aPixels, cpl_size aIndex)
Return the number of rows stored in one pixel.
Definition: muse_pixgrid.h:129