41 #include <libnurbs2.h>
48 void gridWrap::print()
50 printf(
"n_ulines = %i\n", n_ulines);
51 printf(
"n_vlines = %i\n", n_vlines);
52 printf(
"u_min=%f, umax=%f, vmin=%f, vmax=%f\n", u_min, u_max, v_min, v_max);
55 gridWrap::gridWrap(Int nUlines, Real* uvals,
56 Int nVlines, Real* vvals)
65 u_max = uvals[nUlines-1];
67 v_max = vvals[nVlines-1];
68 u_values = (Real*) malloc(
sizeof(Real) * n_ulines);
70 v_values = (Real*) malloc(
sizeof(Real) * n_vlines);
74 for(i=0; i<n_ulines; i++)
75 u_values[i] = uvals[i];
76 for(i=0; i<n_vlines; i++)
77 v_values[i] = vvals[i];
80 gridWrap::gridWrap(Int nUlines, Int nVlines,
92 u_values = (Real*) malloc(
sizeof(Real) * n_ulines);
94 v_values = (Real*) malloc(
sizeof(Real) * n_vlines);
100 Real du = (uMax-uMin)/(nUlines-1);
101 Real dv = (vMax-vMin)/(nVlines-1);
105 for(i=1; i<nUlines; i++)
110 u_values[nUlines-1] = uMax;
114 for(i=1; i<nVlines; i++)
119 v_values[nVlines-1] = vMax;
122 gridWrap::~gridWrap()
128 void gridWrap::draw()
133 for(i=0; i<n_ulines; i++)
134 for(j=0; j<n_vlines; j++)
135 glVertex2f(get_u_value(i), get_v_value(j));
140 void gridWrap::outputFanWithPoint(Int v, Int uleft, Int uright, Real vert[2],
primStream* pStream)
147 pStream->insert(vert);
149 assert(vert[1] != v_values[v]);
151 if(vert[1] > v_values[v])
153 for(i=uleft; i<=uright; i++)
154 pStream->insert(u_values[i], v_values[v]);
158 for(i=uright; i>= uleft; i--)
159 pStream->insert(u_values[i], v_values[v]);
162 pStream->end(PRIMITIVE_STREAM_FAN);
180 gridBoundaryChain::gridBoundaryChain(
182 Int first_vline_index,
187 : grid(gr), firstVlineIndex(first_vline_index), nVlines(n_vlines)
189 ulineIndices = (Int*) malloc(
sizeof(Int) * n_vlines);
190 assert(ulineIndices);
192 innerIndices = (Int*) malloc(
sizeof(Int) * n_vlines);
193 assert(innerIndices);
195 vertices = (Real2*) malloc(
sizeof(Real2) * n_vlines);
201 for(i=0; i<n_vlines; i++){
202 ulineIndices[i] = uline_indices[i];
203 innerIndices[i] = inner_indices[i];
206 for(i=0; i<n_vlines; i++){
207 vertices[i][0] = gr->get_u_value(ulineIndices[i]);
208 vertices[i][1] = gr->get_v_value(first_vline_index-i);
212 void gridBoundaryChain::draw()
216 glBegin(GL_LINE_STRIP);
217 for(i=0; i<nVlines; i++)
219 glVertex2fv(vertices[i]);
225 void gridBoundaryChain::drawInner()
229 for(i=1; i<nVlines; i++)
231 glBegin(GL_LINE_STRIP);
232 glVertex2f(grid->get_u_value(innerIndices[i]), get_v_value(i-1) );
233 glVertex2f(grid->get_u_value(innerIndices[i]), get_v_value(i) );
239 Int gridBoundaryChain::lookfor(Real v, Int i1, Int i2)
245 if(v > vertices[mid][1])
256 void gridBoundaryChain::rightEndFan(Int i,
primStream* pStream)
259 if(getUlineIndex(i) > getUlineIndex(i-1))
262 pStream->insert(get_vertex(i-1));
263 for(j=getUlineIndex(i-1); j<= getUlineIndex(i); j++)
264 pStream->insert(grid->get_u_value(j), get_v_value(i));
265 pStream->end(PRIMITIVE_STREAM_FAN);
267 else if(getUlineIndex(i) < getUlineIndex(i-1))
270 pStream->insert(get_vertex(i));
271 for(j=getUlineIndex(i-1); j>= getUlineIndex(i); j--)
272 pStream->insert(grid->get_u_value(j), get_v_value(i-1));
273 pStream->end(PRIMITIVE_STREAM_FAN);
280 void gridBoundaryChain::leftEndFan(Int i,
primStream* pStream)
283 if(getUlineIndex(i) < getUlineIndex(i-1))
286 pStream->insert(get_vertex(i-1));
287 for(j=getUlineIndex(i); j<= getUlineIndex(i-1); j++)
288 pStream->insert(grid->get_u_value(j), get_v_value(i));
289 pStream->end(PRIMITIVE_STREAM_FAN);
291 else if(getUlineIndex(i) > getUlineIndex(i-1))
294 pStream->insert(get_vertex(i));
295 for(j=getUlineIndex(i); j>= getUlineIndex(i-1); j--)
296 pStream->insert(grid->get_u_value(j), get_v_value(i-1));
297 pStream->end(PRIMITIVE_STREAM_FAN);