4dfd039637
- aggiunte ExeGetPhotoDimensions e ExeGetPhotoPixels - in import piccole modifiche in aggiornamento FilePath progetto corrente.
186 lines
6.7 KiB
C++
186 lines
6.7 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 "/EgtDev/Include/EXeExecutor.h"
|
|
#include "/EgtDev/Include/EXeConst.h"
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
ExeAddPhoto( 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) {
|
|
ExeUnloadTexture( 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) {
|
|
pScene->UnloadTexture( sName) ;
|
|
return GDB_ID_NULL ;
|
|
}
|
|
pPhoto->Set( sName, sPath, ptOri, ptCen, dDimX, dDimY) ;
|
|
pGeomDB->SetUserObj( nId, pPhoto) ;
|
|
ExeSetModified() ;
|
|
return nId ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
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)) ;
|
|
if ( pPhoto == nullptr)
|
|
return false ;
|
|
// imposto la nuova path della fotografia
|
|
return pPhoto->ChangePath( sPath) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
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
|
|
ExeGetPhotoMMxPixel( int nId, double& dMMxPixel)
|
|
{
|
|
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 fisiche della fotografia
|
|
double dDimX, dDimY ;
|
|
if ( ! pPhoto->GetDimensions( dDimX, dDimY))
|
|
return false ;
|
|
// recupero le dimensioni in pixels della fotografia
|
|
string sName ;
|
|
if ( ! pPhoto->GetName( sName))
|
|
return false ;
|
|
int nWidth, nHeight ;
|
|
if ( ! pScene->GetTexturePixels( sName, nWidth, nHeight) || nWidth == 0 || nHeight == 0)
|
|
return false ;
|
|
// calcolo il fattore di scala
|
|
dMMxPixel = ( dDimX / nWidth + dDimY / nHeight) / 2 ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
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) ;
|
|
} |