1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkOpenGLPolyDataMapper.cxx
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14 =========================================================================*/
15 #include "vtkOpenGLPolyDataMapper.h"
16
17 #if !defined(VTK_LEGACY_REMOVE)
18
19 #include "vtkCellArray.h"
20 #include "vtkCellData.h"
21 #include "vtkCommand.h"
22 #include "vtkDataArray.h"
23 #include "vtkFloatArray.h"
24 #include "vtkMatrix4x4.h"
25 #include "vtkObjectFactory.h"
26 #include "vtkOpenGLRenderer.h"
27 #include "vtkPointData.h"
28 #include "vtkPolyData.h"
29 #include "vtkPolygon.h"
30 #include "vtkProperty.h"
31 #include "vtkTimerLog.h"
32 #include "vtkTriangle.h"
33 #include "vtkOpenGLTexture.h"
34 #include "vtkImageData.h"
35 #include "vtkWindow.h"
36 #include "vtkRenderWindow.h"
37
38 #include "vtkOpenGL.h"
39 #include "vtkOpenGLError.h"
40
41 #include <math.h>
42
43 vtkStandardNewMacro(vtkOpenGLPolyDataMapper);
44
45 // some definitions for what the polydata has in it
46 #define VTK_PDM_NORMALS 0x01
47 #define VTK_PDM_COLORS 0x02
48 #define VTK_PDM_TCOORDS 0x04
49 #define VTK_PDM_CELL_COLORS 0x08
50 #define VTK_PDM_CELL_NORMALS 0x10
51 #define VTK_PDM_POINT_TYPE_FLOAT 0x20
52 #define VTK_PDM_POINT_TYPE_DOUBLE 0x40
53 #define VTK_PDM_NORMAL_TYPE_FLOAT 0x80
54 #define VTK_PDM_NORMAL_TYPE_DOUBLE 0x100
55 #define VTK_PDM_TCOORD_TYPE_FLOAT 0x200
56 #define VTK_PDM_TCOORD_TYPE_DOUBLE 0x400
57 #define VTK_PDM_TCOORD_1D 0x800
58 #define VTK_PDM_OPAQUE_COLORS 0x1000
59 #define VTK_PDM_USE_FIELD_DATA 0x2000
60
61 // Construct empty object.
vtkOpenGLPolyDataMapper()62 vtkOpenGLPolyDataMapper::vtkOpenGLPolyDataMapper()
63 {
64 this->ListId = 0;
65 this->TotalCells = 0;
66 this->InternalColorTexture = 0;
67
68 VTK_LEGACY_BODY(vtkOpenGLPolyDataMapper::vtkOpenGLPolyDataMapper,
69 "VTK 6.2");
70 }
71
72 // Destructor (don't call ReleaseGraphicsResources() since it is virtual
~vtkOpenGLPolyDataMapper()73 vtkOpenGLPolyDataMapper::~vtkOpenGLPolyDataMapper()
74 {
75 if (this->LastWindow)
76 {
77 this->ReleaseGraphicsResources(this->LastWindow);
78 }
79 if (this->InternalColorTexture)
80 { // Resources released previously.
81 this->InternalColorTexture->Delete();
82 this->InternalColorTexture = 0;
83 }
84 }
85
86 // Release the graphics resources used by this mapper. In this case, release
87 // the display list if any.
ReleaseGraphicsResources(vtkWindow * win)88 void vtkOpenGLPolyDataMapper::ReleaseGraphicsResources(vtkWindow *win)
89 {
90 if (this->ListId && win && win->GetMapped())
91 {
92 win->MakeCurrent();
93 glDeleteLists(this->ListId, 1);
94 vtkOpenGLCheckErrorMacro("failed after glDeleteLists");
95 }
96 this->ListId = 0;
97 this->LastWindow = NULL;
98 // We may not want to do this here.
99 if (this->InternalColorTexture)
100 {
101 this->InternalColorTexture->ReleaseGraphicsResources(win);
102 }
103 }
104
105 //
106 // Receives from Actor -> maps data to primitives
107 //
RenderPiece(vtkRenderer * ren,vtkActor * act)108 void vtkOpenGLPolyDataMapper::RenderPiece(vtkRenderer *ren, vtkActor *act)
109 {
110 vtkOpenGLClearErrorMacro();
111
112 vtkPolyData *input= this->GetInput();
113
114 // make sure that we've been properly initialized
115 if (ren->GetRenderWindow()->CheckAbortStatus())
116 {
117 return;
118 }
119
120 if (!input)
121 {
122 vtkErrorMacro(<< "No input!");
123 return;
124 }
125 else
126 {
127 this->InvokeEvent(vtkCommand::StartEvent,NULL);
128 if (!this->Static)
129 {
130 this->GetInputAlgorithm()->Update();
131 }
132 this->InvokeEvent(vtkCommand::EndEvent,NULL);
133
134 vtkIdType numPts = input->GetNumberOfPoints();
135 if (numPts == 0)
136 {
137 vtkDebugMacro(<< "No points!");
138 return;
139 }
140 }
141
142 if (!this->LookupTable)
143 {
144 this->CreateDefaultLookupTable();
145 }
146
147 // make sure our window is current
148 ren->GetRenderWindow()->MakeCurrent();
149
150 // add all the clipping planes
151 int numClipPlanes = this->GetNumberOfClippingPlanes();
152 if (numClipPlanes > 6)
153 {
154 vtkErrorMacro(<< "OpenGL has a limit of 6 clipping planes");
155 numClipPlanes = 6;
156 }
157
158 for (int i = 0; i < numClipPlanes; i++)
159 {
160 double planeEquation[4];
161 this->GetClippingPlaneInDataCoords(act->GetMatrix(), i, planeEquation);
162 GLenum clipPlaneId = static_cast<GLenum>(GL_CLIP_PLANE0 + i);
163 glEnable(clipPlaneId);
164 glClipPlane(clipPlaneId, planeEquation);
165 }
166
167 // For vertex coloring, this sets this->Colors as side effect.
168 // For texture map coloring, this sets ColorCoordinates
169 // and ColorTextureMap as a side effect.
170 // I moved this out of the conditional because it is fast.
171 // Color arrays are cached. If nothing has changed,
172 // then the scalars do not have to be regenerted.
173 this->MapScalars(act->GetProperty()->GetOpacity());
174 // If we are coloring by texture, then load the texture map.
175 if (this->ColorTextureMap)
176 {
177 if (this->InternalColorTexture == 0)
178 {
179 this->InternalColorTexture = vtkOpenGLTexture::New();
180 this->InternalColorTexture->RepeatOff();
181 }
182 this->InternalColorTexture->SetInputData(this->ColorTextureMap);
183 // Keep color from interacting with texture.
184 float info[4] = {1.f, 1.f, 1.f, 1.f};
185 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, info);
186 }
187
188 //
189 // if something has changed regenerate colors and display lists
190 // if required
191 //
192 int noAbort = 1;
193 if ( this->GetMTime() > this->BuildTime ||
194 input->GetMTime() > this->BuildTime ||
195 act->GetProperty()->GetMTime() > this->BuildTime ||
196 ren->GetRenderWindow() != this->LastWindow)
197 {
198 if (!this->ImmediateModeRendering &&
199 !this->GetGlobalImmediateModeRendering())
200 {
201 this->ReleaseGraphicsResources(ren->GetRenderWindow());
202 this->LastWindow = ren->GetRenderWindow();
203
204 // If we are coloring by texture, then load the texture map.
205 // Use Map as indicator, because texture hangs around.
206 if (this->ColorTextureMap)
207 {
208 this->InternalColorTexture->Load(ren);
209 }
210
211 // get a unique display list id
212 this->ListId = glGenLists(1);
213 glNewList(this->ListId, GL_COMPILE);
214
215 noAbort = this->Draw(ren,act);
216 glEndList();
217
218 // Time the actual drawing
219 this->Timer->StartTimer();
220 glCallList(this->ListId);
221 this->Timer->StopTimer();
222 }
223 else
224 {
225 this->ReleaseGraphicsResources(ren->GetRenderWindow());
226 this->LastWindow = ren->GetRenderWindow();
227 }
228 if (noAbort)
229 {
230 this->BuildTime.Modified();
231 }
232 }
233 // if nothing changed but we are using display lists, draw it
234 else
235 {
236 if (!this->ImmediateModeRendering &&
237 !this->GetGlobalImmediateModeRendering())
238 {
239 // If we are coloring by texture, then load the texture map.
240 // Use Map as indicator, because texture hangs around.
241 if (this->ColorTextureMap)
242 {
243 this->InternalColorTexture->Load(ren);
244 }
245
246 // Time the actual drawing
247 this->Timer->StartTimer();
248 glCallList(this->ListId);
249 this->Timer->StopTimer();
250 }
251 }
252
253 // if we are in immediate mode rendering we always
254 // want to draw the primitives here
255 if (this->ImmediateModeRendering ||
256 this->GetGlobalImmediateModeRendering())
257 {
258 // If we are coloring by texture, then load the texture map.
259 // Use Map as indicator, because texture hangs around.
260 if (this->ColorTextureMap)
261 {
262 this->InternalColorTexture->Load(ren);
263 }
264 // Time the actual drawing
265 this->Timer->StartTimer();
266 this->Draw(ren,act);
267 this->Timer->StopTimer();
268 }
269
270 this->TimeToDraw = this->Timer->GetElapsedTime();
271
272 // If the timer is not accurate enough, set it to a small
273 // time so that it is not zero
274 if (this->TimeToDraw == 0.0)
275 {
276 this->TimeToDraw = 0.0001;
277 }
278
279 for (int c = 0; c < numClipPlanes; c++)
280 {
281 GLenum clipPlaneId = static_cast<GLenum>(GL_CLIP_PLANE0 + c);
282 glDisable(clipPlaneId);
283 }
284
285 vtkOpenGLCheckErrorMacro("failed after RenderPiece");
286 }
287
288 //
289 // Helper routine which starts a poly, triangle or quad based upon
290 // the number of points in the polygon and whether triangles or quads
291 // were the last thing being drawn (we can get better performance if we
292 // can draw several triangles within a single glBegin(GL_TRIANGLES) or
293 // several quads within a single glBegin(GL_QUADS).
294 //
vtkOpenGLBeginPolyTriangleOrQuad(GLenum aGlFunction,GLenum & previousGlFunction,int npts)295 static void vtkOpenGLBeginPolyTriangleOrQuad(GLenum aGlFunction,
296 GLenum &previousGlFunction,
297 int npts)
298 {
299 if (aGlFunction == GL_POLYGON)
300 {
301 switch (npts)
302 {
303 case 3: // Need to draw a triangle.
304 if (previousGlFunction != GL_TRIANGLES)
305 {
306 // we were not already drawing triangles, were we drawing quads?
307 if (previousGlFunction == GL_QUADS)
308 {
309 // we were previously drawing quads, close down the quads.
310 glEnd();
311 }
312 // start drawing triangles
313 previousGlFunction = GL_TRIANGLES;
314 glBegin(GL_TRIANGLES);
315 }
316 break;
317 case 4: // Need to draw a quad
318 if (previousGlFunction != GL_QUADS)
319 {
320 // we were not already drawing quads, were we drawing triangles?
321 if (previousGlFunction == GL_TRIANGLES)
322 {
323 // we were previously drawing triangles, close down the triangles.
324 glEnd();
325 }
326 // start drawing quads
327 previousGlFunction = GL_QUADS;
328 glBegin(GL_QUADS);
329 }
330 break;
331 default:
332 // if we were supposed to be drawing polygons but were really
333 // drawing triangles or quads, then we need to close down the
334 // triangles or quads and begin a polygon
335 if (previousGlFunction != GL_INVALID_VALUE
336 && previousGlFunction != GL_POLYGON)
337 {
338 glEnd();
339 }
340 previousGlFunction = GL_POLYGON;
341 glBegin(aGlFunction);
342 break;
343 }
344 }
345 else if (aGlFunction == GL_POINTS)
346 {
347 // we are supposed to be drawing points
348 if (previousGlFunction != GL_POINTS)
349 {
350 // We were not drawing points before this, switch to points.
351 // We don't need to worry about switching from triangles or quads
352 // since draw all points before drawing any polygons (i.e. in the polys
353 // case we switch to triangles and quads as an optimization, there is
354 // nothing to switch to that is below points).
355 previousGlFunction = GL_POINTS;
356 glBegin(GL_POINTS);
357 }
358 }
359 else
360 {
361 previousGlFunction = aGlFunction;
362 glBegin(aGlFunction);
363 }
364 }
365
366 //-----------------------------------------
367
368 #define vtkDrawPointsMacro(ptype,ntype,glVertFuncs,glInitFuncs) \
369 { \
370 vtkIdType nPts; unsigned short count = 0; \
371 ptype *points = static_cast<ptype *>(voidPoints); \
372 glInitFuncs \
373 glBegin(GL_POINTS); \
374 while (ptIds < endPtIds) \
375 { \
376 nPts = *ptIds; \
377 ++ptIds; \
378 while (nPts > 0) \
379 { \
380 glVertFuncs \
381 ++ptIds; \
382 --nPts; \
383 } \
384 if (++count == 10000) \
385 { \
386 cellNum += 10000; \
387 count = 0; \
388 this->UpdateProgress(static_cast<double>(cellNum)/this->TotalCells); \
389 if (ren->GetRenderWindow()->CheckAbortStatus()) \
390 { \
391 noAbort = 0; \
392 break; \
393 } \
394 } \
395 } \
396 cellNum += count; \
397 glEnd(); \
398 }
399
400 #define vtkDrawPrimsMacro(ptype,ntype,prim,glVertFuncs,glInitFuncs) \
401 { \
402 vtkIdType nPts; unsigned short count = 0; \
403 ptype *points = static_cast<ptype *>(voidPoints); \
404 glInitFuncs \
405 while (ptIds < endPtIds) \
406 { \
407 nPts = *ptIds; \
408 ++ptIds; \
409 glBegin(prim); \
410 while (nPts > 0) \
411 { \
412 glVertFuncs \
413 ++ptIds; \
414 --nPts; \
415 } \
416 glEnd(); \
417 if (++count == 10000) \
418 { \
419 cellNum += 10000; \
420 count = 0; \
421 this->UpdateProgress(static_cast<double>(cellNum)/this->TotalCells); \
422 if (ren->GetRenderWindow()->CheckAbortStatus()) \
423 { \
424 noAbort = 0; \
425 break; \
426 } \
427 } \
428 } \
429 cellNum += count; \
430 }
431
432 #define vtkDrawPolysMacro(ptype,ntype,ttype,prim,glVertFuncs,glCellFuncs,glInitFuncs) \
433 { \
434 vtkIdType nPts; unsigned short count = 0; \
435 ptype *points = static_cast<ptype *>(voidPoints); \
436 GLenum previousGlFunction=GL_INVALID_VALUE; \
437 glInitFuncs \
438 while (ptIds < endPtIds) \
439 { \
440 nPts = *ptIds; \
441 ++ptIds; \
442 vtkOpenGLBeginPolyTriangleOrQuad( prim, previousGlFunction, nPts ); \
443 glCellFuncs \
444 while (nPts > 0) \
445 { \
446 glVertFuncs \
447 ++ptIds; \
448 --nPts; \
449 } \
450 if (++count == 10000) \
451 { \
452 cellNum += 10000; \
453 count = 0; \
454 this->UpdateProgress(static_cast<double>(cellNum)/this->TotalCells); \
455 if (ren->GetRenderWindow()->CheckAbortStatus()) \
456 { \
457 noAbort = 0; \
458 break; \
459 } \
460 } \
461 if ((previousGlFunction != GL_TRIANGLES) \
462 && (previousGlFunction != GL_QUADS) \
463 && (previousGlFunction != GL_POINTS)) \
464 { \
465 glEnd(); \
466 } \
467 } \
468 cellNum += count; \
469 if ((previousGlFunction == GL_TRIANGLES) \
470 || (previousGlFunction == GL_QUADS) \
471 || (previousGlFunction == GL_POINTS)) \
472 { \
473 glEnd(); \
474 } \
475 }
476
477 #define vtkDrawPolysMacro4Tri(ptype,ntype,ttype,prim,glVertFuncs,glCellFuncs,glInitFuncs) \
478 { \
479 vtkIdType nPts; unsigned short count = 0; \
480 ptype *points = static_cast<ptype *>(voidPoints); \
481 GLenum previousGlFunction=GL_INVALID_VALUE; \
482 glInitFuncs \
483 \
484 double quad_center[3] = {0, 0, 0}; \
485 double quad_center_col[4] = {0, 0, 0, 0}; \
486 double quad_points[4][3]; \
487 double quad_points_col[4][4]; \
488 double dist_center[4] = {0, 0, 0, 0}; \
489 \
490 while (ptIds < endPtIds) \
491 { \
492 nPts = *ptIds; \
493 ++ptIds; \
494 /* If we don't want to draw a QUAD (ex : a triangle nPts = 3) */ \
495 if (nPts != 4) { \
496 /* Classic method */ \
497 vtkOpenGLBeginPolyTriangleOrQuad( prim, previousGlFunction, nPts ); \
498 glCellFuncs \
499 while (nPts > 0) \
500 { \
501 glVertFuncs \
502 ++ptIds; \
503 --nPts; \
504 } \
505 } \
506 /* If we want to draw a QUAD */ \
507 else { \
508 /* We launch glBegin(GL_TRIANGLES) mode in order to draw 4 triangles */ \
509 vtkOpenGLBeginPolyTriangleOrQuad( prim, previousGlFunction, 3 ); \
510 glCellFuncs \
511 /* We keep pointer on the first point of the first triangle */ \
512 /* ptIdsFirstPtQuad will be used for center calculation and for 2nd point of 4th triangle */ \
513 vtkIdType *ptIdsFirstPtQuad; \
514 ptIdsFirstPtQuad = ptIds; \
515 /* QUAD Center calculation */ \
516 /* We save the 4 QUAD points and their color */ \
517 GLfloat *vpt; \
518 GLubyte *vcol; \
519 for (int i=0; i<4; i++) { \
520 /* Position : */ \
521 vpt = points + 3**ptIds; \
522 quad_points[i][0] = vpt[0]; \
523 quad_points[i][1] = vpt[1]; \
524 quad_points[i][2] = vpt[2]; \
525 /* Color : */ \
526 vcol = colors + 4**ptIds; \
527 quad_points_col[i][0] = vcol[0]; \
528 quad_points_col[i][1] = vcol[1]; \
529 quad_points_col[i][2] = vcol[2]; \
530 quad_points_col[i][3] = vcol[3]; \
531 ++ptIds; \
532 } \
533 /* Actual calculation of QUAD center with the 4 summits */ \
534 quad_center[0] = (quad_points[0][0] + quad_points[1][0] + quad_points[2][0] + quad_points[3][0])/4; \
535 quad_center[1] = (quad_points[0][1] + quad_points[1][1] + quad_points[2][1] + quad_points[3][1])/4; \
536 quad_center[2] = (quad_points[0][2] + quad_points[1][2] + quad_points[2][2] + quad_points[3][2])/4; \
537 /* Color center calculation (Interpolation on each component of RGB vector) */ \
538 /* Calculation of distances between center and summits */ \
539 for (int i=0; i<4; i++) { \
540 dist_center[i] = sqrt((quad_points[i][0] - quad_center[0])*(quad_points[i][0] - quad_center[0]) + \
541 (quad_points[i][1] - quad_center[1])*(quad_points[i][1] - quad_center[1]) + \
542 (quad_points[i][2] - quad_center[2])*(quad_points[i][2] - quad_center[2])); \
543 } \
544 /* Color interpolation (3 for RGB and 1 for Alpha transparency) */ \
545 for (int i=0; i<4; i++) { \
546 quad_center_col[i] = ((dist_center[3]*quad_points_col[1][i] + dist_center[1]*quad_points_col[3][i])/(dist_center[1] + dist_center[3]) + \
547 (dist_center[2]*quad_points_col[0][i] + dist_center[0]*quad_points_col[2][i])/(dist_center[2] + dist_center[0]) \
548 )/2; \
549 } \
550 /* We take pointer on the first QUAD point */ \
551 ptIds = ptIdsFirstPtQuad; \
552 /* Actual drawing of 4 triangles */ \
553 for (int i=0; i<4; i++) { \
554 /* 1st point */ \
555 glVertFuncs \
556 ++ptIds; \
557 /* 2nd point */ \
558 if (i >= 3) { /* If it is the last triangle */ \
559 /* this 2nd point = the 1st point of 1st triangle */ \
560 glColor3ubv(colors + 4**ptIdsFirstPtQuad); \
561 glVertex3fv(static_cast<float*>(points) + 3**ptIdsFirstPtQuad); \
562 } \
563 else { \
564 /* Else 2nd point = next point */ \
565 glVertFuncs \
566 } \
567 /* 3rd point */ \
568 glColor4f(quad_center_col[0],quad_center_col[1],quad_center_col[2],quad_center_col[3]); \
569 glVertex3f(quad_center[0],quad_center[1],quad_center[2]); \
570 } \
571 } /* End of if (nPts == 4) */ \
572 if (++count == 10000) \
573 { \
574 cellNum += 10000; \
575 count = 0; \
576 this->UpdateProgress(static_cast<double>(cellNum)/this->TotalCells); \
577 if (ren->GetRenderWindow()->CheckAbortStatus()) \
578 { \
579 noAbort = 0; \
580 break; \
581 } \
582 } \
583 if ((previousGlFunction != GL_TRIANGLES) \
584 && (previousGlFunction != GL_QUADS) \
585 && (previousGlFunction != GL_POINTS)) \
586 { \
587 glEnd(); \
588 } \
589 } \
590 cellNum += count; \
591 if ((previousGlFunction == GL_TRIANGLES) \
592 || (previousGlFunction == GL_QUADS) \
593 || (previousGlFunction == GL_POINTS)) \
594 { \
595 glEnd(); \
596 } \
597 }
598
599 #define vtkDrawPolysMacro4TriTex(ptype,ntype,ttype,prim,glVertFuncs,glCellFuncs,glInitFuncs) \
600 { \
601 vtkIdType nPts; unsigned short count = 0; \
602 ptype *points = static_cast<ptype *>(voidPoints); \
603 GLenum previousGlFunction=GL_INVALID_VALUE; \
604 glInitFuncs \
605 \
606 double quad_center[3] = {0, 0, 0}; \
607 double quad_center_tex = 0; \
608 double quad_points[4][3]; \
609 double quad_points_tex[4]; \
610 double dist_center[4] = {0, 0, 0, 0}; \
611 \
612 while (ptIds < endPtIds) \
613 { \
614 nPts = *ptIds; \
615 ++ptIds; \
616 /* If we don't want to draw a QUAD (ex : a triangle nPts = 3) */ \
617 if (nPts != 4) { \
618 /* Classic method */ \
619 vtkOpenGLBeginPolyTriangleOrQuad( prim, previousGlFunction, nPts ); \
620 glCellFuncs \
621 while (nPts > 0) \
622 { \
623 glVertFuncs \
624 ++ptIds; \
625 --nPts; \
626 } \
627 } \
628 /* If we want to draw a QUAD */ \
629 else { \
630 /* We launch glBegin(GL_TRIANGLES) mode in order to draw 4 triangles */ \
631 vtkOpenGLBeginPolyTriangleOrQuad( prim, previousGlFunction, 3 ); \
632 glCellFuncs \
633 /* We keep pointer on the first point of the first triangle */ \
634 /* ptIdsFirstPtQuad will be used for center calculation and for 2nd point of 4th triangle */ \
635 vtkIdType *ptIdsFirstPtQuad; \
636 ptIdsFirstPtQuad = ptIds; \
637 /* QUAD Center calculation */ \
638 /* We save the 4 QUAD points and their texture value */ \
639 GLfloat *vpt; \
640 GLfloat *vtex; \
641 for (int i=0; i<4; i++) { \
642 /* Position : */ \
643 vpt = points + 3**ptIds; \
644 quad_points[i][0] = vpt[0]; \
645 quad_points[i][1] = vpt[1]; \
646 quad_points[i][2] = vpt[2]; \
647 /* Texture : */ \
648 vtex = tcoords + *ptIds; \
649 quad_points_tex[i] = vtex[0]; \
650 ++ptIds; \
651 } \
652 /* Actual calculation of QUAD center with the 4 summits */ \
653 quad_center[0] = (quad_points[0][0] + quad_points[1][0] + quad_points[2][0] + quad_points[3][0])/4; \
654 quad_center[1] = (quad_points[0][1] + quad_points[1][1] + quad_points[2][1] + quad_points[3][1])/4; \
655 quad_center[2] = (quad_points[0][2] + quad_points[1][2] + quad_points[2][2] + quad_points[3][2])/4; \
656 /* Texture center calculation (Interpolation on each component of RGB vector) */ \
657 /* Calculation of distances between center and summits */ \
658 for (int i=0; i<4; i++) { \
659 dist_center[i] = sqrt((quad_points[i][0] - quad_center[0])*(quad_points[i][0] - quad_center[0]) + \
660 (quad_points[i][1] - quad_center[1])*(quad_points[i][1] - quad_center[1]) + \
661 (quad_points[i][2] - quad_center[2])*(quad_points[i][2] - quad_center[2])); \
662 } \
663 /* Texture interpolation */ \
664 quad_center_tex = ((dist_center[3]*quad_points_tex[1] + dist_center[1]*quad_points_tex[3])/(dist_center[1] + dist_center[3]) + \
665 (dist_center[2]*quad_points_tex[0] + dist_center[0]*quad_points_tex[2])/(dist_center[2] + dist_center[0]) \
666 )/2; \
667 /* We take pointer on the first QUAD point */ \
668 ptIds = ptIdsFirstPtQuad; \
669 /* Actual drawing of 4 triangles */ \
670 for (int i=0; i<4; i++) { \
671 /* 1st point */ \
672 glVertFuncs \
673 ++ptIds; \
674 /* 2nd point */ \
675 if (i >= 3) { /* If it is the last triangle */ \
676 /* this 2nd point = the 1st point of 1st triangle */ \
677 glTexCoord1fv(tcoords + *ptIdsFirstPtQuad); \
678 glVertex3fv(points + 3**ptIdsFirstPtQuad); \
679 } \
680 else { \
681 /* Else 2nd point = next point */ \
682 glVertFuncs \
683 } \
684 /* 3rd point */ \
685 glTexCoord1f(quad_center_tex); \
686 glVertex3f(quad_center[0],quad_center[1],quad_center[2]); \
687 } \
688 } /* End of if (nPts == 4) */ \
689 if (++count == 10000) \
690 { \
691 cellNum += 10000; \
692 count = 0; \
693 this->UpdateProgress(static_cast<double>(cellNum)/this->TotalCells); \
694 if (ren->GetRenderWindow()->CheckAbortStatus()) \
695 { \
696 noAbort = 0; \
697 break; \
698 } \
699 } \
700 if ((previousGlFunction != GL_TRIANGLES) \
701 && (previousGlFunction != GL_QUADS) \
702 && (previousGlFunction != GL_POINTS)) \
703 { \
704 glEnd(); \
705 } \
706 } \
707 cellNum += count; \
708 if ((previousGlFunction == GL_TRIANGLES) \
709 || (previousGlFunction == GL_QUADS) \
710 || (previousGlFunction == GL_POINTS)) \
711 { \
712 glEnd(); \
713 } \
714 }
715
716 #define vtkDrawStripLinesMacro(ptype,ntype,ttype,prim,glVertFuncs,glCellFuncs,glInitFuncs) \
717 { \
718 vtkIdType nPts; \
719 ptype *points = static_cast<ptype *>(voidPoints); \
720 vtkIdType *savedPtIds = ptIds; \
721 glInitFuncs \
722 while (ptIds < endPtIds) \
723 { \
724 glBegin(prim); \
725 nPts = *ptIds; \
726 ++ptIds; \
727 glCellFuncs \
728 while (nPts > 0) \
729 { \
730 glVertFuncs \
731 ptIds += 2; \
732 nPts -= 2; \
733 } \
734 glEnd(); \
735 ptIds += nPts; /* nPts could be 0 or -1 here */ \
736 } \
737 ptIds = savedPtIds; \
738 while (ptIds < endPtIds) \
739 { \
740 glBegin(prim); \
741 nPts = *ptIds; \
742 ++ptIds; \
743 glCellFuncs \
744 ++ptIds; \
745 --nPts; \
746 while (nPts > 0) \
747 { \
748 glVertFuncs \
749 ptIds += 2; \
750 nPts -= 2; \
751 } \
752 glEnd(); \
753 ptIds += nPts; /* nPts could be 0 or -1 here */ \
754 } \
755 }
756
DrawPoints(int idx,vtkPoints * p,vtkDataArray * n,vtkUnsignedCharArray * c,vtkDataArray * t,vtkIdType & cellNum,int & noAbort,vtkCellArray * ca,vtkRenderer * ren)757 void vtkOpenGLPolyDataMapper::DrawPoints(int idx,
758 vtkPoints *p,
759 vtkDataArray *n,
760 vtkUnsignedCharArray *c,
761 vtkDataArray *t,
762 vtkIdType &cellNum,
763 int &noAbort,
764 vtkCellArray *ca,
765 vtkRenderer *ren)
766 {
767 void *voidPoints = p->GetVoidPointer(0);
768 void *voidNormals = 0;
769 unsigned char *colors = 0;
770 if (ca->GetNumberOfCells() == 0)
771 {
772 return;
773 }
774 if (n)
775 {
776 voidNormals = n->GetVoidPointer(0);
777 }
778 if (c)
779 {
780 colors = c->GetPointer(0);
781 }
782
783 vtkIdType *ptIds = ca->GetPointer();
784 vtkIdType *endPtIds = ptIds + ca->GetNumberOfConnectivityEntries();
785
786 // draw all the elements, use fast path if available
787 switch (idx)
788 {
789 case VTK_PDM_POINT_TYPE_FLOAT:
790 vtkDrawPointsMacro(float, float, glVertex3fv(points + 3**ptIds);,;);
791 break;
792 case VTK_PDM_POINT_TYPE_DOUBLE:
793 vtkDrawPointsMacro(double, float, glVertex3dv(points + 3**ptIds);,;);
794 break;
795 case VTK_PDM_POINT_TYPE_FLOAT|VTK_PDM_NORMAL_TYPE_FLOAT|VTK_PDM_NORMALS:
796 vtkDrawPointsMacro(float, float,
797 glNormal3fv(normals + 3**ptIds);
798 glVertex3fv(points + 3**ptIds);,
799 float *normals = static_cast<float *>(voidNormals););
800
801 break;
802 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_COLORS:
803 vtkDrawPointsMacro(float, float,
804 glColor4ubv(colors + 4**ptIds);
805 glVertex3fv(points + 3**ptIds);,;);
806
807 break;
808 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS:
809 vtkDrawPointsMacro(float, float,
810 glColor3ubv(colors + 4**ptIds);
811 glVertex3fv(points + 3**ptIds);,;);
812 break;
813 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT |
814 VTK_PDM_NORMALS | VTK_PDM_COLORS:
815 vtkDrawPointsMacro(float, float,
816 glNormal3fv(normals + 3**ptIds);
817 glColor4ubv(colors + 4**ptIds);
818 glVertex3fv(points + 3**ptIds);,
819 float *normals = static_cast<float *>(voidNormals););
820 break;
821 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT |
822 VTK_PDM_NORMALS | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS:
823 vtkDrawPointsMacro(float, float,
824 glNormal3fv(normals + 3**ptIds);
825 glColor3ubv(colors + 4**ptIds);
826 glVertex3fv(points + 3**ptIds);,
827 float *normals = static_cast<float *>(voidNormals););
828 break;
829 default:
830 {
831 int j;
832 vtkIdType *pts = 0;
833 vtkIdType npts = 0;
834 unsigned short count = 0;
835 glBegin(GL_POINTS);
836 for (ca->InitTraversal(); noAbort && ca->GetNextCell(npts,pts);
837 count++)
838 {
839 for (j = 0; j < npts; j++)
840 {
841 if (c)
842 {
843 if (idx & VTK_PDM_CELL_COLORS)
844 {
845 glColor4ubv(c->GetPointer(cellNum << 2));
846 }
847 else
848 {
849 glColor4ubv(c->GetPointer(pts[j]<< 2));
850 }
851 }
852 if (t)
853 {
854 if (idx & VTK_PDM_TCOORD_1D)
855 {
856 glTexCoord1dv(t->GetTuple(pts[j]));
857 }
858 else
859 {
860 glTexCoord2dv(t->GetTuple(pts[j]));
861 }
862 }
863 if (n)
864 {
865 if (idx & VTK_PDM_CELL_NORMALS)
866 {
867 glNormal3dv(n->GetTuple(cellNum));
868 }
869 else
870 {
871 glNormal3dv(n->GetTuple(pts[j]));
872 }
873 }
874 glVertex3dv(p->GetPoint(pts[j]));
875 }
876
877 // check for abort condition
878 if (count == 10000)
879 {
880 count = 0;
881 // report progress
882 this->UpdateProgress(static_cast<double>(cellNum)/this->TotalCells);
883 if (ren->GetRenderWindow()->CheckAbortStatus())
884 {
885 noAbort = 0;
886 }
887 }
888 ++cellNum;
889 }
890 glEnd();
891 }
892 }
893 }
894
895
DrawLines(int idx,vtkPoints * p,vtkDataArray * n,vtkUnsignedCharArray * c,vtkDataArray * t,vtkIdType & cellNum,int & noAbort,vtkCellArray * ca,vtkRenderer * ren)896 void vtkOpenGLPolyDataMapper::DrawLines(int idx,
897 vtkPoints *p,
898 vtkDataArray *n,
899 vtkUnsignedCharArray *c,
900 vtkDataArray *t,
901 vtkIdType &cellNum,
902 int &noAbort,
903 vtkCellArray *ca,
904 vtkRenderer *ren)
905 {
906 void *voidPoints = p->GetVoidPointer(0);
907 void *voidNormals = 0;
908 void *voidTCoords = 0;
909 unsigned char *colors = 0;
910 if (ca->GetNumberOfCells() == 0)
911 {
912 return;
913 }
914 if (n)
915 {
916 voidNormals = n->GetVoidPointer(0);
917 }
918 if (t)
919 {
920 voidTCoords = t->GetVoidPointer(0);
921 }
922 if (c)
923 {
924 colors = c->GetPointer(0);
925 }
926 vtkIdType *ptIds = ca->GetPointer();
927 vtkIdType *endPtIds = ptIds + ca->GetNumberOfConnectivityEntries();
928
929 // draw all the elements, use fast path if available
930 switch (idx)
931 {
932 case VTK_PDM_POINT_TYPE_FLOAT:
933 vtkDrawPrimsMacro(float, float, GL_LINE_STRIP,
934 glVertex3fv(points + 3**ptIds);,;);
935 break;
936 case VTK_PDM_POINT_TYPE_DOUBLE:
937 vtkDrawPrimsMacro(double, float, GL_LINE_STRIP,
938 glVertex3dv(points + 3**ptIds);,;);
939 break;
940 case VTK_PDM_POINT_TYPE_FLOAT|VTK_PDM_NORMAL_TYPE_FLOAT|VTK_PDM_NORMALS:
941 vtkDrawPrimsMacro(float, float, GL_LINE_STRIP,
942 glNormal3fv(normals + 3**ptIds);
943 glVertex3fv(points + 3**ptIds);,
944 float *normals = static_cast<float *>(voidNormals););
945
946 break;
947 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_COLORS:
948 vtkDrawPrimsMacro(float, float, GL_LINE_STRIP,
949 glColor4ubv(colors + 4**ptIds);
950 glVertex3fv(points + 3**ptIds);,;);
951 break;
952 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS:
953 vtkDrawPrimsMacro(float, float, GL_LINE_STRIP,
954 glColor3ubv(colors + 4**ptIds);
955 glVertex3fv(points + 3**ptIds);,;);
956 break;
957 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT |
958 VTK_PDM_NORMALS | VTK_PDM_COLORS:
959 vtkDrawPrimsMacro(float, float, GL_LINE_STRIP,
960 glNormal3fv(normals + 3**ptIds);
961 glColor4ubv(colors + 4**ptIds);
962 glVertex3fv(points + 3**ptIds);,
963 float *normals = static_cast<float *>(voidNormals);
964 );
965 break;
966 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT |
967 VTK_PDM_NORMALS | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS:
968 vtkDrawPrimsMacro(float, float, GL_LINE_STRIP,
969 glNormal3fv(normals + 3**ptIds);
970 glColor3ubv(colors + 4**ptIds);
971 glVertex3fv(points + 3**ptIds);,
972 float *normals = static_cast<float *>(voidNormals);
973 );
974 break;
975 case VTK_PDM_POINT_TYPE_FLOAT |
976 VTK_PDM_TCOORD_TYPE_FLOAT | VTK_PDM_TCOORD_1D | VTK_PDM_TCOORDS:
977 vtkDrawPrimsMacro(float, float, GL_LINE_STRIP,
978 glTexCoord1fv(tcoords + *ptIds);
979 glVertex3fv(points + 3**ptIds);,
980 float *tcoords = static_cast<float *>(voidTCoords);
981 );
982 break;
983 case VTK_PDM_POINT_TYPE_FLOAT |
984 VTK_PDM_NORMAL_TYPE_FLOAT | VTK_PDM_NORMALS |
985 VTK_PDM_TCOORD_TYPE_FLOAT | VTK_PDM_TCOORD_1D | VTK_PDM_TCOORDS:
986 vtkDrawPrimsMacro(float, float, GL_LINE_STRIP,
987 glNormal3fv(normals + 3**ptIds);
988 glTexCoord1fv(tcoords + *ptIds);
989 glVertex3fv(points + 3**ptIds);,
990 float *tcoords = static_cast<float *>(voidTCoords);
991 float *normals = static_cast<float *>(voidNormals);
992 );
993 break;
994 default:
995 {
996 int j;
997 vtkIdType *pts = 0;
998 vtkIdType npts = 0;
999 unsigned short count = 0;
1000 for (ca->InitTraversal(); noAbort && ca->GetNextCell(npts,pts);
1001 count++)
1002 {
1003 glBegin(GL_LINE_STRIP);
1004 for (j = 0; j < npts; j++)
1005 {
1006 if (c)
1007 {
1008 if (idx & VTK_PDM_CELL_COLORS)
1009 {
1010 glColor4ubv(c->GetPointer(cellNum << 2));
1011 }
1012 else
1013 {
1014 glColor4ubv(c->GetPointer(pts[j] << 2));
1015 }
1016 }
1017 if (t)
1018 {
1019 if (idx & VTK_PDM_TCOORD_1D)
1020 {
1021 glTexCoord1dv(t->GetTuple(pts[j]));
1022 }
1023 else
1024 {
1025 glTexCoord2dv(t->GetTuple(pts[j]));
1026 }
1027 }
1028 if (n)
1029 {
1030 if (idx & VTK_PDM_CELL_NORMALS)
1031 {
1032 glNormal3dv(n->GetTuple(cellNum));
1033 }
1034 else
1035 {
1036 glNormal3dv(n->GetTuple(pts[j]));
1037 }
1038 }
1039 glVertex3dv(p->GetPoint(pts[j]));
1040 }
1041 glEnd();
1042
1043 // check for abort condition
1044 if (count == 10000)
1045 {
1046 count = 0;
1047 // report progress
1048 this->UpdateProgress(static_cast<double>(cellNum)/this->TotalCells);
1049 if (ren->GetRenderWindow()->CheckAbortStatus())
1050 {
1051 noAbort = 0;
1052 }
1053 }
1054 ++cellNum;
1055 }
1056 }
1057 }
1058 }
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068 #define PolyNormal \
1069 { double polyNorm[3]; vtkPolygon::ComputeNormal(p,nPts,ptIds,polyNorm); glNormal3dv(polyNorm); }
1070
DrawPolygons(int idx,vtkPoints * p,vtkDataArray * n,vtkUnsignedCharArray * c,vtkDataArray * t,vtkIdType & cellNum,int & noAbort,GLenum rep,vtkCellArray * ca,vtkRenderer * ren)1071 void vtkOpenGLPolyDataMapper::DrawPolygons(int idx,
1072 vtkPoints *p,
1073 vtkDataArray *n,
1074 vtkUnsignedCharArray *c,
1075 vtkDataArray *t,
1076 vtkIdType &cellNum,
1077 int &noAbort,
1078 GLenum rep,
1079 vtkCellArray *ca,
1080 vtkRenderer *ren)
1081 {
1082 vtkOpenGLClearErrorMacro();
1083
1084 void *voidPoints = p->GetVoidPointer(0);
1085 void *voidNormals = 0;
1086 void *voidTCoords = 0;
1087 unsigned char *colors = 0;
1088 if (ca->GetNumberOfCells() == 0)
1089 {
1090 return;
1091 }
1092 if (n)
1093 {
1094 voidNormals = n->GetVoidPointer(0);
1095 }
1096 if (c)
1097 {
1098 colors = c->GetPointer(0);
1099 // if these are cell colors then advance to the first cell
1100 if (idx & VTK_PDM_CELL_COLORS)
1101 {
1102 colors = colors + cellNum*4;
1103 }
1104 }
1105 if (t)
1106 {
1107 voidTCoords = t->GetVoidPointer(0);
1108 }
1109 vtkIdType *ptIds = ca->GetPointer();
1110 vtkIdType *endPtIds = ptIds + ca->GetNumberOfConnectivityEntries();
1111
1112 // draw all the elements, use fast path if available
1113 switch (idx)
1114 {
1115 case VTK_PDM_POINT_TYPE_FLOAT:
1116 vtkDrawPolysMacro(float, float, float, rep,
1117 glVertex3fv(points + 3**ptIds);,
1118 PolyNormal,;);
1119 break;
1120 case VTK_PDM_POINT_TYPE_DOUBLE:
1121 vtkDrawPolysMacro(double, float, float, rep,
1122 glVertex3dv(points + 3**ptIds);,
1123 PolyNormal,;);
1124 break;
1125 case VTK_PDM_POINT_TYPE_FLOAT|VTK_PDM_NORMAL_TYPE_FLOAT|VTK_PDM_NORMALS:
1126 vtkDrawPolysMacro(float, float, float, rep,
1127 glNormal3fv(normals + 3**ptIds);
1128 glVertex3fv(points + 3**ptIds);,;,
1129 float *normals = static_cast<float *>(voidNormals););
1130 break;
1131 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_COLORS:
1132 vtkDrawPolysMacro(float, float, float, rep,
1133 glColor4ubv(colors + 4**ptIds);
1134 glVertex3fv(points + 3**ptIds);,
1135 PolyNormal,;);
1136 break;
1137 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS:
1138 vtkDrawPolysMacro4Tri(float, float, float, rep,
1139 glColor3ubv(colors + 4**ptIds);
1140 glVertex3fv(points + 3**ptIds);,
1141 PolyNormal,;);
1142 break;
1143 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT |
1144 VTK_PDM_NORMALS | VTK_PDM_COLORS:
1145 vtkDrawPolysMacro(float, float, float, rep,
1146 glNormal3fv(normals + 3**ptIds);
1147 glColor4ubv(colors + 4**ptIds);
1148 glVertex3fv(points + 3**ptIds);,;,
1149 float *normals = static_cast<float *>(voidNormals););
1150 break;
1151 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT |
1152 VTK_PDM_NORMALS | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS:
1153 vtkDrawPolysMacro(float, float, float, rep,
1154 glNormal3fv(normals + 3**ptIds);
1155 glColor3ubv(colors + 4**ptIds);
1156 glVertex3fv(points + 3**ptIds);,;,
1157 float *normals = static_cast<float *>(voidNormals););
1158 break;
1159 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | VTK_PDM_NORMALS |
1160 VTK_PDM_TCOORD_TYPE_FLOAT | VTK_PDM_TCOORD_1D | VTK_PDM_TCOORDS:
1161 vtkDrawPolysMacro(float, float, float, rep,
1162 glNormal3fv(normals + 3**ptIds);
1163 glTexCoord1fv(tcoords + *ptIds);
1164 glVertex3fv(points + 3**ptIds);,;,
1165 float *normals = static_cast<float *>(voidNormals);
1166 float *tcoords = static_cast<float *>(voidTCoords););
1167 break;
1168 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | VTK_PDM_CELL_NORMALS |
1169 VTK_PDM_TCOORD_TYPE_FLOAT | VTK_PDM_TCOORD_1D | VTK_PDM_TCOORDS:
1170 vtkDrawPolysMacro(float, float, float, rep,
1171 glTexCoord1fv(tcoords + *ptIds);
1172 glVertex3fv(points + 3**ptIds);,
1173 glNormal3fv(normals); normals += 3;,
1174 float *tcoords = static_cast<float *>(voidTCoords);
1175 float *normals = static_cast<float *>(voidNormals);
1176 normals += cellNum*3;);
1177 break;
1178 case VTK_PDM_POINT_TYPE_FLOAT |
1179 VTK_PDM_TCOORD_TYPE_FLOAT | VTK_PDM_TCOORD_1D | VTK_PDM_TCOORDS:
1180 vtkDrawPolysMacro4TriTex(float, float, float, rep,
1181 glTexCoord1fv(tcoords + *ptIds);
1182 glVertex3fv(points + 3**ptIds);,
1183 PolyNormal;,
1184 float *tcoords = static_cast<float *>(voidTCoords););
1185 break;
1186 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT |
1187 VTK_PDM_NORMALS | VTK_PDM_TCOORD_TYPE_FLOAT | VTK_PDM_TCOORDS:
1188 vtkDrawPolysMacro(float, float, float, rep,
1189 glNormal3fv(normals + 3**ptIds);
1190 glTexCoord2fv(tcoords + 2**ptIds);
1191 glVertex3fv(points + 3**ptIds);,;,
1192 float *normals = static_cast<float *>(voidNormals);
1193 float *tcoords = static_cast<float *>(voidTCoords););
1194 break;
1195 case VTK_PDM_POINT_TYPE_FLOAT|VTK_PDM_NORMAL_TYPE_FLOAT|
1196 VTK_PDM_CELL_NORMALS:
1197 vtkDrawPolysMacro(float, float, float, rep,
1198 glVertex3fv(points + 3**ptIds);,
1199 glNormal3fv(normals); normals += 3;,
1200 float *normals = static_cast<float *>(voidNormals);
1201 normals += cellNum*3;);
1202 break;
1203 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT |
1204 VTK_PDM_CELL_NORMALS | VTK_PDM_COLORS:
1205 vtkDrawPolysMacro(float, float, float, rep,
1206 glColor4ubv(colors + 4**ptIds);
1207 glVertex3fv(points + 3**ptIds);,
1208 glNormal3fv(normals); normals += 3;,
1209 float *normals = static_cast<float *>(voidNormals);
1210 normals += cellNum*3;);
1211 break;
1212 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT |
1213 VTK_PDM_CELL_NORMALS | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS:
1214 vtkDrawPolysMacro(float, float, float, rep,
1215 glColor3ubv(colors + 4**ptIds);
1216 glVertex3fv(points + 3**ptIds);,
1217 glNormal3fv(normals); normals += 3;,
1218 float *normals = static_cast<float *>(voidNormals);
1219 normals += cellNum*3;);
1220 break;
1221 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT |
1222 VTK_PDM_NORMALS | VTK_PDM_COLORS | VTK_PDM_CELL_COLORS:
1223 vtkDrawPolysMacro(float, float, float, rep,
1224 glNormal3fv(normals + 3**ptIds);
1225 glVertex3fv(points + 3**ptIds);,
1226 glColor4ubv(colors); colors += 4;,
1227 float *normals = static_cast<float *>(voidNormals););
1228 break;
1229 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT |
1230 VTK_PDM_NORMALS | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS |
1231 VTK_PDM_CELL_COLORS:
1232 vtkDrawPolysMacro(float, float, float, rep,
1233 glNormal3fv(normals + 3**ptIds);
1234 glVertex3fv(points + 3**ptIds);,
1235 glColor3ubv(colors); colors += 4;,
1236 float *normals = static_cast<float *>(voidNormals););
1237 break;
1238 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT |
1239 VTK_PDM_CELL_NORMALS | VTK_PDM_COLORS | VTK_PDM_CELL_COLORS:
1240 vtkDrawPolysMacro(float, float, float, rep,
1241 glVertex3fv(points + 3**ptIds);,
1242 glNormal3fv(normals); normals += 3;
1243 glColor4ubv(colors); colors += 4;,
1244 float *normals = static_cast<float *>(voidNormals);
1245 normals += cellNum*3;);
1246 break;
1247 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT |
1248 VTK_PDM_CELL_NORMALS | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS |
1249 VTK_PDM_CELL_COLORS:
1250 vtkDrawPolysMacro(float, float, float, rep,
1251 glVertex3fv(points + 3**ptIds);,
1252 glNormal3fv(normals); normals += 3;
1253 glColor3ubv(colors); colors += 4;,
1254 float *normals = static_cast<float *>(voidNormals);
1255 normals += cellNum*3;);
1256 break;
1257 default:
1258 {
1259 int j;
1260 vtkIdType *pts = 0;
1261 vtkIdType npts = 0;
1262 unsigned short count = 0;
1263 for (ca->InitTraversal(); noAbort && ca->GetNextCell(npts,pts);
1264 count++)
1265 {
1266 glBegin(rep);
1267 if (!n)
1268 {
1269 double polyNorm[3];
1270 vtkPolygon::ComputeNormal(p,npts,pts,polyNorm);
1271 glNormal3dv(polyNorm);
1272 }
1273 for (j = 0; j < npts; j++)
1274 {
1275 if (c)
1276 {
1277 if (idx & VTK_PDM_CELL_COLORS)
1278 {
1279 glColor4ubv(c->GetPointer(cellNum << 2));
1280 }
1281 else
1282 {
1283 glColor4ubv(c->GetPointer(pts[j] << 2));
1284 }
1285 }
1286 if (t)
1287 {
1288 if (idx & VTK_PDM_TCOORD_1D)
1289 {
1290 glTexCoord1dv(t->GetTuple(pts[j]));
1291 }
1292 else
1293 {
1294 glTexCoord2dv(t->GetTuple(pts[j]));
1295 }
1296 }
1297 if (n)
1298 {
1299 if (idx & VTK_PDM_CELL_NORMALS)
1300 {
1301 glNormal3dv(n->GetTuple(cellNum));
1302 }
1303 else
1304 {
1305 glNormal3dv(n->GetTuple(pts[j]));
1306 }
1307 }
1308 glVertex3dv(p->GetPoint(pts[j]));
1309 }
1310 glEnd();
1311
1312 // check for abort condition
1313 if (count == 10000)
1314 {
1315 count = 0;
1316 // report progress
1317 this->UpdateProgress(static_cast<double>(cellNum)/this->TotalCells);
1318 if (ren->GetRenderWindow()->CheckAbortStatus())
1319 {
1320 noAbort = 0;
1321 }
1322 }
1323 ++cellNum;
1324 }
1325 }
1326 }
1327 vtkOpenGLCheckErrorMacro("failed after DrawPolygons");
1328 }
1329
1330 // fix refs here
1331 #define TStripNormal \
1332 if ( vcount > 2) \
1333 { \
1334 if (vcount % 2) \
1335 { \
1336 normIdx[0] = ptIds[-2]; normIdx[1] = ptIds[0]; normIdx[2] = ptIds[-1]; \
1337 vtkTriangle::ComputeNormal(p, 3, normIdx, polyNorm); \
1338 } \
1339 else \
1340 { \
1341 normIdx[0] = ptIds[-2]; normIdx[1] = ptIds[-1]; normIdx[2] = ptIds[0]; \
1342 vtkTriangle::ComputeNormal(p, 3, normIdx, polyNorm); \
1343 } \
1344 glNormal3dv(polyNorm); \
1345 } \
1346 vcount++;
1347
1348 #define TStripNormalStart \
1349 vtkTriangle::ComputeNormal(p, 3, ptIds, polyNorm); \
1350 glNormal3dv(polyNorm); int vcount = 0;
1351
DrawTStrips(int idx,vtkPoints * p,vtkDataArray * n,vtkUnsignedCharArray * c,vtkDataArray * t,vtkIdType & cellNum,int & noAbort,GLenum rep,vtkCellArray * ca,vtkRenderer * ren)1352 void vtkOpenGLPolyDataMapper::DrawTStrips(int idx,
1353 vtkPoints *p,
1354 vtkDataArray *n,
1355 vtkUnsignedCharArray *c,
1356 vtkDataArray *t,
1357 vtkIdType &cellNum,
1358 int &noAbort,
1359 GLenum rep,
1360 vtkCellArray *ca,
1361 vtkRenderer *ren)
1362 {
1363 vtkOpenGLClearErrorMacro();
1364 void *voidPoints = p->GetVoidPointer(0);
1365 void *voidNormals = 0;
1366 void *voidTCoords = 0;
1367 unsigned char *colors = 0;
1368 double polyNorm[3];
1369 vtkIdType normIdx[3];
1370
1371 if (ca->GetNumberOfCells() == 0)
1372 {
1373 return;
1374 }
1375 if (n)
1376 {
1377 voidNormals = n->GetVoidPointer(0);
1378 }
1379 if (c)
1380 {
1381 colors = c->GetPointer(0);
1382 }
1383 if (t)
1384 {
1385 voidTCoords = t->GetVoidPointer(0);
1386 }
1387 vtkIdType *ptIds = ca->GetPointer();
1388 vtkIdType *endPtIds = ptIds + ca->GetNumberOfConnectivityEntries();
1389
1390 // draw all the elements, use fast path if available
1391 switch (idx)
1392 {
1393 case VTK_PDM_POINT_TYPE_FLOAT:
1394 vtkDrawPolysMacro(float, float, float, rep,
1395 TStripNormal glVertex3fv(points + 3**ptIds);,
1396 TStripNormalStart,;);
1397 break;
1398 case VTK_PDM_POINT_TYPE_DOUBLE:
1399 vtkDrawPolysMacro(double, float, float, rep,
1400 TStripNormal glVertex3dv(points + 3**ptIds);,
1401 TStripNormalStart,;);
1402 break;
1403 case VTK_PDM_POINT_TYPE_FLOAT|VTK_PDM_NORMAL_TYPE_FLOAT|VTK_PDM_NORMALS:
1404 vtkDrawPolysMacro(float, float, float, rep,
1405 glNormal3fv(normals + 3**ptIds);
1406 glVertex3fv(points + 3**ptIds);,;,
1407 float *normals = static_cast<float *>(voidNormals););
1408 break;
1409 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_COLORS:
1410 vtkDrawPolysMacro(float, float, float, rep,
1411 TStripNormal
1412 glColor4ubv(colors + (*ptIds << 2));
1413 glVertex3fv(points + 3**ptIds);,
1414 TStripNormalStart,;);
1415 break;
1416 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS:
1417 vtkDrawPolysMacro(float, float, float, rep,
1418 TStripNormal
1419 glColor3ubv(colors + (*ptIds << 2));
1420 glVertex3fv(points + 3**ptIds);,
1421 TStripNormalStart,;);
1422 break;
1423 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT |
1424 VTK_PDM_NORMALS | VTK_PDM_COLORS:
1425 vtkDrawPolysMacro(float, float, float, rep,
1426 glNormal3fv(normals + 3**ptIds);
1427 glColor4ubv(colors + (*ptIds << 2));
1428 glVertex3fv(points + 3**ptIds);,;,
1429 float *normals = static_cast<float *>(voidNormals););
1430 break;
1431 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT |
1432 VTK_PDM_NORMALS | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS:
1433 vtkDrawPolysMacro(float, float, float, rep,
1434 glNormal3fv(normals + 3**ptIds);
1435 glColor3ubv(colors + (*ptIds << 2));
1436 glVertex3fv(points + 3**ptIds);,;,
1437 float *normals = static_cast<float *>(voidNormals););
1438 break;
1439 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | VTK_PDM_NORMALS |
1440 VTK_PDM_TCOORD_1D | VTK_PDM_TCOORD_TYPE_FLOAT | VTK_PDM_TCOORDS:
1441 vtkDrawPolysMacro(float, float, float, rep,
1442 glNormal3fv(normals + 3**ptIds);
1443 glTexCoord1fv(tcoords + *ptIds);
1444 glVertex3fv(points + 3**ptIds);,;,
1445 float *normals = static_cast<float *>(voidNormals);
1446 float *tcoords = static_cast<float *>(voidTCoords););
1447 break;
1448 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT |
1449 VTK_PDM_NORMALS | VTK_PDM_TCOORD_TYPE_FLOAT | VTK_PDM_TCOORDS:
1450 vtkDrawPolysMacro(float, float, float, rep,
1451 glNormal3fv(normals + 3**ptIds);
1452 glTexCoord2fv(tcoords + 2**ptIds);
1453 glVertex3fv(points + 3**ptIds);,;,
1454 float *normals = static_cast<float *>(voidNormals);
1455 float *tcoords = static_cast<float *>(voidTCoords););
1456 break;
1457 default:
1458 {
1459 int j;
1460 vtkIdType nPts = 0;
1461 unsigned short count = 0;
1462 unsigned long coloroffset = cellNum;
1463 for (ca->InitTraversal(); noAbort && ca->GetNextCell(nPts,ptIds);
1464 count++)
1465 {
1466 glBegin(rep);
1467 vtkTriangle::ComputeNormal(p, 3, ptIds, polyNorm);
1468 glNormal3dv(polyNorm);
1469 for (j = 0; j < nPts; j++)
1470 {
1471 if (c)
1472 {
1473 if ( (idx & VTK_PDM_USE_FIELD_DATA) && j>=2 )
1474 {
1475 glColor4ubv(c->GetPointer(coloroffset << 2));
1476 coloroffset++;
1477 }
1478 else if (idx & VTK_PDM_CELL_COLORS)
1479 {
1480 glColor4ubv(c->GetPointer(cellNum << 2));
1481 }
1482 else
1483 {
1484 glColor4ubv(c->GetPointer(ptIds[j] << 2));
1485 }
1486 }
1487 if (t)
1488 {
1489 if (idx & VTK_PDM_TCOORD_1D)
1490 {
1491 glTexCoord1dv(t->GetTuple(ptIds[j]));
1492 }
1493 else
1494 {
1495 glTexCoord2dv(t->GetTuple(ptIds[j]));
1496 }
1497 }
1498 if (n)
1499 {
1500 if (idx & VTK_PDM_CELL_NORMALS)
1501 {
1502 glNormal3dv(n->GetTuple(cellNum));
1503 }
1504 else
1505 {
1506 glNormal3dv(n->GetTuple(ptIds[j]));
1507 }
1508 }
1509 else
1510 {
1511 if (j >= 2)
1512 {
1513 if (j % 2)
1514 {
1515 normIdx[0] = ptIds[j-2]; normIdx[1] = ptIds[j];
1516 normIdx[2] = ptIds[j-1];
1517 vtkTriangle::ComputeNormal(p, 3, normIdx, polyNorm);
1518 }
1519 else
1520 {
1521 normIdx[0] = ptIds[j-2]; normIdx[1] = ptIds[j-1];
1522 normIdx[2] = ptIds[j];
1523 vtkTriangle::ComputeNormal(p, 3, normIdx, polyNorm);
1524 }
1525 }
1526 glNormal3dv(polyNorm);
1527 }
1528 glVertex3dv(p->GetPoint(ptIds[j]));
1529 }
1530 glEnd();
1531
1532 // check for abort condition
1533 if (count == 10000)
1534 {
1535 count = 0;
1536 // report progress
1537 this->UpdateProgress(static_cast<double>(cellNum)/this->TotalCells);
1538 if (ren->GetRenderWindow()->CheckAbortStatus())
1539 {
1540 noAbort = 0;
1541 }
1542 }
1543 ++cellNum;
1544 }
1545 }
1546 }
1547 vtkOpenGLCheckErrorMacro("failed after DrawTStrips");
1548 }
1549
vtkOpenGLPolyDataMapperDrawTStripLines(int idx,vtkPoints * p,vtkDataArray * n,vtkUnsignedCharArray * c,vtkDataArray * t,vtkIdType & cellNum,int & noAbort,GLenum rep,vtkCellArray * ca,vtkRenderer * ren)1550 static void vtkOpenGLPolyDataMapperDrawTStripLines(int idx,
1551 vtkPoints *p,
1552 vtkDataArray *n,
1553 vtkUnsignedCharArray *c,
1554 vtkDataArray *t,
1555 vtkIdType &cellNum,
1556 int &noAbort,
1557 GLenum rep,
1558 vtkCellArray *ca,
1559 vtkRenderer *ren)
1560 {
1561 vtkOpenGLClearErrorMacro();
1562 void *voidPoints = p->GetVoidPointer(0);
1563 void *voidNormals = 0;
1564 void *voidTCoords = 0;
1565 unsigned char *colors = 0;
1566 double polyNorm[3];
1567 vtkIdType normIdx[3];
1568
1569 if (n)
1570 {
1571 voidNormals = n->GetVoidPointer(0);
1572 }
1573 if (c)
1574 {
1575 colors = c->GetPointer(0);
1576 }
1577 if (t)
1578 {
1579 voidTCoords = t->GetVoidPointer(0);
1580 }
1581 vtkIdType *ptIds = ca->GetPointer();
1582 vtkIdType *endPtIds = ptIds + ca->GetNumberOfConnectivityEntries();
1583
1584 // draw all the elements, use fast path if available
1585 switch (idx)
1586 {
1587 case VTK_PDM_POINT_TYPE_FLOAT:
1588 vtkDrawStripLinesMacro(float, float, float, rep,
1589 TStripNormal; glVertex3fv(points + 3**ptIds);,
1590 TStripNormalStart,;);
1591 break;
1592 case VTK_PDM_POINT_TYPE_DOUBLE:
1593 vtkDrawStripLinesMacro(double, float, float, rep,
1594 TStripNormal glVertex3dv(points + 3**ptIds);,
1595 TStripNormalStart,;);
1596 break;
1597 case VTK_PDM_POINT_TYPE_FLOAT|VTK_PDM_NORMAL_TYPE_FLOAT|VTK_PDM_NORMALS:
1598 vtkDrawStripLinesMacro(float, float, float, rep,
1599 glNormal3fv(normals + 3**ptIds);
1600 glVertex3fv(points + 3**ptIds);,;,
1601 float *normals = static_cast<float *>(voidNormals););
1602 break;
1603 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_COLORS:
1604 vtkDrawStripLinesMacro(float, float, float, rep,
1605 TStripNormal;
1606 glColor4ubv(colors + 4**ptIds);
1607 glVertex3fv(points + 3**ptIds);,
1608 TStripNormalStart,;);
1609 break;
1610 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS:
1611 vtkDrawStripLinesMacro(float, float, float, rep,
1612 TStripNormal;
1613 glColor3ubv(colors + 4**ptIds);
1614 glVertex3fv(points + 3**ptIds);,
1615 TStripNormalStart,;);
1616 break;
1617 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT |
1618 VTK_PDM_NORMALS | VTK_PDM_COLORS:
1619 vtkDrawStripLinesMacro(float, float, float, rep,
1620 glNormal3fv(normals + 3**ptIds);
1621 glColor4ubv(colors + 4**ptIds);
1622 glVertex3fv(points + 3**ptIds);,;,
1623 float *normals = static_cast<float *>(voidNormals););
1624 break;
1625 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT |
1626 VTK_PDM_NORMALS | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS:
1627 vtkDrawStripLinesMacro(float, float, float, rep,
1628 glNormal3fv(normals + 3**ptIds);
1629 glColor3ubv(colors + 4**ptIds);
1630 glVertex3fv(points + 3**ptIds);,;,
1631 float *normals = static_cast<float *>(voidNormals););
1632 break;
1633 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT | VTK_PDM_NORMALS |
1634 VTK_PDM_TCOORD_TYPE_FLOAT | VTK_PDM_TCOORD_1D | VTK_PDM_TCOORDS:
1635 vtkDrawStripLinesMacro(float, float, float, rep,
1636 glNormal3fv(normals + 3**ptIds);
1637 glTexCoord1fv(tcoords + *ptIds);
1638 glVertex3fv(points + 3**ptIds);,;,
1639 float *normals = static_cast<float *>(voidNormals);
1640 float *tcoords = static_cast<float *>(voidTCoords););
1641 break;
1642 case VTK_PDM_POINT_TYPE_FLOAT | VTK_PDM_NORMAL_TYPE_FLOAT |
1643 VTK_PDM_NORMALS | VTK_PDM_TCOORD_TYPE_FLOAT | VTK_PDM_TCOORDS:
1644 vtkDrawStripLinesMacro(float, float, float, rep,
1645 glNormal3fv(normals + 3**ptIds);
1646 glTexCoord2fv(tcoords + 2**ptIds);
1647 glVertex3fv(points + 3**ptIds);,;,
1648 float *normals = static_cast<float *>(voidNormals);
1649 float *tcoords = static_cast<float *>(voidTCoords););
1650 break;
1651 default:
1652 {
1653 int j;
1654 vtkIdType nPts = 0;
1655 int count = 0;
1656 unsigned long coloroffset = cellNum;
1657 for (ca->InitTraversal(); noAbort && ca->GetNextCell(nPts,ptIds);
1658 count++)
1659 {
1660 glBegin(rep);
1661 for (j = 0; j < nPts; j += 2)
1662 {
1663 if (c)
1664 {
1665 if ( (idx & VTK_PDM_USE_FIELD_DATA) && j >= 2)
1666 {
1667 glColor4ubv(c->GetPointer((coloroffset+j) << 2));
1668 }
1669 else if (idx & VTK_PDM_CELL_COLORS)
1670 {
1671 glColor4ubv(c->GetPointer(cellNum << 2));
1672 }
1673 else
1674 {
1675 glColor4ubv(c->GetPointer(ptIds[j] << 2));
1676 }
1677 }
1678 if (t)
1679 {
1680 if (idx & VTK_PDM_TCOORD_1D)
1681 {
1682 glTexCoord1dv(t->GetTuple(ptIds[j]));
1683 }
1684 else
1685 {
1686 glTexCoord2dv(t->GetTuple(ptIds[j]));
1687 }
1688 }
1689 if (n)
1690 {
1691 if (idx & VTK_PDM_CELL_NORMALS)
1692 {
1693 glNormal3dv(n->GetTuple(cellNum));
1694 }
1695 else
1696 {
1697 glNormal3dv(n->GetTuple(ptIds[j]));
1698 }
1699 }
1700 else
1701 {
1702 if ( j == 0 )
1703 {
1704 vtkTriangle::ComputeNormal(p, 3, ptIds, polyNorm);
1705 }
1706 else
1707 {
1708 normIdx[0] = ptIds[j-2]; normIdx[1] = ptIds[j-1];
1709 normIdx[2] = ptIds[j];
1710 vtkTriangle::ComputeNormal(p, 3, normIdx, polyNorm);
1711 }
1712 glNormal3dv(polyNorm);
1713 }
1714 glVertex3dv(p->GetPoint(ptIds[j]));
1715 }
1716 glEnd();
1717
1718 glBegin(rep);
1719 for (j = 1; j < nPts; j += 2)
1720 {
1721 if (c)
1722 {
1723 if ( (idx & VTK_PDM_USE_FIELD_DATA) && j >= 2)
1724 {
1725 glColor4ubv(c->GetPointer((coloroffset+j) << 2));
1726 }
1727 else if (idx & VTK_PDM_CELL_COLORS)
1728 {
1729 glColor4ubv(c->GetPointer(cellNum << 2));
1730 }
1731 else
1732 {
1733 glColor4ubv(c->GetPointer(ptIds[j] << 2));
1734 }
1735 }
1736 if (t)
1737 {
1738 if (idx & VTK_PDM_TCOORD_1D)
1739 {
1740 glTexCoord1dv(t->GetTuple(ptIds[j]));
1741 }
1742 else
1743 {
1744 glTexCoord2dv(t->GetTuple(ptIds[j]));
1745 }
1746 }
1747 if (n)
1748 {
1749 if (idx & VTK_PDM_CELL_NORMALS)
1750 {
1751 glNormal3dv(n->GetTuple(cellNum));
1752 }
1753 else
1754 {
1755 glNormal3dv(n->GetTuple(ptIds[j]));
1756 }
1757 }
1758 else
1759 {
1760 if (j == 1)
1761 {
1762 vtkTriangle::ComputeNormal(p, 3, ptIds, polyNorm);
1763 }
1764 else
1765 {
1766 normIdx[0] = ptIds[j-2]; normIdx[1] = ptIds[j];
1767 normIdx[2] = ptIds[j-1];
1768 vtkTriangle::ComputeNormal(p, 3, normIdx, polyNorm);
1769 }
1770 glNormal3dv(polyNorm);
1771 }
1772 glVertex3dv(p->GetPoint(ptIds[j]));
1773 }
1774 glEnd();
1775
1776 // check for abort condition
1777 if (count == 100)
1778 {
1779 count = 0;
1780 if (ren->GetRenderWindow()->CheckAbortStatus())
1781 {
1782 noAbort = 0;
1783 }
1784 }
1785 ++cellNum;
1786 coloroffset += (nPts >= 2)? (nPts - 2) : 0;
1787 }
1788 }
1789 }
1790 vtkOpenGLStaticCheckErrorMacro("failed after DrawTStripLines");
1791 }
1792
1793 // Draw method for OpenGL.
Draw(vtkRenderer * aren,vtkActor * act)1794 int vtkOpenGLPolyDataMapper::Draw(vtkRenderer *aren, vtkActor *act)
1795 {
1796 vtkOpenGLClearErrorMacro();
1797 vtkOpenGLRenderer *ren = static_cast<vtkOpenGLRenderer *>(aren);
1798 int rep, interpolation;
1799 float tran;
1800 vtkProperty *prop;
1801 vtkPoints *p;
1802 vtkUnsignedCharArray *c=NULL;
1803 vtkDataArray *n;
1804 vtkDataArray *t;
1805 int tDim;
1806 int noAbort = 1;
1807 vtkPolyData *input = this->GetInput();
1808 int cellScalars = 0;
1809 vtkIdType cellNum = 0;
1810 int cellNormals;
1811 int resolve=0, zResolve=0;
1812 double zRes = 0.0;
1813
1814 // get the property
1815 prop = act->GetProperty();
1816
1817 // get the transparency
1818 tran = prop->GetOpacity();
1819
1820 // if the primitives are invisable then get out of here
1821 if (tran <= 0.0)
1822 {
1823 return noAbort;
1824 }
1825
1826 // get the representation (e.g., surface / wireframe / points)
1827 rep = prop->GetRepresentation();
1828
1829 // get the shading interpolation
1830 interpolation = prop->GetInterpolation();
1831
1832 // and draw the display list
1833 p = input->GetPoints();
1834
1835 // are they cell or point scalars
1836 if ( this->Colors )
1837 {
1838 c = this->Colors;
1839 if ( (this->ScalarMode == VTK_SCALAR_MODE_USE_CELL_DATA ||
1840 this->ScalarMode == VTK_SCALAR_MODE_USE_CELL_FIELD_DATA ||
1841 this->ScalarMode == VTK_SCALAR_MODE_USE_FIELD_DATA ||
1842 !input->GetPointData()->GetScalars() )
1843 && this->ScalarMode != VTK_SCALAR_MODE_USE_POINT_FIELD_DATA)
1844 {
1845 cellScalars = 1;
1846 }
1847 }
1848
1849 n = input->GetPointData()->GetNormals();
1850 if (interpolation == VTK_FLAT)
1851 {
1852 n = 0;
1853 }
1854
1855 cellNormals = 0;
1856 if (n == 0 && input->GetCellData()->GetNormals())
1857 {
1858 cellNormals = 1;
1859 n = input->GetCellData()->GetNormals();
1860 }
1861
1862 // if we are doing vertex colors then set lmcolor to adjust
1863 // the current materials ambient and diffuse values using
1864 // vertex color commands otherwise tell it not to.
1865 glDisable( GL_COLOR_MATERIAL );
1866 if (c)
1867 {
1868 GLenum lmcolorMode;
1869 if (this->ScalarMaterialMode == VTK_MATERIALMODE_DEFAULT)
1870 {
1871 if (prop->GetAmbient() > prop->GetDiffuse())
1872 {
1873 lmcolorMode = GL_AMBIENT;
1874 }
1875 else
1876 {
1877 lmcolorMode = GL_DIFFUSE;
1878 }
1879 }
1880 else if (this->ScalarMaterialMode == VTK_MATERIALMODE_AMBIENT_AND_DIFFUSE)
1881 {
1882 lmcolorMode = GL_AMBIENT_AND_DIFFUSE;
1883 }
1884 else if (this->ScalarMaterialMode == VTK_MATERIALMODE_AMBIENT)
1885 {
1886 lmcolorMode = GL_AMBIENT;
1887 }
1888 else // if (this->ScalarMaterialMode == VTK_MATERIALMODE_DIFFUSE)
1889 {
1890 lmcolorMode = GL_DIFFUSE;
1891 }
1892 glColorMaterial( GL_FRONT_AND_BACK, lmcolorMode);
1893 glEnable( GL_COLOR_MATERIAL );
1894 }
1895
1896 unsigned long idx = 0;
1897 if (n && !cellNormals)
1898 {
1899 idx |= VTK_PDM_NORMALS;
1900 }
1901 if (c)
1902 {
1903 idx |= VTK_PDM_COLORS;
1904 if (c->GetName())
1905 { // In the future, I will look at the number of components.
1906 // All paths will have to handle 3 componet colors.
1907 idx |= VTK_PDM_OPAQUE_COLORS;
1908 }
1909 }
1910 if (cellScalars)
1911 {
1912 idx |= VTK_PDM_CELL_COLORS;
1913 }
1914 if (cellNormals)
1915 {
1916 idx |= VTK_PDM_CELL_NORMALS;
1917 }
1918 if (this->ScalarMode == VTK_SCALAR_MODE_USE_FIELD_DATA)
1919 {
1920 idx |= VTK_PDM_USE_FIELD_DATA;
1921 }
1922
1923 // store the types in the index
1924 if (p->GetDataType() == VTK_FLOAT)
1925 {
1926 idx |= VTK_PDM_POINT_TYPE_FLOAT;
1927 }
1928 else if (p->GetDataType() == VTK_DOUBLE)
1929 {
1930 idx |= VTK_PDM_POINT_TYPE_DOUBLE;
1931 }
1932 if (n)
1933 {
1934 if (n->GetDataType() == VTK_FLOAT)
1935 {
1936 idx |= VTK_PDM_NORMAL_TYPE_FLOAT;
1937 }
1938 else if (n->GetDataType() == VTK_DOUBLE)
1939 {
1940 idx |= VTK_PDM_NORMAL_TYPE_DOUBLE;
1941 }
1942 }
1943
1944 // Texture and color by texture
1945 t = input->GetPointData()->GetTCoords();
1946 if ( t )
1947 {
1948 tDim = t->GetNumberOfComponents();
1949 if (tDim > 2)
1950 {
1951 vtkDebugMacro(<< "Currently only 1d and 2d textures are supported.\n");
1952 t = NULL;
1953 }
1954 }
1955 // Set the texture if we are going to use texture
1956 // for coloring with a point attribute.
1957 // fixme ... make the existence of the coordinate array the signal.
1958 if (this->InterpolateScalarsBeforeMapping && this->ColorCoordinates &&
1959 ! (idx & VTK_PDM_CELL_COLORS))
1960 {
1961 t = this->ColorCoordinates;
1962 }
1963 // Set the flags
1964 if (t)
1965 {
1966 idx |= VTK_PDM_TCOORDS;
1967 if (t->GetDataType() == VTK_FLOAT)
1968 {
1969 idx |= VTK_PDM_TCOORD_TYPE_FLOAT;
1970 }
1971 else if (t->GetDataType() == VTK_DOUBLE)
1972 {
1973 idx |= VTK_PDM_TCOORD_TYPE_DOUBLE;
1974 }
1975 if (t->GetNumberOfComponents() == 1)
1976 {
1977 idx |= VTK_PDM_TCOORD_1D;
1978 }
1979 // Not 1D assumes 2D texture coordinates.
1980 }
1981
1982 if ( this->GetResolveCoincidentTopology() )
1983 {
1984 resolve = 1;
1985 if ( this->GetResolveCoincidentTopology() == VTK_RESOLVE_SHIFT_ZBUFFER )
1986 {
1987 zResolve = 1;
1988 zRes = this->GetResolveCoincidentTopologyZShift();
1989 }
1990 else
1991 {
1992 #ifdef GL_VERSION_1_1
1993 double f, u;
1994 glEnable(GL_POLYGON_OFFSET_FILL);
1995 this->GetResolveCoincidentTopologyPolygonOffsetParameters(f,u);
1996 glPolygonOffset(f,u);
1997 #endif
1998 }
1999 }
2000
2001 // we need to know the total number of cells so that we can report progress
2002 this->TotalCells =
2003 input->GetVerts()->GetNumberOfCells() +
2004 input->GetLines()->GetNumberOfCells() +
2005 input->GetPolys()->GetNumberOfCells() +
2006 input->GetStrips()->GetNumberOfCells();
2007
2008 // For verts or lines that have no normals, disable shading.
2009 // This will fall back on the color set in the glColor4fv()
2010 // call in vtkOpenGLProperty::Render() - the color returned
2011 // by vtkProperty::GetColor() with alpha set to 1.0.
2012 if (!n)
2013 {
2014 glDisable( GL_LIGHTING);
2015 }
2016
2017 this->DrawPoints(idx,p,n,c,t,cellNum,noAbort,input->GetVerts(), ren);
2018
2019 // do lines
2020 if ( zResolve )
2021 {
2022 glDepthRange(zRes, 1.);
2023 }
2024 if (rep == VTK_POINTS)
2025 {
2026 this->DrawPoints(idx,p,n,c,t,cellNum, noAbort,input->GetLines(), ren);
2027 }
2028 else
2029 {
2030 this->DrawLines(idx,p,n,c,t,cellNum, noAbort, input->GetLines(), ren);
2031 }
2032
2033 // reset the lighting if we turned it off
2034 if (!n)
2035 {
2036 glEnable( GL_LIGHTING);
2037 }
2038
2039 // disable shading if we are rendering points, but have no normals
2040 if (!n && rep == VTK_POINTS)
2041 {
2042 glDisable( GL_LIGHTING);
2043 }
2044
2045 // do polys
2046 if (rep == VTK_POINTS && !prop->GetBackfaceCulling() && !prop->GetFrontfaceCulling() )
2047 {
2048 this->DrawPoints(idx,p,n,c,t,cellNum, noAbort, input->GetPolys(), ren);
2049 }
2050 else if (rep == VTK_WIREFRAME && !prop->GetBackfaceCulling() && !prop->GetFrontfaceCulling())
2051 {
2052 this->DrawPolygons(idx,p,n,c,t,cellNum, noAbort,
2053 GL_LINE_LOOP, input->GetPolys(), ren);
2054 }
2055 else
2056 {
2057 this->DrawPolygons(idx,p,n,c,t,cellNum, noAbort,
2058 GL_POLYGON, input->GetPolys(), ren);
2059 }
2060
2061 // do tstrips
2062 if ( zResolve )
2063 {
2064 glDepthRange(2*zRes, 1.);
2065 }
2066 if (rep == VTK_POINTS && !prop->GetBackfaceCulling() && !prop->GetFrontfaceCulling() )
2067 {
2068 this->DrawPoints(idx,p,n,c,t,cellNum, noAbort, input->GetStrips(), ren);
2069 }
2070 else if (rep == VTK_WIREFRAME && !prop->GetBackfaceCulling() && !prop->GetFrontfaceCulling())
2071 {
2072 vtkIdType oldCellNum = cellNum;
2073 this->DrawTStrips(idx,p,n,c,t,cellNum, noAbort,
2074 GL_LINE_STRIP, input->GetStrips(), ren);
2075 vtkOpenGLPolyDataMapperDrawTStripLines(idx,p,n,c,t,oldCellNum, noAbort,
2076 GL_LINE_STRIP, input->GetStrips(),
2077 ren);
2078 }
2079 else
2080 {
2081 this->DrawTStrips(idx,p,n,c,t,cellNum, noAbort,
2082 GL_TRIANGLE_STRIP, input->GetStrips(), ren);
2083 }
2084
2085 // enable lighting again if necessary
2086 if (!n && rep == VTK_POINTS)
2087 {
2088 glEnable( GL_LIGHTING);
2089 }
2090
2091 if (resolve)
2092 {
2093 if ( zResolve )
2094 {
2095 glDepthRange(0., 1.);
2096 }
2097 else
2098 {
2099 #ifdef GL_VERSION_1_1
2100 glDisable(GL_POLYGON_OFFSET_FILL);
2101 #endif
2102 }
2103 }
2104
2105 vtkOpenGLCheckErrorMacro("failed after Draw");
2106 this->UpdateProgress(1.0);
2107 return noAbort;
2108 }
2109
PrintSelf(ostream & os,vtkIndent indent)2110 void vtkOpenGLPolyDataMapper::PrintSelf(ostream& os, vtkIndent indent)
2111 {
2112 this->Superclass::PrintSelf(os,indent);
2113 }
2114
2115 #endif // VTK_LEGACY_REMOVE
2116