[brlcad-commits] SF.net SVN: brlcad:[39588] brlcad/trunk/src/conv/obj-g_new.c
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <r_...@us...> - 2010-06-10 22:22:48
|
Revision: 39588 http://brlcad.svn.sourceforge.net/brlcad/?rev=39588&view=rev Author: r_weiss Date: 2010-06-10 22:22:41 +0000 (Thu, 10 Jun 2010) Log Message: ----------- adding documentation and performing style cleanup Modified Paths: -------------- brlcad/trunk/src/conv/obj-g_new.c Modified: brlcad/trunk/src/conv/obj-g_new.c =================================================================== --- brlcad/trunk/src/conv/obj-g_new.c 2010-06-10 21:30:18 UTC (rev 39587) +++ brlcad/trunk/src/conv/obj-g_new.c 2010-06-10 22:22:41 UTC (rev 39588) @@ -17,6 +17,13 @@ * License along with this file; see the file named COPYING for more * information. */ +/** + * + * This is a program to convert a WaveFront Object file to a BRL-CAD + * database file. + * + * Example usage: obj-g -u m input.obj output.g + */ #include "common.h" @@ -51,7 +58,7 @@ The -X (NMG_debug_flag) option specifies debug bits for NMG's (see nmg.h).\n"; /* global definition */ -size_t *tmp_ptr = NULL ; +size_t *tmp_ptr = NULL; static int NMG_debug; /* saved arg of -X, for longjmp handling */ static int debug = 0; static int verbose = 0; @@ -114,30 +121,36 @@ void *index_arr_faces; /* face indices into vertex, normal ,texture vertex lists */ size_t *num_vertices_arr; /* number of vertices for each face within index_arr_faces */ size_t *obj_file_face_idx_arr; /* corresponds to the index of the face within the obj file. this - value is useful to trace face errors back to the obj file. */ + * value is useful to trace face errors back to the obj file. + */ struct bu_vls *raw_grouping_name; /* raw name of grouping from obj file; group/object/material/texture */ size_t num_faces; /* number of faces represented by index_arr_faces and num_vertices_arr */ size_t max_faces; /* maximum number of faces based on current memory allocation */ short int *face_status; /* test_face result, 0 = untested, 1 = valid, >1 = degenerate */ short int closure_status; /* i.e. SURF_UNTESTED, SURF_CLOSED, SURF_OPEN */ size_t tot_vertices; /* sum of contents of num_vertices_arr. note: if the face_type - includes normals and/or texture vertices, each vertex must have - an associated normal and/or texture vertice. therefore this - total is also the total of the associated normals and/or texture - vertices. */ + * includes normals and/or texture vertices, each vertex must have + * an associated normal and/or texture vertice. therefore this + * total is also the total of the associated normals and/or texture + * vertices. + */ int face_type; /* i.e. FACE_V, FACE_TV, FACE_NV or FACE_TNV */ int grouping_type; /* i.e. GRP_NONE, GRP_GROUP, GRP_OBJECT, GRP_MATERIAL or GRP_TEXTURE */ size_t grouping_index; /* corresponds to the index of the grouping name within the obj file. - this value is useful to append to the raw_grouping_name to - ensure the resulting name is unique. */ + * this value is useful to append to the raw_grouping_name to + * ensure the resulting name is unique. + */ size_t *vertex_fuse_map; /* maps the vertex index of duplicate (i.e. within tolerance) vertices - into a single vertex index. i.e. points all vertices close enough - together to a single vertex */ + * into a single vertex index. i.e. points all vertices close enough + * together to a single vertex + */ short int *vertex_fuse_flag; /* used during creation of vertex_fuse_map, indicates if the vertex - has already been tested for duplicates or the vertex is a duplicate - of an already processed vertex and does not need to be processed again */ + * has already been tested for duplicates or the vertex is a duplicate + * of an already processed vertex and does not need to be processed again + */ size_t vertex_fuse_offset; /* subtract this value from libobj vertex index to index into the fuse - array to find the libobj vertex index this vertex was fused to */ + * array to find the libobj vertex index this vertex was fused to + */ size_t num_vertex_fuse; /* number of elements in vertex_fuse_map and vertex_fuse_flag arrays */ size_t *texture_vertex_fuse_map; /* same as vertex_fuse_map but for texture vertex */ short int *texture_vertex_fuse_flag; /* same as vertex_fuse_flag but for texture vertex */ @@ -205,7 +218,17 @@ const size_t *attindex_arr_tnv_faces; /* obj_polygonal_tnv_faces */ }; -void collect_global_obj_file_attributes(struct ga_t *ga) { +/* + * C O L L E C T _ G L O B A L _ O B J _ F I L E _ A T T R I B U T E S + * + * Collects object file attributes from the libobj library for use by + * functions called later. Examples of collected attributes are the + * quantity of each face type, the quantity of each grouping type, + * the quantity of vertices, texture vertices, normals etc. + */ +void +collect_global_obj_file_attributes(struct ga_t *ga) +{ size_t i = 0; ga->numPolyAttr = obj_polygonal_attributes(ga->contents, &ga->polyattr_list); @@ -215,8 +238,9 @@ if (verbose > 1) { bu_log("list of all groups i.e. 'g' in OBJ file\n"); - for (i = 0 ; i < ga->numGroups ; i++) + for (i = 0 ; i < ga->numGroups ; i++) { bu_log("(%lu)(%s)\n", i, ga->str_arr_obj_groups[i]); + } } ga->numObjects = obj_objects(ga->contents, &ga->str_arr_obj_objects); @@ -224,8 +248,9 @@ if (verbose > 1) { bu_log("list of all object groups i.e. 'o' in OBJ file\n"); - for (i = 0 ; i < ga->numObjects ; i++) + for (i = 0 ; i < ga->numObjects ; i++) { bu_log("(%lu)(%s)\n", i, ga->str_arr_obj_objects[i]); + } } ga->numMaterials = obj_materials(ga->contents, &ga->str_arr_obj_materials); @@ -233,8 +258,9 @@ if (verbose > 1) { bu_log("list of all material names i.e. 'usemtl' in OBJ file\n"); - for (i = 0 ; i < ga->numMaterials ; i++) + for (i = 0 ; i < ga->numMaterials ; i++) { bu_log("(%lu)(%s)\n", i, ga->str_arr_obj_materials[i]); + } } ga->numTexmaps = obj_texmaps(ga->contents, &ga->str_arr_obj_texmaps); @@ -242,8 +268,9 @@ if (verbose > 1) { bu_log("list of all texture map names i.e. 'usemap' in OBJ file\n"); - for (i = 0 ; i < ga->numTexmaps ; i++) + for (i = 0 ; i < ga->numTexmaps ; i++) { bu_log("(%lu)(%s)\n", i, ga->str_arr_obj_texmaps[i]); + } } ga->numVerts = obj_vertices(ga->contents, &ga->vert_list); @@ -270,7 +297,15 @@ return; } -void cleanup_name(struct bu_vls *outputObjectName_ptr) { +/* + * C L E A N U P _ N A M E + * + * Replaces with underscore characters which are invalid for BRL-CAD + * primitive names and file names. + */ +void +cleanup_name(struct bu_vls *outputObjectName_ptr) +{ char *temp_str; int outputObjectName_length; int i; @@ -280,66 +315,92 @@ /* length does not include null */ outputObjectName_length = bu_vls_strlen(outputObjectName_ptr); - for ( i = 0 ; i < outputObjectName_length ; i++ ) - if (strchr("/\\=",(int)temp_str[i]) != (char *)NULL ) + for (i = 0 ; i < outputObjectName_length ; i++) { + if (strchr("/\\=",(int)temp_str[i]) != (char *)NULL) { temp_str[i] = '_'; + } + } return; } -/* compare function for bsearch for triangle indexes */ -/* compare function for qsort for function 'remove_duplicates' */ -static int comp_b(const void *p1, const void *p2) { +/* + * C O M P _ B + * + * Compare function used by the functions qsort and bsearch for + * sorting and searching an array of numbers. + */ +static int +comp_b(const void *p1, const void *p2) +{ size_t i = * (size_t *) p1; size_t j = * (size_t *) p2; return (int)(i - j); } -/* compare function for qsort for triangle indexes */ -static int comp(const void *p1, const void *p2) { +/* + * C O M P + * + * Compare function used by the function qsort for sorting an index + * into a multi-dimensional array. + */ +static int +comp(const void *p1, const void *p2) +{ size_t i = * (size_t *) p1; size_t j = * (size_t *) p2; return (int)(tmp_ptr[i] - tmp_ptr[j]); } -/* compare function for qsort for edges */ -static int comp_c(const void *p1, const void *p2) { +/* + * C O M P _ C + * + * Compare function used by the function qsort for sorting a 2D array + * of numbers. + */ +static int +comp_c(const void *p1, const void *p2) +{ edge_arr_2D_t i = (edge_arr_2D_t) p1; edge_arr_2D_t j = (edge_arr_2D_t) p2; - if ((i[0][0] - j[0][0]) != 0) + if ((i[0][0] - j[0][0]) != 0) { return (int)(i[0][0] - j[0][0]); - else + } else { return (int)(i[0][1] - j[0][1]); + } } -/* retrieves the coordinates and obj file indexes for the - vertex, normal and texture vertex for the current grouping - and indicated by the face index number of grouping and - vertex index number of face into the grouping array. - note: if the face_type indicates a type which some of - this information is not applicable, the not applicable - information will not be set. */ /* inputs: */ -void retrieve_coord_index(struct ga_t *ga, /* obj file global attributes */ - struct gfi_t *gfi, /* grouping face indices */ - size_t fi, /* face index number of grouping */ - size_t vi, /* vertex index number of face */ - /* outputs: */ - fastf_t *vc, /* vertex coordinates */ - fastf_t *nc, /* normal coordinates */ - fastf_t *tc, /* texture vertex coordinates */ - fastf_t *w, /* vertex weight */ - size_t *vofi, /* vertex obj file index */ - size_t *nofi, /* normal obj file index */ - size_t *tofi) { /* texture vertex obj file index */ +/* + * R E T R I E V E _ C O O R D _ I N D E X + * + * For a grouping of faces, retrieve the coordinates and obj file + * indexes of a specific vertex within a specific face in this + * grouping. If the face type indicates a type where some return + * information is non-applicable, then this non-applicable information + * will be undefined when this function returns. + */ +void /* inputs: */ +retrieve_coord_index(struct ga_t *ga, /* obj file global attributes */ + struct gfi_t *gfi, /* grouping face indices */ + size_t fi, /* face index number of grouping */ + size_t vi, /* vertex index number of face */ + /* outputs: */ + fastf_t *vc, /* vertex coordinates */ + fastf_t *nc, /* normal coordinates */ + fastf_t *tc, /* texture vertex coordinates */ + fastf_t *w, /* vertex weight */ + size_t *vofi, /* vertex obj file index */ + size_t *nofi, /* normal obj file index */ + size_t *tofi) /* texture vertex obj file index */ +{ + const size_t (*index_arr_v_faces) = NULL; /* used by v_faces */ + const size_t (*index_arr_tv_faces)[2] = NULL; /* used by tv_faces */ + const size_t (*index_arr_nv_faces)[2] = NULL; /* used by nv_faces */ + const size_t (*index_arr_tnv_faces)[3] = NULL; /* used by tnv_faces */ - const size_t (*index_arr_v_faces) = NULL ; /* used by v_faces */ - const size_t (*index_arr_tv_faces)[2] = NULL ; /* used by tv_faces */ - const size_t (*index_arr_nv_faces)[2] = NULL ; /* used by nv_faces */ - const size_t (*index_arr_tnv_faces)[3] = NULL ; /* used by tnv_faces */ - arr_1D_t index_arr_faces_1D = NULL; arr_2D_t index_arr_faces_2D = NULL; arr_3D_t index_arr_faces_3D = NULL; @@ -347,42 +408,45 @@ size_t fofi = gfi->obj_file_face_idx_arr[fi]; /* face obj file index */ switch (gfi->face_type) { - case FACE_V : + case FACE_V: index_arr_faces_1D = (arr_1D_t)(gfi->index_arr_faces); /* copy current vertex obj file index into vofi */ - *vofi = index_arr_faces_1D[fi][vi] ; + *vofi = index_arr_faces_1D[fi][vi]; /* used fused vertex index if available */ - if (gfi->vertex_fuse_map != NULL) + if (gfi->vertex_fuse_map != NULL) { *vofi = gfi->vertex_fuse_map[*vofi - gfi->vertex_fuse_offset]; + } /* copy current vertex coordinates into vc */ VMOVE(vc, ga->vert_list[*vofi]); /* copy current vertex weight into w */ - *w = ga->vert_list[*vofi][3] ; + *w = ga->vert_list[*vofi][3]; - if (debug) + if (debug) { bu_log("fi=(%lu)vi=(%lu)fofi=(%lu)vofi=(%lu)v=(%f)(%f)(%f)w=(%f)\n", fi, vi, fofi+1, *vofi+1, vc[0], vc[1], vc[2], *w); + } break; - case FACE_TV : + case FACE_TV: index_arr_faces_2D = (arr_2D_t)(gfi->index_arr_faces); /* copy current vertex coordinates into vc */ VMOVE(vc, ga->vert_list[index_arr_faces_2D[fi][vi][0]]); /* copy current vertex weight into w */ - *w = ga->vert_list[index_arr_faces_2D[fi][vi][0]][3] ; + *w = ga->vert_list[index_arr_faces_2D[fi][vi][0]][3]; /* copy current texture coordinate into tc */ VMOVE(tc, ga->texture_coord_list[index_arr_faces_2D[fi][vi][1]]); /* copy current vertex obj file index into vofi */ *vofi = index_arr_faces_2D[fi][vi][0]; /* copy current texture coordinate obj file index into tofi */ *tofi = index_arr_faces_2D[fi][vi][1]; - if (debug) + if (debug) { bu_log("fi=(%lu)vi=(%lu)fofi=(%lu)vofi=(%lu)tofi=(%lu)v=(%f)(%f)(%f)w=(%f)t=(%f)(%f)(%f)\n", fi, vi, fofi+1, *vofi+1, *tofi+1, vc[0], vc[1], vc[2], *w, tc[0], tc[1], tc[2]); + } break; - case FACE_NV : + case FACE_NV: index_arr_faces_2D = (arr_2D_t)(gfi->index_arr_faces); /* copy current vertex obj file index into vofi */ @@ -391,26 +455,28 @@ *nofi = index_arr_faces_2D[fi][vi][1]; /* use fused vertex index if available */ - if (gfi->vertex_fuse_map != NULL) + if (gfi->vertex_fuse_map != NULL) { *vofi = gfi->vertex_fuse_map[*vofi - gfi->vertex_fuse_offset]; + } /* copy current vertex coordinates into vc */ VMOVE(vc, ga->vert_list[*vofi]); /* copy current vertex weight into w */ - *w = ga->vert_list[*vofi][3] ; + *w = ga->vert_list[*vofi][3]; /* copy current normal into nc */ VMOVE(nc, ga->norm_list[*nofi]); - if (debug) + if (debug) { bu_log("fi=(%lu)vi=(%lu)fofi=(%lu)vofi=(%lu)nofi=(%lu)v=(%f)(%f)(%f)w=(%f)n=(%f)(%f)(%f)\n", fi, vi, fofi+1, *vofi+1, *nofi+1, vc[0], vc[1], vc[2], *w, nc[0], nc[1], nc[2]); + } break; - case FACE_TNV : + case FACE_TNV: index_arr_faces_3D = (arr_3D_t)(gfi->index_arr_faces); /* copy current vertex coordinates into vc */ VMOVE(vc, ga->vert_list[index_arr_faces_3D[fi][vi][0]]); /* copy current vertex weight into w */ - *w = ga->vert_list[index_arr_faces_3D[fi][vi][0]][3] ; + *w = ga->vert_list[index_arr_faces_3D[fi][vi][0]][3]; /* copy current texture coordinate into tc */ VMOVE(tc, ga->texture_coord_list[index_arr_faces_3D[fi][vi][1]]); /* copy current normal into nc */ @@ -421,32 +487,44 @@ *tofi = index_arr_faces_3D[fi][vi][1]; /* copy current normal obj file index into nofi */ *nofi = index_arr_faces_3D[fi][vi][2]; - if (debug) + if (debug) { bu_log("fi=(%lu)vi=(%lu)fofi=(%lu)vofi=(%lu)tofi=(%lu)nofi=(%lu)v=(%f)(%f)(%f)w=(%f)t=(%f)(%f)(%f)n=(%f)(%f)(%f)\n", fi, vi, fofi+1, *vofi+1, *tofi+1, *nofi+1, vc[0], vc[1], vc[2], *w, tc[0], tc[1], tc[2], nc[0], nc[1], nc[2]); + } break; - default: - bu_log("ERROR: logic error, invalid face_type in function 'retrieve_coord_index'\n"); - return; } return; } -/* forces new population of face_status array */ -size_t retest_grouping_faces(struct ga_t *ga, - struct gfi_t *gfi, - fastf_t conv_factor, /* conversion factor from obj file units to mm */ - struct bn_tol *tol) { - +/* + * R E T E S T _ G R O U P I N G _ F A C E S + * + * Within a given grouping of faces, test all the faces for + * degenerate conditions such as duplicate vertex indexes or the + * distance between any pair of vertices of a individual face are + * equal to or less than the distance tolerance. Test results for + * each face of the grouping is recorded to be used later. If a face + * was previously tested, this function will retest the face. + * Retesting is useful if a vertex fuse was performed after the last + * testing of the faces. + */ +size_t +retest_grouping_faces(struct ga_t *ga, + struct gfi_t *gfi, + fastf_t conv_factor, /* conversion factor from obj file units to mm */ + struct bn_tol *tol) +{ size_t face_idx = 0; size_t failed_face_count = 0; /* face_status is populated within test_face function */ - for ( face_idx = 0 ; face_idx < gfi->num_faces ; face_idx++ ) + for (face_idx = 0 ; face_idx < gfi->num_faces ; face_idx++) { /* 1 passed into test_face indicates forced retest */ - if ( test_face(ga, gfi, face_idx, conv_factor, tol, 1) ) + if (test_face(ga, gfi, face_idx, conv_factor, tol, 1)) { failed_face_count++; + } + } return failed_face_count; } @@ -457,24 +535,26 @@ 1 degenerate, <3 vertices 2 degenerate, duplicate vertex indexes 3 degenerate, vertices too close */ -int test_face(struct ga_t *ga, - struct gfi_t *gfi, - size_t face_idx, - fastf_t conv_factor, /* conversion factor from obj file units to mm */ - struct bn_tol *tol, - int force_retest) { /* force the retest of this face if it was already - tested, this is useful when we know a retest is - required such as when the previous test was performed - without fused vertices and now vertices are fused */ - +int +test_face(struct ga_t *ga, + struct gfi_t *gfi, + size_t face_idx, + fastf_t conv_factor, /* conversion factor from obj file units to mm */ + struct bn_tol *tol, + int force_retest) /* force the retest of this face if it was already + * tested, this is useful when we know a retest is + * required such as when the previous test was performed + * without fused vertices and now vertices are fused + */ +{ fastf_t tmp_v_o[3] = { 0.0, 0.0, 0.0 }; /* temporary vertex, referenced from outer loop */ fastf_t tmp_v_i[3] = { 0.0, 0.0, 0.0 }; /* temporary vertex, referenced from inner loop */ - fastf_t tmp_w = 0.0 ; /* temporary weight */ - fastf_t tmp_n[3] = { 0.0, 0.0, 0.0 }; /* temporary normal */ - fastf_t tmp_t[3] = { 0.0, 0.0, 0.0 }; /* temporary texture vertex */ - size_t nofi = 0; /* normal obj file index */ - size_t tofi = 0; /* texture vertex obj file index */ - fastf_t distance_between_vertices = 0.0 ; + fastf_t tmp_w = 0.0; /* temporary weight */ + fastf_t tmp_n[3] = { 0.0, 0.0, 0.0 }; /* temporary normal */ + fastf_t tmp_t[3] = { 0.0, 0.0, 0.0 }; /* temporary texture vertex */ + size_t nofi = 0; /* normal obj file index */ + size_t tofi = 0; /* texture vertex obj file index */ + fastf_t distance_between_vertices = 0.0; size_t vofi_o = 0; /* vertex obj file index, referenced from outer loop */ size_t vofi_i = 0; /* vertex obj file index, referenced from inner loop */ @@ -483,67 +563,73 @@ int degenerate_face = 0; /* if this face has already been tested, return the previous - results unless the force_retest flag is set */ + * results unless the force_retest flag is set + */ if (!force_retest) { - if ( gfi->face_status[face_idx] ) { + if (gfi->face_status[face_idx]) { /* subtract 1 since face_status value of 1 indicates - success and 0 indicates untested */ + * success and 0 indicates untested + */ return (gfi->face_status[face_idx] - 1); } } /* added 1 to internal index values so warning message index values - matches obj file index numbers. this is because obj file indexes - start at 1, internally indexes start at 0. changed the warning - message if grouping_type is GRP_NONE because the group name and - grouping index has no meaning to the user if grouping type is - GRP_NONE */ - - if ( gfi->num_vertices_arr[face_idx] < 3 ) { + * matches obj file index numbers. this is because obj file indexes + * start at 1, internally indexes start at 0. changed the warning + * message if grouping_type is GRP_NONE because the group name and + * grouping index has no meaning to the user if grouping type is + * GRP_NONE + */ + if (gfi->num_vertices_arr[face_idx] < 3) { degenerate_face = 1; - if ( gfi->grouping_type != GRP_NONE ) + if (gfi->grouping_type != GRP_NONE) { bu_log("WARNING: removed degenerate face (reason: < 3 vertices); obj file face group name = (%s) obj file face grouping index = (%lu) obj file face index = (%lu)\n", bu_vls_addr(gfi->raw_grouping_name), gfi->grouping_index, gfi->obj_file_face_idx_arr[face_idx] + 1); - else + } else { bu_log("WARNING: removed degenerate face (reason: < 3 vertices); obj file face index = (%lu)\n", gfi->obj_file_face_idx_arr[face_idx] + 1); + } } - while ( (vert < gfi->num_vertices_arr[face_idx]) && !degenerate_face ) { + while ((vert < gfi->num_vertices_arr[face_idx]) && !degenerate_face) { vert2 = vert+1; - while ( (vert2 < gfi->num_vertices_arr[face_idx]) && !degenerate_face ) { + while ((vert2 < gfi->num_vertices_arr[face_idx]) && !degenerate_face) { retrieve_coord_index(ga, gfi, face_idx, vert, tmp_v_o, tmp_n, tmp_t, &tmp_w, &vofi_o, &nofi, &tofi); retrieve_coord_index(ga, gfi, face_idx, vert2, tmp_v_i, tmp_n, tmp_t, &tmp_w, &vofi_i, &nofi, &tofi); - if ( vofi_o == vofi_i ) { + if (vofi_o == vofi_i) { /* test for duplicate vertex indexes in face */ degenerate_face = 2; - if ( gfi->grouping_type != GRP_NONE ) + if (gfi->grouping_type != GRP_NONE) { bu_log("WARNING: removed degenerate face (reason: duplicate vertex index); obj file face group name = (%s) obj file face grouping index = (%lu) obj file face index = (%lu) obj file vertex index = (%lu)\n", bu_vls_addr(gfi->raw_grouping_name), gfi->grouping_index, gfi->obj_file_face_idx_arr[face_idx] + 1, vofi_o + 1); - else + } else { bu_log("WARNING: removed degenerate face (reason: duplicate vertex index); obj file face index = (%lu) obj file vertex index = (%lu)\n", gfi->obj_file_face_idx_arr[face_idx] + 1, vofi_o + 1); + } } else { - /* test for vertices closer than tol.dist */ - /* tol.dist is assumed to be mm */ + /* test for vertices closer than tol.dist + * tol.dist is assumed to be mm + */ VSCALE(tmp_v_o, tmp_v_o, conv_factor); VSCALE(tmp_v_i, tmp_v_i, conv_factor); - if ( bn_pt3_pt3_equal(tmp_v_o, tmp_v_i, tol) ) { - distance_between_vertices = DIST_PT_PT(tmp_v_o, tmp_v_i) ; + if (bn_pt3_pt3_equal(tmp_v_o, tmp_v_i, tol)) { + distance_between_vertices = DIST_PT_PT(tmp_v_o, tmp_v_i); degenerate_face = 3; - if ( gfi->grouping_type != GRP_NONE ) + if (gfi->grouping_type != GRP_NONE) { bu_log("WARNING: removed degenerate face (reason: vertices too close); obj file face group name = (%s) obj file face grouping index = (%lu) obj file face index = (%lu) obj file vertice indexes (%lu) vs (%lu) tol.dist = (%lfmm) dist = (%fmm)\n", bu_vls_addr(gfi->raw_grouping_name), gfi->grouping_index, gfi->obj_file_face_idx_arr[face_idx] + 1, vofi_o + 1, vofi_i + 1, tol->dist, distance_between_vertices); - else + } else { bu_log("WARNING: removed degenerate face (reason: vertices too close); obj file face index = (%lu) obj file vertice indexes (%lu) vs (%lu) tol.dist = (%lfmm) dist = (%fmm)\n", gfi->obj_file_face_idx_arr[face_idx] + 1, vofi_o + 1, vofi_i + 1, tol->dist, distance_between_vertices); + } } } vert2++; @@ -557,7 +643,9 @@ return degenerate_face; } -void free_gfi(struct gfi_t **gfi) { +void +free_gfi(struct gfi_t **gfi) +{ if (*gfi != NULL) { bu_vls_free((*gfi)->raw_grouping_name); bu_free((*gfi)->raw_grouping_name, "(*gfi)->raw_grouping_name"); @@ -565,10 +653,12 @@ bu_free((*gfi)->num_vertices_arr, "(*gfi)->num_vertices_arr"); bu_free((*gfi)->obj_file_face_idx_arr, "(*gfi)->obj_file_face_idx_arr"); bu_free((*gfi)->face_status, "(*gfi)->face_status"); - if ((*gfi)->vertex_fuse_map != NULL) + if ((*gfi)->vertex_fuse_map != NULL) { bu_free((*gfi)->vertex_fuse_map,"(*gfi)->vertex_fuse_map"); - if ((*gfi)->texture_vertex_fuse_map != NULL) + } + if ((*gfi)->texture_vertex_fuse_map != NULL) { bu_free((*gfi)->texture_vertex_fuse_map,"(*gfi)->texture_vertex_fuse_map"); + } bu_free(*gfi, "*gfi"); *gfi = NULL; } @@ -576,71 +666,72 @@ } /* this function allocates all memory needed for the - gfi structure and its contents. gfi is expected to - be a null pointer when passed to this function. the - gfi structure and its contents is expected to be - freed outside this function. + * gfi structure and its contents. gfi is expected to + * be a null pointer when passed to this function. the + * gfi structure and its contents is expected to be + * freed outside this function. */ -void collect_grouping_faces_indexes(struct ga_t *ga, - struct gfi_t **gfi, - int face_type, - int grouping_type, - size_t grouping_index) { /* grouping_index is ignored if grouping_type - is set to GRP_NONE */ - +void +collect_grouping_faces_indexes(struct ga_t *ga, + struct gfi_t **gfi, + int face_type, + int grouping_type, + size_t grouping_index) /* grouping_index is ignored if grouping_type + * is set to GRP_NONE + */ +{ size_t numFaces = 0; /* number of faces of the current face_type in the entire obj file */ size_t i = 0; const size_t *attindex_arr_faces = (const size_t *)NULL; int found = 0; const char *name_str = (char *)NULL; - size_t setsize = 0 ; + size_t setsize = 0; const size_t *indexset_arr; size_t groupid = 0; - size_t *num_vertices_arr_tmp = NULL ; - size_t *obj_file_face_idx_arr_tmp = NULL ; + size_t *num_vertices_arr_tmp = NULL; + size_t *obj_file_face_idx_arr_tmp = NULL; - const size_t (*index_arr_v_faces) = NULL ; /* used by v_faces */ - const size_t (*index_arr_tv_faces)[2] = NULL ; /* used by tv_faces */ - const size_t (*index_arr_nv_faces)[2] = NULL ; /* used by nv_faces */ - const size_t (*index_arr_tnv_faces)[3] = NULL ; /* used by tnv_faces */ + const size_t (*index_arr_v_faces) = NULL; /* used by v_faces */ + const size_t (*index_arr_tv_faces)[2] = NULL; /* used by tv_faces */ + const size_t (*index_arr_nv_faces)[2] = NULL; /* used by nv_faces */ + const size_t (*index_arr_tnv_faces)[3] = NULL; /* used by tnv_faces */ arr_1D_t index_arr_faces_1D = NULL; arr_2D_t index_arr_faces_2D = NULL; arr_3D_t index_arr_faces_3D = NULL; /* number of faces of the current face_type from the entire obj file - which is found in the current grouping_type and current group */ + * which is found in the current grouping_type and current group + */ size_t numFacesFound = 0; /* number of additional elements to allocate memory - for when the currently allocated memory is exhausted */ + * for when the currently allocated memory is exhausted + */ const size_t max_faces_increment = 128; - if ( *gfi != NULL ) { + if (*gfi != NULL) { bu_log("ERROR: function collect_grouping_faces_indexes passed non-null for gfi\n"); return; } switch (face_type) { - case FACE_V : + case FACE_V: numFaces = ga->numFaces; attindex_arr_faces = ga->attindex_arr_v_faces; break; - case FACE_TV : + case FACE_TV: numFaces = ga->numTexFaces; attindex_arr_faces = ga->attindex_arr_tv_faces; break; - case FACE_NV : + case FACE_NV: numFaces = ga->numNorFaces; attindex_arr_faces = ga->attindex_arr_nv_faces; break; - case FACE_TNV : + case FACE_TNV: numFaces = ga->numTexNorFaces; attindex_arr_faces = ga->attindex_arr_tnv_faces; break; - default: - bu_log("ERROR: logic error, invalid face_type in function 'collect_grouping_faces_indexes'\n"); - return; } /* traverse list of all faces in OBJ file of current face_type */ @@ -654,71 +745,67 @@ /* for each type of grouping, check if current face is in current grouping */ switch (grouping_type) { - case GRP_NONE : + case GRP_NONE: found = 1; /* since there is no grouping, still need a somewhat useful name - for the brlcad primitive and region, set the name to the face_type - which is the inherent grouping */ + * for the brlcad primitive and region, set the name to the face_type + * which is the inherent grouping + */ switch (face_type) { - case FACE_V : - name_str = "v" ; + case FACE_V: + name_str = "v"; break; - case FACE_TV : - name_str = "tv" ; + case FACE_TV: + name_str = "tv"; break; - case FACE_NV : - name_str = "nv" ; + case FACE_NV: + name_str = "nv"; break; - case FACE_TNV : - name_str = "tnv" ; + case FACE_TNV: + name_str = "tnv"; break; - default: - bu_log("ERROR: logic error, invalid face_type in function 'collect_grouping_faces_indexes'\n"); - return; } break; - case GRP_GROUP : + case GRP_GROUP: /* setsize is the number of groups the current nv_face belongs to */ setsize = obj_groupset(ga->contents,face_attr->groupset_index,&indexset_arr); /* loop through each group this face is in */ for (groupid = 0 ; groupid < setsize ; groupid++) { /* if true, current face is in current group grouping */ - if ( grouping_index == indexset_arr[groupid] ) { + if (grouping_index == indexset_arr[groupid]) { found = 1; name_str = ga->str_arr_obj_groups[indexset_arr[groupid]]; } } break; - case GRP_OBJECT : + case GRP_OBJECT: /* if true, current face is in current object grouping */ - if ( grouping_index == face_attr->object_index ) { + if (grouping_index == face_attr->object_index) { found = 1; name_str = ga->str_arr_obj_objects[face_attr->object_index]; } break; - case GRP_MATERIAL : + case GRP_MATERIAL: /* if true, current face is in current material grouping */ - if ( grouping_index == face_attr->material_index ) { + if (grouping_index == face_attr->material_index) { found = 1; name_str = ga->str_arr_obj_materials[face_attr->material_index]; } break; - case GRP_TEXTURE : + case GRP_TEXTURE: /* if true, current face is in current texture map grouping */ - if ( grouping_index == face_attr->texmap_index ) { + if (grouping_index == face_attr->texmap_index) { found = 1; name_str = ga->str_arr_obj_texmaps[face_attr->texmap_index]; } break; - default: - bu_log("ERROR: logic error, invalid grouping_type in function 'collect_grouping_faces_indexes'\n"); - return; } /* if found the first face allocate the output structure and initial allocation - of the index_arr_faces, num_vertices_arr and obj_file_face_idx_arr arrays */ - if ( found && (numFacesFound == 0)) { + * of the index_arr_faces, num_vertices_arr and obj_file_face_idx_arr arrays + */ + if (found && (numFacesFound == 0)) { /* allocate memory for gfi structure */ *gfi = (struct gfi_t *)bu_calloc(1, sizeof(struct gfi_t), "gfi"); @@ -745,16 +832,18 @@ (*gfi)->num_texture_vertex_fuse = 0; /* set face_type, grouping_type, grouping_index inside gfi structure, - the purpose of this is so functions called later do not need to pass - this in seperately */ + * the purpose of this is so functions called later do not need to pass + * this in seperately + */ (*gfi)->face_type = face_type; (*gfi)->grouping_type = grouping_type; - if ( grouping_type != GRP_NONE ) { + if (grouping_type != GRP_NONE) { (*gfi)->grouping_index = grouping_index; } else { /* set grouping_index to face_type since if grouping_type is - GRP_NONE, inherently we are grouping by face_type and we - need a number for unique naming of the brlcad objects. */ + * GRP_NONE, inherently we are grouping by face_type and we + * need a number for unique naming of the brlcad objects. + */ (*gfi)->grouping_index = (size_t)abs(face_type); } @@ -763,7 +852,8 @@ bu_vls_init((*gfi)->raw_grouping_name); /* only need to copy in the grouping name for the first face found within the - grouping since all the faces in the grouping will have the same grouping name */ + * grouping since all the faces in the grouping will have the same grouping name + */ bu_vls_strcpy((*gfi)->raw_grouping_name, name_str); /* sets initial number of elements to allocate memory for */ @@ -777,62 +867,57 @@ /* allocate initial memory for (*gfi)->index_arr_faces based on face_type */ switch (face_type) { - case FACE_V : + case FACE_V: (*gfi)->index_arr_faces = (void *)bu_calloc((*gfi)->max_faces, sizeof(arr_1D_t), "index_arr_faces"); index_arr_faces_1D = (arr_1D_t)((*gfi)->index_arr_faces); break; - case FACE_TV : - case FACE_NV : + case FACE_TV: + case FACE_NV: (*gfi)->index_arr_faces = (void *)bu_calloc((*gfi)->max_faces, sizeof(arr_2D_t), "index_arr_faces"); index_arr_faces_2D = (arr_2D_t)((*gfi)->index_arr_faces); break; - case FACE_TNV : + case FACE_TNV: (*gfi)->index_arr_faces = (void *)bu_calloc((*gfi)->max_faces, sizeof(arr_3D_t), "index_arr_faces"); index_arr_faces_3D = (arr_3D_t)((*gfi)->index_arr_faces); break; - default: - bu_log("ERROR: logic error, invalid face_type in function 'collect_grouping_faces_indexes'\n"); - return; } } - if ( found ) { + if (found) { /* assign obj file face index into array for tracking errors back - to the face within the obj file */ + * to the face within the obj file + */ (*gfi)->obj_file_face_idx_arr[numFacesFound] = attindex_arr_faces[i]; switch (face_type) { - case FACE_V : + case FACE_V: (*gfi)->num_vertices_arr[numFacesFound] = \ obj_polygonal_v_face_vertices(ga->contents,i,&index_arr_v_faces); index_arr_faces_1D[numFacesFound] = index_arr_v_faces; break; - case FACE_TV : + case FACE_TV: (*gfi)->num_vertices_arr[numFacesFound] = \ obj_polygonal_tv_face_vertices(ga->contents,i,&index_arr_tv_faces); index_arr_faces_2D[numFacesFound] = index_arr_tv_faces; break; - case FACE_NV : + case FACE_NV: (*gfi)->num_vertices_arr[numFacesFound] = \ obj_polygonal_nv_face_vertices(ga->contents,i,&index_arr_nv_faces); index_arr_faces_2D[numFacesFound] = index_arr_nv_faces; break; - case FACE_TNV : + case FACE_TNV: (*gfi)->num_vertices_arr[numFacesFound] = \ obj_polygonal_tnv_face_vertices(ga->contents,i,&index_arr_tnv_faces); index_arr_faces_3D[numFacesFound] = index_arr_tnv_faces; break; - default: - bu_log("ERROR: logic error, invalid face_type in function 'collect_grouping_faces_indexes'\n"); - return; } (*gfi)->tot_vertices += (*gfi)->num_vertices_arr[numFacesFound]; /* if needed, increase size of (*gfi)->num_vertices_arr and (*gfi)->index_arr_faces */ - if ( numFacesFound >= (*gfi)->max_faces ) { + if (numFacesFound >= (*gfi)->max_faces) { (*gfi)->max_faces += max_faces_increment; num_vertices_arr_tmp = (size_t *)bu_realloc((*gfi)->num_vertices_arr, @@ -844,25 +929,22 @@ (*gfi)->obj_file_face_idx_arr = obj_file_face_idx_arr_tmp; switch (face_type) { - case FACE_V : + case FACE_V: (*gfi)->index_arr_faces = (void *)bu_realloc(index_arr_faces_1D, sizeof(arr_1D_t) * (*gfi)->max_faces, "index_arr_faces"); index_arr_faces_1D = (arr_1D_t)((*gfi)->index_arr_faces); break; - case FACE_TV : - case FACE_NV : + case FACE_TV: + case FACE_NV: (*gfi)->index_arr_faces = (void *)bu_realloc(index_arr_faces_2D, sizeof(arr_2D_t) * (*gfi)->max_faces, "index_arr_faces"); index_arr_faces_2D = (arr_2D_t)((*gfi)->index_arr_faces); break; - case FACE_TNV : + case FACE_TNV: (*gfi)->index_arr_faces = (void *)bu_realloc(index_arr_faces_3D, sizeof(arr_3D_t) * (*gfi)->max_faces, "index_arr_faces"); index_arr_faces_3D = (arr_3D_t)((*gfi)->index_arr_faces); break; - default: - bu_log("ERROR: logic error, invalid face_type in function 'collect_grouping_faces_indexes'\n"); - return; } } @@ -871,80 +953,84 @@ } /* numFaces loop, when loop exits, all faces have been reviewed */ - if ( numFacesFound ) { - (*gfi)->num_faces = numFacesFound ; + if (numFacesFound) { + (*gfi)->num_faces = numFacesFound; (*gfi)->face_status = (short int *)bu_calloc((*gfi)->num_faces, sizeof(short int), "face_status"); /* initialize array */ - for ( i = 0 ; i < (*gfi)->num_faces ; i++ ) + for (i = 0 ; i < (*gfi)->num_faces ; i++) { (*gfi)->face_status[i] = 0; - + } } else { - *gfi = NULL ; /* this should already be null if no faces were found */ + *gfi = NULL; /* this should already be null if no faces were found */ } return; } -void populate_triangle_indexes(struct ga_t *ga, - struct gfi_t *gfi, - struct ti_t *ti, - size_t face_idx, - int texture_mode, /* PROC_TEX, IGNR_TEX */ - int normal_mode) { /* PROC_NORM, IGNR_NORM */ - +void +populate_triangle_indexes(struct ga_t *ga, + struct gfi_t *gfi, + struct ti_t *ti, + size_t face_idx, + int texture_mode, /* PROC_TEX, IGNR_TEX */ + int normal_mode) /* PROC_NORM, IGNR_NORM */ +{ /* it is assumed that when this function is called, - the number of face vertices is >= 3 */ - - size_t vert_idx = 0; /* index into vertices within for-loop */ - size_t idx = 0; /* sub index */ - size_t num_new_tri = 0; /* number of new triangles to create */ - fastf_t tmp_v[3] = { 0.0, 0.0, 0.0 }; /* temporary vertex */ - fastf_t tmp_n[3] = { 0.0, 0.0, 0.0 }; /* temporary normal */ - fastf_t tmp_rn[3] = { 0.0, 0.0, 0.0 }; /* temporary reverse normal */ - fastf_t tmp_t[3] = { 0.0, 0.0, 0.0 }; /* temporary texture vertex */ - fastf_t tmp_w = 0.0 ; /* temporary weight */ - size_t vofi = 0; /* vertex obj file index */ - size_t nofi = 0; /* normal obj file index */ - size_t tofi = 0; /* texture vertex obj file index */ - size_t svofi = 0; /* start vertex obj file index */ - size_t snofi = 0; /* start normal obj file index */ - size_t stofi = 0; /* start texture vertex obj file index */ + * the number of face vertices is >= 3 + */ + size_t vert_idx = 0; /* index into vertices within for-loop */ + size_t idx = 0; /* sub index */ + size_t num_new_tri = 0; /* number of new triangles to create */ + fastf_t tmp_v[3] = {0.0, 0.0, 0.0}; /* temporary vertex */ + fastf_t tmp_n[3] = {0.0, 0.0, 0.0}; /* temporary normal */ + fastf_t tmp_rn[3] = {0.0, 0.0, 0.0}; /* temporary reverse normal */ + fastf_t tmp_t[3] = {0.0, 0.0, 0.0}; /* temporary texture vertex */ + fastf_t tmp_w = 0.0; /* temporary weight */ + size_t vofi = 0; /* vertex obj file index */ + size_t nofi = 0; /* normal obj file index */ + size_t tofi = 0; /* texture vertex obj file index */ + size_t svofi = 0; /* start vertex obj file index */ + size_t snofi = 0; /* start normal obj file index */ + size_t stofi = 0; /* start texture vertex obj file index */ size_t max_tri_increment = 128; tri_arr_1D_t index_arr_tri_1D = NULL; tri_arr_2D_t index_arr_tri_2D = NULL; tri_arr_3D_t index_arr_tri_3D = NULL; - if ( ti->index_arr_tri == (void *)NULL ) { + if (ti->index_arr_tri == (void *)NULL) { /* adjust ti->tri_type for texture_mode and normal_mode */ switch (gfi->face_type) { - case FACE_V : + case FACE_V: ti->tri_type = gfi->face_type; break; - case FACE_TV : - if (texture_mode == PROC_TEX) + case FACE_TV: + if (texture_mode == PROC_TEX) { ti->tri_type = gfi->face_type; - else + } else { ti->tri_type = FACE_V; + } break; - case FACE_NV : - if (normal_mode == PROC_NORM) + case FACE_NV: + if (normal_mode == PROC_NORM) { ti->tri_type = gfi->face_type; - else + } else { ti->tri_type = FACE_V; + } break; - case FACE_TNV : - if ((texture_mode == PROC_TEX) && (normal_mode == PROC_NORM)) + case FACE_TNV: + if ((texture_mode == PROC_TEX) && (normal_mode == PROC_NORM)) { ti->tri_type = gfi->face_type; - else if ((texture_mode == IGNR_TEX) && (normal_mode == IGNR_NORM)) + } else if ((texture_mode == IGNR_TEX) && (normal_mode == IGNR_NORM)) { ti->tri_type = FACE_V; - else if ((texture_mode == PROC_TEX) && (normal_mode == IGNR_NORM)) + } else if ((texture_mode == PROC_TEX) && (normal_mode == IGNR_NORM)) { ti->tri_type = FACE_TV; - else + } else { ti->tri_type = FACE_NV; + } break; } @@ -953,17 +1039,17 @@ /* allocate memory for initial 'ti->index_arr_tri' array */ switch (ti->tri_type) { - case FACE_V : + case FACE_V: /* 3 vertice indexes */ ti->index_arr_tri = (void *)bu_calloc(ti->max_tri * 3, sizeof(size_t), "triangle_indexes"); break; - case FACE_TV : + case FACE_TV: /* 3 vertice indexes + 3 texture vertice indexes */ - case FACE_NV : + case FACE_NV: /* 3 vertice indexes + 3 normal indexes */ ti->index_arr_tri = (void *)bu_calloc(ti->max_tri * 6, sizeof(size_t), "triangle_indexes"); break; - case FACE_TNV : + case FACE_TNV: /* 3 vertice indexes + 3 normal indexes + 3 texture vertice indexes */ ti->index_arr_tri = (void *)bu_calloc(ti->max_tri * 9, sizeof(size_t), "triangle_indexes"); break; @@ -971,31 +1057,32 @@ } switch (ti->tri_type) { - case FACE_V : + case FACE_V: index_arr_tri_1D = (tri_arr_1D_t)ti->index_arr_tri; break; - case FACE_TV : - case FACE_NV : + case FACE_TV: + case FACE_NV: index_arr_tri_2D = (tri_arr_2D_t)ti->index_arr_tri; break; - case FACE_TNV : + case FACE_TNV: index_arr_tri_3D = (tri_arr_3D_t)ti->index_arr_tri; break; } /* compute number of new triangles to create */ - if ( gfi->num_vertices_arr[face_idx] > 3 ) + if (gfi->num_vertices_arr[face_idx] > 3) { num_new_tri = gfi->num_vertices_arr[face_idx] - 2; - else + } else { num_new_tri = 1; + } /* find start indexes */ retrieve_coord_index(ga, gfi, face_idx, 0, tmp_v, tmp_n, tmp_t, &tmp_w, &svofi, &snofi, &stofi); /* populate triangle indexes array, if necessary, triangulate face */ - for ( vert_idx = 0 ; vert_idx < num_new_tri ; vert_idx++ ) { - for ( idx = 0 ; idx < 3 ; idx++ ) { - if ( !idx ) { /* use the same vertex for the start of each triangle */ + for (vert_idx = 0 ; vert_idx < num_new_tri ; vert_idx++) { + for (idx = 0 ; idx < 3 ; idx++) { + if (!idx) { /* use the same vertex for the start of each triangle */ vofi = svofi; nofi = snofi; tofi = stofi; @@ -1004,18 +1091,18 @@ tmp_t, &tmp_w, &vofi, &nofi, &tofi); } switch (ti->tri_type) { - case FACE_V : + case FACE_V: index_arr_tri_1D[ti->num_tri][idx] = vofi; break; - case FACE_TV : + case FACE_TV: index_arr_tri_2D[ti->num_tri][idx][0] = vofi; index_arr_tri_2D[ti->num_tri][idx][1] = tofi; break; - case FACE_NV : + case FACE_NV: index_arr_tri_2D[ti->num_tri][idx][0] = vofi; index_arr_tri_2D[ti->num_tri][idx][1] = nofi; break; - case FACE_TNV : + case FACE_TNV: index_arr_tri_3D[ti->num_tri][idx][0] = vofi; index_arr_tri_3D[ti->num_tri][idx][1] = tofi; index_arr_tri_3D[ti->num_tri][idx][2] = nofi; @@ -1025,21 +1112,21 @@ ti->num_tri++; /* increment this at the end since arrays start at zero */ /* if needed, increase size of 'ti->index_arr_tri' array */ - if ( ti->num_tri >= ti->max_tri ) { + if (ti->num_tri >= ti->max_tri) { ti->max_tri += max_tri_increment; switch (ti->tri_type) { - case FACE_V : + case FACE_V: ti->index_arr_tri = (void *)bu_realloc(index_arr_tri_1D, sizeof(size_t) * ti->max_tri * 3, "index_arr_tri"); index_arr_tri_1D = (tri_arr_1D_t)(ti->index_arr_tri); break; - case FACE_TV : - case FACE_NV : + case FACE_TV: + case FACE_NV: ti->index_arr_tri = (void *)bu_realloc(index_arr_tri_2D, sizeof(size_t) * ti->max_tri * 6, "index_arr_tri"); index_arr_tri_2D = (tri_arr_2D_t)(ti->index_arr_tri); break; - case FACE_TNV : + case FACE_TNV: ti->index_arr_tri = (void *)bu_realloc(index_arr_tri_3D, sizeof(size_t) * ti->max_tri * 9, "index_arr_tri"); index_arr_tri_3D = (tri_arr_3D_t)(ti->index_arr_tri); @@ -1049,58 +1136,60 @@ } } -void populate_sort_indexes(struct ti_t *ti) { - +void +populate_sort_indexes(struct ti_t *ti) +{ size_t idx = 0; size_t num_indexes = ti->num_tri * 3; switch (ti->tri_type) { - case FACE_V : + case FACE_V: /* vsi ... vertex sort index */ ti->vsi = (size_t *)bu_calloc(num_indexes, sizeof(size_t), "ti->vsi"); - for ( idx = 0 ; idx < num_indexes ; idx++ ) + for (idx = 0 ; idx < num_indexes ; idx++) { ti->vsi[idx] = idx; + } break; - case FACE_TV : + case FACE_TV: /* vsi ... vertex sort index */ ti->vsi = (size_t *)bu_calloc(num_indexes, sizeof(size_t), "ti->vsi"); /* tvsi ... texture vertex sort index */ ti->tvsi = (size_t *)bu_calloc(num_indexes, sizeof(size_t), "ti->tvsi"); - for ( idx = 0 ; idx < num_indexes ; idx++ ) { + for (idx = 0 ; idx < num_indexes ; idx++) { ti->vsi[idx] = idx * 2; ti->tvsi[idx] = (idx * 2) + 1; } break; - case FACE_NV : + case FACE_NV: /* vsi ... vertex sort index */ ti->vsi = (size_t *)bu_calloc(num_indexes, sizeof(size_t), "ti->vsi"); /* vnsi ... vertex normal sort index */ ti->vnsi = (size_t *)bu_calloc(num_indexes, sizeof(size_t), "ti->vnsi"); - for ( idx = 0 ; idx < num_indexes ; idx++ ) { + for (idx = 0 ; idx < num_indexes ; idx++) { ti->vsi[idx] = idx * 2; ti->vnsi[idx] = (idx * 2) + 1; } break; - case FACE_TNV : + case FACE_TNV: /* vsi ... vertex sort index */ ti->vsi = (size_t *)bu_calloc(num_indexes, sizeof(size_t), "ti->vsi"); /* tvsi ... texture vertex sort index */ ti->tvsi = (size_t *)bu_calloc(num_indexes, sizeof(size_t), "ti->tvsi"); /* vnsi ... vertex normal sort index */ ti->vnsi = (size_t *)bu_calloc(num_indexes, sizeof(size_t), "ti->vnsi"); - for ( idx = 0 ; idx < num_indexes ; idx++ ) { + for (idx = 0 ; idx < num_indexes ; idx++) { ti->vsi[idx] = idx * 3; ti->tvsi[idx] = (idx * 3) + 1; ti->vnsi[idx] = (idx * 3) + 2; } break; - default: - break; } return; } -void sort_indexes(struct ti_t *ti) { +void +sort_indexes(struct ti_t *ti) +{ size_t num_indexes = ti->num_tri * 3; /* tmp_ptr is global which is required for qsort */ @@ -1111,34 +1200,40 @@ (int (*)(const void *a, const void *b))comp); /* process vertex normal indexes */ - if ( ti->tri_type == FACE_NV || ti->tri_type == FACE_TNV ) + if (ti->tri_type == FACE_NV || ti->tri_type == FACE_TNV) { qsort(ti->vnsi, num_indexes, sizeof ti->vnsi[0], (int (*)(const void *a, const void *b))comp); + } /* process texture vertex indexes */ - if ( ti->tri_type == FACE_TV || ti->tri_type == FACE_TNV ) + if (ti->tri_type == FACE_TV || ti->tri_type == FACE_TNV) { qsort(ti->tvsi, num_indexes, sizeof ti->tvsi[0], (int (*)(const void *a, const void *b))comp); + } return; } -void create_unique_indexes(struct ti_t *ti) { +void +create_unique_indexes(struct ti_t *ti) +{ size_t last = 0; size_t idx = 0; size_t counter = 0; size_t num_indexes = ti->num_tri * 3; size_t *tmp_arr = (size_t *)ti->index_arr_tri; - /* process vertex indexes */ - /* count sorted and unique libobj vertex indexes */ + /* process vertex indexes, count sorted + * and unique libobj vertex indexes + */ last = tmp_arr[ti->vsi[0]]; ti->num_uvi = 1; - for (idx = 1; idx < num_indexes ; ++idx) + for (idx = 1; idx < num_indexes ; ++idx) { if (tmp_arr[ti->vsi[idx]] != last) { last = tmp_arr[ti->vsi[idx]]; ti->num_uvi++; } + } /* allocate unique triangle vertex index array */ ti->uvi = (size_t *)bu_calloc(ti->num_uvi, sizeof(size_t), "ti->uvi"); @@ -1146,30 +1241,33 @@ /* store unique triangle vertex index array */ counter = 0; last = tmp_arr[ti->vsi[0]]; - ti->uvi[counter] = last ; - for (idx = 1; idx < num_indexes ; ++idx) + ti->uvi[counter] = last; + for (idx = 1; idx < num_indexes ; ++idx) { if (tmp_arr[ti->vsi[idx]] != last) { last = tmp_arr[ti->vsi[idx]]; counter++; - ti->uvi[counter] = last ; + ti->uvi[counter] = last; } + } /* free 'triangle vertex sort index array' (ti->vsi) since - it is no longer needed since 'unique triangle vertex index - array' has been created. */ + * it is no longer needed since 'unique triangle vertex index + * array' has been created. + */ bu_free(ti->vsi, "ti->vsi"); /* end of process vertex indexes */ /* process vertex normal indexes */ - if ( ti->tri_type == FACE_NV || ti->tri_type == FACE_TNV ) { + if (ti->tri_type == FACE_NV || ti->tri_type == FACE_TNV) { /* count sorted and unique libobj vertex normal indexes */ last = tmp_arr[ti->vnsi[0]]; ti->num_uvni = 1; - for (idx = 1; idx < num_indexes ; ++idx) + for (idx = 1; idx < num_indexes ; ++idx) { if (tmp_arr[ti->vnsi[idx]] != last) { last = tmp_arr[ti->vnsi[idx]]; ti->num_uvni++; } + } /* allocate unique triangle vertex normal index array */ ti->uvni = (size_t *)bu_calloc(ti->num_uvni, sizeof(size_t), "ti->uvni"); @@ -1177,30 +1275,33 @@ /* store unique triangle vertex normal index array */ ... [truncated message content] |