e6756735f0adf87af5924c200d84ac8036dc8644
[occt.git] / src / OpenGl / OpenGl_telem_util.cxx
1 /***********************************************************************
2
3 FONCTION :
4 ----------
5 File OpenGl_telem_util :
6
7
8 REMARQUES:
9 ---------- 
10
11
12 HISTORIQUE DES MODIFICATIONS   :
13 --------------------------------
14 xx-xx-xx : xxx ; Creation.
15 07-02-96 : FMN ; - Ajout trace
16 - Suppression code inutile
17 08-03-96 : FMN ; - Ajout include manquant 
18 01-04-96 : CAL ; Integration MINSK portage WNT
19 15-04-96 : CAL ; Integration travail PIXMAP de Jim ROTH
20 22-04-96 : FMN ; Ajout TelReadImage TelDrawImage
21 10-05-96 : CAL ; Ajout d'un nouveau delta dans les copies
22 de pixels (voir CALL_DEF_DELTA)
23 25-06-96 : FMN ; Suppression utilisation de glScissor.
24 02-07-96 : FMN ; Suppression WSWSHeight et WSWSWidth
25 Suppression glViewport inutile.
26 18-07-96 : FMN ; Suppression TelFlush inutile.
27 08-07-96 : FMN ; Suppression de OPENGL_DEBUG inutile avec la nouvelle
28 version de ogldebug.
29 24-10-96 : CAL ; Portage WNT
30 23-01-97 : CAL ; Suppression de TelClearViews dans TelCopyBuffers
31 30-01-97 : FMN ; Ajout commentaires + WNT.
32 12-02-97 : FMN ; Suppression TelEnquireFacilities()
33 22-04-97 : FMN ; Ajout affichage du cadre pour la copie de buffer
34 30-06-97 : FMN ; Suppression OpenGl_telem_light.h
35 18-07-97 : FMN ; Utilisation de la toolkit sur les lights
36 07-10-97 : FMN ; Simplification WNT + correction Transient
37 05-12-97 : FMN ; PRO11168: Suppression TglActiveWs pour project/unproject
38 23-12-97 : FMN ; Suppression TelSetFrontFaceAttri et TelSetBackFaceAttri 
39 30-12-97 : FMN ; CTS18312: Correction back material
40 04-05-98 : CAL ; Contournement bug SGI octane bavure de pixels (PRO12899)
41 30-09-98 : CAL ; Optimisation pour eviter de charger inutilement
42 les matrices de la vue.
43 19-10-98 : FMN ; Suppression de glPixelTransferi dans TelEnable() car cela
44 rentre en conflit avec l'utilisation d'une image de fond.
45 02.14.100 : JR : Warnings on WNT truncations from double to float
46 08-03-01 : GG  ; BUC60823 Avoid crash in the normal computation method
47 when a face has confused or aligned points.
48
49 ************************************************************************/
50
51 #include <OpenGl_GlCore11.hxx>
52
53 #include <OpenGl_telem_util.hxx>
54 #include <InterfaceGraphic_Graphic3d.hxx>
55 #include <InterfaceGraphic_Visual3d.hxx>
56
57 #define GPRECIS 0.000001
58 Tint TelGetPolygonNormal(tel_point pnts, Tint* indexs, Tint npnt, Tfloat *norm ) {
59   Tint status=0;
60
61   norm[0] = norm[1] = norm[2] = 0.;
62   if( npnt > 2 ) { 
63     Tfloat a[3], b[3], c[3];
64     Tint i,j,i0,ii=0,jj;
65
66     i0 = 0; if( indexs ) i0 = indexs[0];
67     for( i=1 ; i<npnt ; i++ ) {
68       ii = i; if( indexs ) ii = indexs[i];
69       vecsub( a, pnts[ii].xyz, pnts[i0].xyz );
70       if( vecmg2(a) > GPRECIS ) break;
71     }
72     if( i < npnt-1 ) {
73       for( j=i+1 ; j<npnt ; j++ ) {
74         jj = j; if( indexs ) jj = indexs[j];
75         vecsub( b, pnts[jj].xyz, pnts[i0].xyz );
76         vecsub( c, pnts[jj].xyz, pnts[ii].xyz );
77         if( (vecmg2(b) > GPRECIS) && (vecmg2(c) > GPRECIS) ) break;
78       }
79       if( j < npnt ) {
80         Tfloat d;
81         veccrs( norm, a, b );
82         d = vecnrmd( norm, d );
83         status = (d > 0.) ? 1 : 0;
84       }
85     }
86   }
87 #ifdef DEB
88   if( !status )
89     printf(" *** OpenGl_TelGetPolygonNormal.has found confused or aligned points\n");
90 #endif
91
92   return status;
93 }
94
95 Tint TelGetNormal(Tfloat *data1, Tfloat *data2, Tfloat *data3, Tfloat *norm ) {
96   Tfloat a[3], b[3];
97   Tint status=0;
98
99   norm[0] = norm[1] = norm[2] = 0.;
100   vecsub( a, data2, data1 );
101   vecsub( b, data3, data2 );
102   if( (vecmg2(a) > GPRECIS) && (vecmg2(b) > GPRECIS) ) {
103     Tfloat d;
104     veccrs( norm, a, b );
105     d = vecnrmd( norm, d );
106     status = (d > 0.) ? 1 : 0;
107   }
108 #ifdef DEB
109   if( !status )
110     printf(" *** OpenGl_TelGetNormal.has found confused or aligned points\n");
111 #endif
112
113   return status;
114 }
115
116 void TelMultiplymat3 (Tmatrix3 c, Tmatrix3 a, Tmatrix3 b)
117 {
118   Tint row, col, i;
119   Tmatrix3 res;
120   Tint dim = 4;
121
122   /* on multiplie d'abord les 2 matrices dim x dim */
123   for (row = 0; row < dim; row++) {
124     for (col = 0; col < dim; col++) {
125       Tfloat sum = ( float )0.0;
126       for (i = 0; i < dim; i++)
127         sum += a[row][i] * b[i][col];
128       res[row][col] = sum;
129     }
130   }
131
132   /* on copie ensuite le resultat */
133   matcpy (c, res);
134
135   return;
136 }