ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

incurveeval.cc
Go to the documentation of this file.
00001 /*
00002 ** License Applicability. Except to the extent portions of this file are
00003 ** made subject to an alternative license as permitted in the SGI Free
00004 ** Software License B, Version 1.1 (the "License"), the contents of this
00005 ** file are subject only to the provisions of the License. You may not use
00006 ** this file except in compliance with the License. You may obtain a copy
00007 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
00008 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
00009 ** 
00010 ** http://oss.sgi.com/projects/FreeB
00011 ** 
00012 ** Note that, as provided in the License, the Software is distributed on an
00013 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
00014 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
00015 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
00016 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
00017 ** 
00018 ** Original Code. The Original Code is: OpenGL Sample Implementation,
00019 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
00020 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
00021 ** Copyright in any portions created by third parties is as indicated
00022 ** elsewhere herein. All Rights Reserved.
00023 ** 
00024 ** Additional Notice Provisions: The application programming interfaces
00025 ** established by SGI in conjunction with the Original Code are The
00026 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
00027 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
00028 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
00029 ** Window System(R) (Version 1.3), released October 19, 1998. This software
00030 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
00031 ** published by SGI, but has not been independently verified as being
00032 ** compliant with the OpenGL(R) version 1.2.1 Specification.
00033 **
00034 ** $Date: 2006-03-12 00:07:02 +0000 (Sun, 12 Mar 2006) $ $Revision: 1.1 $
00035 */
00036 /*
00037 ** $Header: /cygdrive/c/RCVS/CVS/ReactOS/reactos/lib/glu32/libnurbs/interface/incurveeval.cc,v 1.1 2004/02/02 16:39:08 navaraf Exp $
00038 */
00039 
00040 #include <stdlib.h>
00041 #include <stdio.h>
00042 
00043 #include "glcurveval.h"
00044 
00045 
00046 /*
00047  *compute the Bezier polynomials C[n,j](v) for all j at v with 
00048  *return values stored in coeff[], where 
00049  *  C[n,j](v) = (n,j) * v^j * (1-v)^(n-j),
00050  *  j=0,1,2,...,n.
00051  *order : n+1
00052  *vprime: v
00053  *coeff : coeff[j]=C[n,j](v), this array store the returned values.
00054  *The algorithm is a recursive scheme:
00055  *   C[0,0]=1;
00056  *   C[n,j](v) = (1-v)*C[n-1,j](v) + v*C[n-1,j-1](v), n>=1
00057  *This code is copied from opengl/soft/so_eval.c:PreEvaluate
00058  */
00059 void OpenGLCurveEvaluator::inPreEvaluate(int order, REAL vprime, REAL *coeff)
00060 {
00061   int i, j;
00062   REAL oldval, temp;
00063   REAL oneMinusvprime;
00064   
00065   /*
00066    * Minor optimization
00067    * Compute orders 1 and 2 outright, and set coeff[0], coeff[1] to
00068      * their i==1 loop values to avoid the initialization and the i==1 loop.
00069      */
00070   if (order == 1) {
00071     coeff[0] = 1.0;
00072     return;
00073   }
00074   
00075   oneMinusvprime = 1-vprime;
00076   coeff[0] = oneMinusvprime;
00077   coeff[1] = vprime;
00078   if (order == 2) return;
00079   
00080   for (i = 2; i < order; i++) {
00081     oldval = coeff[0] * vprime;
00082     coeff[0] = oneMinusvprime * coeff[0];
00083     for (j = 1; j < i; j++) {
00084       temp = oldval;
00085       oldval = coeff[j] * vprime;
00086         coeff[j] = temp + oneMinusvprime * coeff[j];
00087     }
00088     coeff[j] = oldval;
00089   }
00090 }
00091 
00092 void OpenGLCurveEvaluator::inMap1f(int which, //0: vert, 1: norm, 2: color, 3: tex
00093                    int k, //dimension
00094                    REAL ulower,
00095                    REAL uupper,
00096                    int ustride,
00097                    int uorder,
00098                    REAL *ctlpoints)
00099 {
00100   int i,x;
00101   curveEvalMachine *temp_em;
00102   switch(which){
00103   case 0: //vertex
00104     vertex_flag = 1;
00105     temp_em = &em_vertex;
00106     break;
00107   case 1: //normal
00108     normal_flag = 1;
00109     temp_em = &em_normal;
00110     break;
00111   case 2: //color
00112     color_flag = 1;
00113     temp_em = &em_color;
00114     break;
00115   default:
00116     texcoord_flag = 1;
00117     temp_em = &em_texcoord;
00118     break;
00119   }
00120   
00121   REAL *data = temp_em->ctlpoints;
00122   temp_em->uprime = -1; //initialized
00123   temp_em->k = k;
00124   temp_em->u1 = ulower;
00125   temp_em->u2 = uupper;
00126   temp_em->ustride = ustride;
00127   temp_em->uorder = uorder;
00128   /*copy the control points*/
00129   for(i=0; i<uorder; i++){
00130     for(x=0; x<k; x++){
00131       data[x] = ctlpoints[x];
00132     }
00133     ctlpoints += ustride;
00134     data += k;
00135   }     
00136 }
00137 
00138 void OpenGLCurveEvaluator::inDoDomain1(curveEvalMachine *em, REAL u, REAL *retPoint)
00139 {
00140   int j, row;
00141   REAL the_uprime;
00142   REAL *data;
00143   
00144   if(em->u2 == em->u1)
00145     return;
00146   the_uprime = (u-em->u1) / (em->u2-em->u1);
00147   /*use already cached values if possible*/
00148   if(em->uprime != the_uprime){
00149     inPreEvaluate(em->uorder, the_uprime, em->ucoeff);
00150     em->uprime = the_uprime;
00151   }
00152   
00153   for(j=0; j<em->k; j++){
00154     data = em->ctlpoints+j;
00155     retPoint[j] = 0.0;
00156     for(row=0; row<em->uorder; row++)
00157       {
00158     retPoint[j] += em->ucoeff[row] * (*data);
00159     data += em->k;
00160       }
00161   } 
00162 }
00163 
00164 void  OpenGLCurveEvaluator::inDoEvalCoord1(REAL u)
00165 {
00166   REAL temp_vertex[4];
00167   REAL temp_normal[3];
00168   REAL temp_color[4];
00169   REAL temp_texcoord[4];
00170   if(texcoord_flag) //there is a texture map
00171     {
00172       inDoDomain1(&em_texcoord, u, temp_texcoord);
00173       texcoordCallBack(temp_texcoord, userData);
00174     }
00175 #ifdef DEBUG
00176 printf("color_flag = %i\n", color_flag);
00177 #endif
00178   if(color_flag) //there is a color map
00179     {
00180       inDoDomain1(&em_color, u, temp_color);
00181       colorCallBack(temp_color, userData);
00182     }
00183   if(normal_flag) //there is a normal map
00184     {
00185       inDoDomain1(&em_normal, u, temp_normal);
00186       normalCallBack(temp_normal, userData);
00187     }
00188   if(vertex_flag)
00189     {
00190       inDoDomain1(&em_vertex, u, temp_vertex);
00191       vertexCallBack(temp_vertex, userData);
00192     }
00193 }
00194 
00195 void OpenGLCurveEvaluator::inMapMesh1f(int umin, int umax)
00196 {
00197   REAL du, u;
00198   int i;
00199   if(global_grid_nu == 0)
00200     return; //no points to output
00201   du = (global_grid_u1 - global_grid_u0) / (REAL) global_grid_nu;
00202   bgnline();
00203   for(i=umin; i<= umax; i++){
00204     u = (i==global_grid_nu)? global_grid_u1: global_grid_u0 + i*du;
00205     inDoEvalCoord1(u);
00206   }
00207   endline();
00208 }

Generated on Sun May 27 2012 04:23:38 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.