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

Linux Cross Reference
Tina5/tina-tools/tinatool/tlbase/tlbaseSeq_funcs.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-tools/tinatool/tlbase/tlbaseSeq_funcs.c,v $
 37  * Date    :  $Date: 2005/12/20 16:34:48 $
 38  * Version :  $Revision: 1.6 $
 39  * CVS Id  :  $Id: tlbaseSeq_funcs.c,v 1.6 2005/12/20 16:34:48 matts Exp $
 40  *
 41  * Notes : Bit of a random file with collection of functions which probably 
 42  *         need homes elsewhere
 43  *********
 44 */
 45 
 46 #include "tlbaseSeq_funcs.h"
 47 
 48 #if HAVE_CONFIG_H
 49 #   include <config.h>
 50 #endif
 51 
 52 #include <stdio.h>
 53 #include <tina/image/imgDef.h>
 54 #include <tina/image/imgPro.h>
 55 #include <tina/file/filePro.h>
 56 #include <tina/file/filePro.h>
 57 #include <tina/geometry/geomDef.h>
 58 #include <tina/geometry/geomPro.h>
 59 #include <tinatool/draw/drawPro.h>
 60 #include <tinatool/tlbase/tlbasePro.h>
 61 #include <tinatool/tlbase/tlbase_SeqDef.h>
 62 
 63 static double     TE = 0.25;
 64  
 65 List *get_stride_store(List *store, int stride)
 66 {
 67 
 68   int i; 
 69 
 70   for (i = 0; i < stride; i++)
 71     {
 72       if ((store = store->next) == NULL)
 73         return(NULL);
 74     }
 75 
 76   return(store);
 77 
 78 }
 79 
 80 
 81 /* function to get dimensions as a Vec3 suitable for passing to coreg functions */
 82 
 83 Vec3 *seq_dim_to_vec3(void)
 84 {
 85   Sequence *seq = NULL;
 86   Vec3 * iscales = NULL;
 87 
 88   if ((seq = seq_get_current()) == NULL)
 89     return(NULL);
 90 
 91   iscales = vec3_make(vec3(seq->dim[0], seq->dim[1], seq->dim[2]));
 92   
 93   return(iscales);
 94 }
 95 
 96 
 97 /* sequence wrapper around pushing imrect to imcalc */
 98 
 99 void seq_push_data(Imrect *im)
100 {
101   Imrect *imy;
102 
103   imy = im_copy(im);
104   stack_push(imy, IMRECT, im_free);
105   imcalc_draw(imcalc_tv_get());
106   imcalc_draw(imcal2_tv_get());
107   image_choice_reset();
108   return;
109 }
110 
111 /* sequence wrapper around popping imrect from imcalc */
112 
113 Imrect *seq_pop_data(Imrect *im, int type)
114 {
115         
116   if ((stack_check_types(IMRECT, NULL)) == false)
117     {
118       error("wrong type on stack ", warning);
119       return (NULL);
120     }
121         
122   im = (Imrect *)stack_pop(&type);
123   imcalc_draw(imcalc_tv_get());
124   imcalc_draw(imcal2_tv_get());
125 
126         
127   return (im);
128 }
129 
130 
131 /* Takes a stack of images and puts into sequence tool. 
132    this is a bit unfinished - not sure about the sequence freeing at the beginning */
133 
134 void stack_seq(Vec3 *iscale)
135 {
136   /* Delete the current sequence and move the stack into the sequence instead PAB 25/10/01 */
137   /* This probably needs to be split into subroutines: I put it all here for simplicity */
138 
139   List *dd_el = NULL, *lptr=NULL, *mptr=NULL, *el=NULL;
140   Sequence *seq=NULL;
141   Imrect *im;
142   int type, no_images=0, i;
143   List *get_stack_ptr();
144 
145   if ((seq = seq_get_current()) == NULL)
146   {
147     if ((seq = seq_alloc()) == NULL)
148     {
149       error("can't allocate sequence \n", non_fatal);
150       return;
151     }
152   }
153 
154   dd_el=get_seq_start_el(seq);
155   el = get_stack_ptr();
156   seq->offset=0; 
157   seq->stride=1;
158   
159   for(el=get_stack_ptr(); el!=NULL; el=el->next) no_images++;
160 
161   if(no_images==0) return;
162 
163   for(i=no_images; i>0; i--)
164   {
165     im = (Imrect *)stack_pop(&type);
166     dd_el = dd_ref_addtostart(dd_el, im, SEQ);
167   }
168 
169   set_seq_start_el(seq, dd_el);
170   set_seq_current_el(seq, dd_el);
171   seq_set_current(seq);
172   seq_image_set((Imrect *)dd_el->to);
173 
174   for(lptr=dd_el; lptr!=NULL; lptr=lptr->next) mptr=lptr;
175   set_seq_end_el(seq, mptr);
176 }
177 
178 /* sets up the default Echo Train time for ?permeability images. adds TE to sequence
179    proplist*/
180 /* mjs modified 8/11/05 to create array of TE values rather than single value */
181 static void    seq_setup_default_TE(Sequence *seq, float TE)
182 {
183   float   *fp = NULL;
184   int end = 0, i=0;
185 
186   /*  fp = (float *) ralloc(sizeof(float));*/
187   end = get_seq_end();
188   fp = fvector_alloc(seq->offset, end+1);
189 
190   for (i=seq->offset; i<end+1; i=i+seq->stride)
191     {
192       fp[i] = TE;
193     }
194   seq->props = proplist_addifnp(seq->props, (void *)fp, TE_DATA, rfree, true);
195 
196   return;
197 }
198 
199 /* used to return dynamic scan time between slices. not used now */
200 /*
201   static double seq_dynstime_interval()
202   {
203    float   time;
204    Sequence * seq = (Sequence *)seq_get_current();
205   
206    return((double)time);
207   }
208 */
209 
210 /* Wrapper to get dynamic info (timing and TE times) from the appropriate files */
211 
212 /* NB. there is no setup default dynstimes because you would expect each sequence to 
213    have a new sequence structure, and the default dynstime on initialisation is
214    1.0 secs */
215 
216 void seq_get_dyndata(Sequence *seq, int end, int filetype)
217 {
218 
219   switch(filetype)
220     {
221     case SEQTL_NEMA_FILE :
222       if (!nema_hdr_dynstimes_extract()) 
223         nema_hdr_heartrate_extract();
224 
225       if (!nema_hdr_TE_extract())
226         seq_setup_default_TE(seq, (float)TE);
227       nema_hdr_TR_extract();
228       nema_hdr_flip_angle_extract();
229       nema_hdr_patientdetails_extract();
230       nema_hdr_voxelscale_extract();
231       break;
232 
233     case SEQTL_DICOM_FILE :
234       if (!dicom_hdr_dynstimes_extract(seq,end))
235         dicom_hdr_heartrate_extract(seq,end);
236 
237       if (!dicom_hdr_TE_extract())
238         seq_setup_default_TE(seq, (float)TE);
239       dicom_hdr_patientdetails_extract();
240       dicom_hdr_voxelscale_extract();
241       break;
242 
243     default :
244       error("dynamic format not supported: using default time scale\n", warning);
245       seq_setup_default_TE(seq, (float)TE);
246       break;
247     }
248 
249   return;
250 }
251 
252 
253 
254 Sequence *delete_seq_frame(Sequence *data)
255 {
256   List  *lptr = (List *)get_seq_current_el(data);
257 
258   if (lptr == get_seq_end_el(data))
259     {
260       set_seq_end_el(data, lptr->last);
261       set_seq_current_el(data, lptr->last);
262     }
263   else
264     {
265       set_seq_current_el(data, lptr->next);
266     }
267 
268   if (lptr == get_seq_start_el(data))
269     {
270       set_seq_start_el(data, lptr->next);
271       data->offset = (data->offset) + (data->stride); /*or incr of stride */
272       /* seq_param_update(data);*/
273     }
274 
275   data->start = dd_list_rm_el(data->start, lptr, im_free);
276 
277   if (data->start == NULL)
278     {
279       seq_rm(data);
280       return(NULL);
281     }
282   else
283     {
284       return(data);
285     }
286   
287 }
288 
289 
290 
291 
292 
293 
294 
295 
296 
297 
298 

~ [ 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.