gmcoarsetopo.cpp

来自「算断裂的」· C++ 代码 · 共 924 行 · 第 1/3 页

CPP
924
字号
        ++fspec) {          if (ok_to_delete(fspec)) continue;          Brep::FaceIndex oldfaceind = fspec.faceind();          int lab1 = uf[fdim].get_label(oldfaceind);          Brep::FaceIndex lab2 = renumuf[lab1];          if (lab2 < 0) {            renumuf[lab1] = nextnewfaceind;            lab2 = nextnewfaceind;            ++nextnewfaceind;          }          old_to_new_map(fspec) = lab2;          // ctlog << "old " << fspec << " to new " << Brep::Face_Spec(fdim, lab2) << '\n';        }        new_level_size[fdim] = nextnewfaceind;      }    }    // Now invert old_to_new_map with a multimap new_to_old_map.    typedef multimap<Brep::Face_Spec, Brep::FaceIndex> FspecMM;    FspecMM new_to_old_map;    {      for (int fdim = 0; fdim <= di; ++fdim) {        for (Brep::FaceIndex oldfaceind = 0; oldfaceind < b.level_size(fdim); ++oldfaceind) {          Brep::Face_Spec oldfspec(fdim, oldfaceind);          if (ok_to_delete(oldfspec)) continue;          Brep::Face_Spec newfspec(fdim, old_to_new_map(oldfspec));          new_to_old_map.insert(pair<Brep::Face_Spec, Brep::FaceIndex>            (newfspec, oldfaceind));          // ctlog << "new " << newfspec << " to old " << oldfspec << '\n';        }      }    }    Brep::Face_Labeling<int> occurrence_count(b,0);    Brep::Face_Labeling<int> occurrence_count_last_update(b,0);    Brep::Face_Labeling<int> descendent_last_update(b,0);    Fspec_loop_over_descendents desc_fspec(b);        Brep_Under_Construction newb(di, di);    Fspec_loop_over_descendents desc_fspec_newb(newb);    int passcount = 0;    // Copy property-values from b to newb.    Brep_Under_Construction::Propval_inserter pvi(newb);    for (Brep::Loop_over_propvals_of_brep pvloop(b);    pvloop.notdone();    ++pvloop) {      if (compare_nocase(pvloop.prop(), Brep::global_id_propname()) == 0) {        ostringstream os;        os << "(" << pvloop.val() << "_with_faces_merged_allowable_curvature="          << allowable_curvature << ")";        pvi.insert_propval(Brep::global_id_propname(), os.str());      }      else {        pvi.insert_propval(pvloop.prop(), pvloop.val());      }    }    vector<Real> realcoord(di);    Brep_Under_Construction::Control_point_inserter cpi(newb);    // Copy the control points.    for (Brep::ControlPointIndex cpind = 0;     cpind < b.num_control_points();    ++cpind) {      for (int d = 0; d < di; ++d)        realcoord[d] = b.control_point(cpind, d);      cpi.insert_control_point(realcoord);    }    vector<Brep::ControlPointIndex> controlpts;    // Insert the faces    for (int fdim = 0; fdim <= di; ++fdim) {      Brep_Under_Construction::Top_face_inserter tfi(newb, fdim);      int newfacecount = new_level_size[fdim];      for (Brep::FaceIndex newfaceind = 0; newfaceind < newfacecount; ++newfaceind) {        ++passcount;        Brep::Face_Spec newfspec(fdim, newfaceind);        pair<FspecMM::iterator, FspecMM::iterator> rval =           new_to_old_map.equal_range(newfspec);        FspecMM::iterator startloop = rval.first;        FspecMM::iterator endloop = rval.second;        int mergersize = 0;        {          for (FspecMM::iterator it = startloop; it != endloop; ++it) {            ++mergersize;            if (ok_to_delete(Brep::Face_Spec(fdim, it -> second)))              throw_error("Deleted face part of merge?");          }        }              if (mergersize == 0)          throw_error("New face has no antecedents?");        string facename;        Brep::Face_Spec oldfspec(fdim, startloop -> second);        if (mergersize == 1) {          facename = b.face_name(oldfspec);        }        else {          facename = "Merge_of";          for (FspecMM::iterator it = startloop; it != endloop; ++it) {            facename += "_$_";            facename += b.face_name(Brep::Face_Spec(fdim, it -> second));          }        }                tfi.insert_top_face(facename);        // ctlog << "created new face " << newfspec << " named " << facename << '\n';                // Insert the face pv pairs.            Brep_Under_Construction::Top_face_propval_inserter tfpvi(newb, newfspec);        for (Brep::Loop_over_propvals_of_face pvloop2(b, oldfspec);        pvloop2.notdone();        ++pvloop2) {          tfpvi.insert_propval(pvloop2.prop(), pvloop2.val());        }                        // Add child faces.        // Insert internal boundaries.        Brep_Under_Construction::Top_face_bound_inserter tfbi(newb, newfspec);        Brep_Under_Construction::Top_face_ib_inserter tfii(newb, newfspec);        // Track down the old subfaces of all faces being merged.        {          for (FspecMM::iterator it = startloop; it != endloop; ++it) {            Brep::Face_Spec oldfspec(fdim, it -> second);            for (Brep::Face_Spec_Loop_Over_Face_Subfaces subfspec(b, oldfspec);            subfspec.notdone();            ++subfspec) {              if (occurrence_count_last_update(subfspec) < passcount) {                occurrence_count_last_update(subfspec) = passcount;                occurrence_count(subfspec) = 0;              }              ++occurrence_count(subfspec);              // ctlog << " occurrence count for old fspec " << oldfspec << " child " << subfspec              //  << " incremented to " << occurrence_count(subfspec) << '\n';            }          }        }        // Now insert the subfaces.        {          for (FspecMM::iterator it = startloop; it != endloop; ++it) {            Brep::Face_Spec oldfspec(fdim, it -> second);            for (Brep::Face_Spec_Loop_Over_Face_Subfaces subfspec(b, oldfspec);            subfspec.notdone();            ++subfspec) {              if (ok_to_delete(subfspec)) continue;              int occ_cnt = occurrence_count(subfspec);              if (occ_cnt == 0) continue;              // Find what face this face maps to, and then check              // that the occurrence counts are all consistent.              Brep::Face_Spec newsubfspec(subfspec.fdim(), old_to_new_map(subfspec));              pair<FspecMM::iterator, FspecMM::iterator> rval =                new_to_old_map.equal_range(newsubfspec);              // ctlog << "inserting subfspec " << newsubfspec << " from oldfspec "              //  << oldfspec << " subface " << subfspec << " occcnt = " << occ_cnt << '\n';              for (FspecMM::iterator it2 = rval.first; it2 != rval.second; ++it2) {                Brep::Face_Spec oldsubfspec2(subfspec.fdim(), it2 -> second);                if (occurrence_count(oldsubfspec2) != occ_cnt)                  throw_error("Inconsistent occurrence of child faces");                occurrence_count(oldsubfspec2) = 0;              }              if (newsubfspec.fdim() == fdim - 1) {                int icount = 1;                if (occ_cnt % 2 == 0)                  icount = 2;                for (int i = 0; i < icount; ++i) {                  tfbi.insert_boundary(newsubfspec, subfspec.orientation());                }              }              else {                tfii.insert_ib(newsubfspec);              }            }          }        }        // Now comes a tricky section: because of deleted faces, we may have        // some new internal boundaries to insert.        // Mark the descendents of the face.        {                    for (FspecMM::iterator it = startloop; it != endloop; ++it) {            Brep::Face_Spec oldfspec(fdim, it -> second);            for (desc_fspec.init(oldfspec); desc_fspec.notdone(); ++desc_fspec) {              descendent_last_update(desc_fspec) = passcount;            }          }        }        // Unmark the descendents that occur in the new the face.        {          for (desc_fspec_newb.init(newfspec); desc_fspec_newb.notdone(); ++desc_fspec_newb) {            pair<FspecMM::iterator,FspecMM::iterator> rval =               new_to_old_map.equal_range(desc_fspec_newb);            for (FspecMM::iterator it = rval.first; it != rval.second; ++it) {              Brep::Face_Spec oldsubfspec(desc_fspec_newb.fdim(), it -> second);              descendent_last_update(oldsubfspec) = passcount - 1;            }          }        }        // Find descendents still marked and add them as internal boundaries.           {                    for (FspecMM::iterator it = startloop; it != endloop; ++it) {            Brep::Face_Spec oldfspec(fdim, it -> second);            for (desc_fspec.init(oldfspec); desc_fspec.notdone(); ++desc_fspec) {              if (ok_to_delete(desc_fspec)) continue;              if (descendent_last_update(desc_fspec) == passcount) {                if (desc_fspec.fdim() >= fdim - 2)                  throw_error("Some inconsistency with ib's");                Brep::Face_Spec new_descfspec(desc_fspec.fdim(), old_to_new_map(desc_fspec));                tfii.insert_ib(new_descfspec);                pair<FspecMM::iterator,FspecMM::iterator> rval =                   new_to_old_map.equal_range(new_descfspec);                for (FspecMM::iterator it2 = rval.first; it2 != rval.second; ++it2) {                  descendent_last_update(Brep::Face_Spec(new_descfspec.fdim(),                    it2 -> second)) = passcount - 1;                }              }            }          }        }        // Now insert the patches.                        Brep_Under_Construction::Top_face_patch_inserter           tfpi(newb, newfspec);        {          for (FspecMM::iterator it = startloop; it != endloop; ++it) {            Brep::Face_Spec oldfspec(fdim, it -> second);            for (Brep::Loop_over_patches_of_face ptloop(b, oldfspec);            ptloop.notdone();            ++ptloop) {                            PatchType ptype = ptloop.ptype();              int deg1 = ptloop.degree1();              int ncp, deg2;                            if (fdim == 0) {                ncp = 1;              }              else if (fdim == 1) {                ncp = deg1  + 1;              }              else  { // if (gdim == 2)                 if (ptype == BEZIER_TRIANGLE) {                  ncp = (deg1 + 1) * (deg1 + 2) / 2;                }                 else { // ptype == BEZIER_QUAD                  deg2 = ptloop.degree2();                  ncp = (deg1 + 1) * (deg2 + 1);                }              }                          controlpts.resize(ncp);              for (int j = 0; j < ncp; ++j)                controlpts[j] = ptloop.control_point(j);                              tfpi.insert_patch(deg1, deg2, ptype, controlpts);            }          }        }      }    }    return newb;  }  static void worker(const QMG::FrontEnd::ArgValType& argvalhandle,    QMG::FrontEnd::ReturnValType& returnvalhandle,    QMG::FrontEnd::Interpreter& interp) {        using namespace QMG;    using namespace QMG::FrontEnd;        argvalhandle.verify_nargin(2, 2, GM_ROUTINE_NAME_Q);    returnvalhandle.verify_nargout(1, 1, GM_ROUTINE_NAME_Q);    double allow_curve = argvalhandle.get_double(1);    Brep_Under_Construction newb =       coarsen_topo(argvalhandle.get_brep(0), allow_curve);    returnvalhandle.put_brep(0, newb);  }}#include "gm_entrypoint.cpp"

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?