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

volallo.c

Go to the documentation of this file.
00001 /************************************************************************* 00002 * $Id: volallo.c,v 1.1 2005/09/09 08:22:56 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 <stdlib.h> 00037 #include "idvol.h" 00038 #include "idprint.h" 00039 00040 00041 #define DEBUG 0 00042 00043 /************************************************************************* 00044 * 00045 * Description : Allocation / Destruction d'une structure VOLume compacte 00046 * 00047 **************************************************************************/ 00048 00058 PPPVOLUME 00059 IdVolAlloc(int sx, int sy, int sz, int ty) 00060 { 00061 PRIVATE_VOLUME *pvol; 00062 PPPVOLUME pv = NULL; 00063 int plan, ligne; 00064 00065 if (!(ty & IDO_TYPE) == VOL) { 00066 printf 00067 ("Allocation impossible. Objet de type incompatible."); 00068 return (PPPVOLUME) NULL; 00069 } 00070 00071 pvol = (PRIVATE_VOLUME *) 00072 calloc(1, sizeof(PRIVATE_VOLUME) + sz * sizeof(char **)); 00073 00074 if (pvol == NULL) { 00075 printf("Echec Alloc Volume (partie privee)\n"); 00076 free(pvol); 00077 return (PPPVOLUME) NULL; 00078 } 00079 if (DEBUG) printf("pvol %p\n",pvol); 00080 00081 pvol->_fichier = 0; 00082 pvol->_message = 0; 00083 pv = (PPPVOLUME) & pvol[1]; 00084 IdVolDimX(pv) = sx; 00085 IdVolDimY(pv) = sy; 00086 IdVolDimZ(pv) = sz; 00087 IdVolUsedNbX(pv) = 0; 00088 IdVolUsedNbY(pv) = 0; 00089 IdVolUsedNbZ(pv) = 0; 00090 IdVolType(pv) = ty; 00091 pvol->subObject = 0; 00092 00093 /* 00094 * Gestion du cas des volumes de bits 00095 ls */ 00096 sx = ((ty & TY_SIZE) == TY_BIT) ? ((sx + 7) >> 3) : sx; 00097 00098 pv[0] = (void **) malloc( sz * sy * sizeof(void *)); 00099 00100 if (pv[0] == NULL) { 00101 printf("Echec Alloc Volume (pointeurs sur Lignes)\n"); 00102 free(pvol); 00103 return (PPPVOLUME) NULL; 00104 } 00105 00106 if (DEBUG) printf("pv[0] %p\n",pv[0]); 00107 00108 pv[0][0] = (void *) malloc( sz * sy * sx * IdSizeOfType(pv)); 00109 00110 if (pv[0][0] == NULL) { 00111 printf("Echec Alloc Volume (voxels)\n"); 00112 free(pvol); 00113 return (PPPVOLUME) NULL; 00114 } 00115 00116 for (plan = 0; plan < sz; plan++) { 00117 pv[plan]= pv[0] + plan * sy; 00118 if (DEBUG) printf("\tpv[%d] %p\n",plan, pv[plan]); 00119 for (ligne=0; ligne<sy; ligne++) { 00120 pv[plan][ligne] = (((char *)pv[0][0]) + (plan*sy + ligne )*sx*IdSizeOfType(pv) ); 00121 if (DEBUG) printf("\t pv[%d][%d] %p\n",plan, ligne, pv[plan][ligne]); 00122 } 00123 } 00124 return (pv); 00125 } 00126 00127 00133 void 00134 _IdVolFree(PPPVOLUME * pv) 00135 { 00136 if (*pv) { 00137 if (_IdVolPrivate(*pv)->subObject == 0) { 00138 /* 00139 *Liberation des voxels si PAS un ss-objet 00140 */ 00141 free((*pv)[0][0]); 00142 } 00143 free((*pv)[0]); 00144 00145 if (_IdVolPrivate(*pv)->_message) 00146 free((_IdVolPrivate(*pv)->_message)); 00147 //_IdVolPrivate(*pv)->_message = 0; // inutile 00148 if (_IdVolPrivate(*pv)->_fichier) 00149 free((_IdVolPrivate(*pv)->_fichier)); 00150 //_IdVolPrivate(*pv)->_fichier = 0; // inutile 00151 00152 free(_IdVolPrivate(*pv)); 00153 *pv = 0; 00154 } 00155 }

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