static void update_cube(struct cube *c) { c->c.x += c->delta.x; c->c.y += c->delta.y; c->c.z += c->delta.z; c->c.rx += c->delta.rx; c->c.ry += c->delta.ry; c->c.rz += c->delta.rz; if (c->c.z > 50.0) { init_cube(c, 3.0, N_CUBES_FAR); } }
int main(void) { Cube *CurCube = calloc(1, sizeof(Cube)); init_cube(CurCube); show_cube(CurCube); UpClockwise(CurCube); show_cube(CurCube); free(CurCube); return 0; }
void create_table(cube *(*construct_cube)(cube*), hash_cube_t (*hash_cube)(cube*), cube *(*reconstruct_stickers)(hash_cube_t*), int total_count ) { hash_set_t hash_set = new_hash_set(hash_cube_index, hash_cube_equals); queue q = new_queue(); cube *c0 = construct_cube(init_cube()); hash_cube_t h0 = hash_cube(c0); delete_cube(c0); enqueue(&q, h0); insert(&hash_set, &h0); int count = 0; int depth = 0; while (queue_size(&q) != 0) { int n = queue_size(&q); for (int i = 0; i < n; ++i) { ++count; if (count % 1000 == 0) { fprintf(stderr, "%f\n", (float) count / total_count); } hash_cube_t val = dequeue(&q); cube *c1 = reconstruct_stickers(&val); print_cube_flat(c1); printf(",%d\n", depth); for (int i = 0; i < 18; ++i) { cube *c2 = cube_expand[i](c1); hash_cube_t h1 = hash_cube(c2); if (!contains(&hash_set, &h1)) { enqueue(&q, h1); insert(&hash_set, &h1); } delete_cube(c2); } delete_cube(c1); } ++depth; } free_queue(&q); free_hash_set(&hash_set); }
/***********************************************************************//** * @brief Generate the exposure cube(s). * * This method reads the task parameters from the parfile, sets up the * observation container, loops over all CTA observations in the container * and generates an exposure cube from the CTA observations. ***************************************************************************/ void ctexpcube::run(void) { // If we're in debug mode then all output is also dumped on the screen if (logDebug()) { log.cout(true); } // Get task parameters get_parameters(); // Warn if there are not enough energy bins log_string(TERSE, warn_too_few_energies(m_expcube.energies())); // Write input observation container into logger log_observations(NORMAL, m_obs, "Input observation"); // Initialise exposure cube init_cube(); // Write header into logger log_header1(TERSE, "Generate exposure cube"); // Set pointer to logger dependent on chattiness GLog* logger = (logNormal()) ? &log : NULL; // Fill exposure cube m_expcube.fill(m_obs, logger); // Write exposure cube into logger log_string(EXPLICIT, m_expcube.print(m_chatter)); // Optionally publish exposure cube if (m_publish) { publish(); } // Return return; }
int main(int argc, char *argv[]) { const int winWidth = 300, winHeight = 300; Display *x_dpy; Window win; EGLSurface egl_surf; EGLContext egl_ctx; EGLDisplay egl_dpy; char *dpyName = NULL; GLboolean printInfo = GL_FALSE; EGLint egl_major, egl_minor; int i; const char *s; for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-display") == 0) { dpyName = argv[i+1]; i++; } else if (strcmp(argv[i], "-info") == 0) { printInfo = GL_TRUE; } else { usage(); return -1; } } x_dpy = XOpenDisplay(dpyName); if (!x_dpy) { printf("Error: couldn't open display %s\n", dpyName ? dpyName : getenv("DISPLAY")); return -1; } egl_dpy = eglGetDisplay(x_dpy); if (!egl_dpy) { printf("Error: eglGetDisplay() failed\n"); return -1; } if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) { printf("Error: eglInitialize() failed\n"); return -1; } s = eglQueryString(egl_dpy, EGL_VERSION); printf("EGL_VERSION = %s\n", s); s = eglQueryString(egl_dpy, EGL_VENDOR); printf("EGL_VENDOR = %s\n", s); s = eglQueryString(egl_dpy, EGL_EXTENSIONS); printf("EGL_EXTENSIONS = %s\n", s); s = eglQueryString(egl_dpy, EGL_CLIENT_APIS); printf("EGL_CLIENT_APIS = %s\n", s); make_x_window(x_dpy, egl_dpy, "OpenGL ES 2.x tri", 0, 0, winWidth, winHeight, &win, &egl_ctx, &egl_surf); XMapWindow(x_dpy, win); if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) { printf("Error: eglMakeCurrent() failed\n"); return -1; } if (printInfo) { printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); } init(); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); glDepthFunc(GL_LEQUAL); glDepthRangef(0.2f, 0.99f); glClearDepthf(0.999f); for (i = 0; i < N_CUBES; i++) { print_cube(&cubes[i]); init_cube(&cubes[i], 3.0, N_CUBES_FAR); print_cube(&cubes[i]); } /* Set initial projection/viewing transformation. * We can't be sure we'll get a ConfigureNotify event when the window * first appears. */ reshape(winWidth, winHeight); event_loop(x_dpy, win, egl_dpy, egl_surf); eglDestroyContext(egl_dpy, egl_ctx); eglDestroySurface(egl_dpy, egl_surf); eglTerminate(egl_dpy); XDestroyWindow(x_dpy, win); XCloseDisplay(x_dpy); return 0; }
static inline void init_cube(t_pt_c *cube) { cube[0] = (t_pt_c) { (t_v3f) {1.0f, 1.0f, 1.0f}, 0xff0000, (t_v2f) {0, 0}, 1 }; cube[1] = (t_pt_c) { (t_v3f) {1.0f, 1.0f, -1.0f}, 0x0000ff, (t_v2f) {0, 1}, 1 }; cube[2] = (t_pt_c) { (t_v3f) {-1.0f, 1.0f, -1.0f}, 0x00ffff, (t_v2f) {1, 0}, 1 }; cube[3] = (t_pt_c) { (t_v3f) {-1.0f, 1.0f, 1.0f}, 0x00ff00, (t_v2f) {1, 1}, 1 }; cube[4] = (t_pt_c) { (t_v3f) {1.0f, -1.0f, 1.0f}, 0xff0000, (t_v2f) {0, 0}, 0 }; cube[5] = (t_pt_c) { (t_v3f) {1.0f, -1.0f, -1.0f}, 0x0000ff, (t_v2f) {0, 1}, 0 }; cube[6] = (t_pt_c) { (t_v3f) {1.0f, 1.0f, -1.0f}, 0x00ffff, (t_v2f) {1, 0}, 0 }; cube[7] = (t_pt_c) { (t_v3f) {1.0f, 1.0f, 1.0f}, 0xb895cb, (t_v2f) {1, 1}, 0 }; cube[8] = (t_pt_c) { (t_v3f) {-1.0f, -1.0f, 1.0f}, 0xffab00, (t_v2f) {0, 0}, 0 }; cube[9] = (t_pt_c) { (t_v3f) {-1.0f, -1.0f, -1.0f}, 0x0cc0ff, (t_v2f) {0, 0}, 0 }; cube[10] = (t_pt_c) { (t_v3f) {1.0f, -1.0f, -1.0f}, 0xf0fff0, (t_v2f) {0, 0}, 0 }; cube[11] = (t_pt_c) { (t_v3f) {1.0f, -1.0f, 1.0f}, 0x053916, (t_v2f) {0, 0}, 0 }; cube[12] = (t_pt_c) { (t_v3f) {-1.0f, 1.0f, 1.0f}, 0xffffff, (t_v2f) {0, 0}, 0 }; cube[13] = (t_pt_c) { (t_v3f) {-1.0f, 1.0f, -1.0f}, 0x0000ff, (t_v2f) {0, 0}, 0 }; cube[14] = (t_pt_c) { (t_v3f) {-1.0f, -1.0f, -1.0f}, 0x00ffff, (t_v2f) {0, 0}, 0 }; cube[15] = (t_pt_c) { (t_v3f) {-1.0f, -1.0f, 1.0f}, 0x00ff00, (t_v2f) {0, 0}, 0 }; cube[16] = (t_pt_c) { (t_v3f) {1.0f, 1.0f, -1.0f}, 0x000000 >> 1, (t_v2f) {0, 0}, 0 }; cube[17] = (t_pt_c) { (t_v3f) {1.0f, -1.0f, -1.0f}, 0x0000ff >> 1, (t_v2f) {0, 0}, 0 }; cube[18] = (t_pt_c) { (t_v3f) {-1.0f, -1.0f, -1.0f}, 0x00ffff >> 1, (t_v2f) {0, 0}, 0 }; cube[19] = (t_pt_c) { (t_v3f) {-1.0f, 1.0f, -1.0f}, 0x00ff00, (t_v2f) {0, 0}, 0 }; cube[20] = (t_pt_c) { (t_v3f) {1.0f, -1.0f, 1.0f}, 0xff0000 << 1, (t_v2f) {0, 0}, 0 }; cube[21] = (t_pt_c) { (t_v3f) {1.0f, 1.0f, 1.0f}, 0x0000ff << 1, (t_v2f) {0, 0}, 0 }; cube[22] = (t_pt_c) { (t_v3f) {-1.0f, 1.0f, 1.0f}, 0x00fffa, (t_v2f) {0, 0}, 0 }; cube[23] = (t_pt_c) { (t_v3f) {-1.0f, -1.0f, 1.0f}, 0x341e09, (t_v2f) {0, 0}, 0 }; } static GLuint texture_load(const char *filepath) { glEnable(GL_TEXTURE_2D); return (SOIL_load_OGL_texture( filepath, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y)); } static int main_loop(GLFWwindow *window, GLuint texture, const char *filepath) { t_pt_c pts[POINTS]; load_obj(filepath); init_cube(pts); while ((!glfwWindowShouldClose(window)) && (!keyboard(window))) { (void)texture; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); display(texture, pts); glfwSwapBuffers(window); glfwPollEvents(); } glfwTerminate(); return (0); } void error_handler(int id, const char *str) { ft_printf("[%2d] error: %s\n", id, str); }
int alloc_bb (BB_struct * bp) { char command[MAX_STRING_LEN]; int i, sbnum; extern void srand48 (long); int errors = 0; Ctrl_str *cp; cp = bp->ctrl; /** aargh! \todo straghten this out! -- general*/ /*THUINET 18/02/05 */ int isol, ele_num, ele_1; int iphs, iphs_tot; /*FIN THUINET 18/02/05 */ /************************************************/ /* malloc an array of pointers to SB structures */ /************************************************/ fprintf (stderr, "Entering alloc_bb ...\n"); fprintf (stderr, "mallocing an array of pointers to SB str...\n"); if (!(bp->sb = (SB_struct * *)malloc (bp->ntsb * sizeof (SB_struct *)))) { fprintf (stderr, "ERROR: SB_struct pointer array malloc failed\n"); return (1); } for (sbnum = 0; sbnum < bp->ntsb; sbnum++) { if (init_sb (bp, sbnum) != 0) { fprintf (stderr, "exiting due to init_sb failure"); exit (2); } } /* create the mask and set to zero */ fprintf (stderr, "callocing SB mask ...\n"); if (!(bp->sb_mask = (int *) calloc (bp->ntsb, sizeof (int)))) { fprintf (stderr, "ERROR: SB_mask array malloc failed\n"); return (1); } /*and the supplementary pointer value structures */ /*fraction solid */ if (!(bp->c_fs_values = (Value_struct *) calloc (1, sizeof (Value_struct)))) { fprintf (stderr, "ERROR: c_fs pointer values malloc failed\n"); return (1); } else { if (!(bp->c_fs_values->block_array = (CA_FLOAT * *)calloc (bp->ntsb, sizeof (CA_FLOAT *)))) { fprintf (stderr, "ERROR: c_fs values malloc failed\n"); return (1); } bp->c_fs_values->part_coef = 1; /*correct conc. profile output if not C_LIQ */ sprintf (bp->c_fs_values->id_string, "FS_"); } /*schiel fraction solid */ if (!(bp->sch_fs_values = (Value_struct *) calloc (bp->ntsb, sizeof (Value_struct)))) { fprintf (stderr, "ERROR: sch_fs pointer values malloc failed\n"); return (1); } else { if (!(bp->sch_fs_values->block_array = (CA_FLOAT * *)calloc (bp->ntsb, sizeof (CA_FLOAT *)))) { fprintf (stderr, "ERROR: sch_fs values malloc failed\n"); return (1); } sprintf (bp->sch_fs_values->id_string, "SCH_"); } /*first solute (gas) */ if (!(bp->c_sol_values = (Value_struct *) calloc (bp->ntsb, sizeof (Value_struct)))) { fprintf (stderr, "ERROR: c_sol pointer values malloc failed\n"); return (1); } else { if (!(bp->c_sol_values->block_array = (CA_FLOAT * *)calloc (bp->ntsb, sizeof (CA_FLOAT *)))) { fprintf (stderr, "ERROR: c_sol values malloc failed\n"); return (1); } sprintf (bp->c_sol_values->id_string, "G_"); bp->c_sol_values->disp_max = cp->gas_disp_max; } /*second solute (alloy) */ if (!(bp->c_sol_alloy_values = (Value_struct *) calloc (bp->ntsb, sizeof (Value_struct)))) { fprintf (stderr, "ERROR: c_sol_alloy pointer values malloc failed\n"); exit (1); } else { if (!(bp->c_sol_alloy_values->block_array = (CA_FLOAT * *)calloc (bp->ntsb, sizeof (CA_FLOAT *)))) { fprintf (stderr, "ERROR: c_sol_alloy values malloc failed\n"); return (1); } sprintf (bp->c_sol_alloy_values->id_string, "A_"); bp->c_sol_alloy_values->disp_max = cp->alloy_disp_max; } /*and the supplementary int pointer arrays */ /*grain number */ if (!(bp->gr_array = (int **) calloc (bp->ntsb, sizeof (int *)))) { fprintf (stderr, "ERROR: pointer values malloc failed\n"); return (1); } /*finite element number */ if (!(bp->c_elm_array = (int **) calloc (bp->ntsb, sizeof (int *)))) { fprintf (stderr, "ERROR: pointer values malloc failed\n"); return (1); } /* holder for closed block (int) */ if (!(bp->intclosed = (int *) calloc (bp->ncsb, sizeof (int)))) { fprintf (stderr, "ERROR: pointer values malloc failed\n"); return (1); } /* holder for closed block (float) */ if (!(bp->floatclosed = (CA_FLOAT *) calloc (bp->ncsb, sizeof (CA_FLOAT)))) { fprintf (stderr, "ERROR: pointer values malloc failed\n"); return (1); } /*******************************************/ /* Init cubeptr structure for matrix copy */ /*******************************************/ init_cube (bp); init_facecode (&(bp->cubeptr), bp->nc, bp->dim); /************************************************/ /* Malloc temp CA_FLOAT and int arrays */ /************************************************/ i = (bp->nc[0] + 2) * (bp->nc[1] + 2) * (bp->nc[2] + 2); fprintf (stderr, "%s: total, nx, ny, nz, %d, %d, %d, %d\n", __func__, i, bp->nc[0], bp->nc[1], bp->nc[2]); /** \todo put temporary buffer arrays into the subblocks -- multiblock */ if (!(bp->ftmp_one = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) { fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n"); return (1); } if (!(bp->ftmp_two = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) { fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n"); return (1); } if (!(bp->ftmp_three = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) { fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n"); return (1); } /*by Wei WANG 11-07-02 */ if (!(bp->ftmp_four = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) { fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n"); return (1); } /*by Wei WANG 11-07-02 */ if (!(bp->ftmp_five = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) { fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n"); return (1); } /* modified to protect by options */ /**todo: Fine tune the options so as to avoid unnecessary memory allcation */ if ((bp->ctrl->curvature_3D !=0) || (bp->ctrl->curvature_2D != 0)){ /*xly 2004/09/06 */ if (!(bp->ftmp_nx = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) { fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n"); return (1); } /*xly 2004/09/06 */ if (!(bp->ftmp_ny = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) { fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n"); return (1); } /*dn00 2005/10/21*/ if (!(bp->ftmp_nz = (CA_FLOAT * ) calloc(i, sizeof(CA_FLOAT)))) { fprintf(stderr, "ERROR: tmp CA_FLOAT array malloc failed\n"); return(1); } } /*by THUINET 18-02-05 */ /* L Thuinet polycomponent data arrays */ if (bp->ctrl->diffuse_alloy_poly == 1) { ele_num = cp->NUM_COMP; /* number of elements in the alloy */ ele_1 = ele_num - 1; iphs_tot = cp->NUM_PHS; /* number of solid phases */ if (!(bp->itmp_nat_cell = (int *) calloc (i, sizeof (int)))) { fprintf (stderr, "ERROR: tmp int array malloc failed\n"); return (1); } if (!(bp->itmp_nat_grain = (int *) calloc (i, sizeof (int)))) { fprintf (stderr, "ERROR: tmp int array malloc failed\n"); return (1); } } else { ele_num = 2; ele_1 = 1; iphs_tot = 1; /* number of solid phases */ } /* loop through solutes */ for (isol = 0; isol < ele_1; isol++) { if (!(bp->ftmp_cl_poly[isol] = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) { fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n"); return (1); } if (!(bp->ftmp_ce_poly[isol] = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) { fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n"); return (1); } /* Value structures for polycomponent */ if (!(bp->poly_c_eqv_values[isol] = (Value_struct *) calloc (bp->ntsb, sizeof (Value_struct)))) { fprintf (stderr, "ERROR: calloc failed in %s at %s\n", __func__, __LINE__); return (1); } else { if (!(bp->poly_c_eqv_values[isol]->block_array = (CA_FLOAT * *)calloc (bp->ntsb, sizeof (CA_FLOAT *)))) { fprintf (stderr, "ERROR: calloc failed in %s at %s\n", __func__, __LINE__); return (1); } sprintf (bp->poly_c_eqv_values[isol]->id_string, "A_%i", isol); bp->poly_c_eqv_values[isol]->disp_max = cp->alloy_disp_max; } if (!(bp->poly_c_sol_values[isol] = (Value_struct *) calloc (bp->ntsb, sizeof (Value_struct)))) { fprintf (stderr, "ERROR: calloc failed in %s at %s\n", __func__, __LINE__); return (1); } else { if (!(bp->poly_c_sol_values[isol]->block_array = (CA_FLOAT * *)calloc (bp->ntsb, sizeof (CA_FLOAT *)))) { fprintf (stderr, "ERROR: calloc failed in %s at %s\n", __func__, __LINE__); return (1); } sprintf (bp->poly_c_sol_values[isol]->id_string, "A_%i", isol); bp->poly_c_sol_values[isol]->disp_max = cp->alloy_disp_max; } } /* end of isol loop through solutes */ /* loop through phases */ for (iphs = 0; iphs < iphs_tot; iphs++) { if (!(bp->ftmp_one_poly[iphs] = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) { fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n"); return (1); } /* Value structures for polycomponent phases */ if (!(bp->poly_c_fs_values[iphs] = (Value_struct *) calloc (bp->ntsb, sizeof (Value_struct)))) { fprintf (stderr, "ERROR: calloc failed in %s at %s\n", __func__, __LINE__); return (1); } else { if (!(bp->poly_c_fs_values[iphs]->block_array = (CA_FLOAT * *)calloc (bp->ntsb, sizeof (CA_FLOAT *)))) { fprintf (stderr, "ERROR: calloc failed in %s at %s\n", __func__, __LINE__); return (1); } sprintf (bp->poly_c_fs_values[iphs]->id_string, "FS_%i", iphs); bp->poly_c_fs_values[iphs]->disp_max = 1.0; } } /* end of iphs loop through phases */ /*FIN THUINET 18-02-05 */ /* malloc buffer for decented octahedron *//*by Wei WANG 11-07-02 */ if (cp->decentred_octahedron) { /*malloced only if decentred_ocathedron algorithm used */ if (!(bp->ftmp_dc_d = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) { fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n"); return (1); } if (!(bp->ftmp_dc_x = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) { fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n"); return (1); } if (!(bp->ftmp_dc_y = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) { fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n"); return (1); } if (!(bp->ftmp_dc_z = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) { fprintf (stderr, "ERROR: tmp CA_FLOAT array malloc failed\n"); return (1); } } #ifdef OLD_TUNDER if (!(bp->old_Tunder = (CA_FLOAT *) calloc (i, sizeof (CA_FLOAT)))) { fprintf (stderr, "ERROR: old_Tunder array malloc failed\n"); return (1); } #endif /*OLD_TUNDER */ if (!(bp->itmp_one = (int *) calloc (i, sizeof (int)))) { fprintf (stderr, "ERROR: tmp int array malloc failed\n"); return (1); } /*by Wei WANG 11-07-02 */ if (!(bp->itmp_two = (int *) calloc (i, sizeof (int)))) { fprintf (stderr, "ERROR: tmp int array malloc failed\n"); return (1); } /************************************************/ /* malloc an array of grain structures */ /************************************************/ if (!(bp->gr = (Ind_grain * *)calloc (bp->nprops.gd_max_total, sizeof (Ind_grain *)))) { fprintf (stderr, "ERROR: Ind_grain array malloc failed\n"); return (1); } if (bp->ctrl->fgrid_input) { /* the finite element grid structure */ if (!(bp->fg = (FGrid_str *) calloc (1, sizeof (FGrid_str)))) { fprintf (stderr, "ERROR: fg structure malloc failed\n"); return (1); } /* the finite element grid structure */ if (!(bp->fg_next = (FGrid_str *) calloc (1, sizeof (FGrid_str)))) { fprintf (stderr, "ERROR: fg structure malloc failed\n"); return (1); } } /*************************************/ /* Print out checks on input data... */ /*************************************/ fprintf (stderr, "sb_mask nsb: %d, %d, %d\n", bp->nsb[0], bp->nsb[1], bp->nsb[2]); fprintf (stderr, "Exiting alloc_bb().\n"); return (0); }