subdivider.h revision f220fa62
1f220fa62Smrg/*
2f220fa62Smrg * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3f220fa62Smrg * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
4f220fa62Smrg *
5f220fa62Smrg * Permission is hereby granted, free of charge, to any person obtaining a
6f220fa62Smrg * copy of this software and associated documentation files (the "Software"),
7f220fa62Smrg * to deal in the Software without restriction, including without limitation
8f220fa62Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9f220fa62Smrg * and/or sell copies of the Software, and to permit persons to whom the
10f220fa62Smrg * Software is furnished to do so, subject to the following conditions:
11f220fa62Smrg *
12f220fa62Smrg * The above copyright notice including the dates of first publication and
13f220fa62Smrg * either this permission notice or a reference to
14f220fa62Smrg * http://oss.sgi.com/projects/FreeB/
15f220fa62Smrg * shall be included in all copies or substantial portions of the Software.
16f220fa62Smrg *
17f220fa62Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18f220fa62Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19f220fa62Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20f220fa62Smrg * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21f220fa62Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22f220fa62Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23f220fa62Smrg * SOFTWARE.
24f220fa62Smrg *
25f220fa62Smrg * Except as contained in this notice, the name of Silicon Graphics, Inc.
26f220fa62Smrg * shall not be used in advertising or otherwise to promote the sale, use or
27f220fa62Smrg * other dealings in this Software without prior written authorization from
28f220fa62Smrg * Silicon Graphics, Inc.
29f220fa62Smrg */
30f220fa62Smrg
31f220fa62Smrg/*
32f220fa62Smrg * subdivider.h
33f220fa62Smrg *
34f220fa62Smrg */
35f220fa62Smrg
36f220fa62Smrg#ifndef __glusubdivider_h_
37f220fa62Smrg#define __glusubdivider_h_
38f220fa62Smrg
39f220fa62Smrg#include "mysetjmp.h"
40f220fa62Smrg#include "bin.h"
41f220fa62Smrg#include "flist.h"
42f220fa62Smrg#include "slicer.h"
43f220fa62Smrg#include "arctess.h"
44f220fa62Smrg#include "trimvertex.h"
45f220fa62Smrg#include "trimvertpool.h"
46f220fa62Smrg
47f220fa62Smrgclass Arc;
48f220fa62Smrgclass Pool;
49f220fa62Smrgclass Renderhints;
50f220fa62Smrgclass Quilt;
51f220fa62Smrgclass Patchlist;
52f220fa62Smrgclass Curvelist;
53f220fa62Smrgstruct JumpBuffer;
54f220fa62Smrg
55f220fa62Smrgclass Subdivider {
56f220fa62Smrgpublic:
57f220fa62Smrg			Subdivider( Renderhints&, Backend& );
58f220fa62Smrg			~Subdivider( void );
59f220fa62Smrg    void		clear( void );
60f220fa62Smrg
61f220fa62Smrg    void		beginTrims( void ) {}
62f220fa62Smrg    void		beginLoop( void );
63f220fa62Smrg    void		addArc( REAL *, Quilt *, long );
64f220fa62Smrg    void		addArc( int, TrimVertex *, long );
65f220fa62Smrg    void		endLoop( void ) {}
66f220fa62Smrg    void		endTrims( void ) {}
67f220fa62Smrg
68f220fa62Smrg    void		beginQuilts( void );
69f220fa62Smrg    void		addQuilt( Quilt * );
70f220fa62Smrg    void		endQuilts( void ) {}
71f220fa62Smrg
72f220fa62Smrg    void		drawCurves( void );
73f220fa62Smrg    void		drawSurfaces( long );
74f220fa62Smrg
75f220fa62Smrg    int			ccwTurn_sl( Arc_ptr, Arc_ptr  );
76f220fa62Smrg    int			ccwTurn_sr( Arc_ptr , Arc_ptr   );
77f220fa62Smrg    int			ccwTurn_tl( Arc_ptr , Arc_ptr  );
78f220fa62Smrg    int			ccwTurn_tr( Arc_ptr , Arc_ptr  );
79f220fa62Smrg
80f220fa62Smrg    void		setJumpbuffer( JumpBuffer * );
81f220fa62Smrg
82f220fa62Smrg    void set_domain_distance_u_rate(REAL u_rate)
83f220fa62Smrg      {
84f220fa62Smrg	domain_distance_u_rate = u_rate;
85f220fa62Smrg      }
86f220fa62Smrg    void set_domain_distance_v_rate(REAL v_rate)
87f220fa62Smrg      {
88f220fa62Smrg	domain_distance_v_rate = v_rate;
89f220fa62Smrg      }
90f220fa62Smrg    void set_is_domain_distance_sampling(int flag)
91f220fa62Smrg      {
92f220fa62Smrg	is_domain_distance_sampling = flag;
93f220fa62Smrg      }
94f220fa62Smrg
95f220fa62Smrgprivate:
96f220fa62Smrg    void		classify_headonleft_s( Bin &, Bin &, Bin &, REAL );
97f220fa62Smrg    void		classify_tailonleft_s( Bin &, Bin &, Bin &, REAL );
98f220fa62Smrg    void		classify_headonright_s( Bin &, Bin &, Bin &, REAL );
99f220fa62Smrg    void		classify_tailonright_s( Bin &, Bin &, Bin &, REAL );
100f220fa62Smrg    void		classify_headonleft_t( Bin &, Bin &, Bin &, REAL );
101f220fa62Smrg    void		classify_tailonleft_t( Bin &, Bin &, Bin &, REAL );
102f220fa62Smrg    void		classify_headonright_t( Bin &, Bin &, Bin &, REAL );
103f220fa62Smrg    void		classify_tailonright_t( Bin &, Bin &, Bin &, REAL );
104f220fa62Smrg
105f220fa62Smrg    enum dir 		{ down, same, up, none };
106f220fa62Smrg    void		tessellate( Arc_ptr, REAL );
107f220fa62Smrg    void		monotonize( Arc_ptr , Bin & );
108f220fa62Smrg    int			isMonotone( Arc_ptr  );
109f220fa62Smrg    int			decompose( Bin &, REAL );
110f220fa62Smrg
111f220fa62Smrg
112f220fa62Smrg    Slicer		slicer;
113f220fa62Smrg    ArcTessellator	arctessellator;
114f220fa62Smrg    Pool		arcpool;
115f220fa62Smrg    Pool		bezierarcpool;
116f220fa62Smrg    Pool		pwlarcpool;
117f220fa62Smrg    TrimVertexPool	trimvertexpool;
118f220fa62Smrg
119f220fa62Smrg    JumpBuffer*		jumpbuffer;
120f220fa62Smrg    Renderhints&	renderhints;
121f220fa62Smrg    Backend&		backend;
122f220fa62Smrg
123f220fa62Smrg    Bin			initialbin;
124f220fa62Smrg    Arc_ptr		pjarc;
125f220fa62Smrg    int 		s_index;
126f220fa62Smrg    int			t_index;
127f220fa62Smrg    Quilt *		qlist;
128f220fa62Smrg    Flist		spbrkpts;
129f220fa62Smrg    Flist		tpbrkpts;
130f220fa62Smrg    Flist		smbrkpts;
131f220fa62Smrg    Flist		tmbrkpts;
132f220fa62Smrg    REAL	 	stepsizes[4];
133f220fa62Smrg    int			showDegenerate;
134f220fa62Smrg    int			isArcTypeBezier;
135f220fa62Smrg
136f220fa62Smrg    void		samplingSplit( Curvelist&, int );
137f220fa62Smrg
138f220fa62Smrg    void		subdivideInS( Bin&  );
139f220fa62Smrg    void		splitInS( Bin&, int, int );
140f220fa62Smrg    void		splitInT( Bin&, int, int );
141f220fa62Smrg    void		samplingSplit( Bin&, Patchlist&, int, int );
142f220fa62Smrg    void		nonSamplingSplit( Bin&, Patchlist&, int, int );
143f220fa62Smrg    void		tessellation( Bin&, Patchlist& );
144f220fa62Smrg    void		monosplitInS( Bin&, int, int );
145f220fa62Smrg    void		monosplitInT( Bin&, int, int );
146f220fa62Smrg
147f220fa62Smrg    void		outline( Bin & );
148f220fa62Smrg    void		freejarcs( Bin & );
149f220fa62Smrg    void		render( Bin & );
150f220fa62Smrg    void		split( Bin &, Bin &, Bin &, int, REAL );
151f220fa62Smrg    void		tessellate( Bin &, REAL, REAL, REAL, REAL );
152f220fa62Smrg
153f220fa62Smrg    inline void		setDegenerate( void ) { showDegenerate = 1; }
154f220fa62Smrg    inline void		setNonDegenerate( void ) { showDegenerate = 0; }
155f220fa62Smrg    inline int		showingDegenerate( void ) { return showDegenerate; }
156f220fa62Smrg    inline void		setArcTypeBezier( void ) { isArcTypeBezier = 1; }
157f220fa62Smrg    inline void		setArcTypePwl( void ) { isArcTypeBezier = 0; }
158f220fa62Smrg    inline int		isBezierArcType( void ) { return isArcTypeBezier; }
159f220fa62Smrg
160f220fa62Smrg    void		makeBorderTrim( const REAL *, const REAL * );
161f220fa62Smrg    void		split( Bin &, int, const REAL *, int, int );
162f220fa62Smrg    void		partition( Bin &, Bin &, Bin &, Bin &, Bin &, int, REAL );
163f220fa62Smrg    void		findIrregularS( Bin & );
164f220fa62Smrg    void		findIrregularT( Bin & );
165f220fa62Smrg
166f220fa62Smrg
167f220fa62Smrg    inline int		bbox( TrimVertex *, TrimVertex *, TrimVertex *, int );
168f220fa62Smrg    static int		bbox( REAL, REAL, REAL, REAL, REAL, REAL );
169f220fa62Smrg    static int		ccw( TrimVertex *, TrimVertex *, TrimVertex * );
170f220fa62Smrg    void		join_s( Bin &, Bin &, Arc_ptr, Arc_ptr  );
171f220fa62Smrg    void		join_t( Bin &, Bin &, Arc_ptr , Arc_ptr  );
172f220fa62Smrg    int			arc_split( Arc_ptr , int, REAL, int );
173f220fa62Smrg    void		check_s( Arc_ptr , Arc_ptr  );
174f220fa62Smrg    void		check_t( Arc_ptr , Arc_ptr  );
175f220fa62Smrg    inline void		link( Arc_ptr , Arc_ptr , Arc_ptr , Arc_ptr  );
176f220fa62Smrg    inline void		simple_link( Arc_ptr , Arc_ptr  );
177f220fa62Smrg
178f220fa62Smrg   Bin*                 makePatchBoundary( const REAL *from, const REAL *to );
179f220fa62Smrg
180f220fa62Smrg   /*in domain distance method, the tessellation is controled by two numbers:
181f220fa62Smrg    *GLU_U_STEP: number of u-segments per unit u length of domain
182f220fa62Smrg    *GLU_V_STEP: number of v-segments per unit v length of domain
183f220fa62Smrg    *These two numbers are normally stored in mapdesc->maxs(t)rate.
184f220fa62Smrg    *I (ZL) put these two numbers here so that I can optimize the untrimmed
185f220fa62Smrg    *case in the case of domain distance sampling.
186f220fa62Smrg    *These two numbers are set by set_domain_distance_u_rate() and ..._v_..().
187f220fa62Smrg    */
188f220fa62Smrg   REAL domain_distance_u_rate;
189f220fa62Smrg   REAL domain_distance_v_rate;
190f220fa62Smrg   int is_domain_distance_sampling;
191f220fa62Smrg};
192f220fa62Smrg
193f220fa62Smrginline void
194f220fa62SmrgSubdivider::beginLoop( void )
195f220fa62Smrg{
196f220fa62Smrg    pjarc = 0;
197f220fa62Smrg}
198f220fa62Smrg
199f220fa62Smrg
200f220fa62Smrg#endif /* __glusubdivider_h_ */
201