nurb.h

Go to the documentation of this file.
00001 /*                          N U R B . H
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 1991-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.1 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 /** @addtogroup nurb */
00022 /*@{*/
00023 /** @file nurb.h
00024  *
00025  * @brief
00026  *      Define surface and curve structures for
00027  *      Non Rational Uniform B-Spline (NURB)
00028  *      curves and surfaces.
00029  *
00030  *
00031  *  @author     Paul Randal Stay
00032  *
00033  *  @par Source
00034  *      SECAD/VLD Computing Consortium, Bldg 394
00035  *@n    The U.S. Army Ballistic Research Laboratory
00036  *@n    Aberdeen Proving Ground, Maryland 21005
00037  *
00038  *  $Header: /cvsroot/brlcad/brlcad/include/nurb.h,v 14.9 2006/09/18 05:24:07 lbutler Exp $
00039  */
00040 
00041 #ifndef NURB_H
00042 #define NURB_H seen
00043 
00044 #include "common.h"
00045 
00046 /* make sure all the prerequisite include files have been included
00047  */
00048 #ifndef MACHINE_H
00049 # include "machine.h"
00050 #endif
00051 
00052 #ifndef VMATH_H
00053 # include "vmath.h"
00054 #endif
00055 
00056 #include "nmg.h"
00057 
00058 #ifndef RAYTRACE_H
00059 # include "raytrace.h"
00060 #endif
00061 
00062 /* Define parametric directions for splitting. */
00063 
00064 #define RT_NURB_SPLIT_ROW 0
00065 #define RT_NURB_SPLIT_COL 1
00066 #define RT_NURB_SPLIT_FLAT 2
00067 
00068 /* Definition of NURB point types and coordinates
00069  * Bit:   8765 4321 0
00070  *       |nnnn|tttt|h
00071  *                      h     - 1 if Homogeneous
00072  *                      tttt  - point type
00073  *                              1 = XY
00074  *                              2 = XYZ
00075  *                              3 = UV
00076  *                              4 = Random data
00077  *                              5 = Projected surface
00078  *                      nnnnn - number of coordinates per point
00079  *                              includes the rational coordinate
00080  */
00081 
00082 /* point types */
00083 #define RT_NURB_PT_XY   1                       /**< @brief x,y coordintes */
00084 #define RT_NURB_PT_XYZ  2                       /**< @brief x,y,z coordinates */
00085 #define RT_NURB_PT_UV   3                       /**< @brief trim u,v parameter space */
00086 #define RT_NURB_PT_DATA 4                       /**< @brief random data */
00087 #define RT_NURB_PT_PROJ 5                       /**< @brief Projected Surface */
00088 
00089 #define RT_NURB_PT_RATIONAL     1
00090 #define RT_NURB_PT_NONRAT       0
00091 
00092 #define RT_NURB_MAKE_PT_TYPE(n,t,h)     ((n<<5) | (t<<1) | h)
00093 #define RT_NURB_EXTRACT_COORDS(pt)      (pt>>5)
00094 #define RT_NURB_EXTRACT_PT_TYPE(pt)             ((pt>>1) & 0x0f)
00095 #define RT_NURB_IS_PT_RATIONAL(pt)              (pt & 0x1)
00096 #define RT_NURB_STRIDE(pt)              (RT_NURB_EXTRACT_COORDS(pt) * sizeof( fastf_t))
00097 
00098 /* macros to check/validate a structure pointer
00099  */
00100 #define NMG_CK_KNOT(_p)         BU_CKMAG(_p, RT_KNOT_VECTOR_MAGIC, "knot_vector")
00101 #define NMG_CK_CNURB(_p)        BU_CKMAG(_p, RT_CNURB_MAGIC, "cnurb")
00102 #define NMG_CK_SNURB(_p)        BU_CKMAG(_p, RT_SNURB_MAGIC, "snurb")
00103 
00104 #define GET_CNURB(p/*,m*/)              {BU_GETSTRUCT(p, edge_g_cnurb); \
00105         /* NMG_INCR_INDEX(p,m); */ \
00106         BU_LIST_INIT( &(p)->l ); (p)->l.magic = NMG_EDGE_G_CNURB_MAGIC; }
00107 #define GET_SNURB(p/*,m*/)              {BU_GETSTRUCT(p, face_g_snurb); \
00108         /* NMG_INCR_INDEX(p,m); */ \
00109         BU_LIST_INIT( &(p)->l ); (p)->l.magic = NMG_FACE_G_SNURB_MAGIC; }
00110 
00111 #define RT_CNURB_MAGIC  0x636e7262
00112 
00113 #define RT_SNURB_MAGIC  0x736e7262
00114 
00115 /* ----- Internal structures ----- */
00116 
00117 struct rt_nurb_poly {
00118         struct rt_nurb_poly * next;
00119         point_t         ply[3];         /**< @brief Vertices */
00120         fastf_t         uv[3][2];       /**< @brief U,V parametric values */
00121 };
00122 
00123 struct rt_nurb_uv_hit {
00124         struct rt_nurb_uv_hit * next;
00125         int             sub;
00126         fastf_t         u;
00127         fastf_t         v;
00128 };
00129 
00130 
00131 struct oslo_mat {
00132         struct oslo_mat * next;
00133         int             offset;
00134         int             osize;
00135         fastf_t         * o_vec;
00136 };
00137 
00138 #if !defined(MAX)
00139 # define MAX(i,j)    ( (i) > (j) ? (i) : (j) )
00140 #endif
00141 #if !defined(MIN)
00142 # define MIN(i,j)    ( (i) < (j) ? (i) : (j) )
00143 #endif
00144 
00145 /* --- new way */
00146 
00147 struct bezier_2d_list {
00148         struct bu_list  l;
00149         point2d_t       *ctl;
00150 };
00151 
00152 /* nurb_basis.c */
00153 RT_EXPORT BU_EXTERN(fastf_t rt_nurb_basis_eval, (struct knot_vector *knts, int interval,
00154                         int order, fastf_t mu));
00155 
00156 /* nurb_bezier.c */
00157 RT_EXPORT BU_EXTERN(int rt_nurb_bezier, (struct bu_list *bezier_hd,
00158                         const struct face_g_snurb * srf, struct resource *res));
00159 RT_EXPORT BU_EXTERN(int rt_bez_check, (const struct face_g_snurb * srf));
00160 
00161 /* nurb_bound.c */
00162 RT_EXPORT BU_EXTERN(int rt_nurb_s_bound, (struct face_g_snurb *srf, point_t bmin, point_t bmax));
00163 RT_EXPORT BU_EXTERN(int rt_nurb_c_bound, (struct edge_g_cnurb *crv, point_t bmin, point_t bmax));
00164 RT_EXPORT BU_EXTERN(int rt_nurb_s_check, (struct face_g_snurb *srf));
00165 RT_EXPORT BU_EXTERN(int rt_nurb_c_check, (struct edge_g_cnurb *crv));
00166 
00167 /* nurb_copy.c */
00168 RT_EXPORT BU_EXTERN(struct face_g_snurb *rt_nurb_scopy, (const struct face_g_snurb *srf, struct resource *res));
00169 
00170 /* nurb_diff.c */
00171 RT_EXPORT BU_EXTERN(struct face_g_snurb *rt_nurb_s_diff, (const struct face_g_snurb *srf, int dir));
00172 RT_EXPORT BU_EXTERN(struct edge_g_cnurb *rt_nurb_c_diff, (const struct edge_g_cnurb *crv));
00173 RT_EXPORT BU_EXTERN(void rt_nurb_mesh_diff, (int order, const fastf_t *o_pts,
00174                         fastf_t *n_pts,
00175                         const fastf_t *knots, int o_stride, int n_stride,
00176                         int o_size, int pt_type));
00177 
00178 /* nurb_eval.c */
00179 RT_EXPORT BU_EXTERN(void rt_nurb_s_eval, (const struct face_g_snurb *srf, fastf_t u, fastf_t v, fastf_t * final_value));
00180 RT_EXPORT BU_EXTERN(void rt_nurb_c_eval, (const struct edge_g_cnurb *crv, fastf_t param, fastf_t * final_value));
00181 RT_EXPORT BU_EXTERN(fastf_t *rt_nurb_eval_crv, (fastf_t *crv, int order,
00182                         fastf_t param,
00183                         const struct knot_vector *k_vec, int k_index, int coords));
00184 RT_EXPORT BU_EXTERN(void rt_nurb_pr_crv, (fastf_t *crv, int c_size, int coords));
00185 
00186 /* nurb_flat.c */
00187 RT_EXPORT BU_EXTERN(int rt_nurb_s_flat, (struct face_g_snurb *srf, fastf_t epsilon));
00188 RT_EXPORT BU_EXTERN(fastf_t rt_nurb_crv_flat, (fastf_t *crv, int        size, int pt_type));
00189 
00190 /* nurb_knot.c */
00191 RT_EXPORT BU_EXTERN(void rt_nurb_kvknot, (struct knot_vector *new_knots, int order,
00192                         fastf_t lower, fastf_t upper, int num, struct resource *res));
00193 RT_EXPORT BU_EXTERN(void rt_nurb_kvmult, (struct knot_vector *new_kv,
00194                         const struct knot_vector *kv,
00195                         int num, fastf_t val, struct resource *res));
00196 RT_EXPORT BU_EXTERN(void rt_nurb_kvgen, (struct knot_vector *kv,
00197                         fastf_t lower, fastf_t upper, int num, struct resource *res));
00198 RT_EXPORT BU_EXTERN(void rt_nurb_kvmerge, (struct knot_vector *new_knots,
00199                         const struct knot_vector *kv1,
00200                         const struct knot_vector *kv2, struct resource *res));
00201 RT_EXPORT BU_EXTERN(int rt_nurb_kvcheck, (fastf_t val, const struct knot_vector *kv));
00202 RT_EXPORT BU_EXTERN(void rt_nurb_kvextract, (struct knot_vector *new_kv,
00203                         const struct knot_vector *kv,
00204                         int lower, int upper, struct resource *res));
00205 RT_EXPORT BU_EXTERN(void rt_nurb_kvcopy, (struct knot_vector *new_kv,
00206                         const struct knot_vector *old_kv, struct resource *res));
00207 RT_EXPORT BU_EXTERN(void rt_nurb_kvnorm, (struct knot_vector *kv));
00208 RT_EXPORT BU_EXTERN(int rt_knot_index, (const struct knot_vector *kv, fastf_t k_value,
00209                         int order));
00210 RT_EXPORT BU_EXTERN(void rt_nurb_gen_knot_vector, (struct knot_vector *new_knots,
00211                         int order, fastf_t lower, fastf_t upper, struct resource *res));
00212 
00213 /* nurb_norm.c */
00214 RT_EXPORT BU_EXTERN(void rt_nurb_s_norm, (struct face_g_snurb *srf, fastf_t u, fastf_t v, fastf_t * norm));
00215 
00216 /* nurb_c2.c */
00217 RT_EXPORT BU_EXTERN(void rt_nurb_curvature, (struct curvature *cvp,
00218                         const struct face_g_snurb *srf, fastf_t u, fastf_t v));
00219 
00220 /* nurb_plot.c */
00221 RT_EXPORT BU_EXTERN(void rt_nurb_plot_snurb, (FILE *fp, const struct face_g_snurb *srf));
00222 RT_EXPORT BU_EXTERN(void rt_nurb_plot_cnurb, (FILE *fp, const struct edge_g_cnurb *crv));
00223 RT_EXPORT BU_EXTERN(void rt_nurb_s_plot, (const struct face_g_snurb *srf) );
00224 
00225 /* nurb_interp.c */
00226 RT_EXPORT BU_EXTERN(void rt_nurb_cinterp, (struct edge_g_cnurb *crv, int order,
00227                         const fastf_t *data, int n));
00228 RT_EXPORT BU_EXTERN(void rt_nurb_sinterp, (struct face_g_snurb *srf, int order,
00229                         const fastf_t *data, int ymax, int xmax));
00230 
00231 /* nurb_poly.c */
00232 RT_EXPORT BU_EXTERN(struct rt_nurb_poly *rt_nurb_to_poly, (struct face_g_snurb *srf));
00233 RT_EXPORT BU_EXTERN(struct rt_nurb_poly *rt_nurb_mk_poly,
00234                         (fastf_t *v1, fastf_t *v2, fastf_t *v3,
00235                         fastf_t uv1[2], fastf_t uv2[2], fastf_t uv3[2]));
00236 
00237 /* nurb_ray.c */
00238 RT_EXPORT BU_EXTERN(struct face_g_snurb *rt_nurb_project_srf, (const struct face_g_snurb *srf,
00239                         plane_t plane1, plane_t plane2, struct resource *res));
00240 RT_EXPORT BU_EXTERN(void rt_nurb_clip_srf, (const struct face_g_snurb *srf,
00241                         int dir, fastf_t *min, fastf_t *max));
00242 RT_EXPORT BU_EXTERN(struct face_g_snurb *rt_nurb_region_from_srf, (const struct face_g_snurb *srf,
00243                         int dir, fastf_t param1, fastf_t param2, struct resource *res));
00244 RT_EXPORT BU_EXTERN(struct rt_nurb_uv_hit *rt_nurb_intersect, (const struct face_g_snurb * srf,
00245                         plane_t plane1, plane_t plane2, double uv_tol, struct resource *res));
00246 
00247 /* nurb_refine.c */
00248 RT_EXPORT BU_EXTERN(struct face_g_snurb *rt_nurb_s_refine, (const struct face_g_snurb *srf,
00249                         int dir, struct knot_vector *kv, struct resource *res));
00250 RT_EXPORT BU_EXTERN(struct edge_g_cnurb *rt_nurb_c_refine, (const struct edge_g_cnurb * crv,
00251                         struct knot_vector *kv));
00252 
00253 /* nurb_solve.c */
00254 RT_EXPORT BU_EXTERN(void rt_nurb_solve, (fastf_t *mat_1, fastf_t *mat_2,
00255                         fastf_t *solution, int dim, int coords));
00256 RT_EXPORT BU_EXTERN(void rt_nurb_doolittle, (fastf_t *mat_1, fastf_t *mat_2,
00257                         int row, int coords));
00258 RT_EXPORT BU_EXTERN(void rt_nurb_forw_solve, (const fastf_t *lu, const fastf_t *b,
00259                         fastf_t *y, int n));
00260 RT_EXPORT BU_EXTERN(void rt_nurb_back_solve, (const fastf_t *lu, const fastf_t *y,
00261                         fastf_t *x, int n));
00262 RT_EXPORT BU_EXTERN(void rt_nurb_p_mat, (const fastf_t * mat, int dim));
00263 
00264 /* nurb_split.c */
00265 RT_EXPORT BU_EXTERN(void rt_nurb_s_split, (struct bu_list *split_hd, const struct face_g_snurb *srf,
00266                         int dir, struct resource *res));
00267 RT_EXPORT BU_EXTERN(void rt_nurb_c_split, (struct bu_list *split_hd, const struct edge_g_cnurb *crv));
00268 
00269 /* nurb_util.c */
00270 RT_EXPORT BU_EXTERN(struct face_g_snurb *rt_nurb_new_snurb, (int u_order, int v_order,
00271                         int n_u_knots, int n_v_knots,
00272                         int n_rows, int n_cols, int pt_type, struct resource *res));
00273 RT_EXPORT BU_EXTERN(struct edge_g_cnurb *rt_nurb_new_cnurb, (int order, int n_knots,
00274                         int n_pts, int pt_type));
00275 RT_EXPORT BU_EXTERN(void rt_nurb_free_snurb, (struct face_g_snurb *srf, struct resource *res));
00276 RT_EXPORT BU_EXTERN(void rt_nurb_free_cnurb, (struct edge_g_cnurb * crv));
00277 RT_EXPORT BU_EXTERN(void rt_nurb_c_print, (const struct edge_g_cnurb *crv));
00278 RT_EXPORT BU_EXTERN(void rt_nurb_s_print, (char *c, const struct face_g_snurb *srf));
00279 RT_EXPORT BU_EXTERN(void rt_nurb_pr_kv, (const struct knot_vector *kv));
00280 RT_EXPORT BU_EXTERN(void rt_nurb_pr_mesh, (const struct face_g_snurb *m));
00281 RT_EXPORT BU_EXTERN(void rt_nurb_print_pt_type, (int c));
00282 
00283 /* nurb_xsplit.c */
00284 RT_EXPORT BU_EXTERN(struct face_g_snurb *rt_nurb_s_xsplit, (struct face_g_snurb *srf,
00285                         fastf_t param, int dir));
00286 RT_EXPORT BU_EXTERN(struct edge_g_cnurb *rt_nurb_c_xsplit, (struct edge_g_cnurb *crv, fastf_t param));
00287 
00288 /* oslo_calc.c */
00289 RT_EXPORT BU_EXTERN(struct oslo_mat *rt_nurb_calc_oslo, (int order,
00290                         const struct knot_vector *tau_kv,
00291                         struct knot_vector *t_kv, struct resource *res));
00292 RT_EXPORT BU_EXTERN(void rt_nurb_pr_oslo, (struct oslo_mat *om));
00293 RT_EXPORT BU_EXTERN(void rt_nurb_free_oslo, (struct oslo_mat *om, struct resource *res));
00294 
00295 /* oslo_map.c */
00296 RT_EXPORT BU_EXTERN(void rt_nurb_map_oslo, (struct oslo_mat *oslo,
00297                         fastf_t *old_pts, fastf_t *new_pts,
00298                         int o_stride, int n_stride,
00299                         int lower, int upper, int pt_type));
00300 
00301 /* bezier_2d_isect.c */
00302 RT_EXPORT BU_EXTERN( int CrossingCount, (point2d_t *V, int degree, point2d_t ray_start,
00303                                point2d_t ray_dir, point2d_t ray_perp ) );
00304 RT_EXPORT BU_EXTERN( int ControlPolygonFlatEnough, (point2d_t *V, int degree, fastf_t epsilon ) );
00305 RT_EXPORT BU_EXTERN( void Bezier, (point2d_t *V, int degree, double t,
00306                          point2d_t *Left, point2d_t *Right, point2d_t eval_pt, point2d_t normal ) );
00307 RT_EXPORT BU_EXTERN( int FindRoots, (point2d_t *w, int degree, point2d_t **intercept, point2d_t **normal,
00308                            point2d_t ray_start, point2d_t ray_dir, point2d_t ray_perp,
00309                            int depth, fastf_t epsilon) );
00310 RT_EXPORT BU_EXTERN( struct bezier_2d_list *subdivide_bezier, (struct bezier_2d_list *bezier_hd, int degree,
00311                                                         fastf_t epsilon, int depth) );
00312 #endif
00313 
00314 /*@}*/
00315 /*
00316  * Local Variables:
00317  * mode: C
00318  * tab-width: 8
00319  * c-basic-offset: 4
00320  * indent-tabs-mode: t
00321  * End:
00322  * ex: shiftwidth=4 tabstop=8
00323  */
00324 

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