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