diff --git a/SurfBezier.cpp b/SurfBezier.cpp index 0aa70bb..6ddd9ee 100644 --- a/SurfBezier.cpp +++ b/SurfBezier.cpp @@ -2517,9 +2517,6 @@ SurfBezier::UnprojectPoint( const Point3d& pt3D, Point3d& ptParam, const Point3d GetPointD1D2( ptParam.x / SBZ_TREG_COEFF, ptParam.y / SBZ_TREG_COEFF, ISurfBezier::FROM_MINUS, ISurfBezier::FROM_MINUS, ptBez) ; // usando un algoritmo di newton cerco di avvicinarmi il più possibile al punto - double dDistPoint = Dist( pt3D, ptBez) ; - double dDistPlane = DistPointPlane( ptBez, *pPlCut) ; - double dDistNew = pPlCut == nullptr ? Dist( pt3D, ptBez) : abs(DistPointPlane( ptBez, *pPlCut)) ; double dDistPre ; double dDist0, dDist1; @@ -2661,3 +2658,119 @@ SurfBezier::CalcPoles( void) return true ; } + +//---------------------------------------------------------------------------- +bool +SurfBezier::GetEdges3D( ICRVCOMPOPOVECTOR& vCC, bool bLineOrBezier, int nEdge) const +{ + // se nEdge non è definito ( == -1) allora restituisco tutti gli edge in ordine + if ( m_pSTM == nullptr) + GetAuxSurf() ; + + if ( nEdge == -1 ) { + vCC.emplace_back( GetSingleEdge3D( bLineOrBezier, 0)) ; + vCC.emplace_back( GetSingleEdge3D( bLineOrBezier, 1)) ; + vCC.emplace_back( GetSingleEdge3D( bLineOrBezier, 2)) ; + vCC.emplace_back( GetSingleEdge3D( bLineOrBezier, 3)) ; + } + else + vCC.emplace_back( GetSingleEdge3D( bLineOrBezier, nEdge)) ; + return true ; +} + +//---------------------------------------------------------------------------- +ICurveComposite* +SurfBezier::GetSingleEdge3D( bool bLineOrBezier, int nEdge) const +{ + if ( nEdge < 0 || nEdge > 3) + return nullptr ; + ICurveComposite* pCrvCompo( CreateBasicCurveComposite()) ; + switch ( nEdge) { + case 0 : { + // se il bool è true allora restituisco gli edge con la loro approssimazione in forma di linea spezzata 3D + if ( bLineOrBezier) + pCrvCompo = m_vCCEdge[nEdge]->Clone() ; + // se il bool è falso restituisco le curve Bezier di edge + else { + //edge 0, scorro sulle patch in U + for ( int i = 0 ; i < m_nSpanU ; ++i) { + PtrOwner pCrvBz0( CreateBasicCurveBezier()) ; + if ( IsNull(pCrvBz0) || ! pCrvBz0->Init( m_nDegU, m_bRat)) + return nullptr ; + for ( int p = 0 ; p < m_nDegU + 1 ; ++p ) { + int nIndex = ( m_nDegU * m_nSpanU + 1) * ( m_nDegV * m_nSpanV) + m_nDegU * i + p ; + if ( ! m_bRat) + pCrvBz0->SetControlPoint( p, GetControlPoint( nIndex, nullptr)) ; + else + pCrvBz0->SetControlPoint( p, GetControlPoint( nIndex, nullptr), GetControlWeight( nIndex, nullptr)) ; + } + pCrvCompo->AddCurve( Release( pCrvBz0)) ; + } + } + break ; + } + case 1 : { + if ( bLineOrBezier) + pCrvCompo = m_vCCEdge[nEdge]->Clone() ; + else { + //edge 1, scorro sulle patch in V + for ( int i = 0 ; i < m_nSpanV ; ++i) { + PtrOwner pCrvBz1( CreateBasicCurveBezier()) ; + if ( IsNull(pCrvBz1) || ! pCrvBz1->Init( m_nDegV, m_bRat)) + return nullptr ; + for ( int p = 0 ; p < m_nDegU + 1 ; ++p ) { + int nIndex = ( m_nDegU * m_nSpanU + 1) * p ; + if ( ! m_bRat) + pCrvBz1->SetControlPoint( p, GetControlPoint( nIndex, nullptr)) ; + else + pCrvBz1->SetControlPoint( p, GetControlPoint( nIndex, nullptr), GetControlWeight( nIndex, nullptr)) ; + } + pCrvCompo->AddCurve( Release( pCrvBz1)) ; + } + } + break ; + } + case 2 : { + if ( bLineOrBezier) + pCrvCompo = m_vCCEdge[nEdge]->Clone() ; + else { + // edge 2, scorro sulle patch in U + for ( int i = 0 ; i < m_nSpanU ; ++i) { + PtrOwner pCrvBz2( CreateBasicCurveBezier()) ; + if ( IsNull(pCrvBz2) || ! pCrvBz2->Init( m_nDegU, m_bRat)) + return nullptr ; + for ( int p = 0 ; p < m_nDegU + 1 ; ++p ) { + if ( ! m_bRat) + pCrvBz2->SetControlPoint( p, GetControlPoint(m_nDegU * i + p, nullptr)) ; + else + pCrvBz2->SetControlPoint( p, GetControlPoint(m_nDegU * i + p, nullptr), GetControlWeight(m_nDegU * i + p, nullptr)) ; + } + pCrvCompo->AddCurve( Release( pCrvBz2)) ; + } + } + break ; + } + case 3 : { + if ( bLineOrBezier) + pCrvCompo = m_vCCEdge[nEdge]->Clone() ; + else { + // edge 3, scorro sulle patch in V + for ( int i = 0 ; i < m_nSpanV ; ++i) { + PtrOwner pCrvBz3( CreateBasicCurveBezier()) ; + if ( IsNull(pCrvBz3) || ! pCrvBz3->Init( m_nDegV, m_bRat)) + return nullptr ; + for ( int p = 0 ; p < m_nDegV + 1 ; ++p ) { + int nIndex = ( m_nDegU * m_nSpanU + 1) * ( i + p + 1) - 1 ; + if ( ! m_bRat) + pCrvBz3->SetControlPoint( p, GetControlPoint( nIndex, nullptr)) ; + else + pCrvBz3->SetControlPoint( p, GetControlPoint( nIndex, nullptr), GetControlWeight( nIndex, nullptr)) ; + } + pCrvCompo->AddCurve( Release( pCrvBz3)) ; + } + } + break ; + } + } + return pCrvCompo ; +} \ No newline at end of file diff --git a/SurfBezier.h b/SurfBezier.h index 8cae257..cbf44e6 100644 --- a/SurfBezier.h +++ b/SurfBezier.h @@ -132,6 +132,7 @@ class SurfBezier : public ISurfBezier, public IGeoObjRW // funzioni per incrementare le coordinate restando dentro lo spazio parametrico bool IncreaseUV( double& dU, double dx, bool bUOrV, double* dUVCopy = nullptr, bool bModifyOrig = true) const override ; bool IncreaseUV( Point3d& ptUV, Vector3d vtH , Point3d* ptUVCopy, bool bModifyOrig) const override ; + bool GetEdges3D( ICRVCOMPOPOVECTOR& vCC, bool bLineOrBezier, int nEdge = -1) const override ; public : // IGeoObjRW int GetNgeId( void) const override ; @@ -181,6 +182,7 @@ class SurfBezier : public ISurfBezier, public IGeoObjRW double GetCurveOnVApproxLen( double dU) const ; // funzione che proietta nello spazio parametrico un trim derivante da un taglio con un piano, categorizzandolo come aperto o chiuso ( nel parametrico) bool AddCurveCompoToCuts( ICurveComposite* pCrvCompo, ICRVCOMPOPOVECTOR& vpCCOpen, ICRVCOMPOPOVECTOR& vpCCClosed, double dToler = EPS_SMALL, const Plane3d* pPlCut = nullptr) const ; + ICurveComposite* GetSingleEdge3D( bool bLineOrBezier, int nEdge) const ; private : ObjGraphicsMgr m_OGrMgr ; // gestore grafica dell'oggetto