qbrep_constr.cpp
来自「算断裂的」· C++ 代码 · 共 929 行 · 第 1/3 页
CPP
929 行
// ------------------------------------------------------------------// qbrep_constr.cpp//// This file contains member functions for qbrep_constr.h// ------------------------------------------------------------------// 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"// See qbrep_constr.h for comments. This code is a mess because// of the large number of subcases. But it's not sophisticated.extern "C" {#include <stdlib.h>#include <stdio.h>}#ifdef USE_DEBUG_MALLOC#define malloc(x) debug_malloc(x,__LINE__,__FILE__)#define free(x) debug_free(x,__LINE__,__FILE__)extern "C" { void* debug_malloc(size_t sz, int lineno, const char* filename); void debug_free(void* ptr, int lineno, const char* filename);}#endifnamespace { using namespace QMG; void* malloc1(size_t sz) { char tmp[100]; void* p = malloc(sz); if (p == 0) { sprintf(tmp, "Out of memory on malloc of size %d", sz); throw_error(tmp); } return p; }}QMG::Brep_Under_Construction::Brep_Under_Construction(int intrinsic_dim, int embedded_dim) :Brep(static_cast<Cptc_GeomDesc*>(malloc1(sizeof(Cptc_GeomDesc)))) { geo_ -> intrinsic_dimension = intrinsic_dim; geo_ -> embedded_dimension = embedded_dim; geo_ -> num_properties = 0; geo_ -> num_control_pts = 0; geo_ -> num_top_vertices = 0; geo_ -> num_top_edges = 0; geo_ -> num_top_surfaces = 0; geo_ -> num_top_regions = 0; geo_ -> control_points = 0; geo_ -> top_vertices = 0; geo_ -> top_edges = 0; geo_ -> top_surfaces = 0; geo_ -> top_regions = 0; if (embedded_dim < 2 || embedded_dim > 3) { free(geo_); throw_error("Embedded dimension out of range"); } if (intrinsic_dim < 0 || intrinsic_dim > embedded_dim) { free(geo_); throw_error("Intrinsic dimension out of range"); }}QMG::Brep_Under_Construction::Propval_inserter::Propval_inserter(Brep_Under_Construction& brep) : brep_(brep) { geo_ = brep.geo_; if (geo_-> num_properties != 0) throw_error("Illegal to create Control_pointer_inserter more than once"); maxsize_ = 1; geo_ -> props = static_cast<char**>(malloc1(sizeof(char*))); geo_ -> values = static_cast<char**>(malloc1(sizeof(char*)));}int QMG::Brep_Under_Construction::Propval_inserter::insert_propval(const string& prop, const string& val) { int insertpos = geo_ -> num_properties; if (insertpos == maxsize_) { int newsize = maxsize_ * 2 + 1; char** new_props = static_cast<char**>(malloc1(sizeof(char*) * newsize)); char** new_vals = static_cast<char**>(malloc1(sizeof(char*) * newsize)); for (int j = 0; j < insertpos; ++j) { new_props[j] = geo_ -> props[j]; new_vals[j] = geo_ -> values[j]; } free(geo_ -> props); free(geo_ -> values); maxsize_ = newsize; geo_ -> props = new_props; geo_ -> values = new_vals; } int l1 = prop.length(); geo_ -> props[insertpos] = static_cast<char*>( malloc1(sizeof(char) * (l1 + 1))); prop.copy(geo_ -> props[insertpos], l1); geo_ -> props[insertpos][l1] = 0; int l2 = val.length(); geo_ -> values[insertpos] = static_cast<char*>( malloc1(sizeof(char) * (l2 + 1))); val.copy(geo_ -> values[insertpos], l2); geo_ -> values[insertpos][l2] = 0; ++(geo_ -> num_properties); return insertpos;}QMG::Brep_Under_Construction::Control_point_inserter::Control_point_inserter(Brep_Under_Construction& brep) : brep_(brep) { geo_ = brep.geo_; if (geo_-> control_points != 0) throw_error("Illegal to create Control_pointer_inserter more than once"); maxsize_ = 1; geo_-> control_points = static_cast<Cptc_GPoint*>(malloc1(sizeof(Cptc_GPoint))); geo_ -> num_control_pts = 0;}int QMG::Brep_Under_Construction::Control_point_inserter::insert_control_point(const vector<Real>& coord) { int insertpos = geo_ -> num_control_pts; if (geo_ -> embedded_dimension != coord.size()) throw_error("Control point wrong length"); if (insertpos == maxsize_) { int newsize = maxsize_ * 2 + 1; Cptc_GPoint* new_control_points = static_cast<Cptc_GPoint*>(malloc1(sizeof(Cptc_GPoint) * newsize)); for (int j = 0; j < insertpos; ++j) { new_control_points[j] = geo_ -> control_points[j]; } free(geo_ -> control_points); maxsize_ = newsize; geo_ -> control_points = new_control_points; } for (int ii = 0; ii < coord.size(); ++ii) { geo_ -> control_points[insertpos].coord[ii] = coord[ii]; } ++(geo_ -> num_control_pts); return insertpos;}QMG::Brep_Under_Construction::Top_face_inserter::Top_face_inserter(Brep_Under_Construction& brep, int dim) : brep_(brep) { geo_ = brep.geo_; dim_ = dim; maxsize_ = 1; if (dim_ < 0 || dim_ > geo_ -> intrinsic_dimension) throw_error("Dimension out of range"); if (dim_ == 0) { if (geo_-> top_vertices != 0) throw_error("Illegal to create top vertex inserter more than once"); geo_-> top_vertices = static_cast<Cptc_TVertex*>(malloc1(sizeof(Cptc_TVertex))); geo_ -> num_top_vertices = 0; } else if (dim_ == 1) { if (geo_ -> top_edges != 0) throw_error("Illegal to create top edge inserter more than once"); geo_ -> top_edges = static_cast<Cptc_TEdge*>(malloc1(sizeof(Cptc_TEdge))); geo_ -> num_top_edges = 0; } else if (dim_ == 2) { if (geo_ -> top_surfaces != 0) throw_error("Illegal to create top surface inserter more than once"); geo_ -> top_surfaces = static_cast<Cptc_TSurface*>(malloc1(sizeof(Cptc_TSurface))); geo_ -> num_top_surfaces = 0; } else if (dim_ == 3) { if (geo_ -> top_regions != 0) throw_error("Illegal to create top region inserter more than once"); geo_ -> top_regions = static_cast<Cptc_TRegion*>(malloc1(sizeof(Cptc_TRegion))); geo_ -> num_top_regions = 0; } else { throw_error("Unknown dimension"); }}QMG::Brep::Face_Spec QMG::Brep_Under_Construction::Top_face_inserter::insert_top_face(const string& name) { if (dim_ == 0) { int insertpos = geo_ -> num_top_vertices; if (insertpos == maxsize_) { int newsize = maxsize_ * 2 + 1; Cptc_TVertex* new_vertices = static_cast<Cptc_TVertex*>(malloc1(sizeof(Cptc_TVertex) * newsize)); for (int j = 0; j < insertpos; ++j) { new_vertices[j] = geo_ -> top_vertices[j]; } free(geo_ -> top_vertices); maxsize_ = newsize; geo_ -> top_vertices = new_vertices; } geo_ -> top_vertices[insertpos].props = 0; geo_ -> top_vertices[insertpos].values = 0; geo_ -> top_vertices[insertpos].num_properties = 0; geo_ -> top_vertices[insertpos].control_pnt_indx = -1; int l = name.length(); geo_ -> top_vertices[insertpos].id = static_cast<char*>(malloc1(sizeof(char) * (l+1))); name.copy(geo_ -> top_vertices[insertpos].id, l); geo_ -> top_vertices[insertpos].id[l] = 0; ++(geo_ -> num_top_vertices); return Brep::Face_Spec(0,insertpos); } else if (dim_ == 1) { int insertpos = geo_ -> num_top_edges; if (insertpos == maxsize_) { int newsize = maxsize_ * 2 + 1; Cptc_TEdge* new_edges = static_cast<Cptc_TEdge*>(malloc1(sizeof(Cptc_TEdge) * newsize)); for (int j = 0; j < insertpos; ++j) { new_edges[j] = geo_ -> top_edges[j]; } free(geo_ -> top_edges); maxsize_ = newsize; geo_ -> top_edges = new_edges; } geo_ -> top_edges[insertpos].props = 0; geo_ -> top_edges[insertpos].values = 0; geo_ -> top_edges[insertpos].bound_vertices = 0; geo_ -> top_edges[insertpos].num_bound_vertices = 0; geo_ -> top_edges[insertpos].num_curves = 0; geo_ -> top_edges[insertpos].curves = 0; geo_ -> top_edges[insertpos].num_properties = 0; int l = name.length(); geo_ -> top_edges[insertpos].id = static_cast<char*>(malloc1(sizeof(char) * (l+1))); name.copy(geo_ -> top_edges[insertpos].id, l); geo_ -> top_edges[insertpos].id[l] = 0; ++(geo_ -> num_top_edges); return Brep::Face_Spec(1,insertpos); } else if (dim_ == 2) { int insertpos = geo_ -> num_top_surfaces; if (insertpos == maxsize_) { int newsize = maxsize_ * 2 + 1; Cptc_TSurface* new_surfaces = static_cast<Cptc_TSurface*>(malloc1(sizeof(Cptc_TSurface) * newsize)); for (int j = 0; j < insertpos; ++j) { new_surfaces[j] = geo_ -> top_surfaces[j]; } free(geo_ -> top_surfaces); maxsize_ = newsize; geo_ -> top_surfaces = new_surfaces; } geo_ -> top_surfaces[insertpos].props = 0; geo_ -> top_surfaces[insertpos].values = 0; geo_ -> top_surfaces[insertpos].bound_vertices = 0; geo_ -> top_surfaces[insertpos].num_bound_vertices = 0; geo_ -> top_surfaces[insertpos].bound_edges = 0; geo_ -> top_surfaces[insertpos].num_bound_edges = 0; geo_ -> top_surfaces[insertpos].num_patches = 0; geo_ -> top_surfaces[insertpos].patches = 0; geo_ -> top_surfaces[insertpos].num_properties = 0; int l = name.length(); geo_ -> top_surfaces[insertpos].id = static_cast<char*>(malloc1(sizeof(char) * (l+1))); name.copy(geo_ -> top_surfaces[insertpos].id, l); geo_ -> top_surfaces[insertpos].id[l] = 0; ++(geo_ -> num_top_surfaces); return Brep::Face_Spec(2,insertpos); } // else if dim_ == 3 int insertpos = geo_ -> num_top_regions; if (insertpos == maxsize_) { int newsize = maxsize_ * 2 + 1; Cptc_TRegion* new_regions = static_cast<Cptc_TRegion*>(malloc1(sizeof(Cptc_TRegion) * newsize)); for (int j = 0; j < insertpos; ++j) { new_regions[j] = geo_ -> top_regions[j]; } free(geo_ -> top_regions); maxsize_ = newsize; geo_ -> top_regions = new_regions; } geo_ -> top_regions[insertpos].props = 0; geo_ -> top_regions[insertpos].values = 0; geo_ -> top_regions[insertpos].bound_vertices = 0; geo_ -> top_regions[insertpos].num_bound_vertices = 0; geo_ -> top_regions[insertpos].bound_edges = 0;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?