#ifndef __glusubdivider_h_
#define __glusubdivider_h_
#include "mysetjmp.h"
#include "bin.h"
#include "flist.h"
#include "slicer.h"
#include "arctess.h"
#include "trimvertex.h"
#include "trimvertpool.h"
class Arc;
class Pool;
class Renderhints;
class Quilt;
class Patchlist;
class Curvelist;
struct JumpBuffer;
class Subdivider {
public:
Subdivider( Renderhints&, Backend& );
~Subdivider( void );
void clear( void );
void beginTrims( void ) {}
void beginLoop( void );
void addArc( REAL *, Quilt *, long );
void addArc( int, TrimVertex *, long );
void endLoop( void ) {}
void endTrims( void ) {}
void beginQuilts( void );
void addQuilt( Quilt * );
void endQuilts( void ) {}
void drawCurves( void );
void drawSurfaces( long );
int ccwTurn_sl( Arc_ptr, Arc_ptr );
int ccwTurn_sr( Arc_ptr , Arc_ptr );
int ccwTurn_tl( Arc_ptr , Arc_ptr );
int ccwTurn_tr( Arc_ptr , Arc_ptr );
void setJumpbuffer( JumpBuffer * );
void set_domain_distance_u_rate(REAL u_rate)
{
domain_distance_u_rate = u_rate;
}
void set_domain_distance_v_rate(REAL v_rate)
{
domain_distance_v_rate = v_rate;
}
void set_is_domain_distance_sampling(int flag)
{
is_domain_distance_sampling = flag;
}
private:
void classify_headonleft_s( Bin &, Bin &, Bin &, REAL );
void classify_tailonleft_s( Bin &, Bin &, Bin &, REAL );
void classify_headonright_s( Bin &, Bin &, Bin &, REAL );
void classify_tailonright_s( Bin &, Bin &, Bin &, REAL );
void classify_headonleft_t( Bin &, Bin &, Bin &, REAL );
void classify_tailonleft_t( Bin &, Bin &, Bin &, REAL );
void classify_headonright_t( Bin &, Bin &, Bin &, REAL );
void classify_tailonright_t( Bin &, Bin &, Bin &, REAL );
enum dir { down, same, up, none };
void tessellate( Arc_ptr, REAL );
void monotonize( Arc_ptr , Bin & );
int isMonotone( Arc_ptr );
int decompose( Bin &, REAL );
Slicer slicer;
ArcTessellator arctessellator;
Pool arcpool;
Pool bezierarcpool;
Pool pwlarcpool;
TrimVertexPool trimvertexpool;
JumpBuffer* jumpbuffer;
Renderhints& renderhints;
Backend& backend;
Bin initialbin;
Arc_ptr pjarc;
int s_index;
int t_index;
Quilt * qlist;
Flist spbrkpts;
Flist tpbrkpts;
Flist smbrkpts;
Flist tmbrkpts;
REAL stepsizes[4];
int showDegenerate;
int isArcTypeBezier;
void samplingSplit( Curvelist&, int );
void subdivideInS( Bin& );
void splitInS( Bin&, int, int );
void splitInT( Bin&, int, int );
void samplingSplit( Bin&, Patchlist&, int, int );
void nonSamplingSplit( Bin&, Patchlist&, int, int );
void tessellation( Bin&, Patchlist& );
void monosplitInS( Bin&, int, int );
void monosplitInT( Bin&, int, int );
void outline( Bin & );
void freejarcs( Bin & );
void render( Bin & );
void split( Bin &, Bin &, Bin &, int, REAL );
void tessellate( Bin &, REAL, REAL, REAL, REAL );
inline void setDegenerate( void ) { showDegenerate = 1; }
inline void setNonDegenerate( void ) { showDegenerate = 0; }
inline int showingDegenerate( void ) { return showDegenerate; }
inline void setArcTypeBezier( void ) { isArcTypeBezier = 1; }
inline void setArcTypePwl( void ) { isArcTypeBezier = 0; }
inline int isBezierArcType( void ) { return isArcTypeBezier; }
void makeBorderTrim( const REAL *, const REAL * );
void split( Bin &, int, const REAL *, int, int );
void partition( Bin &, Bin &, Bin &, Bin &, Bin &, int, REAL );
void findIrregularS( Bin & );
void findIrregularT( Bin & );
inline int bbox( TrimVertex *, TrimVertex *, TrimVertex *, int );
static int bbox( REAL, REAL, REAL, REAL, REAL, REAL );
static int ccw( TrimVertex *, TrimVertex *, TrimVertex * );
void join_s( Bin &, Bin &, Arc_ptr, Arc_ptr );
void join_t( Bin &, Bin &, Arc_ptr , Arc_ptr );
int arc_split( Arc_ptr , int, REAL, int );
void check_s( Arc_ptr , Arc_ptr );
void check_t( Arc_ptr , Arc_ptr );
inline void link( Arc_ptr , Arc_ptr , Arc_ptr , Arc_ptr );
inline void simple_link( Arc_ptr , Arc_ptr );
Bin* makePatchBoundary( const REAL *from, const REAL *to );
REAL domain_distance_u_rate;
REAL domain_distance_v_rate;
int is_domain_distance_sampling;
};
inline void
Subdivider::beginLoop( void )
{
pjarc = 0;
}
#endif