EgtGeomKernel 1.5d2 :
- creazione di superfici trimesh da piani contornati e per estrusione - migliorie a PolyLine - migliorie a FromString - modifiche a Vector3d e Point3d.
This commit is contained in:
+115
-2
@@ -14,6 +14,7 @@
|
||||
//--------------------------- Include ----------------------------------------
|
||||
#include "stdafx.h"
|
||||
#include "\EgtDev\Include\EGkPolyLine.h"
|
||||
#include "\EgtDev\Include\EGkPlane3d.h"
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -28,6 +29,16 @@ PolyLine::~PolyLine( void)
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
PolyLine::Clear( void)
|
||||
{
|
||||
m_nCount = 0 ;
|
||||
m_lUPoints.clear() ;
|
||||
m_iter = m_lUPoints.end() ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
PolyLine::AddUPoint( double dPar, const Point3d& ptP)
|
||||
@@ -48,7 +59,7 @@ PolyLine::AddUPoint( double dPar, const Point3d& ptP)
|
||||
bool
|
||||
PolyLine::EraseFirstUPoint( void)
|
||||
{
|
||||
if ( m_lUPoints.begin() == m_lUPoints.end())
|
||||
if ( m_lUPoints.empty())
|
||||
return false ;
|
||||
|
||||
m_lUPoints.pop_front() ;
|
||||
@@ -57,6 +68,19 @@ PolyLine::EraseFirstUPoint( void)
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
PolyLine::EraseLastUPoint( void)
|
||||
{
|
||||
if ( m_lUPoints.empty())
|
||||
return false ;
|
||||
|
||||
m_lUPoints.pop_back() ;
|
||||
m_nCount -- ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
PolyLine::AddOffsetToU( double dOffset)
|
||||
@@ -76,10 +100,21 @@ PolyLine::Splice( PolyLine& PL)
|
||||
{
|
||||
m_lUPoints.splice( m_lUPoints.end(), PL.m_lUPoints) ;
|
||||
m_nCount += PL.GetPointNbr() ;
|
||||
PL.m_nCount = 0 ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
PolyLine::IsClosed( void) const
|
||||
{
|
||||
if ( m_lUPoints.empty())
|
||||
return false ;
|
||||
|
||||
return ( AreSamePointNear( m_lUPoints.front().second, m_lUPoints.back().second)) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
PolyLine::GetFirstUPoint( double* pdPar, Point3d* pptP) const
|
||||
@@ -116,7 +151,12 @@ PolyLine::GetNextUPoint( double* pdPar, Point3d* pptP) const
|
||||
bool
|
||||
PolyLine::GetLastUPoint( double* pdPar, Point3d* pptP) const
|
||||
{
|
||||
if ( m_lUPoints.begin() == m_lUPoints.end())
|
||||
m_iter = m_lUPoints.end() ;
|
||||
if ( m_iter == m_lUPoints.begin())
|
||||
return false ;
|
||||
-- m_iter ;
|
||||
|
||||
if ( m_iter == m_lUPoints.end())
|
||||
return false ;
|
||||
|
||||
if ( pdPar != nullptr)
|
||||
@@ -127,6 +167,22 @@ PolyLine::GetLastUPoint( double* pdPar, Point3d* pptP) const
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
PolyLine::GetPrevUPoint( double* pdPar, Point3d* pptP) const
|
||||
{
|
||||
if ( m_iter == m_lUPoints.begin())
|
||||
return false ;
|
||||
-- m_iter ;
|
||||
|
||||
if ( pdPar != nullptr)
|
||||
*pdPar = m_iter->first ;
|
||||
if ( pptP != nullptr)
|
||||
*pptP = m_iter->second ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
PolyLine::GetFirstULine( double* pdIni, Point3d* pptIni, double* pdFin, Point3d* pptFin) const
|
||||
@@ -176,3 +232,60 @@ PolyLine::GetNextULine( double* pdIni, Point3d* pptIni, double* pdFin, Point3d*
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
PolyLine::NewellPlane( Plane3d& plPlane) const
|
||||
{
|
||||
// Compute normal as being proportional to projected areas of polygon onto the yz,
|
||||
// xz, and xy planes. Also compute centroid as representative point on the plane
|
||||
Vector3d vtN ;
|
||||
Point3d ptCen ;
|
||||
int nNumSide = 0 ;
|
||||
Point3d ptIni, ptFin ;
|
||||
for ( bool bFound = GetFirstLine( ptIni, ptFin) ; bFound ; bFound = GetNextLine( ptIni, ptFin)) {
|
||||
vtN.x += ( ptIni.y - ptFin.y) * ( ptIni.z + ptFin.z) ; // projection on yz
|
||||
vtN.y += ( ptIni.z - ptFin.z) * ( ptIni.x + ptFin.x) ; // projection on xz
|
||||
vtN.z += ( ptIni.x - ptFin.x) * ( ptIni.y + ptFin.y) ; // projection on xy
|
||||
ptCen += ptFin ;
|
||||
++ nNumSide ;
|
||||
}
|
||||
// If open and existent, add segment from last to first points
|
||||
if ( ! IsClosed() && nNumSide > 0) {
|
||||
ptIni = ptFin ;
|
||||
GetFirstPoint( ptFin) ;
|
||||
vtN.x += ( ptIni.y - ptFin.y) * ( ptIni.z + ptFin.z) ; // projection on yz
|
||||
vtN.y += ( ptIni.z - ptFin.z) * ( ptIni.x + ptFin.x) ; // projection on xz
|
||||
vtN.z += ( ptIni.x - ptFin.x) * ( ptIni.y + ptFin.y) ; // projection on xy
|
||||
ptCen += ptFin ;
|
||||
++ nNumSide ;
|
||||
}
|
||||
// At least 3 sides
|
||||
if ( nNumSide < 3)
|
||||
return false ;
|
||||
// Normal must be normalizable
|
||||
if ( ! vtN.Normalize())
|
||||
return false ;
|
||||
// Normalize normal and fill in the plane equation fields
|
||||
plPlane.vtN = vtN ;
|
||||
plPlane.dDist = ( ( ptCen - ORIG) * plPlane.vtN) / nNumSide ; // “centroid / n” is the true centroid point
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
PolyLine::IsPlanar( Plane3d& plPlane, double dToler) const
|
||||
{
|
||||
// Compute a representative plane for the polygon
|
||||
if ( ! NewellPlane( plPlane))
|
||||
return false ;
|
||||
// Test each vertex to see if it is farther from plane than allowed max distance
|
||||
Point3d ptP ;
|
||||
for ( bool bFound = GetFirstPoint( ptP) ; bFound ; bFound = GetNextPoint( ptP)) {
|
||||
double dDist = ( ( ptP - ORIG) * plPlane.vtN) - plPlane.dDist ;
|
||||
if ( fabs( dDist) > dToler)
|
||||
return false ;
|
||||
}
|
||||
// All points passed distance test, so polygon is considered planar
|
||||
return true ;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user