Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
vp_check.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "vp_global.h"
00032
00033
00034 static char *ErrorString[] = {
00035 "limit exceeded",
00036 "singular matrix or vector",
00037 "I/O error",
00038 "invalid buffer size",
00039 "invalid image definition",
00040 "invalid shader definition",
00041 "invalid classifier definition",
00042 "invalid volume definition",
00043 "invalid voxel definition",
00044 "invalid option",
00045 "argument out of range",
00046 "invalid file",
00047 "cannot compute shadow buffer",
00048 };
00049
00050
00051
00052
00053
00054
00055
00056 vpResult
00057 VPCheckVoxelFields(vpc)
00058 vpContext *vpc;
00059 {
00060 int f;
00061 int size, offset;
00062
00063 if (vpc->raw_bytes_per_voxel <= 0)
00064 return(VPSetError(vpc, VPERROR_BAD_VOXEL));
00065 if (vpc->num_voxel_fields <= 0)
00066 return(VPSetError(vpc, VPERROR_BAD_VOXEL));
00067 for (f = 0; f < vpc->num_voxel_fields; f++) {
00068 size = vpc->field_size[f];
00069 offset = vpc->field_offset[f];
00070 if (size != 1 && size != 2 && size != 4)
00071 return(VPSetError(vpc, VPERROR_BAD_VOXEL));
00072 if (offset < 0 || offset + size > vpc->raw_bytes_per_voxel)
00073 return(VPSetError(vpc, VPERROR_BAD_VOXEL));
00074 if (f > 0 && offset < vpc->field_size[f-1] + vpc->field_offset[f-1])
00075 return(VPSetError(vpc, VPERROR_BAD_VOXEL));
00076 }
00077 return(VP_OK);
00078 }
00079
00080
00081
00082
00083
00084
00085
00086 vpResult
00087 VPCheckRawVolume(vpc)
00088 vpContext *vpc;
00089 {
00090 int size, offset, retcode;
00091
00092 if ((retcode = VPCheckVoxelFields(vpc)) != VP_OK)
00093 return(retcode);
00094 if (vpc->xlen <= 0 || vpc->ylen <= 0 || vpc->zlen <= 0)
00095 return(VPSetError(vpc, VPERROR_BAD_VOLUME));
00096 if (vpc->raw_voxels == NULL)
00097 return(VPSetError(vpc, VPERROR_BAD_VOLUME));
00098 if (vpc->raw_bytes_per_voxel * vpc->xlen * vpc->ylen * vpc->zlen !=
00099 vpc->raw_voxels_size)
00100 return(VPSetError(vpc, VPERROR_BAD_VOLUME));
00101 return(VP_OK);
00102 }
00103
00104
00105
00106
00107
00108
00109
00110 vpResult
00111 VPCheckClassifiedVolume(vpc, axis)
00112 vpContext *vpc;
00113 int axis;
00114 {
00115 int retcode;
00116
00117 if ((retcode = VPCheckVoxelFields(vpc)) != VP_OK)
00118 return(retcode);
00119 if (vpc->xlen <= 0 || vpc->ylen <= 0 || vpc->zlen <= 0)
00120 return(VPSetError(vpc, VPERROR_BAD_VOLUME));
00121 if (vpc->rle_bytes_per_voxel == 0)
00122 return(VPSetError(vpc, VPERROR_BAD_VOLUME));
00123 switch (axis) {
00124 case VP_X_AXIS:
00125 if (vpc->rle_x == NULL)
00126 return(VPSetError(vpc, VPERROR_BAD_VOLUME));
00127 ASSERT(vpc->rle_x->ilen == vpc->ylen);
00128 ASSERT(vpc->rle_x->jlen == vpc->zlen);
00129 ASSERT(vpc->rle_x->klen == vpc->xlen);
00130 break;
00131 case VP_Y_AXIS:
00132 if (vpc->rle_y == NULL)
00133 return(VPSetError(vpc, VPERROR_BAD_VOLUME));
00134 ASSERT(vpc->rle_y->ilen == vpc->zlen);
00135 ASSERT(vpc->rle_y->jlen == vpc->xlen);
00136 ASSERT(vpc->rle_y->klen == vpc->ylen);
00137 break;
00138 case VP_Z_AXIS:
00139 if (vpc->rle_z == NULL)
00140 return(VPSetError(vpc, VPERROR_BAD_VOLUME));
00141 ASSERT(vpc->rle_z->ilen == vpc->xlen);
00142 ASSERT(vpc->rle_z->jlen == vpc->ylen);
00143 ASSERT(vpc->rle_z->klen == vpc->zlen);
00144 break;
00145 default:
00146 VPBug("bad axis in VPCheckClassifiedVolume");
00147 }
00148 return(VP_OK);
00149 }
00150
00151
00152
00153
00154
00155
00156
00157 vpResult
00158 VPCheckClassifier(vpc)
00159 vpContext *vpc;
00160 {
00161 int p, f;
00162 int size, offset, retcode;
00163
00164 if ((retcode = VPCheckVoxelFields(vpc)) != VP_OK)
00165 return(retcode);
00166 if (vpc->num_shade_fields <= 0 ||
00167 vpc->num_shade_fields > vpc->num_voxel_fields)
00168 return(VPSetError(vpc, VPERROR_BAD_VOXEL));
00169 if (vpc->num_clsfy_params <= 0 ||
00170 vpc->num_clsfy_params > vpc->num_voxel_fields)
00171 return(VPSetError(vpc, VPERROR_BAD_VOXEL));
00172 for (p = 0; p < vpc->num_clsfy_params; p++) {
00173 f = vpc->param_field[p];
00174 if (f < 0 || f >= vpc->num_voxel_fields)
00175 return(VPSetError(vpc, VPERROR_BAD_CLASSIFIER));
00176 if (vpc->clsfy_table[p] == NULL || vpc->clsfy_table_size[p] !=
00177 (vpc->field_max[f]+1)*sizeof(float))
00178 return(VPSetError(vpc, VPERROR_BAD_CLASSIFIER));
00179 if (p > 0 && f <= vpc->param_field[p-1])
00180 return(VPSetError(vpc, VPERROR_BAD_CLASSIFIER));
00181 }
00182 return(VP_OK);
00183 }
00184
00185
00186
00187
00188
00189
00190
00191 vpResult
00192 VPCheckShader(vpc)
00193 vpContext *vpc;
00194 {
00195 if (vpc->shading_mode == LOOKUP_SHADER) {
00196 if (vpc->color_field < 0 ||
00197 vpc->color_field >= vpc->num_voxel_fields ||
00198 vpc->color_field >= vpc->num_shade_fields)
00199 return(VPSetError(vpc, VPERROR_BAD_SHADER));
00200 if (vpc->shade_color_table == NULL)
00201 return(VPSetError(vpc, VPERROR_BAD_SHADER));
00202 if (vpc->shade_color_table_size != vpc->color_channels*sizeof(float)*
00203 (vpc->field_max[vpc->color_field]+1)*vpc->num_materials)
00204 return(VPSetError(vpc, VPERROR_BAD_SHADER));
00205 if (vpc->field_size[vpc->color_field] != 2)
00206 return(VPSetError(vpc, VPERROR_BAD_SHADER));
00207 if (vpc->num_materials < 1)
00208 return(VPSetError(vpc, VPERROR_BAD_SHADER));
00209 if (vpc->num_materials > 1) {
00210 if (vpc->weight_field < 0 ||
00211 vpc->weight_field >= vpc->num_voxel_fields ||
00212 vpc->weight_field >= vpc->num_shade_fields)
00213 return(VPSetError(vpc, VPERROR_BAD_SHADER));
00214 if (vpc->shade_weight_table == NULL)
00215 return(VPSetError(vpc, VPERROR_BAD_SHADER));
00216 if (vpc->shade_weight_table_size !=
00217 (vpc->field_max[vpc->weight_field]+1) * sizeof(float) *
00218 vpc->num_materials)
00219 return(VPSetError(vpc, VPERROR_BAD_SHADER));
00220 if (vpc->field_size[vpc->weight_field] != 1)
00221 return(VPSetError(vpc, VPERROR_BAD_SHADER));
00222 }
00223 }
00224 return(VP_OK);
00225 }
00226
00227
00228
00229
00230
00231
00232
00233 vpResult
00234 VPCheckImage(vpc)
00235 vpContext *vpc;
00236 {
00237 if (vpc->image == NULL || vpc->image_width <= 0 || vpc->image_height <= 0)
00238 return(VPSetError(vpc, VPERROR_BAD_IMAGE));
00239 switch (vpc->pixel_type) {
00240 case VP_ALPHA:
00241 break;
00242 case VP_LUMINANCE:
00243 case VP_LUMINANCEA:
00244 if (vpc->color_channels != 1)
00245 return(VPSetError(vpc, VPERROR_BAD_OPTION));
00246 break;
00247 case VP_RGB:
00248 case VP_BGR:
00249 case VP_RGBA:
00250 case VP_ABGR:
00251 if (vpc->color_channels != 3)
00252 return(VPSetError(vpc, VPERROR_BAD_OPTION));
00253 break;
00254 default:
00255 return(VPSetError(vpc, VPERROR_BAD_OPTION));
00256 }
00257 return(VP_OK);
00258 }
00259
00260
00261
00262
00263
00264
00265
00266 vpResult
00267 VPCheckShadows(vpc)
00268 vpContext *vpc;
00269 {
00270 if (vpc->enable_shadows) {
00271 if (vpc->shadow_light_num < VP_LIGHT0 ||
00272 vpc->shadow_light_num > VP_LIGHT5)
00273 return(VPSetError(vpc, VPERROR_BAD_OPTION));
00274 if (!vpc->light_enable[vpc->shadow_light_num - VP_LIGHT0])
00275 vpc->enable_shadows = 0;
00276 if (vpc->shadow_color_table_size != vpc->shade_color_table_size ||
00277 vpc->shadow_color_table == NULL)
00278 return(VPSetError(vpc, VPERROR_BAD_SIZE));
00279 }
00280 return(VP_OK);
00281 }
00282
00283
00284
00285
00286
00287
00288
00289
00290 vpResult
00291 vpGetError(vpc)
00292 vpContext *vpc;
00293 {
00294 vpResult code;
00295
00296 code = vpc->error_code;
00297 vpc->error_code = VP_OK;
00298 return(code);
00299 }
00300
00301
00302
00303
00304
00305
00306
00307 char *
00308 vpGetErrorString(code)
00309 vpResult code;
00310 {
00311 if (code == VP_OK)
00312 return("no error");
00313 else if (code < VPERROR_FIRST || code > VPERROR_LAST)
00314 return(NULL);
00315 else
00316 return(ErrorString[code - VPERROR_FIRST]);
00317 }
00318
00319
00320
00321
00322
00323
00324
00325 vpResult
00326 VPSetError(vpc, code)
00327 vpContext *vpc;
00328 vpResult code;
00329 {
00330 if (vpc->error_code == VP_OK)
00331 vpc->error_code = code;
00332 return(code);
00333 }