1 /***********************************************************************
5 File OpenGl_indexpolygons :
11 Le culling et le backfacing ne marchent pas.
14 HISTORIQUE DES MODIFICATIONS :
15 --------------------------------
16 xx-xx-xx : xxx ; Creation.
17 11-03-96 : FMN ; Correction warning compilation
18 01-04-96 : CAL ; Integration MINSK portage WNT
19 09-08-96 : FMN ; Suppression appel glMatrixMode() avant glGetFloatv()
20 21-10-96 : FMN ; Suppression LMC_COLOR fait dans OpenGl_execstruct.c
21 30-06-97 : FMN ; Suppression OpenGl_telem_light.h
22 18-07-97 : FMN ; Ajout desactivation des lights suivant front_lighting_model
23 21-07-97 : FMN ; Amelioration des performances OPTIMISATION_FMN
24 - suppression calcul inutile sur les front faces
25 - utilisation de GL_TRIANGLES et GL_QUADS
26 27-08-97 : FMN ; Correction affichage des edges
27 On n'affiche que les edges dans le mode IS_EMPTY
28 27-08-97 : FMN ; Correction affichage des edges visibility [PRO9859]
29 10-09-97 : FMN ; Amelioration des perfs liees aux lights.
30 15-09-97 : PCT ; Ajout coordonnees textures
31 24-09-97 : FMN ; Suppression OPTIMISATION_FMN.
32 08-12-97 : FMN ; Suppression appel TsmGetAttri inutile.
33 31-12-97 : FMN ; Simplification pour le highlight
34 15-01-98 : FMN ; Ajout Hidden line
35 08-03-01 : GG ; BUC60823 Avoid crash in the normal computation method
38 ************************************************************************/
42 #define G003 /* EUG 07-10-99 Degeneration mode support
45 #define G004 /* VKH 25-01-00 View dump management
46 Disable animation during dump
49 #define BUC60876 /* GG 5/4/2001 Disable local display list
50 // when animation is not required
53 #define OCC749 /* SAV 19/09/02 added processing of colored vertices */
54 #define OCC7824 /* ASL 26/01/05 transparency of polygon with colors assigned to vertices */
56 /*----------------------------------------------------------------------*/
61 #include <OpenGl_tgl_all.hxx>
69 #include <OpenGl_cmn_varargs.hxx>
70 //#include <OpenGl_cmn_memory.hxx>
71 #include <OpenGl_telem_attri.hxx>
72 #include <OpenGl_tsm.hxx>
73 #include <OpenGl_telem.hxx>
74 #include <OpenGl_telem_util.hxx>
75 #include <OpenGl_telem_highlight.hxx>
76 #include <OpenGl_telem_inquire.hxx>
77 #include <OpenGl_telem_view.hxx>
78 #include <OpenGl_tgl_funcs.hxx>
79 #include <OpenGl_LightBox.hxx>
80 #include <OpenGl_TextureBox.hxx>
84 # define DEF_DS_INTERNAL
85 # include <OpenGl_degeneration.hxx>
87 extern GLboolean g_fBitmap;
91 static long s_Rand = 1L;
92 # define OPENGL_RAND() ( ( unsigned )( s_Rand = s_Rand * 214013L + 2531011L ))
94 /*----------------------------------------------------------------------*/
99 /*----------------------------------------------------------------------*/
104 static TStatus PolygonIndicesDisplay( TSM_ELEM_DATA, Tint, cmn_key* );
105 static TStatus PolygonIndicesAdd( TSM_ELEM_DATA, Tint, cmn_key* );
106 static TStatus PolygonIndicesDelete( TSM_ELEM_DATA, Tint, cmn_key* );
107 static TStatus PolygonIndicesPrint( TSM_ELEM_DATA, Tint, cmn_key* );
108 static TStatus PolygonIndicesInquire( TSM_ELEM_DATA, Tint, cmn_key* );
110 /*static GLboolean lighting_mode;*/
112 struct TEL_INDEXPOLY_DATA
114 Tint num_vertices; /* Number of vertices */
115 Tint num_bounds; /* Number of bounds */
116 Tint facet_flag; /* TEL_FA_NONE or TEL_FA_NORMAL */
117 Tint vertex_flag; /* TEL_VT_NONE or TEL_VT_NORMAL */
118 Tint shape_flag; /* TEL_SHAPE_UNKNOWN or TEL_SHAPE_COMPLEX or
119 TEL_SHAPE_CONVEX or TEL_SHAPE_CONCAVE */
120 Tint *edge_vis; /* Edge visibility indicators for each edge */
121 Tint *bounds; /* Bounds array */
122 Tint *indices; /* Connectivity array */
123 tel_point fnormals; /* Facet normals */
124 tel_colour fcolours; /* Facet colour values */
125 tel_point vertices; /* Vertices */
126 tel_colour vcolours; /* Vertex colour values */
127 tel_point vnormals; /* Vertex normals */
128 tel_texture_coord vtexturecoord; /* Texture Coordinates */
129 Tint edge_count; /* Internal field */
133 IMPLEMENT_MEMORY_OPERATORS
135 typedef TEL_INDEXPOLY_DATA* tel_indexpoly_data;
137 static TEL_INDEXPOLY_DATA indexpoly_defaults =
139 0, /* num_vertices */
141 TEL_FA_NONE, /* facet_flag */
142 TEL_VT_NONE, /* vertex_flag */
143 TEL_SHAPE_UNKNOWN, /* shape_flag */
152 0, /* vtexturecoord */
155 , { 0, 0, 0, -1, 0.0F, NULL }
159 static void draw_indexpoly(
161 Tint, /* highlight_flag */
162 Tint, /* front_lighting_model, */
163 Tint, /* interior_style, */
164 tel_colour /* edge_colour, */
171 static void draw_edges ( tel_indexpoly_data, tel_colour, Tint, Tint );
172 static void draw_degenerates_as_points ( tel_indexpoly_data );
173 static void draw_degenerates_as_bboxs ( tel_indexpoly_data );
174 void set_drawable_items ( GLboolean*, int );
176 static void draw_edges( tel_indexpoly_data,tel_colour, Tint);
179 static TStatus (*MtdTbl[])( TSM_ELEM_DATA, Tint, cmn_key* ) =
181 PolygonIndicesDisplay, /* PickTraverse */
182 PolygonIndicesDisplay,
184 PolygonIndicesDelete,
186 PolygonIndicesInquire
189 /*----------------------------------------------------------------------*/
194 extern Tint ForbidSetTextureMapping; /* currently defined in tsm/tsm.c */
195 extern int g_nDegenerateModel;
198 extern float g_fSkipRatio;
199 extern GLboolean g_fAnimation;
202 /*----------------------------------------------------------------------*/
205 TelPolygonIndicesInitClass( TelType* el )
207 *el = TelPolygonIndices;
211 /*----------------------------------------------------------------------*/
214 PolygonIndicesAdd( TSM_ELEM_DATA d, Tint n, cmn_key *k )
216 Tint i, j, a, b, edge_count=0;
217 tel_indexpoly_data data;
219 for( i = 0; i < n; i++ )
221 if( k[i]->id == NUM_VERTICES_ID )
227 if( !(k[i]->data.ldata) )
230 for( j = 0; j < n; j++ )
232 if( k[j]->id == VERTICES_ID )
238 for( a = 0; a < n; a++ )
240 if( k[a]->id == NUM_FACETS_ID )
246 //cmn_memreserve( data, 1, 1 );
247 data = new TEL_INDEXPOLY_DATA();
252 //cmn_memcpy<TEL_INDEXPOLY_DATA>( data, &indexpoly_defaults, 1 );
253 memcpy( data, &indexpoly_defaults, sizeof(TEL_INDEXPOLY_DATA) );
255 data->num_vertices = k[i]->data.ldata;
256 //cmn_memreserve( data->vertices, data->num_vertices, 0 );
257 data->vertices = new TEL_POINT[data->num_vertices];
258 //cmn_memcpy<TEL_POINT>( data->vertices, k[j]->data.pdata, data->num_vertices );
259 memcpy( data->vertices, k[j]->data.pdata, data->num_vertices*sizeof(TEL_POINT) );
260 data->num_bounds = k[a]->data.ldata;
262 for( b = 0; b < n; b++ )
264 if( k[b]->id == BOUNDS_DATA_ID )
269 //cmn_freemem( data->vertices );
270 delete[] data->vertices;
273 //cmn_memreserve( data->bounds, data->num_bounds, 0 );
274 data->bounds = new Tint[data->num_bounds];
275 //cmn_memcpy<Tint>( data->bounds, k[b]->data.pdata, data->num_bounds );
276 memcpy( data->bounds, k[b]->data.pdata, data->num_bounds*sizeof(Tint) );
278 for( b = 0; b < data->num_bounds; b++ )
279 edge_count += data->bounds[b];
281 data->edge_count = edge_count;
283 for( i = 0; i < n; i++ )
288 data->edge_vis = new Tint[edge_count];
289 memcpy( data->edge_vis, k[i]->data.pdata, edge_count*sizeof(Tint) );
292 case CONNECTIVITY_ID:
293 data->indices = new Tint[edge_count];
294 memcpy( data->indices, k[i]->data.pdata, edge_count*sizeof(Tint) );
298 data->facet_flag = TEL_FA_NORMAL;
299 data->fnormals = new TEL_POINT[data->num_bounds];
300 memcpy( data->fnormals, k[i]->data.pdata, data->num_bounds*sizeof(TEL_POINT) );
301 for( a = 0; a < data->num_bounds; a++ )
302 vecnrm( data->fnormals[a].xyz );
305 case FACET_COLOUR_VALS_ID:
306 data->fcolours = new TEL_COLOUR[data->num_bounds];
307 memcpy( data->fcolours, k[i]->data.pdata, data->num_bounds*sizeof(TEL_COLOUR) );
310 case VERTEX_COLOUR_VALS_ID:
311 data->vcolours = new TEL_COLOUR[data->num_vertices];
312 memcpy( data->vcolours, k[i]->data.pdata, data->num_vertices*sizeof(TEL_COLOUR) );
316 data->vertex_flag = TEL_VT_NORMAL;
317 data->vnormals = new TEL_POINT[data->num_vertices];
318 memcpy( data->vnormals, k[i]->data.pdata, data->num_vertices*sizeof(TEL_POINT) );
319 for( j = 0; j < data->num_vertices; j++ )
320 vecnrm( data->vnormals[j].xyz );
324 data->shape_flag = k[i]->data.ldata;
327 case VTEXTURECOORD_ID:
328 data->vtexturecoord = new TEL_TEXTURE_COORD[data->num_vertices];
329 memcpy( data->vtexturecoord, k[i]->data.pdata, data->num_vertices*sizeof(TEL_TEXTURE_COORD) );
334 if( data->facet_flag != TEL_FA_NORMAL )
336 data->fnormals = new TEL_POINT[data->num_bounds];
337 for( i = 0, a = 0; i < data->num_bounds; i++ ) {
339 TelGetPolygonNormal( data->vertices, &data->indices[a],
340 data->bounds[i], data->fnormals[i].xyz );
342 TelGetNormal( data->vertices[data->indices[a]].xyz,
343 data->vertices[data->indices[a+1]].xyz,
344 data->vertices[data->indices[a+j]].xyz,
345 data->fnormals[i].xyz );
346 vecnrm(data->fnormals[i].xyz);
348 a += data->bounds[i];
352 data->d.bDraw = new unsigned char[data->num_bounds];
354 ((tsm_elem_data)(d.pdata))->pdata = data;
359 /*----------------------------------------------------------------------*/
362 PolygonIndicesDisplay( TSM_ELEM_DATA data, Tint n, cmn_key *k )
364 CMN_KEY k11, k12, k17, k111, k114;
369 Tint front_lighting_model;
371 TEL_COLOUR interior_colour;
372 TEL_COLOUR edge_colour;
377 tel_indexpoly_data d;
379 k12.id = TelInteriorReflectanceEquation;
380 k17.id = TelInteriorStyle;
381 k111.id = TelInteriorColour;
382 k111.data.pdata = &interior_colour;
383 k114.id = TelEdgeColour;
384 k114.data.pdata = &edge_colour;
386 k117.id = TelSurfaceAreaProperties;
387 k117.data.pdata = ∝
391 TsmGetAttri( 5, &k12, &k17, &k111, &k114, &k117);
393 TsmGetAttri( 4, &k12, &k17, &k111, &k114);
396 front_lighting_model = k12.data.ldata;
397 interior_style = k17.data.ldata;
400 printf("PolygonIndicesDisplay \n");
404 * Use highlight colours
407 if( k[0]->id == TOn )
411 k11.id = TelHighlightIndex;
412 TsmGetAttri( 1, &k11 );
413 if( TelGetHighlightRep( TglActiveWs, k11.data.ldata, &hrep ) == TSuccess )
415 if( hrep.type == TelHLForcedColour )
417 edge_colour = interior_colour = hrep.col;
418 front_lighting_model = CALL_PHIGS_REFL_NONE;
420 else if( hrep.type == TelHLColour )
422 edge_colour = hrep.col;
428 TelGetHighlightRep( TglActiveWs, 0, &hrep );
429 if( hrep.type == TelHLForcedColour )
431 edge_colour = interior_colour = hrep.col;
432 front_lighting_model = CALL_PHIGS_REFL_NONE;
434 else if( hrep.type == TelHLColour )
436 edge_colour = hrep.col;
442 d = (tel_indexpoly_data)data.pdata;
444 glColor3fv( interior_colour.rgb );
446 printf("PolygonIndicesDisplay.interior_colour %f,%f,%f \n",
447 interior_colour.rgb[0],interior_colour.rgb[1],interior_colour.rgb[2]);
450 draw_indexpoly( d, k[0]->id,
451 front_lighting_model,
463 /*----------------------------------------------------------------------*/
466 draw_indexpoly( tel_indexpoly_data p, Tint hflag,
467 Tint front_lighting_model,
469 tel_colour edge_colour
475 Tint i, j, k, a, newList = 0;
478 /* Following pointers have been provided for performance improvement */
480 tel_point pfn, pvn, pv;
482 tel_texture_coord pvt;
490 pvt = p->vtexturecoord;
492 if ( g_nDegenerateModel < 2 && interior_style != TSM_EMPTY )
494 if ( interior_style != TSM_EMPTY )
503 if ( interior_style == TSM_HIDDENLINE)
509 if (front_lighting_model == CALL_PHIGS_REFL_NONE)
513 lighting_model = front_lighting_model;
518 goto doDraw; /* Disable object display list out of animation */
522 goto doDraw; /* dipsplay lists are NOT shared between */
523 /* window's context and bitmap's one */
526 if ( p -> d.model != lighting_model || !p -> d.list ||
527 p -> d.model == -1 ||( g_nDegenerateModel && p -> d.skipRatio != g_fSkipRatio )) {
529 p -> d.skipRatio = g_fSkipRatio;
530 p -> d.model = lighting_model;
531 p -> d.degMode = g_nDegenerateModel;
534 if ( g_fSkipRatio == 0.0 ) {
535 if ( !p -> d.list ) p -> d.list = glGenLists ( 1 );
537 glNewList ( p -> d.list, GL_COMPILE_AND_EXECUTE );
542 if ( lighting_model == CALL_PHIGS_REFL_NONE ) {
543 if ( p -> bounds[ 0 ] == 3 )
544 glBegin ( GL_TRIANGLES );
545 else if ( p -> bounds[ 0 ] == 4 )
546 glBegin ( GL_QUADS );
547 else glBegin ( GL_POLYGON );
550 for ( i = 0, j = 0, a = 0; i < p -> num_bounds; ++i ) {
551 a = j + p -> bounds[ i ];
552 for ( ; j < a; ++j ) {
553 glColor3fv ( pvc[ ind[ j ] ].rgb );
554 glVertex3fv ( pv[ ind[ j ] ].xyz );
555 } /* end for ( j . . . ) */
556 } /* end for ( i . . . ) */
558 for ( i = 0, j = 0, a = 0; i < p -> num_bounds; ++i ) {
559 a = j + p -> bounds[ i ];
560 glColor3fv ( pfc[ i ].rgb );
561 for ( ; j < a; ++j ) glVertex3fv ( pv[ ind[ j ] ].xyz );
564 for ( i = 0, j = 0, a = 0; i < p -> num_bounds; ++i ) {
565 a = j + p -> bounds[ i ];
566 for ( ; j < a; ++j ) glVertex3fv ( pv[ ind[ j ] ].xyz );
570 } else { /* lighting_model != TelLModelNone */
571 if ( p -> bounds[ 0 ] == 3 )
572 glBegin ( GL_TRIANGLES );
573 else if ( p -> bounds[ 0 ] == 4 )
574 glBegin ( GL_QUADS );
575 else glBegin ( GL_POLYGON );
578 for ( i = a = 0; i < p -> num_bounds; ++i ) {
579 j = a; a += p -> bounds[ i ];
580 if( pfn ) glNormal3fv ( pfn[ i ].xyz );
581 if( pfc && !prop->isphysic ) {
582 GLfloat diff[4], ambi[4], emsv[4], r, g, b;
585 ambi[3] = diff[3] = emsv[3] = prop->trans;
587 ambi[3] = 1.0f; diff[3] = 1.0f; emsv[3] = 1.0f;
590 r = pfc[ i ].rgb[0]; g = pfc[ i ].rgb[1]; b = pfc[ i ].rgb[2];
593 ambi[0] = prop->amb * r;
594 ambi[1] = prop->amb * g;
595 ambi[2] = prop->amb * b;
596 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambi);
599 diff[0] = prop->diff * r;
600 diff[1] = prop->diff * g;
601 diff[2] = prop->diff * b;
602 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diff);
605 emsv[0] = prop->emsv * r;
606 emsv[1] = prop->emsv * g;
607 emsv[2] = prop->emsv * b;
608 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, emsv);
611 for ( ; j < a; ++j ) {
613 if( pvn ) glNormal3fv ( pvn[ k ].xyz );
614 if( pvc && !prop->isphysic ) {
615 GLfloat diff[4], ambi[4], emsv[4], r, g, b;
618 ambi[3] = diff[3] = emsv[3] = prop->trans;
620 ambi[3] = 1.0f; diff[3] = 1.0f; emsv[3] = 1.0f;
623 r = pvc[ k ].rgb[0]; g = pvc[ k ].rgb[1]; b = pvc[ k ].rgb[2];
626 ambi[0] = prop->amb * r;
627 ambi[1] = prop->amb * g;
628 ambi[2] = prop->amb * b;
629 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambi);
632 diff[0] = prop->diff * r;
633 diff[1] = prop->diff * g;
634 diff[2] = prop->diff * b;
635 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diff);
638 emsv[0] = prop->emsv * r;
639 emsv[1] = prop->emsv * g;
640 emsv[2] = prop->emsv * b;
641 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, emsv);
644 if( pvt && !ForbidSetTextureMapping ) glTexCoord2fv ( pvt[ k ].xy );
645 glVertex3fv ( pv[ k ].xyz );
646 } /* end for ( j . . . ) */
647 } /* end for ( i . . . ) */
651 if ( pvt && !ForbidSetTextureMapping )
652 for ( i = 0, j = 0, a = 0; i < p -> num_bounds; ++i ) {
653 a = j + p -> bounds[ i ];
654 for ( ; j < a; ++j ) {
655 glNormal3fv ( pvn[ ind[ j ] ].xyz );
656 glTexCoord2fv ( pvt[ ind[ j ] ].xy );
657 glVertex3fv ( pv[ ind[ j ] ].xyz );
658 } /* end for ( j . . . ) */
659 } /* end for ( i . . . ) */
661 for ( i = 0, j = 0, a = 0; i < p -> num_bounds; ++i ) {
662 a = j + p -> bounds[ i ];
663 for ( ; j < a; ++j ) {
664 glNormal3fv ( pvn[ ind[ j ] ].xyz );
665 glVertex3fv ( pv[ ind[ j ] ].xyz );
666 } /* end for ( j . . . ) */
667 } /* end for ( i . . . ) */
669 for ( i = 0, j = 0, a = 0; i < p -> num_bounds; ++i ) {
670 a = j + p -> bounds[ i ];
671 glNormal3fv ( pfn[ i ].xyz );
672 for ( ; j < a; ++j ) glVertex3fv ( pv[ ind[ j ] ].xyz );
680 } else if ( g_fSkipRatio != 1.0 ) {
681 if ( !p -> d.dlist ) p -> d.dlist = glGenLists ( 1 );
682 glNewList ( p -> d.dlist, GL_COMPILE_AND_EXECUTE );
684 set_drawable_items ( p -> d.bDraw, p -> num_bounds );
685 if ( lighting_model == CALL_PHIGS_REFL_NONE ) {
686 if ( p -> bounds[ 0 ] == 3 )
687 glBegin ( GL_TRIANGLES );
688 else if ( p -> bounds[ 0 ] == 4 )
689 glBegin ( GL_QUADS );
690 else glBegin ( GL_POLYGON );
693 for ( i = 0, j = 0, a = 0; i < p -> num_bounds; ++i ) {
694 a = j + p -> bounds[ i ];
695 if ( p -> d.bDraw[ i ] )
696 for ( ; j < a; ++j ) {
697 glColor3fv ( pvc[ ind[ j ] ].rgb );
698 glVertex3fv ( pv[ ind[ j ] ].xyz );
699 } /* end for ( j . . . ) */
701 } /* end for ( i . . . ) */
703 for ( i = 0, j = 0, a = 0; i < p -> num_bounds; ++i ) {
704 a = j + p -> bounds[ i ];
705 if ( p -> d.bDraw[ i ] ) {
706 glColor3fv ( pfc[ i ].rgb );
707 for ( ; j < a; ++j ) glVertex3fv ( pv[ ind[ j ] ].xyz );
711 for ( i = 0, j = 0, a = 0; i < p -> num_bounds; ++i ) {
712 a = j + p -> bounds[ i ];
713 if ( p -> d.bDraw[ i ] )
714 for ( ; j < a; ++j ) glVertex3fv ( pv[ ind[ j ] ].xyz );
719 } else { /* lighting_model != TelLModelNone */
720 if ( p -> bounds[ 0 ] == 3 )
721 glBegin ( GL_TRIANGLES );
722 else if ( p -> bounds[ 0 ] == 4 )
723 glBegin ( GL_QUADS );
724 else glBegin ( GL_POLYGON );
727 if ( pvt && !ForbidSetTextureMapping )
728 for ( i = 0, j = 0, a = 0; i < p -> num_bounds; ++i ) {
729 a = j + p->bounds[ i ];
730 if ( p -> d.bDraw[ i ] )
731 for ( ; j < a; ++j ) {
732 glNormal3fv ( pvn[ ind[ j ] ].xyz );
733 glTexCoord2fv ( pvt[ ind[ j ] ].xy );
734 glVertex3fv ( pv[ ind[ j ] ].xyz );
735 } /* end for ( j . . . ) */
737 } /* end for ( i . . . ) */
739 for ( i = 0, j = 0, a = 0; i < p -> num_bounds; ++i ) {
740 a = j + p -> bounds[ i ];
741 if ( p -> d.bDraw[ i ] )
742 for ( ; j < a; ++j ) {
743 glNormal3fv ( pvn[ ind[ j ] ].xyz );
744 glVertex3fv ( pv[ ind[ j ] ].xyz );
745 } /* end for ( j . . . ) */
747 } /* end for ( i . . . ) */
749 for ( i = 0, j = 0, a = 0; i < p -> num_bounds; ++i ) {
750 a = j + p -> bounds[ i ];
751 if ( p -> d.bDraw[ i ] ) {
752 glNormal3fv ( pfn[ i ].xyz );
753 for ( ; j < a; ++j ) glVertex3fv ( pv[ ind[ j ] ].xyz );
760 if ( !p -> d.dlist ) p -> d.dlist = glGenLists ( 1 );
761 glNewList ( p -> d.dlist, GL_COMPILE_AND_EXECUTE );
766 if ( newList ) glEndList ();
767 if ( g_nDegenerateModel ) return;
769 glCallList ( g_fSkipRatio == 0.0 ? p -> d.list : p -> d.dlist );
770 if ( g_nDegenerateModel ) return;
777 switch ( g_nDegenerateModel ) {
782 case 2: /* XXX_TDM_WIREFRAME */
786 case 3: /* XXX_TDM_MARKER */
787 draw_degenerates_as_points ( p );
790 case 4: /* XXX_TDM_BBOX */
791 draw_degenerates_as_bboxs ( p );
796 draw_edges ( p, edge_colour, interior_style, i );
798 draw_edges( p, edge_colour, interior_style );
802 /*----------------------------------------------------------------------*/
805 PolygonIndicesDelete( TSM_ELEM_DATA data, Tint n, cmn_key *k )
807 tel_indexpoly_data p;
809 p = (tel_indexpoly_data)data.pdata;
811 //cmn_freemem( p->edge_vis );
812 delete[] p->edge_vis;
814 //cmn_freemem( p->bounds );
817 //cmn_freemem( p->indices );
820 //cmn_freemem( p->fcolours );
821 delete[] p->fcolours;
823 //cmn_freemem( p->fnormals );
824 delete[] p->fnormals;
826 //cmn_freemem( p->vertices );
827 delete[] p->vertices;
829 //cmn_freemem( p->vcolours );
830 delete[] p->vcolours;
832 //cmn_freemem( p->vnormals );
833 delete[] p->vnormals;
834 if (p->vtexturecoord)
835 //cmn_freemem( p->vtexturecoord );
836 delete[] p->vtexturecoord;
838 if ( GET_GL_CONTEXT() != NULL ) {
840 if ( p -> d.list ) glDeleteLists ( p -> d.list, 1 );
841 if ( p -> d.dlist ) glDeleteLists ( p -> d.dlist, 1 );
846 //cmn_freemem ( p -> d.bDraw );
847 delete[] p -> d.bDraw;
850 //cmn_freemem( data.pdata );
856 /*----------------------------------------------------------------------*/
859 PolygonIndicesPrint( TSM_ELEM_DATA data, Tint n, cmn_key *k )
862 tel_indexpoly_data p;
864 p = (tel_indexpoly_data)data.pdata;
866 fprintf( stdout, "TelPolygonIndices. Number of Vertices: %d\n", p->num_vertices );
867 switch( p->shape_flag )
869 case TEL_SHAPE_UNKNOWN:
870 fprintf( stdout, "\t\tShape Flag : UNKNOWN\n" );
873 case TEL_SHAPE_COMPLEX:
874 fprintf( stdout, "\t\tShape Flag : COMPLEX\n" );
877 case TEL_SHAPE_CONCAVE:
878 fprintf( stdout, "\t\tShape Flag : CONCAVE\n" );
881 case TEL_SHAPE_CONVEX:
882 fprintf( stdout, "\t\tShape Flag : CONVEX\n" );
886 switch( p->facet_flag )
890 fprintf( stdout, "\t\tFacet Flag : COLOUR\n" );
892 fprintf( stdout, "\t\tFacet Flag : NONE\n" );
897 fprintf( stdout, "\t\tFacet Flag : COLOURNORMAL\n" );
899 fprintf( stdout, "\t\tFacet Flag : NORMAL\n" );
902 switch( p->vertex_flag )
906 fprintf( stdout, "\t\tVertex Flag : COLOUR\n" );
908 fprintf( stdout, "\t\tVertex Flag : NONE\n" );
913 fprintf( stdout, "\t\tVertex Flag : COLOURNORMAL\n" );
915 fprintf( stdout, "\t\tVertex Flag : NORMAL\n" );
920 fprintf( stdout, "\t\tEdge Visibility Data :\n" );
921 for( i = 0; i < p->edge_count; i++ )
922 fprintf( stdout, "\t\t%d ", p->edge_vis[i] );
923 fprintf( stdout, "\n" );
927 fprintf( stdout, "\t\tBounds array :\n" );
928 for( i = 0; i < p->num_bounds; i++ )
929 fprintf( stdout, "\t\tb[%d] %d \n", i, p->bounds[i] );
933 fprintf( stdout, "\t\tConnectivity array :\n" );
934 for( i = 0; i < p->edge_count; i++ )
935 fprintf( stdout, "\t\tI[%d] %d \n", i, p->indices[i] );
939 fprintf( stdout, "\n\t\tFacet Normals : " );
940 for( i = 0; i < p->num_bounds; i++ )
941 fprintf( stdout, "\n\t\t v[%d] = %g %g %g", i,
942 p->fnormals[i].xyz[0],
943 p->fnormals[i].xyz[1],
944 p->fnormals[i].xyz[2] );
945 fprintf( stdout, "\n" );
948 fprintf( stdout, "\n\t\tFacet Normals not specified\n" );
952 fprintf( stdout, "\n\t\tFacet Colours : " );
953 for( i = 0; i < p->num_bounds; i++ )
954 fprintf( stdout, "\n\t\t v[%d] = %g %g %g", i,
955 p->fcolours[i].rgb[0],
956 p->fcolours[i].rgb[1],
957 p->fcolours[i].rgb[2] ); }
959 fprintf( stdout, "\n\t\tFacet Colours not specified\n" );
963 fprintf( stdout, "\n\t\tVertices : " );
964 for( i = 0; i < p->num_vertices; i++ )
965 fprintf( stdout, "\n\t\t v[%d] = %g %g %g", i,
966 p->vertices[i].xyz[0],
967 p->vertices[i].xyz[1],
968 p->vertices[i].xyz[2] );
971 fprintf( stdout, "\n" );
974 fprintf( stdout, "\n\t\tVertex Colours : " );
975 for( i = 0; i < p->num_vertices; i++ )
976 fprintf( stdout, "\n\t\t v[%d] = %g %g %g", i,
977 p->vcolours[i].rgb[0],
978 p->vcolours[i].rgb[1],
979 p->vcolours[i].rgb[2] );
982 fprintf( stdout, "\n\t\tVertex Colours not specified\n" );
986 fprintf( stdout, "\n\t\tVertex Normals : " );
987 for( i = 0; i < p->num_vertices; i++ )
988 fprintf( stdout, "\n\t\t v[%d] = %g %g %g", i,
989 p->vnormals[i].xyz[0],
990 p->vnormals[i].xyz[1],
991 p->vnormals[i].xyz[2] );
994 fprintf( stdout, "\n\t\tVertex Normals not specified\n" );
996 if (p->vtexturecoord)
998 fprintf(stdout, "\n\t\tTexture Coordinates : ");
999 for (i=0; i<p->num_vertices; i++)
1000 fprintf(stdout, "\n\t\t v[%d] = %g %g", i,
1001 p->vtexturecoord[i].xy[0],
1002 p->vtexturecoord[i].xy[1]);
1005 fprintf( stdout, "\n\t\tTexture Coordinates not specified\n");
1007 fprintf( stdout, "\n" );
1012 /*----------------------------------------------------------------------*/
1015 PolygonIndicesInquire( TSM_ELEM_DATA data, Tint n, cmn_key *k )
1018 tel_indexpoly_data d;
1020 TStatus status = TSuccess;
1023 d = (tel_indexpoly_data)data.pdata;
1026 size_reqd += ( d->edge_count * sizeof( Tint ) );
1028 size_reqd += ( d->num_bounds * sizeof( Tint ) ); /* bounds */
1029 size_reqd += ( d->edge_count * sizeof( Tint ) ); /* connectivity */
1032 size_reqd += ( d->num_bounds * sizeof( TEL_COLOUR ) );
1034 if( d->facet_flag == TEL_FA_NORMAL )
1035 size_reqd += ( d->num_bounds * sizeof( TEL_POINT ) );
1037 size_reqd += ( d->num_vertices * sizeof( TEL_POINT ) );
1040 size_reqd += ( d->num_vertices * sizeof( TEL_COLOUR ) );
1042 if( d->vertex_flag == TEL_VT_NORMAL )
1043 size_reqd += ( d->num_vertices * sizeof( TEL_POINT ) );
1045 for( i = 0; i < n; i++ )
1049 case INQ_GET_SIZE_ID:
1051 k[i]->data.ldata = size_reqd;
1055 case INQ_GET_CONTENT_ID:
1060 c = (tel_inq_content)k[i]->data.pdata;
1061 c->act_size = size_reqd;
1065 w->indexedpolygons3data.shpflag = d->shape_flag;
1066 w->indexedpolygons3data.num_bounds = d->num_bounds;
1067 w->indexedpolygons3data.num_vertices = d->num_vertices;
1069 w->indexedpolygons3data.edgflag = TOn;
1071 w->indexedpolygons3data.edgflag = TOff;
1073 if( c->size >= size_reqd )
1075 if( d->facet_flag == TEL_FA_NORMAL )
1079 w->indexedpolygons3data.fctflag = TEL_FAFLAG_COLOURNORMAL;
1080 w->indexedpolygons3data.gnormals = (tel_point)(c->buf);
1081 for( j = 0; j < d->num_bounds; j++ )
1083 w->indexedpolygons3data.gnormals[j] = d->fnormals[j];
1085 cur_ptr += ( d->num_bounds * sizeof( TEL_POINT ) );
1087 w->indexedpolygons3data.facet_colour_vals =
1088 (tel_colour)(cur_ptr);
1089 for( j = 0; j < d->num_bounds; j++ )
1091 w->indexedpolygons3data.facet_colour_vals[j] =
1094 cur_ptr += ( d->num_bounds * sizeof( TEL_COLOUR ) );
1098 w->indexedpolygons3data.fctflag = TEL_FAFLAG_NORMAL;
1099 w->indexedpolygons3data.facet_colour_vals = 0;
1100 w->indexedpolygons3data.gnormals = (tel_point)(c->buf);
1101 for( j = 0; j < d->num_bounds; j++ )
1103 w->indexedpolygons3data.gnormals[j] = d->fnormals[j];
1105 cur_ptr += ( d->num_bounds * sizeof( TEL_POINT ) );
1110 w->indexedpolygons3data.gnormals = 0;
1113 w->indexedpolygons3data.fctflag = TEL_FAFLAG_COLOUR;
1114 w->indexedpolygons3data.facet_colour_vals =
1115 (tel_colour)(c->buf );
1116 for( j = 0; j < d->num_bounds; j++ )
1118 w->indexedpolygons3data.facet_colour_vals[j] =
1121 cur_ptr += ( d->num_bounds * sizeof( TEL_COLOUR ) );
1125 w->indexedpolygons3data.fctflag = TEL_FAFLAG_NONE;
1126 w->indexedpolygons3data.facet_colour_vals = 0;
1132 w->indexedpolygons3data.edgvis = (Tint *)(cur_ptr);
1133 // cmn_memcpy<Tint>( w->indexedpolygons3data.edgvis,
1136 memcpy( w->indexedpolygons3data.edgvis, d->edge_vis, d->edge_count*sizeof(Tint) );
1137 cur_ptr += (d->edge_count * sizeof( Tint ) );
1140 w->indexedpolygons3data.points = (tel_point)cur_ptr;
1141 for( j = 0; j < d->num_vertices; j++ )
1143 w->indexedpolygons3data.points[j] = d->vertices[j];
1145 cur_ptr += ( d->num_vertices * sizeof( TEL_POINT ) );
1147 w->indexedpolygons3data.bounds = (Tint *)cur_ptr;
1148 // cmn_memcpy<Tint>( w->indexedpolygons3data.bounds,
1151 memcpy( w->indexedpolygons3data.bounds, d->bounds, d->num_bounds*sizeof(Tint) );
1152 cur_ptr += ( d->num_bounds * sizeof( Tint ) );
1154 w->indexedpolygons3data.indices = (Tint *)cur_ptr;
1155 // cmn_memcpy<Tint>( w->indexedpolygons3data.indices,
1158 memcpy( w->indexedpolygons3data.indices, d->indices, d->edge_count*sizeof(Tint) );
1159 cur_ptr += ( d->edge_count * sizeof( Tint ) );
1161 if( d->vertex_flag == TEL_VT_NORMAL )
1165 w->indexedpolygons3data.vrtflag = TEL_VTFLAG_COLOURNORMAL;
1166 w->indexedpolygons3data.vnormals = (tel_point)(cur_ptr);
1167 for( j = 0; j < d->num_vertices; j++ )
1169 w->indexedpolygons3data.vnormals[j] = d->vnormals[i];
1171 cur_ptr += ( d->num_vertices * sizeof( TEL_POINT ) );
1173 w->indexedpolygons3data.colours = (tel_colour)(cur_ptr);
1175 for( j = 0; j < d->num_vertices; j++ )
1177 w->indexedpolygons3data.colours[j] = d->vcolours[i];
1182 w->indexedpolygons3data.vrtflag = TEL_VTFLAG_NORMAL;
1183 w->indexedpolygons3data.colours = 0;
1184 w->indexedpolygons3data.vnormals = (tel_point)(cur_ptr);
1186 for( j = 0; j < d->num_vertices; j++ )
1188 w->indexedpolygons3data.vnormals[j] = d->vnormals[i];
1194 w->indexedpolygons3data.vnormals = 0;
1197 w->indexedpolygons3data.vrtflag = TEL_VTFLAG_COLOUR;
1198 w->indexedpolygons3data.colours = (tel_colour)(cur_ptr);
1199 for( j = 0; j < d->num_vertices; j++ )
1201 w->indexedpolygons3data.colours[j] = d->vcolours[i];
1206 w->indexedpolygons3data.vrtflag = TEL_VTFLAG_NONE;
1207 w->indexedpolygons3data.colours = 0;
1222 /*----------------------------------------------------------------------*/
1226 draw_edges ( tel_indexpoly_data p, tel_colour edge_colour,
1227 Tint interior_style, Tint forceDraw )
1229 draw_edges( tel_indexpoly_data p, tel_colour edge_colour, Tint interior_style )
1232 CMN_KEY k, k1, k2, k3, k4;
1234 Tint i, j, a, newList = 0;
1235 Tint edge_type, line_type_preserve;
1236 Tfloat edge_width, line_width_preserve;
1237 GLboolean texture_on;
1242 if ( interior_style != TSM_HIDDENLINE && !forceDraw )
1244 if (interior_style != TSM_HIDDENLINE)
1248 TsmGetAttri( 1, &k );
1249 if( k.data.ldata == TOff )return;
1257 texture_on = IsTextureEnabled();
1258 if (texture_on) DisableTexture();
1260 k1.id = TelPolylineWidth;
1261 k2.id = TelPolylineType;
1262 k3.id = TelEdgeType;
1263 k4.id = TelEdgeWidth;
1265 TsmGetAttri( 4, &k1, &k2, &k3, &k4 );
1267 line_width_preserve = k1.data.fdata;
1268 line_type_preserve = k2.data.ldata;
1269 edge_type = k3.data.ldata;
1270 edge_width = k4.data.fdata;
1272 if( line_width_preserve != edge_width )
1274 k.id = TelPolylineWidth;
1275 k.data.fdata = edge_width;
1276 TsmSetAttri( 1, &k );
1278 if( line_type_preserve != edge_type )
1280 k.id = TelPolylineType;
1281 k.data.ldata = edge_type;
1282 TsmSetAttri( 1, &k );
1288 glColor3fv ( edge_colour -> rgb );
1289 glPushAttrib ( GL_POLYGON_BIT );
1290 glPolygonMode ( GL_FRONT_AND_BACK, GL_LINE );
1292 for ( i = 0, j = 0, a = 0; i < p -> num_bounds; ++i ) {
1294 a = j + p -> bounds[ i ];
1296 glBegin ( GL_POLYGON );
1298 for ( ; j < a; ++j ) {
1300 glEdgeFlag ( ( GLboolean )( vis[ j ] == 1 ? GL_TRUE : GL_FALSE ) );
1301 glVertex3fv ( pv[ ind[ j ] ].xyz );
1307 glEdgeFlag ( GL_TRUE );
1316 if ( !g_fAnimation )
1317 goto doDraw; /* Disable object display list out of animation */
1324 if ( p -> d.degMode != 2 || p -> d.skipRatio != g_fSkipRatio || !p -> d.dlist ) {
1326 if ( !p -> d.dlist ) p -> d.dlist = glGenLists ( 1 );
1329 p -> d.skipRatio = g_fSkipRatio;
1330 glNewList ( p -> d.dlist, GL_COMPILE_AND_EXECUTE );
1334 glPushAttrib ( GL_POLYGON_BIT | GL_DEPTH_BUFFER_BIT );
1336 glEdgeFlag ( GL_TRUE );
1337 glDisable ( GL_DEPTH_TEST );
1338 glPolygonMode ( GL_FRONT_AND_BACK, GL_LINE );
1340 if ( g_fSkipRatio == 0.0F )
1342 for ( i = 0, j = 0, a = 0; i < p -> num_bounds; ++i ) {
1344 a = j + p -> bounds[ i ];
1346 glBegin ( GL_POLYGON );
1348 for ( ; j < a; ++j ) glVertex3fv ( pv[ ind[ j ] ].xyz );
1354 else if ( g_fSkipRatio != 1.0F ) {
1356 set_drawable_items ( p -> d.bDraw, p -> num_bounds );
1358 for ( i = 0, j = 0, a = 0; i < p -> num_bounds; ++i ) {
1360 a = j + p -> bounds[ i ];
1362 if ( p -> d.bDraw[ i ] ) {
1364 glBegin ( GL_POLYGON );
1366 for ( ; j < a; ++j ) glVertex3fv ( pv[ ind[ j ] ].xyz );
1377 if ( newList ) glEndList ();
1379 } else glCallList ( p -> d.dlist );
1383 glColor3fv( edge_colour->rgb );
1384 glPushAttrib(GL_POLYGON_BIT);
1385 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
1386 for( i = 0, j = 0, a = 0; i < p->num_bounds; i++ )
1388 a = j + p->bounds[i];
1389 glBegin(GL_POLYGON);
1392 if( vis[j] == 1) glEdgeFlag( GL_TRUE );
1393 else glEdgeFlag( GL_FALSE );
1394 glVertex3fv( pv[ ind[j] ].xyz );
1397 glEdgeFlag(GL_TRUE);
1403 if( line_width_preserve != edge_width )
1405 k.id = TelPolylineWidth;
1406 k.data.fdata = line_width_preserve;
1407 TsmSetAttri( 1, &k );
1409 if( line_type_preserve != edge_type )
1411 k.id = TelPolylineType;
1412 k.data.ldata = line_type_preserve;
1413 TsmSetAttri( 1, &k );
1415 if (texture_on) EnableTexture();
1417 /*----------------------------------------------------------------------*/
1419 static void draw_degenerates_as_points ( tel_indexpoly_data p ) {
1422 Tint i, j, n, a, newList = 0;
1428 vis = p -> edge_vis;
1433 if ( g_fBitmap ) goto doDraw;
1436 if ( p -> d.degMode != 3 || p -> d.skipRatio != g_fSkipRatio || !p -> d.dlist ) {
1438 if ( !p -> d.dlist ) p -> d.dlist = glGenLists ( 1 );
1441 p -> d.skipRatio = g_fSkipRatio;
1442 glNewList ( p -> d.dlist, GL_COMPILE_AND_EXECUTE );
1445 if ( g_fSkipRatio == 0.0F ) {
1447 glBegin ( GL_POINTS );
1449 for ( i = 0, j = 0, a = 0; i < p -> num_bounds; ++i ) {
1451 n = p -> bounds[ i ];
1454 for ( pt [ 0 ] = pt[ 1 ] = pt[ 2 ] = 0.; j < a; ++j ) {
1456 pt[ 0 ] += pv[ ind[ j ] ].xyz[ 0 ];
1457 pt[ 1 ] += pv[ ind[ j ] ].xyz[ 1 ];
1458 pt[ 2 ] += pv[ ind[ j ] ].xyz[ 2 ];
1460 } /* end for ( j ) */
1468 } /* end for ( i ) */
1472 } else if ( g_fSkipRatio != 1.0 ) {
1474 set_drawable_items ( p -> d.bDraw, p -> num_bounds );
1476 glBegin ( GL_POINTS );
1478 for ( i = 0, j = 0, a = 0; i < p -> num_bounds; ++i ) {
1480 n = p -> bounds[ i ];
1483 if ( p -> d.bDraw[ i ] ) {
1485 for ( pt [ 0 ] = pt[ 1 ] = pt[ 2 ] = 0.; j < a; ++j ) {
1487 pt[ 0 ] += pv[ ind[ j ] ].xyz[ 0 ];
1488 pt[ 1 ] += pv[ ind[ j ] ].xyz[ 1 ];
1489 pt[ 2 ] += pv[ ind[ j ] ].xyz[ 2 ];
1491 } /* end for ( j ) */
1501 } /* end for ( i ) */
1512 } else glCallList ( p -> d.dlist );
1514 } /* end draw_degenerates_as_points */
1516 static void draw_degenerates_as_bboxs ( tel_indexpoly_data p ) {
1519 Tint i, j, n, a, newList = 0;
1520 GLfloat minp[ 3 ] = { FLT_MAX, FLT_MAX, FLT_MAX };
1521 GLfloat maxp[ 3 ] = { FLT_MIN, FLT_MIN, FLT_MIN };
1526 vis = p -> edge_vis;
1531 if ( g_fBitmap ) goto doDraw;
1534 if ( p -> d.degMode != 4 || !p -> d.dlist ) {
1536 if ( !p -> d.dlist ) p -> d.dlist = glGenLists ( 1 );
1540 glNewList ( p -> d.dlist, GL_COMPILE_AND_EXECUTE );
1543 for ( i = 0, j = 0, a = 0; i < p -> num_bounds; ++i ) {
1545 n = p -> bounds[ i ];
1548 for ( ; j < a; ++j ) {
1550 if ( pv[ ind[ j ] ].xyz[ 0 ] < minp[ 0 ] )
1551 minp[ 0 ] = pv[ ind[ j ] ].xyz[ 0 ] ;
1552 if ( pv[ ind[ j ] ].xyz[ 1 ] < minp[ 1 ] )
1553 minp[ 1 ] = pv[ ind[ j ] ].xyz[ 1 ] ;
1554 if ( pv[ ind[ j ] ].xyz[ 2 ] < minp[ 2 ] )
1555 minp[ 2 ] = pv[ ind[ j ] ].xyz[ 2 ] ;
1557 if ( pv[ ind[ j ] ].xyz[ 0 ] > maxp[ 0 ] )
1558 maxp[ 0 ] = pv[ ind[ j ] ].xyz[ 0 ] ;
1559 if ( pv[ ind[ j ] ].xyz[ 1 ] > maxp[ 1 ] )
1560 maxp[ 1 ] = pv[ ind[ j ] ].xyz[ 1 ] ;
1561 if ( pv[ ind[ j ] ].xyz[ 2 ] > maxp[ 2 ] )
1562 maxp[ 2 ] = pv[ ind[ j ] ].xyz[ 2 ] ;
1564 } /* end for ( j ) */
1566 } /* end for ( i ) */
1568 /* OCC11904 -- Temporarily disable environment mapping */
1569 glPushAttrib(GL_ENABLE_BIT);
1570 glDisable(GL_TEXTURE_1D);
1571 glDisable(GL_TEXTURE_2D);
1573 glBegin ( GL_LINE_STRIP );
1575 glVertex3fv ( minp );
1576 glVertex3f ( minp[ 0 ], maxp[ 1 ], minp[ 2 ] );
1577 glVertex3f ( minp[ 0 ], maxp[ 1 ], maxp[ 2 ] );
1578 glVertex3f ( minp[ 0 ], minp[ 1 ], maxp[ 2 ] );
1579 glVertex3f ( minp[ 0 ], minp[ 1 ], minp[ 2 ] );
1581 glVertex3f ( maxp[ 0 ], minp[ 1 ], minp[ 2 ] );
1582 glVertex3f ( maxp[ 0 ], maxp[ 1 ], minp[ 2 ] );
1583 glVertex3f ( maxp[ 0 ], maxp[ 1 ], maxp[ 2 ] );
1584 glVertex3f ( maxp[ 0 ], minp[ 1 ], maxp[ 2 ] );
1585 glVertex3f ( maxp[ 0 ], minp[ 1 ], minp[ 2 ] );
1587 glVertex3f ( maxp[ 0 ], minp[ 1 ], maxp[ 2 ] );
1588 glVertex3f ( minp[ 0 ], minp[ 1 ], maxp[ 2 ] );
1589 glVertex3f ( minp[ 0 ], maxp[ 1 ], maxp[ 2 ] );
1590 glVertex3fv ( maxp );
1591 glVertex3f ( maxp[ 0 ], maxp[ 1 ], minp[ 2 ] );
1592 glVertex3f ( minp[ 0 ], maxp[ 1 ], minp[ 2 ] );
1601 } else glCallList ( p -> d.dlist );
1603 } /* end draw_degenerates_as_bboxs */
1606 void set_drawable_items ( GLboolean* pbDraw, int n ) {
1610 memset ( pbDraw, 0, sizeof ( GLboolean ) * n );
1612 i = ( int )( ( 1.0F - g_fSkipRatio ) * n );
1614 while ( i-- ) pbDraw[ OPENGL_RAND() % n ] = 1;
1616 } /* end set_drawable_items */