⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qbrep.cpp

📁 算断裂的
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  const mxArray* patchstring = mxGetCell(patchlist, patchind * 3);  char buf[100];  if (patchstring == 0 || mxGetM(patchstring) * mxGetN(patchstring) > 99      || mxGetString(patchstring, buf, 100))    throw_error("Illegal patch string");  string patchstring1(buf);  if ((fdim == 0 && compare_nocase(patchstring1, "vertex") != 0) ||      (fdim == 1 && compare_nocase(patchstring1, "bezier_curve") != 0) ||      (fdim == 2 && compare_nocase(patchstring1, "bezier_triangle") != 0       && compare_nocase(patchstring1, "bezier_quad") != 0) ||      fdim > 2) {    ostringstream os;    os << "Unrecognized patch type \"" << patchstring1 << "\"";    throw_error(os.str());  }  Patchinfo_ returnval;  returnval.ptype = BEZIER_TRIANGLE;  if (compare_nocase(patchstring1, "bezier_quad") == 0)    returnval.ptype = BEZIER_QUAD;  returnval.patchdim = fdim;  const mxArray* patchdeg = mxGetCell(patchlist, patchind * 3 + 1);  if (!patchdeg || !mxIsDouble(patchdeg) || mxIsSparse(patchdeg)      || mxGetPi(patchdeg))    throw_error("Illegal patch degree field");  if ((fdim == 0 && mxGetM(patchdeg) != 0) ||      (fdim == 1 && mxGetM(patchdeg) * mxGetN(patchdeg) != 1) ||      (fdim == 2 && returnval.ptype == BEZIER_TRIANGLE &&       mxGetM(patchdeg) * mxGetN(patchdeg) != 1) ||      (fdim == 2 && returnval.ptype == BEZIER_QUAD &&       mxGetM(patchdeg) * mxGetN(patchdeg) != 2))    throw_error("Wrong number of entries in degree field");  if (fdim >= 1) {    const double* pr = mxGetPr(patchdeg);    if (pr == 0)      throw_error("mxGetPr failed for degrees");    returnval.degree1 = static_cast<int>(pr[0]);    if (returnval.ptype == BEZIER_QUAD)      returnval.degree2 = static_cast<int>(pr[1]);  }  const mxArray* controlpts = mxGetCell(patchlist, patchind * 3 + 2);  if (!controlpts || !mxIsDouble(controlpts) ||      mxIsSparse(controlpts) || mxGetPi(controlpts))    throw_error("Illegal control points field for patch");  int ncp = mxGetM(controlpts) * mxGetN(controlpts);  int ncp1;  if (fdim == 0)    ncp1 = 1;  else if (fdim == 1)    ncp1 = returnval.degree1 + 1;  else if (returnval.ptype == BEZIER_TRIANGLE)    ncp1 = (returnval.degree1 + 1) * (returnval.degree1 + 2) / 2;  else     ncp1 = (returnval.degree1 + 1) * (returnval.degree2 + 1);  if (ncp != ncp1)    throw_error("Patch has wrong number of control points for this type");  const double* pr = mxGetPr(controlpts);  if (pr == 0)    throw_error("mxGetPr failed for control points");  for (int i = 0; i < ncp; ++i) {    int cp = static_cast<int>(pr[i]);    if (cp < 0 || cp >= c_num_control_points_)      throw_error("Control point index out of range");  }  returnval.control_point_indices = pr;  return returnval;}int QMG::Brep::face_number_of_patches(const Face_Spec& fspec) const {  int fdim = fspec.fdim();  int faceind = fspec.faceind();#ifdef DEBUGGING  if (fdim < 0 || fdim > c_gdim_ ||      faceind < 0 || faceind >=  c_num_top_faces_[fdim])    throw_error("Faceind out of range in face_number_of_patches");#endif  const mxArray* patchlist = mxGetCell(c_top_faces_[fdim], 				       5 * faceind + 4);  if (patchlist == 0)     throw_error("Unable to retrieve patchlist from brep face");  int prow = mxGetM(patchlist);  int numpatch = mxGetN(patchlist);  if (numpatch > 0 && prow != 3)    throw_error("Patchlist should be 3-by-k");  return numpatch;}    QMG::Brep::Loop_over_propvals_of_face::Loop_over_propvals_of_face(const Brep& g, const Face_Spec& f) {  int fdim = f.fdim();  int faceind = f.faceind();#ifdef DEBUGGING  if (fdim < 0 || fdim > g.c_gdim_ ||      faceind < 0 || faceind >=  g.c_num_top_faces_[fdim]) {    mexPrintf("Facespec=%d:%d numtopfaces=%d\n", fdim, faceind,	      g.c_num_top_faces_[fdim]);    throw_error("Faceind out of range in loop_over_propvals_of_face");  }#endif  pvlist_ = mxGetCell(g.c_top_faces_[fdim], 5 * faceind + 1);  if (pvlist_ == 0 || !mxIsCell(pvlist_))    throw_error("Illegal propval list for face");  int nr = mxGetM(pvlist_);  num_propvals_ = mxGetN(pvlist_);  if (num_propvals_ > 0 && nr != 2)    throw_error("Propval list of face should be 2-by-k");  count_ = 0;}QMG::string QMG::Brep::Loop_over_propvals_of_face::prop() const {  const mxArray* prop1 = mxGetCell(pvlist_, count_ * 2);  if (prop1 == 0 || !mxIsChar(prop1))    throw_error("Property is not a string");  int l = mxGetM(prop1) * mxGetN(prop1);  char* buf = new char[l + 2];  int returncode = mxGetString(prop1, buf, l + 1);  if (returncode) {    delete[] buf;    throw_error("Unable to retrieve string");  }  string propi(buf);  delete[] buf;  return propi;}QMG::string QMG::Brep::Loop_over_propvals_of_face::val() const {  const mxArray* val1 = mxGetCell(pvlist_, count_ * 2 + 1);  if (val1 == 0 || !mxIsChar(val1))    throw_error("Value is not a string");  int l = mxGetM(val1) * mxGetN(val1);  char* buf = new char[l + 2];  int returncode = mxGetString(val1, buf, l + 1);  if (returncode) {    delete[] buf;    throw_error("Unable to retrieve string");  }  string vali(buf);  delete[] buf;  return vali;}QMG::Brep::Loop_over_propvals_of_brep::Loop_over_propvals_of_brep(const Brep& g) {  pvlist_ = g.c_pvlist_;  num_propvals_ = g.c_numpv_;  count_ = 0;}QMG::string QMG::Brep::Loop_over_propvals_of_brep::prop() const {  const mxArray* prop1 = mxGetCell(pvlist_, count_ * 2);  if (prop1 == 0 || !mxIsChar(prop1))    throw_error("Property is not a string");  int l = mxGetM(prop1) * mxGetN(prop1);  char* buf = new char[l + 2];  int returncode = mxGetString(prop1, buf, l + 1);  if (returncode) {    delete[] buf;    throw_error("Unable to retrieve string");  }  string propi(buf);  delete[] buf;  return propi;}QMG::string QMG::Brep::Loop_over_propvals_of_brep::val() const {  const mxArray* val1 = mxGetCell(pvlist_, count_ * 2 + 1);  if (val1 == 0 || !mxIsChar(val1))    throw_error("Value is not a string");  int l = mxGetM(val1) * mxGetN(val1);  char* buf = new char[l + 2];  int returncode = mxGetString(val1, buf, l + 1);  if (returncode) {    delete[] buf;    throw_error("Unable to retrieve string");  }  string vali(buf);  delete[] buf;  return vali;}QMG::string QMG::Brep::face_lookup_prop_val(const Face_Spec& fspec,                                 const string& property) const {  int fdim = fspec.fdim();  int faceind = fspec.faceind();#ifdef DEBUGGING  if (fdim < 0 || fdim > c_gdim_ ||      faceind < 0 || faceind >=  c_num_top_faces_[fdim]) {    mexPrintf("Facespec=%d:%d numtopfaces=%d\n", fdim, faceind,	      c_num_top_faces_[fdim]);    throw_error("Faceind out of range in loop_over_propvals_of_face (2)");  }#endif  const mxArray* pvlist = mxGetCell(c_top_faces_[fdim], 5 * faceind + 1);  if (pvlist == 0 || !mxIsCell(pvlist))    throw_error("Illegal propval list for face");  int nr = mxGetM(pvlist);  int num_propvals = mxGetN(pvlist);  if (num_propvals > 0 && nr != 2)    throw_error("Propval list of face should be 2-by-k");  int len0 = property.length();  char* buf = new char[len0 + 2];  for (int pvnum = 0; pvnum < num_propvals; ++pvnum) {    const mxArray* prop1 = mxGetCell(pvlist, pvnum * 2);    if (prop1 == 0 || !mxIsChar(prop1)) {      delete[] buf;      throw_error("Illegal property name in face");    }    int len = mxGetM(prop1) * mxGetN(prop1);    if (len != len0) continue;    int returncode = mxGetString(prop1, buf, len0 + 1);    if (returncode) {      delete[] buf;      throw_error("Unable to retrieve string");    }    string p2(buf);    if (compare_nocase(p2, property) == 0) {      delete[] buf;      const mxArray* val1 = mxGetCell(pvlist, pvnum * 2 + 1);      if (val1 == 0 || !mxIsChar(val1))        throw_error("Illegal value in face");      int len1 = mxGetM(val1) * mxGetN(val1);      char* buf1 = new char[len1 + 2];      int returncode = mxGetString(val1, buf1, len1 + 1);      if (returncode) {        delete[] buf1;        throw_error("Unable to retrieve string");      }      string v1(buf1);      delete[] buf1;      return v1;    }  }  delete[] buf;  return string("");}QMG::string QMG::Brep::lookup_brep_propval(const string& property) const {  if (c_pvlist_ == 0 || !mxIsCell(c_pvlist_))    throw_error("Illegal propval list for brep");  int nr = mxGetM(c_pvlist_);  int num_propvals = mxGetN(c_pvlist_);  if (num_propvals > 0 && nr != 2)    throw_error("Propval list of face should be 2-by-k");  int len0 = property.length();  char* buf = new char[len0 + 2];  for (int pvnum = 0; pvnum < num_propvals; ++pvnum) {    const mxArray* prop1 = mxGetCell(c_pvlist_, pvnum * 2);    if (prop1 == 0 || !mxIsChar(prop1)) {      delete[] buf;      throw_error("Illegal property name in face");    }    int len = mxGetM(prop1) * mxGetN(prop1);    if (len != len0) continue;    int returncode = mxGetString(prop1, buf, len0 + 1);    if (returncode) {      delete[] buf;      throw_error("Unable to retrieve string");    }    string p2(buf);    if (compare_nocase(p2, property) == 0) {      delete[] buf;      const mxArray* val1 = mxGetCell(c_pvlist_, pvnum * 2 + 1);      if (val1 == 0 || !mxIsChar(val1))        throw_error("Illegal value in face");      int len1 = mxGetM(val1) * mxGetN(val1);      char* buf1 = new char[len1 + 2];      int returncode = mxGetString(val1, buf1, len1 + 1);      if (returncode) {        delete[] buf1;        throw_error("Unable to retrieve string");      }      string v1(buf1);      delete[] buf1;      return v1;    }  }  delete[] buf;  return string("");}doubleQMG::Brep::scale_factor() const {  double maxdist = 0.0;  for (int j = 0; j < c_num_control_points_ * c_embedded_dim_; ++j) {    Real d1 = fabs(c_control_points_[j]);    if (d1 > maxdist)      maxdist = d1;  }  return maxdist;}  QMG::stringQMG::Brep::face_name(const Face_Spec& fspec) const {  int fdim = fspec.fdim();  int faceind = fspec.faceind();#ifdef DEBUGGING  if (fdim < 0 || fdim > c_gdim_ ||      faceind < 0 || faceind >=  c_num_top_faces_[fdim]) {    mexPrintf("Facespec=%d:%d numtopfaces=%d\n", fdim, faceind,	      c_num_top_faces_[fdim]);    throw_error("Faceind out of range in face_name");  }#endif  const mxArray* facename =     mxGetCell(c_top_faces_[fdim], 5 * faceind);  if (facename == 0 || !mxIsChar(facename))    throw_error("Unable to retrieve face name");  int lth = mxGetM(facename) * mxGetN(facename);  char* buf = new char[lth + 2];  int returncode = mxGetString(facename, buf, lth + 1);  if (returncode) {    delete[] buf;    throw_error("Unable to retrieve string");  }  string s(buf);  delete[] buf;  // mexPrintf("face name %s\n", s.c_str());  return s;}  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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -