Files
Riccardo Elitropi 1545bc07cd EgtGeomKernel 3.1c5 :
- Aggiunto controllo dimensioni Zmap per versioni a 32Bit.
2026-03-24 15:58:51 +01:00

607 lines
40 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2015-2024
//----------------------------------------------------------------------------
// File : VolZmap.h Data : 22.04.24 Versione : 2.6d4
// Contenuto : Dichiarazione della classe Volume Zmap.
//
//
//
// Modifiche : 22.01.15 DS Creazione modulo.
// 12.09.23 DS Aggiunto metodo IsTriDexel.
//
//----------------------------------------------------------------------------
#pragma once
#include "ObjGraphicsMgr.h"
#include "GeoObjRW.h"
#include "Tool.h"
#include "/EgtDev/Include/EGkVolZmap.h"
#include "/EgtDev/Include/EGkIntersLineVolZmap.h"
#include "/EgtDev/Include/EGkSurfTriMesh.h"
#include <unordered_map>
#include <stack>
#include <tuple>
#include <atomic>
typedef std::pair<Point3d, Vector3d> PNTVEC3D ;
typedef std::vector<PNTVEC3D> PNTVEC3DVECTOR ; // vettore di intersezioni punto, vettore, tipo superficie
// ------------------------- FORWARD -------------------------------------------------------------
class IntersParLinesSurfTm ;
// ------------------------- STRUTTURE -----------------------------------------------------------
struct AppliedVector {
Point3d ptPApp ;
Vector3d vtVec ;
int nPropIndex ;
} ;
//----------------------------------------------------------------------------
class VolZmap : public IVolZmap, public IGeoObjRW
{
public : // IGeoObj
~VolZmap( void) override ;
VolZmap* Clone( void) const override ;
GeoObjType GetType( void) const override ;
bool IsValid( void) const override
{ return ( m_nStatus == OK) ; }
const std::string& GetTitle( void) const override ;
bool Dump( std::string& sOut, bool bMM = true, const char* szNewLine = "\n") const override ;
bool GetLocalBBox( BBox3d& b3Loc, int nFlag = BBF_STANDARD) const override ;
bool GetBBox( const Frame3d& frRef, BBox3d& b3Ref, int nFlag = BBF_STANDARD) const override ;
bool Translate( const Vector3d& vtMove) override ;
bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dAngDeg) override
{ double dAngRad = dAngDeg * DEGTORAD ;
return Rotate( ptAx, vtAx, cos( dAngRad), sin( dAngRad)) ; }
bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) override ;
bool Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ) override ;
bool Mirror( const Point3d& ptOn, const Vector3d& vtNorm) override ;
bool Shear( const Point3d& ptOn, const Vector3d& vtNorm, const Vector3d& vtDir, double dCoeff) override ;
bool ToGlob( const Frame3d& frRef) override ;
bool ToLoc( const Frame3d& frRef) override ;
bool LocToLoc( const Frame3d& frOri, const Frame3d& frDest) override ;
void SetObjGraphics( IObjGraphics* pOGr) override
{ m_OGrMgr.SetObjGraphics( pOGr) ; }
IObjGraphics* GetObjGraphics( void) override
{ return m_OGrMgr.GetObjGraphics() ; }
const IObjGraphics* GetObjGraphics( void) const override
{ return m_OGrMgr.GetObjGraphics() ; }
void SetTempProp( int nProp, int nPropInd = 0) override
{ if ( nPropInd >= 0 && nPropInd < 2)
m_nTempProp[nPropInd] = nProp ; }
int GetTempProp( int nPropInd = 0) const override
{ return (( nPropInd >= 0 && nPropInd < 2) ? m_nTempProp[nPropInd] : 0) ; }
void SetTempParam( double dParam, int nParamInd = 0) override
{ if ( nParamInd >= 0 && nParamInd < 2)
m_dTempParam[nParamInd] = dParam ; }
double GetTempParam( int nParamInd = 0) const override
{ return (( nParamInd >= 0 && nParamInd < 2) ? m_dTempParam[nParamInd] : 0.0) ; }
public : // IVolZmap
bool CopyFrom( const IGeoObj* pGObjSrc) override ;
bool Clear( void) override ;
bool Create( const Point3d& ptO, double dDimX, double dDimY, double dDimZ, double dStep, bool bTriDex, int* nError = nullptr) override ;
bool CreateEmpty( const Point3d& ptO, double dDimX, double dDimY, double dDimZ, double dStep, bool bTriDex, int* nError = nullptr) override ;
bool CreateFromFlatRegion( const ISurfFlatRegion& Surf, double dDimZ, double dStep, bool bTriDex, int* nError = nullptr) override ;
bool CreateFromTriMesh( const ISurfTriMesh& Surf, double dStep, bool bTriDex, double dExtraBox = 0, int* nError = nullptr) override ;
int GetBlockCount( void) const override ;
int GetBlockUpdatingCounter( int nBlock) const override ;
bool GetBlockTriangles( int nBlock, TRIA3DEXVECTOR& vTria) const override ;
ISurfTriMesh* GetSurfTriMesh( void) const override ;
bool GetEdges( ICURVEPOVECTOR& vpCurve) const override ;
bool GetVolume( double& dVol) const override ;
bool IsTriDexel( void) const override
{ return m_nMapNum == 3 ; }
bool GetDexelLines( int nDir, int nPos1, int nPos2, POLYLINELIST& lstPL) const override ;
int GetResolution( void) const override
{ return m_nDexVoxRatio ; }
bool ChangeResolution( int nDexVoxRatio) override ;
void SetShowEdges( bool bShow) override
{ m_bShowEdges = bShow ; // qui è necessario far ricreare la grafica
m_OGrMgr.Clear() ; }
bool GetShowEdges( void) const override
{ return m_bShowEdges ; }
bool SetToolTolerances( double dLinTol, double dAngTolDeg = 90) override ;
bool SetStdTool( const std::string& sToolName,
double dH, double dR, double dCornR, double dCutterH, int nFlag, bool bFirst) override ;
bool SetAdvTool( const std::string& sToolName,
double dH, double dR, double dTipH, double dTipR, double dCornR, double dCutterH, int nFlag, bool bFirst) override ;
bool SetSawTool( const std::string& sToolName,
double dH, double dR, double dThick, double dStemR, double dCornR, int nFlag, bool bFirst) override ;
bool SetGenTool( const std::string& sToolName,
const ICurveComposite* pToolOutline, int nFlag, bool bFirst) override ;
bool SetMortiserTool( const std::string& sToolName,
double dH, double dW, double dTh, double dRc, int nFlag, bool bFirst) override ;
bool SetChiselTool( const std::string& sToolName,
double dH, double dW, double dTh, int nFlag, bool bFirst) override ;
bool SetAdditiveTool( const std::string& sToolName,
double dH, double dR, double dRc, int nFlag, bool bFirst) override ;
int GetToolCount( void) const override ;
bool SetCurrTool( int nCurrTool) override ;
bool ResetTools( void) override ;
const ICurveComposite& GetToolOutline( bool bApprox = false) const override ;
bool MillingStep( int nCurrTool,
const Point3d& ptPs, const Vector3d& vtDs,
const Point3d& ptPe, const Vector3d& vtDe) override ;
bool MillingStep( int nCurrTool,
const Point3d& ptPs, const Vector3d& vtDs, const Vector3d& vtAs,
const Point3d& ptPe, const Vector3d& vtDe, const Vector3d& vtAe) override ;
bool GetDepth( const Point3d& ptP, const Vector3d& vtD, double& dInLength, double& dOutLength, bool bExact) const override ;
bool CDeBox( const Frame3d& frBox, const Vector3d& vtDiag, double dSafeDist, bool bPrecise = false) const override ;
bool CDeSphere( const Point3d& ptCenter, double dRad, double dSafeDist, bool bPrecise = false) const override ;
bool CDeCylinder( const Frame3d& frCyl, double dR, double dH, double dSafeDist, bool bPrecise = false) const override ;
bool CDeConeFrustum( const Frame3d& frCone, double dRadBot, double dRadTop, double dHeight,
double dSafeDist, bool bPrecise = false) const override ;
bool CDeRectPrismoid( const Frame3d& frPrismoid, double dLenghtBaseX, double dLenghtBaseY,
double dLenghtTopX, double dLenghtTopY, double dHeight,
double dSafeDist, bool bPrecise = false) const override ;
bool CDeTorus( const Frame3d& frTorus, double dRadMax, double dRadMin,
double dSafeDist, bool bPrecise = false) const override ;
bool CDeSurfTm( const ISurfTriMesh& tmSurf, double dSafeDist, bool bPrecise = false) const override ;
bool Cut( const Plane3d& plPlane) override ;
bool Compact( void) override ;
int GetPartCount( void) const override ;
bool GetPartVolume( int nPart, double& dVol) const override ;
bool GetPartLocalBBox( int nPart, BBox3d& b3Loc, int nFlag = BBF_STANDARD) const override ;
bool GetPartBBox( int nPart, const Frame3d& frRef, BBox3d& b3Ref, int nFlag = BBF_STANDARD) const override ;
VolZmap* ClonePart( int nPart) const override ;
bool RemovePart( int nPart) override ;
int GetPartMinDistFromPoint( const Point3d& ptP) const override ;
bool AddSurfTm( const ISurfTriMesh* pStm) override ;
bool SubtractSurfTm( const ISurfTriMesh* pStm) override ;
bool MakeUniform( double dToler, bool bIsExtensionFirst, int nToolNum) override ;
bool RemoveFins( const Vector3d& vtDir, double dThick) override ;
bool Offset( double dOffs, int nType) override ;
public : // IGeoObjRW
int GetNgeId( void) const override ;
bool Save( NgeWriter& ngeOut) const override ;
bool PreSave( GdbGeo& Wrapper) const override ;
bool PostSave( GdbGeo& Wrapper) const override ;
bool Load( NgeReader& ngeIn) override ;
bool PostLoad( GdbGeo& Wrapper) override ;
public :
VolZmap( void) ;
VolZmap( const VolZmap& stSrc)
{ if ( ! CopyFrom( stSrc))
LOG_ERROR( GetEGkLogger(), "VolZmap : copy constructor error") }
VolZmap& operator =( const VolZmap& stSrc)
{ if ( ! CopyFrom( stSrc))
LOG_ERROR( GetEGkLogger(), "VolZmap : copy error")
return *this ; }
bool GetLineIntersection( const Point3d& ptP, const Vector3d& vtD, ILZIVECTOR& vIntersInfo) const ;
bool GetPlaneIntersection( const Plane3d& plPlane, ICURVEPOVECTOR& vpLoop) const ;
bool CreateFromTriMeshOffset( const CISURFTMPVECTOR& vSurf, double dOffs, double dTol, int nType = STMOFF_FILLET) ;
bool CreateFromTriMeshThickeningOffset( const CISURFTMPVECTOR& vSurf, double dOffs, double dTol, int nType = STMOFF_FILLET) ;
private :
enum CubeType { VOX_EXTERN = 1,
VOX_ON_BOUNDARY = 0,
VOX_INNER = -1} ;
// Per la creazione dei rettangoli grandi
struct HeigthAndColor {
int nTool ;
double dHeigth ;
HeigthAndColor( void) : nTool( 0), dHeigth( 0) {}
HeigthAndColor( int nT, double dH) : nTool( nT), dHeigth( dH) {}
} ;
typedef std::unordered_map <int, HeigthAndColor> FlatVoxelContainer ;
// Struttura indici di voxel
struct VoxelIndexes {
int nI, nJ, nK ;
} ;
// Struttura per componenti connesse
struct ConComp {
Point3d ptVert ;
Vector3d vtNullSpace ;
AppliedVector CompVecField[7] ;
int nVertNum ;
bool bInside ;
bool bCorner ;
} ;
// Struttura per Voxel
struct Voxel {
int i, j, k ;
int nNumComp ;
ConComp Compo[4] ;
} ;
// Triangoli sharp-feature
struct SharpTriaStruct {
int i, j, k ;
PNTVECTOR ptCompoVert ;
std::vector<TRIA3DEXVECTOR> vCompoTria ;
std::vector<BOOLVECTOR> vbFlipped ;
} ;
// Triangoli smooth
struct SmoothTriaStruct {
int i, j, k ;
TRIA3DEXVECTOR vTria ;
} ;
// Matrice di SharpTriaStruct con sharp feature: il primo indice individua il blocco, il secondo il voxel
typedef std::vector<std::vector<SharpTriaStruct>> SharpTriaMatrix ;
// Matrice di SmoothTriaStruct con triangoli smooth: il primo indice individua il blocco, il secondo il voxel
typedef std::vector<std::vector<SmoothTriaStruct>> SmoothTriaMatrix ;
// Tavola hash di Voxel
typedef std::unordered_map<int, Voxel> VoxelContainer ;
// Unordered map per la coerenza topologica
typedef std::unordered_map<int, bool> InterVoxMatter ;
#if !defined(_WIN64)
// Numero massimo approssimativo di Dexel per versione 32-bit per evitare Crash con memoria
#if defined(_DEBUG)
static const int MAX_DEXEL_32_BIT = 3000000 + 1 ;
#else
static const int MAX_DEXEL_32_BIT = 5000000 + 1 ;
#endif
static int m_nDexelNbr ; // numero corrente di Dexel presenti
#endif
private :
bool CopyFrom( const VolZmap& clSrc) ;
bool ResetGraphics( void) ;
bool GetChunkPrisms( int nPos1, int nPos2, int nDim1, int nDim2, int nDimChk, int nBlock) const ;
bool CalcChunkPrisms( int nPos1, int nPos2, int nDim1, int nDim2, int nBlock) const ;
bool CalcDexelPrisms( int nPos1, int nPos2, int nBlock) const ;
bool AddDexelSideFace( int nPos, int nPosAdj, const Point3d& ptP, const Point3d& ptQ,
const Vector3d& vtZ, const Vector3d& vtNorm, int nBlock) const ;
bool UpdateSingleMapGraphics( void) const ;
bool UpdateTripleMapGraphics( void) const ;
bool ExtMarchingCubes( int nBlock, VoxelContainer& vVox) const ;
bool RegulateFeaturesChain( std::vector<VoxelContainer>& vVecVox) const ;
bool BrokenChain( std::vector<VoxelContainer>& vVecVox) const ;
bool CreateSharpFeatureTriangle( int nBlock, const VoxelContainer& vVox) const ;
bool CreateSmoothTriangle( int nIndex, int nVertNum, AppliedVector TriVert[], bool bWasSharp, SmoothTriaStruct& VoxSmoothTria) const ;
bool FlipEdgesII( int nBlock) const ;
bool FlipEdgesBB( void) const ;
bool IsThereMat( int nI, int nJ, int nK) const ;
int CalcIndex( int nI, int nJ, int nK) const ;
bool IntersPos( int nVec1[], int nVec2[], bool bFirstCorner, AppliedVector& vfField) const ;
bool IsPointInsideVoxelApprox( int nI, int nJ, int nK, const Point3d& ptP, double dPrec = EPS_SMALL) const ;
bool GetPointVoxel( const Point3d& ptP, int& nVoxI, int& nVoxJ, int& nVoxK) const ;
// Per regolarizzazione della catena di feature
bool FindAdjComp( const std::vector<VoxelContainer>& vVecVox, int nCurBlock, int nCurVox, int nCurComp,
INTVECTOR& vAdjBlockVoxComp, INTVECTOR& vAdjBordBlockVoxComp) const ;
// OPERAZIONI SU INTERVALLI
bool SubtractIntervals( int nGrid, int nI, int nJ,
double dMin, double dMax, const Vector3d& vtNMin, const Vector3d& vtNMax,
int nToolNum, bool bSkipSwap = false) ;
bool AddIntervals( int nGrid, int nI, int nJ,
double dMin, double dMax, const Vector3d& vtNMin, const Vector3d& vtNMax,
int nToolNum, bool bSkipSwap = false) ;
bool UniformIntervalsInVoxel( int nGrid, int nI, int nJ, double dZMin, double dZMax,
double dToler, bool bAdd, int nToolNum, const Vector3d& vtToolMin,
const Vector3d& vtToolMax) ;
bool AddStripInterval( int nGrid, int nI, int nJ, double dZMin, double dZMax, int nToolNum) ;
bool ManageSubIntervalInVoxel( VolZmap* VolZmapRef, int nGrid, int nI, int nJ, int nK, double& dMin, double& dMax,
Vector3d& vtMin, Vector3d& vtMax) ;
// Spostamenti utensile
bool MillingTranslationStep( const Point3d& ptPs, const Point3d& ptPe, const Vector3d& vtD, const Vector3d& vtA) ;
bool MillingGeneralMotionStep( const Point3d& ptPs, const Vector3d& vtDs, const Vector3d& vtAs,
const Point3d& ptPe, const Vector3d& vtDe, const Vector3d& vtAe) ;
bool SelectGeneralMotion( int nGrid, const Point3d& ptPs, const Point3d& ptPe, const Vector3d& vtLs, const Vector3d& vtLe, int n5AxisType) ;
bool SelectMotion( int nGrid, const Point3d& ptLs, const Point3d& ptLe, const Vector3d& vtL, const Vector3d& vtAL) ;
bool InitializePointsAndVectors( const Point3d& ptPs, const Point3d& ptPe, const Vector3d& vtDs, const Vector3d& vtAs,
Point3d ptLs[3], Point3d ptLe[3], Vector3d vtLs[3], Vector3d vtALs[3]) ;
bool InitializeAuxPoints( Point3d ptTop1s[3], Point3d ptTop1e[3], Point3d ptTop2s[3], Point3d ptTop2e[3],
Point3d ptBottom1s[3], Point3d ptBottom1e[3], Point3d ptBottom2s[3], Point3d ptBottom2e[3]) ;
// SOTTRAZIONI
// UTENSILI
// Asse di simmetria parallelo a Z
bool CylBall_ZDrilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ;
bool CylBall_ZPerp( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ;
bool CylBall_ZMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ;
bool Conus_ZDrilling( int nGrid, const Point3d & ptS, const Point3d& ptE, const Vector3d& vtToolDir) ;
bool Conus_ZPerp( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ;
bool Conus_ZMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ;
bool Mrt_ZDrilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) ;
bool Chs_ZDrilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) ;
bool Chs_ZMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) ;
bool GenTool_ZDrilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ;
bool GenTool_ZMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ;
// Asse di simmetria nel piano
bool CylBall_XYDrilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ;
bool CylBall_XYPerp( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ;
bool CylBall_XYMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ;
bool Conus_XYDrilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ;
bool Conus_XYPerp( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ;
bool Conus_XYMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ;
// Asse di simmetria con orientazione generica
bool CylBall_Drilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ;
bool CylBall_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ;
bool Conus_Drilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ;
bool Conus_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ;
bool Mrt_Drilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) ;
bool Mrt_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) ; // E' in realt un Perp
bool Chs_Drilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) ;
bool Chs_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) ; // E' in realt un Perp
bool GenTool_Drilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ;
bool GenTool_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ;
// lavorazioni a 5 assi
bool GenTool_5AxisMilling(int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtLs, const Vector3d& vtLe, int nToolNum, int n5AxisType = ACROSS) ;
bool Cyl_5AxisMilling(int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtLs, const Vector3d& vtLe, int nToolNum, double dHeightCorr = 0, int n5AxisType = ACROSS) ;
bool CylBall_5AxisMilling(int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtLs, const Vector3d& vtLe, int nToolNum, int n5AxisType = ACROSS) ;
bool Conus_5AxisMilling(int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtLs, const Vector3d& vtLe, int nToolNum, int n5AxisType = ACROSS) ;
// COMPONENTI
// Asse di simmetria diretto come l'asse Z
bool CompCyl_ZDrilling( int nGrid, const Point3d& ptLs, const Point3d& ptLe, const Vector3d& vtToolDir,
double dHei, double dRad, int nToolNum) ;
bool CompConus_ZDrilling( int nGrid, const Point3d& ptLs, const Point3d& ptLe, const Vector3d& vtToolDir,
double dHei, double dMaxRad, double dMinRad,
const Vector3d& vtArcNormMaxR, const Vector3d& vtArcNormMinR, int nToolNum) ;
bool CompPar_ZDrilling( int nGrid, double dLenX, double dLenY, double dLenZ,
const Point3d& ptS, const Point3d& ptE,
const Vector3d& vtToolDir, const Vector3d& vtAux, int nToolNum) ;
bool CompCyl_ZMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir,
double dHei, double dRad, int nToolNum) ;
bool CompConus_ZMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir,
double dHei, double dMaxRad, double dMinRad,
const Vector3d& vtArcNormMaxR, const Vector3d& vtArcNormMinR, int nToolNum) ;
bool CompPar_ZMilling( int nGrid, double dLenX, double dLenY, double dLenZ,
const Point3d& ptS, const Point3d& ptE,
const Vector3d& vtToolDir, const Vector3d& vtAux, int nToolNum) ; // E' in realt MillingPerp
// Asse di simmetria con orientazione generica
bool CompCyl_Drilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir,
double dHei, double dRad, bool bTapB, bool bTapT, int nToolNum) ;
bool CompConus_Drilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir,
double dHei, double dMaxRad, double dMinRad, bool bTapB, bool bTapT,
const Vector3d& vtArcNormMaxR, const Vector3d& vtArcNormMinR, int nToolNum) ;
bool CompPar_Drilling( int nGrid, double dLenX, double dLenY, double dLenZ,
const Point3d& ptS, const Point3d& ptE,
const Vector3d& vtToolDir, const Vector3d& vtAux, int nToolNum) ;
bool CompCyl_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir,
double dHei, double dRad, bool bTapB, bool bTapT, int nToolNum) ;
bool CompConus_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, double dHei, double dMaxRad, double dMinRad, bool bTapB, bool bTapT,
const Vector3d& vtArcNormMaxR, const Vector3d& vtArcNormMinR, int nToolNum) ;
bool CompPar_Milling( int nGrid, double dLenX, double dLenY, double dLenZ,
const Point3d& ptS, const Point3d& ptE,
const Vector3d& vtToolDir, const Vector3d& vtAux, int nToolNum) ; // E' in realtà MillingPerp
// lavorazioni a 5 assi
bool Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtLs, const Vector3d& vtLe,
double dHeight, double dMaxRad, double dMinRad, int nToolNum, int n5AxisType) ;
bool CompCyl_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtLs, const Vector3d& vtLe,
double dHeight, double dRadius, int nToolNum, int n5AxisType) ;
bool CompConus_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDirS, const Vector3d& vtToolDirE, double dHei, double dMaxRad, double dMinRad,
bool bTapB, bool bTapT, const Vector3d& vtArcNormMaxR, const Vector3d& vtArcNormMinR, int nToolNum, int n5AxisType) ;
// Generica traslazione sfera
bool CompBall_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, double dRad, int nToolNum) ;
// Additivi
bool AddingMotion( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtAx) ;
bool AddingCylinder( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtAx, double dHei, double dRad) ;
bool AddingTruncatedCone( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtAx,
double dMaxRad, double dMinRad, double dHei,
const Vector3d& vtArcNormMaxR, const Vector3d& vtArcNormMinR) ;
bool AddingSphere( int nGrid, const Point3d& ptS, const Point3d& ptE, double dRad) ;
bool AddingGeneral( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtAx) ;
// BBox per utensili e solidi semplici con movimenti di traslazione
inline bool TestToolBBox( int nGrid, const Point3d& ptP1, const Point3d& ptP2, const Vector3d& vtV,
int& nStI, int& nStJ, int& nEnI, int& nEnJ) ;
inline bool TestCompoBBox( int nGrid, const Point3d& ptP1, const Point3d& ptP2, const Vector3d& vtV, const Vector3d& vtV2,
double dRad, double dTipRad, double dHei,
int& nStI, int& nStJ, int& nEnI, int& nEnJ) ;
inline bool TestParaBBox( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtD, const Vector3d& vtA,
double dLenX, double dLenY, double dLenZ,
int& nStI, int& nStJ, int& nEnI, int& nEnJ) ;
// Intersezioni
bool IntersLineZMapLattice( const Point3d& ptP, const Vector3d& vtV, double& dU1, double& dU2) const ;
bool IntersLineZMapBBox( const Point3d& ptP, const Vector3d& vtV, double& dU1, double& dU2) const ;
bool IntersLineDexel( const Point3d& ptP, const Vector3d& vtV, int nGrid, int nI, int nJ,
double& dU1, double& dU2) const ;
bool IntersRayDexel( const Point3d& ptP, const Vector3d& vtV, int nGrid, int nI, int nJ,
double& dU1, double& dU2) const ;
bool GetDepthWithDexel( const Point3d& ptP, const Vector3d& vtDir, double& dInLength, double& dOutLength) const ;
bool GetDepthWithVoxel( const Point3d& ptP, const Vector3d& vtDir, double& dInLength, double& dOutLength) const ;
bool IntersLineCylinder( const Point3d& ptLineSt, const Vector3d& vtLineDir,
const Frame3d& CylFrame, double dH, double dRad, bool bTapLow, bool bTapUp,
Point3d& ptInt1, Vector3d& vtN1, Point3d& ptInt2, Vector3d& vtN2) const ;
bool IntersLineEllipticalCylinder( const Point3d& ptLineSt, const Vector3d& vtLineDir,
const Frame3d& CircFrame, double dRad, double dLongMvLen, double dOrtMvLen,
bool bTapLow, bool bTapUp,
Point3d& ptInt1, Vector3d& vtN1, Point3d& ptInt2, Vector3d& vtN2) const ;
bool IntersLineConus( const Point3d& ptLineSt, const Vector3d& vtLineDir,
const Frame3d& ConusFrame, double dTan, double dMinH, double dMaxH, bool bTapLow, bool bTapUp,
Point3d& ptInt1, Vector3d& vtN1, Point3d& ptInt2, Vector3d& vtN2) const ;
bool IntersLineMyPolyhedron( const Point3d& ptLineSt, const Vector3d& vtLineDir,
const Frame3d& PolyFrame, double dLenX, double dLenY, double dLenZ, double dDeltaX,
Point3d& ptInt1, Vector3d& vtN1, Point3d& ptInt2, Vector3d& vtN2) const ;
bool IntersLineTruncatedPyramid( const Point3d& ptLineSt, const Vector3d& vtLineDir,
const Frame3d& frTruncPyramFrame, double dSegMin, double dSegMax, double dHeight,
Point3d& ptInt1, Vector3d& vtN1, Point3d& ptInt2, Vector3d& vtN2) const ;
bool TestIntersPlaneZmapBBox( const Plane3d& plPlane) const ;
// Voxel: esistenza e passaggio da N a ijk per i voxel
bool IsValidVoxel( int nN) const ;
bool IsValidVoxel( int nI, int nJ, int nK) const ;
bool GetVoxIJKFromN( int nN, int& nI, int& nJ, int& nK) const ;
bool GetVoxNFromIJK( int nI, int nJ, int nK, int& nN) const ;
bool GetVoxelBox( int nI, int nJ, int nK, BBox3d& b3VoxBox) const ;
// Funzioni di gestione dei blocchi
bool GetBlockIJKFromN( int nBlock, int nIJK[]) const ;
bool GetBlockNFromIJK( int nIJK[], int& nBlock) const ;
bool GetBlockLimitsIJK( const int nIJK[], int nLimits[]) const ;
bool GetBlockBox( const int nIJK[], BBox3d& b3VoxBox) const ;
bool GetVoxelBlockIJK( const int nVoxIJK[], int nBlockIJK[]) const ;
bool GetVoxelBlockN( int nVox, int& nBlock) const ;
bool SetToModifyDexelBlocks( int nGrid, int nDex, int nInt) ;
bool GetAdjBlockToBlock( int nBlockN, int nDeltaI, int nDeltaJ, int nDeltaK, int& nAdjBlockN) const ;
bool IsAVoxelOnBoundary( const int nLimits[], const int nIJK[], bool bType) const ;
bool IsAVoxelOnBoundary( const int nLimits[], const int nIJK[], int nDeltaIndex[]) const ;
bool GetFirstVoxIJK( int& i, int& j, int& k) const ;
bool GetLastVoxIJK( int& i, int& j, int& k) const ;
bool IsVoxelOnBoxEdge( int i, int j, int k) const ;
bool CheckForFanNodeInterferance( AppliedVector CompVecField[], Point3d& ptFanVert,
int nBasePointNum, int nVoxConfig, int nVoxI, int nVoxJ, int nVoxK) const ;
bool CalcBlockNum( void) ;
bool IsTriangleOnBorder( const Triangle3dEx& trTria, const int nBlockLimits[], const int nVoxIJK[]) const ;
// Funzioni per facce canoniche con grandi triangoli
bool ProcessVoxContXY( FlatVoxelContainer& VoxContXY, int nBlock, bool bPlus) const ;
bool ProcessVoxContYZ( FlatVoxelContainer& VoxContYZ, int nBlock, bool bPlus) const ;
bool ProcessVoxContXZ( FlatVoxelContainer& VoxContXZ, int nBlock, bool bPlus) const ;
bool Find( const FlatVoxelContainer& VoxCont, int nI, int nJ, int nK, double dPos, int nTool) const ;
bool Remove( FlatVoxelContainer& VoxCont, int nI, int nJ, int nK) const ;
// Connessione Zmap
struct IntervalIndexes {
int tMap ;
int tDex ;
int tInt ;
} ;
typedef std::stack <IntervalIndexes> IntContainer ;
typedef std::vector<IntContainer> IntContainerVec ;
bool CheckMapConnection( void) ;
bool ExpandFromXInterval( IntContainer& IntCont) ;
bool ExpandFromYInterval( IntContainer& IntCont) ;
bool ExpandFromZInterval( IntContainer& IntCont) ;
bool FirstExpansionFromZ( int nNumThread, IntervalIndexes IntSt, IntContainerVec& IntervalsToProcessStackVec) ;
bool ProcessIntervals( IntContainer& IntervalsToProcess) ;
bool IsMapPartABox( int nMap, int nInfI, int nSupI, int nInfJ, int nSupJ, double& dMinZ, double& dMaxZ) ;
bool IsBox( void) ;
// Collision Detection semplici
bool CDeSimpleBox( const Frame3d& frBox, const Vector3d& vtDiag, bool bPrecise = false) const ;
bool CDeSimpleSphere( const Point3d& ptCenter, double dRad, bool bPrecise = false) const ;
bool CDeSimpleCylinder( const Frame3d& frCyl, double dR, double dH, bool bPrecise = false) const ;
bool CDeSimpleConeFrustum( const Frame3d& frCone, double dMinRad, double dMaxRad, double dHeight, bool bPrecise = false) const ;
bool CDeSimpleRectPrismoid( const Frame3d& frPrismoid, double dLenghtBaseX, double dLenghtBaseY,
double dLenghtTopX, double dLenghtTopY, double dHeight, bool bPrecise = false) const ;
bool CDeSimpleTorus( const Frame3d& frTorus, double dMaxRad, double dMinRad, bool bPrecise = false) const ;
// Funzione per crezione solido in parallelo
bool CreateMapPart( int nMap, int nInfI, int nSupI, int nInfJ, int nSupJ, const Vector3d& vtLen, const Point3d& ptMapOrig,
const ISurfTriMesh& Surf, IntersParLinesSurfTm& intPLSTM) ;
bool AddMapPart( int nMap, int nInfI, int nSupI, int nInfJ, int nSupJ, const Vector3d& vtLen, const Point3d& ptMapOrig,
const ISurfTriMesh& Surf, IntersParLinesSurfTm& intPLSTM) ;
bool SubtractMapPart( int nMap, int nInfI, int nSupI, int nInfJ, int nSupJ, const Vector3d& vtLen, const Point3d& ptMapOrig,
const ISurfTriMesh& Surf, IntersParLinesSurfTm& intPLSTM) ;
// Funzioni per Offset di superfici
bool InitVolZMapOffset( const CISURFTMPVECTOR& vSurf, double dOffs, double dTol) ;
bool InitVolZMapThickeningOffset( const CISURFTMPVECTOR& vSurf, double dOffs, double dTol) ;
bool UpdateVolZMapByOpenSurfFilletOffset( const ISurfTriMesh* Surf, double dOffs, double dTol) ;
bool UpdateVolZMapByOpenSurfSharpedOffset( const ISurfTriMesh* Surf, int nType, double dOffs, double dTol) ;
bool UpdateVolZMapByClosedSurfFilletOffset( const ISurfTriMesh* Surf, double dOffs, double dTol) ;
bool UpdateVolZMapByClosedSurfSharpedOffset( const ISurfTriMesh* Surf, int nType, double dOffs, double dTol) ;
bool UpdateVolZMapBySurfThickeningFilletOffset( const ISurfTriMesh* Surf, double dOffs, double dTol) ;
bool UpdateVolZMapBySurfThickeningSharpedOffset( const ISurfTriMesh* Surf, int nType, double dOffs, double dTol) ;
bool CreateOffsetSphereOnVertex( const Point3d& ptV, double dOffs, int nGrid, int nVertexType = 0) ;
bool CreateOffsetCylinderOnEdge( const Point3d& ptP1, const Point3d& ptP2, double dOffs, int nGrid, int nVertexType = 0) ;
bool CreateFatOffsetExtrusionFace( const ISurfTriMesh* Surf, double dOffs, bool bThickle, int nTool = 0) ;
bool CreateOrientedOffsetExtrusionFace( const ISurfTriMesh* Surf, double dOffs) ;
bool SubtractIntervalsForOffset( int nGrid, int nI, int nJ,
double dMin, double dMax, const Vector3d& vtNMin, const Vector3d& vtNMax,
int nToolNum, bool bSkipSwap = false) ;
bool AddIntervalsForOffset( int nGrid, int nI, int nJ,
double dMin, double dMax, const Vector3d& vtNMin, const Vector3d& vtNMax,
int nToolMin, int nToolMax, bool bSkipSwap = false) ;
bool CutByPlaneForOffset( const Plane3d& plCut) ;
bool AddSurfTmForOffset( const ISurfTriMesh* pStm, int nTool) ;
bool AddMapPartForOffset( int nMap, int nInfI, int nSupI, int nInfJ, int nSupJ, const Vector3d& vtLen, const Point3d& ptMapOrig,
const ISurfTriMesh& Surf, int nTool, IntersParLinesSurfTm& intPLSTM) ;
// Funzioni per Offset di Zmap
bool OffsetFillet( double dOffs) ;
bool OffsetSharped( double dOffs, int nType) ;
// Funzione analisi punti/Normali per Alette
bool GetLocalPoint( int nGrid, int nI, int nJ, double dZ, Point3d& ptLoc) ;
bool ComputePointAndNormalForRemovingFins( int nGrid, int nI, int nJ, double dZ,
const Vector3d& vtDir, double dThick, bool bMinVsMax, int nTool,
Vector3d& vtN, double& dNewZ) ;
private :
enum Move5Axis {
ALONG_CONVEX = 0 ,
ALONG_CONCAVE = 1 ,
ACROSS = 2 ,
NO_BASE_INTERS = 3} ;
enum Status {
ERR = 0,
OK = 1,
TO_VERIFY = 2} ;
enum Shape {
GENERIC = 0,
BOX = 1,
EXTRUSION = 2,
OFFSET = 3} ;
static const int N_MAPS = 3 ;
static const int N_VOXBLOCK = 32 ;
private :
ObjGraphicsMgr m_OGrMgr ; // gestore grafica dell'oggetto
Status m_nStatus ; // stato
int m_nTempProp[2] ; // vettore proprietà temporanee
double m_dTempParam[2] ; // vettore parametri temporanei
bool m_bShowEdges ; // flag di visualizzazione spigoli vivi
Frame3d m_MapFrame ; // riferimento intrinseco dello Zmap
double m_dStep ; // passo delle griglie
int m_nMapNum ; // numero di griglie ( 1 o 3)
int m_nNx[N_MAPS] ; // dimensione di ciascuna griglia in X
int m_nNy[N_MAPS] ; // dimensione di ciascuna griglia in Y
int m_nDim[N_MAPS] ; // dimensione di ciascuna griglia ( X * Y)
double m_dMinZ[N_MAPS] ; // minimo in Zlocale di ciascuna griglia
double m_dMaxZ[N_MAPS] ; // massimo in Zlocale di ciascuna griglia
struct Data { // Tratto di dexel : dati estremi, versori normali e corpo di appartenenza
double dMin ;
Vector3d vtMinN ;
int nToolMin ;
double dMax ;
Vector3d vtMaxN ;
int nToolMax ;
int nCompo ;
} ;
std::vector<std::vector<Data>> m_Values[N_MAPS] ; // dexel delle 3 griglie
int m_nShape ; // Forma : 0 generica, 1 box, 2 estrusione
int m_nVoxNumPerBlock ; // Numero di voxel per blocco
int m_nDexVoxRatio ; // Rapporto dexel voxel
int m_nFracLin[3] ; // Numero di blocchi per ogni asse
int m_nNumBlock ; // Numero totale di blocchi
mutable BOOLVECTOR m_BlockToUpdate ;
mutable INTVECTOR m_BlockUpdatingCounter ;
int m_nConnectedCompoCount ; // Se == - 1 il numero di componenti non è noto
// Se >= 0 è il numero di componenti connesse
mutable std::vector<VoxelContainer> m_InterBlockVox ;
mutable SharpTriaMatrix m_InterBlockOriginalSharpTria ;
mutable SharpTriaMatrix m_InterBlockSharpTria ;
mutable SharpTriaMatrix m_BlockSharpTria ;
mutable SmoothTriaMatrix m_BlockSmoothTria ;
mutable std::vector<TRIA3DEXVECTOR> m_BlockBigTria ;
mutable std::vector<TRIA3DEXVECTOR> m_SingleMapTria ;
mutable std::vector<InterVoxMatter> m_SliceXY ;
mutable std::vector<InterVoxMatter> m_SliceXZ ;
mutable std::vector<InterVoxMatter> m_SliceYZ ;
mutable std::atomic_flag m_SliceFlag ;
bool m_bIsBox ;
int m_nCurrTool ;
std::vector<Tool> m_vTool ;
double m_dToolLinTol ;
double m_dToolAngTolDeg ;
} ;
// Offset
enum {
VOLZMAP_OFFS_FILLET = 0,
VOLZMAP_OFFS_CHANFER = 1,
VOLZMAP_OFFS_EXTENDED = 2
} ;
//-----------------------------------------------------------------------------
inline VolZmap* CreateBasicVolZmap( void)
{ return ( static_cast<VolZmap*>( CreateGeoObj( VOL_ZMAP))) ; }
inline VolZmap* CloneBasicVolZmap( const IGeoObj* pGObj)
{ if ( pGObj == nullptr || pGObj->GetType() != VOL_ZMAP)
return nullptr ;
return ( static_cast<VolZmap*>( pGObj->Clone())) ; }
inline const VolZmap* GetBasicVolZmap( const IGeoObj* pGObj)
{ if ( pGObj == nullptr || pGObj->GetType() != VOL_ZMAP)
return nullptr ;
return ( static_cast<const VolZmap*>( pGObj)) ; }
inline VolZmap* GetBasicVolZmap( IGeoObj* pGObj)
{ if ( pGObj == nullptr || pGObj->GetType() != VOL_ZMAP)
return nullptr ;
return ( static_cast<VolZmap*>( pGObj)) ; }