1f220fa62Smrg/*
2f220fa62Smrg** License Applicability. Except to the extent portions of this file are
3f220fa62Smrg** made subject to an alternative license as permitted in the SGI Free
4f220fa62Smrg** Software License B, Version 1.1 (the "License"), the contents of this
5f220fa62Smrg** file are subject only to the provisions of the License. You may not use
6f220fa62Smrg** this file except in compliance with the License. You may obtain a copy
7f220fa62Smrg** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8f220fa62Smrg** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
9f220fa62Smrg**
10f220fa62Smrg** http://oss.sgi.com/projects/FreeB
11f220fa62Smrg**
12f220fa62Smrg** Note that, as provided in the License, the Software is distributed on an
13f220fa62Smrg** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14f220fa62Smrg** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15f220fa62Smrg** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16f220fa62Smrg** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
17f220fa62Smrg**
18f220fa62Smrg** Original Code. The Original Code is: OpenGL Sample Implementation,
19f220fa62Smrg** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20f220fa62Smrg** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21f220fa62Smrg** Copyright in any portions created by third parties is as indicated
22f220fa62Smrg** elsewhere herein. All Rights Reserved.
23f220fa62Smrg**
24f220fa62Smrg** Additional Notice Provisions: The application programming interfaces
25f220fa62Smrg** established by SGI in conjunction with the Original Code are The
26f220fa62Smrg** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27f220fa62Smrg** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28f220fa62Smrg** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29f220fa62Smrg** Window System(R) (Version 1.3), released October 19, 1998. This software
30f220fa62Smrg** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31f220fa62Smrg** published by SGI, but has not been independently verified as being
32f220fa62Smrg** compliant with the OpenGL(R) version 1.2.1 Specification.
33f220fa62Smrg**
34f220fa62Smrg*/
35f220fa62Smrg/*
36f220fa62Smrg*/
37f220fa62Smrg
38f220fa62Smrg#include "gluos.h"
39f220fa62Smrg#include <stdlib.h>
40f220fa62Smrg#include <stdio.h>
41f220fa62Smrg#include "glimports.h"
42f220fa62Smrg#include "zlassert.h"
43f220fa62Smrg#include <GL/gl.h>
44f220fa62Smrg
45f220fa62Smrg#include "rectBlock.h"
46f220fa62Smrg
47f220fa62SmrgrectBlock::rectBlock(gridBoundaryChain* left, gridBoundaryChain* right, Int beginVline, Int endVline)
48f220fa62Smrg{
49f220fa62Smrg  Int i;
50f220fa62Smrg
51f220fa62Smrg
52f220fa62Smrg  upGridLineIndex = left->getVlineIndex(beginVline);
53f220fa62Smrg
54f220fa62Smrg  lowGridLineIndex = left->getVlineIndex(endVline);
55f220fa62Smrg
56f220fa62Smrg  Int n = upGridLineIndex-lowGridLineIndex+1; //number of grid lines
57f220fa62Smrg  leftIndices = (Int*) malloc(sizeof(Int) * n);
58f220fa62Smrg  assert(leftIndices);
59f220fa62Smrg  rightIndices = (Int*) malloc(sizeof(Int) * n);
60f220fa62Smrg  assert(rightIndices);
61f220fa62Smrg  for(i=0; i<n; i++)
62f220fa62Smrg    {
63f220fa62Smrg
64f220fa62Smrg      leftIndices[i] = left->getInnerIndex(i+beginVline);
65f220fa62Smrg      rightIndices[i] = right->getInnerIndex(i+beginVline);
66f220fa62Smrg    }
67f220fa62Smrg}
68f220fa62Smrg
69f220fa62Smrg
70f220fa62SmrgrectBlock::~rectBlock()
71f220fa62Smrg{
72f220fa62Smrg  free(leftIndices);
73f220fa62Smrg  free(rightIndices);
74f220fa62Smrg}
75f220fa62Smrg
76f220fa62Smrgvoid rectBlock::print()
77f220fa62Smrg{
78f220fa62Smrg  Int i;
79f220fa62Smrg  printf("block:\n");
80f220fa62Smrg  for(i=upGridLineIndex; i >= lowGridLineIndex; i--)
81f220fa62Smrg    {
82f220fa62Smrg      printf("gridline %i, (%i,%i)\n", i, leftIndices[upGridLineIndex-i], rightIndices[upGridLineIndex-i]);
83f220fa62Smrg    }
84f220fa62Smrg}
85f220fa62Smrg
86f220fa62Smrg
87f220fa62Smrg
88f220fa62Smrgvoid rectBlock::draw(Real* u_values, Real* v_values)
89f220fa62Smrg{
90f220fa62Smrg  Int i,j,k;
91f220fa62Smrg  //upgrid line to bot grid line
92f220fa62Smrg#ifdef DEBUG
93f220fa62Smrgprintf("upGridLineIndex=%i, lowGridLineIndex=%i\n", upGridLineIndex, lowGridLineIndex);
94f220fa62Smrg#endif
95f220fa62Smrg  for(k=0, i=upGridLineIndex; i > lowGridLineIndex; i--, k++)
96f220fa62Smrg    {
97f220fa62Smrg      glBegin(GL_QUAD_STRIP);
98f220fa62Smrg
99f220fa62Smrg      for(j=leftIndices[k+1]; j<= rightIndices[k+1]; j++)
100f220fa62Smrg	{
101f220fa62Smrg	  glVertex2f(u_values[j], v_values[i]);
102f220fa62Smrg	  glVertex2f(u_values[j], v_values[i-1]);
103f220fa62Smrg	}
104f220fa62Smrg      glEnd();
105f220fa62Smrg    }
106f220fa62Smrg}
107f220fa62Smrg
108f220fa62Smrg
109f220fa62SmrgInt rectBlock::num_quads()
110f220fa62Smrg{
111f220fa62Smrg  Int ret=0;
112f220fa62Smrg  Int k,i;
113f220fa62Smrg  for(k=0, i=upGridLineIndex; i>lowGridLineIndex; i--, k++)
114f220fa62Smrg    {
115f220fa62Smrg      ret += (rightIndices[k+1]-leftIndices[k+1]);
116f220fa62Smrg    }
117f220fa62Smrg  return ret;
118f220fa62Smrg}
119f220fa62Smrg
120f220fa62SmrgInt rectBlockArray::num_quads()
121f220fa62Smrg{
122f220fa62Smrg  Int ret=0;
123f220fa62Smrg  for(Int i=0; i<n_elements; i++)
124f220fa62Smrg    ret += array[i]->num_quads();
125f220fa62Smrg  return ret;
126f220fa62Smrg}
127f220fa62Smrg
128f220fa62SmrgrectBlockArray::rectBlockArray(Int s)
129f220fa62Smrg{
130f220fa62Smrg  Int i;
131f220fa62Smrg  n_elements = 0;
132f220fa62Smrg  size = s;
133f220fa62Smrg  array = (rectBlock**) malloc(sizeof(rectBlock*) * s);
134f220fa62Smrg  assert(array);
135f220fa62Smrg//initialization
136f220fa62Smrg  for(i=0; i<s; i++)
137f220fa62Smrg    array[i] = NULL;
138f220fa62Smrg}
139f220fa62Smrg
140f220fa62SmrgrectBlockArray::~rectBlockArray()
141f220fa62Smrg{
142f220fa62Smrg  Int i;
143f220fa62Smrg  for(i=0; i<size; i++)
144f220fa62Smrg    {
145f220fa62Smrg      if(array[i] != NULL)
146f220fa62Smrg	delete array[i];
147f220fa62Smrg    }
148f220fa62Smrg  free(array);
149f220fa62Smrg}
150f220fa62Smrg
151f220fa62Smrg//put to the end of the array, check the size
152f220fa62Smrgvoid rectBlockArray::insert(rectBlock* newBlock)
153f220fa62Smrg{
154f220fa62Smrg  Int i;
155f220fa62Smrg  if(n_elements == size) //full
156f220fa62Smrg    {
157f220fa62Smrg      rectBlock** temp = (rectBlock**) malloc(sizeof(rectBlock) * (2*size+1));
158f220fa62Smrg      assert(temp);
159f220fa62Smrg      //initialization
160f220fa62Smrg      for(i=0; i<2*size+1; i++)
161f220fa62Smrg	temp[i] = NULL;
162f220fa62Smrg
163f220fa62Smrg      for(i=0; i<n_elements; i++)
164f220fa62Smrg	temp[i] = array[i];
165f220fa62Smrg
166f220fa62Smrg      free(array);
167f220fa62Smrg      array = temp;
168f220fa62Smrg      size = 2*size +  1;
169f220fa62Smrg    }
170f220fa62Smrg
171f220fa62Smrg  array[n_elements++] = newBlock;
172f220fa62Smrg}
173f220fa62Smrg
174f220fa62Smrgvoid rectBlockArray::print()
175f220fa62Smrg{
176f220fa62Smrg  Int i;
177f220fa62Smrg  for(i=0; i<n_elements; i++)
178f220fa62Smrg    array[i]->print();
179f220fa62Smrg}
180f220fa62Smrg
181f220fa62Smrgvoid rectBlockArray::draw(Real* u_values, Real* v_values)
182f220fa62Smrg{
183f220fa62Smrg  Int i;
184f220fa62Smrg  for(i=0; i<n_elements; i++)
185f220fa62Smrg    array[i]->draw(u_values, v_values);
186f220fa62Smrg}
187f220fa62Smrg
188f220fa62Smrg
189f220fa62Smrg
190f220fa62Smrg
191f220fa62Smrg
192f220fa62Smrg
193f220fa62Smrg
194f220fa62Smrg
195f220fa62Smrg
196f220fa62Smrg
197