Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

gunu_intersect.h

Go to the documentation of this file.
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_INTERSECT_H
00021 #define GUNU_INTERSECT_H
00022 
00023 namespace gunu {
00024 
00025 using gul::Ptr;
00026 using gul::point;
00027 using gul::hpoint;
00028 using gul::line2;
00029 using gul::cross_product;
00030 using gul::euclid;
00031 
00032 /*-----------------------------------------------------------------------
00033   Estimate the (u,v) parameter values of a point P for a NURBS surface F,
00034   assuming that A = F(0,0), B = F(1,0), C = F(0,1)
00035 ------------------------------------------------------------------------*/
00036 /*  this is nonsense
00037 template< class T >
00038 inline void BarycentricUV( 
00039                     const point<T> A, const point<T> B, const point<T> C,
00040                     const point<T> P, T *u, T *v )
00041 {
00042   point<T> AB,AC,AP;
00043   T fABC, fACP, fABP;
00044 
00045   AB = B - A;
00046   AC = C - A;
00047   fABC = cross_product( AB, AC );    // Flaecheninhalt Parallelogramm
00048   AP = P - A;
00049   fACP = cross_product( AC, AP );    // Flaecheninhalt Parallelogramm
00050   fABP = cross_product( AB, AP );
00051 
00052   *v = fABP / fABC;
00053   *u = fACP / fABC;
00054 }    
00055 */
00056 
00057 template< class T >
00058 class IntersectionLineInfo : public gul::pool_object
00059 {
00060 public:
00061   gul::point2<T> Suv[2];
00062   int            Sflag[2];
00063 };
00064 
00065 template< class T >
00066 class IntersectInfo : public gul::pool_object
00067 {
00068 public:
00069   T minx,miny,minz,scalei;
00070 
00071   gul::List<gul::ListNode<IntersectionLineInfo<T> > > IA,IB;
00072   // only for debugging
00073   gul::List<gul::ListNode<gul::line<T> > > IS;
00074 };
00075 
00076 template< class T, class HP >
00077 struct SurfaceInfo
00078 {
00079   int      nu;
00080   int      pu;
00081   Ptr< T > U; 
00082   int      nv;
00083   int      pv;
00084   Ptr< T > V;
00085   Ptr< Ptr< HP > > Pw;
00086   void    *reserved[2];   /* for boundaries */
00087 
00088   point<T> P00;    /* Eckpunkte der Flaeche (um zu verhindern,  */
00089   point<T> P01;    /* das an T-Stellen der Tesselierung Loecher */
00090   point<T> P10;    /* entstehen)                                */
00091   point<T> P11;
00092 
00093   void *operator new( size_t s )
00094   {
00095     size_t dummy;
00096 
00097     void *p = gust::PoolAlloc( s, &dummy );
00098     if( p == NULL ) throw gul::PoolAllocError();
00099     return(p);
00100   }  
00101   void operator delete( void *p, size_t s )
00102   {
00103     gust::PoolFree( p, s );
00104   }
00105 };
00106 
00107 template< class T, class HP >
00108 class TessInfo
00109 {
00110 public:
00111   T x1;   /* Bounding Box */
00112   T x2;
00113   T y1;
00114   T y2;
00115   T z1;
00116   T z2;
00117 
00118   T u1;   /* Parameterwerte der Flaeche (bezogen auf  */
00119   T u2;   /* die Originalflaeche)                     */
00120   T v1;
00121   T v2;
00122 
00123   unsigned int linearized : 1;
00124   unsigned int divided    : 1;
00125   
00126   SurfaceInfo<T,HP>      *org;    /* Originalzustand (ungeteilt); */
00127   TessInfo               *sub[4]; /* Flaeche in 4 Teilflaechen zerteilt */
00128 
00129   void operator delete( void *p, size_t s )
00130   {
00131     gust::PoolFree( p, s );
00132   }
00133   void *operator new( size_t s )
00134   {
00135     size_t dummy;
00136     void *p = gust::PoolAlloc( s, &dummy );
00137     if( p == NULL ) throw gul::PoolAllocError();
00138     return(p);
00139   }  
00140 
00141   TessInfo()
00142   {
00143     linearized = divided = 0;
00144     org = new SurfaceInfo<T,HP>();
00145     for( int i = 0; i < 4; i++ ) sub[i] = 0;
00146   }
00147   ~TessInfo()
00148   {
00149     int i;
00150 
00151 //    if( f.divided )
00152 //    {
00153       for( i = 0; i < 4; i++ )
00154       {
00155         delete sub[i];
00156         sub[i] = 0;
00157       }
00158 //    } 
00159 //    else
00160 //    {  
00161       delete org;   /* Speicher fuer ungeteilte Flaeche freigeben */
00162       org = 0;
00163 //    }  
00164   }
00165 };
00166 
00167 
00168 /*--------------------------------------------------------------------
00169   Check if a NURBS surface can be approximated with two triangles through
00170   its four corners. If not the surface is subdivided into four parts
00171 ----------------------------------------------------------------------*/
00172 template< class T, class HP >
00173 void LinearizeOrDivide( TessInfo<T,HP> *A, const T tol, 
00174                         bool need_bbox = false );
00175 
00176 /*-------------------------------------------------------------------
00177   Approximate NURBS-Surface with triangles
00178 --------------------------------------------------------------------*/
00179 template< class T, class HP >
00180 void DoLinearizeSurface( 
00181                  int current_iter, int max_iter,
00182                  TessInfo<T,HP> *A,
00183                  const T tol,
00184                  void    outfunc( TessInfo<T,HP> *, void * ),                                   
00185                  void   *outfunc_data );
00186 
00187 
00188 /*---------------------------------------------------------------------
00189   intersect the linear approximation of two nurbs surfaces
00190 ----------------------------------------------------------------------*/
00191 template< class T, class HP >
00192 void DoIntersectSurfaces( 
00193                  TessInfo<T,HP> *A, TessInfo<T,HP> *B,
00194                  T tol,
00195                  IntersectInfo<T> *II );
00196 
00197 /*---------------------------------------------------------------------
00198   intersects the linear approximation of two nurbs surfaces
00199 ----------------------------------------------------------------------*/
00200 template< class T, class HP >
00201 GULAPI void IntersectSurfaces( 
00202             int nu1, int pu1, const Ptr< T >& U1,
00203             int nv1, int pv1, const Ptr< T >& V1,
00204             const Ptr< Ptr < HP > >& Pw1,
00205             int nu2, int pu2, const Ptr< T >& U2,
00206             int nv2, int pv2, const Ptr< T >& V2,
00207             const Ptr< Ptr < HP > >& Pw2,
00208             T tol,
00209             gul::List<gul::ListNode<IntersectionLineInfo<T> > >& S1,
00210             gul::List<gul::ListNode<IntersectionLineInfo<T> > >& S2,
00211             gul::List<gul::ListNode<gul::line<T> > >& S );
00212 
00213 
00214 }
00215 
00216 #endif

Generated on Mon Jan 21 04:17:39 2002 for GUL 0.6 - Geometry Utility Library by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001