qbrep.h
来自「算断裂的」· C头文件 代码 · 共 458 行
H
458 行
// ------------------------------------------------------------------// qbrep.h//// This file contains the definitions of the class Brep and its// nested classes.// ------------------------------------------------------------------// 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.// ------------------------------------------------------------------#ifndef QBREP_H#define QBREP_H#include "qnamesp.h"#include "qpoint.h"#include "qpatchmath.h"extern "C" {#include "GeoFmt.h"}// ------------------------------------------------------------------// Class QMG::Brep// A Brep is a C++ wrapper around the internal C data structure to// represent geometries.class QMG::Brep {protected: Cptc_GeomDesc* geo_; explicit Brep(Cptc_GeomDesc* geo) : geo_(geo) { } // No assignmentprivate: void operator=(const Brep&) { }public: // Copying OK; copies pointer Brep(const Brep& o) : geo_(o.geo_) { } // The name of the property with the global id. static string global_id_propname() {return string("geo_global_id");} // The type string to go into ascii format. static const char* io_header_code() {return "brep_v2.0";} typedef int FaceIndex; // ------------------------------------------------------------------ // class QMG::Brep::Face_Spec // a Brep::Face_Spec specifies a topological face (entity) of a brep. // It is two integers: the first is the dimension of the face // (i.e. 0 = top vtx, 1 = top edge, etc) and the second is the // index within the dimension. class Face_Spec { protected: int fdim_; FaceIndex faceind_; public: inline int fdim() const {return fdim_;} inline FaceIndex faceind() const {return faceind_;} Face_Spec(int fdim1, FaceIndex faceind1) : fdim_(fdim1), faceind_(faceind1) { } Face_Spec() { } Face_Spec(const Face_Spec& fspec) : fdim_(fspec.fdim_), faceind_(fspec.faceind_) { } inline virtual Face_Spec& operator=(const Face_Spec& fspec) { fdim_ = fspec.fdim(); faceind_ = fspec.faceind(); return *this; } inline bool operator==(const Face_Spec& fspec) const { return fspec.fdim_ == fdim_ && fspec.faceind_ == faceind_; } inline bool operator!=(const Face_Spec& fspec) const { return fspec.fdim_ != fdim_ || fspec.faceind_ != faceind_; } inline bool operator<(const Face_Spec& fspec) const { return fdim_ < fspec.fdim_ || (fdim_ == fspec.fdim_ && faceind_ < fspec.faceind_); } inline bool operator<=(const Face_Spec& fspec) const { return (*this < fspec) || (*this == fspec); } inline bool operator>(const Face_Spec& fspec) const { return fspec < *this; } inline bool operator>=(const Face_Spec& fspec) const { return (fspec < *this) || (*this == fspec); } virtual ~Face_Spec() {} }; typedef int PatchIndex; typedef int ControlPointIndex; int level_size(int dim) const; // ------------------------------------------------------------------ // class QMG::Brep::Face_Spec_Loop_Over_Faces_Of_Dim // This class is for iterating over all topological faces of a certain // dimension. It is used like this: // for (Brep::Face_Spec_Loop_Over_Faces_Of_Dim fspec(g, d); fspec.notdone(); // ++fspec()) { ... } class Face_Spec_Loop_Over_Faces_Of_Dim; friend class Face_Spec_Loop_Over_Faces_Of_Dim; class Face_Spec_Loop_Over_Faces_Of_Dim : public Face_Spec { private: int num_face_; // no copying, no assignment Face_Spec_Loop_Over_Faces_Of_Dim(const Face_Spec_Loop_Over_Faces_Of_Dim&) { } virtual Face_Spec& operator=(const Face_Spec&) {return *this;} void operator=(const Face_Spec_Loop_Over_Faces_Of_Dim&) { } public: Face_Spec_Loop_Over_Faces_Of_Dim(const Brep& g, int d) : Face_Spec(d,0), num_face_(g.level_size(d)) { } bool notdone() const {return this -> faceind_ < num_face_;} void operator++() { ++(this -> faceind_); } }; // ------------------------------------------------------------------ // class QMG::Brep::Face_Spec_Loop_Over_Faces // This class is for iterating over all topological faces of the // whole brep. Its usage is: // for (Brep::Face_Spec_Loop_Over_Faces fspec(g); fspec.notdone(); // ++fspec()) { ... } class Face_Spec_Loop_Over_Faces; friend class Face_Spec_Loop_Over_Faces; class Face_Spec_Loop_Over_Faces : public Face_Spec { private: const Brep& g_; int num_face_this_lev_; int bump_lev_(int d) { while (d <= g_.gdim() && g_.level_size(d) == 0) ++d; return d; } // no copying, no assignment virtual Face_Spec& operator=(const Face_Spec&) {return *this; } Face_Spec_Loop_Over_Faces(const Face_Spec_Loop_Over_Faces& o) : g_(o.g_) { } void operator=(const Face_Spec_Loop_Over_Faces&) { } public: explicit Face_Spec_Loop_Over_Faces(const Brep& g) : g_(g) { this -> fdim_ = bump_lev_(0); this -> faceind_ = 0; } void operator++() { ++(this -> faceind_); if (this -> faceind_ == g_.level_size(this -> fdim_)) { this -> fdim_ = bump_lev_(this -> fdim_ + 1); this -> faceind_ = 0; } } bool notdone() const {return this -> fdim_ <= g_.gdim(); } }; // ------------------------------------------------------------------ // class QMG::Brep::Face_Spec_Loop_Over_Face_Subfaces // This class is for iterating over all topological faces that are // subfaces (either internal boundaries or bounding) of a given face. // The usage is: // for (Brep::Face_Spec_Loop_Over_Face_Subfaces subfspec(g,fspec); subfspec.notdone(); // ++subfspec()) { ... } class Face_Spec_Loop_Over_Face_Subfaces; friend class Face_Spec_Loop_Over_Face_Subfaces; class Face_Spec_Loop_Over_Face_Subfaces : public Face_Spec { int parentfdim_; union { Cptc_TEdge* this_edge_; Cptc_TSurface* this_surf_; Cptc_TRegion* this_region_; }; int count_; int orientation_; void set_this_(); // no copying, no assignment Face_Spec_Loop_Over_Face_Subfaces(const Face_Spec_Loop_Over_Face_Subfaces&) { } void operator=(const Face_Spec_Loop_Over_Face_Subfaces&) { } virtual Face_Spec& operator=(const Face_Spec&) {return *this; } public: Face_Spec_Loop_Over_Face_Subfaces(const Brep& g, const Face_Spec& f); void operator++() {++count_; set_this_();} bool notdone() const {return this -> fdim_ >= 0;} int orientation() const { return orientation_;} bool is_internal_boundary() const {return this -> fdim_ < parentfdim_ - 1; } };private: // ------------------------------------------------------------------ // This class is for doing math with patches of a // brep. It is a wrapper around the patchmath class. class PatchMath_for_Brep; friend class PatchMath_for_Brep; class PatchMath_for_Brep : public PatchMath { private: Cptc_GeomDesc* geo_; int patchdim_; FaceIndex faceind_; PatchIndex patchind_; Real control_point_coord_(int cpnum, int d) const; public: PatchMath_for_Brep(PatchType ptype, int degree1, int degree2, Cptc_GeomDesc* geo, int facedim, FaceIndex faceind, PatchIndex patchind) : PatchMath(ptype, degree1, degree2, facedim, geo -> embedded_dimension, false), geo_(geo), patchdim_(facedim), faceind_(faceind), patchind_(patchind) { } ~PatchMath_for_Brep() { } };public: PatchMath_for_Brep patchmath(const Face_Spec& fspec, PatchIndex patchind) const; int patch_degree1(const Face_Spec& fspec, PatchIndex patchind) const; int patch_degree2(const Face_Spec& fspec, PatchIndex patchind) const; PatchType patch_type(const Face_Spec& fspec, PatchIndex patchind) const; ControlPointIndex patch_control_point(const Face_Spec& fspec, PatchIndex patchind, int cpindex) const; int face_number_of_patches(const Face_Spec& fspec) const; // ------------------------------------------------------------------ // class QMG::Brep::Loop_over_patches_of_face // This class is for iterating over all patches of a topological face. // The usage is: // for (Brep::Loop_over_patches_of_face patch(g,fspec); patch.notdone(); // ++patch()) { Use patch.X here } class Loop_over_patches_of_face; friend class Loop_over_patches_of_face; class Loop_over_patches_of_face { const Brep& brep_; const Face_Spec& fspec_; union { Cptc_TVertex* this_vertex_; Cptc_TEdge* this_edge_; Cptc_TSurface* this_surf_; }; PatchIndex count_; int num_patches_; // no copying, no assignment Loop_over_patches_of_face(const Loop_over_patches_of_face& o): brep_(o.brep_), fspec_(o.fspec_) { } void operator=(const Loop_over_patches_of_face&) { } public: Loop_over_patches_of_face(const Brep& g, const Face_Spec& f); void operator++() {++count_;} bool notdone() const {return count_ < num_patches_;} int degree1() const; int degree2() const; PatchType ptype() const; PatchIndex index() const {return count_;} ControlPointIndex control_point(int j) const; PatchMath_for_Brep patchmath() const { return brep_.patchmath(fspec_, count_); } }; // ------------------------------------------------------------------ // class QMG::Brep::Loop_over_propvals_of_face // This class is for iterating over all property-value pairs of a topological face. // The usage is: // for (Brep::Loop_over_propvals_of_face pvloop(g, fspec); pvloop.notdone(); // ++pvloop) { Use pvloop.prop() and pvloop.val() } class Loop_over_propvals_of_face; friend class Loop_over_propvals_of_face; class Loop_over_propvals_of_face { const char* const* props_; const char* const* vals_; int count_; int num_propvals_; // no copying, no assignment Loop_over_propvals_of_face(const Loop_over_propvals_of_face&) { } void operator=(const Loop_over_propvals_of_face&) { } public: Loop_over_propvals_of_face(const Brep& g, const Face_Spec& f); void operator++() {++count_;} bool notdone() const {return count_ < num_propvals_;} string prop() const {return string(props_[count_]);} string val() const {return string(vals_[count_]);} }; // ------------------------------------------------------------------ // class QMG::Brep::Loop_over_propvals_of_brep // This class is for iterating over all property-value pairs of the rep // The usage is: // for (Brep::Loop_over_propvals_of_face brep(g); pvloop.notdone(); // ++pvloop) { Use pvloop.prop() and pvloop.val() } class Loop_over_propvals_of_brep; friend class Loop_over_propvals_of_brep; class Loop_over_propvals_of_brep { const char* const* props_; const char* const* vals_; int count_; int num_propvals_; // no copying, no assignment Loop_over_propvals_of_brep(const Loop_over_propvals_of_brep&) { } void operator=(const Loop_over_propvals_of_brep&) { } public: explicit Loop_over_propvals_of_brep(const Brep& g); void operator++() {++count_;} bool notdone() const {return count_ < num_propvals_;} string prop() const {return string(props_[count_]);} string val() const {return string(vals_[count_]);} }; // ------------------------------------------------------------------ // class Brep::Face_Labeling<T> // A data structure to that allows brep faces to be labeled with // elements of data type T. // To construct one, use Brep::Face_Labeling<T> lbl1(g, {,t}) // where g is a brep and t is the default value for faces // not explicitly assigned a label. // To set a label use // lbl1(fspec) = value; // To read it // t = lbl1(fspec); template<class T> class Face_Labeling { map<Face_Spec, T> labels_; typedef map<Face_Spec, T> MapType;#ifdef NEED_TYPENAME_KEYWD typedef typename map<Face_Spec,T>::iterator FaceLabelIt; typedef typename MapType::const_iterator FaceLabelCIt;#else typedef MapType::iterator FaceLabelIt; typedef MapType::const_iterator FaceLabelCIt;#endif T default_label_; // no copying, no assignment Face_Labeling(const Face_Labeling<T>& ) { } void operator=(const Face_Labeling<T>&) { } public: explicit Face_Labeling(const Brep&, const T& default1 = T()) : default_label_(default1) { } T& operator()(const Face_Spec& fspec) { FaceLabelIt it = labels_.find(fspec); if (it == labels_.end()) { labels_[fspec] = default_label_; return labels_[fspec]; } else { return it -> second; } } const T& operator()(const Face_Spec& fspec) const { FaceLabelCIt it = labels_.find(fspec); if (it == labels_.end()) { return default_label_; } else { return it -> second; } } ~Face_Labeling() { } }; class Ancestor_Lookup; // g.gdim() returns the intrinsic dimension of the brep int gdim() const {return geo_ -> intrinsic_dimension;} // g.embedded_dim() returns the embedded dimension of the brep int embedded_dim() const {return geo_ -> embedded_dimension;} // g.num_control_points() returns the total number of control points of the brep. int num_control_points() const { return geo_ -> num_control_pts;} // g.control_point(i,j) returns coordinate entry j of control point i. Real control_point(ControlPointIndex i, int d) const {#ifdef RANGECHECK if (i < 0 || i >= geo_ -> num_control_pts) { throw_error("Conrol point index out of range"); } if (d < 0 || d >= geo_ -> embedded_dimension) { throw_error("Dimension of control point out of range"); }#endif return geo_ -> control_points[i].coord[d]; } // g.face_lookup_propval(fspec, prop) looks up the value associated with // property prop for topological face fspec. If no such property exists, // the null string is returned. string face_lookup_prop_val(const Face_Spec& fspec, const string& property) const; string lookup_brep_propval(const string& property) const; double scale_factor() const; // g.face_name(fspec) gives the name of a face. string face_name(const Face_Spec& fspec) const; virtual ~Brep() { }};// Brep_From_FrontEnd same as brep.class QMG::Brep_From_FrontEnd : public QMG::Brep {public: Brep_From_FrontEnd(const Brep_From_FrontEnd& b) : Brep(b) { } explicit Brep_From_FrontEnd(Cptc_GeomDesc* geo) : Brep(geo) { }};extern QMG::ostream& operator<<(QMG::ostream& s, const QMG::Brep& brep);extern QMG::ostream& operator<<(QMG::ostream& s, const QMG::Brep::Face_Spec& fspec);#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?