1 /***********************************************************************
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
19 ************************************************************************/
21 /*----------------------------------------------------------------------*/
27 #include <OpenGl_tgl_all.hxx>
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>
40 /*----------------------------------------------------------------------*/
42 * Definition des types
45 struct TEL_DEPTHCUE_DATA
49 IMPLEMENT_MEMORY_OPERATORS
51 typedef TEL_DEPTHCUE_DATA* tel_depthcue_data;
53 struct TEL_WS_DEPTHCUES
55 Tint num; /* number of depthcues for a workstation */
56 Tint siz; /* size allocated */
57 tel_depthcue_data data; /* depthcue definitions for the workstation */
59 typedef TEL_WS_DEPTHCUES* tel_ws_depthcues;
63 /*----------------------------------------------------------------------*/
66 b_s( Tint id, tel_depthcue_data tbl, Tint low, Tint high )
73 mid = low+high, mid /= 2;
74 i = id - tbl[mid].dcid;
76 return i == 0 ? mid : i < 0 ? b_s( id, tbl, low, mid-1 ) :
77 b_s( id, tbl, mid+1, high );
80 /*----------------------------------------------------------------------*/
83 lnumcomp( const void *a, const void *b )
85 return *( ( int* )a )- *( ( int* )b );
88 /*----------------------------------------------------------------------*/
91 TelSetDepthCueRep( Tint Wsid, Tint dcid, tel_depthcue dc )
94 tel_depthcue_data dcptr;
95 tel_ws_depthcues ws_dcues;
98 TsmGetWSAttri( Wsid, WSDepthCues, &key );
99 ws_dcues = (tel_ws_depthcues)key.pdata ; /* Obtain list of defined depthcues*/
101 if( !ws_dcues ) /* no depthcues defined yet */
103 //cmn_memreserve( ws_dcues, 1, 0 );
104 ws_dcues = new TEL_WS_DEPTHCUES();
108 ws_dcues->data = new TEL_DEPTHCUE_DATA[GROW_SIZE];
109 if( !ws_dcues->data )
112 ws_dcues->siz = GROW_SIZE;
115 key.pdata = ws_dcues;/* Set list for the workstation */
116 TsmSetWSAttri( Wsid, WSDepthCues, &key );
118 else if( ws_dcues->num == ws_dcues->siz ) /* insufficient memory */
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) );
124 ws_dcues->data = cmn_resizemem<TEL_DEPTHCUE_DATA>( ws_dcues->data, ws_dcues->siz
130 ws_dcues->siz += GROW_SIZE;
132 key.pdata = ws_dcues; /* Reset list for the workstation */
133 TsmSetWSAttri( Wsid, WSDepthCues, &key );
135 dcptr = 0; /* Locate depthcue if already defined */
136 i = b_s( dcid, ws_dcues->data, 0, ws_dcues->num-1 );
138 dcptr = &ws_dcues->data[i]; /* depthcue already defined */
140 if( !dcptr ) /* new depthcue */
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 );
149 dcptr->dc = *dc; /* copy depthcue definition */
154 /*----------------------------------------------------------------------*/
157 TelGetGLDepthCue( Tint Wsid, Tint Vid, Tint dcid, tel_gl_depthcue gldc )
160 tel_depthcue_data dcptr;
161 tel_ws_depthcues ws_dcues;
166 TsmGetWSAttri( Wsid, WSDepthCues, &key );
167 ws_dcues = (tel_ws_depthcues)key.pdata ; /* Obtain list of defined depthcues */
170 return TFailure; /* no depthcues defined */
172 dcptr = 0; /* Locate depthcue if already defined */
173 i = b_s( dcid, ws_dcues->data, 0, ws_dcues->num-1 );
175 return TFailure; /* dcid undefined */
177 if( TelGetViewRepresentation( Wsid, Vid, &vrep ) == TFailure )
178 return TFailure; /* Bad View Rep */
180 dcptr = &ws_dcues->data[i];
181 gldc->dcrep = dcptr->dc;
182 if( dcptr->dc.mode == TelDCAllowed )
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;
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);
201 /*----------------------------------------------------------------------*/
204 TelPrintDepthCueRep( Tint Wsid, Tint dcid )
207 tel_depthcue_data dcptr;
208 tel_ws_depthcues ws_dcues;
211 TsmGetWSAttri( Wsid, WSDepthCues, &key );
212 ws_dcues = (tel_ws_depthcues)key.pdata ; /* Obtain list of defined depthcues */
215 return; /* no depthcues defined */
217 dcptr = 0; /* Locate depthcue if already defined */
218 i = b_s( dcid, ws_dcues->data, 0, ws_dcues->num-1 );
221 fprintf( stdout, "\nBad DepthCue %d\n", dcid );
222 return; /* dcid undefined */
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" );
242 /*----------------------------------------------------------------------*/
245 TelDeleteDepthCuesForWS( Tint wsid )
250 TsmGetWSAttri( wsid, WSDepthCues, &key );
251 d = (tel_ws_depthcues)key.pdata;
262 /*----------------------------------------------------------------------*/