#include "MGCLStdAfx.h" #include "mg/Tolerance.h" #include "mg/drawParam.h" #include "mg/BPointSeq.h" #include "mg/SurfCurve.h" #include "topo/Edge.h" #include "topo/LEPoint.h" #include "topo/Loop.h" #include "topo/Face.h" #include "Tl2/TL2parameter.h" #include "Tl2/TL2Fans.h" #include "Tl2/TL2Polyline.h" #include "Tl2/TL2Face.h" #if defined(_DEBUG) #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif using namespace std; /****************************************************************/ /* Copyright (c) 2017 by System fugen G.K. */ /* All rights reserved. */ /****************************************************************/ ///////////Constructor////////// //copy constructor. mgTL2Face::mgTL2Face(const mgTL2Face& face) :m_param(face.m_param){ } mgTL2Face::mgTL2Face( const MGDrawParam& param,//parameter for the tessellation. const MGSurface& face //テセレーションするフェイス //Must be MGFace or MGSurface. ):m_param(face,param){ polygonizeBoundaries(); } mgTL2Face::mgTL2Face( const MGDrawParam& param,///* polylines ///< Input polygonized polylines for the face boundaries. ///< polylines[i][j] is a j-th edge's polyline for face.loop(i), ///< must be MGLBRep of order 2. ///< polylines[i][j]=0 indicates loop i's edge j can be face's bounday and ///< has any common edges. ///< **polylines[i][j] must be the same direction as the faces's parameter edge. ):m_param(face,param,polylines){ //face.outFS(std::cout); polygonizeBoundaries(); } mgTL2Face::mgTL2Face( const MGFSurface& face,///<テセレーションするフェイス ///* polylines ///< Input polygonized polylines for the face boundaries. ///< polylines[i][j] is a j-th edge's polyline for face.loop(i), ///< must be MGLBRep of order 2. ///< polylines[i][j]=0 indicates loop i's edge j can be face's bounday and ///< has any common edges. ///< **polylines[i][j] must be the same direction as the faces's parameter edge. ):m_param(face,crvTol,surfTol,polylines,max_edge_len){ polygonizeBoundaries(); } ////////Member function////////// ///make_Edge() makes a polyline edge(parameter edge) of edge edgeuv which are wholly ///on a curve of Bpoly(). ///All of the points of m_param.Bpoly()[id[0]][id[1]] will be converted to ///surface (u,v) parameter. These (u,v) representation makes the polyline edge. MGEdge* make_Edge( const mgTL2parameter& tlpara, const MGEdge& edgeuv, short id[3], //pointer to uniform LBRep of m_param.Bpoly(), must not be null //(id[0] and id[1]). //On return, id of the starting point will be return. mgTL2Polyline*& poly //generated mgTL2Polyline* for the edge will be returned. ){ const std::vector& Bpolylines=*(tlpara.Bpoly()); const MGLBRep* edgexyz=Bpolylines[id[0]][id[1]]; const MGSurface& srf=tlpara.get_surface(); MGTrimmedCurve crvuv=edgeuv.trimmed_curve(); MGSurfCurve plinexyz(srf,crvuv); const MGBPointSeq& bpxyz=edgexyz->line_bcoef(); int nbd=edgexyz->bdim(); bool equalDirection=edgeuv.equal_direction_to_binder(); double s0=crvuv.param_s(), s1=crvuv.param_e(); double sguess=s0; poly=new mgTL2Polyline(tlpara); poly->set_type(mgTL2Polyline::WHOLE_BOUNDARY); MGBPointSeq& uvbp=poly->line_bcoef(); MGKnotVector& uvKnotv=poly->knot_vector(); uvbp.resize(nbd,2);uvKnotv.size_change(2,nbd); for(int k=0; kset_endID(id); id[2]=equalDirection ? 0:short(nbd-1); poly->set_startID(id); return new MGEdge(poly); } ///Polygonize all the boundaries of the target face, ///and make an MGFace that has the polygonized boundaries. ///The face made will be m_polygon. ///The face does not have surface geometery, only has bounfaries. void mgTL2Face::polygonizeBoundaries(){ size_t nloop=0; const MGFace& fOrigin=m_param.get_face(); if(m_param.target_is_face()) nloop=(size_t)fOrigin.number_of_loops(); if(!nloop){ polygonizeSurfaceBoundaries(); return; } m_polygon=std::unique_ptr(new MGFace); size_t nBpolylines=0; const std::vector& Bpolylines=*(Bpoly()); if(&Bpolylines) nBpolylines=Bpolylines.size(); for(size_t i=0; isize(); } short id[3]; id[0]=(short)i;//id[0] is loop number. short idtemp[3]; int nedge=lpi->number_of_edges(); MGLoop* lp=new MGLoop; const MGLBRep* edgepoly=0; mgTL2Polyline* polyPre=0; mgTL2Polyline* polyStart=0; mgTL2Polyline* poly=0; for(int j=0; jedge(j));//The original edge j in loop i. const MGLBRep* eijxyz=0; if(jboundaryType()set_endID(id); } } } if(!eijxyz){ poly=new mgTL2Polyline(m_param,edgeuv.trimmed_curve()); eij= new MGEdge(poly); if(polyPre){ if(polyPre->boundaryType()==mgTL2Polyline::WHOLE_BOUNDARY){ polyPre->get_endID(idtemp); poly->set_startID(idtemp); } } } lp->append(eij); if(j==0) polyStart=poly; polyPre=poly; //std::cout<<(*poly)<boundaryType()boundaryType()==mgTL2Polyline::WHOLE_BOUNDARY){ poly->get_endID(idtemp); polyStart->set_startID(idtemp); }else if(polyStart->boundaryType()==mgTL2Polyline::WHOLE_BOUNDARY && poly->boundaryType()get_startID(idtemp); poly->set_endID(idtemp); } lp->make_close(); m_polygon->append_boundary(lp); } } ///Polygonize MGSurface boundaries, ///and make an MGFace that has the polygonized boundaries. ///The face made will be m_polygon. ///The face does not have surface geometery, only has bounfaries. ///The target must be MGSurface. void mgTL2Face::polygonizeSurfaceBoundaries(){ m_polygon=std::unique_ptr(new MGFace); const MGSurface& srf=m_param.get_surface(); MGLoop* lp=new MGLoop; MGPvector bcurves=srf.outer_boundary_param(); size_t n=bcurves.size(); for(size_t i=0; iappend(ei); } lp->make_close(); m_polygon->append_boundary(lp); } ostream& operator<< (ostream& out, const mgTL2Face& face){ out<<"mgTL2Face="<<(&face); out<