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