void parse_light(char *buffer){ LITE *pl; char *pamb, *pdiff, *pspec, *ppos, *pdir, *pang; my_assert ((num_lights < MAX_LIGHTS), "too many lights"); pl = &my_lights[++num_lights]; strtok(buffer, "()"); pamb = strtok(NULL, "()"); strtok(NULL, "()"); pdiff = strtok(NULL, "()"); strtok(NULL, "()"); pspec = strtok(NULL, "()"); strtok(NULL, "()"); ppos = strtok(NULL, "()"); strtok(NULL, "()"); pdir = strtok(NULL, "()"); strtok(NULL, "()"); pang = strtok(NULL, "()"); parse_floats(pamb, pl->amb); parse_floats(pdiff, pl->diff); parse_floats(pspec, pl->spec); parse_floats(ppos, pl->pos); if (pdir) { parse_floats(pdir, pl->dir); pl->angle = atof(pang); //printf("angle %f\n", pl->angle); } else pl->dir[0]= pl->dir[1]= pl->dir[2] =0; printf("read light\n"); }
void parse_camera(char *buffer){ CAM *pc; char *ppos, *plook, *pup; pc = &my_cam; strtok(buffer, "()"); ppos = strtok(NULL, "()"); strtok(NULL, "()"); plook = strtok(NULL, "()"); strtok(NULL, "()"); pup = strtok(NULL, "()"); strtok(NULL, "()"); parse_floats(ppos, pc->pos); parse_floats(plook, pc->at); parse_floats(pup, pc->up); pc->at[0] += pc->pos[0]; pc->at[1] += pc->pos[1]; pc->at[2] += pc->pos[2]; pc->dir[0] = pc->at[0] - pc->pos[0]; pc->dir[1] = pc->at[1] - pc->pos[1]; pc->dir[2] = pc->at[2] - pc->pos[2]; normalize(pc->dir); printf("read camera\n"); }
void parse_camera(char *buffer){ CAM *pc; char *ppos, *plook, *pup; pc = &my_cam; strtok(buffer, "()"); ppos = strtok(NULL, "()"); strtok(NULL, "()"); plook = strtok(NULL, "()"); strtok(NULL, "()"); pup = strtok(NULL, "()"); strtok(NULL, "()"); parse_floats(ppos, pc->pos); parse_floats(plook, pc->at); parse_floats(pup, pc->up); pc->at[0] += pc->pos[0]; pc->at[1] += pc->pos[1]; pc->at[2] += pc->pos[2]; pc->dir[0] = pc->at[0] - pc->pos[0]; pc->dir[1] = pc->at[1] - pc->pos[1]; pc->dir[2] = pc->at[2] - pc->pos[2]; normalize(pc->dir); //Set up camera values cam = new Camera(); cam->at[0] = pc->at[0]; cam->at[1] = pc->at[1]; cam->at[2] = pc->at[2]; cam->dir[0] = pc->dir[0]; cam->dir[1] = pc->dir[1]; cam->dir[2] = pc->dir[2]; cam->pos[0] = pc->pos[0]; cam->pos[1] = pc->pos[1]; cam->pos[2] = pc->pos[2]; cam->up[0] = pc->up[0]; cam->up[1] = pc->up[1]; cam->up[2] = pc->up[2]; //Create u,v,w for the first and only time. The rest of the time they just get altered cam->setUVW(); printf("read camera\n"); }
void parse_obj(char *buffer){ OBJECT *po; char *pshape, *pshine, *pemi, *pamb, *pdiff, *pspec, *ptranslate, *pscale, *protate; my_assert ((num_objects < NUM_OBJECTS), "too many objects"); po = &my_objects[num_objects++]; pshape = strtok(buffer, " "); //printf("pshape is %s\n",pshape); ptranslate = strtok(NULL, "()"); strtok(NULL, "()"); pscale = strtok(NULL, "()"); strtok(NULL, "()"); protate = strtok(NULL, "()"); strtok(NULL, "()"); pshine = strtok(NULL, "()");strtok(NULL, "()"); //printf("pshine is %s\n",pshine); pemi = strtok(NULL, "()"); strtok(NULL, "()"); pamb = strtok(NULL, "()"); strtok(NULL, "()"); pdiff = strtok(NULL, "()"); strtok(NULL, "()"); pspec = strtok(NULL, "()"); strtok(NULL, "()"); po->sid = atoi(pshape); po->shine = atof(pshine); parse_floats(ptranslate, po->translate); parse_floats(pscale, po->scale); parse_floats(protate, po->rotate); parse_floats(pemi, po->emi); parse_floats(pamb, po->amb); parse_floats(pdiff, po->diff); parse_floats(pspec, po->spec); // use switch to create your objects, cube given as example switch (po->sid){ case 1: //cube make_cube_smart(po, 1); break; } // scale, rotate, translate using your real tranformations from assignment 3 depending on input from spec file real_scaling(po, po->scale[0], po->scale[1], po->scale[2]); real_rotation(po, po->rotate[0], 1, 0, 0); real_rotation(po, po->rotate[1], 0, 1, 0); real_rotation(po, po->rotate[2], 0, 0, 1); real_translation(po, po->translate[0], po->translate[1], po->translate[2]); printf("read object\n"); }
int main(int argc, char *argv[]) { if (argc != 9 && argc != 8) { fprintf(stderr, "usage:\n\t" "%s a b method \"params\" step nscales lastscale [f]\n", *argv); // 0 1 2 3 4 5 6 7 8 return EXIT_FAILURE; } char *filename_a = argv[1]; char *filename_b = argv[2]; char *method_id = argv[3]; char *parstring = argv[4]; float scale_step = atof(argv[5]); int nscales = atoi(argv[6]); int last_scale = atoi(argv[7]); char *filename_f = argc > 8 ? argv[8] : "-"; float params[0x100]; int nparams = parse_floats(params, 0x100, parstring); int w, h, ww, hh; float *a = iio_read_image_float(filename_a, &w, &h); float *b = iio_read_image_float(filename_b, &ww, &hh); if (w != ww || h != hh) fail("input image size mismatch"); float *u = xmalloc(2 * w * h * sizeof(float)); float *v = u + w * h; // bound the number of scales to disallow images smaller than 16 pixels float Nscales = 1.5+log(BAD_MIN(w,h)/3.0)/log(fabs(scale_step)); if (Nscales < nscales) nscales = Nscales; multi_scale_optical_flow(method_id, params, nparams, u, v, a, b, w, h, nscales, scale_step, last_scale); iio_save_image_float_split(filename_f, u, w, h, 2); xfree(u); xfree(a); xfree(b); return EXIT_SUCCESS; }
void Config::get_RGB (const std::string& key, float* ret, float default_R, float default_G, float default_B) { std::string value = get (key); if (value.size()) { try { std::vector<default_type> V (parse_floats (value)); if (V.size() < 3) throw Exception ("malformed RGB entry \"" + value + "\" for key \"" + key + "\" in configuration file - ignored"); ret[0] = V[0]; ret[1] = V[1]; ret[2] = V[2]; } catch (Exception) { } } else { ret[0] = default_R; ret[1] = default_G; ret[2] = default_B; } }
void parse_obj(char *buffer){ OBJECT *po; char *pshape, *pshine, *pemi, *pamb, *pdiff, *pspec, *ptranslate, *pscale, *protate; Shape *s = NULL; my_assert ((num_objects < NUM_OBJECTS), "too many objects"); po = &my_objects[num_objects++]; pshape = strtok(buffer, " "); //printf("pshape is %s\n",pshape); ptranslate = strtok(NULL, "()"); strtok(NULL, "()"); pscale = strtok(NULL, "()"); strtok(NULL, "()"); protate = strtok(NULL, "()"); strtok(NULL, "()"); pshine = strtok(NULL, "()");strtok(NULL, "()"); //printf("pshine is %s\n",pshine); pemi = strtok(NULL, "()"); strtok(NULL, "()"); pamb = strtok(NULL, "()"); strtok(NULL, "()"); pdiff = strtok(NULL, "()"); strtok(NULL, "()"); pspec = strtok(NULL, "()"); strtok(NULL, "()"); po->sid = atoi(pshape); po->shine = atof(pshine); parse_floats(ptranslate, po->translate); parse_floats(pscale, po->scale); parse_floats(protate, po->rotate); parse_floats(pemi, po->emi); parse_floats(pamb, po->amb); parse_floats(pdiff, po->diff); parse_floats(pspec, po->spec); //Create the shape switch (po->sid) { case 1: //cube { s = new Shape(CUBE, 1, 1, 1, 1); break; } case 2: //house { s = new Shape(HOUSE, 1, 1, 1, 1); break; } case 3: { s = new Shape(SPHERE, 1, 1, 25, 25); break; } case 4: { s = new Shape(CYLINDER, 1, 1, 10, 10); break; } case 5: { s = new Shape(CONE, 1, 1, 10, 10); break; } case 6: //Torus { s = new Shape(1.2, .2, 15, 40); break; } } if (s != NULL) s->switchRenderMode(); // scale, rotate, translate the shape using the struct values real_scaling(s, po->scale[0], po->scale[1], po->scale[2]); real_rotation(s, po->rotate[0], 1, 0, 0); real_rotation(s, po->rotate[1], 0, 1, 0); real_rotation(s, po->rotate[2], 0, 0, 1); real_translation(s, po->translate[0], po->translate[1], po->translate[2]); //Add to list shapeList.push_back(s); printf("read object\n"); }
void parse_obj(char *buffer){ OBJECT *po; char *pshape, *pshine, *pemi, *pamb, *pdiff, *pspec, *ptranslate, *pscale, *protate; my_assert ((num_objects < NUM_OBJECTS), "too many objects"); po = &my_objects[num_objects++]; pshape = strtok(buffer, " "); //printf("pshape is %s\n",pshape); ptranslate = strtok(NULL, "()"); strtok(NULL, "()"); pscale = strtok(NULL, "()"); strtok(NULL, "()"); protate = strtok(NULL, "()"); strtok(NULL, "()"); pshine = strtok(NULL, "()");strtok(NULL, "()"); //printf("pshine is %s\n",pshine); pemi = strtok(NULL, "()"); strtok(NULL, "()"); pamb = strtok(NULL, "()"); strtok(NULL, "()"); pdiff = strtok(NULL, "()"); strtok(NULL, "()"); pspec = strtok(NULL, "()"); strtok(NULL, "()"); po->sid = atoi(pshape); po->shine = atof(pshine); parse_floats(ptranslate, po->translate); parse_floats(pscale, po->scale); parse_floats(protate, po->rotate); parse_floats(pemi, po->emi); parse_floats(pamb, po->amb); parse_floats(pdiff, po->diff); parse_floats(pspec, po->spec); po->center[0] = 0; po->center[1] = 0; po->center[2] = 0; po->center[3] = 1; //translation held_val[0] = po->center[0]; held_val[1] = po->center[1]; held_val[2] =po->center[2]; held_val[3] =po->center[3]; set_T(po->translate[0],po->translate[1],po->translate[2]); matrix_mult(T,held_val); po->center[0] = result[0]; po->center[1] = result[1]; po->center[2] = result[2]; po->center[3] = result[3]; //rotation point printf("objects center:\n x: %f\ny: %f\nz: %f\n",po->center[0],po->center[1],po->center[2]); // scale, rotate, translate using your real tranformations from assignment 3 depending on input from spec file printf("read object\n"); }