Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

niml_vector.c File Reference

#include "niml_private.h"

Go to the source code of this file.


Functions

void * NI_new_vector (int dtyp, NI_index_t len)
void NI_set_vector_range (void *nvv)

Function Documentation

void* NI_new_vector int    dtyp,
NI_index_t    len
 

Create a new vector, of the given type and length. Returns NULL if an error occurs. Otherwise, the vec and vec_range arrays are calloc()-ed, and the statistic struct is set to NULL. -------------------------------------------------------------

Definition at line 10 of file niml_vector.c.

References NI_datatype_size, NI_index_t, NI_is_builtin_type, NI_malloc, NI_new, NI_STRING, NI_VECTOR_TYPE, NI_vector::statistic, NI_vector::vec, NI_vector::vec_range, and NI_vector::vec_typ.

Referenced by NI_dataset_transpose().

00011 {
00012    NI_vector *nv ;
00013    NI_index_t ii ;
00014    int siz ;
00015 
00016    if( len <= 0 ) return NULL ;
00017 
00018    siz = NI_datatype_size( dtyp ) ;
00019    if( dtyp != NI_STRING && siz <= 0 ) return NULL ;
00020 
00021    nv = NI_new(NI_vector) ;
00022    if( NI_is_builtin_type(dtyp) )
00023      nv->type  = NI_VECTOR_TYPE + dtyp + 1 ;  /* type patched */
00024    else
00025      nv->type  = NI_VECTOR_TYPE ;             /* generic type */
00026    nv->vec_typ = dtyp ;
00027 
00028    if( dtyp != NI_STRING ){
00029      nv->vec       = NI_malloc(void,  NI_datatype_size(dtyp) * len ) ;
00030      nv->vec_range = NI_malloc(void, NI_datatype_size(dtyp) * 2   ) ;
00031    } else {
00032      nv->vec       = NI_malloc(void, sizeof(char *) * len ) ;
00033      nv->vec_range = NULL ;  /* string vectors don't use vec_range */
00034    }
00035    nv->statistic = NULL ;
00036    return (void *)nv ;
00037 }

void NI_set_vector_range void *    nvv
 

Set the range in a vector struct.

Definition at line 42 of file niml_vector.c.

References rgba::a, rgba::b, rgb::b, rgba::g, rgb::g, complex::i, NI_BYTE, NI_COMPLEX, NI_datatype_size, NI_DOUBLE, NI_FLOAT, NI_index_t, NI_INT, NI_is_builtin_type, NI_is_vector_type, NI_malloc, NI_RGB, NI_RGBA, NI_SHORT, NI_STRING, rgba::r, rgb::r, complex::r, NI_vector::vec, NI_vector::vec_len, NI_vector::vec_range, and NI_vector::vec_typ.

Referenced by NI_dataset_transpose().

00043 {
00044    NI_vector *nv = (NI_vector *)nvv ;
00045    NI_index_t len, ii ;
00046 
00047    if( nv == NULL                       ||
00048        !NI_is_vector_type(nv->type)     ||
00049        !NI_is_builtin_type(nv->vec_typ) ||
00050        nv->vec_typ == NI_STRING           ) return ;
00051 
00052    len = nv->vec_len ; if( len <= 0 ) return ;
00053 
00054    if( nv->vec_range == NULL )
00055      nv->vec_range = NI_malloc(void, 2*NI_datatype_size(nv->vec_typ) ) ;
00056 
00057    switch( nv->vec_typ ){  /* no default */
00058 
00059      case NI_BYTE:{
00060        byte *vv = (byte *)nv->vec ;
00061        byte *vr = (byte *)nv->vec_range ;
00062        byte vbot=vv[0], vtop=vv[0] ;
00063        for( ii=1 ; ii < len ; ii++ )
00064               if( vv[ii] < vbot ) vbot = vv[ii] ;
00065          else if( vv[ii] > vtop ) vtop = vv[ii] ;
00066        vr[0] = vbot ; vr[1] = vtop ;
00067      }
00068      break ;
00069 
00070      case NI_SHORT:{
00071        short *vv = (short *)nv->vec ;
00072        short *vr = (short *)nv->vec_range ;
00073        short vbot=vv[0], vtop=vv[0] ;
00074        for( ii=1 ; ii < len ; ii++ )
00075               if( vv[ii] < vbot ) vbot = vv[ii] ;
00076          else if( vv[ii] > vtop ) vtop = vv[ii] ;
00077        vr[0] = vbot ; vr[1] = vtop ;
00078      }
00079      break ;
00080 
00081      case NI_INT:{
00082        int *vv = (int *)nv->vec ;
00083        int *vr = (int *)nv->vec_range ;
00084        int vbot=vv[0], vtop=vv[0] ;
00085        for( ii=1 ; ii < len ; ii++ )
00086               if( vv[ii] < vbot ) vbot = vv[ii] ;
00087          else if( vv[ii] > vtop ) vtop = vv[ii] ;
00088        vr[0] = vbot ; vr[1] = vtop ;
00089      }
00090      break ;
00091 
00092      case NI_FLOAT:{
00093        float *vv = (float *)nv->vec ;
00094        float *vr = (float *)nv->vec_range ;
00095        float vbot=vv[0], vtop=vv[0] ;
00096        for( ii=1 ; ii < len ; ii++ )
00097               if( vv[ii] < vbot ) vbot = vv[ii] ;
00098          else if( vv[ii] > vtop ) vtop = vv[ii] ;
00099        vr[0] = vbot ; vr[1] = vtop ;
00100      }
00101      break ;
00102 
00103      case NI_DOUBLE:{
00104        double *vv = (double *)nv->vec ;
00105        double *vr = (double *)nv->vec_range ;
00106        double vbot=vv[0], vtop=vv[0] ;
00107        for( ii=1 ; ii < len ; ii++ )
00108               if( vv[ii] < vbot ) vbot = vv[ii] ;
00109          else if( vv[ii] > vtop ) vtop = vv[ii] ;
00110        vr[0] = vbot ; vr[1] = vtop ;
00111      }
00112      break ;
00113 
00114      case NI_COMPLEX:{
00115        complex *vv = (complex *)nv->vec ;
00116        complex *vr = (complex *)nv->vec_range ;
00117        complex vbot=vv[0], vtop=vv[0] ;
00118        for( ii=1 ; ii < len ; ii++ ){
00119               if( vv[ii].r < vbot.r ) vbot.r = vv[ii].r ;
00120          else if( vv[ii].r > vtop.r ) vtop.r = vv[ii].r ;
00121               if( vv[ii].i < vbot.i ) vbot.i = vv[ii].i ;
00122          else if( vv[ii].i > vtop.i ) vtop.i = vv[ii].i ;
00123        }
00124        vr[0] = vbot ; vr[1] = vtop ;
00125      }
00126      break ;
00127 
00128      case NI_RGB:{
00129        rgb *vv = (rgb *)nv->vec ;
00130        rgb *vr = (rgb *)nv->vec_range ;
00131        rgb vbot=vv[0], vtop=vv[0] ;
00132        for( ii=1 ; ii < len ; ii++ ){
00133               if( vv[ii].r < vbot.r ) vbot.r = vv[ii].r ;
00134          else if( vv[ii].r > vtop.r ) vtop.r = vv[ii].r ;
00135               if( vv[ii].g < vbot.g ) vbot.g = vv[ii].g ;
00136          else if( vv[ii].g > vtop.g ) vtop.g = vv[ii].g ;
00137               if( vv[ii].b < vbot.b ) vbot.b = vv[ii].b ;
00138          else if( vv[ii].b > vtop.b ) vtop.b = vv[ii].b ;
00139        }
00140        vr[0] = vbot ; vr[1] = vtop ;
00141      }
00142      break ;
00143 
00144      case NI_RGBA:{
00145        rgba *vv = (rgba *)nv->vec ;
00146        rgba *vr = (rgba *)nv->vec_range ;
00147        rgba vbot=vv[0], vtop=vv[0] ;
00148        for( ii=1 ; ii < len ; ii++ ){
00149               if( vv[ii].r < vbot.r ) vbot.r = vv[ii].r ;
00150          else if( vv[ii].r > vtop.r ) vtop.r = vv[ii].r ;
00151               if( vv[ii].g < vbot.g ) vbot.g = vv[ii].g ;
00152          else if( vv[ii].g > vtop.g ) vtop.g = vv[ii].g ;
00153               if( vv[ii].b < vbot.b ) vbot.b = vv[ii].b ;
00154          else if( vv[ii].b > vtop.b ) vtop.b = vv[ii].b ;
00155               if( vv[ii].a < vbot.a ) vbot.a = vv[ii].a ;
00156          else if( vv[ii].a > vtop.a ) vtop.a = vv[ii].a ;
00157        }
00158        vr[0] = vbot ; vr[1] = vtop ;
00159      }
00160      break ;
00161 
00162    }
00163 
00164    return ;
00165 }
 

Powered by Plone

This site conforms to the following standards: