Commit c3720c86 authored by jonasstienen's avatar jonasstienen
Browse files

Fixing some issues with itaPigeon poject class and adding an example

parent d586998f
function generateConfig(this,sourcePosition,receiverPosition)
% This function generates the .ini file of the city path algorithm
visualizationPaths = [];
% change single '\' to '\\' in folder name, necessary for fprintf
this.geometryFilePath = strrep(this.geometryFilePath,'\','\\');
this.outFilePath = strrep(this.outFilePath,'\','\\');
for idx = 1:length(this.visualizationPaths)
% visualizationPaths{idx} = varargin{idx};
visualizationPaths{idx} = strrep(this.visualizationPaths{idx},'\','\\');
end
receiverString = ['SensorPos = ',num2str(receiverPosition(1)),', ',num2str(receiverPosition(2)),', ',num2str(receiverPosition(3)),'\n' ];
sourceString = ['EmitterPos = ',num2str(sourcePosition(1)),', ',num2str(sourcePosition(2)),', ',num2str(sourcePosition(3)),'\n' ];
if ~exist(fullfile(this.outFilePath),'dir')
mkdir(fullfile(this.outFilePath))
end
%% save old content of file as backup
if this.saveBackupConfig
backup = fopen([this.outFilePath,this.resultName,'_backup.ini'],'w+');
try
oldContent = fileread([this.outFilePath,this.resultName,'.ini']);
catch
oldContent = ''; %.ini File not created yet
end
% change '\' to '\\'
oldContent = strrep(oldContent,'\','\\');
fprintf(backup,oldContent);
fclose(backup);
end
%% create new .ini file
file = fopen([this.outFilePath,this.resultName,'.ini'],'w');
% go through file one by one and write the necessary output
fprintf(file,'[pidgeon:scene]\n');
fprintf(file,' \n');
fprintf(file,['GeometryFilePath = ',this.geometryFilePath,this.modelName,'.skp \n']);
fprintf(file,['OutputFilePath = ',this.outFilePath,this.resultName,'.json \n']);
fprintf(file,receiverString);
fprintf(file,sourceString);
fprintf(file,' \n');
fprintf(file,'[pidgeon:config] \n');
fprintf(file,' \n');
fprintf(file,['MaxDiffractionOrder = ',num2str(this.MaxDiffractionOrder),' \n']);
fprintf(file,['MaxReflectionOrder = ',num2str(this.MaxReflectionOrder),' \n']);
fprintf(file,['MaxCombinedOrder = ',num2str(this.MaxCombinedOrder),' \n']);
fprintf(file,' \n');
fprintf(file,['OnlyNeighbouredEdgeDiffraction = ',this.OnlyNeighbouredEdgeDiffraction,' \n']);
fprintf(file,['DiffractionOnlyIntoShadowedEdges = ',this.DiffractionOnlyIntoShadowedEdges,' \n']);
fprintf(file,['FilterNotVisiblePathsBetweenEdges = ',this.FilterNotVisiblePathsBetweenEdges,' \n']);
fprintf(file,['FilterNotVisiblePointToEdge = ',this.FilterNotVisiblePointToEdge,' \n']);
fprintf(file,['IntersectionTestResolution = ',num2str(this.IntersectionTestResolution),' \n']);
fprintf(file,['NumIterations = ',num2str(this.NumIterations),' \n']);
fprintf(file,' \n');
fprintf(file,['MaxAccumulatedDiffractionAngle = ',num2str(this.MaxAccumulatedDiffractionAngle),' \n']);
fprintf(file,' \n');
fprintf(file,['LevelDropThreshhold = ',num2str(this.LevelDropThreshold),' \n']);
fprintf(file,['ReflectionPenalty = ',num2str(this.ReflectionPenalty),' \n']);
fprintf(file,['DiffractionPenalty = ',num2str(this.DiffractionPenalty),' \n']);
fprintf(file,' \n');
fprintf(file,['ExportVisualisation = ',this.ExportVisualisation,' \n']);
fprintf(file,' \n');
% fprintf(file,'[pidgeon:visualization:PidgeonVizLayer1] \n');
for idx=1:length(visualizationPaths)
fprintf(file,['[pidgeon:visualization:PidgeonVizLayer',num2str(idx),'] \n']);
fprintf(file,' \n');
fprintf(file,['path',num2str(1),' = ',visualizationPaths{idx},' \n']);
fprintf(file,' \n');
end
fclose(file);
end
function generate_config( obj, source_pos, receiver_pos )
% This function generates the .ini file of the city path algorithm
[ output_folder, file_base_name ] = fileparts( obj.config_file_path );
if isempty( output_folder )
output_folder = pwd;
else
if ~exist( output_folder, 'dir' )
mkdir( output_folder )
end
end
visualizationPaths = [];
for idx = 1:length(obj.visualizationPaths)
% visualizationPaths{idx} = varargin{idx};
visualizationPaths{idx} = strrep(obj.visualizationPaths{idx},'\','\\');
end
receiverString = ['SensorPos = ',num2str(receiver_pos(1)),', ',num2str(receiver_pos(2)),', ',num2str(receiver_pos(3)),'\n' ];
sourceString = ['EmitterPos = ',num2str(source_pos(1)),', ',num2str(source_pos(2)),', ',num2str(source_pos(3)),'\n' ];
%% save old content of file as backup
if obj.saveBackupConfig
config_path_backup = fopen( fullfile( output_folder, strcat( file_base_name, '_backup.ini' ) ), 'w+' );
try
txt = fileread([obj.outFilePath,obj.resultName,'.ini']);
catch
txt = ''; %.ini File not created yet
end
% change '\' to '\\'
txt = strrep(txt,'\','\\');
fprintf( config_path_backup, txt );
fclose( config_path_backup );
end
%% create new .ini file
file = fopen( obj.config_file_path, 'w' );
% go through file one by one and write the necessary output
fprintf(file,'[pigeon:scene]\n');
fprintf(file,' \n');
fprintf(file, 'GeometryFilePath = %s\n', obj.geometry_file_path );
fprintf(file, 'OutputFilePath = %s\n', obj.result_file_path );
fprintf(file,receiverString);
fprintf(file,sourceString);
fprintf(file,' \n');
fprintf(file,'[pigeon:config] \n');
fprintf(file,' \n');
fprintf(file,['MaxDiffractionOrder = ',num2str(obj.MaxDiffractionOrder),' \n']);
fprintf(file,['MaxReflectionOrder = ',num2str(obj.MaxReflectionOrder),' \n']);
fprintf(file,['MaxCombinedOrder = ',num2str(obj.MaxCombinedOrder),' \n']);
fprintf(file,' \n');
fprintf(file,['OnlyNeighbouredEdgeDiffraction = ',obj.OnlyNeighbouredEdgeDiffraction,' \n']);
fprintf(file,['DiffractionOnlyIntoShadowedEdges = ',obj.DiffractionOnlyIntoShadowedEdges,' \n']);
fprintf(file,['FilterNotVisiblePaths = ',obj.FilterNotVisiblePaths,' \n']);
fprintf(file,['FilterEmitterToEdgeIntersectedPaths = ',obj.FilterNotVisiblePointToEdge,' \n']);
fprintf(file,['FilterSensorToEdgeIntersectedPaths = ',obj.FilterNotVisiblePointToEdge,' \n']);
fprintf(file,['IntersectionTestResolution = ',num2str(obj.IntersectionTestResolution),' \n']);
fprintf(file,['NumIterations = ',num2str(obj.NumIterations),' \n']);
fprintf(file,' \n');
fprintf(file,['MaxAccumulatedDiffractionAngle = ',num2str(obj.MaxAccumulatedDiffractionAngle),' \n']);
fprintf(file,' \n');
fprintf(file,['LevelDropThreshhold = ',num2str(obj.LevelDropThreshold),' \n']);
fprintf(file,['ReflectionPenalty = ',num2str(obj.ReflectionPenalty),' \n']);
fprintf(file,['DiffractionPenalty = ',num2str(obj.DiffractionPenalty),' \n']);
fprintf(file,' \n');
fprintf(file,['ExportVisualisation = ',obj.export_visualization,' \n']);
fprintf(file,' \n');
% fprintf(file,'[pigeon:visualization:pigeonVizLayer1] \n');
for idx=1:length(visualizationPaths)
fprintf(file,['[pigeon:visualization:pigeonVizLayer',num2str(idx),'] \n']);
fprintf(file,' \n');
fprintf(file,['path',num2str(1),' = ',visualizationPaths{idx},' \n']);
fprintf(file,' \n');
end
fclose(file);
end
classdef itaPigeonProject
%ITA_CAU_URBANPROPAGATION interface class for the urban simulation
%itaPigeonProject interface class for the urban simulation
properties(Access = public)
......@@ -10,31 +10,34 @@ classdef itaPigeonProject
MaxCombinedOrder = 2;
OnlyNeighbouredEdgeDiffraction = 'false';
DiffractionOnlyIntoShadowedEdges = 'false';
FilterNotVisiblePathsBetweenEdges = 'false';
FilterNotVisiblePointToEdge = 'false';
FilterNotVisiblePaths = 'true';
FilterNotVisiblePointToEdge = 'true';
IntersectionTestResolution = 0.001;
NumIterations = 10;
MaxAccumulatedDiffractionAngle = - 6.2;
MaxAccumulatedDiffractionAngle = -6.2;
LevelDropThreshold = -131.0;
ReflectionPenalty = 0.97;
DiffractionPenalty = 2.5;
ExportVisualisation = 'false';
outFilePath = [cd,'\results\'];
export_visualization = 'false';
fixDirectPath = true;
result_file_path = 'pigeon_project.json';
geometry_file_path;
config_file_path = 'pigeon_project.ini';
run_quiet = false;
end
properties(Access = public, Hidden = true)
% path settings
pigeonPath
geometryFilePath
resultName = 'UrbanPaths';
pigeon_exe_path;
visualizationPaths = [];
modelName = 'scene_1_0';
saveBackupConfig = false;
end
......@@ -42,11 +45,13 @@ classdef itaPigeonProject
%% Initialization
methods
function obj = itaPigeonProject()
%ITA_CAU_URBANPROPAGATION Construct an instance of this class
%itaPigeonProject Construct an instance of this class
fullpath = mfilename('fullpath');
obj.pigeonPath = [fileparts(fullpath),'\private\'];
obj.geometryFilePath = obj.pigeonPath;
pigeon_exe_path = which( 'pigeon.exe' );
if isempty( pigeon_exe_path )
error 'Could not locate pigeon executable, please make pigeon available in the Matlab environment'
end
obj.pigeon_exe_path = pigeon_exe_path;
end
......@@ -56,24 +61,51 @@ classdef itaPigeonProject
%% public functions
methods(Access = public)
function urbanPaths = run(this,sourcePosition,receiverPosition)
function paths = run( obj,source_pos, receiver_pos )
% generate Config file
this.generateConfig(sourcePosition,receiverPosition);
exePath = [this.pigeonPath,'bin\','pigeon.exe'];%full path to the .exe file
configName = [this.outFilePath,this.resultName,'.ini'];
obj.generate_config( source_pos, receiver_pos );
command = sprintf( 'call "%s" "%s"', exePath, configName );
[ s, o ] = system( command );
urbanPaths = ita_propagation_load_paths([this.outFilePath,this.resultName,'.json']);
if obj.run_quiet
be_quiet = 'quiet';
else
be_quiet = '';
end
command = sprintf( 'call "%s" "%s" %s', obj.pigeon_exe_path, obj.config_file_path, be_quiet );
[ rcode, outp ] = system( command );
if ~isempty(urbanPaths) && this.fixDirectPath
urbanPaths = this.fixPaths(urbanPaths);
if rcode == 0
if ~obj.run_quiet
fprintf( '*** Pigeon exited successfully ***\n\n%s\n\n', outp );
fprintf( '*** To deactivate the output of the pigeon app, set run_quiet to ''true'' ***\n\n' );
end
if ~exist( obj.result_file_path, 'file' )
error( 'Result file ''%s'' has not been generated by pigeon application', obj.result_file_path )
end
paths = ita_propagation_load_paths( obj.result_file_path );
if obj.fixDirectPath
paths = obj.fixPaths( paths );
end
else
error( 'Pigeon exited with an error: \n%s\n', rcode, outp );
end
end
function run_gui( obj )
command = sprintf( 'call "%s"', obj.pigeon_exe_path );
[ ~, ~ ] = system( command );
end
function axHandle = plotPaths(this,urbanPaths,colors,axHandle)
if nargin < 3
......@@ -151,16 +183,16 @@ classdef itaPigeonProject
end
end
function obj = set.FilterNotVisiblePathsBetweenEdges(obj,input)
function obj = set.FilterNotVisiblePaths(obj,input)
if islogical(input)
switch input
case true
obj.FilterNotVisiblePathsBetweenEdges = 'true';
obj.FilterNotVisiblePaths = 'true';
case false
obj.FilterNotVisiblePathsBetweenEdges = 'false';
obj.FilterNotVisiblePaths = 'false';
end
else
obj.FilterNotVisiblePathsBetweenEdges = input;
obj.FilterNotVisiblePaths = input;
end
end
......@@ -177,16 +209,16 @@ classdef itaPigeonProject
end
end
function obj = set.ExportVisualisation(obj,input)
function obj = set.export_visualization(obj,input)
if islogical(input)
switch input
case true
obj.ExportVisualisation = 'true';
obj.export_visualization = 'true';
case false
obj.ExportVisualisation = 'false';
obj.export_visualization = 'false';
end
else
obj.ExportVisualisation = input;
obj.export_visualization = input;
end
end
......
......@@ -4,27 +4,23 @@
geoPropSim = itaGeoPropagation();
% load directivity
% directivity_id = geoPropSim.load_directivity( 'Genelec8020_2016_1x1.v17.ir.daff', 'Genelec8020' );
% directivity_id = geoPropSim.load_directivity( 'Genelec8020.ir.daff', 'Genelec8020' );
%% run simulation
geoPropSim.load_paths('ppa_example_paths.json');
% extract paths that lead to error
%geoPropSim.pps = geoPropSim.pps(84);
testPath1 = geoPropSim.pps;
geoPropSim.pps = geoPropSim.pps( 12 );
% Single path
geoPropSim.load_paths( 'ppa_example_paths.json' );
geoPropSim.pps = geoPropSim.pps( 12 ); % Pick a path
pps1TF = itaAudio();
pps1TF.freqData = geoPropSim.run;
pps1TF.freqData = geoPropSim.run();
geoPropSim.load_paths('ppa_example_paths_2.json');
% Multiple paths
geoPropSim.load_paths( 'ppa_example_paths_2.json' );
% extract paths that lead to error
%geoPropSim.pps = geoPropSim.pps(184);
testPath2 = geoPropSim.pps;
geoPropSim.pps = geoPropSim.pps( [ 1:83 85:181 182 183 185:249 ] ); % Skip paths that lead to errors
pps2TF = itaAudio();
pps2TF.freqData = geoPropSim.run;
pps2TF.freqData = geoPropSim.run();
%% General
pgn = itaPigeonProject();
pgn.geometry_file_path = fullfile( pwd, 'pigeon_test.skp' );
pgn.config_file_path = 'pigeon_test.ini';
pgn.result_file_path = 'pigeon_test.json';
pgn.run_quiet = false;
pgn.export_visualization = true;
emitter_pos = [ 10 10 1.1 ];
sensor_pos = [ 0 0 1.7 ];
paths = pgn.run( emitter_pos, sensor_pos );
fprintf( 'Received %i geometrical propagation paths\n', numel( paths ) )
%pgn.run_gui() % Opens the GUI of pigeon instead
B໿SketchUp Modelࣿ{19.0.1}韠䴳ᷟ䧡憸쥩䜗區僿C:\dev\toolbox\applications\SoundFieldSimulation\Pigeon\examples\pigeon_test.skp킰念￿ 噃牥楳湯慍ー￾䌉䄀爀挀䌀甀爀瘀攀̀＀￾䌊䄀琀琀爀椀戀甀琀攀＀￾䌓䄀琀琀爀椀戀甀琀攀䌀漀渀琀愀椀渀攀爀＀￾䌏䄀琀琀爀椀戀甀琀攀一愀洀攀搀Ā＀￾䌐䈀愀挀欀最爀漀甀渀搀䤀洀愀最攀਀＀￾䌇䌀愀洀攀爀愀Ԁ＀￾䌊䌀漀洀瀀漀渀攀渀琀଀＀￾䌒䌀漀洀瀀漀渀攀渀琀䈀攀栀愀瘀椀漀爀Ԁ＀￾䌔䌀漀洀瀀漀渀攀渀琀䐀攀昀椀渀椀琀椀漀渀଀＀￾䌒䌀漀洀瀀漀渀攀渀琀䤀渀猀琀愀渀挀攀؀＀￾䌕䌀漀渀猀琀爀甀挀琀椀漀渀䜀攀漀洀攀琀爀礀＀￾䌑䌀漀渀猀琀爀甀挀琀椀漀渀䰀椀渀攀Ā＀￾䌒䌀漀渀猀琀爀甀挀琀椀漀渀倀漀椀渀琀＀￾䌆䌀甀爀瘀攀Ѐ＀￾䌐䌀甀猀琀漀洀䰀椀渀攀匀琀礀氀攀Ȁ＀￾䌏䐀攀昀椀渀椀琀椀漀渀䰀椀猀琀＀￾䌄䐀椀戀̀＀￾䌊䐀椀洀攀渀猀椀漀渀Ā＀￾䌐䐀椀洀攀渀猀椀漀渀䰀椀渀攀愀爀؀＀￾䌐䐀椀洀攀渀猀椀漀渀刀愀搀椀愀氀Ȁ＀￾䌏䐀椀洀攀渀猀椀漀渀匀琀礀氀攀Ѐ＀￾䌏䐀爀愀眀椀渀最䔀氀攀洀攀渀琀ऀ＀￾䌅䔀搀最攀Ȁ＀￾䌈䔀搀最攀唀猀攀Ā＀￾䌇䔀渀琀椀琀礀Ԁ＀￾䌅䘀愀挀攀̀＀￾䌒䘀愀挀攀吀攀砀琀甀爀攀䌀漀漀爀搀猀Ѐ＀￾䌌䘀漀渀琀䴀愀渀愀最攀爀＀￾䌆䜀爀漀甀瀀Ā＀￾䌆䤀洀愀最攀Ā＀￾䌆䰀愀礀攀爀̀＀￾䌍䰀愀礀攀爀䴀愀渀愀最攀爀Ѐ＀￾䌑䰀椀渀攀匀琀礀氀攀䴀愀渀愀最攀爀Ā＀￾䌅䰀漀漀瀀Ā＀￾䌉䴀愀琀攀爀椀愀氀ఀ＀￾䌐䴀愀琀攀爀椀愀氀䴀愀渀愀最攀爀Ѐ＀￾䌉倀愀最攀䰀椀猀琀Ā＀￾䌋倀漀氀礀氀椀渀攀㌀搀＀￾䌍刀攀氀愀琀椀漀渀猀栀椀瀀＀￾䌐刀攀氀愀琀椀漀渀猀栀椀瀀䴀愀瀀＀￾䌑刀攀渀搀攀爀椀渀最伀瀀琀椀漀渀猀☀＀￾䌋匀挀栀攀洀愀䘀椀氀攀Ā＀￾䌑匀挀栀攀洀愀䘀椀氀琀攀爀䘀椀氀攀＀￾䌎匀挀栀攀洀愀娀椀瀀䘀椀氀攀Ā＀￾䌍匀攀挀琀椀漀渀倀氀愀渀攀̀＀￾䌋匀栀愀搀漀眀䤀渀昀漀܀＀￾䌇匀欀䘀漀渀琀Ā＀￾䌉匀欀攀琀挀栀䌀匀＀￾䌎匀欀攀琀挀栀唀瀀䴀漀搀攀氀ᴀ＀￾䌍匀欀攀琀挀栀唀瀀倀愀最攀Ā＀￾䌉匀欀瀀匀琀礀氀攀Ā＀￾䌐匀欀瀀匀琀礀氀攀䴀愀渀愀最攀爀Ȁ＀￾䌅吀攀砀琀ऀ＀￾䌊吀攀砀琀匀琀礀氀攀Ԁ＀￾䌈吀攀砀琀甀爀攀؀＀￾䌊吀栀甀洀戀渀愀椀氀Ā＀￾䌇嘀攀爀琀攀砀＀￾䌉嘀椀攀眀倀愀最攀ఀ＀￾䌊圀愀琀攀爀洀愀爀欀Ā＀￾䌑圀愀琀攀爀洀愀爀欀䴀愀渀愀最攀爀Ȁ＀￾䔒渀搀ⴀ伀昀ⴀ嘀攀爀猀椀漀渀ⴀ䴀愀瀀Ā뀀Ā̀?＀ϿЀ䌀楄Ѣ됀褀乐േᨊ
Supports Markdown
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