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

Linux Cross Reference
Tina4/src/tools/smartROI/sroi_alloc.c

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

  1 /*
  2  * sroi_alloc.c
  3  *
  4  * Memory allocation functions for sroi tool
  5  *
  6  */
  7 
  8 #include <stdio.h>
  9 #include <values.h>
 10 #include <math.h>
 11 #include <tina/sys.h>
 12 #include <tina/sysfuncs.h>
 13 #include <tina/math.h>
 14 #include <tina/mathfuncs.h>
 15 #include <tina/vision.h>
 16 #include <tina/visionfuncs.h>
 17 #include <tina/tv.h>
 18 #include <tina/tvfuncs.h>
 19 #include <tina/draw.h>
 20 #include <tina/drawfuncs.h>
 21 #include <tina/infrtoolfuncs.h>
 22 #include <tina/toolsfuncs.h>
 23 #include <tina/sroi_tool.h>
 24 
 25 
 26 /*
 27  * Local variables
 28  *
 29  */
 30 
 31 static Model *model = NULL;
 32 
 33 
 34 
 35 Model *get_model()
 36 {
 37   return (model);
 38 }
 39 
 40 
 41 void set_model(Model * m)
 42 {
 43   if (m == NULL)
 44     return;
 45 
 46   model_free(model);
 47   model = m;
 48 }
 49 
 50 
 51 
 52 Model *model_alloc(int nRows, int nPoints, int nOuter, int nProf)
 53 {
 54   Sroi_dparams *params = sroi_get_dparams();
 55   Model         *mdl = NULL;
 56   unsigned int size, i, ng;
 57 
 58   ng = nPoints * (2 * nProf - 1);
 59 
 60   if ((mdl = (Model *) ralloc(sizeof(Model))) == NULL)
 61   {
 62     error(" memory allocation failure ", non_fatal);
 63     return (NULL);
 64   }
 65   mdl->P_Evec = (Matrix **) pvector_alloc(0, nPoints);
 66   mdl->P_Eval = (Vector **) pvector_alloc(0, nPoints);
 67 
 68   mdl->m = matrix_alloc(nRows, nPoints, matrix_full, double_v);
 69   mdl->profile = matrix_alloc(nPoints, 2 * nProf - 1, matrix_full, float_v);
 70   mdl->g_profile = matrix_alloc(nPoints, 2 * nProf - 1, matrix_full, double_v);
 71   mdl->alpha = vector_alloc(nPoints, double_v);
 72   mdl->maxgrad = vector_alloc(nPoints, int_v);
 73   mdl->M_Evec = matrix_alloc(2 * nPoints, 2 * nPoints, matrix_full, double_v);
 74   mdl->M_Eval = vector_alloc(2 * nPoints, double_v);
 75   mdl->G_Evec = matrix_alloc(ng, nPoints, matrix_full, double_v);
 76   mdl->G_Eval = vector_alloc(nPoints, double_v);
 77 
 78   for (i = 0; i < nPoints; i++)
 79   {
 80     mdl->P_Evec[i] = matrix_alloc(2 * nProf - 1, 2 * nProf - 1, matrix_full, double_v);
 81     mdl->P_Eval[i] = vector_alloc(2 * nProf - 1, double_v);
 82   }
 83 
 84   mdl->m_weight = vector_alloc(2 * nPoints, double_v);
 85   mdl->p_weight = matrix_alloc(nPoints, 2 * nProf - 1, matrix_full, double_v);
 86 
 87   mdl->c = nPoints;
 88   mdl->r = nRows;
 89   mdl->o = nOuter;
 90   mdl->vsize = nProf;
 91   mdl->pcavsize = params->pcavsize;
 92   mdl->m_modes = params->m_modes;
 93   mdl->p_modes = params->p_modes;
 94   mdl->p_length =params->p_length;
 95   mdl->s_min = params->s_min;
 96   mdl->s_max = params->s_max;
 97   mdl->theta_max = params->theta;
 98   mdl->m_max = params->m_max;
 99   mdl->p_max = params->p_max;
100   mdl->g_max = params->g_max;
101 
102   return (mdl);
103 }
104 
105 
106 void model_free(Model * mdl)
107 {
108   int i;
109 
110   if (mdl == NULL)
111     return;
112 
113   matrix_free(mdl->m);
114   matrix_free(mdl->profile);
115   matrix_free(mdl->g_profile);
116   vector_free(mdl->alpha);
117   vector_free(mdl->maxgrad);
118   matrix_free(mdl->M_Evec);
119   vector_free(mdl->M_Eval);
120   matrix_free(mdl->G_Evec);
121   vector_free(mdl->G_Eval);
122   for (i = 0; i < mdl->c; i++)
123   {
124     matrix_free(mdl->P_Evec[i]);
125     vector_free(mdl->P_Eval[i]);
126   }
127   vector_free(mdl->m_weight);
128   matrix_free(mdl->p_weight);
129   rfree(mdl);
130 }
131 
132 
133 
134 Model *model_alloc_inner(Model *mdl, int nInner)
135 {
136 /*
137  * expands model with outer roi only to include
138  * inner roi. routine fails if inner model already
139  * exists
140  *
141  * relies on vector_expand & matrix_expand
142  */
143 
144   void         **temp;
145   unsigned int   i, ng;
146   int            nPoints;
147 
148   if ((mdl == NULL) || (nInner < 1))
149     return (NULL);
150 
151   if (mdl->o != mdl->c)
152     return (NULL);
153 
154   nPoints = mdl->o+nInner;
155   ng = nPoints*(2*mdl->r-1);
156 
157   mdl->m = matrix_expand(mdl->m, mdl->r, nPoints);
158   mdl->profile = matrix_expand(mdl->profile, nPoints, (2*mdl->r)-1);
159   mdl->g_profile = matrix_expand(mdl->g_profile, nPoints, (2*mdl->r)-1);
160   mdl->alpha = vector_expand(mdl->alpha, nPoints);
161   mdl->maxgrad = vector_expand(mdl->maxgrad, nPoints);
162   mdl->M_Evec = matrix_expand(mdl->M_Evec, 2*nPoints, 2*nPoints);
163   mdl->M_Eval = vector_expand(mdl->M_Eval, 2*nPoints);
164   mdl->G_Evec = matrix_expand(mdl->G_Evec, ng, nPoints);
165   mdl->G_Eval = vector_expand(mdl->G_Eval, nPoints);
166   mdl->m_weight = vector_expand(mdl->m_weight, 2*nPoints);
167   mdl->p_weight = matrix_expand(mdl->p_weight, nPoints, (2*mdl->r)-1);
168 
169   temp = pvector_alloc(0, nPoints);
170   pvector_copy_inplace((char *)temp, (char *)(mdl->P_Evec), 0, mdl->o);
171   pvector_free(mdl->P_Evec, 0);
172   mdl->P_Evec = (Matrix **)temp;
173   temp = pvector_alloc(0, nPoints);
174   pvector_copy_inplace((char *)temp, (char *)(mdl->P_Eval), 0, mdl->o);
175   pvector_free(mdl->P_Eval, 0);
176   mdl->P_Eval = (Vector **)temp;
177   for (i = mdl->o; i < nPoints; i++)
178   {
179     mdl->P_Evec[i] = matrix_alloc((2*mdl->r)-1, (2*mdl->r)-1, 
180                                   matrix_full, double_v);
181     mdl->P_Eval[i] = vector_alloc((2*mdl->r)-1, double_v);
182   }
183 
184   mdl->c = nPoints;
185 
186   return (mdl);
187 }
188 
189 

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