984292fed9
- funzioni di intersezione raccolte in modulo apposito - aggiunta funzione Exe e Lua BoxLineInters.
194 lines
5.8 KiB
C++
194 lines
5.8 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2018-2018
|
|
//----------------------------------------------------------------------------
|
|
// File : LUA_GeoInters.cpp Data : 27.09.18 Versione : 1.9i4
|
|
// Contenuto : Funzioni di intersezioni tra oggetto geometrici per LUA.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 27.09.18 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "LUA.h"
|
|
#include "/EgtDev/Include/EXeExecutor.h"
|
|
#include "/EgtDev/Include/EXeConst.h"
|
|
#include "/EgtDev/Include/EGkLuaAux.h"
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaBoxLineInters( lua_State* L)
|
|
{
|
|
// 3 parametri : b3Box, ptP, vtDir
|
|
BBox3d b3Box ;
|
|
LuaCheckParam( L, 1, b3Box)
|
|
Point3d ptP ;
|
|
LuaCheckParam( L, 2, ptP)
|
|
Vector3d vtDir ;
|
|
LuaCheckParam( L, 3, vtDir)
|
|
LuaClearStack( L) ;
|
|
// recupero i punti di intersezione tra linea e superficie trimesh
|
|
INTDBLVECTOR vInters ;
|
|
if ( ExeBoxLineInters( b3Box, ptP, vtDir, vInters)) {
|
|
LuaSetParam( L, true) ;
|
|
INTVECTOR vType( vInters.size()) ;
|
|
DBLVECTOR vPar( vInters.size()) ;
|
|
for ( size_t i = 0 ; i < vInters.size() ; ++ i) {
|
|
vType[i] = vInters[i].first ;
|
|
vPar[i] = vInters[i].second ;
|
|
}
|
|
LuaSetParam( L, vType) ;
|
|
LuaSetParam( L, vPar) ;
|
|
}
|
|
else {
|
|
LuaSetParam( L) ;
|
|
LuaSetParam( L) ;
|
|
LuaSetParam( L) ;
|
|
}
|
|
return 3 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaSurfTmLineInters( lua_State* L)
|
|
{
|
|
// 3 o 4 parametri : Id, ptP, vtDir [, nRefId]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
Point3d ptP ;
|
|
LuaCheckParam( L, 2, ptP)
|
|
Vector3d vtDir ;
|
|
LuaCheckParam( L, 3, vtDir)
|
|
int nRefType = nId ;
|
|
LuaGetParam( L, 4, nRefType) ;
|
|
LuaClearStack( L) ;
|
|
// recupero i punti di intersezione tra linea e superficie trimesh
|
|
INTDBLVECTOR vInters ;
|
|
if ( ExeSurfTmLineInters( nId, ptP, vtDir, nRefType, vInters)) {
|
|
LuaSetParam( L, true) ;
|
|
INTVECTOR vType( vInters.size()) ;
|
|
DBLVECTOR vPar( vInters.size()) ;
|
|
for ( size_t i = 0 ; i < vInters.size() ; ++ i) {
|
|
vType[i] = vInters[i].first ;
|
|
vPar[i] = vInters[i].second ;
|
|
}
|
|
LuaSetParam( L, vType) ;
|
|
LuaSetParam( L, vPar) ;
|
|
}
|
|
else {
|
|
LuaSetParam( L) ;
|
|
LuaSetParam( L) ;
|
|
LuaSetParam( L) ;
|
|
}
|
|
return 3 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaSurfTmPlaneInters( lua_State* L)
|
|
{
|
|
// 4 o 5 parametri : Id, ptOn, vtN, nDestGrpId [, nRefType]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
Point3d ptOn ;
|
|
LuaCheckParam( L, 2, ptOn)
|
|
Vector3d vtN ;
|
|
LuaCheckParam( L, 3, vtN)
|
|
int nDestGrpId ;
|
|
LuaGetParam( L, 4, nDestGrpId) ;
|
|
int nRefType = RTY_DEFAULT ;
|
|
LuaGetParam( L, 5, nRefType) ;
|
|
LuaClearStack( L) ;
|
|
// eseguo l'intersezione
|
|
int nPntCount = 0 ;
|
|
int nCrvCount = 0 ;
|
|
int nSrfCount = 0 ;
|
|
int nNewId = ExeSurfTmPlaneInters( nId, ptOn, vtN, nDestGrpId, nRefType, &nPntCount, &nCrvCount, &nSrfCount) ;
|
|
// restituisco il risultato
|
|
if ( nNewId != GDB_ID_NULL)
|
|
LuaSetParam( L, nNewId) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
LuaSetParam( L, nPntCount) ;
|
|
LuaSetParam( L, nCrvCount) ;
|
|
LuaSetParam( L, nSrfCount) ;
|
|
return 4 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaSurfTmSurfTmInters( lua_State* L)
|
|
{
|
|
// 3 parametri : Id1, nId2, nDestGrpId
|
|
int nId1 ;
|
|
LuaCheckParam( L, 1, nId1)
|
|
int nId2 ;
|
|
LuaCheckParam( L, 2, nId2)
|
|
int nDestGrpId ;
|
|
LuaCheckParam( L, 3, nDestGrpId) ;
|
|
LuaClearStack( L) ;
|
|
// eseguo l'intersezione
|
|
int nPntCount = 0 ;
|
|
int nCrvCount = 0 ;
|
|
int nSrfCount = 0 ;
|
|
int nNewId = ExeSurfTmSurfTmInters( nId1, nId2, nDestGrpId, &nPntCount, &nCrvCount, &nSrfCount) ;
|
|
// restituisco il risultato
|
|
if ( nNewId != GDB_ID_NULL)
|
|
LuaSetParam( L, nNewId) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
LuaSetParam( L, nPntCount) ;
|
|
LuaSetParam( L, nCrvCount) ;
|
|
LuaSetParam( L, nSrfCount) ;
|
|
return 4 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaVolZmapPlaneInters( lua_State* L)
|
|
{
|
|
// 4 o 5 parametri : nId, ptP, vtN, nDestGrpId [, nRefType]
|
|
int nId ;
|
|
LuaCheckParam( L, 1, nId)
|
|
Point3d ptP ;
|
|
LuaCheckParam( L, 2, ptP)
|
|
Vector3d vtN ;
|
|
LuaCheckParam( L, 3, vtN)
|
|
int nDestGrpId ;
|
|
LuaCheckParam( L, 4, nDestGrpId)
|
|
int nRefType = RTY_DEFAULT ;
|
|
LuaGetParam( L, 5, nRefType) ;
|
|
LuaClearStack( L) ;
|
|
// eseguo calcolo intersezione
|
|
int nCount ;
|
|
int nFirstId = ExeVolZmapPlaneInters( nId, ptP, vtN, nDestGrpId, nRefType, &nCount) ;
|
|
// restituisco il risultato
|
|
if ( nFirstId != GDB_ID_NULL) {
|
|
LuaSetParam( L, nFirstId) ;
|
|
LuaSetParam( L, nCount) ;
|
|
}
|
|
else {
|
|
LuaSetParam( L) ;
|
|
LuaSetParam( L) ;
|
|
}
|
|
return 2 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
bool
|
|
LuaInstallGeoInters( LuaMgr& luaMgr)
|
|
{
|
|
bool bOk = ( &luaMgr != nullptr) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtBoxLineInters", LuaBoxLineInters) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmLineInters", LuaSurfTmLineInters) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmPlaneInters", LuaSurfTmPlaneInters) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmSurfTmInters", LuaSurfTmSurfTmInters) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapPlaneInters", LuaVolZmapPlaneInters) ;
|
|
return bOk ;
|
|
}
|