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

Linux Cross Reference
Tina6/tina-libs/tina/math/mathVec_get.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/math/mathVec_get.c,v $
 37  * Date    :  $Date: 2008/12/09 00:15:22 $
 38  * Version :  $Revision: 1.7 $
 39  * CVS Id  :  $Id: mathVec_get.c,v 1.7 2008/12/09 00:15:22 paul Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes : Vector (1 dimensional array) component reading
 44  *
 45  *********
 46 */
 47 /** 
 48  *  @file
 49  *  @brief   Vector (1 dimensional array) component reading.    
 50  *
 51  *  Contains two main types of function;
 52  *
 53  *  - functions to obtain a vector value at position i in the vector.
 54  *  - functions to obtain an interpolated vector value at a non-integer position.
 55  * 
 56 */
 57 
 58 #include "mathVec_get.h"
 59 
 60 #if HAVE_CONFIG_H
 61 #include <config.h>
 62 #endif
 63 
 64 
 65 #include <stdio.h>
 66 #include <tina/sys/sysDef.h>
 67 #include <tina/sys/sysPro.h>
 68 #include <tina/math/math_VecDef.h>
 69 
 70 static Complex  zero = {Complex_id, 0.0, 0.0};
 71 
 72 void           *vector_getp(Vector * v, int i)
 73 {
 74         void           *vi;
 75 
 76         if (v == NULL || v->vtype != ptr_v)
 77                 return (NULL);
 78         if (i < 0 || i >= v->n)
 79                 return (NULL);
 80         VECTOR_GETP(v, i, vi);
 81         return (vi);
 82 }
 83 
 84 int             vector_get(Vector * v, int i)
 85 {
 86         double          vi;
 87 
 88         if (v == NULL || v->vtype == ptr_v)
 89                 return (0);
 90         if (i < 0 || i >= v->n)
 91                 return (0);
 92         VECTOR_GET(v, i, vi);
 93         return ((int) vi);
 94 }
 95 
 96 double          vector_getf(Vector * v, int i)
 97 {
 98         double          vi;
 99 
100         if (v == NULL || v->vtype == ptr_v)
101                 return (0.0);
102         if (i < 0 || i >= v->n)
103                 return (0.0);
104         VECTOR_GET(v, i, vi);
105         return (vi);
106 }
107 
108 Complex         vector_getz(Vector * v, int i)
109 {
110         Complex         vi = {Complex_id};
111 
112         if (v == NULL || v->vtype == ptr_v)
113                 return (zero);
114         if (i < 0 || i >= v->n)
115                 return (zero);
116         VECTOR_GETZ(v, i, vi);
117         return (vi);
118 }
119 
120 double          vector_interpf(Vector * v, double x)
121 {
122         int             xi;
123         double          x1, x2;
124         double          vi, v1, v2;
125 
126         if (v == NULL || v->vtype == ptr_v)
127                 return (0);
128         if (x < 0 || x > v->n)
129                 return (0.0);
130 
131         if (x < v->n)
132                 xi = (int) x;
133         else
134                 xi = v->n;
135 
136         x1 = x - xi;
137         x2 = 1.0 - x1;
138         VECTOR_GET(v, xi, v1);
139         VECTOR_GET(v, xi + 1, v2);
140         vi = x2 * v1 + x1 * v2;
141         return (vi);
142 }
143 
144 Complex         vector_interpz(Vector * v, double x)
145 {
146         int             xi;
147         double          x1, x2;
148         Complex         vi = {Complex_id};
149         Complex         v1 = {Complex_id};
150         Complex         v2 = {Complex_id};
151 
152         if (v == NULL || v->vtype == ptr_v)
153                 return (zero);
154         if (x < 0 || x > v->n)
155                 return (zero);
156 
157         if (x < v->n)
158                 xi = (int) x;
159         else
160                 xi = v->n;
161 
162         x1 = x - xi;
163         x2 = 1.0 - x1;
164         VECTOR_GETZ(v, xi, v1);
165         VECTOR_GETZ(v, xi + 1, v2);
166         vi.x = x2 * v1.x + x1 * v2.x;
167         vi.y = x2 * v1.y + x1 * v2.y;
168         return (vi);
169 }
170 

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