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

seqallo.c

Go to the documentation of this file.
00001 /************************************************************************* 00002 * $Id: seqallo.c,v 1.1 2005/09/09 08:22:53 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 <stdio.h> 00037 #include <stdlib.h> 00038 00039 #include "idseq-base.h" 00040 #include "idima-private.h" 00041 00042 #define DEBUG 0 00043 00044 /************************************************************************* 00045 * 00046 * Description : Allocation / Destruction d'une structure SEQuence compacte . 00047 * 00048 **************************************************************************/ 00049 00062 PPPPSEQUENCE 00063 IdSeqAlloc(int sx, int sy, int sz, int sb, int ty) 00064 { 00065 PRIVATE_SEQUENCE *pseq; 00066 PPPPSEQUENCE pv = NULL; 00067 int ibloc, iplan, iligne; 00068 00069 if (!(ty & IDO_TYPE) == SEQ) { 00070 printf 00071 ("Allocation impossible. Objet de type incompatible."); 00072 return (PPPPSEQUENCE) 0; 00073 } 00074 00075 pseq = (PRIVATE_SEQUENCE *) 00076 calloc(1, sizeof(PRIVATE_SEQUENCE) + sb * sizeof(void ***)); 00077 00078 if (pseq ==NULL) { 00079 printf 00080 ("Echec d'allocation PRIVATE_SEQUENCE."); 00081 return (PPPPSEQUENCE) NULL; 00082 } 00083 00084 if (DEBUG) printf("pseq %p\n",pseq); 00085 00086 00087 pseq->_fichier = 0; 00088 pseq->_message = 0; 00089 pv = (PPPPSEQUENCE) & pseq[1]; 00090 00091 IdSeqDimX(pv) = sx; 00092 IdSeqDimY(pv) = sy; 00093 IdSeqDimZ(pv) = sz; 00094 IdSeqDimT(pv) = sb; 00095 00096 IdSeqUsedNbX(pv) = 0; 00097 IdSeqUsedNbY(pv) = 0; 00098 IdSeqUsedNbZ(pv) = 0; 00099 IdSeqUsedNbT(pv) = 0; 00100 00101 IdSeqType(pv) = ty; 00102 pseq->subObject = 0; 00103 00104 /* 00105 * Gestion du cas des sequences de bits 00106 */ 00107 sx = ((ty & TY_SIZE) == TY_BIT) ? ((sx + 7) >> 3) : sx; 00108 00109 pv[0] = (void ***) malloc( sb * sz * sizeof(void *)); 00110 00111 if (pv[0] == NULL) { 00112 printf("Echec Alloc Sequence (pointeurs sur Plans)\n"); 00113 free(pseq); 00114 return (PPPPSEQUENCE) NULL; 00115 } 00116 if (DEBUG) printf("IdSeqAlloc : pv[0] : %p\n", pv[0]); 00117 00118 pv[0][0] = (void **) malloc( sb * sz * sy * sizeof(void *) ); 00119 00120 if (pv[0][0] == NULL) { 00121 printf("Echec Alloc Sequence (pointeurs sur Lignes)\n"); 00122 free(pv[0]); 00123 free(pseq); 00124 return (PPPPSEQUENCE) NULL; 00125 } 00126 00127 if (DEBUG) printf("IdSeqAlloc : pv[0][0] : %p\n", pv[0][0]); 00128 00129 pv[0][0][0] = (void *) malloc( sb * sz * sy * sx * IdSizeOfType(pv)); 00130 00131 if (pv[0][0][0] == NULL) { 00132 printf("Echec Alloc Sequence (seqxels)\n"); 00133 free(pv[0][0]); 00134 free(pv[0]); 00135 free(pseq); 00136 return (PPPPSEQUENCE) NULL; 00137 } 00138 00139 if (DEBUG) printf("IdSeqAlloc : pv[0][0][0] : %p\n", pv[0][0][0]); 00140 00141 for (ibloc = 0; ibloc < sb; ibloc++) { 00142 pv[ibloc]= pv[0] + ibloc * sz; 00143 if (DEBUG) printf("ibloc : pv[%d] %p\n", ibloc, pv[ibloc]); 00144 } 00145 00146 for (ibloc = 0; ibloc < sb; ibloc++) { 00147 for (iplan = 0; iplan < sz; iplan++) { 00148 pv[ibloc][iplan]= pv[0][0] + (ibloc*sz + iplan) * sy; 00149 if (DEBUG) printf(" plan : pv[%d][%d] %p \n", ibloc, iplan,pv[ibloc][iplan]); 00150 00151 } 00152 } 00153 00154 for (ibloc = 0; ibloc < sb; ibloc++) { 00155 for (iplan = 0; iplan < sz; iplan++) { 00156 for (iligne=0; iligne<sy; iligne++) { 00157 pv[ibloc][iplan][iligne] = (( (char *)pv[0][0][0]) 00158 + ((ibloc*sz + iplan) * sy + iligne )*sx*IdSizeOfType(pv) ); 00159 if (DEBUG) printf(" iligne : pv[%d][%d][%d] %p\n", 00160 ibloc, iplan, iligne, pv[ibloc][iplan][iligne]); 00161 } 00162 } 00163 } 00164 return (pv); 00165 } 00166 00167 00173 void 00174 _IdSeqFree(PPPPSEQUENCE * pv) 00175 { 00176 if (*pv) { 00177 if (_IdSeqPrivate(*pv)->subObject == 0) { 00178 /* 00179 *Liberation des seqxels si PAS un ss-objet 00180 */ 00181 if(DEBUG) printf("Liberation des seqxels car PAS un ss-objet\n"); 00182 free((*pv)[0][0][0]); 00183 } 00184 00185 if(DEBUG) printf("Liberation Pointeurs Plans\n"); 00186 free((*pv)[0][0]); 00187 if(DEBUG) printf("Liberation Pointeurs Volumes\n"); 00188 free((*pv)[0]); 00189 if(DEBUG) printf("fin Liberation Pointeurs Volumes\n"); 00190 00191 if (_IdSeqPrivate(*pv)->_message) { 00192 if(DEBUG) printf("Liberation _message\n"); 00193 free((_IdSeqPrivate(*pv)->_message)); 00194 } 00195 00196 if (_IdSeqPrivate(*pv)->_fichier) { 00197 if(DEBUG) printf("Liberation _fichier\n"); 00198 free((_IdSeqPrivate(*pv)->_fichier)); 00199 } 00200 if(DEBUG) printf("Liberation _IdSeqPrivate\n"); 00201 free(_IdSeqPrivate(*pv)); 00202 *pv = 0; 00203 } 00204 }

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