0026348: Visualization, TKOpenGl - eliminate invalid NULL checks for transformation...
[occt.git] / src / OpenGl / OpenGl_telem_util.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
7fd59977 15/***********************************************************************
16
17FONCTION :
18----------
19File OpenGl_telem_util :
20
21
22REMARQUES:
23----------
24
25
26HISTORIQUE DES MODIFICATIONS :
27--------------------------------
28xx-xx-xx : xxx ; Creation.
2907-02-96 : FMN ; - Ajout trace
30- Suppression code inutile
3108-03-96 : FMN ; - Ajout include manquant
3201-04-96 : CAL ; Integration MINSK portage WNT
3315-04-96 : CAL ; Integration travail PIXMAP de Jim ROTH
3422-04-96 : FMN ; Ajout TelReadImage TelDrawImage
3510-05-96 : CAL ; Ajout d'un nouveau delta dans les copies
36de pixels (voir CALL_DEF_DELTA)
3725-06-96 : FMN ; Suppression utilisation de glScissor.
3802-07-96 : FMN ; Suppression WSWSHeight et WSWSWidth
39Suppression glViewport inutile.
4018-07-96 : FMN ; Suppression TelFlush inutile.
4108-07-96 : FMN ; Suppression de OPENGL_DEBUG inutile avec la nouvelle
42version de ogldebug.
4324-10-96 : CAL ; Portage WNT
4423-01-97 : CAL ; Suppression de TelClearViews dans TelCopyBuffers
4530-01-97 : FMN ; Ajout commentaires + WNT.
4612-02-97 : FMN ; Suppression TelEnquireFacilities()
4722-04-97 : FMN ; Ajout affichage du cadre pour la copie de buffer
4830-06-97 : FMN ; Suppression OpenGl_telem_light.h
4918-07-97 : FMN ; Utilisation de la toolkit sur les lights
5007-10-97 : FMN ; Simplification WNT + correction Transient
5105-12-97 : FMN ; PRO11168: Suppression TglActiveWs pour project/unproject
5223-12-97 : FMN ; Suppression TelSetFrontFaceAttri et TelSetBackFaceAttri
5330-12-97 : FMN ; CTS18312: Correction back material
5404-05-98 : CAL ; Contournement bug SGI octane bavure de pixels (PRO12899)
5530-09-98 : CAL ; Optimisation pour eviter de charger inutilement
56les matrices de la vue.
5719-10-98 : FMN ; Suppression de glPixelTransferi dans TelEnable() car cela
58rentre en conflit avec l'utilisation d'une image de fond.
5902.14.100 : JR : Warnings on WNT truncations from double to float
6008-03-01 : GG ; BUC60823 Avoid crash in the normal computation method
61when a face has confused or aligned points.
62
63************************************************************************/
64
d64e6d05 65#include <stdio.h>
66
5f8b738e 67#include <OpenGl_GlCore11.hxx>
7fd59977 68
7fd59977 69#include <OpenGl_telem_util.hxx>
2166f0fa 70#include <InterfaceGraphic_Graphic3d.hxx>
7fd59977 71
7fd59977 72#define GPRECIS 0.000001
73Tint TelGetPolygonNormal(tel_point pnts, Tint* indexs, Tint npnt, Tfloat *norm ) {
74 Tint status=0;
75
76 norm[0] = norm[1] = norm[2] = 0.;
77 if( npnt > 2 ) {
78 Tfloat a[3], b[3], c[3];
79 Tint i,j,i0,ii=0,jj;
80
81 i0 = 0; if( indexs ) i0 = indexs[0];
82 for( i=1 ; i<npnt ; i++ ) {
83 ii = i; if( indexs ) ii = indexs[i];
84 vecsub( a, pnts[ii].xyz, pnts[i0].xyz );
85 if( vecmg2(a) > GPRECIS ) break;
86 }
87 if( i < npnt-1 ) {
88 for( j=i+1 ; j<npnt ; j++ ) {
89 jj = j; if( indexs ) jj = indexs[j];
90 vecsub( b, pnts[jj].xyz, pnts[i0].xyz );
91 vecsub( c, pnts[jj].xyz, pnts[ii].xyz );
92 if( (vecmg2(b) > GPRECIS) && (vecmg2(c) > GPRECIS) ) break;
93 }
94 if( j < npnt ) {
95 Tfloat d;
96 veccrs( norm, a, b );
97 d = vecnrmd( norm, d );
98 status = (d > 0.) ? 1 : 0;
99 }
100 }
101 }
0797d9d3 102#ifdef OCCT_DEBUG
7fd59977 103 if( !status )
104 printf(" *** OpenGl_TelGetPolygonNormal.has found confused or aligned points\n");
105#endif
106
107 return status;
108}
109
110Tint TelGetNormal(Tfloat *data1, Tfloat *data2, Tfloat *data3, Tfloat *norm ) {
111 Tfloat a[3], b[3];
112 Tint status=0;
113
114 norm[0] = norm[1] = norm[2] = 0.;
115 vecsub( a, data2, data1 );
116 vecsub( b, data3, data2 );
117 if( (vecmg2(a) > GPRECIS) && (vecmg2(b) > GPRECIS) ) {
118 Tfloat d;
119 veccrs( norm, a, b );
120 d = vecnrmd( norm, d );
121 status = (d > 0.) ? 1 : 0;
122 }
0797d9d3 123#ifdef OCCT_DEBUG
7fd59977 124 if( !status )
125 printf(" *** OpenGl_TelGetNormal.has found confused or aligned points\n");
126#endif
127
128 return status;
129}
7fd59977 130
2166f0fa 131void TelMultiplymat3 (Tmatrix3 c, Tmatrix3 a, Tmatrix3 b)
7fd59977 132{
133 Tint row, col, i;
134 Tmatrix3 res;
135 Tint dim = 4;
136
137 /* on multiplie d'abord les 2 matrices dim x dim */
138 for (row = 0; row < dim; row++) {
139 for (col = 0; col < dim; col++) {
140 Tfloat sum = ( float )0.0;
141 for (i = 0; i < dim; i++)
142 sum += a[row][i] * b[i][col];
143 res[row][col] = sum;
144 }
145 }
146
147 /* on copie ensuite le resultat */
148 matcpy (c, res);
149
150 return;
151}