struct rt_bot_internal * dup_bot( struct rt_bot_internal *bot_in ) { struct rt_bot_internal *bot; size_t i; RT_BOT_CK_MAGIC( bot_in ); BU_ALLOC(bot, struct rt_bot_internal); *bot = *bot_in; /* struct copy */ bot->faces = (int *)bu_calloc( bot_in->num_faces*3, sizeof( int ), "bot faces" ); for ( i=0; i<bot_in->num_faces*3; i++ ) bot->faces[i] = bot_in->faces[i]; bot->vertices = (fastf_t *)bu_calloc( bot_in->num_vertices*3, sizeof( fastf_t ), "bot verts" ); for ( i=0; i<bot_in->num_vertices*3; i++ ) bot->vertices[i] = bot_in->vertices[i]; if ( bot_in->thickness ) { bot->thickness = (fastf_t *)bu_calloc( bot_in->num_faces, sizeof( fastf_t ), "bot thickness" ); for ( i=0; i<bot_in->num_faces; i++ ) bot->thickness[i] = bot_in->thickness[i]; } if ( bot_in->face_mode ) { bot->face_mode = bu_bitv_dup( bot_in->face_mode ); } return bot; }
/* duplicate bot */ struct rt_bot_internal * dup_bot(struct rt_bot_internal *bot_in) { struct rt_bot_internal *bot; size_t i; RT_BOT_CK_MAGIC(bot_in); BU_ALLOC(bot, struct rt_bot_internal); bot->magic = bot_in->magic; bot->mode = bot_in->mode; bot->orientation = bot_in->orientation; bot->bot_flags = bot_in->bot_flags; bot->num_vertices = bot_in->num_vertices; bot->num_faces = bot_in->num_faces; bot->num_normals = bot_in->num_normals; bot->num_face_normals = bot_in->num_face_normals; bot->faces = (int *)bu_calloc(bot_in->num_faces * 3, sizeof(int), "bot faces"); for (i = 0; i < bot_in->num_faces * 3; i++) { bot->faces[i] = bot_in->faces[i]; } bot->vertices = (fastf_t *)bu_calloc(bot_in->num_vertices * 3, sizeof(fastf_t), "bot verts"); for (i = 0; i < bot_in->num_vertices * 3; i++) { bot->vertices[i] = bot_in->vertices[i]; } if ((bot_in->bot_flags & RT_BOT_PLATE) || (bot_in->bot_flags & RT_BOT_PLATE_NOCOS)) { if (bot_in->thickness) { bot->thickness = (fastf_t *)bu_calloc(bot_in->num_faces, sizeof(fastf_t), "bot thickness"); for (i = 0; i < bot_in->num_faces; i++) { bot->thickness[i] = bot_in->thickness[i]; } } else { bu_bomb("dup_bot(): flag should not say plate but thickness is null\n"); } } if (bot_in->face_mode) { bot->face_mode = bu_bitv_dup(bot_in->face_mode); } if (bot_in->bot_flags & RT_BOT_HAS_SURFACE_NORMALS) { bot->num_normals = bot_in->num_normals; bot->normals = (fastf_t *)bu_calloc(bot_in->num_normals * 3, sizeof(fastf_t), "BOT normals"); bot->face_normals = (int *)bu_calloc(bot_in->num_faces * 3, sizeof(int), "BOT face normals"); memcpy(bot->face_normals, bot_in->face_normals, bot_in->num_faces * 3 * sizeof(int)); } return bot; }
static int rt_mk_bot_w_normals( struct rt_wdb *fp, const char *name, unsigned char botmode, unsigned char orientation, unsigned char flags, int num_vertices, int num_faces, fastf_t *vertices, /* array of floats for vertices [num_vertices*3] */ int *botfaces, /* array of ints for faces [num_faces*3] */ fastf_t *platethickness, /* array of plate mode thicknesses * (corresponds to array of faces) * NULL for modes RT_BOT_SURFACE and * RT_BOT_SOLID. */ struct bu_bitv *face_mode, /* a flag for each face indicating * thickness is appended to hit point, * otherwise thickness is centered * about hit point */ int num_normals, /* number of unit normals in normals array */ fastf_t *normals, /* array of floats for normals [num_normals*3] */ int *face_normals) /* array of ints (indices into normals * array), must have 3*num_faces * entries */ { struct rt_bot_internal *botip; int i; if ((num_normals > 0) && (db_version(fp->dbip) < 5)) { bu_log("You are using an old database format which does not support surface normals for BOT primitives\n"); bu_log("You are attempting to create a BOT primitive named \"%s\" with surface normals\n", name); bu_log("The surface normals will not be saved\n"); bu_log("Please upgrade to the current database format by using \"dbupgrade\"\n"); } BU_ALLOC(botip, struct rt_bot_internal); botip->magic = RT_BOT_INTERNAL_MAGIC; botip->mode = botmode; botip->orientation = orientation; botip->bot_flags = flags; botip->num_vertices = num_vertices; botip->num_faces = num_faces; botip->vertices = (fastf_t *)bu_calloc(num_vertices * 3, sizeof(fastf_t), "botip->vertices"); for (i = 0; i < num_vertices * 3; i++) botip->vertices[i] = vertices[i]; botip->faces = (int *)bu_calloc(num_faces * 3, sizeof(int), "botip->faces"); for (i = 0; i < num_faces * 3; i++) botip->faces[i] = botfaces[i]; if (mode == RT_BOT_PLATE) { botip->thickness = (fastf_t *)bu_calloc(num_faces, sizeof(fastf_t), "botip->thickness"); for (i = 0; i < num_faces; i++) botip->thickness[i] = platethickness[i]; botip->face_mode = bu_bitv_dup(face_mode); } else { botip->thickness = (fastf_t *)NULL; botip->face_mode = (struct bu_bitv *)NULL; } if ((num_normals > 0) && (db_version(fp->dbip) > 4)) { botip->num_normals = num_normals; botip->num_face_normals = botip->num_faces; botip->normals = (fastf_t *)bu_calloc(botip->num_normals * 3, sizeof(fastf_t), "BOT normals"); botip->face_normals = (int *)bu_calloc(botip->num_faces * 3, sizeof(int), "BOT face normals"); memcpy(botip->normals, normals, botip->num_normals * 3 * sizeof(fastf_t)); memcpy(botip->face_normals, face_normals, botip->num_faces * 3 * sizeof(int)); } else { botip->bot_flags = 0; botip->num_normals = 0; botip->num_face_normals = 0; botip->normals = (fastf_t *)NULL; botip->face_normals = (int *)NULL; } return wdb_export(fp, name, (genptr_t)botip, ID_BOT, 1.0); }