📄 qbrep_constr.cpp
字号:
// ------------------------------------------------------------------// qbrep_constr.cpp//// This file contains member functions of the class Brep_Under_Construction, and its// nested classes. This is a brep that is being built on the fly.// Matlab version.// ------------------------------------------------------------------// 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.// ------------------------------------------------------------------#include "qbrep_constr.h"namespace { void pause(const char* str) { mexPrintf("%s\nPress return", str); mxArray* plhs[1]; mxArray* prhs[1]; mexCallMATLAB(0, plhs, 0, prhs, "pause"); mexPrintf("continuing\n"); }}QMG::Brep_Under_Construction::Brep_Under_Construction(int intrinsic_dim, int embedded_dim) : Brep(){ mxArray* plhsa[1]; mxArray* prhsa[1]; mexCallMATLAB(1,plhsa,0, prhsa, "make_empty_zba"); geo_ = plhsa[0]; mxArray* oldentries = mxGetFieldByNumber(geo_,0, 0); if (oldentries) mxFree(oldentries); c_gdim_ = intrinsic_dim; c_embedded_dim_ = embedded_dim; c_numpv_ = 0; c_pvlist_ = mxCreateCellMatrix(2,0); c_num_control_points_ = 0; control_points_a_ = mxCreateDoubleMatrix(embedded_dim,0, mxREAL); c_control_points_ = mxGetPr(control_points_a_); child_lookup_map_ = new ChildLookupMapType; ib_lookup_map_ = new IBLookupMapType; { for (int fdim = 0; fdim <= intrinsic_dim; ++fdim) { c_num_top_faces_[fdim] = 0; c_top_faces_[fdim] = mxCreateCellMatrix(5,0); } } mxArray* geo_entries = mxCreateCellMatrix(6+intrinsic_dim,1); mxSetCell(geo_entries, 0, mxCreateString(io_header_code())); mxArray* intdim1 = mxCreateDoubleMatrix(1,1,mxREAL); *(mxGetPr(intdim1)) = static_cast<double>(intrinsic_dim); mxSetCell(geo_entries, 1, intdim1); mxArray* embdim1 = mxCreateDoubleMatrix(1,1,mxREAL); *(mxGetPr(embdim1)) = static_cast<double>(embedded_dim); mxSetCell(geo_entries, 2, embdim1); mxSetCell(geo_entries, 3, const_cast<mxArray*>(c_pvlist_)); mxSetCell(geo_entries, 4, control_points_a_); { for (int fdim = 0; fdim <= intrinsic_dim; ++fdim) { mxSetCell(geo_entries, 5+fdim, const_cast<mxArray*>(c_top_faces_[fdim])); } } mxSetFieldByNumber(const_cast<mxArray*>(geo_),0,0,geo_entries);}QMG::Brep_Under_Construction::Propval_inserter::Propval_inserter(Brep_Under_Construction& brep) : brep_(brep) { if (brep_.c_numpv_ > 0) throw_error("Propval inserter called more than once for brep"); maxsize_ = 0;}int QMG::Brep_Under_Construction::Propval_inserter::insert_propval(const string& prop, const string& val) { int npv = brep_.c_numpv_; if (npv == maxsize_) { int newsize = npv * 2 + 2; mxArray** oldcells = static_cast<mxArray**>(mxGetData(brep_.c_pvlist_)); mxArray** newcells = static_cast<mxArray**>(mxMalloc(2 * newsize * sizeof(mxArray*))); for (int j = 0; j < 2 * npv; ++j) newcells[j] = oldcells[j]; mxFree(oldcells); mxSetData(const_cast<mxArray*>(brep_.c_pvlist_), static_cast<void*>(newcells)); maxsize_ = newsize; } mxSetCell(const_cast<mxArray*>(brep_.c_pvlist_), 2 * npv, mxCreateString(prop.c_str())); mxSetCell(const_cast<mxArray*>(brep_.c_pvlist_), 2 * npv + 1, mxCreateString(val.c_str())); mxSetN(const_cast<mxArray*>(brep_.c_pvlist_), npv + 1); ++brep_.c_numpv_; return npv;} QMG::Brep_Under_Construction::Control_point_inserter::Control_point_inserter(Brep_Under_Construction& brep) : brep_(brep) { if (brep_.c_num_control_points_ > 0) throw_error("Control point inserter called more than once for brep"); maxsize_ = 0;}int QMG::Brep_Under_Construction::Control_point_inserter::insert_control_point(const vector<Real>& coord) { int di = brep_.c_embedded_dim_; if (coord.size() != di) throw_error("Wrong size vector in insert_control_point"); int ncp = brep_.c_num_control_points_; int numcoord = ncp * di; if (ncp == maxsize_) { int newsize = ncp * 2 + 2; double* newcp = static_cast<double*>(mxMalloc(sizeof(double) * newsize * di)); for (int j = 0; j < numcoord; ++j) newcp[j] = brep_.c_control_points_[j]; mxFree(const_cast<double*>(brep_.c_control_points_)); brep_.c_control_points_ = newcp; mxSetPr(brep_.control_points_a_, newcp); maxsize_ = newsize; } for (int i = 0; i < di; ++i) const_cast<double*>(brep_.c_control_points_)[di * ncp + i] = coord[i]; ++brep_.c_num_control_points_; mxSetN(brep_.control_points_a_, ncp + 1); return ncp;}QMG::Brep_Under_Construction::Top_face_inserter::Top_face_inserter(Brep_Under_Construction& brep, int dim) : brep_(brep), dim_(dim) { if (dim < 0 || dim > brep_.c_gdim_ || brep_.c_num_top_faces_[dim] > 0) throw_error("Top face inserter called more than once for brep"); maxsize_ = 0;}QMG::Brep::Face_SpecQMG::Brep_Under_Construction::Top_face_inserter::insert_top_face(const string& facename) { int numface = brep_.c_num_top_faces_[dim_]; mxArray* topfaces = const_cast<mxArray*>(brep_.c_top_faces_[dim_]); if (numface == maxsize_) { int newsize = numface * 2 + 2; mxArray** newlev = static_cast<mxArray**>(mxMalloc(sizeof(mxArray*) * newsize * 5)); mxArray** oldlev = static_cast<mxArray**>(mxGetData(topfaces)); for (int j = 0; j < numface * 5; ++j) newlev[j] = oldlev[j]; mxFree(oldlev); mxSetData(topfaces, static_cast<void*>(newlev)); maxsize_ = newsize; } mxSetCell(topfaces, 5 * numface, mxCreateString(facename.c_str())); mxSetCell(topfaces, 5 * numface + 1, mxCreateCellMatrix(2, 0)); mxSetCell(topfaces, 5 * numface + 2, mxCreateCellMatrix(1, 0)); mxSetCell(topfaces, 5 * numface + 3, mxCreateCellMatrix(1, 0)); mxSetCell(topfaces, 5 * numface + 4, mxCreateCellMatrix(3, 0)); mxSetN(topfaces, numface + 1); ++brep_.c_num_top_faces_[dim_]; return Brep::Face_Spec(dim_, numface);}QMG::Brep_Under_Construction::Top_face_bound_inserter::Top_face_bound_inserter(Brep_Under_Construction& brep, const Brep::Face_Spec& fspec) : brep_(brep), childlist_((*(brep.child_lookup_map_))[fspec]), fspec_(fspec){ int fdim = fspec.fdim(); int faceind = fspec.faceind(); if (fdim < 0 || fdim > brep_.c_gdim_ || faceind < 0 || faceind >= brep_.c_num_top_faces_[fdim]) throw_error("Range error in top face bound inserter"); childlist1_ = mxGetCell(brep_.c_top_faces_[fdim], 5 * faceind + 2); if (childlist1_ == 0 || mxGetN(childlist1_) > 0) throw_error("Attempt to create child-inserter to face that already has children"); maxsize_ = 0;}void QMG::Brep_Under_Construction::Top_face_bound_inserter::insert_boundary(const Brep::Face_Spec& subfspec, int orientation) { int numchild = mxGetN(childlist1_); if (numchild == maxsize_) { int newsize = numchild * 2 + 2; mxArray** oldcells = static_cast<mxArray**>(mxGetData(childlist1_)); mxArray** newcells = static_cast<mxArray**>(mxMalloc(newsize * sizeof(mxArray*))); for (int j = 0; j < numchild; ++j) newcells[j] = oldcells[j]; mxFree(oldcells); mxSetData(childlist1_, static_cast<void*>(newcells)); maxsize_ = newsize; } mxSetN(childlist1_, numchild + 1); if (orientation == 0) { mxSetCell(childlist1_, numchild, mxCreateString((string("+") + brep_.face_name(subfspec)).c_str())); } else if (orientation == 1) { mxSetCell(childlist1_, numchild, mxCreateString((string("-") + brep_.face_name(subfspec)).c_str())); } else { mxSetCell(childlist1_, numchild, mxCreateString(brep_.face_name(subfspec).c_str())); } Face_Rec1 rec; rec.faceind = subfspec.faceind(); rec.ori = orientation; childlist_.push_back(rec);}QMG::Brep_Under_Construction::Top_face_ib_inserter::Top_face_ib_inserter(Brep_Under_Construction& brep, const Brep::Face_Spec& fspec) : brep_(brep), childlist_((*(brep.child_lookup_map_))[fspec]),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -