1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
/***********************************************************************
FONCTION :
----------
File OpenGl_depthcue :
REMARQUES:
----------
HISTORIQUE DES MODIFICATIONS :
--------------------------------
xx-xx-xx : xxx ; Creation.
11-03-96 : FMN ; Correction warning compilation
01-04-96 : CAL ; Integration MINSK portage WNT
12-02-97 : FMN ; Suppression de TelGetDepthCueRep
************************************************************************/
/* Workaround for internal bcc32 compiler bug. */
/* Starting from bcc32 v6.40 this flag should be passed as a compiler option. */
#if defined(__BORLANDC__) && __BORLANDC__ < 0x0640 /* bcc32 v6.40 */
#pragma option -x-
#endif
/*----------------------------------------------------------------------*/
/*
* Includes
*/
#include <OpenGl_tgl_all.hxx>
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <OpenGl_cmn_varargs.hxx>
#include <OpenGl_telem.hxx>
#include <OpenGl_telem_view.hxx>
#include <OpenGl_tsm_ws.hxx>
#include <OpenGl_telem_depthcue.hxx>
#include <OpenGl_Memory.hxx>
/*----------------------------------------------------------------------*/
/*
* Definition des types
*/
struct TEL_DEPTHCUE_DATA
{
Tint dcid;
TEL_DEPTHCUE dc;
IMPLEMENT_MEMORY_OPERATORS
};
typedef TEL_DEPTHCUE_DATA* tel_depthcue_data;
struct TEL_WS_DEPTHCUES
{
Tint num; /* number of depthcues for a workstation */
Tint siz; /* size allocated */
tel_depthcue_data data; /* depthcue definitions for the workstation */
};
typedef TEL_WS_DEPTHCUES* tel_ws_depthcues;
#define GROW_SIZE 25
/*----------------------------------------------------------------------*/
static Tint
b_s( Tint id, tel_depthcue_data tbl, Tint low, Tint high )
{
register Tint mid, i;
if( low > high )
return -1;
mid = low+high, mid /= 2;
i = id - tbl[mid].dcid;
return i == 0 ? mid : i < 0 ? b_s( id, tbl, low, mid-1 ) :
b_s( id, tbl, mid+1, high );
}
/*----------------------------------------------------------------------*/
static int
lnumcomp( const void *a, const void *b )
{
return *( ( int* )a )- *( ( int* )b );
}
/*----------------------------------------------------------------------*/
TStatus
TelSetDepthCueRep( Tint Wsid, Tint dcid, tel_depthcue dc )
{
CMN_KEY_DATA key;
tel_depthcue_data dcptr;
tel_ws_depthcues ws_dcues;
register Tint i;
TsmGetWSAttri( Wsid, WSDepthCues, &key );
ws_dcues = (tel_ws_depthcues)key.pdata ; /* Obtain list of defined depthcues*/
if( !ws_dcues ) /* no depthcues defined yet */
{ /* allocate */
//cmn_memreserve( ws_dcues, 1, 0 );
ws_dcues = new TEL_WS_DEPTHCUES();
if( !ws_dcues )
return TFailure;
ws_dcues->data = new TEL_DEPTHCUE_DATA[GROW_SIZE];
if( !ws_dcues->data )
return TFailure;
ws_dcues->siz = GROW_SIZE;
ws_dcues->num = 0;
key.pdata = ws_dcues;/* Set list for the workstation */
TsmSetWSAttri( Wsid, WSDepthCues, &key );
}
else if( ws_dcues->num == ws_dcues->siz ) /* insufficient memory */
{ /* realloc */
#if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x530)
ws_dcues->data = (TEL_DEPTHCUE_DATA*)realloc( ws_dcues->data, (ws_dcues->siz
+ GROW_SIZE)*sizeof(TEL_DEPTHCUE_DATA) );
#else
ws_dcues->data = cmn_resizemem<TEL_DEPTHCUE_DATA>( ws_dcues->data, ws_dcues->siz
+ GROW_SIZE );
#endif
if( !ws_dcues )
return TFailure;
ws_dcues->siz += GROW_SIZE;
key.pdata = ws_dcues; /* Reset list for the workstation */
TsmSetWSAttri( Wsid, WSDepthCues, &key );
}
dcptr = 0; /* Locate depthcue if already defined */
i = b_s( dcid, ws_dcues->data, 0, ws_dcues->num-1 );
if( i != -1 )
dcptr = &ws_dcues->data[i]; /* depthcue already defined */
if( !dcptr ) /* new depthcue */
{
dcptr = &ws_dcues->data[ws_dcues->num];
dcptr->dcid = dcid; /* depthcues for the workstation */
ws_dcues->num++; /* and sort the entries */
qsort( ws_dcues->data, ws_dcues->num,
sizeof(TEL_DEPTHCUE_DATA), lnumcomp );
}
dcptr->dc = *dc; /* copy depthcue definition */
return TSuccess;
}
/*----------------------------------------------------------------------*/
TStatus
TelGetGLDepthCue( Tint Wsid, Tint Vid, Tint dcid, tel_gl_depthcue gldc )
{
CMN_KEY_DATA key;
tel_depthcue_data dcptr;
tel_ws_depthcues ws_dcues;
TEL_VIEW_REP vrep;
register Tint i;
Tfloat ramp;
TsmGetWSAttri( Wsid, WSDepthCues, &key );
ws_dcues = (tel_ws_depthcues)key.pdata ; /* Obtain list of defined depthcues */
if( !ws_dcues )
return TFailure; /* no depthcues defined */
dcptr = 0; /* Locate depthcue if already defined */
i = b_s( dcid, ws_dcues->data, 0, ws_dcues->num-1 );
if( i == -1 )
return TFailure; /* dcid undefined */
if( TelGetViewRepresentation( Wsid, Vid, &vrep ) == TFailure )
return TFailure; /* Bad View Rep */
dcptr = &ws_dcues->data[i];
gldc->dcrep = dcptr->dc;
if( dcptr->dc.mode == TelDCAllowed )
{
ramp = (dcptr->dc.planes[1] - dcptr->dc.planes[0]) /
(dcptr->dc.scales[1] - dcptr->dc.scales[0]) ;
gldc->dist[0] = dcptr->dc.planes[0] - (1-dcptr->dc.scales[0]) * ramp;
gldc->dist[1] = dcptr->dc.planes[1] + dcptr->dc.scales[1] * ramp;
ramp = vrep.extra.map.fpd - vrep.extra.map.bpd;
gldc->dist[0] = gldc->dist[0]*ramp - vrep.extra.map.fpd;
gldc->dist[1] = gldc->dist[1]*ramp - vrep.extra.map.fpd;
#ifdef TRACE
printf( "Dist: Near: %f\tFar: %f\n", gldc->dist[0], gldc->dist[1] );
printf( "Scal: Near: %f\tFar: %f ramp %f\n",dcptr->dc.scales[0], dcptr->dc.scales[1],ramp );
printf( "map Near: %f\tFar: %f\n",vrep.extra.map.fpd,vrep.extra.map.bpd);
#endif
}
return TSuccess;
}
/*----------------------------------------------------------------------*/
void
TelPrintDepthCueRep( Tint Wsid, Tint dcid )
{
CMN_KEY_DATA key;
tel_depthcue_data dcptr;
tel_ws_depthcues ws_dcues;
register Tint i;
TsmGetWSAttri( Wsid, WSDepthCues, &key );
ws_dcues = (tel_ws_depthcues)key.pdata ; /* Obtain list of defined depthcues */
if( !ws_dcues )
return; /* no depthcues defined */
dcptr = 0; /* Locate depthcue if already defined */
i = b_s( dcid, ws_dcues->data, 0, ws_dcues->num-1 );
if( i == -1 )
{
fprintf( stdout, "\nBad DepthCue %d\n", dcid );
return; /* dcid undefined */
}
dcptr = &ws_dcues->data[i];
fprintf( stdout, "\nDepthCue Id: %d", dcid );
fprintf( stdout, "\nDepthCue mode: %s", dcptr->dc.mode == TelDCAllowed ?
"TelDCAllowed" : "TelDCSuppressed" );
fprintf( stdout, "\n\tPlanes: Near %f\tFar %f",
dcptr->dc.planes[0], dcptr->dc.planes[1] );
fprintf( stdout, "\n\tScales: Near %f\tFar %f",
dcptr->dc.scales[0], dcptr->dc.scales[1] );
fprintf( stdout, "\n\tColour: %f %f %f",
dcptr->dc.col.rgb[0],
dcptr->dc.col.rgb[1],
dcptr->dc.col.rgb[2] );
fprintf( stdout, "\n" );
return;
}
/*----------------------------------------------------------------------*/
TStatus
TelDeleteDepthCuesForWS( Tint wsid )
{
CMN_KEY_DATA key;
tel_ws_depthcues d;
TsmGetWSAttri( wsid, WSDepthCues, &key );
d = (tel_ws_depthcues)key.pdata;
if( !d )
return TSuccess;
//cmn_freemem( d );
delete d;
return TSuccess;
}
/*----------------------------------------------------------------------*/
|