1 | /* |
---|
2 | |
---|
3 | Brian Curless |
---|
4 | |
---|
5 | Computer Graphics Laboratory |
---|
6 | Stanford University |
---|
7 | |
---|
8 | --------------------------------------------------------------------- |
---|
9 | |
---|
10 | Copyright (1997) The Board of Trustees of the Leland Stanford Junior |
---|
11 | University. Except for commercial resale, lease, license or other |
---|
12 | commercial transactions, permission is hereby given to use, copy, |
---|
13 | modify this software for academic purposes only. No part of this |
---|
14 | software or any derivatives thereof may be used in the production of |
---|
15 | computer models for resale or for use in a commercial |
---|
16 | product. STANFORD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND |
---|
17 | CONCERNING THIS SOFTWARE. No support is implied or provided. |
---|
18 | |
---|
19 | */ |
---|
20 | |
---|
21 | |
---|
22 | #include <unistd.h> |
---|
23 | #include <stdio.h> |
---|
24 | #include <malloc.h> |
---|
25 | #include <sys/times.h> |
---|
26 | #include <sys/types.h> |
---|
27 | #include <math.h> |
---|
28 | #include <time.h> |
---|
29 | |
---|
30 | #include "plyio.h" |
---|
31 | #include "DepthMap.h" |
---|
32 | #include "OccGrid.h" |
---|
33 | #include "renderGeom.h" |
---|
34 | #include "defines.h" |
---|
35 | #include "Matrix4f.h" |
---|
36 | #include "vrip.h" |
---|
37 | #include "vripGlobals.h" |
---|
38 | #include "linePersp.h" |
---|
39 | #include "perspective.h" |
---|
40 | |
---|
41 | #include "sl_export.H" |
---|
42 | #include "sl_vertex.H" |
---|
43 | #include "sl_texture.H" |
---|
44 | #include "sl_framebuffer.H" |
---|
45 | |
---|
46 | |
---|
47 | static FB_IntensityBuffer theZBuffer; |
---|
48 | |
---|
49 | static int ClockWise; |
---|
50 | |
---|
51 | static clock_t tm; |
---|
52 | static void start_time(); |
---|
53 | static void end_time(); |
---|
54 | static float time_elapsed(); |
---|
55 | void Clear(FB_IntensityBuffer *buffer, Real Z, Real I); |
---|
56 | void drawMeshConfidence(Mesh *mesh, FB_IntensityBuffer *zbuffer); |
---|
57 | void drawMeshEdgeSteps(Mesh *mesh, FB_IntensityBuffer *zbuffer); |
---|
58 | void drawMeshNx(Mesh *mesh, FB_IntensityBuffer *zbuffer); |
---|
59 | void drawMeshNy(Mesh *mesh, FB_IntensityBuffer *zbuffer); |
---|
60 | void drawMeshNz(Mesh *mesh, FB_IntensityBuffer *zbuffer); |
---|
61 | |
---|
62 | const int SCREEN_XDIM = 1280; |
---|
63 | const int SCREEN_YDIM = 1024; |
---|
64 | |
---|
65 | void transformVerts(Mesh *mesh, Matrix4f *mfinal); |
---|
66 | void transformNorms(Mesh *mesh, Matrix4f *mrot); |
---|
67 | void transformVertsLinePersp(Mesh *mesh, Matrix4f &mmodel, Matrix4f &mvport); |
---|
68 | void transformVertsPersp(Mesh *mesh, Matrix4f &mmodel, Matrix4f &mvport); |
---|
69 | |
---|
70 | static void |
---|
71 | start_time() |
---|
72 | { |
---|
73 | struct tms buffer; |
---|
74 | times(&buffer); |
---|
75 | tm = buffer.tms_utime; |
---|
76 | } |
---|
77 | |
---|
78 | static void |
---|
79 | end_time() |
---|
80 | { |
---|
81 | struct tms buffer; |
---|
82 | times(&buffer); |
---|
83 | tm = buffer.tms_utime - tm; |
---|
84 | } |
---|
85 | |
---|
86 | static float |
---|
87 | time_elapsed() |
---|
88 | { |
---|
89 | return (double) tm / (double) CLOCKS_PER_SEC; |
---|
90 | } |
---|
91 | |
---|
92 | |
---|
93 | void |
---|
94 | prepareRender(Mesh *mesh, OrthoShear *shear, BBox3f *bbox, |
---|
95 | float resolution, DepthMap *dm, int useNorms) |
---|
96 | { |
---|
97 | int xdim, ydim, xorg, yorg; |
---|
98 | float new_xnur, new_ynur; |
---|
99 | |
---|
100 | xdim = int(ceil((bbox->nur.x - bbox->fll.x)/resolution) + 3); |
---|
101 | ydim = int(ceil((bbox->nur.y - bbox->fll.y)/resolution) + 3); |
---|
102 | |
---|
103 | if (dm == NULL) |
---|
104 | dm = new DepthMap(xdim, ydim, useNorms, DEPTH_TREE_GRANULARITY); |
---|
105 | else |
---|
106 | dm->reuse(xdim, ydim); |
---|
107 | |
---|
108 | dm->origin[0] = (int(bbox->fll[0]/resolution)-1)*resolution; |
---|
109 | dm->origin[1] = (int(bbox->fll[1]/resolution)-1)*resolution; |
---|
110 | dm->resolution = resolution; |
---|
111 | dm->linePersp = 0; |
---|
112 | dm->perspective = 0; |
---|
113 | |
---|
114 | theZBuffer.width = xdim; |
---|
115 | theZBuffer.height = ydim; |
---|
116 | theZBuffer.sampleZI = (FB_SampleZI *)dm->elems; |
---|
117 | |
---|
118 | new_xnur = (xdim-1)*resolution + bbox->fll.x; |
---|
119 | new_ynur = (ydim-1)*resolution + bbox->fll.y; |
---|
120 | |
---|
121 | if (Verbose) |
---|
122 | printf("BBox: (%f, %f, %f) -> (%f, %f, %f)\n", |
---|
123 | bbox->fll.x, bbox->fll.y, bbox->fll.z, |
---|
124 | new_xnur, new_ynur, bbox->nur.z); |
---|
125 | |
---|
126 | Matrix4f mrot; |
---|
127 | mesh->quat.toMatrix(mrot); |
---|
128 | |
---|
129 | if (useNorms) |
---|
130 | transformNorms(mesh, &mrot); |
---|
131 | |
---|
132 | Matrix4f mtrans; |
---|
133 | mtrans.makeIdentity(); |
---|
134 | mtrans.translate(mesh->trans); |
---|
135 | |
---|
136 | Matrix4f maxes; |
---|
137 | maxes.makeIdentity(); |
---|
138 | if (shear->axis == X_AXIS) { |
---|
139 | maxes.m[0][0] = 0; |
---|
140 | maxes.m[0][2] = 1; |
---|
141 | maxes.m[2][2] = 0; |
---|
142 | maxes.m[2][0] = 1; |
---|
143 | } |
---|
144 | else if (shear->axis == Y_AXIS) { |
---|
145 | maxes.m[1][1] = 0; |
---|
146 | maxes.m[1][2] = 1; |
---|
147 | maxes.m[2][2] = 0; |
---|
148 | maxes.m[2][1] = 1; |
---|
149 | } |
---|
150 | |
---|
151 | Matrix4f mflipz; |
---|
152 | mflipz.makeIdentity(); |
---|
153 | if (shear->flip) |
---|
154 | mflipz.m[2][2] = -1; |
---|
155 | |
---|
156 | Matrix4f msh; |
---|
157 | msh.makeIdentity(); |
---|
158 | msh.m[0][2] = shear->sx; |
---|
159 | msh.m[1][2] = shear->sy; |
---|
160 | |
---|
161 | //Matrix4f mztrans; |
---|
162 | //mztrans.makeIdentity(); |
---|
163 | //mztrans.m[2][3] = -frontRLEGrid->origin[2]; |
---|
164 | |
---|
165 | Matrix4f mfinal; |
---|
166 | mfinal.makeIdentity(); |
---|
167 | mfinal.multLeft(mrot); |
---|
168 | mfinal.multLeft(mtrans); |
---|
169 | mfinal.multLeft(maxes); |
---|
170 | mfinal.multLeft(mflipz); |
---|
171 | // mfinal.multLeft(mztrans); |
---|
172 | mfinal.multLeft(msh); |
---|
173 | |
---|
174 | if (Verbose) { |
---|
175 | printf("Transformation:\n"); |
---|
176 | mfinal.print(); |
---|
177 | } |
---|
178 | |
---|
179 | Matrix4f vtrans; |
---|
180 | vtrans.makeIdentity(); |
---|
181 | vtrans.translate(-dm->origin[0], -dm->origin[1], 0); |
---|
182 | Matrix4f vscale; |
---|
183 | vscale.makeIdentity(); |
---|
184 | vscale.setScale(1/resolution, 1/resolution, 1); |
---|
185 | |
---|
186 | mfinal.multLeft(vtrans); |
---|
187 | mfinal.multLeft(vscale); |
---|
188 | |
---|
189 | transformVerts(mesh, &mfinal); |
---|
190 | |
---|
191 | ClockWise = (shear->axis == Z_AXIS) ^ (shear->flip); |
---|
192 | } |
---|
193 | |
---|
194 | |
---|
195 | void |
---|
196 | prepareRenderLinePersp(Mesh *mesh, OrthoShear *shear, BBox3f *bbox, |
---|
197 | float resolution, DepthMap *dm, int useNorms) |
---|
198 | { |
---|
199 | int xdim, ydim, xorg, yorg; |
---|
200 | float new_xnur, new_ynur; |
---|
201 | |
---|
202 | xdim = int(ceil((bbox->nur.x - bbox->fll.x)/resolution) + 3); |
---|
203 | ydim = int(ceil((bbox->nur.y - bbox->fll.y)/resolution) + 3); |
---|
204 | |
---|
205 | if (dm == NULL) |
---|
206 | dm = new DepthMap(xdim, ydim, useNorms, DEPTH_TREE_GRANULARITY); |
---|
207 | else |
---|
208 | dm->reuse(xdim, ydim); |
---|
209 | |
---|
210 | dm->origin[0] = (int(bbox->fll[0]/resolution)-1)*resolution; |
---|
211 | dm->origin[1] = (int(bbox->fll[1]/resolution)-1)*resolution; |
---|
212 | dm->resolution = resolution; |
---|
213 | dm->linePersp = 1; |
---|
214 | dm->perspective = 0; |
---|
215 | |
---|
216 | theZBuffer.width = xdim; |
---|
217 | theZBuffer.height = ydim; |
---|
218 | theZBuffer.sampleZI = (FB_SampleZI *)dm->elems; |
---|
219 | |
---|
220 | new_xnur = (xdim-1)*resolution + bbox->fll.x; |
---|
221 | new_ynur = (ydim-1)*resolution + bbox->fll.y; |
---|
222 | |
---|
223 | if (Verbose) |
---|
224 | printf("BBox: (%f, %f, %f) -> (%f, %f, %f)\n", |
---|
225 | bbox->fll.x, bbox->fll.y, bbox->fll.z, |
---|
226 | new_xnur, new_ynur, bbox->nur.z); |
---|
227 | |
---|
228 | Matrix4f mmodel, mvport, mscale, mpermute, mflipz; |
---|
229 | Vec3f trans; |
---|
230 | |
---|
231 | mpermute.makeIdentity(); |
---|
232 | if (shear->axis == X_AXIS) { |
---|
233 | mpermute.m[0][0] = 0; |
---|
234 | mpermute.m[0][2] = 1; |
---|
235 | mpermute.m[2][2] = 0; |
---|
236 | mpermute.m[2][0] = 1; |
---|
237 | } |
---|
238 | else if (shear->axis == Y_AXIS) { |
---|
239 | mpermute.m[1][1] = 0; |
---|
240 | mpermute.m[1][2] = 1; |
---|
241 | mpermute.m[2][2] = 0; |
---|
242 | mpermute.m[2][1] = 1; |
---|
243 | } |
---|
244 | |
---|
245 | // Set up flip matrix |
---|
246 | |
---|
247 | mflipz.makeIdentity(); |
---|
248 | if (shear->flip) |
---|
249 | mflipz.m[2][2] = -1; |
---|
250 | |
---|
251 | mesh->quat.toMatrix(mmodel); |
---|
252 | |
---|
253 | if (useNorms) |
---|
254 | transformNorms(mesh, &mmodel); |
---|
255 | |
---|
256 | mmodel.translate(mesh->trans); |
---|
257 | mmodel.multLeft(mpermute); |
---|
258 | mmodel.multLeft(mflipz); |
---|
259 | |
---|
260 | trans.setValue(-dm->origin[0], -dm->origin[1], 0); |
---|
261 | mvport.makeIdentity(); |
---|
262 | mvport.translate(trans); |
---|
263 | mscale.makeIdentity(); |
---|
264 | mscale.scale(1/resolution, 1/resolution, 1); |
---|
265 | mvport.multLeft(mscale); |
---|
266 | |
---|
267 | transformVertsLinePersp(mesh, mmodel, mvport); |
---|
268 | |
---|
269 | ClockWise = (shear->axis == Z_AXIS) ^ (shear->flip); |
---|
270 | } |
---|
271 | |
---|
272 | |
---|
273 | void |
---|
274 | prepareRenderPersp(Mesh *mesh, OrthoShear *shear, BBox3f *bbox, |
---|
275 | float resolution, DepthMap *dm, int useNorms) |
---|
276 | { |
---|
277 | int xdim, ydim, xorg, yorg; |
---|
278 | float new_xnur, new_ynur; |
---|
279 | |
---|
280 | xdim = int(ceil((bbox->nur.x - bbox->fll.x)/resolution) + 3); |
---|
281 | ydim = int(ceil((bbox->nur.y - bbox->fll.y)/resolution) + 3); |
---|
282 | |
---|
283 | if (dm == NULL) { |
---|
284 | dm = new DepthMap(xdim, ydim, useNorms, DEPTH_TREE_GRANULARITY); |
---|
285 | theDepthMap = dm; |
---|
286 | } |
---|
287 | else { |
---|
288 | if (!dm->reuse(xdim, ydim)) { |
---|
289 | delete dm; |
---|
290 | dm = new DepthMap(xdim, ydim, useNorms, DEPTH_TREE_GRANULARITY); |
---|
291 | theDepthMap = dm; |
---|
292 | } |
---|
293 | } |
---|
294 | |
---|
295 | dm->origin[0] = (int(bbox->fll[0]/resolution)-1)*resolution; |
---|
296 | dm->origin[1] = (int(bbox->fll[1]/resolution)-1)*resolution; |
---|
297 | dm->resolution = resolution; |
---|
298 | dm->linePersp = 0; |
---|
299 | dm->perspective = 1; |
---|
300 | |
---|
301 | theZBuffer.width = xdim; |
---|
302 | theZBuffer.height = ydim; |
---|
303 | theZBuffer.sampleZI = (FB_SampleZI *)dm->elems; |
---|
304 | |
---|
305 | new_xnur = (xdim-1)*resolution + bbox->fll.x; |
---|
306 | new_ynur = (ydim-1)*resolution + bbox->fll.y; |
---|
307 | |
---|
308 | if (Verbose) |
---|
309 | printf("BBox: (%f, %f, %f) -> (%f, %f, %f)\n", |
---|
310 | bbox->fll.x, bbox->fll.y, bbox->fll.z, |
---|
311 | new_xnur, new_ynur, bbox->nur.z); |
---|
312 | |
---|
313 | Matrix4f mmodel, mvport, mscale, mpermute, mflipz; |
---|
314 | Vec3f trans; |
---|
315 | |
---|
316 | mpermute.makeIdentity(); |
---|
317 | if (shear->axis == X_AXIS) { |
---|
318 | mpermute.m[0][0] = 0; |
---|
319 | mpermute.m[0][2] = 1; |
---|
320 | mpermute.m[2][2] = 0; |
---|
321 | mpermute.m[2][0] = 1; |
---|
322 | } |
---|
323 | else if (shear->axis == Y_AXIS) { |
---|
324 | mpermute.m[1][1] = 0; |
---|
325 | mpermute.m[1][2] = 1; |
---|
326 | mpermute.m[2][2] = 0; |
---|
327 | mpermute.m[2][1] = 1; |
---|
328 | } |
---|
329 | |
---|
330 | // Set up flip matrix |
---|
331 | |
---|
332 | mflipz.makeIdentity(); |
---|
333 | if (shear->flip) |
---|
334 | mflipz.m[2][2] = -1; |
---|
335 | |
---|
336 | mesh->quat.toMatrix(mmodel); |
---|
337 | |
---|
338 | if (useNorms) |
---|
339 | transformNorms(mesh, &mmodel); |
---|
340 | |
---|
341 | mmodel.translate(mesh->trans); |
---|
342 | mmodel.multLeft(mpermute); |
---|
343 | mmodel.multLeft(mflipz); |
---|
344 | |
---|
345 | trans.setValue(-dm->origin[0], -dm->origin[1], 0); |
---|
346 | mvport.makeIdentity(); |
---|
347 | mvport.translate(trans); |
---|
348 | mscale.makeIdentity(); |
---|
349 | mscale.scale(1/resolution, 1/resolution, 1); |
---|
350 | mvport.multLeft(mscale); |
---|
351 | |
---|
352 | transformVertsPersp(mesh, mmodel, mvport); |
---|
353 | |
---|
354 | ClockWise = (shear->axis == Z_AXIS) ^ (shear->flip); |
---|
355 | } |
---|
356 | |
---|
357 | void |
---|
358 | softRenderConfidence(Mesh *mesh) |
---|
359 | { |
---|
360 | start_time(); |
---|
361 | |
---|
362 | Clear(&theZBuffer, -MAXFLOAT, 0.0f); |
---|
363 | drawMeshConfidence(mesh, &theZBuffer); |
---|
364 | |
---|
365 | end_time(); |
---|
366 | |
---|
367 | if (Verbose) |
---|
368 | printf("Time to render and read frame buffer = %f.\n", |
---|
369 | time_elapsed()); |
---|
370 | } |
---|
371 | |
---|
372 | void |
---|
373 | softRenderEdgeSteps(Mesh *mesh) |
---|
374 | { |
---|
375 | start_time(); |
---|
376 | |
---|
377 | Clear(&theZBuffer, -MAXFLOAT, 0.0f); |
---|
378 | drawMeshEdgeSteps(mesh, &theZBuffer); |
---|
379 | |
---|
380 | end_time(); |
---|
381 | |
---|
382 | if (Verbose) |
---|
383 | printf("Time to render and read frame buffer = %f.\n", |
---|
384 | time_elapsed()); |
---|
385 | } |
---|
386 | |
---|
387 | |
---|
388 | void |
---|
389 | softRenderNx(Mesh *mesh) |
---|
390 | { |
---|
391 | start_time(); |
---|
392 | |
---|
393 | Clear(&theZBuffer, -MAXFLOAT, 0.0f); |
---|
394 | drawMeshNx(mesh, &theZBuffer); |
---|
395 | |
---|
396 | end_time(); |
---|
397 | |
---|
398 | if (Verbose) |
---|
399 | printf("Time to render and read frame buffer = %f.\n", |
---|
400 | time_elapsed()); |
---|
401 | } |
---|
402 | |
---|
403 | |
---|
404 | void |
---|
405 | softRenderNy(Mesh *mesh) |
---|
406 | { |
---|
407 | start_time(); |
---|
408 | |
---|
409 | Clear(&theZBuffer, -MAXFLOAT, 0.0f); |
---|
410 | drawMeshNy(mesh, &theZBuffer); |
---|
411 | |
---|
412 | end_time(); |
---|
413 | |
---|
414 | if (Verbose) |
---|
415 | printf("Time to render and read frame buffer = %f.\n", |
---|
416 | time_elapsed()); |
---|
417 | } |
---|
418 | |
---|
419 | |
---|
420 | void |
---|
421 | softRenderNz(Mesh *mesh) |
---|
422 | { |
---|
423 | start_time(); |
---|
424 | |
---|
425 | Clear(&theZBuffer, -MAXFLOAT, 0.0f); |
---|
426 | drawMeshNz(mesh, &theZBuffer); |
---|
427 | |
---|
428 | end_time(); |
---|
429 | |
---|
430 | if (Verbose) |
---|
431 | printf("Time to render and read frame buffer = %f.\n", |
---|
432 | time_elapsed()); |
---|
433 | } |
---|
434 | |
---|
435 | |
---|
436 | void |
---|
437 | transformNorms(Mesh *mesh, Matrix4f *mrot) |
---|
438 | { |
---|
439 | Vertex *vert; |
---|
440 | vert = mesh->verts; |
---|
441 | for (int j = 0; j < mesh->numVerts; j++, vert++) { |
---|
442 | mrot->multVec(vert->norm, vert->norm); |
---|
443 | } |
---|
444 | } |
---|
445 | |
---|
446 | |
---|
447 | void |
---|
448 | transformVerts(Mesh *mesh, Matrix4f *mfinal) |
---|
449 | { |
---|
450 | Vertex *vert; |
---|
451 | float m00,m01,m02,m03; |
---|
452 | float m10,m11,m12,m13; |
---|
453 | float m20,m21,m22,m23; |
---|
454 | float m30,m31,m32,m33; |
---|
455 | float x,y,z,w,overw; |
---|
456 | |
---|
457 | m00 = mfinal->m[0][0]; m01 = mfinal->m[0][1]; |
---|
458 | m02 = mfinal->m[0][2]; m03 = mfinal->m[0][3]; |
---|
459 | |
---|
460 | m10 = mfinal->m[1][0]; m11 = mfinal->m[1][1]; |
---|
461 | m12 = mfinal->m[1][2]; m13 = mfinal->m[1][3]; |
---|
462 | |
---|
463 | m20 = mfinal->m[2][0]; m21 = mfinal->m[2][1]; |
---|
464 | m22 = mfinal->m[2][2]; m23 = mfinal->m[2][3]; |
---|
465 | |
---|
466 | m30 = mfinal->m[3][0]; m31 = mfinal->m[3][1]; |
---|
467 | m32 = mfinal->m[3][2]; m33 = mfinal->m[3][3]; |
---|
468 | |
---|
469 | vert = mesh->verts; |
---|
470 | for (int j = 0; j < mesh->numVerts; j++, vert++) { |
---|
471 | x = vert->coord.x; |
---|
472 | y = vert->coord.y; |
---|
473 | z = vert->coord.z; |
---|
474 | w = 1; |
---|
475 | |
---|
476 | overw = 1/(m30*x + m31*y + m32*z + m33*w); |
---|
477 | overw = 1; |
---|
478 | vert->coord.x = (m00*x + m01*y + m02*z + m03*w)*overw; |
---|
479 | vert->coord.y = (m10*x + m11*y + m12*z + m13*w)*overw; |
---|
480 | vert->coord.z = (m20*x + m21*y + m22*z + m23*w)*overw; |
---|
481 | } |
---|
482 | } |
---|
483 | |
---|
484 | |
---|
485 | void |
---|
486 | transformVertsLinePersp(Mesh *mesh, Matrix4f &mmodel, Matrix4f &mvport) |
---|
487 | { |
---|
488 | Vec3f v1, v2; |
---|
489 | Vertex *vert; |
---|
490 | |
---|
491 | vert = mesh->verts; |
---|
492 | for (int j = 0; j < mesh->numVerts; j++, vert++) { |
---|
493 | mmodel.multVec(vert->coord, v1); |
---|
494 | applyLinePersp(v1, v2); |
---|
495 | mvport.multVec(v2, vert->coord); |
---|
496 | } |
---|
497 | } |
---|
498 | |
---|
499 | |
---|
500 | void |
---|
501 | transformVertsPersp(Mesh *mesh, Matrix4f &mmodel, Matrix4f &mvport) |
---|
502 | { |
---|
503 | Vec3f v1, v2; |
---|
504 | Vertex *vert; |
---|
505 | |
---|
506 | float dist; |
---|
507 | |
---|
508 | vert = mesh->verts; |
---|
509 | for (int j = 0; j < mesh->numVerts; j++, vert++) { |
---|
510 | mmodel.multVec(vert->coord, v1); |
---|
511 | applyPersp(v1, v2); |
---|
512 | mvport.multVec(v2, vert->coord); |
---|
513 | } |
---|
514 | } |
---|
515 | |
---|
516 | |
---|
517 | void |
---|
518 | drawMeshConfidence(Mesh *mesh, FB_IntensityBuffer *zbuffer) |
---|
519 | { |
---|
520 | Vertex *v0, *v1, *v2; |
---|
521 | float x1, y1, x2, y2, crossz; |
---|
522 | IS_Vertex_ZI vzi0, vzi1, vzi2; |
---|
523 | Triangle *tri = mesh->tris; |
---|
524 | for (int j = 0; j < mesh->numTris; j++, tri++) { |
---|
525 | v0 = mesh->verts + tri->vindex1; |
---|
526 | v1 = mesh->verts + tri->vindex2; |
---|
527 | v2 = mesh->verts + tri->vindex3; |
---|
528 | if (v0->coord.x < -0.5 || v0->coord.x > zbuffer->width-0.5 || |
---|
529 | v0->coord.y < -0.5 || v0->coord.y > zbuffer->height-0.5 || |
---|
530 | v1->coord.x < -0.5 || v1->coord.x > zbuffer->width-0.5 || |
---|
531 | v1->coord.y < -0.5 || v1->coord.y > zbuffer->height-0.5 || |
---|
532 | v2->coord.x < -0.5 || v2->coord.x > zbuffer->width-0.5 || |
---|
533 | v2->coord.y < -0.5 || v2->coord.y > zbuffer->height-0.5) |
---|
534 | continue; |
---|
535 | |
---|
536 | x1 = v0->coord.x - v1->coord.x; |
---|
537 | y1 = v0->coord.y - v1->coord.y; |
---|
538 | |
---|
539 | x2 = v0->coord.x - v2->coord.x; |
---|
540 | y2 = v0->coord.y - v2->coord.y; |
---|
541 | |
---|
542 | crossz = x1*y2 - x2*y1; |
---|
543 | |
---|
544 | if (crossz < 0 && ClockWise) { |
---|
545 | vzi0.I = -1; |
---|
546 | vzi1.I = -1; |
---|
547 | vzi2.I = -1; |
---|
548 | } else { |
---|
549 | vzi0.I = v0->confidence; |
---|
550 | vzi1.I = v1->confidence; |
---|
551 | vzi2.I = v2->confidence; |
---|
552 | } |
---|
553 | |
---|
554 | vzi0.x = v0->coord.x; |
---|
555 | vzi0.y = v0->coord.y; |
---|
556 | vzi0.Z = v0->coord.z; |
---|
557 | |
---|
558 | vzi1.x = v1->coord.x; |
---|
559 | vzi1.y = v1->coord.y; |
---|
560 | vzi1.Z = v1->coord.z; |
---|
561 | |
---|
562 | vzi2.x = v2->coord.x; |
---|
563 | vzi2.y = v2->coord.y; |
---|
564 | vzi2.Z = v2->coord.z; |
---|
565 | |
---|
566 | SL_SCTriangle_DDA(&vzi0, &vzi1, &vzi2, |
---|
567 | (IS_CAttr_None *) NULL, zbuffer); |
---|
568 | } |
---|
569 | |
---|
570 | for (int i = 0; i < zbuffer->width * zbuffer->height; i++) { |
---|
571 | if (zbuffer->sampleZI[i].I < 0) { |
---|
572 | zbuffer->sampleZI[i].Z = -MAXFLOAT; |
---|
573 | zbuffer->sampleZI[i].I = 0; |
---|
574 | } |
---|
575 | } |
---|
576 | |
---|
577 | } |
---|
578 | |
---|
579 | |
---|
580 | void |
---|
581 | drawMeshEdgeSteps(Mesh *mesh, FB_IntensityBuffer *zbuffer) |
---|
582 | { |
---|
583 | Vertex *v0, *v1, *v2; |
---|
584 | float x1, y1, x2, y2, crossz; |
---|
585 | IS_Vertex_ZI vzi0, vzi1, vzi2; |
---|
586 | Triangle *tri = mesh->tris; |
---|
587 | for (int j = 0; j < mesh->numTris; j++, tri++) { |
---|
588 | v0 = mesh->verts + tri->vindex1; |
---|
589 | v1 = mesh->verts + tri->vindex2; |
---|
590 | v2 = mesh->verts + tri->vindex3; |
---|
591 | if (v0->coord.x < -0.5 || v0->coord.x > zbuffer->width-0.5 || |
---|
592 | v0->coord.y < -0.5 || v0->coord.y > zbuffer->height-0.5 || |
---|
593 | v1->coord.x < -0.5 || v1->coord.x > zbuffer->width-0.5 || |
---|
594 | v1->coord.y < -0.5 || v1->coord.y > zbuffer->height-0.5 || |
---|
595 | v2->coord.x < -0.5 || v2->coord.x > zbuffer->width-0.5 || |
---|
596 | v2->coord.y < -0.5 || v2->coord.y > zbuffer->height-0.5) |
---|
597 | continue; |
---|
598 | |
---|
599 | vzi0.x = v0->coord.x; |
---|
600 | vzi0.y = v0->coord.y; |
---|
601 | vzi0.Z = v0->coord.z; |
---|
602 | vzi0.I = float(v0->stepsToEdge)/MaxStepsToEdge; |
---|
603 | |
---|
604 | vzi1.x = v1->coord.x; |
---|
605 | vzi1.y = v1->coord.y; |
---|
606 | vzi1.Z = v1->coord.z; |
---|
607 | vzi1.I = float(v1->stepsToEdge)/MaxStepsToEdge; |
---|
608 | |
---|
609 | vzi2.x = v2->coord.x; |
---|
610 | vzi2.y = v2->coord.y; |
---|
611 | vzi2.Z = v2->coord.z; |
---|
612 | vzi2.I = float(v2->stepsToEdge)/MaxStepsToEdge; |
---|
613 | |
---|
614 | /* |
---|
615 | if (vzi0.I < 0) { |
---|
616 | vzi0.I = 1.0; |
---|
617 | } |
---|
618 | if (vzi1.I < 0) { |
---|
619 | vzi1.I = 1.0; |
---|
620 | } |
---|
621 | if (vzi2.I < 0) { |
---|
622 | vzi2.I = 1.0; |
---|
623 | } |
---|
624 | */ |
---|
625 | |
---|
626 | SL_SCTriangle_DDA(&vzi0, &vzi1, &vzi2, |
---|
627 | (IS_CAttr_None *) NULL, zbuffer); |
---|
628 | } |
---|
629 | |
---|
630 | /* |
---|
631 | for (int i = 0; i < zbuffer->width * zbuffer->height; i++) { |
---|
632 | if (zbuffer->sampleZI[i].I < 0) { |
---|
633 | zbuffer->sampleZI[i].Z = -MAXFLOAT; |
---|
634 | } |
---|
635 | } |
---|
636 | */ |
---|
637 | |
---|
638 | } |
---|
639 | |
---|
640 | |
---|
641 | void |
---|
642 | drawMeshNx(Mesh *mesh, FB_IntensityBuffer *zbuffer) |
---|
643 | { |
---|
644 | Vertex *v0, *v1, *v2; |
---|
645 | IS_Vertex_ZI vzi0, vzi1, vzi2; |
---|
646 | Triangle *tri = mesh->tris; |
---|
647 | for (int j = 0; j < mesh->numTris; j++, tri++) { |
---|
648 | v0 = mesh->verts + tri->vindex1; |
---|
649 | v1 = mesh->verts + tri->vindex2; |
---|
650 | v2 = mesh->verts + tri->vindex3; |
---|
651 | if (v0->coord.x < -0.5 || v0->coord.x > zbuffer->width-0.5 || |
---|
652 | v0->coord.y < -0.5 || v0->coord.y > zbuffer->height-0.5 || |
---|
653 | v1->coord.x < -0.5 || v1->coord.x > zbuffer->width-0.5 || |
---|
654 | v1->coord.y < -0.5 || v1->coord.y > zbuffer->height-0.5 || |
---|
655 | v2->coord.x < -0.5 || v2->coord.x > zbuffer->width-0.5 || |
---|
656 | v2->coord.y < -0.5 || v2->coord.y > zbuffer->height-0.5) |
---|
657 | continue; |
---|
658 | |
---|
659 | vzi0.x = v0->coord.x; |
---|
660 | vzi0.y = v0->coord.y; |
---|
661 | vzi0.Z = v0->coord.z; |
---|
662 | vzi0.I = v0->norm.x; |
---|
663 | |
---|
664 | vzi1.x = v1->coord.x; |
---|
665 | vzi1.y = v1->coord.y; |
---|
666 | vzi1.Z = v1->coord.z; |
---|
667 | vzi1.I = v1->norm.x; |
---|
668 | |
---|
669 | vzi2.x = v2->coord.x; |
---|
670 | vzi2.y = v2->coord.y; |
---|
671 | vzi2.Z = v2->coord.z; |
---|
672 | vzi2.I = v2->norm.x; |
---|
673 | |
---|
674 | SL_SCTriangle_DDA(&vzi0, &vzi1, &vzi2, |
---|
675 | (IS_CAttr_None *) NULL, zbuffer); |
---|
676 | } |
---|
677 | } |
---|
678 | |
---|
679 | void |
---|
680 | drawMeshNy(Mesh *mesh, FB_IntensityBuffer *zbuffer) |
---|
681 | { |
---|
682 | Vertex *v0, *v1, *v2; |
---|
683 | IS_Vertex_ZI vzi0, vzi1, vzi2; |
---|
684 | Triangle *tri = mesh->tris; |
---|
685 | for (int j = 0; j < mesh->numTris; j++, tri++) { |
---|
686 | v0 = mesh->verts + tri->vindex1; |
---|
687 | v1 = mesh->verts + tri->vindex2; |
---|
688 | v2 = mesh->verts + tri->vindex3; |
---|
689 | if (v0->coord.x < -0.5 || v0->coord.x > zbuffer->width-0.5 || |
---|
690 | v0->coord.y < -0.5 || v0->coord.y > zbuffer->height-0.5 || |
---|
691 | v1->coord.x < -0.5 || v1->coord.x > zbuffer->width-0.5 || |
---|
692 | v1->coord.y < -0.5 || v1->coord.y > zbuffer->height-0.5 || |
---|
693 | v2->coord.x < -0.5 || v2->coord.x > zbuffer->width-0.5 || |
---|
694 | v2->coord.y < -0.5 || v2->coord.y > zbuffer->height-0.5) |
---|
695 | continue; |
---|
696 | |
---|
697 | vzi0.x = v0->coord.x; |
---|
698 | vzi0.y = v0->coord.y; |
---|
699 | vzi0.Z = v0->coord.z; |
---|
700 | vzi0.I = v0->norm.y; |
---|
701 | |
---|
702 | vzi1.x = v1->coord.x; |
---|
703 | vzi1.y = v1->coord.y; |
---|
704 | vzi1.Z = v1->coord.z; |
---|
705 | vzi1.I = v1->norm.y; |
---|
706 | |
---|
707 | vzi2.x = v2->coord.x; |
---|
708 | vzi2.y = v2->coord.y; |
---|
709 | vzi2.Z = v2->coord.z; |
---|
710 | vzi2.I = v2->norm.y; |
---|
711 | |
---|
712 | SL_SCTriangle_DDA(&vzi0, &vzi1, &vzi2, |
---|
713 | (IS_CAttr_None *) NULL, zbuffer); |
---|
714 | } |
---|
715 | |
---|
716 | } |
---|
717 | |
---|
718 | void |
---|
719 | drawMeshNz(Mesh *mesh, FB_IntensityBuffer *zbuffer) |
---|
720 | { |
---|
721 | Vertex *v0, *v1, *v2; |
---|
722 | IS_Vertex_ZI vzi0, vzi1, vzi2; |
---|
723 | Triangle *tri = mesh->tris; |
---|
724 | for (int j = 0; j < mesh->numTris; j++, tri++) { |
---|
725 | v0 = mesh->verts + tri->vindex1; |
---|
726 | v1 = mesh->verts + tri->vindex2; |
---|
727 | v2 = mesh->verts + tri->vindex3; |
---|
728 | if (v0->coord.x < -0.5 || v0->coord.x > zbuffer->width-0.5 || |
---|
729 | v0->coord.y < -0.5 || v0->coord.y > zbuffer->height-0.5 || |
---|
730 | v1->coord.x < -0.5 || v1->coord.x > zbuffer->width-0.5 || |
---|
731 | v1->coord.y < -0.5 || v1->coord.y > zbuffer->height-0.5 || |
---|
732 | v2->coord.x < -0.5 || v2->coord.x > zbuffer->width-0.5 || |
---|
733 | v2->coord.y < -0.5 || v2->coord.y > zbuffer->height-0.5) |
---|
734 | continue; |
---|
735 | |
---|
736 | vzi0.x = v0->coord.x; |
---|
737 | vzi0.y = v0->coord.y; |
---|
738 | vzi0.Z = v0->coord.z; |
---|
739 | vzi0.I = v0->norm.z; |
---|
740 | |
---|
741 | vzi1.x = v1->coord.x; |
---|
742 | vzi1.y = v1->coord.y; |
---|
743 | vzi1.Z = v1->coord.z; |
---|
744 | vzi1.I = v1->norm.z; |
---|
745 | |
---|
746 | vzi2.x = v2->coord.x; |
---|
747 | vzi2.y = v2->coord.y; |
---|
748 | vzi2.Z = v2->coord.z; |
---|
749 | vzi2.I = v2->norm.z; |
---|
750 | |
---|
751 | SL_SCTriangle_DDA(&vzi0, &vzi1, &vzi2, |
---|
752 | (IS_CAttr_None *) NULL, zbuffer); |
---|
753 | } |
---|
754 | } |
---|
755 | |
---|
756 | void |
---|
757 | Clear(FB_IntensityBuffer *buffer, Real Z, Real I) |
---|
758 | { |
---|
759 | for (int i = 0; i < buffer->width * buffer->height; i++) { |
---|
760 | buffer->sampleZI[i].Z = Z; |
---|
761 | buffer->sampleZI[i].I = I; |
---|
762 | } |
---|
763 | } |
---|