~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina6/tina-libs/tina/image/imgSeq_alloc.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**********
  2  *
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  *
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-libs/tina/image/imgSeq_alloc.c,v $
 37  * Date    :  $Date: 2008/12/07 02:27:36 $
 38  * Version :  $Revision: 1.10 $
 39  * CVS Id  :  $Id: imgSeq_alloc.c,v 1.10 2008/12/07 02:27:36 paul Exp $
 40  *
 41  */
 42 
 43 /** 
 44  *  @file
 45  *  @brief Sequence Structure Allocation, copying and removal.
 46  *
 47  */
 48 
 49 #if HAVE_CONFIG_H
 50 #include <config.h>
 51 #endif
 52 
 53 #include "imgSeq_alloc.h"
 54 
 55 #include <stdio.h>
 56 #include <string.h>
 57 #include <tina/sys/sysDef.h>
 58 #include <tina/sys/sysPro.h>
 59 #include <tina/math/mathDef.h>
 60 #include <tina/math/mathPro.h>
 61 #include <tina/image/imgDef.h>
 62 #include <tina/image/imgPro.h>
 63 
 64 
 65 /*
 66  * seq_alloc to allocate a sequence and initialize all the pointers to NULL
 67  * the offset to 0, stride to 1 and x=y=z=1mm time=1sec
 68  */
 69 
 70 Sequence       *seq_alloc(void)
 71 {
 72         unsigned int    size;
 73         Sequence       *seq = NULL;
 74 
 75         size = sizeof(Sequence);
 76         if ((seq = ralloc(size)) == NULL)
 77         {
 78                 error(" memory allocation failure ", non_fatal);
 79                 return (NULL);
 80         }
 81         seq->filename = NULL;
 82         seq->start = NULL;
 83         seq->end = NULL;
 84         seq->current = NULL;
 85         seq->props = NULL;
 86 
 87         seq->offset = 0;
 88         seq->stride = 1;
 89         seq->downsample = 1;
 90 
 91         seq->dim[0] = seq->dim[1] = seq->dim[2] = seq->dim[3] = 1.0;
 92 
 93         return (seq);
 94 
 95 }
 96 
 97 /*
 98  * seq_rm removes the contents of the Sequence, including removing the imrect
 99  * list AND all of the imrects
100  */
101 
102 /* very similar to seq_free_proc */
103 /* PROBLEMS: cvector_free has trouble */
104 
105 void            seq_rm(Sequence * seq)
106 {
107         if (seq == NULL)
108                 return;
109 
110         if (seq->props != NULL)
111                 proplist_freelist(seq->props);
112 
113         if (seq->filename != NULL)
114                 cvector_free(seq->filename, 0);
115 
116         if (seq->start != NULL)
117                 dd_list_rm(seq->start, im_free);
118 
119         /*
120          * if (seq->dim != NULL) fvector_free(seq->dim, 0);
121          *//* ah it's not dynamically allocated... */
122 
123         rfree(seq);
124         seq_set_current(NULL);
125 
126 }
127 
128 /* mjs 8/11/05 modified to include TR and FA data and to get start and end values from the sequence */
129 void           *seq_prop_copy(Prop * prop, int list_el_type)
130 {
131 
132         int             prop_type = prop->type;
133         Prop           *copy = NULL;
134         void           *ptr = NULL;
135         int end = 0;
136         Sequence *seq=NULL;
137 
138         seq = seq_get_current(); /* if we are in a position to copy the sequence prop list
139                                     i think it's safe to assume the sequence exists */
140         end = get_end_frame(seq)+1;
141 
142         switch (prop_type)
143         {
144         case VOXELS:
145                 {
146                         ptr = (vec3_copy((Vec3 *) prop->to));
147                         break;
148                 }
149         case TE_DATA:
150                 {
151                         ptr = (fvector_copy((void *) prop->to, seq->offset, end));
152                         break;
153                 }
154         case TR_DATA:
155                 {
156                         ptr = (fvector_copy((void *) prop->to, seq->offset, end));
157                         break;
158                 }
159         case FLIP_ANGLE_DATA:
160                 {
161                         ptr = (fvector_copy((void *) prop->to, seq->offset, end));
162                         break;
163                 }
164         case PAT_DATA:
165                 {
166                         ptr = (cvector_copy((void *) prop->to, 0, 256));
167                         break;
168                 }
169         default:
170                 {
171                         format("\n Can't copy an unknown proc\n ");
172                         return (NULL);
173                 }
174         }
175 
176 
177         copy = prop_alloc(ptr, prop_type, prop->freefunc);
178 
179 
180         return (copy);
181 }
182 
183 /* seq_copy will create a complete copy of a given sequence */
184 
185 Sequence       *seq_copy(Sequence * seq)
186 {
187 
188         Sequence       *seq_copy = NULL;
189         int             filename_length;
190 
191         seq_copy = seq_alloc();
192 
193         /* easy ones first :) */
194 
195         seq_copy->offset = seq->offset;
196         seq_copy->stride = seq->stride;
197         seq_copy->downsample = seq->downsample;
198         seq_copy->type = seq->type;
199         seq_copy->dim[0] = seq->dim[0];
200         seq_copy->dim[1] = seq->dim[1];
201         seq_copy->dim[2] = seq->dim[2];
202         seq_copy->dim[3] = seq->dim[3];
203 
204         /* filename */
205 
206         filename_length = strlen(seq->filename);
207 
208         seq_copy->filename = cvector_copy(seq->filename, 0, filename_length + 1);
209 
210         /*
211          * need to copy the image list, and the images, and set the start,
212          * current and ends to appropriate elements
213          */
214 
215         seq_copy->start = list_copy(seq->start, (void *(*) ())im_copy, NULL);
216         seq_copy->end = list_get_end(seq_copy->start);
217         seq_copy->current = seq_copy->start;    /* better to put the image on
218                                                  * the same as the original i
219                                                  * guess, but i'm lazy */
220 
221         /* need to copy the proplist and all the props */
222 
223         seq_copy->props = proplist_propcopy(seq->props, seq_prop_copy);
224 
225         return (seq_copy);
226 
227 }
228 
229 
230 /*
231  * seq_init resets the values of a sequence, all the pointers are set to NULL
232  * and the stride, offset and dim are set to the defaults
233  */
234 
235 /*
236  * Not sure that this will have much use/may need to be modified Currently
237  * not used
238  */
239 
240 Sequence       *seq_init(Sequence * seq)
241 {
242         seq->filename = NULL;
243         seq->start = NULL;
244         seq->end = NULL;
245         seq->current = NULL;
246         seq->props = NULL;
247 
248         seq->offset = 0;
249         seq->stride = 1;
250         seq->downsample = 1;
251 
252         seq->dim[0] = seq->dim[1] = seq->dim[2] = seq->dim[3] = 1.0;
253 
254         return (seq);
255 
256 }
257 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.