| 1 | // | 
|---|
| 2 | // tricoef.cc | 
|---|
| 3 | // | 
|---|
| 4 | // Copyright (C) 1996 Limit Point Systems, Inc. | 
|---|
| 5 | // | 
|---|
| 6 | // Author: Curtis Janssen <cljanss@limitpt.com> | 
|---|
| 7 | // Maintainer: LPS | 
|---|
| 8 | // | 
|---|
| 9 | // This file is part of the SC Toolkit. | 
|---|
| 10 | // | 
|---|
| 11 | // The SC Toolkit is free software; you can redistribute it and/or modify | 
|---|
| 12 | // it under the terms of the GNU Library General Public License as published by | 
|---|
| 13 | // the Free Software Foundation; either version 2, or (at your option) | 
|---|
| 14 | // any later version. | 
|---|
| 15 | // | 
|---|
| 16 | // The SC Toolkit is distributed in the hope that it will be useful, | 
|---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 19 | // GNU Library General Public License for more details. | 
|---|
| 20 | // | 
|---|
| 21 | // You should have received a copy of the GNU Library General Public License | 
|---|
| 22 | // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to | 
|---|
| 23 | // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 
|---|
| 24 | // | 
|---|
| 25 | // The U.S. Government is granted a limited license as per AL 91-7. | 
|---|
| 26 | // | 
|---|
| 27 |  | 
|---|
| 28 | #ifdef __GNUC__ | 
|---|
| 29 | #pragma implementation | 
|---|
| 30 | #endif | 
|---|
| 31 |  | 
|---|
| 32 | #include <math/isosurf/triangle.h> | 
|---|
| 33 | #include <math/isosurf/tricoef.h> | 
|---|
| 34 |  | 
|---|
| 35 | using namespace sc; | 
|---|
| 36 |  | 
|---|
| 37 | ///////////////////////////////////////////////////////////////////////// | 
|---|
| 38 | // Utility functions | 
|---|
| 39 |  | 
|---|
| 40 | static inline void | 
|---|
| 41 | init_coef_deriv(double L, int order, double *Lcoef, double *Lcoefderiv) | 
|---|
| 42 | { | 
|---|
| 43 | int i; | 
|---|
| 44 | Lcoef[0] = 1.0; | 
|---|
| 45 | Lcoefderiv[0] = 0.0; | 
|---|
| 46 | double spacing = 1.0/order; | 
|---|
| 47 | for (i=1; i<=order; i++) { | 
|---|
| 48 | Lcoef[i] = Lcoef[i-1] * (L - (i-1)*spacing)/(i*spacing); | 
|---|
| 49 | Lcoefderiv[i] = Lcoefderiv[i-1] * (L - (i-1)*spacing)/(i*spacing) | 
|---|
| 50 | + Lcoef[i-1]/(i*spacing); | 
|---|
| 51 | } | 
|---|
| 52 | } | 
|---|
| 53 |  | 
|---|
| 54 |  | 
|---|
| 55 | ///////////////////////////////////////////////////////////////////////// | 
|---|
| 56 | // The TriInterpCoef Utility Class | 
|---|
| 57 |  | 
|---|
| 58 | TriInterpCoef::TriInterpCoef(const TriInterpCoefKey& key) | 
|---|
| 59 | { | 
|---|
| 60 | int i,j,k; | 
|---|
| 61 |  | 
|---|
| 62 | int order = key.order(); | 
|---|
| 63 | double L1 = key.L1(); | 
|---|
| 64 | double L2 = key.L2(); | 
|---|
| 65 | double L3 = key.L3(); | 
|---|
| 66 | int n = order_to_nvertex(order); | 
|---|
| 67 | coef_ = new double[n]; | 
|---|
| 68 | rderiv_ = new double[n]; | 
|---|
| 69 | sderiv_ = new double[n]; | 
|---|
| 70 |  | 
|---|
| 71 | double L1coef[Triangle::max_order+1]; | 
|---|
| 72 | double L2coef[Triangle::max_order+1]; | 
|---|
| 73 | double L3coef[Triangle::max_order+1]; | 
|---|
| 74 |  | 
|---|
| 75 | double L1coefderiv[Triangle::max_order+1]; | 
|---|
| 76 | double L2coefderiv[Triangle::max_order+1]; | 
|---|
| 77 | double L3coefderiv[Triangle::max_order+1]; | 
|---|
| 78 |  | 
|---|
| 79 | init_coef_deriv(L1, order, L1coef, L1coefderiv); | 
|---|
| 80 | init_coef_deriv(L2, order, L2coef, L2coefderiv); | 
|---|
| 81 | init_coef_deriv(L3, order, L3coef, L3coefderiv); | 
|---|
| 82 |  | 
|---|
| 83 | // the r derivatives | 
|---|
| 84 | double L1coef_r[Triangle::max_order+1]; | 
|---|
| 85 | double L2coef_r[Triangle::max_order+1]; | 
|---|
| 86 | double L3coef_r[Triangle::max_order+1]; | 
|---|
| 87 |  | 
|---|
| 88 | // the s derivatives | 
|---|
| 89 | double L1coef_s[Triangle::max_order+1]; | 
|---|
| 90 | double L2coef_s[Triangle::max_order+1]; | 
|---|
| 91 | double L3coef_s[Triangle::max_order+1]; | 
|---|
| 92 |  | 
|---|
| 93 | // convert into r and s derivatives | 
|---|
| 94 | for (i=0; i<=order; i++) { | 
|---|
| 95 | L1coef_r[i] = -L1coefderiv[i]; | 
|---|
| 96 | L1coef_s[i] = -L1coefderiv[i]; | 
|---|
| 97 | L2coef_r[i] =  L2coefderiv[i]; | 
|---|
| 98 | L2coef_s[i] =  0.0; | 
|---|
| 99 | L3coef_r[i] =  0.0; | 
|---|
| 100 | L3coef_s[i] =  L3coefderiv[i]; | 
|---|
| 101 | } | 
|---|
| 102 |  | 
|---|
| 103 | for (i=0; i<=order; i++) { | 
|---|
| 104 | for (j=0; j <= order-i; j++) { | 
|---|
| 105 | k = order - i - j; | 
|---|
| 106 | coef(i,j,k) = L1coef[i]*L2coef[j]*L3coef[k]; | 
|---|
| 107 | sderiv(i,j,k) = L1coef_s[i]*L2coef[j]*L3coef[k] | 
|---|
| 108 | +L1coef[i]*L2coef_s[j]*L3coef[k] | 
|---|
| 109 | +L1coef[i]*L2coef[j]*L3coef_s[k]; | 
|---|
| 110 | rderiv(i,j,k) = L1coef_r[i]*L2coef[j]*L3coef[k] | 
|---|
| 111 | +L1coef[i]*L2coef_r[j]*L3coef[k] | 
|---|
| 112 | +L1coef[i]*L2coef[j]*L3coef_r[k]; | 
|---|
| 113 | } | 
|---|
| 114 | } | 
|---|
| 115 | } | 
|---|
| 116 |  | 
|---|
| 117 | TriInterpCoef::~TriInterpCoef() | 
|---|
| 118 | { | 
|---|
| 119 | delete[] coef_; | 
|---|
| 120 | delete[] rderiv_; | 
|---|
| 121 | delete[] sderiv_; | 
|---|
| 122 | } | 
|---|
| 123 |  | 
|---|
| 124 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 125 |  | 
|---|
| 126 | // Local Variables: | 
|---|
| 127 | // mode: c++ | 
|---|
| 128 | // c-file-style: "CLJ" | 
|---|
| 129 | // End: | 
|---|