Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals

sigtoima.c

Go to the documentation of this file.
00001 /************************************************************************* 00002 * $Id: sigtoima.c,v 1.1 2005/09/09 08:22:55 bellet Exp $ 00003 ************************************************************************** 00004 This software is governed by the CeCILL license under French law and 00005 abiding by the rules of distribution of free software. You can use, 00006 modify and/ or redistribute the software under the terms of the CeCILL 00007 license as circulated by CEA, CNRS and INRIA at the following URL 00008 "http://www.cecill.info". 00009 00010 As a counterpart to the access to the source code and rights to copy, 00011 modify and redistribute granted by the license, users are provided only 00012 with a limited warranty and the software's author, the holder of the 00013 economic rights, and the successive licensors have only limited 00014 liability. 00015 00016 In this respect, the user's attention is drawn to the risks associated 00017 with loading, using, modifying and/or developing or reproducing the 00018 software by the user in light of its specific status of free software, 00019 that may mean that it is complicated to manipulate, and that also 00020 therefore means that it is reserved for developers and experienced 00021 professionals having in-depth computer knowledge. Users are therefore 00022 encouraged to load and test the software's suitability as regards their 00023 requirements in conditions enabling the security of their systems and/or 00024 data to be ensured and, more generally, to use and operate it in the 00025 same conditions as regards security. 00026 00027 The fact that you are presently reading this means that you have had 00028 knowledge of the CeCILL license and that you accept its terms. 00029 00030 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de 00031 l'Image). All rights reserved. See License.txt for details. 00032 00033 Version 1.0 05/09/2005 00034 *************************************************************************/ 00035 00036 #include "idima.h" 00037 #include "idsig.h" 00038 #include "idprint.h" 00039 00040 /* 00041 * Undocumented parameters 00042 */ 00043 #define PCY 0.5 00044 #define MRG0 2 00045 00067 PPIMAGE_UCHAR 00068 IdImaSignalToImage(PSIGNAL sig, int off, int lh, int Urg, double maxi, 00069 double mini, int dimx, int dimy, int bgnd, int vpix) 00070 { 00071 int i, j, dx1, dy1, coo, end, ty, previousend=0, xfin; 00072 double kx, val=0., step; 00073 PPIMAGE_UCHAR Im; 00074 double tmp; 00075 00076 Im = (PPIMAGE_UCHAR) IdImaAlloc(dimx, dimy, IMA_UCHAR); 00077 if (!Im) { 00078 IdErrPrintf 00079 ("erreur allocation image pour IdImaSignalToIma\n"); 00080 return (0); 00081 } 00082 IdImaSetValue(Im, bgnd); 00083 00084 if (mini == -1.) 00085 if (maxi == -1.) 00086 IdSigMinMaxInterv(sig, off, off + lh, &mini, 00087 &maxi); 00088 else 00089 IdSigMinMaxInterv(sig, off, off + lh, &mini, &tmp); 00090 else if (maxi == -1) 00091 IdSigMinMaxInterv(sig, off, off + lh, &tmp, &maxi); 00092 00093 dx1 = IdImaDimX(Im) - 1; 00094 dy1 = IdImaDimY(Im) - 1; 00095 ty = IdSigType(sig); 00096 00097 /* 00098 * mettre l'echelle 'proprement' 00099 */ 00100 00101 for (j = 0; j < (dx1 + 1); j++) { 00102 Im[0][j] = vpix; 00103 Im[dy1][j] = vpix; 00104 } 00105 for (i = 0; i < (dy1 + 1); i++) { 00106 Im[i][0] = vpix; 00107 Im[i][dx1] = vpix; 00108 } 00109 00110 if (lh >= dimx) 00111 { /* 00112 * on sous-echantillonne le signal 00113 */ 00114 00115 kx = (double) (lh) / dx1; 00116 for (j = 1; j < dx1; j++) { 00117 coo = (int) (j * kx + off - 1 + .5); 00118 switch (ty) { 00119 case SIG_UCHAR: 00120 val = ((PSIGNAL_UCHAR) sig)[coo]; 00121 break; 00122 case SIG_CHAR: 00123 val = ((PSIGNAL_CHAR) sig)[coo]; 00124 break; 00125 case SIG_USHORT: 00126 val = ((PSIGNAL_USHORT) sig)[coo]; 00127 break; 00128 case SIG_SHORT: 00129 val = ((PSIGNAL_SHORT) sig)[coo]; 00130 break; 00131 case SIG_LONG: 00132 val = ((PSIGNAL_LONG) sig)[coo]; 00133 break; 00134 case SIG_ULONG: 00135 val = ((PSIGNAL_ULONG) sig)[coo]; 00136 break; 00137 case SIG_FLOAT: 00138 val = ((PSIGNAL_FLOAT) sig)[coo]; 00139 break; 00140 case SIG_DOUBLE: 00141 val = ((PSIGNAL_DOUBLE) sig)[coo]; 00142 break; 00143 } 00144 end = (int) (((maxi - val) / (maxi - mini)) * dy1); 00145 00146 if (end < 0) 00147 end = 0; 00148 if (j == 1) { 00149 previousend = end; 00150 } 00151 else { 00152 Im = 00153 IdImaDrawLine(Im, vpix, 0, j - 1, 00154 previousend, j, end); 00155 previousend = end; 00156 } 00157 00158 } 00159 } 00160 00161 /* 00162 * fin sous-ech signal 00163 */ 00164 else { /* 00165 * interpolation 00166 */ 00167 00168 step = (double) dimx / (double) (lh - 1); 00169 00170 for (j = 0; j < lh; j++) { /* 00171 * pour tous les pts du signal 00172 */ 00173 coo = j + off; 00174 switch (ty) { 00175 case SIG_UCHAR: 00176 val = ((PSIGNAL_UCHAR) sig)[coo]; 00177 break; 00178 case SIG_CHAR: 00179 val = ((PSIGNAL_CHAR) sig)[coo]; 00180 break; 00181 case SIG_USHORT: 00182 val = ((PSIGNAL_USHORT) sig)[coo]; 00183 break; 00184 case SIG_SHORT: 00185 val = ((PSIGNAL_SHORT) sig)[coo]; 00186 break; 00187 case SIG_LONG: 00188 val = ((PSIGNAL_LONG) sig)[coo]; 00189 break; 00190 case SIG_ULONG: 00191 val = ((PSIGNAL_ULONG) sig)[coo]; 00192 break; 00193 case SIG_FLOAT: 00194 val = ((PSIGNAL_FLOAT) sig)[coo]; 00195 break; 00196 case SIG_DOUBLE: 00197 val = ((PSIGNAL_DOUBLE) sig)[coo]; 00198 break; 00199 } 00200 00201 end = (int) (((maxi - val) / (maxi - mini)) * dy1); 00202 if (end < 0) 00203 end = 0; 00204 00205 if (j == 0) { 00206 previousend = end; 00207 } 00208 00209 else { 00210 if ((xfin = (int) (j * step)) == dimx) 00211 xfin--; 00212 Im = 00213 IdImaDrawLine(Im, vpix, 0, 00214 (int) ((j - 1) * step), 00215 previousend, xfin, end); 00216 previousend = end; 00217 } 00218 } 00219 00220 } 00221 return (Im); 00222 }

Generated on Wed Oct 19 09:28:34 2005 for SIMRI3D by doxygen 1.3.7