1 /*
2  * vp_renderC.c
3  *
4  * Function to render classified 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.27 $
29  */
30 
31 #include "vp_global.h"
32 
33 #define COMP_AC1PB_FUNC		VPCompAC1PB
34 extern void VPCompAC1PB();
35 
36 #define COMP_AC3PB_FUNC		VPCompAC3PB
37 extern void VPCompAC3PB();
38 
39 #ifdef COMP_AC11B
40 #define COMP_AC11B_FUNC		VPCompAC11B
41 extern void VPCompAC11B();
42 #else
43 #define COMP_AC11B_FUNC		VPCompAC1NB
44 #endif
45 
46 #ifdef COMP_AC31B
47 #define COMP_AC31B_FUNC		VPCompAC31B
48 extern void VPCompAC31B();
49 #else
50 #define COMP_AC31B_FUNC		VPCompAC3NB
51 #endif
52 
53 #ifdef COMP_AC12B
54 #define COMP_AC12B_FUNC		VPCompAC12B
55 extern void VPCompAC12B();
56 #else
57 #define COMP_AC12B_FUNC		VPCompAC1NB
58 #endif
59 
60 #ifdef COMP_AC32B
61 #define COMP_AC32B_FUNC		VPCompAC32B
62 extern void VPCompAC32B();
63 #else
64 #define COMP_AC32B_FUNC		VPCompAC3NB
65 #endif
66 
67 #define COMP_AC1NB_FUNC		VPCompAC1NB
68 extern void VPCompAC1NB();
69 
70 #define COMP_AC3NB_FUNC		VPCompAC3NB
71 extern void VPCompAC3NB();
72 
73 
74 #define COMP_AC1PS_FUNC		VPCompAC1PB
75 
76 #define COMP_AC3PS_FUNC		VPCompAC3PB
77 
78 #ifdef COMP_AC11S
79 #define COMP_AC11S_FUNC		VPCompAC11S
80 extern void VPCompAC11S();
81 #else
82 #define COMP_AC11S_FUNC		VPCompAC1NS
83 #endif
84 
85 #ifdef COMP_AC31S
86 #define COMP_AC31S_FUNC		VPCompAC31S
87 extern void VPCompAC31S();
88 #else
89 #define COMP_AC31S_FUNC		VPCompAC3NS
90 #endif
91 
92 #ifdef COMP_AC12S
93 #define COMP_AC12S_FUNC		VPCompAC12S
94 extern void VPCompAC12S();
95 #else
96 #define COMP_AC12S_FUNC		VPCompAC1NS
97 #endif
98 
99 #ifdef COMP_AC32S
100 #define COMP_AC32S_FUNC		VPCompAC32S
101 extern void VPCompAC32S();
102 #else
103 #define COMP_AC32S_FUNC		VPCompAC3NS
104 #endif
105 
106 #define COMP_AC1NS_FUNC		VPCompAC1NS
107 extern void VPCompAC1NS();
108 
109 #define COMP_AC3NS_FUNC		VPCompAC3NS
110 extern void VPCompAC3NS();
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_AC1PB_FUNC, COMP_AC3PB_FUNC },
133 	{ COMP_AC11B_FUNC, COMP_AC31B_FUNC },
134 	{ COMP_AC12B_FUNC, COMP_AC32B_FUNC },
135 	{ COMP_AC1NB_FUNC, COMP_AC3NB_FUNC }
136     },
137     {
138 	{ COMP_AC1PS_FUNC, COMP_AC3PS_FUNC },
139 	{ COMP_AC11S_FUNC, COMP_AC31S_FUNC },
140 	{ COMP_AC12S_FUNC, COMP_AC32S_FUNC },
141 	{ COMP_AC1NS_FUNC, COMP_AC3NS_FUNC }
142     }
143 };
144 
145 /*
146  * vpRenderClassifiedVolume
147  *
148  * Render a classified, run-length encoded volume using the shear-warp
149  * algorithm.
150  */
151 
152 vpResult
vpRenderClassifiedVolume(vpc)153 vpRenderClassifiedVolume(vpc)
154 vpContext *vpc;
155 {
156     int retcode;
157     void (*composite_func)();
158     int shadow_option, material_option, color_option;
159 #ifdef INDEX_VOLUME
160     int have_index;
161 #endif
162 
163     /* check for errors and initialize */
164     if ((retcode = VPCheckShader(vpc)) != VP_OK)
165 	return(retcode);
166     if ((retcode = VPFactorView(vpc)) != VP_OK)
167 	return(retcode);
168     if ((retcode = VPCheckClassifiedVolume(vpc, vpc->best_view_axis)) != VP_OK)
169 	return(retcode);
170     if ((retcode = VPCheckImage(vpc)) != VP_OK)
171 	return(retcode);
172     if ((retcode = VPCheckShadows(vpc)) != VP_OK)
173 	return(retcode);
174 
175 #ifdef INDEX_VOLUME
176     switch (vpc->best_view_axis) {
177     case VP_X_AXIS:
178 	if (vpc->rle_x->voxel_index != NULL)
179 	    have_index = 1;
180 	else
181 	    have_index = 0;
182 	break;
183     case VP_Y_AXIS:
184 	if (vpc->rle_y->voxel_index != NULL)
185 	    have_index = 1;
186 	else
187 	    have_index = 0;
188 	break;
189     case VP_Z_AXIS:
190 	if (vpc->rle_z->voxel_index != NULL)
191 	    have_index = 1;
192 	else
193 	    have_index = 0;
194 	break;
195     default:
196 	VPBug("invalid viewing axis in vpRenderClassifiedVolume");
197     }
198 #endif /* INDEX_VOLUME */
199 
200     Debug((vpc, VPDEBUG_RENDER, "Algorithm: affine RLEvolume\n"));
201 
202     /* determine which options are enabled */
203     if (vpc->enable_shadows)
204 	shadow_option = SHADOWS_ON;
205     else
206 	shadow_option = SHADOWS_OFF;
207     if (vpc->shading_mode == CALLBACK_SHADER)
208 	material_option = MATERIAL_CALLBACK;
209     else if (vpc->num_materials == 1)
210 	material_option = MATERIAL_ONE;
211     else if (vpc->num_materials == 2)
212 	material_option = MATERIAL_TWO;
213     else
214 	material_option = MATERIAL_MORE;
215     if (vpc->color_channels == 1)
216 	color_option = COLOR_GRAY;
217     else
218 	color_option = COLOR_RGB;
219 
220     /* render */
221     if (vpc->affine_view) {
222 	/* choose a compositing function */
223 	composite_func = AffineProcTable[shadow_option][material_option]
224 					[color_option];
225 #ifdef INDEX_VOLUME
226 	if (have_index && shadow_option == SHADOWS_OFF &&
227 	    material_option == MATERIAL_ONE && color_option == COLOR_GRAY) {
228 	    composite_func = VPCompAI11B;
229 	}
230 #endif
231 	VPRenderAffine(vpc, USE_RLEVOLUME, composite_func);
232     } else {
233 	/* XXX perspective rendering not available yet */
234 	return(VPSetError(vpc, VPERROR_BAD_OPTION));
235     }
236 
237     return(VP_OK);
238 }
239