00001 /* N U R B _ T R I M _ U T I L . C 00002 * BRL-CAD 00003 * 00004 * Copyright (c) 1990-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_trim_util.c 00025 * Trimming curve Utilities. 00026 * 00027 * Author: Paul R. Stay 00028 * Source 00029 * SECAD/VLD Computing Consortium, Bldg 394 00030 * The US Army Ballistic Research Laboratory 00031 * Aberdeen Proving Ground, Maryland 21005 00032 * 00033 * Date: Mon July 3, 1995 00034 */ 00035 /*@}*/ 00036 00037 #ifndef lint 00038 static const char rcs_ident[] = "$Header: /cvsroot/brlcad/brlcad/src/librt/nurb_trim_util.c,v 14.11 2006/09/16 02:04:25 lbutler Exp $"; 00039 #endif 00040 00041 #include "common.h" 00042 00043 00044 00045 #include <stdio.h> 00046 #include <math.h> 00047 00048 #include "machine.h" 00049 #include "vmath.h" 00050 #include "raytrace.h" 00051 #include "nurb.h" 00052 00053 /* Check to see if the curve conmtrol polygon 00054 * wonders outside the parametric range given. 00055 * This is usefull if a trimming curve control polygon is outside 00056 * but the evaluated curve is not. We will want to refine the 00057 * curve so that is lies within the range; 00058 * otherwise it breaks the surface evaluation 00059 */ 00060 00061 int 00062 rt_nurb_crv_in_range(struct edge_g_cnurb *crv, fastf_t u_min, fastf_t u_max, fastf_t v_min, fastf_t v_max) 00063 { 00064 point_t eval; 00065 fastf_t *pts; 00066 int coords = RT_NURB_EXTRACT_COORDS( crv->pt_type ); 00067 int rat = RT_NURB_IS_PT_RATIONAL(crv->pt_type); 00068 int i; 00069 00070 pts = &crv->ctl_points[0]; 00071 00072 for( i = 0; i < crv->c_size; i++) 00073 { 00074 if (rat) 00075 { 00076 eval[0] = pts[0] / pts[2]; 00077 eval[1] = pts[1] / pts[2]; 00078 eval[2] = 1; 00079 } else { 00080 eval[0] = pts[0]; 00081 eval[1] = pts[1]; 00082 eval[2] = 1; 00083 } 00084 00085 if( eval[0] < u_min || eval[0] > u_max ) 00086 return 0; 00087 00088 if( eval[1] < v_min || eval[1] > v_max ) 00089 return 0; 00090 00091 pts += coords; 00092 } 00093 return 1; 00094 } 00095 00096 /* 00097 * Local Variables: 00098 * mode: C 00099 * tab-width: 8 00100 * c-basic-offset: 4 00101 * indent-tabs-mode: t 00102 * End: 00103 * ex: shiftwidth=4 tabstop=8 00104 */