1 /*   viewer3d.h
2 * ===========================================================================
3 *
4 *                            PUBLIC DOMAIN NOTICE
5 *            National Center for Biotechnology Information (NCBI)
6 *
7 *  This software/database is a "United States Government Work" under the
8 *  terms of the United States Copyright Act.  It was written as part of
9 *  the author's official duties as a United States Government employee and
10 *  thus cannot be copyrighted.  This software/database is freely available
11 *  to the public for use. The National Library of Medicine and the U.S.
12 *  Government do not place any restriction on its use or reproduction.
13 *  We would, however, appreciate having the NCBI and the author cited in
14 *  any work or product based on this material
15 *
16 *  Although all reasonable efforts have been taken to ensure the accuracy
17 *  and reliability of the software and data, the NLM and the U.S.
18 *  Government do not and cannot warrant the performance or results that
19 *  may be obtained by using this software or data. The NLM and the U.S.
20 *  Government disclaim all warranties, express or implied, including
21 *  warranties of performance, merchantability or fitness for any particular
22 *  purpose.
23 *
24 * ===========================================================================
25 *
26 * File Name:  viewer3d.h
27 *
28 * Author:  Alex Smirnov
29 *
30 * Version Creation Date:   03/29/95
31 *
32 * $Revision: 6.3 $
33 *
34 * File Description:  3D-Viewer API
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * $Log: viewer3d.h,v $
39 * Revision 6.3  2000/01/11 01:16:45  lewisg
40 * fix color selection in Cn3D, other misc. bugs
41 *
42 * Revision 6.2  1998/08/12 23:04:07  vakatov
43 * [64-bit platforms]  Made "idBuffer" be VoidPtr[] rather than Int4[];
44 * Fixed bugs mostly caused by casting between Int4 vars and 8-byte pointers
45 *
46 * Revision 6.1  1998/04/20 18:30:40  lewisg
47 * moved typedef for _Nlm_Viewer3D to include file
48 *
49 * Revision 6.0  1997/08/25 18:58:20  madden
50 * Revision changed to 6.0
51 *
52 * Revision 5.4  1997/03/31 16:52:56  vakatov
53 * Changed the Nlm_CreateViewer3D() proto to reduce a number of arguments
54 * and to allow one to specify appearance of any(incl. Z-)rotation scrollbars.
55 * Splitted std. mouse group Mouse3D_Rotate --> Mouse3D_Rotate[YX,ZX,YZ].
56 *
57  * Revision 1.13  1997/03/31  16:19:31  vakatov
58  * XZ --> ZX
59  *
60  * Revision 1.12  1997/03/25  22:59:44  vakatov
61  * All coord-rotation code from rotateXY(), QRotate() and RotateVierer()
62  * moved to the new universal Rotate()
63  * Z-rotation added to alternative standard mouse groups(-XZ and -YZ)
64  *
65  * Revision 1.11  1997/03/25  19:40:42  vakatov
66  * Z-rotation works;  wanna revise the former rotateXY() function to let
67  * it rotate around an arbitrary point
68  *
69  * Revision 5.3  1997/03/20  19:02:55  vakatov
70  * Heavily redesigned to work with the new panel-mouse management.
71  * Revised API for work with the 3D-Viewer controls.
72  * Hided internal structure definitions and the Viewer3D handle itself.
73  *
74  * Revision 5.2  1996/06/14  16:39:21  kans
75  * copy and print 3d viewer now ifndef win_motif
76  *
77  * Revision 5.1  1996/06/14  14:29:58  vakatov
78  * Nlm_SetBackground3D() added to change 3D-Viewer background color.
79  * "Copy" and "Print" buttons related stuff carefully commented everywhere.
80  *
81  * Revision 5.0  1996/05/28  13:45:08  ostell
82  * Set to revision 5.0
83  *
84  * Revision 1.13  1996/05/23  14:36:35  hogue
85  * Fixed PrintViewer/PasteViewer discrepancy in .h file, added
86  * IsPlaying3D, StopPlaying3D, StartPlaying3D for more
87  * external control of the animation
88  *
89  * Revision 1.12  1996/05/13  15:04:38  hogue
90  * Save button in Viewer Controls now optional
91  *
92  * Revision 1.11  1996/05/09  18:30:38  vakatov
93  * Added CAMERA_SIZE_I4 constant for an external use
94  *
95  * Revision 1.10  1996/05/07  18:30:25  vakatov
96  * Nlm_CreateViewer3D() prototype -- modified
97  *
98  * Revision 1.9  1996/04/17  21:31:33  vakatov
99  * Added "Nlm_GetViewerImage3D()" function returning image of the 3D-viewer.
100  *
101  * Revision 1.8  1996/04/07  20:04:56  kans
102  * getlayertop3d needed (void) as prototype
103  *
104  * Revision 1.7  1996/04/04  18:52:45  vakatov
105  * The camera position storing structure size is increased
106  *
107  * Revision 1.6  1996/04/02  22:30:53  vakatov
108  * AttachZoomPic3D() removed; now previously stored camera position
109  * is to be restored within AttachPicture3D automatically, as soon as
110  * valid (non-NULL and initialized) "camera" argument is provided
111  *
112  * Revision 1.5  1996/04/01  23:03:09  vakatov
113  * Added "dscale" member to the "Nlm_camera3d" structure
114  *
115  * Revision 1.4  1996/03/30  23:25:55  hogue
116  * Added AttachZoomPic3D
117  *
118 *
119 */
120 
121 #ifndef _VIEWER3D_
122 #define _VIEWER3D_
123 
124 #ifndef _VIBRANT_
125 #include <vibrant.h>
126 #endif
127 
128 #ifndef _PICTUR3D_
129 #include <pictur3d.h>
130 #endif
131 
132 #include <image.h>
133 #include <vibmouse.h>
134 
135 #ifdef __cplusplus
136 extern "C" {
137 #endif
138 
139 /*****************************************************************************
140 *
141 *   DEFINES
142 *
143 *****************************************************************************/
144 /* Types of adjust for Nlm_SetAdjust3D() */
145 #define ADJUST3D_PERSPECT 1
146 #define ADJUST3D_BRIGH    2
147 #define ADJUST3D_COLOR    3
148 
149 #define enumStdMA3D Nlm_enumStdMA3D
150 #define MAX_FOUND_PRIM 32
151 
152 
153 /*****************************************************************************
154 *
155 *   TYPEDEFS
156 *
157 *****************************************************************************/
158 
159 /* Standard set of the viewer mouse callback groups
160  */
161 typedef enum
162 {
163   Mouse3D_DoNothing = 0,
164 
165   Mouse3D_RotateYX,
166   Mouse3D_RotateZX,
167   Mouse3D_RotateYZ,
168   Mouse3D_Move,
169   Mouse3D_Zoom,
170 
171   Mouse3D_NumStd
172 }  Nlm_enumStdMA3D;
173 
174 typedef struct _Nlm_Viewer3D
175 {
176   double      dAOrt[3][3];
177   double      dC[3];
178   double      dscale;
179   Int4        a[3][3];
180   Int4        c[3];
181   Int4        scale;
182   Int4        zmax;
183   Picture3D   pic;
184   Image       image;
185   Boolean     layerTable[256];
186   Int4        p_version;
187   Int4        g_version;
188   Int4        g_versionPrev;
189   Int4        c_version;
190   Int4        c_versionPrev;
191   Int4        colorOffset;
192   Int4        colorStep;
193   Int4        colorScale;
194   MAPtr       ma;
195   MA_GroupPtr ma_std_group[Mouse3D_NumStd];
196   BaR         z_rotate;
197   PaneL       panel;
198   WindoW      parentWindow;
199   Handle      zBuffer;
200   Prim3D      foundPrim[MAX_FOUND_PRIM];
201   Uint2       nPrimFound;
202   Int2        width;
203   Int2        height;
204   Int2        is_zoomed;
205   Uint1       perspectN;
206   Uint1       brighN;
207   Uint1       colorPicN;
208   Uint1       colorHLR, colorHLG, colorHLB;
209   Uint1       colorFon;
210   Uint1       adjust;
211   Uint1       perspect;
212   Uint1       colorFonR, colorFonG, colorFonB;
213 }  PNTR Nlm_Viewer3D;
214 
215 struct _Nlm_Controls3D;
216 typedef struct _Nlm_Controls3D PNTR Nlm_Controls3D;
217 
218 
219 #define CAMERA_SIZE_I4 17
220 typedef struct Nlm_camera3d {
221   Int4 dummy[CAMERA_SIZE_I4];
222 } Nlm_Camera3D, PNTR Nlm_Camera3DPtr;
223 
224 
225 typedef Boolean (*Nlm_MAInit3DFunc) PROTO((MAPtr ma, VoidPtr data));
226 
227 /*****************************************************************************
228 *
229 *   EXTERN FUNCTION
230 *
231 *****************************************************************************/
232 
233 /* Create 3D-viewer as a child of group "prnt";
234  * set its size to "width"(can be adjusted a bit) and "height".
235  * Provide the viewer with the rotation scrollbars according to
236  * the "flags"(see #[XYZ]_SCROLL).
237  * If "ma_group_menu" or "ma_action_menu"(can be a menubar cascade item or
238  * submenu(s)) are not NULL then attach mouse-control user interface to these;
239  * if "ma_init_func" is not NULL then it will be called with the
240  * "ma_init_data"(as a <2nd> argument) right after the standard initialization
241  * of the 3D-Viewer mouse controls.
242  */
243 #define X_ROTATE_SBAR 0x1
244 #define Y_ROTATE_SBAR 0x2
245 #define Z_ROTATE_SBAR 0x4
246 
247 extern Nlm_Viewer3D  Nlm_CreateViewer3D    PROTO((Nlm_GrouP prnt,
248                                     Uint2Ptr width, Uint2 height,
249                                     Int4 flags,
250                                     MenU ma_group_menu, MenU ma_action_menu,
251                                     Nlm_MAInit3DFunc ma_init_func,
252                                     VoidPtr          ma_init_data));
253 
254 /* Resize/Move the Viewer according to the "rect".
255  * NOTE: "rect->right" can be adjusted(decreased by some points only!);
256  *       if the viewer has scrollbar(s) then the scrollbars will be fit
257  *       into the specified "rect".
258  */
259 extern Boolean       Nlm_SetPosition3D     PROTO((Nlm_Viewer3D vvv,
260                                                   RectPtr rect));
261 
262 extern Image         Nlm_GetViewerImage3D  PROTO((Nlm_Viewer3D viewer));
263 extern void          Nlm_DeleteViewer3D    PROTO((Nlm_Viewer3D viewer));
264 extern Boolean       Nlm_AttachPicture3D   PROTO((Nlm_Viewer3D viewer,
265                                                   Picture3D picture,
266                                                   Nlm_Camera3DPtr camera));
267 extern void          Nlm_GetViewerInfo3D   PROTO((Nlm_Viewer3D viewer,
268                                                   Picture3D PNTR pic,
269                                                   Nlm_Camera3DPtr camera,
270                                                   RectPtr rectangle));
271 extern Boolean       Nlm_RedrawViewer3D    PROTO((Nlm_Viewer3D viewer));
272 extern Uint2         Nlm_FindPrim3D        PROTO((Nlm_Viewer3D viewer,
273                                                   PoinT pt));
274 extern Prim3D        Nlm_GetFoundPrim3D    PROTO((Nlm_Viewer3D viewer,
275                                                   Uint2 primIndex));
276 extern void          Nlm_SetHLColor3D      PROTO((Nlm_Viewer3D viewer,
277                                                   Uint1 red,
278                                                   Uint1 green,
279                                                   Uint1 blue));
280 extern void          Nlm_HighlightSeg3D    PROTO((Nlm_Viewer3D viewer,
281                                                   Segment3D segment,
282                                                   Boolean highlight));
283 extern Boolean       Nlm_IsSeg3DHlighted   PROTO((Nlm_Viewer3D viewer,
284                                                   Segment3D segment));
285 extern void          Nlm_HighlightPrim3D   PROTO((Nlm_Viewer3D viewer,
286                                                   Prim3D prim,
287                                                   Boolean highlight));
288 extern Boolean       Nlm_IsPrim3DHlighted  PROTO((Nlm_Viewer3D viewer,
289                                                   Prim3D prim));
290 extern Boolean       Nlm_ResetHighlight3D  PROTO((Nlm_Viewer3D viewer));
291 extern Boolean       Nlm_MapWorldToViewer3D  PROTO((Nlm_Viewer3D viewer,
292                                                     Int4 x, Int4 y, Int4 z,
293                                                     PoinT PNTR vPoint));
294 
295 
296 extern void          Nlm_SetBackground3D   PROTO((Nlm_Viewer3D viewer,
297                                                   Nlm_Uint1 red,
298                                                   Nlm_Uint1 green,
299                                                   Nlm_Uint1 blue));
300 
301 /* Standard set of the viewer controls
302  */
303 extern Nlm_Controls3D Nlm_CreateControls3D PROTO((GrouP prnt,
304                                                   Boolean vertical,
305                                                   Boolean anim_ctrl,
306                                                   GrouP  *ctrl_group));
307 extern void          Nlm_LinkControls3D    PROTO((Nlm_Controls3D controls,
308                                                   Nlm_Viewer3D viewer));
309 
310 /* Remove the group containig the viewer controls;
311  * whenever the group is removed, the controls' internal data gets destroyed
312  */
313 extern void          Nlm_DeleteControls3D  PROTO((Nlm_Controls3D controls));
314 
315 
316 /* Aux. functions for the viewer MA and PaneL callbacks
317  */
318 extern Nlm_Viewer3D Nlm_MAToViewer3D       PROTO((MAPtr ma));
319 extern Nlm_Viewer3D Nlm_PanelToViewer3D    PROTO((PaneL panel));
320 
321 
322 extern Boolean       Nlm_SetStdMouse3D     PROTO((Nlm_Viewer3D viewer,
323                                                   Nlm_enumStdMA3D action));
324 
325 /* Auxiliary functions, that can be used in button callbacks
326  */
327 extern void          BgColorDlg3D         PROTO((Nlm_Viewer3D viewer));
328 extern void          Nlm_ZoomAll3D        PROTO((Nlm_Viewer3D viewer));
329 extern void          Nlm_SetAdjust3D      PROTO((Nlm_Viewer3D viewer,
330                                                  Uint1 ajust));
331 extern void          Nlm_Adjust3D         PROTO((Nlm_Viewer3D viewer,
332                                                  Boolean plus));
333 extern void          Nlm_SaveViewer3D     PROTO((Nlm_Viewer3D viewer));
334 #ifndef WIN_MOTIF
335 extern void          Nlm_CopyViewer3D     PROTO((Nlm_Viewer3D viewer));
336 extern void          Nlm_PrintViewer3D    PROTO((Nlm_Viewer3D viewer));
337 #endif
338 
339 extern void 	     Nlm_PlayLayer3D      PROTO((Nlm_Viewer3D viewer));
340 extern void 	     Nlm_NextLayer3D      PROTO((Nlm_Viewer3D viewer));
341 extern void    	     Nlm_PrevLayer3D      PROTO((Nlm_Viewer3D viewer));
342 extern void	     Nlm_SetLayerTop3D    PROTO((Uint1 top));
343 extern Uint1         Nlm_GetLayerTop3D    PROTO((void));
344 extern Boolean       Nlm_IsPlaying3D      PROTO((void));
345 extern void          Nlm_StopPlaying3D    PROTO((void));
346 extern void          Nlm_StartPlaying3D   PROTO((Nlm_Viewer3D viewer));
347 extern void          Nlm_AllLayerSet3D(Nlm_Viewer3D viewer, Nlm_Boolean state);
348 
349 
350 
351 /*****************************************************************************
352 *
353 *   NAME REDEFINITION
354 *
355 *****************************************************************************/
356 #define Viewer3D            Nlm_Viewer3D
357 #define Camera3D            Nlm_Camera3D
358 #define Controls3D          Nlm_Controls3D
359 #define Camera3DPtr         Nlm_Camera3DPtr
360 #define V3DControlsPtr      Nlm_V3DControlsPtr
361 #define CreateViewer3D      Nlm_CreateViewer3D
362 #define SetPosition3D       Nlm_SetPosition3D
363 #define CreateControls3D    Nlm_CreateControls3D
364 #define LinkControls3D      Nlm_LinkControls3D
365 #define DeleteControls3D    Nlm_DeleteControls3D
366 #define GetViewerImage3D    Nlm_GetViewerImage3D
367 #define DeleteViewer3D      Nlm_DeleteViewer3D
368 #define AttachPicture3D     Nlm_AttachPicture3D
369 #define GetViewerInfo3D     Nlm_GetViewerInfo3D
370 #define RedrawViewer3D      Nlm_RedrawViewer3D
371 #define FindPrim3D          Nlm_FindPrim3D
372 #define GetFoundPrim3D      Nlm_GetFoundPrim3D
373 #define SetHLColor3D        Nlm_SetHLColor3D
374 #define HighlightSeg3D      Nlm_HighlightSeg3D
375 #define IsSeg3DHlighted     Nlm_IsSeg3DHlighted
376 #define HighlightPrim3D     Nlm_HighlightPrim3D
377 #define IsPrim3DHlighted    Nlm_IsPrim3DHlighted
378 #define ResetHighlight3D    Nlm_ResetHighlight3D
379 #define MapWorldToViewer3D  Nlm_MapWorldToViewer3D
380 #define SetBackground3D     Nlm_SetBackground3D
381 
382 #define MAToViewer3D        Nlm_MAToViewer3D
383 #define PanelToViewer3D     Nlm_PanelToViewer3D
384 #define SetStdMouse3D       Nlm_SetStdMouse3D
385 #define GetStdMouse3D       Nlm_SetStdMouse3D
386 
387 #define ZoomAll3D           Nlm_ZoomAll3D
388 #define SetAdjust3D         Nlm_SetAdjust3D
389 #define Adjust3D            Nlm_Adjust3D
390 #define SaveViewer3D        Nlm_SaveViewer3D
391 #ifndef WIN_MOTIF
392 #define CopyViewer3D        Nlm_CopyViewer3D
393 #define PrintViewer3D       Nlm_PrintViewer3D
394 #endif
395 #define PlayLayer3D	    Nlm_PlayLayer3D
396 #define NextLayer3D         Nlm_NextLayer3D
397 #define PrevLayer3D   	    Nlm_PrevLayer3D
398 #define SetLayerTop3D       Nlm_SetLayerTop3D
399 #define GetLayerTop3D       Nlm_GetLayerTop3D
400 #define IsPlaying3D         Nlm_IsPlaying3D
401 #define StopPlaying3D       Nlm_StopPlaying3D
402 #define StartPlaying3D      Nlm_StartPlaying3D
403 
404 
405 #ifdef __cplusplus
406 }
407 #endif
408 
409 #endif
410 
411