Commit 85fbb26e authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen

Merge branch 'develop' of https://git.rwth-aachen.de/ita/ITAGeo into develop

parents af282f39 eda267a2
......@@ -22,6 +22,9 @@
// ITAGeo includes
#include <ITAGeoDefinitions.h>
// ITABase
#include <ITAThirdOctaveMagnitudeSpectrum.h>
// Vista includes
#include <VistaBase/VistaQuaternion.h>
#include <VistaBase/VistaVector3D.h>
......@@ -48,14 +51,14 @@ namespace ITAGeo
public:
enum
{
ITA_MATERIAL_NOTYPE = 0, //!< No data type specified
ITA_MATERIAL_VISUALIZATION, //!< Visualization material (colors, textures, etc)
ITA_MATERIAL_ONE_DIM, //!< One dimensional values, see CITAOneDimAcousticMaterial
ITA_MATERIAL_TRI_BAND, //!< Three values, see CITATriBandAcousticMaterial
ITA_MATERIAL_WHOLE_OCTAVE, //!< Whole-octave values, see CITAWholeOctaveAcousticMaterial
ITA_MATERIAL_THIRD_OCTAVE, //!< Third-octave values, see CITAThirdOctaveAcousticMaterial
ITA_MATERIAL_SPECTRUM, //!< Complex-valued spectrum, see ?
ITA_MATERIAL_MAGNITUDE_SPECTRUM, //!< Magnitude spectrum values, see ?
NONE = 0, //!< No data type specified
VISUALIZATION, //!< Visualization material (colors, textures, etc)
SCALAR, //!< One dimensional values, see CITAOneDimAcousticMaterial
TRI_BAND, //!< Three values, see CITATriBandAcousticMaterial
WHOLE_OCTAVE, //!< Whole-octave values, see CITAWholeOctaveAcousticMaterial
THIRD_OCTAVE, //!< Third-octave values, see CITAThirdOctaveAcousticMaterial
COMPLEX_SPECTRUM, //!< Complex-valued spectrum, see ?
MAGNITUDE_SPECTRUM, //!< Magnitude spectrum values, see ?
};
//! Return string type (for casting)
......@@ -77,7 +80,7 @@ namespace ITAGeo
std::string sName;
inline CVisualizationMaterial() : dRed( 0 ), dGreen( 0 ), dBlue( 0 ), dAlpha( 1.0f ) {};
inline std::string GetIdentifier() const { return sName; };
inline int GetType() const { return IAcousticMaterial::ITA_MATERIAL_VISUALIZATION; };
inline int GetType() const { return IAcousticMaterial::VISUALIZATION; };
double dRed, dGreen, dBlue, dAlpha; //!< Data range from 0 to 1
inline void SetBlack()
......@@ -93,7 +96,7 @@ namespace ITAGeo
};
};
class ITA_GEO_API COneDimAcousticMaterial : public IAcousticMaterial
class ITA_GEO_API CScalarMaterial : public IAcousticMaterial
{
public:
std::string sName; //! Versatile name (for debugging)
......@@ -101,7 +104,7 @@ namespace ITAGeo
std::complex< double > cdTransmissionFactor; //! Complex-valued transmission factor [0..1]
std::complex< double > cdScatteringCoefficient; //! Complex-valued scattering coefficient [0..1]
inline ~COneDimAcousticMaterial() {};
inline ~CScalarMaterial() {};
inline std::string GetIdentifier() const
{
......@@ -110,7 +113,7 @@ namespace ITAGeo
inline int GetType() const
{
return IAcousticMaterial::ITA_MATERIAL_ONE_DIM;
return IAcousticMaterial::SCALAR;
};
inline void SetDefaults()
......@@ -127,18 +130,15 @@ namespace ITAGeo
};
};
class ITA_GEO_API CSpectrumMaterial : public IAcousticMaterial
class ITA_GEO_API CThirdOctaveMaterial : public IAcousticMaterial
{
public:
std::string sName; //! Versatile name (for debugging)
// @todo: use ITABAse classes such as CITAComplexAmplitudeSpectrum
std::vector< double > vdFrequencies; //!< Frequency base values
std::vector< std::complex< double > > vcfComplexReflectionFactor; //! Complex reflection factor vector |R| = [0..1]
std::vector< std::complex< double > > vcfComplexTransmitionFactor; //! Complex transmission factor vector |T| = [0..1]
std::vector< std::complex< double > > vcfScatteringCoefficient; //! Complex scattering factor vector |S| = [0..1]
ITABase::CThirdOctaveGainMagnitudeSpectrum oAbsorptionCoefficients;
ITABase::CThirdOctaveGainMagnitudeSpectrum oScatteringCoefficients;
inline ~CSpectrumMaterial() {};
inline ~CThirdOctaveMaterial() {};
inline std::string GetIdentifier() const
{
......@@ -147,12 +147,12 @@ namespace ITAGeo
inline int GetType() const
{
return IAcousticMaterial::ITA_MATERIAL_SPECTRUM;
return IAcousticMaterial::THIRD_OCTAVE;
};
inline size_t GetNumBins() const
inline int GetNumBands() const
{
return vdFrequencies.size();
return ITABase::CThirdOctaveGainMagnitudeSpectrum::GetNumBands();
};
};
......@@ -199,18 +199,18 @@ namespace ITAGeo
return *this;
};
inline IAcousticMaterial* GetMaterial() const
inline const IAcousticMaterial* GetMaterial() const
{
return m_pMaterial;
};
void SetMaterial( IAcousticMaterial* pMaterial )
inline void SetMaterial( const IAcousticMaterial* pMaterial )
{
m_pMaterial = pMaterial;
};
private:
IAcousticMaterial* m_pMaterial; //! Pointer to complex material
const IAcousticMaterial* m_pMaterial; //! Pointer to complex material
};
}
......
......@@ -55,7 +55,9 @@ namespace ITAGeo
/**
* @return True, if possible, false if already existing or manager is read-only
*/
virtual inline bool AddMaterialCopy( ITAGeo::IAcousticMaterial* pMaterial ) { return false; };
virtual bool AddMaterialCopy( const std::string& sIdentifier, const ITAGeo::IAcousticMaterial* pMat ) = 0;
virtual bool GetReadOnly() const = 0;
};
......@@ -67,12 +69,18 @@ namespace ITAGeo
CMaterialDirectory( const std::string& sFolderPath, const bool bRecursive = true );
~CMaterialDirectory();
std::vector< std::string > GetPaths() const;
void AddMaterialsFromFolder( const std::string& sFolderPath, const bool bRecursive = false );
const ITAGeo::IAcousticMaterial* GetMaterial( const std::string& sMaterialIdentifier ) const;
int GetNumMaterials() const;
std::vector< std::string > GetMaterialIdentifier() const;
bool AddMaterialCopy( const std::string&, const ITAGeo::IAcousticMaterial* );
bool GetReadOnly() const;
private:
std::map< std::string, ITAGeo::IAcousticMaterial* > m_mMaterials;
std::vector< std::string > m_vsPaths;
};
}
......
......@@ -80,7 +80,7 @@ namespace ITAGeo
*
* @param[in] pMaterialManager Associated material manager (with write access)
*/
void SetAssociatedMaterialManager( ITAGeo::CMaterialManager* pMaterialManager );
void SetMaterialManager( ITAGeo::CMaterialManager* pMaterialManager );
protected:
......
......@@ -59,9 +59,18 @@ ITAGeo::CMaterialDirectory::~CMaterialDirectory()
delete m.second;
}
std::vector< std::string > ITAGeo::CMaterialDirectory::GetPaths() const
{
return m_vsPaths;
}
void ITAGeo::CMaterialDirectory::AddMaterialsFromFolder( const std::string& sFolderPath, const bool bRecursive /*= false*/ )
{
for( auto pNode : VistaFileSystemDirectory( sFolderPath ) )
VistaFileSystemDirectory oNewPath( sFolderPath );
if( oNewPath.Exists() )
m_vsPaths.push_back( oNewPath.GetName() );
for( auto pNode : oNewPath )
{
if( pNode->IsDirectory() && bRecursive && pNode->GetLocalName() != "." && pNode->GetLocalName() != "..")
AddMaterialsFromFolder( pNode->GetName(), bRecursive );
......@@ -78,17 +87,11 @@ void ITAGeo::CMaterialDirectory::AddMaterialsFromFolder( const std::string& sFol
CMATFileMaterial oMaterial;
oMaterial.LoadFromFile( pNode->GetName() );
CSpectrumMaterial* pMaterial = new CSpectrumMaterial();
CThirdOctaveMaterial* pMaterial = new CThirdOctaveMaterial();
pMaterial->sName = oMaterial.sName;
pMaterial->vdFrequencies = ITAConstants::THIRD_OCTAVE_CENTER_FREQUENCIES_ISO_D;
if( oMaterial.vfAbsorptionCoefficients.size() == pMaterial->vdFrequencies.size() )
for( size_t i = 0; i < pMaterial->GetNumBins(); i++ )
pMaterial->vcfComplexReflectionFactor.push_back( 1.0f - ( double ) oMaterial.vfAbsorptionCoefficients[ i ] );
if( oMaterial.vfScatteringCoefficients.size() == pMaterial->vdFrequencies.size() )
for( size_t i = 0; i < pMaterial->GetNumBins(); i++ )
pMaterial->vcfScatteringCoefficient.push_back( ( double ) oMaterial.vfScatteringCoefficients[ i ] );
pMaterial->oAbsorptionCoefficients.SetMagnitudes( oMaterial.vfAbsorptionCoefficients );
pMaterial->oScatteringCoefficients.SetMagnitudes( oMaterial.vfScatteringCoefficients );
m_mMaterials[ sIdentifier ] = pMaterial;
}
......@@ -103,6 +106,30 @@ const ITAGeo::IAcousticMaterial* ITAGeo::CMaterialDirectory::GetMaterial( const
return m_mMaterials.find( sMaterialIdentifier )->second;
}
int ITAGeo::CMaterialDirectory::GetNumMaterials() const
{
return ( int ) m_mMaterials.size();
}
std::vector< std::string > ITAGeo::CMaterialDirectory::GetMaterialIdentifier() const
{
std::vector< std::string > vsIDs;
std::map< std::string, IAcousticMaterial* >::const_iterator cit = m_mMaterials.begin();
while( cit != m_mMaterials.end() )
vsIDs.push_back( cit++->first );
return vsIDs;
}
bool ITAGeo::CMaterialDirectory::AddMaterialCopy( const std::string&, const ITAGeo::IAcousticMaterial* )
{
return !GetReadOnly();
}
bool ITAGeo::CMaterialDirectory::GetReadOnly() const
{
return true;
}
void CMATFileMaterial::LoadFromFile( const std::string& sFilePath )
{
INIFileUseFile( sFilePath );
......
......@@ -9,7 +9,7 @@
#include <iomanip>
void ITAGeo::CModelBase::SetAssociatedMaterialManager( CMaterialManager* pMaterialManager )
void ITAGeo::CModelBase::SetMaterialManager( CMaterialManager* pMaterialManager )
{
m_pAssociatedMaterialManager = pMaterialManager;
}
......
#include "ITAGeoSUMaterials.h"
#include "ITAGeoSUHelper.h"
// ITAGeo includes
#include <ITAGeoAcousticMaterial.h>
#include <ITAGeoMaterialManager.h>
// ITABase includes
#include <ITAException.h>
......@@ -30,7 +34,7 @@ bool AddFaceMaterial( CITAMesh* pMesh, ITAGeo::IAcousticMaterial* pMaterial, CIT
return true;
}
bool SUColorToOneDimAcousticMaterial( ITAGeo::COneDimAcousticMaterial* pMaterial, const SUColor& tColor )
bool SUColorToOneDimAcousticMaterial( ITAGeo::CScalarMaterial* pMaterial, const SUColor& tColor )
{
assert( pMaterial );
pMaterial->cdTransmissionFactor = tColor.alpha / 255.0f; // T, complex
......@@ -51,7 +55,7 @@ bool AcousticMaterialToSUMaterial( CITAMesh* pMesh, CITAMesh::FaceHandle hFace,
int iMaterialType = pMaterial->GetType();
switch( iMaterialType )
{
case IAcousticMaterial::ITA_MATERIAL_VISUALIZATION:
case IAcousticMaterial::VISUALIZATION:
{
const CVisualizationMaterial* pVisMaterial = static_cast< const CVisualizationMaterial* >( pMaterial );
assert( pVisMaterial );
......@@ -61,12 +65,12 @@ bool AcousticMaterialToSUMaterial( CITAMesh* pMesh, CITAMesh::FaceHandle hFace,
oSUColor.alpha = ( unsigned char ) ( pVisMaterial->dAlpha * 255.0f );
break;
}
case IAcousticMaterial::ITA_MATERIAL_NOTYPE:
case IAcousticMaterial::ITA_MATERIAL_ONE_DIM:
case IAcousticMaterial::ITA_MATERIAL_THIRD_OCTAVE:
case IAcousticMaterial::ITA_MATERIAL_WHOLE_OCTAVE:
case IAcousticMaterial::ITA_MATERIAL_SPECTRUM:
case IAcousticMaterial::ITA_MATERIAL_MAGNITUDE_SPECTRUM:
case IAcousticMaterial::NONE:
case IAcousticMaterial::SCALAR:
case IAcousticMaterial::THIRD_OCTAVE:
case IAcousticMaterial::WHOLE_OCTAVE:
case IAcousticMaterial::COMPLEX_SPECTRUM:
case IAcousticMaterial::MAGNITUDE_SPECTRUM:
default:
{
pSUFaceMaterial = NULL;
......@@ -82,6 +86,10 @@ bool AcousticMaterialToSUMaterial( CITAMesh* pMesh, CITAMesh::FaceHandle hFace,
SUResult SUMaterialToAcousticMaterial( CITAMesh* pMesh, CITAMesh::FaceHandle hFace, SUFaceRef rFace, ITAGeo::CMaterialManager* pManager )
{
// Without a manager, the material assignment is skipped.
if( !pManager )
return SU_ERROR_NONE;
SUResult sur;
SUMaterialRef rMaterial = SU_INVALID;
......@@ -103,74 +111,57 @@ SUResult SUMaterialToAcousticMaterial( CITAMesh* pMesh, CITAMesh::FaceHandle hFa
SUStringRef rTextureFileName = SU_INVALID;
SUStringCreate( &rTextureFileName );
SUTextureRef rTexture;
SUColor tColor;
if( tMaterial == SUMaterialType_Colored )
{
sur = SUMaterialGetColor( rMaterial, &tColor );
if( sur != SU_ERROR_NONE )
return sur; // or defaults and skip?
// If the manager has an acoustic material with the name of the
// face material, it will be assigned, otherwise created and assigned if possible
// Set material connection for this face
COneDimAcousticMaterial* pMat = new COneDimAcousticMaterial;
if( pManager->HasMaterial( sMaterialName ) )
{
const IAcousticMaterial* pMat = pManager->GetMaterial( sMaterialName );
pMesh->property( tAcousticFaceProp, hFace ).SetMaterial( pMat );
SUColorToOneDimAcousticMaterial( pMat, tColor );
}
else if( tMaterial == SUMaterialType_ColorizedTexture )
else if( pManager->GetReadOnly() == false )
{
// Texture stronger than material, fallback if not available in database
bool bMaterialFound = false;
SUTextureRef rTexture;
SUColor tColor;
SUMaterialGetColor( rMaterial, &tColor );
SUMaterialGetTexture( rMaterial, &rTexture );
if( SUTextureGetFileName( rTexture, &rTextureFileName ) == SU_ERROR_NONE )
sTextureFileName = SUStringToStdString( rTextureFileName );
CScalarMaterial* pNewMat = nullptr;
if( pManager != nullptr )
switch( tMaterial )
{
pManager; // TODO pull data from DB
bMaterialFound = true;
}
if( bMaterialFound )
case( SUMaterialType_Colored ) :
{
sur = SUMaterialGetColor( rMaterial, &tColor );
if( sur != SU_ERROR_NONE )
return sur;
// Create Material
pNewMat = new CScalarMaterial;
SUColorToOneDimAcousticMaterial( pNewMat, tColor );
break;
}
else
case( SUMaterialType_ColorizedTexture ) :
{
// Set material connection for this face
COneDimAcousticMaterial* pMaterial = new COneDimAcousticMaterial;
pMesh->property( tAcousticFaceProp, hFace ).SetMaterial( pMaterial );
SUColorToOneDimAcousticMaterial( pMaterial, tColor );
}
}
else if( tMaterial == SUMaterialType_Textured )
{
SUMaterialGetTexture( rMaterial, &rTexture );
if( SUTextureGetFileName( rTexture, &rTextureFileName ) == SU_ERROR_NONE )
sTextureFileName = SUStringToStdString( rTextureFileName );
// Texture stronger than material, fallback if not available in database
bool bMaterialFound = false;
if( pManager != nullptr )
{
/* @todo weiter
const IITAAcousticMaterial* pMaterial = pManager->GetMaterial( sMaterialName );
if( pMaterial != nullptr )
{
CITADatabaseMaterial oDBMaterial;
pManager->AddMaterialCopy( oDBMaterial );
}
*/
sur = SUMaterialGetColor( rMaterial, &tColor );
if( sur != SU_ERROR_NONE )
return sur;
SUMaterialGetTexture( rMaterial, &rTexture );
if( SUTextureGetFileName( rTexture, &rTextureFileName ) == SU_ERROR_NONE )
sTextureFileName = SUStringToStdString( rTextureFileName );
// Create material
pNewMat = new CScalarMaterial;
SUColorToOneDimAcousticMaterial( pNewMat, tColor );
}
else
{
return SU_ERROR_NO_DATA;
}
// TODO: add aoustic material based on geo textures
}
else
{
return SU_ERROR_NO_DATA;
if( pNewMat && pManager->AddMaterialCopy( sMaterialName, pNewMat ) )
pMesh->property( tAcousticFaceProp, hFace ).SetMaterial( pManager->GetMaterial( sMaterialName ) );
delete pNewMat;
}
}
......
......@@ -46,7 +46,7 @@ void AddAcousticFacePropertyToMesh( CITAMesh* pMesh );
bool AddFaceMaterial( CITAMesh* pMesh, ITAGeo::IAcousticMaterial* pMaterial, CITAMesh::FaceHandle hFace );
//! Converts a color to a one-dimensional acoustic material
bool SUColorToOneDimAcousticMaterial( ITAGeo::COneDimAcousticMaterial* pMaterial, const SUColor& tColor );
bool SUColorToOneDimAcousticMaterial( ITAGeo::CScalarMaterial* pMaterial, const SUColor& tColor );
//! Creates SU material from acoutic material
bool AcousticMaterialToSUMaterial( CITAMesh* pMesh, CITAMesh::FaceHandle hFace, SUMaterialRef* rFaceMaterial, ITAGeo::CMaterialManager* pManager );
......
......@@ -18,6 +18,7 @@
#include <ITAException.h>
#include <ITAGeoSketchUpModel.h>
#include <ITAGeoMaterialManager.h>
#include <VistaTools/VistaFileSystemFile.h>
......@@ -34,7 +35,10 @@ int main( int, char** )
std::string sModelName = "GroupCompTest";
VistaFileSystemFile oFile( sBasePath + sModelName + "." + sSuffix );
CMaterialDirectory oMatDir( "." );
CSketchUpModel oGeoModel;
oGeoModel.SetMaterialManager( &oMatDir );
try
{
......
......@@ -10,6 +10,16 @@ using namespace ITAGeo;
int main( int, char** )
{
CMaterialDirectory oMaterialDirectory( "./" );
cout << "Found " << oMaterialDirectory.GetNumMaterials() << " unique material(s);" << endl;
for( auto s : oMaterialDirectory.GetMaterialIdentifier() )
cout << s << endl;
cout << endl;
cout << "Paths: " << endl;
for( auto s : oMaterialDirectory.GetPaths() )
cout << s << endl;
const IAcousticMaterial* pMaterial = oMaterialDirectory.GetMaterial( "stonewall" );
return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment