1 /* 2 * Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT, 3 * Applied Mathematics, Norway. 4 * 5 * Contact information: E-mail: tor.dokken@sintef.no 6 * SINTEF ICT, Department of Applied Mathematics, 7 * P.O. Box 124 Blindern, 8 * 0314 Oslo, Norway. 9 * 10 * This file is part of SISL. 11 * 12 * SISL is free software: you can redistribute it and/or modify 13 * it under the terms of the GNU Affero General Public License as 14 * published by the Free Software Foundation, either version 3 of the 15 * License, or (at your option) any later version. 16 * 17 * SISL is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU Affero General Public License for more details. 21 * 22 * You should have received a copy of the GNU Affero General Public 23 * License along with SISL. If not, see 24 * <http://www.gnu.org/licenses/>. 25 * 26 * In accordance with Section 7(b) of the GNU Affero General Public 27 * License, a covered work must retain the producer line in every data 28 * file that is created or manipulated using SISL. 29 * 30 * Other Usage 31 * You can be released from the requirements of the license by purchasing 32 * a commercial license. Buying such a license is mandatory as soon as you 33 * develop commercial activities involving the SISL library without 34 * disclosing the source code of your own applications. 35 * 36 * This file may be used in accordance with the terms contained in a 37 * written agreement between you and SINTEF ICT. 38 */ 39 40 #include "sisl-copyright.h" 41 42 /* 43 * 44 * $Id: make3D.c,v 1.3 2001-03-19 16:13:07 afr Exp $ 45 * 46 */ 47 48 49 #define MAKE3D 50 51 #include "sislP.h" 52 53 54 #if defined(SISLNEEDPROTOTYPES) 55 void make3D(SISLSurf * ps,SISLSurf ** rsnew,int * jstat)56 make3D (SISLSurf *ps, SISLSurf **rsnew, int *jstat) 57 #else 58 void 59 make3D (ps, rsnew, jstat) 60 SISLSurf *ps; 61 SISLSurf **rsnew; 62 int *jstat; 63 #endif 64 /* 65 ******************************************************************** 66 * 67 ********************************************************************* 68 * 69 * PURPOSE : To convert a 1D surface to a 3D representation. 70 * 71 * 72 * 73 * INPUT : ps - 1D Surface. 74 * 75 * 76 * 77 * OUTPUT : rsnew - The 3D surface. 78 * jstat - status messages 79 * > 0 : warning 80 * = 0 : ok 81 * < 0 : error 82 * 83 * 84 * METHOD : We want to change f(u,v) ----> (u,v,f(u,v)). 85 * Using marsdens identity on u and v will do the job. 86 * (In fact the u and v are translated to origin and scaled.) 87 * 88 * 89 * REFERENCES : 90 * 91 *- 92 * 93 * WRITTEN BY : Ulf J. Krystad, SI, 10.94. 94 * Revised by : 95 * 96 **********************************************************************/ 97 { 98 99 int kk1,kk2,kn1,kn2; /* Orders and numbers of vertices */ 100 double *st1,*st2,*scoef; /* Knots and vertices of input surface */ 101 double *s3coef=SISL_NULL; /* 3-D coeff */ 102 int kkm1,kkm2; /* Orders minus 1 */ 103 int kincre; /* Number of doubles in first vertex direction */ 104 int ki,kj,kl,kstop; 105 double tsum,*sp,*sq; 106 //int kstat=0,kpos=0; 107 108 if (!ps) goto errnull; 109 if (ps->idim != 1) goto errdim; 110 111 112 kk1 = ps -> ik1; 113 kk2 = ps -> ik2; 114 kn1 = ps -> in1; 115 kn2 = ps -> in2; 116 st1 = ps -> et1; 117 st2 = ps -> et2; 118 scoef = ps -> ecoef; 119 120 /* Allocate array for 3-D representation of surface */ 121 122 if((s3coef = newarray(kn1*kn2*3,DOUBLE)) == SISL_NULL) goto err101; 123 124 125 126 /* Make 3-D description of the surface */ 127 128 129 /* Make representation of coefficients from Marsdens identity for the 130 * function f(t) = t, this will be used as the x-coordinate in the 3-D 131 * representation */ 132 133 kkm1 = kk1 - 1; 134 kincre = 3*kn1; 135 136 for (ki=0,kl=0,sp=s3coef ; ki<kn1 ; ki++,kl+=3,sp+=3) 137 { 138 tsum = (double)0.0; 139 kstop = ki+kk1; 140 for (kj=ki+1;kj<kstop;kj++) 141 tsum +=st1[kj]; 142 143 tsum = tsum/kkm1; 144 145 146 /* Copy x-coordinate to the other vertex rows */ 147 for (kj=0,sq=sp ; kj<kn2 ; kj++,sq+=kincre) *sq = tsum; 148 149 } 150 151 /* Make representation of coefficients from Marsdens identity for the 152 * function f(t) = t, with the knot vector in second parameter direction 153 * scaled to [0,tfak]. This will be used as the x-coordinate in the 3-D 154 * representation */ 155 156 kkm2 = kk2 - 1; 157 for (ki=0,sp=s3coef+1 ; ki< kn2 ; ki++) 158 { 159 tsum = (double)0.0; 160 kstop = ki+kk2; 161 for (kj=ki+1;kj<kstop;kj++) 162 tsum +=st2[kj]; 163 164 tsum = tsum/kkm2; 165 166 /* Copy to remaining y-coordinates in first vertex row */ 167 168 for (kj=0 ; kj<kn1 ; kj++,sp+=3) *sp = tsum; 169 170 } 171 172 /* Copy z-coordinates */ 173 174 for (kj=0,sp=s3coef+2,sq=scoef ; kj < kn2 ; kj++) 175 for (ki=0 ; ki<kn1 ; ki++,sp+=3,sq++) 176 *sp = *sq; 177 178 /* Make 3-D surface */ 179 180 if(((*rsnew) = newSurf(kn1,kn2,kk1,kk2,st1,st2,s3coef,1,3,1)) == SISL_NULL) goto err101; 181 182 goto out; 183 184 /* ____________________________________________________________________ */ 185 /* Error in alloc */ 186 err101: 187 *jstat = -101; 188 s6err ("make3D", *jstat, 0); 189 goto out; 190 191 /* Null pointer */ 192 errnull: 193 *jstat = -200; 194 s6err ("make3D", *jstat, 0); 195 goto out; 196 197 /* Dimension NE 1 */ 198 errdim: 199 *jstat = -201; 200 s6err ("make3D", *jstat, 0); 201 goto out; 202 203 out: 204 if (s3coef) freearray(s3coef); 205 206 } 207