qbrep.cpp

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

CPP
580
字号
    int count1 = count_ - this_surf_ -> num_bound_vertices;    if (count1 < this_surf_ -> num_bound_edges) {      this -> fdim_ = 1;      this -> faceind_ = this_surf_ -> bound_edges[count1];      return;    }  }  if (parentfdim_ == 3) {    if (count_ < this_region_ -> num_bound_vertices) {      this -> fdim_ = 0;      this -> faceind_ = this_region_ -> bound_vertices[count_];      return;    }    int count1 = count_ - this_region_ -> num_bound_vertices;    if (count1 < this_region_ -> num_bound_edges) {      this -> fdim_ = 1;      this -> faceind_ = this_region_ -> bound_edges[count1];      return;    }    count1 -= this_region_ -> num_bound_edges;    if (count1 < this_region_ -> num_bound_surfaces) {      this -> fdim_ = 2;      this -> faceind_ = this_region_ -> bound_surfaces[count1];      orientation_ = this_region_ -> surface_orientation[count1];      return;    }  }  this -> fdim_ = -1;  this -> faceind_ = -1;  return;}QMG::Brep::Loop_over_patches_of_face::Loop_over_patches_of_face(const Brep& g, const Face_Spec& f) :brep_(g), fspec_(f) {   count_ = 0;  int fdim = f.fdim();  FaceIndex parentfaceind = f.faceind();#ifdef RANGECHECK  if (fdim < 0 || fdim > g.gdim())    throw_error("Fdim out of range in loop_over_patches");  if (parentfaceind < 0)    throw_error("Faceind out of range (-1) in loop_over_patches");#endif  if (fdim == 0) {#ifdef RANGECHECK    if (parentfaceind >= g.geo_ -> num_top_vertices)       throw_error("Faceind out range (0) in loop_over_patches");#endif    this_vertex_ = & (g.geo_ -> top_vertices[parentfaceind]);    num_patches_ = 1;  }   else if (fdim == 1) {#ifdef RANGECHECK    if (parentfaceind >= g.geo_ -> num_top_edges)       throw_error("Faceind out range (1) in loop_over_patches");#endif    this_edge_ = & (g.geo_ -> top_edges[parentfaceind]);    num_patches_ = this_edge_ -> num_curves;  }  else if (fdim == 2) {#ifdef RANGECHECK    if (parentfaceind >= g.geo_ -> num_top_surfaces)      throw_error("Faceind out of range (2) in loop_over_patches");#endif    this_surf_ = & (g.geo_ -> top_surfaces[parentfaceind]);    num_patches_ = this_surf_ -> num_patches;  }  else if (fdim == 3) {#ifdef RANGECHECK    if (parentfaceind >= g.geo_ -> num_top_regions)      throw_error("Faceind out of range (2) in loop_over_patches");#endif    num_patches_ = 0;  }}int QMG::Brep::Loop_over_patches_of_face::degree1() const {  if (fspec_.fdim() == 0) {    return 1;  }  if (fspec_.fdim() == 1) {    return this_edge_ -> curves[count_].order;  }  return this_surf_ -> patches[count_].order_u;}int QMG::Brep::Loop_over_patches_of_face::degree2() const {#ifdef DEBUGGING  if (fspec_.fdim() != 2 || this_surf_ -> patches[count_].type != CPTC_PATCHTYPE_QUAD) {    throw_error("Illegal to invoke degree 2 on a nonquad patch");  }#endif  return this_surf_ -> patches[count_].order_v;}QMG::PatchTypeQMG::Brep::Loop_over_patches_of_face::ptype() const {  if (fspec_.fdim() < 2) {    return QMG::BEZIER_TRIANGLE;  }  return (this_surf_ -> patches[count_].type == CPTC_PATCHTYPE_QUAD)?    QMG::BEZIER_QUAD : QMG::BEZIER_TRIANGLE;}QMG::Brep::ControlPointIndexQMG::Brep::Loop_over_patches_of_face::control_point(int j) const {  if (fspec_.fdim() == 0)     return this_vertex_ -> control_pnt_indx;  if (fspec_.fdim() == 1)     return this_edge_ -> curves[count_].control_pnt_indx[j];  return this_surf_ -> patches[count_].control_pnt_indx[j];}QMG::Brep::Loop_over_propvals_of_face::Loop_over_propvals_of_face(const Brep& g,                           const Brep::Face_Spec& f) {  count_ = 0;  int fdim = f.fdim();  FaceIndex parentfaceind = f.faceind();#ifdef RANGECHECK  if (fdim < 0 || fdim > g.gdim())    throw_error("Fdim out of range in loop_over_propvals");  if (parentfaceind < 0)    throw_error("Faceind out of range (-1) in loop_over_propvals");#endif  if (fdim == 0) {#ifdef RANGECHECK    if (parentfaceind >= g.geo_ -> num_top_vertices)       throw_error("Faceind out range (0) in loop_over_propvals");#endif    props_ = g.geo_ -> top_vertices[parentfaceind].props;    vals_ = g.geo_ -> top_vertices[parentfaceind].values;    num_propvals_ = g.geo_ -> top_vertices[parentfaceind].num_properties;  }   else if (fdim == 1) {#ifdef RANGECHECK    if (parentfaceind >= g.geo_ -> num_top_edges)       throw_error("Faceind out range (1) in loop_over_propvals");#endif    props_ = g.geo_ -> top_edges[parentfaceind].props;    vals_ = g.geo_ -> top_edges[parentfaceind].values;    num_propvals_ = g.geo_ -> top_edges[parentfaceind].num_properties;  }  else if (fdim == 2) {#ifdef RANGECHECK    if (parentfaceind >= g.geo_ -> num_top_surfaces)      throw_error("Faceind out of range (2) in loop_over_propvals");#endif    props_ = g.geo_ -> top_surfaces[parentfaceind].props;    vals_ = g.geo_ -> top_surfaces[parentfaceind].values;    num_propvals_ = g.geo_ -> top_surfaces[parentfaceind].num_properties;  }  else if (fdim == 3) {#ifdef RANGECHECK    if (parentfaceind >= g.geo_ -> num_top_regions)      throw_error("Faceind out of range (3) in loop_over_propvals");#endif    props_ = g.geo_ -> top_regions[parentfaceind].props;    vals_ = g.geo_ -> top_regions[parentfaceind].values;    num_propvals_ = g.geo_ -> top_regions[parentfaceind].num_properties;  }}QMG::Brep::Loop_over_propvals_of_brep::Loop_over_propvals_of_brep(const Brep& g) {  count_ = 0;  props_ = g.geo_ -> props;  vals_ = g.geo_ -> values;  num_propvals_ = g.geo_ -> num_properties;}QMG::stringQMG::Brep::face_lookup_prop_val(const Face_Spec& fspec,                                 const string& property) const {  for (Loop_over_propvals_of_face loop(*this, fspec);  loop.notdone();  ++loop) {    if (compare_nocase(property, loop.prop()) == 0) {      return loop.val();    }  }  return string("");}QMG::stringQMG::Brep::lookup_brep_propval(const string& property) const {  for (Loop_over_propvals_of_brep loop(*this);  loop.notdone();  ++loop) {    if (compare_nocase(property, loop.prop()) == 0) {      return loop.val();    }  }  return string("");}QMG::string QMG::Brep::face_name(const Face_Spec& fspec) const {  int fdim = fspec.fdim();  int faceind = fspec.faceind();#ifdef RANGECHECK  if (fdim < 0 || fdim > geo_ -> intrinsic_dimension) {    throw_error("Dimension out of range in face_name");  }#endif  if (fdim == 0) {#ifdef RANGECHECK    if (faceind < 0 || faceind >= geo_ -> num_top_vertices) {      throw_error("Faceind out of range (0) in face_name");    }#endif    return string(geo_ -> top_vertices[faceind].id);  }  else if (fdim == 1) {#ifdef RANGECHECK    if (faceind < 0 || faceind >= geo_ -> num_top_edges) {      throw_error("Faceind out of range (1) in face_name");    }#endif    return string(geo_ -> top_edges[faceind].id);  }  else if (fdim == 2) {#ifdef RANGECHECK    if (faceind < 0 || faceind >= geo_ -> num_top_surfaces) {      throw_error("Faceind out of range (2) in face_name");    }#endif    return string(geo_ -> top_surfaces[faceind].id);  }  else { // fdim = 3#ifdef RANGECHECK    if (faceind < 0 || faceind >= geo_ -> num_top_regions) {      throw_error("Faceind out of range (3) in face_name");    }#endif    return string(geo_ -> top_regions[faceind].id);  }}doubleQMG::Brep::scale_factor() const {  double maxdist = 0.0;  bool firstfound = false;  int di = this -> embedded_dim();  for (Face_Spec_Loop_Over_Faces fspec(*this); fspec.notdone(); ++fspec) {    for (Loop_over_patches_of_face patch(*this, fspec); patch.notdone(); ++patch) {      int ncp;      if (fspec.fdim() == 1) {        ncp = patch.degree1() + 1;      }      else if (fspec.fdim() == 0) {        ncp = 1;      }      else if (fspec.fdim() == 2) {        if (patch.ptype() == BEZIER_TRIANGLE)          ncp = (patch.degree1() + 1) * (patch.degree1() + 2) / 2;        else          ncp = (patch.degree1() + 1) * (patch.degree2() + 1);      }      for (int ll = 0; ll < ncp; ++ll) {        ControlPointIndex i = patch.control_point(ll);        for (int j = 0; j < di; ++j) {          Real d = fabs(this -> control_point(i,j));          if (d > maxdist) {            maxdist = d;          }        }      }    }  }  return maxdist;}QMG::ostream& operator<<(QMG::ostream& s, const QMG::Brep::Face_Spec& fspec) {  s << fspec.fdim() << ":" << fspec.faceind();  return s;}

⌨️ 快捷键说明

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