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 33f220fa62Smrg#ifndef _MONO_TRIANGULATION_H 34f220fa62Smrg#define _MONO_TRIANGULATION_H 35f220fa62Smrg 36f220fa62Smrg#include "definitions.h" 37f220fa62Smrg#include "primitiveStream.h" 38f220fa62Smrg#include "directedLine.h" 39f220fa62Smrg#include "arc.h" 40f220fa62Smrg 41f220fa62Smrgclass Backend; 42f220fa62Smrg 43f220fa62Smrgclass reflexChain{ 44f220fa62Smrg Real2 *queue; 45f220fa62Smrg /*the order of the polygon vertices: either q[0],q[1].., or 46f220fa62Smrg * q[n-1], q[n-2], ..., q[0] 47f220fa62Smrg *this order determines the interior of the polygon, so it 48f220fa62Smrg *also used to determines whether a chain is reflex or convex 49f220fa62Smrg */ 50f220fa62Smrg Int isIncreasing; 51f220fa62Smrg Int index_queue; 52f220fa62Smrg Int size_queue; /*allocated size*/ 53f220fa62Smrg 54f220fa62Smrgpublic: 55f220fa62Smrg reflexChain(Int size, Int isIncreasing); 56f220fa62Smrg ~reflexChain(); 57f220fa62Smrg 58f220fa62Smrg void insert(Real u, Real v); 59f220fa62Smrg void insert(Real v[2]); 60f220fa62Smrg 61f220fa62Smrg void processNewVertex(Real v[2], primStream* pStream); 62f220fa62Smrg void outputFan(Real v[2], primStream* pStream); 63f220fa62Smrg 64f220fa62Smrg void processNewVertex(Real v[2], Backend* backend); 65f220fa62Smrg void outputFan(Real v[2], Backend* backend); 66f220fa62Smrg 67f220fa62Smrg void print(); 68f220fa62Smrg}; 69f220fa62Smrg 70f220fa62Smrg/*dynamic array of pointers to reals. 71f220fa62Smrg *Intended to store an array of (u,v). 72f220fa62Smrg *Notice that it doesn't allocate or dealocate the space 73f220fa62Smrg *for the (u,v) themselfs. So it assums that someone else 74f220fa62Smrg *is taking care of them, while this class only plays with 75f220fa62Smrg *the pointers. 76f220fa62Smrg */ 77f220fa62Smrgclass vertexArray{ 78f220fa62Smrg Real** array; 79f220fa62Smrg Int index; 80f220fa62Smrg Int size; 81f220fa62Smrgpublic: 82f220fa62Smrg vertexArray(Int s); 83f220fa62Smrg vertexArray(Real vertices[][2], Int nVertices); 84f220fa62Smrg ~vertexArray(); 85f220fa62Smrg void appendVertex(Real* ptr); /*the content (pointed by ptr is NOT copied*/ 86f220fa62Smrg Real* getVertex(Int i) {return array[i];} 87f220fa62Smrg Real** getArray() {return array;} 88f220fa62Smrg Int getNumElements() {return index;} 89f220fa62Smrg Int findIndexAbove(Real v); 90f220fa62Smrg Int findIndexAboveGen(Real v, Int startIndex, Int EndIndex); 91f220fa62Smrg Int findIndexBelowGen(Real v, Int startIndex, Int EndIndex); 92f220fa62Smrg Int findIndexStrictBelowGen(Real v, Int startIndex, Int EndIndex); 93f220fa62Smrg Int findIndexFirstAboveEqualGen(Real v, Int startIndex, Int endIndex); 94f220fa62Smrg Int skipEqualityFromStart(Real v, Int start, Int end); 95f220fa62Smrg //return i such that fron [i+1, end] is strictly U-monotone (left to right 96f220fa62Smrg Int findDecreaseChainFromEnd(Int begin, Int end); 97f220fa62Smrg void print(); 98f220fa62Smrg}; 99f220fa62Smrg 100f220fa62Smrgvoid monoTriangulation(directedLine* monoPolygon, primStream* pStream); 101f220fa62Smrg 102f220fa62Smrgvoid monoTriangulationRec(Real* topVertex, Real* botVertex, 103f220fa62Smrg vertexArray* inc_chain, Int inc_current, 104f220fa62Smrg vertexArray* dec_chain, Int dec_current, 105f220fa62Smrg primStream* pStream); 106f220fa62Smrg 107f220fa62Smrgvoid monoTriangulationRec(directedLine* inc_chain, Int inc_index, 108f220fa62Smrg directedLine* dec_chain, Int dec_index, 109f220fa62Smrg directedLine* topVertex, Int top_index, 110f220fa62Smrg directedLine* botVertex, 111f220fa62Smrg primStream* pStream); 112f220fa62Smrg 113f220fa62Smrg/*the chain could be increasing or decreasing, although we use the 114f220fa62Smrg * name inc_chain. 115f220fa62Smrg *the argument is_increase_chain indicates whether this chain 116f220fa62Smrg *is increasing (left chain in V-monotone case) or decreaing (right chain 117f220fa62Smrg *in V-monotone case). 118f220fa62Smrg */ 119f220fa62Smrgvoid monoTriangulation2(Real* topVertex, Real* botVertex, 120f220fa62Smrg vertexArray* inc_chain, Int inc_smallIndex, 121f220fa62Smrg Int inc_largeIndex, 122f220fa62Smrg Int is_increase_chain, 123f220fa62Smrg primStream* pStream); 124f220fa62Smrgvoid monoTriangulationRecGen(Real* topVertex, Real* botVertex, 125f220fa62Smrg vertexArray* inc_chain, Int inc_current, Int inc_end, 126f220fa62Smrg vertexArray* dec_chain, Int dec_current, Int dec_end, 127f220fa62Smrg primStream* pStream); 128f220fa62Smrg 129f220fa62Smrgvoid monoTriangulationRecGenOpt(Real* topVertex, Real* botVertex, 130f220fa62Smrg vertexArray* inc_chain, Int inc_current, Int inc_end, 131f220fa62Smrg vertexArray* dec_chain, Int dec_current, Int dec_end, 132f220fa62Smrg primStream* pStream); 133f220fa62Smrg 134f220fa62Smrgvoid triangulateXYMonoTB(Int n_left, Real** leftVerts, 135f220fa62Smrg Int n_right, Real** rightVerts, 136f220fa62Smrg primStream* pStream); 137f220fa62Smrg 138f220fa62Smrgvoid monoTriangulationRecGenTBOpt(Real* topVertex, Real* botVertex, 139f220fa62Smrg vertexArray* inc_chain, Int inc_current, Int inc_end, 140f220fa62Smrg vertexArray* dec_chain, Int dec_current, Int dec_end, 141f220fa62Smrg primStream* pStream); 142f220fa62Smrg 143f220fa62Smrgvoid monoTriangulationRecOpt(Real* topVertex, Real* botVertex, 144f220fa62Smrg vertexArray* left_chain, Int left_current, 145f220fa62Smrg vertexArray* right_chain, Int right_current, 146f220fa62Smrg primStream* pStream); 147f220fa62Smrg 148f220fa62Smrgvoid monoTriangulationRecFunGen(Real* topVertex, Real* botVertex, 149f220fa62Smrg vertexArray* inc_chain, Int inc_current, Int inc_end, 150f220fa62Smrg vertexArray* dec_chain, Int dec_current, Int dec_end, 151f220fa62Smrg Int (*compFun)(Real*, Real*), 152f220fa62Smrg primStream* pStream); 153f220fa62Smrg 154f220fa62Smrgvoid monoTriangulationRecFun(Real* topVertex, Real* botVertex, 155f220fa62Smrg vertexArray* inc_chain, Int inc_current, 156f220fa62Smrg vertexArray* dec_chain, Int dec_current, 157f220fa62Smrg Int (*compFun)(Real*, Real*), 158f220fa62Smrg primStream* pStream); 159f220fa62Smrgvoid monoTriangulationFun(directedLine* monoPolygon, 160f220fa62Smrg Int (*compFun)(Real*, Real*), primStream* pStream); 161f220fa62Smrg 162f220fa62Smrg 163f220fa62Smrg 164f220fa62Smrg 165f220fa62Smrgvoid monoTriangulationRec(Real* topVertex, Real* botVertex, 166f220fa62Smrg vertexArray* inc_chain, Int inc_current, 167f220fa62Smrg vertexArray* dec_chain, Int dec_current, 168f220fa62Smrg Backend* backend); 169f220fa62Smrg 170f220fa62Smrgvoid monoTriangulationFunBackend(Arc_ptr loop, Int (*compFun)(Real*, Real*), Backend* backend); 171f220fa62Smrg 172f220fa62Smrgvoid monoTriangulationRecFunBackend(Real* topVertex, Real* botVertex, 173f220fa62Smrg vertexArray* inc_chain, Int inc_current, 174f220fa62Smrg vertexArray* dec_chain, Int dec_current, 175f220fa62Smrg Int (*compFun)(Real*, Real*), 176f220fa62Smrg Backend* backend); 177f220fa62Smrg 178f220fa62Smrgvoid monoTriangulationOpt(directedLine* poly, primStream* pStream); 179f220fa62Smrg 180f220fa62Smrg#endif 181f220fa62Smrg 182f220fa62Smrg 183f220fa62Smrg 184f220fa62Smrg 185