int gsl_integration_qawo_table_set (gsl_integration_qawo_table * t, double omega, double L, enum gsl_integration_qawo_enum sine) { t->omega = omega; t->sine = sine; t->L = L; t->par = 0.5 * omega * L; /* recompute the moments */ { size_t i; double scale = 1.0; for (i = 0 ; i < t->n; i++) { compute_moments (t->par * scale, t->chebmo + 25*i); scale *= 0.5; } } return GSL_SUCCESS; }
int gsl_integration_qawo_table_set_length (gsl_integration_qawo_table * t, double L) { /* return immediately if the length is the same as the old length */ if (L == t->L) return GSL_SUCCESS; /* otherwise reset the table and compute the new parameters */ t->L = L; t->par = 0.5 * t->omega * L; /* recompute the moments */ { size_t i; double scale = 1.0; for (i = 0 ; i < t->n; i++) { compute_moments (t->par * scale, t->chebmo + 25*i); scale *= 0.5; } } return GSL_SUCCESS; }
static PyObject * blob_moments( PyObject *self, PyObject *args, PyObject *kwds){ PyArrayObject *r = NULL; int verbose = 0 ; static char *kwlist[] = { "res", "verbose", NULL }; if(!PyArg_ParseTupleAndKeywords(args, kwds, "O!|i", kwlist, &PyArray_Type, &r, &verbose)) return NULL; if (r->dimensions[1] != NPROPERTY || r->descr->type_num != PyArray_DOUBLE ){ PyErr_SetString(PyExc_ValueError, "Results array looks corrupt\n"); return NULL; } Py_BEGIN_ALLOW_THREADS; if(verbose){ printf("Welcome to blob_moments\n"); printf("%p r->data\n\n",r->data); printf("dim[0] = %d dim[1] = %d\n",r->dimensions[0], r->dimensions[1]); } compute_moments( (double *) r->data, r->dimensions[0] ); Py_END_ALLOW_THREADS; Py_INCREF(Py_None); return Py_None; }
static void qc25c (gsl_function * f, double a, double b, double c, double *result, double *abserr, int *err_reliable) { double cc = (2 * c - b - a) / (b - a); if (fabs (cc) > 1.1) { double resabs, resasc; gsl_function weighted_function; struct fn_cauchy_params fn_params; fn_params.function = f; fn_params.singularity = c; weighted_function.function = &fn_cauchy; weighted_function.params = &fn_params; gsl_integration_qk15 (&weighted_function, a, b, result, abserr, &resabs, &resasc); if (*abserr == resasc) { *err_reliable = 0; } else { *err_reliable = 1; } return; } else { double cheb12[13], cheb24[25], moment[25]; double res12 = 0, res24 = 0; size_t i; gsl_integration_qcheb (f, a, b, cheb12, cheb24); compute_moments (cc, moment); for (i = 0; i < 13; i++) { res12 += cheb12[i] * moment[i]; } for (i = 0; i < 25; i++) { res24 += cheb24[i] * moment[i]; } *result = res24; *abserr = fabs(res24 - res12) ; *err_reliable = 0; return; } }
gsl_integration_qawo_table * gsl_integration_qawo_table_alloc (double omega, double L, enum gsl_integration_qawo_enum sine, size_t n) { gsl_integration_qawo_table *t; double * chebmo; if (n == 0) { GSL_ERROR_VAL ("table length n must be positive integer", GSL_EDOM, 0); } t = (gsl_integration_qawo_table *) malloc (sizeof (gsl_integration_qawo_table)); if (t == 0) { GSL_ERROR_VAL ("failed to allocate space for qawo_table struct", GSL_ENOMEM, 0); } chebmo = (double *) malloc (25 * n * sizeof (double)); if (chebmo == 0) { free (t); GSL_ERROR_VAL ("failed to allocate space for chebmo block", GSL_ENOMEM, 0); } t->n = n; t->sine = sine; t->omega = omega; t->L = L; t->par = 0.5 * omega * L; t->chebmo = chebmo; /* precompute the moments */ { size_t i; double scale = 1.0; for (i = 0 ; i < t->n; i++) { compute_moments (t->par * scale, t->chebmo + 25*i); scale *= 0.5; } } return t; }
int RAPID_model::build_hierarchy() { // allocate the boxes and set the box list globals num_boxes_alloced = num_tris * 2; b = new box[num_boxes_alloced]; if (b == 0) return RAPID_ERR_MODEL_OUT_OF_MEMORY; RAPID_boxes = b; RAPID_boxes_inited = 1; // we are in process of initializing b[0]. // Determine initial orientation, mean point, and splitting axis. int i; accum M; // double F1[3]; // double S1[6]; double C[3][3]; RAPID_moment = new moment[num_tris]; if (RAPID_moment == 0) { delete [] b; return RAPID_ERR_MODEL_OUT_OF_MEMORY; } compute_moments(RAPID_moment, tris, num_tris); clear_accum(M); for(i=0; i<num_tris; i++) accum_moment(M, RAPID_moment[i]); mean_from_accum(b[0].pT, M); covariance_from_accum(C, M); eigen_and_sort1(b[0].pR, C); // create the index list int *t = new int[num_tris]; if (t == 0) { delete [] b; delete [] RAPID_moment; return RAPID_ERR_MODEL_OUT_OF_MEMORY; } for(i=0; i<num_tris; i++) t[i] = i; // set the tri pointer RAPID_tri = tris; // do the build int rc = b[0].split_recurse(t, num_tris); if (rc != RAPID_OK) { delete [] b; delete [] RAPID_moment; delete [] t; return RAPID_ERR_MODEL_OUT_OF_MEMORY; } // free the moment list delete [] RAPID_moment; RAPID_moment = 0; // null the tri pointer RAPID_tri = 0; // free the index list delete [] t; return RAPID_OK; }
int build_recurse(PQP_Model *m, int bn, int first_tri, int num_tris) { BV *b = m->child(bn); // compute a rotation matrix PQP_REAL C[3][3], E[3][3], R[3][3], s[3], axis[3], mean[3], coord; #if RAPID2_FIT moment *tri_moment = new moment[num_tris]; compute_moments(tri_moment, &(m->tris[first_tri]), num_tris); accum acc; clear_accum(acc); for(int i = 0; i < num_tris; i++) accum_moment(acc, tri_moment[i]); delete [] tri_moment; covariance_from_accum(C,acc); #else get_covariance_triverts(C,&m->tris[first_tri],num_tris); #endif Meigen(E, s, C); // place axes of E in order of increasing s int min, mid, max; if (s[0] > s[1]) { max = 0; min = 1; } else { min = 0; max = 1; } if (s[2] < s[min]) { mid = min; min = 2; } else if (s[2] > s[max]) { mid = max; max = 2; } else { mid = 2; } McolcMcol(R,0,E,max); McolcMcol(R,1,E,mid); R[0][2] = E[1][max]*E[2][mid] - E[1][mid]*E[2][max]; R[1][2] = E[0][mid]*E[2][max] - E[0][max]*E[2][mid]; R[2][2] = E[0][max]*E[1][mid] - E[0][mid]*E[1][max]; // fit the BV b->FitToTris(R, &m->tris[first_tri], num_tris); if (num_tris == 1) { // BV is a leaf BV - first_child will index a triangle b->first_child = -(first_tri + 1); } else if (num_tris > 1) { // BV not a leaf - first_child will index a BV b->first_child = m->num_bvs; m->num_bvs+=2; // choose splitting axis and splitting coord McolcV(axis,R,0); #if RAPID2_FIT mean_from_accum(mean,acc); #else get_centroid_triverts(mean,&m->tris[first_tri],num_tris); #endif coord = VdotV(axis, mean); // now split int num_first_half = split_tris(&m->tris[first_tri], num_tris, axis, coord); // recursively build the children build_recurse(m, m->child(bn)->first_child, first_tri, num_first_half); build_recurse(m, m->child(bn)->first_child + 1, first_tri + num_first_half, num_tris - num_first_half); } return PQP_OK; }