Debian Codegraph @

lib/database/src/so/nodes/nurbs/clients/softcurvmap.c++

raw
1 /*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37 /*
38 * softcurvmap.c++ - curve evaluator
39 *
40 * $Revision: 1.2 $
41 */
42
43 #include "mystdio.h"
44 #include "myassert.h"
45 #include "mystring.h"
46 #include "defines.h"
47 #include "softcurvmap.h"
48
49 #include <cstring>
50
51 #define SHALLOWCOPY
52
53
54 _SoNurbsCurveMap::_SoNurbsCurveMap(long _type, int _rational, int _ncoords )
55 {
56 type = _type;
57 rational = _rational;
58 ncoords = _ncoords;
59 next = 0;
60 pts = 0;
61 isdefined = 0;
62 isenabled = 0;
63 }
64
65
66 void _SoNurbsCurveMap::domain( float * ) {}
67 void _SoNurbsCurveMap::point( float * ) {}
68 void _SoNurbsCurveMap::uderiv( float * ) {}
69 void _SoNurbsCurveMap::uuderiv( float * ) {}
70
71 int
72 _SoNurbsCurveMap::isType( long _type )
73 {
74 return (_type == type) ? 1 : 0;
75 }
76
77 _SoNurbsCurveMap::~_SoNurbsCurveMap()
78 {
79 if( pts ) delete[] pts;
80 }
81
82 void
83 _SoNurbsCurveMap::disable( void )
84 {
85 isenabled = 0;
86 }
87
88 void
89 _SoNurbsCurveMap::enable( void )
90 {
91 isenabled = 1;
92 }
93
94 /*-------------------------------------------------------------------------
95 * map1f - pass a desription of a curve map
96 *-------------------------------------------------------------------------
97 */
98 void
99 _SoNurbsCurveMap::map1f(
100 REAL _ulo, /* lower parametric bound */
101 REAL _uhi, /* upper parametric bound */
102 long _stride, /* distance to next point */
103 long _order, /* parametric order */
104 REAL *_pts /* control points */
105 )
106 {
107 assert( _pts );
108 assert( _stride >= 0 );
109 assert( _order >= 0 );
110 assert( _order <= MAXORDER );
111 assert( _ulo <= _uhi );
112
113 isdefined = 1;
114
115 lo = _ulo;
116 hi = _uhi;
117 stride = (int) _stride;
118 order = (int) _order;
119
120 if( pts == NULL )
121 pts = new REAL[MAXCOORDS * MAXORDER];
122
123 #ifdef SHALLOWCOPY
124 ctlpts = _pts;
125 #endif
126
127 #ifdef DEEPCOPY
128 deepCopy( _pts );
129 #endif
130
131 #ifdef HORNER
132 deepCopyAndScale( _pts );
133 #endif
134 }
135
136 /*-------------------------------------------------------------------------
137 * evalcoord1f - evaluate a point on a curve
138 *-------------------------------------------------------------------------
139 */
140 void
141 _SoNurbsCurveMap::evalcoord1f( REAL _u )
142 {
143 REAL pt[MAXCOORDS];
144 REAL pu[MAXCOORDS];
145 REAL puu[MAXCOORDS];
146
147 if( isdefined && isenabled ) {
148 init( order, stride, _u, lo, hi ); // XXX
149 for( int i=0; i != ncoords; i++ )
150 evaluate( &ctlpts[i], &pt[i], &pu[i], &puu[i] ); // XXX
151 domain( &_u );
152 uuderiv( puu );
153 uderiv( pu );
154 point( pt );
155 }
156 }
157
158 void
159 _SoNurbsCurveMap::deepCopy( REAL *_pts )
160 {
161 assert( _pts );
162
163 if( stride == ncoords ) {
164 memcpy( pts, _pts, order * ncoords * sizeof( REAL ) );
165 } else {
166 REAL *mp = pts;
167 REAL *p = _pts;
168 for( int i=0; i != order; i++, p += stride )
169 for( int j=0; j != ncoords; j++ )
170 *(mp++) = p[j];
171 }
172
173 ctlpts = pts;
174 stride = ncoords;
175 }
176
177 void
178 _SoNurbsCurveMap::deepCopyAndScale( REAL *_pts )
179 {
180 assert( _pts );
181
182 REAL *mp = pts;
183 REAL *p = _pts;
184 for( int i=0; i<order; i++, p += stride ) {
185 REAL comb = Ch(order-1, i);
186 for( int j=0; j<ncoords; j++ )
187 *(mp++) = p[j] * comb;
188 }
189
190 ctlpts = pts;
191 stride = ncoords;
192 }