double.cpp

来自「算断裂的」· C++ 代码 · 共 1,820 行 · 第 1/5 页

CPP
1,820
字号
// ------------------------------------------------------------------// double//// This file contains the driver function for QMG routine// to (1) make patch orientations consistent.//    (2) make internal boundaries doubled.// The function takes either a brep, or a (brep,mesh) pair as// input.// ------------------------------------------------------------------// Author: Stephen A. Vavasis// Copyright (c) 1999 by Cornell University.  All rights reserved.// // See the accompanying file 'Copyright' for authorship information,// the terms of the license governing this software, and disclaimers// concerning this software.// ------------------------------------------------------------------// This file is part of the QMG software.  // Version 2.0 of QMG, release date September 3, 1999.// ------------------------------------------------------------------#ifdef _MSC_VER#if _MSC_VER == 1200#include "qmatvec.h"#endif#endif#ifdef _MSC_VER#include "qnamesp.h"static void unused_func() {  using QMG::pair;  pair<int,int> b;  pair<int,int> a(3,2);  b = a;}#endif#include "qbrep_constr.h"#include "qmatvec.h"#include "qancestor.h"#include "qsimpcomp.h"#include "qpatchtab.h"#include "qunionfind.h"#include "qlog.h"#include "qerr.h"namespace QMG {  namespace MG {    using namespace QMG;    // see qsmall.cpp    extern void small_initialize_static_data(int di);    // Functions defined in this file.    Brep_Under_Construction      double_brep(const Brep& b,                  const vector<Brep::Face_Spec>& faces_to_double,                  double tol,                  // other return variables:                  Brep::Face_Labeling<Brep::FaceIndex>& oldfspec_to_new_map,                  Brep::Face_Labeling<int>& face_num_copies,                  map<PatchInBrepAddress, bool>& patch_is_flipped);    SimpComplex_Under_Construction      double_simpcomp(const Brep& b,                      const Brep& newb,                      const SimpComplex& sc,                      const Brep::Face_Labeling<Brep::FaceIndex>& oldfspec_to_new_map,                      const Brep::Face_Labeling<int>& num_copies,                      const map<PatchInBrepAddress,bool>& patch_is_flipped,                      double tol                      );  }#ifdef DEBUGGING  namespace Local_to_PatchMath_CPP {    extern bool dump_everything;    extern ostream* debug_str;  }#endif}namespace {  using namespace QMG;  using namespace QMG::MG;  struct NewBrepFaceInfo {    vector<Brep::FaceIndex> childlist;    vector<int> child_ori;    vector<Brep::Face_Spec> iblist;    NewBrepFaceInfo() { }  private:    NewBrepFaceInfo(const NewBrepFaceInfo&) { }    void operator=(const NewBrepFaceInfo&) { }  };  class NewBrepType {    int di_;    vector<NewBrepFaceInfo*>* nbrf_;  public:    NewBrepFaceInfo& get_face(const Brep::Face_Spec& fspec) {      return *(nbrf_[fspec.fdim()][fspec.faceind()]);    }    Brep::Face_Spec add_face(int fdim) {      nbrf_[fdim].push_back(new NewBrepFaceInfo());      return Brep::Face_Spec(fdim, nbrf_[fdim].size() - 1);    }    NewBrepType(int di) :       di_(di),       nbrf_(new vector<NewBrepFaceInfo*>[di + 1]) { }    ~NewBrepType();  };  NewBrepType::~NewBrepType() {    for (int fdim = di_; fdim >= 0; --fdim) {      int sz = nbrf_[fdim].size();      for (int faceind = sz - 1; faceind >= 0; --faceind) {        delete nbrf_[fdim][faceind];      }    }    delete[] nbrf_;  }    struct AnglePatchIndPair {    Real angle;    PatchTable::Index patchind;    int which_copy;    bool is_forward;    Brep::Face_Spec region_above;    Brep::Face_Spec region_below;    AnglePatchIndPair() { }    AnglePatchIndPair(const AnglePatchIndPair& o) :      angle(o.angle), patchind(o.patchind),      which_copy(o.which_copy), is_forward(o.is_forward),      region_above(o.region_above), region_below(o.region_below) { }    AnglePatchIndPair(Real a, PatchTable::Index p, int w, bool i,                      const Brep::Face_Spec& above,                       const Brep::Face_Spec& below) :      angle(a), patchind(p), which_copy(w), is_forward(i),      region_above(above), region_below(below) { }    bool operator<(const AnglePatchIndPair& o) const;    static Real tol;  };  Real AnglePatchIndPair::tol;  bool AnglePatchIndPair::operator<(const AnglePatchIndPair& o) const {    Real diff = angle - o.angle;    if (fabs(diff) < tol) {      bool rb = region_below.faceind() >= 0;#ifdef DEBUGGING      bool ra = region_above.faceind() >= 0;      bool orb = o.region_below.faceind() >= 0;      bool ora = o.region_above.faceind() >= 0;      if ((ra && rb) || (!ra && !rb) || (ora && orb) ||          (!ora && !orb) || (ra && ora) || (!ra && !ora))        throw_error("Inconsistent region above/below for same-angle patches");#endif      return rb;    }    return diff < 0;  }   struct EdgeLookupKey {    Brep::Face_Spec fspec1;    Brep::Face_Spec fspec2;    Brep::Face_Spec fspec3;    bool operator<(const EdgeLookupKey& o) const;    EdgeLookupKey() { }    EdgeLookupKey(const Brep::Face_Spec& f1,                   const Brep::Face_Spec& f2,                  const Brep::Face_Spec& f3) :      fspec1(f1), fspec2(f2), fspec3(f3) { }    EdgeLookupKey(const EdgeLookupKey& o) :      fspec1(o.fspec1), fspec2(o.fspec2), fspec3(o.fspec3) { }  };  bool EdgeLookupKey::operator<(const EdgeLookupKey& o) const {    if (fspec1 < o.fspec1) return true;    if (fspec1 > o.fspec1) return false;    if (fspec2 < o.fspec2) return true;    if (fspec2 > o.fspec2) return false;    return fspec3 < o.fspec3;  }   struct SegHitRecord {    Real dist;    int pos;    bool interior_on_far_side;    bool interior_on_near_side;    SegHitRecord(Real d1,                 int p1,                 bool far1,                 bool near1) :       dist(d1), pos(p1), interior_on_far_side(far1),      interior_on_near_side(near1) { }    SegHitRecord(const SegHitRecord& o) :      dist(o.dist), pos(o.pos), interior_on_far_side(o.interior_on_far_side),      interior_on_near_side(o.interior_on_near_side) { }    SegHitRecord() { }    bool operator<(const SegHitRecord& o) const;    static double tol;  };  double SegHitRecord::tol;  bool SegHitRecord::operator<(const SegHitRecord& o) const {    Real diff = dist - o.dist;    if (fabs(diff) < tol) {#ifdef DEBUGGING      if ((interior_on_near_side && interior_on_far_side) ||          (!interior_on_near_side && !interior_on_far_side) ||          (o.interior_on_near_side && o.interior_on_far_side) ||          (!o.interior_on_near_side && !o.interior_on_far_side) ||          (interior_on_near_side && o.interior_on_near_side) ||          (!interior_on_near_side && !o.interior_on_near_side)) {        throw_error("Inconsistent sides for same-angle patches");      }#endif      return interior_on_near_side;    }    return diff < 0.0;  }  class OnErrorFlushLog : public QMG::Error_Task {  private:    Logstream& log_;    // Override base case function    virtual void on_error_do(const string& errmsg) {       log_.str() << errmsg << '\n';      QMG::Error_Message::put_error_messages_into_stream(log_.str());      log_.str() << std::flush;    }  public:    OnErrorFlushLog(Logstream& logs) : log_(logs) { }    ~OnErrorFlushLog() { }  };  const Real PI_OVER_2 = 1.57079632679490;  struct FacetMapKey {    SimpComplex::VertexGlobalIndex verts[MAXDIM];    static int di;    void sort();    bool operator<(const FacetMapKey& other) const;  };  int FacetMapKey::di;  ostream& operator<<(ostream& os, const FacetMapKey& key) {    for (int i = 0; i < key.di; ++i)      os << key.verts[i] << ' ';    return os;  }  void FacetMapKey::sort() {    for (int i = 0; i < di - 1; ++i) {      for (int j = i + 1; j < di; ++j) {        if (verts[j] < verts[i]) {          SimpComplex::VertexGlobalIndex tmp = verts[i];          verts[i] = verts[j];          verts[j] = tmp;        }      }    }  }  bool FacetMapKey::operator<(const FacetMapKey& o) const {    for (int i = 0; i < di; ++i) {      if (verts[i] < o.verts[i]) return true;      if (verts[i] > o.verts[i]) return false;    }    return false;  }  struct FacetMapRec1 {    Brep::FaceIndex owner_faceind;    int owner_seqno;    int which_facet : 4;  };  /*  ostream& operator<<(ostream& os, const FacetMapRec1& rec) {    os << "di:" << rec.owner_faceind << "#" << rec.owner_seqno      << " fa " << rec.which_facet << " srchd?" << rec.is_searched      << " isondbled?" << rec.is_on_doubled_ib;    return os;  }  */  struct FacetMapRec2 {    Brep::Face_Spec fspec;    int seqno;    bool operator<(const FacetMapRec2& o) const;  };  bool FacetMapRec2::operator<(const FacetMapRec2& o) const {    if (fspec < o.fspec) return true;    if (fspec > o.fspec) return false;    return seqno < o.seqno;  }  ostream& operator<<(ostream& os, const FacetMapRec2& rec) {    ::operator<<(os, rec.fspec) << '#' << rec.seqno;    return os;  }  struct FspecSimpMaskKey {    Brep::Face_Spec low_dim_fspec;    Brep::FaceIndex simpfaceind;    int simpseqno;    unsigned int mask;    bool operator<(const FspecSimpMaskKey& o) const;  };  bool FspecSimpMaskKey::operator<(const FspecSimpMaskKey& o) const {    if (low_dim_fspec < o.low_dim_fspec) return true;    if (low_dim_fspec > o.low_dim_fspec) return false;    if (simpfaceind < o.simpfaceind) return true;    if (simpfaceind > o.simpfaceind) return false;    if (simpseqno < o.simpseqno) return true;    if (simpseqno > o.simpseqno) return false;    return mask < o.mask;  }  struct SimpVertKey {    Brep::Face_Spec fspec;    int seqno;    SimpComplex::VertexGlobalIndex vertex;    bool operator<(const SimpVertKey& o) const;  };  bool SimpVertKey::operator<(const SimpVertKey& o) const {    if (fspec < o.fspec) return true;    if (fspec > o.fspec) return false;    if (seqno < o.seqno) return true;    if (seqno > o.seqno) return false;    return vertex < o.vertex;  }      struct FspecCopyNum {    Brep::Face_Spec fspec;    int copynum;    bool operator<(const FspecCopyNum& o) const;  };

⌨️ 快捷键说明

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