1 /*
2  * vp_renderR.c
3  *
4  * Function to render raw (unclassified) volumes.
5  *
6  * Copyright (c) 1994 The Board of Trustees of The Leland Stanford
7  * Junior University.  All rights reserved.
8  *
9  * Permission to use, copy, modify and distribute this software and its
10  * documentation for any purpose is hereby granted without fee, provided
11  * that the above copyright notice and this permission notice appear in
12  * all copies of this software and that you do not sell the software.
13  * Commercial licensing is available by contacting the author.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
17  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  * Author:
20  *    Phil Lacroute
21  *    Computer Systems Laboratory
22  *    Electrical Engineering Dept.
23  *    Stanford University
24  */
25 
26 /*
27  * $Date: 1994/12/30 23:52:38 $
28  * $Revision: 1.23 $
29  */
30 
31 #include "vp_global.h"
32 
33 #define COMP_AR1PB_FUNC		VPCompAR1PB
34 extern void VPCompAR1PB();
35 
36 #define COMP_AR3PB_FUNC		VPCompAR3PB
37 extern void VPCompAR3PB();
38 
39 #ifdef COMP_AR11B
40 #define COMP_AR11B_FUNC		VPCompAR11B
41 extern void VPCompAR11B();
42 #else
43 #define COMP_AR11B_FUNC		VPCompAR1NB
44 #endif
45 
46 #ifdef COMP_AR31B
47 #define COMP_AR31B_FUNC		VPCompAR31B
48 extern void VPCompAR31B();
49 #else
50 #define COMP_AR31B_FUNC		VPCompAR3NB
51 #endif
52 
53 #ifdef COMP_AR12B
54 #define COMP_AR12B_FUNC		VPCompAR12B
55 extern void VPCompAR12B();
56 #else
57 #define COMP_AR12B_FUNC		VPCompAR1NB
58 #endif
59 
60 #ifdef COMP_AR32B
61 #define COMP_AR32B_FUNC		VPCompAR32B
62 extern void VPCompAR32B();
63 #else
64 #define COMP_AR32B_FUNC		VPCompAR3NB
65 #endif
66 
67 #define COMP_AR1NB_FUNC		VPCompAR1NB
68 extern void VPCompAR1NB();
69 
70 #define COMP_AR3NB_FUNC		VPCompAR3NB
71 extern void VPCompAR3NB();
72 
73 
74 #define COMP_AR1PS_FUNC		VPCompAR1PB
75 
76 #define COMP_AR3PS_FUNC		VPCompAR3PB
77 
78 #ifdef COMP_AR11S
79 #define COMP_AR11S_FUNC		VPCompAR11S
80 extern void VPCompAR11S();
81 #else
82 #define COMP_AR11S_FUNC		VPCompAR1NS
83 #endif
84 
85 #ifdef COMP_AR31S
86 #define COMP_AR31S_FUNC		VPCompAR31S
87 extern void VPCompAR31S();
88 #else
89 #define COMP_AR31S_FUNC		VPCompAR3NS
90 #endif
91 
92 #ifdef COMP_AR12S
93 #define COMP_AR12S_FUNC		VPCompAR12S
94 extern void VPCompAR12S();
95 #else
96 #define COMP_AR12S_FUNC		VPCompAR1NS
97 #endif
98 
99 #ifdef COMP_AR32S
100 #define COMP_AR32S_FUNC		VPCompAR32S
101 extern void VPCompAR32S();
102 #else
103 #define COMP_AR32S_FUNC		VPCompAR3NS
104 #endif
105 
106 #define COMP_AR1NS_FUNC		VPCompAR1NS
107 extern void VPCompAR1NS();
108 
109 #define COMP_AR3NS_FUNC		VPCompAR3NS
110 extern void VPCompAR3NS();
111 
112 #ifdef INDEX_VOLUME
113 extern void VPCompAI11B();
114 #endif
115 
116 #define SHADOWS_OFF		0
117 #define SHADOWS_ON		1
118 #define SHADOW_OPTS		2
119 
120 #define MATERIAL_CALLBACK	0
121 #define MATERIAL_ONE		1
122 #define MATERIAL_TWO		2
123 #define MATERIAL_MORE		3
124 #define MATERIAL_OPTS		4
125 
126 #define COLOR_GRAY		0
127 #define COLOR_RGB		1
128 #define COLOR_OPTS		2
129 
130 static void (*AffineProcTable[SHADOW_OPTS][MATERIAL_OPTS][COLOR_OPTS])() = {
131     {
132 	{ COMP_AR1PB_FUNC, COMP_AR3PB_FUNC },
133 	{ COMP_AR11B_FUNC, COMP_AR31B_FUNC },
134 	{ COMP_AR12B_FUNC, COMP_AR32B_FUNC },
135 	{ COMP_AR1NB_FUNC, COMP_AR3NB_FUNC }
136     },
137     {
138 	{ COMP_AR1PS_FUNC, COMP_AR3PS_FUNC },
139 	{ COMP_AR11S_FUNC, COMP_AR31S_FUNC },
140 	{ COMP_AR12S_FUNC, COMP_AR32S_FUNC },
141 	{ COMP_AR1NS_FUNC, COMP_AR3NS_FUNC }
142     }
143 };
144 
145 /*
146  * vpRenderRawVolume
147  *
148  * Render an uclassified volume using the shear-warp algorithm.
149  */
150 
151 vpResult
vpRenderRawVolume(vpc)152 vpRenderRawVolume(vpc)
153 vpContext *vpc;
154 {
155     int retcode;
156     void (*composite_func)();
157     int shadow_option, material_option, color_option;
158 
159     /* check for errors and initialize */
160     if ((retcode = VPCheckRawVolume(vpc)) != VP_OK)
161 	return(retcode);
162     if ((retcode = VPCheckClassifier(vpc)) != VP_OK)
163 	return(retcode);
164     if ((retcode = VPCheckShader(vpc)) != VP_OK)
165 	return(retcode);
166     if ((retcode = VPCheckImage(vpc)) != VP_OK)
167 	return(retcode);
168     if (vpc->num_clsfy_params > 2)
169 	return(VPSetError(vpc, VPERROR_LIMIT_EXCEEDED));
170     if ((retcode = VPFactorView(vpc)) != VP_OK)
171 	return(retcode);
172 
173     Debug((vpc, VPDEBUG_RENDER, "Algorithm: affine RAWvolume (%s)\n",
174 	   vpc->mm_octree == NULL ? "no octree" : "with octree"));
175 
176     /* determine which options are enabled */
177     if (vpc->enable_shadows)
178 	shadow_option = SHADOWS_ON;
179     else
180 	shadow_option = SHADOWS_OFF;
181     if (vpc->shading_mode == CALLBACK_SHADER)
182 	material_option = MATERIAL_CALLBACK;
183     else if (vpc->num_materials == 1)
184 	material_option = MATERIAL_ONE;
185     else if (vpc->num_materials == 2)
186 	material_option = MATERIAL_TWO;
187     else
188 	material_option = MATERIAL_MORE;
189     if (vpc->color_channels == 1)
190 	color_option = COLOR_GRAY;
191     else
192 	color_option = COLOR_RGB;
193 
194     /* render */
195     if (vpc->affine_view) {
196 	/* choose a compositing function */
197 	composite_func = AffineProcTable[shadow_option][material_option]
198 					[color_option];
199 	VPRenderAffine(vpc, USE_RAWVOLUME, composite_func);
200     } else {
201 	/* XXX perspective rendering not available yet */
202 	return(VPSetError(vpc, VPERROR_BAD_OPTION));
203     }
204 
205     return(VP_OK);
206 }
207