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

📄 ogl_helper.h

📁 很多二维 三维几何计算算法 C++ 类库
💻 H
📖 第 1 页 / 共 2 页
字号:
      style = index;    }    bool is_initialized() const { return init_; }    Bbox_3  bbox() const { return bbox_; }    Bbox_3& bbox()       { return bbox_; }    void draw(Vertex_iterator v) const {       //      CGAL_NEF_TRACEN("drawing vertex "<<*v);      CGAL::Color cf(CGAL_NEF3_MARKED_VERTEX_COLOR), 	ct(CGAL_NEF3_UNMARKED_VERTEX_COLOR); // more blue-ish      CGAL::Color c = v->mark() ? ct : cf;      glPointSize(10);      glColor3ub(c.red(), c.green(), c.blue());      glBegin(GL_POINTS);      glVertex3d(v->x(),v->y(),v->z());      glEnd();    }    void draw(Edge_iterator e) const {       //      CGAL_NEF_TRACEN("drawing edge "<<*e);      Double_point p = e->source(), q = e->target();      CGAL::Color cf(CGAL_NEF3_MARKED_EDGE_COLOR), 	ct(CGAL_NEF3_UNMARKED_EDGE_COLOR); // more blue-ish      CGAL::Color c = e->mark() ? ct : cf;      glLineWidth(5);      glColor3ub(c.red(),c.green(),c.blue());      glBegin(GL_LINE_STRIP);      glVertex3d(p.x(), p.y(), p.z());      glVertex3d(q.x(), q.y(), q.z());      glEnd();    }    void draw(Halffacet_iterator f) const {       //      CGAL_NEF_TRACEN("drawing facet "<<(f->debug(),""));      GLUtesselator* tess_ = gluNewTess();      gluTessCallback(tess_, GLenum(GLU_TESS_VERTEX_DATA),		      (GLvoid (CGAL_GLU_TESS_CALLBACK *)(CGAL_GLU_TESS_DOTS)) &vertexCallback);      gluTessCallback(tess_, GLenum(GLU_TESS_BEGIN),		      (GLvoid (CGAL_GLU_TESS_CALLBACK *)(CGAL_GLU_TESS_DOTS)) &beginCallback);      gluTessCallback(tess_, GLenum(GLU_TESS_END),		      (GLvoid (CGAL_GLU_TESS_CALLBACK *)(CGAL_GLU_TESS_DOTS)) &endCallback);      gluTessCallback(tess_, GLenum(GLU_TESS_ERROR),		      (GLvoid (CGAL_GLU_TESS_CALLBACK *)(CGAL_GLU_TESS_DOTS)) &errorCallback);      gluTessProperty(tess_, GLenum(GLU_TESS_WINDING_RULE),		      GLU_TESS_WINDING_POSITIVE);      DFacet::Coord_const_iterator cit;      CGAL::Color cf(CGAL_NEF3_MARKED_FACET_COLOR),	ct(CGAL_NEF3_UNMARKED_FACET_COLOR); // more blue-ish      CGAL::Color c = (f->mark() ? ct : cf);      glColor3ub(c.red(),c.green(),c.blue());      gluTessBeginPolygon(tess_,f->normal());      //      CGAL_NEF_TRACEN(" ");      //      CGAL_NEF_TRACEN("Begin Polygon");      gluTessNormal(tess_,f->dx(),f->dy(),f->dz());      // forall facet cycles of f:      for(unsigned i = 0; i < f->number_of_facet_cycles(); ++i) {        gluTessBeginContour(tess_);	//	CGAL_NEF_TRACEN("  Begin Contour");	// put all vertices in facet cycle into contour:	for(cit = f->facet_cycle_begin(i); 	    cit != f->facet_cycle_end(i); ++cit) {	  gluTessVertex(tess_, *cit, *cit);	  //	  CGAL_NEF_TRACEN("    add Vertex");	}        gluTessEndContour(tess_);	//	CGAL_NEF_TRACEN("  End Contour");      }      gluTessEndPolygon(tess_);      //      CGAL_NEF_TRACEN("End Polygon");      gluDeleteTess(tess_);    }    void construct_axes() const    {       glLineWidth(2.0);      // red x-axis      glColor3f(1.0,0.0,0.0);      glBegin(GL_LINES);      glVertex3f(0.0,0.0,0.0);      glVertex3f(5000.0,0.0,0.0);      glEnd();       // green y-axis       glColor3f(0.0,1.0,0.0);      glBegin(GL_LINES);      glVertex3f(0.0,0.0,0.0);      glVertex3f(0.0,5000.0,0.0);      glEnd();      // blue z-axis and equator      glColor3f(0.0,0.0,1.0);      glBegin(GL_LINES);      glVertex3f(0.0,0.0,0.0);      glVertex3f(0.0,0.0,5000.0);      glEnd();      // six coordinate points in pink:      glPointSize(10);      glBegin(GL_POINTS);      glColor3f(1.0,0.0,0.0);      glVertex3d(5,0,0);      glColor3f(0.0,1.0,0.0);      glVertex3d(0,5,0);      glColor3f(0.0,0.0,1.0);      glVertex3d(0,0,5);      glEnd();    }    void fill_display_lists() {      glNewList(object_list_, GL_COMPILE);      Vertex_iterator v;      for(v=vertices_.begin();v!=vertices_.end();++v) 	draw(v);      glEndList();           glNewList(object_list_+1, GL_COMPILE);      Edge_iterator e;      for(e=edges_.begin();e!=edges_.end();++e)	draw(e);      glEndList();           glNewList(object_list_+2, GL_COMPILE);      Halffacet_iterator f;      for(f=halffacets_.begin();f!=halffacets_.end();++f)	draw(f);      glEndList();      glNewList(object_list_+3, GL_COMPILE); // axes:      construct_axes();      glEndList();    }    void init() {       if (init_) return;      init_ = true;      switches[SNC_AXES] = false;      style = SNC_BOUNDARY;      object_list_ = glGenLists(4);       CGAL_assertion(object_list_);       fill_display_lists();    }    void draw() const    {       if (!is_initialized()) const_cast<Polyhedron&>(*this).init();      double l = (std::max)( (std::max)( bbox().xmax() - bbox().xmin(),					 bbox().ymax() - bbox().ymin()),			     bbox().zmax() - bbox().zmin());      if ( l < 1) // make sure that a single point doesn't screw up here          l = 1;      glScaled( 4.0/l, 4.0/l, 4.0/l);      glTranslated( -(bbox().xmax() + bbox().xmin()) / 2.0,                    -(bbox().ymax() + bbox().ymin()) / 2.0,                    -(bbox().zmax() + bbox().zmin()) / 2.0);      if (style == SNC_BOUNDARY) {	//glEnable(GL_LIGHTING); 	glCallList(object_list_+2); // facets	//glDisable(GL_LIGHTING);      }      // move edges and vertices a bit towards the view-point,       // i.e., 1/100th of the unit vector in camera space      //      double f = l / 4.0 / 100.0;      //      glTranslated( z_vec[0] * f, z_vec[1] * f, z_vec[2] * f);      glCallList(object_list_+1); // edges      glCallList(object_list_);   // vertices      if (switches[SNC_AXES]) glCallList(object_list_+3); // axis   }    void debug(std::ostream& os = std::cerr) const    {      os << "OGL::Polyhedron" << std::endl;      os << "Vertices:" << std::endl;      Vertex_iterator v;      for(v=vertices_.begin();v!=vertices_.end();++v) 	os << "  "<<*v<<", mark="<<v->mark()<<std::endl;      os << "Edges:" << std::endl;      Edge_iterator e;      for(e=edges_.begin();e!=edges_.end();++e)	os << "  "<<*e<<", mark="<<e->mark()<<std::endl;      os << "Facets:" << std::endl;      Halffacet_iterator f;      for(f=halffacets_.begin();f!=halffacets_.end();++f)	f->debug(); os << std::endl;      os << std::endl;    }  }; // Polyhedron  template<typename Nef_polyhedron>  class Nef3_Converter {     typedef typename Nef_polyhedron::SNC_structure           SNC_structure;    typedef CGAL::SNC_decorator<SNC_structure>               Base;    typedef CGAL::SNC_FM_decorator<SNC_structure>            FM_decorator;        public:    typedef typename SNC_structure::Vertex_const_iterator Vertex_const_iterator;     typedef typename SNC_structure::Halfedge_const_iterator Halfedge_const_iterator;     typedef typename SNC_structure::Halffacet_const_iterator Halffacet_const_iterator;     typedef typename SNC_structure::Halffacet_cycle_const_iterator Halffacet_cycle_const_iterator;        typedef typename SNC_structure::Object_const_handle Object_const_handle;    typedef typename SNC_structure::SHalfedge_const_handle SHalfedge_const_handle;     typedef typename SNC_structure::SHalfloop_const_handle SHalfloop_const_handle;         typedef typename SNC_structure::Vertex_const_handle Vertex_const_handle;     typedef typename SNC_structure::Halfedge_const_handle Halfedge_const_handle;     typedef typename SNC_structure::Halffacet_const_handle Halffacet_const_handle;        typedef typename SNC_structure::Point_3 Point_3;    typedef typename SNC_structure::Vector_3 Vector_3;    typedef typename SNC_structure::Segment_3 Segment_3;    typedef typename SNC_structure::Plane_3 Plane_3;    typedef typename SNC_structure::Mark Mark;    typedef typename SNC_structure::SHalfedge_around_facet_const_circulator       SHalfedge_around_facet_const_circulator;      private:    static OGL::Double_point double_point(const Point_3& p)      { return OGL::Double_point(CGAL::to_double(p.x()),				 CGAL::to_double(p.y()),				 CGAL::to_double(p.z())); }        static OGL::Double_segment double_segment(const Segment_3& s)      { return OGL::Double_segment(double_point(s.source()),				   double_point(s.target())); }        static void draw(Vertex_const_handle v, const Nef_polyhedron& , 		     CGAL::OGL::Polyhedron& P) {       Point_3 bp = v->point();      //    CGAL_NEF_TRACEN("vertex " << bp);      P.push_back(double_point(bp), v->mark());     }        static void draw(Halfedge_const_handle e, const Nef_polyhedron& ,		     CGAL::OGL::Polyhedron& P) {       Vertex_const_handle s = e->source();      Vertex_const_handle t = e->twin()->source();      Segment_3 seg(s->point(),t->point());      //    CGAL_NEF_TRACEN("edge " << seg);      P.push_back(double_segment(seg), e->mark());     }        static void draw(Halffacet_const_handle f, const Nef_polyhedron& ,		     CGAL::OGL::Polyhedron& P) {       OGL::DFacet g;      Halffacet_cycle_const_iterator fc; // all facet cycles:      CGAL_forall_facet_cycles_of(fc,f)	if ( fc.is_shalfedge() ) { // non-trivial facet cycle	  g.new_facet_cycle();	  SHalfedge_const_handle h = fc;	  SHalfedge_around_facet_const_circulator hc(h), he(hc);	  CGAL_For_all(hc,he){ // all vertex coordinates in facet cycle	    Point_3 sp = hc->source()->source()->point();	    //	      CGAL_NEF_TRACEN(" ");CGAL_NEF_TRACEN("facet" << sp);	    g.push_back_vertex(double_point(sp));	  }	}      Vector_3 v = f->plane().orthogonal_vector();      g.set_normal(CGAL::to_double(v.x()), 		   CGAL::to_double(v.y()), 		   CGAL::to_double(v.z()), 		   f->mark());      P.push_back(g);    }        // Returns the bounding box of the finite vertices of the polyhedron.    // Returns $[-1,+1]^3$ as bounding box if no finite vertex exists.        static Bbox_3  bounded_bbox(const Nef_polyhedron& N) {      bool first_vertex = true;      Bbox_3 bbox( -1.0, -1.0, -1.0, 1.0, 1.0, 1.0);      Vertex_const_iterator vi;      CGAL_forall_vertices(vi, N) {	Point_3 p = vi->point();	double x = CGAL::to_double(p.hx());	double y = CGAL::to_double(p.hy());	double z = CGAL::to_double(p.hz());	double w = CGAL::to_double(p.hw());	if (N.is_standard(vi)) {	  if(first_vertex) {	    bbox = Bbox_3(x/w, y/w, z/w, x/w, y/w, z/w);	    first_vertex = false;	  } else {	    bbox = bbox + Bbox_3(x/w, y/w, z/w, x/w, y/w, z/w);	    first_vertex = false;	  }	}      }      return bbox;    }          static void set_R(Bbox_3& bbox, const Nef_polyhedron& N) {      if(N.is_standard_kernel()) return;      double size = abs(bbox.xmin());      if(size < bbox.xmax()) size = bbox.xmax();      if(size < bbox.ymin()) size = bbox.ymin();      if(size < bbox.ymax()) size = bbox.ymax();      if(size < bbox.zmin()) size = bbox.zmin();      if(size < bbox.zmax()) size = bbox.zmax();      N.set_size_of_infimaximal_box(size*50);      //    CGAL_NEF_TRACEN("set infi box size to " << size);      Vertex_const_iterator vi;      CGAL_forall_vertices(vi, N)	if(N.is_standard(vi))	  return;      bbox = Bbox_3(bbox.xmin()*10,bbox.ymin()*10,bbox.zmin()*10,		    bbox.xmax()*10,bbox.ymax()*10,bbox.zmax()*10);    }  public:    static void convert_to_OGLPolyhedron(const Nef_polyhedron& N, CGAL::OGL::Polyhedron* P) {       Bbox_3 bbox(bounded_bbox(N));      set_R(bbox,N);      P->bbox() = bbox;          Vertex_const_iterator v;      CGAL_forall_vertices(v,*N.sncp()) draw(v,N,*P);      Halfedge_const_iterator e;      CGAL_forall_edges(e,*N.sncp()) draw(e,N,*P);      Halffacet_const_iterator f;      CGAL_forall_facets(f,*N.sncp()) draw(f,N,*P);    }      }; // Nef3_Converter} // namespace OGLCGAL_END_NAMESPACE#endif // CGAL_NEF_OPENGL_HELPER_H

⌨️ 快捷键说明

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