Revision: 69082 http://sourceforge.net/p/brlcad/code/69082 Author: starseeker Date: 2016-10-16 21:06:49 +0000 (Sun, 16 Oct 2016) Log Message: ----------- put oslo files with the rest of the nmg nurbs logic in bspline.
Modified Paths: -------------- brlcad/trunk/src/librt/CMakeLists.txt Added Paths: ----------- brlcad/trunk/src/librt/primitives/bspline/nurb_oslo_calc.c brlcad/trunk/src/librt/primitives/bspline/nurb_oslo_map.c Removed Paths: ------------- brlcad/trunk/src/librt/oslo_calc.c brlcad/trunk/src/librt/oslo_map.c Modified: brlcad/trunk/src/librt/CMakeLists.txt =================================================================== --- brlcad/trunk/src/librt/CMakeLists.txt 2016-10-16 21:03:29 UTC (rev 69081) +++ brlcad/trunk/src/librt/CMakeLists.txt 2016-10-16 21:06:49 UTC (rev 69082) @@ -72,8 +72,6 @@ memalloc.c mkbundle.c op.c - oslo_calc.c - oslo_map.c pr.c prep.c primitives/arb8/arb8.c @@ -120,6 +118,8 @@ primitives/bspline/nurb_interp.c primitives/bspline/nurb_knot.c primitives/bspline/nurb_norm.c + primitives/bspline/nurb_oslo_calc.c + primitives/bspline/nurb_oslo_map.c primitives/bspline/nurb_plot.c primitives/bspline/nurb_poly.c primitives/bspline/nurb_ray.c Deleted: brlcad/trunk/src/librt/oslo_calc.c =================================================================== --- brlcad/trunk/src/librt/oslo_calc.c 2016-10-16 21:03:29 UTC (rev 69081) +++ brlcad/trunk/src/librt/oslo_calc.c 2016-10-16 21:06:49 UTC (rev 69082) @@ -1,234 +0,0 @@ -/* O S L O _ C A L C . C - * BRL-CAD - * - * Copyright (c) 1986-2016 United States Government as represented by - * the U.S. Army Research Laboratory. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this file; see the file named COPYING for more - * information. - */ -/** @addtogroup librt */ -/** @{ */ -/** @file librt/oslo_calc.c - * - * Calculate the Oslo refinement matrix. - * - * This algorithm was taken from the paper: - * - * "Making the Oslo Algorithm More Efficient" by T. Lyche and K. Morken - * - * The algorithm referenced in the paper is algorithm 1 since we will - * be dealing mostly with surfaces. This routine computes the - * refinement matrix and returns a oslo structure which will allow a - * new curve or surface to be built. - * - * Since we only want the last row of the alpha's as outlined in the - * paper we can use a one dimensional array for the ah. - */ - -#include "common.h" - -#include "bio.h" - -#include "vmath.h" -#include "nmg.h" -#include "raytrace.h" - -#define AMAX(i, j) ((i) > (j) ? (i) : (j)) -#define AMIN(i, j) ((i) < (j) ? (i) : (j)) - -struct oslo_mat * -nmg_nurb_calc_oslo(register int order, register const struct knot_vector *tau_kv, register struct knot_vector *t_kv) - -/* old knot vector */ -/* new knot vector */ - -{ - register fastf_t *t_p; - register const fastf_t *tau_p; - fastf_t ah[20]; - fastf_t newknots[20]; /* new knots */ - register int j; /* d(j), j = 0 : # of new ctl points */ - int mu, /* mu: tau[mu] <= t[j] < tau[mu+1]*/ - muprim, - v, /* Nu value (order of matrix) */ - p, - iu, /* upper bound loop counter */ - il, /* lower bound loop counter */ - ih, - n1; /* upper bound of t knot vector - order*/ - - fastf_t tj; - - struct oslo_mat * head, * o_ptr, *new_o; - - n1 = t_kv->k_size - order; - - t_p = t_kv->knots; - tau_p = tau_kv->knots; - - mu = 0; /* initialize mu */ - - head = (struct oslo_mat *) bu_malloc ( - sizeof(struct oslo_mat), - "nmg_nurb_calc_oslo: oslo mat head"); - - o_ptr = head; - - for (j = 0; j < n1; j++) { - register int i; - - if (j != 0) { - new_o = (struct oslo_mat *) bu_malloc ( - sizeof(struct oslo_mat), - "nmg_nurb_calc_oslo: oslo mat struct"); - - o_ptr->next = new_o; - o_ptr = new_o; - } - - /* find the bounding mu */ - while (tau_p[mu + 1] <= t_p[j]) mu++; - - muprim = mu; - - i = j + 1; - - while (ZERO(t_p[i] - tau_p[muprim]) && i < (j + order)) { - i++; - muprim--; - } - - ih = muprim + 1; - - for (v = 0, p = 1; p < order; p++) { - if (ZERO(t_p[j + p] - tau_p[ih])) - ih++; - else - newknots[++v - 1] = t_p[j + p]; - } - - ah[order-1] = 1.0; - - for (p = 1; p <= v; p++) { - - fastf_t beta1; - int o_m; - - beta1 = 0.0; - o_m = order - muprim; - - tj = newknots[p-1]; - - if (p > muprim) { - beta1 = ah[o_m]; - beta1 = ((tj - tau_p[0]) * beta1) / - (tau_p[p + order - v] - tau_p[0]); - } - i = muprim - p + 1; - il = AMAX (1, i); - i = n1 - 1 + v - p; - iu = AMIN (muprim, i); - - for (i = il; i <= iu; i++) { - fastf_t d1, d2; - fastf_t beta; - - d1 = tj - tau_p[i]; - d2 = tau_p[i + p + order - v - 1] - tj; - - beta = ah[i + o_m - 1] / (d1 + d2); - - ah[i + o_m - 2] = d2 * beta + beta1; - beta1 = d1 * beta; - } - - ah[iu + o_m - 1] = beta1; - - if (iu < muprim) { - register fastf_t kkk; - register fastf_t ahv; - - kkk = tau_p[n1 - 1 + order]; - ahv = ah[iu + o_m]; - ah[iu + o_m - 1] = - beta1 + (kkk - tj) * - ahv / (kkk - tau_p[iu + 1]); - } - } - - o_ptr->o_vec = (fastf_t *) bu_malloc (sizeof(fastf_t) * (v+1), - "nmg_nurb_calc_oslo: oslo vector"); - - o_ptr->offset = AMAX(muprim -v, 0); - o_ptr->osize = v; - - for (i = v, p = 0; i >= 0; i--) - o_ptr->o_vec[p++] = ah[(order-1) - i]; - } - - o_ptr->next = (struct oslo_mat*) 0; - return head; -} - - -/** - * For debugging purposes only - */ -void -nmg_nurb_pr_oslo(struct oslo_mat *om) -{ - struct oslo_mat * omp; - int j; - - for (omp = om; omp!= (struct oslo_mat *) 0; omp = omp->next) { - fprintf(stderr, "%p offset %d osize %d next %p\n", - (void *)omp, omp->offset, omp->osize, - (void *)omp->next); - - fprintf(stderr, "\t%f", omp->o_vec[0]); - - for (j = 1; j <= omp->osize; j++) - fprintf(stderr, "\t%f", omp->o_vec[j]); - fprintf(stderr, "\n"); - } -} - - -/** - * Free up the structures and links for the oslo matrix. - */ -void -nmg_nurb_free_oslo(struct oslo_mat *om) -{ - register struct oslo_mat * omp; - - while (om != (struct oslo_mat *) 0) { - omp = om; - om = om->next; - bu_free((char *)omp->o_vec, "nmg_nurb_free_oslo: ovec"); - bu_free((char *)omp, "nmg_nurb_free_oslo: struct oslo"); - } -} - - -/** @} */ -/* - * Local Variables: - * mode: C - * tab-width: 8 - * indent-tabs-mode: t - * c-file-style: "stroustrup" - * End: - * ex: shiftwidth=4 tabstop=8 - */ Deleted: brlcad/trunk/src/librt/oslo_map.c =================================================================== --- brlcad/trunk/src/librt/oslo_map.c 2016-10-16 21:03:29 UTC (rev 69081) +++ brlcad/trunk/src/librt/oslo_map.c 2016-10-16 21:06:49 UTC (rev 69082) @@ -1,102 +0,0 @@ -/* O S L O _ M A P . C - * BRL-CAD - * - * Copyright (c) 1990-2016 United States Government as represented by - * the U.S. Army Research Laboratory. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this file; see the file named COPYING for more - * information. - */ -/** @addtogroup nurb */ -/** @{ */ -/** @file librt/oslo_map.c - * - * Map the oslo matrix with the old curve resulting in a new one. - * - */ - -#include "common.h" - -#include "bio.h" - -#include "vmath.h" -#include "nmg.h" -#include "raytrace.h" - -/* This routine takes a oslo refinement matrix as described in the - * paper "Making the Oslo Algorithm More Efficient" and maps it to the - * old control points resulting in new control points. (this - * procedure should probably never called by a user program but should - * remain internal to the library. Bounds are given to facilitate - * easier splitting of the surface. - */ - -void -nmg_nurb_map_oslo(struct oslo_mat *oslo, fastf_t *old_pts, fastf_t *new_pts, int o_stride, int n_stride, int lower, int upper, int pt_type) -/* Oslo matrix */ -/* Old control points */ -/* New control points */ -/* inc to next point of old mesh*/ -/* inc to next point of new mesh*/ -/* Upper and lower bounds for curve generation */ - -{ - register fastf_t *c_ptr; /* new curve pointer */ - register fastf_t *o_pts; - register struct oslo_mat *o_ptr; /* oslo matrix pointer */ - register int k; - int j, /* j loop */ - i; /* oslo loop */ - int coords; - - coords = RT_NURB_EXTRACT_COORDS(pt_type); - - c_ptr = new_pts; - - if (lower != 0) - for (i = 0, o_ptr = oslo; i < lower; i++, o_ptr = - o_ptr->next) - ; - else - o_ptr = oslo; - - for (j = lower; j < upper; j++, o_ptr = o_ptr->next) { - fastf_t o_scale; - o_pts = &old_pts[(o_ptr->offset * o_stride)]; - - o_scale = o_ptr->o_vec[0]; - - for (k = 0; k < coords; k++) - c_ptr[k] = o_pts[k] * o_scale; - - for (i = 1; i <= o_ptr->osize; i++) { - o_scale = o_ptr->o_vec[i]; - o_pts += o_stride; - for (k = 0; k < coords; k++) - c_ptr[k] += o_scale * o_pts[k]; - } - c_ptr += n_stride; - } -} - - -/** @} */ -/* - * Local Variables: - * mode: C - * tab-width: 8 - * indent-tabs-mode: t - * c-file-style: "stroustrup" - * End: - * ex: shiftwidth=4 tabstop=8 - */ Copied: brlcad/trunk/src/librt/primitives/bspline/nurb_oslo_calc.c (from rev 69080, brlcad/trunk/src/librt/oslo_calc.c) =================================================================== --- brlcad/trunk/src/librt/primitives/bspline/nurb_oslo_calc.c (rev 0) +++ brlcad/trunk/src/librt/primitives/bspline/nurb_oslo_calc.c 2016-10-16 21:06:49 UTC (rev 69082) @@ -0,0 +1,234 @@ +/* O S L O _ C A L C . C + * BRL-CAD + * + * Copyright (c) 1986-2016 United States Government as represented by + * the U.S. Army Research Laboratory. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this file; see the file named COPYING for more + * information. + */ +/** @addtogroup librt */ +/** @{ */ +/** @file librt/oslo_calc.c + * + * Calculate the Oslo refinement matrix. + * + * This algorithm was taken from the paper: + * + * "Making the Oslo Algorithm More Efficient" by T. Lyche and K. Morken + * + * The algorithm referenced in the paper is algorithm 1 since we will + * be dealing mostly with surfaces. This routine computes the + * refinement matrix and returns a oslo structure which will allow a + * new curve or surface to be built. + * + * Since we only want the last row of the alpha's as outlined in the + * paper we can use a one dimensional array for the ah. + */ + +#include "common.h" + +#include "bio.h" + +#include "vmath.h" +#include "nmg.h" +#include "raytrace.h" + +#define AMAX(i, j) ((i) > (j) ? (i) : (j)) +#define AMIN(i, j) ((i) < (j) ? (i) : (j)) + +struct oslo_mat * +nmg_nurb_calc_oslo(register int order, register const struct knot_vector *tau_kv, register struct knot_vector *t_kv) + +/* old knot vector */ +/* new knot vector */ + +{ + register fastf_t *t_p; + register const fastf_t *tau_p; + fastf_t ah[20]; + fastf_t newknots[20]; /* new knots */ + register int j; /* d(j), j = 0 : # of new ctl points */ + int mu, /* mu: tau[mu] <= t[j] < tau[mu+1]*/ + muprim, + v, /* Nu value (order of matrix) */ + p, + iu, /* upper bound loop counter */ + il, /* lower bound loop counter */ + ih, + n1; /* upper bound of t knot vector - order*/ + + fastf_t tj; + + struct oslo_mat * head, * o_ptr, *new_o; + + n1 = t_kv->k_size - order; + + t_p = t_kv->knots; + tau_p = tau_kv->knots; + + mu = 0; /* initialize mu */ + + head = (struct oslo_mat *) bu_malloc ( + sizeof(struct oslo_mat), + "nmg_nurb_calc_oslo: oslo mat head"); + + o_ptr = head; + + for (j = 0; j < n1; j++) { + register int i; + + if (j != 0) { + new_o = (struct oslo_mat *) bu_malloc ( + sizeof(struct oslo_mat), + "nmg_nurb_calc_oslo: oslo mat struct"); + + o_ptr->next = new_o; + o_ptr = new_o; + } + + /* find the bounding mu */ + while (tau_p[mu + 1] <= t_p[j]) mu++; + + muprim = mu; + + i = j + 1; + + while (ZERO(t_p[i] - tau_p[muprim]) && i < (j + order)) { + i++; + muprim--; + } + + ih = muprim + 1; + + for (v = 0, p = 1; p < order; p++) { + if (ZERO(t_p[j + p] - tau_p[ih])) + ih++; + else + newknots[++v - 1] = t_p[j + p]; + } + + ah[order-1] = 1.0; + + for (p = 1; p <= v; p++) { + + fastf_t beta1; + int o_m; + + beta1 = 0.0; + o_m = order - muprim; + + tj = newknots[p-1]; + + if (p > muprim) { + beta1 = ah[o_m]; + beta1 = ((tj - tau_p[0]) * beta1) / + (tau_p[p + order - v] - tau_p[0]); + } + i = muprim - p + 1; + il = AMAX (1, i); + i = n1 - 1 + v - p; + iu = AMIN (muprim, i); + + for (i = il; i <= iu; i++) { + fastf_t d1, d2; + fastf_t beta; + + d1 = tj - tau_p[i]; + d2 = tau_p[i + p + order - v - 1] - tj; + + beta = ah[i + o_m - 1] / (d1 + d2); + + ah[i + o_m - 2] = d2 * beta + beta1; + beta1 = d1 * beta; + } + + ah[iu + o_m - 1] = beta1; + + if (iu < muprim) { + register fastf_t kkk; + register fastf_t ahv; + + kkk = tau_p[n1 - 1 + order]; + ahv = ah[iu + o_m]; + ah[iu + o_m - 1] = + beta1 + (kkk - tj) * + ahv / (kkk - tau_p[iu + 1]); + } + } + + o_ptr->o_vec = (fastf_t *) bu_malloc (sizeof(fastf_t) * (v+1), + "nmg_nurb_calc_oslo: oslo vector"); + + o_ptr->offset = AMAX(muprim -v, 0); + o_ptr->osize = v; + + for (i = v, p = 0; i >= 0; i--) + o_ptr->o_vec[p++] = ah[(order-1) - i]; + } + + o_ptr->next = (struct oslo_mat*) 0; + return head; +} + + +/** + * For debugging purposes only + */ +void +nmg_nurb_pr_oslo(struct oslo_mat *om) +{ + struct oslo_mat * omp; + int j; + + for (omp = om; omp!= (struct oslo_mat *) 0; omp = omp->next) { + fprintf(stderr, "%p offset %d osize %d next %p\n", + (void *)omp, omp->offset, omp->osize, + (void *)omp->next); + + fprintf(stderr, "\t%f", omp->o_vec[0]); + + for (j = 1; j <= omp->osize; j++) + fprintf(stderr, "\t%f", omp->o_vec[j]); + fprintf(stderr, "\n"); + } +} + + +/** + * Free up the structures and links for the oslo matrix. + */ +void +nmg_nurb_free_oslo(struct oslo_mat *om) +{ + register struct oslo_mat * omp; + + while (om != (struct oslo_mat *) 0) { + omp = om; + om = om->next; + bu_free((char *)omp->o_vec, "nmg_nurb_free_oslo: ovec"); + bu_free((char *)omp, "nmg_nurb_free_oslo: struct oslo"); + } +} + + +/** @} */ +/* + * Local Variables: + * mode: C + * tab-width: 8 + * indent-tabs-mode: t + * c-file-style: "stroustrup" + * End: + * ex: shiftwidth=4 tabstop=8 + */ Copied: brlcad/trunk/src/librt/primitives/bspline/nurb_oslo_map.c (from rev 69080, brlcad/trunk/src/librt/oslo_map.c) =================================================================== --- brlcad/trunk/src/librt/primitives/bspline/nurb_oslo_map.c (rev 0) +++ brlcad/trunk/src/librt/primitives/bspline/nurb_oslo_map.c 2016-10-16 21:06:49 UTC (rev 69082) @@ -0,0 +1,102 @@ +/* O S L O _ M A P . C + * BRL-CAD + * + * Copyright (c) 1990-2016 United States Government as represented by + * the U.S. Army Research Laboratory. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this file; see the file named COPYING for more + * information. + */ +/** @addtogroup nurb */ +/** @{ */ +/** @file librt/oslo_map.c + * + * Map the oslo matrix with the old curve resulting in a new one. + * + */ + +#include "common.h" + +#include "bio.h" + +#include "vmath.h" +#include "nmg.h" +#include "raytrace.h" + +/* This routine takes a oslo refinement matrix as described in the + * paper "Making the Oslo Algorithm More Efficient" and maps it to the + * old control points resulting in new control points. (this + * procedure should probably never called by a user program but should + * remain internal to the library. Bounds are given to facilitate + * easier splitting of the surface. + */ + +void +nmg_nurb_map_oslo(struct oslo_mat *oslo, fastf_t *old_pts, fastf_t *new_pts, int o_stride, int n_stride, int lower, int upper, int pt_type) +/* Oslo matrix */ +/* Old control points */ +/* New control points */ +/* inc to next point of old mesh*/ +/* inc to next point of new mesh*/ +/* Upper and lower bounds for curve generation */ + +{ + register fastf_t *c_ptr; /* new curve pointer */ + register fastf_t *o_pts; + register struct oslo_mat *o_ptr; /* oslo matrix pointer */ + register int k; + int j, /* j loop */ + i; /* oslo loop */ + int coords; + + coords = RT_NURB_EXTRACT_COORDS(pt_type); + + c_ptr = new_pts; + + if (lower != 0) + for (i = 0, o_ptr = oslo; i < lower; i++, o_ptr = + o_ptr->next) + ; + else + o_ptr = oslo; + + for (j = lower; j < upper; j++, o_ptr = o_ptr->next) { + fastf_t o_scale; + o_pts = &old_pts[(o_ptr->offset * o_stride)]; + + o_scale = o_ptr->o_vec[0]; + + for (k = 0; k < coords; k++) + c_ptr[k] = o_pts[k] * o_scale; + + for (i = 1; i <= o_ptr->osize; i++) { + o_scale = o_ptr->o_vec[i]; + o_pts += o_stride; + for (k = 0; k < coords; k++) + c_ptr[k] += o_scale * o_pts[k]; + } + c_ptr += n_stride; + } +} + + +/** @} */ +/* + * Local Variables: + * mode: C + * tab-width: 8 + * indent-tabs-mode: t + * c-file-style: "stroustrup" + * End: + * ex: shiftwidth=4 tabstop=8 + */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ BRL-CAD Source Commits mailing list brlcad-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/brlcad-commits