// runs the raytrace over all tests and saves the corresponding images int main(int argc, char** argv) { // test that glfw and glew are linked properly uiloop(); message("GLFW and GLEW seem to work\n\n"); // test max_component function vec3f v(1,2,-3); float max_val = max_component(v); message("Result of max_component: %f\n", max_val); // test sum of three vectors vec3f va(1,0,0); vec3f vb(0,4,0); vec3f vc(0,0,2); vec3f vabc = sum_three(va, vb, vc); message("Result of sum_three: %s\n", tostring(vabc).c_str()); // test sum of vectors vector<vec3f> vs = { {3.14,1.5,2.7}, {2.71,8.2,8.2}, {1.61,8.0,3.4}, {1.41,4.2,1.4}, }; vec3f vsum = sum_many(vs); message("Result of sum_many: %s\n", tostring(vsum).c_str()); message("\nThis message indicates a successful build!\n\n"); return 0; }
EXPORT bool scatter_front( Front *front) { COMPONENT max_comp; INTERFACE *intfc = front->interf; RECT_GRID *gr = front->rect_grid; bool status; bool sav_copy = copy_intfc_states(); bool sav_intrp = interpolate_intfc_states(intfc); int i, dim = gr->dim; DEBUG_ENTER(scatter_front) max_comp = max_component(intfc); pp_global_imax(&max_comp,1L); add_time_start(3); if ((dim == 3) && debugging("consistency")) { (void) printf("Check consistency of interface " "before scatter_front()\n"); if (!consistent_interface(intfc)) { screen("ERROR in scatter_front(), input interface is " "inconsistent\n"); clean_up(ERROR); } (void) printf("Interface into scatter_front is consistent\n"); } if (dim == 2) { for (i = 0; i < dim; ++i) if ((gr->lbuf[i] > 0) || (gr->ubuf[i] > 0)) break; if (i == dim) { DEBUG_LEAVE(scatter_front) status = FUNCTION_SUCCEEDED; /* No subdomains to process */ return pp_min_status(status); } } set_copy_intfc_states(YES); interpolate_intfc_states(intfc) = NO; status = form_subintfc_via_communication(front); //if(dim == 3) // delete_outside_surface(front->interf); max_comp = max_component(intfc); pp_global_imax(&max_comp,1L); max_component(intfc) = max_comp; interpolate_intfc_states(intfc) = sav_intrp; set_copy_intfc_states(sav_copy); if ((status) && (dim == 3) && debugging("consistency")) { (void) printf("Check consistency of interface "); (void) printf("after scatter_front()\n"); if (!consistent_interface(intfc)) { screen("ERROR in scatter_front(), output interface is " "inconsistent\n"); clean_up(ERROR); } } DEBUG_LEAVE(scatter_front) status = pp_min_status(status); add_time_end(3); return status; } /*end scatter_front*/
Shape* read_ply(const string& filename, bool flipface, bool normalize, bool flipyz) { FILE* f = fopen(filename.c_str(), "rt"); if(not f) ERROR("cannot open file %s", filename.c_str()); char line[LINE_SIZE]; // magic fgets(line, LINE_SIZE, f); if(not _startswith(line, "ply")) ERROR("unknown file format"); // format fgets(line, LINE_SIZE, f); if(not _startswith(line, "format")) ERROR("unknown file format"); // skip till vertex fgets(line, LINE_SIZE, f); while(not _startswith(line, "element vertex")) fgets(line, LINE_SIZE, f); // vertex int vertex_num = 0; sscanf(line, "element vertex %d", &vertex_num); // vertex props int vertex_pos = -1, vertex_norm = -1, vertex_uv = -1, vertex_col8 = -1, vertex_colf = -1; int vertex_vals = 0; fgets(line, LINE_SIZE, f); while(_startswith(line, "property")) { if(_startswith(line, "property float x") or _startswith(line, "property float32 x")) vertex_pos = vertex_vals; if(_startswith(line, "property float nx") or _startswith(line, "property float32 nx")) vertex_norm = vertex_vals; if(_startswith(line, "property uchar diffuse_red") or _startswith(line, "property uint8 diffuse_red")) vertex_col8 = vertex_vals; if(_startswith(line, "property uchar red") or _startswith(line, "property uint8 red")) vertex_col8 = vertex_vals; if(_startswith(line, "property float diffuse_red") or _startswith(line, "property float32 diffuse_red")) vertex_colf = vertex_vals; if(_startswith(line, "property float red") or _startswith(line, "property float32 red")) vertex_colf = vertex_vals; vertex_vals ++; fgets(line, LINE_SIZE, f); } // skip till faces while(not _startswith(line, "element face")) fgets(line, LINE_SIZE, f); // face int face_num = 0; sscanf(line, "element face %d", &face_num); // face props int face_start = -1; int face_vals = 0; fgets(line, LINE_SIZE, f); while(_startswith(line, "property")) { if(_startswith(line, "property list uchar int vertex_ind")) face_start = face_vals; if(_startswith(line, "property list uchar uint vertex_ind")) face_start = face_vals; if(_startswith(line, "property list uint8 int32 vertex_ind")) face_start = face_vals; if(_startswith(line, "property list char int vertex_ind")) face_start = face_vals; if(_startswith(line, "property list int8 int32 vertex_ind")) face_start = face_vals; face_vals ++; fgets(line, LINE_SIZE, f); } ERROR_IF_NOT(face_start>=0, "bad face start"); // skip till end of header while(not _startswith(line, "end_header")) fgets(line, LINE_SIZE, f); // read vertex data vector<vec3f> pos; vector<vec3f> norm; vector<vec2f> uv; for(int i = 0; i < vertex_num; i ++) { vector<float> vdata; for(int j = 0; j < vertex_vals; j ++) { float v; fscanf(f, "%f", &v); vdata.push_back(v); } pos.push_back( vec3f(vdata[vertex_pos+0],vdata[vertex_pos+1],vdata[vertex_pos+2]) ); if(vertex_norm >= 0) norm.push_back( vec3f(vdata[vertex_norm+0],vdata[vertex_norm+1],vdata[vertex_norm+2]) ); if(vertex_uv >= 0) uv.push_back( vec2f(vdata[vertex_uv+0],vdata[vertex_uv+1] )); } if(normalize) { range3f bbox; for(auto v : pos) bbox = runion(bbox,v); vec3f c = center(bbox); float s = 1/max_component(size(bbox)); for(vec3f& v : pos) v = (v-c)*s; } if(flipyz) { for(vec3f& v : pos) swap(v.y,v.z); for(vec3f& v : norm) swap(v.y,v.z); } // read vertex data vector<vec3i> triangles; vector<vec4i> quads; for(int i = 0; i < face_num; i ++) { int n = 0; fscanf(f, "%d", &n); if(n == 3) { vec3i face; for(int j=0;j<3;j++) fscanf(f, "%d", &(face[j])); triangles.push_back(face); } if(n == 4) { vec4i face; for(int j=0;j<4;j++) fscanf(f, "%d", &(face[j])); quads.push_back(face); } if(n != 3 and n != 4) ERROR("unsupported face type"); } if(flipface) { for(vec3i& t : triangles) swap(t.y,t.z); for(vec4i& t : quads) swap(t.y,t.w); } fclose(f); if(triangles.size() == 0 and quads.size() > 0) { auto mesh = new Mesh(); mesh->pos = pos; mesh->norm = norm; mesh->texcoord = uv; mesh->quad = quads; return mesh; } else if(triangles.size() > 0 and quads.size() == 0) { auto mesh = new TriangleMesh(); mesh->pos = pos; mesh->norm = norm; mesh->texcoord = uv; mesh->triangle = triangles; return mesh; } else if(triangles.size() > 0 and quads.size() > 0) { auto mesh = new Mesh(); mesh->pos = pos; mesh->norm = norm; mesh->texcoord = uv; mesh->triangle = triangles; mesh->quad = quads; return mesh; } else { WARNING("empty mesh"); return 0; } }
EXPORT COMPONENT new_component( COMPONENT comp) { COMPONENT mincomp, maxcomp; HYPER_SURF **hs; INTERFACE *intfc; struct Table *firstIT, *T; static COMPONENT last_reused_comp = NO_COMP; if (comp != NO_COMP) { firstIT = interface_table_list(); switch (comp) { case UNUSED_COMP: maxcomp = INT_MIN; mincomp = INT_MAX; for (T = firstIT; T != NULL; T = T->next) { intfc = T->interface; maxcomp = max(maxcomp,max_component(intfc)); mincomp = min(mincomp,min_component(intfc)); } ++maxcomp; for (comp = mincomp; comp <= maxcomp; ++comp) { if (comp == last_reused_comp) continue; for (T = firstIT; T != NULL; T = T->next) { intfc = T->interface; if (is_exterior_comp(comp,intfc) || is_excluded_comp(comp,intfc)) break; if (intfc->hss != NULL) { for (hs = intfc->hss; *hs; ++hs) { if ((positive_component(*hs) == comp) || (negative_component(*hs) == comp)) break; } if (*hs) break; } } if (T == NULL) break; } last_reused_comp = comp; break; case NEW_COMP: comp = INT_MIN; for (T = firstIT; T != NULL; T = T->next) { intfc = T->interface; comp = max(comp,max_component(intfc)); } ++comp; last_reused_comp = NO_COMP; break; default: last_reused_comp = NO_COMP; break; } for (T = firstIT; T != NULL; T = T->next) { intfc = T->interface; max_component(intfc) = max(comp,max_component(intfc)); min_component(intfc) = min(comp,min_component(intfc)); } } return comp; } /*end new_component*/