00001 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 00002 /* vim:set sw=2 sts=2 et cin: */ 00003 /* 00004 * This file is part of the MUSE Instrument Pipeline 00005 * Copyright (C) 2005-2014 European Southern Observatory 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #ifndef MUSE_PIXGRID_H 00023 #define MUSE_PIXGRID_H 00024 00025 /*----------------------------------------------------------------------------* 00026 * Includes * 00027 *----------------------------------------------------------------------------*/ 00028 #include "muse_pixtable.h" 00029 00030 /*----------------------------------------------------------------------------* 00031 * Defines * 00032 *----------------------------------------------------------------------------*/ 00033 00034 /*----------------------------------------------------------------------------* 00035 * Special variable types * 00036 *----------------------------------------------------------------------------*/ 00037 00041 /*----------------------------------------------------------------------------*/ 00045 /*----------------------------------------------------------------------------*/ 00046 typedef struct { 00047 int npix; /* number of pixels in this grid point */ 00048 cpl_size *pix; /* the row number(s) in the pixel table */ 00049 } muse_pixels_ext; 00050 00051 /*----------------------------------------------------------------------------*/ 00055 /*----------------------------------------------------------------------------*/ 00056 typedef struct { 00057 cpl_size *pix; /* The pixel grid array, elements can be * 00058 * 0: empty * 00059 * positive: row_number in the pixel table * 00060 * negative: -(i_ext+1) in the extension array */ 00061 cpl_size size_x; /* horizontal spatial size */ 00062 cpl_size size_y; /* vertical spatial size */ 00063 cpl_size size_z; /* size in dispersion direction */ 00064 cpl_size n_ext; /* number of filled pixels in the extension map */ 00065 cpl_size n_alloc; /* number of allocated pixels in the extension map */ 00066 muse_pixels_ext *ext; /* the extension map */ 00067 } muse_pixgrid; 00068 00069 /*----------------------------------------------------------------------------* 00070 * Inline functions * 00071 *----------------------------------------------------------------------------*/ 00072 00073 /*---------------------------------------------------------------------------*/ 00087 /*---------------------------------------------------------------------------*/ 00088 static inline cpl_size 00089 muse_pixgrid_get_index(muse_pixgrid *aPixels, cpl_size aX, cpl_size aY, 00090 cpl_size aZ, cpl_boolean aAllowOutside) 00091 { 00092 if (!aAllowOutside && 00093 (aX < 0 || aX >= aPixels->size_x || aY < 0 || aY >= aPixels->size_y || 00094 aZ < 0 || aZ >= aPixels->size_z)) { 00095 return -1; 00096 } 00097 if (aX < 0) { 00098 aX = 0; 00099 } 00100 if (aX >= aPixels->size_x) { 00101 aX = aPixels->size_x - 1; 00102 } 00103 if (aY < 0) { 00104 aY = 0; 00105 } 00106 if (aY >= aPixels->size_y) { 00107 aY = aPixels->size_y - 1; 00108 } 00109 if (aZ < 0) { 00110 aZ = 0; 00111 } 00112 if (aZ >= aPixels->size_z) { 00113 aZ = aPixels->size_z - 1; 00114 } 00115 return aX + aPixels->size_x * (aY + aPixels->size_y * aZ); 00116 } /* muse_pixgrid_get_index() */ 00117 00118 /*---------------------------------------------------------------------------*/ 00127 /*---------------------------------------------------------------------------*/ 00128 static inline cpl_size 00129 muse_pixgrid_get_count(muse_pixgrid *aPixels, cpl_size aIndex) 00130 { 00131 if (aIndex < 0) { 00132 return 0; 00133 } 00134 cpl_size p = aPixels->pix[aIndex]; 00135 return (p == 0) ? 0 00136 : (p > 0) ? 1 : aPixels->ext[-p-1].npix; 00137 } /* muse_pixgrid_get_count() */ 00138 00139 /*---------------------------------------------------------------------------*/ 00148 /*---------------------------------------------------------------------------*/ 00149 static inline const cpl_size * 00150 muse_pixgrid_get_rows(muse_pixgrid *aPixels, cpl_size aIndex) 00151 { 00152 if (aIndex < 0) { 00153 return 0; 00154 } 00155 cpl_size p = aPixels->pix[aIndex]; 00156 return (p == 0) ? NULL 00157 : (p > 0) ? aPixels->pix + aIndex : aPixels->ext[-p-1].pix; 00158 } /* muse_pixgrid_get_rows() */ 00159 00162 /*----------------------------------------------------------------------------* 00163 * Function prototypes * 00164 *----------------------------------------------------------------------------*/ 00165 muse_pixgrid *muse_pixgrid_create(muse_pixtable *, cpl_propertylist *, cpl_size, cpl_size, cpl_size); 00166 muse_pixgrid *muse_pixgrid_2d_create(cpl_table *, double, double, double, double, float *); 00167 void muse_pixgrid_delete(muse_pixgrid *); 00168 00169 #endif /* MUSE_PIXGRID_H */
1.6.1