nurb_refine.c

Go to the documentation of this file.
00001 /*                   N U R B _ R E F I N E . C
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 1986-2006 United States Government as represented by
00005  * the U.S. Army Research Laboratory.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License
00009  * as published by the Free Software Foundation; either version 2 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this file; see the file named COPYING for more
00019  * information.
00020  */
00021 
00022 /** @addtogroup nurb */
00023 /*@{*/
00024 /** @file nurb_refine.c
00025  *     Refines a surface by inserting knots with respect to the row or
00026  *     columns of the control points resulting in the same surface with new
00027  *     control points.
00028  *
00029  * Author -
00030  *     Paul R. Stay
00031  *
00032  * Source -
00033  *     SECAD/VLD Computing Consortium, Bldg 394
00034  *     The U.S. Army Ballistic Research Laboratory
00035  *     Aberdeen Proving Ground, Maryland 21005
00036  *
00037  */
00038 /*@}*/
00039 
00040 #include "common.h"
00041 
00042 
00043 
00044 #include <stdio.h>
00045 #include "machine.h"
00046 #include "vmath.h"
00047 #include "nmg.h"
00048 #include "raytrace.h"
00049 #include "nurb.h"
00050 
00051 /*
00052  *                      R T _ N U R B _ S _ R E F I N E
00053  *
00054  *  Returns a refined surface.
00055  *  The original surface is unmodified.
00056  */
00057 struct face_g_snurb *
00058 rt_nurb_s_refine(const struct face_g_snurb *srf, int dir, struct knot_vector *kv, struct resource *res)
00059                                                 /* Old surface to be refined */
00060                                         /* Direction to refine */
00061                                         /* Row = 0, Col = 1 */
00062                                         /* New knot vector */
00063 
00064 {
00065         register struct face_g_snurb * nurb_srf;
00066         struct oslo_mat *oslo;  /* oslo refinement matrix */
00067         int i;
00068 
00069         NMG_CK_SNURB(srf);
00070 
00071         if (dir == RT_NURB_SPLIT_ROW) {         /* Row (u) direction */
00072                 GET_SNURB(nurb_srf);
00073                 nurb_srf->order[0] = srf->order[0];
00074                 nurb_srf->order[1] = srf->order[1];
00075 
00076                 rt_nurb_kvcopy(&nurb_srf->u, kv, res);
00077                 rt_nurb_kvcopy(&nurb_srf->v, &srf->v, res);
00078 
00079                 nurb_srf->s_size[0] = srf->s_size[0];
00080                 nurb_srf->s_size[1] = kv->k_size - srf->order[0];
00081                 nurb_srf->pt_type = srf->pt_type;
00082                 nurb_srf->ctl_points = (fastf_t *)
00083                                 bu_malloc( sizeof (fastf_t) *
00084                                 nurb_srf->s_size[0] *
00085                                 nurb_srf->s_size[1] *
00086                                 RT_NURB_EXTRACT_COORDS( nurb_srf->pt_type),
00087                                 "rt_nurb_s_refine: row mesh control points");
00088 
00089                 oslo = (struct oslo_mat *)
00090                       rt_nurb_calc_oslo (srf -> order[RT_NURB_SPLIT_ROW], &srf->u, kv, res);
00091 
00092                 for( i = 0; i < nurb_srf->s_size[0]; i++)
00093                 {
00094                         fastf_t * old_mesh_ptr;
00095                         fastf_t * new_mesh_ptr;
00096 
00097                         old_mesh_ptr = &srf->ctl_points[
00098                                 i * srf->s_size[1] *
00099                                 RT_NURB_EXTRACT_COORDS( srf->pt_type)];
00100                         new_mesh_ptr = &nurb_srf->ctl_points[
00101                                 i * nurb_srf->s_size[1] *
00102                                 RT_NURB_EXTRACT_COORDS( nurb_srf->pt_type)];
00103                         rt_nurb_map_oslo( oslo, old_mesh_ptr, new_mesh_ptr,
00104                                 RT_NURB_EXTRACT_COORDS( srf->pt_type ),
00105                                 RT_NURB_EXTRACT_COORDS( nurb_srf->pt_type ),
00106                                 0, kv->k_size - nurb_srf->order[0],
00107                                 nurb_srf->pt_type);
00108                 }
00109 
00110                 rt_nurb_free_oslo(oslo, res);
00111 
00112         } else  {               /* Col (v) direction */
00113                 GET_SNURB(nurb_srf);
00114                 nurb_srf->order[0] = srf->order[0];
00115                 nurb_srf->order[1] = srf->order[1];
00116 
00117                 rt_nurb_kvcopy(&nurb_srf->u, &srf->u, res);
00118                 rt_nurb_kvcopy(&nurb_srf->v, kv, res);
00119 
00120                 nurb_srf->s_size[0] = kv->k_size - srf->order[1];
00121                 nurb_srf->s_size[1] = srf->s_size[1];
00122 
00123                 nurb_srf->pt_type = srf->pt_type;
00124                 nurb_srf->ctl_points = (fastf_t *)
00125                                 bu_malloc( sizeof (fastf_t) *
00126                                 nurb_srf->s_size[0] *
00127                                 nurb_srf->s_size[1] *
00128                                 RT_NURB_EXTRACT_COORDS( nurb_srf->pt_type),
00129                                 "rt_nurb_s_refine: row mesh control points");
00130 
00131                 oslo = (struct oslo_mat *)
00132                       rt_nurb_calc_oslo (srf->order[RT_NURB_SPLIT_COL], &srf->v, kv, res);
00133 
00134                 for( i = 0; i < nurb_srf->s_size[1]; i++)
00135                 {
00136                         fastf_t * old_mesh_ptr;
00137                         fastf_t * new_mesh_ptr;
00138 
00139                         old_mesh_ptr = &srf->ctl_points[
00140                                 i * RT_NURB_EXTRACT_COORDS( srf->pt_type)];
00141                         new_mesh_ptr = &nurb_srf->ctl_points[
00142                                 i * RT_NURB_EXTRACT_COORDS( nurb_srf->pt_type)];
00143                         rt_nurb_map_oslo( oslo, old_mesh_ptr, new_mesh_ptr,
00144                                 srf->s_size[1] *
00145                                 RT_NURB_EXTRACT_COORDS( srf->pt_type ),
00146                                 nurb_srf->s_size[1] *
00147                                 RT_NURB_EXTRACT_COORDS( nurb_srf->pt_type ),
00148                                 0, kv->k_size - nurb_srf->order[1],
00149                                 nurb_srf->pt_type);
00150                 }
00151                 rt_nurb_free_oslo( oslo, res );
00152         }
00153         return nurb_srf;
00154 }
00155 
00156 struct edge_g_cnurb *
00157 rt_nurb_c_refine(const struct edge_g_cnurb *crv, struct knot_vector *kv)
00158 {
00159         struct oslo_mat * oslo;
00160         struct edge_g_cnurb * new_crv;
00161         int i, coords;
00162 
00163         NMG_CK_CNURB(crv);
00164 
00165         coords = RT_NURB_EXTRACT_COORDS( crv->pt_type);
00166 
00167         new_crv = ( struct edge_g_cnurb *) rt_nurb_new_cnurb(
00168                 crv->order, kv->k_size, kv->k_size - crv->order,
00169                 crv->pt_type);
00170 
00171         oslo = (struct oslo_mat *) rt_nurb_calc_oslo(
00172                 crv->order, &crv->k, kv, (struct resource *)NULL);
00173 
00174         rt_nurb_map_oslo( oslo, crv->ctl_points,
00175                 new_crv->ctl_points,
00176                 coords, coords, 0,
00177                 kv->k_size - new_crv->order,
00178                 new_crv->pt_type);
00179 
00180         new_crv->k.k_size = kv->k_size;
00181 
00182         for( i = 0; i < kv->k_size; i++)
00183                 new_crv->k.knots[i] = kv->knots[i];
00184 
00185         rt_nurb_free_oslo( oslo, (struct resource *)NULL );
00186 
00187         return new_crv;
00188 }
00189 
00190 /*
00191  * Local Variables:
00192  * mode: C
00193  * tab-width: 8
00194  * c-basic-offset: 4
00195  * indent-tabs-mode: t
00196  * End:
00197  * ex: shiftwidth=4 tabstop=8
00198  */

Generated on Mon Sep 18 01:24:55 2006 for BRL-CAD by  doxygen 1.4.6