gridWrap.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 33f220fa62Smrg#ifndef _GRIDWRAP_H 34f220fa62Smrg#define _GRIDWRAP_H 35f220fa62Smrg 36f220fa62Smrg#include <stdio.h> 37f220fa62Smrg#include "definitions.h" 38f220fa62Smrg 39f220fa62Smrg#include "primitiveStream.h" 40f220fa62Smrg#include "zlassert.h" 41f220fa62Smrg 42f220fa62Smrgclass gridWrap{ 43f220fa62Smrg Int n_ulines; 44f220fa62Smrg Int n_vlines; 45f220fa62Smrg Real u_min, u_max; 46f220fa62Smrg Real v_min, v_max; 47f220fa62Smrg 48f220fa62Smrg /*cache the coordinate values for efficiency. 49f220fa62Smrg *these are redundant information when 50f220fa62Smrg *the grid is uniform. 51f220fa62Smrg */ 52f220fa62Smrg Real* u_values; /*size is n_ulines*/ 53f220fa62Smrg Real* v_values; /*size is n_vlines*/ 54f220fa62Smrg 55f220fa62Smrg Int is_uniform; 56f220fa62Smrg 57f220fa62Smrgpublic: 58f220fa62Smrg //uniform grid constructor 59f220fa62Smrg gridWrap(Int nUlines, Int nVlines, 60f220fa62Smrg Real uMin, Real uMax, 61f220fa62Smrg Real vMin, Real vMax 62f220fa62Smrg ); 63f220fa62Smrg 64f220fa62Smrg //nonuniform grid constructor. 65f220fa62Smrg gridWrap(Int nUlines, Real *uvals, 66f220fa62Smrg Int nVlines, Real *vvlas 67f220fa62Smrg ); 68f220fa62Smrg ~gridWrap(); 69f220fa62Smrg 70f220fa62Smrg void print(); 71f220fa62Smrg Int get_n_ulines() {return n_ulines;} 72f220fa62Smrg Int get_n_vlines() {return n_vlines;} 73f220fa62Smrg Real get_u_min() {return u_min;} 74f220fa62Smrg Real get_u_max() {return u_max;} 75f220fa62Smrg Real get_v_min() {return v_min;} 76f220fa62Smrg Real get_v_max() {return v_max;} 77f220fa62Smrg 78f220fa62Smrg Real get_u_value(Int i) 79f220fa62Smrg { 80f220fa62Smrg assert(i<n_ulines); 81f220fa62Smrg /*if(i>=n_ulines){printf("ERROR, n_ulines=%i,i=%i\n",n_ulines,i);exit(0);}*/ 82f220fa62Smrg return u_values[i];} 83f220fa62Smrg Real get_v_value(Int j) {return v_values[j];} 84f220fa62Smrg 85f220fa62Smrg Real* get_u_values() {return u_values;} 86f220fa62Smrg Real* get_v_values() {return v_values;} 87f220fa62Smrg 88f220fa62Smrg void outputFanWithPoint(Int v, Int uleft, Int uright, 89f220fa62Smrg Real vert[2], primStream* pStream); 90f220fa62Smrg 91f220fa62Smrg void draw(); 92f220fa62Smrg 93f220fa62Smrg Int isUniform() {return is_uniform;} 94f220fa62Smrg}; 95f220fa62Smrg 96f220fa62Smrgclass gridBoundaryChain{ 97f220fa62Smrg gridWrap* grid; 98f220fa62Smrg Int firstVlineIndex; 99f220fa62Smrg Int nVlines; 100f220fa62Smrg Int* ulineIndices; /*each v line has a boundary*/ 101f220fa62Smrg Int* innerIndices; /*the segment of the vertical gridline from */ 102f220fa62Smrg /*(innerIndices[i], i) to (innerIndices[i+1], i-1) */ 103f220fa62Smrg /*is inside the polygon: i=1,...,nVlines-1*/ 104f220fa62Smrg 105f220fa62Smrg Real2* vertices; /*one grid point at each grid V-line, cached for efficiency*/ 106f220fa62Smrg 107f220fa62Smrgpublic: 108f220fa62Smrg gridBoundaryChain(gridWrap* gr, Int first_vline_index, Int n_vlines, Int* uline_indices, Int* inner_indices); 109f220fa62Smrg 110f220fa62Smrg ~gridBoundaryChain() 111f220fa62Smrg { 112f220fa62Smrg free(innerIndices); 113f220fa62Smrg free(ulineIndices); 114f220fa62Smrg free(vertices); 115f220fa62Smrg } 116f220fa62Smrg 117f220fa62Smrg /*i indexes the vlines in this chain. 118f220fa62Smrg */ 119f220fa62Smrg Int getVlineIndex(Int i) {return firstVlineIndex-i;} 120f220fa62Smrg Int getUlineIndex(Int i) {return ulineIndices[i];} 121f220fa62Smrg Real get_u_value(Int i) {return vertices[i][0];} 122f220fa62Smrg Real get_v_value(Int i) {return vertices[i][1];} 123f220fa62Smrg Int get_nVlines() {return nVlines;} 124f220fa62Smrg Int getInnerIndex(Int i) {return innerIndices[i];} 125f220fa62Smrg Real getInner_u_value(Int i) {return grid->get_u_value(innerIndices[i]);} 126f220fa62Smrg 127f220fa62Smrg Real* get_vertex(Int i) {return vertices[i];} 128f220fa62Smrg gridWrap* getGrid() {return grid;} 129f220fa62Smrg void leftEndFan(Int i, primStream* pStream); 130f220fa62Smrg void rightEndFan(Int i, primStream* pStream); 131f220fa62Smrg 132f220fa62Smrg Int lookfor(Real v, Int i1, Int i2); //find i in [i1,i2] so that vertices[i][1]>= v > vertices[i+1][1] 133f220fa62Smrg void draw(); 134f220fa62Smrg void drawInner(); 135f220fa62Smrg}; 136f220fa62Smrg 137f220fa62Smrg#endif 138