void BinaryMeshFileReader::read_meshes(ReaderAdapter& reader, IMeshBuilder& builder) { try { while (true) { // Read the name of the next mesh. string mesh_name; try { mesh_name = read_string(reader); } catch (const ExceptionEOF&) { // Expected EOF. break; } builder.begin_mesh(mesh_name.c_str()); read_vertices(reader, builder); read_vertex_normals(reader, builder); read_texture_coordinates(reader, builder); read_material_slots(reader, builder); read_faces(reader, builder); builder.end_mesh(); } } catch (const ExceptionEOF&) { // Unexpected EOF. throw ExceptionIOError(); } }
// create a mesh storing a pointer in a map so it can be retrieved later by geometry UID bool MeshImporter::write_geometry(const COLLADAFW::Geometry *geom) { if (geom->getType() != COLLADAFW::Geometry::GEO_TYPE_MESH) { // TODO: report warning fprintf(stderr, "Mesh type %s is not supported\n", bc_geomTypeToStr(geom->getType())); return true; } COLLADAFW::Mesh *mesh = (COLLADAFW::Mesh *)geom; if (!is_nice_mesh(mesh)) { fprintf(stderr, "Ignoring mesh %s\n", bc_get_dae_name(mesh).c_str()); return true; } const std::string& str_geom_id = mesh->getName().size() ? mesh->getName() : mesh->getOriginalId(); Mesh *me = BKE_mesh_add(G.main, (char *)str_geom_id.c_str()); me->id.us--; // is already 1 here, but will be set later in BKE_mesh_assign_object // store the Mesh pointer to link it later with an Object // mesh_geom_map needed to map mesh to its geometry name (for shape key naming) this->uid_mesh_map[mesh->getUniqueId()] = me; this->mesh_geom_map[std::string(me->id.name)] = str_geom_id; read_vertices(mesh, me); read_polys(mesh, me); BKE_mesh_calc_edges(me, false, false); // read_lines() must be called after the face edges have been generated. // Oterwise the loose edges will be silently deleted again. read_lines(mesh, me); return true; }
mesh::mesh(std::string vfile_name, std::string sfile_name, std::string efile_name) { std::ifstream vfile(vfile_name.c_str()), sfile(sfile_name.c_str()), efile(efile_name.c_str()); vfile >> nv; sfile >> ns; efile >> ne; v = new vertex[nv]; s = new side[ns]; e = new element[ne]; read_vertices(vfile); read_sides(sfile); read_elems(efile); vfile.close(); sfile.close(); efile.close(); compute_geom_props(); init_boundary_vertices(); init_boundary_sides(); ncolors = edge_coloring::do_edge_coloring(*this, false); nbcolors = edge_coloring::do_edge_coloring(*this, true); init_color_sides(); init_b_color_sides(); }
void read_rst(const char *fn) { /* just read */ FILE *fd; fd = safe_fopen(fn, "r"); read_header(fd); read_vertices(fd); read_faces(fd); fclose(fd); }
void read_fst(const char *fn) { /* read and alloc */ FILE *fd; fd = safe_fopen(fn, "r"); read_header(fd); balloc(); read_vertices(fd); read_faces(fd); fclose(fd); }
void xrLC_GlobalData::read_lm_data ( INetReader &r ) { read_vertices( r ); read_deflectors = xr_new< tread_deflectors >( &_g_deflectors ); //create_read_faces(); read_deflectors->read( r ); //destroy_read_faces(); xr_delete( ::read_vertices ); xr_delete( read_deflectors ); }
int main(int argc, char** argv) { #ifdef LOGGING rlog::RLogInit(argc, argv); #endif std::string complex_fn, values_fn, output_prefix; bool skip_infinite_vines = false, explicit_events = false, save_vines = false; program_options(argc, argv, complex_fn, values_fn, output_prefix, skip_infinite_vines, save_vines, explicit_events); // Read in the complex PLVineyard::LSFiltration simplices; read_simplices(complex_fn, simplices); std::cout << "Complex read, size: " << simplices.size() << std::endl; // Read in vertex values VertexVectorVector vertices; read_vertices(values_fn, vertices); // Setup the vineyard VertexEvaluator veval(vertices[0]); PLVineyard::VertexComparison vcmp(veval); PLVineyard::SimplexComparison scmp(vcmp); simplices.sort(scmp); PLVineyard v(boost::counting_iterator<Vertex>(0), boost::counting_iterator<Vertex>(vertices[0].size()), simplices, veval); std::cout << "Pairing computed" << std::endl; // Compute vineyard for (size_t i = 1; i < vertices.size(); ++i) { veval = VertexEvaluator(vertices[i]); v.compute_vineyard(veval); std::cout << "Processed frame: " << i << std::endl; } std::cout << "Vineyard computed" << std::endl; if (save_vines) v.vineyard().save_vines(output_prefix, skip_infinite_vines); else v.vineyard().save_edges(output_prefix, skip_infinite_vines); }
void read_mesh(context_t* context, const reader_mesh_t* mesh) { hwgm_mesh_t* out = NULL; hwgm_vertices_t* vertices = NULL; hwgm_material_t* material = NULL; out = (hwgm_mesh_t*)(context->meshes + context->mesh_pos); hwgm_mesh_initialize(out); vertices = read_vertices(context, mesh); out->vertices = vertices; material = read_material(context, &mesh->material); out->material = material; context->mesh_pos += calc_size_mesh(mesh); return out; }
ErrorCode ReadCCMIO::read_processor(CCMIOID /* stateID */, CCMIOID problemID, CCMIOID processorID, CCMIOID verticesID, CCMIOID topologyID, CCMIOSize_t proc, Range *new_ents) { ErrorCode rval; // vert_map fields: s: none, i: gid, ul: vert handle, r: none //TupleList vert_map(0, 1, 1, 0, 0); TupleList vert_map; rval = read_vertices(proc, processorID, verticesID, topologyID, new_ents, vert_map); CHKERR(rval, NULL); rval = read_cells(proc, problemID, verticesID, topologyID, vert_map, new_ents); CHKERR(rval, NULL); return rval; }
file_load_status quake3_bsp_map::load(istream& stream) { if (!stream.good()) { m_last_error = "The stream was invalid"; return FILE_NOT_FOUND; } if (!load_and_check_header(stream)) { m_last_error = "Map contains an invalid header string"; return FILE_LOAD_FAILED; } read_lumps(stream); read_entities(stream); read_vertices(stream); read_faces(stream); read_face_indices(stream); read_textures(stream); read_lightmaps(stream); read_bsp_nodes(stream); read_bsp_leaves(stream); read_bsp_leaf_faces(stream); read_bsp_leaf_brushes(stream); read_models(stream); read_planes(stream); read_brushes(stream); read_brushsides(stream); read_effects(stream); read_lightvols(stream); read_visibility_data(stream); do_post_load(); print_statistics(); return FILE_LOAD_SUCCESS; }
ErrorCode ReadTemplate::load_file(const char* filename, const EntityHandle *file_set, const FileOptions& opts, const ReaderIface::SubsetList* subset_list, const Tag* /*file_id_tag*/) { if (subset_list) { // See src/moab/ReaderIface.hpp, definition of SubsetList struct; this basically specifies // an integer tag and tag values for sets to read on this proc, or a part number and total # parts // for reading a trivial partition of entities } // Save filename to member variable so we don't need to pass as an argument // to called functions fileName = filename; // Process options; see src/FileOptions.hpp for API for FileOptions class, and doc/metadata_info.doc for // a description of various options used by some of the readers in MOAB ErrorCode result = process_options(opts);MB_CHK_SET_ERR(result, fileName << ": problem reading options"); // Open file; filePtr is member of ReadTemplate, change to whatever mechanism is used to identify file FILE* filePtr = fopen(fileName, "r"); if (!filePtr) { MB_SET_ERR(MB_FILE_DOES_NOT_EXIST, fileName << ": fopen returned error"); } // Read number of verts, elements, sets long num_verts = 0, num_elems = 0, num_sets = 0; // read_ents keeps a running set of entities read from this file, including vertices, elements, and sets; // these will get added to file_set (if input) at the end of the read Range read_ents; // start_vertex is passed back so we know how to convert indices from the file into vertex handles; most // of the time this is done by adding start_vertex to the (0-based) index; if the index is 1-based, you also // need to subtract one; see read_elements for details EntityHandle start_vertex; result = read_vertices(num_verts, start_vertex, read_ents); if (MB_SUCCESS != result) { fclose(filePtr); return result; } // Create/read elements; this template assumes that all elements are the same type, so can be read in a single // call to read_elements, and kept track of with a single start_elem handle. If there are more entity types, // might have to keep these start handles in an array/vector. start_elem is only really needed if you're reading // sets later, and need to convert some file-based index to an entity handle EntityHandle start_elem; result = read_elements(num_elems, start_vertex, start_elem, read_ents); if (MB_SUCCESS != result) { fclose(filePtr); return result; } // Read/create entity sets; typically these sets have some tag identifying what they're for, see doc/metadata_info.doc // for examples of different kinds of sets and how they're marked result = create_sets(num_sets, start_vertex, num_verts, start_elem, num_elems, read_ents); if (MB_SUCCESS != result) { fclose(filePtr); return result; } // Finally, add all read_ents into the file set, if one was input if (file_set && *file_set) { result = mbImpl->add_entities(*file_set, read_ents); if (MB_SUCCESS != result) { fclose(filePtr); return result; } } fclose(filePtr); return result; }
int main ( ) /******************************************************************************/ /* Purpose: MAIN is the main program for TRIANGULATE. Modified: 02 January 2013 Author: Joseph O'Rourke Reference: Joseph ORourke, Computational Geometry, Second Edition, Cambridge, 1998, ISBN: 0521649765, LC: QA448.D38. */ { tVertex a; double area; int nvertices; tVertex p; int scale; int xmax; int xmin; int ymax; int ymin; read_vertices ( &nvertices ); scale_data ( &xmin, &xmax, &ymin, &ymax, &scale ); print_vertices ( nvertices, xmin, xmax, ymin, ymax, scale ); area = 0.5 * ( double ) area_poly2 ( ); printf ( "%%Area of polygon = %g\n", area ); if ( area == 0.0 ) { fprintf ( stderr, "\n" ); fprintf ( stderr, "TRIANGULATE - Fatal error!\n" ); fprintf ( stderr, " Computed area of polygon is zero.\n" ); exit ( 1 ); } if ( area < 0.0 ) { fprintf ( stderr, "\n" ); fprintf ( stderr, "TRIANGULATE - Fatal error!\n" ); fprintf ( stderr, " Computed area of polygon is negative.\n" ); fprintf ( stderr, " The vertices are probably listed in clockwise order.\n" ); fprintf ( stderr, " Revise the input file by reversing the vertex order.\n" ); exit ( 1 ); } /* Refuse to accept input if two consecutive vertices are equal. */ p = vertices; a = p->next; do { if ( p->v[X] == a->v[X] && p->v[Y] == a->v[Y] ) { fprintf ( stderr, "\n" ); fprintf ( stderr, "TRIANGULATE - Fatal error!\n" ); fprintf ( stderr, " Vertices %d and %d are equal.\n", p->vnum, a->vnum ); exit ( 1 ); } p = a; a = p->next; } while ( a->next != vertices ); /* Compute the triangulation. */ triangulate ( nvertices, xmin, xmax, ymin, ymax, scale ); printf ( "showpage\n%%%%EOF\n" ); /* Terminate. */ return 0; }