//================================================================ //begin: off file outpur function //================================================================ void TMesh::OutMeshOffFile(char *filename) { FILE *fp; if( (fp = fopen(filename, "w")) == NULL ) { std::cout<<"Failed to open file!"<<std::endl; return; } fprintf(fp, "LIST\n"); fprintf(fp, "appearance {linewidth 7}\n"); fprintf(fp, "{\n"); fprintf(fp, "OFF\n"); fprintf(fp, "%d %d 0\n", v_count(), f_count()); for(unsigned int i = 0; i < v_count(); i ++) { fprintf(fp, "%f %f %f\n", (vertex(i).coord())(0), (vertex(i).coord())(1), (vertex(i).coord())(2)); } for(unsigned int i = 0; i < f_count(); i ++) { if( vertex(facet(i).vert(0)).check_flag(VTMESH_FLAG_SELECTED) && vertex(facet(i).vert(1)).check_flag(VTMESH_FLAG_SELECTED) && vertex(facet(i).vert(2)).check_flag(VTMESH_FLAG_SELECTED)) fprintf(fp, "3 %d %d %d 0.2 0.2 0.2 1\n", facet(i).vert(0), facet(i).vert(1), facet(i).vert(2)); else fprintf(fp, "3 %d %d %d 1 1 1 1\n", facet(i).vert(0), facet(i).vert(1), facet(i).vert(2)); } fprintf(fp, "}\n"); fclose(fp); }
bool TestExtStream::test_stream_wrapper_restore() { int64_t count = f_count(f_stream_get_wrappers()); VS(f_stream_wrapper_unregister("http"), true); VS(f_count(f_stream_get_wrappers()), count - 1); VS(f_stream_wrapper_restore("http"), true); VS(f_count(f_stream_get_wrappers()), count); return Count(true); }
void TMesh::PrintMeshTopo() { cout<<"vertex top"<<endl; for(unsigned int i = 0; i < v_count(); i ++) { cout<<"vertex "<<i<<": "<<vertex(i).coord()<<endl; cout<<"\t incident vertex: "; for(unsigned int vit = 0; vit < vertex(i).n_verts(); vit ++) cout<<"\t"<<vertex(i).vert(vit)<<" "; cout<<endl; cout<<"\t incident triangle: "; for(unsigned int fit = 0; fit < vertex(i).n_facets(); fit ++) cout<<"\t"<<vertex(i).facet(fit)<<" "; cout<<endl; } cout<<endl; cout<<"triangle top"<<endl; for(unsigned int i = 0; i < f_count(); i ++) { cout<<"triangle "<<i<<endl; cout<<"\t vert: "; for(int j = 0; j < 3; j ++) cout<<"\t"<<facet(i).vert(j)<<" "; cout<<endl; cout<<"\t adj_facet: "; for(int j = 0; j < 3; j ++) cout<<"\t"<<facet(i).facet(j)<<" "; cout<<endl; } cout<<endl; }
bool TestExtMailparse::test_mailparse_msg_create() { const char *files[] = { "mime", "phpcvs1", "qp", "uue" }; for (unsigned int i = 0; i < sizeof(files)/sizeof(files[0]); i++) { string file = files[i]; string testname = "test/ext/test_ext_mailparse." + file + ".txt"; string expname = "test/ext/test_ext_mailparse." + file + ".exp"; Variant mime = f_mailparse_msg_create(); PlainFile input; input.open(testname, "r"); while (!input.eof()) { String data = input.read(1024); if (!data.isNull()) { f_mailparse_msg_parse(mime, data); } } input.close(); Array arr = f_mailparse_msg_get_structure(mime); f_ob_start(); echo("Message: "); echo(file.c_str()); echo("\n"); for (ArrayIter iter(arr); iter; ++iter) { Variant partname = iter.second(); int depth = f_count(f_explode(".", partname)) - 1; String indent = f_str_repeat(" ", depth * 2); Variant subpart = f_mailparse_msg_get_part(mime, partname); if (subpart.isNull()) { f_var_dump(partname); echo("\n"); f_var_dump(arr); break; } Variant data = f_mailparse_msg_get_part_data(subpart); echo("\n"); echo(indent); echo("Part "); echo(partname); echo("\n"); f_ksort(ref(data)); for (ArrayIter iter(data); iter; ++iter) { String key = iter.first().toString(); if (key != "headers" && key != "ending-pos-body") { echo(indent); echo(key); echo(" => "); f_var_dump(iter.second()); } } } String output = f_ob_get_contents(); Variant expect = f_file_get_contents(expname.c_str()); VS(output, expect); f_ob_end_clean(); } return Count(true); }
void TMesh::OutMeshOffFile(FILE *fp, double r, double g, double b, double a) { if( fp == NULL ) { std::cout<<"Invalid FILE pointer"<<std::endl; return; } fprintf(fp, "{\n"); fprintf(fp, "OFF\n"); fprintf(fp, "%d %d 0\n", v_count(), f_count()); for(unsigned int i = 0; i < v_count(); i ++) { fprintf(fp, "%f %f %f\n", (vertex(i).coord())(0), (vertex(i).coord())(1), (vertex(i).coord())(2)); } for(unsigned int i = 0; i < f_count(); i ++) { if( facet(i).check_flag(FTMESH_FLAG_SELECT) ) fprintf(fp, "3 %d %d %d 1 0 0 1\n", facet(i).vert(0), facet(i).vert(1), facet(i).vert(2)); else fprintf(fp, "3 %d %d %d %f %f %f %f\n", facet(i).vert(0), facet(i).vert(1), facet(i).vert(2), r, g, b, a); } fprintf(fp, "}\n"); }
bool TMesh::CheckMeshTopo() { //check facet topo bool good = true; for(unsigned int i = 0; i < f_count(); i ++) { for(int j = 0; j < 3; j ++) { int fid = facet(i).facet(j); if(fid < 0) continue; int findex = facet(fid).findex(facet(i).vert((j + 1) % 3), facet(i).vert((j + 2) % 3)); if(findex < 0) { cerr<<"mesh topo check error!"<<endl; cerr<<"fid: "<<i<<" eid: "<<" fid_adj: "<<fid<<endl; good = false; } //assert(findex >= 0); } } //check vertex topo for(unsigned int i = 0; i < v_count(); i ++) { for(unsigned int j = 0; j < vertex(i).n_facets(); j ++) { unsigned int fid = vertex(i).facet(j); int vindex = facet(fid).index(i); if(vindex < 0) { cerr<<"mesh topo check error!"<<endl; cerr<< "vid: "<<i<<" fid: "<<fid<<endl; good = false; } //assert(vindex >= 0); } for(unsigned int j = 0; j < vertex(i).n_verts(); j ++) { unsigned int vid = vertex(i).vert(j); int vindex = vertex(vid).index(i); if(vindex < 0) { cerr<<"mesh topo check error!"<<endl; cerr<<"vid: "<<i<<" vid: "<<vid<<endl; good = false; } //assert(vindex >= 0); } } if(!good) { cerr<<"Warning: the input mesh is not a manifold, which MAY crash the successive computation."<<endl; } return true; }
//////////////////////////////////////////////////////////////////////////////////////// //Meshsize //-------- //Estimate mesh size // void TMesh::MeshSize(double& maxs, double& mins, double& aves) { maxs = -FLT_MAX; mins = FLT_MAX; aves = 0; for(unsigned int i = 0; i < f_count(); i ++) { for(unsigned int j = 0; j < 3; j ++) { int vid0 = facet(i).vert(j); int vid1 = facet(i).vert((j + 1) % 3); double length = dot(vertex(vid0).coord() - vertex(vid1).coord(), vertex(vid0).coord() - vertex(vid1).coord()); length = sqrt(fabs(length)); aves += length; if(maxs < length) { maxs = length; } if(mins > length) { mins = length; } } } aves /= 3 * f_count(); cout<<"maxs: "<<maxs<<" mins: "<<mins<<" aves: "<<aves<<endl; }
//-------------------------------------------------- //OrientateFacets: //---------------- //Orientate the facets so that all the manifold facets will have //a consistent orientation //-------------------------------------------------- void TMesh::OrientateFacets() { unsigned int fid, f; queue<unsigned int> fid_queue; unsigned int max_nfacets, nfacets, fid_start; unsigned int vid1, vid2; int ind1, ind2; int fid_adj; //Find largest part of the surface which can be orientated. max_nfacets = 0; for(f = 0; f < f_count(); f ++) { if( facet(f).check_flag(FTMESH_FLAG_NMANIFOLD) ) continue; if( facet(f).check_flag(FTMESH_FLAG_VISITED) ) continue; fid_queue.push(f); facet(f).set_flag(FTMESH_FLAG_VISITED); nfacets = 0; while( !fid_queue.empty() ) { fid = fid_queue.front(); fid_queue.pop(); nfacets ++; for(int j = 0; j < 3; j ++) { fid_adj = facet(fid).facet(j); if(fid_adj < 0) continue; if( facet(fid_adj).check_flag(FTMESH_FLAG_NMANIFOLD) ) continue; if( facet(fid_adj).check_flag(FTMESH_FLAG_VISITED) ) continue; fid_queue.push(fid_adj); facet(fid_adj).set_flag(FTMESH_FLAG_VISITED); } } if( nfacets > max_nfacets ) { max_nfacets = nfacets; fid_start = f; } } //unset flags for(f = 0; f < f_count(); f ++) facet(f).un_set_flag(FTMESH_FLAG_VISITED); //orientate the facets fid_queue.push(fid_start); facet(fid_start).set_flag(FTMESH_FLAG_ORIENTATE); while( !fid_queue.empty()) { fid = fid_queue.front(); fid_queue.pop(); for(int j = 0; j < 3; j ++) { fid_adj = facet(fid).facet(j); if(fid_adj < 0) continue; if( facet(fid_adj).check_flag(FTMESH_FLAG_NMANIFOLD) ) continue; if( facet(fid_adj).check_flag(FTMESH_FLAG_ORIENTATE) ) continue; vid1 = facet(fid).vert( (j + 1) % 3 ); vid2 = facet(fid).vert( (j + 2) % 3 ); ind1 = facet(fid_adj).index(vid1); ind2 = facet(fid_adj).index(vid2); assert( ind1 >= 0 && ind2 >= 0 ); //If the orientation of "fid" and "fid_adj" are consisitent if( (ind2 + 1) % 3 == ind1 ) { if( facet(fid).check_flag(FTMESH_FLAG_REVERSE) ) facet(fid_adj).set_flag(FTMESH_FLAG_REVERSE); } else { //Otherwise the orientation of "fid" and "fid_adj" are NOT consisitent assert( (ind1 + 1) % 3 == ind2 ); if( !(facet(fid).check_flag(FTMESH_FLAG_REVERSE)) ) facet(fid_adj).set_flag(FTMESH_FLAG_REVERSE); } fid_queue.push(fid_adj); facet(fid_adj).set_flag(FTMESH_FLAG_ORIENTATE); }//for j }//while }
void TMesh::GenerateMeshTopo() { unsigned int vid0, vid1, vid2; for(unsigned int i = 0; i < f_count(); i ++) { vid0 = facet(i).vert(0); vid1 = facet(i).vert(1); vid2 = facet(i).vert(2); // cout<<i<<"th facet: vertices: "<<vid0<<" "<<vid1<<" "<<vid2<<endl; //generate the vertex topology vertex(vid0).add_facet(i); vertex(vid1).add_facet(i); vertex(vid2).add_facet(i); vertex(vid0).add_unique_vert(vid1); vertex(vid1).add_unique_vert(vid0); vertex(vid1).add_unique_vert(vid2); vertex(vid2).add_unique_vert(vid1); vertex(vid2).add_unique_vert(vid0); vertex(vid0).add_unique_vert(vid2); } //cerr<<"facet done"<<endl; for(unsigned int i = 0; i < f_count(); i ++) { //cout<<"fid: "<<i<<endl; //iterate over all facets for(int j = 0; j < 3; j ++) { //cout<<j<<"th vertex "<<endl; //edge vert(j) -- vert((j + 1) % 3) vid1 = facet(i).vert(j); vid2 = facet(i).vert((j + 1) % 3); //seach the adjacent triangle sharing edge (j + 2) % 3 for(unsigned int fit = 0; fit < vertex(vid1).n_facets(); fit ++) { unsigned int fid = vertex(vid1).facet(fit); if(fid <= i) continue; //cout<<"connected facet: "<<fid<<endl; int i1, i2; if( (i2 = facet(fid).index(vid2)) == -1 ) continue; i1 = facet(fid).index(vid1); assert(i1 >= 0); if( facet(i).facet((j + 2) % 3) >= 0) { cerr<<"non-manifold1: "<<i<<"--"<<fid<<" along edge: "<<vid1<<" "<<vid2<<endl; continue; } for(int k = 0; k < 3; k ++) { if(k != i1 && k != i2) { if(facet(fid).facet(k) >= 0) { cerr<<"non-manifold1: "<<i<<"--"<<fid<<" along edge: "<<vid1<<" "<<vid2<<endl; } else { //Only when both facets have not neighbouring facet along //this edge can they be the neighbouring faect for each other. facet(fid).set_facet(k, i); facet(i).set_facet((j + 2) % 3, fid); } break; } }//for k }//for fit }//for j }//for i //cout<<"topo done"<<endl; //set boundary flag //for particle for(unsigned int i = 0; i < f_count(); i ++) { for(int j = 0; j < 3; j ++) { if(facet(i).facet(j) >= 0) continue; facet(i).set_flag(FTMESH_FLAG_BOUNDARY); vertex( facet(i).vert((j + 1) % 3) ).set_flag(VTMESH_FLAG_BOUNDARY); vertex( facet(i).vert((j + 2) % 3) ).set_flag(VTMESH_FLAG_BOUNDARY); } } //Check whether the topology of the mesh is valid. CheckMeshTopo(); }
bool TMesh::ReadOffFile(char *filename, bool wcolor) { ifstream fin_temp; fin_temp.open(filename); if( !fin_temp.good() ) { return false; } ofstream fout_temp; fout_temp.open("temp.m"); if(!fout_temp.good()) { cerr<<"Failed to open file temp.m"<<endl; return false; } // Read the off file and skip the comments. // Write the comment-less off file to a file, called "temp.m". while(! fin_temp.eof()) { char line[90]; fin_temp.getline(line, 90); if(line[0] == 'O' || line[0] == '#') ; else fout_temp << line << endl; } fin_temp.close(); fout_temp.close(); FILE *fp; if( (fp = fopen("temp.m", "r")) == NULL ) { cerr<<"Failed to open file temp.m"<<endl; return false; } unsigned int n_ver, n_facet, n_edge; fscanf(fp, "%d %d %d", &n_ver, &n_facet, &n_edge); // cerr<<"n_ver: "<<n_ver<<" n_facet: "<<n_facet<<endl; float x, y, z; //vertex information for(unsigned int i = 0; i < n_ver; i ++) { fscanf(fp, "%f %f %f", &x, &y, &z); //cerr<<"x y z"<<x<<" "<<y<<" "<<z<<endl; //VTMesh v(x, y, z); add_vertex( VTMesh(x, y, z) ); } //cout<<"vertex done"<<endl; //facet information int nv, vid0, vid1, vid2; float r, g, b, a; for(unsigned int i = 0; i < n_facet; i ++) { fscanf(fp, "%d %d %d %d", &nv, &vid0, &vid1, &vid2); if(wcolor) fscanf(fp, "%f %f %f %f", &r, &g, &b, &a); unsigned int fid = add_facet( FTMesh(vid0, vid1, vid2) ); assert(fid == i); } //cerr<<"facet done"<<endl; assert(v_count() == n_ver); assert(f_count() == n_facet); //get the bounding box of mesh GetBBox(); //Delete the temp.m file system("rm temp.m"); //Generate the topology for tmesh GenerateMeshTopo(); //Mark the non_manifoldness MarkNonManifoldness(); //debug // PrintMeshTopo(); // getchar(); return true; }
int64_t f_sizeof(CVarRef var, bool recursive /* = false */) { return f_count(var, recursive); }
static VALUE string_to_c_internal(VALUE self) { VALUE s; s = self; if (RSTRING_LEN(s) == 0) return rb_assoc_new(Qnil, self); { VALUE m, sr, si, re, r, i; int po; m = f_match(comp_pat0, s); if (!NIL_P(m)) { sr = f_aref(m, INT2FIX(1)); si = f_aref(m, INT2FIX(2)); re = f_post_match(m); po = 1; } if (NIL_P(m)) { m = f_match(comp_pat1, s); if (!NIL_P(m)) { sr = Qnil; si = f_aref(m, INT2FIX(1)); if (NIL_P(si)) si = rb_usascii_str_new2(""); { VALUE t; t = f_aref(m, INT2FIX(2)); if (NIL_P(t)) t = rb_usascii_str_new2("1"); rb_str_concat(si, t); } re = f_post_match(m); po = 0; } } if (NIL_P(m)) { m = f_match(comp_pat2, s); if (NIL_P(m)) return rb_assoc_new(Qnil, self); sr = f_aref(m, INT2FIX(1)); if (NIL_P(f_aref(m, INT2FIX(2)))) si = Qnil; else { VALUE t; si = f_aref(m, INT2FIX(3)); t = f_aref(m, INT2FIX(4)); if (NIL_P(t)) t = rb_usascii_str_new2("1"); rb_str_concat(si, t); } re = f_post_match(m); po = 0; } r = INT2FIX(0); i = INT2FIX(0); if (!NIL_P(sr)) { if (f_include_p(sr, a_slash)) r = f_to_r(sr); else if (f_gt_p(f_count(sr, a_dot_and_an_e), INT2FIX(0))) r = f_to_f(sr); else r = f_to_i(sr); } if (!NIL_P(si)) { if (f_include_p(si, a_slash)) i = f_to_r(si); else if (f_gt_p(f_count(si, a_dot_and_an_e), INT2FIX(0))) i = f_to_f(si); else i = f_to_i(si); } if (po) return rb_assoc_new(rb_complex_polar(r, i), re); else return rb_assoc_new(rb_complex_new2(r, i), re); } }