36901494f9
- aggiunta funzione ExeChangePhotoCenterAsFlatScan.
332 lines
12 KiB
C++
332 lines
12 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2015-2015
|
|
//----------------------------------------------------------------------------
|
|
// File : EXE_Photo.cpp Data : 05.10.15 Versione : 1.6j1
|
|
// Contenuto : Funzioni per gestione fotografia.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 05.10.15 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "PhotoObj.h"
|
|
#include "EXE.h"
|
|
#include "EXE_Macro.h"
|
|
#include "AuxTools.h"
|
|
#include "/EgtDev/Include/EXeExecutor.h"
|
|
#include "/EgtDev/Include/EXeConst.h"
|
|
#include "/EgtDev/Include/EGkStringUtils3d.h"
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
MyAddPhoto( const string& sName, const string& sPath,
|
|
const Point3d& ptOri, const Point3d& ptCen, double dMMxPixel,
|
|
int nParentId, const Point3d& ptMin, const Point3d& ptMax)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
IEGrScene* pScene = GetCurrScene() ;
|
|
VERIFY_SCENE( pScene, GDB_ID_NULL)
|
|
// Carico la texture
|
|
if ( ! pScene->UnloadTexture( sName) ||
|
|
! pScene->LoadTexture( sName, sPath, dMMxPixel, 0, 0, TXR_CLAMP))
|
|
return GDB_ID_NULL ;
|
|
// Recupero le dimensioni fisiche
|
|
double dDimX, dDimY ;
|
|
pScene->GetTextureDimensions( sName, dDimX, dDimY) ;
|
|
// Inserisco la regione rettangolare della foto (tutti i dati sono in Globale)
|
|
Point3d ptIni = ptOri ;
|
|
Point3d ptCross = ptIni + Vector3d( dDimX, dDimY, 0) ;
|
|
ptIni.x = max( ptIni.x, ptMin.x) ;
|
|
ptIni.y = max( ptIni.y, ptMin.y) ;
|
|
ptCross.x = min( ptCross.x, ptMax.x) ;
|
|
ptCross.y = min( ptCross.y, ptMax.y) ;
|
|
int nId = ExeCreateSurfFrRectangle( nParentId, ptIni, ptCross, RTY_GLOB) ;
|
|
if ( nId == GDB_ID_NULL) {
|
|
pScene->UnloadTexture( sName) ;
|
|
return GDB_ID_NULL ;
|
|
}
|
|
// Assegno gli attributi
|
|
pGeomDB->SetMaterial( nId, WHITE) ;
|
|
pGeomDB->SetName( nId, sName) ;
|
|
// Assegno i dati della texture
|
|
pGeomDB->SetTextureName( nId, sName) ;
|
|
pGeomDB->SetTextureFrame( nId, Frame3d( ptOri)) ;
|
|
// Installo e inizializzo il gestore della foto
|
|
PhotoObj* pPhoto = new( nothrow) PhotoObj ;
|
|
if ( pPhoto == nullptr) {
|
|
pGeomDB->Erase( nId) ;
|
|
pScene->UnloadTexture( sName) ;
|
|
return GDB_ID_NULL ;
|
|
}
|
|
pPhoto->Set( sName, sPath, ptOri, ptCen, dDimX, dDimY) ;
|
|
pGeomDB->SetUserObj( nId, pPhoto) ;
|
|
return nId ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
ExeAddPhoto( const string& sName, const string& sPath,
|
|
const Point3d& ptOri, const Point3d& ptCen, double dMMxPixel,
|
|
int nParentId, const Point3d& ptMin, const Point3d& ptMax)
|
|
{
|
|
// lancio esecuzione
|
|
int nId = MyAddPhoto( sName, sPath, ptOri, ptCen, dMMxPixel, nParentId, ptMin, ptMax) ;
|
|
ExeSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtAddPhoto('" + StringToLuaString( sName) + "','" +
|
|
StringToLuaString( sPath) + "',{" +
|
|
ToString( ptOri) + "},{" +
|
|
ToString( ptCen) + "}," +
|
|
ToString( dMMxPixel) + "," +
|
|
IdToString( nParentId) + ",{" +
|
|
ToString( ptMin) + "},{" +
|
|
ToString( ptMax) + "})" +
|
|
" -- Id=" + ToString( nId) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco risultato
|
|
return nId ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
ExeAddPhoto( const string& sName, const string& sPath,
|
|
const Point3d& ptOri, const Point3d& ptCen, double dDimX, double dDimY,
|
|
int nParentId, const Point3d& ptMin, const Point3d& ptMax)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
IEGrScene* pScene = GetCurrScene() ;
|
|
VERIFY_SCENE( pScene, GDB_ID_NULL)
|
|
// Carico la texture
|
|
if ( ! pScene->UnloadTexture( sName) ||
|
|
! pScene->LoadTexture( sName, sPath, 0, dDimX, dDimY, TXR_CLAMP))
|
|
return GDB_ID_NULL ;
|
|
// Inserisco la regione rettangolare della foto (tutti i dati sono in Globale)
|
|
Point3d ptIni = ptOri ;
|
|
Point3d ptCross = ptIni + Vector3d( dDimX, dDimY, 0) ;
|
|
ptIni.x = max( ptIni.x, ptMin.x) ;
|
|
ptIni.y = max( ptIni.y, ptMin.y) ;
|
|
ptCross.x = min( ptCross.x, ptMax.x) ;
|
|
ptCross.y = min( ptCross.y, ptMax.y) ;
|
|
int nId = ExeCreateSurfFrRectangle( nParentId, ptIni, ptCross, RTY_GLOB) ;
|
|
if ( nId == GDB_ID_NULL) {
|
|
pScene->UnloadTexture( sName) ;
|
|
return GDB_ID_NULL ;
|
|
}
|
|
// Assegno gli attributi
|
|
pGeomDB->SetMaterial( nId, WHITE) ;
|
|
pGeomDB->SetName( nId, sName) ;
|
|
// Assegno i dati della texture
|
|
pGeomDB->SetTextureName( nId, sName) ;
|
|
pGeomDB->SetTextureFrame( nId, Frame3d( ptOri)) ;
|
|
// Installo e inizializzo il gestore della foto
|
|
PhotoObj* pPhoto = new( nothrow) PhotoObj ;
|
|
if ( pPhoto == nullptr) {
|
|
pGeomDB->Erase( nId) ;
|
|
pScene->UnloadTexture( sName) ;
|
|
return GDB_ID_NULL ;
|
|
}
|
|
pPhoto->Set( sName, sPath, ptOri, ptCen, dDimX, dDimY) ;
|
|
pGeomDB->SetUserObj( nId, pPhoto) ;
|
|
ExeSetModified() ;
|
|
return nId ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeMovePhoto( int nId, const Vector3d& vtMove)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero il gestore dei dati della fotografia dell'oggetto
|
|
PhotoObj* pPhoto = dynamic_cast<PhotoObj*>( pGeomDB->GetUserObj( nId)) ;
|
|
if ( pPhoto == nullptr)
|
|
return false ;
|
|
// eseguo il movimento
|
|
pGeomDB->TranslateGlob( nId, vtMove) ;
|
|
Frame3d frTxt ;
|
|
pGeomDB->GetTextureFrame( nId, frTxt) ;
|
|
frTxt.Translate( vtMove) ;
|
|
pGeomDB->SetTextureFrame( nId, frTxt) ;
|
|
// aggiorno i punti notevoli della fotografia
|
|
Point3d ptCen ;
|
|
pPhoto->GetCenter( ptCen) ;
|
|
ptCen.Translate( vtMove) ;
|
|
pPhoto->ChangeCenter( ptCen) ;
|
|
Point3d ptOrig ;
|
|
pPhoto->GetOrigin( ptOrig) ;
|
|
ptOrig.Translate( vtMove) ;
|
|
pPhoto->ChangeOrigin( ptOrig) ;
|
|
ExeSetModified() ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeRotatePhoto( int nId, const Point3d& ptAx, const Vector3d& vtAx, double dAngDeg)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero il gestore dei dati della fotografia dell'oggetto
|
|
PhotoObj* pPhoto = dynamic_cast<PhotoObj*>( pGeomDB->GetUserObj( nId)) ;
|
|
if ( pPhoto == nullptr)
|
|
return false ;
|
|
// eseguo la rotazione
|
|
pGeomDB->RotateGlob( nId, ptAx, vtAx, dAngDeg) ;
|
|
Frame3d frTxt ;
|
|
pGeomDB->GetTextureFrame( nId, frTxt) ;
|
|
frTxt.Rotate( ptAx, vtAx, dAngDeg) ;
|
|
pGeomDB->SetTextureFrame( nId, frTxt) ;
|
|
// aggiorno i punti notevoli della fotografia
|
|
Point3d ptCen ;
|
|
pPhoto->GetCenter( ptCen) ;
|
|
ptCen.Rotate( ptAx, vtAx, dAngDeg) ;
|
|
pPhoto->ChangeCenter( ptCen) ;
|
|
Point3d ptOrig ;
|
|
pPhoto->GetOrigin( ptOrig) ;
|
|
ptOrig.Rotate( ptAx, vtAx, dAngDeg) ;
|
|
pPhoto->ChangeOrigin( ptOrig) ;
|
|
ExeSetModified() ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeGetPhotoPath( int nId, string& sPath)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero il gestore dei dati della fotografia dell'oggetto
|
|
PhotoObj* pPhoto = dynamic_cast<PhotoObj*>( pGeomDB->GetUserObj( nId)) ;
|
|
if ( pPhoto == nullptr)
|
|
return false ;
|
|
// recupero la path della fotografia
|
|
return pPhoto->GetPath( sPath) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeChangePhotoPath( int nId, const string& sPath)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero il gestore dei dati della fotografia dell'oggetto
|
|
PhotoObj* pPhoto = dynamic_cast<PhotoObj*>( pGeomDB->GetUserObj( nId)) ;
|
|
bool bOk = ( pPhoto != nullptr) ;
|
|
// imposto la nuova path della fotografia
|
|
bOk = bOk && pPhoto->ChangePath( sPath) ;
|
|
ExeSetModified() ;
|
|
// se richiesto, salvo il comando Lua equivalente
|
|
if ( IsCmdLog()) {
|
|
string sLua = "EgtChangePhotoPath(" + IdToString( nId) + ",'" +
|
|
StringToLuaString( sPath) + "')" +
|
|
" -- Ok=" + ToString( bOk) ;
|
|
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
|
}
|
|
// restituisco risultato
|
|
return bOk ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeGetPhotoOrigin( int nId, Point3d& ptOri)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero il gestore dei dati della fotografia dell'oggetto
|
|
PhotoObj* pPhoto = dynamic_cast<PhotoObj*>( pGeomDB->GetUserObj( nId)) ;
|
|
if ( pPhoto == nullptr)
|
|
return false ;
|
|
// recupero l'origine della fotografia
|
|
return pPhoto->GetOrigin( ptOri) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeGetPhotoCenter( int nId, Point3d& ptCen)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero il gestore dei dati della fotografia dell'oggetto
|
|
PhotoObj* pPhoto = dynamic_cast<PhotoObj*>( pGeomDB->GetUserObj( nId)) ;
|
|
if ( pPhoto == nullptr)
|
|
return false ;
|
|
// recupero il centro di ripresa della fotografia
|
|
return pPhoto->GetCenter( ptCen) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeChangePhotoCenterAsFlatScan( int nId)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero il gestore dei dati della fotografia dell'oggetto
|
|
PhotoObj* pPhoto = dynamic_cast<PhotoObj*>( pGeomDB->GetUserObj( nId)) ;
|
|
if ( pPhoto == nullptr)
|
|
return false ;
|
|
// imposto il centro di ripresa della fotografia
|
|
return pPhoto->ChangeCenter( Point3d( 0, 0, INFINITO)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeGetPhotoDimensions( int nId, double& dDimX, double& dDimY)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero il gestore dei dati della fotografia dell'oggetto
|
|
PhotoObj* pPhoto = dynamic_cast<PhotoObj*>( pGeomDB->GetUserObj( nId)) ;
|
|
if ( pPhoto == nullptr)
|
|
return false ;
|
|
// recupero le dimensioni fisiche della fotografia
|
|
return pPhoto->GetDimensions( dDimX, dDimY) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeGetPhotoPixels( int nId, int& nPixelX, int& nPixelY)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
IEGrScene* pScene = GetCurrScene() ;
|
|
VERIFY_SCENE( pScene, false)
|
|
// recupero il gestore dei dati della fotografia dell'oggetto
|
|
PhotoObj* pPhoto = dynamic_cast<PhotoObj*>( pGeomDB->GetUserObj( nId)) ;
|
|
if ( pPhoto == nullptr)
|
|
return false ;
|
|
// recupero le dimensioni in pixels della fotografia
|
|
string sName ;
|
|
if ( ! pPhoto->GetName( sName))
|
|
return false ;
|
|
return ( pScene->GetTexturePixels( sName, nPixelX, nPixelY) && nPixelX > 0 && nPixelY > 0) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeGetPhotoImagePixels( int nId, int& nPixelX, int& nPixelY)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
IEGrScene* pScene = GetCurrScene() ;
|
|
VERIFY_SCENE( pScene, false)
|
|
// recupero il gestore dei dati della fotografia dell'oggetto
|
|
PhotoObj* pPhoto = dynamic_cast<PhotoObj*>( pGeomDB->GetUserObj( nId)) ;
|
|
if ( pPhoto == nullptr)
|
|
return false ;
|
|
// recupero le dimensioni in pixels della immagine da cui è stata derivata la fotografia
|
|
string sName ;
|
|
if ( ! pPhoto->GetName( sName))
|
|
return false ;
|
|
return ( pScene->GetTextureImagePixels( sName, nPixelX, nPixelY) && nPixelX > 0 && nPixelY > 0) ;
|
|
}
|