00001 /* LIBGUL - Geometry Utility Library 00002 * Copyright (C) 1998-1999 Norbert Irmer 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Library General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Library General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Library General Public 00015 * License along with this library; if not, write to the 00016 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 * Boston, MA 02111-1307, USA. 00018 */ 00019 00020 #ifndef GUNU_REFINE_H 00021 #define GUNU_REFINE_H 00022 00023 namespace gunu { 00024 00025 using gul::Ptr; 00026 00027 /*-------------------------------------------------------------------------*//** 00028 Inserts 'r'+1 knots given by the refinement vector 'X' into the knot vector 00029 of a curve (and calculates the changed control points). 00030 no validity checks are made, multiplicity of the inserted knots mustn't 00031 exceed the degree 'p', memory for the new knot vector 'Ubar' and control 00032 point vector 'Q' must be reserved by the caller: Ubar: n+p+2+r, Q: n+1+r */ 00033 /*----------------------------------------------------------------------------*/ 00034 template< class T, class HP > 00035 void RefineCurve( int n, int p, const Ptr<T>& U, const Ptr<HP> P, 00036 const Ptr<T> X, int r, Ptr<T>& Ubar, Ptr<HP> Q ); 00037 00038 /*-------------------------------------------------------------------------*//** 00039 Inserts 'r'+1 knots given by the refinement vector 'X' into the U or 00040 V knot vector of a surface (and calculates the changed control points). 00041 no validity checks are made, multiplicity of the inserted knots mustn't 00042 exceed the degree 'pu' or 'pv', memory for the new knot vectors 'Ubar' 00043 and Vbar and the control point matrix 'Q' must be reserved by the caller: 00044 Ubar: nu+pu+2+r, Q: [nv]*[nu+1+r], if 'dir' == u_direction, 00045 Vbar: nv+pv+2+r, Q: [nv+1+r]*[nu], if 'dir' == v_direction */ 00046 /*----------------------------------------------------------------------------*/ 00047 00048 template< class T, class HP > 00049 void RefineSurfaceU( 00050 int nu, int pu, const Ptr<T>& U, int nv, int pv, const Ptr<T>& V, 00051 const Ptr< Ptr< HP > >& P, const Ptr<T>& X, int r, 00052 Ptr<T>& Ubar, Ptr<T>& Vbar, Ptr< Ptr< HP > >& Q ); 00053 00054 template< class T, class HP > 00055 void RefineSurfaceV( 00056 int nu, int pu, const Ptr<T>& U, int nv, int pv, const Ptr<T>& V, 00057 const Ptr< Ptr< HP > >& P, const Ptr<T>& X, int r, 00058 Ptr<T>& Ubar, Ptr<T>& Vbar, Ptr< Ptr< HP > >& Q ); 00059 00060 template< class T, class HP > 00061 void RefineSurface( 00062 int nu, int pu, const Ptr<T>& U, int nv, int pv, const Ptr<T>& V, 00063 const Ptr< Ptr< HP > >& P, const Ptr<T>& X, int r, int dir, 00064 Ptr<T>& Ubar, Ptr<T>& Vbar, Ptr< Ptr< HP > >& Q ) 00065 { 00066 if( dir == gul::u_direction ) 00067 RefineSurfaceU( nu,pu,U,nv,pv,V,P,X,r,Ubar,Vbar,Q ); 00068 else 00069 RefineSurfaceV( nu,pu,U,nv,pv,V,P,X,r,Ubar,Vbar,Q ); 00070 } 00071 00072 /*----------------------------------------------------------------- 00073 Calculates the positions and multiplicities of the inner knots 00074 and the last knot (knot vector must be clamped) of a knot vector 00075 -----------------------------------------------------------------*/ 00076 template< class T > 00077 int BezierPositions( int n, int p, const Ptr<T>& U, 00078 Ptr<int>& K, Ptr<int>& M ); 00079 00080 /*-------------------------------------------------------------------------*//** 00081 decompose a curve into its Bezier segments. returns the number of created 00082 segments */ 00083 /*----------------------------------------------------------------------------*/ 00084 template< class T, class HP > 00085 void BezierDecomposeCurve( 00086 int nK, const Ptr<int>& K, const Ptr<int>& M, 00087 int n, int p, const Ptr<T>& U, const Ptr<HP>& Pw, 00088 Ptr< Ptr<HP> > *retQw ); 00089 00090 /*-------------------------------------------------------------------------*//** 00091 decompose a surface in u or v direction into its Bezier segments. 00092 when for example decomposing in U-direction, the function returns 00093 a array containing bezier strips with [nv+1]*[pu+1] control point 00094 matrices, the function result is the number of created bezier segments */ 00095 /*----------------------------------------------------------------------------*/ 00096 /* Example for decomposition in U-direction: 00097 00098 -----------------------------------------> (U-direction)| 00099 | 00100 | Bezier : Bezier : Bezier : 00101 | Stip : Strip : Strip : ... 00102 (nv)- | 0 : 1 : 2 : 00103 rows | : : : 00104 | <------> : <------> : <------> : 00105 | (pu+1)- : (pu+1)- : (pu+1)- : 00106 | columns : columns : columns : 00107 | : : : 00108 | : : : 00109 | : : : 00110 V 00111 (V-direction) 00112 */ 00113 00114 template< class T, class HP > 00115 void BezierDecomposeSurfaceU( 00116 int nK, const Ptr<int>& K, const Ptr<int>& M, 00117 int nu, int pu, const Ptr<T>& U, 00118 int nv, int pv, const Ptr<T>& V, 00119 const Ptr< Ptr<HP> >& Pw, 00120 Ptr< Ptr< Ptr<HP> > > *retQw ); 00121 00122 template< class T, class HP > 00123 void BezierDecomposeSurfaceV( 00124 int nK, const Ptr<int>& K, const Ptr<int>& M, 00125 int nu, int pu, const Ptr<T>& U, 00126 int nv, int pv, const Ptr<T>& V, 00127 const Ptr< Ptr<HP> >& Pw, 00128 Ptr< Ptr< Ptr<HP> > > *retQw ); 00129 00130 template< class T, class HP > 00131 inline void BezierDecomposeSurface( 00132 int nu, int pu, const Ptr<T>& U, 00133 int nv, int pv, const Ptr<T>& V, 00134 const Ptr< Ptr<HP> >& Pw, int dir, 00135 Ptr< Ptr< Ptr<HP> > > *retQw ) 00136 { 00137 int nK; 00138 Ptr<int> K,M; 00139 00140 if( dir == gul::u_direction ) 00141 { 00142 nK = BezierPositions( nu, pu, U, K, M ); 00143 BezierDecomposeSurfaceU( nK,K,M,nu,pu,U,nv,pv,V,Pw,retQw ); 00144 } 00145 else 00146 { 00147 nK = BezierPositions( nv, pv, V, K, M ); 00148 BezierDecomposeSurfaceV( nK,K,M,nu,pu,U,nv,pv,V,Pw,retQw ); 00149 } 00150 } 00151 00152 00153 } 00154 00155 #endif 00156 00157