00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include "common.h"
00040
00041
00042
00043 #include <stdio.h>
00044
00045 #include "machine.h"
00046 #include "vmath.h"
00047 #include "raytrace.h"
00048 #include "nurb.h"
00049
00050
00051
00052
00053
00054
00055
00056 struct rt_nurb_poly *
00057 rt_nurb_to_poly(struct face_g_snurb *srf)
00058 {
00059 int coords = srf->pt_type;
00060 fastf_t * p1, *p2, *p3, *p4;
00061 fastf_t uv1[2], uv2[2], uv3[2], uv4[2];
00062 struct rt_nurb_poly *p, *p_head;
00063
00064
00065
00066 p1 = srf->ctl_points;
00067 p2 = srf->ctl_points + coords * srf->s_size[1];
00068 p3 = srf->ctl_points + (coords * srf->s_size[1] *
00069 (srf->s_size[0] - 1)) +
00070 ((srf->s_size[1] - 1) * coords);
00071 p4 = srf->ctl_points + (coords * srf->s_size[1] *
00072 (srf->s_size[0] - 1));
00073
00074
00075 if ( RT_NURB_IS_PT_RATIONAL(srf->pt_type)) {
00076 int w_index;
00077
00078 if ( RT_NURB_EXTRACT_PT_TYPE( srf->pt_type) == RT_NURB_PT_XY)
00079 w_index = 2;
00080 else if ( RT_NURB_EXTRACT_PT_TYPE( srf->pt_type) == RT_NURB_PT_UV)
00081 w_index = 2;
00082 else if ( RT_NURB_EXTRACT_PT_TYPE( srf->pt_type) == RT_NURB_PT_XYZ)
00083 w_index = 3;
00084 else
00085 w_index = 3;
00086
00087 p1[0] = p1[0] / p1[w_index];
00088 p2[0] = p2[0] / p1[w_index];
00089 p3[0] = p3[0] / p1[w_index];
00090 p4[0] = p4[0] / p1[w_index];
00091 }
00092
00093 uv1[0] = srf->u.knots[0];
00094 uv1[1] = srf->v.knots[0];
00095
00096 uv2[0] = srf->u.knots[srf->u.k_size -1];
00097 uv2[1] = srf->v.knots[0];
00098
00099 uv3[0] = srf->u.knots[srf->u.k_size -1];
00100 uv3[1] = srf->v.knots[srf->v.k_size -1];
00101
00102 uv4[0] = srf->u.knots[0];
00103 uv4[1] = srf->v.knots[srf->v.k_size -1];
00104
00105 p = rt_nurb_mk_poly(p1, p2, p3, uv1, uv2, uv3 );
00106 p_head = p;
00107 p = rt_nurb_mk_poly(p3, p4, p1, uv3, uv4, uv1 );
00108 p->next = p_head;
00109 p_head = p;
00110
00111 return p_head;
00112 }
00113
00114
00115 struct rt_nurb_poly *
00116 rt_nurb_mk_poly(fastf_t *v1, fastf_t *v2, fastf_t *v3, fastf_t *uv1, fastf_t *uv2, fastf_t *uv3)
00117 {
00118 struct rt_nurb_poly *p;
00119
00120 p = (struct rt_nurb_poly *) bu_malloc( sizeof( struct rt_nurb_poly ),
00121 "rt_nurb_mk_poly: rt_nurb_poly struct" );
00122
00123 p->next = (struct rt_nurb_poly *) 0;
00124
00125 VMOVE( p->ply[0], v1);
00126 VMOVE( p->ply[1], v2);
00127 VMOVE( p->ply[2], v3);
00128
00129 p->uv[0][0] = uv1[0];
00130 p->uv[0][1] = uv1[1];
00131 p->uv[1][0] = uv2[0];
00132 p->uv[1][1] = uv2[1];
00133 p->uv[2][0] = uv3[0];
00134 p->uv[2][1] = uv3[1];
00135
00136 return p;
00137 }
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147