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

Linux Cross Reference
Tina4/src/geomstat/state/state.c

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

  1 /**@(#)
  2 **/
  3 /**
  4 state.c:
  5 basic statistics structure handling
  6 **/
  7 
  8 #include <stdio.h>
  9 #include <math.h>
 10 #include <tina/sys.h>
 11 #include <tina/math.h>
 12 #include <tina/mathfuncs.h>
 13 #include <tina/sysfuncs.h>
 14 #include <tina/vision.h>
 15 #include <tina/visionfuncs.h>
 16 
 17 void   *geom_basis();
 18 
 19 /**
 20 allocate a state
 21 maxnum is estimate of maximum number of geometrical primitives
 22 **/
 23 
 24 #define PUSH(x, list) {(list) = ref_addtostart((List *) list, (void *) (x), (int)NULL);}
 25 #define POP(type, x, list) {(x) = (type) (list)->to; (list) = link_rm_el(list);}
 26 
 27 State  *state_alloc(int maxnum, double lscale, double accuracy)
 28 {
 29     State  *state = ts_ralloc(State);
 30     int     i;
 31 
 32     /** internal indexing has maxnum free places **/
 33     state->maxnum = maxnum;
 34     state->maxindex = 0;
 35     state->freeindex = NULL;
 36     for (i = maxnum - 1; i >= 0; i--)
 37         PUSH(i, state->freeindex);
 38 
 39     /** pointers to geometry and statistics information **/
 40     state->type = vector_alloc(maxnum, int_v);
 41     state->geom = vector_alloc(maxnum, ptr_v);
 42     state->basis = vector_alloc(maxnum, ptr_v);
 43     state->s = matrix_alloc(maxnum, maxnum, matrix_lower, ptr_v);
 44     state->x = vector_alloc(maxnum, ptr_v);
 45     state->m = vector_alloc(maxnum, ptr_v);
 46 
 47     state->lscale = lscale;
 48     state->accuracy = accuracy;
 49 
 50     return (state);
 51 }
 52 
 53 /**
 54 free all the memory associated with a state
 55 
 56 (except for primlist)
 57 **/
 58 
 59 void    state_free(State * state)
 60 {
 61     int     i, j;
 62     int    *type = (int *) state->type->data;
 63     void  **geom = (void **) state->geom->data;
 64     void  **basis = (void **) state->basis->data;
 65     Matrix ***s = (Matrix ***) state->s->el.ptr_v;
 66     Vector **x = (Vector **) state->x->data;
 67     Vector **m = (Vector **) state->m->data;
 68 
 69     for (i = 0; i < state->maxindex; i++)
 70     {
 71         geom_free(geom[i], type[i]);
 72         rfree((void *) basis[i]);
 73         vector_free(x[i]);
 74         vector_free(m[i]);
 75         matrix_free(s[i][i]);
 76         for (j = 0; j < i; j++)
 77             matrix_free(s[i][j]);
 78     }
 79 
 80     vector_free(state->type);
 81     vector_free(state->geom);
 82     vector_free(state->basis);
 83     matrix_free(state->s);
 84     vector_free(state->x);
 85     vector_free(state->m);
 86     list_rm((List *) state->freeindex, (void (*) ()) NULL);
 87 
 88     rfree((void *) state);
 89 }
 90 
 91 /**
 92 add a new primitive into state
 93 **/
 94 
 95 int     state_add(State * state, void *newgeom, int newtype)
 96 {
 97     int     i;
 98     int    *type = (int *) state->type->data;
 99     void  **geom = (void **) state->geom->data;
100     void  **basis = (void **) state->basis->data;
101 
102     if (state->freeindex == NULL)
103     {
104         error("state_add: state full", non_fatal);
105         return (-1);
106 
107         /**
108           int             maxnum = state->maxnum;
109         int newmaxnum = maxnum+MAX(1, maxnum/3);
110         Matrix       ***s = (Matrix ***) state->s->el.ptr_v;
111         Vector        **x = (Vector **) state->x->data;
112         Vector        **m = (Vector **) state->m->data;
113         message("state_add: extending state length");
114         type = ivector_extend(type,  0, maxnum, 0, newmaxnum);
115         geom = pvector_extend(geom,  0, maxnum, 0, newmaxnum);
116         basis = pvector_extend(basis,  0, maxnum, 0, newmaxnum);
117         s = (Matrix ***) plower_extend((void ***) s, 0, maxnum, 0, newmaxnum);
118         x = (Vector **) pvector_extend((void **) x, 0, maxnum, 0, newmaxnum);
119         m = (Vector **) pvector_extend((void **) m, 0, maxnum, 0, newmaxnum);
120         for(i = newmaxnum-1; i >= maxnum; i++)
121             PUSH(i, state->freeindex);
122         **/
123     }
124     POP(int, i, state->freeindex);
125     if (state->maxindex == i)
126         state->maxindex = i + 1;
127     type[i] = newtype;
128     geom[i] = geom_copy(newgeom, newtype);
129     basis[i] = geom_basis(newgeom, newtype);
130 
131     /**
132     s[i][i] = matrix_alloc(geom_df(newtype), geom_df(newtype),
133         matrix_lower, double_v);
134     geom_set_infcov(newtype, s[i][i], state->lscale);
135     **/
136 
137     /**
138     x[i] = vector_alloc(geom_df(newtype), double_v);
139     m[i] = vector_alloc(geom_df(newtype), double_v);
140     **/
141     return (i);
142 }
143 
144 State  *state_make(List * list, double accuracy)
145 {
146     List   *ptr;
147     int     n, l;
148     State  *state;
149     Vec3    centre = {Vec3_id};
150 /*BUGFIX Julian Briggs 1/12/93: was    float   radius;*/
151     double    radius;
152 
153     geom_hull_get(list, &centre, &radius);
154     l = list_length(list);
155     n = MAX(3 * l, l + 30);
156     state = state_alloc(n, radius, accuracy);
157 
158     for (ptr = list; ptr != NULL; ptr = ptr->next)
159         (void) state_add_tina(state, ptr->to, LINE3);
160 
161     return (state);
162 }
163 
164 
165 /**delete prim with given label from prim**/
166 
167 int     state_delete(State * state, int i)
168 {
169     int     j;
170     int    *type = (int *) state->type->data;
171     void  **geom = (void **) state->geom->data;
172     void  **basis = (void **) state->basis->data;
173     Matrix ***s = (Matrix ***) state->s->el.ptr_v;
174     Vector **x = (Vector **) state->x->data;
175     Vector **m = (Vector **) state->m->data;
176 
177     geom_free(geom[i], type[i]);
178     type[i] = (int) NULL;
179     geom[i] = NULL;
180     rfree((void *) basis[i]);
181     basis[i] = NULL;
182     vector_free(x[i]);
183     x[i] = NULL;
184     vector_free(m[i]);
185     m[i] = NULL;
186     for (j = 0; j <= i; j++)
187     {
188         matrix_free(s[i][j]);
189         s[i][j] = NULL;
190     }
191     if (i == state->maxindex - 1)
192         state->maxindex--;
193     PUSH(i, state->freeindex);
194     return(i);
195 }
196 

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