Applying shared ptr concept for all source files and tests

parent 5647b4a3
......@@ -55,6 +55,7 @@ namespace ITAGeo
public:
enum EAnchorType
{
INVALID = -1, //!< Invalid anchor
GENERIC_ANCHOR = 0, //!< Propagation anchor without specified type
ACOUSTIC_EMITTER, //!< Sound-emitting anchor (acoustic source, vibrating plane)
ACOUSTIC_SENSOR, //!< Sound-sensing anchor (microphone, sensivitive area, listener, portal)
......@@ -67,7 +68,6 @@ namespace ITAGeo
VistaVector3D v3InteractionPoint; //!< Point of geometric interaction, has to be further defined by deriving class
std::shared_ptr< IAcousticMaterial > pAcousticMaterial; //!< Acoustic material connection, i.e. absorption coefficient
bool bProtected; //!< Protect this anchor from destruction in DeleteAnchorsAndClear function
CPropagationAnchor();
CPropagationAnchor( const VistaVector3D& v3Pos );
......@@ -81,6 +81,8 @@ namespace ITAGeo
//! Output stream operator for console formatting etc.
friend std::ostream& operator<<( std::ostream&, const ITAGeo::CPropagationAnchor& );
virtual std::string ToString() const;
};
......@@ -200,13 +202,12 @@ namespace ITAGeo
inline virtual ~CMirrorImage() {};
inline void CopyFromAnchor( const ITAGeo::CPropagationAnchor& oOther, ITAGeo::CMaterialManager* pManager = nullptr )
inline void CopyFromAnchor( std::shared_ptr< const ITAGeo::CPropagationAnchor > pOther, ITAGeo::CMaterialManager* pManager = nullptr )
{
bProtected = oOther.bProtected;
v3InteractionPoint = oOther.v3InteractionPoint;
v3InteractionPoint = pOther->v3InteractionPoint;
if( pManager )
pManager->AddMaterial( oOther.pAcousticMaterial->GetIdentifier(), pAcousticMaterial );
pManager->AddMaterial( pOther->pAcousticMaterial->GetIdentifier(), pAcousticMaterial );
};
private:
inline const CMirrorImage operator=( const CMirrorImage& )
......@@ -233,14 +234,7 @@ namespace ITAGeo
};
ITA_GEO_API typedef std::vector< CPropagationAnchor* > CPropagationPath; //!< Geometric propagation path
//! Clears and deletes all anchors of path without protection flag enabled
/**
* @note Calls destructor on all anchors - make sure that no double deletion occurs!
*/
ITA_GEO_API void DeleteAnchorsAndClear( CPropagationPath& oDestructiblePath );
ITA_GEO_API typedef std::vector< std::shared_ptr< CPropagationAnchor > > CPropagationPath; //!< Geometric propagation path
}
......@@ -266,7 +260,7 @@ inline std::ostream& operator<<( std::ostream& os, const ITAGeo::CPropagationPat
os << "GeoPropagationPath: " << vPaths.size() << " anchors found" << std::endl;
for( size_t i = 0; i < vPaths.size(); i++ )
{
const ITAGeo::CPropagationAnchor* pAnchor( vPaths[ i ] );
auto pAnchor( vPaths[ i ] );
os << " GeoAnchor #" << std::setw( 3 ) << 1 + i << ": " << pAnchor << std::endl;
}
return os;
......
......@@ -44,8 +44,8 @@ namespace ITAGeo
~CScene();
CModelBase* pGeoModel; //!< Acoustic geometric data
std::vector< ITAGeo::CEmitter > vSoundEmitters; //!< Acoustic sound sources
std::vector< ITAGeo::CSensor > vSoundSensors; //!< Acoustic sound receivers
std::vector< std::shared_ptr< ITAGeo::CEmitter > > vpSoundEmitters; //!< Acoustic sound sources
std::vector< std::shared_ptr< ITAGeo::CSensor > > vpSoundSensors; //!< Acoustic sound receivers
};
}
......
......@@ -6,6 +6,8 @@ std::string ITAGeo::CPropagationAnchor::GetAnchorTypeStr( ITAGeo::CPropagationAn
{
switch( iType )
{
case INVALID:
return "InvalidAnchor";
case ACOUSTIC_EMITTER:
return "Source";
case ACOUSTIC_SENSOR:
......@@ -19,16 +21,22 @@ std::string ITAGeo::CPropagationAnchor::GetAnchorTypeStr( ITAGeo::CPropagationAn
case DIFFRACTION_APEX:
return "EdgeDiffraction";
case GENERIC_ANCHOR:
return "InvalidAnchor";
return "GenericAnchor";
default:
return "Unkown";
}
}
std::string ITAGeo::CPropagationAnchor::ToString() const
{
std::stringstream ss;
ss << "[ " << std::setw( 10 ) << GetAnchorTypeStr( iAnchorType ) << " ] Interaction point : " << v3InteractionPoint ;
return ss.str();
}
ITAGeo::CPropagationAnchor::CPropagationAnchor()
: iAnchorType( GENERIC_ANCHOR )
, pAcousticMaterial( NULL )
, bProtected( false )
{
}
......@@ -36,7 +44,6 @@ ITAGeo::CPropagationAnchor::CPropagationAnchor()
ITAGeo::CPropagationAnchor::CPropagationAnchor( const VistaVector3D& v3InteractionPoint )
: iAnchorType( GENERIC_ANCHOR )
, pAcousticMaterial( NULL )
, bProtected( false )
, v3InteractionPoint( v3InteractionPoint )
{
......@@ -46,12 +53,3 @@ ITAGeo::CPropagationAnchor::~CPropagationAnchor()
{
}
void ITAGeo::DeleteAnchorsAndClear( ITAGeo::CPropagationPath& oDestructiblePath )
{
for( size_t n = 0; n < oDestructiblePath.size(); n++ )
if( !oDestructiblePath[ n ]->bProtected )
delete oDestructiblePath[ n ];
oDestructiblePath.clear();
}
......@@ -426,8 +426,8 @@ bool ITAGeo::CSketchUpModel::Store( const std::string& sSKPFilePath, bool bOverw
std::vector< SUEdgeRef > vrEdges( oPath.size() - 1 );
for( size_t m = 0; m < vrEdges.size(); m++ )
{
const CPropagationAnchor* pSourceAnchor( oPath[ m ] );
const CPropagationAnchor* pTargetAnchor( oPath[ m + 1 ] );
auto pSourceAnchor( oPath[ m ] );
auto pTargetAnchor( oPath[ m + 1 ] );
if( pSourceAnchor == pTargetAnchor )
ITA_EXCEPT_INVALID_PARAMETER( "A propagation path can not have the same anchors in a row." );
......
......@@ -44,18 +44,16 @@ int main( int, char** )
for( int n=0; n<nPoints; n++ )
vvPointCloud.push_back( VistaVector3D( &dPointArray[ n * 5 + 1] ) );
CPropagationPath oDummyPath;
CPropagationPath oVisualizationPath;
for( int n=0; n<nPoints; n++ )
{
CPropagationAnchor* pAnchor = new CPropagationAnchor( vvPointCloud[ n ] );
oDummyPath.push_back( pAnchor );
auto pAnchor = std::make_shared< CPropagationAnchor >( vvPointCloud[ n ] );
oVisualizationPath.push_back( pAnchor );
}
CSketchUpModel oModel;
oModel.AddPropagationPathVisualization( oDummyPath, "PointCloudPolyLine" );
oModel.AddPropagationPathVisualization( oVisualizationPath, "PointCloudPolyLine" );
oModel.Store( "PointCloudExport.skp" );
ITAGeo::DeleteAnchorsAndClear( oDummyPath );
return 0;
}
......@@ -71,10 +71,10 @@ void load_sketchup_file()
CPropagationPath oPropPath;
oPropPath.resize( 4 );
oPropPath[ 0 ] = new CPropagationAnchor( VistaVector3D( ( double ) 0, ( double ) -10, ( double ) 0 ) );
oPropPath[ 1 ] = new CPropagationAnchor( VistaVector3D( ( double ) 0, ( double ) -10, ( double ) 100 ) );
oPropPath[ 2 ] = new CPropagationAnchor( VistaVector3D( ( double ) 100, ( double ) -10, ( double ) 100 ) );
oPropPath[ 3 ] = new CPropagationAnchor( VistaVector3D( ( double ) 100, ( double ) -10, ( double ) 0 ) );
oPropPath[ 0 ] = std::make_shared< CPropagationAnchor >( VistaVector3D( ( double ) 0, ( double ) -10, ( double ) 0 ) );
oPropPath[ 1 ] = std::make_shared< CPropagationAnchor >( VistaVector3D( ( double ) 0, ( double ) -10, ( double ) 100 ) );
oPropPath[ 2 ] = std::make_shared< CPropagationAnchor >( VistaVector3D( ( double ) 100, ( double ) -10, ( double ) 100 ) );
oPropPath[ 3 ] = std::make_shared< CPropagationAnchor >( VistaVector3D( ( double ) 100, ( double ) -10, ( double ) 0 ) );
model.AddPropagationPathVisualization( oPropPath, "test" );
model.Store( "SolidCube2017Store.skp" );
......
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