| 1 | /* $Id: incurveeval.cpp,v 1.1 2000-02-09 08:49:02 jeroen Exp $ */
|
|---|
| 2 | /*
|
|---|
| 3 | ** License Applicability. Except to the extent portions of this file are
|
|---|
| 4 | ** made subject to an alternative license as permitted in the SGI Free
|
|---|
| 5 | ** Software License B, Version 1.0 (the "License"), the contents of this
|
|---|
| 6 | ** file are subject only to the provisions of the License. You may not use
|
|---|
| 7 | ** this file except in compliance with the License. You may obtain a copy
|
|---|
| 8 | ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
|---|
| 9 | ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
|---|
| 10 | **
|
|---|
| 11 | ** http://oss.sgi.com/projects/FreeB
|
|---|
| 12 | **
|
|---|
| 13 | ** Note that, as provided in the License, the Software is distributed on an
|
|---|
| 14 | ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
|---|
| 15 | ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
|---|
| 16 | ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
|---|
| 17 | ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
|---|
| 18 | **
|
|---|
| 19 | ** Original Code. The Original Code is: OpenGL Sample Implementation,
|
|---|
| 20 | ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
|---|
| 21 | ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
|---|
| 22 | ** Copyright in any portions created by third parties is as indicated
|
|---|
| 23 | ** elsewhere herein. All Rights Reserved.
|
|---|
| 24 | **
|
|---|
| 25 | ** Additional Notice Provisions: The application programming interfaces
|
|---|
| 26 | ** established by SGI in conjunction with the Original Code are The
|
|---|
| 27 | ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
|---|
| 28 | ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
|---|
| 29 | ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
|---|
| 30 | ** Window System(R) (Version 1.3), released October 19, 1998. This software
|
|---|
| 31 | ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
|---|
| 32 | ** published by SGI, but has not been independently verified as being
|
|---|
| 33 | ** compliant with the OpenGL(R) version 1.2.1 Specification.
|
|---|
| 34 | **
|
|---|
| 35 | ** $Date: 2000-02-09 08:49:02 $ $Revision: 1.1 $
|
|---|
| 36 | */
|
|---|
| 37 | /*
|
|---|
| 38 | ** $Header: /home/ktk/tmp/odin/2007/netlabs.cvs/odin32/src/opengl/glu/nurbs/interface/incurveeval.cpp,v 1.1 2000-02-09 08:49:02 jeroen Exp $
|
|---|
| 39 | */
|
|---|
| 40 |
|
|---|
| 41 | #include <stdlib.h>
|
|---|
| 42 | #include <stdio.h>
|
|---|
| 43 |
|
|---|
| 44 | #include "glcurveval.h"
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 | /*
|
|---|
| 48 | *compute the Bezier polynomials C[n,j](v) for all j at v with
|
|---|
| 49 | *return values stored in coeff[], where
|
|---|
| 50 | * C[n,j](v) = (n,j) * v^j * (1-v)^(n-j),
|
|---|
| 51 | * j=0,1,2,...,n.
|
|---|
| 52 | *order : n+1
|
|---|
| 53 | *vprime: v
|
|---|
| 54 | *coeff : coeff[j]=C[n,j](v), this array store the returned values.
|
|---|
| 55 | *The algorithm is a recursive scheme:
|
|---|
| 56 | * C[0,0]=1;
|
|---|
| 57 | * C[n,j](v) = (1-v)*C[n-1,j](v) + v*C[n-1,j-1](v), n>=1
|
|---|
| 58 | *This code is copied from opengl/soft/so_eval.c:PreEvaluate
|
|---|
| 59 | */
|
|---|
| 60 | void OpenGLCurveEvaluator::inPreEvaluate(int order, REAL vprime, REAL *coeff)
|
|---|
| 61 | {
|
|---|
| 62 | int i, j;
|
|---|
| 63 | REAL oldval, temp;
|
|---|
| 64 | REAL oneMinusvprime;
|
|---|
| 65 |
|
|---|
| 66 | /*
|
|---|
| 67 | * Minor optimization
|
|---|
| 68 | * Compute orders 1 and 2 outright, and set coeff[0], coeff[1] to
|
|---|
| 69 | * their i==1 loop values to avoid the initialization and the i==1 loop.
|
|---|
| 70 | */
|
|---|
| 71 | if (order == 1) {
|
|---|
| 72 | coeff[0] = 1.0;
|
|---|
| 73 | return;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | oneMinusvprime = 1-vprime;
|
|---|
| 77 | coeff[0] = oneMinusvprime;
|
|---|
| 78 | coeff[1] = vprime;
|
|---|
| 79 | if (order == 2) return;
|
|---|
| 80 |
|
|---|
| 81 | for (i = 2; i < order; i++) {
|
|---|
| 82 | oldval = coeff[0] * vprime;
|
|---|
| 83 | coeff[0] = oneMinusvprime * coeff[0];
|
|---|
| 84 | for (j = 1; j < i; j++) {
|
|---|
| 85 | temp = oldval;
|
|---|
| 86 | oldval = coeff[j] * vprime;
|
|---|
| 87 | coeff[j] = temp + oneMinusvprime * coeff[j];
|
|---|
| 88 | }
|
|---|
| 89 | coeff[j] = oldval;
|
|---|
| 90 | }
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | void OpenGLCurveEvaluator::inMap1f(int which, //0: vert, 1: norm, 2: color, 3: tex
|
|---|
| 94 | int k, //dimension
|
|---|
| 95 | REAL ulower,
|
|---|
| 96 | REAL uupper,
|
|---|
| 97 | int ustride,
|
|---|
| 98 | int uorder,
|
|---|
| 99 | REAL *ctlpoints)
|
|---|
| 100 | {
|
|---|
| 101 | int i,j,x;
|
|---|
| 102 | curveEvalMachine *temp_em;
|
|---|
| 103 | switch(which){
|
|---|
| 104 | case 0: //vertex
|
|---|
| 105 | vertex_flag = 1;
|
|---|
| 106 | temp_em = &em_vertex;
|
|---|
| 107 | break;
|
|---|
| 108 | case 1: //normal
|
|---|
| 109 | normal_flag = 1;
|
|---|
| 110 | temp_em = &em_normal;
|
|---|
| 111 | break;
|
|---|
| 112 | case 2: //color
|
|---|
| 113 | color_flag = 1;
|
|---|
| 114 | temp_em = &em_color;
|
|---|
| 115 | break;
|
|---|
| 116 | default:
|
|---|
| 117 | texcoord_flag = 1;
|
|---|
| 118 | temp_em = &em_texcoord;
|
|---|
| 119 | break;
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | REAL *data = temp_em->ctlpoints;
|
|---|
| 123 | temp_em->uprime = -1; //initialized
|
|---|
| 124 | temp_em->k = k;
|
|---|
| 125 | temp_em->u1 = ulower;
|
|---|
| 126 | temp_em->u2 = uupper;
|
|---|
| 127 | temp_em->ustride = ustride;
|
|---|
| 128 | temp_em->uorder = uorder;
|
|---|
| 129 | /*copy the control points*/
|
|---|
| 130 | for(i=0; i<uorder; i++){
|
|---|
| 131 | for(x=0; x<k; x++){
|
|---|
| 132 | data[x] = ctlpoints[x];
|
|---|
| 133 | }
|
|---|
| 134 | ctlpoints += ustride;
|
|---|
| 135 | data += k;
|
|---|
| 136 | }
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | void OpenGLCurveEvaluator::inDoDomain1(curveEvalMachine *em, REAL u, REAL *retPoint)
|
|---|
| 140 | {
|
|---|
| 141 | int j, row;
|
|---|
| 142 | REAL the_uprime;
|
|---|
| 143 | REAL p;
|
|---|
| 144 | REAL *data;
|
|---|
| 145 |
|
|---|
| 146 | if(em->u2 == em->u1)
|
|---|
| 147 | return;
|
|---|
| 148 | the_uprime = (u-em->u1) / (em->u2-em->u1);
|
|---|
| 149 | /*use already cached values if possible*/
|
|---|
| 150 | if(em->uprime != the_uprime){
|
|---|
| 151 | inPreEvaluate(em->uorder, the_uprime, em->ucoeff);
|
|---|
| 152 | em->uprime = the_uprime;
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | for(j=0; j<em->k; j++){
|
|---|
| 156 | data = em->ctlpoints+j;
|
|---|
| 157 | retPoint[j] = 0.0;
|
|---|
| 158 | for(row=0; row<em->uorder; row++)
|
|---|
| 159 | {
|
|---|
| 160 | retPoint[j] += em->ucoeff[row] * (*data);
|
|---|
| 161 | data += em->k;
|
|---|
| 162 | }
|
|---|
| 163 | }
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | void OpenGLCurveEvaluator::inDoEvalCoord1(REAL u)
|
|---|
| 167 | {
|
|---|
| 168 | REAL temp_vertex[4];
|
|---|
| 169 | REAL temp_normal[3];
|
|---|
| 170 | REAL temp_color[4];
|
|---|
| 171 | REAL temp_texcoord[4];
|
|---|
| 172 | if(texcoord_flag) //there is a texture map
|
|---|
| 173 | {
|
|---|
| 174 | inDoDomain1(&em_texcoord, u, temp_texcoord);
|
|---|
| 175 | texcoordCallBack(temp_texcoord, userData);
|
|---|
| 176 | }
|
|---|
| 177 | #ifdef DEBUG
|
|---|
| 178 | printf("color_flag = %i\n", color_flag);
|
|---|
| 179 | #endif
|
|---|
| 180 | if(color_flag) //there is a color map
|
|---|
| 181 | {
|
|---|
| 182 | inDoDomain1(&em_color, u, temp_color);
|
|---|
| 183 | colorCallBack(temp_color, userData);
|
|---|
| 184 | }
|
|---|
| 185 | if(normal_flag) //there is a normal map
|
|---|
| 186 | {
|
|---|
| 187 | inDoDomain1(&em_normal, u, temp_normal);
|
|---|
| 188 | normalCallBack(temp_normal, userData);
|
|---|
| 189 | }
|
|---|
| 190 | if(vertex_flag)
|
|---|
| 191 | {
|
|---|
| 192 | inDoDomain1(&em_vertex, u, temp_vertex);
|
|---|
| 193 | vertexCallBack(temp_vertex, userData);
|
|---|
| 194 | }
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | void OpenGLCurveEvaluator::inMapMesh1f(int umin, int umax)
|
|---|
| 198 | {
|
|---|
| 199 | REAL du, u;
|
|---|
| 200 | int i;
|
|---|
| 201 | if(global_grid_nu == 0)
|
|---|
| 202 | return; //no points to output
|
|---|
| 203 | du = (global_grid_u1 - global_grid_u0) / (REAL) global_grid_nu;
|
|---|
| 204 | bgnline();
|
|---|
| 205 | for(i=umin; i<= umax; i++){
|
|---|
| 206 | u = (i==global_grid_nu)? global_grid_u1: global_grid_u0 + i*du;
|
|---|
| 207 | inDoEvalCoord1(u);
|
|---|
| 208 | }
|
|---|
| 209 | endline();
|
|---|
| 210 | }
|
|---|